Skip to contentSkip to conversation

arm: kirkwood: fix freeze on boot

PATCH In review Tom Rini 2 participants 3 messages Jun 23, 2025

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH v2 1/1 arm: kirkwood: fix freeze on boot

From: Jerome Forissier <[email protected]>

Commit 6fe50e395080 ("arm: asm/system.h: mrc and mcr need .arm if __thumb2__ is not set") is not a proper fix for the LTO link error mentioned in its description. It causes 32-bit arm instructions to be mixed with thumb instructions, which the Kirkwood SoCs do not support. For example, board_init_r() is mostly generated in Thumb-1 mode as expected since the build flags contain -mthumb -mthumb-interwork. The MCR instruction corresponding to writefr_extra_feature_reg() is also correcly emitted as a 32-bit ARM instruction (it cannot be encoded in Thumb-1 anyways). The problem is, the compiler inlines the MCR without generating the BX or BLX instruction which are needed to transition between the ARM and the Thumb-1 states. From the objdump output:

006186a0 <board_init_r>:
board_init_r():
/home/jerome/work/u-boot/common/board_r.c:799

  6186a0:       b5f0            push    {r4, r5, r6, r7, lr}
  6186a2:       b0ab            sub     sp, #172        @ 0xac

get_gd():
/home/jerome/work/u-boot/./arch/arm/include/asm/global_data.h:127
6186a4: 464a mov r2, r9
...
/home/jerome/work/u-boot/arch/arm/mach-kirkwood/cpu.c:242
619aae: 9b15 ldr r3, [sp, #84] @ 0x54
writefr_extra_feature_reg():
/home/jerome/work/u-boot/./arch/arm/include/asm/arch/cpu.h:100
619ab0: ee2f3f11 mcr 15, 1, r3, cr15, cr1, {0}
^^^^^^^^
32-bit ARM instruction

Further investigation is needed to understand how to fix the issue so that the code size is minimal for all boards. In the mean time, this fix disables LTO for the two problematic files (common/board_f.c and common/board_r.c). This makes the Kirkwood-based boards bootable again. The binary size is increased by 1048 bytes which is perfectly acceptable.

Fixes 6fe50e395080 ("arm: asm/system.h: mrc and mcr need .arm if __thumb2__ is not set")

---
Changes in v2:
- Guard the change with 'ifdef CONFIG_$(PHASE_)SYS_THUMB_BUILD'

---
 common/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
common/Makefile +4 -0
index 35991562a12b..e589f3072621 100644
@@ -19,6 +19,10 @@ obj-y += version.o
 # # boards
 obj-y += board_f.o
 obj-y += board_r.o
+ifdef CONFIG_$(PHASE_)SYS_THUMB_BUILD
+CFLAGS_REMOVE_board_f.o := $(LTO_CFLAGS)
+CFLAGS_REMOVE_board_r.o := $(LTO_CFLAGS)
+endif
 obj-$(CONFIG_DISPLAY_BOARDINFO) += board_info.o
 obj-$(CONFIG_DISPLAY_BOARDINFO_LATE) += board_info.o
 
Signature · 1 line
2.43.0
Tested-by on v2 1/1
#1 lore raw
Quoted 66 lines · Tom Rini

From: Jerome Forissier <[email protected]>

Commit 6fe50e395080 ("arm: asm/system.h: mrc and mcr need .arm if __thumb2__ is not set") is not a proper fix for the LTO link error mentioned in its description. It causes 32-bit arm instructions to be mixed with thumb instructions, which the Kirkwood SoCs do not support. For example, board_init_r() is mostly generated in Thumb-1 mode as expected since the build flags contain -mthumb -mthumb-interwork. The MCR instruction corresponding to writefr_extra_feature_reg() is also correcly emitted as a 32-bit ARM instruction (it cannot be encoded in Thumb-1 anyways). The problem is, the compiler inlines the MCR without generating the BX or BLX instruction which are needed to transition between the ARM and the Thumb-1 states. From the objdump output:

006186a0 <board_init_r>:
board_init_r():
/home/jerome/work/u-boot/common/board_r.c:799

  6186a0:       b5f0            push    {r4, r5, r6, r7, lr}
  6186a2:       b0ab            sub     sp, #172        @ 0xac

get_gd():
/home/jerome/work/u-boot/./arch/arm/include/asm/global_data.h:127
6186a4: 464a mov r2, r9
...
/home/jerome/work/u-boot/arch/arm/mach-kirkwood/cpu.c:242
619aae: 9b15 ldr r3, [sp, #84] @ 0x54
writefr_extra_feature_reg():
/home/jerome/work/u-boot/./arch/arm/include/asm/arch/cpu.h:100
619ab0: ee2f3f11 mcr 15, 1, r3, cr15, cr1, {0}
^^^^^^^^
32-bit ARM instruction

Further investigation is needed to understand how to fix the issue so that the code size is minimal for all boards. In the mean time, this fix disables LTO for the two problematic files (common/board_f.c and common/board_r.c). This makes the Kirkwood-based boards bootable again. The binary size is increased by 1048 bytes which is perfectly acceptable.

Fixes 6fe50e395080 ("arm: asm/system.h: mrc and mcr need .arm if __thumb2__ is not set")

---
Changes in v2:
- Guard the change with 'ifdef CONFIG_$(PHASE_)SYS_THUMB_BUILD'

---
 common/Makefile | 4 ++++
 1 file changed, 4 insertions(+)
common/Makefile +4 -1
index 35991562a12b..e589f3072621 100644
@@ -19,6 +19,10 @@ obj-y += version.o
 # # boards
 obj-y += board_f.o
 obj-y += board_r.o
+ifdef CONFIG_$(PHASE_)SYS_THUMB_BUILD
+CFLAGS_REMOVE_board_f.o := $(LTO_CFLAGS)
+CFLAGS_REMOVE_board_r.o := $(LTO_CFLAGS)
+endif
 obj-$(CONFIG_DISPLAY_BOARDINFO) += board_info.o
 obj-$(CONFIG_DISPLAY_BOARDINFO_LATE) += board_info.o
 
--
Quoted 2 lines

2.43.0

author
#2 lore raw
In reply to Tom Rini
Quoted 12 lines · Tom Rini

Commit 6fe50e395080 ("arm: asm/system.h: mrc and mcr need .arm if __thumb2__ is not set") is not a proper fix for the LTO link error mentioned in its description. It causes 32-bit arm instructions to be mixed with thumb instructions, which the Kirkwood SoCs do not support. For example, board_init_r() is mostly generated in Thumb-1 mode as expected since the build flags contain -mthumb -mthumb-interwork. The MCR instruction corresponding to writefr_extra_feature_reg() is also correcly emitted as a 32-bit ARM instruction (it cannot be encoded in Thumb-1 anyways). The problem is, the compiler inlines the MCR without generating the BX or BLX instruction which are needed to transition between the ARM and the Thumb-1 states. From the objdump output:

Quoted 1 line

[...]

Applied to u-boot/master, thanks!

[1/1] arm: kirkwood: fix freeze on boot

      commit: 410d59095a9f2319585bd66152b31f72389dcdaf
Signature · 1 line
Tom