歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> uboot環境配置

uboot環境配置

日期:2017/2/28 13:45:44   编辑:Linux教程

通過配置uboot讓它在啟動過程中從tftp獲取內核和設備樹,並從在加載內核之後把通過啟動參數將"從nfs掛載根文件系統"傳入內核。這個配置主要是通過uboot內建的"set 變量名 變量值+save"設置環境變量的方式進行配置,下面是我采用的uboot的環境變量,下面是我用的環境變量設置:

#pri                    #即printenv  
baudrate=115200
bootargs=root=/dev/nfs nfsroot=192.168.0.50:/nfs rw console=ttySAC2,115200n8 init=/linuxrc ip=192.168.0.55 loglevel=7 clk_ignore_unused
bootcmd=tftp 41000000 uImage;tftp 42000000 exynos4412-origen.dtb;bootm 41000000 - 42000000
bootdelay=4
ethact=dm9000
ethaddr=11:22:33:44:55:66
fileaddr=41000000
filesize=26D213
gatewayip=192.168.2.1
ipaddr=192.168.0.55
netmask=255.255.255.0
serverip=192.168.0.50
stderr=serial
stdin=serial
stdout=serial

baudrate就是波特率,習慣上就設成115200,根據硬件的不同可以相應的修改

bootargs啟動參數,這個參數除了uboot要用,啟動內核之後還會傳入內核。
其中,root=/dev/nfs表示開發板的根文件系統從nfs網絡設備中加載,nfsroot=192.168.0.55:/nfs表示從網絡中的ip是192.168.0.55的主機中的/nfs目錄加載根文件系統,rw表示可讀可寫,console=ttySAC2表示使用的中端,115200表示波特率,init=/linuxrc表示啟動的祖先進程的位置,顯然這是給linux內核用的,ip=192.168.0.55是開發板的ip,需要和主機在同一個網段,loglevel=7就是登錄等級,這個不設也行,clk_ignore_unused忽略時鐘。這個參數的實質是uboot傳入內核的,所以需要參考內核的啟動參數的相關文件,我在下面做了簡要的說明。除了啟動參數,uboot還需要做一些其他的准備工作,並不是這個參數准備好了內核就可以工作了,比如,關於arm平台的linux內核啟動條件,可以參考Linux內核源碼中的Documentation/arm/Booting ,這裡就不做說明了
bootcmd啟動命令,tftp 41000000 uImage表示從tftp網絡中下載uImage內核鏡像到41000000地址處,tftp 42000000 exynos4412-origen.dtb表示下載從tftp網絡中下載設備樹文件到42000000地址處,bootm 41000000 - 42000000表示從41000000啟動內核,我這沒有randisk,用-代替,不是從41000000到42000000的意思!!!此外,一旦填入了ramdisk地址,內核就會從ramdisk掛載根文件系統而忽略nfs。最後,把設備樹從42000000傳入內核。
注意:多個命令之間用;分隔,所以為了在設置變量的時候不立即執行,應該寫成set bootcmd tftp 41000000 uImage\;tftp 42000000 exynos4412-origen.dtb\;bootm 41000000 - 42000000

bootdelay啟動倒計時的秒數

gatewayip表示網關

ipaddr表示開發板的ip

serverip表示主機的ip

netmask表示子網掩碼

stderrstdinstdout表示標准輸入輸出錯誤設備,基本都填串口serial

Linux內核啟動參數

內核需要的啟動參數在linux-4.8.5/Documentation/kernel-parameters.txt以及相應的文件中,這些參數就是uboot需要通過bootargs將他們准備好並傳給內核,當然,這些參數都是有缺省值的,我們只需要對需要的參數進行配置,這裡列出這裡用到的幾個

noinitrd    [RAM] Tells the kernel not to load any configured
            initial RAM disk.
            
root=       [KNL] Root filesystem
            See name_to_dev_t comment in init/do_mounts.c.

nfsroot=    [NFS] nfs root filesystem for disk-less boxes.
            See Documentation/filesystems/nfs/nfsroot.txt.

rw          [KNL] Mount root device read-write on boot

rootwait    [KNL] Wait (indefinitely) for root device to show up.
            Useful for devices that are detected asynchronously
            (e.g. USB and MMC devices).

ip=         [IP_PNP]
            See Documentation/filesystems/nfs/nfsroot.txt.

console=    [KNL] Output console device and options.
        。。。

init=       [KNL]
            Format: <full_path>
            Run specified binary instead of /sbin/init as init
            process.

loglevel=   All Kernel Messages with a loglevel smaller than the
            console loglevel will be printed to the console. 
            。。。
            
clk_ignore_unused
            [CLK]
            Prevents the clock framework from automatically gating
            clocks that have not been explicitly enabled by a Linux
            device driver but are enabled in hardware at reset or
            by the bootloader/firmware. 
            。。。
$grep ip=  Documentation/filesystems/nfs/nfsroot.txt -A 20
ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>:<dns0-ip>:<dns1-ip>

  This parameter tells the kernel how to configure IP addresses of devices and also how to set up the IP routing table. It was originally called 'nfsaddrs', but now the boot-time IP configuration works independently of NFS, so it was renamed to 'ip' and the old name remained as an alias for compatibility reasons.
。。。。
$grep nfsroot=  Documentation/filesystems/nfs/nfsroot.txt -A 20
nfsroot=[<server-ip>:]<root-dir>[,<nfs-options>]

  If the 'nfsroot' parameter is NOT given on the command line,
  the default "/tftpboot/%s" will be used.
 。。。
Copyright © Linux教程網 All Rights Reserved