Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Whether the current version have file system function support #59

@YanMinge

Description

@YanMinge

when setup the system, I can get the log:

could not open file 'boot.py' for reading
could not open file 'main.py' for reading

and I try to add a function mptask_init_sflash_filesystem like pycom-micropython, I use the ff from
micropython-esp32\lib\oofatfs

STATIC void mptask_init_sflash_filesystem (void) {
    FILINFO fno;

    // Initialise the local flash filesystem.
    // Create it if needed, and mount in on /flash.
    FRESULT res = f_mount(&sflash_fatfs);
    if (res == FR_NO_FILESYSTEM) {
        // no filesystem, so create a fresh one
        res = f_mkfs(&sflash_fatfs, FM_SFD | FM_FAT, 0, NULL, 0);
        if (res != FR_OK) {
            printf("no file sys,failed to create flash\n");
        }
        // create empty main.py
        mptask_create_main_py();
    }
    else if (res == FR_OK) {
        // mount sucessful
        if (FR_OK != f_stat(&sflash_fatfs,"/flash/main.py", &fno)) {
            // create empty main.py
            mptask_create_main_py();
        }
    } else {
        printf("failed to create flash,res:%d\n",res);
    }

    // create /flash/sys, /flash/lib and /flash/cert if they don't exist
    if (FR_OK != f_chdir (&sflash_fatfs,"/flash/sys")) {
        f_mkdir(&sflash_fatfs,"/flash/sys");
    }
    if (FR_OK != f_chdir (&sflash_fatfs,"/flash/lib")) {
        f_mkdir(&sflash_fatfs,"/flash/lib");
    }
    if (FR_OK != f_chdir (&sflash_fatfs,"/flash/cert")) {
        f_mkdir(&sflash_fatfs,"flash/cert");
    }

    f_chdir (&sflash_fatfs,"/flash");

    // make sure we have a /flash/boot.py. Create it if needed.
    res = f_stat(&sflash_fatfs,"/flash/boot.py", &fno);
    if (res == FR_OK) {
        if (fno.fattrib & AM_DIR) {
            // exists as a directory
            // TODO handle this case
            // see http://elm-chan.org/fsw/ff/img/app2.c for a "rm -rf" implementation
        } else {
            // exists as a file, good!
        }
    } else {
        // doesn't exist, create fresh file
        FIL fp;
        f_open(&sflash_fatfs,&fp, "/flash/boot.py", FA_WRITE | FA_CREATE_ALWAYS);
        UINT n;
        f_write(&fp, fresh_boot_py, sizeof(fresh_boot_py) - 1 /* don't count null terminator */, &n);
        // TODO check we could write n bytes
        f_close(&fp);
    }
}

f_mount will return error: FR_NOT_READY, /* (3) The physical drive cannot work */
I would like to ask how to operate the file additions, deletions, modify..?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions