[PATCH 5/7] filetype: differentiate between STM32MP FSBL and SSBL images

Ahmad Fatoum a.fatoum at pengutronix.de
Thu Jun 2 02:01:31 PDT 2022


We have some special handling for legacy (non-FIP) STM32 images:
We have a bootm handler for chainloading and an update handler
for use with GPT ssbl partitions. Both aren't applicable to the
TF-A image used as FSBL. As barebox always has 0x00000000 at
offset 0xfc and TF-A alrways has 0x10000000, we can use that
to differentiate between the two images to make sure we refuse
TF-A images when barebox images are expected.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/arm/mach-stm32mp/include/mach/bbu.h |  2 +-
 arch/arm/mach-stm32mp/stm32image.c       |  2 +-
 common/filetype.c                        | 13 ++++++++++---
 include/filetype.h                       |  3 ++-
 4 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-stm32mp/include/mach/bbu.h b/arch/arm/mach-stm32mp/include/mach/bbu.h
index d49fb045ea06..3a6951a8f1a0 100644
--- a/arch/arm/mach-stm32mp/include/mach/bbu.h
+++ b/arch/arm/mach-stm32mp/include/mach/bbu.h
@@ -10,7 +10,7 @@ static inline int stm32mp_bbu_mmc_register_handler(const char *name,
 						   unsigned long flags)
 {
 	return bbu_register_std_file_update(name, flags, devicefile,
-					    filetype_stm32_image_v1);
+					    filetype_stm32_image_ssbl_v1);
 }
 
 #endif /* MACH_STM32MP_BBU_H_ */
diff --git a/arch/arm/mach-stm32mp/stm32image.c b/arch/arm/mach-stm32mp/stm32image.c
index caff68651c47..7867418e6caa 100644
--- a/arch/arm/mach-stm32mp/stm32image.c
+++ b/arch/arm/mach-stm32mp/stm32image.c
@@ -40,7 +40,7 @@ static int do_bootm_stm32image(struct image_data *data)
 static struct image_handler image_handler_stm32_image_v1_handler = {
 	.name = "STM32 image (v1)",
 	.bootm = do_bootm_stm32image,
-	.filetype = filetype_stm32_image_v1,
+	.filetype = filetype_stm32_image_ssbl_v1,
 };
 
 static int stm32mp_register_stm32image_image_handler(void)
diff --git a/common/filetype.c b/common/filetype.c
index 0ded64b83c00..3e9e14c1d79e 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -71,7 +71,8 @@ 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" },
+	[filetype_stm32_image_fsbl_v1] = { "STM32MP FSBL image (v1)", "stm32-fsbl-v1" },
+	[filetype_stm32_image_ssbl_v1] = { "STM32MP SSBL image (v1)", "stm32-ssbl-v1" },
 	[filetype_zynq_image] = { "Zynq image", "zynq-image" },
 	[filetype_mxs_sd_image] = { "i.MX23/28 SD card image", "mxs-sd-image" },
 	[filetype_rockchip_rkns_image] = { "Rockchip boot image", "rk-image" },
@@ -372,8 +373,14 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 		return filetype_unknown;
 
 	if (strncmp(buf8, "STM\x32", 4) == 0) {
-		if (buf8[74] == 0x01)
-			return filetype_stm32_image_v1;
+		if (buf8[74] == 0x01) {
+			switch(le32_to_cpu(buf[63])) {
+			case 0x00000000:
+				return filetype_stm32_image_ssbl_v1;
+			case 0x10000000:
+				return filetype_stm32_image_fsbl_v1;
+			}
+		}
 	}
 
 	if (bufsize < 512)
diff --git a/include/filetype.h b/include/filetype.h
index 9b7499fdf307..00d54e48d528 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -52,7 +52,8 @@ enum filetype {
 	filetype_layerscape_image,
 	filetype_layerscape_qspi_image,
 	filetype_ubootvar,
-	filetype_stm32_image_v1,
+	filetype_stm32_image_fsbl_v1,
+	filetype_stm32_image_ssbl_v1,
 	filetype_zynq_image,
 	filetype_mxs_sd_image,
 	filetype_rockchip_rkns_image,
-- 
2.30.2




More information about the barebox mailing list