Commit 67e6c343 authored by Adam Wujek's avatar Adam Wujek

sw/petalinux/diot-util: print information from uboot

Print:
- version of the DTB
- boot source of uboot
- boot source of uimage
- reset reason
Signed-off-by: 's avatarAdam Wujek <dev_public@wujek.eu>
parent c010d696
......@@ -26,6 +26,10 @@
#include "fru.h"
#include "fru_utils.h"
#define DTB_HW_VER_FILE "/sys/firmware/devicetree/base/chosen/hw_ver"
#define DTB_MODEBOOT_FILE "/sys/firmware/devicetree/base/chosen/modeboot"
#define DTB_UIMAGE_SOURCE_FILE "/sys/firmware/devicetree/base/chosen/uimage_source"
#define DTB_RESET_REASON_FILE "/sys/firmware/devicetree/base/chosen/reset_reason"
#define READLINE_PROMPT "diot_util> "
......@@ -39,6 +43,11 @@ struct command_entry {
char *cmd_params;
};
struct string_map {
char *index;
char *label;
};
/* readline related */
char **command_completion(const char *, int, int);
char *command_name_generator(const char *, int);
......@@ -49,6 +58,26 @@ int cmd_exit(char *params);
int cmd_help(char *params);
int cmd_version(char *params);
struct string_map reset_reason_db[] = {
{ "DEBUG", "debuger" },
{ "SOFT", "soft" },
{ "SRST", "external" },
{ "PS-ONLY", "ps-only" },
{ "PMU", "pmu" },
{ "INTERNAL", "internal POR" },
{ "EXTERNAL", "external POR" },
};
struct string_map boot_mode_db[] = {
{ "usb_dfu_spl", "usb" },
{ "jtagboot", "jtag" },
{ "qspiboot", "qspi" },
{ "emmcboot", "emmc" },
{ "sdboot", "microSD" },
{ "nandboot", "nand" },
};
struct command_entry commands_list[] = {
{ .cmd_name = "status", .cmd_func = cmd_print_status, .cmd_help_string = "Print status\n", .cmd_params = NULL},
{ .cmd_name = "exit", .cmd_func = cmd_exit, .cmd_help_string = "quit program\n", .cmd_params = NULL},
......@@ -186,6 +215,72 @@ static void print_fmc_status(void)
free(fru);
}
static char * get_file_content(char *filename, char *buff, size_t buff_size)
{
FILE *file_h;
file_h = fopen(filename, "r");
if (!file_h) {
diot_error_add("Unable to open file (%s)\n", filename);
return "Error";
}
(void)! fread(buff, 1, buff_size, file_h);
/* make sure the last character is 0 */
buff[buff_size - 1] = 0;
if (ferror(file_h)) {
diot_error_add("Error while reading file (%s)\n", filename);
return "Error";
}
fclose(file_h);
return buff;
}
static char *string_map_get(char *name, struct string_map *map, size_t map_size)
{
int i;
for (i = 0; i < map_size; i++)
if (!strcmp(map[i].index, name))
return map[i].label;
return "Unknown";
}
static void print_uboot_info(void)
{
char buff[30];
printf("Boot information\n");
printf("-------------------+----------------+\n");
printf("DTB for HW version |%15s |\n",
get_file_content(DTB_HW_VER_FILE, buff, sizeof(buff)));
printf("uboot boot source |%15s |\n",
string_map_get(get_file_content(DTB_MODEBOOT_FILE, buff,
sizeof(buff)),
boot_mode_db,
sizeof(boot_mode_db)/sizeof(boot_mode_db[0]))
);
printf("uimage boot source |%15s |\n",
get_file_content(DTB_UIMAGE_SOURCE_FILE, buff, sizeof(buff)));
printf("reset reason |%15s |\n",
string_map_get(get_file_content(DTB_RESET_REASON_FILE, buff,
sizeof(buff)),
reset_reason_db,
sizeof(reset_reason_db)/sizeof(reset_reason_db[0]))
);
printf("-------------------+----------------+\n");
}
int cmd_print_status(char *params)
{
int hw_version;
......@@ -216,6 +311,9 @@ int cmd_print_status(char *params)
print_fmc_status();
printf("\n");
print_uboot_info();
printf("\n");
diot_error_print();
return 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment