Hacker News new | ask | show | jobs
by devanl 1282 days ago
In case you haven't seen the UF2 file format, it's specifically designed to be robust w.r.t ensuring that the content makes it to the target intact despite common OS quirks.

https://github.com/microsoft/uf2

  - Data is divided into 512 byte blocks, which lines up with the mass storage transfer size.
  - Each block has an identifying magic sequence, a payload address, and size, which can be used to identify the destination.
    - This allows the emulated storage to ignore metadata blocks and to handle out-of-order and repeated blocks.
1 comments

The UF2 format is a hack that can be made to generally work (e.g. it relies on things like per-block beginning and ending magic numbers to identify blocks that should be written to flash, which means isn't dependent on seeing FAT table writes in a particular order).

UF2 is just the file format, though. The mechanism for reading/writing UF2 files is via the emulated USB mass storage, which is fundamentally broken.

The USB storage device responds to SCSI write commands with a success status, but actually throws away data, such that a successive read does not return the previously written blocks.

To an OS or filesystem, that's just a failing drive. You might get lucky and things might work.