Make sure to number your Application Note correctly. It should be successive.
This Application Note explains a simple method showing how to Store/Retrieve MAC IDs from EEPROM. |
Your target hardware may have different sysfs IDs for the EEPROM you are targeting. Please note that you may have to modify the device ID from what is used in the code-blocks below. You may also have different ethernet interfaces on your device. You can use ifconfig to list your interfaces.
Beginning at byte 0 of the EEPROM, the data is formatted as follows:
eth0:001122334455 |
Beginning at byte 0 of the EEPROM, the data is formatted as follows:
eth1:002233445566 eth2:DEEEADBEEEEF wlan0:502d00cceedd |
Write a file containing MAC IDs to the EEPROM
$ dd if=macids.txt of=/sys/bus/i2c/devices/2-0051/eeprom |
Create a string of MAC IDs (assuming you have multiple interfaces) and write them to the EEPROM
$ printf "eth1:002233445566\neth2:DEEEADBEEEEF\nwlan0:502d00cceedd\n" > /sys/bus/i2c/devices/2-0051/eeprom |
The dd command can also take in stdin instead of an if= argument, and can be used to skip (seek past) # blocks of size bs=. This is useful to append MAC IDs instead of overwriting each one, allowing individual writes.
$ printf "eth2:DEEEADBEEEEF\nwlan0:502d00cceedd\n" | dd of=/sys/bus/i2c/devices/2-0051/eeprom bs=1 seek=18 |
$ cat /sys/bus/i2c/devices/2-0051/eeprom eth1:002233445566 eth2:DEEEADBEEEEF wlan0:502d00cceedd |
3p directs sed to print the third line.
$ sed -n '3p' /sys/bus/i2c/devices/2-0051/eeprom wlan0:502d00cceedd |
$ grep -i eth2 /sys/bus/i2c/devices/2-0051/eeprom eth2:DEEEADBEEEEF |
A sed command: sed -e 's/^.*://' is used to strip the interface and display only the MAC ID that can be directly passed to ifconfig. It can be combined with the output of any of the display commands to grab the desired MAC IDs.
$ cat /sys/bus/i2c/devices/2-0051/eeprom | sed -e 's/^.*://' 002233445566 DEEEADBEEEEF 502d00cceedd $ sed -n '3p' /sys/bus/i2c/devices/2-0051/eeprom | sed -e 's/^.*://' 502d00cceedd $ grep -i eth2 /sys/bus/i2c/devices/2-0051/eeprom | sed -e 's/^.*://' DEEEADBEEEEF |
This script uses ifconfig to gather a list of supported ethernet and wlan interfaces then sets the corresponding MAC ID for that interface. This example is done after the interfaces have potentially come up, but can be modified and implemented as part of the network init scripts specific to each device's filesystem.
#!/bin/sh INTERFACES=(`ifconfig -a | grep -o "eth[0-9]\|wlan[0-9]"`) for iface in ${INTERFACES[@]}; do MACID=`grep -i ${iface} /sys/bus/i2c/devices/2-0051/eeprom | sed -e 's/^ ifconfig ${iface} down ifconfig ${iface} hw ether ${MACID} ifconfig ${iface} up done exit 0 |