[PATCH v2] board_f: Add support for CONFIG_OF_BOARD_FIXUP for XIP images

Pali Rohár pali at kernel.org
Sun Oct 9 13:32:30 CEST 2022


Simon, could you review this patch? If not, who can do it?

On Sunday 28 August 2022 17:19:29 Marek Behún wrote:
> From: Pali Rohár <pali at kernel.org>
> 
> 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_DTB_READONLY_BEFORE_RELOC 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 at kernel.org>
> Signed-off-by: Marek Behún <kabel at kernel.org>
> ---
> Changes since v1:
> - just changed the new Kconfig option name and associated help string
> ---
>  common/board_f.c | 8 +++++++-
>  dts/Kconfig      | 6 ++++++
>  2 files changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/common/board_f.c b/common/board_f.c
> index 18e2246733..35fb4a0753 100644
> --- a/common/board_f.c
> +++ b/common/board_f.c
> @@ -911,7 +911,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_DTB_READONLY_BEFORE_RELOC)
>  	fix_fdt,
>  #endif
>  #ifdef CONFIG_PRAM
> @@ -926,6 +926,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_DTB_READONLY_BEFORE_RELOC)
> +	reloc_fdt,
> +	fix_fdt,
> +#endif
>  	reserve_bootstage,
>  	reserve_bloblist,
>  	reserve_arch,
> @@ -936,7 +940,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_DTB_READONLY_BEFORE_RELOC)
>  	reloc_fdt,
> +#endif
>  	reloc_bootstage,
>  	reloc_bloblist,
>  	setup_reloc,
> diff --git a/dts/Kconfig b/dts/Kconfig
> index bc5f22029f..29e5248b15 100644
> --- a/dts/Kconfig
> +++ b/dts/Kconfig
> @@ -105,6 +105,12 @@ config OF_EMBED
>  
>  endchoice
>  
> +config OF_DTB_READONLY_BEFORE_RELOC
> +	bool "Initial DTB (before relocation) for DT control is read-only"
> +	help
> +	  If initial (before relocation) DTB for DT control is read-only,
> +	  (e.g. points to memory-mapped flash memory), 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
> -- 
> 2.35.1
> 


More information about the U-Boot mailing list