全志A33-修改linux kernel启动参数
開發板:A33,運行linux-3.4.39
主機:Ubuntu 14.04
----------------------------------------------
?
?
1. 修改kernel啟動參數的幾種方式
1)make menuconfig里修改“General Setup”子菜單中的“Default kernel command string” 選項,通過修改這個選項來修改autoconf.h文件中的CONFIG_CMDLINE宏。
2)直接修改arch/arm/kernel/setup.c文件default_command_line,CONFIG_CMDLINE宏的值最終是賦值給這個變量的。
3)一般情況下還可以修改uboot的環境變量中的啟動參數bootargs,這個啟動參數會由uboot傳遞給內核。
推薦方式3。
?
?
2. 內核配置中有如下選項
make menuconfig-> Boot options -> Kernel command line type (***) (X ) Use bootloader kernel arguments if available ( ) Extend bootloader kernel arguments () Always use the default kernel command string
?
解釋:
第一項:Use bootloader kernel arguments if available
?Uses the command-line options passed by the boot loader. If the boot loader doesn't provide any, the default kernel command string provided in CMDLINE will be used.
第二項:Extend bootloader kernel arguments
The command-line arguments provided by the boot loader will be appended to the default kernel command string.
BootLoader環境變量bootargs被追加到kernel command string后面
第三項:Always use the default kernel command string
Always use the default kernel command string, even if the boot loader passes other arguments to the kernel. This is useful if you cannot or don't want to change the command-line options your boot loader passes to the kernel.
如果選擇第三項,則內核只使用default kernel command string作為kernel啟動參數(也在Boot options下設置)。
A33默認為:earlyprintk=ttyS0,115200 loglevel=9 initcall_debug=1 console=ttyS0,115200 ramfs
?
3. 測試
將Kernel command line type 配置為第二項:Extend bootloader kernel arguments,編譯內核,然后重新打包燒錄到A33。
內核啟動時可以發現,uboot的環境變量bootargs被添加到kernel command string后面,如下:
Kernel command line: earlyprintk=ttyS0,115200 console=ttyS0,115200 root=/dev/mmcblk0p7 init=/init ......
注:kernel command string已修改為:earlyprintk=ttyS0,115200
?
建議選擇第一項:Use bootloader kernel arguments if available,因為修改uboot環境變量bootargs要比修改內核再重新編譯燒錄簡單高效的多。
?
4. uboot給kernel傳參:bootargs
(1)linux內核啟動時可以接收uboot給他傳遞的啟動參數,這些啟動參數是uboot和內核約定好的形式、內容,linux內核在這些啟動參數的指導下完成啟動過程。這樣的設計是為了靈活,為了內核在不重新編譯的情況下可以用不同的方式啟動。
(2)我們要做的事情就是:在uboot的環境變量中設置bootargs,然后bootm命令啟動內核時會自動將bootargs傳給內核。
(3)bootargs=console=ttySAC2,115200 root=/dev/mmcblk0p2 rw init=/linuxrc rootfstype=ext3
意義解釋:
console=ttySAC2,115200 控制臺使用串口2,波特率115200.
root=/dev/mmcblk0p2 rw 根文件系統在SD卡端口0設備(iNand)第2分區,根文件系統是可讀可寫的
init=/linuxrc linux的進程1(init進程)的路徑
rootfstype=ext3 根文件系統的類型是ext3
(4)A33開發板bootargs 參數設置如下
setargs_mmc=setenv bootargs console=${console} root=${mmc_root} init=${init} ion_cma_512m=120m ion_cma_1g=176m ion_carveout_512m=96m ion_carveout_1g=150m coherent_pool=4m loglevel=${loglevel} partitions=${partitions}
?
setargs_nand=setenv bootargs console=${console} root=${nand_root} init=${init} ion_cma_512m=120m ion_cma_1g=176m ion_carveout_512m=96m ion_carveout_1g=150m coherent_pool=4m loglevel=${loglevel} partitions=${partitions}
?
5. 環境變量
(1)第一個命令:printenv/print
print命令不用帶參數,作用是打印出系統中所有的環境變量。
環境變量就好像程序的全局變量一樣。程序中任何地方都可以根據需要去調用或者更改環境變量(一般都是調用),環境變量和全局變量不同之處在于:全局變量的生命周期是在程序的一次運行當中,開始運行時誕生程序結束時死亡,下次運行程序時從頭開始;但是環境變量被存儲在Flash的另一塊專門區域(Flash上有一個環境變量分區),一旦我們在程序中保存了該環境變量,那么下次開機時該環境變量的值將維持上一次更改保存后的值。
(2)設置(添加/更改)環境變量:setenv/set
用法:set name value
(3)保存環境變量的更改:saveenv/save
saveenv/save命令不帶參數,直接執行,作用是將內存中的環境變量的值同步保存到Flash中環境變量的分區。注意:環境變量的保存是整體的覆蓋保存,也就是說內存中所有的環境變量都會整體的將Flash中環境變量分區中原來的內容整體覆蓋。
?
總結:徹底更改一個環境變量的值,需要2步:第一步set命令來更改內存中的環境變量,第二步用save命令將其同步到Flash中環境變量的分區。
有時候我們只是想測試下這個環境變量,不希望影響到下一次開機,那就只set不save,這樣set后當前本次運行的uboot已經起效果了,只不過沒save下一次開機還是會恢復到原來的狀況。
?
注:A33 uboot環境變量:
boot_fastboot=fastboot
boot_normal=sunxi_flash read 40007800 boot;boota 40007800
boot_recovery=sunxi_flash read 40007800 recovery;boota 40007800
bootcmd=run setargs_mmc boot_normal
bootdelay=0
console=ttyS0,115200
fastboot_key_value_max=0x8
fastboot_key_value_min=0x2
filesize=6B1B6
init=/init
loglevel=7
mmc_root=/dev/mmcblk0p7
nand_root=/dev/nandd
partitions=boot-res@mmcblk0p2:env@mmcblk0p5:boot@mmcblk0p6:rootfs@mmcblk0p7:data@mmcblk0p8:UDISK@mmcblk0p1
recovery_key_value_max=0x13
recovery_key_value_min=0x10
setargs_mmc=setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p7 init=/init ion_cma_512m=120m ion_cma_1g=176m ion_carveout_512m=96m ion_carveout_1g=150m coherent_pool=4m loglevel=7 partitions=boot-res@mmcblk0p2:env@mmcblk0p5:boot@mmcblk0p6:rootfs@mmcblk0p7:data@mmcblk0p8:UDISK@mmcblk0p1
setargs_nand=setenv bootargs console=${console} root=${nand_root} init=${init} ion_cma_512m=120m ion_cma_1g=176m ion_carveout_512m=96m ion_carveout_1g=150m coherent_pool=4m loglevel=${loglevel} partitions=${partitions}
stderr=serial
stdin=serial
stdout=serial
總結
以上是生活随笔為你收集整理的全志A33-修改linux kernel启动参数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ChatGPT 勉强通过了法律与商业研究
- 下一篇: 国航航班颠簸下坠乘客录视频遗言以防不测: