From 6478a7ee3bae03bab4d9e092d91157a75d9fcf24 Mon Sep 17 00:00:00 2001 From: "Klaus H. Sorensen" Date: Wed, 11 Dec 2019 11:18:29 +0000 Subject: cmd/eeprom.c: prepend 0x to hex numbers in output message format If the numbers do not happen to contain any digits from [a-f], it's not clear that they are base 16. Signed-off-by: Klaus H. Sorensen Signed-off-by: Rasmus Villemoes Reviewed-by: Lukasz Majewski Reviewed-by: Heiko Schocher --- cmd/eeprom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/eeprom.c b/cmd/eeprom.c index 4a1569baf31..667149e2d45 100644 --- a/cmd/eeprom.c +++ b/cmd/eeprom.c @@ -308,7 +308,7 @@ static int eeprom_execute_command(enum eeprom_action action, int i2c_bus, { int rcode = 0; const char *const fmt = - "\nEEPROM @0x%lX %s: addr %08lx off %04lx count %ld ... "; + "\nEEPROM @0x%lX %s: addr 0x%08lx off 0x%04lx count %ld ... "; #ifdef CONFIG_CMD_EEPROM_LAYOUT struct eeprom_layout layout; #endif -- cgit v1.2.3 From b84acf10565af1578e68c533a36e629fe8b8e84a Mon Sep 17 00:00:00 2001 From: Eugeniu Rosca Date: Tue, 24 Dec 2019 17:51:06 +0100 Subject: dtimg/am57xx_evm_defconfig: Rename dtimg to adtimg Rename the existing 'dtimg' command to 'adtimg', in order to: - Suggest the Android origins and scope - Be consistent with the upcoming 'abootimg' command (naming suggested by Simon [*]) The change in _not_ backward compatible, but its benefits outweigh its downsides, given that we don't expect active users of 'dtimg' today. Perform the rename in several steps: 1. Rename *.c file and Kconfig symbol. This should allow 'git log --follow' to properly track the history of 'adtimg.c' 2. 's/dtimg/adtimg/g' in the internal namespace of 'adtimg.c' ELF comparison [**] before and after shows no functional change. [*] https://patchwork.ozlabs.org/patch/1182212/#2291600 [**] diff -u <(objdump -d cmd/dtimg.o) <(objdump -d cmd/adtimg.o) Cc: Tom Rini Signed-off-by: Eugeniu Rosca Reviewed-by: Simon Glass Reviewed-by: Sam Protsenko --- cmd/Kconfig | 4 +- cmd/Makefile | 2 +- cmd/adtimg.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ cmd/dtimg.c | 142 ----------------------------------------------------------- 4 files changed, 145 insertions(+), 145 deletions(-) create mode 100644 cmd/adtimg.c delete mode 100644 cmd/dtimg.c (limited to 'cmd') diff --git a/cmd/Kconfig b/cmd/Kconfig index 26c6551ed61..298feae24d3 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -364,8 +364,8 @@ config CMD_BOOTMENU help Add an ANSI terminal boot menu command. -config CMD_DTIMG - bool "dtimg" +config CMD_ADTIMG + bool "adtimg" help Android DTB/DTBO image manipulation commands. Read dtb/dtbo files from image into RAM, dump image structure information, etc. Those dtb/dtbo diff --git a/cmd/Makefile b/cmd/Makefile index 8df39f3a19f..ecf687d49f3 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -47,7 +47,7 @@ obj-$(CONFIG_CMD_SOUND) += sound.o ifdef CONFIG_POST obj-$(CONFIG_CMD_DIAG) += diag.o endif -obj-$(CONFIG_CMD_DTIMG) += dtimg.o +obj-$(CONFIG_CMD_ADTIMG) += adtimg.o obj-$(CONFIG_CMD_ECHO) += echo.o obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o obj-$(CONFIG_CMD_EEPROM) += eeprom.o diff --git a/cmd/adtimg.c b/cmd/adtimg.c new file mode 100644 index 00000000000..6c5d53cc680 --- /dev/null +++ b/cmd/adtimg.c @@ -0,0 +1,142 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2018 Linaro Ltd. + * Sam Protsenko + */ + +#include +#include +#include + +enum cmd_dtimg_info { + CMD_DTIMG_START = 0, + CMD_DTIMG_SIZE, +}; + +static int do_dtimg_dump(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + char *endp; + ulong hdr_addr; + + if (argc != 2) + return CMD_RET_USAGE; + + hdr_addr = simple_strtoul(argv[1], &endp, 16); + if (*endp != '\0') { + printf("Error: Wrong image address\n"); + return CMD_RET_FAILURE; + } + + if (!android_dt_check_header(hdr_addr)) { + printf("Error: DT image header is incorrect\n"); + return CMD_RET_FAILURE; + } + + android_dt_print_contents(hdr_addr); + + return CMD_RET_SUCCESS; +} + +static int dtimg_get_fdt(int argc, char * const argv[], enum cmd_dtimg_info cmd) +{ + ulong hdr_addr; + u32 index; + char *endp; + ulong fdt_addr; + u32 fdt_size; + char buf[65]; + + if (argc != 4) + return CMD_RET_USAGE; + + hdr_addr = simple_strtoul(argv[1], &endp, 16); + if (*endp != '\0') { + printf("Error: Wrong image address\n"); + return CMD_RET_FAILURE; + } + + if (!android_dt_check_header(hdr_addr)) { + printf("Error: DT image header is incorrect\n"); + return CMD_RET_FAILURE; + } + + index = simple_strtoul(argv[2], &endp, 0); + if (*endp != '\0') { + printf("Error: Wrong index\n"); + return CMD_RET_FAILURE; + } + + if (!android_dt_get_fdt_by_index(hdr_addr, index, &fdt_addr, &fdt_size)) + return CMD_RET_FAILURE; + + switch (cmd) { + case CMD_DTIMG_START: + snprintf(buf, sizeof(buf), "%lx", fdt_addr); + break; + case CMD_DTIMG_SIZE: + snprintf(buf, sizeof(buf), "%x", fdt_size); + break; + default: + printf("Error: Unknown cmd_dtimg_info value: %d\n", cmd); + return CMD_RET_FAILURE; + } + + env_set(argv[3], buf); + + return CMD_RET_SUCCESS; +} + +static int do_dtimg_start(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + return dtimg_get_fdt(argc, argv, CMD_DTIMG_START); +} + +static int do_dtimg_size(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + return dtimg_get_fdt(argc, argv, CMD_DTIMG_SIZE); +} + +static cmd_tbl_t cmd_dtimg_sub[] = { + U_BOOT_CMD_MKENT(dump, 2, 0, do_dtimg_dump, "", ""), + U_BOOT_CMD_MKENT(start, 4, 0, do_dtimg_start, "", ""), + U_BOOT_CMD_MKENT(size, 4, 0, do_dtimg_size, "", ""), +}; + +static int do_dtimg(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + cmd_tbl_t *cp; + + cp = find_cmd_tbl(argv[1], cmd_dtimg_sub, ARRAY_SIZE(cmd_dtimg_sub)); + + /* Strip off leading 'dtimg' command argument */ + argc--; + argv++; + + if (!cp || argc > cp->maxargs) + return CMD_RET_USAGE; + if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp)) + return CMD_RET_SUCCESS; + + return cp->cmd(cmdtp, flag, argc, argv); +} + +U_BOOT_CMD( + dtimg, CONFIG_SYS_MAXARGS, 0, do_dtimg, + "manipulate dtb/dtbo Android image", + "dump \n" + " - parse specified image and print its structure info\n" + " : image address in RAM, in hex\n" + "dtimg start \n" + " - get address (hex) of FDT in the image, by index\n" + " : image address in RAM, in hex\n" + " : index of desired FDT in the image\n" + " : name of variable where to store address of FDT\n" + "dtimg size \n" + " - get size (hex, bytes) of FDT in the image, by index\n" + " : image address in RAM, in hex\n" + " : index of desired FDT in the image\n" + " : name of variable where to store size of FDT" +); diff --git a/cmd/dtimg.c b/cmd/dtimg.c deleted file mode 100644 index 6c5d53cc680..00000000000 --- a/cmd/dtimg.c +++ /dev/null @@ -1,142 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * (C) Copyright 2018 Linaro Ltd. - * Sam Protsenko - */ - -#include -#include -#include - -enum cmd_dtimg_info { - CMD_DTIMG_START = 0, - CMD_DTIMG_SIZE, -}; - -static int do_dtimg_dump(cmd_tbl_t *cmdtp, int flag, int argc, - char * const argv[]) -{ - char *endp; - ulong hdr_addr; - - if (argc != 2) - return CMD_RET_USAGE; - - hdr_addr = simple_strtoul(argv[1], &endp, 16); - if (*endp != '\0') { - printf("Error: Wrong image address\n"); - return CMD_RET_FAILURE; - } - - if (!android_dt_check_header(hdr_addr)) { - printf("Error: DT image header is incorrect\n"); - return CMD_RET_FAILURE; - } - - android_dt_print_contents(hdr_addr); - - return CMD_RET_SUCCESS; -} - -static int dtimg_get_fdt(int argc, char * const argv[], enum cmd_dtimg_info cmd) -{ - ulong hdr_addr; - u32 index; - char *endp; - ulong fdt_addr; - u32 fdt_size; - char buf[65]; - - if (argc != 4) - return CMD_RET_USAGE; - - hdr_addr = simple_strtoul(argv[1], &endp, 16); - if (*endp != '\0') { - printf("Error: Wrong image address\n"); - return CMD_RET_FAILURE; - } - - if (!android_dt_check_header(hdr_addr)) { - printf("Error: DT image header is incorrect\n"); - return CMD_RET_FAILURE; - } - - index = simple_strtoul(argv[2], &endp, 0); - if (*endp != '\0') { - printf("Error: Wrong index\n"); - return CMD_RET_FAILURE; - } - - if (!android_dt_get_fdt_by_index(hdr_addr, index, &fdt_addr, &fdt_size)) - return CMD_RET_FAILURE; - - switch (cmd) { - case CMD_DTIMG_START: - snprintf(buf, sizeof(buf), "%lx", fdt_addr); - break; - case CMD_DTIMG_SIZE: - snprintf(buf, sizeof(buf), "%x", fdt_size); - break; - default: - printf("Error: Unknown cmd_dtimg_info value: %d\n", cmd); - return CMD_RET_FAILURE; - } - - env_set(argv[3], buf); - - return CMD_RET_SUCCESS; -} - -static int do_dtimg_start(cmd_tbl_t *cmdtp, int flag, int argc, - char * const argv[]) -{ - return dtimg_get_fdt(argc, argv, CMD_DTIMG_START); -} - -static int do_dtimg_size(cmd_tbl_t *cmdtp, int flag, int argc, - char * const argv[]) -{ - return dtimg_get_fdt(argc, argv, CMD_DTIMG_SIZE); -} - -static cmd_tbl_t cmd_dtimg_sub[] = { - U_BOOT_CMD_MKENT(dump, 2, 0, do_dtimg_dump, "", ""), - U_BOOT_CMD_MKENT(start, 4, 0, do_dtimg_start, "", ""), - U_BOOT_CMD_MKENT(size, 4, 0, do_dtimg_size, "", ""), -}; - -static int do_dtimg(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) -{ - cmd_tbl_t *cp; - - cp = find_cmd_tbl(argv[1], cmd_dtimg_sub, ARRAY_SIZE(cmd_dtimg_sub)); - - /* Strip off leading 'dtimg' command argument */ - argc--; - argv++; - - if (!cp || argc > cp->maxargs) - return CMD_RET_USAGE; - if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp)) - return CMD_RET_SUCCESS; - - return cp->cmd(cmdtp, flag, argc, argv); -} - -U_BOOT_CMD( - dtimg, CONFIG_SYS_MAXARGS, 0, do_dtimg, - "manipulate dtb/dtbo Android image", - "dump \n" - " - parse specified image and print its structure info\n" - " : image address in RAM, in hex\n" - "dtimg start \n" - " - get address (hex) of FDT in the image, by index\n" - " : image address in RAM, in hex\n" - " : index of desired FDT in the image\n" - " : name of variable where to store address of FDT\n" - "dtimg size \n" - " - get size (hex, bytes) of FDT in the image, by index\n" - " : image address in RAM, in hex\n" - " : index of desired FDT in the image\n" - " : name of variable where to store size of FDT" -); -- cgit v1.2.3 From 4c6edc288b4aa487824e8a276b925170f78fbe3a Mon Sep 17 00:00:00 2001 From: Eugeniu Rosca Date: Tue, 24 Dec 2019 17:51:07 +0100 Subject: cmd: adtimg: Rename internal symbols With 'dtimg.c' renamed to 'adtimg.c', now ensure the naming consistency in the internal implementation of 'adtimg.c'. No functional change intended. Signed-off-by: Eugeniu Rosca Reviewed-by: Sam Protsenko Reviewed-by: Simon Glass --- cmd/adtimg.c | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'cmd') diff --git a/cmd/adtimg.c b/cmd/adtimg.c index 6c5d53cc680..22b4f5e1a83 100644 --- a/cmd/adtimg.c +++ b/cmd/adtimg.c @@ -8,13 +8,13 @@ #include #include -enum cmd_dtimg_info { - CMD_DTIMG_START = 0, - CMD_DTIMG_SIZE, +enum cmd_adtimg_info { + CMD_ADTIMG_START = 0, + CMD_ADTIMG_SIZE, }; -static int do_dtimg_dump(cmd_tbl_t *cmdtp, int flag, int argc, - char * const argv[]) +static int do_adtimg_dump(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) { char *endp; ulong hdr_addr; @@ -38,7 +38,8 @@ static int do_dtimg_dump(cmd_tbl_t *cmdtp, int flag, int argc, return CMD_RET_SUCCESS; } -static int dtimg_get_fdt(int argc, char * const argv[], enum cmd_dtimg_info cmd) +static int adtimg_get_fdt(int argc, char * const argv[], + enum cmd_adtimg_info cmd) { ulong hdr_addr; u32 index; @@ -71,14 +72,14 @@ static int dtimg_get_fdt(int argc, char * const argv[], enum cmd_dtimg_info cmd) return CMD_RET_FAILURE; switch (cmd) { - case CMD_DTIMG_START: + case CMD_ADTIMG_START: snprintf(buf, sizeof(buf), "%lx", fdt_addr); break; - case CMD_DTIMG_SIZE: + case CMD_ADTIMG_SIZE: snprintf(buf, sizeof(buf), "%x", fdt_size); break; default: - printf("Error: Unknown cmd_dtimg_info value: %d\n", cmd); + printf("Error: Unknown cmd_adtimg_info value: %d\n", cmd); return CMD_RET_FAILURE; } @@ -87,31 +88,31 @@ static int dtimg_get_fdt(int argc, char * const argv[], enum cmd_dtimg_info cmd) return CMD_RET_SUCCESS; } -static int do_dtimg_start(cmd_tbl_t *cmdtp, int flag, int argc, - char * const argv[]) +static int do_adtimg_start(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) { - return dtimg_get_fdt(argc, argv, CMD_DTIMG_START); + return adtimg_get_fdt(argc, argv, CMD_ADTIMG_START); } -static int do_dtimg_size(cmd_tbl_t *cmdtp, int flag, int argc, - char * const argv[]) +static int do_adtimg_size(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) { - return dtimg_get_fdt(argc, argv, CMD_DTIMG_SIZE); + return adtimg_get_fdt(argc, argv, CMD_ADTIMG_SIZE); } -static cmd_tbl_t cmd_dtimg_sub[] = { - U_BOOT_CMD_MKENT(dump, 2, 0, do_dtimg_dump, "", ""), - U_BOOT_CMD_MKENT(start, 4, 0, do_dtimg_start, "", ""), - U_BOOT_CMD_MKENT(size, 4, 0, do_dtimg_size, "", ""), +static cmd_tbl_t cmd_adtimg_sub[] = { + U_BOOT_CMD_MKENT(dump, 2, 0, do_adtimg_dump, "", ""), + U_BOOT_CMD_MKENT(start, 4, 0, do_adtimg_start, "", ""), + U_BOOT_CMD_MKENT(size, 4, 0, do_adtimg_size, "", ""), }; -static int do_dtimg(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +static int do_adtimg(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { cmd_tbl_t *cp; - cp = find_cmd_tbl(argv[1], cmd_dtimg_sub, ARRAY_SIZE(cmd_dtimg_sub)); + cp = find_cmd_tbl(argv[1], cmd_adtimg_sub, ARRAY_SIZE(cmd_adtimg_sub)); - /* Strip off leading 'dtimg' command argument */ + /* Strip off leading 'adtimg' command argument */ argc--; argv++; @@ -124,17 +125,17 @@ static int do_dtimg(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } U_BOOT_CMD( - dtimg, CONFIG_SYS_MAXARGS, 0, do_dtimg, + adtimg, CONFIG_SYS_MAXARGS, 0, do_adtimg, "manipulate dtb/dtbo Android image", "dump \n" " - parse specified image and print its structure info\n" " : image address in RAM, in hex\n" - "dtimg start \n" + "adtimg start \n" " - get address (hex) of FDT in the image, by index\n" " : image address in RAM, in hex\n" " : index of desired FDT in the image\n" " : name of variable where to store address of FDT\n" - "dtimg size \n" + "adtimg size \n" " - get size (hex, bytes) of FDT in the image, by index\n" " : image address in RAM, in hex\n" " : index of desired FDT in the image\n" -- cgit v1.2.3 From 4f731c795d75aee548f6886f4f0da0a49a99354d Mon Sep 17 00:00:00 2001 From: Eugeniu Rosca Date: Tue, 24 Dec 2019 17:51:08 +0100 Subject: cmd: adtimg: Refactor usage style Trying to extend 'adtimg' functionality [1], we've been severely hit by a major limitation in the command's usage scheme. Specifically, the command's user interface appears to be too centric to getting the DTB/DTBO entry [3] based on the index of the desired DT in the image, which makes it really difficult retrieving the DT entry based on alternative criteria (e.g. filtering by id/rev fields), the latter being demanded by real life customer use-cases [1]. This went to the point of receiving below feedback from Sam [2]: -- snip -- As for 'dtimg' command: after giving it some thought, I think not much people using it yet. So in this particular case I don't have some strong preference, and if you think the 'dtimg' interface is ugly, and it overcomes "don't break interfaces" rule, maybe now is a good time to rework it (before it gets widely used). -- snip -- Given the above, rework the usage pattern from [4] to [5], in order to allow an intuitive enablement of "by id|rev" DT search [6]. [1] https://patchwork.ozlabs.org/cover/1202575/ ("cmd: dtimg: Enhance with --id and --rev options (take #1)") [2] https://patchwork.ozlabs.org/patch/1182207/#2317020 [3] https://source.android.com/devices/architecture/dto/partitions [4] Old usage adtimg dump - Print image contents adtimg start - Get DT address by index adtimg size - Get DT size by index [5] New usage adtimg addr - Set image location to adtimg dump - Print out image contents adtimg get dt --index= [avar [svar]] - Get DT address and size by index [6] Soon-to-be-provided "by id|rev" add-on functionality adtimg get dt --id= --rev= [avar [svar [ivar]]] - Get DT address/size/index by id|rev fields Signed-off-by: Eugeniu Rosca Reviewed-by: Sam Protsenko --- cmd/adtimg.c | 217 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 158 insertions(+), 59 deletions(-) (limited to 'cmd') diff --git a/cmd/adtimg.c b/cmd/adtimg.c index 22b4f5e1a83..60bb01c3498 100644 --- a/cmd/adtimg.c +++ b/cmd/adtimg.c @@ -2,18 +2,22 @@ /* * (C) Copyright 2018 Linaro Ltd. * Sam Protsenko + * Eugeniu Rosca */ #include #include #include -enum cmd_adtimg_info { - CMD_ADTIMG_START = 0, - CMD_ADTIMG_SIZE, -}; +#define OPT_INDEX "--index" -static int do_adtimg_dump(cmd_tbl_t *cmdtp, int flag, int argc, +/* + * Current/working DTB/DTBO Android image address. + * Similar to 'working_fdt' variable in 'fdt' command. + */ +static ulong working_img; + +static int do_adtimg_addr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { char *endp; @@ -24,86 +28,185 @@ static int do_adtimg_dump(cmd_tbl_t *cmdtp, int flag, int argc, hdr_addr = simple_strtoul(argv[1], &endp, 16); if (*endp != '\0') { - printf("Error: Wrong image address\n"); + printf("Error: Wrong image address '%s'\n", argv[1]); return CMD_RET_FAILURE; } - if (!android_dt_check_header(hdr_addr)) { - printf("Error: DT image header is incorrect\n"); + /* + * Allow users to set an address prior to copying the DTB/DTBO + * image to that same address, i.e. skip header verification. + */ + + working_img = hdr_addr; + return CMD_RET_SUCCESS; +} + +static int adtimg_check_working_img(void) +{ + if (!working_img) { + printf("Error: Please, call 'adtimg addr '. Aborting!\n"); return CMD_RET_FAILURE; } - android_dt_print_contents(hdr_addr); + if (!android_dt_check_header(working_img)) { + printf("Error: Invalid image header at 0x%lx\n", working_img); + return CMD_RET_FAILURE; + } return CMD_RET_SUCCESS; } -static int adtimg_get_fdt(int argc, char * const argv[], - enum cmd_adtimg_info cmd) +static int do_adtimg_dump(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) { - ulong hdr_addr; - u32 index; - char *endp; - ulong fdt_addr; - u32 fdt_size; - char buf[65]; - - if (argc != 4) + if (argc != 1) return CMD_RET_USAGE; - hdr_addr = simple_strtoul(argv[1], &endp, 16); - if (*endp != '\0') { - printf("Error: Wrong image address\n"); + if (adtimg_check_working_img() != CMD_RET_SUCCESS) + return CMD_RET_FAILURE; + + android_dt_print_contents(working_img); + + return CMD_RET_SUCCESS; +} + +static int adtimg_getopt_u32(char * const opt, char * const name, u32 *optval) +{ + char *endp, *str; + u32 val; + + if (!opt || !name || !optval) + return CMD_RET_FAILURE; + + str = strchr(opt, '='); + if (!str) { + printf("Error: Option '%s' not followed by '='\n", name); return CMD_RET_FAILURE; } - if (!android_dt_check_header(hdr_addr)) { - printf("Error: DT image header is incorrect\n"); + if (*++str == '\0') { + printf("Error: Option '%s=' not followed by value\n", name); return CMD_RET_FAILURE; } - index = simple_strtoul(argv[2], &endp, 0); + val = simple_strtoul(str, &endp, 0); if (*endp != '\0') { - printf("Error: Wrong index\n"); + printf("Error: Wrong integer value '%s=%s'\n", name, str); return CMD_RET_FAILURE; } - if (!android_dt_get_fdt_by_index(hdr_addr, index, &fdt_addr, &fdt_size)) + *optval = val; + return CMD_RET_SUCCESS; +} + +static int adtimg_getopt_index(int argc, char * const argv[], u32 *index, + char **avar, char **svar) +{ + int ret; + + if (!argv || !avar || !svar) return CMD_RET_FAILURE; - switch (cmd) { - case CMD_ADTIMG_START: - snprintf(buf, sizeof(buf), "%lx", fdt_addr); - break; - case CMD_ADTIMG_SIZE: - snprintf(buf, sizeof(buf), "%x", fdt_size); - break; - default: - printf("Error: Unknown cmd_adtimg_info value: %d\n", cmd); + if (argc > 3) { + printf("Error: Unexpected argument '%s'\n", argv[3]); return CMD_RET_FAILURE; } - env_set(argv[3], buf); + ret = adtimg_getopt_u32(argv[0], OPT_INDEX, index); + if (ret != CMD_RET_SUCCESS) + return ret; + + if (argc > 1) + *avar = argv[1]; + if (argc > 2) + *svar = argv[2]; return CMD_RET_SUCCESS; } -static int do_adtimg_start(cmd_tbl_t *cmdtp, int flag, int argc, - char * const argv[]) +static int adtimg_get_dt_by_index(int argc, char * const argv[]) { - return adtimg_get_fdt(argc, argv, CMD_ADTIMG_START); + ulong addr; + u32 index, size; + int ret; + char *avar = NULL, *svar = NULL; + + ret = adtimg_getopt_index(argc, argv, &index, &avar, &svar); + if (ret != CMD_RET_SUCCESS) + return ret; + + if (!android_dt_get_fdt_by_index(working_img, index, &addr, &size)) + return CMD_RET_FAILURE; + + if (avar && svar) { + ret = env_set_hex(avar, addr); + if (ret) { + printf("Error: Can't set '%s' to 0x%lx\n", avar, addr); + return CMD_RET_FAILURE; + } + ret = env_set_hex(svar, size); + if (ret) { + printf("Error: Can't set '%s' to 0x%x\n", svar, size); + return CMD_RET_FAILURE; + } + } else if (avar) { + ret = env_set_hex(avar, addr); + if (ret) { + printf("Error: Can't set '%s' to 0x%lx\n", avar, addr); + return CMD_RET_FAILURE; + } + printf("0x%x (%d)\n", size, size); + } else { + printf("0x%lx, 0x%x (%d)\n", addr, size, size); + } + + return CMD_RET_SUCCESS; } -static int do_adtimg_size(cmd_tbl_t *cmdtp, int flag, int argc, - char * const argv[]) +static int adtimg_get_dt(int argc, char * const argv[]) { - return adtimg_get_fdt(argc, argv, CMD_ADTIMG_SIZE); + if (argc < 2) { + printf("Error: No options passed to '%s'\n", argv[0]); + return CMD_RET_FAILURE; + } + + /* Strip off leading 'dt' command argument */ + argc--; + argv++; + + if (!strncmp(argv[0], OPT_INDEX, sizeof(OPT_INDEX) - 1)) + return adtimg_get_dt_by_index(argc, argv); + + printf("Error: Option '%s' not supported\n", argv[0]); + return CMD_RET_FAILURE; +} + +static int do_adtimg_get(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + if (argc < 2) { + printf("Error: No arguments passed to '%s'\n", argv[0]); + return CMD_RET_FAILURE; + } + + if (adtimg_check_working_img() != CMD_RET_SUCCESS) + return CMD_RET_FAILURE; + + /* Strip off leading 'get' command argument */ + argc--; + argv++; + + if (!strcmp(argv[0], "dt")) + return adtimg_get_dt(argc, argv); + + printf("Error: Wrong argument '%s'\n", argv[0]); + return CMD_RET_FAILURE; } static cmd_tbl_t cmd_adtimg_sub[] = { - U_BOOT_CMD_MKENT(dump, 2, 0, do_adtimg_dump, "", ""), - U_BOOT_CMD_MKENT(start, 4, 0, do_adtimg_start, "", ""), - U_BOOT_CMD_MKENT(size, 4, 0, do_adtimg_size, "", ""), + U_BOOT_CMD_MKENT(addr, CONFIG_SYS_MAXARGS, 1, do_adtimg_addr, "", ""), + U_BOOT_CMD_MKENT(dump, CONFIG_SYS_MAXARGS, 1, do_adtimg_dump, "", ""), + U_BOOT_CMD_MKENT(get, CONFIG_SYS_MAXARGS, 1, do_adtimg_get, "", ""), }; static int do_adtimg(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) @@ -127,17 +230,13 @@ static int do_adtimg(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) U_BOOT_CMD( adtimg, CONFIG_SYS_MAXARGS, 0, do_adtimg, "manipulate dtb/dtbo Android image", - "dump \n" - " - parse specified image and print its structure info\n" - " : image address in RAM, in hex\n" - "adtimg start \n" - " - get address (hex) of FDT in the image, by index\n" - " : image address in RAM, in hex\n" - " : index of desired FDT in the image\n" - " : name of variable where to store address of FDT\n" - "adtimg size \n" - " - get size (hex, bytes) of FDT in the image, by index\n" - " : image address in RAM, in hex\n" - " : index of desired FDT in the image\n" - " : name of variable where to store size of FDT" + "addr - Set image location to \n" + "adtimg dump - Print out image contents\n" + "adtimg get dt --index= [avar [svar]] - Get DT address/size by index\n" + "\n" + "Legend:\n" + " - : DTB/DTBO image address (hex) in RAM\n" + " - : index (hex/dec) of desired DT in the image\n" + " - : variable name to contain DT address (hex)\n" + " - : variable name to contain DT size (hex)" ); -- cgit v1.2.3