Custom u-boot environment location

I would like to move the u-boot environment from its original location into the user area partition right after the partition table and in front of the first partition.

In the original image the script states that the u-boot environment is created into the cbootimage apalis-tk1.img (after the BCT and u-boot which are also contained in apalis-tk1.img) which is then flashed into the boot area partition 1 (“primary eMMC boot sector”) in front of the confgblock.bin. I could not find the info about the u-boot environment in the cbootimage config file apalis-tk1.img.cfg. The apalis-tk1.img has a total size of 599.040 bytes. When one is assuming no compression and subtracts the BCT PM375_Hynix_2GB_H5TC4G63AFR_RDA_924MHz.bct size of 8.192 bytes and my custom u-boot u-boot-dtb-tegra-rc.bin size of 582.506 bytes (the original u-boot-dtb-tegra-apalis-tk1-v2016.11-v2.7b1+gitAUTOINC+22e68cbd1f-r0.bin has a slightly bigger size of 583.062 bytes) the remaining size for the u-boot environment should be 8.342 bytes.

How must I configure the apalis-tk1.img.cfg that the u-boot environment is not placed in the cbootimage apalis-tk1.img?

How must I modify the flashing script flash_eth.scr to support the u-boot environment with a size of 0x20000 and device offset of 0x800000 and the redundant u-boot environment with a size of also 0x20000 and a device offset of 0x1000000 (8MB alignment)? Do I have to “raw copy” a file for the u-boot environment into the eMMC after the mbr.bin and in front of the 1 partition? Or do I have to generate an image for the u-boot environment with mkenvimage? As the flashing of the configblock.bin is not called in another u-boot command I need to execute run update_configblock in addition to run setupdate and run update during debugging, right?

Again I am totally missing what exactly you are trying to achieve. But please note a few things you may have misunderstood:

  • By default we do not store the U-Boot environment into a file but rather raw eMMC blocks.
  • What #define CONFIG_SYS_MMC_ENV_PART 1 means is that it stores it into the first eMMC hardware area boot partition which has really nothing to do with the VFAT partition you now put some arbitrary files in.

The background for this misunderstanding:
I tried to integrate with the OTA software updater by following their integration guide. I discovered that they used two different approaches related with the storage location of the u-boot environment over time. First the u-boot environment has been stored in a file uboot.env but now the u-boot environment is stored in the eMMC (like you do). The approach changed without my notification. Sorry for that confusion…

I will change the question with relation to the new approach.

The IMAGE_ROOTFS_ALIGNMENT (4 MiB) in is required to reserve space for the partition table, right?

At least some amount, yes. We kept it at 4 MiB due to earlier variants of certain modules having had even the boot loader as well as the config block in that area. But of course like everything else you may change this to your liking but just be aware of potential side effects.

Ok, now I understand… (I did not understand because the mbr.bin file has just 512 bytes = 1 sector).

With mkenvimage I get a corresponding u-boot environment image u-boot-env.bin from u-boot-env.txt when running ~/ws_gitlab/u-boot-toradex$ ./tools/mkenvimage -r -s 0x20000 -o u-boot-env.bin u-boot-env.txt. (The u-boot sources need to have CONFIG_ENV_ADDR_REDUND and CONFIG_ENV_SIZE_REDUND set because of the redundant environment: mkenvimage: a tool to generate a U-Boot environment binary image .)

The uboot environment (and the redundant copy) are stored into the eMMC initially by u-boot itself. There is no need to raw copy blob files (uboot.env) into the eMMC manually. However the #define CONFIG_ENV_SIZE_REDUND CONFIG_ENV_SIZE (in include/configs/apalis-tk1.h) needs to be set explicitly in addition to the other config values mentioned above and #define CONFIG_SYS_MMC_ENV_DEV 0 #define CONFIG_SYS_MMC_ENV_PART 0 #define CONFIG_ENV_OFFSET 0x800000 CONFIG_ENV_OFFSET_REDUND 0x100000. The spacing between the offsets needs to consider the size of the u-boot environment and the alignment used (e.g. 8MB). There needs to be enough space to hold the u-boot environments after the mbr.bin (1 block, usually flashed into startblock 0x0) and in front of the first partition usually holding boot.vfat.