Fix Directory entries

The media would show as corrupt in CMD.EXE in Windows.
This is because the date/time fields were invalid.
Since this needed to be fixed anyways, update so that
the date and time correspond to the time that the
preprocessor parsed the source file.
This commit is contained in:
Henry Gabryjelski 2019-03-13 22:05:57 -07:00
parent 53a99195bf
commit 174e6e9724
2 changed files with 37 additions and 8 deletions

View File

@ -9,9 +9,9 @@
#include "bootloader_settings.h"
#include "bootloader.h"
// Uncomment the next line to create an additional 20 files in root.
// #define CREATE_MANY_FILES
typedef struct {
uint8_t JumpInstruction[3];
uint8_t OEMInfo[8];
@ -67,7 +67,8 @@ const char infoUf2File[] = //
"Model: " PRODUCT_NAME "\r\n"
"Board-ID: " BOARD_ID "\r\n"
"Bootloader: " BOOTLOADER_ID "\r\n"
"Date: " __DATE__ "\r\n";
"Date: " __DATE__ "\r\n"
"Time: " __TIME__ "\r\n";
const char indexFile[] = //
"<!doctype html>\n"
@ -276,22 +277,31 @@ void read_block(uint32_t block_no, uint8_t *data) {
// volume label is first directory entry
padded_memcpy(d->name, (char const *) BootBlock.VolumeLabel, 11);
d->attrs = 0x28;
d++;
remainingEntries--;
}
for (int i = DIRENTRIES_PER_SECTOR * sectionIdx;
remainingEntries > 0 && i < NUM_FILES;
i++, d++) {
// WARNING -- code presumes all but last file take exactly one sector
uint16_t startCluster = i + 2;
struct TextFile const * inf = &info[i];
padded_memcpy(d->name, inf->name, 11);
d->createTimeFine = __SECONDS_INT__ % 2 * 100;
d->createTime = __DOSTIME__;
d->createDate = __DOSDATE__;
d->lastAccessDate = __DOSDATE__;
d->highStartCluster = startCluster >> 8;
// DIR_WrtTime and DIR_WrtDate must be supported
d->updateTime = __DOSTIME__;
d->updateDate = __DOSDATE__;
d->startCluster = startCluster & 0xFF;
// WARNING -- code presumes only one NULL .content for .UF2 file
// and requires it be the last element of the array
d->size = inf->content ? strlen(inf->content) : UF2_SIZE;
d->startCluster = i + 2;
padded_memcpy(d->name, inf->name, 11);
// DIR_WrtTime and DIR_WrtDate must be supported
d->updateDate = __DOSDATE__;
d->lastAccessDate = __DOSDATE__;
d->createDate = __DOSDATE__;
}
} else {

View File

@ -323,11 +323,30 @@ static inline void check_uf2_handover(uint8_t *buffer, uint32_t blocks_remaining
(__DATE__ [4u] == ' ' ? 0u : __DATE__ [4u] - '0') * 10u \
+ (__DATE__ [5u] - '0') )
// __TIME__ expands to an eight-character string constant
// "23:59:01", or (if cannot determine time) "??:??:??"
#define __HOUR_INT__ ( \
(__TIME__ [0u] == '?' ? 0u : __TIME__ [0u] - '0') * 10u \
+ (__TIME__ [1u] == '?' ? 0u : __TIME__ [1u] - '0') )
#define __MINUTE_INT__ ( \
(__TIME__ [3u] == '?' ? 0u : __TIME__ [3u] - '0') * 10u \
+ (__TIME__ [4u] == '?' ? 0u : __TIME__ [4u] - '0') )
#define __SECONDS_INT__ ( \
(__TIME__ [6u] == '?' ? 0u : __TIME__ [6u] - '0') * 10u \
+ (__TIME__ [7u] == '?' ? 0u : __TIME__ [7u] - '0') )
#define __DOSDATE__ ( \
((__YEAR_INT__ - 1980u) << 9u) | \
( __MONTH_INT__ << 5u) | \
( __DAY_INT__ << 0u) )
#define __DOSTIME__ ( \
( __HOUR_INT__ << 11u) | \
( __MONTH_INT__ << 5u) | \
( __DAY_INT__ << 0u) )
#endif // COMPILE_DATE_H