mac地址作为一个路由器的基础信息,需要确保工厂写入唯一的mac地址到路由器指定位置,网卡从指定位置读取mac进行使用。
openwrt的做法是专门开辟了一个factory分区,将mac地址写在该分区,后面以太网eth或者无线wireless的驱动,都从factory分区读取mac地址,进行对应的转换操作。
1、有线网卡eth读取mac地址
代码位于.\drivers\net\ethernet\mediatek\mtk_eth_soc.c
,如下:
可以看到通过of_get_ethdev_address
函数读取dts中“mediatek,eth-mac”节点的mac地址。
static int mtk_probe(struct platform_device *pdev)
{
...
for_each_child_of_node(pdev->dev.of_node, mac_np) {
if (!of_device_is_compatible(mac_np,
"mediatek,eth-mac"))
continue;
if (!of_device_is_available(mac_np))
continue;
err = mtk_add_mac(eth, mac_np);
if (err) {
of_node_put(mac_np);
goto err_deinit_hw;
}
}
...
}
static int mtk_