u-boot 可以支持多个网口吗?

Can u-boot support more than one ethernet port?

我想 ping 出多个以太网端口。 u-boot 仅支持单个以太网端口是否存在固有限制?

Can u-boot support more than one ethernet port?

是的,在最新版本的 U-Boot 中(至少可以追溯到 2012.10)。
eth_current_changed()eth_set_current()中的eth_current_changed()。 c.

Is there an inherent restriction where u-boot only supports a single ethernet port?

不,最新版本的 U-Boot 可以支持板上的多个以太网端口。

当有多个以太网接口可用时(如启动时 "Net" 设备列表所报告的,例如 "Net: macb0, gmac0, usb_ether"),环境变量 ethact用于定义选定的活动以太网接口。
使用printenv ethact命令查看当前选择。
使用 setenv ethact <port name> 更改活动以太网端口。

U-Boot 网络命令,例如 pingtftpboot,将使用由 ethact 变量。这保留了旧版本 U-Boot 的命令语法,并且无论可用端口的数量如何,语法都是一致的(例如,脚本不会更改)。

每个以太网端口都分配有自己的 MAC 地址,使用以下环境变量:

ethaddr: Ethernet MAC address for first/only ethernet interface (= eth0 in Linux).
         This variable can be set only once (usually during manufacturing of the board). U-Boot refuses to delete or overwrite this variable once it has been set.

eth1addr: Ethernet MAC address for second ethernet interface (= eth1 in Linux).

eth2addr: Ethernet MAC address for third ethernet interface (= eth2 in Linux).

显然您一次只能(轻松地)访问一个端口。
也只有一个静态 IP 地址分配,即 ipaddr 环境变量。
(我不知道用一个端口通过DHCP获取IP地址,然后更改活动端口会发生什么情况。)

U-Boot> printenv ethact
ethact=macb0
U-Boot> setenv ethact gmac0
U-Boot> ping 192.168.1.1
gmac0: PHY present at 7
gmac0: Starting autonegotiation...
gmac0: Autonegotiation complete
gmac0: link up, 1000Mbps full-duplex (lpa: 0x2800)
Using gmac0 device
host 192.168.1.1 is alive
U-Boot>

请注意,还有一个轮换方案可以在端口关闭时自动更改活动端口:

U-Boot> printenv ethact
ethact=gmac0
U-Boot> ping 192.168.1.1
gmac0: PHY present at 7
gmac0: Starting autonegotiation...
gmac0: Autonegotiation timed out (status=0x7949)
gmac0: link down (status: 0x7949)
ERROR: Need valid 'usbnet_devaddr' to be set
at drivers/usb/gadget/ether.c:2362/usb_eth_init()
macb0: PHY present at 0
macb0:0 is connected to macb0.  Reconnecting to macb0
macb0: Starting autonegotiation...
macb0: Autonegotiation timed out (status=0x7849)
macb0: link up, 100Mbps full-duplex (lpa: 0x41e1)
Using macb0 device
ping failed; host 192.168.1.1 is not alive
U-Boot> printenv ethact
ethact=macb0
U-Boot>