waldheinz/fat32-lib

Image File Does Not Work When Deploying to Pi Zero

Closed this issue · 1 comments

I used the ImageBuilder class to build a simple 4 file Raspberry Pi boot image (containing a custom serial boot loader...not a linux OS). I use dd to transfer the image to an SD card. When I mount the card on my Mac, I see the files, and when I md5 all the files on the card, they match with the source directory. However, when I try to boot the Pi, it will not boot. However, if I re-mount the card on my Mac, and then copy the original files over the files deployed with the image (via the Finder), the Pi will then boot.

I would have thought that not having a partition table (via the super floppy format) might be a problem with the Pi, but simply copying files should not alter the partition table.

I see this really nice lib has not been updated in a while, but I would appreciate some guidance on what I might try to diagnose.

I determined that the first and second stage boot loaders within the Raspberry Pi firmware do not know how to read the long file names emitted by this library. LFNs are written for these files (even though they are all 8.3 or shorter) because the files are lowercase. If I add the files to the image with uppercase names, then the Pi will boot fine.

It also works if I copy the files over the files within the image (from my Mac) because the Mac FAT driver honors the quirk of setting bit 3 and 4 if the file name or file type (respectively) are lower case, on directory record offset byte 0x0C. I verified this by looking at the volume in a binary editor.

Perhaps Pi firmware does not support LFNs, or there is a bug in this lib. My Mac reads the resulting volume fine, however. There was a recent change to this lib made where I can see LFNs were avoided if a file was 8.3 and all uppercase. This lib could be further modified to support this quirk. If I get some time, I can fork and make an attempt.