linux kernel中的cmdline的详细介绍
cmdline
- 1、向linux kernel添加cmdline的四种方式
- (1)、 在dts中的bootargs中添加
- (2)、在BoardConfig中添加
- (3)、在uboot中添加
- (4)、在android的Makefile中添加
- 2、在uboot中,将cmdline统一放置在FDT中
- 3、在kernel中,从FDT中解析处cmdline并使用
- (1)、跳转linux kernel之前-准备cmdline
- (2)、kernel启动-解析cmdline
★★★ 友情链接 : 个人博客导读首页—点击此处 ★★★
1、向linux kernel添加cmdline的四种方式
在linux启动时候,串口log中会打印cmdline
[ 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中添加
/ {model = "yyyyyyy";compatible = "yyyyyyy", "xxxxxxxx";chosen {/** initrd parameters not set in dts file since the ramdisk.img size* need to check in uboot, and the initrd load address and size will* set in uboot stage.*/bootargs = "earlycon androidboot.selinux=permissive uart_dma keep_dbgclk_on clk_ignore_unused";stdout-path = "serial0:115200";};
......
}
(2)、在BoardConfig中添加
vim device/xxx/xxx_evb/BoardConfigCommon.mk
BOARD_KERNEL_CMDLINE += androidboot.selinux=enforcing androidboot.hardware=xxxx_phone androidboot.dtbo_idx=0
(3)、在uboot中添加
vim u-boot/common/cmd_bootm.c
append_bootargs("recovery=1");sprintf(dm_buf,"init=/init skip_initramfs rootwait root=/dev/dm-0 dm=\"system none ro,0 1 android-verity /dev/mmcblk0p%d\"",ret);
append_bootargs((const char *)dm_buf);
(4)、在android的Makefile中添加
vim build/core/Makefile
INTERNAL_KERNEL_CMDLINE := $(strip $(BOARD_KERNEL_CMDLINE) buildvariant=$(TARGET_BUILD_VARIANT) $(VERITY_KEYID))
ifdef INTERNAL_KERNEL_CMDLINE
INTERNAL_BOOTIMAGE_ARGS += --cmdline "$(INTERNAL_KERNEL_CMDLINE)"
endif
2、在uboot中,将cmdline统一放置在FDT中
以后再写,哈哈哈哈
3、在kernel中,从FDT中解析处cmdline并使用
(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 getcorrupted by bogus network packets or disk data. This will saveyou many hours of debug.- Primary CPU general-purpose register settingsx0 = 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)
(2)、kernel启动-解析cmdline
linux kernel从stext开始启动,整个流程大概就是读取X0(FDT地址)保存到X21中,又将X21保存到__fdt_pointer全局变量中
然后再将__fdt_pointer解析处cmdline数据到boot_command_line全局变量中
/** The following callee saved general purpose registers are used on the* primary lowlevel boot path:** Register Scope Purpose* x21 stext() .. start_kernel() FDT pointer passed at boot in x0* x23 stext() .. start_kernel() physical misalignment/KASLR offset* x28 __create_page_tables() callee preserved temp register* x19/x20 __primary_switch() callee preserved temp registers*/
ENTRY(stext)bl preserve_boot_argsbl el2_setup // Drop to EL1, w0=cpu_boot_modeadrp x23, __PHYS_OFFSETand x23, x23, MIN_KIMG_ALIGN - 1 // KASLR offset, defaults to 0bl set_cpu_boot_mode_flagbl __create_page_tables/** The following calls CPU setup code, see arch/arm64/mm/proc.S for* details.* On return, the CPU will be ready for the MMU to be turned on and* the TCR will have been set.*/bl __cpu_setup // initialise processorb __primary_switch
ENDPROC(stext)
这里调用了:
preserve_boot_args
__primary_switch
在preserve_boot_args将X0(fdt地址)暂时先保存到了X21中
preserve_boot_args:mov x21, x0 // x21=FDTadr_l x0, boot_args // record the contents ofstp x21, x1, [x0] // x0 .. x3 at kernel entrystp x2, x3, [x0, #16]dmb sy // needed before dc ivac with// MMU offmov x1, #0x20 // 4 x 8 bytesb __inval_dcache_area // tail call
ENDPROC(preserve_boot_args)
__primary_switch调用了__primary_switched
__primary_switch:
#ifdef CONFIG_RANDOMIZE_BASEmov x19, x0 // preserve new SCTLR_EL1 valuemrs x20, sctlr_el1 // preserve old SCTLR_EL1 value
#endifbl __enable_mmu
#ifdef CONFIG_RELOCATABLEbl __relocate_kernel
#ifdef CONFIG_RANDOMIZE_BASEldr x8, =__primary_switchedadrp x0, __PHYS_OFFSETblr x8
__primary_switched将X21(fdt地址)保存到了__fdt_pointer全局变量中
__primary_switched:adrp x4, init_thread_unionadd sp, x4, #THREAD_SIZEadr_l x5, init_taskmsr sp_el0, x5 // Save thread_infoadr_l x8, vectors // load VBAR_EL1 with virtualmsr vbar_el1, x8 // vector table addressisbstp xzr, x30, [sp, #-16]!mov x29, spstr_l x21, __fdt_pointer, x5 // Save FDT pointerldr_l x4, kimage_vaddr // Save the offset betweensub x4, x4, x0 // the kernel virtual andstr_l x4, kimage_voffset, x5 // physical mappings// Clear BSSadr_l x0, __bss_startmov x1, xzradr_l x2, __bss_stopsub x2, x2, x0bl __pi_memsetdsb ishst // Make zero page visible to PTW
在setup_arch()的时候,调用setup_machine_fdt将fdt解析到了boot_command_line全局变量中
void __init setup_arch(char **cmdline_p)
{pr_info("Boot CPU: AArch64 Processor [%08x]\n", read_cpuid_id());
......*cmdline_p = boot_command_line;
......setup_machine_fdt(__fdt_pointer);
......
}
setup_machine_fdt()—>early_init_dt_scan()—>early_init_dt_scan_nodes()
在中,将fdt解析到了boot_command_line中
of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line)
static void __init setup_machine_fdt(phys_addr_t dt_phys)
{void *dt_virt = fixmap_remap_fdt(dt_phys);const char *name;if (!dt_virt || !early_init_dt_scan(dt_virt)) {pr_crit("\n""Error: invalid device tree blob at physical address %pa (virtual address 0x%p)\n""The dtb must be 8-byte aligned and must not exceed 2 MB in size\n""\nPlease check your bootloader.",&dt_phys, dt_virt);while (true)cpu_relax();}name = of_flat_dt_get_machine_name();if (!name)return;/* backward-compatibility for third-party applications */machine_desc_set(name);pr_info("Machine model: %s\n", name);dump_stack_set_arch_desc("%s (DT)", name);
}
bool __init early_init_dt_scan(void *params){bool status;status = early_init_dt_verify(params);if (!status)return false;early_init_dt_scan_nodes();return true;}
void __init early_init_dt_scan_nodes(void){/* Retrieve various information from the /chosen node */of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);/* Initialize {size,address}-cells info */of_scan_flat_dt(early_init_dt_scan_root, NULL);/* Setup memory, calling early_init_dt_add_memory_arch */of_scan_flat_dt(early_init_dt_scan_memory, NULL);}
在start_kernel()打印了cmdline.
asmlinkage __visible void __init start_kernel(void)
{
…
pr_notice(“Kernel command line: %s\n”, boot_command_line);
…
}
linux kernel中的cmdline的详细介绍相关推荐
- Linux文件系统中的inode节点详细介绍
一.inode是什么? 理解inode,要从文件储存说起. 文件储存在硬盘上,硬盘的最小存储单位叫做"扇区"(Sector).每个扇区储存512字节(相当于0.5KB). 操作系统 ...
- 向linux kernel中添加cmdline的四种方式
cmdline 1. 在dts中的bootargs中添加 2.在BoardConfig中添加 3.在uboot中添加 4.在android的Makefile中添加 ★★★ 友情链接 : 个人博客导读首 ...
- Linux Kernel中的同步机制的介绍
快速链接: .
- linux xorg 文件 位置,Linux系统中xorg.conf文件详细介绍
先看一个完整的xorg.conf文件,如下:复制代码 代码如下: # /.../ # SaX generated X11 config file # Created on: 2009-05-31T19 ...
- linux中各目录及详细介绍
linux中各目录及详细介绍 一.Linux文件系统的层次结构 在Linux或UNIX操作系统中,所有的文件和目录都被组织成一个以根节点开始的倒置的树状结构,如图: 二.目录 1.目录的定义 目录相当 ...
- linux kernel中的栈的介绍
目录 1.linux kernel中的中断irq的栈stack (1).arm32体系的irq的栈 (2).arm64体系的irq的栈 2.linux kernel中的栈stack (1).概念介绍: ...
- Linux kernel 中模块化的平台驱动代码介绍
介绍 在linux kernel中通过module_platform_driver来实现模块化平台驱动.大量的设备驱动程序都基于该种方式来实现,使用频次非常的高,在linux kernel 5.4.1 ...
- linux中的chmod命令详细介绍、使用及实例
linux中的chmod命令详细介绍.使用及实例 chmod命令 chmod用于改变 linux 系统文件或目录的访问权限,可以用它控制文件或目录的访问权限.该命令有两种用法:一种是包含字母的文字设定 ...
- 内存访问顺序 - part2: 屏障及Linux kernel中屏障的使用
文章目录 屏障是什么 Linux Kernel 中的屏障 Linux 屏障 API 一般的屏障 强制性屏障 SMP 条件屏障 隐式屏障 其他屏障 屏障的开销 未来的文章 本文翻译自 Memory ac ...
最新文章
- Re-Located Record in Grid
- mysql8创建用户并授权_新版mysql8.0.12添加用户并设置权限避免踩坑!
- Flex Socket 安全沙箱问题解决
- 2. Mysql数据库的入门知识
- 微软相关的开发资源列表(update)
- vue应用开发过程中在谷歌浏览器遇到的奇葩问题——谷歌插件屏蔽接口请求
- python qt库,用于 Python 的高级 GUI 库(Qt 和 PyQt)(1)Unix系统 -电脑资料
- 【九】Jmeter 实现验证码登录
- 从SQL到NoSQL再到NewSQL
- 从王者荣耀看设计模式(五.组合模式)
- Linux下iptables 禁止端口和开放端口
- 实战:SpringMVC实现用户角色管理
- excel怎么设置自动计算_Excel智能化考勤表,自带万年历设置,考勤加班计算,无脑轻松...
- 基于微信小程序的鲜花销售系统毕业设计源码
- Logstash: Grok 模式示例
- Could not enlist in transaction on entering meta-aware object
- 自然语言处理入门-第4章 隐马尔可夫模型与序列标注
- 【51单片机】连接蓝牙模块(AT模式、解决返回乱码)
- 当你感觉轻松的时候,就要警惕了
- mac、windows 设置终端代理
热门文章
- @所有粉丝,祝大家新春快乐!
- 直流UPS与传统UPS系统节能分析
- Py之pyttsx:pyttsx/pyttsx3​​​​​​​的简介、安装、使用方法之详细攻略
- DL之Mask R-CNN:2018.6.26世界杯阿根廷队VS尼日利亚比赛2:1实现Mask R-CNN目标检测
- Py之pycurl:Python 库之pycurl的简介、安装、使用方法之详细攻略
- ExecutableNotFound: failed to execute ['dot', '-Tsvg'], make sure the Graphviz executables are on yo
- TypeError: Can not convert a float32 into a Tensor or Operation.
- 云安全,到底是什么一回事?
- ( 1 )Linux 常用命令
- 十年之后再看“面向对象”