Skip to content

Commit 97263d7

Browse files
committed
Specifying a non-zero SPI start physical address does not work #2
1 parent fb69571 commit 97263d7

5 files changed

Lines changed: 48 additions & 20 deletions

File tree

src/spiffs_gc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ s32_t spiffs_gc_quick(
5252
s32_t res = SPIFFS_OK;
5353
u32_t blocks = fs->block_count;
5454
spiffs_block_ix cur_block = 0;
55-
u32_t cur_block_addr = SPIFFS_CFG_PHYS_ADDR(fs);
55+
u32_t cur_block_addr = 0;
5656
int cur_entry = 0;
5757
spiffs_obj_id *obj_lu_buf = (spiffs_obj_id *)fs->lu_work;
5858

@@ -194,7 +194,7 @@ s32_t spiffs_gc_erase_page_stats(
194194
while (res == SPIFFS_OK && obj_lookup_page < SPIFFS_OBJ_LOOKUP_PAGES(fs)) {
195195
int entry_offset = obj_lookup_page * entries_per_page;
196196
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
197-
0, SPIFFS_BLOCK_TO_PADDR(fs, bix) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page), SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
197+
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);
198198
// check each entry
199199
while (res == SPIFFS_OK &&
200200
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(
223223
s32_t res = SPIFFS_OK;
224224
u32_t blocks = fs->block_count;
225225
spiffs_block_ix cur_block = 0;
226-
u32_t cur_block_addr = SPIFFS_CFG_PHYS_ADDR(fs);
226+
u32_t cur_block_addr = 0;
227227
spiffs_obj_id *obj_lu_buf = (spiffs_obj_id *)fs->lu_work;
228228
int cur_entry = 0;
229229

@@ -383,7 +383,7 @@ s32_t spiffs_gc_clean(spiffs *fs, spiffs_block_ix bix) {
383383
while (scan && res == SPIFFS_OK && obj_lookup_page < SPIFFS_OBJ_LOOKUP_PAGES(fs)) {
384384
int entry_offset = obj_lookup_page * entries_per_page;
385385
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
386-
0, SPIFFS_BLOCK_TO_PADDR(fs, bix) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
386+
0, bix * SPIFFS_CFG_LOG_BLOCK_SZ(fs) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
387387
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
388388
// check each entry
389389
while (scan && res == SPIFFS_OK &&
@@ -420,7 +420,7 @@ s32_t spiffs_gc_clean(spiffs *fs, spiffs_block_ix bix) {
420420
SPIFFS_CHECK_RES(res);
421421
// move wipes obj_lu, reload it
422422
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
423-
0, SPIFFS_BLOCK_TO_PADDR(fs, bix) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
423+
0, bix * SPIFFS_CFG_LOG_BLOCK_SZ(fs) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
424424
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
425425
SPIFFS_CHECK_RES(res);
426426
} else {
@@ -461,7 +461,7 @@ s32_t spiffs_gc_clean(spiffs *fs, spiffs_block_ix bix) {
461461
spiffs_cb_object_event(fs, 0, SPIFFS_EV_IX_UPD, obj_id, p_hdr.span_ix, new_pix, 0);
462462
// move wipes obj_lu, reload it
463463
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
464-
0, SPIFFS_BLOCK_TO_PADDR(fs, bix) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
464+
0, bix * SPIFFS_CFG_LOG_BLOCK_SZ(fs) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page),
465465
SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
466466
SPIFFS_CHECK_RES(res);
467467
} else {

src/spiffs_hydrogen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ s32_t SPIFFS_vis(spiffs *fs) {
697697
while (res == SPIFFS_OK && obj_lookup_page < SPIFFS_OBJ_LOOKUP_PAGES(fs)) {
698698
int entry_offset = obj_lookup_page * entries_per_page;
699699
res = _spiffs_rd(fs, SPIFFS_OP_T_OBJ_LU | SPIFFS_OP_C_READ,
700-
0, SPIFFS_BLOCK_TO_PADDR(fs, bix) + SPIFFS_PAGE_TO_PADDR(fs, obj_lookup_page), SPIFFS_CFG_LOG_PAGE_SZ(fs), fs->lu_work);
700+
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);
701701
// check each entry
702702
while (res == SPIFFS_OK &&
703703
cur_entry - entry_offset < entries_per_page && cur_entry < SPIFFS_PAGES_PER_BLOCK(fs)-SPIFFS_OBJ_LOOKUP_PAGES(fs)) {

src/spiffs_nucleus.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ s32_t spiffs_obj_lu_find_entry_visitor(
130130
s32_t res = SPIFFS_OK;
131131
s32_t entry_count = fs->block_count * SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs);
132132
spiffs_block_ix cur_block = starting_block;
133-
u32_t cur_block_addr = SPIFFS_BLOCK_TO_PADDR(fs, starting_block);
133+
u32_t cur_block_addr = starting_block * SPIFFS_CFG_LOG_BLOCK_SZ(fs);
134134

135135
spiffs_obj_id *obj_lu_buf = (spiffs_obj_id *)fs->lu_work;
136136
int cur_entry = starting_lu_entry;
@@ -140,11 +140,11 @@ s32_t spiffs_obj_lu_find_entry_visitor(
140140
if (cur_entry >= SPIFFS_OBJ_LOOKUP_MAX_ENTRIES(fs) - 1) {
141141
cur_entry = 0;
142142
cur_block++;
143-
cur_block_addr = SPIFFS_BLOCK_TO_PADDR(fs, cur_block);
143+
cur_block_addr = cur_block * SPIFFS_CFG_LOG_BLOCK_SZ(fs);
144144
if (cur_block >= fs->block_count) {
145145
// block wrap
146146
cur_block = 0;
147-
cur_block_addr = SPIFFS_CFG_PHYS_ADDR(fs);
147+
cur_block_addr = 0;
148148
}
149149
}
150150

@@ -203,7 +203,7 @@ s32_t spiffs_obj_lu_find_entry_visitor(
203203
} else {
204204
// block wrap
205205
cur_block = 0;
206-
cur_block_addr = SPIFFS_CFG_PHYS_ADDR(fs);
206+
cur_block_addr = 0;
207207
}
208208
}
209209
} // per block

src/test/params_test.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@
88
#ifndef PARAMS_TEST_H_
99
#define PARAMS_TEST_H_
1010

11-
#define FLASH_SIZE (2*1024*1024)
12-
#define SECTOR_SIZE 65536
13-
#define LOG_BLOCK (SECTOR_SIZE*2)
14-
#define LOG_PAGE (SECTOR_SIZE/256)
11+
// total emulated spi flash size
12+
#define PHYS_FLASH_SIZE (16*1024*1024)
13+
// spiffs file system size
14+
#define SPIFFS_FLASH_SIZE (2*1024*1024)
15+
// spiffs file system offset in emulated spi flash
16+
#define SPIFFS_PHYS_ADDR (4*1024*1024)
17+
18+
#define SECTOR_SIZE 65536
19+
#define LOG_BLOCK (SECTOR_SIZE*2)
20+
#define LOG_PAGE (SECTOR_SIZE/256)
1521

1622
#define FD_BUF_SIZE 64*6
1723
#define CACHE_BUF_SIZE (LOG_PAGE + 32)*8

src/test/test_spiffs.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
#include <dirent.h>
2525
#include <unistd.h>
2626

27-
static unsigned char area[FLASH_SIZE];
27+
static unsigned char area[PHYS_FLASH_SIZE];
2828

29-
static int erases[sizeof(area)/SECTOR_SIZE];
29+
static int erases[SPIFFS_FLASH_SIZE/SECTOR_SIZE];
3030
static char _path[256];
3131
static u32_t bytes_rd = 0;
3232
static u32_t bytes_wr = 0;
@@ -80,6 +80,14 @@ static s32_t _read(u32_t addr, u32_t size, u8_t *dst) {
8080
return SPIFFS_ERR_TEST;
8181
}
8282
}
83+
if (addr < SPIFFS_PHYS_ADDR) {
84+
printf("FATAL read addr too low %08x < %08x\n", addr, SPIFFS_PHYS_ADDR);
85+
exit(0);
86+
}
87+
if (addr + size > SPIFFS_PHYS_ADDR + SPIFFS_FLASH_SIZE) {
88+
printf("FATAL read addr too high %08x + %08x > %08x\n", addr, size, SPIFFS_PHYS_ADDR + SPIFFS_FLASH_SIZE);
89+
exit(0);
90+
}
8391
memcpy(dst, &area[addr], size);
8492
return 0;
8593
}
@@ -97,6 +105,16 @@ static s32_t _write(u32_t addr, u32_t size, u8_t *src) {
97105
return SPIFFS_ERR_TEST;
98106
}
99107
}
108+
109+
if (addr < SPIFFS_PHYS_ADDR) {
110+
printf("FATAL write addr too low %08x < %08x\n", addr, SPIFFS_PHYS_ADDR);
111+
exit(0);
112+
}
113+
if (addr + size > SPIFFS_PHYS_ADDR + SPIFFS_FLASH_SIZE) {
114+
printf("FATAL write addr too high %08x + %08x > %08x\n", addr, size, SPIFFS_PHYS_ADDR + SPIFFS_FLASH_SIZE);
115+
exit(0);
116+
}
117+
100118
for (i = 0; i < size; i++) {
101119
if (((addr + i) & (LOG_PAGE-1)) != offsetof(spiffs_page_header, flags)) {
102120
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
294312
}
295313

296314
void fs_reset() {
297-
memset(area, 0xff, sizeof(area));
315+
memset(area, 0xcc, sizeof(area));
316+
memset(&area[SPIFFS_PHYS_ADDR], 0xff, SPIFFS_FLASH_SIZE);
298317
spiffs_config c;
299318
c.hal_erase_f = _erase;
300319
c.hal_read_f = _read;
301320
c.hal_write_f = _write;
302321
c.log_block_size = LOG_BLOCK;
303322
c.log_page_size = LOG_PAGE;
304-
c.phys_addr = 0;
323+
c.phys_addr = SPIFFS_PHYS_ADDR;
305324
c.phys_erase_block = SECTOR_SIZE;
306-
c.phys_size = sizeof(area);
325+
c.phys_size = SPIFFS_FLASH_SIZE;
307326
memset(erases,0,sizeof(erases));
308327
memset(_cache,0,sizeof(_cache));
309328

@@ -548,6 +567,9 @@ void _teardown() {
548567
printf(" fs consistency check:\n");
549568
SPIFFS_check(FS);
550569
clear_test_path();
570+
571+
//hexdump_mem(&area[SPIFFS_PHYS_ADDR - 16], 32);
572+
//hexdump_mem(&area[SPIFFS_PHYS_ADDR + SPIFFS_FLASH_SIZE - 16], 32);
551573
}
552574

553575
u32_t tfile_get_size(tfile_size s) {

0 commit comments

Comments
 (0)