sunxi: Add arm64 FEL support
Subsystems (2)
PATCH 1/1 sunxi: Add arm64 FEL support
So far we did not support the BootROM based FEL USB debug mode on the 64-bit builds for Allwinner SoCs: The BootROM is using AArch32, but the SPL runs in AArch64.
Returning back to AArch32 was not working as expected, since the RMR reset into 32-bit mode always starts execution in the BootROM, but not in the FEL routine.
After some debug and research and with help via IRC, the CPU hotplug mechanism emerged as a solution: If a certain R_CPUCFG register contains some magic, the BootROM will immediately branch to an address stored in some other register. This works well for our purposes.
Enable the FEL feature by providing early AArch32 code to first save the FEL state, *before* initially entering AArch64.
If we eventually determine that we should return to FEL, we reset back into AArch32, and use the CPU hotplug mechanism to run some small AArch32 code snippet that restores the initially saved FEL state.
That allows the normal AArch64 SPL build to be loaded via the sunxi-fel tool, with it returning into FEL mode, so that other payloads can be transferred via FEL as well.
Tested on A64, H5 and H6.
--- arch/arm/cpu/armv8/Makefile | 2 + arch/arm/cpu/armv8/fel_utils.S | 78 +++++++++++++++++++++++++ arch/arm/include/asm/arch-sunxi/boot0.h | 14 +++++ include/configs/sunxi-common.h | 2 - 4 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 arch/arm/cpu/armv8/fel_utils.S
arch/arm/cpu/armv8/Makefile +2 -0
@@ -27,6 +27,8 @@ obj-$(CONFIG_ARM_SMCCC) += smccc-call.o ifndef CONFIG_SPL_BUILD obj-$(CONFIG_ARMV8_SPIN_TABLE) += spin_table.o spin_table_v8.o +else +obj-$(CONFIG_ARCH_SUNXI) += fel_utils.o endif obj-$(CONFIG_$(SPL_)ARMV8_SEC_FIRMWARE_SUPPORT) += sec_firmware.o sec_firmware_asm.o
arch/arm/cpu/armv8/fel_utils.S new file +78 -0
78 lines not on this page · raw message
arch/arm/include/asm/arch-sunxi/boot0.h +14 -0
@@ -15,6 +15,19 @@ tst x0, x0 // this is "b #0x84" in ARM b reset .space 0x7c + + .word 0xe28f0058 // add r0, pc, #88 + .word 0xe59f1054 // ldr r1, [pc, #84] + .word 0xe0800001 // add r0, r0, r1 + .word 0xe580d000 // str sp, [r0] + .word 0xe580e004 // str lr, [r0, #4] + .word 0xe10fe000 // mrs lr, CPSR + .word 0xe580e008 // str lr, [r0, #8] + .word 0xee11ef10 // mrc 15, 0, lr, cr1, cr0, {0} + .word 0xe580e00c // str lr, [r0, #12] + .word 0xee1cef10 // mrc 15, 0, lr, cr12, cr0, {0} + .word 0xe580e010 // str lr, [r0, #16] + .word 0xe59f1024 // ldr r1, [pc, #36] ; 0x170000a0 .word 0xe59f0024 // ldr r0, [pc, #36] ; CONFIG_*_TEXT_BASE .word 0xe5810000 // str r0, [r1]
@@ -36,6 +49,7 @@ #else .word CONFIG_SYS_TEXT_BASE #endif + .word fel_stash - .#else /* normal execution */ b reset
include/configs/sunxi-common.h +0 -2
@@ -163,9 +163,7 @@#define CONFIG_SYS_MONITOR_LEN (768 << 10)/* 768 KiB */ -#ifndef CONFIG_ARM64 /* AArch64 FEL support is not ready yet */ #define CONFIG_SPL_BOARD_LOAD_IMAGE -#endif /* * We cannot use expressions here, because expressions won't be evaluated in
Signature · 1 line
2.17.5
PATCH 1/1 sunxi: Add arm64 FEL support
Quoted 24 lines · Andre Przywara
So far we did not support the BootROM based FEL USB debug mode on the 64-bit builds for Allwinner SoCs: The BootROM is using AArch32, but the SPL runs in AArch64.
Returning back to AArch32 was not working as expected, since the RMR reset into 32-bit mode always starts execution in the BootROM, but not in the FEL routine.After some debug and research and with help via IRC, the CPU hotplug mechanism emerged as a solution: If a certain
R_CPUCFGregister contains some magic, the BootROM will immediately branch to an address stored in some other register. This works well for our purposes.Enable the FEL feature by providing early AArch32 code to first save the FEL state, *before* initially entering AArch64.
If we eventually determine that we should return to FEL, we reset back into AArch32, and use the CPU hotplug mechanism to run some small AArch32 code snippet that restores the initially saved FEL state.That allows the normal AArch64 SPL build to be loaded via the sunxi-fel tool, with it returning into FEL mode, so that other payloads can be transferred via FEL as well.
Tested on A64, H5 and H6.
Quoted 8 lines
Signed-off-by Andre Przywara <[email protected]>--- arch/arm/cpu/armv8/Makefile | 2 + arch/arm/cpu/armv8/fel_utils.S | 78 +++++++++++++++++++++++++ arch/arm/include/asm/arch-sunxi/boot0.h | 14 +++++ include/configs/sunxi-common.h | 2 - 4 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 arch/arm/cpu/armv8/fel_utils.S
Don't you want to also update board/sunxi/README.sunxi64 ?
Quoted 151 lines
arch/arm/cpu/armv8/Makefile +2
-0@@ -27,6 +27,8 @@ obj-$(CONFIG_ARM_SMCCC) += smccc-call.o ifndef CONFIG_SPL_BUILD obj-$(CONFIG_ARMV8_SPIN_TABLE) += spin_table.o spin_table_v8.o +else +obj-$(CONFIG_ARCH_SUNXI) += fel_utils.o endif obj-$(CONFIG_$(SPL_)ARMV8_SEC_FIRMWARE_SUPPORT) += sec_firmware.o sec_firmware_asm.oarch/arm/cpu/armv8/fel_utils.S new file +78
-0@@ -0,0 +1,78 @@ +/* + * Utility functions for FEL mode, when running SPL in AArch64. + * + * Copyright (c) 2017 Arm Ltd. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <asm-offsets.h> +#include <config.h> +#include <asm/system.h> +#include <linux/linkage.h> + +/* + * We don't overwrite save_boot_params() here, to save the FEL state upon + * entry, since this would run *after* the RMR reset, which clobbers that + * state. + * Instead we store the state _very_ early in the boot0 hook, *before* + * resetting to AArch64. + */ + +/* + * The FEL routines in BROM run in AArch32. + * Reset back into 32-bit mode here and restore the saved FEL state + * afterwards. + * Resetting back into AArch32/EL3 using the RMR always enters the BROM, + * but we can use the CPU hotplug mechanism to branch back to our code + * immediately. + */ +ENTRY(return_to_fel) + /* + * the RMR reset will clear all registers, so save the arguments + * (LR and SP) in the fel_stash structure, which we read anyways later + */ + adr x2, fel_stash + str w0, [x2] + str w1, [x2, #4] + + adr x1, fel_stash_addr // to find the fel_stash address in AA32 + str w2, [x1] + + ldr x0, =0xfa50392f // CPU hotplug magic +#ifndef CONFIG_MACH_SUN50I_H6 + ldr x2, =(SUNXI_CPUCFG_BASE + 0x1a4) // offset for CPU hotplug base + str w0, [x2, #0x8] +#else + ldr x2, =(SUNXI_RTC_BASE + 0x1b8) // BOOT_CPU_HP_FLAG_REG + str w0, [x2], #0x4 +#endif + adr x0, back_in_32 + str w0, [x2] + + dsb sy + isb sy + mov x0, #2 // RMR reset into AArch32 + dsb sy + msr RMR_EL3, x0 + isb sy +1: wfi + b 1b + +/* AArch32 code to restore the state from fel_stash and return back to FEL. */ +back_in_32: + .word 0xe59f0028 // ldr r0, [pc, #40] ; load fel_stash address + .word 0xe5901008 // ldr r1, [r0, #8] + .word 0xe129f001 // msr CPSR_fc, r1 + .word 0xf57ff06f // isb + .word 0xe590d000 // ldr sp, [r0] + .word 0xe590e004 // ldr lr, [r0, #4] + .word 0xe5901010 // ldr r1, [r0, #16] + .word 0xee0c1f10 // mcr 15, 0, r1, cr12, cr0, {0} ; VBAR + .word 0xe590100c // ldr r1, [r0, #12] + .word 0xee011f10 // mcr 15, 0, r1, cr1, cr0, {0} ; SCTLR + .word 0xf57ff06f // isb + .word 0xe12fff1e // bx lr ; return to FEL +fel_stash_addr: + .word 0x00000000 // receives fel_stash addr, by AA64 code above +ENDPROC(return_to_fel)arch/arm/include/asm/arch-sunxi/boot0.h +14
-0@@ -15,6 +15,19 @@ tst x0, x0 // this is "b #0x84" in ARM b reset .space 0x7c + + .word 0xe28f0058 // add r0, pc, #88 + .word 0xe59f1054 // ldr r1, [pc, #84] + .word 0xe0800001 // add r0, r0, r1 + .word 0xe580d000 // str sp, [r0] + .word 0xe580e004 // str lr, [r0, #4] + .word 0xe10fe000 // mrs lr, CPSR + .word 0xe580e008 // str lr, [r0, #8] + .word 0xee11ef10 // mrc 15, 0, lr, cr1, cr0, {0} + .word 0xe580e00c // str lr, [r0, #12] + .word 0xee1cef10 // mrc 15, 0, lr, cr12, cr0, {0} + .word 0xe580e010 // str lr, [r0, #16] + .word 0xe59f1024 // ldr r1, [pc, #36] ; 0x170000a0 .word 0xe59f0024 // ldr r0, [pc, #36] ; CONFIG_*_TEXT_BASE .word 0xe5810000 // str r0, [r1]@@ -36,6 +49,7 @@ #else .word CONFIG_SYS_TEXT_BASE #endif + .word fel_stash - .#else /* normal execution */ b resetinclude/configs/sunxi-common.h +0
-2@@ -163,9 +163,7 @@#define CONFIG_SYS_MONITOR_LEN (768 << 10)/* 768 KiB */ -#ifndef CONFIG_ARM64 /* AArch64 FEL support is not ready yet */ #define CONFIG_SPL_BOARD_LOAD_IMAGE -#endif /* * We cannot use expressions here, because expressions won't be evaluated in Signature · 6 lines
2.17.5 -- You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe at googlegroups.com. To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/20201119105442.24711-1-andre.przywara%40arm.com.
PATCH 1/1 sunxi: Add arm64 FEL support
Quoted 34 lines · Priit Laes
Quoted 24 lines · Andre Przywara
So far we did not support the BootROM based FEL USB debug mode on the 64-bit builds for Allwinner SoCs: The BootROM is using AArch32, but the SPL runs in AArch64.
Returning back to AArch32 was not working as expected, since the RMR reset into 32-bit mode always starts execution in the BootROM, but not in the FEL routine.After some debug and research and with help via IRC, the CPU hotplug mechanism emerged as a solution: If a certain
R_CPUCFGregister contains some magic, the BootROM will immediately branch to an address stored in some other register. This works well for our purposes.Enable the FEL feature by providing early AArch32 code to first save the FEL state, *before* initially entering AArch64.
If we eventually determine that we should return to FEL, we reset back into AArch32, and use the CPU hotplug mechanism to run some small AArch32 code snippet that restores the initially saved FEL state.That allows the normal AArch64 SPL build to be loaded via the sunxi-fel tool, with it returning into FEL mode, so that other payloads can be transferred via FEL as well.
Tested on A64, H5 and H6.
Quoted 8 lines
Signed-off-by Andre Przywara <[email protected]>--- arch/arm/cpu/armv8/Makefile | 2 + arch/arm/cpu/armv8/fel_utils.S | 78 +++++++++++++++++++++++++ arch/arm/include/asm/arch-sunxi/boot0.h | 14 +++++ include/configs/sunxi-common.h | 2 - 4 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 arch/arm/cpu/armv8/fel_utils.S
Quoted 1 line
Don't you want to also update board/sunxi/README.sunxi64 ?
Yes, but I am in the process of rewriting this anyway, since some parts apply to 32-bit SoCs as well (SD card, SPI flash), and there is currently no documentation about them. So bear with me, I will post a documentation update ASAP, just didn't want to hold back this patch.
Thanks!
Andre.
Quoted 151 lines
Quoted 151 lines
arch/arm/cpu/armv8/Makefile +2
-0@@ -27,6 +27,8 @@ obj-$(CONFIG_ARM_SMCCC) += smccc-call.o ifndef CONFIG_SPL_BUILD obj-$(CONFIG_ARMV8_SPIN_TABLE) += spin_table.o spin_table_v8.o +else +obj-$(CONFIG_ARCH_SUNXI) += fel_utils.o endif obj-$(CONFIG_$(SPL_)ARMV8_SEC_FIRMWARE_SUPPORT) += sec_firmware.o sec_firmware_asm.oarch/arm/cpu/armv8/fel_utils.S new file +78
-0@@ -0,0 +1,78 @@ +/* + * Utility functions for FEL mode, when running SPL in AArch64. + * + * Copyright (c) 2017 Arm Ltd. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <asm-offsets.h> +#include <config.h> +#include <asm/system.h> +#include <linux/linkage.h> + +/* + * We don't overwrite save_boot_params() here, to save the FEL state upon + * entry, since this would run *after* the RMR reset, which clobbers that + * state. + * Instead we store the state _very_ early in the boot0 hook, *before* + * resetting to AArch64. + */ + +/* + * The FEL routines in BROM run in AArch32. + * Reset back into 32-bit mode here and restore the saved FEL state + * afterwards. + * Resetting back into AArch32/EL3 using the RMR always enters the BROM, + * but we can use the CPU hotplug mechanism to branch back to our code + * immediately. + */ +ENTRY(return_to_fel) + /* + * the RMR reset will clear all registers, so save the arguments + * (LR and SP) in the fel_stash structure, which we read anyways later + */ + adr x2, fel_stash + str w0, [x2] + str w1, [x2, #4] + + adr x1, fel_stash_addr // to find the fel_stash address in AA32 + str w2, [x1] + + ldr x0, =0xfa50392f // CPU hotplug magic +#ifndef CONFIG_MACH_SUN50I_H6 + ldr x2, =(SUNXI_CPUCFG_BASE + 0x1a4) // offset for CPU hotplug base + str w0, [x2, #0x8] +#else + ldr x2, =(SUNXI_RTC_BASE + 0x1b8) // BOOT_CPU_HP_FLAG_REG + str w0, [x2], #0x4 +#endif + adr x0, back_in_32 + str w0, [x2] + + dsb sy + isb sy + mov x0, #2 // RMR reset into AArch32 + dsb sy + msr RMR_EL3, x0 + isb sy +1: wfi + b 1b + +/* AArch32 code to restore the state from fel_stash and return back to FEL. */ +back_in_32: + .word 0xe59f0028 // ldr r0, [pc, #40] ; load fel_stash address + .word 0xe5901008 // ldr r1, [r0, #8] + .word 0xe129f001 // msr CPSR_fc, r1 + .word 0xf57ff06f // isb + .word 0xe590d000 // ldr sp, [r0] + .word 0xe590e004 // ldr lr, [r0, #4] + .word 0xe5901010 // ldr r1, [r0, #16] + .word 0xee0c1f10 // mcr 15, 0, r1, cr12, cr0, {0} ; VBAR + .word 0xe590100c // ldr r1, [r0, #12] + .word 0xee011f10 // mcr 15, 0, r1, cr1, cr0, {0} ; SCTLR + .word 0xf57ff06f // isb + .word 0xe12fff1e // bx lr ; return to FEL +fel_stash_addr: + .word 0x00000000 // receives fel_stash addr, by AA64 code above +ENDPROC(return_to_fel)arch/arm/include/asm/arch-sunxi/boot0.h +14
-0@@ -15,6 +15,19 @@ tst x0, x0 // this is "b #0x84" in ARM b reset .space 0x7c + + .word 0xe28f0058 // add r0, pc, #88 + .word 0xe59f1054 // ldr r1, [pc, #84] + .word 0xe0800001 // add r0, r0, r1 + .word 0xe580d000 // str sp, [r0] + .word 0xe580e004 // str lr, [r0, #4] + .word 0xe10fe000 // mrs lr, CPSR + .word 0xe580e008 // str lr, [r0, #8] + .word 0xee11ef10 // mrc 15, 0, lr, cr1, cr0, {0} + .word 0xe580e00c // str lr, [r0, #12] + .word 0xee1cef10 // mrc 15, 0, lr, cr12, cr0, {0} + .word 0xe580e010 // str lr, [r0, #16] + .word 0xe59f1024 // ldr r1, [pc, #36] ; 0x170000a0 .word 0xe59f0024 // ldr r0, [pc, #36] ; CONFIG_*_TEXT_BASE .word 0xe5810000 // str r0, [r1]@@ -36,6 +49,7 @@ #else .word CONFIG_SYS_TEXT_BASE #endif + .word fel_stash - .#else /* normal execution */ b resetinclude/configs/sunxi-common.h +0
-2@@ -163,9 +163,7 @@#define CONFIG_SYS_MONITOR_LEN (768 << 10)/* 768 KiB */ -#ifndef CONFIG_ARM64 /* AArch64 FEL support is not ready yet */ #define CONFIG_SPL_BOARD_LOAD_IMAGE -#endif /* * We cannot use expressions here, because expressions won't be evaluated in Signature · 6 lines
2.17.5 -- You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe at googlegroups.com. To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/20201119105442.24711-1-andre.przywara%40arm.com.
Jernej Škrabec
maintainerPATCH 1/1 sunxi: Add arm64 FEL support
Hi Andre,
thanks for working on this!
Dne petek, 20. november 2020 ob 10:42:15 CET je Andr? Przywara napisal(a):
Quoted 46 lines · Priit Laes
Quoted 34 lines · Andre Przywara
Quoted 24 lines
So far we did not support the BootROM based FEL USB debug mode on the 64-bit builds for Allwinner SoCs: The BootROM is using AArch32, but the SPL runs in AArch64.
Returning back to AArch32 was not working as expected, since the RMR reset into 32-bit mode always starts execution in the BootROM, but not in the FEL routine.After some debug and research and with help via IRC, the CPU hotplug mechanism emerged as a solution: If a certain
R_CPUCFGregister contains some magic, the BootROM will immediately branch to an address stored in some other register. This works well for our purposes.Enable the FEL feature by providing early AArch32 code to first save the FEL state, *before* initially entering AArch64.
If we eventually determine that we should return to FEL, we reset back into AArch32, and use the CPU hotplug mechanism to run some small AArch32 code snippet that restores the initially saved FEL state.That allows the normal AArch64 SPL build to be loaded via the sunxi-fel tool, with it returning into FEL mode, so that other payloads can be transferred via FEL as well.
Tested on A64, H5 and H6.
Quoted 8 lines
Signed-off-by Andre Przywara <[email protected]>--- arch/arm/cpu/armv8/Makefile | 2 + arch/arm/cpu/armv8/fel_utils.S | 78 +++++++++++++++++++++++++ arch/arm/include/asm/arch-sunxi/boot0.h | 14 +++++ include/configs/sunxi-common.h | 2 - 4 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 arch/arm/cpu/armv8/fel_utils.SQuoted 1 line
Don't you want to also update board/sunxi/README.sunxi64 ?
Yes, but I am in the process of rewriting this anyway, since some parts apply to 32-bit SoCs as well (SD card, SPI flash), and there is currently no documentation about them. So bear with me, I will post a documentation update ASAP, just didn't want to hold back this patch.
Thanks!
Andre.Quoted 1 line
Quoted 1 line
Quoted 5 lines
Quoted 5 lines
arch/arm/cpu/armv8/Makefile obj-$(CONFIG_ARM_SMCCC) += smccc-
Quoted 5 lines
arch/arm/cpu/armv8/Makefile +0
-0@@ -27,6 +27,8 @@ obj-$(CONFIG_ARM_SMCCC) += smccc-
call.o
Quoted 7 lines
Quoted 7 lines
arch/arm/cpu/armv8/Makefile obj-$(CONFIG_ARM_SMCCC) += smccc-call.o
Quoted 7 lines
arch/arm/cpu/armv8/Makefile +2
-0ifndef CONFIG_SPL_BUILD obj-$(CONFIG_ARMV8_SPIN_TABLE) += spin_table.o spin_table_v8.o +else +obj-$(CONFIG_ARCH_SUNXI) += fel_utils.o endif obj-$(CONFIG_$(SPL_)ARMV8_SEC_FIRMWARE_SUPPORT) += sec_firmware.o
sec_firmware_asm.o
Quoted 2 lines
Quoted 2 lines
arch/arm/cpu/armv8/
Quoted 2 lines
arch/arm/cpu/armv8/ renamed from arch/arm/cpu/armv8/fel_utils.S +0
-0
fel_utils.S
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
new file mode 100644
index 00000000000..334fdef7fa0arch/arm/cpu/armv8/fel_utils.S new file +7
-0@@ -0,0 +1,78 @@ +/* + * Utility functions for FEL mode, when running SPL in AArch64. + * + * Copyright (c) 2017 Arm Ltd. + * + * SPDX-License-Identifier: GPL-2.0+ + */
Quoted 8 lines
Quoted 8 lines
arch/arm/cpu/armv8/fel_utils.S
Quoted 8 lines
arch/arm/cpu/armv8/fel_utils.S new file +8
-0+ +#include <asm-offsets.h> +#include <config.h> +#include <asm/system.h> +#include <linux/linkage.h> + +/* + * We don't overwrite save_boot_params() here, to save the FEL state
upon
Quoted 1 line
Quoted 1 line
arch/arm/cpu/armv8/fel_utils.S line 16
Quoted 1 line
arch/arm/cpu/armv8/fel_utils.S new file +1
-0+ * entry, since this would run *after* the RMR reset, which clobbers
that
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
arch/arm/cpu/armv8/fel_utils.S new file +9
-0+ * state. + * Instead we store the state _very_ early in the boot0 hook, *before* + * resetting to AArch64. + */ + +/* + * The FEL routines in BROM run in AArch32. + * Reset back into 32-bit mode here and restore the saved FEL state + * afterwards.
Quoted 8 lines
Quoted 8 lines
arch/arm/cpu/armv8/fel_utils.S
Quoted 8 lines
arch/arm/cpu/armv8/fel_utils.S new file +8
-0+ * Resetting back into AArch32/EL3 using the RMR always enters the BROM, + * but we can use the CPU hotplug mechanism to branch back to our code + * immediately. + */ +ENTRY(return_to_fel) + /* + * the RMR reset will clear all registers, so save the arguments + * (LR and SP) in the fel_stash structure, which we read anyways
later
Quoted 6 lines
Quoted 6 lines
arch/arm/cpu/armv8/fel_utils.S
Quoted 6 lines
arch/arm/cpu/armv8/fel_utils.S new file +6
-0+ */ + adr x2, fel_stash + str w0, [x2] + str w1, [x2, #4] + + adr x1, fel_stash_addr // to find the fel_stash
address in AA32
Quoted 5 lines
Quoted 5 lines
arch/arm/cpu/armv8/fel_utils.S
Quoted 5 lines
arch/arm/cpu/armv8/fel_utils.S new file +5
-0+ str w2, [x1] + + ldr x0, =0xfa50392f // CPU hotplug magic +#ifndef CONFIG_MACH_SUN50I_H6 + ldr x2, =(SUNXI_CPUCFG_BASE + 0x1a4) // offset for CPU
hotplug base
Quoted 3 lines
Quoted 3 lines
arch/arm/cpu/armv8/fel_utils.S
Quoted 3 lines
arch/arm/cpu/armv8/fel_utils.S new file +3
-0+ str w0, [x2, #0x8] +#else + ldr x2, =(SUNXI_RTC_BASE + 0x1b8) //
BOOT_CPU_HP_FLAG_REG
Quoted 2 lines
Quoted 2 lines
arch/arm/cpu/armv8/fel_utils.S line 49
Quoted 2 lines
arch/arm/cpu/armv8/fel_utils.S new file +2
-0+ str w0, [x2], #0x4 +#endif
I suggest to turn around those ifdefs, e.g. put specific one first and general last. That way it will be much more readable when new exception will be added. For example, H616 has it's own address.
Best regards,
Jernej
Quoted 6 lines
Quoted 6 lines
arch/arm/cpu/armv8/fel_utils.S
Quoted 6 lines
arch/arm/cpu/armv8/fel_utils.S new file +6
-0+ adr x0, back_in_32 + str w0, [x2] + + dsb sy + isb sy + mov x0, #2 // RMR reset into
AArch32
Quoted 7 lines
Quoted 7 lines
arch/arm/cpu/armv8/fel_utils.S
Quoted 7 lines
arch/arm/cpu/armv8/fel_utils.S new file +7
-0+ dsb sy + msr RMR_EL3, x0 + isb sy +1: wfi + b 1b + +/* AArch32 code to restore the state from fel_stash and return back to
FEL. */
Quoted 2 lines
Quoted 2 lines
arch/arm/cpu/armv8/fel_utils.S line 64
Quoted 2 lines
arch/arm/cpu/armv8/fel_utils.S new file +2
-0+back_in_32: + .word 0xe59f0028 // ldr r0, [pc, #40] ; load fel_stash
address
Quoted 7 lines
Quoted 7 lines
arch/arm/cpu/armv8/fel_utils.S
Quoted 7 lines
arch/arm/cpu/armv8/fel_utils.S new file +7
-0+ .word 0xe5901008 // ldr r1, [r0, #8] + .word 0xe129f001 // msr CPSR_fc, r1 + .word 0xf57ff06f // isb + .word 0xe590d000 // ldr sp, [r0] + .word 0xe590e004 // ldr lr, [r0, #4] + .word 0xe5901010 // ldr r1, [r0, #16] + .word 0xee0c1f10 // mcr 15, 0, r1, cr12, cr0, {0} ;
VBAR
Quoted 2 lines
Quoted 2 lines
arch/arm/cpu/armv8/fel_utils.S line 73
Quoted 2 lines
arch/arm/cpu/armv8/fel_utils.S new file +2
-0+ .word 0xe590100c // ldr r1, [r0, #12] + .word 0xee011f10 // mcr 15, 0, r1, cr1, cr0, {0} ;
SCTLR
Quoted 2 lines
Quoted 2 lines
arch/arm/cpu/armv8/fel_utils.S line 75
Quoted 2 lines
arch/arm/cpu/armv8/fel_utils.S new file +2
-0+ .word 0xf57ff06f // isb + .word 0xe12fff1e // bx lr ; return
to FEL
Quoted 2 lines
Quoted 2 lines
arch/arm/cpu/armv8/fel_utils.S line 77
Quoted 2 lines
arch/arm/cpu/armv8/fel_utils.S new file +2
-0+fel_stash_addr: + .word 0x00000000 // receives fel_stash addr, by AA64 code
above
Quoted 2 lines
Quoted 2 lines
arch/arm/include/
Quoted 2 lines
arch/arm/cpu/armv8/fel_utils.S new file +1
-0+ENDPROC(return_to_fel)arch/arm/include/ renamed from arch/arm/include/asm/arch-sunxi/boot0.h +0
-0
asm/arch-sunxi/boot0.h
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
index
54c144afd8c..46d0f0666c2100644arch/arm/include/asm/arch-sunxi/boot0.h +7
-0@@ -15,6 +15,19 @@ tst x0, x0 // this is "b #0x84" in ARM b reset .space 0x7c + + .word 0xe28f0058 // add r0, pc, #88 + .word 0xe59f1054 // ldr r1, [pc, #84] + .word 0xe0800001 // add r0, r0, r1 + .word 0xe580d000 // str sp, [r0] + .word 0xe580e004 // str lr, [r0, #4] + .word 0xe10fe000 // mrs lr, CPSR
Quoted 8 lines
Quoted 8 lines
arch/arm/include/asm/arch-sunxi/boot0.h
Quoted 8 lines
arch/arm/include/asm/arch-sunxi/boot0.h +6
-0+ .word 0xe580e008 // str lr, [r0, #8] + .word 0xee11ef10 // mrc 15, 0, lr, cr1, cr0, {0} + .word 0xe580e00c // str lr, [r0, #12] + .word 0xee1cef10 // mrc 15, 0, lr, cr12, cr0, {0} + .word 0xe580e010 // str lr, [r0, #16] + .word 0xe59f1024 // ldr r1, [pc, #36] ; 0x170000a0 .word 0xe59f0024 // ldr r0, [pc, #36] ;
CONFIG_*_TEXT_BASE
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
arch/arm/include/asm/arch-sunxi/boot0.h +1
-0.word 0xe5810000 // str r0, [r1]@@ -36,6 +49,7 @@ #else .word CONFIG_SYS_TEXT_BASE #endif + .word fel_stash - .#else /* normal execution */ b resetinclude/configs/sunxi-common.h +0
-0@@ -163,9 +163,7 @@
Quoted 1 line
Quoted 1 line
include/configs/sunxi-common.h line 164
Quoted 1 line
include/configs/sunxi-common.h +0
-0#define CONFIG_SYS_MONITOR_LEN (768 << 10)/* 768 KiB
*/
Quoted 2 lines
Quoted 2 lines
include/configs/sunxi-common.h line 165
Quoted 2 lines
include/configs/sunxi-common.h +0
-1-#ifndef CONFIG_ARM64 /* AArch64 FEL support is not
ready yet */
Quoted 5 lines
Quoted 5 lines
include/configs/sunxi-common.h
Quoted 5 lines
include/configs/sunxi-common.h +0
-1#define CONFIG_SPL_BOARD_LOAD_IMAGE -#endif /* * We cannot use expressions here, because expressions won't be
evaluated in
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Signature · 4 lines
2.17.5 -- You received this message because you are subscribed to the Google Groups
"linux-sunxi" group.
Quoted 1 line
Quoted 1 line
Quoted 1 line
To unsubscribe from this group and stop receiving emails from it, send an
email to linux-sunxi+unsubscribe at googlegroups.com.
Quoted 1 line
Quoted 1 line
Quoted 1 line
To view this discussion on the web, visit https://groups.google.com/d/
msgid/linux-sunxi/20201119105442.24711-1-andre.przywara%40arm.com.
Quoted 3 lines
Signature · 2 lines
-- You received this message because you are subscribed to the Google Groups
"linux-sunxi" group.
Quoted 1 line
To unsubscribe from this group and stop receiving emails from it, send an
email to linux-sunxi+unsubscribe at googlegroups.com.
Quoted 1 line
To view this discussion on the web, visit https://groups.google.com/d/msgid/
linux-sunxi/0fd3cbb4-a2c9-85d5-5fbd-057bb654863d%40arm.com.
Quoted 1 line
PATCH 1/1 sunxi: Add arm64 FEL support
In reply to Andre Przywara? 2020-11-19???? 10:54 +0000?Andre Przywara???
Quoted 24 lines
So far we did not support the BootROM based FEL USB debug mode on the 64-bit builds for Allwinner SoCs: The BootROM is using AArch32, but the
SPL runs in AArch64.
Returning back to AArch32 was not working as expected, since the RMR reset into 32-bit mode always starts execution in the BootROM, but not
in the FEL routine.After some debug and research and with help via IRC, the CPU hotplug mechanism emerged as a solution: If a certain
R_CPUCFGregister contains
some magic, the BootROM will immediately branch to an address stored in
some other register. This works well for our purposes.Enable the FEL feature by providing early AArch32 code to first save the
FEL state, *before* initially entering AArch64.
If we eventually determine that we should return to FEL, we reset back
into AArch32, and use the CPU hotplug mechanism to run some small AArch32 code snippet that restores the initially saved FEL state.
Quoted 8 lines
That allows the normal AArch64 SPL build to be loaded via the sunxi- fel
tool, with it returning into FEL mode, so that other payloads can be transferred via FEL as well.Tested on A64, H5 and H6.
Signed-off-by Andre Przywara <[email protected]>
Quoted 180 lines
--- arch/arm/cpu/armv8/Makefile | 2 + arch/arm/cpu/armv8/fel_utils.S | 78 +++++++++++++++++++++++++ arch/arm/include/asm/arch-sunxi/boot0.h | 14 +++++ include/configs/sunxi-common.h | 2 - 4 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 arch/arm/cpu/armv8/fel_utils.Sarch/arm/cpu/armv8/Makefile +2
-0@@ -27,6 +27,8 @@ obj-$(CONFIG_ARM_SMCCC) += smccc-call.o ifndef CONFIG_SPL_BUILD obj-$(CONFIG_ARMV8_SPIN_TABLE) += spin_table.o spin_table_v8.o +else +obj-$(CONFIG_ARCH_SUNXI) += fel_utils.o endif obj-$(CONFIG_$(SPL_)ARMV8_SEC_FIRMWARE_SUPPORT) += sec_firmware.osec_firmware_asm.o
arch/arm/cpu/armv8/fel_utils.S new file +15
-0@@ -0,0 +1,78 @@ +/* + * Utility functions for FEL mode, when running SPL in AArch64. + * + * Copyright (c) 2017 Arm Ltd. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <asm-offsets.h> +#include <config.h> +#include <asm/system.h> +#include <linux/linkage.h> + +/* + * We don't overwrite save_boot_params() here, to save the FEL stateupon
+ * entry, since this would run *after* the RMR reset, which clobbers that
+ * state.
+ * Instead we store the state _very_ early in the boot0 hook, *before*
+ * resetting to AArch64.
+ */arch/arm/cpu/armv8/fel_utils.S new file +6
-0+ +/* + * The FEL routines in BROM run in AArch32. + * Reset back into 32-bit mode here and restore the saved FEL state + * afterwards. + * Resetting back into AArch32/EL3 using the RMR always enters theBROM,
+ * but we can use the CPU hotplug mechanism to branch back to our code
+ * immediately.
+ */arch/arm/cpu/armv8/fel_utils.S new file +3
-0+ENTRY(return_to_fel) + /* + * the RMR reset will clear all registers, so save thearguments
arch/arm/cpu/armv8/fel_utils.S new file +1
-0+ * (LR and SP) in the fel_stash structure, which we readanyways later
arch/arm/cpu/armv8/fel_utils.S new file +6
-0+ */ + adr x2, fel_stash + str w0, [x2] + str w1, [x2, #4] + + adr x1, fel_stash_addr // to find the fel_stashaddress in AA32
arch/arm/cpu/armv8/fel_utils.S new file +5
-0+ str w2, [x1] + + ldr x0, =0xfa50392f // CPU hotplug magic +#ifndef CONFIG_MACH_SUN50I_H6 + ldr x2, =(SUNXI_CPUCFG_BASE + 0x1a4) // offset for CPUhotplug base
arch/arm/cpu/armv8/fel_utils.S new file +3
-0+ str w0, [x2, #0x8] +#else + ldr x2, =(SUNXI_RTC_BASE + 0x1b8) //
BOOT_CPU_HP_FLAG_REGarch/arm/cpu/armv8/fel_utils.S new file +15
-0+ str w0, [x2], #0x4 +#endif + adr x0, back_in_32 + str w0, [x2] + + dsb sy + isb sy + mov x0, #2 // RMR reset into AArch32 + dsb sy + msr RMR_EL3, x0 + isb sy +1: wfi + b 1b + +/* AArch32 code to restore the state from fel_stash and return backto FEL. */
arch/arm/cpu/armv8/fel_utils.S new file +2
-0+back_in_32: + .word 0xe59f0028 // ldr r0, [pc, #40] ; load
fel_stashaddressarch/arm/cpu/armv8/fel_utils.S new file +7
-0+ .word 0xe5901008 // ldr r1, [r0, #8] + .word 0xe129f001 // msr CPSR_fc, r1 + .word 0xf57ff06f // isb + .word 0xe590d000 // ldr sp, [r0] + .word 0xe590e004 // ldr lr, [r0, #4] + .word 0xe5901010 // ldr r1, [r0, #16] + .word 0xee0c1f10 // mcr 15, 0, r1, cr12, cr0, {0} ;VBAR
arch/arm/cpu/armv8/fel_utils.S new file +2
-0+ .word 0xe590100c // ldr r1, [r0, #12] + .word 0xee011f10 // mcr 15, 0, r1, cr1, cr0, {0} ;SCTLR
arch/arm/cpu/armv8/fel_utils.S new file +2
-0+ .word 0xf57ff06f // isb + .word 0xe12fff1e // bx lr ; return toFEL
arch/arm/cpu/armv8/fel_utils.S new file +2
-0+fel_stash_addr: + .word 0x00000000 // receives fel_stash addr, by AA64code above
arch/arm/cpu/armv8/fel_utils.S new file +1
-0+ENDPROC(return_to_fel)arch/arm/include/asm/arch-sunxi/boot0.h +13
-0@@ -15,6 +15,19 @@ tst x0, x0 // this is "b #0x84" in ARM b reset .space 0x7c + + .word 0xe28f0058 // add r0, pc, #88 + .word 0xe59f1054 // ldr r1, [pc, #84] + .word 0xe0800001 // add r0, r0, r1 + .word 0xe580d000 // str sp, [r0] + .word 0xe580e004 // str lr, [r0, #4] + .word 0xe10fe000 // mrs lr, CPSR + .word 0xe580e008 // str lr, [r0, #8] + .word 0xee11ef10 // mrc 15, 0, lr, cr1, cr0, {0} + .word 0xe580e00c // str lr, [r0, #12] + .word 0xee1cef10 // mrc 15, 0, lr, cr12, cr0, {0} + .word 0xe580e010 // str lr, [r0, #16] + .word 0xe59f1024 // ldr r1, [pc, #36] ; 0x170000a0 .word 0xe59f0024 // ldr r0, [pc, #36] ;CONFIG_*_TEXT_BASE
arch/arm/include/asm/arch-sunxi/boot0.h +1
-0.word 0xe5810000 // str r0, [r1]@@ -36,6 +49,7 @@ #else .word CONFIG_SYS_TEXT_BASE #endif + .word fel_stash - .#else /* normal execution */ b resetinclude/configs/sunxi- renamed from include/configs/sunxi-common.h +0
-0
common.h
indexa6a4879523a..203cb10fbab100644include/configs/sunxi-common.h +0
-0@@ -163,9 +163,7 @@#define CONFIG_SYS_MONITOR_LEN (768 << 10)/* 768 KiB */
-#ifndef
CONFIG_ARM64/* AArch64 FEL support is not ready yet
*/
#defineCONFIG_SPL_BOARD_LOAD_IMAGE
-#endif/*
* We cannot use expressions here, because expressions won't be
evaluated inSignature · 1 line
2.17.5
PATCH 1/1 sunxi: Add arm64 FEL support
In reply to Andre PrzywaraQuoted 19 lines · Andre Przywara
So far we did not support the BootROM based FEL USB debug mode on the 64-bit builds for Allwinner SoCs: The BootROM is using AArch32, but the SPL runs in AArch64.
Returning back to AArch32 was not working as expected, since the RMR reset into 32-bit mode always starts execution in the BootROM, but not in the FEL routine.After some debug and research and with help via IRC, the CPU hotplug mechanism emerged as a solution: If a certain
R_CPUCFGregister contains some magic, the BootROM will immediately branch to an address stored in some other register. This works well for our purposes.Enable the FEL feature by providing early AArch32 code to first save the FEL state, *before* initially entering AArch64.
If we eventually determine that we should return to FEL, we reset back into AArch32, and use the CPU hotplug mechanism to run some small AArch32 code snippet that restores the initially saved FEL state.
Quoted 8 lines
That allows the normal AArch64 SPL build to be loaded via the sunxi-fel tool, with it returning into FEL mode, so that other payloads can be transferred via FEL as well.
Tested on A64, H5 and H6.
Signed-off-by Andre Przywara <[email protected]>---
PATCH 1/1 sunxi: Add arm64 FEL support
In reply to Andre PrzywaraQuoted 18 lines · Andre Przywara
So far we did not support the BootROM based FEL USB debug mode on the 64-bit builds for Allwinner SoCs: The BootROM is using AArch32, but the SPL runs in AArch64.
Returning back to AArch32 was not working as expected, since the RMR reset into 32-bit mode always starts execution in the BootROM, but not in the FEL routine.After some debug and research and with help via IRC, the CPU hotplug mechanism emerged as a solution: If a certain
R_CPUCFGregister contains some magic, the BootROM will immediately branch to an address stored in some other register. This works well for our purposes.Enable the FEL feature by providing early AArch32 code to first save the FEL state, *before* initially entering AArch64.
If we eventually determine that we should return to FEL, we reset back into AArch32, and use the CPU hotplug mechanism to run some small AArch32 code snippet that restores the initially saved FEL state.
Quoted 5 lines
That allows the normal AArch64 SPL build to be loaded via the sunxi-fel tool, with it returning into FEL mode, so that other payloads can be transferred via FEL as well.
Tested on A64, H5 and H6.
For A64 (on Olimex A64-Olinuxino):
Also writing down the command to run as it was not that obvious:
$ sunxi-fel spl sunxi-spl.bin \ write 0x4a000000 u-boot.bin \ write 0x44000 bl31.bin \ write 0x50000 scp.bin \ reset64 0x44000
Quoted 159 lines
Signed-off-by Andre Przywara <[email protected]>--- arch/arm/cpu/armv8/Makefile | 2 + arch/arm/cpu/armv8/fel_utils.S | 78 +++++++++++++++++++++++++ arch/arm/include/asm/arch-sunxi/boot0.h | 14 +++++ include/configs/sunxi-common.h | 2 - 4 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 arch/arm/cpu/armv8/fel_utils.Sarch/arm/cpu/armv8/Makefile +2
-0@@ -27,6 +27,8 @@ obj-$(CONFIG_ARM_SMCCC) += smccc-call.o ifndef CONFIG_SPL_BUILD obj-$(CONFIG_ARMV8_SPIN_TABLE) += spin_table.o spin_table_v8.o +else +obj-$(CONFIG_ARCH_SUNXI) += fel_utils.o endif obj-$(CONFIG_$(SPL_)ARMV8_SEC_FIRMWARE_SUPPORT) += sec_firmware.o sec_firmware_asm.oarch/arm/cpu/armv8/fel_utils.S new file +78
-0@@ -0,0 +1,78 @@ +/* + * Utility functions for FEL mode, when running SPL in AArch64. + * + * Copyright (c) 2017 Arm Ltd. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <asm-offsets.h> +#include <config.h> +#include <asm/system.h> +#include <linux/linkage.h> + +/* + * We don't overwrite save_boot_params() here, to save the FEL state upon + * entry, since this would run *after* the RMR reset, which clobbers that + * state. + * Instead we store the state _very_ early in the boot0 hook, *before* + * resetting to AArch64. + */ + +/* + * The FEL routines in BROM run in AArch32. + * Reset back into 32-bit mode here and restore the saved FEL state + * afterwards. + * Resetting back into AArch32/EL3 using the RMR always enters the BROM, + * but we can use the CPU hotplug mechanism to branch back to our code + * immediately. + */ +ENTRY(return_to_fel) + /* + * the RMR reset will clear all registers, so save the arguments + * (LR and SP) in the fel_stash structure, which we read anyways later + */ + adr x2, fel_stash + str w0, [x2] + str w1, [x2, #4] + + adr x1, fel_stash_addr // to find the fel_stash address in AA32 + str w2, [x1] + + ldr x0, =0xfa50392f // CPU hotplug magic +#ifndef CONFIG_MACH_SUN50I_H6 + ldr x2, =(SUNXI_CPUCFG_BASE + 0x1a4) // offset for CPU hotplug base + str w0, [x2, #0x8] +#else + ldr x2, =(SUNXI_RTC_BASE + 0x1b8) // BOOT_CPU_HP_FLAG_REG + str w0, [x2], #0x4 +#endif + adr x0, back_in_32 + str w0, [x2] + + dsb sy + isb sy + mov x0, #2 // RMR reset into AArch32 + dsb sy + msr RMR_EL3, x0 + isb sy +1: wfi + b 1b + +/* AArch32 code to restore the state from fel_stash and return back to FEL. */ +back_in_32: + .word 0xe59f0028 // ldr r0, [pc, #40] ; load fel_stash address + .word 0xe5901008 // ldr r1, [r0, #8] + .word 0xe129f001 // msr CPSR_fc, r1 + .word 0xf57ff06f // isb + .word 0xe590d000 // ldr sp, [r0] + .word 0xe590e004 // ldr lr, [r0, #4] + .word 0xe5901010 // ldr r1, [r0, #16] + .word 0xee0c1f10 // mcr 15, 0, r1, cr12, cr0, {0} ; VBAR + .word 0xe590100c // ldr r1, [r0, #12] + .word 0xee011f10 // mcr 15, 0, r1, cr1, cr0, {0} ; SCTLR + .word 0xf57ff06f // isb + .word 0xe12fff1e // bx lr ; return to FEL +fel_stash_addr: + .word 0x00000000 // receives fel_stash addr, by AA64 code above +ENDPROC(return_to_fel)arch/arm/include/asm/arch-sunxi/boot0.h +14
-0@@ -15,6 +15,19 @@ tst x0, x0 // this is "b #0x84" in ARM b reset .space 0x7c + + .word 0xe28f0058 // add r0, pc, #88 + .word 0xe59f1054 // ldr r1, [pc, #84] + .word 0xe0800001 // add r0, r0, r1 + .word 0xe580d000 // str sp, [r0] + .word 0xe580e004 // str lr, [r0, #4] + .word 0xe10fe000 // mrs lr, CPSR + .word 0xe580e008 // str lr, [r0, #8] + .word 0xee11ef10 // mrc 15, 0, lr, cr1, cr0, {0} + .word 0xe580e00c // str lr, [r0, #12] + .word 0xee1cef10 // mrc 15, 0, lr, cr12, cr0, {0} + .word 0xe580e010 // str lr, [r0, #16] + .word 0xe59f1024 // ldr r1, [pc, #36] ; 0x170000a0 .word 0xe59f0024 // ldr r0, [pc, #36] ; CONFIG_*_TEXT_BASE .word 0xe5810000 // str r0, [r1]@@ -36,6 +49,7 @@ #else .word CONFIG_SYS_TEXT_BASE #endif + .word fel_stash - .#else /* normal execution */ b resetinclude/configs/sunxi-common.h +0
-2@@ -163,9 +163,7 @@#define CONFIG_SYS_MONITOR_LEN (768 << 10)/* 768 KiB */ -#ifndef CONFIG_ARM64 /* AArch64 FEL support is not ready yet */ #define CONFIG_SPL_BOARD_LOAD_IMAGE -#endif /* * We cannot use expressions here, because expressions won't be evaluated in Signature · 6 lines
2.17.5 -- You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe at googlegroups.com. To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/20201119105442.24711-1-andre.przywara%40arm.com.