uboot启动内核(3)

时间:2021-06-15 16:30:14

 

nand read.jffs2 0x30007FC0 kernel;

从NAND读出内核:从哪读,从kernel分区     

 放到哪去   -0x30007FC0  

nand read.jffs2 0x30007FC0   0x00200000      0x00060000  

device nand0 <nandflash0>, # parts = 4  

#: name                        size            offset          mask_flags  0: bootloader          0x00040000      0x00000000      0  

1: params              0x00020000      0x00040000      0  

2: kernel              0x00200000      0x00060000      0  

3: root                0x0fda0000      0x00260000      0

active partition: nand0,0 - (bootloader) 0x00040000 @ 0x00000000

defaults: mtdids  : nand0=nandflash0

mtdparts: mtdparts=nandflash0:256k@0(bootloader),128k(params),2m(kernel),-(root)

.jffs2 方便不用块对齐

bootm 0x30007FC0

flash内的内核,uimage 头部(64k) + 内核 0x30007FC0 是为了使内核的加载地址刚好为0x30008000 节省时间不必再把内核移动到加载地址

(1)根据头部移动内核到加载地址

(2)启动内核do_bootm_linux   

    1、u_boot告诉内核一些参数,设置启动阐述

     2、跳到入口地址启动内核    

 


setup_start_tag (bd);
setup_memory_tags (bd_t *bd)
setup_commandline_tag (bd_t *bd, char *commandline)
setup_end_tag (bd_t *bd)

 

struct tag {  

struct tag_header hdr;  

union {   

 struct tag_core  core;

  struct tag_mem32 mem;

  struct tag_videotext videotext;

  struct tag_ramdisk ramdisk;

  struct tag_initrd initrd;

  struct tag_serialnr serialnr;

  struct tag_revision revision;

  struct tag_videolfb videolfb;

  struct tag_cmdline cmdline;

  /*    * Acorn specific    */   struct tag_acorn acorn;

  /*    * DC21285 specific    */   struct tag_memclk memclk;

 } u;

 

struct tag_header {

 u32 size;

 u32 tag;

};

static void setup_start_tag (bd_t *bd)

{  params = (struct tag *) bd->bi_boot_params; ·  //开始开始存放地址

 params->hdr.tag = ATAG_CORE;             //0x54410001

 params->hdr.size = tag_size (tag_core);      //tag + size + core >>2 单位为4个字节

 params->u.core.flags = 0;

 params->u.core.pagesize = 0;

 params->u.core.rootdev = 0;

   params = tag_next (params);      //指向下一个tag

}

static void setup_memory_tags (bd_t *bd)

{

  int i;

  for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)

  {            //CONFIG_NR_DRAM_BANKS    1  

   params->hdr.tag = ATAG_MEM;     //0x54410002   

   params->hdr.size = tag_size (tag_mem32);      //

    params->u.mem.start = bd->bi_dram[i].start;     //0x30000000   

   params->u.mem.size = bd->bi_dram[i].size;      //大小为初始化自定值  0x04000000

    params = tag_next (params);  

 }

}

static void setup_commandline_tag (bd_t *bd, char *commandline)

{  

  char *p;                //char *commandline = getenv ("bootargs");

   if (!commandline)        //bootargs=noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0使用串口0  

     return;

   /* eat leading white space */  

  for (p = commandline; *p == ' '; p++);

   /* skip non-existent command lines so the kernel will still  

    * use its default command line.   */

   if (*p == '\0')   return;

   params->hdr.tag = ATAG_CMDLINE;     //0x54410009

   params->hdr.size =   (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;

   strcpy (params->u.cmdline.cmdline, p);

   params = tag_next (params); }

static void setup_end_tag (bd_t *bd)

{

   params->hdr.tag = ATAG_NONE;

   params->hdr.size = 0;

}

u_boot: 启动内核
1、从flash里读
2、启动
 a、设置启动参数
 b、跳跳到入口地址
 
 theKernel (0, bd->bi_arch_number, bd->bi_boot_params);
   bd->bi_boot_params 参数地址
   bd->bi_arch_number 机器id