向linux kernel中添加cmdline的四种方式

108 阅读1分钟

在linux启动时候,串口log中会打印cmdline

  1. [ 0.000000] c0 0 (swapper) Kernel command line: earlycon androidboot.selinux=permissive uart_dma keep_dbgclk_on clk_ignore_unused initrd=0xd0000000,38711808 rw crash_page=0x8f040000 initrd=/recoveryrc boot_reason=0x2000 ota_status=0x1001
    在linux启动完成后,通过 cat /proc/cmdline也是可以看到cmdline. 那么cmdline是如何添加的呢?

1、 在dts中的bootargs中添加

  1. / {
  2.  model = "xxx yyyyyyy FPGA";
    
  3.  compatible = "xxx ,yyyyy-fpga", "xxx ,yyyyyy";
    
  4.  chosen {
    
  5.      /*
    
  6.       * initrd parameters not set in dts file since the ramdisk.img size
    
  7.       * need to check in uboot, and the initrd load address and size will
    
  8.       * set in uboot stage.
    
  9.      */
    
  10.     bootargs = "earlycon androidboot.selinux=permissive uart_dma keep_dbgclk_on clk_ignore_unused";
    
  11.     stdout-path = "serial0:115200";
    
  12. };
    
  13. }
    2、在BoardConfig中添加
    vim device/xxx/xxx_evb/BoardConfigCommon.mk
  14. BOARD_KERNEL_CMDLINE += androidboot.selinux=enforcing androidboot.hardware=xxxxx_phone androidboot.dtbo_idx=0
    3、在uboot中添加
    vim u-boot/common/cmd_bootm.c
  15. append_bootargs(“recovery=1”);
  16. sprintf(dm_buf,“init=/init skip_initramfs rootwait root=/dev/dm-0 dm=“system none ro,0 1 android-verity /dev/mmcblk0p%d””,ret);
  17. append_bootargs((const char *)dm_buf);

4、在android的Makefile中添加
vim build/core/Makefile

  1. INTERNAL_KERNEL_CMDLINE := (strip (BOARDKERNELCMDLINE)buildvariant=(BOARDKERNELCMDLINE)buildvariant=(TARGETBUILDVARIANT)(strip (BOARDKERNELCMDLINE)buildvariant=(BOARDK​ERNELC​MDLINE)buildvariant=(TARGET_BUILD_VARIANT) (VERITY_KEYID))
  2. ifdef INTERNAL_KERNEL_CMDLINE
  3. INTERNAL_BOOTIMAGE_ARGS += --cmdline “$(INTERNAL_KERNEL_CMDLINE)”
  4. endif
    image.png
    《ARMv8/ARMv9架构学习系列课程》全系列,共计52节课,超16h的视频课程 添加威♥:sami01_2023,回复ARM中文,领取ARM中文手册