BPI R3 — Why is the MAC modified? (custom image)

The MAC addresses on my BPI R3 router change with each firmware build (OpenWrt Buildroot).

# mediatek_setup_macs $board

I disabled the above command from the script files/etc/board.d/02_network hoping to keep the factory MAC of the WAN interface eth1.

	case $board in
	bananapi,bpi-r3|\
	bananapi,bpi-r3-mini|\
	bananapi,bpi-r4)
		wan_mac=$(macaddr_add $(cat /sys/class/net/eth0/address) 1)
		;;

Could someone explain to me why the MAC keeps changing after a firmware rebuild?

I'd have to find a way to extract the MAC to generate the DHCPv4 (v6) client identifier option. The MAC is copied into the file /etc/board.json via the function mediatek_setup_macs $board and ultimately retrieved in the Shell script /bin/config_generate. Would it be much simpler to copy the factory MAC?

Best regards

I got a few things mixed up.

  • The MAC addresses of the interfaces wan and eth1 had been overwritten (as seen in the LuCi interface) in the factory image (downloaded on OpenWrt).
  • The MAC addresses were reset to a new value after each new firmware build (Buildroot).

I didn't know how the MAC addresses were extracted. I thought OpenWrt had a process that modified the original MAC addresses: the addresses changed at each build and were overwritten. I did some research to find out where the MAC address was coming from, but I couldn't find a clear answer. Digging around, I realized that the MAC addresses were generated before the OpenWrt image was booted. I also realized that the code snippet mentioned in the previous post didn't generate a new MAC address but rather retrieved an existing one (eth1) and applied it to the two interfaces eth1 and wan (in the “official” OpenWrt image, wan is a physical switch port that is bridged with eth1 to build the logical WAN interface).

	if [ -n "$macaddr" ]; then
		uci -q batch <<-EOF
			add network device
			set network.@device[-1].name='$device'
			set network.@device[-1].macaddr='$macaddr'
		EOF
	fi

The code above in /bin/config_generate modifies the MAC address, but I hadn't noticed it because in my configuration file files/etc/uci-defaults/99-custom it was explicitly removed. This explains my confusion. I didn't know how to retrieve the MAC address generated. Indeed, I thought the function macaddr_add generated a new address whereas I wanted to keep the default one.

More precisely, the U-boot environment variable ethtaddr seems to be set in the file /etc/uci-defaults/99_fwenv-store-ethaddr.sh:

bananapi,bpi-r3|\
bananapi,bpi-r3-mini|\
bananapi,bpi-r4|\
bananapi,bpi-r4-poe)
        [ -z "$(fw_printenv -n ethaddr 2>/dev/null)" ] &&
                fw_setenv ethaddr "$(cat /sys/class/net/eth0/address)"
        [ -z "$(fw_printenv -n eth1addr 2>/dev/null)" ] &&
                fw_setenv eth1addr "$(macaddr_add $(cat /sys/class/net/eth0/address) 1)"
        ;;

I've found some new additional information by doing a search.

Being a development board, the Bananapi BPi-R64 doesn't come with (a) MAC address(es) allocated and assigned by the vendor. Hence it is left to the user to assign a permanent address to the device. If there is a MAC address stored in the U-Boot environment used during boot, this address is used by U-Boot and it is handed down to Linux and becomes the default for all downstream interfaces in OpenWrt as well. To set it from inside OpenWrt, run

fw_setenv ethaddr 02:33:44:55:66:77

and reboot.

Source: Sinovoip BananaPi BPi-R64: Setting a permanent MAC address for Ethernet

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.