Here on a microsoft blog, we have a discussion of some of the "why". Microsoft created this file format to be used with their web based PXT (programming experience toolkit). One of the main goals was that it would allow beginning users to load code on devices that acted like mass storage devices. Another was to be 512 byte block oriented, to work nicely with existing flash memory devices.
The next link gives what seems to be the official description of the format.
The file is composed of 512 byte blocks. Each block has a 32 byte header, 476 bytes of payload, and a final 4 byte magic number. It seems to be pretty common to put only 256 bytes of actual payload into each block.Some people calculate a CRC for the entire image and append it as part of the payload in the last block, but I see no mention of this in the documents and things seem to work just fine without it.
The SDK includes a uf2 utility in tools/elf2uf2 -- it is about 400 lines of C++, but it looks like plain C to me and looks fairly straightforward.
The bootrom only wants a CRC to make it happy to load the first "sector" (256 bytes) from flash. It thinks this is the second stage boot loader and once it validates it, it jumps into it and it is responsible to load whatever else ought to be loaded.
So for simple demos, you have two choices. If they are less than 256 bytes, you can slap a checksum onto the end of that sector and the bootrom will load and run it thinking it is a second stage loader. If they are bigger than 256 bytes, you can send them via a UF2 file to ram and run them there. Of course they will vanish as soon as the device is reset or power cycled.
Code bigger than 252 bytes will require setting up a second stage boot loader if you want to put it on flash. The SDK knows all about this.
Tom's electronics pages / tom@mmto.org