esp8266: Change to use new generic VFS sub-system.
The VFS sub-system supports mounting of an arbitrary number of devices (limited only by available RAM). The internal flash is now mounted at "/flash".
This commit is contained in:
parent
f1e04148a1
commit
f9ecd484bb
@ -49,8 +49,8 @@ STATIC void mp_reset(void) {
|
||||
mp_init();
|
||||
mp_obj_list_init(mp_sys_path, 0);
|
||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script)
|
||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
|
||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_));
|
||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_flash_slash_lib));
|
||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_flash));
|
||||
mp_obj_list_init(mp_sys_argv, 0);
|
||||
MP_STATE_PORT(term_obj) = MP_OBJ_NULL;
|
||||
MP_STATE_PORT(dupterm_arr_obj) = MP_OBJ_NULL;
|
||||
@ -109,34 +109,23 @@ void user_init(void) {
|
||||
system_init_done_cb(init_done);
|
||||
}
|
||||
|
||||
mp_import_stat_t fat_vfs_import_stat(const char *path);
|
||||
|
||||
#if !MICROPY_VFS_FAT
|
||||
#if !MICROPY_VFS
|
||||
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
mp_import_stat_t mp_import_stat(const char *path) {
|
||||
#if MICROPY_VFS_FAT
|
||||
return fat_vfs_import_stat(path);
|
||||
#else
|
||||
(void)path;
|
||||
return MP_IMPORT_STAT_NO_EXIST;
|
||||
#endif
|
||||
}
|
||||
|
||||
mp_obj_t vfs_proxy_call(qstr method_name, mp_uint_t n_args, const mp_obj_t *args);
|
||||
mp_obj_t mp_builtin_open(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) {
|
||||
#if MICROPY_VFS_FAT
|
||||
// TODO: Handle kwargs!
|
||||
return vfs_proxy_call(MP_QSTR_open, n_args, args);
|
||||
#else
|
||||
return mp_const_none;
|
||||
#endif
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
|
||||
|
||||
#endif
|
||||
|
||||
void MP_FASTCODE(nlr_jump_fail)(void *val) {
|
||||
printf("NLR jump failed\n");
|
||||
for (;;) {
|
||||
|
@ -5,7 +5,9 @@ from flashbdev import bdev
|
||||
|
||||
try:
|
||||
if bdev:
|
||||
vfs = uos.VfsFat(bdev, "")
|
||||
vfs = uos.VfsFat(bdev)
|
||||
uos.mount(vfs, '/flash')
|
||||
uos.chdir('/flash')
|
||||
except OSError:
|
||||
import inisetup
|
||||
vfs = inisetup.setup()
|
||||
|
@ -26,14 +26,10 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "py/mpconfig.h"
|
||||
#include "py/nlr.h"
|
||||
#include "py/obj.h"
|
||||
#include "py/objtuple.h"
|
||||
#include "py/objstr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/mperrno.h"
|
||||
#include "extmod/misc.h"
|
||||
#include "extmod/vfs.h"
|
||||
#include "extmod/vfs_fat.h"
|
||||
#include "genhdr/mpversion.h"
|
||||
#include "esp_mphal.h"
|
||||
@ -70,74 +66,6 @@ STATIC mp_obj_t os_uname(void) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname);
|
||||
|
||||
#if MICROPY_VFS_FAT
|
||||
mp_obj_t vfs_proxy_call(qstr method_name, mp_uint_t n_args, const mp_obj_t *args) {
|
||||
if (MP_STATE_PORT(fs_user_mount)[0] == NULL) {
|
||||
mp_raise_OSError(MP_ENODEV);
|
||||
}
|
||||
|
||||
mp_obj_t meth[n_args + 2];
|
||||
mp_load_method(MP_STATE_PORT(fs_user_mount)[0], method_name, meth);
|
||||
if (args != NULL) {
|
||||
memcpy(meth + 2, args, n_args * sizeof(*args));
|
||||
}
|
||||
return mp_call_method_n_kw(n_args, 0, meth);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t os_listdir(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
return vfs_proxy_call(MP_QSTR_listdir, n_args, args);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_listdir_obj, 0, 1, os_listdir);
|
||||
|
||||
STATIC mp_obj_t os_mkdir(mp_obj_t path_in) {
|
||||
return vfs_proxy_call(MP_QSTR_mkdir, 1, &path_in);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_mkdir_obj, os_mkdir);
|
||||
|
||||
STATIC mp_obj_t os_rmdir(mp_obj_t path_in) {
|
||||
return vfs_proxy_call(MP_QSTR_rmdir, 1, &path_in);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_rmdir_obj, os_rmdir);
|
||||
|
||||
STATIC mp_obj_t os_chdir(mp_obj_t path_in) {
|
||||
return vfs_proxy_call(MP_QSTR_chdir, 1, &path_in);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_chdir_obj, os_chdir);
|
||||
|
||||
STATIC mp_obj_t os_getcwd(void) {
|
||||
return vfs_proxy_call(MP_QSTR_getcwd, 0, NULL);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_getcwd_obj, os_getcwd);
|
||||
|
||||
STATIC mp_obj_t os_remove(mp_obj_t path_in) {
|
||||
return vfs_proxy_call(MP_QSTR_remove, 1, &path_in);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_remove_obj, os_remove);
|
||||
|
||||
STATIC mp_obj_t os_rename(mp_obj_t path_old, mp_obj_t path_new) {
|
||||
mp_obj_t args[2];
|
||||
args[0] = path_old;
|
||||
args[1] = path_new;
|
||||
return vfs_proxy_call(MP_QSTR_rename, 2, args);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(os_rename_obj, os_rename);
|
||||
|
||||
STATIC mp_obj_t os_stat(mp_obj_t path_in) {
|
||||
return vfs_proxy_call(MP_QSTR_stat, 1, &path_in);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_stat_obj, os_stat);
|
||||
|
||||
STATIC mp_obj_t os_statvfs(mp_obj_t path_in) {
|
||||
return vfs_proxy_call(MP_QSTR_statvfs, 1, &path_in);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_statvfs_obj, os_statvfs);
|
||||
|
||||
STATIC mp_obj_t os_umount(void) {
|
||||
return vfs_proxy_call(MP_QSTR_umount, 0, NULL);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_umount_obj, os_umount);
|
||||
#endif
|
||||
|
||||
STATIC mp_obj_t os_urandom(mp_obj_t num) {
|
||||
mp_int_t n = mp_obj_get_int(num);
|
||||
vstr_t vstr;
|
||||
@ -166,16 +94,17 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
|
||||
#endif
|
||||
#if MICROPY_VFS_FAT
|
||||
{ MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&os_listdir_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&os_mkdir_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_rmdir), MP_ROM_PTR(&os_rmdir_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_chdir), MP_ROM_PTR(&os_chdir_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_getcwd), MP_ROM_PTR(&os_getcwd_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&os_remove_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&os_rename_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&os_stat_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&os_statvfs_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&os_umount_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&mp_vfs_listdir_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&mp_vfs_mkdir_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_rmdir), MP_ROM_PTR(&mp_vfs_rmdir_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_chdir), MP_ROM_PTR(&mp_vfs_chdir_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_getcwd), MP_ROM_PTR(&mp_vfs_getcwd_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&mp_vfs_remove_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_rename), MP_ROM_PTR(&mp_vfs_rename_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_stat), MP_ROM_PTR(&mp_vfs_stat_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&mp_vfs_statvfs_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&mp_vfs_umount_obj) },
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
#define MICROPY_MEM_STATS (0)
|
||||
#define MICROPY_DEBUG_PRINTERS (1)
|
||||
#define MICROPY_DEBUG_PRINTER_DEST mp_debug_print
|
||||
#define MICROPY_READER_FATFS (MICROPY_VFS_FAT)
|
||||
#define MICROPY_READER_VFS (MICROPY_VFS)
|
||||
#define MICROPY_ENABLE_GC (1)
|
||||
#define MICROPY_STACK_CHECK (1)
|
||||
#define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1)
|
||||
@ -94,13 +94,13 @@
|
||||
#define MICROPY_MODULE_FROZEN_LEXER mp_lexer_new_from_str32
|
||||
#define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool
|
||||
|
||||
#define MICROPY_VFS (1)
|
||||
#define MICROPY_FATFS_OO (1)
|
||||
#define MICROPY_FATFS_ENABLE_LFN (1)
|
||||
#define MICROPY_FATFS_RPATH (2)
|
||||
#define MICROPY_FATFS_VOLUMES (2)
|
||||
#define MICROPY_FATFS_MAX_SS (4096)
|
||||
#define MICROPY_FATFS_LFN_CODE_PAGE (437) /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */
|
||||
#define MICROPY_FSUSERMOUNT (1)
|
||||
#define MICROPY_VFS_FAT (1)
|
||||
#define MICROPY_ESP8266_APA102 (1)
|
||||
#define MICROPY_ESP8266_NEOPIXEL (1)
|
||||
@ -141,6 +141,11 @@ void *esp_native_code_commit(void*, size_t);
|
||||
#define mp_type_fileio fatfs_type_fileio
|
||||
#define mp_type_textio fatfs_type_textio
|
||||
|
||||
// use vfs's functions for import stat and builtin open
|
||||
#define mp_import_stat mp_vfs_import_stat
|
||||
#define mp_builtin_open mp_vfs_open
|
||||
#define mp_builtin_open_obj mp_vfs_open_obj
|
||||
|
||||
// extra built in names to add to the global namespace
|
||||
#define MICROPY_PORT_BUILTINS \
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \
|
||||
|
@ -5,8 +5,8 @@
|
||||
#undef MICROPY_EMIT_INLINE_XTENSA
|
||||
#define MICROPY_EMIT_INLINE_XTENSA (0)
|
||||
|
||||
#undef MICROPY_FSUSERMOUNT
|
||||
#define MICROPY_FSUSERMOUNT (0)
|
||||
#undef MICROPY_VFS
|
||||
#define MICROPY_VFS (0)
|
||||
#undef MICROPY_VFS_FAT
|
||||
#define MICROPY_VFS_FAT (0)
|
||||
|
||||
@ -25,3 +25,7 @@
|
||||
|
||||
#undef MICROPY_PY_FRAMEBUF
|
||||
#define MICROPY_PY_FRAMEBUF (0)
|
||||
|
||||
#undef mp_import_stat
|
||||
#undef mp_builtin_open
|
||||
#undef mp_builtin_open_obj
|
||||
|
@ -27,5 +27,5 @@
|
||||
// qstrs specific to this port, only needed if they aren't auto-generated
|
||||
|
||||
// Entries for sys.path
|
||||
Q(/)
|
||||
Q(/lib)
|
||||
Q(/flash)
|
||||
Q(/flash/lib)
|
||||
|
@ -37,8 +37,10 @@ def setup():
|
||||
print("Performing initial setup")
|
||||
wifi()
|
||||
uos.VfsFat.mkfs(bdev)
|
||||
vfs = uos.VfsFat(bdev, "")
|
||||
with open("/boot.py", "w") as f:
|
||||
vfs = uos.VfsFat(bdev)
|
||||
uos.mount(vfs, '/flash')
|
||||
uos.chdir('/flash')
|
||||
with open("boot.py", "w") as f:
|
||||
f.write("""\
|
||||
# This file is executed on every boot (including wake-boot from deepsleep)
|
||||
#import esp
|
||||
|
Loading…
Reference in New Issue
Block a user