/本文档是个人整理,保留最终解释权,仅供参考,有jdm独家提供/
以2K1000为例,针对目前pmon版本,commit fb1e467f74bf25de83d9ddf00d043ae93ffd7ebf Date: Tue Apr 7 10:53:30 2020 +0800
内核版本,commit 103a9ad99285e010f4da02682b37b0c9b30c3608 Date: Thu Jun 11 12:59:26 2020 +0800
龙芯平台的mac地址一般有三种存储方式:
1.存放在i2c连接的eeprom中,
pmon下查看方式:
PMON> setmac
设置方式:
PMON> setmac syn0 "22 33 44 55 66 77"
代码所在位置:
Targets/LS2K/dev/eeprom.c
当然也可以通过eeprom的读写接口读写mac地址
读方式:
PMON> eepread 0 6
写方式:
PMON> eepwrite
Please accord to correct format, for example:
eepwrite a0 "00 11 af"
This means 0xa0 = 0x00; 0xa1 = 0x11; 0xa2 = 0xaf
PMON> eepwrite 0x00 "22 33 44 55 66 77"
2.存放在flash中的环境变量里,目前pmon存储在1M的flash中,内存存储结构为pmon+env(环境变量)+dts
pmon下查看方式:
PMON> set
FR = 1
al = (usb0,0)/boot/vmlinuz
append = "'console=ttyS0,115200 console=tty initcall_debug=1 loglevel=20'"
al1 = (wd0,0)/boot/vmlinuz
activecom = 0x00
em_enable = 0x00
ethaddr = 00:00:00:00:00:00 (syn0的mac地址)
设置方式:
PMON> set ethaddr 22:33:44:55:66:77
PMON> set
FR = 1
al = (usb0,0)/boot/vmlinuz
append = "'console=ttyS0,115200 console=tty initcall_debug=1 loglevel=20'"
al1 = (wd0,0)/boot/vmlinuz
activecom = 0x00
em_enable = 0x00
ethaddr = 22:33:44:55:66:77
目前官网代码pmon下只有一路有此环境变量
代码所在位置:
pmon/cmds/cmd_env.c
3.存放在flash中的dts中
pmon下查看方式
PMON> print_dtb ethernet0 mac-address
mac-address = [00 55 7b b5 7d f7]
设置方式:
PMON> set_dtb ethernet0 mac-address 22 33 44 55 66 77
Programming flash 8f007b44:4000 into bfcfb000
\Verifying FLASH. No Errors found.
PMON> print_dtb ethernet0 mac-address
mac-address = "22", "33", "44", "55", "66", "77"
代码所在位置:
Targets/LS2K/dev/load_dtb.c
如果采用此种处理方式,需要修改pmon代码如下:
Targets/LS2K/dev/load_dtb.c
331 if(!check_prop_ok("dma-coherent", ls2k_version()) || !check_prop_ok("pci-probe-only", pci_probe_only == 1) || !check_pci_bridge_ok() \
332 || !check_mem_args(working_fdt)) {
333 //if(!check_mac_ok() || !check_prop_ok("dma-coherent", ls2k_version()) || !check_prop_ok("pci-probe-only", pci_probe_only == 1) || !check_pci_
334 || !check_mem_args(working_fdt)) {
335 u8 buff[DTB_SIZE] = {0};
336 fdt_open_into(working_fdt, buff + 4, DTB_SIZE - 8);
337 update_prop_flag(buff + 4, "dma-coherent", ls2k_version());
338 update_prop_flag(buff + 4, "pci-probe-only", pci_probe_only == 1);
339 //update_mac(buff + 4, 0);
340 //update_mac(buff + 4, 1);
修改原因如下:
pmon的默认处理方式是,先取读取eeprom中的mac地址,然后判断是否和dts中的mac地址一样,如果不一样,就把eeprom的mac地址写入dts中,如果eeprom读写异常,就会更新默认的mac地址到dts中;
内核mac地址处理
stmmac_pltfr_probe
ret = stmmac_probe_config_dt(pdev, plat_dat, &mac);从dts里取mac地址;
...
priv = stmmac_dvr_probe(&(pdev->dev), plat_dat, addr, mac);
stmmac_check_ether_addr(priv, mac);此处设置mac地址
1772 if (of_mac) { //dts中的mac地址
1773 memcpy(priv->dev->dev_addr, of_mac, ETH_ALEN);
1774 } else if (!is_valid_ether_addr(priv->dev->dev_addr)) { //dev_addr为mac地址;
1775 priv->hw->mac->get_umac_addr((void __iomem *) //读取控制器的40,44寄存器中的mac地址,存放在dev_addr中;
1776 priv->dev->base_addr,
1777 priv->dev->dev_addr, 0);
1778 if (!is_valid_ether_addr(priv->dev->dev_addr)) //判断是否无效;
1779 eth_hw_addr_random(priv->dev); //如果无效,随机mac地址;
1780 }
1781 pr_warn("%s: device MAC address %pM\n", priv->dev->name,
1782 priv->dev->dev_addr);
相关文件:drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
linux下设置mac地址方法:
ifconfig eth0 hw ether 22:33:44:55:55:77