ILD

uboot传递bootargs过程
作者:Yuan Jianpeng 邮箱:yuanjp89@163.com
发布时间:2022-5-24 站点:Inside Linux Development

这里是arm平台,fit image格式,fit image包含kernel,initramfs,和device tree blob。那uboot的bootargs环境变量是怎么传递给内核的呢?


common/cmd_bootm.c

    do_bootm()

        -》do_bootm_states()


common/bootm.c

    do_bootm_states()

        -》bootm_start()

        -》 bootm_find_os()读取内核

        -》bootm_find_other()读取initramfs,dtb。

        boot_fn = bootm_os_get_boot_func(images->os.os);

        

common/bootm_os.c

    bootm_os_get_boot_func()

        return boot_os[os];


    static boot_os_fn *boot_os[] = {

        [IH_OS_LINUX] = do_bootm_linux,

    }


arch/arm/lib/bootm.c

    do_bootm_linux()

        -》boot_prep_linux(images);

            -》image_setup_linux(images)


common/image.c

    image_setup_linux()

        -》ret = image_setup_libfdt(images, *of_flat_tree, of_size, lmb);


common/image-fdt.c

    image_setup_libfdt()

        -》fdt_chosen(blob)

    这个函数会更新device tree中的各种参数,不仅仅是chosen。


common/fdt_support.c

    int fdt_chosen(void *fdt)

        str = getenv("bootargs")

        nodeoffset = fdt_find_or_add_subnode(fdt, 0, "chosen");

        err = fdt_setprop(fdt, nodeoffset, "bootargs", str, strlen(str) + 1);


fdt_chosen()这个函数最终将bootargs设置到device tree的chosen节点的bootargs里面。在内核里面,可以查看:

# cat /sys/firmware/devicetree/base/chosen/bootargs

ubi.mtd=rootfs_1 root=mtd:ubi_rootfs rootfstype=squashfs rootwait uart_en=1


总结:bootargs是通过修改device tree的chosen.bootargs。伴随device tree传递给内核的。device tree是通过r2寄存器传递给内核的。


Copyright © linuxdev.cc 2017-2024. Some Rights Reserved.