From bc42579f01632add5e7e10184a1e3cf55bc4a014 Mon Sep 17 00:00:00 2001 From: Christoph Baumann Date: Thu, 9 Oct 2025 12:36:35 +0200 Subject: [PATCH] boot_storage_mount: only deinitialize storage, if it wasnt initialized to begin with --- bdk/storage/boot_storage.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/bdk/storage/boot_storage.c b/bdk/storage/boot_storage.c index d5e750a9..a8b57eae 100644 --- a/bdk/storage/boot_storage.c +++ b/bdk/storage/boot_storage.c @@ -112,7 +112,10 @@ static bool _boot_storage_mount(){ FRESULT res; - if(!emmc_get_initialized() && !emmc_initialize(false)){ + bool prev_emmc_initialized = emmc_get_initialized(); + bool prev_sd_initialized = sd_get_card_initialized(); + + if(!prev_emmc_initialized && !emmc_initialize(false)){ goto emmc_init_fail; } @@ -134,7 +137,9 @@ static bool _boot_storage_mount(){ } if(res != FR_OK){ - emmc_end(); + if(!prev_emmc_initialized) { + emmc_end(); + } } if(res == FR_OK){ @@ -147,7 +152,9 @@ emmc_init_fail: } if(!emmc_mount()){ - emmc_end(); + if(!prev_emmc_initialized) { + emmc_end(); + } goto emmc_init_fail2; } @@ -165,7 +172,9 @@ emmc_init_fail2: } if(!sd_mount()){ - sd_end(); + if(!prev_sd_initialized) { + sd_end(); + } goto out; } @@ -177,7 +186,9 @@ emmc_init_fail2: return true; } - sd_end(); + if(!prev_sd_initialized) { + sd_end(); + } out: return false;