Summary
I want to use fw_printenv and fw_setenv on Raspberry Pi 4(RPi4) with Ubuntu 20.04 to print and set a environment value for U-Boot. When runs those commands, then I can see following errors on the UART console:
ubuntu@ubuntu:~$ sudo fw_printenv
Environment WRONG, copy 0
Cannot read environment, using default
Cannot read default environment from file
ubuntu@ubuntu:~$ sudo fw_setenv asdf 123
Environment WRONG, copy 0
Cannot read environment, using default
Cannot read default environment from file
Does anyone know how to fix the problem?
What I've tried
First I created a SD card with Ubuntu Server 20.04.3 LTS 64-bit (Released: 2021-08-26) using the official Raspberry Pi Imager. Then I run it on RPi4 and updated the software by sudo apt update && sudo apt upgrade -y.
After updating, I realized that uboot.env does not exist at /boot/firmware, so I set a test environment value on U-Boot something like:
U-Boot> setenv asdf 123
U-Boot> saveenv
Saving Environment to FAT... OK
U-Boot> printenv
arch=arm
asdf=123
...
Then uboot.env has been created at /boot/firmware. It could be confirmed on Ubuntu:
ubuntu@ubuntu:/boot/firmware$ ls -l uboot.env
-rwxr-xr-x 1 root root 131072 Jan 1 1980 uboot.env
In addition, I could not find a configuration file for the fw_printenv at /etc/fw_env.config, so I created it:
/boot/firmware/uboot.env 0x0000 0x20000
Finally I run the fw_printenv and fw_setenv but got the errors as I mentioned earlier. On the other hand, uboot.env is accessible simply running less or cat:
ubuntu@ubuntu:/boot/firmware$ less uboot.env
"uboot.env" may be a binary file. See it anyway?
<BA><9C>^Sf^Aarch=arm^@asdf=123^@ ...
Version Info
On U-Boot:
U-Boot> version
U-Boot 2021.01+dfsg-3ubuntu0~20.04.3 (Jul 30 2021 - 14:38:17 +0000)
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
GNU ld (GNU Binutils for Ubuntu) 2.34
On Ubuntu:
ubuntu@ubuntu:~$ uname -a
Linux ubuntu 5.4.0-1044-raspi #48-Ubuntu SMP PREEMPT Thu Sep 9 15:24:01 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux
ubuntu@ubuntu:~$ fw_setenv -V
0.2
ubuntu@ubuntu:~$ fw_printenv -V
0.2