Skip to content

Commit d2bebf7

Browse files
committed
Merge remote-tracking branch 'ata/restore-sd-reinsert'
2 parents 6494a12 + f4c67e8 commit d2bebf7

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ customers cannot upgrade their bootloader, its changes are recorded separately.
99
### [Unreleased]
1010
- Update manufacturer HID descriptor to bitbox.swiss
1111
- Ethereum: remove deprecated Goerli network
12+
- SD card: solve backup bug when sd card is re-inserted
1213

1314
### 9.21.0
1415
- Bitcoin: add support for sending to silent payment (BIP-352) addresses

src/sd.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#ifndef TESTING
2121
#include "driver_init.h"
2222
#include "sd_mmc.h"
23+
#include "sd_mmc/sd_mmc_start.h"
2324
#endif
2425

2526
#include "flags.h"
@@ -107,7 +108,14 @@ static bool _mount(void)
107108
sd_mmc_resume_clock();
108109
#endif
109110
memset(&fs, 0, sizeof(FATFS));
110-
if (f_mount(&fs, "SD", 1) == FR_INVALID_DRIVE) {
111+
int res = f_mount(&fs, "", 1);
112+
if (res == FR_DISK_ERR) {
113+
#ifndef TESTING
114+
sd_mmc_start();
115+
#endif
116+
res = f_mount(&fs, "", 1);
117+
}
118+
if (res == FR_INVALID_DRIVE) {
111119
#ifndef TESTING
112120
sd_mmc_pause_clock();
113121
#endif
@@ -117,11 +125,11 @@ static bool _mount(void)
117125
}
118126

119127
/**
120-
* Unmunts an SD card and pauses the bus clock.
128+
* Unmounts an SD card and pauses the bus clock.
121129
*/
122130
static void _unmount(void)
123131
{
124-
f_mount(NULL, "SD", 1);
132+
f_unmount("");
125133
#ifndef TESTING
126134
sd_mmc_pause_clock();
127135
#endif
@@ -268,7 +276,8 @@ bool sd_list_subdir(sd_list_t* list_out, const char* subdir)
268276
if (list_out->num_files == allocated_files) {
269277
char** new_list_out_files;
270278
allocated_files *= 2;
271-
new_list_out_files = (char**)realloc(list_out->files, sizeof(char*) * allocated_files);
279+
new_list_out_files =
280+
(char**)realloc((void*)list_out->files, sizeof(char*) * allocated_files);
272281
if (new_list_out_files == NULL) {
273282
sd_free_list(list_out);
274283
Abort("Error: realloc sd_list_subdir");
@@ -295,7 +304,7 @@ void sd_free_list(sd_list_t* list)
295304
util_zero(list->files[i], strlen(list->files[i]));
296305
free(list->files[i]);
297306
}
298-
free(list->files);
307+
free((void*)list->files);
299308
list->files = NULL;
300309
}
301310

0 commit comments

Comments
 (0)