From 78425208ba0883f9b7b876a3e54ea87899f2bf99 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Thu, 18 Nov 2021 20:36:04 +0200 Subject: [PATCH] nrf/main: Use VFS helper function to mount fs and chdir. --- ports/nrf/main.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/ports/nrf/main.c b/ports/nrf/main.c index 254d9491c0..3768b8f404 100644 --- a/ports/nrf/main.c +++ b/ports/nrf/main.c @@ -106,28 +106,6 @@ void do_str(const char *src, mp_parse_input_kind_t input_kind) { extern uint32_t _heap_start; extern uint32_t _heap_end; -#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE -STATIC int vfs_mount_and_chdir(mp_obj_t bdev, mp_obj_t mount_point) { - nlr_buf_t nlr; - mp_int_t ret = -MP_EIO; - if (nlr_push(&nlr) == 0) { - mp_obj_t args[] = { bdev, mount_point }; - mp_vfs_mount(2, args, (mp_map_t *)&mp_const_empty_map); - mp_vfs_chdir(mount_point); - ret = 0; // success - nlr_pop(); - } else { - mp_obj_base_t *exc = nlr.ret_val; - if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(exc->type), MP_OBJ_FROM_PTR(&mp_type_OSError))) { - mp_obj_t v = mp_obj_exception_get_value(MP_OBJ_FROM_PTR(exc)); - mp_obj_get_int_maybe(v, &ret); // get errno value - ret = -ret; - } - } - return ret; -} -#endif - int main(int argc, char **argv) { @@ -203,11 +181,11 @@ soft_reset: // Try to mount the flash on "/flash" and chdir to it for the boot-up directory. mp_obj_t mount_point = MP_OBJ_NEW_QSTR(MP_QSTR__slash_flash); - int ret = vfs_mount_and_chdir((mp_obj_t)&nrf_flash_obj, mount_point); + int ret = mp_vfs_mount_and_chdir_protected((mp_obj_t)&nrf_flash_obj, mount_point); if ((ret == -MP_ENODEV) || (ret == -MP_EIO)) { pyexec_frozen_module("_mkfs.py"); // Frozen script for formatting flash filesystem. - ret = vfs_mount_and_chdir((mp_obj_t)&nrf_flash_obj, mount_point); + ret = mp_vfs_mount_and_chdir_protected((mp_obj_t)&nrf_flash_obj, mount_point); } if (ret != 0) {