diff options
author | Damien George <damien.p.george@gmail.com> | 2016-02-10 16:32:57 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-02-10 23:40:10 +0000 |
commit | b33a7705966a743c5e4c0c3c3bb83e6d97b5e84d (patch) | |
tree | 2c62a5389a7f0189119b5fcbbb9b30f0ff5b9db5 /stmhal/main.c | |
parent | 34023eb673d5356bb4eb6fc635d6d48eefb35135 (diff) |
extmod/fsusermount: Support mounting of multiple block devices.
This patch adds support to fsusermount for multiple block devices
(instead of just one). The maximum allowed is fixed at compile time by
the size of the fs_user_mount array accessed via MP_STATE_PORT, which
in turn is set by MICROPY_FATFS_VOLUMES.
With this patch, stmhal (which is still tightly coupled to fsusermount)
is also modified to support mounting multiple devices And the flash and
SD card are now just two block devices that are mounted at start up if
they exist (and they have special native code to make them more
efficient).
Diffstat (limited to 'stmhal/main.c')
-rw-r--r-- | stmhal/main.c | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/stmhal/main.c b/stmhal/main.c index 882de6e1a..02dcc7617 100644 --- a/stmhal/main.c +++ b/stmhal/main.c @@ -38,6 +38,7 @@ #include "lib/utils/pyexec.h" #include "lib/fatfs/ff.h" +#include "extmod/fsusermount.h" #include "systick.h" #include "pendsv.h" @@ -64,10 +65,7 @@ void SystemClock_Config(void); -static FATFS fatfs0; -#if MICROPY_HW_HAS_SDCARD -static FATFS fatfs1; -#endif +fs_user_mount_t fs_user_mount_flash; void flash_error(int n) { for (int i = 0; i < n; i++) { @@ -169,8 +167,18 @@ static const char fresh_readme_txt[] = // we don't make this function static because it needs a lot of stack and we // want it to be executed without using stack within main() function void init_flash_fs(uint reset_mode) { + // init the vfs object + fs_user_mount_t *vfs = &fs_user_mount_flash; + vfs->str = "/flash"; + vfs->len = 6; + vfs->flags = 0; + pyb_flash_init_vfs(vfs); + + // put the flash device in slot 0 (it will be unused at this point) + MP_STATE_PORT(fs_user_mount)[0] = vfs; + // try to mount the flash - FRESULT res = f_mount(&fatfs0, "/flash", 1); + FRESULT res = f_mount(&vfs->fatfs, vfs->str, 1); if (reset_mode == 3 || res == FR_NO_FILESYSTEM) { // no filesystem, or asked to reset it, so create a fresh one @@ -183,7 +191,9 @@ void init_flash_fs(uint reset_mode) { if (res == FR_OK) { // success creating fresh LFS } else { - __fatal_error("could not create LFS"); + printf("PYB: can't create flash filesystem\n"); + MP_STATE_PORT(fs_user_mount)[0] = NULL; + return; } // set label @@ -213,7 +223,9 @@ void init_flash_fs(uint reset_mode) { } else if (res == FR_OK) { // mount sucessful } else { - __fatal_error("could not access LFS"); + printf("PYB: can't mount flash\n"); + MP_STATE_PORT(fs_user_mount)[0] = NULL; + return; } // The current directory is used as the boot up directory. @@ -448,6 +460,9 @@ soft_reset: mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_flash_slash_lib)); mp_obj_list_init(mp_sys_argv, 0); + // zero out the pointers to the mounted devices + memset(MP_STATE_PORT(fs_user_mount), 0, sizeof(MP_STATE_PORT(fs_user_mount))); + // Initialise low-level sub-systems. Here we need to very basic things like // zeroing out memory and resetting any of the sub-systems. Following this // we can run Python scripts (eg boot.py), but anything that is configurable @@ -493,9 +508,24 @@ soft_reset: #if MICROPY_HW_HAS_SDCARD // if an SD card is present then mount it on /sd/ if (sdcard_is_present()) { - FRESULT res = f_mount(&fatfs1, "/sd", 1); + // create vfs object + fs_user_mount_t *vfs = m_new_obj_maybe(fs_user_mount_t); + if (vfs == NULL) { + goto no_mem_for_sd; + } + vfs->str = "/sd"; + vfs->len = 3; + vfs->flags = FSUSER_FREE_OBJ; + sdcard_init_vfs(vfs); + + // put the sd device in slot 1 (it will be unused at this point) + MP_STATE_PORT(fs_user_mount)[1] = vfs; + + FRESULT res = f_mount(&vfs->fatfs, vfs->str, 1); if (res != FR_OK) { - printf("[SD] could not mount SD card\n"); + printf("PYB: can't mount SD card\n"); + MP_STATE_PORT(fs_user_mount)[1] = NULL; + m_del_obj(fs_user_mount_t, vfs); } else { // TODO these should go before the /flash entries in the path mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_sd)); @@ -517,6 +547,7 @@ soft_reset: f_chdrive("/sd"); } } + no_mem_for_sd:; } #endif |