]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
board_f: Add support for CONFIG_OF_BOARD_FIXUP for XIP images
authorPali Rohár <pali@kernel.org>
Thu, 6 Jun 2024 16:33:21 +0000 (18:33 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 12 Jul 2024 19:07:43 +0000 (13:07 -0600)
When U-Boot is running from flash memory (execute in place) then
gd->fdt_blob before relocation points to read-only flash memory.

So U-Boot calls board_fix_fdt() with read-only gd->fdt_blob pointer which
cause immediate CPU crash when callback is trying to modify gd->fdt_blob.

Fix this issue by introducing a new config option OF_INITIAL_DTB_READONLY
which moves fix_fdt callback after the reloc_fdt callback. This makes
CONFIG_OF_BOARD_FIXUP working also if U-Boot before relocation is not
running from read/write (S)RAM memory.

This is required for mpc85xx boards when booting from flash NOR.

Signed-off-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Marek Mojík <marek.mojik@nic.cz>
Reviewed-by: Marek Behún <kabel@kernel.org>
common/board_f.c
dts/Kconfig

index 212ffb3090b202dff40273abe76a892a40cb49da..22c180b21877c390f1892924a41a037bfcfe50d2 100644 (file)
@@ -949,7 +949,7 @@ static const init_fnc_t init_sequence_f[] = {
         *  - board info struct
         */
        setup_dest_addr,
-#ifdef CONFIG_OF_BOARD_FIXUP
+#if defined(CONFIG_OF_BOARD_FIXUP) && !defined(CONFIG_OF_INITIAL_DTB_READONLY)
        fix_fdt,
 #endif
 #ifdef CFG_PRAM
@@ -965,6 +965,10 @@ static const init_fnc_t init_sequence_f[] = {
        reserve_board,
        reserve_global_data,
        reserve_fdt,
+#if defined(CONFIG_OF_BOARD_FIXUP) && defined(CONFIG_OF_INITIAL_DTB_READONLY)
+       reloc_fdt,
+       fix_fdt,
+#endif
        reserve_bootstage,
        reserve_bloblist,
        reserve_arch,
@@ -975,7 +979,9 @@ static const init_fnc_t init_sequence_f[] = {
        setup_bdinfo,
        display_new_sp,
        INIT_FUNC_WATCHDOG_RESET
+#if !defined(CONFIG_OF_BOARD_FIXUP) || !defined(CONFIG_OF_INITIAL_DTB_READONLY)
        reloc_fdt,
+#endif
        reloc_bootstage,
        reloc_bloblist,
        setup_reloc,
index 6883a000a05252988339c22b9c66d253395f1f13..569d4be338e3ac39d648141874dd4a296b6f34ea 100644 (file)
@@ -145,6 +145,12 @@ config OF_EMBED
 
 endchoice
 
+config OF_INITIAL_DTB_READONLY
+       bool "Initial DTB for DT control is read-only"
+       help
+         If initial DTB for DT control is read-only (e.g. points to
+         memory-mapped flash memory), then set this option.
+
 config OF_BOARD
        bool "Provided by the board (e.g a previous loader) at runtime"
        default y if SANDBOX || OF_HAS_PRIOR_STAGE