mirror of
https://github.com/pellepl/spiffs.git
synced 2026-09-13 04:30:05 +00:00
Specifying a non-zero SPI start physical address does not work #2
This commit is contained in:
+6
-6
@@ -52,7 +52,7 @@ s32_t spiffs_gc_quick(
|
|||||||
s32_t res = SPIFFS_OK;
|
s32_t res = SPIFFS_OK;
|
||||||
u32_t blocks = fs->block_count;
|
u32_t blocks = fs->block_count;
|
||||||
spiffs_block_ix cur_block = 0;
|
spiffs_block_ix cur_block = 0;
|
||||||
u32_t cur_block_addr = SPIFFS_CFG_PHYS_ADDR(fs);
|
u32_t cur_block_addr = 0;
|
||||||
int cur_entry = 0;
|
int cur_entry = 0;
|
||||||
spiffs_obj_id *obj_lu_buf = (spiffs_obj_id *)fs->lu_work;
|
spiffs_obj_id *obj_lu_buf = (spiffs_obj_id *)fs->lu_work;
|
||||||
|
|
||||||
@@ -194,7 +194,7 @@ s32_t spiffs_gc_erase_page_stats(
|
|||||||
while (res == SPIFFS_OK && obj_lookup_page < SPIFFS_OBJ_LOOKUP_PAGES(fs)) {
|
while (res == SPIFFS_OK && obj_lookup_page < SPIFFS_OBJ_LOOKUP_PAGES(fs)) {
|
||||||
int entry_offset = obj_lookup_page * entries_per_page;
|
int entry_offset = obj_lookup_page * entries_per_page;
|
||||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
|
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
|
||||||
0, SPIFFS_BLOCK_TO_PADDR(fs, bix) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page), SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
0, bix * SPIFFS_CFG_LOG_BLOCK_SZ(fs) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page), SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
||||||
// check each entry
|
// check each entry
|
||||||
while (res == SPIFFS_OK &&
|
while (res == SPIFFS_OK &&
|
||||||
cur_entry - entry_offset < entries_per_page && cur_entry < SPIFFS_PAGES_PER_BLOCK(fs)-SPIFFS_OBJ_LOOKUP_PAGES(fs)) {
|
cur_entry - entry_offset < entries_per_page && cur_entry < SPIFFS_PAGES_PER_BLOCK(fs)-SPIFFS_OBJ_LOOKUP_PAGES(fs)) {
|
||||||
@@ -223,7 +223,7 @@ s32_t spiffs_gc_find_candidate(
|
|||||||
s32_t res = SPIFFS_OK;
|
s32_t res = SPIFFS_OK;
|
||||||
u32_t blocks = fs->block_count;
|
u32_t blocks = fs->block_count;
|
||||||
spiffs_block_ix cur_block = 0;
|
spiffs_block_ix cur_block = 0;
|
||||||
u32_t cur_block_addr = SPIFFS_CFG_PHYS_ADDR(fs);
|
u32_t cur_block_addr = 0;
|
||||||
spiffs_obj_id *obj_lu_buf = (spiffs_obj_id *)fs->lu_work;
|
spiffs_obj_id *obj_lu_buf = (spiffs_obj_id *)fs->lu_work;
|
||||||
int cur_entry = 0;
|
int cur_entry = 0;
|
||||||
|
|
||||||
@@ -383,7 +383,7 @@ s32_t spiffs_gc_clean(spiffs *fs, spiffs_block_ix bix) {
|
|||||||
while (scan && res == SPIFFS_OK && obj_lookup_page < SPIFFS_OBJ_LOOKUP_PAGES(fs)) {
|
while (scan && res == SPIFFS_OK && obj_lookup_page < SPIFFS_OBJ_LOOKUP_PAGES(fs)) {
|
||||||
int entry_offset = obj_lookup_page * entries_per_page;
|
int entry_offset = obj_lookup_page * entries_per_page;
|
||||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
|
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
|
||||||
0, SPIFFS_BLOCK_TO_PADDR(fs, bix) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
|
0, bix * SPIFFS_CFG_LOG_BLOCK_SZ(fs) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
|
||||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
||||||
// check each entry
|
// check each entry
|
||||||
while (scan && res == SPIFFS_OK &&
|
while (scan && res == SPIFFS_OK &&
|
||||||
@@ -420,7 +420,7 @@ s32_t spiffs_gc_clean(spiffs *fs, spiffs_block_ix bix) {
|
|||||||
SPIFFS_CHECK_RES(res);
|
SPIFFS_CHECK_RES(res);
|
||||||
// move wipes obj_lu, reload it
|
// move wipes obj_lu, reload it
|
||||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
|
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
|
||||||
0, SPIFFS_BLOCK_TO_PADDR(fs, bix) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
|
0, bix * SPIFFS_CFG_LOG_BLOCK_SZ(fs) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
|
||||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
||||||
SPIFFS_CHECK_RES(res);
|
SPIFFS_CHECK_RES(res);
|
||||||
} else {
|
} else {
|
||||||
@@ -461,7 +461,7 @@ s32_t spiffs_gc_clean(spiffs *fs, spiffs_block_ix bix) {
|
|||||||
spiffs_cb_object_event(fs, 0, SPIFFS_EV_IX_UPD, obj_id, p_hdr.span_ix, new_pix, 0);
|
spiffs_cb_object_event(fs, 0, SPIFFS_EV_IX_UPD, obj_id, p_hdr.span_ix, new_pix, 0);
|
||||||
// move wipes obj_lu, reload it
|
// move wipes obj_lu, reload it
|
||||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
|
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
|
||||||
0, SPIFFS_BLOCK_TO_PADDR(fs, bix) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
|
0, bix * SPIFFS_CFG_LOG_BLOCK_SZ(fs) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
|
||||||
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
||||||
SPIFFS_CHECK_RES(res);
|
SPIFFS_CHECK_RES(res);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -697,7 +697,7 @@ s32_t SPIFFS_vis(spiffs *fs) {
|
|||||||
while (res == SPIFFS_OK && obj_lookup_page < SPIFFS_OBJ_LOOKUP_PAGES(fs)) {
|
while (res == SPIFFS_OK && obj_lookup_page < SPIFFS_OBJ_LOOKUP_PAGES(fs)) {
|
||||||
int entry_offset = obj_lookup_page * entries_per_page;
|
int entry_offset = obj_lookup_page * entries_per_page;
|
||||||
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
|
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
|
||||||
0, SPIFFS_BLOCK_TO_PADDR(fs, bix) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page), SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
0, bix * SPIFFS_CFG_LOG_BLOCK_SZ(fs) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page), SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
|
||||||
// check each entry
|
// check each entry
|
||||||
while (res == SPIFFS_OK &&
|
while (res == SPIFFS_OK &&
|
||||||
cur_entry - entry_offset < entries_per_page && cur_entry < SPIFFS_PAGES_PER_BLOCK(fs)-SPIFFS_OBJ_LOOKUP_PAGES(fs)) {
|
cur_entry - entry_offset < entries_per_page && cur_entry < SPIFFS_PAGES_PER_BLOCK(fs)-SPIFFS_OBJ_LOOKUP_PAGES(fs)) {
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ s32_t spiffs_obj_lu_find_entry_visitor(
|
|||||||
s32_t res = SPIFFS_OK;
|
s32_t res = SPIFFS_OK;
|
||||||
s32_t entry_count = fs->block_count * SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs);
|
s32_t entry_count = fs->block_count * SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs);
|
||||||
spiffs_block_ix cur_block = starting_block;
|
spiffs_block_ix cur_block = starting_block;
|
||||||
u32_t cur_block_addr = SPIFFS_BLOCK_TO_PADDR(fs, starting_block);
|
u32_t cur_block_addr = starting_block * SPIFFS_CFG_LOG_BLOCK_SZ(fs);
|
||||||
|
|
||||||
spiffs_obj_id *obj_lu_buf = (spiffs_obj_id *)fs->lu_work;
|
spiffs_obj_id *obj_lu_buf = (spiffs_obj_id *)fs->lu_work;
|
||||||
int cur_entry = starting_lu_entry;
|
int cur_entry = starting_lu_entry;
|
||||||
@@ -140,11 +140,11 @@ s32_t spiffs_obj_lu_find_entry_visitor(
|
|||||||
if (cur_entry >= SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs) - 1) {
|
if (cur_entry >= SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs) - 1) {
|
||||||
cur_entry = 0;
|
cur_entry = 0;
|
||||||
cur_block++;
|
cur_block++;
|
||||||
cur_block_addr = SPIFFS_BLOCK_TO_PADDR(fs, cur_block);
|
cur_block_addr = cur_block * SPIFFS_CFG_LOG_BLOCK_SZ(fs);
|
||||||
if (cur_block >= fs->block_count) {
|
if (cur_block >= fs->block_count) {
|
||||||
// block wrap
|
// block wrap
|
||||||
cur_block = 0;
|
cur_block = 0;
|
||||||
cur_block_addr = SPIFFS_CFG_PHYS_ADDR(fs);
|
cur_block_addr = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +203,7 @@ s32_t spiffs_obj_lu_find_entry_visitor(
|
|||||||
} else {
|
} else {
|
||||||
// block wrap
|
// block wrap
|
||||||
cur_block = 0;
|
cur_block = 0;
|
||||||
cur_block_addr = SPIFFS_CFG_PHYS_ADDR(fs);
|
cur_block_addr = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // per block
|
} // per block
|
||||||
|
|||||||
+10
-4
@@ -8,10 +8,16 @@
|
|||||||
#ifndef PARAMS_TEST_H_
|
#ifndef PARAMS_TEST_H_
|
||||||
#define PARAMS_TEST_H_
|
#define PARAMS_TEST_H_
|
||||||
|
|
||||||
#define FLASH_SIZE (2*1024*1024)
|
// total emulated spi flash size
|
||||||
#define SECTOR_SIZE 65536
|
#define PHYS_FLASH_SIZE (16*1024*1024)
|
||||||
#define LOG_BLOCK (SECTOR_SIZE*2)
|
// spiffs file system size
|
||||||
#define LOG_PAGE (SECTOR_SIZE/256)
|
#define SPIFFS_FLASH_SIZE (2*1024*1024)
|
||||||
|
// spiffs file system offset in emulated spi flash
|
||||||
|
#define SPIFFS_PHYS_ADDR (4*1024*1024)
|
||||||
|
|
||||||
|
#define SECTOR_SIZE 65536
|
||||||
|
#define LOG_BLOCK (SECTOR_SIZE*2)
|
||||||
|
#define LOG_PAGE (SECTOR_SIZE/256)
|
||||||
|
|
||||||
#define FD_BUF_SIZE 64*6
|
#define FD_BUF_SIZE 64*6
|
||||||
#define CACHE_BUF_SIZE (LOG_PAGE + 32)*8
|
#define CACHE_BUF_SIZE (LOG_PAGE + 32)*8
|
||||||
|
|||||||
+27
-5
@@ -24,9 +24,9 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
static unsigned char area[FLASH_SIZE];
|
static unsigned char area[PHYS_FLASH_SIZE];
|
||||||
|
|
||||||
static int erases[sizeof(area)/SECTOR_SIZE];
|
static int erases[SPIFFS_FLASH_SIZE/SECTOR_SIZE];
|
||||||
static char _path[256];
|
static char _path[256];
|
||||||
static u32_t bytes_rd = 0;
|
static u32_t bytes_rd = 0;
|
||||||
static u32_t bytes_wr = 0;
|
static u32_t bytes_wr = 0;
|
||||||
@@ -80,6 +80,14 @@ static s32_t _read(u32_t addr, u32_t size, u8_t *dst) {
|
|||||||
return SPIFFS_ERR_TEST;
|
return SPIFFS_ERR_TEST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (addr < SPIFFS_PHYS_ADDR) {
|
||||||
|
printf("FATAL read addr too low %08x < %08x\n", addr, SPIFFS_PHYS_ADDR);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if (addr + size > SPIFFS_PHYS_ADDR + SPIFFS_FLASH_SIZE) {
|
||||||
|
printf("FATAL read addr too high %08x + %08x > %08x\n", addr, size, SPIFFS_PHYS_ADDR + SPIFFS_FLASH_SIZE);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
memcpy(dst, &area[addr], size);
|
memcpy(dst, &area[addr], size);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -97,6 +105,16 @@ static s32_t _write(u32_t addr, u32_t size, u8_t *src) {
|
|||||||
return SPIFFS_ERR_TEST;
|
return SPIFFS_ERR_TEST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (addr < SPIFFS_PHYS_ADDR) {
|
||||||
|
printf("FATAL write addr too low %08x < %08x\n", addr, SPIFFS_PHYS_ADDR);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if (addr + size > SPIFFS_PHYS_ADDR + SPIFFS_FLASH_SIZE) {
|
||||||
|
printf("FATAL write addr too high %08x + %08x > %08x\n", addr, size, SPIFFS_PHYS_ADDR + SPIFFS_FLASH_SIZE);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
if (((addr + i) & (LOG_PAGE-1)) != offsetof(spiffs_page_header, flags)) {
|
if (((addr + i) & (LOG_PAGE-1)) != offsetof(spiffs_page_header, flags)) {
|
||||||
if (check_valid_flash && ((area[addr + i] ^ src[i]) & src[i])) {
|
if (check_valid_flash && ((area[addr + i] ^ src[i]) & src[i])) {
|
||||||
@@ -294,16 +312,17 @@ static void spiffs_check_cb_f(spiffs_check_type type, spiffs_check_report report
|
|||||||
}
|
}
|
||||||
|
|
||||||
void fs_reset() {
|
void fs_reset() {
|
||||||
memset(area, 0xff, sizeof(area));
|
memset(area, 0xcc, sizeof(area));
|
||||||
|
memset(&area[SPIFFS_PHYS_ADDR], 0xff, SPIFFS_FLASH_SIZE);
|
||||||
spiffs_config c;
|
spiffs_config c;
|
||||||
c.hal_erase_f = _erase;
|
c.hal_erase_f = _erase;
|
||||||
c.hal_read_f = _read;
|
c.hal_read_f = _read;
|
||||||
c.hal_write_f = _write;
|
c.hal_write_f = _write;
|
||||||
c.log_block_size = LOG_BLOCK;
|
c.log_block_size = LOG_BLOCK;
|
||||||
c.log_page_size = LOG_PAGE;
|
c.log_page_size = LOG_PAGE;
|
||||||
c.phys_addr = 0;
|
c.phys_addr = SPIFFS_PHYS_ADDR;
|
||||||
c.phys_erase_block = SECTOR_SIZE;
|
c.phys_erase_block = SECTOR_SIZE;
|
||||||
c.phys_size = sizeof(area);
|
c.phys_size = SPIFFS_FLASH_SIZE;
|
||||||
memset(erases,0,sizeof(erases));
|
memset(erases,0,sizeof(erases));
|
||||||
memset(_cache,0,sizeof(_cache));
|
memset(_cache,0,sizeof(_cache));
|
||||||
|
|
||||||
@@ -548,6 +567,9 @@ void _teardown() {
|
|||||||
printf(" fs consistency check:\n");
|
printf(" fs consistency check:\n");
|
||||||
SPIFFS_check(FS);
|
SPIFFS_check(FS);
|
||||||
clear_test_path();
|
clear_test_path();
|
||||||
|
|
||||||
|
//hexdump_mem(&area[SPIFFS_PHYS_ADDR - 16], 32);
|
||||||
|
//hexdump_mem(&area[SPIFFS_PHYS_ADDR + SPIFFS_FLASH_SIZE - 16], 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
u32_t tfile_get_size(tfile_size s) {
|
u32_t tfile_get_size(tfile_size s) {
|
||||||
|
|||||||
Reference in New Issue
Block a user