[PATCH] riscv: Skip riscv_cpu_setup() when CPU driver is disabled
Michal Simek
michal.simek at amd.com
Mon May 4 11:00:17 CEST 2026
On 5/1/26 10:54, Yao Zi wrote:
> On Thu, Apr 30, 2026 at 01:57:51PM +0200, Michal Simek wrote:
>> Building on commit c64fc632a86a ("riscv: cpu: Use CONFIG_IS_ENABLED(CPU)
>> instead of plain ifdef"), add an early return in riscv_cpu_setup() when
>> CONFIG_CPU is not enabled. This allows platforms to save code space in
>> SPL by disabling CONFIG_SPL_CPU.
>>
>> The compiler's dead-code elimination combined with --gc-sections
>> removes the unreachable code and all associated static data,
>> achieving significant size reduction without preprocessor guards:
>>
>> spl/u-boot-spl:all -4332 spl/u-boot-spl:rodata -2872
>> spl/u-boot-spl:text -1460
>>
>> Signed-off-by: Michal Simek <michal.simek at amd.com>
>> ---
>>
>> arch/riscv/cpu/cpu.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/arch/riscv/cpu/cpu.c b/arch/riscv/cpu/cpu.c
>> index bbadd0c9a469..3bec7c7cb6d0 100644
>> --- a/arch/riscv/cpu/cpu.c
>> +++ b/arch/riscv/cpu/cpu.c
>> @@ -638,6 +638,9 @@ int riscv_cpu_setup(void)
>> const char *isa, **exts;
>> struct udevice *dev;
>>
>> + if (!CONFIG_IS_ENABLED(CPU))
>> + return 0;
>
> Should we return zero here, or -ENOENT like the original behavior when
> no UCLASS_CPU device is found?
if you put there error value then when CONFIG_CPU is disable you get boot hang
which is likely what you don't want to see right?
initcall_run_f(): initcall initf_dm() failed
### ERROR ### Please RESET the board ###
Thanks,
Michal
More information about the U-Boot
mailing list