2014年12月16日 星期二

U-Boot 指令及建立 uEnv.txt


一、U-Boot 指令介紹

接續前一章節 Rootfs 植入 sdcard.img 開機 ,
當我們進入 U-Boot# 後 ,有以下幾個常用的指令介紹:

0. help

指令總覽

1. mmc

跟 SD/MMC 有關的指令及輸出。

下面 mmc list 可以印出,
目前裝置所接有的 SD Card 代號為 mmc 0
U-Boot# mmc list
OMAP SD/MMC: 0

下面 mmc part 可以印出,
mmc 0 這裝置之磁區分割 (Partition)
U-Boot# mmc part
Partition Map for MMC device 0  --   Partition Type: DOS

Part Start Sector Num Sectors UUID  Type
  1 2048       163840     925db895-01 0b Boot
  2 165888     1931264    925db895-02 83

下面 mmc info 可以看到目前 sd card 相關資訊。
U-Boot# mmc info
Device: OMAP SD/MMC
Manufacturer ID: aa
OEM: 5859
Name: QEMU! 
Tran Speed: 25000000
Rd Block Len: 512
SD version 1.0
High Capacity: No
Capacity: 1 GiB
Bus Width: 4-bit


2. bdinfo

查看嵌入式版子資訊,
其中比較需要注意的是第五行 -> start    = 0x80000000,
這跟我們載入開機的記憶體位址有關。
U-Boot# bdinfo
arch_number = 0x0000060A
boot_params = 0x80000100
DRAM bank   = 0x00000000
-> start    = 0x80000000
-> size     = 0x08000000
DRAM bank   = 0x00000001
-> start    = 0x88000000
-> size     = 0x08000000
eth0name    = usb_ether
ethaddr     = (not set)
current eth = usb_ether
ip_addr     = 
baudrate    = 115200 bps
TLB addr    = 0x8FFF0000
relocaddr   = 0x8FF4C000
reloc off   = 0x0FE4C000
irq_sp      = 0x8EF2BEE0
sp start    = 0x8EF2BED0

3. ls

查看 SD Card 內容之檔案目錄。

其中 mmc 0:1 是指 sdcard.img1:
U-Boot# ls mmc 0:1
  1852516   u-boot 
   392152   u-boot.bin 
    51100   mlo 
   392216   u-boot.img 
  2533720   uimage 

5 file(s), 0 dir(s)

其中 mmc 0:2 是指 sdcard.img2:
U-Boot# ls mmc 0:2
       4096 .
       4096 ..
      16384 lost+found
       4096 bin
       4096 boot
       4096 dev
       4096 etc
       4096 home
       4096 lib
       4096 media
       4096 mnt
       4096 opt
       4096 proc
       4096 root
       4096 run
       4096 sbin
       4096 selinux
       4096 srv
       4096 sys
       4096 tmp
       4096 usr
       4096 var

4. reset

重新啟動 U-Boot

5. printenv

印出 u-boot environment 設定檔。


二、建立 uEnv.txt


0. 進入 U-Boot#

參考前一章 Rootfs 植入 sdcard.img 開機 ,
最後面用 runsdcard.sh 進到 U-boot 內。
runsdcard.sh 內容如下:
qemu-system-arm -M beagle -m 512 -nographic -sd sdcard.img

1. printenv -> uEnv.txt

於 U-Boot# 內使用指令 printenv 將全部內容複製,
並貼上建立一個 uEnv.txt ,其原始內容如下:
arch=arm
baudrate=115200
beaglerev=C4
board=beagle
board_name=beagle
bootargs=console=ttyO2,115200n8 mpurate=auto buddy=none camera=none vram=12M omapfb.mode=dvi:640x480MR-16@60 omapdss.def_disp=dvi root=ubi0:rootfs ubi.mtd=4 rootfstype=ubifs
bootcmd=run findfdt; mmc dev ${mmcdev}; if mmc rescan; then if run userbutton; then setenv bootenv uEnv.txt;else setenv bootenv user.txt;fi;echo SD/MMC found on device ${mmcdev};if run loadbootenv; then echo Loaded environment from ${bootenv};run importbootenv;fi;if test -n $uenvcmd; then echo Running uenvcmd ...;run uenvcmd;fi;if run loadimage; then run mmcboot;fi;fi;run nandboot;setenv bootfile uImage;if run loadimage; then run loadfdt;run mmcbootz; fi;
bootdelay=1
bootdir=/
bootenv=uEnv.txt
bootfile=uImage
bootpart=0:1
buddy=none
camera=none
console=ttyO2,115200n8
cpu=armv7
defaultdisplay=dvi
dieid#=51454d5551454d555400000051454d55
dvimode=640x480MR-16@60
ethact=usb_ether
fdt_high=0xffffffff
fdtaddr=0x80f80000
fdtfile=omap3-beagle.dtb
findfdt=if test $beaglerev = AxBx; then setenv fdtfile omap3-beagle.dtb; fi; if test $beaglerev = Cx; then setenv fdtfile omap3-beagle.dtb; fi; if test $beaglerev = C4; then setenv fdtfile omap3-beagle.dtb; fi; if test $beaglerev = xMAB; then setenv fdtfile omap3-beagle-xm-ab.dtb; fi; if test $beaglerev = xMC; then setenv fdtfile omap3-beagle-xm.dtb; fi; if test $fdtfile = undefined; then echo WARNING: Could not determine device tree to use; fi;
importbootenv=echo Importing environment from mmc ...; env import -t $loadaddr $filesize
loadaddr=0x80000000
loadbootenv=fatload mmc ${mmcdev} ${loadaddr} ${bootenv}
loadfdt=run validatefdt; load mmc ${bootpart} ${fdtaddr} ${bootdir}/${fdtfile}
loadimage=load mmc ${bootpart} ${loadaddr} ${bootdir}/${bootfile}
loadramdisk=load mmc ${bootpart} ${rdaddr} ${bootdir}/${ramdisk}
mmcargs=setenv bootargs console=${console} ${optargs} mpurate=${mpurate} buddy=${buddy} camera=${camera} vram=${vram} omapfb.mode=dvi:${dvimode} omapdss.def_disp=${defaultdisplay} root=${mmcroot} rootfstype=${mmcrootfstype}
mmcboot=echo Booting from mmc ...; run mmcargs; bootm ${loadaddr}
mmcbootz=echo Booting with DT from mmc${mmcdev} ...; run mmcargs; bootz ${loadaddr} - ${fdtaddr}
mmcdev=0
mmcroot=/dev/mmcblk0p2 rw
mmcrootfstype=ext4 rootwait
mpurate=auto
nandargs=setenv bootargs console=${console} ${optargs} mpurate=${mpurate} buddy=${buddy} camera=${camera} vram=${vram} omapfb.mode=dvi:${dvimode} omapdss.def_disp=${defaultdisplay} root=${nandroot} rootfstype=${nandrootfstype}
nandboot=echo Booting from nand ...; run nandargs; nand read ${loadaddr} 280000 400000; bootm ${loadaddr}
nandroot=ubi0:rootfs ubi.mtd=4
nandrootfstype=ubifs
ramargs=setenv bootargs console=${console} ${optargs} mpurate=${mpurate} buddy=${buddy} vram=${vram} omapfb.mode=dvi:${dvimode} omapdss.def_disp=${defaultdisplay} root=${ramroot} rootfstype=${ramrootfstype}
ramboot=echo Booting from ramdisk ...; run ramargs; bootm ${loadaddr}
ramdisk=ramdisk.gz
ramroot=/dev/ram0 rw ramdisk_size=65536 initrd=0x81000000,64M
ramrootfstype=ext2
rdaddr=0x81000000
soc=omap3
stderr=serial
stdin=serial
stdout=serial
usbtty=cdc_acm
userbutton=if gpio input 173; then run userbutton_xm; else run userbutton_nonxm; fi;
userbutton_nonxm=gpio input 7;
userbutton_xm=gpio input 4;
validatefdt=if test $beaglerev = xMAB; then if test ! -e mmc ${bootpart} ${bootdir}/${fdtfile}; then setenv fdtfile omap3-beagle-xm.dtb; fi; fi;
vendor=ti
ver=U-Boot 2014.07 (Oct 14 2014 - 12:06:49)
vram=12M

2. 整理語法

先將 uEnv.txt 備份為 uEnv.txt.sh ,
並對其內容做語法整理,方便我們了解它寫的內容,
我的整理如下:
arch=arm
baudrate=115200
beaglerev=C4
board=beagle
board_name=beagle

bootargs=console=ttyO2,115200n8
         mpurate=auto
         buddy=none
         camera=none
         vram=12M
         omapfb.mode=dvi:640x480MR-16@60
         omapdss.def_disp=dvi
         root=ubi0:rootfs
         ubi.mtd=4
         rootfstype=ubifs

bootcmd=run findfdt;
        mmc dev ${mmcdev};
        if mmc rescan;  then
                if run userbutton; then
                        setenv bootenv uEnv.txt;
                else
                        setenv bootenv user.txt;
                fi;
                echo SD/MMC found on device ${mmcdev};
                if run loadbootenv; then
                        echo Loaded environment from ${bootenv};
                        run importbootenv;
                fi;
                if test -n $uenvcmd; then
                        echo Running uenvcmd ...;
                        run uenvcmd;
                fi;
                if run loadimage; then
                        run mmcboot;
                fi;
        fi;
        run nandboot;
        setenv bootfile uImage;
        if run loadimage; then
                run loadfdt;
                run mmcbootz;
        fi;

bootdelay=1
bootdir=/
bootenv=uEnv.txt
bootfile=uImage
bootpart=0:1
buddy=none
camera=none
console=ttyO2,115200n8
cpu=armv7
defaultdisplay=dvi
dieid#=51454d5551454d555400000051454d55
dvimode=640x480MR-16@60
ethact=usb_ether
fdt_high=0xffffffff
fdtaddr=0x80f80000
fdtfile=omap3-beagle.dtb

findfdt=if test $beaglerev = AxBx; then
                setenv fdtfile omap3-beagle.dtb;
        fi;
        if test $beaglerev = Cx; then
                setenv fdtfile omap3-beagle.dtb;
        fi;
        if test $beaglerev = C4; then
                setenv fdtfile omap3-beagle.dtb;
        fi;
        if test $beaglerev = xMAB; then
                setenv fdtfile omap3-beagle-xm-ab.dtb;
        fi;
        if test $beaglerev = xMC; then
                setenv fdtfile omap3-beagle-xm.dtb;
        fi;
        if test $fdtfile = undefined; then
                echo WARNING: Could not determine device tree to use;
        fi;

importbootenv=echo Importing environment from mmc ...;
              env import -t $loadaddr $filesize

loadaddr=0x80000000
loadbootenv=fatload mmc ${mmcdev} ${loadaddr} ${bootenv}
loadfdt=run validatefdt; load mmc ${bootpart} ${fdtaddr} ${bootdir}/${fdtfile}
loadimage=load mmc ${bootpart} ${loadaddr} ${bootdir}/${bootfile}
loadramdisk=load mmc ${bootpart} ${rdaddr} ${bootdir}/${ramdisk}

mmcargs=setenv bootargs console=${console} ${optargs} mpurate=${mpurate} buddy=${buddy} camera=${camera} vram=${vram} omapfb.mode=dvi:${dvimode} omapdss.def_disp=${defaultdisplay} root=${mmcroot} rootfstype=${mmcrootfstype}

mmcboot=echo Booting from mmc ...;
run mmcargs;
bootm ${loadaddr}

mmcbootz=echo Booting with DT from mmc${mmcdev} ...;
         run mmcargs;
         bootz ${loadaddr} - ${fdtaddr}

mmcdev=0
mmcroot=/dev/mmcblk0p2 rw
mmcrootfstype=ext4 rootwait
mpurate=auto

nandargs=setenv bootargs console=${console} ${optargs} mpurate=${mpurate} buddy=${buddy} camera=${camera} vram=${vram} omapfb.mode=dvi:${dvimode} omapdss.def_disp=${defaultdisplay} root=${nandroot} rootfstype=${nandrootfstype}

nandboot=echo Booting from nand ...;
         run nandargs;
         nand read ${loadaddr} 280000 400000;
         bootm ${loadaddr}

nandroot=ubi0:rootfs ubi.mtd=4
nandrootfstype=ubifs

ramargs=setenv bootargs console=${console} ${optargs} mpurate=${mpurate} buddy=${buddy} vram=${vram} omapfb.mode=dvi:${dvimode} omapdss.def_disp=${defaultdisplay} root=${ramroot} rootfstype=${ramrootfstype}

ramboot=echo Booting from ramdisk ...;
        run ramargs;
        bootm ${loadaddr}
ramdisk=ramdisk.gz
ramroot=/dev/ram0 rw ramdisk_size=65536 initrd=0x81000000,64M
ramrootfstype=ext2
rdaddr=0x81000000
soc=omap3
stderr=serial
stdin=serial
stdout=serial
usbtty=cdc_acm

userbutton=if gpio input 173; then
                run userbutton_xm;
           else
                run userbutton_nonxm;
           fi;

userbutton_nonxm=gpio input 7;
userbutton_xm=gpio input 4;

validatefdt=if test $beaglerev = xMAB; then
                if test ! -e mmc ${bootpart} ${bootdir}/${fdtfile}; then
                        setenv fdtfile omap3-beagle-xm.dtb;
                fi;
            fi;

vendor=ti
ver=U-Boot 2014.07 (Oct 14 2014 - 12:06:49)
vram=12M

3. 修改 uEnv.txt內容

我們看的是 uEnv.txt.sh ,
真正最後要載入 sdcard.img 的是 uEnv.txt ,
所以邊看 .sh 那份做修改,同時也要改 uEnv.txt,
兩者同步進行,改的主要項目為:

  • zImage -> uImage
  • loadaddr=0x80200000 -> loadaddr=0x80000000
  • bootpart=0:2 -> bootpart=0:1
  • mmcrootfstype=ext3 -> mmcrootfstype=ext4
  • bootdir=/boot -> bootdir=/

4. 植入 uEnv.txt -> sdcard1

將修變好的 uEnv.txt 植入到 sdcard partition 1 內。
mount -o loop,offset=$[512*2048] sdcard.img /mnt
rsync-av ~/qrmu_img/bootloader/uEnv.txt /mnt

5. 執行 runsdcard.sh

sh runsdcard.sh

執行結果,若正確的話,
應該要自動且快速通過 U-boot ,並直接載入 kernel ,
做正確的開機程序。











Reference:
http://pominglee.blogspot.tw/2013/12/uboot.html

http://pominglee.blogspot.tw/2014/12/uboot.html

沒有留言:

張貼留言