uboot boots kernel



. do_bootm函数读取image
int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
addr = simple_strtoul(argv[1], NULL, 16); // kernel flash地址


image_header_t *hdr = &header;
    // 从flash的addr读取image_header_t到header结构体中,read_dataflash函数的第三个参数是dest,或者是从RAM上复制
#ifdef CONFIG_HAS_DATAFLASH
if (addr_dataflash(addr)){
read_dataflash(addr, sizeof(image_header_t), (char *)&header);
} else
#endif
memmove (&header, (char *)addr, sizeof(image_header_t));

    // 读取image_header_t和image(应该是Linux kernel)到RAM地址CFG_LOAD_ADDR,注意这个宏没有定义也是可以的
#ifdef CONFIG_HAS_DATAFLASH
if (addr_dataflash(addr)){
len  = ntohl(hdr->ih_size) + sizeof(image_header_t); // hdr->ih_size是image的大小
read_dataflash(addr, len, (char *)CFG_LOAD_ADDR);
addr = CFG_LOAD_ADDR;
}
#endif
data = addr + sizeof(image_header_t);
len  = ntohl(hdr->ih_size);

switch (hdr->ih_comp) {
case IH_COMP_NONE:
if(ntohl(hdr->ih_load) == data) { // 如果image header结构中保存的image data的加载地址和地址data是一样的,XIP. 这里的data是RAM上的地址,而hdr->ih_load是kernel image的目标地址,一般是flash地址。
printf ("   XIP %s ... ", name);
        // 否则将image data复制到其加载地址hdr->ih_load(应该是flash上的),这种情况应该是直接把kernel下载到ram中,并没有
        // 烧录到flash上就执行启动kernel的命令了。
case IH_COMP_GZIP: // 如果是GZIP压缩格式的image
printf ("   Uncompressing %s ... ", name);
// 将RAM上的image data解压缩至hdr->ih_load(一般是在flash上),len是image data的长度
if (gunzip ((void *)ntohl(hdr->ih_load), unc_len,   // int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
   (uchar *)data, &len) != 0) {
   
    // 调用do_bootm_linux
    do_bootm_linux  (cmdtp, flag, argc, argv,
    addr, len_ptr, verify);
对于启动的image是kernel,addr是ram地址0x33000000;
len_ptr指向image header之后的data;
verify是环境变量verify。


. do_bootm函数主要做的事情
1. kernel flash地址读取image_header_t到header结构体;
2. 读取kernel包括image header和image data到RAM地址0x33000000;
3. 解压缩(如果必要)至image header结构hdr->ih_load指定的地址,这个地址一般在flash上;如果image data不是压缩的,将ram上的image data复制到hdr->ih_load地址;
4. 调用do_bootm_linux函数。




. image types(u-boot)
in include/image.h
/*
 * Image Types
 *
 * "Standalone Programs" are directly runnable in the environment
 * provided by U-Boot; it is expected that (if they behave
 * well) you can continue to work in U-Boot after return from
 * the Standalone Program.
 * "OS Kernel Images" are usually images of some Embedded OS which
 * will take over control completely. Usually these programs
 * will install their own set of exception handlers, device
 * drivers, set up the MMU, etc. - this means, that you cannot
 * expect to re-enter U-Boot except by resetting the CPU.
 * "RAMDisk Images" are more or less just data blocks, and their
 * parameters (address, size) are passed to an OS kernel that is
 * being started.
 * "Multi-File Images" contain several images, typically an OS
 * (Linux) kernel image and one or more data images like
 * RAMDisks. This construct is useful for instance when you want
 * to boot over the network using BOOTP etc., where the boot
 * server provides just a single image file, but you want to get
 * for instance an OS kernel and a RAMDisk image.
 *
 * "Multi-File Images" start with a list of image sizes, each
 * image size (in bytes) specified by an "uint32_t" in network
 * byte order. This list is terminated by an "(uint32_t)0".
 * Immediately after the terminating 0 follow the images, one by
 * one, all aligned on "uint32_t" boundaries (size rounded up to
 * a multiple of 4 bytes - except for the last file).
 *
 * "Firmware Images" are binary images containing firmware (like
 * U-Boot or FPGA images) which usually will be programmed to
 * flash memory.
 *
 * "Script files" are command sequences that will be executed by
 * U-Boot's command interpreter; this feature is especially
 * useful when you configure U-Boot to use a real shell (hush)
 * as command interpreter (=> Shell Scripts).
 */


#define IH_TYPE_INVALID 0 /* Invalid Image */
#define IH_TYPE_STANDALONE 1 /* Standalone Program */
#define IH_TYPE_KERNEL 2 /* OS Kernel Image */
#define IH_TYPE_RAMDISK 3 /* RAMDisk Image */
#define IH_TYPE_MULTI 4 /* Multi-File Image */
#define IH_TYPE_FIRMWARE 5 /* Firmware Image */
#define IH_TYPE_SCRIPT 6 /* Script file */
#define IH_TYPE_FILESYSTEM 7 /* Filesystem Image (any type) */
#define IH_TYPE_FLATDT 8 /* Binary Flat Device Tree Blob */





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值