u-boot引导VxWorks分析
扫描二维码
随时随地手机看文章
准备工作
在定义CONFIG_MP的情况下,u-boot会依次调用init_sequence_r里定义的初始化函数
执行路径为:board_init_r() -> cpu_init_r() -> setup_mp()
setup_mp()做以下操作:
调用determine_mp_bootpg(),使用(2G-4K)的地址作为bootpg的地址
调用如下代码,获得__bootpg_addr和__spin_table_addr的物理地址
并将这些地址填充到物理内存当中,供启动slave core时,release.s去使用(在该core上创建TLB)
/*
* Store the bootpg's cache-able half address for use by secondary
* CPU cores to continue to boot
*/
__bootpg_addr = (u32)virt_to_phys(&__second_half_boot_page);
/* Store spin table's physical address for use by secondary cores */
__spin_table_addr = (u32)get_spin_phys_addr();
调用find_tlb_idx((void *)CONFIG_BPTR_VIRT_ADDR, 1),
查找目前配置的TLB entry一个TLB当中,覆盖了bootpg的virtual addr的TLB
- 若找到,则将该TLB使无效,并重配一个TLB(vir:CONFIG_BPTR_VIRT_ADDR <-> phy:bootpg)
- 若未找到,则无法启动slave core
将bootpg的代码:__secondary_start_page 复制到 CONFIG_BPTR_VIRT_ADDR
调用plat_mp_up()
- 查找当前bootpg使用的LAW,由于当前的bootpg放置在内存中,因此LAW的target_id对应于DDR
- 设置LAW为对应的属性到bstrar; /* Boot space translation attributes */
- 关闭目标CPU core的time base
- 设置brrl为启动的目标CPU core
- ... //此时应该目标CPU core已经从hold_off状态激活, 并在对应的CPU core的spin table写1
- 等待目标CPU core是否已经启动完成,否则打印timeout
- 重新使能CPU core的time base
目标CPU core上运行的bootpg(4k)的流程:
4k的代码范围:start: __secondary_start_page end: __secondary_reset_vector
spin_table对应的virtual start: __spin_table end:__spin_table_end
spin_table的大小:CONFIG_MAX_CPUS * ENTRY_SIZE
- 首先是4字节的跳转,从__secondary_reset_vector执行:b __secondary_start_page
- 使无效L1 指令和数据 cache
- 建立新的TLB entry,使之可以访问__bootpg_addr和__spin_table_addr
- 代码跳转到__bootpg_addr物理地址去运行,即运行:__second_half_boot_page
- 获取到__spin_table,然后对目标CPU core所属的BOOT_ENTRY_ADDR_LOWER位域赋值为1
li r8,1
msync
stw r8,ENTRY_ADDR_LOWER(r10)
- 相当于table[cpu * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER] = 1
- 至此目标CPU core进入spin loop状态,等待core0再次release core 0一旦执行"cpu 1 release 0x201002e8 2 1 1"
即对目标CPU core所属的BOOT_ENTRY_ADDR_LOWER位域填充cpu-release-addr的值
/* spin waiting for addr */
3:
lwz r4,ENTRY_ADDR_LOWER(r10)
andi. r11,r4,1
bne 3b
isync
- 目标CPU core再将它所对应的的BOOT_ENTRY_ADDR_LOWER位域赋值为3
/* mark the entry as released */
li r8,3
stw r8,ENTRY_ADDR_LOWER(r10)
- 相当于table[cpu * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER] = 3
u-boot命令
bootm -> do_bootm() -> do_bootm_states() -> bootm_os_get_boot_func()
其中bootm_os_get_boot_func()会去根据bootm_headers所指向的加载目标image的OS类型
对应于boot_os[os],该数组保存加载相应各个OS类型的函数指针
对于VxWorks来说,就是do_bootm_vxworks()
- 如果定义了CONFIG_FIT,则do_bootm_vxworks()函数会先去判断image的头信息是否有效 然后执行do_bootvx_fdt(images)
- 如果未定义CONFIG_FIT,则直接执行do_bootvx_fdt(images)
do_bootvx_fdt(images) 会依次调用下面的函数:
-> boot_prep_vxworks(images)
-> boot_jump_vxworks(images)
boot_prep_vxworks(images)做以下操作:
1. 查找FDT里/memory这个节点,若没有找到,则会创建该节点,
设置起始地址为:gd->bd->bi_memstart
设置大小为:gd->bd->bi_memsize
2. 执行ft_fixup_cpu(),在定义了CONFIG_OF_LIBFDT的情况下:
调用get_spin_phys_addr(),获得__spin_table的物理地址,赋值给spin_tbl_addr
调用determine_mp_bootpg(),使用(2G-4K)的地址作为bootpg的地址
该函数查找FDT里"device_type"为"cpu"这一项,获取"reg"代表的thread的值
对于E6500,thread/2即为物理的core的值,作为phys_cpu_id,
根据val = phys_cpu_id * SIZE_BOOT_ENTRY + spin_tbl_addr;
将enable_method设置为"spin-table";
将cpu-release-addr的值赋值为val
3. 执行ft_fixup_num_cores()
cpu_numcores() -> hweight32(cpu_mask())
其中cpu_mask() -> compute_ppc_cpumask()返回cpu的cpu->mask
hweight32()会返回32bit的cpu->mask当中有多少个bit被置位
则cpu_numcores()返回当前cpu上有多少个core
将cpu core的信息填充到FDT里"device_type"为"cpu"这一项
4. 执行flush_cache,将data cache里的dirty数据(修改的FDT数据)刷新到DDR
flush_cache((unsigned long)images->ft_addr, images->ft_len);
boot_jump_vxworks(images)做以下操作:
/* PowerPC VxWorks boot interface conforms to the ePAPR standard
* general purpuse registers:
*
* r3: Effective address of the device tree image
* r4: 0
* r5: 0
* r6: ePAPR magic value
* r7: shall be the size of the boot IMA in bytes
* r8: 0
* r9: 0
* TCR: WRC = 0, no watchdog timer reset will occur
*/
((void (*)(void *, ulong, ulong, ulong,
ulong, ulong, ulong))images->ep)(images->ft_addr,
0, 0, EPAPR_MAGIC, getenv_bootm_mapsize(), 0, 0);
激活VxWorks的步骤
=> tftpboot 0x20100000 vxWorks.st.bin && cpu 1 release 0x201002e8 2 1 1
步骤1:
tftpboot -> do_tftpb() -> netboot_common() -> bootm_maybe_autostart() -> do_bootm()
步骤2:
cpu -> cpu_cmd() -> cpu_release()
cpu release [args]
- Release cpu at with [args]
[args] :
pir - processor id (if writeable)
r3 - value for gpr 3
r6 - value for gpr 6
Use '-' for any arg if you want the default value.
Default for r3 is and r6 is 0
When cpu is released r4 and r5 = 0.
r7 will contain the size of the initial mapped area
cpu_release()做以下操作:
table[BOOT_ENTRY_ADDR_UPPER] = (u32)(boot_addr >> 32);
/* ensure all table updates complete before final address write */
eieio();
table[BOOT_ENTRY_ADDR_LOWER] = (u32)(boot_addr & 0xffffffff);