Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagn...@jcrosoft.com> --- common/filetype.c | 35 +++++++++++++++++++++++++++++++++++ include/filetype.h | 2 ++ 2 files changed, 37 insertions(+)
diff --git a/common/filetype.c b/common/filetype.c index 8652f1d..16b217b 100644 --- a/common/filetype.c +++ b/common/filetype.c @@ -23,6 +23,7 @@ #include <fs.h> #include <malloc.h> #include <errno.h> +#include <linux/license.h> struct filetype_str { const char *name; /* human readable filetype */ @@ -49,6 +50,8 @@ static const struct filetype_str filetype_str[] = { [filetype_png] = { "PNG image", "png" }, [filetype_ext] = { "ext filesystem", "ext" }, [filetype_gpt] = { "GUID Partition Table", "gpt" }, + [filetype_arm_application] = { "arm barebox application", "arm-barebox-app"}, + [filetype_arm_gpl_application] = { "arm barebox GPL compatible application", "arm-barebox-gpl-app"}, }; const char *file_type_to_string(enum filetype f) @@ -151,6 +154,35 @@ enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec) return filetype_mbr; } +bool is_barebox_app_gpl_compatible(const uint8_t *buf8, size_t bufsize) +{ + int i; + + if (bufsize < 12) + return false; + + bufsize -= 12; + + for (i = 0; i < bufsize; i++, buf8++) { + if (!strncmp("license=", buf8, 8) && + license_is_gpl_compatible(buf8 + 8)) + return true; + } + + return false; +} + +enum filetype is_barebox_arm_app(const uint8_t *buf8, size_t bufsize) +{ + if (strcmp(buf8 + 0x20, "barebox_arm_app")) + return filetype_unknown; + /* license=GPL */ + if (is_barebox_app_gpl_compatible(buf8 + 0x80, bufsize)) + return filetype_arm_gpl_application; + + return filetype_arm_application; +} + enum filetype file_detect_type(const void *_buf, size_t bufsize) { const u32 *buf = _buf; @@ -201,6 +233,9 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize) if (buf[9] == 0x016f2818 || buf[9] == 0x18286f01) return filetype_arm_zimage; + type = is_barebox_arm_app(buf8, bufsize); + if (type != filetype_unknown) + return type; if (bufsize < 512) return filetype_unknown; diff --git a/include/filetype.h b/include/filetype.h index 78ca5d2..09cdc99 100644 --- a/include/filetype.h +++ b/include/filetype.h @@ -24,6 +24,8 @@ enum filetype { filetype_png, filetype_ext, filetype_gpt, + filetype_arm_application, + filetype_arm_gpl_application, filetype_max, }; -- 1.7.10.4 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox