2021-02-27 15:14:02 +00:00
|
|
|
--- a/cmd/bootm.c
|
|
|
|
+++ b/cmd/bootm.c
|
2023-01-13 03:13:24 +00:00
|
|
|
@@ -259,6 +259,67 @@ U_BOOT_CMD(
|
2021-02-27 15:14:02 +00:00
|
|
|
/* iminfo - print header info for a requested image */
|
|
|
|
/*******************************************************************/
|
|
|
|
#if defined(CONFIG_CMD_IMI)
|
2022-07-12 02:41:30 +00:00
|
|
|
+#if defined(CONFIG_FIT)
|
2021-02-27 15:14:02 +00:00
|
|
|
+#define SECTOR_SHIFT 9
|
|
|
|
+static int image_totalsize(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
+ char *const argv[], short int in_blocks)
|
|
|
|
+{
|
|
|
|
+ ulong addr;
|
|
|
|
+ void *fit;
|
2021-02-20 13:04:38 +00:00
|
|
|
+ int bsize, tsize;
|
2021-02-27 15:14:02 +00:00
|
|
|
+ char buf[16];
|
|
|
|
+
|
|
|
|
+ if (argc >= 2)
|
|
|
|
+ addr = simple_strtoul(argv[1], NULL, 16);
|
|
|
|
+ else
|
|
|
|
+ addr = image_load_addr;
|
|
|
|
+
|
|
|
|
+ fit = (void *)map_sysmem(addr, 0);
|
|
|
|
+ tsize = fit_get_totalsize(fit);
|
|
|
|
+ unmap_sysmem(fit);
|
|
|
|
+ if (tsize == 0)
|
|
|
|
+ return 1;
|
|
|
|
+
|
|
|
|
+ bsize = (tsize >> SECTOR_SHIFT) + ((tsize & ((1 << SECTOR_SHIFT) - 1))?1:0);
|
|
|
|
+
|
|
|
|
+ if (!in_blocks)
|
|
|
|
+ snprintf(buf, sizeof(buf), "%x", tsize);
|
|
|
|
+ else
|
|
|
|
+ snprintf(buf, sizeof(buf), "%x", bsize);
|
|
|
|
+
|
|
|
|
+ if (argc >= 3)
|
|
|
|
+ return env_set(argv[2], buf);
|
|
|
|
+ else
|
|
|
|
+ printf("%s\n", buf);
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int do_imsz(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
+ char *const argv[])
|
|
|
|
+{
|
|
|
|
+ return image_totalsize(cmdtp, flag, argc, argv, 0);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int do_imszb(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
+ char *const argv[])
|
|
|
|
+{
|
|
|
|
+ return image_totalsize(cmdtp, flag, argc, argv, 1);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+U_BOOT_CMD(
|
|
|
|
+ imsz, CONFIG_SYS_MAXARGS, 1, do_imsz,
|
|
|
|
+ "get image total size (in bytes)",
|
|
|
|
+ "addr [maxhdrlen] [varname]\n"
|
|
|
|
+);
|
|
|
|
+
|
|
|
|
+U_BOOT_CMD(
|
|
|
|
+ imszb, CONFIG_SYS_MAXARGS, 1, do_imszb,
|
|
|
|
+ "get image total size (in blocks)",
|
|
|
|
+ "addr [maxhdrlen] [varname]\n"
|
|
|
|
+);
|
|
|
|
+
|
2022-07-12 02:41:30 +00:00
|
|
|
+#endif
|
2021-02-27 15:14:02 +00:00
|
|
|
static int do_iminfo(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
|
|
|
{
|
2022-01-11 21:26:43 +00:00
|
|
|
--- a/boot/image-fit.c
|
|
|
|
+++ b/boot/image-fit.c
|
2023-10-20 03:59:34 +00:00
|
|
|
@@ -2051,6 +2051,47 @@ static const char *fit_get_image_type_pr
|
2021-02-27 15:14:02 +00:00
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
+size_t fit_get_totalsize(const void *fit)
|
|
|
|
+{
|
|
|
|
+ int ret, ndepth, noffset, images_noffset;
|
|
|
|
+ size_t data_size, hdrsize, img_total, max_size = 0;
|
|
|
|
+ const void *data;
|
|
|
|
+
|
|
|
|
+ ret = fdt_check_header(fit);
|
|
|
|
+ if (ret) {
|
|
|
|
+ debug("Wrong FIT format: not a flattened device tree (err=%d)\n",
|
|
|
|
+ ret);
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ hdrsize = fdt_totalsize(fit);
|
|
|
|
+
|
2023-06-12 03:06:40 +00:00
|
|
|
+ /* take care of simple FIT with internal images */
|
|
|
|
+ max_size = hdrsize;
|
2021-02-27 15:14:02 +00:00
|
|
|
+
|
|
|
|
+ images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH);
|
2023-10-20 03:59:34 +00:00
|
|
|
+ if (images_noffset < 0)
|
|
|
|
+ goto out;
|
2021-02-27 15:14:02 +00:00
|
|
|
+
|
|
|
|
+ for (ndepth = 0,
|
|
|
|
+ noffset = fdt_next_node(fit, images_noffset, &ndepth);
|
|
|
|
+ (noffset >= 0) && (ndepth > 0);
|
|
|
|
+ noffset = fdt_next_node(fit, noffset, &ndepth)) {
|
|
|
|
+ if (ndepth == 1) {
|
|
|
|
+ ret = fit_image_get_data_and_size(fit, noffset, &data, &data_size);
|
|
|
|
+ if (ret)
|
2023-10-20 03:59:34 +00:00
|
|
|
+ goto out;
|
2021-02-27 15:14:02 +00:00
|
|
|
+
|
|
|
|
+ img_total = data_size + (data - fit);
|
|
|
|
+
|
|
|
|
+ max_size = (max_size > img_total) ? max_size : img_total;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
2023-10-20 03:59:34 +00:00
|
|
|
+out:
|
2021-02-27 15:14:02 +00:00
|
|
|
+ return max_size;
|
|
|
|
+}
|
|
|
|
+
|
2023-01-13 03:13:24 +00:00
|
|
|
int fit_image_load(struct bootm_headers *images, ulong addr,
|
2021-02-27 15:14:02 +00:00
|
|
|
const char **fit_unamep, const char **fit_uname_configp,
|
2023-01-13 03:13:24 +00:00
|
|
|
int arch, int ph_type, int bootstage_id,
|
2021-02-27 15:14:02 +00:00
|
|
|
--- a/include/image.h
|
|
|
|
+++ b/include/image.h
|
2023-07-22 14:50:27 +00:00
|
|
|
@@ -1047,6 +1047,7 @@ int fit_parse_subimage(const char *spec,
|
2021-02-27 15:14:02 +00:00
|
|
|
ulong *addr, const char **image_name);
|
|
|
|
|
|
|
|
int fit_get_subimage_count(const void *fit, int images_noffset);
|
|
|
|
+size_t fit_get_totalsize(const void *fit);
|
|
|
|
void fit_print_contents(const void *fit);
|
|
|
|
void fit_image_print(const void *fit, int noffset, const char *p);
|
|
|
|
|