Exemplo n.º 1
0
// FS formatting function
bool spiffs_format()
{
  spiffs_unmount();
  spiffs_config cfg = spiffs_get_storage_config();
  spiffs_format_internal(&cfg);
  spiffs_mount();
  return true;
}
Exemplo n.º 2
0
void HttpFirmwareUpdate::start()
{
	WDT.enable(false);
	spiffs_unmount();
	spiffs_config cfg = spiffs_get_storage_config();
	spiffs_format_internal(&cfg);
	pos = cfg.phys_addr;

	timer.initializeMs(500, TimerDelegate(&HttpFirmwareUpdate::onTimer, this)).start();
}
Exemplo n.º 3
0
bool spiffs_mount() {
    spiffs_config cfg = spiffs_get_storage_config();
    if (cfg.phys_addr == 0) {
        SYSTEM_ERROR("Can't start file system, wrong address");
        return false;
    }

    debugf("fs.start:%x, size:%d Kb\n", cfg.phys_addr, cfg.phys_size / 1024);

    cfg.hal_read_f = api_spiffs_read;
    cfg.hal_write_f = api_spiffs_write;
    cfg.hal_erase_f = api_spiffs_erase;

    uint32_t dat;
    bool writeFirst = false;
    flashmem_read(&dat, cfg.phys_addr, 4);

    if (dat == UINT32_MAX) {
        debugf("First init file system");
        if(!spiffs_format_internal()) {
            SYSTEM_ERROR("Can't format file system");
            return false;
        }
        writeFirst = true;
    }

    int res = SPIFFS_mount(&_filesystemStorageHandle,
                           &cfg,
                           spiffs_work_buf,
                           spiffs_fds,
                           sizeof(spiffs_fds),
                           spiffs_cache,
                           sizeof(spiffs_cache),
                           NULL);
    debugf("mount res: %d\n", res);

    if(res != 0) return false;

    if (writeFirst) {
        file_t fd = SPIFFS_open(&_filesystemStorageHandle, "initialize_fs_header.dat", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);
        SPIFFS_write(&_filesystemStorageHandle, fd, (u8_t *)"1", 1);
        SPIFFS_fremove(&_filesystemStorageHandle, fd);
        SPIFFS_close(&_filesystemStorageHandle, fd);
    }
    return true;
}
Exemplo n.º 4
0
bool spiffs_format_internal() {
    spiffs_config cfg = spiffs_get_storage_config();
    if (cfg.phys_addr == 0) {
        SYSTEM_ERROR("Can't format file system, wrong address");
        return false;
    }

    u32_t sect_first, sect_last;
    sect_first = flashmem_get_first_free_block_address();
    sect_last = flashmem_get_sector_of_address((u32_t)&_SPIFFS_end);
    debugf("sect_first: %x, sect_last: %x\n", sect_first, sect_last);
    while( sect_first <= sect_last ) {
        if(!flashmem_erase_sector( sect_first ++ ))
            return false;
    }
    return true;
}
Exemplo n.º 5
0
void spiffs_mount()
{
  spiffs_config cfg = spiffs_get_storage_config();
  spiffs_mount_internal(&cfg);
}