How to modify the uboot environment from userspace
OverviewThis How-To is meant to be a starting point for people to learn how access to the uboot environment from userspace. This is my first wiki page so please be benevolent with the formatting?:-) Tools neededIn order to modify the uboot environment variables from userspace we will need a program called fw_setenv,we can compile this program ourselves from the u-boot sources,follow the instructions in this wiki page and then proceed to compile with (don't modify the .h file as it says in the tools/env/README file): make env This will give us fw_printenv,in order to get fw_setenv we just have to change the name of the file. Magic!! cp fw_printenv fw_setenv The next thing we will need is the fw_env.config file with the appropiate settings for our board. Here comes the confusion?:-) In this file you have to specify:
Finding out the correct values for fw_env.configOk,so in order to get all this information the easyest thing is to read it from dmesg or from /proc/mtd cat /proc/mtd All my initial confusion comes from using an incorrect kernel,my first tries where with 2.6.28.10 and the driver used to read mtd was NAND,in the kernel configuration file I only had?: CONFIG_MTD_NAND=y being the output of /proc/mtd: dev: size erasesize name mtd0: 00080000 00040000 "X-Loader" mtd1: 001e0000 00040000 "U-Boot" mtd2: 00020000 00040000 "U-Boot Env" mtd3: 00500000 00040000 "Kernel" mtd4: 1f880000 00040000 "File System"
[ 1174.517120] Creating 5 MTD partitions on "omap2-onenand": [ 1174.522552] 0x00000000-0x00080000?: "X-Loader" [ 1174.528381] 0x00080000-0x00260000?: "U-Boot" [ 1174.533508] 0x00260000-0x00280000?: "U-Boot Env" [ 1174.538177] mtd: partition "U-Boot Env" doesn't start on an erase block boundary -- force read-only [ 1174.548126] 0x00280000-0x00780000?: "Kernel" [ 1174.553192] 0x00780000-0x20000000?: "File System" But if we use the aproppiate kernel,in my case 2.6.33.7-0 with the onenand driver instead of the nand driver: CONFIG_MTD_ONENAND=y The output of /proc/mtd is different: dev: size erasesize name mtd0: 00080000 00040000 "X-Loader" mtd1: 00180000 00040000 "U-Boot" mtd2: 00080000 00040000 "Environment" mtd3: 00300000 00040000 "Kernel" mtd4: 1fa80000 00040000 "File System" Now we can fill in all the values we needed (that's what I thought)
I figured these out by reading different posts and by trial and error,but I still don't understand the environment size value or the flash sector size,I can imagine the device offset is 0 if you specify /dev/mtd2 but I'd be great if someone could edit this page and point out why are this the correct values. Giving it a tryIn order to give it a try is better to poke with fw_printenv than with fw_setenv,because the first one just tries to read,so go ahead and try it: fw_printenv this should output something like: ethact=smc911x-0 distro=poky project=poky-image-sato ipaddr=192.168.254.254 netmask=255.255.255.0 gatewayip=192.168.254.10 serverip=192.168.254.10 addip=setenv bootargs ${bootargs} ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}::eth0: mmc-boot=mmc init 0; if fatload mmc 0 80000000 boot.ini; then source; else if fatload mmc 0 80000000 uImage; then run mmc-bootargs; bootm; fi; fi onenand-bootargs=setenv bootargs ${bootargs-base} root=/dev/mtdblock4 rootfstype=jffs2?; run addip onenand-boot=run onenand-bootargs; onenand read 80000000 280000 400000?; bootm 80000000 nfs-bootargs=setenv bootargs ${bootargs-base} root=/dev/nfs nfsroot=${serverip}:/srv/nfs/${distro}/${project}/${machine}?; run addip nfs-boot=if ping ${serverip}; then run nfs-bootargs; tftp 0x80000000 ${distro}/${project}/${machine}/uImage; bootm; fi; machine=igep0020 mmc-bootargs=setenv bootargs ${bootargs-base} root=/dev/mmcblk0p2 rw rootwait dieid=${dieid#} dieid#=638a00040000000004036abc07016018 mpurate=110 stdin=serial stdout=serial stderr=serial bootargs-base=mem=512M console=ttyS2,115200n8 console=tty0 omapfb.mode=dvi:1024x768MR-16@60 mpurate=110 bootcmd=run onenand-boot; run mmc-boot; if you get something like: Warning: Bad CRC,using default environment bootcmd=bootp; setenv bootargs root=/dev/nfs nfsroot=${serverip}:${rootpath} ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}::off; bootm bootdelay=5 baudrate=115200 it means the values in /etc/fw_env.config are not correct,so don't even try fw_setenv Now that we found out the correct values for /etc/fw_env.config you can just use fw_setenv with the same syntax as if you were in u-boot command line,to assing a value don't use "=" but a space. ./fw_setenv test 1234 then fw_printenv should output test=1234 notice we didn't need to use saveenv as we would do in u-boot command line. That's it!! Creating articles in the wiki is a collaborative process,at any point,if you see a mistake you can contribute to this article. Please,use the discussion tab for user comments. This is useful to separate page content and the discussion thereof and also,if you don't want to give normal users the right to edit the page but still want user contributed notes. Editing permissions are restricted to registered users.?Register in the main IGEP site?and you will have single sign-on. Consult the?User's Guide?for information on using the wiki software. There is a set of?Wiki contribution guidelines. References
make env For building against older versions of the?MTD?headers (meaning before v2.6.8-rc1) it is required to pass the argument "MTD_VERSION=old" to make: make MTD_VERSION=old env The resulting binary is called? These tools work exactly like the U-Boot commands? # Configuration file for fw_(printenv/saveenv) utility. # Up to two entries are valid,in this case the redundand # environment sector is assumed present. ######################################################################### # For TQM8xxL modules: ######################################################################### # MTD device name Device offset Env. size Flash sector size /dev/mtd0 0x8000 0x4000 0x4000 /dev/mtd0 0xC000 0x4000 0x4000 ######################################################################### # For NSCU: ######################################################################### # MTD device name Device offset Env. size Flash sector size #/dev/mtd1 0x0000 0x8000 0x20000 #/dev/mtd2 0x0000 0x8000 0x20000 ######################################################################### # For LWMON ######################################################################### # MTD device name Device offset Env. size Flash sector size #/dev/mtd1 0x0000 0x2000 0x40000 代码分析: README: This is a demo implementation of a Linux command line tool to access For the run-time utiltity configuration uncomment the line 这个有误,应该是用配置文件时,不要注释掉这个宏 See comments in the fw_env.config file for definitions for the Configuration can also be done via #defines in the fw_env.h file. The #define HAVE_REDUND??? /* For systems with 2 env sectors */ Current configuration matches the environment layout of the TRAB HAVE_REDUND是用来环境变量备份用的 Un-define HAVE_REDUND,if you want to use the utlities on a system The DEVICEx_NAME constants define which MTD character devices are to The DEVICEx_OFFSET constants define the environment offset within the ENVx_SIZE defines the size in bytes taken by the environment,which DEVICEx_ESIZE defines the size of the first sector in the flash ? DEVICEx_NAME设备名 DEVICEx_OFFSET设备中环境变量的偏移 ENVx_SIZE 环境变量大小,可能比1sector小 ? 查看环境变量大小: pri查看 Environment size: 1560/4092 bytes include/configs/mv_kv.h #define CFG_ENV_SIZE??????? 0x1000 所以大小是0x1000 查看环境变量偏移: #define CFG_MONITOR_LEN??????????? (512 << 10)??? /* Reserve 512 kB for Monitor */?? uboot镜像长度 0x80000 =512k //uboot的基址和环境变量的基址 #define CFG_ENV_SIZE??????? 0x1000?? //4k ? 根据CFG_ENV_ADDR 知道环境变量偏移是0x80000 ? 查看erasesize /opt/qtmarvell/mvqt/tools # cat /proc/mtd? ? 编译fw_printenv: 下载http://ftp.denx.de/pub/u-boot/u-boot-2011.03.tar.bz2 根目录下: make env HOSTCC=arm-mv5sft-linux-gnueabi-gcc ln -s fw_printenv fw_setenv ? 修改fw_env.config ,根据上面的信息: /opt/qtmarvell/mvqt/tools # cat fw_env.config? # MTD device name?????? Device offset?? Env. size?????? Flash sector size?????? Number of sectors /dev/mtd0?????????????? 0x80000???????? 0x1000????????? 0x10000 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |