From 410d59095a9f2319585bd66152b31f72389dcdaf Mon Sep 17 00:00:00 2001 From: Jerome Forissier Date: Mon, 23 Jun 2025 13:10:11 -0600 Subject: [PATCH] arm: kirkwood: fix freeze on boot 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(): /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") Reported-by: Tony Dinh Tested-by: Tony Dinh Signed-off-by: Jerome Forissier Signed-off-by: Tom Rini --- common/Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/Makefile b/common/Makefile index 35991562a12..e589f307262 100644 --- a/common/Makefile +++ b/common/Makefile @@ -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 -- 2.39.5