ethtool修改永久修改eeprom(MAC)地址

背景

项目中移植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/

  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值