* [PATCH 0/7] ARM: add support for chainloading barebox inside FIP images
@ 2025-04-09 14:01 Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 1/7] fip: add struct fip_image_desc::private_data Ahmad Fatoum
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: Ahmad Fatoum @ 2025-04-09 14:01 UTC (permalink / raw)
To: barebox
For use on the STM32MP1, add a bootm handler for chainloading FIP
images. This removes the last remaining use case for SSBL .stm32 images,
after TF-A had dropped support late 2022.
Ahmad Fatoum (7):
fip: add struct fip_image_desc::private_data
fip: mark predefined toc_entries array const
bootm: implement UIMAGE_IS_ADDRESS_VALID helper
ARM: legacy: make architecture number unsigned
ARM: introduce jump_to_linux helper
ARM: add support for chainloading barebox inside FIP images
ARM: stm32mp: retire non-FIP stm32mp_bbu_mmc_register_handler
arch/arm/Kconfig | 11 +
arch/arm/boards/lxa-mc1/board.c | 4 +-
.../boards/phytec-phycore-stm32mp1/board.c | 2 +-
arch/arm/boards/protonic-stm32mp1/board.c | 16 +-
arch/arm/boards/protonic-stm32mp13/board.c | 16 +-
arch/arm/boards/seeed-odyssey/board.c | 4 +-
arch/arm/boards/stm32mp15x-ev1/board.c | 4 +-
arch/arm/boards/stm32mp15xx-dkx/board.c | 4 +-
arch/arm/cpu/Makefile | 1 +
arch/arm/cpu/bootm-fip.c | 276 ++++++++++++++++++
arch/arm/include/asm/armlinux.h | 4 +-
arch/arm/include/asm/boot.h | 28 ++
arch/arm/lib32/armlinux.c | 24 +-
arch/arm/lib64/armlinux.c | 12 +-
arch/arm/mach-stm32mp/init.c | 10 +
commands/fiptool.c | 4 +-
common/booti.c | 3 +-
include/bootm.h | 3 +
include/bootstrap.h | 2 +-
include/fiptool.h | 18 +-
include/mach/stm32mp/bbu.h | 8 -
lib/fip.c | 2 +-
lib/tbbr_config.c | 4 +-
23 files changed, 399 insertions(+), 61 deletions(-)
create mode 100644 arch/arm/cpu/bootm-fip.c
create mode 100644 arch/arm/include/asm/boot.h
--
2.39.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/7] fip: add struct fip_image_desc::private_data
2025-04-09 14:01 [PATCH 0/7] ARM: add support for chainloading barebox inside FIP images Ahmad Fatoum
@ 2025-04-09 14:01 ` Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 2/7] fip: mark predefined toc_entries array const Ahmad Fatoum
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Ahmad Fatoum @ 2025-04-09 14:01 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
For use by FIP consumer code, add a private data field that can be
assigned as the consumer wishes.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/fiptool.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/fiptool.h b/include/fiptool.h
index 73b0fbe3983a..1b70824a8694 100644
--- a/include/fiptool.h
+++ b/include/fiptool.h
@@ -23,6 +23,7 @@ struct fip_image_desc {
char *cmdline_name;
int action;
char *action_arg;
+ void *private_data;
struct fip_image *image;
struct list_head list;
};
--
2.39.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/7] fip: mark predefined toc_entries array const
2025-04-09 14:01 [PATCH 0/7] ARM: add support for chainloading barebox inside FIP images Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 1/7] fip: add struct fip_image_desc::private_data Ahmad Fatoum
@ 2025-04-09 14:01 ` Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 3/7] bootm: implement UIMAGE_IS_ADDRESS_VALID helper Ahmad Fatoum
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Ahmad Fatoum @ 2025-04-09 14:01 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
There is no use case for modifying these mapping structure used by the
fiptool command, so mark them appropriately.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/fiptool.c | 4 ++--
include/fiptool.h | 4 ++--
lib/fip.c | 2 +-
lib/tbbr_config.c | 4 ++--
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/commands/fiptool.c b/commands/fiptool.c
index 46b5ed29c317..ccf99491bf66 100644
--- a/commands/fiptool.c
+++ b/commands/fiptool.c
@@ -115,9 +115,9 @@ static int info_cmd(struct fip_state *fip, int argc, char *argv[])
static int uuid_cmd(struct fip_state *fip, int argc, char *argv[])
{
- for (toc_entry_t *t = toc_entries; t->cmdline_name != NULL; t++)
+ for (const toc_entry_t *t = toc_entries; t->cmdline_name != NULL; t++)
printf("%pU\t%-16s\t%s\n", &t->uuid, t->cmdline_name, t->name);
- for (toc_entry_t *t = plat_def_toc_entries; t->cmdline_name != NULL; t++)
+ for (const toc_entry_t *t = plat_def_toc_entries; t->cmdline_name != NULL; t++)
printf("%pU\t%-16s\t%s\n", &t->uuid, t->cmdline_name, t->name);
return 0;
}
diff --git a/include/fiptool.h b/include/fiptool.h
index 1b70824a8694..1a0dbe0e6975 100644
--- a/include/fiptool.h
+++ b/include/fiptool.h
@@ -91,8 +91,8 @@ typedef struct toc_entry {
char *cmdline_name;
} toc_entry_t;
-extern toc_entry_t toc_entries[];
-extern toc_entry_t plat_def_toc_entries[];
+extern const toc_entry_t toc_entries[];
+extern const toc_entry_t plat_def_toc_entries[];
#define fip_for_each_desc(fip, e) \
list_for_each_entry(e, &(fip)->descs, list)
diff --git a/lib/fip.c b/lib/fip.c
index f3754bdc29af..9470aa5d3398 100644
--- a/lib/fip.c
+++ b/lib/fip.c
@@ -105,7 +105,7 @@ void fip_free(struct fip_state *fip)
void fip_fill_image_descs(struct fip_state *fip)
{
- toc_entry_t *toc_entry;
+ const toc_entry_t *toc_entry;
for (toc_entry = toc_entries;
toc_entry->cmdline_name != NULL;
diff --git a/lib/tbbr_config.c b/lib/tbbr_config.c
index 3d777e5648a9..9e5f51029beb 100644
--- a/lib/tbbr_config.c
+++ b/lib/tbbr_config.c
@@ -5,7 +5,7 @@
#include <fiptool.h>
/* The images used depends on the platform. */
-toc_entry_t toc_entries[] = {
+const toc_entry_t toc_entries[] = {
{
.name = "SCP Firmware Updater Configuration FWU SCP_BL2U",
.uuid = UUID_TRUSTED_UPDATE_FIRMWARE_SCP_BL2U,
@@ -187,7 +187,7 @@ toc_entry_t toc_entries[] = {
}
};
-toc_entry_t plat_def_toc_entries[] = {
+const toc_entry_t plat_def_toc_entries[] = {
#ifdef CONFIG_ARCH_STM32MP
{
.name = "STM32MP CONFIG CERT",
--
2.39.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/7] bootm: implement UIMAGE_IS_ADDRESS_VALID helper
2025-04-09 14:01 [PATCH 0/7] ARM: add support for chainloading barebox inside FIP images Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 1/7] fip: add struct fip_image_desc::private_data Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 2/7] fip: mark predefined toc_entries array const Ahmad Fatoum
@ 2025-04-09 14:01 ` Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 4/7] ARM: legacy: make architecture number unsigned Ahmad Fatoum
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Ahmad Fatoum @ 2025-04-09 14:01 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Instead of open-coding the comparison against the two magic UIMAGE_
constants, introduce a UIMAGE_IS_ADDRESS_VALID helper.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/booti.c | 3 +--
include/bootm.h | 3 +++
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/common/booti.c b/common/booti.c
index c8f6b5d4fc6d..40611b8f7228 100644
--- a/common/booti.c
+++ b/common/booti.c
@@ -15,8 +15,7 @@ static unsigned long get_kernel_address(unsigned long os_address,
resource_size_t start, end;
int ret;
- if (os_address == UIMAGE_SOME_ADDRESS ||
- os_address == UIMAGE_INVALID_ADDRESS) {
+ if (!UIMAGE_IS_ADDRESS_VALID(os_address)) {
ret = memory_bank_first_find_space(&start, &end);
if (ret)
return UIMAGE_INVALID_ADDRESS;
diff --git a/include/bootm.h b/include/bootm.h
index bc6c69e8134d..b35deb25bf8f 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -154,6 +154,9 @@ bool bootm_signed_images_are_forced(void);
void bootm_force_signed_images(void);
#define UIMAGE_SOME_ADDRESS (UIMAGE_INVALID_ADDRESS - 1)
+#define UIMAGE_IS_ADDRESS_VALID(addr) \
+ ((addr) != UIMAGE_INVALID_ADDRESS && \
+ (addr) != UIMAGE_SOME_ADDRESS)
void *booti_load_image(struct image_data *data, phys_addr_t *oftree);
--
2.39.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 4/7] ARM: legacy: make architecture number unsigned
2025-04-09 14:01 [PATCH 0/7] ARM: add support for chainloading barebox inside FIP images Ahmad Fatoum
` (2 preceding siblings ...)
2025-04-09 14:01 ` [PATCH 3/7] bootm: implement UIMAGE_IS_ADDRESS_VALID helper Ahmad Fatoum
@ 2025-04-09 14:01 ` Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 5/7] ARM: introduce jump_to_linux helper Ahmad Fatoum
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Ahmad Fatoum @ 2025-04-09 14:01 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The number is effectively unsigned, but we have some places where we
still use int. Switch it over to use unsigned throughout.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/include/asm/armlinux.h | 4 ++--
arch/arm/lib32/armlinux.c | 12 ++++++------
include/bootstrap.h | 2 +-
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/arch/arm/include/asm/armlinux.h b/arch/arm/include/asm/armlinux.h
index 8d8e05105b08..c648ef3d78d0 100644
--- a/arch/arm/include/asm/armlinux.h
+++ b/arch/arm/include/asm/armlinux.h
@@ -9,7 +9,7 @@
#if defined CONFIG_ARM_LINUX && defined CONFIG_CPU_32
void armlinux_set_bootparams(void *params);
-void armlinux_set_architecture(int architecture);
+void armlinux_set_architecture(unsigned architecture);
void armlinux_set_revision(unsigned int);
void armlinux_set_serial(u64);
#else
@@ -17,7 +17,7 @@ static inline void armlinux_set_bootparams(void *params)
{
}
-static inline void armlinux_set_architecture(int architecture)
+static inline void armlinux_set_architecture(unsigned architecture)
{
}
diff --git a/arch/arm/lib32/armlinux.c b/arch/arm/lib32/armlinux.c
index eb30f4a952ee..0b332d23639d 100644
--- a/arch/arm/lib32/armlinux.c
+++ b/arch/arm/lib32/armlinux.c
@@ -30,7 +30,7 @@
static struct tag *params;
static void *armlinux_bootparams = NULL;
-static int armlinux_architecture;
+static unsigned armlinux_architecture;
static u32 armlinux_system_rev;
static u64 armlinux_system_serial;
@@ -38,13 +38,13 @@ BAREBOX_MAGICVAR(armlinux_architecture, "ARM machine ID");
BAREBOX_MAGICVAR(armlinux_system_rev, "ARM system revision");
BAREBOX_MAGICVAR(armlinux_system_serial, "ARM system serial");
-void armlinux_set_architecture(int architecture)
+void armlinux_set_architecture(unsigned architecture)
{
export_env_ull("armlinux_architecture", architecture);
armlinux_architecture = architecture;
}
-static int armlinux_get_architecture(void)
+static unsigned armlinux_get_architecture(void)
{
getenv_uint("armlinux_architecture", &armlinux_architecture);
@@ -241,7 +241,7 @@ static void setup_tags(unsigned long initrd_address,
setup_end_tag();
printf("commandline: %s\n"
- "arch_number: %d\n", commandline, armlinux_get_architecture());
+ "arch_number: %u\n", commandline, armlinux_get_architecture());
}
@@ -251,9 +251,9 @@ void start_linux(void *adr, int swap, unsigned long initrd_address,
unsigned long initrd_size, void *oftree,
enum arm_security_state state, void *optee)
{
- void (*kernel)(int zero, int arch, void *params) = adr;
+ void (*kernel)(int zero, unsigned arch, void *params) = adr;
void *params = NULL;
- int architecture;
+ unsigned architecture;
int ret;
if (IS_ENABLED(CONFIG_ARM_SECURE_MONITOR) && state > ARM_STATE_SECURE) {
diff --git a/include/bootstrap.h b/include/bootstrap.h
index 3e006d3cc9f7..801cbeb3da4b 100644
--- a/include/bootstrap.h
+++ b/include/bootstrap.h
@@ -10,7 +10,7 @@
#define bootstrap_err(fmt, arg...) printf(fmt, ##arg)
-typedef void (*kernel_entry_func)(int zero, int arch, void *params);
+typedef void (*kernel_entry_func)(int zero, unsigned arch, void *params);
void bootstrap_boot(kernel_entry_func func, bool barebox);
#ifdef CONFIG_BOOTSTRAP_DEVFS
--
2.39.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 5/7] ARM: introduce jump_to_linux helper
2025-04-09 14:01 [PATCH 0/7] ARM: add support for chainloading barebox inside FIP images Ahmad Fatoum
` (3 preceding siblings ...)
2025-04-09 14:01 ` [PATCH 4/7] ARM: legacy: make architecture number unsigned Ahmad Fatoum
@ 2025-04-09 14:01 ` Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 6/7] ARM: add support for chainloading barebox inside FIP images Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 7/7] ARM: stm32mp: retire non-FIP stm32mp_bbu_mmc_register_handler Ahmad Fatoum
6 siblings, 0 replies; 8+ messages in thread
From: Ahmad Fatoum @ 2025-04-09 14:01 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
The upcoming FIP bootm handler should be usable on both ARM32 and ARM64
and thus we need an arch-independent way of booting a kernel with a
given device tree.
Introduce a jump_to_linux helper in <asm/boot.h> for this purpose.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/include/asm/boot.h | 28 ++++++++++++++++++++++++++++
arch/arm/lib32/armlinux.c | 14 +++++++-------
arch/arm/lib64/armlinux.c | 12 ++++++------
3 files changed, 41 insertions(+), 13 deletions(-)
create mode 100644 arch/arm/include/asm/boot.h
diff --git a/arch/arm/include/asm/boot.h b/arch/arm/include/asm/boot.h
new file mode 100644
index 000000000000..a75d139ed8ea
--- /dev/null
+++ b/arch/arm/include/asm/boot.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _ASM_BOOT_H_
+#define _ASM_BOOT_H_
+
+#include <linux/types.h>
+
+#ifdef CONFIG_ARM64
+static inline void jump_to_linux(const void *_kernel, phys_addr_t dtb)
+{
+ void (*kernel)(unsigned long dtb, unsigned long x1, unsigned long x2,
+ unsigned long x3) = _kernel;
+ kernel(dtb, 0, 0, 0);
+}
+#else
+static inline void __jump_to_linux(const void *_kernel, unsigned arch,
+ phys_addr_t params)
+{
+ void (*kernel)(int zero, unsigned arch, ulong params) = _kernel;
+ kernel(0, arch, params);
+}
+static inline void jump_to_linux(const void *_kernel, phys_addr_t dtb)
+{
+ __jump_to_linux(_kernel, ~0, dtb);
+}
+#endif
+
+#endif /* _ASM_BOOT_H_ */
diff --git a/arch/arm/lib32/armlinux.c b/arch/arm/lib32/armlinux.c
index 0b332d23639d..56f278d3dbae 100644
--- a/arch/arm/lib32/armlinux.c
+++ b/arch/arm/lib32/armlinux.c
@@ -26,6 +26,7 @@
#include <asm/armlinux.h>
#include <asm/system.h>
#include <asm/secure.h>
+#include <asm/boot.h>
static struct tag *params;
static void *armlinux_bootparams = NULL;
@@ -251,8 +252,7 @@ void start_linux(void *adr, int swap, unsigned long initrd_address,
unsigned long initrd_size, void *oftree,
enum arm_security_state state, void *optee)
{
- void (*kernel)(int zero, unsigned arch, void *params) = adr;
- void *params = NULL;
+ phys_addr_t params = 0;
unsigned architecture;
int ret;
@@ -264,11 +264,11 @@ void start_linux(void *adr, int swap, unsigned long initrd_address,
if (oftree) {
pr_debug("booting kernel with devicetree\n");
- params = oftree;
+ params = virt_to_phys(oftree);
} else {
- params = armlinux_get_bootparams();
+ params = virt_to_phys(armlinux_get_bootparams());
- if ((unsigned long)params < PAGE_SIZE)
+ if (params < PAGE_SIZE)
zero_page_access();
setup_tags(initrd_address, initrd_size, swap);
@@ -288,8 +288,8 @@ void start_linux(void *adr, int swap, unsigned long initrd_address,
}
if (optee && IS_ENABLED(CONFIG_BOOTM_OPTEE)) {
- start_kernel_optee(optee, kernel, oftree);
+ start_kernel_optee(optee, adr, oftree);
} else {
- kernel(0, architecture, params);
+ __jump_to_linux(adr, architecture, params);
}
}
diff --git a/arch/arm/lib64/armlinux.c b/arch/arm/lib64/armlinux.c
index 5feee9c24f2a..13721a71236b 100644
--- a/arch/arm/lib64/armlinux.c
+++ b/arch/arm/lib64/armlinux.c
@@ -5,18 +5,18 @@
#include <memory.h>
#include <init.h>
#include <bootm.h>
+#include <asm/boot.h>
#include <efi/efi-mode.h>
static int do_bootm_linux(struct image_data *data)
{
- void (*fn)(unsigned long dtb, unsigned long x1, unsigned long x2,
- unsigned long x3);
+ void *image;
phys_addr_t devicetree;
int ret;
- fn = booti_load_image(data, &devicetree);
- if (IS_ERR(fn))
- return PTR_ERR(fn);
+ image = booti_load_image(data, &devicetree);
+ if (IS_ERR(image))
+ return PTR_ERR(image);
if (data->dryrun)
return 0;
@@ -27,7 +27,7 @@ static int do_bootm_linux(struct image_data *data)
shutdown_barebox();
- fn(devicetree, 0, 0, 0);
+ jump_to_linux(image, devicetree);
return -EINVAL;
}
--
2.39.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 6/7] ARM: add support for chainloading barebox inside FIP images
2025-04-09 14:01 [PATCH 0/7] ARM: add support for chainloading barebox inside FIP images Ahmad Fatoum
` (4 preceding siblings ...)
2025-04-09 14:01 ` [PATCH 5/7] ARM: introduce jump_to_linux helper Ahmad Fatoum
@ 2025-04-09 14:01 ` Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 7/7] ARM: stm32mp: retire non-FIP stm32mp_bbu_mmc_register_handler Ahmad Fatoum
6 siblings, 0 replies; 8+ messages in thread
From: Ahmad Fatoum @ 2025-04-09 14:01 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
For use on the STM32MP1, add a bootm handler for chainloading FIP
images. This removes the last remaining use case for SSBL .stm32 images,
after TF-A had dropped support late 2022.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/Kconfig | 11 ++
arch/arm/cpu/Makefile | 1 +
arch/arm/cpu/bootm-fip.c | 276 +++++++++++++++++++++++++++++++++++
arch/arm/mach-stm32mp/init.c | 10 ++
include/fiptool.h | 13 ++
5 files changed, 311 insertions(+)
create mode 100644 arch/arm/cpu/bootm-fip.c
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index ab7ff5369b20..84b1660d1ed9 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -473,6 +473,17 @@ config ARM_BOOTM_ELF
help
Add support to load elf file with bootm.
+config ARM_BOOTM_FIP
+ bool
+ depends on BOOTM
+ select FIP
+ prompt "FIP loading support"
+ default ARCH_STM32MP
+ help
+ Add support to load FIP file with bootm.
+ This allows barebox to chainload barebox on platforms where it
+ is located inside a FIP. This can be useful during development.
+
config ARM_ATF
bool
diff --git a/arch/arm/cpu/Makefile b/arch/arm/cpu/Makefile
index d59aae1ee55c..39e59c2a2f73 100644
--- a/arch/arm/cpu/Makefile
+++ b/arch/arm/cpu/Makefile
@@ -32,6 +32,7 @@ obj-$(CONFIG_CMD_ARM_CPUINFO) += cpuinfo.o
obj-$(CONFIG_MMUINFO) += mmuinfo.o mmuinfo_$(S64_32).o
obj-$(CONFIG_OFDEVICE) += dtb.o
obj-$(CONFIG_ARM_BOOTM_ELF) += bootm-elf.o
+obj-$(CONFIG_ARM_BOOTM_FIP) += bootm-fip.o
ifeq ($(CONFIG_MMU),)
obj-$(CONFIG_CPU_32v7) += no-mmu.o
diff --git a/arch/arm/cpu/bootm-fip.c b/arch/arm/cpu/bootm-fip.c
new file mode 100644
index 000000000000..89201ade5f12
--- /dev/null
+++ b/arch/arm/cpu/bootm-fip.c
@@ -0,0 +1,276 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#define pr_fmt(fmt) "bootm-fip: " fmt
+
+#include <bootm.h>
+#include <common.h>
+#include <init.h>
+#include <memory.h>
+#include <linux/sizes.h>
+#include <asm/boot.h>
+#include <fip.h>
+#include <libfile.h>
+#include <bootm.h>
+#include <fiptool.h>
+
+const struct fip_binding *fip_bindings;
+
+#define for_each_fip_binding(bindings, binding) \
+ for (binding = bindings; !uuid_is_null(&binding->uuid); binding++)
+
+static inline struct resource *desc_get_res(struct fip_image_desc *desc)
+{
+ return desc->private_data;
+}
+
+static inline void desc_set_res(struct fip_image_desc *desc,
+ struct resource *res)
+{
+ desc->private_data = res;
+}
+
+static int desc_to_sdram(struct fip_image_desc *loadable, ulong load_address)
+{
+ struct resource *res;
+
+ if (desc_get_res(loadable))
+ return 0;
+
+ res = request_sdram_region("fip", load_address,
+ loadable->image->toc_e.size);
+ if (!res)
+ return -EBUSY;
+
+ memcpy((void *)res->start,
+ loadable->image->buffer, loadable->image->toc_e.size);
+
+ desc_set_res(loadable, res);
+
+ return 0;
+}
+
+static void desc_release_sdram(struct fip_image_desc *loadable)
+{
+ struct resource *res = loadable ? desc_get_res(loadable) : NULL;
+ if (res)
+ release_sdram_region(res);
+}
+
+enum { IMAGE_BL33, IMAGE_HW_CONFIG, IMAGE_COUNT };
+
+static int parse_dtb_registry(struct fip_image_desc *fw_config_desc,
+ struct fip_image_desc *loadables[],
+ int verbose)
+{
+ struct fip_toc_entry *toc_entry = &fw_config_desc->image->toc_e;
+ struct device_node *fw_config, *fconf = NULL, *image, *tmp;
+ const struct fip_binding *binding;
+ void *buf;
+ int ret = 0;
+
+ if (!fip_bindings) {
+ if (verbose)
+ printf("Platform registered no FIP bindings. Skipping firmware config\n");
+ return 0;
+ }
+
+ /* We have no alignment guarantees for the buffer, so we need to copy it */
+ buf = xmemdup(fw_config_desc->image->buffer, toc_entry->size);
+
+ fw_config = of_unflatten_dtb(buf, toc_entry->size);
+ if (!IS_ERR(fw_config))
+ fconf = of_find_compatible_node(fw_config, NULL,
+ "fconf,dyn_cfg-dtb_registry");
+ if (!fconf) {
+ pr_warn("error parsing fw_config devicetree\n");
+ goto out;
+ }
+
+ for_each_fip_binding(fip_bindings, binding) {
+ for_each_child_of_node_safe(fconf, tmp, image) {
+ u64 load_addr;
+ u32 id;
+ int ret;
+
+ ret = of_property_read_u32(image, "id", &id);
+ if (ret)
+ continue;
+
+ ret = of_property_read_u64(image, "load-address", &load_addr);
+ if (ret || load_addr > ULONG_MAX)
+ continue;
+
+ if (id != binding->id)
+ continue;
+
+ for (int i = 0; i < IMAGE_COUNT; i++) {
+ struct fip_image_desc *loadable = loadables[i];
+
+ if (!loadable)
+ continue;
+
+ if (!uuid_equal(&binding->uuid,
+ &loadable->image->toc_e.uuid))
+ continue;
+
+ ret = desc_to_sdram(loadable, load_addr);
+ if (ret) {
+ pr_warn("load address 0x%08llx for image ID %u"
+ " conflicts with reservation\n",
+ load_addr, binding->id);
+ goto out;
+ }
+
+ if (verbose > 1)
+ printf("loaded image ID %u to address 0x%08llx\n",
+ binding->id, load_addr);
+ break;
+ }
+
+ /* No need to iterate over this node again, so drop it */
+ of_delete_node(image);
+ }
+ }
+
+out:
+ if (!IS_ERR(fw_config))
+ of_delete_node(fw_config);
+ free(buf);
+ return ret;
+}
+
+static int fip_load(struct image_data *data,
+ struct fip_image_desc *fw_config_desc,
+ struct fip_image_desc *loadables[])
+{
+ resource_size_t start, end;
+ int ret;
+
+ if (UIMAGE_IS_ADDRESS_VALID(data->os_address)) {
+ ret = desc_to_sdram(loadables[IMAGE_BL33], data->os_address);
+ if (ret)
+ return ret;
+ }
+
+ if (fw_config_desc) {
+ ret = parse_dtb_registry(fw_config_desc, loadables, data->verbose);
+ if (ret)
+ return ret;
+ }
+
+ ret = memory_bank_first_find_space(&start, &end);
+ if (ret)
+ return ret;
+
+ for (int i = 0; i < IMAGE_COUNT; i++) {
+ struct fip_image_desc *loadable = loadables[i];
+
+ if (!loadable || desc_get_res(loadable))
+ continue;
+
+ start = ALIGN(start, SZ_4K);
+
+ ret = desc_to_sdram(loadable, start);
+ if (ret)
+ return ret;
+
+ /* Leave a stack's worth of space after each artifact;
+ * The STM32MP1 barebox entry point depends on it.
+ */
+ start += resource_size(desc_get_res(loadable));
+ start += CONFIG_STACK_SIZE;
+ start = ALIGN(start, 16);
+ }
+
+ return 0;
+}
+
+static const uuid_t uuid_bl33 = UUID_NON_TRUSTED_FIRMWARE_BL33;
+static const uuid_t uuid_hwconfig = UUID_HW_CONFIG;
+static const uuid_t uuid_fwconfig = UUID_FW_CONFIG;
+
+static int do_bootm_fip(struct image_data *data)
+{
+ struct fip_image_desc *fwconfig = NULL;
+ struct fip_image_desc *loadables[IMAGE_COUNT] = {};
+ struct fip_image_desc *desc;
+ struct fip_state *fip;
+ int ret;
+
+ if (!data->os_file)
+ return -EINVAL;
+
+ fip = fip_new();
+ ret = fip_parse(fip, data->os_file, NULL);
+ if (ret)
+ goto out;
+
+ fip_for_each_desc(fip, desc) {
+ struct fip_toc_entry *toc_entry = &desc->image->toc_e;
+
+ if (uuid_equal(&toc_entry->uuid, &uuid_bl33))
+ loadables[IMAGE_BL33] = desc;
+ else if (uuid_equal(&toc_entry->uuid, &uuid_hwconfig))
+ loadables[IMAGE_HW_CONFIG] = desc;
+ else if (uuid_equal(&toc_entry->uuid, &uuid_fwconfig))
+ fwconfig = desc;
+ }
+
+ if (!loadables[IMAGE_BL33]) {
+ pr_err("FIP is missing BL33 image to chainload\n");
+ ret = -ENOENT;
+ goto out;
+ }
+
+ ret = fip_load(data, fwconfig, loadables);
+ if (ret)
+ goto out;
+
+ if (data->verbose) {
+ printf("Loaded non-trusted firmware to 0x%08lx",
+ (ulong)desc_get_res(loadables[IMAGE_BL33])->start);
+ if (loadables[IMAGE_HW_CONFIG])
+ printf(", hardware config to 0x%08lx",
+ (ulong)desc_get_res(loadables[IMAGE_HW_CONFIG])->start);
+ printf("\n");
+ }
+
+ if (data->dryrun) {
+ ret = 0;
+ goto out;
+ }
+
+ shutdown_barebox();
+
+ /* We don't actually expect NT FW to be a Linux image, but
+ * we want to use the Linux boot calling convention
+ */
+ jump_to_linux((void *)desc_get_res(loadables[IMAGE_BL33])->start,
+ desc_get_res(loadables[IMAGE_HW_CONFIG])->start);
+
+ ret = -EIO;
+out:
+ for (int i = 0; i < IMAGE_COUNT; i++)
+ desc_release_sdram(loadables[i]);
+
+ if (fip)
+ fip_free(fip);
+ return ret;
+}
+
+void plat_set_fip_bindings(const struct fip_binding *bindings)
+{
+ fip_bindings = bindings;
+}
+
+struct image_handler fip_image_handler = {
+ .name = "FIP",
+ .bootm = do_bootm_fip,
+ .filetype = filetype_fip,
+};
+
+static int stm32mp_register_fip_bootm_handler(void)
+{
+ return register_image_handler(&fip_image_handler);
+}
+late_initcall(stm32mp_register_fip_bootm_handler);
diff --git a/arch/arm/mach-stm32mp/init.c b/arch/arm/mach-stm32mp/init.c
index 1c7f62dbb033..422218e18e5a 100644
--- a/arch/arm/mach-stm32mp/init.c
+++ b/arch/arm/mach-stm32mp/init.c
@@ -13,6 +13,7 @@
#include <mach/stm32mp/revision.h>
#include <mach/stm32mp/bootsource.h>
#include <bootsource.h>
+#include <fiptool.h>
#include <dt-bindings/pinctrl/stm32-pinfunc.h>
/* Package = bit 27:29 of OTP16
@@ -236,6 +237,13 @@ unsigned stm32mp_soc_code(void)
return __st32mp_soc;
}
+static const struct fip_binding stm32mp_fip_handler[] = {
+ { 1, UUID_FW_CONFIG },
+ { 2, UUID_HW_CONFIG },
+ { 5, UUID_NON_TRUSTED_FIRMWARE_BL33 },
+ { /* sentinel */ }
+};
+
static int stm32mp_init(void)
{
u32 boot_ctx;
@@ -264,6 +272,8 @@ static int stm32mp_init(void)
setup_boot_mode(boot_ctx);
+ plat_set_fip_bindings(stm32mp_fip_handler);
+
return 0;
}
postcore_initcall(stm32mp_init);
diff --git a/include/fiptool.h b/include/fiptool.h
index 1a0dbe0e6975..8cb1f7d3959d 100644
--- a/include/fiptool.h
+++ b/include/fiptool.h
@@ -104,4 +104,17 @@ struct fip_state *fip_image_open(const char *filename, size_t offset);
int fip_sha256(struct fip_state *fip, char *hash);
+struct fip_binding {
+ unsigned id;
+ uuid_t uuid;
+};
+
+#ifdef CONFIG_ARM_BOOTM_FIP
+void plat_set_fip_bindings(const struct fip_binding *bindings);
+#else
+static inline void plat_set_fip_bindings(const struct fip_binding *bindings)
+{
+}
+#endif
+
#endif /* FIPTOOL_H */
--
2.39.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 7/7] ARM: stm32mp: retire non-FIP stm32mp_bbu_mmc_register_handler
2025-04-09 14:01 [PATCH 0/7] ARM: add support for chainloading barebox inside FIP images Ahmad Fatoum
` (5 preceding siblings ...)
2025-04-09 14:01 ` [PATCH 6/7] ARM: add support for chainloading barebox inside FIP images Ahmad Fatoum
@ 2025-04-09 14:01 ` Ahmad Fatoum
6 siblings, 0 replies; 8+ messages in thread
From: Ahmad Fatoum @ 2025-04-09 14:01 UTC (permalink / raw)
To: barebox; +Cc: Robin van der Gracht, Ahmad Fatoum
FIP images have been the only supported SSBL format by TF-A for more
2.5 years now.
In preparation for dropping support for the old SSBL format with STM32
header, switch all update handlers to operate on FIP images instead.
The handler will automatically look for a fip GPT partition on SD.
Cc: Robin van der Gracht <robin@protonic.nl>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/boards/lxa-mc1/board.c | 4 ++--
arch/arm/boards/phytec-phycore-stm32mp1/board.c | 2 +-
arch/arm/boards/protonic-stm32mp1/board.c | 16 +++++++++-------
arch/arm/boards/protonic-stm32mp13/board.c | 16 +++++++++-------
arch/arm/boards/seeed-odyssey/board.c | 4 ++--
arch/arm/boards/stm32mp15x-ev1/board.c | 4 ++--
arch/arm/boards/stm32mp15xx-dkx/board.c | 4 ++--
include/mach/stm32mp/bbu.h | 8 --------
8 files changed, 27 insertions(+), 31 deletions(-)
diff --git a/arch/arm/boards/lxa-mc1/board.c b/arch/arm/boards/lxa-mc1/board.c
index 8be265b0fca0..0071a10a4696 100644
--- a/arch/arm/boards/lxa-mc1/board.c
+++ b/arch/arm/boards/lxa-mc1/board.c
@@ -35,10 +35,10 @@ static int mc1_probe(struct device *dev)
int flags;
flags = bootsource_get_instance() == 0 ? BBU_HANDLER_FLAG_DEFAULT : 0;
- stm32mp_bbu_mmc_register_handler("sd", "/dev/mmc0.ssbl", flags);
+ stm32mp_bbu_mmc_fip_register("sd", "/dev/mmc0", flags);
flags = bootsource_get_instance() == 1 ? BBU_HANDLER_FLAG_DEFAULT : 0;
- stm32mp_bbu_mmc_register_handler("emmc", "/dev/mmc1.ssbl", flags);
+ stm32mp_bbu_mmc_fip_register("emmc", "/dev/mmc1", flags);
if (bootsource_get_instance() == 0) {
diff --git a/arch/arm/boards/phytec-phycore-stm32mp1/board.c b/arch/arm/boards/phytec-phycore-stm32mp1/board.c
index 6690e36ca718..61eb9f424a03 100644
--- a/arch/arm/boards/phytec-phycore-stm32mp1/board.c
+++ b/arch/arm/boards/phytec-phycore-stm32mp1/board.c
@@ -16,7 +16,7 @@ static int phycore_stm32mp1_probe(struct device *dev)
emmc_bbu_flags = BBU_HANDLER_FLAG_DEFAULT;
}
- stm32mp_bbu_mmc_register_handler("sd", "/dev/mmc0.ssbl", sd_bbu_flags);
+ stm32mp_bbu_mmc_fip_register("sd", "/dev/mmc0", sd_bbu_flags);
stm32mp_bbu_mmc_fip_register("emmc", "/dev/mmc1", emmc_bbu_flags);
barebox_set_hostname("phyCORE-STM32MP1");
diff --git a/arch/arm/boards/protonic-stm32mp1/board.c b/arch/arm/boards/protonic-stm32mp1/board.c
index 9116876ad59f..bc5abe2a47e8 100644
--- a/arch/arm/boards/protonic-stm32mp1/board.c
+++ b/arch/arm/boards/protonic-stm32mp1/board.c
@@ -55,7 +55,7 @@ static const struct prt_stm32_boot_dev prt_stm32_boot_devs[] = {
{
.name = "emmc",
.env = "/chosen/environment-emmc",
- .dev = "/dev/mmc1.ssbl",
+ .dev = "/dev/mmc1",
.flags = PRT_STM32_BOOTSRC_EMMC,
.boot_src = BOOTSOURCE_MMC,
.boot_idx = 1,
@@ -71,7 +71,7 @@ static const struct prt_stm32_boot_dev prt_stm32_boot_devs[] = {
* list. */
.name = "sd",
.env = "/chosen/environment-sd",
- .dev = "/dev/mmc0.ssbl",
+ .dev = "/dev/mmc0",
.flags = PRT_STM32_BOOTSRC_SD,
.boot_src = BOOTSOURCE_MMC,
.boot_idx = 0,
@@ -275,11 +275,13 @@ static int prt_stm32_probe(struct device *dev)
env_path = bd->env;
}
- ret = stm32mp_bbu_mmc_register_handler(bd->name, bd->dev,
- bbu_flags);
- if (ret < 0)
- dev_warn(dev, "Failed to enable %s bbu (%pe)\n",
- bd->name, ERR_PTR(ret));
+ if (bd->boot_src == BOOTSOURCE_MMC) {
+ ret = stm32mp_bbu_mmc_fip_register(bd->name, bd->dev,
+ bbu_flags);
+ if (ret < 0)
+ dev_warn(dev, "Failed to enable %s bbu (%pe)\n",
+ bd->name, ERR_PTR(ret));
+ }
}
if (!env_path)
diff --git a/arch/arm/boards/protonic-stm32mp13/board.c b/arch/arm/boards/protonic-stm32mp13/board.c
index fe251b9e7764..19f21a00b6b1 100644
--- a/arch/arm/boards/protonic-stm32mp13/board.c
+++ b/arch/arm/boards/protonic-stm32mp13/board.c
@@ -51,7 +51,7 @@ static const struct prt_stm32_boot_dev prt_stm32_boot_devs[] = {
{
.name = "emmc",
.env = "/chosen/environment-emmc",
- .dev = "/dev/mmc1.ssbl",
+ .dev = "/dev/mmc1",
.flags = PRT_STM32_BOOTSRC_EMMC,
.boot_src = BOOTSOURCE_MMC,
.boot_idx = 1,
@@ -68,7 +68,7 @@ static const struct prt_stm32_boot_dev prt_stm32_boot_devs[] = {
*/
.name = "sd",
.env = "/chosen/environment-sd",
- .dev = "/dev/mmc0.ssbl",
+ .dev = "/dev/mmc0",
.flags = PRT_STM32_BOOTSRC_SD,
.boot_src = BOOTSOURCE_MMC,
.boot_idx = 0,
@@ -256,11 +256,13 @@ static int prt_stm32_probe(struct device *dev)
env_path = bd->env;
}
- ret = stm32mp_bbu_mmc_register_handler(bd->name, bd->dev,
- bbu_flags);
- if (ret < 0)
- dev_warn(dev, "Failed to enable %s bbu (%pe)\n",
- bd->name, ERR_PTR(ret));
+ if (bd->boot_src == BOOTSOURCE_MMC) {
+ ret = stm32mp_bbu_mmc_fip_register(bd->name, bd->dev,
+ bbu_flags);
+ if (ret < 0)
+ dev_warn(dev, "Failed to enable %s bbu (%pe)\n",
+ bd->name, ERR_PTR(ret));
+ }
}
if (!env_path)
diff --git a/arch/arm/boards/seeed-odyssey/board.c b/arch/arm/boards/seeed-odyssey/board.c
index 5befd3266475..683afe9aadda 100644
--- a/arch/arm/boards/seeed-odyssey/board.c
+++ b/arch/arm/boards/seeed-odyssey/board.c
@@ -13,10 +13,10 @@ static int odyssey_som_probe(struct device *dev)
int instance = bootsource_get_instance();
flags = instance == 0 ? BBU_HANDLER_FLAG_DEFAULT : 0;
- stm32mp_bbu_mmc_register_handler("sd", "/dev/mmc0.ssbl", flags);
+ stm32mp_bbu_mmc_fip_register("sd", "/dev/mmc0", flags);
flags = instance == 1 ? BBU_HANDLER_FLAG_DEFAULT : 0;
- stm32mp_bbu_mmc_register_handler("emmc", "/dev/mmc1.ssbl", flags);
+ stm32mp_bbu_mmc_fip_register("emmc", "/dev/mmc1", flags);
if (instance == 0)
diff --git a/arch/arm/boards/stm32mp15x-ev1/board.c b/arch/arm/boards/stm32mp15x-ev1/board.c
index fd58e2817b0b..68f63d558780 100644
--- a/arch/arm/boards/stm32mp15x-ev1/board.c
+++ b/arch/arm/boards/stm32mp15x-ev1/board.c
@@ -11,10 +11,10 @@ static int ed1_probe(struct device *dev)
int flags;
flags = bootsource_get_instance() == 0 ? BBU_HANDLER_FLAG_DEFAULT : 0;
- stm32mp_bbu_mmc_register_handler("sd", "/dev/mmc0.ssbl", flags);
+ stm32mp_bbu_mmc_fip_register("sd", "/dev/mmc0", flags);
flags = bootsource_get_instance() == 1 ? BBU_HANDLER_FLAG_DEFAULT : 0;
- stm32mp_bbu_mmc_register_handler("emmc", "/dev/mmc1.ssbl", flags);
+ stm32mp_bbu_mmc_fip_register("emmc", "/dev/mmc1", flags);
if (bootsource_get_instance() == 0)
of_device_enable_path("/chosen/environment-sd");
diff --git a/arch/arm/boards/stm32mp15xx-dkx/board.c b/arch/arm/boards/stm32mp15xx-dkx/board.c
index 1783c5ca17af..9f005ec1091f 100644
--- a/arch/arm/boards/stm32mp15xx-dkx/board.c
+++ b/arch/arm/boards/stm32mp15xx-dkx/board.c
@@ -8,8 +8,8 @@ static int dkx_probe(struct device *dev)
{
const void *model;
- stm32mp_bbu_mmc_register_handler("sd", "/dev/mmc0.ssbl",
- BBU_HANDLER_FLAG_DEFAULT);
+ stm32mp_bbu_mmc_fip_register("sd", "/dev/mmc0",
+ BBU_HANDLER_FLAG_DEFAULT);
if (dev_get_drvdata(dev, &model) == 0)
barebox_set_model(model);
diff --git a/include/mach/stm32mp/bbu.h b/include/mach/stm32mp/bbu.h
index b469cdeb7c93..233bcf647839 100644
--- a/include/mach/stm32mp/bbu.h
+++ b/include/mach/stm32mp/bbu.h
@@ -5,14 +5,6 @@
#include <bbu.h>
-static inline int stm32mp_bbu_mmc_register_handler(const char *name,
- const char *devicefile,
- unsigned long flags)
-{
- return bbu_register_std_file_update(name, flags, devicefile,
- filetype_stm32_image_ssbl_v1);
-}
-
#ifdef CONFIG_BAREBOX_UPDATE
int stm32mp_bbu_mmc_fip_register(const char *name, const char *devicefile,
--
2.39.5
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-04-09 14:40 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-09 14:01 [PATCH 0/7] ARM: add support for chainloading barebox inside FIP images Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 1/7] fip: add struct fip_image_desc::private_data Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 2/7] fip: mark predefined toc_entries array const Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 3/7] bootm: implement UIMAGE_IS_ADDRESS_VALID helper Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 4/7] ARM: legacy: make architecture number unsigned Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 5/7] ARM: introduce jump_to_linux helper Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 6/7] ARM: add support for chainloading barebox inside FIP images Ahmad Fatoum
2025-04-09 14:01 ` [PATCH 7/7] ARM: stm32mp: retire non-FIP stm32mp_bbu_mmc_register_handler Ahmad Fatoum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox