From ce8d1eca91b5b83e34d0fe8ada27d7522542ece0 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Tue, 15 Feb 2022 00:17:53 +0200 Subject: [PATCH] bdk: remove sd mounts from ianos and check if sd is mounted in sd ops --- bdk/ianos/ianos.c | 17 +++++++---------- bdk/storage/sd.c | 6 ++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/bdk/ianos/ianos.c b/bdk/ianos/ianos.c index fdc3488..99a996d 100644 --- a/bdk/ianos/ianos.c +++ b/bdk/ianos/ianos.c @@ -74,19 +74,16 @@ uintptr_t ianos_loader(char *path, elfType_t type, void *moduleConfig) el_ctx ctx; uintptr_t epaddr = 0; - if (!sd_mount()) - goto elfLoadFinalOut; - // Read library. fileBuf = sd_file_read(path, NULL); if (!fileBuf) - goto elfLoadFinalOut; + goto out; ctx.pread = _ianos_read_cb; if (el_init(&ctx)) - goto elfLoadFinalOut; + goto out; // Set our relocated library's buffer. switch (type & 0xFFFF) @@ -100,15 +97,15 @@ uintptr_t ianos_loader(char *path, elfType_t type, void *moduleConfig) } if (!elfBuf) - goto elfLoadFinalOut; + goto out; // Load and relocate library. ctx.base_load_vaddr = ctx.base_load_paddr = (uintptr_t)elfBuf; if (el_load(&ctx, _ianos_alloc_cb)) - goto elfFreeOut; + goto out_free; if (el_relocate(&ctx)) - goto elfFreeOut; + goto out_free; // Launch. epaddr = ctx.ehdr.e_entry + (uintptr_t)elfBuf; @@ -116,11 +113,11 @@ uintptr_t ianos_loader(char *path, elfType_t type, void *moduleConfig) _ianos_call_ep(ep, moduleConfig); -elfFreeOut: +out_free: free(fileBuf); elfBuf = NULL; fileBuf = NULL; -elfLoadFinalOut: +out: return epaddr; } \ No newline at end of file diff --git a/bdk/storage/sd.c b/bdk/storage/sd.c index 9f45fe9..a20975b 100644 --- a/bdk/storage/sd.c +++ b/bdk/storage/sd.c @@ -210,6 +210,9 @@ bool sd_is_gpt() void *sd_file_read(const char *path, u32 *fsize) { FIL fp; + if (!sd_get_card_mounted()) + return NULL; + if (f_open(&fp, path, FA_READ) != FR_OK) return NULL; @@ -236,6 +239,9 @@ int sd_save_to_file(void *buf, u32 size, const char *filename) { FIL fp; u32 res = 0; + if (!sd_get_card_mounted()) + return NULL; + res = f_open(&fp, filename, FA_CREATE_ALWAYS | FA_WRITE); if (res) {