|
发表于 2022-8-11 11:37:08
只看该作者
板凳
好啦,我自己搞定了:
/ ~# ^2 W+ }7 J6 P1 w V1、小板子上执行 dmesg | grep mac,找到大致下面信息,发现mac地址的获取是通过rk_get_eth_addr这个函数。
0 ?7 l# D- d0 w* A. T5 ~' Xrk_get_eth_addr: rk_vendor_read eth mac address failed (-1)
4 ]1 h2 x5 y! @: G1 l& V& krk_get_eth_addr: rk_vendor_write eth mac address failed (-1)
0 ~. W4 J5 {% Q/ Jrk_get_eth_addr: mac address: cc:10:ad:eb:70:55# P6 ^1 k e4 `8 t
2、执行grep rk_get_eth_addr -r ./ 定位rk_get_eth_addr函数在kernel/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c文件里
3 C1 Y8 @- W. W) |0 ~+ R/ n+ Y( ~3、找到这个函数,在if (ret != 6 || is_zero_ether_addr(addr)) {这段代码的后面加上这些内容:
* b: k }5 \- i) ?! O! s X/*modified by woodrow*/6 S3 j" v4 Y! ~6 d. j
union {9 t8 k" v' K. ^! ?4 i9 r
unsigned long ul;
( f! Q" T, Q3 r7 I4 \) [) a unsigned char uc[8];
6 \" N" U" ~8 m9 E } cc;, \9 l! \2 z2 M- |; l
//random_ether_addr(addr);
, X- l" o) Y9 J+ [( y // dev_err(dev, "%s: generate random eth mac address: %02x:%02x:%02x:%02x:%02x:%02x",( C& n6 h- r/ F! P4 Y
// __func__, addr[0], addr[1], addr[2],
$ Z, f. P. F! z! e // addr[3], addr[4], addr[5]);
* l' C7 C; H' m- _ C9 { unsigned long system_low = (unsigned long)system_serial_low;
. \7 ^1 S5 e( i, R* c3 H unsigned long system_high = (unsigned long)system_serial_high;; Z/ a0 ^3 m. Y* T7 e
dev_err(dev, "%s: rk_vendor_read eth mac address failed (%d)", __func__, ret);
1 b' x& Z# O' S# }& h9 w$ D dev_err(dev, "%s: system_serial_low (%lu), system_serial_high (%lu).\n", __func__, system_low, system_high);
6 R! J% X0 p! P) P4 S6 G cc.ul = system_low;
9 _3 K8 h0 R1 S0 E6 D$ R0 i addr[0] = 0xcc;, i* {) j* g1 q+ m
addr[1] = 0x10;
0 j% [6 D; a( B7 s# J# a addr[2] = cc.uc[3];
6 o1 z) Q& @$ g" E# q5 Z addr[3] = cc.uc[2];: e4 p R7 z4 `5 |* q" p4 p0 q
addr[4] = cc.uc[1];. H9 J3 \4 r, A& S2 T" B# T
addr[5] = cc.uc[0];: B2 u$ a; q9 j% B7 o: f9 h7 ]* Q
/*modified by woodrow*/; W# S# _4 |$ n7 Z; W
这段代码的用途是,当没有在vendor_storage里读到mac地址的时候,不是随机产生一个mac地址,而是将cpu序列号作为mac地址的一部分。cpu序列号:system_serial_low和system_serial_high是2个全局变量,需要引入头文件:#include <asm/system_info.h>才能使用。 |
|