在继续分析之前,先回顾一下当前相关寄存器的值、内存空间的使用情况和相关变量的值的情况。
Registers:r0 = 0r9 = 0x42BF_FF60 @ &gdr13 = &( bl mmu_turn_on ) @ /uboot-root/arch/arm/cpu/slsiap/s5p4418/start.Ssp = 0x42BF_FF60lr = &( bl board_init_f ) @ /uboot-root/arch/arm/cpu/slsiap/s5p4418/start.SRAM:0xC000_0000-0x5000_0000(RAM_TOP)-0x4FFE_F800UBOOT(Reserve 478K)0x4FF7_8000-0x4FFF_4000TLB table0x4FFF_0000-0x4DF9_8000malloc(Reserve 32768K)0x4DF7_8000Board Info(Reserve 80B) = gd->bd0x4DF7_7FB0New GD0x4DF7_7F10IRQ0x4DF7_7F00(IRQ_SP)-0x4DF7_7EF0(START_ADDR_SP)UBOOT0x42C0_0000GD0x42BF_FF60UBoot-Stack0x4000_0000
gd值:
bd_t *bd{unsigned long bi_memstart = 0phys_size_t bi_memsize = 0unsigned long bi_flashstart = 0unsigned long bi_flashsize = 0unsigned long bi_flashoffset = 0unsigned long bi_sramstart = 0unsigned long bi_sramsize = 0unsigned long bi_bootflags = 0unsigned long bi_ip_addr = 0unsigned char bi_enetaddr[6] = 0unsigned short bi_ethspeed = 0unsigned long bi_intfreq = 0unsigned long bi_busfreq = 0ulong bi_arch_number = 0ulong bi_boot_params = 0struct bi_dram[1]{ulong start = 0ulong size = 0}}unsigned long flags = 0unsigned int baudrate = 115200unsigned long cpu_clk = 0unsigned long bus_clk = 0unsigned long pci_clk = 0unsigned long mem_clk = 0unsigned long have_console = 1unsigned long env_addr = &default_environment[0]unsigned long env_valid = 1unsigned long ram_top = 0x5000_0000unsigned long relocaddr = 0x4FF7_8000phys_size_t ram_size = 0x1000_0000unsigned long mon_len = 0x0007_7988unsigned long irq_sp = 0x4DF7_7F00unsigned long start_addr_sp = 0x4df7_7EF0unsigned long reloc_off = 0struct global_data *new_gd = 0x4df7_7f10const void *fdt_blob = 0void *new_fdt = 0unsigned long fdt_size = 0void **jt = 0char env_buf[32] = 0unsigned long timebase_h = 0unsigned long timebase_l = 0struct arch_global_data arch{unsigned long timer_rate_hz = 0unsigned long tbu = 0unsigned long tbl = 0unsigned long lastinc = 0unsigned long long timer_reset_value = 0unsigned long tlb_addr = 0x4fff_0000unsigned 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 = 0phys_size_t bi_memsize = 0unsigned long bi_flashstart = 0unsigned long bi_flashsize = 0unsigned long bi_flashoffset = 0unsigned long bi_sramstart = 0unsigned long bi_sramsize = 0unsigned long bi_bootflags = 0unsigned long bi_ip_addr = 0unsigned char bi_enetaddr[6] = 0unsigned short bi_ethspeed = 0unsigned long bi_intfreq = 0unsigned long bi_busfreq = 0ulong bi_arch_number = 4330ulong bi_boot_params = 0x4000_0100struct bi_dram[1]{ulong start = 0x4000_0000ulong size = 0x4000_0000}}unsigned long flags = 0unsigned int baudrate = 115200unsigned long cpu_clk = 0unsigned long bus_clk = 0unsigned long pci_clk = 0unsigned long mem_clk = 0unsigned long have_console = 1unsigned long env_addr = &default_environment[0]unsigned long env_valid = 1unsigned long ram_top = 0x5000_0000unsigned long relocaddr = 0x4FF7_8000phys_size_t ram_size = 0x1000_0000unsigned long mon_len = 0x0007_7988unsigned long irq_sp = 0x4DF7_7F00unsigned long start_addr_sp = 0x4df7_7EF0unsigned long reloc_off = 0struct global_data *new_gd = 0x4df7_7f10const void *fdt_blob = 0void *new_fdt = 0unsigned long fdt_size = 0void **jt = 0char env_buf[32] = 0unsigned long timebase_h = 0unsigned long timebase_l = 0struct arch_global_data arch{unsigned long timer_rate_hz = 0unsigned long tbu = 0unsigned long tbl = 0unsigned long lastinc = 0unsigned long long timer_reset_value = 0unsigned long tlb_addr = 0x4fff_0000unsigned 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 = 0phys_size_t bi_memsize = 0unsigned long bi_flashstart = 0unsigned long bi_flashsize = 0unsigned long bi_flashoffset = 0unsigned long bi_sramstart = 0unsigned long bi_sramsize = 0unsigned long bi_bootflags = 0unsigned long bi_ip_addr = 0unsigned char bi_enetaddr[6] = 0unsigned short bi_ethspeed = 0unsigned long bi_intfreq = 0unsigned long bi_busfreq = 0ulong bi_arch_number = 4330ulong bi_boot_params = 0x4000_0100struct bi_dram[1]{ulong start = 0x4000_0000ulong size = 0x4000_0000}}unsigned long flags = 0unsigned int baudrate = 115200unsigned long cpu_clk = 0unsigned long bus_clk = 0unsigned long pci_clk = 0unsigned long mem_clk = 0unsigned long have_console = 1unsigned long env_addr = &default_environment[0]unsigned long env_valid = 1unsigned long ram_top = 0x5000_0000unsigned long relocaddr = 0x4ff7_8000phys_size_t ram_size = 0x1000_0000unsigned long mon_len = 0x0007_7988unsigned long irq_sp = 0x4DF7_7F00unsigned long start_addr_sp = 0x4df7_7EF0unsigned long reloc_off = 0x0D37_8000struct global_data *new_gd = 0x4df7_7f10const void *fdt_blob = 0void *new_fdt = 0unsigned long fdt_size = 0void **jt = 0char env_buf[32] = 0unsigned long timebase_h = 0unsigned long timebase_l = 0struct arch_global_data arch{unsigned long timer_rate_hz = 0unsigned long tbu = 0unsigned long tbl = 0unsigned long lastinc = 0unsigned long long timer_reset_value = 0unsigned long tlb_addr = 0x4fff_0000unsigned long tlb_size = 0x0000_4000}
到这里,init_sequence_f[]里的所有函数全部调用完毕。回忆相关的寄存器值:
r0 = 0r9 = 0x42BF_FF60 @ &gdr13 = &( bl mmu_turn_on ) @ /uboot-root/arch/arm/cpu/slsiap/s5p4418/start.Ssp = 0x42BF_FF60lr = &( 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 @ &gdr1 = 0x42C0_0000r2 = 0x42BF_FF10 @ &spr9 = 0x42BF_FF60 @ &gdr13 = &( bl mmu_turn_on ) @ /uboot-root/arch/arm/cpu/slsiap/s5p4418/start.Ssp = 0x42BF_FF10lr = &( bl gdt_reset ) @ /uboot-root/arch/arm/cpu/slsiap/s5p4418/start.SRAM:0xC000_0000-
0x5000_0000(RAM_TOP)-
0x4FFE_F800UBOOT(Reserve 478K)0x4FF7_8000-
0x4FFF_4000TLB table0x4FFF_0000-
0x4DF9_8000malloc(Reserve 32768K)0x4DF7_8000Board Info(Reserve 80B) = gd->bd0x4DF7_7FB0New GD0x4DF7_7F10IRQ0x4DF7_7F00(IRQ_SP)-
0x4DF7_7EF0(START_ADDR_SP)UBOOT0x42C0_0000GD0x42BF_FF60BD Info0x42BF_FF10UBoot-Stack0x4000_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%08lxn", heap_end-TOTAL_MALLOC_LEN, heap_end);printf("Code = 0x%08lx~0x%08lxn", text_start, text_end);printf("GLD = 0x%08lxn", (ulong)gd);printf("GLBD = 0x%08lxn", (ulong)gd->bd);printf("SP = 0x%08lx,0x%08lx(CURR)n", gd->start_addr_sp, sp);printf("PC = 0x%08lxn", pc);printf("TAGS = 0x%08lx n", gd->bd->bi_boot_params);ulong page_tlb = (text_end & 0xffff0000) + 0x10000;printf("PAGE = 0x%08lx~0x%08lxn", 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 = 0phys_size_t bi_memsize = 0unsigned long bi_flashstart = 0unsigned long bi_flashsize = 0unsigned long bi_flashoffset = 0unsigned long bi_sramstart = 0unsigned long bi_sramsize = 0unsigned long bi_bootflags = 0unsigned long bi_ip_addr = 0unsigned char bi_enetaddr[6] = 0unsigned short bi_ethspeed = 0unsigned long bi_intfreq = 0unsigned long bi_busfreq = 0ulong bi_arch_number = 4330ulong bi_boot_params = 0x4000_0100struct bi_dram[1]{ulong start = 0x4000_0000ulong size = 0x4000_0000}}unsigned long flags = 0unsigned int baudrate = 115200unsigned long cpu_clk = 0unsigned long bus_clk = 0unsigned long pci_clk = 0unsigned long mem_clk = 0unsigned long have_console = 1unsigned long env_addr = &default_environment[0]unsigned long env_valid = 1unsigned long ram_top = 0x5000_0000unsigned long relocaddr = 0x4500_0000phys_size_t ram_size = 0x1000_0000unsigned long mon_len = 0x0007_7988unsigned long irq_sp = 0x4DF7_7F00unsigned long start_addr_sp = 0x42BF_FF10unsigned long reloc_off = 0struct global_data *new_gd = 0x4df7_7f10const void *fdt_blob = 0void *new_fdt = 0unsigned long fdt_size = 0void **jt = 0char env_buf[32] = 0unsigned long timebase_h = 0unsigned long timebase_l = 0struct arch_global_data arch{unsigned long timer_rate_hz = 0unsigned long tbu = 0unsigned long tbl = 0unsigned long lastinc = 0unsigned long long timer_reset_value = 0unsigned long tlb_addr = 0x4fff_0000unsigned long tlb_size = 0x0000_4000}
接下来是刷新dcache和输出内存空间表:
RAM:0xC000_0000-0x5000_0000(RAM_TOP)-0x4FFE_F800UBOOT(Reserve 478K)0x4FF7_8000-0x4FFF_4000TLB table0x4FFF_0000-0x4DF9_8000malloc(Reserve 32768K)0x4DF7_8000Board Info(Reserve 80B) = gd->bd0x4DF7_7FB0New GD0x4DF7_7F10IRQ0x4DF7_7F00(IRQ_SP)-0x4DF7_7EF0-0x4500_0000Heap0x4300_0000-0x42C8_C000Page0x42C8_0000-0x42C7_7988UBOOT0x42C0_0000GD0x42BF_FEB8BD Info0x42BF_FE68(START_ADDR_SP)UBoot-Stack0x4000_0000
接下来UBoot又返回 /uboot-root/arch/arm/cpu/slsiap/s5p4418/start.S 继续执行。由于之后又是一个新的阶段,本节暂告一段落。
本文发布于:2024-02-01 12:13:49,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170676082936517.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |