nrf/main: Use VFS helper function to mount fs and chdir.
This commit is contained in:
parent
f7a0c98e00
commit
78425208ba
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user