This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] AM3352:在 u-boot 中设置 MAC 地址不会反映在 Linux 中

Guru**** 2333780 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1510553/am3352-setting-mac-address-in-u-boot-does-not-reflect-in-linux

器件型号:AM3352

工具/软件:

我已在 u-boot 中设置了一个 MAC 地址并保存了环境、但一旦启动、Linux 中就不会反映这一点。 当我在 u-boot 中设置 serial#时、它也反映在 Linux 中。 我不确定内核为什么不使用设置的 MAC 地址。 我是否需要使用设置或配置选项来配置内核以允许此操作?

U-boot 版本:TI-uboot-2023.04

内核版本:TI-Linux-6.1

在 u-boot 中设置环境(这在下电上电后是持久的、并保存在 eMMC 的引导分区中):

U-Boot 2023.04-gc30478b7-dirty (Apr 24 2025 - 13:20:35 +0200)

CPU  : AM335X-GP rev 2.1
Model: TI AM335x BeagleBone Black
DRAM:  512 MiB
Core:  161 devices, 18 uclasses, devicetree: separate
WDT:   Started wdt@44e35000 with servicing every 1000ms (60s timeout)
NAND:  0 MiB
MMC:   OMAP SD/MMC: 0, OMAP SD/MMC: 1
Loading Environment from FAT... Unable to read "uboot.env" from mmc1:1...
<ethaddr> not set. Validating first E-fuse MAC
Net:   eth2: ethernet@4a100000, eth3: usb_ether
Hit any key to stop autoboot:  0
=> print ethaddr
ethaddr=88:0c:e0:3f:d3:0e
=> print serial#
serial#=88:0c:e0:3f:d3:0e
=> setenv ethaddr D4:84:31:9C:68:2C
=> setenv serial# 1234-1234
=> saveenv
Saving Environment to FAT... OK
=>

在下电上电后确认变量:

U-Boot SPL 2023.04-gc30478b7-dirty (Oct 08 2024 - 12:05:34 +0200)
Trying to boot from MMC2


U-Boot 2023.04-gc30478b7-dirty (Apr 24 2025 - 13:20:35 +0200)

CPU  : AM335X-GP rev 2.1
Model: TI AM335x BeagleBone Black
DRAM:  512 MiB
Core:  161 devices, 18 uclasses, devicetree: separate
WDT:   Started wdt@44e35000 with servicing every 1000ms (60s timeout)
NAND:  0 MiB
MMC:   OMAP SD/MMC: 0, OMAP SD/MMC: 1
Loading Environment from FAT... OK
Net:   eth2: ethernet@4a100000, eth3: usb_ether
Hit any key to stop autoboot:  0
=> print ethaddr
ethaddr=D4:84:31:9C:68:2C
=> print serial#
serial#=1234-1234
=>

相关启动日志:

...
[    1.803560] omap_rng 48310000.rng: Random Number Generator ver. 20
[    1.810404] random: crng init done
[    1.870255] davinci_mdio 4a101000.mdio: davinci mdio revision 1.6, bus freq 1000000
[    1.878163] davinci_mdio 4a101000.mdio: detected phy mask fffffffe
[    1.911397] davinci_mdio 4a101000.mdio: phy[0]: device 4a101000.mdio:00, driver SMSC LAN8710/LAN8720
[    1.930809] cpsw 4a100000.ethernet: No slave[1] phy_id, phy-handle, or fixed-link property
[    1.939388] cpsw 4a100000.ethernet: initialized cpsw ale version 1.4
[    1.960273] cpsw 4a100000.ethernet: ALE Table size 1024
[    1.965760] cpsw 4a100000.ethernet: cpts: overflow check period 500 (jiffies)
[    1.990289] cpsw 4a100000.ethernet: Detected MACID = 88:0c:e0:3f:d3:0e
[    2.017371] debugfs: Directory '49000000.dma' with parent 'dmaengine' already present!
[    2.040265] edma 49000000.dma: TI EDMA DMA engine driver
...

如果您希望获得任何帮助、

TJ

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    嗨,我现在尝试设置一堆 Mac 地址,以检查它是否可能从其他地方拉它,但它似乎不是这样的情况

    => print eth1addr
    eth1addr=88:0c:e0:3f:d3:10
    => print eth2addr
    eth2addr=88:0c:e0:3f:d3:0e
    => print eth3addr
    eth3addr=de:ad:be:ef:00:01
    => setenv eth1addr D4:84:31:9C:68:01
    => setenv eth2addr D4:84:31:9C:68:02
    => setenv eth3addr D4:84:31:9C:68:03
    => saveenv
    Saving Environment to FAT... OK
    =>
    

    下电上电后确认设置了该设置:

    Hit any key to stop autoboot:  0
    => print eth1addr
    eth1addr=D4:84:31:9C:68:01
    => print eth2addr
    eth2addr=D4:84:31:9C:68:02
    => print eth3addr
    eth3addr=D4:84:31:9C:68:03
    

    引导日志:

    [    1.808978] random: crng init done
    [    1.880259] davinci_mdio 4a101000.mdio: davinci mdio revision 1.6, bus freq 1000000
    [    1.888169] davinci_mdio 4a101000.mdio: detected phy mask fffffffe
    [    1.921409] davinci_mdio 4a101000.mdio: phy[0]: device 4a101000.mdio:00, driver SMSC LAN8710/LAN87          20
    [    1.940819] cpsw 4a100000.ethernet: No slave[1] phy_id, phy-handle, or fixed-link property
    [    1.949402] cpsw 4a100000.ethernet: initialized cpsw ale version 1.4
    [    1.970274] cpsw 4a100000.ethernet: ALE Table size 1024
    [    1.975761] cpsw 4a100000.ethernet: cpts: overflow check period 500 (jiffies)
    [    2.000284] cpsw 4a100000.ethernet: Detected MACID = 88:0c:e0:3f:d3:0e
    [    2.027377] debugfs: Directory '49000000.dma' with parent 'dmaengine' already present!
    [    2.050266] edma 49000000.dma: TI EDMA DMA engine driver
    

    如何确定 u-boot 是否正确地将 Mac 地址传递给内核? 或者检查内核在哪里获得检测到的 MACID?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    大家好、我遗漏了什么吗? 根据我的理解、这个选项应该起作用、我应该查看具体的内核配置选项吗?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、  

    传递给内核的 MAC 地址不是使用环境中存储的 u-boot MAC 地址。 U-boot 传递存储在器件电子保险丝中的地址。 Linux 引导序列中的 MAC 地址是 TI 地址。 您必须在 u-boot 中更改代码并使用 i2c EEPROM 等器件来存储唯一地址。 我将查看代码并指向 u-boot 正在读取代码的区域。

    此致、

    Schuyler

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Schuyler:

    感谢您的答复。

    在文件"ti-uboot/board/ti/am33x/board.c"中、我看到函数"int board_lay_init (void)"中是从电子保险丝读取 MAC 地址的位置、然后以下代码会检查 ethaddr 环境变量:

    	if (!env_get("ethaddr")) {
    		printf("<ethaddr> not set. Validating first E-fuse MAC\n");
    
    		if (is_valid_ethaddr(mac_addr))
    			eth_env_set_enetaddr("ethaddr", mac_addr);
    	}

    这在我看来、如果它没有找到 ethaddr 变量为 set、它会将 MAC 地址设置为从电子保险丝读取的地址。 如果发现 ethaddr 已置位、则不会运行此代码。 我在这里看到的不同之处在于、它调用 eth_env_set_enetaddr 来设置环境变量、而当设置 serial#时、它使用 env_set ("serial#"、board_serial);。 这是否意味着我必须运行 eth_env_set_enetaddr 来使用我自己的 MAC 地址设置变量

    此致、

    TJ

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、

    我设法解决了这个问题、这是设备树的问题。 在升级到较新的 Yocto 版本期间、由于网络正常工作、设备树的原始网络部分未修改。 我以"am335x-bone-commot.dtsi"为基础修改了器件树。 下面是我所做的更改。

    旧 DTS:

    &cpsw_emac0 {
    	phy_id = <&davinci_mdio>, <0>;
    	phy-mode = "mii";
    };
    
    &mac {
    	pinctrl-names = "default";
    	pinctrl-0 = <&mii1_pins_default>;
    	status = "okay";
    };
    
    &davinci_mdio {
    	pinctrl-names = "default";
    	pinctrl-0 = <&mdio_pins_default>;
    	status = "okay";
    };

    新 DTS:

    &cpsw_port1 {
    	phy-handle = <&ethphy0>;
    	phy-mode = "mii";
    	ti,dual-emac-pvid = <1>;
    };
    
    &cpsw_port2 {
    	status = "disabled";
    };
    
    &mac_sw {
    	pinctrl-names = "default";
    	pinctrl-0 = <&mii1_pins_default>;
    	status = "okay";
    };
    
    &davinci_mdio_sw {
    	pinctrl-names = "default";
    	pinctrl-0 = <&mdio_pins_default>;
    
    	ethphy0: ethernet-phy@0 {
    		reg = <0>;
    	};
    };

    UBoot 日志:

    U-Boot 2023.04-gc30478b7-dirty (Apr 24 2025 - 13:20:35 +0200)
    
    CPU  : AM335X-GP rev 2.1
    Model: TI AM335x BeagleBone Black
    DRAM:  512 MiB
    Core:  161 devices, 18 uclasses, devicetree: separate
    WDT:   Started wdt@44e35000 with servicing every 1000ms (60s timeout)
    NAND:  0 MiB
    MMC:   OMAP SD/MMC: 0, OMAP SD/MMC: 1
    Loading Environment from FAT... OK
    Net:
    Warning: ethernet@4a100000 MAC addresses don't match:
    Address in ROM is               88:0c:e0:3f:d3:0e
    Address in environment is       d4:84:31:9c:68:02
    eth2: ethernet@4a100000
    Warning: usb_ether MAC addresses don't match:
    Address in ROM is               de:ad:be:ef:00:01
    Address in environment is       d4:84:31:9c:68:03
    , eth3: usb_ether
    Hit any key to stop autoboot:  0
    => print ethaddr
    ethaddr=00:11:22:33:44:55
    

    我收到了一些关于 MAC 地址不同于环境和 ROM 的警告、因此必须查看它的来源(可能只是我在测试时打破常规)

    确认它已在 Linux 中设置:

    root@ipb5:~# dmesg | grep cpsw
    [    1.930560] cpsw-switch 4a100000.switch: initialized cpsw ale version 1.4
    [    1.937552] cpsw-switch 4a100000.switch: ALE Table size 1024
    [    1.960359] cpsw-switch 4a100000.switch: cpts: overflow check period 500 (jiffies)
    [    1.968160] cpsw-switch 4a100000.switch: CPTS: ref_clk_freq:250000000 calc_mult:2147483648 calc_shift:29 error:0 nsec/sec
    [    2.000270] cpsw-switch 4a100000.switch: Detected MACID = 00:11:22:33:44:55
    [    2.008591] cpsw-switch 4a100000.switch: initialized (regs 0x4a100000, pool size 256) hw_ver:0019010C 1.12 (0)
    [   11.855716] cpsw-switch 4a100000.switch: starting ndev. mode: dual_mac
    [   14.191158] cpsw-switch 4a100000.switch eth0: Link is Up - 100Mbps/Full - flow control off
    
    
    root@ipb5:~# ip addr
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host noprefixroute
           valid_lft forever preferred_lft forever
    2: sit0@NONE: <NOARP> mtu 1480 qdisc noop qlen 1000
        link/sit 0.0.0.0 brd 0.0.0.0
    3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq qlen 1000
        link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff
        inet 192.168.0.131/24 brd 192.168.0.255 scope global dynamic eth0
           valid_lft 86290sec preferred_lft 86290sec
        inet6 fe80::211:22ff:fe33:4455/64 scope link
           valid_lft forever preferred_lft forever