]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
riscv: Skip riscv_cpu_setup() when CPU driver is disabled
authorMichal Simek <michal.simek@amd.com>
Mon, 11 May 2026 08:31:52 +0000 (10:31 +0200)
committerLeo Yu-Chi Liang <leo.liang@sifive.com>
Mon, 27 Jul 2026 02:39:21 +0000 (19:39 -0700)
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.

Without this patch, building U-Boot with CONFIG_CPU=n and CONFIG_EVENT=y
is broken: riscv_cpu_setup() is registered as an EVT_DM_POST_INIT_F event
spy, and when the CPU uclass is unavailable uclass_find_first_device()
returns no device, so the function returns -ENODEV. That in turn makes
event_notify_null() in dm_init_and_scan() fail and triggers a boot hang
("initcall initf_dm() failed"). Returning 0 early avoids that failure.

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@amd.com>
Reviewed-by: Yao Zi <me@ziyao.cc>
arch/riscv/cpu/cpu.c

index bbadd0c9a469d6f659a688db14174e4330756a51..3bec7c7cb6d06cda1b344acb58bdee07240460d5 100644 (file)
@@ -638,6 +638,9 @@ int riscv_cpu_setup(void)
        const char *isa, **exts;
        struct udevice *dev;
 
+       if (!CONFIG_IS_ENABLED(CPU))
+               return 0;
+
        uclass_find_first_device(UCLASS_CPU, &dev);
        if (!dev) {
                debug("unable to find the RISC-V cpu device\n");