stm32/mboot: Don't search for firmware on FS, just attempt to open it.
There's no need to do a directory listing to search for the given firmware filename, it just takes extra time and code size. Instead this commit changes it so that the requested firmware file is opened immediately and will abort if the file couldn't be opened. This also allows to specify files in a directory. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
717b5073aa
commit
763bd448a4
@ -204,7 +204,7 @@ static int fsload_program_file(FATFS *fatfs, const char *filename, bool write_to
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fsload_process_fatfs(uint32_t base_addr, uint32_t byte_len, size_t fname_len, const char *fname) {
|
static int fsload_process_fatfs(uint32_t base_addr, uint32_t byte_len, const char *fname) {
|
||||||
fsload_bdev_t bdev = {base_addr, byte_len};
|
fsload_bdev_t bdev = {base_addr, byte_len};
|
||||||
FATFS fatfs;
|
FATFS fatfs;
|
||||||
fatfs.drv = &bdev;
|
fatfs.drv = &bdev;
|
||||||
@ -213,34 +213,14 @@ static int fsload_process_fatfs(uint32_t base_addr, uint32_t byte_len, size_t fn
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
FF_DIR dp;
|
// Validate firmware
|
||||||
res = f_opendir(&fatfs, &dp, "/");
|
led_state_all(2);
|
||||||
if (res != FR_OK) {
|
int r = fsload_program_file(&fatfs, fname, false);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Search for firmware file with correct name
|
if (r == 0) {
|
||||||
int r;
|
// Firmware is valid, program it
|
||||||
for (;;) {
|
led_state_all(4);
|
||||||
FILINFO fno;
|
r = fsload_program_file(&fatfs, fname, true);
|
||||||
res = f_readdir(&dp, &fno);
|
|
||||||
char *fn = fno.fname;
|
|
||||||
if (res != FR_OK || fn[0] == 0) {
|
|
||||||
// Finished listing dir, no firmware found
|
|
||||||
r = -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (memcmp(fn, fname, fname_len) == 0 && fn[fname_len] == '\0') {
|
|
||||||
// Found firmware
|
|
||||||
led_state_all(2);
|
|
||||||
r = fsload_program_file(&fatfs, fn, false);
|
|
||||||
if (r == 0) {
|
|
||||||
// Firmware is valid, program it
|
|
||||||
led_state_all(4);
|
|
||||||
r = fsload_program_file(&fatfs, fn, true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
@ -252,9 +232,12 @@ int fsload_process(void) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get mount point id and create null-terminated filename
|
||||||
uint8_t mount_point = elem[0];
|
uint8_t mount_point = elem[0];
|
||||||
uint8_t fname_len = elem[-1] - 1;
|
uint8_t fname_len = elem[-1] - 1;
|
||||||
const char *fname = (const char*)&elem[1];
|
char fname[256];
|
||||||
|
memcpy(fname, &elem[1], fname_len);
|
||||||
|
fname[fname_len] = '\0';
|
||||||
|
|
||||||
elem = ELEM_DATA_START;
|
elem = ELEM_DATA_START;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -267,7 +250,7 @@ int fsload_process(void) {
|
|||||||
uint32_t base_addr = get_le32(&elem[2]);
|
uint32_t base_addr = get_le32(&elem[2]);
|
||||||
uint32_t byte_len = get_le32(&elem[6]);
|
uint32_t byte_len = get_le32(&elem[6]);
|
||||||
if (elem[1] == ELEM_MOUNT_FAT) {
|
if (elem[1] == ELEM_MOUNT_FAT) {
|
||||||
int ret = fsload_process_fatfs(base_addr, byte_len, fname_len, fname);
|
int ret = fsload_process_fatfs(base_addr, byte_len, fname);
|
||||||
// Flash LEDs based on success/failure of update
|
// Flash LEDs based on success/failure of update
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user