Update: the function that handles the file writing seems to be here.
Here’s a test i’m doing in case it lights up ideas in someone’s head:
U-Boot CosmOS > env set toto tata
U-Boot CosmOS > env print toto
toto=tata
U-Boot CosmOS > saveenv
Saving Environment to FAT... OK
U-Boot CosmOS > boot
6694592 bytes read in 47 ms (135.8 MiB/s)
## Booting kernel from Legacy Image at 00080000 ...
Image Name: Linux kernel (CosmOS)
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 6694528 Bytes = 6.4 MiB
Load Address: 00008000
Entry Point: 00008000
Verifying Checksum ... OK
## Flattened Device Tree blob at 2eff3a00
Booting using the fdt blob at 0x2eff3a00
Loading Kernel Image
Using Device Tree in place at 2eff3a00, end 2f002f6b
Starting kernel ...
root@pi:~ fw_printenv | grep toto
root@pi:~ cat /etc/fw_env.config
/boot/u-boot/uboot.env 0x0000 0x4000
/boot/u-boot/uboot-redund.env 0x0000 0x4000
root@pi:~ cat /etc/fstab
proc /proc proc defaults 0 0
/dev/root / ext4 defaults,noatime 0 1
/dev/sda1 /boot/u-boot vfat defaults 0 2
/dev/sda4 /data ext4 defaults 0 2
rpi_4_32b_defconfig
CONFIG_ENV_SIZE=0x4000
CONFIG_ENV_FAT_DEVICE_AND_PART="0:1"
CONFIG_ENV_FAT_INTERFACE="usb"
CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
CONFIG_SYS_RELOC_GD_ENV_ADDR=y
CONFIG_SYS_REDUNDAND_ENVIRONMENT=y