u-boot引導(dǎo)VxWorks分析
準(zhǔn)備工作
在定義CONFIG_MP的情況下,u-boot會(huì)依次調(diào)用init_sequence_r里定義的初始化函數(shù)
執(zhí)行路徑為:board_init_r() -> cpu_init_r() -> setup_mp()
setup_mp()做以下操作:
調(diào)用determine_mp_bootpg(),使用(2G-4K)的地址作為bootpg的地址
調(diào)用如下代碼,獲得__bootpg_addr和__spin_table_addr的物理地址
并將這些地址填充到物理內(nèi)存當(dāng)中,供啟動(dòng)slave core時(shí),release.s去使用(在該core上創(chuàng)建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();
調(diào)用find_tlb_idx((void *)CONFIG_BPTR_VIRT_ADDR, 1),
查找目前配置的TLB entry一個(gè)TLB當(dāng)中,覆蓋了bootpg的virtual addr的TLB
- 若找到,則將該TLB使無(wú)效,并重配一個(gè)TLB(vir:CONFIG_BPTR_VIRT_ADDR <-> phy:bootpg)
- 若未找到,則無(wú)法啟動(dòng)slave core
將bootpg的代碼:__secondary_start_page 復(fù)制到 CONFIG_BPTR_VIRT_ADDR
調(diào)用plat_mp_up()
- 查找當(dāng)前bootpg使用的LAW,由于當(dāng)前的bootpg放置在內(nèi)存中,因此LAW的target_id對(duì)應(yīng)于DDR
- 設(shè)置LAW為對(duì)應(yīng)的屬性到bstrar; /* Boot space translation attributes */
- 關(guān)閉目標(biāo)CPU core的time base
- 設(shè)置brrl為啟動(dòng)的目標(biāo)CPU core
- ... //此時(shí)應(yīng)該目標(biāo)CPU core已經(jīng)從hold_off狀態(tài)激活, 并在對(duì)應(yīng)的CPU core的spin table寫1
- 等待目標(biāo)CPU core是否已經(jīng)啟動(dòng)完成,否則打印timeout
- 重新使能CPU core的time base
目標(biāo)CPU core上運(yùn)行的bootpg(4k)的流程:
4k的代碼范圍:start: __secondary_start_page end: __secondary_reset_vector
spin_table對(duì)應(yīng)的virtual start: __spin_table end:__spin_table_end
spin_table的大?。篊ONFIG_MAX_CPUS * ENTRY_SIZE
- 首先是4字節(jié)的跳轉(zhuǎn),從__secondary_reset_vector執(zhí)行:b __secondary_start_page
- 使無(wú)效L1 指令和數(shù)據(jù) cache
- 建立新的TLB entry,使之可以訪問(wèn)__bootpg_addr和__spin_table_addr
- 代碼跳轉(zhuǎn)到__bootpg_addr物理地址去運(yùn)行,即運(yùn)行:__second_half_boot_page
- 獲取到__spin_table,然后對(duì)目標(biāo)CPU core所屬的BOOT_ENTRY_ADDR_LOWER位域賦值為1
li r8,1
msync
stw r8,ENTRY_ADDR_LOWER(r10)
- 相當(dāng)于table[cpu * NUM_BOOT_ENTRY + BOOT_ENTRY_ADDR_LOWER] = 1
- 至此目標(biāo)CPU core進(jìn)入spin loop狀態(tài),等待core0再次release core 0一旦執(zhí)行"cpu 1 release 0x201002e8 2 1 1"
即對(duì)目標(biāo)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
- 目標(biāo)CPU core再將它所對(duì)應(yīng)的的BOOT_ENTRY_ADDR_LOWER位域賦值為3
/* mark the entry as released */
li r8,3
stw r8,ENTRY_ADDR_LOWER(r10)
- 相當(dāng)于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()會(huì)去根據(jù)bootm_headers所指向的加載目標(biāo)image的OS類型
對(duì)應(yīng)于boot_os[os],該數(shù)組保存加載相應(yīng)各個(gè)OS類型的函數(shù)指針
對(duì)于VxWorks來(lái)說(shuō),就是do_bootm_vxworks()
- 如果定義了CONFIG_FIT,則do_bootm_vxworks()函數(shù)會(huì)先去判斷image的頭信息是否有效 然后執(zhí)行do_bootvx_fdt(images)
- 如果未定義CONFIG_FIT,則直接執(zhí)行do_bootvx_fdt(images)
do_bootvx_fdt(images) 會(huì)依次調(diào)用下面的函數(shù):
-> boot_prep_vxworks(images)
-> boot_jump_vxworks(images)
boot_prep_vxworks(images)做以下操作:
1. 查找FDT里/memory這個(gè)節(jié)點(diǎn),若沒(méi)有找到,則會(huì)創(chuàng)建該節(jié)點(diǎn),
設(shè)置起始地址為:gd->bd->bi_memstart
設(shè)置大小為:gd->bd->bi_memsize
2. 執(zhí)行ft_fixup_cpu(),在定義了CONFIG_OF_LIBFDT的情況下:
調(diào)用get_spin_phys_addr(),獲得__spin_table的物理地址,賦值給spin_tbl_addr
調(diào)用determine_mp_bootpg(),使用(2G-4K)的地址作為bootpg的地址
該函數(shù)查找FDT里"device_type"為"cpu"這一項(xiàng),獲取"reg"代表的thread的值
對(duì)于E6500,thread/2即為物理的core的值,作為phys_cpu_id,
根據(jù)val = phys_cpu_id * SIZE_BOOT_ENTRY + spin_tbl_addr;
將enable_method設(shè)置為"spin-table";
將cpu-release-addr的值賦值為val
3. 執(zhí)行ft_fixup_num_cores()
cpu_numcores() -> hweight32(cpu_mask())
其中cpu_mask() -> compute_ppc_cpumask()返回cpu的cpu->mask
hweight32()會(huì)返回32bit的cpu->mask當(dāng)中有多少個(gè)bit被置位
則cpu_numcores()返回當(dāng)前cpu上有多少個(gè)core
將cpu core的信息填充到FDT里"device_type"為"cpu"這一項(xiàng)
4. 執(zhí)行flush_cache,將data cache里的dirty數(shù)據(jù)(修改的FDT數(shù)據(jù))刷新到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);