3 @@ -228,6 +228,65 @@ U_BOOT_CMD(
4 /* iminfo - print header info for a requested image */
5 /*******************************************************************/
6 #if defined(CONFIG_CMD_IMI)
7 +#define SECTOR_SHIFT 9
8 +static int image_totalsize(struct cmd_tbl *cmdtp, int flag, int argc,
9 + char *const argv[], short int in_blocks)
17 + addr = simple_strtoul(argv[1], NULL, 16);
19 + addr = image_load_addr;
21 + fit = (void *)map_sysmem(addr, 0);
22 + tsize = fit_get_totalsize(fit);
27 + bsize = (tsize >> SECTOR_SHIFT) + ((tsize & ((1 << SECTOR_SHIFT) - 1))?1:0);
30 + snprintf(buf, sizeof(buf), "%x", tsize);
32 + snprintf(buf, sizeof(buf), "%x", bsize);
35 + return env_set(argv[2], buf);
37 + printf("%s\n", buf);
42 +static int do_imsz(struct cmd_tbl *cmdtp, int flag, int argc,
45 + return image_totalsize(cmdtp, flag, argc, argv, 0);
48 +static int do_imszb(struct cmd_tbl *cmdtp, int flag, int argc,
51 + return image_totalsize(cmdtp, flag, argc, argv, 1);
55 + imsz, CONFIG_SYS_MAXARGS, 1, do_imsz,
56 + "get image total size (in bytes)",
57 + "addr [maxhdrlen] [varname]\n"
61 + imszb, CONFIG_SYS_MAXARGS, 1, do_imszb,
62 + "get image total size (in blocks)",
63 + "addr [maxhdrlen] [varname]\n"
66 static int do_iminfo(struct cmd_tbl *cmdtp, int flag, int argc,
69 --- a/common/image-fit.c
70 +++ b/common/image-fit.c
71 @@ -1970,6 +1970,51 @@ static const char *fit_get_image_type_pr
75 +size_t fit_get_totalsize(const void *fit)
77 + int ret, ndepth, noffset, images_noffset;
78 + size_t data_size, hdrsize, img_total, max_size = 0;
81 + ret = fdt_check_header(fit);
83 + debug("Wrong FIT format: not a flattened device tree (err=%d)\n",
88 + hdrsize = fdt_totalsize(fit);
90 + /* simple FIT with internal images */
91 + if (hdrsize > 0x1000)
94 + images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
95 + if (images_noffset < 0) {
96 + printf("Can't find images parent node '%s' (%s)\n",
97 + FIT_IMAGES_PATH, fdt_strerror(images_noffset));
102 + noffset = fdt_next_node(fit, images_noffset, &ndepth);
103 + (noffset >= 0) && (ndepth > 0);
104 + noffset = fdt_next_node(fit, noffset, &ndepth)) {
106 + ret = fit_image_get_data_and_size(fit, noffset, &data, &data_size);
110 + img_total = data_size + (data - fit);
112 + max_size = (max_size > img_total) ? max_size : img_total;
120 int fit_image_load(bootm_headers_t *images, ulong addr,
121 const char **fit_unamep, const char **fit_uname_configp,
122 int arch, int image_type, int bootstage_id,
123 --- a/include/image.h
124 +++ b/include/image.h
125 @@ -1041,6 +1041,7 @@ int fit_parse_subimage(const char *spec,
126 ulong *addr, const char **image_name);
128 int fit_get_subimage_count(const void *fit, int images_noffset);
129 +size_t fit_get_totalsize(const void *fit);
130 void fit_print_contents(const void *fit);
131 void fit_image_print(const void *fit, int noffset, const char *p);