Skip to content

Commit e025141

Browse files
committed
Add some additional comments.
1 parent 12bb62e commit e025141

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/usb/uf2/ghostfat.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,30 +177,30 @@ void read_block(uint32_t block_no, uint8_t *data) {
177177
memset(data, 0, 512);
178178
uint32_t sectionIdx = block_no;
179179

180-
if (block_no == 0) {
180+
if (block_no == 0) { // Requested boot block
181181
memcpy(data, &BootBlock, sizeof(BootBlock));
182182
data[510] = 0x55;
183183
data[511] = 0xaa;
184184
// logval("data[0]", data[0]);
185-
} else if (block_no < START_ROOTDIR) {
185+
} else if (block_no < START_ROOTDIR) { // Requested FAT table sector
186186
sectionIdx -= START_FAT0;
187187
// logval("sidx", sectionIdx);
188188
if (sectionIdx >= SECTORS_PER_FAT)
189-
sectionIdx -= SECTORS_PER_FAT;
189+
sectionIdx -= SECTORS_PER_FAT; // second FAT is same as the first...
190190
if (sectionIdx == 0) {
191-
data[0] = 0xf8;
191+
data[0] = 0xf8; // first FAT entry must match BPB MediaDescriptor
192192
for (int i = 1; i < NUM_INFO * 2 + 4; ++i) {
193193
data[i] = 0xff;
194194
}
195195
}
196-
for (int i = 0; i < 256; ++i) {
196+
for (int i = 0; i < 256; ++i) { // Generate the FAT chain for the firmware "file"
197197
uint32_t v = sectionIdx * 256 + i;
198198
if (UF2_FIRST_SECTOR <= v && v <= UF2_LAST_SECTOR)
199199
((uint16_t *)(void *)data)[i] = v == UF2_LAST_SECTOR ? 0xffff : v + 1;
200200
}
201-
} else if (block_no < START_CLUSTERS) {
201+
} else if (block_no < START_CLUSTERS) { // Requested root directory sector
202202
sectionIdx -= START_ROOTDIR;
203-
if (sectionIdx == 0) {
203+
if (sectionIdx == 0) { // only one sector of directory entries generated
204204
DirEntry *d = (void *)data;
205205
padded_memcpy(d->name, (char const *) BootBlock.VolumeLabel, 11);
206206
d->attrs = 0x28;
@@ -212,7 +212,7 @@ void read_block(uint32_t block_no, uint8_t *data) {
212212
padded_memcpy(d->name, inf->name, 11);
213213
}
214214
}
215-
} else {
215+
} else { // else Generate the UF2 file data on-the-fly
216216
sectionIdx -= START_CLUSTERS;
217217
if (sectionIdx < NUM_INFO - 1) {
218218
memcpy(data, info[sectionIdx].content, strlen(info[sectionIdx].content));

0 commit comments

Comments
 (0)