From 5b00e59614f584cc6dc440cc064097a2fb7321f7 Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Sat, 26 Jan 2013 16:50:50 +0000 Subject: [PATCH] imxtools/sbtools: fix file type detection Change-Id: I872e98f5810df3ecc975e025385f9c5ca7b47a44 --- utils/imxtools/sbtools/sbtoelf.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/utils/imxtools/sbtools/sbtoelf.c b/utils/imxtools/sbtools/sbtoelf.c index c61650d274..98bb2dcc45 100644 --- a/utils/imxtools/sbtools/sbtoelf.c +++ b/utils/imxtools/sbtools/sbtoelf.c @@ -267,6 +267,9 @@ enum sb_version_guess_t guess_sb_version(const char *filename) FILE *f = fopen(filename, "rb"); if(f == NULL) bugp("Cannot open file for reading\n"); + fseek(f, 0, SEEK_END); + long file_size = ftell(f); + fseek(f, 0, SEEK_SET); // check signature uint8_t sig[4]; if(fseek(f, 20, SEEK_SET)) @@ -283,12 +286,13 @@ enum sb_version_guess_t guess_sb_version(const char *filename) ret(SB_VERSION_UNK); if(hdr_size == 0x34) ret(SB_VERSION_1); - // check header size (v2) - if(fseek(f, 32, SEEK_SET)) + // check image size (v2) + uint32_t img_size; + if(fseek(f, 28, SEEK_SET)) ret(SB_VERSION_UNK); - if(fread(&hdr_size, 4, 1, f) != 1) + if(fread(&img_size, 4, 1, f) != 1) ret(SB_VERSION_UNK); - if(hdr_size == 0xc) + if(img_size * 16 == (uint32_t)file_size) ret(SB_VERSION_2); ret(SB_VERSION_UNK); #undef ret -- 2.11.4.GIT