背景
项目中移植DM9621网卡的时候,发现eth网络接口正常出现,但是不能配置MAC地址。只要通过“ifconfig eth0 hw ether“”指令配置了MAC地址,就不再能够PING通其他主机。后分析发现内核驱动加载为cdc_ether,而不是dm9621。经分析发现应是我们自己做的硬件的eeprom内无配置内容,故dm9621芯片的工作模式不对。所以,我们需要刷写eeprom。
工具
刷写eeprom的工具为ethtool。
源码地址:https://mirrors.edge.kernel.org/pub/software/network/ethtool/
交叉编译指令:./configure --host=arm-linux CC=arm-fsl-linux-gnueabi-gcc LDFLAGS=-static
指令
ethtool -e|–eeprom-dump devname [raw on|off] [offset N] [length N]
ethtool -E|–change-eeprom devname [magic N] [offset N] [length N] [value N]
示例
configs="
0x00 0x60 0x6e 0x10 0x00 0xf1 0x51 0x15 0x46 0x0a 0x21 0x96 0x8f 0x00 0x84 0x41
0x10 0x22 0x21 0x32 0x3a 0x0a 0x5a 0x00 0x10 0x00 0xff 0xff 0xff 0xff 0xff 0xff
0x22 0x03 0x44 0x00 0x41 0x00 0x56 0x00 0x49 0x00 0x43 0x00 0x4f 0x00 0x4d 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x32 0x03 0x44 0x00 0x4d 0x00 0x39 0x00 0x36 0x00 0x32 0x00 0x31 0x00
0x41 0x00 0x20 0x00 0x55 0x00 0x53 0x00 0x42 0x00 0x20 0x00 0x54 0x00 0x6f 0x00
0x20 0x00 0x46 0x00 0x61 0x00 0x73 0x00 0x74 0x00 0x45 0x00 0x74 0x00 0x68 0x00
0x65 0x00 0x72 0x00 0x0a 0x03 0x30 0x00 0x30 0x00 0x30 0x00 0x32 0x00 0xff 0xff
"
dec2hex(){
printf "%x" $1
}
i=0
offset="0x"$(dec2hex $i)
for value in $configs;do
# echo $value;
# echo $offset;
./ethtool -E eth1 magic 0x9620 offset $offset value $value;
let i++;
offset="0x"$(dec2hex $i)
done
其中magic 的值为设备相关的,我这里dm9621的magic为0x9620。
Because of the persistent nature of writing to the EEPROM, a device-specific magic key must be specified to prevent the accidental writing to the EEPROM.
参考
https://bka-dev.github.io/post/how-to-permanently-change-a-mac-address-using-ethtool/