How to modify the uboot environment from userspace

From IGEP - ISEE Wiki

Revision as of 19:18, 12 October 2010 by Marc (talk | contribs)

Jump to: navigation, search

Overview

This 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 emoticon

tools needed

In 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 emoticon

In this file you have to specify:

1.- MTD device name 2.- Device Offset 3.- Environment Size 4.- Flash sector size 5.- Number of sectors (ignored in NOR)

Ok, 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"


through "dmesg" I could see this line indicating something was wrong:


[ 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"


I'll continue in a couple of hours.

Feedback and Contributing

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