[Bananapi-r2] Where is board's MAC address stored?

The driver searches in dts for notes: “mac-address”, “address”. or “local-mac-address” for the network device. If there are none of them the mac generares randomly.

P.S.

I don’t know how it works with uboot.

Uboot way needs also dts modification (alias + blank mac on nic) and dtb loaded separately. You can only set nic,not dsa ports.

1 Like

If i understand correctly uboot defined mac doesn’t affect on linux, when it’s not fefined in linut dts?

i.e. Once defined in u-boot it still random in linux unless defined in linux too?

Mostly right. Uboot can only pass mac if dtb is passed separately to linux. It cannot change appended dtb. It needs alias set to right gmac/nic.

1 Like

Acording my knowlege, we usually story MAC address in EEPROM, and kernel linux will read it because every device should have the unique mac address. If we have 1000 device, I think it is not convience if we pass MAC address manually via dst

maybe there is a BIA stored in efuse, but i have no info about this…i guess ethernet-chips without a BIA are cheaper :wink:

btw. found my posting for changing mac with uboot: Set MAC-Address on boot

Is it just set with ethaddr/eth1addr u-boot env?

Is there a way to show mac from u-boot CLI?

UPD: didn’t works for me:

[ 5.810447] mtk_soc_eth 1b100000.ethernet: generated random MAC address d2:15:f9:13:b4:4d

on each boot afrer u-boot ethaddr has been set.

Do have any method to set unique mac address for every device automatic ?

Have you booted using separate devicetree?

  • load kernel without devicetree
  • load fdt
  • modify ethaddr
  • bootm kerneladdr - dtaddr

I have only 1 device so - no. IMHO if needed it’s possible to use templates for OS/kernel/uboot building. i.e. to build multiple images for mutiple devices with different predefined MACs.

kernel - dts overlays OS - udev-rules. Ansible/Puppet/etc also may help (doesn’t needed with dts) u-boot - … here i need to read more manuals. uEnv.txt(?)

Anyway, it’s only a theories :slight_smile:

BTW @frank-w do you know any method to modify uboot environment without uboot cli, or can ethernetaddress be defined in uEnv.txt?

Yes in GRUB, but it’s still experimental - not default loader.

with u-boot - no, still not so familiar with it

ftd is it the same as devicetree (dtb)? if so then do i need to define it twice: ethaddr for uboot purposes and ftd(dtb(?)) for kernel?

You can use uboot-utils: It have binary fw_printenv and fw_setenv. So you can modify u-boot enviroment from linux command

1 Like

Fdt is only name for Flattened Device Tree. Uboot has its own device tree loaded before you can enter any command in uboot. The DT you load is for kernel and you have to load it before setting mac in uboot. Imho all you do on console can be done with environment/uboot scripts. The challenge is to load devicetree before setting mac-address. Imho easiest way should be using dt-overlays. Here you can set mac for each device and leave uboot/kernel untouched. But also here you need to load kernel with separate fdt (fdt,dto,apply dto which overrides parts of fdt,then load kernel and pass your modified dt).

Do you know the offset and size for emmc/sd? For /etc/fw_env.config.

UPD: got in from u-boot boot messages:

[PART] [0x0000000000000000-0x000000000003FFFF] "PRELOADER" (512 blocks)                                                                                                                                                                            
[PART] [0x0000000000000000-0x000000000003FFFF] "MBR" (512 blocks)                                                                                                                                                                                  
[PART] [0x0000000000040000-0x00000000000BFFFF] "UBOOT" (1024 blocks)                                                                                                                                                                               
[PART] [0x00000000000C0000-0x00000000000FFFFF] "CONFIG" (512 blocks)

UPD2:

set /etc/fw_env.config to:

bpi-r2-gentoo ~ # cat /etc/fw_env.config | grep -v "#"

/dev/mmcblk0            0xc0000         0x40000

got error on fw_printenv :

bpi-r2-gentoo ~ # fw_printenv             
Warning: Bad CRC, using default environment
bootcmd=bootp; setenv bootargs root=/dev/nfs nfsroot=${serverip}:${rootpath} ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}::off; bootm
bootdelay=2
baudrate=115200
stdin=serial,cros-ec-keyb,usbkbd
stdout=serial,vidconsole
stderr=serial,vidconsole
ethaddr=00:00:11:22:33:44
eth1addr=00:00:11:22:33:45
eth3addr=00:00:11:22:33:46
eth5addr=00:00:11:22:33:47
ipaddr=1.2.3.4
bootm_size=0x10000000
kernel_addr_r=0x1000000
fdt_addr_r=0xc00000
ramdisk_addr_r=0x2000000
scriptaddr=0x1000
pxefile_addr_r=0x2000

Offset is imho 1MB…have you used saveenv in uboot before? Else you can just change uenv.txt on boot partition. No need to change binary env because uenv.txt overrides it

this is offset: /dev/mmcblk0 0x4c000 0x4000

Please check again

Found it from SD image:

/dev/mmcblk0 0x100000 0x2000

(atleast for U-Boot 2020.01-bpi-r2)

Same error as before

Also found it in mt7623n_bpir2_defconfig :see_no_evil::

CONFIG_ENV_SIZE=0x2000                                                                                                                                                                                                                              
CONFIG_ENV_OFFSET=0x100000

P.S. also works great with MMC: /dev/mmcblk1

Menus, and the default entry is in it.

Do you mean “uenv.txt”, not uEnv.txt?, like for full rewrite?

I mean uEnv.txt on boot-partition which overrides saved environment at offset 1m (direct on storage)

1 Like

I’m also trying to save the mac-address in the environment variable and trying to access it via fw_printenv

But I get the following error when I use the command.

Cannot parse config file: No such file or directory

Any ideas on how to resolve it?