RT ROM boot简介
目錄
- ROM Boot process
- Get boot mode
- 讀取fuse,確定HAB是否使能
- Get boot device
- Boot類(lèi)型綜述
- Primary boot
- Redundant boot
- Secondary boot
- Recovery boot
- MFG boot
- Plugin boot
- Serial download
imx-RT是恩智浦新出的一款基于M7內(nèi)核的芯片,其特點(diǎn)是高性能,低售價(jià)。
目前是MCU市場(chǎng)上一款炙手可熱的芯片。
本文針對(duì)RT ROM做一些介紹。
具體內(nèi)容如下:
- Boot流程
- 各種類(lèi)型的boot
- image架構(gòu)
ROM Boot process
Get boot mode
上電后,Boot_mode撥碼的值會(huì)自動(dòng)加載到SBMR2寄存器中,ROM讀取SBMR2[25:24]來(lái)決定boot_mode
RT支持四種啟動(dòng)模式
- Boot from fuse。 根據(jù)fuse中的boot device進(jìn)行boot
- Serial download。 ROM進(jìn)入detect mode,等待上位機(jī)跟ROM通信。
- internal boot。 根據(jù)boot device撥碼進(jìn)行boot
- Test mode。 ROM will run into loop
- ROM讀取SBMR2
#define HAPI_SRC_get_bootmode() ((SRC->SBMR2 & SBMR2_BMOD_MASK) >> SBMR2_BMOD_SHIFT)
SRC->SBMR2右移24位截取bit[25:24]得到boot_mode
讀取fuse,確定HAB是否使能
hab_rvt.report_status(&hab_config, NULL);
HAB - high assurance boot.
一旦開(kāi)啟HAB,簽名的image需要ROM認(rèn)證后才能boot。
Get boot device
ROM支持的boot device有
flexspi nand、flexspi nor、SEMC nand、SEMC nor、SD、EMMC、EEP
如果BT_FUSE_SEL沒(méi)有燒寫(xiě),boot device撥碼的值會(huì)加載到SBMR1寄存器中。
否則,fuse 0x450關(guān)于boot device的值會(huì)加載到SBMR1中
ROM根據(jù)SRC->SBMR1寄存器的值來(lái)判斷boot device- Boot device初始化代碼
pu_irom_setup_boot_selection(); Boot device撥碼
講到這里,我們來(lái)回顧下。
首先,上電后板子會(huì)自動(dòng)將boot_mode的信息加載到SBMR2寄存器中。將boot_device的值加載到SBMR1中
關(guān)于boot device分兩種情況。
ROM會(huì)根據(jù)SBMR2中的信息來(lái)確定boot mode,然后根據(jù)SBMR1中值確定boot device
從對(duì)應(yīng)的device boot或者進(jìn)入相應(yīng)的boot mode
Boot類(lèi)型綜述
Primary boot
FlexSPINor\Nand boot,SD\EMMC boot
FlexSPI nor可以選擇XIP boot。其他的device都是Non-XIPboot。。即image需要從boot device中搬到RAM中執(zhí)行
Nand支持redundant boot,最多給4次boot機(jī)會(huì)
SD、EMMC支持secondary boot,在offset 0x200處重新制定image的存儲(chǔ)架構(gòu)。EMMC支持fast boot
Redundant boot
primary boot失敗后進(jìn)入redundant boot。只有燒寫(xiě)了支持redundant boot的fuse后,才能進(jìn)入此種boot。Boot device一般都是EEPROM
MFG boot
如上boot 失敗后,會(huì)從SD卡中嘗試最后一次boot。
Plug-in boot
ROM支持的boot device只有flexspi nand\nor等等。。但是想要支持其他的boot device,比如從USB boot的話(huà)ROM是否支持呢。Plug-in boot的存在目的就是如此。
plug-in boot的話(huà)需要兩個(gè)image。
一個(gè)image存在ROM支持的boot device上,這個(gè)image的目的是用來(lái)初始化USB,將USB的數(shù)據(jù)讀取到RAM中。
第二個(gè)image存儲(chǔ)在USB中,這個(gè)就是用來(lái)boot的image
Primary boot
- 支持XIP的device,FlexSPI nor, SEMC nor
以FlexSPI nor為例,ROM從0x60000000處讀取12K數(shù)據(jù)。從0x60001000處獲取IVT,根據(jù)IVT中的boot data進(jìn)行數(shù)據(jù)處理。如果boot image運(yùn)行地址在nor上,則進(jìn)行XIP。否則將image copy到ram中boot - 不支持XIP的device,FlexSPI nand等
ROM從device中讀取2K數(shù)據(jù)到0x20208000處,然后從0x20208400處獲取IVT。根據(jù)IVT中的boot data將boot image coppy對(duì)應(yīng)的運(yùn)行地址進(jìn)行boot
Redundant boot
- nand 支持redundant boot。給4次boot機(jī)會(huì)
- NAND FCB會(huì)制定image的存儲(chǔ),備份信息。
- ROM根據(jù)FCB找到對(duì)應(yīng)的block,根據(jù)IVT將image復(fù)制到對(duì)應(yīng)的運(yùn)行地址。如果boot失敗,ROM會(huì)根據(jù)FCB查找下一個(gè)備份的image,然后進(jìn)行boot
- redundant register用來(lái)標(biāo)記當(dāng)前是第幾次boot。 Bit[23:22]= 0b00表示第一份image,以此類(lèi)推。
UINT32 redundant_boot = get_persist_redundant_boot_value();
while (++redundant_boot <= REDUNDANT_IMG_IDX_MAX)
{
/* Set secondary image persistent bit /
set_persist_redundant_boot_value(redundant_boot);
/ Add secondary image log entry /
pu_irom_log_add((pu_irom_log_entry_t)(ROM_LOG_PRIM_IMAGE_SELECT + redundant_boot));
/ Try download secondary image /
if (download_initial_image() == TRUE)
{
/ Update data_ptr on success /
data_ptr = (hab_ivt_v0_t )((UINT32)driver_data->initial_image_address + driver_data->ivt_offset);
break;
}
}
Secondary boot
- SD emmc支持secondary boot。Normal boot制定image base address為0x0,IVT offset為0x400.ROM會(huì)從0x0處讀取數(shù)據(jù),抓取0x400處的IVT來(lái)得到boot information。
Secondary boot table位于offset0x200處。ROM第一次從0x400獲取IVT后,如果boot失敗,則從0x200處獲取table,table中可以重定義image base address為firstSectorNumber。那么ROM就會(huì)從firstSectorNumber處獲取image。
舉例說(shuō)明:
結(jié)構(gòu)體里面的數(shù)據(jù)是小端模式。
SD\EMMC 一個(gè)block的長(zhǎng)度為0x200
Tag : 0x00112233
FirstSectorNumber :
EMMC的image start address = 0x8000 IVT offset = 0x400
Table address = 0x200
設(shè)定secondary start address為0x9000,則firstSectorNumber為:
(0x9000-0x8000) /0x200 = 8
secondary table如下
typedef struct {UINT32 chipNum; /* Chip Select, ROM does not use it */UINT32 driveType; /* Always system drive, ROM does not use it */UINT32 tag; /* Tag, must be 0x584D2E69 (i.MX) */UINT32 firstSectorNumber; /* Block address of secondary image, block size is 512B */UINT32 sectorCount; /* Not used by ROM */ } SECONDARY_IMG_TBL_T;Recovery boot
使能這個(gè)fuse即可。如果promary boot失敗,ROM會(huì)從recovery boot device中進(jìn)行boot。
EEPROM_RECOVERY_EN
MFG boot
所有primary、recovery boot失敗后,從SD boot。
Plugin boot
這個(gè)boot類(lèi)型是為了滿(mǎn)足ROM從不支持的device中boot。
- 當(dāng)配置IVT中BootData的plugin為1時(shí)。bootRom支持boot plugimage
- Plug-in boot需要兩個(gè)image
- 供ROM boot的image,IVT, base address等都需要根據(jù)ROM的規(guī)定制定。此處的image就是沒(méi)有使用plug in功能時(shí)的boot image。
只不過(guò)這個(gè)image的功能不是我們常用的點(diǎn)燈,而是將IVT,base address,image length指向plug in image。如果有需要的話(huà),還需要對(duì)存放plugin image的設(shè)備進(jìn)行初始化 - plug-in image
當(dāng)1中的image制定了plug-in image的base address, IVT offset, image length后。BOOTROM對(duì)這個(gè)image認(rèn)證后,執(zhí)行此image
示例
依照ROM的規(guī)則做第一個(gè)image
int main(uint32_t **start, uint32_t *bytes, uint32_t *ivt_offset) { *start = (uint32_t *)0x60004000; *bytes = 0x5000; *ivt_offset = 0x1000; return 1; }第二個(gè)image的功能為點(diǎn)燈,image中斷向量地址為NOR中的0x60006000。給這個(gè)image加上IVT,IVT的存儲(chǔ)地址設(shè)置為0x60005000,image的base address設(shè)置為0x60004000
將第一個(gè)image燒寫(xiě)到0x6000000處,第二個(gè)image燒寫(xiě)到0x60004000處。reset 板子,plug-in boot即可成功。
我們來(lái)分析下image是如何運(yùn)行的。
Serial download
ROM 進(jìn)到這個(gè)模式后,會(huì)等待上位機(jī)通訊。支持USB跟UART。
可以通過(guò)SD\P_host上位機(jī)的write_filem命令將image寫(xiě)到RAM中,然后Jump_addr命令執(zhí)行image
讀到這里,我們應(yīng)該知道了primary boot,recovery boot,MFG boot,Plug-in boot
- primary boot中,SD、EMMC支持secondary boot。NAND 支持redundant boot。這兩種boot我們都可以通過(guò)persist register來(lái)查看使用第幾份image進(jìn)行boot。
- recovery boot是在primary boot失敗后的一種boot,需要開(kāi)啟recovery boot的fuse
- MFG boot呢,就是如上如上兩個(gè)boot都失敗,ROM給與的最后一次boot。它從SD boot
- plug-in boot則是為了讓ROM支持目前未曾支持的device,需要兩份image。第一份image的IVT中需要開(kāi)啟plug-in boot flag。
我們用Nor模擬了這種boot。plug-in boot支持如上所有的boot類(lèi)型 - 如果所有boot都失敗的話(huà),ROM會(huì)進(jìn)入serial download等待上位機(jī)與其通信。可以使用上位機(jī)燒寫(xiě)image到RAM中,然后運(yùn)行RAM中的image。
關(guān)于RT的boot 流程,boot類(lèi)型就介紹到此。下個(gè)章節(jié)我們來(lái)談?wù)刬mage的架構(gòu),看看ROM是如何根據(jù)IVT的內(nèi)容進(jìn)行boot的。
轉(zhuǎn)載于:https://www.cnblogs.com/richard-xiong/p/9542603.html
總結(jié)
以上是生活随笔為你收集整理的RT ROM boot简介的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 图中长度为k的路径的计数
- 下一篇: RK3288 双屏异显,两屏默认方向不一