|
发表于 2022-8-11 11:37:08
只看该作者
板凳
好啦,我自己搞定了:0 O3 s, v0 _9 z# R
1、小板子上执行 dmesg | grep mac,找到大致下面信息,发现mac地址的获取是通过rk_get_eth_addr这个函数。3 t1 \0 z8 l& B6 P+ Y3 f
rk_get_eth_addr: rk_vendor_read eth mac address failed (-1)- [4 q8 I o" L8 }! k# }3 F
rk_get_eth_addr: rk_vendor_write eth mac address failed (-1)
, `- a6 A! V" R! P; _rk_get_eth_addr: mac address: cc:10:ad:eb:70:55
5 a7 Z8 f2 i5 ]7 T5 v8 a8 H4 {2、执行grep rk_get_eth_addr -r ./ 定位rk_get_eth_addr函数在kernel/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c文件里
8 {, o* v4 \& u# X' L3、找到这个函数,在if (ret != 6 || is_zero_ether_addr(addr)) {这段代码的后面加上这些内容:: o$ X# t+ a. k. r4 `; S& i
/*modified by woodrow*/6 u- ]2 V& z" `0 g+ D, e
union {6 W9 k h/ A6 u( S. _" M
unsigned long ul;
3 C7 q! W2 E. P1 c. u unsigned char uc[8];. \; @/ ?3 u& U; H9 S
} cc;: S I) h# t! n5 [% c6 }
//random_ether_addr(addr);
& f- J4 ], p2 q0 O, r3 F$ W // dev_err(dev, "%s: generate random eth mac address: %02x:%02x:%02x:%02x:%02x:%02x",
; |5 {) W: e% c/ v3 P" x3 c // __func__, addr[0], addr[1], addr[2],- q) D+ U+ A1 x! l
// addr[3], addr[4], addr[5]);" v5 [, x' w1 w; f/ E" {
unsigned long system_low = (unsigned long)system_serial_low;
4 f% P% ^# q1 [* K5 l9 g6 ` unsigned long system_high = (unsigned long)system_serial_high;5 p: y4 B: O/ V) `* t# S
dev_err(dev, "%s: rk_vendor_read eth mac address failed (%d)", __func__, ret);2 p' P8 n5 c4 ]5 ?, `
dev_err(dev, "%s: system_serial_low (%lu), system_serial_high (%lu).\n", __func__, system_low, system_high);
3 Q3 l3 |2 H8 j/ D1 h" x* A, e cc.ul = system_low;9 z7 p0 n8 f2 w* ]! C
addr[0] = 0xcc;" O: l: R) F% N' G+ q
addr[1] = 0x10;
8 z3 `9 R6 L$ s# {* d7 y addr[2] = cc.uc[3];
/ v8 G1 \/ f- a+ Q$ v4 G; t addr[3] = cc.uc[2];
0 g# E% n% _4 k3 p* [. _ addr[4] = cc.uc[1];
9 j& l* w7 b$ U5 e+ n @; _- Q addr[5] = cc.uc[0];
c0 g; C( e$ W5 u, l, r. L U/*modified by woodrow*/- | |3 R& x% U. I$ }/ \
这段代码的用途是,当没有在vendor_storage里读到mac地址的时候,不是随机产生一个mac地址,而是将cpu序列号作为mac地址的一部分。cpu序列号:system_serial_low和system_serial_high是2个全局变量,需要引入头文件:#include <asm/system_info.h>才能使用。 |
|