[U-Boot] [PATCH v3 1/2] armv8: Support loading 32-bit OS in AArch32 execution state

Alexander Graf agraf at suse.de
Fri Jun 3 11:41:47 CEST 2016



Am 03.06.2016 um 11:31 schrieb Huan Wang <alison.wang at nxp.com>:

>> On 03.06.16 05:11, Huan Wang wrote:
>>>> On 26.05.16 10:41, Alison Wang wrote:
>>>>> To support loading a 32-bit OS, the execution state will change from
>>>>> AArch64 to AArch32 when jumping to kernel.
>>>>> 
>>>>> The architecture information will be got through checking FIT image,
>>>>> then U-Boot will load 32-bit OS or 64-bit OS automatically.
>>>>> 
>>>>> Signed-off-by: Ebony Zhu <ebony.zhu at nxp.com>
>>>>> Signed-off-by: Alison Wang <alison.wang at nxp.com>
>>>>> Signed-off-by: Chenhui Zhao <chenhui.zhao at nxp.com>
>>>>> ---
>>>>> Changes in v3:
>>>>> - Comments the functions and the arguments.
>>>>> - Rename the real parameters.
>>>>> - Use the macros instead of the magic values.
>>>>> - Remove the redundant codes.
>>>>> - Clean up all of the mess in boot_jump_linux().
>>>>> - Add CONFIG_ARM64_SUPPORT_AARCH32 to detect for some ARM64 system
>>>> doesn't support AArch32 state.
>>>>> 
>>>>> Changes in v2:
>>>>> - armv8_switch_to_el2_aarch32() is removed. armv8_switch_to_el2_m is
>>>> used
>>>>>  to switch to AArch64 EL2 or AArch32 Hyp.
>>>>> - armv8_switch_to_el1_aarch32() is removed. armv8_switch_to_el1_m is
>>>> used
>>>>>  to switch to AArch64 EL1 or AArch32 SVC.
>>>>> 
>>>>> arch/arm/Kconfig                |   6 ++
>>>>> arch/arm/cpu/armv8/transition.S |   8 +-
>>>>> arch/arm/include/asm/macro.h    | 174
>> ++++++++++++++++++++++++++++++-
>>>> ---------
>>>>> arch/arm/include/asm/system.h   | 118 ++++++++++++++++++++++++++-
>>>>> arch/arm/lib/bootm.c            |  19 ++++-
>>>>> common/image-fit.c              |  14 +++-
>>>>> 6 files changed, 287 insertions(+), 52 deletions(-)
>>>>> 
>>>>> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index
>>>>> 729b181..794cb4f 100644
>>>>> --- a/arch/arm/Kconfig
>>>>> +++ b/arch/arm/Kconfig
>>>>> @@ -77,6 +77,12 @@ config SYS_L2CACHE_OFF
>>>>>      If SoC does not support L2CACHE or one do not want to enable
>>>>>      L2CACHE, choose this option.
>>>>> 
>>>>> +config ARM64_SUPPORT_AARCH32
>>>>> +    bool "ARM64 system support AArch32 execution state"
>>>>> +    default y if ARM64 && !CONFIG_THUNDERX
>>>> 
>>>> I don't think that works. In Kconfig you need to omit the CONFIG_
>> parts.
>>>> It's "ARM64" also, not "CONFIG_ARM64".
>>>> 
>>>> Please just try to run a local make defconfig on the thunderx
>>>> reference system and see whether it includes the option or not.
>>> [Alison Wang] Yes, I missed it. Will change in the next version.
>>>> 
>>>>> +    help
>>>>> +      This ARM64 system supports AArch32 execution state.
>>>>> +
>>>>> choice
>>>>>    prompt "Target select"
>>>>>    default TARGET_HIKEY
>>>>> diff --git a/arch/arm/cpu/armv8/transition.S
>>>>> b/arch/arm/cpu/armv8/transition.S index 253a39b..417e8b4 100644
>>>>> --- a/arch/arm/cpu/armv8/transition.S
>>>>> +++ b/arch/arm/cpu/armv8/transition.S
>>>>> @@ -11,13 +11,13 @@
>>>>> #include <asm/macro.h>
>>>>> 
>>>>> ENTRY(armv8_switch_to_el2)
>>>>> -    switch_el x0, 1f, 0f, 0f
>>>>> +    switch_el x4, 1f, 0f, 0f
>>>>> 0:    ret
>>>>> -1:    armv8_switch_to_el2_m x0
>>>>> +1:    armv8_switch_to_el2_m x0, x1, x2, x3, x4
>>>>> ENDPROC(armv8_switch_to_el2)
>>>>> 
>>>>> ENTRY(armv8_switch_to_el1)
>>>>> -    switch_el x0, 0f, 1f, 0f
>>>>> +    switch_el x4, 0f, 1f, 0f
>>>>> 0:    ret
>>>>> -1:    armv8_switch_to_el1_m x0, x1
>>>>> +1:    armv8_switch_to_el1_m x0, x1, x2, x3, x4
>>>>> ENDPROC(armv8_switch_to_el1)
>>>>> diff --git a/arch/arm/include/asm/macro.h
>>>>> b/arch/arm/include/asm/macro.h index 9bb0efa..dd2c510 100644
>>>>> --- a/arch/arm/include/asm/macro.h
>>>>> +++ b/arch/arm/include/asm/macro.h
>>>>> @@ -8,6 +8,9 @@
>>>>> 
>>>>> #ifndef __ASM_ARM_MACRO_H__
>>>>> #define __ASM_ARM_MACRO_H__
>>>>> +
>>>>> +#include <asm/system.h>
>>>>> +
>>>>> #ifdef __ASSEMBLY__
>>>>> 
>>>>> /*
>>>>> @@ -135,13 +138,18 @@ lr    .req    x30
>>>>> #endif
>>>>> .endm
>>>>> 
>>>>> -.macro armv8_switch_to_el2_m, xreg1
>>>>> -    /* 64bit EL2 | HCE | SMD | RES1 (Bits[5:4]) | Non-secure EL0/EL1
>>>> */
>>>>> -    mov    \xreg1, #0x5b1
>>>>> -    msr    scr_el3, \xreg1
>>>>> +/*
>>>>> + * Switch from EL3 to EL2 for ARMv8
>>>>> + * @ep:     kernel entry point
>>>>> + * @arch:   machine nr
>>>>> + * @ftaddr: fdt address
>>>>> + * @flag:   The execution state flag for lower exception
>>>>> + *          level, ES_TO_AARCH64 or ES_TO_AARCH32
>>>>> + */
>>>>> +.macro armv8_switch_to_el2_m, ep, arch, ftaddr, flag, xreg5
>>>> 
>>>> You're never really using the arch and ftaddr arguments. Just
>>>> describe in the macro header that they need to be in x1 and x2
>>>> respectively and leave them out of the argument list for the macro.
>>> [Alison Wang] Do you mean rename arch and ftaddr to x1 and x2 here?
>> 
>> I mean omit arch and ftaddr from the macro arguments and instead mention
>> that x1 and x2 get passed as x1 and x2 to the guest and are usually
>> "ftaddr" and "arch".
>> 
>> Also it would make the code more consistent to always use ep.
> [Alison Wang] I don't think arch and ftaddr can be removed from the
> macro arguments in the current code. For 32-bit kernel startup entry
> point, the requirements are: r0 = 0, r1 = machine nr, r2 = atags or
> dtb pointer.

You don't refer to them, so they can be removed. Don't remove them from the function prototype - only from the macro.

Or if you find it too confusing to read then, pass a struct that contains ep, x0, x1, x2 and load the values from there.

Alex




More information about the U-Boot mailing list