openwrt的uboot環境變量分析


目前燒寫完CC(chaos calmer 15.05)版本,查看其uboot變量如下:

ath> printenv
bootargs=console=ttyS0,115200 root=31:02 rootfstype=jffs2 init=/sbin/init mtdparts=ath-nor0:256k(u-boot),64k(u-boot-env),14528k(rootfs),1408k(uImage),64k(mib0),64k(ART)
bootcmd=bootm 0x9fE80000
bootdelay=2
baudrate=115200
ethaddr=0x00:0xaa:0xbb:0xcc:0xdd:0xee
dir=
lu=tftp 0x80060000 ${dir}u-boot.bin&&erase 0x9f000000 +$filesize&&cp.b $fileaddr 0x9f000000 $filesize
lf=tftp 0x80060000 ${dir}openwrt-ar71xx-generic-ap143-16M-rootfs-squashfs.bin&&erase 0x9f050000 +0xE30000&&cp.b $fileaddr 0x9f050000 $filesize
lk=tftp 0x80060000 ${dir}openwrt-ar71xx-generic-ap143-16M-kernel.bin&&erase 0x9fE80000 +$filesize&&cp.b $fileaddr 0x9fE80000 $filesize
ethact=eth0
ipaddr=192.168.2.101
serverip=192.168.2.234
stdin=serial
stdout=serial
stderr=serial

Environment size: 742/65532 bytes

 

具體變量定義可以查看openwrt官網的聲明。

地址如下:  https://wiki.openwrt.org/doc/techref/bootloader/uboot.config

下面簡單介紹一下:

bootargs:The contents of this variable are passed to the Linux kernel as boot arguments (aka "command line").

              傳送給linux內核的參數,用於啟動(boot),也稱作命令行。

bootargs=console=ttyS0,115200 root=31:02 rootfstype=jffs2 init=/sbin/init mtdparts=ath-nor0:256k(u-boot),64k(u-boot-env),14528k(rootfs),1408k(uImage),64k(mib0),64k(ART) 

(1)console=ttyS0 串口

(2)115200  波特率為115200

(3)root=31:02     ?暫時不知什么意思

(4)rootfstype=jffs2  文件系統為jffs2

(5)init=/sbin/init   初始化腳本調用/sbin/init

(6)mtdparts=ath-nor0:256k(u-boot),64k(u-boot-env),14528k(rootfs),1408k(uImage),64k(mib0),64k(ART) 

       mtd分區為:   u-boot  256k

                           u-boot-env     64k

                           rootfs   14528k

                           uImage  1408k(linux 內核)

                           mib0   64k(factory)

                           ART    64k(無線校正區)

       啟動完成后,查看分區情況可以看到:

        root@OpenWrt:/# cat /proc/mtd
      dev:    size         erasesize  name
      mtd0: 00040000 00010000 "u-boot"
      mtd1: 00010000 00010000 "u-boot-env"
      mtd2: 00e30000 00010000 "rootfs"
      mtd3: 00be0000 00010000 "rootfs_data"
      mtd4: 00160000 00010000 "kernel"
      mtd5: 00010000 00010000 "factory"
      mtd6: 00010000 00010000 "art"
      mtd7: 00f80000 00010000 "firmware"

 

bootcmd:This variable defines a command string that is automatically executed when the initial countdown is not interrupted. This command is only   executed when the variable bootdelay is also defined!

                當初始化(initial)計時結束后開始執行此命令,此命令不可被中斷,並且只能跟bootdelay一起使用。

bootcmd=bootm 0x9fE80000      跳轉到地址0x9fE80000去啟動 

bootm命令可以引導啟動存儲在內存中的程序映像。這些內存包括RAM和可以永久保存的Flash。
第1個參數addr是程序映像的地址,這個程序映像必須轉換成U-Boot的格式。
第2個參數對於引導Linux內核有用,通常作為U-Boot格式的RAMDISK映像存儲地址;也可以是傳遞給Linux內核的參數(缺省情況下傳遞bootargs環境變量給內核)。
附加說明: 要求二進制代碼為制定格式的。通常為mkimage處理過的二進制文件。起動UBOOT TOOLS制作的壓縮LINUX內核, bootm 3200000

 

 

bootdelay:After reset, U-Boot will wait this number of seconds before it executes the contents of the bootcmd variable. During this time a countdown is printed, which can be interrupted by pressing any key. Set this variable to 0 boot without delay. Be careful: depending on the contents of your bootcmd variable, this can prevent you from entering interactive commands again forever! 
Set this variable to -1 to disable autoboot.

                 reset后,經過bootdelay的時間后,執行bootcmd命令。在此期間,打印countdown計時,此時可以按任意鍵打斷。如果這個值設置為0,則立即執行bootcmd,無需等待bootdelay的時間。如果設置為-1,則進制自動啟動(autoboot)

bootdelay=2  倒計時2 . 1 后執行bootcmd命令

 

 

baudrate:a decimal number that selects the console baudrate (in bps)

               串口的波特率(單位:bps)

baudrate=115200

 

 

ethaddr:Ethernet MAC address for first/only ethernet interface (eth0 in Linux). 
This variable can be set only once (usually during manufacturing of the board). U-Boot refuses to delete or overwrite this variable once it has been set.

              第一個以太口的MAC地址,這個變量只可被設置一次(一般在制造單板時設置)。一旦設置,U-Boot拒絕刪除或覆蓋這個變量。

ethaddr=0x00:0xaa:0xbb:0xcc:0xdd:0xee    地址設置為: 00:aa:bb:cc:dd:ee

 

設置lu lf 和 lk 為別名,代替后面的命令集

lu=tftp 0x80060000 ${dir}u-boot.bin&&erase 0x9f000000 +$filesize&&cp.b $fileaddr 0x9f000000 $filesize

    (1) 將u-boot.bin文件上傳到0x80060000地址;  

    (2)然后從地址0x9f000000開始,擦除filesize大小;

    (3)從fileaddr地址中復制數據,大小為filesize,到地址0x9f000000.

也就是說設備的地址從0x9f000000開始,到 0x9f000000+filesize里面存放的是u-boot。


lf=tftp 0x80060000 ${dir}openwrt-ar71xx-generic-ap143-16M-rootfs-squashfs.bin&&erase 0x9f050000 +0xE30000&&cp.b $fileaddr 0x9f050000 $filesize

     (1)上傳openwrt-ar71xx-generic-ap143-16M-rootfs-squashfs.bin到地址0x80060000;

     (2)然后從地址0x9f050000開始,擦除0xE30000大小;

     (3)從fileaddr地址中復制數據,大小為filesize,到地址0x9f050000

也就是說設備的地址從0x9f050000開始,到 0x9f050000+filesize里面存放的是rootfs。

 


lk=tftp 0x80060000 ${dir}openwrt-ar71xx-generic-ap143-16M-kernel.bin&&erase 0x9fE80000 +$filesize&&cp.b $fileaddr 0x9fE80000 $filesize

     (1)上傳openwrt-ar71xx-generic-ap143-16M-kernel.bin到地址0x80060000;

     (2)然后從地址0x9fE80000開始,擦除filesize大小;

     (3)從fileaddr地址中復制數據,大小為filesize,到地址0x9E80000

也就是說設備的地址從0x9fE80000開始,到 0x9fE80000+filesize里面存放的是kernel。

 

ethact: uboot 要求使用環境變量 "ethact" 來指明尋找網絡設備的起點。

ethact=eth0

 

 

ipaddr=192.168.2.101      設置設備地址,用於tftp使用
serverip=192.168.2.234    設置服務器地址,供tftp使用

 

輸入,輸出,錯誤打印均在串口

stdin=serial
stdout=serial
stderr=serial

 

附錄:

cp [.b, .w, .l] source target count

       - copy memory

cp命令可以在內存中復制數據塊,包括對Flash的讀寫操作。

第1個參數source是要復制的數據塊起始地址

第2個參數target是數據塊要復制到的地址。這個地址如果在Flash中,那么會直接調用寫Flash的函數操作。所以U-Boot寫Flash就使用這個命令,當然需要先把對應Flash區域擦凈。

第3個參數count是要復制的數目,根據cp.b cp.w cp.l分別以字節、字、長字為單位。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM