Skip to content

Commit d01ec43

Browse files
committed
sd: prompt user for formatting if format is not VFAT compatible
This commit inserts a check to validate whether the sdcard where the backup will be put is VFAT compatible or not. VFAT compatilibity is crucial for using the card and lack of it could result in errors in the firmware. Therefore, when setting up the device, this commit validates it and if it is not compatible, it asks user whether he/she is okay with formatting or not. When the user confirms, SD card is formatted accordingly and the fresh SD card is ready to be used by BitBox02. Signed-off-by: asi345 <[email protected]>
1 parent 5ce4a18 commit d01ec43

File tree

6 files changed

+38
-4
lines changed

6 files changed

+38
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ customers cannot upgrade their bootloader, its changes are recorded separately.
1010
- Update manufacturer HID descriptor to bitbox.swiss
1111
- Ethereum: remove deprecated Goerli network
1212
- SD card: solve backup bug when sd card is re-inserted
13+
- SD card: prompt user for formatting if sd is not VFAT compatible
1314

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

src/rust/bitbox02-rust/src/hww/api/backup.rs

+11
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ pub async fn create(
8989
})
9090
.await?;
9191

92+
let is_vfat_formatted = bitbox02::sd::sdcard_vfat_formatted();
93+
if !is_vfat_formatted {
94+
confirm::confirm(&confirm::Params {
95+
title: "SD card\nformatting needed",
96+
body: "This will erase all\ndata on the SD card.",
97+
..Default::default()
98+
})
99+
.await?;
100+
bitbox02::sd::sd_format();
101+
}
102+
92103
let is_initialized = bitbox02::memory::is_initialized();
93104

94105
if is_initialized {

src/rust/bitbox02-sys/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ const ALLOWLIST_FNS: &[&str] = &[
117117
"screen_saver_disable",
118118
"screen_saver_enable",
119119
"sd_card_inserted",
120+
"sd_card_vfat_formatted",
120121
"sd_erase_file_in_subdir",
121122
"sd_format",
122123
"sd_free_list",

src/rust/bitbox02/src/sd.rs

+14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ pub fn sdcard_inserted() -> bool {
3030
data.sdcard_inserted.unwrap()
3131
}
3232

33+
#[cfg(not(feature = "testing"))]
34+
pub fn sdcard_vfat_formatted() -> bool {
35+
unsafe { bitbox02_sys::sd_card_vfat_formatted() }
36+
}
37+
38+
#[cfg(feature = "testing")]
39+
pub fn sdcard_vfat_formatted() -> bool {
40+
true
41+
}
42+
43+
pub fn sd_format() -> bool {
44+
unsafe { bitbox02_sys::sd_format() }
45+
}
46+
3347
struct SdList(bitbox02_sys::sd_list_t);
3448

3549
impl Drop for SdList {

src/sd.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,16 @@ bool sd_erase_file_in_subdir(const char* fn, const char* subdir)
370370
return status;
371371
}
372372

373-
#ifdef TESTING
373+
bool sd_card_vfat_formatted(void)
374+
{
375+
if (!_mount()) {
376+
return -1;
377+
}
378+
int result = fs.fs_type == FS_FAT32;
379+
_unmount();
380+
return result;
381+
}
382+
374383
bool sd_format(void)
375384
{
376385
const MKFS_PARM params = {
@@ -384,4 +393,3 @@ bool sd_format(void)
384393
uint8_t work[FF_MAX_SS] = {0};
385394
return f_mkfs("SD", &params, work, sizeof(work)) == FR_OK;
386395
}
387-
#endif

src/sd.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ USE_RESULT bool sd_write_bin(
6464
uint16_t length,
6565
bool replace);
6666

67-
#ifdef TESTING
67+
USE_RESULT bool sd_card_vfat_formatted(void);
6868
USE_RESULT bool sd_format(void);
69-
#endif
7069

7170
#endif

0 commit comments

Comments
 (0)