|
发表于 2022-8-11 11:37:08
只看该作者
板凳
好啦,我自己搞定了:
6 S+ _9 S& C$ C6 I* O2 X1、小板子上执行 dmesg | grep mac,找到大致下面信息,发现mac地址的获取是通过rk_get_eth_addr这个函数。
8 f5 n) r% C5 P; _$ krk_get_eth_addr: rk_vendor_read eth mac address failed (-1)
, C6 E8 } v* Yrk_get_eth_addr: rk_vendor_write eth mac address failed (-1)
! v/ w0 m0 t$ E0 Q( i/ crk_get_eth_addr: mac address: cc:10:ad:eb:70:55
4 M" Q! D/ c. _( K& C4 Q# f2、执行grep rk_get_eth_addr -r ./ 定位rk_get_eth_addr函数在kernel/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c文件里' `6 a( M* X/ U& P, R% v9 S
3、找到这个函数,在if (ret != 6 || is_zero_ether_addr(addr)) {这段代码的后面加上这些内容:
. k8 H" Y3 l- a7 k; i/*modified by woodrow*/: E, u& ?# k' r& U: ?7 z0 n
union {
) T( B" p& p% z: T5 l: q: [ unsigned long ul;
6 X t! o/ e& Q unsigned char uc[8];
) L4 w$ i' B) T" N- \ } cc;% _! Q6 E9 H7 Z
//random_ether_addr(addr);
: _ ]. o9 ?2 ~2 b' o // dev_err(dev, "%s: generate random eth mac address: %02x:%02x:%02x:%02x:%02x:%02x",: c* Y6 [5 f$ @ s# D
// __func__, addr[0], addr[1], addr[2],
* U D0 W% @: i1 _+ _ // addr[3], addr[4], addr[5]);& A. v2 R5 |$ y" U) y" P1 R
unsigned long system_low = (unsigned long)system_serial_low;) y1 G# Y2 E- P
unsigned long system_high = (unsigned long)system_serial_high;
# F7 ]5 v, j9 C+ D7 @8 N6 E) N dev_err(dev, "%s: rk_vendor_read eth mac address failed (%d)", __func__, ret);
* D1 ?7 q X& l% R dev_err(dev, "%s: system_serial_low (%lu), system_serial_high (%lu).\n", __func__, system_low, system_high);
, P3 r) f- q0 E2 P' |: C: `6 k8 O cc.ul = system_low;4 E( ?% L0 X( v' [+ p1 q( F
addr[0] = 0xcc;
. u0 u! Y0 d1 L( G( W addr[1] = 0x10;) e' K& M- ?6 k( n1 x; z; i
addr[2] = cc.uc[3];
- G! f/ p7 o1 `2 W- a addr[3] = cc.uc[2];
) ~0 r3 n' S& a: C \0 K1 X) C addr[4] = cc.uc[1];, u. Z3 x3 g. U, L/ q3 k
addr[5] = cc.uc[0];' D' n& t9 h& K- y" z/ O! s. b
/*modified by woodrow*/% P1 S5 _4 A+ _- D5 `# }; [
这段代码的用途是,当没有在vendor_storage里读到mac地址的时候,不是随机产生一个mac地址,而是将cpu序列号作为mac地址的一部分。cpu序列号:system_serial_low和system_serial_high是2个全局变量,需要引入头文件:#include <asm/system_info.h>才能使用。 |
|