lib: sbi: Introduce early hart initialization scheme
PATCH 1/2 lib: sbi: Introduce early hart initialization scheme
Referencing U-Boot (edd9ad81 riscv: cpu: Add callback to init each core) Introduce a callback function for each hart to do its own initialization as early as possible.
--- firmware/fw_base.S | 6 ++++++ lib/sbi/sbi_init.c | 4 ++++ 2 files changed, 10 insertions(+)
firmware/fw_base.S +6 -0
@@ -47,6 +47,12 @@ .globl _start .globl _start_warm _start: + /* Setup temporary stack */ + lla s4, _fw_end + li s5, (SBI_SCRATCH_SIZE * 2) + add sp, s4, s5 + /* call harts_early_init */ + call harts_early_init /* Find preferred boot HART id */ MOV_3R s0, a0, s1, a1, s2, a2 call fw_boot_hart
lib/sbi/sbi_init.c +4 -0
@@ -536,3 +536,7 @@ void __noreturn sbi_exit(struct sbi_scratch *scratch)sbi_hsm_exit (scratch); } + +__attribute__((weak))void harts_early_init (void ) +{ +}
Signature · 1 line
2.17.0
PATCH 1/2 lib: sbi: Introduce early hart initialization scheme
? 2021-09-23???? 10:28 +0800?Leo Yu-Chi Liang???
Quoted 18 lines
Referencing U-Boot (
edd9ad81riscv: cpu: Add callback to init each core)
Introduce a callback function for each hart to do its own initialization
as early as possible.Signed-off-by Leo Yu-Chi Liang <[email protected]>---
?firmware/fw_base.S | 6 ++++++
?lib/sbi/sbi_init.c | 4 ++++
?2 files changed, 10 insertions(+)firmware/fw_base.S +0
-0@@ -47,6 +47,12 @@????????.globl
_start
Quoted 8 lines
????????.globl
_start_warm
?_start:
+???????/* Setup temporary stack */
+???????lla?????s4,_fw_end
+???????li??????s5, (SBI_SCRATCH_SIZE* 2)
+???????add?????sp, s4, s5
+???????/* callharts_early_init*/
+???????callharts_early_init
This will destroy the parameters (a0/a1/a2) that the firmware passed to opensbi in the previous stage. And here, the stack pointers of multiple cores are set to the same memory address, which may cause memory conflicts.
Regards,
Xiang W
Quoted 20 lines
????????/* Find preferred boot HART id */
????????MOV_3R??s0, a0, s1, a1, s2, a2
????????call????fw_boot_hartlib/sbi/sbi_init.c +0
-0@@ -536,3 +536,7 @@ void __noreturn sbi_exit(struct sbi_scratch *scratch)?
????????sbi_hsm_exit(scratch);
?}lib/sbi/sbi_init.c +4
-0+ +__attribute__((weak))void harts_early_init (void ) +{ +}Signature · 1 line
2.17.0