Skip to content

Uf2File, Reader, Writer - #4

Merged
liamkinne merged 22 commits into
umi-eng:mainfrom
mestrode:writer
Jul 5, 2026
Merged

Uf2File, Reader, Writer#4
liamkinne merged 22 commits into
umi-eng:mainfrom
mestrode:writer

Conversation

@mestrode

@mestrode mestrode commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

here is my Uf2File, Reader and Writer implementation

Unfortunately the writer feature does require std due to:

  • File I/O operations - std::fs::write(), std::fs::read() for file-based convenience methods
  • I/O traits - std::io::Write, std::io::Read for stream-based operations
  • String manipulation - ToString trait for converting numbers to strings (used in extensions)
  • MD5 hashing - The md5 crate dependency requires std for checksum calculations
  • Path handling - std::path::Path for file path operations
  • Error handling - std::error::Error trait implementations

That’s probably too much for a workaround. However, Block, Uf2File and Reader do not depend on std.

I have added some synthetic UF2 test files. The reader test, however, only reads the file – it does not check all data fields.

The UF2 specification could be clearer. Some details are also ambiguous. This implementation therefore does not cover the entire specific

@liamkinne liamkinne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see review comments. Once those are addressed I will probably do a pass over everything to make sure all of the APIs are something I'm happy to commit to before cutting a new release.

Comment thread src/block.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/uf2file.rs Outdated
Comment thread src/file.rs
Comment thread src/writer.rs
Comment thread src/file.rs
mestrode added 8 commits July 4, 2026 20:55
- Change BlockError, WriterError, and ReaderError to implement
  core::error::Error instead of std::error::Error
- Remove #[cfg(feature = "std")] gates from error implementations
- Keep std-dependent I/O methods (to_writer, to_file, add_binary) gated
- Gate writer tests with #[cfg(all(test, feature = "std"))]
This makes the error types available in no_std environments while maintaining std-dependent functionality behind feature gates.
this is the last element for block to fulfill Uf2 spec
@mestrode

mestrode commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

last commit does cover invalid Block Numbers (>= TotalBlockNumbers)

Beyond that, there are additional requirements in the spec, I like to skip:

  • File Container Support
  • NotMainFlash Flag is supported, but must be set manually
  • Extensions defined but has no API
    • SHA-2 Checksum
    • Device Type Identifier
    • Description Extension Tag

@mestrode
mestrode requested a review from liamkinne July 5, 2026 11:47
@liamkinne
liamkinne merged commit 1d3174b into umi-eng:main Jul 5, 2026
3 checks passed
@mestrode
mestrode deleted the writer branch July 10, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants