diff --git a/common/filetype.c b/common/filetype.c index 5941ad2..22fc621 100644 --- a/common/filetype.c +++ b/common/filetype.c @@ -145,7 +145,7 @@ return filetype_aimage; if (buf64[0] == le64_to_cpu(0x0a1a0a0d474e5089ull)) return filetype_png; - if (strncmp(buf8 + 0x10, "barebox", 7) == 0) + if (is_barebox_mips_head(_buf)) return filetype_mips_barebox; if (bufsize < 64) diff --git a/include/filetype.h b/include/filetype.h index 502b920..3b0715f 100644 --- a/include/filetype.h +++ b/include/filetype.h @@ -50,4 +50,20 @@ } #endif +#define MIPS_HEAD_SIZE 0x20 +#define MIPS_HEAD_MAGICWORD_OFFSET 0x10 +#define MIPS_HEAD_SIZE_OFFSET 0x1C + +#ifdef CONFIG_MIPS +static inline int is_barebox_mips_head(const char *head) +{ + return !strcmp(head + MIPS_HEAD_MAGICWORD_OFFSET, "barebox"); +} +#else +static inline int is_barebox_mips_head(const char *head) +{ + return 0; +} +#endif + #endif /* __FILE_TYPE_H */