如何修改uboot的环境变量env的值来指定uImage的名字
今天繼續玩基于uboot的nfs。昨天總算是基本搞清了make zImage和make uImage的區別,那么今天就來實際編譯幾個玩一玩。
不過,在利用mkimage工具對zImage鏡像文件加工完、生成了符合uboot格式的uImage鏡像文件之后,我突然意識到,此時的鏡像文件,已經完完全全是名副其實的uboot格式了,那么此時再將其稱為zImage.img,其實已經是不合適的,應該改名為uImage.img才對。也就是說,我在(make zImage和make uImage的區別和mkimage工具的使用)博客中引用的tekkaman前輩的下面這條命令:
mkimage -n 'tekkaman' -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008040 -d zImage zImage.img其實應該是有瑕疵的。應該要將其中的zImage.img改為uImage.img才對。如下:
mkimage -n 'tekkaman' -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008040 -d zImage uImage.img于是,我將鏡像文件改名,復制到nfs目錄下,然后啟動開發板。卻發現,開發板中的uboot不認uImage.img的名字,它只認zImage.img,引導內核失敗,要修改一下。
一開始我嘗試通過修改uboot的源代碼的方法來做,修改mini2440.h頭文件中的相關宏的定義:
#define CONFIG_BOOTCOMMAND "nfs 0x30008000 192.168.100.120:/opt/FriendlyARM/mini2440/rootfs/uImage.img;bootm"修改完后使用super-vivi將uboot燒錄進去,重啟開發板,卻發現問題仍然存在。這是為什么呢?
經過一番思索,我找到原因了。這是因為uboot已經將zImage.img這個名字寫入了它的環境變量中。光修改上面的宏是沒有用的,必須修改它的環境變量,否則它不會接受這個新的名字。
可是,要如何來修改它的環境變量呢?網上百度,也沒度到什么對應的資料,看來還得自己去摸索。好在uboot提供了一整套方便使用的命令。直接在uboot啟動時,敲擊鍵盤進入它的命令行模式,輸入help命令便可以看到,如下所示:
[u-boot@MINI2440]# help ? - alias for 'help' askenv - get environment variables from stdin base - print or set address offset bdinfo - print Board Info structure bmp - manipulate BMP image data boot - boot default, i.e., run 'bootcmd' bootd - boot default, i.e., run 'bootcmd' bootelf - Boot from an ELF image in memory bootm - boot application image from memory bootp - boot image via network using BOOTP/TFTP protocol bootvx - Boot vxWorks from an ELF image cmp - memory compare coninfo - print console devices and information cp - memory copy crc32 - checksum calculation date - get/set/reset date & time dcache - enable or disable data cache dhcp - boot image via network using DHCP/TFTP protocol echo - echo args to console editenv - edit environment variable eeprom - EEPROM sub-system erase - erase FLASH memory exit - exit script false - do nothing, unsuccessfully fatinfo - print information about filesystem fatload - load binary file from a dos filesystem fatls - list files in a directory (default /) flinfo - print FLASH memory information fsinfo - print information about filesystems fsload - load binary file from a filesystem image go - start application at address 'addr' help - print command description/usage i2c - I2C sub-system icache - enable or disable instruction cache iminfo - print header information for application image imls - list all images found in flash imxtract- extract a part of a multi-image itest - return true/false on integer compare loadb - load binary file over serial line (kermit mode) loads - load S-Record file over serial line loadx - load binary file over serial line (xmodem mode) loady - load binary file over serial line (ymodem mode) loop - infinite loop on address range ls - list files in a directory (default /) md - memory display mm - memory modify (auto-incrementing address) mmc - MMC sub-system mtest - simple RAM read/write test mw - memory write (fill) nand - NAND sub-system nboot - boot from NAND device nfs - boot image via network using NFS protocol nm - memory modify (constant address) ping - send ICMP ECHO_REQUEST to network host printenv- print environment variables protect - enable or disable FLASH write protection rarpboot- boot image via network using RARP/TFTP protocol reginfo - print register information reset - Perform RESET of the CPU run - run commands in an environment variable saveenv - save environment variables to persistent storage setenv - set environment variables showvar - print local hushshell variables sleep - delay execution for some time source - run script from memory test - minimal test like /bin/sh tftpboot- boot image via network using TFTP protocol true - do nothing, successfully unzip - unzip a memory region usb - USB sub-system usbboot - boot from USB device usbslave- usbslave - get file from host(PC)version - print monitor version找到其中與環境變量env相關的命令。一個是打印當前的環境變量的命令printenv,一個是修改環境變量的命令editenv,還有一個是保存環境變量到存儲器的命令saveenv。一個一個的用起來吧。
1、首先把當前的環境變量env的值打印出來。如下:
[u-boot@MINI2440]# printenv bootargs=noinitrd root=/dev/nfs rw nfsroot=192.168.100.120:/opt/FriendlyARM/mini2440/rootfs ip=192.168.100.230:192.168.100.120:192.168.100.1:255.255.255.0 console=ttySAC0,115200 init=/linuxrc mem=64M bootcmd=nfs 0x30008000 192.168.100.120:/opt/FriendlyARM/mini2440/rootfs/zImage.img;bootm bootdelay=10 baudrate=115200 ethaddr=08:08:11:18:12:27 ipaddr=192.168.100.230 serverip=192.168.100.120 gatewayip=192.168.100.1 netmask=255.255.255.0 tekkaman=bmp d 70000stdin=serial stdout=serial stderr=serial ethact=dm9000Environment size: 515/131068 bytes可以看到,變量bootcmd的值,確實是zImage.img。那么接下來我們就要修改這個參數就好。使用editenv這個命令,如下:
[u-boot@MINI2440]# editenv bootcmd edit: nfs 0x30008000 192.168.100.120:/opt/FriendlyARM/mini2440/rootfs/uImage.img;bootm修改完后記得手動保存一下,否則uboot是不會自動將你的修改動作存入存儲器的,一重啟就丟失了,白弄了。如下:
[u-boot@MINI2440]# saveenv Saving Environment to NAND... Erasing Nand... Erasing at 0x7c00000000002 -- 0% complete. Writing to Nand... doneOK,修改完成了。如果不太放心有沒有修改成功,那么我們再將此刻最新的環境變量值打印出來看看吧,如下:
[u-boot@MINI2440]# printenv bootargs=noinitrd root=/dev/nfs rw nfsroot=192.168.100.120:/opt/FriendlyARM/mini2440/rootfs ip=192.168.100.230:192.168.100.120:192.168.100.1:255.255.255.0 console=ttySAC0,115200 init=/linuxrc mem=64M bootdelay=10 baudrate=115200 ethaddr=08:08:11:18:12:27 ipaddr=192.168.100.230 serverip=192.168.100.120 gatewayip=192.168.100.1 netmask=255.255.255.0 tekkaman=bmp d 70000stdin=serial stdout=serial stderr=serial ethact=dm9000 bootcmd=nfs 0x30008000 192.168.100.120:/opt/FriendlyARM/mini2440/rootfs/uImage.img;bootmEnvironment size: 515/131068 bytes可以看到,變量bootcmd的值,已經成功修改為了uImage.img。OK,此時可以放心的重啟了,輸入reset命令就好!
uboot重啟完后,可以看到,順利的按照新的路徑和文件名定位到內核文件,成功的引導了系統啟動!
搞定,收工!
總結
以上是生活随笔為你收集整理的如何修改uboot的环境变量env的值来指定uImage的名字的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Win10怎么卸载自带软件 Win10自
- 下一篇: 嵌入式linux开发业内各个常用开源项目