[PATCH 4/5] mach-snapdragon: support building SPL
Michael Srba
Michael.Srba at seznam.cz
Wed Apr 8 19:03:37 CEST 2026
On 4/6/26 16:27, Tom Rini wrote:
> On Sat, Apr 04, 2026 at 01:18:19AM +0200, michael.srba at seznam.cz wrote:
>
>> From: Michael Srba <Michael.Srba at seznam.cz>
>>
>> Initially sdm845 support is added, and only usb boot
>> is supported for the next stage.
>>
>> Signed-off-by: Michael Srba <Michael.Srba at seznam.cz>
> [snip]
>> diff --git a/arch/arm/mach-snapdragon/Kconfig b/arch/arm/mach-snapdragon/Kconfig
>> index 976c0e35fce..938e6ebd8bf 100644
>> --- a/arch/arm/mach-snapdragon/Kconfig
>> +++ b/arch/arm/mach-snapdragon/Kconfig
>> @@ -1,6 +1,24 @@
>> if ARCH_SNAPDRAGON
>>
>> +# SoC specific SRAM addresses
>> +
>> +# sdm845
>> +SDM845_BOOT_IMEM_BASE := 0x14800000
>> +SDM845_BOOT_IMEM_SIZE := 0x180000
>> +# we may not be able to use the whole BOOT_IMEM depending on the whitelisted regions hardcoded in PBL
>> +# (we could technically relocate ourselves after the fact)
>> +SDM845_BOOT_IMEM_OFFSET := 0x3f000
>> +SDM845_BOOT_IMEM_USABLE_SIZE := 0xc1000
>> +# technically the below would work, except the memory from 0x14833000 to 0x1483F000 gets trashed
>> +# between the ELF getting loaded and XBL_SEC jumping to our code
>> +#SDM845_BOOT_IMEM_OFFSET := 0x16000
>> +#SDM845_BOOT_IMEM_USABLE_SIZE := 0xea000
>> +SDM845_OCIMEM_BASE := 0x14680000
>> +SDM845_OCIMEM_SIZE := 0x00040000
>> +SDM845_OCIMEM_END := $(shell, printf "0x%x\n" "$(dollar)(($(SDM845_OCIMEM_BASE) + $(SDM845_OCIMEM_SIZE) - 1))")
> I didn't know Kconfig even allowed this. And I *really* don't like it,
> and I think it's going in the wrong direction with respect to being able
> to configure a system. If these are configurable, then they need to be
> "hex" type "config" options, and then used later on. Otherwise they
> should just be the evaluated value as "default ... if ..." later on,
> instead.
This is per-SoC hardware info. The SRAM is physically located at that
address with that size. The offset/usable size are further restrictions
imposed by the bootrom, which are relevant for placing the text section
(the bootrom will copy the ELF segment precisely where the ELF segment
says it wants to live, as long as that's in a whitelisted region).
I really don't like the idea of just hardcoding hex values with either
no explanation of where they come from, or with a comment that may or
may not reflect the reality since there's no mechanism that would enforce
that the value was actually computed according to the comment.
(also the amount and complexity of such comments would be higher since
comments can't reference nonexistent intermediate variables)
What I wanted to do here was more along the lines of:
```
config QCOM_BOOT_IMEM_BASE
default 0x14800000 if SPL_TARGET_SDM845
config QCOM_BOOT_IMEM_SIZE
default 0x180000 if SPL_TARGET_SDM845
config QCOM_BOOT_IMEM_OFFSET
default 0x3f000 if SPL_TARGET_SDM845
config QCOM_BOOT_IMEM_USABLE_SIZE
default 0xc1000 if SPL_TARGET_SDM845
```
and then
```
config SPL_STACK
default SDM845_OCIMEM_START + SDM845_OCIMEM_SIZE
config SPL_TEXT_BASE
default QCOM_BOOT_IMEM_BASE + QCOM_BOOT_IMEM_OFFSET
config SPL_SYS_MALLOC_F_LEN
QCOM_BOOT_IMEM_SIZE / 2
```
The problem with the above is that Kconfig absolutely doesn't support
doing that. The only way to do arithmetics is to use the preprocessor
("macro language"), and the preprocessor obviously doesn't have access
to the values of symbols, only to preprocessor variables.
The current form is the only solution I could come up with that avoids
hardcoding hex values, and from reading kconfig docs and sources I think
it's also the only solution possible short of patching kconfig to support
arithmetics.
If you consider this more ugly than magic hex values (which afaict is
the only other option, other than patching kconfig of course),
I can obviously do that, although it does make me very sad, and I'd prefer
if we can find a solution that avoids hardcoding. What do you think?
> [snip]
>> +config QCOM_SPL
>> + bool "Enable SPL for Snapdragon SOCs"
>> + select SUPPORT_SPL
>> + select ARMV8_SPL_EXCEPTION_VECTORS
>> + select ENABLE_ARM_SOC_BOOT0_HOOK
>> + select SPL
>> + select SPL_DM
>> + select SPL_DM_GPIO
>> + select SPL_DM_PMIC
>> + select SPL_DM_USB_GADGET
>> + select SPL_ENV_SUPPORT
>> + select SPL_GPIO
>> + select SPL_HAS_BSS_LINKER_SECTION
>> + select SPL_LIBCOMMON_SUPPORT
>> + select SPL_LIBDISK_SUPPORT
>> + select SPL_LIBGENERIC_SUPPORT
>> + select SPL_MMC
>> + select SPL_OF_REAL
>> + select SPL_OF_CONTROL
>> + select SPL_PINCONF
>> + select SPL_PINCTRL
>> + select SPL_PINCTRL_FULL
>> + select SPL_PINCTRL_GENERIC
>> + select SPL_PINCONF_RECURSIVE
>> + select SPL_PINMUX
>> + select SPL_SPRINTF
>> + select SPL_STRTO
>> + select SPL_USB_GADGET
> This should be in the appropriate defconfig, or a config fragment if
> re-used a lot. Or mirroring other platforms, as part of the stanza for
> TARGET_... (or ARCH_...) as needed.
>
> [snip]
>> diff --git a/doc/board/qualcomm/spl.rst b/doc/board/qualcomm/spl.rst
>> new file mode 100644
>> index 00000000000..817c76b659e
>> --- /dev/null
>> +++ b/doc/board/qualcomm/spl.rst
>> @@ -0,0 +1,70 @@
>> +.. SPDX-License-Identifier: GPL-2.0+
>> +.. sectionauthor:: Michael Srba <Michael.Srba at seznam.cz>
>> +
>> +======================================
>> +Booting U-Boot SPL on Qualcomm SoCs
>> +======================================
>> +
>> +Overview
>> +----------
> These are style errors that will trip up CI when it builds the docs.
> Please run "make htmldocs KDOC_WERROR=1" for v2, thanks.
>
More information about the U-Boot
mailing list