Linux Development :  Bluewater Systems Support Forum
Covers issues with Linux development, such as tool chains, packages, kernel issues etc... 
Access to U-Boot environment vars from Linux
Posted by: pas ()
Date: September 01, 2009 06:40AM

Has anyone successfully used the fw_setenv tool (from u-boot/tools/env) to modify
or set new U-Boot environment vars from linux? Also is there a backup image of the Parameters
flash partition for the Snapper available on-line?

I have built the U-Boot fw_* tools and fw_printenv correctly shows my U-Boot environment,
unfortunately when I used fw_setenv it erased my U-Boot environment and I had not made
a backup.

Regards,

Pete

Options: ReplyQuote
Re: Access to U-Boot environment vars from Linux
Posted by: pas ()
Date: September 02, 2009 11:36AM

I used the SA-MBA tool to rewrite the environment. I still can't get the fw_setenv
tool to work correctly:

root@snapper:~$ ./fw_setenv myarg 1234
Unlocking flash...
nand_write: Attempt to write not page aligned data
Done
Erasing old environment...
Done
Writing environment to /dev/mtd2...
CRC write error on /dev/mtd2: Invalid argument
Error: can't write fw_env to flash

The fw_env.config file:
cat /etc/fw_env.config

/dev/mtd2 0x00000 0x20000 0x20000

Pete

Options: ReplyQuote
Re: Access to U-Boot environment vars from Linux
Posted by: andre ()
Date: September 03, 2009 04:42PM

We don't use the U-Boot -> Linux environment tools, but we do have an alternative utility which performs similar functions:
[www.bluewatersys.com]
This will parse the same kinds of scripts as samba-script, and write them into your environment. It also supports setting variables on the command line.

Hopefully this is able to help you out.

Regards,
Andre

Options: ReplyQuote
Re: Access to U-Boot environment vars from Linux
Posted by: pas ()
Date: September 08, 2009 01:25PM

I tried the environment tool you referenced and it gives results similar to the U-Boot tools,
i.e. they display the environment but updating a variable results in a CRC error on reboot:

root@snapper:~$ ./uboot_script -m Environment -v serial=105
U-Boot Environment Generator
Partition 'Environment' size: 131072
Adding variables 'serial
root@snapper:~$ ./uboot_script -m Environment -t
U-Boot Environment Generator
Partition 'Environment' size: 131072

[snip (removed to save space)]

serial=105
root@snapper:~$ reboot

>Start Snapper 9260 Bootstrap...


U-Boot 1.1.6 (Sep 2 2009 - 11:59:41)

Processor: AT91SAM9xx Series
Processor Speed: 180.07 MHz
Peripheral Speed: 090.03 MHz
External Crystal: 18.432 MHz
USB Speed: 48.08 MHz
Core: ARM926EJS, version: 2
Internal SRAM: 8KB
RAM Configuration:
Bank #0: 20000000 64 MB
NAND: 256 MiB
*** Warning - bad CRC or NAND, using default environment

Pete

Options: ReplyQuote
Re: Access to U-Boot environment vars from Linux
Posted by: pas ()
Date: September 09, 2009 12:36PM

After looking at the U-Boot code it looks like the "*** Warning - bad CRC or NAND, using default environment" message is as a result of an ECC error. I notice that the uboot_script code does not appear to explicitly use any ECC specific writes etc. If this is the problem any clues on how I should modify uboot_script to set the ECC correctly would be appreciated.

Regards,

Pete

Options: ReplyQuote
Re: Access to U-Boot environment vars from Linux
Posted by: Ryan ()
Date: September 09, 2009 03:22PM

Can you stop the unit in U-Boot, and then post the results of the following command:
nand bad

Options: ReplyQuote
Re: Access to U-Boot environment vars from Linux
Posted by: pas ()
Date: September 10, 2009 06:17AM

Snapper> nand bad

Device 0 bad blocks:
09f60000
0dca0000

Options: ReplyQuote
Re: Access to U-Boot environment vars from Linux
Posted by: Ryan ()
Date: September 10, 2009 02:26PM

Ok that looks fine. Can I just get you to run a few tests to get a better idea of where the problem is.

Are you able to write the U-Boot environment from U-Boot correctly, try:
setenv serial 105
saveenv
then power cycle the unit and see if the serial variable is still set. If so, then the NAND should be working correctly, and potentially the problem is just with Linux.

After doing that, boot into Linux. Could you please post the output of the following:
uname -a
cat /proc/mtd
./uboot_script -m Environment -v serial=105 
nand --dump Environment 0x0 1

Then reboot into U-Boot and post the result of the following:
nand dump 0x60000

Thanks,
~Ryan

Options: ReplyQuote
Re: Access to U-Boot environment vars from Linux
Posted by: pas ()
Date: September 11, 2009 06:46AM

root@snapper:~$ uname -a
Linux snapper 2.6.29 #8 Wed Sep 2 10:05:01 EDT 2009 armv5tejl unknown
root@snapper:~$ cat /proc/mtd
dev: size erasesize name
mtd0: 00020000 00020000 "Preboot"
mtd1: 00040000 00020000 "Bootloader"
mtd2: 00020000 00020000 "Environment"
mtd3: 00400000 00020000 "Kernel"
mtd4: 08000000 00020000 "Filesystem1"
mtd5: 07b80000 00020000 "Filesystem2"
root@snapper:~$
root@snapper:~$ ./uboot_script -m Environment -v serial=105
U-Boot Environment Generator
Partition 'Environment' size: 131072
Partition:Environment CRC:0x953b30f9
Adding variables 'serial
root@snapper:~$ nand --dump Environment 0x0 1
-sh: nand: not found

--- reboot ---

>Start Snapper 9260 Bootstrap...


U-Boot 1.1.6 (Sep 2 2009 - 11:59:41)

Processor: AT91SAM9xx Series
Processor Speed: 180.07 MHz
Peripheral Speed: 090.03 MHz
External Crystal: 18.432 MHz
USB Speed: 48.08 MHz
Core: ARM926EJS, version: 2
Internal SRAM: 8KB
RAM Configuration:
Bank #0: 20000000 64 MB
NAND: 256 MiB
*** Warning - bad CRC or NAND, using default environment

In: serial
Out: serial
Err: serial
Snapper> nand dump 0x60000
Page 00060000 dump:
95 71 08 b6 65 74 68 61 64 64 72 3d 30 30 3a 35
30 3a 43 32 3a 34 31 3a 41 43 3a 42 45 00 6d 6f
64 65 6c 3d 39 32 36 30 00 62 6f 6f 74 61 64 64
72 3d 30 78 32 33 30 30 30 30 30 30 00 63 6f 6e
73 6f 6c 65 3d 74 74 79 53 30 00 79 61 66 66 73
72 6f 6f 74 3d 2f 64 65 76 2f 6d 74 64 62 6c 6f
63 6b 34 00 62 61 75 64 72 61 74 65 3d 31 31 35
32 30 30 00 69 70 61 64 64 72 3d 31 39 32 2e 31
36 38 2e 32 2e 32 30 30 00 73 65 72 76 65 72 69
70 3d 31 39 32 2e 31 36 38 2e 32 2e 32 35 00 67
61 74 65 77 61 79 3d 31 39 32 2e 31 36 38 2e 32
2e 32 35 34 00 6e 65 74 6d 61 73 6b 3d 32 35 35
2e 32 35 35 2e 32 35 35 2e 30 00 72 6f 6f 74 70
61 74 68 3d 2f 65 78 70 6f 72 74 2f 72 6f 6f 74
00 74 66 74 70 70 61 74 68 3d 2f 74 66 74 70 62
6f 6f 74 2f 73 6e 61 70 70 65 72 00 6b 65 72 6e
65 6c 3d 75 49 6d 61 67 65 2d 39 32 36 30 2d 31
30 34 00 66 70 67 61 3d 66 70 67 61 2e 72 62 66
2d 31 30 34 00 72 65 67 65 6e 5f 73 63 72 69 70
74 73 3d 0a 20 20 73 65 74 65 6e 76 20 63 6f 6d
6d 6f 6e 5f 62 6f 6f 74 61 72 67 73 20 63 6f 6e
73 6f 6c 65 3d 24 63 6f 6e 73 6f 6c 65 2c 24 62
61 75 64 72 61 74 65 20 6c 63 64 3d 24 6c 63 64
20 62 61 73 65 62 6f 61 72 64 3d 24 62 61 73 65
62 6f 61 72 64 20 62 61 73 65 62 6f 61 72 64 5f
72 65 76 3d 24 62 61 73 65 62 6f 61 72 64 5f 72
65 76 20 65 74 68 61 64 64 72 3d 24 65 74 68 61
64 64 72 20 24 65 78 74 72 61 5f 62 6f 6f 74 61
72 67 73 20 3b 0a 20 20 73 65 74 65 6e 76 20 6e
65 74 5f 62 6f 6f 74 61 72 67 73 20 69 70 3d 24
69 70 61 64 64 72 3a 24 73 65 72 76 65 72 69 70
3a 24 67 61 74 65 77 61 79 3a 24 6e 65 74 6d 61
73 6b 3a 73 6e 61 70 70 65 72 3a 65 74 68 30 3a
6f 66 66 20 6e 66 73 72 6f 6f 74 3d 24 72 6f 6f
74 70 61 74 68 2c 76 33 2c 72 73 69 7a 65 3d 31
30 32 34 2c 77 73 69 7a 65 3d 31 30 32 34 20 3b
0a 20 20 73 65 74 65 6e 76 20 64 68 63 70 5f 62
6f 6f 74 61 72 67 73 20 69 70 3d 61 6e 79 20 6e
66 73 72 6f 6f 74 3d 24 72 6f 6f 74 70 61 74 68
2c 76 33 2c 72 73 69 7a 65 3d 31 30 32 34 2c 77
73 69 7a 65 3d 31 30 32 34 20 3b 0a 20 20 73 65
74 65 6e 76 20 79 61 66 66 73 5f 62 6f 6f 74 61
72 67 73 20 72 6f 6f 74 3d 24 79 61 66 66 73 72
6f 6f 74 20 72 6f 6f 74 66 73 74 79 70 65 3d 79
61 66 66 73 20 69 70 3d 24 69 70 61 64 64 72 3a
24 73 65 72 76 65 72 69 70 3a 24 67 61 74 65 77
61 79 3a 24 6e 65 74 6d 61 73 6b 3a 73 6e 61 70
70 65 72 3a 65 74 68 30 3a 6f 66 66 20 3b 0a 20
20 73 65 74 65 6e 76 20 63 72 61 6d 66 73 5f 62
6f 6f 74 61 72 67 73 20 72 6f 6f 74 3d 24 63 72
61 6d 66 73 72 6f 6f 74 20 72 6f 6f 74 66 73 74
79 70 65 3d 63 72 61 6d 66 73 20 00 66 70 67 61
69 6e 69 74 3d 65 63 68 6f 20 4e 6f 20 46 50 47
41 20 6f 6e 20 74 68 69 73 20 6d 6f 64 75 6c 65
2c 20 6f 72 20 6e 6f 20 46 50 47 41 20 69 6e 69
74 20 72 65 71 75 69 72 65 64 00 73 65 72 69 61
6c 5f 62 6f 6f 74 3d 0a 20 20 20 20 20 20 20 72
75 6e 20 72 65 67 65 6e 5f 73 63 72 69 70 74 73
3b 0a 20 20 20 20 20 20 20 73 65 74 65 6e 76 20
62 6f 6f 74 61 72 67 73 20 24 63 6f 6d 6d 6f 6e
5f 62 6f 6f 74 61 72 67 73 20 24 64 68 63 70 5f
62 6f 6f 74 61 72 67 73 3b 0a 20 20 20 20 20 20
20 6c 6f 61 64 79 20 26 26 0a 20 20 20 20 20 20
20 62 6f 6f 74 6d 00 79 61 66 66 73 5f 62 6f 6f
74 3d 0a 20 20 72 75 6e 20 72 65 67 65 6e 5f 73
63 72 69 70 74 73 3b 20 0a 20 20 73 65 74 65 6e
76 20 62 6f 6f 74 61 72 67 73 20 24 63 6f 6d 6d
6f 6e 5f 62 6f 6f 74 61 72 67 73 20 24 79 61 66
66 73 5f 62 6f 6f 74 61 72 67 73 20 26 26 0a 20
20 6e 62 6f 6f 74 20 24 62 6f 6f 74 61 64 64 72
20 30 20 24 6b 65 72 6e 65 6c 5f 6f 66 66 73 65
74 20 26 26 0a 20 20 62 6f 6f 74 6d 00 6b 65 72
6e 65 6c 5f 6f 66 66 73 65 74 3d 30 78 38 30 30
30 30 00 6e 66 73 5f 62 6f 6f 74 3d 0a 20 20 72
75 6e 20 72 65 67 65 6e 5f 73 63 72 69 70 74 73
3b 0a 20 20 72 75 6e 20 66 70 67 61 69 6e 69 74
3b 20 0a 20 20 73 65 74 65 6e 76 20 62 6f 6f 74
61 72 67 73 20 24 63 6f 6d 6d 6f 6e 5f 62 6f 6f
74 61 72 67 73 20 24 6e 65 74 5f 62 6f 6f 74 61
72 67 73 3b 20 0a 20 20 6e 66 73 20 24 62 6f 6f
74 61 64 64 72 20 24 73 65 72 76 65 72 69 70 3a
24 72 6f 6f 74 70 61 74 68 2f 24 6b 65 72 6e 65
6c 20 26 26 0a 20 20 62 6f 6f 74 6d 00 64 68 63
70 5f 62 6f 6f 74 3d 0a 20 20 73 65 74 65 6e 76
20 62 6f 6f 74 66 69 6c 65 20 24 74 66 74 70 70
61 74 68 2f 24 6b 65 72 6e 65 6c 3b 0a 20 20 62
6f 6f 74 70 20 26 26 0a 20 20 72 75 6e 20 72 65
67 65 6e 5f 73 63 72 69 70 74 73 3b 20 0a 20 20
72 75 6e 20 66 70 67 61 69 6e 69 74 3b 20 0a 20
20 73 65 74 65 6e 76 20 62 6f 6f 74 61 72 67 73
20 24 63 6f 6d 6d 6f 6e 5f 62 6f 6f 74 61 72 67
73 20 24 64 68 63 70 5f 62 6f 6f 74 61 72 67 73
20 26 26 0a 20 20 62 6f 6f 74 6d 00 66 70 67 61
5f 62 6f 6f 74 3d 0a 20 20 72 75 6e 20 72 65 67
65 6e 5f 73 63 72 69 70 74 73 20 3b 0a 20 20 73
65 74 65 6e 76 20 62 6f 6f 74 61 72 67 73 20 24
63 6f 6d 6d 6f 6e 5f 62 6f 6f 74 61 72 67 73 20
24 64 68 63 70 5f 62 6f 6f 74 61 72 67 73 3b 0a
20 20 73 65 74 65 6e 76 20 61 75 74 6f 6c 6f 61
64 20 6e 3b 0a 20 20 62 6f 6f 74 70 20 26 26 0a
20 20 74 66 74 70 20 24 62 6f 6f 74 61 64 64 72
20 24 74 66 74 70 70 61 74 68 2f 24 66 70 67 61
20 26 26 0a 20 20 73 6e 61 70 20 66 70 67 61 20
24 62 6f 6f 74 61 64 64 72 20 26 26 0a 20 20 73
65 74 65 6e 76 20 62 6f 6f 74 66 69 6c 65 20 24
74 66 74 70 70 61 74 68 2f 24 6b 65 72 6e 65 6c
20 26 26 20 0a 20 20 73 65 74 65 6e 76 20 61 75
74 6f 6c 6f 61 64 20 79 20 26 26 0a 20 20 62 6f
6f 74 70 20 26 26 0a 20 20 62 6f 6f 74 6d 00 62
6f 6f 74 63 6d 64 3d 72 75 6e 20 70 6f 77 65 72
5f 64 6f 6d 61 69 6e 73 5f 69 6e 69 74 20 3b 20
72 75 6e 20 79 61 66 66 73 5f 62 6f 6f 74 20 3b
20 72 75 6e 20 64 68 63 70 5f 62 6f 6f 74 20 3b
20 72 75 6e 20 6e 66 73 5f 62 6f 6f 74 00 73 6e
39 32 36 30 5f 70 6f 77 65 72 3d 0a 20 20 20 20
20 20 20 6d 61 78 37 33 31 31 20 30 20 33 20 63
6f 6e 66 69 67 20 30 20 26 26 0a 20 20 20 20 20
20 20 6d 61 78 37 33 31 31 20 30 20 33 20 6f 75
74 70 75 74 20 30 20 26 26 0a 20 20 20 20 20 20
20 6d 61 78 37 33 31 31 20 30 20 32 20 63 6f 6e
66 69 67 20 30 20 26 26 0a 20 20 20 20 20 20 20
6d 61 78 37 33 31 31 20 30 20 32 20 6f 75 74 70
75 74 20 30 00 70 6f 77 65 72 5f 64 6f 6d 61 69
6e 73 5f 69 6e 69 74 3d 65 63 68 6f 20 49 6e 69
74 69 6e 67 20 70 6f 77 65 72 20 64 6f 6d 61 69
6e 73 2e 2e 2e 3b 20 72 75 6e 20 73 6e 39 32 36
30 5f 70 6f 77 65 72 00 73 74 64 69 6e 3d 73 65
72 69 61 6c 00 73 74 64 6f 75 74 3d 73 65 72 69
OOB:
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff ff ff ff 62 0f 62 0f
Snapper>

I assume the first four bytes of the Environment block are the CRC, if so then the CRC
in the dump is different from the CRC shown during the uboot_script write (I turned on some
debug).

Pete

Options: ReplyQuote
Re: Access to U-Boot environment vars from Linux
Posted by: pas ()
Date: September 11, 2009 08:51AM

Ryan,

I switched back to the 2.6.20 kernel an it works.....

Pete

Options: ReplyQuote
Re: Access to U-Boot environment vars from Linux
Posted by: pas ()
Date: September 14, 2009 02:25PM

Ryan,

Can I assist in tracking this issue down? I'd really like to use the 2.6.29 kernel
since it has user space SPI access.

Regards

Pete

Options: ReplyQuote
Re: Access to U-Boot environment vars from Linux
Posted by: Ryan ()
Date: September 14, 2009 04:49PM

There appears that our uboot-script mtd interface is not compatible with the 2.6.29 kernel (it was originally written for the 2.6.20 kernel and the mtd interfaces have changed). We will try and release a new version with 2.6.29 support soon. In the meantime, are you able to continue with setting variables directly from U-Boot?

Options: ReplyQuote
Re: Access to U-Boot environment vars from Linux
Posted by: pas ()
Date: September 15, 2009 06:44AM

Ryan,

For the time being yes. Please let me know if there's anything I can do to assist.

Regards,

Pete

Options: ReplyQuote
Re: Access to U-Boot environment vars from Linux 2.6.29 - SOLVED
Posted by: pas ()
Date: October 01, 2009 01:26PM

Seems that the 2.6.29 kernel has hardware ECC turned on by default, changing this to software ECC seems to fix the issue. Look under Device Drivers->MTD->NAND device support->ECC management for NAND flash for AT91 etc->Software ECC in your kernel config menu.

Regards,

Pete

Options: ReplyQuote


Your Name: 
Your Email: 
Subject: 
Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
This is a moderated forum. Your message will remain hidden until it has been approved by a moderator or administrator
This forum powered by Phorum.

Applications

rs1

rs_2

rs_3

rs_4