fix(uboot): stabilize serial transfers#145
Merged
Merged
Conversation
There was a problem hiding this comment.
代码审查总结
整体改动方向正确,针对性地解决了 ROC-RK3568-PC 串口传输不稳定的一系列问题。以下是详细审查意见。
✅ 优点
- 串口打开后清空输入缓冲 (
clear_serial_input_after_open):引入SerialOpenCleanuptrait 提高了可测试性,且清空失败仅 warn 不中断 session,设计合理。 - power-on 期间暂缓客户端写入:在
run_serial_ws_inner中将ws_receiver.next()从power_on_task.is_some()的 select 分支移除,使客户端消息在 power-on 期间自然缓冲在 websocket 流中,完成后自动消费。逻辑正确。 - Session TTL 从 2s 提升到 10s:对于
loady长传输场景合理,session heartbeat 机制保证活跃 session 不会过早过期。 - YMODEM 重试预算按包重置:将
self.retries改为局部变量retries,ACK 成功后自动重置,避免前一个包的 NAK 消耗后续包的容错能力。修复正确。 loady整次传输重试:失败后发送 Ctrl-C 恢复 U-Boot shell、重新clear_shell、再执行loady,设计清晰。最多 3 次尝试,LOADY_RETRY_DELAY300ms 合理。- 测试覆盖良好:新增 ymodem 单元测试、loady 模拟测试、server 集成测试,测试场景全面。
❌ 需要修复
Clippy 错误 (-D warnings 下编译失败):
uboot-shell/src/lib.rs 第 488、492 行:
self.queue_read([b'C']); // clippy: byte-char-slices应改为:
self.queue_read(*b"C");运行 cargo clippy -p uboot-shell --all-targets -- -D warnings 可复现。
💡 建议(非阻塞)
loady最终失败时的错误消息中last_err.map(...).unwrap_or_else(|| "unknown error".to_string())理论上last_err不可能为None(循环至少执行一次且失败路径一定设置last_err),可考虑直接.unwrap()或使用更明确的类型保证。- 集成测试
websocket_buffers_client_serial_input_until_power_on_finishes使用 shell 脚本作 power-on 门控,设计巧妙,但仅限 unix 平台(已有#![cfg(unix)]保护)。
Powered by mimo-v2.5-pro
This was referenced Jun 25, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
近期 ROC-RK3568-PC 的 dev 板测在进入内核前不稳定,日志里主要表现为:
loady/YMODEM 传输偶发 NAK,当前重试预算会被前面包消耗,后续包容错下降。修改
ostool-server打开串口后先清理 input buffer,避免新会话继承旧串口残留。uboot-shell::loady每次 attempt 前先 drain 当前串口输入,再执行loady。loady增加整次传输重试:一次 YMODEM 传输失败后用 Ctrl-C 恢复 U-Boot shell,重新打开文件并重新执行loady。loady整次失败后恢复并重传、server power-on 前暂缓客户端串口写入。验证
cargo fmt --allcargo test -p uboot-shellcargo clippy -p uboot-shell --all-targets -- -D warningscargo test -p ostool-servercargo clippy -p ostool-server --all-targets -- -D warningscargo test -p ostoolcargo clippy -p ostool --all-targets -- -D warningsostool/uboot-shell客户端。RUST_LOG=info,ostool=debug,uboot_shell=debug cargo xtask axvisor test board --board roc-rk3568-pc-linux --server 10.3.10.194 --port 2999loady完成 FIT image 传输,U-Boot 输出2(SOH)/2423(STX)/0(CAN) packets, 1 retries,随后bootm启动 Linux guest,最终匹配login:,测试输出ok: smoke/roc-rk3568-pc-linux/all axvisor board test groups passed。备注
ostool-server.service仍为 active,session 为空,ROC-RK3568-PC 可用。