|
| 1 | +--- a/cmd/bootm.c |
| 2 | ++++ b/cmd/bootm.c |
| 3 | +@@ -260,6 +260,76 @@ 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) |
| 10 | ++{ |
| 11 | ++ ulong addr; |
| 12 | ++ void *hdr; |
| 13 | ++ uint32_t bsize, tsize = 0; |
| 14 | ++ char buf[16]; |
| 15 | ++ |
| 16 | ++ if (argc >= 2) |
| 17 | ++ addr = simple_strtoul(argv[1], NULL, 16); |
| 18 | ++ else |
| 19 | ++ addr = image_load_addr; |
| 20 | ++ |
| 21 | ++ hdr = (void *)map_sysmem(addr, 0); |
| 22 | ++ |
| 23 | ++ switch (genimg_get_format(hdr)) { |
| 24 | ++ case IMAGE_FORMAT_LEGACY: |
| 25 | ++ if(CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)) |
| 26 | ++ tsize = image_get_image_size(hdr); |
| 27 | ++ break; |
| 28 | ++ case IMAGE_FORMAT_FIT: |
| 29 | ++ if(CONFIG_IS_ENABLED(FIT)) |
| 30 | ++ tsize = fit_get_totalsize(hdr); |
| 31 | ++ break; |
| 32 | ++ } |
| 33 | ++ |
| 34 | ++ unmap_sysmem(hdr); |
| 35 | ++ if (tsize == 0) |
| 36 | ++ return 1; |
| 37 | ++ |
| 38 | ++ bsize = (tsize >> SECTOR_SHIFT) + ((tsize & ((1 << SECTOR_SHIFT) - 1))?1:0); |
| 39 | ++ |
| 40 | ++ if (!in_blocks) |
| 41 | ++ snprintf(buf, sizeof(buf), "%x", tsize); |
| 42 | ++ else |
| 43 | ++ snprintf(buf, sizeof(buf), "%x", bsize); |
| 44 | ++ |
| 45 | ++ if (argc >= 3) |
| 46 | ++ return env_set(argv[2], buf); |
| 47 | ++ else |
| 48 | ++ printf("%s\n", buf); |
| 49 | ++ |
| 50 | ++ return 0; |
| 51 | ++} |
| 52 | ++ |
| 53 | ++static int do_imsz(struct cmd_tbl *cmdtp, int flag, int argc, |
| 54 | ++ char *const argv[]) |
| 55 | ++{ |
| 56 | ++ return image_totalsize(cmdtp, flag, argc, argv, 0); |
| 57 | ++} |
| 58 | ++ |
| 59 | ++static int do_imszb(struct cmd_tbl *cmdtp, int flag, int argc, |
| 60 | ++ char *const argv[]) |
| 61 | ++{ |
| 62 | ++ return image_totalsize(cmdtp, flag, argc, argv, 1); |
| 63 | ++} |
| 64 | ++ |
| 65 | ++U_BOOT_CMD( |
| 66 | ++ imsz, CONFIG_SYS_MAXARGS, 1, do_imsz, |
| 67 | ++ "get image total size (in bytes)", |
| 68 | ++ "addr [maxhdrlen] [varname]\n" |
| 69 | ++); |
| 70 | ++ |
| 71 | ++U_BOOT_CMD( |
| 72 | ++ imszb, CONFIG_SYS_MAXARGS, 1, do_imszb, |
| 73 | ++ "get image total size (in blocks)", |
| 74 | ++ "addr [maxhdrlen] [varname]\n" |
| 75 | ++); |
| 76 | ++ |
| 77 | + static int do_iminfo(struct cmd_tbl *cmdtp, int flag, int argc, |
| 78 | + char *const argv[]) |
| 79 | + { |
| 80 | +--- a/boot/image-fit.c |
| 81 | ++++ b/boot/image-fit.c |
| 82 | +@@ -2054,6 +2054,47 @@ static const char *fit_get_image_type_pr |
| 83 | + return "unknown"; |
| 84 | + } |
| 85 | + |
| 86 | ++size_t fit_get_totalsize(const void *fit) |
| 87 | ++{ |
| 88 | ++ int ret, ndepth, noffset, images_noffset; |
| 89 | ++ size_t data_size, hdrsize, img_total, max_size = 0; |
| 90 | ++ const void *data; |
| 91 | ++ |
| 92 | ++ ret = fdt_check_header(fit); |
| 93 | ++ if (ret) { |
| 94 | ++ debug("Wrong FIT format: not a flattened device tree (err=%d)\n", |
| 95 | ++ ret); |
| 96 | ++ return 0; |
| 97 | ++ } |
| 98 | ++ |
| 99 | ++ hdrsize = fdt_totalsize(fit); |
| 100 | ++ |
| 101 | ++ /* take care of simple FIT with internal images */ |
| 102 | ++ max_size = hdrsize; |
| 103 | ++ |
| 104 | ++ images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); |
| 105 | ++ if (images_noffset < 0) |
| 106 | ++ goto out; |
| 107 | ++ |
| 108 | ++ for (ndepth = 0, |
| 109 | ++ noffset = fdt_next_node(fit, images_noffset, &ndepth); |
| 110 | ++ (noffset >= 0) && (ndepth > 0); |
| 111 | ++ noffset = fdt_next_node(fit, noffset, &ndepth)) { |
| 112 | ++ if (ndepth == 1) { |
| 113 | ++ ret = fit_image_get_data(fit, noffset, &data, &data_size); |
| 114 | ++ if (ret) |
| 115 | ++ goto out; |
| 116 | ++ |
| 117 | ++ img_total = data_size + (data - fit); |
| 118 | ++ |
| 119 | ++ max_size = (max_size > img_total) ? max_size : img_total; |
| 120 | ++ } |
| 121 | ++ } |
| 122 | ++ |
| 123 | ++out: |
| 124 | ++ return max_size; |
| 125 | ++} |
| 126 | ++ |
| 127 | + int fit_image_load(struct bootm_headers *images, ulong addr, |
| 128 | + const char **fit_unamep, const char **fit_uname_configp, |
| 129 | + int arch, int ph_type, int bootstage_id, |
| 130 | +--- a/include/image.h |
| 131 | ++++ b/include/image.h |
| 132 | +@@ -1113,6 +1113,7 @@ int fit_parse_subimage(const char *spec, |
| 133 | + ulong *addr, const char **image_name); |
| 134 | + |
| 135 | + int fit_get_subimage_count(const void *fit, int images_noffset); |
| 136 | ++size_t fit_get_totalsize(const void *fit); |
| 137 | + void fit_print_contents(const void *fit); |
| 138 | + void fit_image_print(const void *fit, int noffset, const char *p); |
| 139 | + |
0 commit comments