[PATCH 08/18] sparc32,leon: identify LEON before the firmware model lookup

From: Magnus Lindholm

Date: Thu Nov 26 2026 - 04:31:51 EST


The legacy firmware lacks the compatible property expected by startup,
so LEON is misidentified as sun4m. With LEON support enabled, identify
PSR implementation 0xf before the firmware lookup and enter leon_init.

Fixes: 1ddb22e13dea ("sparc32,leon: fix leon bootup")
Signed-off-by: Magnus Lindholm <linmag7@xxxxxxxxx>
---
arch/sparc/kernel/head_32.S | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/arch/sparc/kernel/head_32.S b/arch/sparc/kernel/head_32.S
index 11a1746829a4..97000e9dffd6 100644
--- a/arch/sparc/kernel/head_32.S
+++ b/arch/sparc/kernel/head_32.S
@@ -27,6 +27,13 @@
#include <asm/errno.h>
#include <asm/pgtable.h> /* PGDIR_SHIFT */

+ .macro leon_psr_compare reg
+ rd %psr, \reg
+ srl \reg, PSR_IMPL_SHIFT, \reg
+ and \reg, PSR_IMPL_SHIFTED_MASK, \reg
+ cmp \reg, PSR_IMPL_LEON
+ .endm
+
.data
/* The following are used with the prom_vector node-ops to figure out
* the cpu-type
@@ -205,10 +212,7 @@ not_a_sun4:
*/

/* Check if this is a LEON CPU */
- rd %psr, %g3
- srl %g3, PSR_IMPL_SHIFT, %g3
- and %g3, PSR_IMPL_SHIFTED_MASK, %g3
- cmp %g3, PSR_IMPL_LEON
+ leon_psr_compare %g3
be leon_remap /* It is a LEON - jump */
nop

@@ -366,6 +370,23 @@ execute_in_high_mem:
sethi %hi(linux_dbvec), %g1
st %o1, [%g1 + %lo(linux_dbvec)]

+#ifdef CONFIG_SPARC_LEON
+ /* Old LEON U-Boot uses "compatability", not "compatible".
+ * Identify the CPU before choosing platform initialization,
+ * and publish the same model for sparc32_start_kernel().
+ */
+ leon_psr_compare %g3
+ bne .Lprom_machine_type
+ nop
+ set cputypval, %o2
+ set 0x6c656f6e, %g3 ! "leon"
+ st %g3, [%o2]
+ stb %g0, [%o2 + 4]
+ ba leon_init
+ nop
+.Lprom_machine_type:
+#endif /* CONFIG_SPARC_LEON */
+
/* Get the machine type via the romvec
* getprops node operation
*/
--
2.43.0