mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
SPIFFS : FIXES FS corruption against high numbero f current losses, high number of files manipulation. FIXES LOG_BLOCK erasing handlers. FIXES Garbage Collector. Overall, SPIFFS should now be WAY MORE resilient to any form of misbehavior. In case of corrupted filesystem (should still be readable !), spamming 'mem spiffs check' from the client will ensure at least 2 new free 4k blocks each tile (if number of LOG_PAGE available is enough) and in the same pass will move/reorganize the LOG_PAGES of contextual blocks. Yiha
This commit is contained in:
parent
1da98c7aa6
commit
961f98c125
8 changed files with 100 additions and 69 deletions
|
@ -22,9 +22,11 @@
|
|||
// case, will ensure a flush by rollbacking to previous Unmounted state
|
||||
#define RDV40_SPIFFS_CACHE_SZ ((LOG_PAGE_SIZE + 32) * 4)
|
||||
#define SPIFFS_FD_SIZE (32)
|
||||
#define RDV40_SPIFFS_MAX_FD (2)
|
||||
#define RDV40_SPIFFS_MAX_FD (3)
|
||||
#define RDV40_SPIFFS_FDBUF_SZ (SPIFFS_FD_SIZE * RDV40_SPIFFS_MAX_FD)
|
||||
|
||||
#define RDV40_LLERASE_BLOCKSIZE (64*1024)
|
||||
|
||||
#define RDV40_SPIFFS_LAZY_HEADER \
|
||||
int changed = 0; \
|
||||
if ((level == RDV40_SPIFFS_SAFETY_LAZY) || (level == RDV40_SPIFFS_SAFETY_SAFE)) { \
|
||||
|
@ -43,12 +45,6 @@
|
|||
RDV40_SPIFFS_SAFE_FOOTER
|
||||
|
||||
#include "spiffs.h"
|
||||
#include "flashmem.h"
|
||||
#include "dbprint.h"
|
||||
#include "printf.h"
|
||||
#include "common.h"
|
||||
#include "string.h"
|
||||
#include "BigBuf.h"
|
||||
|
||||
///// FLASH LEVEL R/W/E operations for feeding SPIFFS Driver/////////////////
|
||||
static s32_t rdv40_spiffs_llread(u32_t addr, u32_t size, u8_t *dst) {
|
||||
|
@ -70,28 +66,29 @@ static s32_t rdv40_spiffs_llwrite(u32_t addr, u32_t size, u8_t *src) {
|
|||
|
||||
static s32_t rdv40_spiffs_llerase(u32_t addr, u32_t size) {
|
||||
|
||||
|
||||
uint8_t erased = 0;
|
||||
|
||||
if (!FlashInit()) {
|
||||
return 130;
|
||||
}
|
||||
|
||||
uint32_t bytes_erased = 0, bytes_remaining = size;
|
||||
while (bytes_remaining > 0) {
|
||||
|
||||
addr += bytes_erased;
|
||||
if (DBGLEVEL > 2) Dbprintf("LLERASEDBG : Orig addr : %d\n", addr);
|
||||
uint8_t block, sector = 0;
|
||||
block = addr / RDV40_LLERASE_BLOCKSIZE;
|
||||
if (block){
|
||||
addr = addr - (block*RDV40_LLERASE_BLOCKSIZE);
|
||||
}
|
||||
if (DBGLEVEL > 2) Dbprintf("LLERASEDBG : Result addr : %d\n", addr);
|
||||
sector = addr / SPIFFS_CFG_LOG_BLOCK_SZ;
|
||||
Flash_CheckBusy(BUSY_TIMEOUT);
|
||||
Flash_WriteEnable();
|
||||
FlashSendByte(SECTORERASE);
|
||||
Flash_TransferAdresse(addr);
|
||||
FlashSendLastByte(0);
|
||||
|
||||
bytes_remaining -= 4096;
|
||||
bytes_erased += 4096;
|
||||
}
|
||||
if (DBGLEVEL > 2) Dbprintf("LLERASEDBG : block : %d, sector : %d \n", block, sector);
|
||||
erased = Flash_Erase4k(block, sector);
|
||||
|
||||
Flash_CheckBusy(BUSY_TIMEOUT);
|
||||
FlashStop();
|
||||
|
||||
return SPIFFS_OK;
|
||||
return SPIFFS_OK == erased ;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -162,6 +159,15 @@ int rdv40_spiffs_unmount() {
|
|||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int rdv40_spiffs_check() {
|
||||
rdv40_spiffs_lazy_mount();
|
||||
SPIFFS_check(&fs);
|
||||
SPIFFS_gc_quick(&fs,0);
|
||||
rdv40_spiffs_lazy_unmount();
|
||||
rdv40_spiffs_lazy_mount();
|
||||
return SPIFFS_gc(&fs,8192) == SPIFFS_OK;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///// Base RDV40_SPIFFS_SAFETY_NORMAL operations////////////////////////////////
|
||||
|
@ -533,21 +539,16 @@ void rdv40_spiffs_safe_print_fsinfo() {
|
|||
rdv40_spiffs_fsinfo fsinfo;
|
||||
rdv40_spiffs_getfsinfo(&fsinfo, RDV40_SPIFFS_SAFETY_SAFE);
|
||||
DbpString(_BLUE_("Flash Memory FileSystem Info (SPIFFS)"));
|
||||
// Dbprintf("-------------------------------------");
|
||||
Dbprintf(" Logical Block Size........." _YELLOW_("%d")"bytes", fsinfo.blockSize);
|
||||
Dbprintf(" Logical Page Size.........." _YELLOW_("%d")"bytes", fsinfo.pageSize);
|
||||
Dbprintf("");
|
||||
Dbprintf(" Max Open Files............." _YELLOW_("%d")"file descriptors", fsinfo.maxOpenFiles);
|
||||
Dbprintf(" Max Path Length............" _YELLOW_("%d")"chars", fsinfo.maxPathLength);
|
||||
// DbpString(_BLUE_("Details"));
|
||||
DbpString("");
|
||||
Dbprintf(" Filesystem\tSize\tUsed\tAvailable\tUse%\tMounted on");
|
||||
Dbprintf(" spiffs \t%d B\t%d B\t%d B\t\t"_YELLOW_("%d%")"\t/"
|
||||
, fsinfo.totalBytes
|
||||
, fsinfo.usedBytes
|
||||
, fsinfo.freeBytes
|
||||
, fsinfo.usedPercent
|
||||
);
|
||||
Dbprintf("-------------------------------------");
|
||||
Dbprintf("* Filesystem Logical Block Size.........%d bytes", fsinfo.blockSize);
|
||||
Dbprintf("* Filesystem Logical Page Size..........%d bytes", fsinfo.pageSize);
|
||||
Dbprintf("--");
|
||||
Dbprintf("* Filesystem Max Open Files.............%d file descriptors", fsinfo.maxOpenFiles);
|
||||
Dbprintf("* Filesystem Max Path Length............%d chars", fsinfo.maxPathLength);
|
||||
Dbprintf("--");
|
||||
Dbprintf("Filesystem\tSize\tUsed\tAvailable\tUse%\tMounted on");
|
||||
Dbprintf("spiffs\t%dB\t%dB\t%dB\t\t%d%\t/", fsinfo.totalBytes, fsinfo.usedBytes, fsinfo.freeBytes,
|
||||
fsinfo.usedPercent);
|
||||
}
|
||||
|
||||
// this function is safe and WILL rollback since it is only a PRINTING function,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue