How uboot modifies the cmdline passed to the kernel

The method of uboot to modify the cmdline passed to the kernel:

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. How uboot uses the device tree, you can parse the bootargs node in the device tree and edit it.

#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
 

 

Guess you like

Origin blog.csdn.net/u014426028/article/details/110931584