UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Adventurer
Adventurer
24,143 Views
Registered: ‎09-19-2014

Where does U-Boot saveenv to?

Jump to solution

I'll start by saying I've solved this issue for myself. But surely there has to be an easier and better-documented way?!

 

I have a Zynq Mini-ITX board. I built my own U-Boot from OpenEmbedded recipes: https://github.com/Xilinx/meta-xilinx/tree/master/recipes-bsp/u-boot

U-Boot 2014.01 (Oct 13 2014 - 16:53:16)

 

I'm booting from QSPI, and have a PL bitstream and Linux kernel/image as part of that.

So I had some U-Boot environment variables that I needed to save (specifically, the memory offsets to different partitions of the QSPI memory block).

 

Nowhere could I see it documented where U-Boot's saveenv command was saving to!

 

I ran it:

zynq-uboot> saveenv
Saving Environment to SPI Flash...
SF: Detected S25FL128S_64K with page size 512 Bytes, erase size 128 KiB, total 32 MiB
Erasing SPI flash...Writing to SPI flash...done

 

Okay, so it's saving to QSPI flash... which is where I boot from. What offset is it saving to??

I then restart, and it fails to boot, because saveenv obviously just overwritten and corrupted my boot partitions in QSPI.

 

I eventually found the README for this U-Boot repository:

https://github.com/Xilinx/u-boot-xlnx

Do a search for CONFIG_ENV_IS_IN_FLASH. Then it mentions these, which are exactly what I'm after:

CONFIG_ENV_OFFSET
CONFIG_ENV_SIZE

 

Then I found these are defined in: https://github.com/Xilinx/u-boot-xlnx/blob/master/include/configs/zynq-common.h

Which gave me the answer of 0xE0000 and 131,072, respectively.

I avoided that memory region of the QSPI, and now it boots and saves successfully.

 

Why is it such a secret where saveenv saves to? Is this better documented somewhere else that I missed? How is booting from QSPI meant to be done to avoid this pain?

Hopefully it helps someone else out. :)

0 Kudos
1 Solution

Accepted Solutions
Adventurer
Adventurer
38,930 Views
Registered: ‎09-19-2014

Re: Where does U-Boot saveenv to?

Jump to solution

It seems to me that the options are:

1. Boot from something other than QSPI and you can use saveenv (32MB QSPI just to store 128KB of settings).

2. Boot from QSPI, but you can't use saveenv.

3. Read the source, Luke.

 

If the only place you can find out an essential piece of (non-internal) information is to read the source, then I would definitely class that as information underload!

So developers are people too - if they want to use saveenv during a project, then why not let them?

I remember being puzzled by the "bad CRC" message, but that's easy enough to google. It was much harder to google for this missing offset info.

 

I may look into contributing (time permitting)...

0 Kudos
8 Replies
Scholar rfs613
Scholar
24,123 Views
Registered: ‎05-28-2013

Re: Where does U-Boot saveenv to?

Jump to solution

There are actually several options in u-boot for saving the environment. Putting it at a fixed spot in the flash memory is just one option (that's CONFIG_ENV_IS_IN_FLASH). It can also go in NVRAM, in EEPROM, in FAT filesystem, etc.

 

Those options are documeted in the u-boot README file, starting around line 4051 until 4455. (http://git.denx.de/?p=u-boot.git;a=blob;f=README;h=46def0086b8f3d95c77a78bda532eacdbab91c6e;hb=HEAD#l4050)

 

The specific addresses, as you have found, are defined in board-specifc configuration files.

 

Most users do not make use of the ability to customize and save the environment in u-boot. They just use the default environment, which also happens to be defined in include/configs/zynq-common.h (for Zynq anyways).

 

HTH...

0 Kudos
Adventurer
Adventurer
24,111 Views
Registered: ‎09-19-2014

Re: Where does U-Boot saveenv to?

Jump to solution

Yes, I did notice it was possible to put the environment settings in different locations and devices, and noted that different boards could define different things. That's the same README I was referring to.

That's a bit surprising that most people don't use saveenv (or rather, it's unusual to do so). So I guess it's not documented more completely somewhere that I missed then?

It seems like something simple like when doing saveenv and it probes and writes to QSPI, it could at least output the memory offset it's using! In the board-specific documentation and QSPI boot examples, it could also mention that the block of memory should be avoided because U-Boot environment is written there... There's a few ways the documentation could be improved so it's not so obscured and hidden!

0 Kudos
Scholar rfs613
Scholar
24,093 Views
Registered: ‎05-28-2013

Re: Where does U-Boot saveenv to?

Jump to solution
I should perhaps clarify: I meant that *end-users* typically do not make use of 'saveenv'. For that matter, end-users generally do not really know about u-boot, or even the O/S on their device. They just want it to play music, or send tweets, or whatever ;-)

Developers on the other hand might make use of 'saveenv' while they are working on a new product/project. But typically once they figure out what settings they want, that just gets put into the default environment (at compile time). There is little point to wasting a whole flash page for settings that won't be changed by end-users.

Of course each situation is different, there sure surely some devices that actually change u-boot settings on-the-fly. But I suspect they are a minority.

As for documentation, and printing out the memory addresses: it could be done, but like most things, it just contributes to "information overload". Consider how often people ask about the "bad CRC - using default environment" message -- even though it is #4 on the u-boot FAQ.

Still you should feel free to contribute code or documentation patches to the u-boot project to improve the situation. Don't let me talk you out of trying ;-)
0 Kudos
Adventurer
Adventurer
38,931 Views
Registered: ‎09-19-2014

Re: Where does U-Boot saveenv to?

Jump to solution

It seems to me that the options are:

1. Boot from something other than QSPI and you can use saveenv (32MB QSPI just to store 128KB of settings).

2. Boot from QSPI, but you can't use saveenv.

3. Read the source, Luke.

 

If the only place you can find out an essential piece of (non-internal) information is to read the source, then I would definitely class that as information underload!

So developers are people too - if they want to use saveenv during a project, then why not let them?

I remember being puzzled by the "bad CRC" message, but that's easy enough to google. It was much harder to google for this missing offset info.

 

I may look into contributing (time permitting)...

0 Kudos
23,495 Views
Registered: ‎12-28-2014

Re: Where does U-Boot saveenv to?

Jump to solution

I was also having this issue. Thanks to this thread I know what the cause was.

 

I agree the lack of documentation / log info as to where env vars are saved is quite annoying. Perhaps Xilinx should consider storing them higher up so a bitstream will fit without having to specify new offsets (or at least warn that bitstreams and saved env vars will clash).

 

After doing some experimenting, it seems you can specify an offset for the bitstream beyond the env pages (0x100000+). It doesn't look like the FSBL does anything with saved environment variables, and my bitstream programmed correctly. I've had to squeeze the other files beyond the bitstream (u-boot, kernel image, etc) so FSBL finds u-boot before anything else higher up. On my zc702 board, it's tricky to get the bin file under 16MB to fit on the flash, having to squash out a bit of empty page space.

0 Kudos
Adventurer
Adventurer
23,484 Views
Registered: ‎09-19-2014

Re: Where does U-Boot saveenv to?

Jump to solution

Hi John, glad to hear I'm not alone on this. Let us stand together in our frustration!

Having a warning that the bitstream and U-Boot saved env will clash is a bit tricky, because it would need to know the u-boot sources. I have built mine separately from the SDK, so it just sees a binary that it tries to program the flash with, and it wouldn't even realise it is a u-boot binary. So to implement that would be hacky and tricky for the general case. Just easier for U-Boot to document it IMO.

And the default is definitely awkward for having the bitstream too. I do put my bitstream at 0x100000 after the saved env too, which amounts to 504KB of wasted space before the saved env. I've given up attempting to squeeze it in under 16MB.

0 Kudos
Scholar rfs613
Scholar
23,477 Views
Registered: ‎05-28-2013

Re: Where does U-Boot saveenv to?

Jump to solution

Keep in mind that the u-boot environment can be stored in places other than the QSPI flash.  For example, a serial EEPROM can be used. The zc702 board has one (component U7, an M24C08 device) connected via a port expander to the processor I2C interface. It is not used (as far as I can tell), but the zynq-zc702.dts devicetree does include it, so you can quite easly read/write it from Linux.

 

To get u-boot to read/write from this eeprom, instead of using CONFIG_ENV_IS_IN_FLASH, you would make use of CONFIG_ENV_IS_IN_EEPROM instead. There are other I2C related settings you must also supply. In particular you would need to set CONFIG_I2C_ENV_EEPROM_BUS due to the port expander.

0 Kudos
Adventurer
Adventurer
23,469 Views
Registered: ‎09-19-2014

Re: Where does U-Boot saveenv to?

Jump to solution

Yes @rfs613, that is true, and those macro defines are mentioned in the U-Boot README.

0 Kudos