|
发表于 2022-8-11 11:37:08
只看该作者
板凳
好啦,我自己搞定了:
1 E' k3 g% q |( Q0 ^- [% ~1、小板子上执行 dmesg | grep mac,找到大致下面信息,发现mac地址的获取是通过rk_get_eth_addr这个函数。
+ W9 J& \3 c! {9 K# k* }rk_get_eth_addr: rk_vendor_read eth mac address failed (-1)
) }8 E- |/ K2 {7 y5 ]rk_get_eth_addr: rk_vendor_write eth mac address failed (-1)
' d3 S. q- R7 m' Q9 crk_get_eth_addr: mac address: cc:10:ad:eb:70:55; E# i2 b+ S: t4 H; m8 J- C9 a
2、执行grep rk_get_eth_addr -r ./ 定位rk_get_eth_addr函数在kernel/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c文件里. X4 r+ [7 ~' H5 f
3、找到这个函数,在if (ret != 6 || is_zero_ether_addr(addr)) {这段代码的后面加上这些内容:! j8 f# ^4 l0 d7 ^5 ~ u
/*modified by woodrow*/
& a6 @- X% O8 T5 a: W2 [ union {" `+ O" W% E) z* H' T
unsigned long ul;
8 u+ ~" O( l. |# ~ unsigned char uc[8];
% {. s$ w2 X7 a" p* w' L } cc;# B; p) k! H4 D
//random_ether_addr(addr);3 N' {' G! v) o: J
// dev_err(dev, "%s: generate random eth mac address: %02x:%02x:%02x:%02x:%02x:%02x",/ J& {% X( c; t4 U7 P- x3 U2 L
// __func__, addr[0], addr[1], addr[2],
6 l+ e- d) x% h7 S4 u# l( D4 m! H // addr[3], addr[4], addr[5]);/ S' q, Y( H# Q- I8 p
unsigned long system_low = (unsigned long)system_serial_low;
( h! \2 [ P- c. N, z unsigned long system_high = (unsigned long)system_serial_high;
8 A. v& q z! i" e# x/ r, `9 A dev_err(dev, "%s: rk_vendor_read eth mac address failed (%d)", __func__, ret);1 ]: r2 ^. F+ X2 @, F. z* x8 b
dev_err(dev, "%s: system_serial_low (%lu), system_serial_high (%lu).\n", __func__, system_low, system_high);9 v: i/ \0 ~, g$ e5 U
cc.ul = system_low;
! F& @* M/ m+ t1 D% ~ addr[0] = 0xcc;
. J K' u- n5 J' H. a( m1 F addr[1] = 0x10;
% R7 ? u; @$ E! }" I4 y addr[2] = cc.uc[3];
) U8 \$ O, _) r: P( s& S( E* w$ a addr[3] = cc.uc[2];+ `, M8 f" o' v5 J1 _# a3 H7 W p
addr[4] = cc.uc[1];
1 T9 p1 B: J" E, m addr[5] = cc.uc[0];5 g# U$ m& ?& D: h) J
/*modified by woodrow*/
" H6 y* D2 I: S# F1 T4 R2 o这段代码的用途是,当没有在vendor_storage里读到mac地址的时候,不是随机产生一个mac地址,而是将cpu序列号作为mac地址的一部分。cpu序列号:system_serial_low和system_serial_high是2个全局变量,需要引入头文件:#include <asm/system_info.h>才能使用。 |
|