uefi: serial: add read_exact() and write_exact() + fix core::fmt::Write for Serial#1875
Merged
nicholasbishop merged 3 commits intomainfrom Mar 21, 2026
Merged
Conversation
fae721f to
da6a8ed
Compare
11 tasks
da6a8ed to
84787aa
Compare
465e4d3 to
df9a189
Compare
Member
nicholasbishop
left a comment
There was a problem hiding this comment.
Initial comments in. For ease of review, I'd like to move the read/write changes to a separate PR, those seem independent of the new methods being added.
df9a189 to
c12f302
Compare
2 tasks
2b1e723 to
655f2f7
Compare
655f2f7 to
625238c
Compare
Member
Author
|
thanks for your helpful remarks and ideas! The new state is much better: no infinite loops, cleaner interfaces. I tested this on real hardware - multiple times. Hope we are good to go now - looking forward to your feedback! |
Knowing how long a single byte takes to transmit at the current baud rate lets retry logic stall for just the right amount of time - long enough for the FIFO to drain or fill, short enough to stay responsive. Required groundwork for the exact-read/write helpers that follow.
625238c to
65c57d7
Compare
Callers that simply want to send or receive a fixed number of bytes should not have to implement their own retry loop. These helpers absorb the TIMEOUT-and-retry pattern internally, keeping call sites clean. Endless-loop protection ensures a hardware fault cannot stall the system forever. Validated on real hardware with reading/writing 16 KiB chunks.
65c57d7 to
27248a8
Compare
On real hardware, Status::TIMEOUT is common even during normal operation, not just on failure. The previous implementation treated it as a hard error, silently dropping bytes. Retrying until all bytes are sent makes the fmt::Write impl reliable and match the expectations of its callers. This uses an the same endless loop protection mentioned earlier.
27248a8 to
62f4691
Compare
nicholasbishop
approved these changes
Mar 21, 2026
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.
Serial Protocol Improvements
Serial::read_exact()andSerial::write_exact()methods, which block until the entire buffer is read or written, automatically retrying on timeouts and stalling based on baud rate to avoid busy-waiting. These methods help prevent partial I/O and improve reliability when communicating over serial devices.fmt::Writeimplementation forSerialto usewrite_exact()Timing and Reliability Enhancements
duration_per_byte_estimateandduration_fifo_estimate) to conservatively estimate the time needed for serial operations, taking into account baud rate, data bits, parity, and stop bits. These are used to determine appropriate stalling durations between retries.Testing and Documentation