作者:盧浩
時間:2017.2.20
轉載請註明出處
部分用戶提出zynq-7000的linux系統下,原生的以太網mac地址,每次啓動linux系統,mac都會發生變化,這個主要是驅動裏關於mac的處理機制導致的,我們來看源代碼:
驅動文件位置:drivers/net/ethernet/cadence/macb.c
187 static void macb_get_hwaddr(struct macb *bp)
188 {
189 struct macb_platform_data *pdata;
190 u32 bottom;
191 u16 top;
192 u8 addr[6];
193 int i;
194
195 pdata = dev_get_platdata(&bp->pdev->dev);
196
197 /* Check all 4 address register for vaild address */
198 for (i = 0; i < 4; i++) {
199 bottom = macb_or_gem_readl(bp, SA1B + i * 8);
200 top = macb_or_gem_readl(bp, SA1T + i * 8);
201
202 if (pdata && pdata->rev_eth_addr) {
203 addr[5] = bottom & 0xff;
204 addr[4] = (bottom >> 8) & 0xff;
205 addr[3] = (bottom >> 16) & 0xff;
206 addr[2] = (bottom >> 24) & 0xff;
207 addr[1] = top & 0xff;
208 addr[0] = (top & 0xff00) >> 8;
209 } else {
210 addr[0] = bottom & 0xff;
211 addr[1] = (bottom >> 8) & 0xff;
212 addr[2] = (bottom >> 16) & 0xff;
213 addr[3] = (bottom >> 24) & 0xff;
214 addr[4] = top & 0xff;
215 addr[5] = (top >> 8) & 0xff;
216 }
217
218 if (is_valid_ether_addr(addr)) {
219 memcpy(bp->dev->dev_addr, addr, sizeof(addr));
220 return;
221 }
222 }
223
224 dev_info(&bp->pdev->dev, "invalid hw address, using random\n");
225 eth_hw_addr_random(bp->dev);
226 }
在沒有可用的 hw address的時候,會調用這個函數eth_hw_addr_random
隨機生成一組mac地址。
我們把這個函數註釋掉就可以了,mac地址就不會每次啓動都變化了。