Utility to modify UBOOT-Parameter out of linux ?!

This forum is for users of Microchip MPUs and who are interested in using Linux OS.

Moderator: nferre

ManuelSahm
Posts: 82
Joined: Tue Jun 26, 2007 6:27 pm

Utility to modify UBOOT-Parameter out of linux ?!

Tue Mar 25, 2008 5:36 pm

Hello,

how is it possible to modify the uboot enviroment variables out of linux ?

I use a NAND flash.

Thank you very very very much

Manuel Sahm
blue_z
Location: USA
Posts: 1940
Joined: Thu Apr 19, 2007 10:15 pm

Tue Mar 25, 2008 10:55 pm

Hi there

You could write your own utility, assuming

1. the area of the NAND flash containing the environment variables is properly declared as an MTD partition, and it has a char device node in /dev

2. you obtain a CRC32 function (you can get the source from U-Boot)

The layout of the env vars is simple. There's a 4-byte CRC32, followed by null-terminated text strings. The CRC32 is calculated over the entire partition except for the first 4 bytes. You could use the built-in U-Boot commands cp, mm and crc32 to experiment.

Regards
ManuelSahm
Posts: 82
Joined: Tue Jun 26, 2007 6:27 pm

Wed Mar 26, 2008 9:21 am

Hello,

thank you for your help.

Could you please help me developing such a small program ?

The Enviroment is in /dev/mtd1 with offset 0x40000.
The size of the enviroment is 0x20000

[The pageSize of the NAND is 2k]
[The EraseBlockSize is 128k]

So is it correct, that there schould be a Variable mabye called :
char enviroment[0x20000];
char CRC32[4];
char Data[0x20000];

memcpy(&Data[0], "Bootdelay=0",11);
//crc Calculation over Data...

memcpy(&enviroment[0], &CRC32[0], 4);
memcpy(&enviroment[4], &Data[0], 11);

---------------------------------------------------------------------------
How do I write this variable in the nand flash ?
and what about the ECC ?

Thanks very very much...

Manuel Sahm
blue_z
Location: USA
Posts: 1940
Joined: Thu Apr 19, 2007 10:15 pm

Wed Mar 26, 2008 9:34 pm

Hi there

You're using Linux now, and MTD will make its partition look like a file (just like every device is made to resemble a file), and all the low level pagesize and erase blocksize stuff is handled/hidden in the lower-level (NAND) device driver(s). The 0x40000 offset of the partition within the NAND device is taken care of when the partition is defined; the app doesn't worry about it.

You should try to read the partition before you write it. Something like

Code: Select all

fd = open("/dev/mtd1", O_RDONLY);
rcount = read(fd, &ev_part, PART_SIZE);
close(fd);
where

Code: Select all

#define PART_SIZE 0x20000
struct {
        ulong    crc;
        uchar    envvars[PART_SIZE - 4];
} ev_part;

Regards
ManuelSahm
Posts: 82
Joined: Tue Jun 26, 2007 6:27 pm

Thu Mar 27, 2008 8:21 pm

Hi ,

Is it possible to use the read function with an offset, because my uboot enviroment is /dev/mtd1 + 0x40000 and has a size of 0x20000

OK Ithink in the first 4 bytes the CRC is saved, correct ?

Now my application modifies the ev_part.envars.

How could I make the new CRC vlaue for my modified envars[] ?

AND

How could I write it in the nandflash ?
Maybe this is solution ?

Code: Select all

fd = open("/dev/mtd1", O_RDRW);
rcount = write(fd, &ev_part, PART_SIZE);
close(fd);
Do I have to calculate an ECC too, and write it into flash ?
How could I make this, if it´s necessary ?


Thank you very very much
blue_z
Location: USA
Posts: 1940
Joined: Thu Apr 19, 2007 10:15 pm

Thu Mar 27, 2008 9:42 pm

Hi there
Is it possible to use the read function with an offset, because my uboot enviroment is /dev/mtd1 + 0x40000 and has a size of 0x20000
You could, but that's a bad design.
Defining the MTD partitions to match the data organization makes more sense. There's no requirement that the MTD partitions in Linux (w/respect to offset, size and number of partitions) match the partitions defined in U-Boot.
OK Ithink in the first 4 bytes the CRC is saved, correct ?
That's what I wrote in the 1st reply, and showed in the structure.
You can confirm this yourself by using U-Boot md commands.
How could I make the new CRC vlaue for my modified envars[] ?
Maybe there's a CRC32 function in libC, I don't know.
How could I write it in the nandflash ?
That code should work
Do I have to calculate an ECC too, and write it into flash ?
ECC is usually handled in hardware.

Regards
ManuelSahm
Posts: 82
Joined: Tue Jun 26, 2007 6:27 pm

Wed Apr 02, 2008 11:19 am

Hello,

I need help with the flag byte for redundant nand Uboot Enviroment.

The Enviroment is: 4 Byte CRC; 1 Byte flags, and 0x20000-5 Byte Data.

What about the flags byte, which values should I store there ?

Thank you
svolpe
Posts: 12
Joined: Sun May 11, 2008 9:20 pm

U-boot has this utility built in

Sun May 11, 2008 9:29 pm

There is tools built into the u-boot project that allows you to compile a tool for Linux to set u-boot variables.

From the u-boot source tree type:
make env
This will make the Linux tool fw_printenv. If you run fw_printenv in Linux it will list all the u-boot environment variables. If you make a symbolic link "fw_setenv" pointing to fw_printenv and run the symbolic link fw_setenv it will set any u-boot variable you pass it.:

example:
ln -s /sbin/fw_setenv fw_setenv
./fw_setenv bootdelay 5


You also need to make a config file "/etc/fw_env.config" on the target system and set it up correctly, here is an example of the one I use:
/dev/mtd1 is were my u-boot configuration is stored.

# Configuration file for fw_(printenv/saveenv) utility.
# Up to two entries are valid, in this case the redundand
# environment sector is assumed present.

# MTD device name Device offset Env. size Flash sector size
/dev/mtd1 0x00000 0x40000 0x40000
J2
Location: France
Posts: 1
Joined: Sun Nov 04, 2007 4:43 pm

Fri Jul 11, 2008 2:18 pm

hello.
I have make my own linux, whith the help of linux4sam.org.
I have also make env tool of u-boot.
I can read my u-boot environment but i can't write.
(my u-boot environment is in nandflash and i follow the linux4sam.org memory map)

Code: Select all

root@at91sam9263ek:~$ ./fw_printenv
ethaddr=3a:1f:34:08:54:54
bootdelay=3
baudrate=115200
stdin=serial
stdout=serial
stderr=serial
bootargs=mem=64M console=ttyS0,115200 root=/dev/mtdblock1 rw rootfstype=jffs2
bootcmd=nand read 0x22200000 0x00200000 0x0015FB98; bootm 0x22200000

Code: Select all

Unlocking flash...
Done
Erasing old environment...nand_write: Attempt to write not page aligned data

Done
Writing environment to /dev/mtd0...
CRC write error on /dev/mtd0: Invalid argument
Error: can't write fw_env to flash
this is my config file :

Code: Select all

root@at91sam9263ek:~$ cat /etc/fw_env.config
# Configuration file for fw_(printenv/saveenv) utility.
# Up to two entries are valid, in this case the redundand
# environment sector is assumed present.

# MTD device name       Device offset   Env. size       Flash sector size
/dev/mtd0               0x60000         0x20000         0x20000
/dev/mtd0               0x80000         0x20000         0x20000
I try to debug fw_env.c , the error "nand_write: Attempt to write not page aligned data" seems to be near of:

Code: Select all

if (write (fdr, &environment, len) != len) {
			fprintf (stderr,
				"CRC write error on %s: %s\n",
				DEVNAME (otherdev), strerror (errno));
			return (-1);
}
I use u-boot version provided by linux4sam (1.1.5 patch 1.7). I try the last version 1.3.3 and i have the same issue.

If anyone have an idea to help me?
Thanks a lot.

ps: when i use the Linux binaries provided directly by linux4sam i have the same issue too.
Support of mtd is enable into the kernel.
ajits
Posts: 4
Joined: Wed Dec 31, 2008 4:24 pm

Re: Utility to modify UBOOT-Parameter out of linux ?!

Thu Apr 09, 2009 10:42 pm

Facing the same issue, has anyone been able to resolve
blue_z
Location: USA
Posts: 1940
Joined: Thu Apr 19, 2007 10:15 pm

Re: Utility to modify UBOOT-Parameter out of linux ?!

Fri Apr 10, 2009 9:29 pm

Hi there

You need to evaluate the following numbers:
1. the start and length of the U-Boot partition for the environment variables.
2. the start and length of the MTD partition that corresponds to the above U-Boot partition (the length might be longer).
3. the flash read/write size (page size?) and the flash erase size (sector size?).

IIRC U-Boot likes the length of its partition to be multiples of a nice round power of 2 number. MTD likes its partition length to be a multiple of the sector size. If you're using DataFlash, then these numbers will not match up.

You may have to start over and redefine the partitions in U-Boot and/or MTD to line thing up for easy read/write access. Or else you have to read/save the portions of the partitions before and after the U-Boot partition you are really changing, then erase the encompassing sector(s), and then write back the untouched leading partition, the environment variables and the untouched trailing partition. You might have to define a mtd0 partition to encompass the entire flash device to provide linear address access.

The flash filesystem hides all of these tedious page and sector boundary issues. But if you want to access the flash at a lower level through MTD then you will have to pay attention to page/sector alignment/boundaries of flash memory devices.

Regards
_yagi_
Posts: 1
Joined: Wed Apr 15, 2009 3:15 pm

Re: Utility to modify UBOOT-Parameter out of linux ?!

Wed Apr 15, 2009 4:39 pm

try using the latest version of u-boot's env tools (u-boot/tools/env). in versions prior to september 2008 there's a bug in the nand routine
ajits
Posts: 4
Joined: Wed Dec 31, 2008 4:24 pm

Re: Utility to modify UBOOT-Parameter out of linux ?!

Tue Apr 28, 2009 3:18 pm

i took uboot-2009.01 and it indeed works, lots of code churn in fw_env.c
Thanks Yagi

Return to “LINUX”

Who is online

Users browsing this forum: No registered users and 2 guests