Hello,
I am facing a strange/weird issue when trying to access to filesystem based (/boot/uboot.env) in STM32MP157c-dk2 evaluation board. Uboot is 2020.07-rc5 from github, the board DEVICETREE is stm32mp157c-dk2, the kernel is from Robert C.Nelson repository (from DigiKey EEWiki) and it is 5.12.0-rc6 with some patches applied during built time.
The FSBL1 and FSBL2 and SSBL are written in the specific partitions.
The linux filesystem has 3 partitions: /boot (for kernel, devicetrees and uboot.env) as EXT4 filesystem, / (for Debian 11 Bullseye rootfilesystem) and /recoveryfs has a Debian 10 minimal bootstrap configuration.

Usually UBoot is looking for the bit 2 of each partition (bootable flag) and look for extlinux.conf configuration.
This configuration file is with a couple of entries:
label Linux 5.12.0-rc6-armv7-lpae-x7
    kernel /vmlinuz-5.12.0-rc6-armv7-lpae-x7
    append console=ttySTM0,115200 root=/dev/mmcblk0p6 ro rootfstype=ext4 
rootwait noswap mem=512M
    fdtdir /dtbs/5.12.0-rc6-armv7-lpae-x7/
    devicetree /dtbs/5.12.0-rc6-armv7-lpae-x7/stm32mp157c-dk2.dtb
label Recovery 5.12.0-rc6-armv7-lpae-x7
    kernel /vmlinuz-5.12.0-rc6-armv7-lpae-x7
    append console=ttySTM0,115200 root=/dev/mmcblk0p5 ro rootfstype=ext4 
rootwait noswap mem=512M recovery
    fdtdir /dtbs/5.12.0-rc6-armv7-lpae-x7/
    devicetree /dtbs/5.12.0-rc6-armv7-lpae-x7/stm32mp157c-dk2.dtb

Linux & Recovery.

Linux is Debian 11 Bullseye and Recovery is Debian 10 Minimal Install.

My goal at the moment is to add the ethaddr environment variable to the /boot/uboot.env (EXT4) configuration file.

Using the u-boot tools with fw_printenv it fails with:
# fw_printenv
Cannot read environment, using default
Cannot read default environment from file

The file /etc/fw_env.config has only one entry:

/boot/uboot.env 0x0000 0x4000

The file itself is 8192 bytes (0x4000 == 16384) but the fw_env.config is (partially) wrong. I do not know if this extra information are used when accessing a file-system-based u-boot environment anyway.

Following strace fw_printenv here is the culprit:


execve("/usr/bin/fw_printenv", ["fw_printenv"], 0xbeaf6770 /* 20 vars */) = 0
brk(NULL)                               = 0x92f000
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0xb6fb2000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=118003, ...}) = 0
mmap2(NULL, 118003, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb6f6e000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/arm-linux-gnueabihf/libubootenv.so.0.3", 
O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\320\f\0\0004\0\0\0"..., 
512) = 512
fstat64(3, {st_mode=S_IFREG|0644, st_size=13784, ...}) = 0
mmap2(NULL, 78040, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 
0xb6f5a000
mprotect(0xb6f5d000, 61440, PROT_NONE)  = 0
mmap2(0xb6f6c000, 8192, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0xb6f6c000
close(3)                                = 0
openat(AT_FDCWD, "/lib/arm-linux-gnueabihf/libz.so.1", 
O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0h\32\0\0004\0\0\0"..., 
512) = 512
fstat64(3, {st_mode=S_IFREG|0644, st_size=75404, ...}) = 0
mmap2(NULL, 139500, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 
0xb6f37000
mprotect(0xb6f49000, 61440, PROT_NONE)  = 0
mmap2(0xb6f58000, 8192, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x11000) = 0xb6f58000
close(3)                                = 0
openat(AT_FDCWD, "/lib/arm-linux-gnueabihf/libc.so.6", 
O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\3\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0Y\253\1\0004\0\0\0"..., 
512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=973416, ...}) = 0
mmap2(NULL, 1042632, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 
0xb6e38000
mprotect(0xb6f22000, 61440, PROT_NONE)  = 0
mmap2(0xb6f31000, 16384, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xe9000) = 0xb6f31000
mmap2(0xb6f35000, 6344, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb6f35000
close(3)                                = 0
set_tls(0xb6fb3580)                     = 0
mprotect(0xb6f31000, 8192, PROT_READ)   = 0
mprotect(0xb6f58000, 4096, PROT_READ)   = 0
mprotect(0xb6f6c000, 4096, PROT_READ)   = 0
mprotect(0x431000, 4096, PROT_READ)     = 0
mprotect(0xb6fb4000, 4096, PROT_READ)   = 0
munmap(0xb6f6e000, 118003)              = 0
brk(NULL)                               = 0x92f000
brk(0x950000)                           = 0x950000

Now the interesting stuff:

openat(AT_FDCWD, "/etc/fw_env.config", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=36, ...}) = 0
read(3, "/boot/uboot.env    0x0000    0x4"..., 4096) = 36
lstat64("/boot", {st_mode=S_IFDIR|0755, st_size=1024, ...}) = 0
lstat64("/boot/uboot.env", {st_mode=S_IFREG|0755, st_size=8192, ...}) = 0
stat64("/boot/uboot.env", {st_mode=S_IFREG|0755, st_size=8192, ...}) = 0
openat(AT_FDCWD, "/boot/uboot.env", O_RDONLY) = 4
close(4)                                = 0
read(3, "", 4096)                       = 0
close(3)                                = 0
openat(AT_FDCWD, "/var/lock/fw_printenv.lock", O_WRONLY|O_CREAT|O_TRUNC, 0666) 
= 3
flock(3, LOCK_EX)                       = 0
openat(AT_FDCWD, "/boot/uboot.env", O_RDONLY) = 4
read(4, "t\310;\372\1altbootcmd=run bootcmd\0arch"..., 16384) = 8192
close(4)                                = 0
write(2, "Cannot read environment, using d"..., 39Cannot read environment, 
using default
) = 39
openat(AT_FDCWD, "/etc/u-boot-initial-env", O_RDONLY) = -1 ENOENT (No such file 
or directory)
write(2, "Cannot read default environment "..., 42Cannot read default 
environment from file
) = 42
exit_group(-13)                         = ?
+++ exited with 243 +++

What is happening here? The 16384 when reading read(4, "t\310;"..., 16384) = 8192 is correct?

Obvioulsy I do not have a /etc/u-boot-initial-env so this error is a no-go issue.

Why I cannot read the environment?

This environment is written by u-boot itself when not finding any previous uboot.env at the first boot.

This is FSBL1

U-Boot SPL 2020.07-rc5 (Apr 07 2021 - 17:20:03 +0200)
Model: STMicroelectronics STM32MP157C-DK2 Discovery Board
RAM: DDR3-DDR3L 16bits 533000Khz
Trying to boot from MMC1



This is SSBL (U-BOOT)

U-Boot 2020.07-rc5 (Apr 07 2021 - 17:20:03 +0200)

CPU: STM32MP157CAC Rev.B
Model: STMicroelectronics STM32MP157C-DK2 Discovery Board
Board: stm32mp1 in basic mode (st,stm32mp157c-dk2)
Board: MB1272 Var2.0 Rev.C-01
DRAM:  512 MiB
Clocks:
- MPU : 650 MHz
- MCU : 208.878 MHz
- AXI : 266.500 MHz
- PER : 24 MHz
- DDR : 533 MHz
NAND:  0 MiB
MMC:   STM32 SD/MMC: 0
Loading Environment from EXT4... ** File not found /uboot.env **

** Unable to read "/uboot.env" from mmc0:4 **

In this case there is NO uboot.env so the warning is normal.

In:    serial
Out:   serial
Err:   serial
Net:   eth0: ethernet@5800a000
Hit any key to stop autoboot:  0
Boot over mmc0!
Saving Environment to EXT4... File System is consistent

Now it saves the uboot.env with some default/board default configurations

update journal finished
done
OK

update the filesystem (for journal too)

switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:4...
Found /extlinux/extlinux.conf
Retrieving file: /extlinux/extlinux.conf
590 bytes read in 27 ms (20.5 KiB/s)
1:      Linux 5.12.0-rc6-armv7-lpae-x7

Why it found only 1 entry? The file is composed by two entries as above.

Retrieving file: /vmlinuz-5.12.0-rc6-armv7-lpae-x7
11526656 bytes read in 516 ms (21.3 MiB/s)
append: console=ttySTM0,115200 root=/dev/mmcblk0p6 ro rootfstype=ext4 rootwait 
noswap mem=512M
Retrieving file: /dtbs/5.12.0-rc6-armv7-lpae-x7/stm32mp157c-dk2.dtb
59602 bytes read in 31 ms (1.8 MiB/s)
## Flattened Device Tree blob at c4000000
   Booting using the fdt blob at 0xc4000000
   Loading Device Tree to cffee000, end cffff8d1 ... OK

Starting kernel ...

And from now on everything is normal / as expected...

In u-boot commandline I am unable to change the uboot.env:

STM32MP> setenv ethaddr 00:11:22:33:44:55
## Error: Can't overwrite "ethaddr"
## Error inserting "ethaddr" variable, errno=1

But uboot is able to change the environment in that partition. :-(
But it is able to add another entry (for example ethaddr0).
When trying to delete ethaddr with:

STM32MP> setenv ethaddr 00:11:22:33:44:55

it fails with:

## Error: Can't overwrite "ethaddr"
## Error inserting "ethaddr" variable, errno=1

I tried another command:
STM32MP> env delete ethaddr
## Error: Can't delete "ethaddr"

What's wrong?

My first goal is to give this board a particular mac address without writing it on the OTP registers.
Is this possible?

Where am I wrong?

Thank you for any help you give me.

Regards,
Gianluca
--
Eurek s.r.l.                          |
Electronic Engineering                | http://www.eurek.it
via Celletta 8/B, 40026 Imola, Italy  | Phone: +39-(0)542-609120
p.iva 00690621206 - c.f. 04020030377  | Fax:   +39-(0)542-609212

Reply via email to