summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/imxtools/sbtools/sbtoelf.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/utils/imxtools/sbtools/sbtoelf.c b/utils/imxtools/sbtools/sbtoelf.c
index 98bb2dcc45..540d55acc1 100644
--- a/utils/imxtools/sbtools/sbtoelf.c
+++ b/utils/imxtools/sbtools/sbtoelf.c
@@ -267,9 +267,6 @@ enum sb_version_guess_t guess_sb_version(const char *filename)
267 FILE *f = fopen(filename, "rb"); 267 FILE *f = fopen(filename, "rb");
268 if(f == NULL) 268 if(f == NULL)
269 bugp("Cannot open file for reading\n"); 269 bugp("Cannot open file for reading\n");
270 fseek(f, 0, SEEK_END);
271 long file_size = ftell(f);
272 fseek(f, 0, SEEK_SET);
273 // check signature 270 // check signature
274 uint8_t sig[4]; 271 uint8_t sig[4];
275 if(fseek(f, 20, SEEK_SET)) 272 if(fseek(f, 20, SEEK_SET))
@@ -286,13 +283,20 @@ enum sb_version_guess_t guess_sb_version(const char *filename)
286 ret(SB_VERSION_UNK); 283 ret(SB_VERSION_UNK);
287 if(hdr_size == 0x34) 284 if(hdr_size == 0x34)
288 ret(SB_VERSION_1); 285 ret(SB_VERSION_1);
289 // check image size (v2) 286 // check header params relationship
290 uint32_t img_size; 287 struct
291 if(fseek(f, 28, SEEK_SET)) 288 {
289 uint16_t nr_keys; /* Number of encryption keys */
290 uint16_t key_dict_off; /* Offset to key dictionary (in blocks) */
291 uint16_t header_size; /* In blocks */
292 uint16_t nr_sections; /* Number of sections */
293 uint16_t sec_hdr_size; /* Section header size (in blocks) */
294 } __attribute__((packed)) u;
295 if(fseek(f, 0x28, SEEK_SET))
292 ret(SB_VERSION_UNK); 296 ret(SB_VERSION_UNK);
293 if(fread(&img_size, 4, 1, f) != 1) 297 if(fread(&u, sizeof(u), 1, f) != 1)
294 ret(SB_VERSION_UNK); 298 ret(SB_VERSION_UNK);
295 if(img_size * 16 == (uint32_t)file_size) 299 if(u.sec_hdr_size == 1 && u.header_size == 6 && u.key_dict_off == u.header_size + u.nr_sections)
296 ret(SB_VERSION_2); 300 ret(SB_VERSION_2);
297 ret(SB_VERSION_UNK); 301 ret(SB_VERSION_UNK);
298#undef ret 302#undef ret