MT7688 wifi 调试(二) 如何修改ra0 mac地址

本系列导航:
MT7688 wifi 调试

1. 查看ra0 mac地址

# ifconfig -a ra0
ra0       Link encap:Ethernet  HWaddr 00:00:00:00:00:00  
          inet6 addr: fe80::200:ff:fe00:0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:51894 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1585 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:13104021 (12.4 MiB)  TX bytes:83336 (81.3 KiB)
          Interrupt:6 

怎么是 00:00:00:00:00:00 ?有什么方法修改?

2. 一般修改 mac 地址的方法

通过 ifconfig 帮助信息可知 ,ifconfig ra0 hw ether xx 可以修改mac地址

ifconfig --help
BusyBox v1.23.2 (2019-04-01 17:15:57 CST) multi-call binary.

Usage: ifconfig [-a] interface [address]

Configure a network interface

        [add ADDRESS[/PREFIXLEN]]
        [del ADDRESS[/PREFIXLEN]]
        [[-]broadcast [ADDRESS]] [[-]pointopoint [ADDRESS]]
        [netmask ADDRESS] [dstaddr ADDRESS]
        [hw ether ADDRESS] [metric NN] [mtu NN]
        [[-]trailers] [[-]arp] [[-]allmulti]
        [multicast] [[-]promisc] [txqueuelen NN] [[-]dynamic]
        [up|down] ...

使用 ifconfig ra0 hw ether 12:34:56:78:99:10
实测结果:

# ifconfig ra0 hw ether 12:34:56:78:99:10 
ifconfig: SIOCSIFHWADDR: Operation not supported

说明这个方法对对mt7688 并不管用。
那怎么办呢?难道就没有办法改mac 地址了?要知道如果两个mac地址相同的设备在组网时是会有冲突的!
为了解决这个问题,有两个思路,一是网上搜索更多的资料,二是看能不能找到驱动源码(这个是闭源驱动)。

3. 网上找的方法

3.1 一点一滴分析LinkIt Smart 7688 问题汇总 - huang的专栏 - CSDN博客

https://blog.csdn.net/hnhkj/article/details/50930483
摘要:

2.1.2 dd命令:/bin/dd
读取mtd2内的数据内容,mac地址
$ dd bs=1 skip=3 count=6 if=/dev/mtd2 2>/dev/null | hexdump
参考文档:linkit-smart-7688-feed\mtk-linkit\files\etc\uci-defaults\51_linkit_config - Line30:
MAC=$(dd bs=1 skip=7 count=3 if=/dev/mtd2 2>/dev/null | hexdump -v -n 3 -e ‘3/1 “%02X”’

2.1.4 备份MTD2/factory信息
$ dd if=/dev/mtd2 of=/tmp/factory.bin

2.1.5 写factory.bin到mtd2
$ mtd -r write /tmp/factory.bin factory
注意:如果命令返回不能写入MTD2,可能是由于你的系统设定了禁止写该区域的权限。我们可以通过修改target/linux/ramips/dts/LINKIT7688.dts,注销禁止代码(read-only)。这样就可以将数据写入到MTD2区域了。

有效信息:

  • 1./dev/mtd2 用于存放 factory 信息,里面包含mac地址
  • 2.mtd -r write /tmp/factory.bin factory 可以改写 /dev/mtd2 里的内容
  • 3.需要修改 target/linux/ramips/dts/LINKIT7688.dts 使/dev/mtd2 可写

验证:

1.查看 /dev/mtd2 数据
# dd if=/dev/mtd2 of=/tmp/f.bin
# hexdump f.bin  
0000000 ffff ffff ffff ffff ffff ffff ffff ffff
*
0010000

居然是全FF !!。也难怪,因为之前从没写过该分区。

2.如何确定 ra0 mac地址存储的位置?

由于只知道ra0 mac地址 从mtd2里读取,而不知道具体是哪个位置,为了确定ra0 mac 在mtd2 中的位置
我使用下面的方法生成了一个f.bin文件,

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main()
{
        int fd = open("./f.bin",O_RDWR|O_CREAT);

        int i = 0;
        int j = 0;

        for(i=0;i< 0x100;i++)
        {
                for(j=0;j< 0x100;j+=2)
                {
                        unsigned char data1 = i;//i;
                        unsigned char data2 = j;//j;

                        write(fd,&data1,1);
                        write(fd,&data2,1);
                }
        }

        close(fd);

        return 0;
}

生成的 bin 文件内容如下:
f.bin
假如 ra0 mac 为00:92:00:94:00:96 则说明,位置是mtd2 的 0x92 。

3.验证

rm /lib/firmware/mt7628.eeprom
mtd -r write /tmp/f.bin factory
重启后 查看mac

# ifconfig -a ra0
ra0       Link encap:Ethernet  HWaddr 00:00:00:00:00:00  
          inet6 addr: fe80::200:ff:fe00:0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:51894 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1585 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:13104021 (12.4 MiB)  TX bytes:83336 (81.3 KiB)
          Interrupt:6 

!!! 仍然是 00:00:00:00:00:00
很遗憾!此方法似乎不起作用?

继续找方法。。。

3.2 通过 iwpriv 指令修改工厂参数 - mcusun2000的博客 - CSDN博客

https://blog.csdn.net/mcusun2000/article/details/50953582
摘要:

iwpriv ra0 e2p

从手册可以看出,ra0 的 mac 是读取 0x0004,0x0006 和 0x0008 三个寄存器。
若果想把 Mac 地址修改为 64:51:7e:80:88:99
输入:
root@OpenWrt:/# iwpriv ra0 e2p 08=9988 (高字节09保存99,低字节08保存88)

步骤四: 删除 wireless 文件,重启网络或者重启 wrtnode2r 板子
root@OpenWrt:/# rm /etc/config/wireless
root@OpenWrt:/# etc/init.d/network restart 重启网络

有效信息:

  • 1.iwpriv ra0 e2p 可查看eeprom 数据
  • 2.ra0 的 mac 是读取 0x0004,0x0006 和 0x0008
  • 3.iwpriv ra0 e2p 08=9988 可修改mac

验证:

1.iwpriv ra0 e2p
~# iwpriv ra0 e2p
ra0       e2p:
[0x0000]:7628  [0x0002]:0001  [0x0004]:0000  [0x0006]:0000  
[0x0008]:0000  [0x000A]:0000  [0x000C]:0000  [0x000E]:0000  
[0x0010]:FFFF  [0x0012]:FFFF  [0x0014]:FFFF  [0x0016]:FFFF  
[0x0018]:FFFF  [0x001A]:FFFF  [0x001C]:FFFF  [0x001E]:FFFF  
[0x0020]:0000  [0x0022]:0000  [0x0024]:0020  [0x0026]:0000  
[0x0028]:0000  [0x002A]:0000  [0x002C]:0000  [0x002E]:0000  
[0x0030]:0000  [0x0032]:0000  [0x0034]:3422  [0x0036]:2000  
[0x0038]:FFFF  [0x003A]:0100  [0x003C]:0000  [0x003E]:0000 
...

0x0004,0x0006 和 0x0008 确实是全00 ,怪不得ra0 mac是全00了。

2.修改e2p 0x0004,0x0006 和 0x0008

iwpriv ra0 e2p 4=1234
iwpriv ra0 e2p 6=5678
iwpriv ra0 e2p 8=9010

~# iwpriv ra0 e2p 4=1234
ra0       e2p:
[0x04]:1234  
~# iwpriv ra0 e2p 6=5678
ra0       e2p:
iwpr[0x06]:5678  
~# iwpriv ra0 e2p 8=9010
ra0       e2p:
[0x08]:9010  
~# iwpriv ra0 e2p 4
ra0       e2p:
[0x0004]:0x1234  
~# iwpriv ra0 e2p 6
ra0       e2p:
[0x0006]:0x5678  
~# iwpriv ra0 e2p 9
ra0       e2p:
[0x0009]:0x0090  
~# 
3.重启网络

etc/init.d/network restart

结果:

~# ifconfig -a ra0
ra0       Link encap:Ethernet  HWaddr 00:00:00:00:00:00  
          inet6 addr: fe80::200:ff:fe00:0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:564285 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16157 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:138761440 (132.3 MiB)  TX bytes:865783 (845.4 KiB)
          Interrupt:6 

!!! 结果还是 00:00:00:00:00:00
很遗憾!此方法不起作用!
继续找方法。。。

3.3 MAC address nulled · Issue #41 · Nossiac/mtk-openwrt-feeds

https://github.com/Nossiac/mtk-openwrt-feeds/issues/41

the correct mt7628 rf parameter should be like this:
ziqiang@ziqiang:~/Router/mpkg/drivers/tm7628/files/lib/firmware$ hexdump mt7628.eeprom.bin
0000000 7628 0200 0c00 e143 2876 0000 0000 0000
0000010 ffff ffff ffff ffff ffff ffff ffff ffff
0000020 0000 0000 0020 0000 0c00 e143 2976 0c00
0000030 e143 2a76 3422 2000 ffff 0100 0000 0000
0000040 0000 0022 0000 0000 0030 0000 0000 0000
0000050 0082 9400 b040 cac0 0023 0000 ca40 0023
0000060 0000 0000 0000 0000 0000 0000 0000 0000

in order to dump the correct rf parameter, you must know the factory mtd block, and shold have the correct partion for mtd block. maybe isn’t not easy.

you can download one from https://github.com/dcboy/mt7628-p4rev-120395/blob/master/src/eeprom/MT7628_EEPROM_20140317.bin, and rename it to /lib/firmware/mt7628.eeprom.bin. be careful, the mac in this file is null, you can edit the mac feild to what you want.

有效信息:

验证:
7628.eeprom.bin

mtd write /tmp/MT7628_EEPROM_20140317.bin factory
rm /lib/firmware/mt7628.eeprom
reboot

重启后查看mac

ra0       Link encap:Ethernet  HWaddr 12:34:56:78:90:10  
          inet6 addr: fe80::1034:56ff:fe78:9010/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:561 errors:0 dropped:0 overruns:0 frame:0
          TX packets:30 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:135666 (132.4 KiB)  TX bytes:1148 (1.1 KiB)
          Interrupt:6 

终于生效了!!

此时再查看 iwpriv ra0 e2p

~# iwpriv ra0 e2p
ra0       e2p:
[0x0000]:7628  [0x0002]:0001  [0x0004]:3412  [0x0006]:7856  
[0x0008]:1090  [0x000A]:0000  [0x000C]:0000  [0x000E]:0000  
[0x0010]:FFFF  [0x0012]:FFFF  [0x0014]:FFFF  [0x0016]:FFFF  
[0x0018]:FFFF  [0x001A]:FFFF  [0x001C]:FFFF  [0x001E]:FFFF  
[0x0020]:0000  [0x0022]:0000  [0x0024]:0020  [0x0026]:0000  
[0x0028]:0000  [0x002A]:0000  [0x002C]:0000  [0x002E]:0000  
[0x0030]:0000  [0x0032]:0000  [0x0034]:3422  [0x0036]:2000  
[0x0038]:FFFF  [0x003A]:0100  [0x003C]:0000  [0x003E]:0000  
[0x0040]:0000  [0x0042]:0022  [0x0044]:0000  [0x0046]:0000  
[0x0048]:0030  [0x004A]:0000  [0x004C]:0000  [0x004E]:0000  
[0x0050]:0081  [0x0052]:9400  [0x0054]:B040  [0x0056]:C640  

发现e2p 的内容也跟着改过来了。

总结梳理:

修改 mt7628/88 的ra0 mac 地址的方法

1.修改target/linux/ramips/dts/LINKIT7688.dts 将factory分区属性改为可写(去掉read-only)
2. 下载一个别人备份的eeprom.bin https://github.com/dcboy/mt7628-p4rev-120395/blob/master/src/eeprom/MT7628_EEPROM_20140317.bin
3. 修改MT7628_EEPROM_20140317.bin 的 4 到 9字节,改成想要的mac地址
4. mtd write /tmp/MT7628_EEPROM_20140317.bin factory 将bin写入factory 分区
5. rm /lib/firmware/mt7628.eeprom 删掉缓存文件
6. reboot

疑难杂症

1.修改MAC 后,apcli0 无法连上wifi,无法获取ip ?

ifconfig -a
apcli0    Link encap:Ethernet  HWaddr 76:28:43:01:10:00  
          inet6 addr: fe80::7428:43ff:fe01:1000/64 Scope:Link
          UP BROADCAST RUNNING 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)

问题分析:可确定一点是跟MAC 地址有关,因为没改之前是好好的。
查了相关资料,说 MAC 必须是4的整数倍。
我把ra0 地址改为 74:XX:XX:XX:XX:XX 后,连接正常。

了解一下mac 地址格式
MAC地址格式详解-1111-51CTO博客
https://blog.51cto.com/9723340/1759570

不明白一点是为什么我ra0 mac 设置成12:34:56:78:90:00 时也是好的?
0x12 也不是4的整数倍啊,可为什么可以连接正常呢?这说明4的整数倍不是充要条件吧?
那么充要条件又是什么呢?等有空回头再研究一下。

发布了63 篇原创文章 · 获赞 20 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/agave7/article/details/88979146