• uboot入口boot flow(ARMv8)


    uboot入口boot flow(ARMv8)

    uboot entry point是_start,这个在u-boot.lds里有define

    _start里执行b reset跳转到reset label处执行

    19 .globl    _start
    20 _start:
    21 #if defined(CONFIG_LINUX_KERNEL_IMAGE_HEADER)
    22 #include <asm/boot0-linux-kernel-header.h>
    23 #elif defined(CONFIG_ENABLE_ARM_SOC_BOOT0_HOOK)
    24 /*
    25  * Various SoCs need something special and SoC-specific up front in
    26  * order to boot, allow them to set that in their boot0.h file and then
    27  * use it here.
    28  */
    29 #include <asm/arch/boot0.h>
    30 #else
    31     b    reset
    32 #endif

    u-boot-2019.04\arch\arm\cpu\armv8\u-boot.lds

    OUTPUT_ARCH(aarch64)
    ENTRY(_start)
    SECTIONS

    reset label里会调用switch_el、lowlevel_init(define本文件,start.S),然后bl _main

    104     switch_el x1, 3f, 2f, 1f
    105 3:    set_vbar vbar_el3, x0
    106     mrs    x0, scr_el3
    107     orr    x0, x0, #0xf            /* SCR_EL3.NS|IRQ|FIQ|EA */
    108     msr    scr_el3, x0
    109     msr    cptr_el3, xzr            /* Enable FP/SIMD */
    110 #ifdef COUNTER_FREQUENCY
    111     ldr    x0, =COUNTER_FREQUENCY
    112     msr    cntfrq_el0, x0            /* Initialize CNTFRQ */
    113 #endif
    114     b    0f
    115 2:    set_vbar    vbar_el2, x0
    116     mov    x0, #0x33ff
    117     msr    cptr_el2, x0            /* Enable FP/SIMD */
    118     b    0f
    119 1:    set_vbar    vbar_el1, x0
    120     mov    x0, #3 << 20
    121     msr    cpacr_el1, x0            /* Enable FP/SIMD */
    122 0:
    ...
    148     /* Processor specific initialization */
    149     bl    lowlevel_init
    ...
    168 master_cpu:
    169     bl    _main

    _main()主要所做的事情如下:

    1. 设置relocation前的sp(初始stack pointer),此时的sp将是这一阶段运行的stack,然后调用board_init_f设置relocation相关的gd成员(gd->relocaddr/gd->reloc_off/gd->start_addr_sp/gd->new_gd)

    2. 设置relocation的sp(gd->start_addr_sp),此时的sp将是之后uboot运行的stack(top),之后调用relocate_code完成uboot relocation

    3. 调用board_init_r,第一参数的值是gd指针,第二个参数为gd->relocaddr

    66 ENTRY(_main)
    79     ldr    x0, =(CONFIG_SYS_INIT_SP_ADDR)
    80 #endif
    81     bic    sp, x0, #0xf    /* 16-byte alignment for ABI compliance */
    82     mov    x0, sp
    83     bl    board_init_f_alloc_reserve
    84     mov    sp, x0
    85     /* set up gd here, outside any C code */
    86     mov    x18, x0
    87     bl    board_init_f_init_reserve
    88 
    89     mov    x0, #0
    90     bl    board_init_f
    ...
    92 #if !defined(CONFIG_SPL_BUILD)
    93 /*
    94  * Set up intermediate environment (new sp and gd) and call
    95  * relocate_code(addr_moni). Trick here is that we'll return
    96  * 'here' but relocated.
    97  */
    98     ldr    x0, [x18, #GD_START_ADDR_SP]    /* x0 <- gd->start_addr_sp */
    99     bic    sp, x0, #0xf    /* 16-byte alignment for ABI compliance */
    100     ldr    x18, [x18, #GD_NEW_GD]        /* x18 <- gd->new_gd */
    102     adr    lr, relocation_return
    110     /* Add in link-vs-relocation offset */
    111     ldr    x9, [x18, #GD_RELOC_OFF]    /* x9 <- gd->reloc_off */
    112     add    lr, lr, x9    /* new return address after relocation */
    113     ldr    x0, [x18, #GD_RELOCADDR]    /* x0 <- gd->relocaddr */
    114     b    relocate_code
    115 
    116 relocation_return:
    140 /*
    141  * Clear BSS section
    142  */
    143     ldr    x0, =__bss_start        /* this is auto-relocated! */
    144     ldr    x1, =__bss_end            /* this is auto-relocated! */
    145 clear_loop:
    146     str    xzr, [x0], #8
    147     cmp    x0, x1
    148     b.lo    clear_loop
    149 
    150     /* call board_init_r(gd_t *id, ulong dest_addr) */
    151     mov    x0, x18                /* gd_t */
    152     ldr    x1, [x18, #GD_RELOCADDR]    /* dest_addr */
    153     b    board_init_r            /* PC relative jump */
    154 
    155     /* NOTREACHED - board_init_r() does not return */
    156 #endif
    157 
    158 ENDPROC(_main)
  • 相关阅读:
    log4j不生成日志文件的问题
    前端得到或者改变组件的值
    取list的值
    idea Library XXXXXXXX has broken classes paths
    session.save()返回值问题
    Intellij Error:Cannot build Artifact 'XXX:war exploded' because it is included into a circular dependency
    shell小结
    python操作rabbitMQ小结
    python+rabbitMQ实现生产者和消费者模式
    Python操作rabbitmq消息队列持久化
  • 原文地址:https://www.cnblogs.com/aspirs/p/16368590.html
Copyright © 2020-2023  润新知