9
9
#include "bootloader_settings.h"
10
10
#include "bootloader.h"
11
11
12
+ // #define CREATE_MANY_FILES
13
+
12
14
13
15
typedef struct {
14
16
uint8_t JumpInstruction [3 ];
@@ -48,7 +50,6 @@ typedef struct {
48
50
uint16_t startCluster ;
49
51
uint32_t size ;
50
52
} __attribute__((packed )) DirEntry ;
51
-
52
53
STATIC_ASSERT (sizeof (DirEntry ) == 32 );
53
54
54
55
struct TextFile {
@@ -78,9 +79,56 @@ const char indexFile[] = //
78
79
"</body>"
79
80
"</html>\n" ;
80
81
82
+ #ifdef CREATE_MANY_FILES
83
+ const char dataFile00 [] = "This is the data for File 00\r\n" ;
84
+ const char dataFile01 [] = "This is the data for File 01\r\n" ;
85
+ const char dataFile02 [] = "This is the data for File 02\r\n" ;
86
+ const char dataFile03 [] = "This is the data for File 03\r\n" ;
87
+ const char dataFile04 [] = "This is the data for File 04\r\n" ;
88
+ const char dataFile05 [] = "This is the data for File 05\r\n" ;
89
+ const char dataFile06 [] = "This is the data for File 06\r\n" ;
90
+ const char dataFile07 [] = "This is the data for File 07\r\n" ;
91
+ const char dataFile08 [] = "This is the data for File 08\r\n" ;
92
+ const char dataFile09 [] = "This is the data for File 09\r\n" ;
93
+ const char dataFile10 [] = "This is the data for File 10\r\n" ;
94
+ const char dataFile11 [] = "This is the data for File 11\r\n" ;
95
+ const char dataFile12 [] = "This is the data for File 12\r\n" ;
96
+ const char dataFile13 [] = "This is the data for File 13\r\n" ;
97
+ const char dataFile14 [] = "This is the data for File 14\r\n" ;
98
+ const char dataFile15 [] = "This is the data for File 15\r\n" ;
99
+ const char dataFile16 [] = "This is the data for File 16\r\n" ;
100
+ const char dataFile17 [] = "This is the data for File 17\r\n" ;
101
+ const char dataFile18 [] = "This is the data for File 18\r\n" ;
102
+ const char dataFile19 [] = "This is the data for File 19\r\n" ;
103
+ #endif // CREATE_MANY_FILES
104
+
105
+ // WARNING -- code presumes only one NULL .content for .UF2 file
106
+ // and requires it be the last element of the array
81
107
static struct TextFile const info [] = {
82
108
{.name = "INFO_UF2TXT" , .content = infoUf2File },
83
109
{.name = "INDEX HTM" , .content = indexFile },
110
+ #ifdef CREATE_MANY_FILES
111
+ {.name = "FILE00 TXT" , .content = dataFile00 },
112
+ {.name = "FILE01 TXT" , .content = dataFile01 },
113
+ {.name = "FILE02 TXT" , .content = dataFile02 },
114
+ {.name = "FILE03 TXT" , .content = dataFile03 },
115
+ {.name = "FILE04 TXT" , .content = dataFile04 },
116
+ {.name = "FILE05 TXT" , .content = dataFile05 },
117
+ {.name = "FILE06 TXT" , .content = dataFile06 },
118
+ {.name = "FILE07 TXT" , .content = dataFile07 },
119
+ {.name = "FILE08 TXT" , .content = dataFile08 },
120
+ {.name = "FILE09 TXT" , .content = dataFile09 },
121
+ {.name = "FILE10 TXT" , .content = dataFile10 },
122
+ {.name = "FILE11 TXT" , .content = dataFile11 },
123
+ {.name = "FILE12 TXT" , .content = dataFile12 },
124
+ {.name = "FILE13 TXT" , .content = dataFile13 },
125
+ {.name = "FILE14 TXT" , .content = dataFile14 },
126
+ {.name = "FILE15 TXT" , .content = dataFile15 },
127
+ {.name = "FILE16 TXT" , .content = dataFile16 },
128
+ {.name = "FILE17 TXT" , .content = dataFile17 },
129
+ {.name = "FILE18 TXT" , .content = dataFile18 },
130
+ {.name = "FILE19 TXT" , .content = dataFile19 },
131
+ #endif
84
132
{.name = "CURRENT UF2" },
85
133
};
86
134
@@ -110,8 +158,9 @@ STATIC_ASSERT(ARRAY_SIZE2(indexFile) < 512);
110
158
111
159
// all directory entries must fit in a single sector
112
160
// because otherwise current code overflows buffer
113
- STATIC_ASSERT (NUM_DIRENTRIES < (512 / sizeof (DirEntry )));
114
- // STATIC_ASSERT(NUM_DIRENTRIES < (512 / sizeof(DirEntry)) * ROOT_DIR_SECTORS);
161
+ #define DIRENTRIES_PER_SECTOR (512/sizeof(DirEntry))
162
+
163
+ STATIC_ASSERT (NUM_DIRENTRIES < DIRENTRIES_PER_SECTOR * ROOT_DIR_SECTORS );
115
164
116
165
117
166
static FAT_BootBlock const BootBlock = {
@@ -121,7 +170,7 @@ static FAT_BootBlock const BootBlock = {
121
170
.SectorsPerCluster = 1 ,
122
171
.ReservedSectors = RESERVED_SECTORS ,
123
172
.FATCopies = 2 ,
124
- .RootDirectoryEntries = (ROOT_DIR_SECTORS * 512 / 32 ),
173
+ .RootDirectoryEntries = (ROOT_DIR_SECTORS * DIRENTRIES_PER_SECTOR ),
125
174
.TotalSectors16 = NUM_FAT_BLOCKS - 2 ,
126
175
.MediaDescriptor = 0xF8 ,
127
176
.SectorsPerFAT = SECTORS_PER_FAT ,
@@ -205,8 +254,11 @@ void read_block(uint32_t block_no, uint8_t *data) {
205
254
sectionIdx -= SECTORS_PER_FAT ;
206
255
if (sectionIdx == 0 ) {
207
256
data [0 ] = 0xf0 ;
257
+ // WARNING -- code presumes only one NULL .content for .UF2 file
258
+ // and all non-NULL .content fit in one sector
259
+ // and requires it be the last element of the array
208
260
for (int i = 1 ; i < NUM_FILES * 2 + 4 ; ++ i ) {
209
- data [i ] = 0xff ; // WARNING -- code presumes each non-UF2 file content fits in single sector
261
+ data [i ] = 0xff ;
210
262
}
211
263
}
212
264
for (int i = 0 ; i < 256 ; ++ i ) {
@@ -215,20 +267,33 @@ void read_block(uint32_t block_no, uint8_t *data) {
215
267
((uint16_t * )(void * )data )[i ] = v == UF2_LAST_SECTOR ? 0xffff : v + 1 ;
216
268
}
217
269
} else if (block_no < START_CLUSTERS ) {
218
- // Use STATIC_ASSERT() above to ensure only first sector has entries
270
+
219
271
sectionIdx -= START_ROOTDIR ;
220
- if (sectionIdx == 0 ) {
221
- DirEntry * d = (void * )data ;
272
+
273
+ DirEntry * d = (void * )data ;
274
+ int remainingEntries = DIRENTRIES_PER_SECTOR ;
275
+ if (sectionIdx == 0 ) { // volume label first
276
+ // volume label is first directory entry
222
277
padded_memcpy (d -> name , (char const * ) BootBlock .VolumeLabel , 11 );
223
278
d -> attrs = 0x28 ;
224
- for (int i = 0 ; i < NUM_FILES ; ++ i ) {
225
- d ++ ;
226
- struct TextFile const * inf = & info [i ];
227
- d -> size = inf -> content ? strlen (inf -> content ) : UF2_SIZE ;
228
- d -> startCluster = i + 2 ;
229
- padded_memcpy (d -> name , inf -> name , 11 );
230
- }
279
+ remainingEntries -- ;
231
280
}
281
+
282
+ for (int i = DIRENTRIES_PER_SECTOR * sectionIdx ;
283
+ remainingEntries > 0 && i < NUM_FILES ;
284
+ i ++ , d ++ ) {
285
+ struct TextFile const * inf = & info [i ];
286
+ // WARNING -- code presumes only one NULL .content for .UF2 file
287
+ // and requires it be the last element of the array
288
+ d -> size = inf -> content ? strlen (inf -> content ) : UF2_SIZE ;
289
+ d -> startCluster = i + 2 ;
290
+ padded_memcpy (d -> name , inf -> name , 11 );
291
+ // DIR_WrtTime and DIR_WrtDate must be supported
292
+ d -> updateDate = __DOSDATE__ ;
293
+ d -> lastAccessDate = __DOSDATE__ ;
294
+ d -> createDate = __DOSDATE__ ;
295
+ }
296
+
232
297
} else {
233
298
sectionIdx -= START_CLUSTERS ;
234
299
if (sectionIdx < NUM_FILES - 1 ) {
0 commit comments