Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux 程式設計 >> Linux 程式設計

FL2440 板子上 U-Boot 在記憶體中的分布解析

當 U-Boot 從 NAND Flash 開機時,硬體會自動把 NAND Flash 前 0x1000 Byte(即 4KB)複製到 'Steppingstone' 中。'Steppingstone' 有兩個起始位址映射,一個是 0x0,另一個是 0x40000000。此時 PC 會跳轉到 0x0,也就是 'Steppingstone' 的起始位置,執行這 4KB 的程式碼。這段程式碼負責初始化 CPU 模式與時鐘等。值得一提的是此時的堆疊初始化:sp 直接指向 0x33f0fffC(即 STACK_BASE+STACK_SIZE-4),fp 則為 0x0,也就是 'Steppingstone' 的起始位址。關於 FP(frame pointer)的介紹可參考 https://www.linuxidc.com/Linux/2013-03/81247.htm 。

接著,程式會把 NAND Flash 起始 0x0 位置起、長度 0x60000(#define LENGTH_UBOOT 0x60000)的內容複製到 0x33f80000(TEXT_BASE)。64MB 的 SDRAM 掛在 NGCS6 上,NGCS6 的起始位址是 0x30000000,因此 SDRAM 的範圍是 0x30000000 到 0x34000000。由於 0x34000000 - 0x33f80000 = 0x80000 大於 U-Boot 的程式碼空間 0x60000,兩者相差 0x20000,也就是 U-Boot 高處還空著 0x20000。

值得注意的是,'Steppingstone' 中那 4KB 程式碼複製完自己之後,並沒有立刻跳到 0x33f80000 執行,而是先在 SDRAM 中初始化堆疊(這是第二次初始化堆疊)。sp 的計算方式為:

sp = _TEXT_BASE - CONFIG_SYS_MALLOC_LEN - CONFIG_SYS_GBL_DATA_SIZE /* -(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ),因為沒有用到中斷而註解掉 */ - 12(保留 3 words 給 abort-stack)

= 0x33f80000 - (0x10000 + 0x4000) - 0x80 - 0xc = 0x33f6bf74(sp 尚未設定)。.rodata、.data、.got、.u_boot_cmd、.bss 等段在 arch/arm/cpu/arm920t/u-boot.lds 中定義,位於 U-Boot 程式碼段之後,緊貼在 0x33fe0000 之前。

在 start_armboot 中有一個全域資料指標:gd = (gd_t*)(_armboot_start - CONFIG_SYS_MALLOC_LEN - sizeof(gd_t)),依上述分析它位於 global_data 的頂端。這個指標所指向的 global_data 結構如下:

typedef struct global_data {
    bd_t            *bd;
    unsigned long   flags;
    unsigned long   baudrate;
    unsigned long   have_console;   /* serial_init() was called */
    unsigned long   env_addr;       /* Address of Environment struct */
    unsigned long   env_valid;      /* Checksum of Environment valid? */
    unsigned long   fb_base;        /* base address of frame buffer */
#ifdef CONFIG_VFD
    unsigned char   vfd_type;       /* display type */
#endif
#ifdef CONFIG_FSL_ESDHC
    unsigned long   sdhc_clk;
#endif
#if 0
    unsigned long   cpu_clk;        /* CPU clock in Hz! */
    unsigned long   bus_clk;
    phys_size_t     ram_size;       /* RAM size */
    unsigned long   reset_status;   /* reset status register at boot */
#endif
    void            **jt;           /* jump table */
} gd_t;
Copyright © Linux教程網 All Rights Reserved