setenv or set : 명령이용하여 환경변수 설정가능 uboot에서 많은 환경변수를 제공하며, script기능도 제공
1.1 Uboot Hush Script 이해
환경변수 설정과 기본 script 실행하는 방법은 아래와 같으며, Uboot에서 사용하는 Command는 Uboot 빌드시 CONFIG 옵션에 따라
변경되기 때문에 차이는 있지만, 기본 Command들은 대체적으로 알아두자.
- UBoot의 기본 env 와 command 이해
- bootcmd: uboot가 기본적으로 실행되는 변수 (가장중요)
- 이외에 암묵적으로 많이 사용하는 환경변수가 존재 (stdin,stdout, 등 )
- script의 기본은 uboot cmd의 나열로 구성하고 환경변수 및 구분자를 세미콜론사용
- run을 이용하여 만들어진 script을 실행가능
- setenv 이용하여 환경변수 및 script 생성
- UBoot Script 의 확장이해
- if <list>; then <command list>; [elif <list>; then <list>; ] [else <list>; then <list>;]
- while <list>; do <list>; done
- until <list>; do <list>; done
- for <name> in <word list>; do <list> ; done
1,2,3 앞에
- 에 test command를 이용하여 비교가 가능하며, 뒤에
- 는 script or 환경변수를 넣으면 된다.
http://www.compulab.co.il/utilite-computer/wiki/index.php/U-Boot_Scripts
1.2 Uboot Hush Script 의 예제
위에서 확장으로 사용되는 예제들을 한번 살펴보자.
- Uboot Script if 문 test 예제
findfdt=if test $board_name = AM43EPOS; then setenv fdtfile am43x-epos-evm.dtb; fi; if test $board_name = AM43__GP; then setenv fdtfile am437x-gp-evm.dtb; fi; if test $board_name = AM43__SK; then setenv fdtfile am437x-sk-evm.dtb; fi; if test $fdtfile = undefined; then echo WARNING: Could not determine device tree; fi; // if문 예제
- Uboot Script for 문 예제
boot_targets=mmc0 legacy_mmc0 mmc1 legacy_mmc1 nand0 pxe dhcp // target list distro_bootcmd=for target in ${boot_targets}; do run bootcmd_${target}; done //for boot_targets에서 환경변수에서 target을 추출하여 bootcmd_x 실행 bootcmd_dhcp=run boot_net_usb_start; if dhcp ${scriptaddr} ${boot_script_dhcp}; then source ${scriptaddr}; fi bootcmd_legacy_mmc0=setenv mmcdev 0; setenv bootpart 0:2 ; run mmcboot bootcmd_legacy_mmc1=setenv mmcdev 1; setenv bootpart 1:2 ; run mmcboot bootcmd_mmc0=setenv devnum 0; run mmc_boot bootcmd_mmc1=setenv devnum 1; run mmc_boot bootcmd_nand=run nandboot bootcmd_pxe=run boot_net_usb_start; dhcp; if pxe get; then pxe boot; fi
uboot script은 쉽게 이해가능하며, 누구나 쉽게 사용가능.
1.3 외부 Uboot Script 사용방법
- Uboot에서 Uboot Script 실행
U-Boot# pri ... script_addr=0x80900000 loadbootscript=fatload mmc 0 ${script_addr} boot.scr bootscript= echo Running bootscript from MMC/SD to set the ENV...; source ${script_addr} bootcmd=if mmc init; then if run loadbootscript; then run bootscript; else if run loaduimage; then run mmcboot; else run nandboot; f i; fi; else run nandboot; fi ...
- 외부 Uboot Script 생성방법
$ vi boot-nfs.txt
setenv bootargs 'console=ttyO0,115200n8 root=/dev/nfs nfsrootdebug rw rootdelay=10 mem=80M vram=4M notifyk.vpssm3_sva=0xBFD00000 nfsroot=192.168.1.100:/home/jhlee/dm8127/work/Source/ipnc_rdk/target/filesys,nolock eth=32:30:3a:63:64:3a ip=192.168.1.168 cmemk.phys_start=0x85000000 cmemk.phys_end=0x89000000 cmemk.allowOverlap=1 earlyprintk'
$ mkimage -A arm -T script -C none -d boot-nfs.txt boot.scr // Uboot Script 생성
생성된 boot.scr를 FAT에 복사하여 실행가능하여 이외에도 상위의 if문을 비롯하여 다양한 연속적인 Uboot Script을 생성가능하다
- mkimage 설치
$ sudo apt-get install uboot-mkimage //mkimage가 없을 경우 설치
https://wiki.ubuntu.com/ARM/EditBootscr
http://www.denx.de/wiki/DULG/UBootScripts
2. Uboot 와 Device Tree Boot 설정
AM437x와 AM335x는 Uboot에서 손쉽게 Device Tree Boot를 설정변경이 가능하며,
이전에 Device Tree File에 대해서 설명했듯이 zImage와 dtb 파일은 filesystem의 /boot라는 곳에 저장이 되어있다.
Device Tree 관련내용
https://ahyuo79.blogspot.com/2015/08/kernel-boot-kernel-device-tree.html
- Uboot 와 Device Tree Boot 역할
- Device Tree Boot 설정 변경 (다양한 Kernel 및 Device Tree 선택)
특히 findfdt는 device tree의 file을 설정을 하는 것이며, findfdt 대신 직접 설정을 하여도 좋다.
2.1 Uboot의 boot 분석 (AM437x-EVM-GP)
이제 중요한 uboot에서 dtb을 찾고 zImage를 찾아 booting을 해보자
기본명령어는 다음과 같다
bootz ${loadaddr} - ${fdtaddr}
FDT (Flattened Device Tree) 는 DTB (Device Tree Blob)를 말하며 관련 구조는 Device Tree Spec를 참조
- Uboot Env MMC BOOT 분석
- bootcmd : dtb를 찾아 설정 후 mmcboot / usbboot/ nand boot로 순차실행
- findfdt : 현재 board_name에 따라 fdtfile 에 dtb 파일설정
- mmcboot: mmc device를 설정하고 rescan
- mmcboot: uEnv.txt (uboot Env) File이 존재한다면 찾아 설정
- mmcboot: importenv는 외부에 존재 할 경우, uenvcmd는 존재할 경우 동작 두부분 생략
- mmcboot: loadimage로 kernel을 load_addr로 load 한다 ( File system의 /boot)
- mmcboot: loadfdt로 dtb file을 fdt_addr로 load한다 (File system의 /boot)
- mmcboot: mmcargs로 kernel argument 설정
- mmcboot: bootz ${loadaddr} - ${fdtaddr} 로 kernel과 dtb booting
U-Boot# pri arch=arm baudrate=115200 board=am43xx board_name=AM43__GP board_rev=1.4A bootcmd=run findfdt; run mmcboot;run usbboot;run nandboot; bootdelay=1 bootdir=/boot bootenv=uEnv.txt bootfile=zImage bootm_size=0x10000000 bootpart=0:2 console=ttyO0,115200n8 cpu=armv7 dfu_alt_info_emmc=MLO raw 0x100 0x100 mmcpart 0;u-boot.img raw 0x300 0x1000 mmcpart 0 dfu_alt_info_mmc=boot part 0 1;rootfs part 0 2;MLO fat 0 1;spl-os-args fat 0 1;spl-os-image fat 0 1;u-boot.img fat 0 1;uEnv.txt fat 0 1 dfu_alt_info_ram=kernel ram 0x80200000 0x4000000;fdt ram 0x80f80000 0x80000;ramdisk ram 0x81000000 0x4000000 dfu_bufsiz=0x10000 eth1addr=34:b1:f7:30:fb:00 ethact=cpsw ethaddr=34:b1:f7:30:f7:fe fdt_addr_r=0x88000000 fdtaddr=0x88000000 fdtfile=undefined findfdt=if test $board_name = AM43EPOS; then setenv fdtfile am43x-epos-evm.dtb; fi; if test $board_name = AM43__GP; then setenv fdtfile am437x-gp-evm.dtb; fi; if test $board_name = AM43__SK; then setenv fdtfile am437x-sk-evm.dtb; fi; if test $fdtfile = undefined; then echo WARNING: Could not determine device tree; fi; importbootenv=echo Importing environment from mmc ...; env import -t $loadaddr $filesize kernel_addr_r=0x82000000 loadaddr=0x82000000 loadbootenv=load ${devtype} ${devnum} ${loadaddr} ${bootenv} loadfdt=load ${devtype} ${bootpart} ${fdtaddr} ${bootdir}/${fdtfile} loadimage=load ${devtype} ${bootpart} ${loadaddr} ${bootdir}/${bootfile} loadramdisk=load ${devtype} ${devnum} ${rdaddr} ramdisk.gz mmcargs=setenv bootargs console=${console} ${optargs} root=${mmcroot} rootfstype=${mmcrootfstype} mmcboot=mmc dev ${mmcdev}; setenv devnum ${mmcdev}; setenv devtype mmc; if mmc rescan; then echo SD/MMC found on device ${devnum};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 loadfdt; echo Booting from mmc${mmcdev} ...; run mmcargs; bootz ${loadaddr} - ${fdtaddr}; fi;fi; mmcdev=0 mmcroot=/dev/mmcblk0p2 rw mmcrootfstype=ext4 rootwait mtdids=nand0=nand.0 mtdparts=mtdparts=nand.0:256k(NAND.SPL),256k(NAND.SPL.backup1),256k(NAND.SPL.backup2),256k(NAND.SPL.backup3),512k(NAND.u-boot-spl-os),1m(NAND.u-boot),256k(NAND.u-boot-env),256k(NAND.u-boot-env.backup1),7m(NAND.kernel),-(NAND.file-system) nandargs=setenv bootargs console=${console} ${optargs} root=${nandroot} rootfstype=${nandrootfstype} nandboot=echo Booting from nand ...; run nandargs; nand read ${fdtaddr} NAND.u-boot-spl-os; nand read ${loadaddr} NAND.kernel; bootz ${loadaddr} - ${fdtaddr} nandroot=ubi0:rootfs rw ubi.mtd=NAND.file-system,4096 nandrootfstype=ubifs rootwait=1 netargs=setenv bootargs console=${console} ${optargs} root=/dev/nfs nfsroot=${serverip}:${rootpath},${nfsopts} rw ip=dhcp netboot=echo Booting from network ...; setenv autoload no; dhcp; tftp ${loadaddr} ${bootfile}; tftp ${fdtaddr} ${fdtfile}; run netargs; bootz ${loadaddr} - ${fdtaddr} nfsopts=nolock partitions=uuid_disk=${uuid_gpt_disk};name=rootfs,start=2MiB,size=-,uuid=${uuid_gpt_rootfs} ramargs=setenv bootargs console=${console} ${optargs} root=${ramroot} rootfstype=${ramrootfstype} ramdisk_addr_r=0x88080000 ramroot=/dev/ram0 rw ramrootfstype=ext2 rdaddr=0x88080000 rootpath=/export/rootfs soc=am33xx static_ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}::off stderr=serial stdin=serial stdout=serial usbargs=setenv bootargs console=${console} ${optargs} root=${usbroot} rootfstype=${usbrootfstype} usbboot=setenv devnum ${usbdev}; setenv devtype usb; usb start ${usbdev}; if usb dev ${usbdev}; then 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 loadfdt; echo Booting from usb ${usbdev}...; run usbargs;bootz ${loadaddr} - ${fdtaddr}; fi;fi;usb stop ${usbdev}; usbdev=0 usbnet_devaddr=34:b1:f7:30:fb:00 usbroot=/dev/sda2 rw usbrootfstype=ext4 rootwait vendor=ti ver=U-Boot 2014.07-gfb6ab76 (Jul 06 2015 - 16:10:49) Environment size: 4128/65532 bytes
- Uboot Env ( NFS - Network 고정 IP Mode)
만약 AP에서 dhcp 세부설정이 가능하다면 위와 같이 사용.
setenv ipaddr '192.168.1.101' setenv serverip '192.168.1.100' setenv netmask '255.255.255.0' setenv rootpath '/home/jhlee/am437x/targetNFS' setenv netargs 'setenv bootargs console=${console} ${optargs} root=/dev/nfs nfsroot=${serverip}:${rootpath},${nfsopts} rw ip=${ipaddr}' setenv netboot1 'echo Booting from network ...; setenv autoload no; tftp ${loadaddr} ${bootfile}; tftp ${fdtaddr} ${fdtfile}; run netargs; bootz ${loadaddr} - ${fdtaddr}' setenv bootcmd 'run findfdt; run netboot1;' setenv bootfile 'zImage' setenv fdtfile 'am437x-gp-evm.dtb' //직접 설정 후 run findfdt를 삭제가능
Linux server의 /tftpboot에 bootfile과 fdtfile을 보관해야한다.
2.2 Uboot Env 분석 (AM335x SK, Start Kit )
AM437x와 거의 동일하며 UBOOT에서 zImage와 *.dtb을 변경을 해주면된다.
- Device Tree Booting Command
bootz ${loadaddr} - ${fdtaddr}
- Uboot Env 분석
=>pri arch=arm args_fit=setenv bootargs console=${console} args_mmc=run finduuid;setenv bootargs console=${console} ${optargs} root=PARTUUID=${uuid} rw rootfstype=${mmcrootfstype} baudrate=115200 board=am335x board_name=A335X_SK board_rev=1.2B board_serial=34124P192908 boot_a_script=load ${devtype} ${devnum}:${distro_bootpart} ${scriptaddr} ${prefix}${script}; source ${scriptaddr} boot_efi_binary=load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_r} efi/boot/bootarm.efi; if fdt addr ${fdt_addr_r}; then bootefi ${kernel_addr_r} ${fdt_addr_r};elsebootefi ${kernel_addr_r} ${fdtcontroladdr};fi boot_extlinux=sysboot ${devtype} ${devnum}:${distro_bootpart} any ${scriptaddr} ${prefix}extlinux/extlinux.conf boot_fdt=try boot_fit=0 boot_net_usb_start=usb start boot_prefixes=/ /boot/ boot_script_dhcp=boot.scr.uimg boot_scripts=boot.scr.uimg boot.scr boot_targets=mmc0 legacy_mmc0 mmc1 legacy_mmc1 nand0 pxe dhcp bootcmd=if test ${boot_fit} -eq 1; then run update_to_fit;fi;run findfdt; run init_console; run envboot; run distro_bootcmd bootcmd_dhcp=run boot_net_usb_start; if dhcp ${scriptaddr} ${boot_script_dhcp}; then source ${scriptaddr}; fi bootcmd_legacy_mmc0=setenv mmcdev 0; setenv bootpart 0:2 ; run mmcboot bootcmd_legacy_mmc1=setenv mmcdev 1; setenv bootpart 1:2 ; run mmcboot bootcmd_mmc0=setenv devnum 0; run mmc_boot bootcmd_mmc1=setenv devnum 1; run mmc_boot bootcmd_nand=run nandboot bootcmd_pxe=run boot_net_usb_start; dhcp; if pxe get; then pxe boot; fi bootcount=4 bootdelay=2 bootdir=/boot bootenvfile=uEnv.txt bootfile=zImage bootm_size=0x10000000 bootpart=0:2 bootscript=echo Running bootscript from mmc${mmcdev} ...; source ${loadaddr} console=ttyO0,115200n8 cpu=armv7 dfu_alt_info_emmc=rawemmc raw 0 3751936 dfu_alt_info_mmc=boot part 0 1;rootfs part 0 2;MLO fat 0 1;MLO.raw raw 0x100 0x100;u-boot.img.raw raw 0x300 0x400;spl-os-args.raw raw 0x80 0x80;spl-os-image.raw raw 0x900 0x2000;spl-os-args fat 0 1;spl-os-image fat 0 1;u-boot.img fat 0 1;uEnv.txt fat 0 1 dfu_alt_info_nand=SPL part 0 1;SPL.backup1 part 0 2;SPL.backup2 part 0 3;SPL.backup3 part 0 4;u-boot part 0 5;u-boot-spl-os part 0 6;kernel part 0 8;rootfs part 0 9 dfu_alt_info_ram=kernel ram 0x80200000 0xD80000;fdt ram 0x80F80000 0x80000;ramdisk ram 0x81000000 0x4000000 distro_bootcmd=for target in ${boot_targets}; do run bootcmd_${target}; done efi_dtb_prefixes=/ /dtb/ /dtb/current/ envboot=mmc dev ${mmcdev}; if mmc rescan; then echo SD/MMC found on device ${mmcdev};if run loadbootscript; then run bootscript;else if run loadbootenv; then echo Loaded env from ${bootenvfile};run importbootenv;fi;if test -n $uenvcmd; then echo Running uenvcmd ...;run uenvcmd;fi;fi;fi; eth1addr=d4:94:a1:86:70:e1 ethaddr=d4:94:a1:86:70:e0 fdt_addr_r=0x88000000 fdtaddr=0x88000000 fdtcontroladdr=8ef282f8 fdtfile=undefined findfdt=if test $board_name = A335BONE; then setenv fdtfile am335x-bone.dtb; fi; if test $board_name = A335BNLT; then setenv fdtfile am335x-boneblack.dtb; fi; if test $board_name = BBG1; then setenv fdtfile am335x-bonegreen.dtb; fi; if test $board_name = A33515BB; then setenv fdtfile am335x-evm.dtb; fi; if test $board_name = A335X_SK; then setenv fdtfile am335x-evmsk.dtb; fi; if test $board_name = A335_ICE; then setenv fdtfile am335x-icev2.dtb; fi; if test $fdtfile = undefined; then echo WARNING: Could not determine device tree to use; fi; finduuid=part uuid mmc ${bootpart} uuid fit_bootfile=fitImage.itb fit_loadaddr=0x88000000 importbootenv=echo Importing environment from mmc${mmcdev} ...; env import -t ${loadaddr} ${filesize} init_console=if test $board_name = A335_ICE; then setenv console ttyO3,115200n8;else setenv console ttyO0,115200n8;fi; kernel_addr_r=0x82000000 load_efi_dtb=load ${devtype} ${devnum}:${distro_bootpart} ${fdt_addr_r} ${prefix}${efi_fdtfile} loadaddr=0x82000000 loadbootenv=fatload mmc ${mmcdev} ${loadaddr} ${bootenvfile} loadbootscript=load mmc ${mmcdev} ${loadaddr} boot.scr loadfdt=load ${devtype} ${bootpart} ${fdtaddr} ${bootdir}/${fdtfile} loadfit=run args_fit; bootm ${loadaddr}#${fdtfile}; loadimage=load ${devtype} ${bootpart} ${loadaddr} ${bootdir}/${bootfile} loadramdisk=load mmc ${mmcdev} ${rdaddr} ramdisk.gz mmc_boot=if mmc dev ${devnum}; then setenv devtype mmc; run scan_dev_for_boot_part; fi mmcboot=mmc dev ${mmcdev}; setenv devnum ${mmcdev}; setenv devtype mmc; if mmc rescan; then echo SD/MMC found on device ${mmcdev};if run loadimage; then if test ${boot_fit} -eq 1; then run loadfit; else run mmcloados;fi;fi;fi; mmcdev=0 mmcloados=run args_mmc; if test ${boot_fdt} = yes || test ${boot_fdt} = try; then if run loadfdt; then bootz ${loadaddr} - ${fdtaddr}; else if test ${boot_fdt} = try; then bootz; else echo WARN: Cannot load the DT; fi; fi; else bootz; fi; mmcrootfstype=ext4 rootwait mtdids=nand0=nand.0 mtdparts=mtdparts=nand.0:128k(NAND.SPL),128k(NAND.SPL.backup1),128k(NAND.SPL.backup2),128k(NAND.SPL.backup3),256k(NAND.u-boot-spl-os),1m(NAND.u-boot),128k(NAND.u-boot-env),128k(NAND.u-boot-env.backup1),8m(NAND.kernel),-(NAND.file-system) nandargs=setenv bootargs console=${console} ${optargs} root=${nandroot} rootfstype=${nandrootfstype} nandboot=echo Booting from nand ...; run nandargs; nand read ${fdtaddr} NAND.u-boot-spl-os; nand read ${loadaddr} NAND.kernel; bootz ${loadaddr} - ${fdtaddr} nandroot=ubi0:rootfs rw ubi.mtd=NAND.file-system,2048 nandrootfstype=ubifs rootwait=1 netargs=setenv bootargs console=${console} ${optargs} root=/dev/nfs nfsroot=${serverip}:${rootpath},${nfsopts} rw ip=dhcp netboot=echo Booting from network ...; setenv autoload no; dhcp; run netloadimage; run netloadfdt; run netargs; bootz ${loadaddr} - ${fdtaddr} netloadfdt=tftp ${fdtaddr} ${fdtfile} netloadimage=tftp ${loadaddr} ${bootfile} nfsopts=nolock partitions=uuid_disk=${uuid_gpt_disk};name=rootfs,start=2MiB,size=-,uuid=${uuid_gpt_rootfs} pxefile_addr_r=0x80100000 ramargs=setenv bootargs console=${console} ${optargs} root=${ramroot} rootfstype=${ramrootfstype} ramboot=echo Booting from ramdisk ...; run ramargs; bootz ${loadaddr} ${rdaddr} ${fdtaddr} ramdisk_addr_r=0x88080000 ramroot=/dev/ram0 rw ramrootfstype=ext2 rdaddr=0x88080000 rootpath=/export/rootfs scan_dev_for_boot=echo Scanning ${devtype} ${devnum}:${distro_bootpart}...; for prefix in ${boot_prefixes}; do run scan_dev_for_extlinux; run scan_dev_for_scripts; done;run scan_dev_for_efi; scan_dev_for_boot_part=part list ${devtype} ${devnum} -bootable devplist; env exists devplist || setenv devplist 1; for distro_bootpart in ${devplist}; do if fstype ${devtype} ${devnum}:${distro_bootpart} bootfstype; then run scan_dev_for_boot; fi; done scan_dev_for_efi=setenv efi_fdtfile ${fdtfile}; if test -z "${fdtfile}" -a -n "${soc}"; then setenv efi_fdtfile ${soc}-${board}${boardver}.dtb; fi; for prefix in ${efi_dtb_prefixes}; do if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${efi_fdtfile}; then run load_efi_dtb; fi;done;if test -e ${devtype} ${devnum}:${distro_bootpart} efi/boot/bootarm.efi; then echo Found EFI removable media binary efi/boot/bootarm.efi; run boot_efi_binary; echo EFI LOAD FAILED: continuing...; fi; setenv efi_fdtfile scan_dev_for_extlinux=if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}extlinux/extlinux.conf; then echo Found ${prefix}extlinux/extlinux.conf; run boot_extlinux; echo SCRIPT FAILED: continuing...; fi scan_dev_for_scripts=for script in ${boot_scripts}; do if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${script}; then echo Found U-Boot script ${prefix}${script}; run boot_a_script; echo SCRIPT FAILED: continuing...; fi; done scriptaddr=0x80000000 soc=am33xx spiargs=setenv bootargs console=${console} ${optargs} root=${spiroot} rootfstype=${spirootfstype} spiboot=echo Booting from spi ...; run spiargs; sf probe ${spibusno}:0; sf read ${loadaddr} ${spisrcaddr} ${spiimgsize}; bootz ${loadaddr} spibusno=0 spiimgsize=0x362000 spiroot=/dev/mtdblock4 rw spirootfstype=jffs2 spisrcaddr=0xe0000 static_ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}::off stderr=serial@44e09000 stdin=serial@44e09000 stdout=serial@44e09000 update_to_fit=setenv loadaddr ${fit_loadaddr}; setenv bootfile ${fit_bootfile} usb_boot=usb start; if usb dev ${devnum}; then setenv devtype usb; run scan_dev_for_boot_part; fi usbnet_devaddr=de:ad:be:ef:00:01 vendor=ti ver=U-Boot 2016.05-g6c5519b6fc (Dec 14 2016 - 19:14:27 -0500) Environment size: 8557/131068 bytes
댓글 없음 :
댓글 쓰기