Skip to content

Commit f57be61

Browse files
aykevlglennrub
authored andcommitted
ports/nrf: Add compile switch to disable VFS.
This saves about 17kB.
1 parent 61b6fae commit f57be61

4 files changed

Lines changed: 29 additions & 33 deletions

File tree

ports/nrf/builtin_open.c

Lines changed: 0 additions & 30 deletions
This file was deleted.

ports/nrf/main.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <string.h>
3131

3232
#include "py/nlr.h"
33+
#include "py/mperrno.h"
3334
#include "py/lexer.h"
3435
#include "py/parse.h"
3536
#include "py/obj.h"
@@ -213,6 +214,21 @@ pin_init0();
213214
return 0;
214215
}
215216

217+
#if !MICROPY_VFS
218+
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
219+
mp_raise_OSError(MP_ENOENT);
220+
}
221+
222+
mp_import_stat_t mp_import_stat(const char *path) {
223+
return MP_IMPORT_STAT_NO_EXIST;
224+
}
225+
226+
STATIC mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
227+
mp_raise_OSError(MP_EPERM);
228+
}
229+
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
230+
#endif
231+
216232
void HardFault_Handler(void)
217233
{
218234
#if NRF52

ports/nrf/modules/uos/moduos.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ STATIC mp_obj_t os_uname(void) {
7979
}
8080
STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname);
8181

82+
#if MICROPY_VFS
8283
/// \function sync()
8384
/// Sync all filesystems.
8485
STATIC mp_obj_t os_sync(void) {
@@ -89,6 +90,7 @@ STATIC mp_obj_t os_sync(void) {
8990
return mp_const_none;
9091
}
9192
MP_DEFINE_CONST_FUN_OBJ_0(mod_os_sync_obj, os_sync);
93+
#endif
9294

9395
#if MICROPY_HW_ENABLE_RNG
9496
/// \function urandom(n)
@@ -133,6 +135,7 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
133135

134136
{ MP_ROM_QSTR(MP_QSTR_uname), MP_ROM_PTR(&os_uname_obj) },
135137

138+
#if MICROPY_VFS
136139
{ MP_ROM_QSTR(MP_QSTR_chdir), MP_ROM_PTR(&mp_vfs_chdir_obj) },
137140
{ MP_ROM_QSTR(MP_QSTR_getcwd), MP_ROM_PTR(&mp_vfs_getcwd_obj) },
138141
{ MP_ROM_QSTR(MP_QSTR_listdir), MP_ROM_PTR(&mp_vfs_listdir_obj) },
@@ -145,6 +148,7 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
145148
{ MP_ROM_QSTR(MP_QSTR_unlink), MP_ROM_PTR(&mp_vfs_remove_obj) }, // unlink aliases to remove
146149

147150
{ MP_ROM_QSTR(MP_QSTR_sync), MP_ROM_PTR(&mod_os_sync_obj) },
151+
#endif
148152

149153
/// \constant sep - separation character used in paths
150154
{ MP_ROM_QSTR(MP_QSTR_sep), MP_ROM_QSTR(MP_QSTR__slash_) },
@@ -155,9 +159,11 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
155159

156160
// these are MicroPython extensions
157161
{ MP_ROM_QSTR(MP_QSTR_dupterm), MP_ROM_PTR(&mod_os_dupterm_obj) },
162+
#if MICROPY_VFS
158163
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) },
159164
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&mp_vfs_umount_obj) },
160165
{ MP_ROM_QSTR(MP_QSTR_VfsFat), MP_ROM_PTR(&mp_fat_vfs_type) },
166+
#endif
161167
};
162168

163169
STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table);

ports/nrf/mpconfigport.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@
3030
#include <mpconfigboard.h>
3131

3232
// options to control how MicroPython is built
33+
#ifndef MICROPY_VFS
34+
#define MICROPY_VFS (1)
35+
#endif
36+
#define MICROPY_VFS_FAT (MICROPY_VFS)
3337
#define MICROPY_ALLOC_PATH_MAX (512)
3438
#define MICROPY_PERSISTENT_CODE_LOAD (0)
3539
#define MICROPY_EMIT_THUMB (0)
3640
#define MICROPY_EMIT_INLINE_THUMB (0)
3741
#define MICROPY_COMP_MODULE_CONST (0)
3842
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0)
39-
#define MICROPY_READER_VFS (1)
43+
#define MICROPY_READER_VFS (MICROPY_VFS)
4044
#define MICROPY_ENABLE_GC (1)
4145
#define MICROPY_ENABLE_FINALISER (1)
4246
#define MICROPY_STACK_CHECK (0)
@@ -54,8 +58,6 @@
5458
#define MICROPY_OPT_COMPUTED_GOTO (0)
5559
#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (0)
5660
#define MICROPY_OPT_MPZ_BITWISE (0)
57-
#define MICROPY_VFS (1)
58-
#define MICROPY_VFS_FAT (1)
5961

6062
// fatfs configuration used in ffconf.h
6163
#define MICROPY_FATFS_ENABLE_LFN (1)
@@ -69,9 +71,11 @@
6971
#define mp_type_textio fatfs_type_textio
7072

7173
// use vfs's functions for import stat and builtin open
74+
#if MICROPY_VFS
7275
#define mp_import_stat mp_vfs_import_stat
7376
#define mp_builtin_open mp_vfs_open
7477
#define mp_builtin_open_obj mp_vfs_open_obj
78+
#endif
7579

7680
#define MICROPY_STREAMS_NON_BLOCK (1)
7781
#define MICROPY_MODULE_WEAK_LINKS (1)

0 commit comments

Comments
 (0)