2009-10-03 21:07:49     u-boot-tools: fw_env/fw_printenv/fw_setenv config value problem

Document created by Aaronwu Employee on Sep 24, 2013Last modified by Aaronwu Employee on Sep 24, 2013
Version 2Show Document
  • View in full screen mode

2009-10-03 21:07:49     u-boot-tools: fw_env/fw_printenv/fw_setenv config value problem

Dave Barndt (UNITED STATES)

Message: 80822   

 

Hi,

 

I'm trying to get the U-Boot fw_printenv/fw_setenv tool working and I'm almost there; I'm hoping someone can help me get the last piece of the puzzle.

 

fw_printenv seems to work perfectly; fw_setenv is giving me an error:

 

root:~> fw_printenv                                                          

bootargs=root=/dev/mtdblock2 rw rootfstype=jffs2                             

bootcmd=run eepromboot                                                       

bootdelay=3                                                                  

baudrate=57600                                                               

loads_echo=1                                                                 

autoload=no                                                                  

rootpath=/romfs                                                              

netmask=255.255.255.0                                                        

hostname=BFIN                                                                

loadaddr=0x1000000                                                           

ubootfile=u-boot.ldr                                                         

update=tftp $(loadaddr) $(ubootfile);eeprom write $(loadaddr) 0x0 $(filesize)

addip=set bootargs $(bootargs) ip=$(ipaddr):$(serverip):$(gatewayip):$(netmask)f

ramargs=set bootargs root=/dev/mtdblock2 rw rootfstype=jffs2                 

ramboot=tftp $(loadaddr) uImage;run ramargs;run addip;bootm                  

nfsargs=set bootargs root=/dev/nfs rw nfsroot=$(serverip):$(rootpath),tcp,nfsve3

nfsboot=tftp $(loadaddr) vmImage;run nfsargs;run addip;bootm                 

flashboot=bootm 0x20100000                                                   

eepromboot=eeprom read 0x2000000 0x40000 0xFC0000;bootm 0x2000000            

ethact=Blackfin EMAC                                                         

ethaddr=00:25:44:00:00:02                                                    

stdin=serial                                                                 

stdout=serial                                                                

stderr=serial                                                                

ipaddr=10.12.5.100                                                           

serverip=10.12.4.75                                                          

gatewayip=10.12.5.1                                                          

root:/bin> fw_printenv bootdelay                                             

bootdelay=3                                                                  

root:/bin> fw_setenv bootdelay 5                                             

Unlocking flash...                                                           

Done                                                                         

Erasing old environment...                                                   

MTD erase error on /dev/mtd0: Invalid argument                               

Error: can't write fw_env to flash                                           

 

I'm running U-Boot 1.1.6, and the fw_env sources are identical to the one in the 2008R1 SVN branch on this site.  I tried grabbing the 2009R1 SVN branch fw_env sources and building them, and got the same error (with a couple fewer messages):

 

root:~> fw_setenv bootdelay 5                                                 

MTD erase error on /dev/mtd0: Invalid argument                                

Error: can't write fw_env to flash                                            

 

I'm using an fw_env.config file, and its contents are as follows:

 

root:~> 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               0x4000          0x2000          0x2000               

 

I believe the device offset is correct, because I get no checksum error running fw_printenv, and the env. size is also correct I believe, based on the relevant board stamp file values in u-boot-1.1.6/include/configs/bf537-stamp.h:

 

#define BFIN_BOOT_MODE         BFIN_BOOT_SPI_MASTER

 

#define CONFIG_MEM_SIZE                 64      /* 128, 64, 32, 16 */

#define CONFIG_MEM_ADD_WDTH             10      /* 8, 9, 10, 11 */

 

#define CONFIG_MEM_MT48LC32M16A2P_75    1       /* GC 0700208 16 bit wide SDRAM*/

 

#define CFG_FLASH_BASE          0x20000000

 

#define CFG_FLASH_CFI           /* The flash is CFI compatible */

 

#define CFG_NO_FLASH            /* remove parallel flash to use SPI only, undefine for uart */

/*#define CFG_FLASH_CFI_DRIVER  /* Use common CFI driver, define for uart */

 

#if (BFIN_BOOT_MODE == BFIN_BOOT_SPI_MASTER)

#define CFG_ENV_IS_IN_EEPROM    1

#define CFG_ENV_OFFSET          0x4000

#define CFG_ENV_HEADER          (CFG_ENV_OFFSET + 0x16e) /* 0x12A is the length of LDR file header */

#else

.

.

.

#endif

 

#define CFG_ENV_SIZE            0x2000

#define CFG_ENV_SECT_SIZE       0x2000  /* Total Size of Environment Sector */

 

(I've attached the entire bf537-stamp.h file for reference if it would help.)

 

The device offset in the config file matches CFG_ENV_OFFSET above, and the env. size in the config file matches CFG_ENV_SIZE above.  But the flash sector size seems to be the thorn.  I've tried 0x2000 (CFG_ENV_SECT_SIZE), 64K = 0x10000 and 256K = 0x40000 (number referring to sector sizes in the memory chip specs), and every power of 2 in between, with no luck (256K gives me a different error, a read error).

 

I'm so close I can taste it.  Is it apparent to anyone what the problem is?  Am I missing something obvious?

 

Thanks for any help!

 

bf537-stamp.h

QuoteReplyEditDelete

 

 

2009-10-03 23:34:04     Re: u-boot-tools: fw_env/fw_printenv/fw_setenv config value problem

Mike Frysinger (UNITED STATES)

Message: 80823   

 

look at your /proc/mtd to make sure the sector size is correct, and look at your board settings to make sure the partition isnt marked read only.  and try running flash_unlock on /dev/mtd0 first.

QuoteReplyEditDelete

 

 

2009-10-04 13:40:02     Re: u-boot-tools: fw_env/fw_printenv/fw_setenv config value problem

Dave Barndt (UNITED STATES)

Message: 80825   

 

Hi Mike,

 

Thanks very much for the off-hours (if there is such a thing) reply.  Sorry I didn't include the /proc/mtd output in my original note, it's:

 

root:~> cat /proc/mtd                                                         

dev:    size   erasesize  name                                                

mtd0: 00040000 00040000 "bootloader"                                          

mtd1: 001c0000 00040000 "kernel"                                              

mtd2: 00e00000 00040000 "file system"                                         

 

Anyway, I took the value 0x40000 and used that as the flash sector size.  When I used that with the newer version of the fw_env tool (2009R1) from SVN... it worked!!!  THANK YOU!!!

 

To sum up, in case it might help someone else know where to look, here's how I determined (with Mike's help) the settings in fw_env.config (or built into the fw_env tool directly):

 

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               0x4000          0x2000          0x40000               

 

Device offset => value of CFG_ENV_OFFSET in board stamp file (in my case, bf537-stamp.h, 0x4000)

 

Env. size => value of CFG_ENV_SIZE in board stamp file (in my case, bf537-stamp.h, 0x2000)

 

Flash sector size => "erasesize" value of U-Boot area in output of "cat /proc/mtd" (in my case, /dev/mtd0, 0x40000)

 

If you do not want to use the config file and build the values into the tool directly, you need to modify uClinux-dist/user/blkfin-apps/u-boot-tools/env/fw_env.h.  This is what I did (again, my MTD area is /dev/mtd0 and I do not use a redundant environment sector):

 

/*

* To build the utility with the run-time configuration

* uncomment the next line.

* See included "fw_env.config" sample file (TRAB board)

* for notes on configuration.

*/

/*#define CONFIG_FILE     "/etc/fw_env.config"*/

 

/*#define HAVE_REDUND /* For systems with 2 env sectors */

#define DEVICE1_NAME      "/dev/mtd0"

/*#define DEVICE2_NAME      "/dev/mtd2"*/

#define DEVICE1_OFFSET    0x4000

#define ENV1_SIZE         0x2000

#define DEVICE1_ESIZE     0x40000

#define DEVICE1_ENVSECTORS     1

/*#define DEVICE2_OFFSET    0x0000*/

/*#define ENV2_SIZE         0x4000*/

/*#define DEVICE2_ESIZE     0x4000*/

/*#define DEVICE2_ENVSECTORS     1*/

 

(Note: I did have to add DEVICE*_ENVSECTORS to get fw_env.c to compile.  You don't have to do this if you use the config file with 2009R1 as the ENVSECTORS value is not in the config file and thus defaults to 1.)

 

Anyway, hope this helps someone.  And once again, THANK YOU Mike for getting me over the hump!!!

QuoteReplyEditDelete

Attachments

Outcomes