|
发表于 2022-8-11 11:37:08
好啦,我自己搞定了:
0 O9 Y3 t! V5 F. f; {0 m' N7 v! D1、小板子上执行 dmesg | grep mac,找到大致下面信息,发现mac地址的获取是通过rk_get_eth_addr这个函数。
/ s) X0 ]/ F2 grk_get_eth_addr: rk_vendor_read eth mac address failed (-1)
1 i# { t7 X% `: y1 C0 trk_get_eth_addr: rk_vendor_write eth mac address failed (-1)
% v% w/ c: w1 h( O/ Erk_get_eth_addr: mac address: cc:10:ad:eb:70:55
$ l1 f3 {3 x$ A2、执行grep rk_get_eth_addr -r ./ 定位rk_get_eth_addr函数在kernel/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c文件里
2 U& y( p6 i' P. z+ Y# J6 V3、找到这个函数,在if (ret != 6 || is_zero_ether_addr(addr)) {这段代码的后面加上这些内容:
, q4 S# p4 o' a5 ~- V; \; }/*modified by woodrow*/
* J- H1 g' d6 x% [6 a union {) A3 t4 |: H4 V) f0 a
unsigned long ul;
' M8 A( f% w# b% g unsigned char uc[8];
0 [0 G4 U5 h7 ~ } cc;
8 O4 n7 B4 I7 J0 Q1 Q, G% p% ` //random_ether_addr(addr);" G0 q3 w: Y7 _5 W
// dev_err(dev, "%s: generate random eth mac address: %02x:%02x:%02x:%02x:%02x:%02x",
0 V- A) X$ G0 w. t1 B8 x // __func__, addr[0], addr[1], addr[2],* W5 J5 Z: A' Z% Q, h
// addr[3], addr[4], addr[5]);
, u) h! M; K% F6 [7 d unsigned long system_low = (unsigned long)system_serial_low;
+ M$ n F1 L- W4 r V8 z7 a unsigned long system_high = (unsigned long)system_serial_high;0 j4 o- o/ ^1 c) f; ~
dev_err(dev, "%s: rk_vendor_read eth mac address failed (%d)", __func__, ret);
1 |7 A- d+ `, m4 B; X: z dev_err(dev, "%s: system_serial_low (%lu), system_serial_high (%lu).\n", __func__, system_low, system_high);
, b& S# `8 u% e9 F cc.ul = system_low;
& r3 s- K5 T R1 d) i' m addr[0] = 0xcc;
+ J! Q% A# i/ y- q% t3 f addr[1] = 0x10;9 Z7 Y" U4 E t3 J# v. m2 b& u+ t
addr[2] = cc.uc[3];
6 Z V2 e: I) s6 o addr[3] = cc.uc[2];4 o8 v9 D' k2 f" _3 z! T
addr[4] = cc.uc[1];
0 I' [) v/ A% u# r" g/ a addr[5] = cc.uc[0];
" q; g( Q+ \2 O- Q9 E S/*modified by woodrow*/: [; q. L4 Z; `6 F
这段代码的用途是,当没有在vendor_storage里读到mac地址的时候,不是随机产生一个mac地址,而是将cpu序列号作为mac地址的一部分。cpu序列号:system_serial_low和system_serial_high是2个全局变量,需要引入头文件:#include <asm/system_info.h>才能使用。 |
|