|
发表于 2022-8-11 11:37:08
只看该作者
板凳
好啦,我自己搞定了:
1 T* r: Q# r: [5 g1、小板子上执行 dmesg | grep mac,找到大致下面信息,发现mac地址的获取是通过rk_get_eth_addr这个函数。; r$ r5 k9 \9 O% A/ j
rk_get_eth_addr: rk_vendor_read eth mac address failed (-1)
. r2 m `: o; f+ nrk_get_eth_addr: rk_vendor_write eth mac address failed (-1)
4 t7 Y7 E5 x' x5 j7 V* P# Drk_get_eth_addr: mac address: cc:10:ad:eb:70:55& C& c/ H, @/ `
2、执行grep rk_get_eth_addr -r ./ 定位rk_get_eth_addr函数在kernel/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c文件里7 ?$ H# H) f3 i( [% D
3、找到这个函数,在if (ret != 6 || is_zero_ether_addr(addr)) {这段代码的后面加上这些内容: I I& v6 i( E! @* x; e" C
/*modified by woodrow*/& Y5 Y# S* R8 N' G
union {9 v$ X4 p: r" n8 d' Q
unsigned long ul;
, X: X% k7 z0 F1 o* ` unsigned char uc[8];) r9 @" g8 g! t) x7 S7 m
} cc;9 f6 T% N* ~3 K* ?# V8 A
//random_ether_addr(addr);) F6 b# R# W! q7 Q% J
// dev_err(dev, "%s: generate random eth mac address: %02x:%02x:%02x:%02x:%02x:%02x",! b$ [( J6 N( q
// __func__, addr[0], addr[1], addr[2],
% J. Z9 D+ D: I6 e! d/ R // addr[3], addr[4], addr[5]);- y7 ]' b' A5 C. t! {
unsigned long system_low = (unsigned long)system_serial_low;
/ c5 a/ k2 k5 P8 z unsigned long system_high = (unsigned long)system_serial_high;
: _: A7 w3 s: D C1 c6 S- C dev_err(dev, "%s: rk_vendor_read eth mac address failed (%d)", __func__, ret);6 A0 W% f2 ?0 Y$ G2 a- x, K Y
dev_err(dev, "%s: system_serial_low (%lu), system_serial_high (%lu).\n", __func__, system_low, system_high);
3 D4 U; Z) n$ Q1 R1 ^: H cc.ul = system_low;
~/ w9 i i6 x2 u4 @8 _* p1 s addr[0] = 0xcc;6 N& o0 [6 j& \; Z6 |4 ]
addr[1] = 0x10;* E0 Y% O& ? L4 d& j
addr[2] = cc.uc[3];; Z ^+ I% S; q& e5 z. k& _
addr[3] = cc.uc[2];
5 ~& b" X g8 ?2 w0 i- e addr[4] = cc.uc[1];8 U e+ v' f( t3 U+ r3 c" o' k" o
addr[5] = cc.uc[0];
/ ^( D9 I; a, j4 N" v+ p0 u/*modified by woodrow*/8 G& S6 ]4 s2 m5 C9 |: F
这段代码的用途是,当没有在vendor_storage里读到mac地址的时候,不是随机产生一个mac地址,而是将cpu序列号作为mac地址的一部分。cpu序列号:system_serial_low和system_serial_high是2个全局变量,需要引入头文件:#include <asm/system_info.h>才能使用。 |
|