NanoPC-T2 Uboot启动过程分析 - 2-4 init_sequence_f[] part 2

在继续分析之前,先回顾一下当前相关寄存器的值、内存空间的使用情况和相关变量的值的情况。


Registers:

r0 = 0

r9 = 0x42BF_FF60 @ &gd

r13 = &( bl mmu_turn_on ) @ /uboot-root/arch/arm/cpu/slsiap/s5p4418/start.S

sp = 0x42BF_FF60

lr = &( bl board_init_f ) @ /uboot-root/arch/arm/cpu/slsiap/s5p4418/start.S

RAM:

0xC000_0000

 -

0x5000_0000(RAM_TOP)

 -

0x4FFE_F800

 UBOOT(Reserve 478K)

0x4FF7_8000

 -

0x4FFF_4000

 TLB table

0x4FFF_0000

 -

0x4DF9_8000

 malloc(Reserve 32768K)

0x4DF7_8000

 Board Info(Reserve 80B) = gd->bd

0x4DF7_7FB0

 New GD

0x4DF7_7F10

 IRQ

0x4DF7_7F00(IRQ_SP)

 -

0x4DF7_7EF0(START_ADDR_SP)

 UBOOT

0x42C0_0000

 GD

0x42BF_FF60

 UBoot-Stack

0x4000_0000

gd值:


bd_t *bd

{

unsigned long bi_memstart = 0

phys_size_t bi_memsize = 0

unsigned long bi_flashstart = 0

unsigned long bi_flashsize = 0

unsigned long bi_flashoffset = 0

unsigned long bi_sramstart = 0

unsigned long bi_sramsize = 0

unsigned long bi_bootflags = 0

unsigned long bi_ip_addr = 0

unsigned char bi_enetaddr[6] = 0

unsigned short bi_ethspeed = 0

unsigned long bi_intfreq = 0

unsigned long bi_busfreq = 0

ulong bi_arch_number = 0

ulong bi_boot_params = 0

struct bi_dram[1]

{

ulong start = 0

ulong size = 0

}

}

unsigned long flags = 0

unsigned int baudrate = 115200

unsigned long cpu_clk = 0

unsigned long bus_clk = 0

unsigned long pci_clk = 0

unsigned long mem_clk = 0

unsigned long have_console = 1

unsigned long env_addr = &default_environment[0]

unsigned long env_valid = 1

unsigned long ram_top = 0x5000_0000

unsigned long relocaddr = 0x4FF7_8000

phys_size_t ram_size = 0x1000_0000

unsigned long mon_len = 0x0007_7988

unsigned long irq_sp = 0x4DF7_7F00

unsigned long start_addr_sp = 0x4df7_7EF0

unsigned long reloc_off = 0

struct global_data *new_gd = 0x4df7_7f10

const void *fdt_blob = 0

void *new_fdt = 0

unsigned long fdt_size = 0

void **jt = 0

char env_buf[32] = 0

unsigned long timebase_h = 0

unsigned long timebase_l = 0

struct arch_global_data arch

{

unsigned long timer_rate_hz = 0

unsigned long tbu = 0

unsigned long tbl = 0

unsigned long lastinc = 0

unsigned long long timer_reset_value = 0

unsigned long tlb_addr = 0x4fff_0000

unsigned long tlb_size = 0x0000_4000

}

现在继续分析位于 \/uboot-root\/common\/board_f.c 中的 init_sequence_f[] 中的 setup_dram_config() 。这个函数调用了位于 \/uboot-root\/arch\/arm\/cpu\/slsiap\/s5p4418\/cpu.c 中的 dram_init_banksize()。主要更新了 gd 中的成员,与DRAM、架构号和启动参数位置有关。更新后的内容如下:


bd_t *bd

{

unsigned long bi_memstart = 0

phys_size_t bi_memsize = 0

unsigned long bi_flashstart = 0

unsigned long bi_flashsize = 0

unsigned long bi_flashoffset = 0

unsigned long bi_sramstart = 0

unsigned long bi_sramsize = 0

unsigned long bi_bootflags = 0

unsigned long bi_ip_addr = 0

unsigned char bi_enetaddr[6] = 0

unsigned short bi_ethspeed = 0

unsigned long bi_intfreq = 0

unsigned long bi_busfreq = 0

ulong bi_arch_number = 4330

ulong bi_boot_params = 0x4000_0100

struct bi_dram[1]

{

ulong start = 0x4000_0000

ulong size = 0x4000_0000

}

}

unsigned long flags = 0

unsigned int baudrate = 115200

unsigned long cpu_clk = 0

unsigned long bus_clk = 0

unsigned long pci_clk = 0

unsigned long mem_clk = 0

unsigned long have_console = 1

unsigned long env_addr = &default_environment[0]

unsigned long env_valid = 1

unsigned long ram_top = 0x5000_0000

unsigned long relocaddr = 0x4FF7_8000

phys_size_t ram_size = 0x1000_0000

unsigned long mon_len = 0x0007_7988

unsigned long irq_sp = 0x4DF7_7F00

unsigned long start_addr_sp = 0x4df7_7EF0

unsigned long reloc_off = 0

struct global_data *new_gd = 0x4df7_7f10

const void *fdt_blob = 0

void *new_fdt = 0

unsigned long fdt_size = 0

void **jt = 0

char env_buf[32] = 0

unsigned long timebase_h = 0

unsigned long timebase_l = 0

struct arch_global_data arch

{

unsigned long timer_rate_hz = 0

unsigned long tbu = 0

unsigned long tbl = 0

unsigned long lastinc = 0

unsigned long long timer_reset_value = 0

unsigned long tlb_addr = 0x4fff_0000

unsigned long tlb_size = 0x0000_4000

}

接下来调用的是 show_dram_config()。这里主要是输出DRAM的信息,因此不详细展开。

接下来调用的是 display_new_sp()。这里主要是输出栈的信息,因此忽略。

接下来调用的是 reloc_fdt()。由于gd->new_fdt=0,因此这里没有动作,忽略。

接下来调用的是 setup_reloc()。这里是一个关键的地方。首先先更新gd->reloc_off,然后将整个gd的内容复制到之前保留的gd->new_gd的地址上,即0x4df7_7f10。以下是更新后的gd内容:


bd_t *bd

{

unsigned long bi_memstart = 0

phys_size_t bi_memsize = 0

unsigned long bi_flashstart = 0

unsigned long bi_flashsize = 0

unsigned long bi_flashoffset = 0

unsigned long bi_sramstart = 0

unsigned long bi_sramsize = 0

unsigned long bi_bootflags = 0

unsigned long bi_ip_addr = 0

unsigned char bi_enetaddr[6] = 0

unsigned short bi_ethspeed = 0

unsigned long bi_intfreq = 0

unsigned long bi_busfreq = 0

ulong bi_arch_number = 4330

ulong bi_boot_params = 0x4000_0100

struct bi_dram[1]

{

ulong start = 0x4000_0000

ulong size = 0x4000_0000

}

}

unsigned long flags = 0

unsigned int baudrate = 115200

unsigned long cpu_clk = 0

unsigned long bus_clk = 0

unsigned long pci_clk = 0

unsigned long mem_clk = 0

unsigned long have_console = 1

unsigned long env_addr = &default_environment[0]

unsigned long env_valid = 1

unsigned long ram_top = 0x5000_0000

unsigned long relocaddr = 0x4ff7_8000

phys_size_t ram_size = 0x1000_0000

unsigned long mon_len = 0x0007_7988

unsigned long irq_sp = 0x4DF7_7F00

unsigned long start_addr_sp = 0x4df7_7EF0

unsigned long reloc_off = 0x0D37_8000

struct global_data *new_gd = 0x4df7_7f10

const void *fdt_blob = 0

void *new_fdt = 0

unsigned long fdt_size = 0

void **jt = 0

char env_buf[32] = 0

unsigned long timebase_h = 0

unsigned long timebase_l = 0

struct arch_global_data arch

{

unsigned long timer_rate_hz = 0

unsigned long tbu = 0

unsigned long tbl = 0

unsigned long lastinc = 0

unsigned long long timer_reset_value = 0

unsigned long tlb_addr = 0x4fff_0000

unsigned long tlb_size = 0x0000_4000

}

到这里,init_sequence_f[]里的所有函数全部调用完毕。回忆相关的寄存器值:


r0 = 0

r9 = 0x42BF_FF60 @ &gd

r13 = &( bl mmu_turn_on ) @ /uboot-root/arch/arm/cpu/slsiap/s5p4418/start.S

sp = 0x42BF_FF60

lr = &( bl board_init_f ) @ /uboot-root/arch/arm/cpu/slsiap/s5p4418/start.S

根据 lr 的值,UBoot重新回到 \/uboot-root\/arch\/arm\/cpu\/slsiap\/s5p4418\/start.S 继续执行,其代码如下:


    mov sp, r9 /* SP is GD's base address */

    bic sp, sp, #7 /* 8-byte alignment for ABI compliance */    

    sub sp, #GENERATED_BD_INFO_SIZE /* allocate one BD above SP */

    bic sp, sp, #7 /* 8-byte alignment for ABI compliance */

    mov r0, r9 /* gd_t *gd */

    ldr r1, TEXT_BASE /* ulong text */

    mov r2, sp /* ulong sp */

    bl gdt_reset

以上的代码更新了一些寄存器,并为调用 gdt_reset() 准备参数。因此,在调用最后一条指令时,相关寄存器的值和内存使用空间如下:


r0 = 0x42BF_FF60 @ &gd

r1 = 0x42C0_0000

r2 = 0x42BF_FF10 @ &sp

r9 = 0x42BF_FF60 @ &gd

r13 = &( bl mmu_turn_on ) @ /uboot-root/arch/arm/cpu/slsiap/s5p4418/start.S

sp = 0x42BF_FF10

lr = &( bl gdt_reset ) @ /uboot-root/arch/arm/cpu/slsiap/s5p4418/start.S

RAM:

0xC000_0000

 -

0x5000_0000(RAM_TOP)

 -

0x4FFE_F800

 UBOOT(Reserve 478K)

0x4FF7_8000

 -

0x4FFF_4000

 TLB table

0x4FFF_0000

 -

0x4DF9_8000

 malloc(Reserve 32768K)

0x4DF7_8000

 Board Info(Reserve 80B) = gd->bd

0x4DF7_7FB0

 New GD

0x4DF7_7F10

 IRQ

0x4DF7_7F00(IRQ_SP)

 -

0x4DF7_7EF0(START_ADDR_SP)

 UBOOT

0x42C0_0000

 GD

0x42BF_FF60

 BD Info

0x42BF_FF10

 UBoot-Stack

0x4000_0000

gdt_reset()位于 \/uboot-root\/arch\/arm\/cpu\/slsiap\/s5p4418\/cpu.c 中。其代码如下:


void gdt_reset(gd_t *gd, ulong text, ulong sp)

{

 ulong text_start, text_end, heap_end;

 ulong bd;

 /* for smp cores */

 global_descriptor = gd;

 /* reconfig stack info */

 gd->relocaddr = text;

 gd->start_addr_sp = sp;

 gd->reloc_off = 0;

 /* copy bd info */

 bd = (unsigned int)gd - sizeof(bd_t);

 memcpy((void *)bd, (void *)gd->bd, sizeof(bd_t));

 /* reset gd->bd */

 gd->bd = (bd_t *)bd;

 /* prevent dataabort, when access enva_addr + data (0x04) */

 gd->env_addr = (ulong)default_environment;

 /* get cpu info */

 text_start = (unsigned int)(gd->relocaddr);

 text_end = (unsigned int)(gd->relocaddr + _bss_end_ofs);

 heap_end = CONFIG_SYS_MALLOC_END;

 /* refer initr_malloc (common/board_r.c) */

 gd->relocaddr = heap_end;

 flush_dcache_all();

 ulong pc;

 asm("mov %0, pc":"=r" (pc));

 asm("mov %0, sp":"=r" (sp));

 printf("Heap = 0x%08lx~0x%08lx\n", heap_end-TOTAL_MALLOC_LEN, heap_end);

 printf("Code = 0x%08lx~0x%08lx\n", text_start, text_end);

 printf("GLD = 0x%08lx\n", (ulong)gd);

 printf("GLBD = 0x%08lx\n", (ulong)gd->bd);

 printf("SP = 0x%08lx,0x%08lx(CURR)\n", gd->start_addr_sp, sp);

 printf("PC = 0x%08lx\n", pc);

 printf("TAGS = 0x%08lx \n", gd->bd->bi_boot_params);

 ulong page_tlb = (text_end & 0xffff0000) + 0x10000;

 printf("PAGE = 0x%08lx~0x%08lx\n", page_tlb, page_tlb + 0xc000 );

 printf("MACH = [%ld] \n", gd->bd->bi_arch_number);

 printf("VER = %u \n", nxp_cpu_version());

 printf("BOARD= [%s] \n", CONFIG_SYS_BOARD);

}

这里首先先更新gd里的relocaddr、start_addr_sp和reloc_off。接下来将原本存储在gd->bd中的内容复制到0x42BF_FF10开始的地方,即内存空间使用表中的BD Info的位置,同时重新更新gd->bd指向的位置。此时gd的内容如下:


bd_t *bd = 0x42BF_FF10

{

unsigned long bi_memstart = 0

phys_size_t bi_memsize = 0

unsigned long bi_flashstart = 0

unsigned long bi_flashsize = 0

unsigned long bi_flashoffset = 0

unsigned long bi_sramstart = 0

unsigned long bi_sramsize = 0

unsigned long bi_bootflags = 0

unsigned long bi_ip_addr = 0

unsigned char bi_enetaddr[6] = 0

unsigned short bi_ethspeed = 0

unsigned long bi_intfreq = 0

unsigned long bi_busfreq = 0

ulong bi_arch_number = 4330

ulong bi_boot_params = 0x4000_0100

struct bi_dram[1]

{

ulong start = 0x4000_0000

ulong size = 0x4000_0000

}

}

unsigned long flags = 0

unsigned int baudrate = 115200

unsigned long cpu_clk = 0

unsigned long bus_clk = 0

unsigned long pci_clk = 0

unsigned long mem_clk = 0

unsigned long have_console = 1

unsigned long env_addr = &default_environment[0]

unsigned long env_valid = 1

unsigned long ram_top = 0x5000_0000

unsigned long relocaddr = 0x4500_0000

phys_size_t ram_size = 0x1000_0000

unsigned long mon_len = 0x0007_7988

unsigned long irq_sp = 0x4DF7_7F00

unsigned long start_addr_sp = 0x42BF_FF10

unsigned long reloc_off = 0

struct global_data *new_gd = 0x4df7_7f10

const void *fdt_blob = 0

void *new_fdt = 0

unsigned long fdt_size = 0

void **jt = 0

char env_buf[32] = 0

unsigned long timebase_h = 0

unsigned long timebase_l = 0

struct arch_global_data arch

{

unsigned long timer_rate_hz = 0

unsigned long tbu = 0

unsigned long tbl = 0

unsigned long lastinc = 0

unsigned long long timer_reset_value = 0

unsigned long tlb_addr = 0x4fff_0000

unsigned long tlb_size = 0x0000_4000

}

接下来是刷新dcache和输出内存空间表:


RAM:

0xC000_0000

 -

0x5000_0000(RAM_TOP)

 -

0x4FFE_F800

 UBOOT(Reserve 478K)

0x4FF7_8000

 -

0x4FFF_4000

 TLB table

0x4FFF_0000

 -

0x4DF9_8000

 malloc(Reserve 32768K)

0x4DF7_8000

 Board Info(Reserve 80B) = gd->bd

0x4DF7_7FB0

 New GD

0x4DF7_7F10

 IRQ

0x4DF7_7F00(IRQ_SP)

 -

0x4DF7_7EF0

 -

0x4500_0000

 Heap

0x4300_0000

 -

0x42C8_C000

 Page

0x42C8_0000

 -

0x42C7_7988

 UBOOT

0x42C0_0000

 GD

0x42BF_FEB8

 BD Info

0x42BF_FE68(START_ADDR_SP)

 UBoot-Stack

0x4000_0000

接下来UBoot又返回 /uboot-root/arch/arm/cpu/slsiap/s5p4418/start.S 继续执行。由于之后又是一个新的阶段,本节暂告一段落。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值