Example #1
0
static void spiffs_mount_internal(spiffs_config *cfg)
{
  if (cfg->phys_addr == 0)
  {
	  SYSTEM_ERROR("Can't start file system, wrong address");
	  return;
  }

  debugf("fs.start: size:%d Kb, offset:0x%X\n", cfg->phys_size / 1024, cfg->phys_addr - INTERNAL_FLASH_START_ADDRESS);

  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);
  //debugf("%X", dat);

  if (dat == UINT32_MAX)
  {
	  debugf("First init file system");
	  spiffs_format_internal(cfg);
	  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 (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);
  }

  //dat=0;
  //flashmem_read(&dat, cfg.phys_addr, 4);
  //debugf("%X", dat);
}
Example #2
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;
}
Example #3
0
static s32_t api_spiffs_read(u32_t addr, u32_t size, u8_t *dst) {
    flashmem_read(dst, addr, size);
    return SPIFFS_OK;
}