内核参数cmdline/command_line怎么传递到内核?

参考: 

linux kernel中的cmdline的详细介绍_kernel command line-CSDN博客

cmdline(二):uboot cmdline怎么传?&&cmdline kernel怎么用?-CSDN博客

linux kernel的启动参数是怎么拿到的-以arm64为例 - 半山随笔 - 博客园 (cnblogs.com)

Kernel怎么解析这个传过来的参数呢?

(1)、跳转linux kernel之前-准备cmdline
在跳转linux kernel之前(如uboot中),将cmdline数据放到了FDT中,然后将FDT的地址写入到了X0中。然后再跳转linux kernel.

请看kernel-4.14/Documentation/arm64/booting.txt

Before jumping into the kernel, the following conditions must be met:

- Quiesce all DMA capable devices so that memory does not get
  corrupted by bogus network packets or disk data.  This will save
  you many hours of debug.

- Primary CPU general-purpose register settings
  x0 = physical address of device tree blob (dtb) in system RAM.
  x1 = 0 (reserved for future use)
  x2 = 0 (reserved for future use)
  x3 = 0 (reserved for future use)

arm64即时采用uefi也依然会通过fdt传递内核参数:

/sys/firmware/fdt

/dts-v1/;
// magic:        0xd00dfeed
// totalsize:        0x29d (669)
// off_dt_struct:    0x38
// off_dt_strings:    0x1c8
// off_mem_rsvmap:    0x28
// version:        17
// last_comp_version:    17
// boot_cpuid_phys:    0x0
// size_dt_strings:    0xd5
// size_dt_struct:    0x190

/ {
    #size-cells = <0x00000002>;
    #address-cells = <0x00000002>;
    chosen {
        linux,uefi-mmap-desc-ver = <0x00000001>;
        linux,uefi-mmap-desc-size = <0x00000030>;
        linux,uefi-mmap-size = <0x00000f90>;
        linux,uefi-mmap-start = <0x00000000 0xf67b1018>;
        linux,uefi-system-table = <0x00000000 0xfbfe0018>;
        bootargs = "BOOT_IMAGE=/vmlinuz-5.15.0-g8223071764d2-dirty root=UUID=e50cdacd-1591-485d-8b81-f6c611309734 ro video=VGA-1:640x480-32@60me cgroup_disable=files apparmor=0 crashkernel=1024M,high smmu.bypassdev=0x1000:0x17 smmu.bypassdev=0x1000:0x15 console=tty0";
        linux,initrd-end = <0x00000000 0xef09a6e3>;
        linux,initrd-start = <0x00000000 0xedc1b000>;
    };
};

uefi将内核当成efi文件执行入口: 


efi_pe_entry:
{
    cmdline_ptr = efi_convert_cmdline(image, &cmdline_size); //获取cmdline 启动参数
 
    efi_info("Booting Linux Kernel...\n");

    si = setup_graphics();

    status = handle_kernel_image(&image_addr, &image_size,
                                     &reserve_addr,
                                     &reserve_size,
                                     image);                 //重新将内核镜像移动位置,地址保存在image_addr

    
    status = allocate_new_fdt_and_exit_boot(handle, &fdt_addr,
                                                initrd_addr, initrd_size,
                                                cmdline_ptr, fdt_addr, fdt_size);
            
            
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

古井无波1999

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值