rp2: Enable VfsMap.

Signed-off-by: Damien George <damien@micropython.org>
pull/8381/head
Damien George 2022-03-04 10:57:38 +11:00
rodzic c31503c203
commit 56d038088f
3 zmienionych plików z 29 dodań i 1 usunięć

Wyświetl plik

@ -1,7 +1,13 @@
import vfs
import sys
import machine, rp2
mapfs = rp2.Flash("mapfs")
vfs.mount(vfs.VfsMap(mapfs.ioctl(0x100, 0), mapfs), "/mapfs")
sys.path.insert(0, "/mapfs")
# Try to mount the filesystem, and format the flash if it doesn't exist.
# Note: the flash requires the programming size to be aligned to 256 bytes.
bdev = rp2.Flash()
@ -12,4 +18,4 @@ except:
fs = vfs.VfsLfs2(bdev, progsize=256)
vfs.mount(fs, "/")
del vfs, bdev, fs
del vfs, sys, bdev, fs, mapfs

Wyświetl plik

@ -146,6 +146,7 @@
#define MICROPY_VFS (1)
#define MICROPY_VFS_LFS2 (1)
#define MICROPY_VFS_FAT (1)
#define MICROPY_VFS_MAP (1)
#define MICROPY_SSL_MBEDTLS (1)
#define MICROPY_PY_LWIP_SOCK_RAW (MICROPY_PY_LWIP)

Wyświetl plik

@ -28,6 +28,7 @@
#include "py/mphal.h"
#include "py/runtime.h"
#include "py/mperrno.h"
#include "extmod/vfs.h"
#include "modrp2.h"
#include "hardware/flash.h"
@ -44,6 +45,9 @@ static_assert(MICROPY_HW_FLASH_STORAGE_BYTES % 4096 == 0, "Flash storage size mu
#define MICROPY_HW_FLASH_STORAGE_BASE (PICO_FLASH_SIZE_BYTES - MICROPY_HW_FLASH_STORAGE_BYTES)
#endif
#define MICROPY_HW_MAPFS_BASE (512 * 1024) // leave 512k for firmware...
#define MICROPY_HW_MAPFS_BYTES (MICROPY_HW_FLASH_STORAGE_BASE - MICROPY_HW_MAPFS_BASE)
static_assert(MICROPY_HW_FLASH_STORAGE_BYTES <= PICO_FLASH_SIZE_BYTES, "MICROPY_HW_FLASH_STORAGE_BYTES too big");
static_assert(MICROPY_HW_FLASH_STORAGE_BASE + MICROPY_HW_FLASH_STORAGE_BYTES <= PICO_FLASH_SIZE_BYTES, "MICROPY_HW_FLASH_STORAGE_BYTES too big");
@ -53,6 +57,12 @@ typedef struct _rp2_flash_obj_t {
uint32_t flash_size;
} rp2_flash_obj_t;
static rp2_flash_obj_t rp2_flash_mapfs_obj = {
.base = { &rp2_flash_type },
.flash_base = MICROPY_HW_MAPFS_BASE,
.flash_size = MICROPY_HW_MAPFS_BYTES,
};
static rp2_flash_obj_t rp2_flash_obj = {
.base = { &rp2_flash_type },
.flash_base = MICROPY_HW_FLASH_STORAGE_BASE,
@ -87,6 +97,15 @@ static void end_critical_flash_section(uint32_t state) {
}
static mp_obj_t rp2_flash_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
if (n_args == 1 && n_kw == 0 && mp_obj_is_str(all_args[0])) {
if (mp_obj_str_get_qstr(all_args[0]) == MP_QSTR_mapfs) {
if (MICROPY_HW_MAPFS_BYTES <= 0) {
mp_raise_OSError(MP_ENODEV);
}
return MP_OBJ_FROM_PTR(&rp2_flash_mapfs_obj);
}
}
// Parse arguments
enum { ARG_start, ARG_len };
static const mp_arg_t allowed_args[] = {
@ -190,6 +209,8 @@ static mp_obj_t rp2_flash_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t arg_
// TODO check return value
return MP_OBJ_NEW_SMALL_INT(0);
}
case 0x100: // mmap
return mp_obj_new_int(XIP_BASE + self->flash_base);
default:
return mp_const_none;
}