diff mbox series

[2/2] sunxi: binman: Fix U-Boot offset when SPL is not 32 KiB

Message ID 20230121232518.49723-3-samuel@sholland.org
State Accepted
Commit 9a4aa31ad514a534e57b2607df327cb4f93b87bc
Delegated to: Andre Przywara
Headers show
Series sunxi: binman: Fix U-Boot offset when SPL is not 32 KiB | expand

Commit Message

Samuel Holland Jan. 21, 2023, 11:25 p.m. UTC
On sunxi boards, SPL looks for U-Boot at a 32 KiB offset, unless SPL is
larger than 32 KiB, in which case U-Boot immediately follows SPL. See
the logic in spl_mmc_get_uboot_raw_sector() and spl_spi_load_image().

In two cases, the existing binman description mismatches the SPL code.
For 64-bit boards, binman would place U-Boot immediately following SPL,
even if SPL is smaller than 32 KiB. This can happen when SPL MMC support
is disabled (i.e. when booting from SPI flash).

In contrast, for 32-bit boards, binman would place U-Boot at 32 KiB,
even if SPL is larger than that. This happens because the 'offset'
property does not consider the size of previous entries.

Fix both issues by setting a minimum size for the SPL entry, which
exactly matches the logic in the SPL code. Unfortunately, this size must
be provided as a magic number, since none of the relevant config symbols
(SPL_PAD_TO, SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR, and SYS_SPI_U_BOOT_OFFS)
are guaranteed to be defined in all cases.

Fixes: cfa3db602caf ("sunxi: Convert 64-bit boards to use binman")
Signed-off-by: Samuel Holland <samuel@sholland.org>
---

 arch/arm/dts/sunxi-u-boot.dtsi | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Simon Glass Jan. 23, 2023, 6:49 p.m. UTC | #1
On Sat, 21 Jan 2023 at 16:25, Samuel Holland <samuel@sholland.org> wrote:
>
> On sunxi boards, SPL looks for U-Boot at a 32 KiB offset, unless SPL is
> larger than 32 KiB, in which case U-Boot immediately follows SPL. See
> the logic in spl_mmc_get_uboot_raw_sector() and spl_spi_load_image().
>
> In two cases, the existing binman description mismatches the SPL code.
> For 64-bit boards, binman would place U-Boot immediately following SPL,
> even if SPL is smaller than 32 KiB. This can happen when SPL MMC support
> is disabled (i.e. when booting from SPI flash).
>
> In contrast, for 32-bit boards, binman would place U-Boot at 32 KiB,
> even if SPL is larger than that. This happens because the 'offset'
> property does not consider the size of previous entries.
>
> Fix both issues by setting a minimum size for the SPL entry, which
> exactly matches the logic in the SPL code. Unfortunately, this size must
> be provided as a magic number, since none of the relevant config symbols
> (SPL_PAD_TO, SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR, and SYS_SPI_U_BOOT_OFFS)
> are guaranteed to be defined in all cases.
>
> Fixes: cfa3db602caf ("sunxi: Convert 64-bit boards to use binman")
> Signed-off-by: Samuel Holland <samuel@sholland.org>
> ---
>
>  arch/arm/dts/sunxi-u-boot.dtsi | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)

Reviewed-by: Simon Glass <sjg@chromium.org>



>
> diff --git a/arch/arm/dts/sunxi-u-boot.dtsi b/arch/arm/dts/sunxi-u-boot.dtsi
> index 2028d5b6a9..8a6c9e901a 100644
> --- a/arch/arm/dts/sunxi-u-boot.dtsi
> +++ b/arch/arm/dts/sunxi-u-boot.dtsi
> @@ -31,6 +31,11 @@
>                 pad-byte = <0xff>;
>
>                 blob {
> +                       /*
> +                        * This value matches SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR
> +                        * and SYS_SPI_U_BOOT_OFFS if those are defined.
> +                        */
> +                       min-size = <0x8000>;
>                         filename = "spl/sunxi-spl.bin";
>                 };
>
> @@ -107,7 +112,6 @@
>                 };
>  #else
>                 u-boot-img {
> -                       offset = <CONFIG_SPL_PAD_TO>;
>                 };
>  #endif
>         };
> --
> 2.37.4
>
Andre Przywara April 14, 2023, 10:53 a.m. UTC | #2
On Sat, 21 Jan 2023 17:25:17 -0600
Samuel Holland <samuel@sholland.org> wrote:

Hi Samuel,

> On sunxi boards, SPL looks for U-Boot at a 32 KiB offset, unless SPL is
> larger than 32 KiB, in which case U-Boot immediately follows SPL. See
> the logic in spl_mmc_get_uboot_raw_sector() and spl_spi_load_image().
> 
> In two cases, the existing binman description mismatches the SPL code.
> For 64-bit boards, binman would place U-Boot immediately following SPL,
> even if SPL is smaller than 32 KiB. This can happen when SPL MMC support
> is disabled (i.e. when booting from SPI flash).
> 
> In contrast, for 32-bit boards, binman would place U-Boot at 32 KiB,
> even if SPL is larger than that. This happens because the 'offset'
> property does not consider the size of previous entries.
> 
> Fix both issues by setting a minimum size for the SPL entry, which
> exactly matches the logic in the SPL code. Unfortunately, this size must
> be provided as a magic number, since none of the relevant config symbols
> (SPL_PAD_TO, SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR, and SYS_SPI_U_BOOT_OFFS)
> are guaranteed to be defined in all cases.
> 
> Fixes: cfa3db602caf ("sunxi: Convert 64-bit boards to use binman")
> Signed-off-by: Samuel Holland <samuel@sholland.org>

thanks for this patch. Indeed a 24K arm64 SPL would break the image, and
this patch fixes it. The exact inner workings of binman are beyond me, but
I build tested various key platforms and it seems to work now.
Maybe that would also fix the build problem I saw with the 32-bit FIT
series.

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Queued for sunxi/master.

Cheers,
Andre

> ---
> 
>  arch/arm/dts/sunxi-u-boot.dtsi | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/dts/sunxi-u-boot.dtsi b/arch/arm/dts/sunxi-u-boot.dtsi
> index 2028d5b6a9..8a6c9e901a 100644
> --- a/arch/arm/dts/sunxi-u-boot.dtsi
> +++ b/arch/arm/dts/sunxi-u-boot.dtsi
> @@ -31,6 +31,11 @@
>  		pad-byte = <0xff>;
>  
>  		blob {
> +			/*
> +			 * This value matches SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR
> +			 * and SYS_SPI_U_BOOT_OFFS if those are defined.
> +			 */
> +			min-size = <0x8000>;
>  			filename = "spl/sunxi-spl.bin";
>  		};
>  
> @@ -107,7 +112,6 @@
>  		};
>  #else
>  		u-boot-img {
> -			offset = <CONFIG_SPL_PAD_TO>;
>  		};
>  #endif
>  	};
diff mbox series

Patch

diff --git a/arch/arm/dts/sunxi-u-boot.dtsi b/arch/arm/dts/sunxi-u-boot.dtsi
index 2028d5b6a9..8a6c9e901a 100644
--- a/arch/arm/dts/sunxi-u-boot.dtsi
+++ b/arch/arm/dts/sunxi-u-boot.dtsi
@@ -31,6 +31,11 @@ 
 		pad-byte = <0xff>;
 
 		blob {
+			/*
+			 * This value matches SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR
+			 * and SYS_SPI_U_BOOT_OFFS if those are defined.
+			 */
+			min-size = <0x8000>;
 			filename = "spl/sunxi-spl.bin";
 		};
 
@@ -107,7 +112,6 @@ 
 		};
 #else
 		u-boot-img {
-			offset = <CONFIG_SPL_PAD_TO>;
 		};
 #endif
 	};