Issue found when porting to new device.

Vicente Bergas <[email protected]>
Newsgroups org.u-boot-project.lists.u-boot
Message-ID <CAAMcf8A2fkH41UP9jsJZSaPS2PUaoB_CNT5g4E4KXG0thmUvOQ@mail.gmail.com>
Hi,
i am porting u-boot to a new device:
https://handhelds.wiki/R36S_Handheld_Wiki

Given the similarity with ODROID_GO2, i've based my efforts on it and
all goes fine up to the very last step: jumping from u-boot to linux.

In the file arch/arm/cpu/armv8/transition.S there is a call to
armv8_switch_to_el2_m which is supposed to jump into linux, but it
doesn't.

I've added some debug prints around it (see patch below) and it prints
the first message:
"before switch from EL3 to EL2"
but it does not print either of the messages after.

As another test, i've tried to replace
armv8_switch_to_el2_m x4, x5, x6
to
br x4
and then it indeed switches to linux, but then linux crashes, prints a
trace and reboots, that is, it doesn't like running from EL3.

Please, can somebody help here?

Regards,
  Vicente.

--- a/arch/arm/include/asm/macro.h
+++ b/arch/arm/include/asm/macro.h
@@ -209,6 +209,7 @@
     msr    spsr_el3, \tmp
     msr    elr_el3, \ep
     eret
+    b    2f

 1:
     /*
@@ -228,6 +229,7 @@
     msr    spsr_el3, \tmp
     msr     elr_el3, \ep
     eret
+2:
 .endm

 /*
--- a/arch/arm/cpu/armv8/transition.S
+++ b/arch/arm/cpu/armv8/transition.S
@@ -36,8 +36,46 @@
      * address saved in x4.
      */
     br x4
-1:    armv8_switch_to_el2_m x4, x5, x6
+1:
+
+    adr x8, msg_before
+    bl uart5_asciiz
+
+    adr x8, switch_to_el2_ok
+    armv8_switch_to_el2_m x8, x5, x6
+
+    adr x8, msg_aft_ko
+    bl uart5_asciiz
+
+switch_to_el2_ko:
+    b switch_to_el2_ko
+
+switch_to_el2_ok:
+    adr x8, msg_aft_ok
+    bl uart5_asciiz
+
+    br x4
+
+msg_before: .asciz "before switch from EL3 to EL2\n"
+msg_aft_ko: .asciz "switch to EL2 failed\n"
+msg_aft_ok: .asciz "now running in EL2\n"
 ENDPROC(armv8_switch_to_el2)
+
+ENTRY(uart5_asciiz)
+    mov  x10, #0x8000
+    movk x10, #0xFF17, lsl #16
+2:
+    ldrb w9, [x8]
+    cbnz w9, 3f
+    ret
+3:
+    add  x8, x8, #1
+4:
+    ldr  w11, [x10, #20] // [UART5_LSR]
+    tbz  w11, #5, 4b     // while (!trans_hold_reg_empty)
+    str  w9, [x10]       // [UART5_THR] <= *str++;
+    b    2b
+ENDPROC(uart5_asciiz)
 .popsection

 .pushsection .text.armv8_switch_to_el1, "ax"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.