topic Re: Where does U-Boot saveenv to? in Embedded Linuxhttps://forums.xilinx.com/t5/Embedded-Linux/Where-does-U-Boot-saveenv-to/m-p/533515#M10975
<P>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.</P>
<P>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?</P>
<P>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!</P>Fri, 17 Oct 2014 00:19:36 GMTsam_jaeschke2014-10-17T00:19:36ZWhere does U-Boot saveenv to?https://forums.xilinx.com/t5/Embedded-Linux/Where-does-U-Boot-saveenv-to/m-p/532915#M10959
<P>I'll start by saying I've solved this issue for myself. But surely there has to be an easier and better-documented way?!</P>
<P>&nbsp;</P>
<P>I have a Zynq Mini-ITX board. I built my own U-Boot from OpenEmbedded recipes:&nbsp;<A href="https://github.com/Xilinx/meta-xilinx/tree/master/recipes-bsp/u-boot" target="_blank">https://github.com/Xilinx/meta-xilinx/tree/master/recipes-bsp/u-boot</A></P>
<P>U-Boot 2014.01 (Oct 13 2014 - 16:53:16)</P>
<P>&nbsp;</P>
<P>I'm booting from QSPI, and have a PL bitstream and Linux kernel/image as part of that.</P>
<P>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).</P>
<P>&nbsp;</P>
<P><STRONG>Nowhere could I see it documented where U-Boot's saveenv command was saving to!</STRONG></P>
<P>&nbsp;</P>
<P>I ran it:</P>
<P>zynq-uboot&gt; saveenv<BR />Saving Environment to SPI Flash...<BR />SF: Detected S25FL128S_64K with page size 512 Bytes, erase size 128 KiB, total 32 MiB<BR />Erasing SPI flash...Writing to SPI flash...done</P>
<P>&nbsp;</P>
<P>Okay, so it's saving to QSPI flash... which is where I boot from. What offset is it saving to??</P>
<P>I then restart, and it fails to boot, because saveenv obviously just overwritten and corrupted my boot partitions in QSPI.</P>
<P>&nbsp;</P>
<P>I eventually found the README for this U-Boot repository:</P>
<P><A href="https://github.com/Xilinx/u-boot-xlnx" target="_blank">https://github.com/Xilinx/u-boot-xlnx</A></P>
<P>Do a search for CONFIG_ENV_IS_IN_FLASH. Then it mentions these, which are exactly what I'm after:</P>
<P>CONFIG_ENV_OFFSET<BR />CONFIG_ENV_SIZE</P>
<P>&nbsp;</P>
<P>Then I found these are defined in:&nbsp;<A href="https://github.com/Xilinx/u-boot-xlnx/blob/master/include/configs/zynq-common.h" target="_blank">https://github.com/Xilinx/u-boot-xlnx/blob/master/include/configs/zynq-common.h</A></P>
<P>Which gave me the answer of 0xE0000 and 131,072, respectively.</P>
<P>I avoided that memory region of the QSPI, and now it boots and saves successfully.</P>
<P>&nbsp;</P>
<P><STRONG>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?</STRONG></P>
<P>Hopefully it helps someone else out. :)</P>Thu, 16 Oct 2014 04:08:38 GMThttps://forums.xilinx.com/t5/Embedded-Linux/Where-does-U-Boot-saveenv-to/m-p/532915#M10959sam_jaeschke2014-10-16T04:08:38ZRe: Where does U-Boot saveenv to?https://forums.xilinx.com/t5/Embedded-Linux/Where-does-U-Boot-saveenv-to/m-p/533255#M10963
<P>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.</P>
<P>&nbsp;</P>
<P>Those options are documeted in the u-boot README file, starting around line 4051 until 4455. (<A href="http://git.denx.de/?p=u-boot.git;a=blob;f=README;h=46def0086b8f3d95c77a78bda532eacdbab91c6e;hb=HEAD#l4050)" target="_blank">http://git.denx.de/?p=u-boot.git;a=blob;f=README;h=46def0086b8f3d95c77a78bda532eacdbab91c6e;hb=HEAD#l4050)</A></P>
<P>&nbsp;</P>
<P>The specific addresses, as you have found, are defined in board-specifc configuration files.</P>
<P>&nbsp;</P>
<P>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).</P>
<P>&nbsp;</P>
<P>HTH...</P>Thu, 16 Oct 2014 12:49:23 GMThttps://forums.xilinx.com/t5/Embedded-Linux/Where-does-U-Boot-saveenv-to/m-p/533255#M10963rfs6132014-10-16T12:49:23ZRe: Where does U-Boot saveenv to?https://forums.xilinx.com/t5/Embedded-Linux/Where-does-U-Boot-saveenv-to/m-p/533515#M10975
<P>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.</P>
<P>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?</P>
<P>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!</P>Fri, 17 Oct 2014 00:19:36 GMThttps://forums.xilinx.com/t5/Embedded-Linux/Where-does-U-Boot-saveenv-to/m-p/533515#M10975sam_jaeschke2014-10-17T00:19:36ZRe: Where does U-Boot saveenv to?https://forums.xilinx.com/t5/Embedded-Linux/Where-does-U-Boot-saveenv-to/m-p/533833#M10983
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 ;-)<BR /><BR />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.<BR /><BR />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.<BR /><BR />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.<BR /><BR />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 ;-)Fri, 17 Oct 2014 13:52:06 GMThttps://forums.xilinx.com/t5/Embedded-Linux/Where-does-U-Boot-saveenv-to/m-p/533833#M10983rfs6132014-10-17T13:52:06ZRe: Where does U-Boot saveenv to?https://forums.xilinx.com/t5/Embedded-Linux/Where-does-U-Boot-saveenv-to/m-p/536425#M11041
<P>It seems to me that the options are:</P>
<P>1. Boot from something other than QSPI and you can use saveenv (32MB QSPI just to store 128KB of settings).</P>
<P>2. Boot from QSPI, but you can't use saveenv.</P>
<P>3. Read the source, Luke.</P>
<P>&nbsp;</P>
<P>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!</P>
<P>So developers are people too - if they want to use saveenv during a project, then why not let them?</P>
<P>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.</P>
<P>&nbsp;</P>
<P>I may look into contributing (time permitting)...</P>Fri, 24 Oct 2014 05:07:12 GMThttps://forums.xilinx.com/t5/Embedded-Linux/Where-does-U-Boot-saveenv-to/m-p/536425#M11041sam_jaeschke2014-10-24T05:07:12ZRe: Where does U-Boot saveenv to?https://forums.xilinx.com/t5/Embedded-Linux/Where-does-U-Boot-saveenv-to/m-p/556572#M11640
<P>I was also having this issue. Thanks to this thread I know what the cause was.</P>
<P>&nbsp;</P>
<P>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).</P>
<P>&nbsp;</P>
<P>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&nbsp;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&nbsp;a bit of empty page space.</P>Tue, 06 Jan 2015 03:01:46 GMThttps://forums.xilinx.com/t5/Embedded-Linux/Where-does-U-Boot-saveenv-to/m-p/556572#M11640john.dalton@rftechnology2015-01-06T03:01:46ZRe: Where does U-Boot saveenv to?https://forums.xilinx.com/t5/Embedded-Linux/Where-does-U-Boot-saveenv-to/m-p/556622#M11646
<P>Hi John, glad to hear I'm not alone on this. Let us stand together in our frustration!</P>
<P>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.</P>
<P>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.</P>Tue, 06 Jan 2015 06:10:18 GMThttps://forums.xilinx.com/t5/Embedded-Linux/Where-does-U-Boot-saveenv-to/m-p/556622#M11646sam_jaeschke2015-01-06T06:10:18ZRe: Where does U-Boot saveenv to?https://forums.xilinx.com/t5/Embedded-Linux/Where-does-U-Boot-saveenv-to/m-p/556734#M11655
<P>Keep in mind that the u-boot environment can be stored in places other than the QSPI flash.&nbsp; 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.</P>
<P>&nbsp;</P>
<P>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.</P>Tue, 06 Jan 2015 15:03:10 GMThttps://forums.xilinx.com/t5/Embedded-Linux/Where-does-U-Boot-saveenv-to/m-p/556734#M11655rfs6132015-01-06T15:03:10ZRe: Where does U-Boot saveenv to?https://forums.xilinx.com/t5/Embedded-Linux/Where-does-U-Boot-saveenv-to/m-p/556802#M11661
<P>Yes <LI-USER uid="48887"></LI-USER>,&nbsp;that is true, and those macro defines are mentioned in the U-Boot README.</P>Tue, 06 Jan 2015 22:35:04 GMThttps://forums.xilinx.com/t5/Embedded-Linux/Where-does-U-Boot-saveenv-to/m-p/556802#M11661sam_jaeschke2015-01-06T22:35:04Z