|
发表于 2022-8-11 11:37:08
只看该作者
板凳
好啦,我自己搞定了:
) |% C. N2 T8 v3 n ~( T5 b1、小板子上执行 dmesg | grep mac,找到大致下面信息,发现mac地址的获取是通过rk_get_eth_addr这个函数。5 L2 _) m+ m2 {
rk_get_eth_addr: rk_vendor_read eth mac address failed (-1)
: f) G; ]1 n' j" D" ?- Lrk_get_eth_addr: rk_vendor_write eth mac address failed (-1)
& o$ D: G1 {* N) U$ Vrk_get_eth_addr: mac address: cc:10:ad:eb:70:55
: D+ f' Z) B+ ~6 S2、执行grep rk_get_eth_addr -r ./ 定位rk_get_eth_addr函数在kernel/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c文件里& c/ N; s3 b* U( E; ~$ h/ d7 g2 K
3、找到这个函数,在if (ret != 6 || is_zero_ether_addr(addr)) {这段代码的后面加上这些内容:
2 u$ a# W2 ?5 W6 k, i/*modified by woodrow*/
* r0 F: s0 Q- _" E- _) I union {3 U+ a' w R. ^! r
unsigned long ul;4 {& ]% e% N% N; h4 H ]5 D
unsigned char uc[8];- C2 j7 {5 `$ i* v$ h. K
} cc;
! v& x! n2 I1 o- {5 v3 F" D- { //random_ether_addr(addr);
6 R& d' U7 ^/ T& ] // dev_err(dev, "%s: generate random eth mac address: %02x:%02x:%02x:%02x:%02x:%02x",
6 p5 m3 F! C- Q& K& U4 j8 H // __func__, addr[0], addr[1], addr[2],
3 g! d0 A1 |1 m/ M+ ?: |4 k* P/ m& ] // addr[3], addr[4], addr[5]);
2 N3 ^9 n% N0 Y7 \ unsigned long system_low = (unsigned long)system_serial_low;, w" z& A' t& d8 M+ R1 ]; m1 A
unsigned long system_high = (unsigned long)system_serial_high;
6 T% g* W- g! o. R5 v$ ]& W. i5 w dev_err(dev, "%s: rk_vendor_read eth mac address failed (%d)", __func__, ret);
4 x+ @+ J9 A1 r dev_err(dev, "%s: system_serial_low (%lu), system_serial_high (%lu).\n", __func__, system_low, system_high);
/ S8 g0 V9 E/ Y4 g1 X cc.ul = system_low;4 n, \0 s) L$ M4 G$ o% f' W, S
addr[0] = 0xcc;
7 O$ q- ^, u, Z: O5 n2 M4 k addr[1] = 0x10;
, k. m1 q; a* V) a' N+ ~4 d addr[2] = cc.uc[3];6 C# a* k) O$ t I) |$ m5 w9 W
addr[3] = cc.uc[2];
) }) i1 }5 ^$ Y addr[4] = cc.uc[1];
! o$ U9 Z3 w& ?; H8 d1 j8 E addr[5] = cc.uc[0];. B$ q6 i! }! t9 A% X- F
/*modified by woodrow*/
2 q0 V( T" C% @# v! g Z1 d这段代码的用途是,当没有在vendor_storage里读到mac地址的时候,不是随机产生一个mac地址,而是将cpu序列号作为mac地址的一部分。cpu序列号:system_serial_low和system_serial_high是2个全局变量,需要引入头文件:#include <asm/system_info.h>才能使用。 |
|