1.uboot启动内核的代码缩减如下:
Uboot 1.16/lib_arm/board.c中start_armboot()函数调用/common/main.c中main_loop()函数,在main_loop()中有uboot启动内核的代码:
s = getenv ("bootcmd");
debug ("### main_loop: bootcmd=\"%s\"\n", s ? s :"<UNDEFINED>");
if (bootdelay >= 0 && s && !abortboot (bootdelay))
{
run_command(s, 0);
}
2.假设bootcmd = nandread.jffs2 0x30007FC0 kernel; bootm 0x30007FC0
<1> nandread.jffs2 0x30007FC0 kernel
从nand读出内核:
从哪里读? : kernel分区
读到哪里去?:0x30007FC0
何为分区?
简单的说就是将nand划分为几个区域,一般如下:
bootloader->params->kernel->root
这些分区划分在/include/configs/100ask24x0.h中写死的:
#define MTDPARTS_DEFAULT"mtdparts=nandflash0:256k@0(bootloader)," \
"128k(params)," \
"2m(kernel)," \
"-(root)"
进入uboot执行mtd ,可以查看已有分区:
# name 大小 在nand上的起始地址
0 bootloader 0x00040000 0x00000000
1 params 0x00020000 0x00040000
2 kernel 0x00200000 0x00060000
3 root 0xfda00000 0x00260000
上面的nand read.jffs2 0x30007FC0 kernel等价于:
nand read.jffs20x30007FC0 0x00060000 0x00200000
注:read.jffs2并不是指定特定的格式, 仅表示不需要块/页对齐,所以kernel的分区大小可以随意定。
<2> bootm0x30007FC0
关键函数do_bootm()
flash上存的内核:uImage
uImage = 头部+真正的内核
头部的定义如下:
typedef struct image_header {
uint32_t ih_magic;
uint32_t ih_hcrc;
uint32_t ih_time;
uint32_t ih_size;
uint32_t ih_load;
uint32_t ih_ep;
uint32_t ih_dcrc;
uint8_t ih_os;
uint8_t ih_arch;
uint8_t ih_type;
uint8_t ih_comp;
uint8_t ih_name[IH_NMLEN];
} image_header_t;<