-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[components][net][lwip][port] 1.修复eth驱动层初始化失败导致lwip初始化不完整; #10810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -485,24 +485,11 @@ static err_t eth_netif_device_init(struct netif *netif) | |||||||||||||||||||||||||||||||||||||||||||||
| ethif = (struct eth_device*)netif->state; | ||||||||||||||||||||||||||||||||||||||||||||||
| if (ethif != RT_NULL) | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| rt_device_t device; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #ifdef RT_USING_NETDEV | ||||||||||||||||||||||||||||||||||||||||||||||
| /* network interface device register */ | ||||||||||||||||||||||||||||||||||||||||||||||
| netdev_add(netif); | ||||||||||||||||||||||||||||||||||||||||||||||
| #endif /* RT_USING_NETDEV */ | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /* get device object */ | ||||||||||||||||||||||||||||||||||||||||||||||
| device = (rt_device_t) ethif; | ||||||||||||||||||||||||||||||||||||||||||||||
| if (rt_device_init(device) != RT_EOK) | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| return ERR_IF; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK) | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| return ERR_IF; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /* copy device flags to netif flags */ | ||||||||||||||||||||||||||||||||||||||||||||||
| netif->flags = (ethif->flags & 0xff); | ||||||||||||||||||||||||||||||||||||||||||||||
| netif->mtu = ETHERNET_MTU; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -545,6 +532,19 @@ static err_t eth_netif_device_init(struct netif *netif) | |||||||||||||||||||||||||||||||||||||||||||||
| dhcp_start(netif); | ||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| rt_device_t device; | ||||||||||||||||||||||||||||||||||||||||||||||
| /* get device object */ | ||||||||||||||||||||||||||||||||||||||||||||||
| device = (rt_device_t) ethif; | ||||||||||||||||||||||||||||||||||||||||||||||
| if (rt_device_init(device) != RT_EOK) | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| return ERR_IF; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK) | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+539
to
+543
|
||||||||||||||||||||||||||||||||||||||||||||||
| { | |
| return ERR_IF; | |
| } | |
| if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK) | |
| { | |
| { | |
| /* Clean up netif if device init fails */ | |
| #if LWIP_DHCP | |
| dhcp_stop(netif); | |
| #endif | |
| netif_set_down(netif); | |
| LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_init: device init failed, cleaned up netif\n")); | |
| return ERR_IF; | |
| } | |
| if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK) | |
| { | |
| /* Clean up netif if device open fails */ | |
| #if LWIP_DHCP | |
| dhcp_stop(netif); | |
| #endif | |
| netif_set_down(netif); | |
| LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_init: device open failed, cleaned up netif\n")); |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这样的目的是为网络协议栈和硬件分开初始化,当硬件的link状态改变后保证lwip功能完整;
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Using |= operator after device initialization may incorrectly combine flags. If rt_device_init or rt_device_open modifies ethif->flags, this could set unintended flag bits. The original assignment at line 494 (netif->flags = (ethif->flags & 0xff)) should be removed to avoid setting flags twice with different operators.
错误:在设备初始化后使用|=运算符可能会错误地组合标志。如果rt_device_init或rt_device_open修改了ethif->flags,这可能会设置意外的标志位。应该删除第494行的原始赋值(netif->flags = (ethif->flags & 0xff))以避免使用不同运算符两次设置标志。
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
状态已改变了,需要再次同步一次
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Same issue as Comment 1 - returning ERR_IF after netif_set_up leaves the network interface in an inconsistent state. This contradicts the PR's stated goal of allowing lwIP to function even when ETH driver initialization fails.
错误:与评论1相同的问题 - 在netif_set_up之后返回ERR_IF会使网络接口处于不一致状态。这与PR声明的"ETH驱动层初始化失败不影响lwip的功能"目标相矛盾。
| { | |
| return ERR_IF; | |
| } | |
| if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK) | |
| { | |
| { | |
| netif_set_down(netif); | |
| return ERR_IF; | |
| } | |
| if (rt_device_open(device, RT_DEVICE_FLAG_RDWR) != RT_EOK) | |
| { | |
| netif_set_down(netif); |
Copilot uses AI. Check for mistakes.
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Same issue as Comment 3 - duplicate flag assignment with different operators. Line 682 sets netif->flags = (ethif->flags & 0xff) and line 730 uses |=, which may produce incorrect flag combinations.
错误:与评论3相同的问题 - 使用不同运算符重复赋值标志。第682行设置netif->flags = (ethif->flags & 0xff),第730行使用|=,这可能产生错误的标志组合。
| netif->flags |= (ethif->flags & 0xff); | |
| /* netif->flags |= (ethif->flags & 0xff); -- removed duplicate assignment */ |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
佬,这部分可以延续你的思路,稍微更改一下,我没用过gd32,提供一个参考。
考虑到可能有其他 BSP 代码依赖 init 后的 flags 来配置 lwIP 的参数,我们尽量不要去改 lwIP port 层的逻辑。
在 GD32 上,可以模拟实现类似 STM32 ETH 驱动的效果,
rt_device_init阶段不直接调用enet_init,而是只做 PHY、MAC 等不会触发链路状态检查的基础配置。在 PHY 链路检测函数里,再判断
enet_init是否已经执行过,如果还没有,就在链路 up 的时候补一次初始化。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
几天前review的,忘记提交了