uboot移植-内存分布

时间:2022-12-28 23:49:36

设置堆栈 uboot内存使用图

 1、uboot第一阶段start.S

       设置堆栈

       stack_setup:

                 ldr   r0, _TEXT_BASE            /* upper 128 KiB: relocated uboot   */

                 sub  r0, r0, #CONFIG_SYS_MALLOC_LEN   /* malloc area                */

                 sub  r0, r0, #CONFIG_SYS_GBL_DATA_SIZE /*  跳过全局数据区               */

       #ifdef CONFIG_USE_IRQ

                sub  r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)

     #endif

                 sub  sp, r0, #12           /* leave 3 words for abort-stack    */只要将sp指针指向一段没有被使用的内存就完成栈的设置了。

 

注:在配置文件tx244.h定义

             #define CONFIG_SYS_MALLOC_LEN  (CONFIG_ENV_SIZE + 128*1024)=192Kbyte
             #define CONFIG_SYS_GBL_DATA_SIZE 128 /* size in bytes reserved for initial data */

            #define CONFIG_ENV_SIZE   0x20000

 

2、uboot第二阶段 start_armboot()

      设置全局变量gd

        gd = (gd_t*)(_armboot_start - CONFIG_SYS_MALLOC_LEN - sizeof(gd_t));
       __asm__ __volatile__("": : :"memory");

        memset ((void*)gd, 0, sizeof (gd_t));//将gd所指向内存区域的前gd_t所需空间  置零
        gd->bd = (bd_t*)((char*)gd - sizeof(bd_t)); //申请bd_t区间
        memset (gd->bd, 0, sizeof (bd_t));

        gd->flags |= GD_FLG_RELOC; //Code was relocated to RAM   表示代码已经搬运到RAM中

        monitor_flash_len = _bss_start - _armboot_start;//计算uboot代码length

 

      根据上面的代码可以知道U-Boot内存使用情况了,如下图所示:

                        uboot移植-内存分布

         注:1、用户堆区_bss_start、_end地址如何得到?根据uboot.lds链接脚本,知道分布位置。但具体地址由编译后得到。             

                   uboot.lds内容:

                  OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
                   OUTPUT_ARCH(arm)
                   ENTRY(_start)
                   SECTIONS
                   {
                     。。。。。。。。。。。。。。。。。

                    . = ALIGN(4);
                   __bss_start = .;
                 .bss (NOLOAD) : { *(.bss) . = ALIGN(4); }
                 _end = .;
                  }

               2、查看uboot.map编译后地址

                 uboot移植-内存分布

                                                                          _bss_start地址

 

                uboot移植-内存分布

                                                 _end地址

其中1、gd_t结构说明:

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;



           2、bd_t结构说明:

typedef struct bd_info {
int bi_baudrate; /* serial console baudrate */
unsigned long bi_ip_addr; /* IP Address */
struct environment_s *bi_env;
ulong bi_arch_number; /* unique id for this board */
ulong bi_boot_params; /* where this board expects params */
struct /* RAM configuration */
{
ulong start;
ulong size;
} bi_dram[CONFIG_NR_DRAM_BANKS];
} bd_t;