kernel ping pong boot(bootloader kernel 传递参数)

bootloader 传递不同参数 kernel挂载不同数据

使用U-boot作为kernel bootloader,对于3.5以后的kernel,uboot支持扁平设备树(FDT),Linux内核对设备树进行解析解析因此当bootloader传递的参数比较少时,可以通过在FDT中添加自定义参数,然后再在kernel中进行解析。具体做法如下:

在u-boot中,include/fdt.h中,有如下结构体:

struct fdt_header {
fdt32_t magic;/* magic word FDT_MAGIC */
fdt32_t totalsize;/* total size of DT block */
fdt32_t off_dt_struct;/* offset to structure */
fdt32_t off_dt_strings;/* offset to strings */
fdt32_t off_mem_rsvmap;/* offset to memory reserve map */
fdt32_t version;/* format version */
fdt32_t last_comp_version;/* last compatible version */


/* version 2 fields below */
fdt32_t boot_cpuid_phys;/* Which physical CPU id we're
   booting on */
/* version 3 fields below */
fdt32_t size_dt_strings;/* size of the strings block */


/* version 17 fields below */
fdt32_t size_dt_struct;/* size of the structure block */


/* add for ivy ping-pong boot  */
fdt32_t flag_ppboot;
};

如上,添加了flag_ppboot的u32参数,在common/image-fdt.c中,对该结构体reloacte,

int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size),在boot kernel的过程中,

uboot将fdt保存到reserve的memory,供kernel使用。

在kernel的include/linux/of_fdt.h中,同样有fdt_header对应的结构体,

struct boot_param_header {
__be32 magic; /* magic word OF_DT_HEADER */
__be32 totalsize; /* total size of DT block */
__be32 off_dt_struct; /* offset to structure */
__be32 off_dt_strings; /* offset to strings */
__be32 off_mem_rsvmap; /* offset to memory reserve map */
__be32 version; /* format version */
__be32 last_comp_version; /* last compatible version */
/* version 2 fields below */
__be32 boot_cpuid_phys; /* Physical CPU id we're booting on */
/* version 3 fields below */
__be32 dt_strings_size; /* size of the DT strings block */
/* version 17 fields below */
__be32 dt_struct_size; /* size of the DT structure block */
/* ivy ping-pong boot support */
__be32 flag_ppboot;
};

在该结构体中同样添加flag_ppboot的参数,kernel在driver/of/fdt.c中解析uboot的fdt_header,

获取flag_ppboot,这样参数就被传递给了kernel.

[Note*]:对于少数的参数,这样传递应该没有问题,但是,如果参数很多时,可能就需要reserve一段

memory了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值