Dragonboard : lib/firmware ethmacaddr0

i am trying to modify the /lib/firmware/smsc75xx/ethmacaddr0 as sudo , but still i am getting Read-only file system

this is my snapcraft.yaml wrt firmware

firmware:
plugin: tar-content
source: firmware.tar.gz
destination: firmware
stage-packages:
- linux-firmware
organize:
lib/firmware: firmware
prime:
- -usr
- -lib
install: |
mkdir -p $SNAPCRAFT_PART_INSTALL/firmware/wlan
ln -s /run/macaddr0 $SNAPCRAFT_PART_INSTALL/firmware/wlan/
mkdir -p $SNAPCRAFT_PART_INSTALL/firmware/smsc75xx
echo “58:fc:db:40:20:fa” > SNAPCRAFT_PART_INSTALL/firmware/smsc75xx/ethmacaddr0

after boot, /lib/firmware/smsc75xx/ethmacaddr0 is created , it’s content is 58:fc:db:40:20:fa . i tried to modify this file, but it failed saying Read-only file system.
echo “58:fc:db:40:20:fb” | sudo tee /lib/firmware/smsc75xx/ethmacaddr0

Could you please suggest how to modify/set write permissions for /lib/firmware content files. So that i will be able to set mac address after booting in target

similar thing i need to do for the firmware/wlan//macaddr0 for wifi also.

In short … there is no way, you can only do it at build time … /lib/firmware is a bind-mount of /snap/<kernel-snap>/firmware and that is inside a loop mounted and gpg signed squashfs file …

you can do the same in the install scriptlet that is done for wlan/macaddr0 and ship a dangling symlink in the snap pointing to /var/snap/<your-daemon-snap>/current/ethmacaddr0 … and then have a daemon snap that fills this file with content …

We are able to overwrite the mac address (/lib/firmware/smsc75xx/ethmacaddr0) in case of debian/ubuntu version rootfs

even in the case of scriplets for wlan/macaddr0 it is choosing based on the androidboot.serialno . but later it has to be changed for each board will be assigned different mac address based on the mac address recieved for that hardware.

echo “58:fc:db:40:20:fa” | sudo tee /run/macaddr0
this changes at that moment only, after reboot, wlan mac address retains the old one based on androidboot.serialno.
[this script should actually first need to pick the programmed mac address, if it is not present it should set based on .serialno]


scriplet is part of snapcore, how do i need to build my own script and integrate to ubuntu-xenial(kernel.snap) and dragonboard gadget.snap and build the .img

you can not modify the initrd, nor can you modify the readonly rootfs or the readonly kernel, this is by (security-)design

the method i described above is the only way to do it without making any incompatible changes to the system …

Edit: indeed you can patch the drivers themselves in the kernel tree to look at certain writable places (like /run) that you then fill from a daemon snap … (or patch them to read a kernel cmdline option)

In ubuntu-xenial.git , snapcraft.yaml they had linked the /run/macaddr0 to firmware/wlan/macaddr0

i need some clarification how does this scriplet blob/master/initramfs/scripts/local-premount/dragonmac get executed and writes to /run/macaddr0

so i need to create /run/ethmacddr0 and link to firmware/smc75xx/ethmacaddr0

Could you please give some reference or pointer?

well, you gave the pointer yourself above already … with a slight modification it should just work for smsc75xx:

install: |
  ...
  mkdir -p $SNAPCRAFT_PART_INSTALL/firmware/smsc75xx
  ln -s /run/ethaddr0 $SNAPCRAFT_PART_INSTALL/firmware/smsc75xx/

now if you create a /run/ethaddr0 (from a snap for example) the mac address should be read from there … (if the smsc75xx driver supports that behaviour indeed)

when i modified the file snapcraft.yaml

mkdir -p $SNAPCRAFT_PART_INSTALL/firmware/smsc75xx
ln -s /run/ethaddr0 $SNAPCRAFT_PART_INSTALL/firmware/smsc75xx/

after booting from sdcard or even after reboot after first boot, it does not creates this file /run/ethaddr0.

i guess in case of wifi, snapcraft core is creating /run/macaddr0 file and writing content to it
ln -s /run/macaddr0 $SNAPCRAFT_PART_INSTALL/firmware/wlan/

as i said a few times above, you have to create this file from a snap or script …

i am able to create a snap and install in --devmode and /run/ethmacaddr0 got created.

in the uboot.env.in i had added this args=androidboot.serialno=f2103d96 ethmacaddr=58fcdb4020fe
so it will have persistent storage. I can change the ethmacaddr for each boards in uboot or using fw_setenv

But it creates only when i run that snap. is it possible to run that snap by default before ethernet(smsc75xx) driver gets loaded.

is it possible to build the custom core-build ? so that i can modify the dragonmac and add a new ethmacaddr script also


ethmacaddr

#!/bin/sh -e

initramfs local-premount script to set a

mac address on the dragonboard

PREREQ=""

Output pre-requisites

prereqs()
{
echo “$PREREQ”
}

case “$1” in
prereqs)
prereqs
exit 0
;;
esac

if [ -e /proc/device-tree/model ]; then
if grep -q “APQ 8016” /proc/device-tree/model; then
if grep -q ethmacaddr /proc/cmdline; then
for i in $(cat /proc/cmdline); do
case “$i” in
ethmacaddr=*)
echo “${i#ethmacaddr=}”|
sed ‘s/.{2}/&:/g;s/.$//’ >/run/ethmacaddr0
;;
esac
done
fi
fi
fi



snapcraft.yaml

name: ifc6309-mac
version: ‘0.1’
summary: ethernet programming
description: |
ethernet mac address programming
confinement: strict

apps:
ethmacaddr:
command: ethmacaddr
plugs: [network, network-control]

parts:
ethmacaddr:
source: .
plugin: dump
organize:
ethmacaddr : usr/bin/ethmacaddr

well … i created a snap for you … do:

snap install mac-spoofer --edge 

then follow the instructions at:

for a second interface just add an additional line to the config file… after configuring it once the devices should come up with the new MAC addresses on each boot …

i installed and tried the snap, i am able to set the macaddresses for eth0, eth1 and wlan0.

if we spoof the mac address, i guess we do not even need the
snapcore/core-build/blob/master/initramfs/scripts/local-premount/dragonmac

**but if we go with this approach, boot up time took almost 2minutes. **
Is this a feasible solution?

vinaysimha@localhost:~$ cat /var/snap/mac-spoofer/current/config
eth1 58:fc:db:40:20:a1
eth0 58:fc:db:40:20:a2
wlan0 58:fc:db:40:20:a3
vinaysimha@localhost:~$

vinaysimha@localhost:~$ ifconfig -a
eth0 Link encap:Ethernet HWaddr 58:fc:db:40:20:a2
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

eth1 Link encap:Ethernet HWaddr 58:fc:db:40:20:a1
inet6 addr: fe80::5afc:dbff:fe40:20a1/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:59 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4634 (4.6 KB) TX bytes:712 (712.0 B)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:160 errors:0 dropped:0 overruns:0 frame:0
TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:12800 (12.8 KB) TX bytes:12800 (12.8 KB)

sit0 Link encap:IPv6-in-IPv4
NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

wlan0 Link encap:Ethernet HWaddr 58:fc:db:40:20:a3
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

i assume not all of your network cards are configured ?
that would be:

(a fix for this bug is still being researched)

fyi,

mac spoofing does not work always, i tried multiple reboots, it does not sets the mac addresses assigned in /var/snap/mac-spoofer/current/config . it picks the random mac addresses for interafces.

it is set from a snap, so it will only spoof once the daemon in the snap gets started (check again after waiting a little)

i tried multiple reboots, sometimes mac address set properly, sometimes not. it is having random behaviour

i want to build the custom core-build ? so that i can modify the dragonmac and add a new ethmacaddr script for initramfs

While you could do that for development, a custom core is not upgradeable, the same goes for the kernel snap if you change the initrd … i’d suggest to rather find out why exactly the mac spoofer snap does not work (does it run to early ? try adding some sleep to the script for a test) and fix that …

core-build/blob/master/initramfs/scripts/local-premount/dragonmac

is just a temporary solution for having unique mac address, We should program the actual mac address

this should change
from echo “0200${i#androidboot.serialno=}”|
to
echo “${i#androidboot.serialno=}”|

androidboot.serialno will be programmed once after the boot.

the similar way it should be applicable to ethmaccdr programming.

Why we need to run a daemon everytime at boot? if we can have permanent solution in persisent storage.

as i said above, this is a workaound for a bug in the driver introduced by the 96board guys. if the driver gets fixed to actually use ROM code as it should, the link in /run as well as the script in initrd will be removed. This is nothing permanent, normally MAC addresses are set form the hardware.

did you look at that “daemon” ? it is a script that only executes 3 lines of ip/ifconfig commands per device, nothing more … (and technically the poper way to do this if your network devices actually operate according to the spec)

In the old world (when using ifupdown) you would have used /etc/network/interfaces and added something like:

hwaddress ether 00:01:04:1b:2C:1F

to that file to set a mac address from software, but Ubuntu Core uses netplan instead of ifupdown which does not support this feature yet, so the call to “ip link set <device> address <addr>” is the proper fallback way until netplan grows such a feature. the initrd hack will go away as soon as the driver is fixed by upstream to read from the ROM or to use the devicetree for the address.

I have filed a whishlist bug at:

"this is a workaound for a bug in the driver introduced by the 96board guys. if the driver gets fixed to actually use ROM code "

this is not going to get fixed. dragonboard is already manufactured without any EEPROM on board. so the mac address has to be stored in emmc only.

the initrd hack will go away as soon as the driver is fixed by upstream to read from the ROM or to use the devicetree for the address.

since there is no ROM, i guess you are talking about storing the MAC addresses in devicetree(apq8016-sbc-snappy.dtsi)
In this case if there are 100 boards, each boards should be flashed with different .img by building different kernel snaps with modification in the .dtsi file.

Not really … it will likely just feed the devicetree from the lk during boot (by using the board serial), similar to to the pending patch used for setting the BT address at: