让U-boot支持Nor Flash
这节的移植应该是最简单的,修改代码量最少。但是我们还是要对源码进行一个简单的分析。
首先紧接上一节最后的那张图,我们已经让U-boot可以从Nand Flash启动,然后打印出来的调试信息中Flash: 对应的就是Nor Flash的大小,NAND: 就是NAND FALSH的大小。这里发现NAND居然能识别出大小,但是如果我换为Nor启动以后,NAND就又识别不出来了,这边我们先不管他,这节主要还是针对Nor Flash。
首先查一下“Flash:”是在哪里打印的,然后经过分析我们可以得到一下函数调用关系:
注意:以下函数内都经过删减方便分析,只是分析,不需要修改代码
\common\board_r.c,第370行
static int initr_flash(void)
{
ulong flash_size = 0;
bd_t *bd = gd->bd;
puts("Flash: "); //在这里打印了"Flash: "字符串
if (board_flash_wp_on())
printf("Uninitialized - Write Protect On\n");
else
flash_size = flash_init(); //下一步函数调用
print_size(flash_size, "");
putc('\n');
/* update start of FLASH memory */
#ifdef CONFIG_SYS_FLASH_BASE
bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; //设置Nor Flash基地址也就是0x00000000
#endif
/* size of FLASH memory (final value) */
bd->bi_flashsize = flash_size;
#if defined(CONFIG_OXC) || defined(CONFIG_RMU)
/* flash mapped at end of memory map */
bd->bi_flashoffset = CONFIG_SYS_TEXT_BASE + flash_size;
#elif CONFIG_SYS_MONITOR_BASE == CONFIG_SYS_FLASH_BASE
bd->bi_flashoffset = monitor_flash_len; /* reserved area for monitor */
#endif
return 0;
}
我们查找“Flash:”字符串,然后定位到这个函数,接着这个函数调用flash_init();对Flash初始化和识别
\drivers\mtd\cfi_flash.c,第2348行
unsigned long flash_init (void)
{
unsigned long size = 0;
int i;
/* Init: no FLASHes known */
for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
flash_info[i].flash_id = FLASH_UNKNOWN;