uboot修改传递给内核的cmdline的方法

uboot修改传递给内核的cmdline的方法:

1.setenv bootargs

    /*将数组转化为字符串*/
    printf("setenv ipaddr!\n");
    ip4s_to_string(ip_addr_local,ip_addr_local_str);
    puts(ip_addr_local_str);
    printf("\n");
    /*设置ipaddr*/
    //env_set("ipaddr",ip_addr_local_str);
      
    strcpy(str,"setenv ipaddr ");
    strcat(str,ip_addr_local_str);
    result = run_command(str,0);

2.如何uboot使用了设备树,可以解析设备树中的bootargs节点,并对其进行编辑。

#include <common.h>
#include <libfdt.h>
#include <version_autogenerated.h>

extern unsigned int xilinx_ID;

#ifdef CONFIG_OF_BOARD_SETUP
int ft_board_setup(void *blob, bd_t *bd)
{
        int   nodeoffset;
    void *fdt = blob;
    /* just for test! When use, we set the addstr to be what we want */
    /* we must begin addstr with ' '! */
    char  addstr[64]=" BOOT_VERSION=";
  char  addstr1[64]=" XILINX_ID=";
        int   err;
        char  *str;     /* used to set string properties */

    strcat(addstr,U_BOOT_VERSION);
  sprintf (str, "%d",xilinx_ID);
    strcat(addstr1,str);
    strcat(addstr,addstr1);
    printf("ft_board_setup: %s\n",addstr);
    
    err = fdt_check_header(fdt);
    if (err < 0) {
        printf("fdt_chosen: %s\n", fdt_strerror(err));
        return err;
    }

    /* find or create "/chosen" node. */
    nodeoffset = fdt_find_or_add_subnode(fdt, 0, "chosen");
    if (nodeoffset < 0)
    {
        printf("ft_board_setup fdt_find_or_add_subnode <0\n");
        return nodeoffset;
    }

    //printf(" addstr = %s len=%d\n",addstr,strlen(addstr));
    err = fdt_appendprop(fdt, nodeoffset, "bootargs", addstr,
            strlen(addstr) + 1);
    if (err < 0) {
        printf("WARNING: could not set bootargs %s.\n",
            fdt_strerror(err));
        return err;
    }

    return 0;
}
#endif
 

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值