u-boot 可以支持多个以太网端口吗?
是的,在最近版本的 U-Boot 中(至少可以追溯到 2012.10)。
突出的代码是eth_current_changed() and eth_set_current() in 网/eth.c.
u-boot 仅支持单个以太网端口是否存在固有限制?
不可以,最新版本的 U-Boot 可以支持板上多个以太网端口。
当多个以太网接口可用时(如启动时“Net”设备列表所报告的,例如“Net: macb0, gmac0, usb_ether”),环境变量ethact用于定义选定的活动以太网接口。
使用printenv ethact
命令查看当前选择。
使用setenv ethact <port name>
更改活动以太网端口。
U-Boot网络命令,例如ping and tftpboot,将使用由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>