summaryrefslogtreecommitdiffstats
path: root/common/filetype.c
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2019-07-12 12:24:55 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-07-15 08:46:12 +0200
commit0e3d00a70de6412c9543d09445de59900b93e25e (patch)
tree3163faf6b981c2ae1c4df0123d83e57a268d060f /common/filetype.c
parent464de25d425a0949b066b0aacf872b2a48e682af (diff)
downloadbarebox-0e3d00a70de6412c9543d09445de59900b93e25e.tar.gz
barebox-0e3d00a70de6412c9543d09445de59900b93e25e.tar.xz
filetype: add STM32 image type
Both STM32MP BootROM and TF-A first stage expect subsequent bootloader stages to feature a specific 256-byte long STM32 file header. Add detection of the header to file_detect_type(). While there's only one version of the header so far, identify the new header as v1 anyway, so new versions can be unambiguously added. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/filetype.c')
-rw-r--r--common/filetype.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/common/filetype.c b/common/filetype.c
index 329f5144bf..825bf25ad1 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -79,6 +79,7 @@ static const struct filetype_str filetype_str[] = {
[filetype_layerscape_qspi_image] = { "Layerscape QSPI image", "layerscape-qspi-PBL" },
[filetype_ubootvar] = { "U-Boot environmemnt variable data",
"ubootvar" },
+ [filetype_stm32_image_v1] = { "STM32 image (v1)", "stm32-image-v1" },
};
const char *file_type_to_string(enum filetype f)
@@ -355,6 +356,14 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
if (buf8[0] == 'M' && buf8[1] == 'Z')
return filetype_exe;
+ if (bufsize < 256)
+ return filetype_unknown;
+
+ if (strncmp(buf8, "STM\x32", 4) == 0) {
+ if (buf8[74] == 0x01)
+ return filetype_stm32_image_v1;
+ }
+
if (bufsize < 512)
return filetype_unknown;