Skip to content

Commit

Permalink
sd: prompt user for formatting if format is not VFAT compatible
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
asi345 committed Dec 4, 2024
1 parent 5ce4a18 commit 24c9b76
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ customers cannot upgrade their bootloader, its changes are recorded separately.
- Update manufacturer HID descriptor to bitbox.swiss
- Ethereum: remove deprecated Goerli network
- SD card: solve backup bug when sd card is re-inserted
- SD card: prompt user for formatting if sd is not VFAT compatible

### 9.21.0
- Bitcoin: add support for sending to silent payment (BIP-352) addresses
Expand Down
10 changes: 10 additions & 0 deletions src/rust/bitbox02-rust/src/hww/api/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ pub async fn create(
})
.await?;

let is_vfat_formatted = bitbox02::sd::sdcard_vfat_formatted();
if is_vfat_formatted {
confirm::confirm(&confirm::Params {
title: "SD card\nformatting needed",
body: "This will erase all\ndata on the SD card.",
..Default::default()
}).await?;
bitbox02::sd::sd_format();
}

let is_initialized = bitbox02::memory::is_initialized();

if is_initialized {
Expand Down
1 change: 1 addition & 0 deletions src/rust/bitbox02-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const ALLOWLIST_FNS: &[&str] = &[
"screen_saver_disable",
"screen_saver_enable",
"sd_card_inserted",
"sd_card_vfat_formatted",
"sd_erase_file_in_subdir",
"sd_format",
"sd_free_list",
Expand Down
14 changes: 14 additions & 0 deletions src/rust/bitbox02/src/sd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ pub fn sdcard_inserted() -> bool {
data.sdcard_inserted.unwrap()
}

#[cfg(not(feature = "testing"))]
pub fn sdcard_vfat_formatted() -> bool {
unsafe { bitbox02_sys::sd_card_vfat_formatted() }
}

#[cfg(feature = "testing")]
pub fn sdcard_vfat_formatted() -> bool {
true
}

pub fn sd_format() -> bool {
unsafe { bitbox02_sys::sd_format() }
}

struct SdList(bitbox02_sys::sd_list_t);

impl Drop for SdList {
Expand Down
12 changes: 10 additions & 2 deletions src/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,16 @@ bool sd_erase_file_in_subdir(const char* fn, const char* subdir)
return status;
}

#ifdef TESTING
bool sd_card_vfat_formatted(void)
{
if (!_mount()) {
return -1;
}
int result = fs.fs_type == FS_FAT32;
_unmount();
return result;
}

bool sd_format(void)
{
const MKFS_PARM params = {
Expand All @@ -384,4 +393,3 @@ bool sd_format(void)
uint8_t work[FF_MAX_SS] = {0};
return f_mkfs("SD", &params, work, sizeof(work)) == FR_OK;
}
#endif
3 changes: 1 addition & 2 deletions src/sd.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ USE_RESULT bool sd_write_bin(
uint16_t length,
bool replace);

#ifdef TESTING
USE_RESULT bool sd_card_vfat_formatted(void);
USE_RESULT bool sd_format(void);
#endif

#endif

0 comments on commit 24c9b76

Please sign in to comment.