ethtool命令对EEPROM进行读写

使用ethtool命令对EEPROM进行读写

Android系统默认未支持ethtool命令,需增加工具。
参考:http://blog.csdn.net/u013686019/article/details/51491364
下载ethtool源码进行编译。
源码地址:https://www.kernel.org/pub/software/network/ethtool/
增加Android.mk进行编译如下:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
define all-c-files-under
$(patsubst ./%,%, $(shell find $(LOCAL_PATH) -name “platform” -prune -o -name "
.c" -and -not -name "."))
endef
define all-subdir-c-files
$(call all-c-files-under,.)
endef
C_FILES := $(call all-subdir-c-files)
LOCAL_SRC_FILES := ( C F I L E S : (C_FILES: (CFILES:(LOCAL_PATH)/%=%)
LOCAL_SHARED_LIBRARIES := libcutils libutils libcrypto libc
#LOCAL_C_INCLUDES := $(KERNEL_HEADERS) //此处修改网站参考内容
LOCAL_CFLAGS := -DANDROID_CHANGES -DCHAPMS=1 -DMPPE=1 -Iexternal/openssl/include
LOCAL_MODULE :=ethtool
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)

生成ethtool push到system/bin中。命令如下:
ethtool -e|–eeprom-dump DEVNAME Do a EEPROM dump
[ raw on|off ]
[ offset N ]
[ length N ]
ethtool -E|–change-eeprom DEVNAME Change bytes in device EEPROM
[ magic N ]
[ offset N ]
[ length N ]
[ value N ]

示例

本次使用ethtool实现对LAN9514的Mac地址烧写
MAC地址写号命令如下:
ethtool -E eth0 magic 0x9500 offset 0x0000 length 1 value 0xff
ethtool -E eth0 magic 0x9500 offset 0x0001 length 1 value 0x00
ethtool -E eth0 magic 0x9500 offset 0x0002 length 1 value 0x1a
ethtool -E eth0 magic 0x9500 offset 0x0003 length 1 value 0x13
ethtool -E eth0 magic 0x9500 offset 0x0004 length 1 value 0x14
ethtool -E eth0 magic 0x9500 offset 0x0005 length 1 value 0x56
ethtool -E eth0 magic 0x9500 offset 0x0006 length 1 value 0x78

0x9500是需要写入的EEPROM地址
写入后回读情况如下:
在这里插入图片描述
回读EEPROM内容正确,但需重启才会更新MAC地址,否则还是原来随机分配的地址。

批量操作

使用adb push ethtool后对输入的mac地址进行解析处理,再通过命令写号并回读。
脚本参考ethtool_mac.bat
@set mac=
@set /p mac=MAC:
@echo %mac%
@set mac1=%mac:~0,2%
@set mac2=%mac:~2,2%
@set mac3=%mac:~4,2%
@set mac4=%mac:~6,2%
@set mac5=%mac:~8,2%
@set mac6=%mac:~10,2%

@tools\adb.exe shell /data/ethtool -E eth0 magic 0x9500 offset 0x0001 length 1 value 0x%mac1%
@tools\adb.exe shell /data/ethtool -E eth0 magic 0x9500 offset 0x0002 length 1 value 0x%mac2%
@tools\adb.exe shell /data/ethtool -E eth0 magic 0x9500 offset 0x0003 length 1 value 0x%mac3%
@tools\adb.exe shell /data/ethtool -E eth0 magic 0x9500 offset 0x0004 length 1 value 0x%mac4%
@tools\adb.exe shell /data/ethtool -E eth0 magic 0x9500 offset 0x0005 length 1 value 0x%mac5%
@tools\adb.exe shell /data/ethtool -E eth0 magic 0x9500 offset 0x0006 length 1 value 0x%mac6%

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值