Commit 97f17fa6278747d059fccb8eef7f79ec3dfc9502
Committed by
Stefano Babic
1 parent
cf4128e53c
Exists in
smarc_8mq_lf_v2020.04
and in
22 other branches
tools: imximage: refactor header length calculations for imximage v1
We can use the same header length calculations for both imximage v1 and v2. This addresses TODO comments about imximage v1 in the current code. With this patch applied, *header_size_ptr in imximage_set_header() will have the correct value for both imximage v1 and v2. This is necessary for people wanting to add proprietary data behind the created imximage. Signed-off-by: Martin Kaiser <martin@kaiser.cx> Cc: sbabic@denx.de
Showing 1 changed file with 16 additions and 22 deletions Side-by-side Diff
tools/imximage.c
... | ... | @@ -300,8 +300,7 @@ |
300 | 300 | /* Set magic number */ |
301 | 301 | fhdr_v1->app_code_barker = APP_CODE_BARKER; |
302 | 302 | |
303 | - /* TODO: check i.MX image V1 handling, for now use 'old' style */ | |
304 | - hdr_base = entry_point - 4096; | |
303 | + hdr_base = entry_point - imximage_init_loadsize + flash_offset; | |
305 | 304 | fhdr_v1->app_dest_ptr = hdr_base - flash_offset; |
306 | 305 | fhdr_v1->app_code_jump_vector = entry_point; |
307 | 306 | |
308 | 307 | |
309 | 308 | |
... | ... | @@ -833,18 +832,19 @@ |
833 | 832 | /* Parse dcd configuration file */ |
834 | 833 | dcd_len = parse_cfg_file(imxhdr, params->imagename); |
835 | 834 | |
836 | - if (imximage_version == IMXIMAGE_V2) { | |
835 | + if (imximage_version == IMXIMAGE_V1) | |
836 | + header_size = sizeof(flash_header_v1_t); | |
837 | + else { | |
837 | 838 | header_size = sizeof(flash_header_v2_t) + sizeof(boot_data_t); |
838 | 839 | if (!plugin_image) |
839 | 840 | header_size += sizeof(dcd_v2_t); |
840 | 841 | else |
841 | 842 | header_size += MAX_PLUGIN_CODE_SIZE; |
842 | - | |
843 | - if (imximage_init_loadsize < imximage_ivt_offset + header_size) | |
844 | - imximage_init_loadsize = imximage_ivt_offset + | |
845 | - header_size; | |
846 | 843 | } |
847 | 844 | |
845 | + if (imximage_init_loadsize < imximage_ivt_offset + header_size) | |
846 | + imximage_init_loadsize = imximage_ivt_offset + header_size; | |
847 | + | |
848 | 848 | /* Set the imx header */ |
849 | 849 | (*set_imx_hdr)(imxhdr, dcd_len, params->ep, imximage_ivt_offset); |
850 | 850 | |
851 | 851 | |
852 | 852 | |
... | ... | @@ -913,23 +913,21 @@ |
913 | 913 | /* Parse dcd configuration file */ |
914 | 914 | parse_cfg_file(&imximage_header, params->imagename); |
915 | 915 | |
916 | - /* TODO: check i.MX image V1 handling, for now use 'old' style */ | |
917 | - if (imximage_version == IMXIMAGE_V1) { | |
918 | - alloc_len = 4096; | |
919 | - header_size = 4096; | |
920 | - } else { | |
916 | + if (imximage_version == IMXIMAGE_V1) | |
917 | + header_size = sizeof(imx_header_v1_t); | |
918 | + else { | |
921 | 919 | header_size = sizeof(flash_header_v2_t) + sizeof(boot_data_t); |
922 | 920 | if (!plugin_image) |
923 | 921 | header_size += sizeof(dcd_v2_t); |
924 | 922 | else |
925 | 923 | header_size += MAX_PLUGIN_CODE_SIZE; |
926 | - | |
927 | - if (imximage_init_loadsize < imximage_ivt_offset + header_size) | |
928 | - imximage_init_loadsize = imximage_ivt_offset + | |
929 | - header_size; | |
930 | - alloc_len = imximage_init_loadsize - imximage_ivt_offset; | |
931 | 924 | } |
932 | 925 | |
926 | + if (imximage_init_loadsize < imximage_ivt_offset + header_size) | |
927 | + imximage_init_loadsize = imximage_ivt_offset + header_size; | |
928 | + | |
929 | + alloc_len = imximage_init_loadsize - imximage_ivt_offset; | |
930 | + | |
933 | 931 | if (alloc_len < header_size) { |
934 | 932 | fprintf(stderr, "%s: header error\n", |
935 | 933 | params->cmdname); |
... | ... | @@ -959,11 +957,7 @@ |
959 | 957 | |
960 | 958 | pad_len = ROUND(sbuf.st_size, 4096) - sbuf.st_size; |
961 | 959 | |
962 | - /* TODO: check i.MX image V1 handling, for now use 'old' style */ | |
963 | - if (imximage_version == IMXIMAGE_V1) | |
964 | - return 0; | |
965 | - else | |
966 | - return pad_len; | |
960 | + return pad_len; | |
967 | 961 | } |
968 | 962 | |
969 | 963 |