diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2012-11-27 22:16:56 +0100 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2012-11-27 22:16:56 +0100 |
commit | 7dc3e939d2cd0a39035587f211587167eb6671de (patch) | |
tree | 8e932df28e865b66988c2e13cbed222f9347708e /utils/imxtools/sbtools/sbtoelf.c | |
parent | 9716d1f1f964a29c5087a2861e2b94afd140dcbb (diff) | |
download | rockbox-7dc3e939d2cd0a39035587f211587167eb6671de.tar.gz rockbox-7dc3e939d2cd0a39035587f211587167eb6671de.zip |
sbtoelf: implement sb1 loading and dumping
Implement actual loading of a sb1 file to a structure in full
generality. Also implement dumping for debug purpose
Change-Id: I320035ea628719480a79aaccb05dce9a83256927
Diffstat (limited to 'utils/imxtools/sbtools/sbtoelf.c')
-rw-r--r-- | utils/imxtools/sbtools/sbtoelf.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/utils/imxtools/sbtools/sbtoelf.c b/utils/imxtools/sbtools/sbtoelf.c index 0445c4a366..01a51cae90 100644 --- a/utils/imxtools/sbtools/sbtoelf.c +++ b/utils/imxtools/sbtools/sbtoelf.c | |||
@@ -162,7 +162,6 @@ static void extract_sb1_file(struct sb1_file_t *file) | |||
162 | FILE *f = fopen(g_out_prefix, "wb"); | 162 | FILE *f = fopen(g_out_prefix, "wb"); |
163 | if(f == NULL) | 163 | if(f == NULL) |
164 | bugp("Cannot open %s for writing\n", g_out_prefix); | 164 | bugp("Cannot open %s for writing\n", g_out_prefix); |
165 | fwrite(file->data, file->data_size, 1, f); | ||
166 | fclose(f); | 165 | fclose(f); |
167 | } | 166 | } |
168 | 167 | ||
@@ -228,33 +227,35 @@ enum sb_version_guess_t | |||
228 | 227 | ||
229 | enum sb_version_guess_t guess_sb_version(const char *filename) | 228 | enum sb_version_guess_t guess_sb_version(const char *filename) |
230 | { | 229 | { |
230 | #define ret(x) do { fclose(f); return x; } while(0) | ||
231 | FILE *f = fopen(filename, "rb"); | 231 | FILE *f = fopen(filename, "rb"); |
232 | if(f == NULL) | 232 | if(f == NULL) |
233 | bugp("Cannot open file for reading\n"); | 233 | bugp("Cannot open file for reading\n"); |
234 | // check signature | 234 | // check signature |
235 | uint8_t sig[4]; | 235 | uint8_t sig[4]; |
236 | if(fseek(f, 20, SEEK_SET)) | 236 | if(fseek(f, 20, SEEK_SET)) |
237 | return SB_VERSION_UNK; | 237 | ret(SB_VERSION_UNK); |
238 | if(fread(sig, 4, 1, f) != 1) | 238 | if(fread(sig, 4, 1, f) != 1) |
239 | return SB_VERSION_UNK; | 239 | ret(SB_VERSION_UNK); |
240 | if(memcmp(sig, "STMP", 4) != 0) | 240 | if(memcmp(sig, "STMP", 4) != 0) |
241 | return SB_VERSION_UNK; | 241 | ret(SB_VERSION_UNK); |
242 | // check header size (v1) | 242 | // check header size (v1) |
243 | uint32_t hdr_size; | 243 | uint32_t hdr_size; |
244 | if(fseek(f, 8, SEEK_SET)) | 244 | if(fseek(f, 8, SEEK_SET)) |
245 | return SB_VERSION_UNK; | 245 | ret(SB_VERSION_UNK); |
246 | if(fread(&hdr_size, 4, 1, f) != 1) | 246 | if(fread(&hdr_size, 4, 1, f) != 1) |
247 | return SB_VERSION_UNK; | 247 | ret(SB_VERSION_UNK); |
248 | if(hdr_size == 0x34) | 248 | if(hdr_size == 0x34) |
249 | return SB_VERSION_1; | 249 | ret(SB_VERSION_1); |
250 | // check header size (v2) | 250 | // check header size (v2) |
251 | if(fseek(f, 32, SEEK_SET)) | 251 | if(fseek(f, 32, SEEK_SET)) |
252 | return SB_VERSION_UNK; | 252 | ret(SB_VERSION_UNK); |
253 | if(fread(&hdr_size, 4, 1, f) != 1) | 253 | if(fread(&hdr_size, 4, 1, f) != 1) |
254 | return SB_VERSION_UNK; | 254 | ret(SB_VERSION_UNK); |
255 | if(hdr_size == 0xc) | 255 | if(hdr_size == 0xc) |
256 | return SB_VERSION_2; | 256 | ret(SB_VERSION_2); |
257 | return SB_VERSION_UNK; | 257 | ret(SB_VERSION_UNK); |
258 | #undef ret | ||
258 | } | 259 | } |
259 | 260 | ||
260 | int main(int argc, char **argv) | 261 | int main(int argc, char **argv) |