mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-07-30 11:39:14 -07:00
make style
This commit is contained in:
parent
b4d54ae0a2
commit
9beabaabf5
29 changed files with 4784 additions and 4778 deletions
|
@ -102,7 +102,7 @@ void ReadLastTagFromFlash() {
|
||||||
uint8_t *mem = BigBuf_malloc(size);
|
uint8_t *mem = BigBuf_malloc(size);
|
||||||
|
|
||||||
//this one will handle filetype (symlink or not) and resolving by itself
|
//this one will handle filetype (symlink or not) and resolving by itself
|
||||||
rdv40_spiffs_read_as_filetype((char *)HFCOLIN_LASTTAG_SYMLINK,(uint8_t *)mem,len, RDV40_SPIFFS_SAFETY_SAFE);
|
rdv40_spiffs_read_as_filetype((char *)HFCOLIN_LASTTAG_SYMLINK, (uint8_t *)mem, len, RDV40_SPIFFS_SAFETY_SAFE);
|
||||||
|
|
||||||
emlSetMem(mem, 0, 64);
|
emlSetMem(mem, 0, 64);
|
||||||
|
|
||||||
|
@ -126,14 +126,14 @@ void WriteTagToFlash(uint32_t uid, size_t size) {
|
||||||
|
|
||||||
char dest[SPIFFS_OBJ_NAME_LEN];
|
char dest[SPIFFS_OBJ_NAME_LEN];
|
||||||
uint8_t buid[4];
|
uint8_t buid[4];
|
||||||
num_to_bytes(uid,4,buid);
|
num_to_bytes(uid, 4, buid);
|
||||||
sprintf(dest,"hf_colin/mf_%02x%02x%02x%02x.bin",buid[0],buid[1],buid[2],buid[3]);
|
sprintf(dest, "hf_colin/mf_%02x%02x%02x%02x.bin", buid[0], buid[1], buid[2], buid[3]);
|
||||||
|
|
||||||
// TODO : by using safe function for multiple writes we are both breaking cache mecanisms and making useless and unoptimized mount operations
|
// TODO : by using safe function for multiple writes we are both breaking cache mecanisms and making useless and unoptimized mount operations
|
||||||
// we should manage at out level the mount status before and after the whole standalone mode
|
// we should manage at out level the mount status before and after the whole standalone mode
|
||||||
rdv40_spiffs_write((char *)dest,(uint8_t *)data,len, RDV40_SPIFFS_SAFETY_SAFE);
|
rdv40_spiffs_write((char *)dest, (uint8_t *)data, len, RDV40_SPIFFS_SAFETY_SAFE);
|
||||||
// lastag will only contain filename/path to last written tag file so we don't loose time or space.
|
// lastag will only contain filename/path to last written tag file so we don't loose time or space.
|
||||||
rdv40_spiffs_make_symlink((char *)dest,(char *)HFCOLIN_LASTTAG_SYMLINK,RDV40_SPIFFS_SAFETY_SAFE);
|
rdv40_spiffs_make_symlink((char *)dest, (char *)HFCOLIN_LASTTAG_SYMLINK, RDV40_SPIFFS_SAFETY_SAFE);
|
||||||
|
|
||||||
DbprintfEx(FLAG_NEWLINE, "[OK] TAG WRITTEN TO FLASH !");
|
DbprintfEx(FLAG_NEWLINE, "[OK] TAG WRITTEN TO FLASH !");
|
||||||
cjSetCursLeft();
|
cjSetCursLeft();
|
||||||
|
|
110
armsrc/appmain.c
110
armsrc/appmain.c
|
@ -1591,13 +1591,13 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
}
|
}
|
||||||
#ifdef WITH_FLASH
|
#ifdef WITH_FLASH
|
||||||
case CMD_SPIFFS_TEST: {
|
case CMD_SPIFFS_TEST: {
|
||||||
test_spiffs();
|
test_spiffs();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_SPIFFS_MOUNT: {
|
case CMD_SPIFFS_MOUNT: {
|
||||||
rdv40_spiffs_lazy_mount();
|
rdv40_spiffs_lazy_mount();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_SPIFFS_UNMOUNT: {
|
case CMD_SPIFFS_UNMOUNT: {
|
||||||
rdv40_spiffs_lazy_unmount();
|
rdv40_spiffs_lazy_unmount();
|
||||||
break;
|
break;
|
||||||
|
@ -1606,24 +1606,24 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
rdv40_spiffs_safe_print_tree(false);
|
rdv40_spiffs_safe_print_tree(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_SPIFFS_PRINT_FSINFO: {
|
case CMD_SPIFFS_PRINT_FSINFO: {
|
||||||
rdv40_spiffs_safe_print_fsinfos();
|
rdv40_spiffs_safe_print_fsinfos();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_SPIFFS_DOWNLOAD: {
|
case CMD_SPIFFS_DOWNLOAD: {
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
uint8_t filename[32];
|
uint8_t filename[32];
|
||||||
uint8_t *pfilename = packet->data.asBytes;
|
uint8_t *pfilename = packet->data.asBytes;
|
||||||
memcpy(filename,pfilename,SPIFFS_OBJ_NAME_LEN);
|
memcpy(filename, pfilename, SPIFFS_OBJ_NAME_LEN);
|
||||||
if (DBGLEVEL > 1) Dbprintf("> Filename received for spiffs dump : %s", filename);
|
if (DBGLEVEL > 1) Dbprintf("> Filename received for spiffs dump : %s", filename);
|
||||||
|
|
||||||
//uint32_t size = 0;
|
//uint32_t size = 0;
|
||||||
//rdv40_spiffs_stat((char *)filename, (uint32_t *)size,RDV40_SPIFFS_SAFETY_SAFE);
|
//rdv40_spiffs_stat((char *)filename, (uint32_t *)size,RDV40_SPIFFS_SAFETY_SAFE);
|
||||||
uint32_t size = packet->oldarg[1];
|
uint32_t size = packet->oldarg[1];
|
||||||
//uint8_t buff[size];
|
//uint8_t buff[size];
|
||||||
|
|
||||||
uint8_t *buff = BigBuf_malloc(size);
|
uint8_t *buff = BigBuf_malloc(size);
|
||||||
rdv40_spiffs_read_as_filetype((char *)filename,(uint8_t *)buff, size, RDV40_SPIFFS_SAFETY_SAFE);
|
rdv40_spiffs_read_as_filetype((char *)filename, (uint8_t *)buff, size, RDV40_SPIFFS_SAFETY_SAFE);
|
||||||
|
|
||||||
// arg0 = filename
|
// arg0 = filename
|
||||||
// arg1 = size
|
// arg1 = size
|
||||||
|
@ -1640,59 +1640,59 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
LED_B_OFF();
|
LED_B_OFF();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_SPIFFS_STAT:{
|
case CMD_SPIFFS_STAT: {
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
uint8_t filename[32];
|
uint8_t filename[32];
|
||||||
uint8_t *pfilename = packet->data.asBytes;
|
uint8_t *pfilename = packet->data.asBytes;
|
||||||
memcpy(filename,pfilename,SPIFFS_OBJ_NAME_LEN);
|
memcpy(filename, pfilename, SPIFFS_OBJ_NAME_LEN);
|
||||||
if (DBGLEVEL > 1) Dbprintf("> Filename received for spiffs STAT : %s", filename);
|
if (DBGLEVEL > 1) Dbprintf("> Filename received for spiffs STAT : %s", filename);
|
||||||
int changed = rdv40_spiffs_lazy_mount();
|
int changed = rdv40_spiffs_lazy_mount();
|
||||||
uint32_t size = size_in_spiffs((char *)filename);
|
uint32_t size = size_in_spiffs((char *)filename);
|
||||||
if (changed) rdv40_spiffs_lazy_unmount();
|
if (changed) rdv40_spiffs_lazy_unmount();
|
||||||
reply_old(CMD_ACK, size, 0, 0, 0, 0);
|
reply_old(CMD_ACK, size, 0, 0, 0, 0);
|
||||||
LED_B_OFF();
|
LED_B_OFF();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_SPIFFS_REMOVE:{
|
case CMD_SPIFFS_REMOVE: {
|
||||||
LED_B_ON();
|
|
||||||
uint8_t filename[32];
|
|
||||||
uint8_t *pfilename = packet->data.asBytes;
|
|
||||||
memcpy(filename,pfilename,SPIFFS_OBJ_NAME_LEN);
|
|
||||||
if (DBGLEVEL > 1) Dbprintf("> Filename received for spiffs REMOVE : %s", filename);
|
|
||||||
rdv40_spiffs_remove((char *) filename,RDV40_SPIFFS_SAFETY_SAFE);
|
|
||||||
LED_B_OFF();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case CMD_SPIFFS_RENAME:{
|
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
uint8_t srcfilename[32];
|
uint8_t filename[32];
|
||||||
uint8_t destfilename[32];
|
|
||||||
uint8_t *pfilename = packet->data.asBytes;
|
uint8_t *pfilename = packet->data.asBytes;
|
||||||
char *token;
|
memcpy(filename, pfilename, SPIFFS_OBJ_NAME_LEN);
|
||||||
token = strtok((char *)pfilename, ",");
|
if (DBGLEVEL > 1) Dbprintf("> Filename received for spiffs REMOVE : %s", filename);
|
||||||
strcpy((char*)srcfilename,token);
|
rdv40_spiffs_remove((char *) filename, RDV40_SPIFFS_SAFETY_SAFE);
|
||||||
token = strtok(NULL,",");
|
LED_B_OFF();
|
||||||
strcpy((char *)destfilename,token);
|
|
||||||
if (DBGLEVEL > 1) Dbprintf("> Filename received as source for spiffs RENAME : %s", srcfilename);
|
|
||||||
if (DBGLEVEL > 1) Dbprintf("> Filename received as destination for spiffs RENAME : %s", destfilename);
|
|
||||||
rdv40_spiffs_rename((char *) srcfilename,(char *)destfilename,RDV40_SPIFFS_SAFETY_SAFE);
|
|
||||||
LED_B_OFF();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_SPIFFS_COPY:{
|
case CMD_SPIFFS_RENAME: {
|
||||||
LED_B_ON();
|
LED_B_ON();
|
||||||
uint8_t srcfilename[32];
|
uint8_t srcfilename[32];
|
||||||
uint8_t destfilename[32];
|
uint8_t destfilename[32];
|
||||||
uint8_t *pfilename = packet->data.asBytes;
|
uint8_t *pfilename = packet->data.asBytes;
|
||||||
char *token;
|
char *token;
|
||||||
token = strtok((char *)pfilename, ",");
|
token = strtok((char *)pfilename, ",");
|
||||||
strcpy((char*)srcfilename,token);
|
strcpy((char *)srcfilename, token);
|
||||||
token = strtok(NULL,",");
|
token = strtok(NULL, ",");
|
||||||
strcpy((char *)destfilename,token);
|
strcpy((char *)destfilename, token);
|
||||||
|
if (DBGLEVEL > 1) Dbprintf("> Filename received as source for spiffs RENAME : %s", srcfilename);
|
||||||
|
if (DBGLEVEL > 1) Dbprintf("> Filename received as destination for spiffs RENAME : %s", destfilename);
|
||||||
|
rdv40_spiffs_rename((char *) srcfilename, (char *)destfilename, RDV40_SPIFFS_SAFETY_SAFE);
|
||||||
|
LED_B_OFF();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case CMD_SPIFFS_COPY: {
|
||||||
|
LED_B_ON();
|
||||||
|
uint8_t srcfilename[32];
|
||||||
|
uint8_t destfilename[32];
|
||||||
|
uint8_t *pfilename = packet->data.asBytes;
|
||||||
|
char *token;
|
||||||
|
token = strtok((char *)pfilename, ",");
|
||||||
|
strcpy((char *)srcfilename, token);
|
||||||
|
token = strtok(NULL, ",");
|
||||||
|
strcpy((char *)destfilename, token);
|
||||||
if (DBGLEVEL > 1) Dbprintf("> Filename received as source for spiffs COPY : %s", srcfilename);
|
if (DBGLEVEL > 1) Dbprintf("> Filename received as source for spiffs COPY : %s", srcfilename);
|
||||||
if (DBGLEVEL > 1) Dbprintf("> Filename received as destination for spiffs COPY : %s", destfilename);
|
if (DBGLEVEL > 1) Dbprintf("> Filename received as destination for spiffs COPY : %s", destfilename);
|
||||||
rdv40_spiffs_copy((char *) srcfilename,(char *)destfilename,RDV40_SPIFFS_SAFETY_SAFE);
|
rdv40_spiffs_copy((char *) srcfilename, (char *)destfilename, RDV40_SPIFFS_SAFETY_SAFE);
|
||||||
LED_B_OFF();
|
LED_B_OFF();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_SPIFFS_WRITE: {
|
case CMD_SPIFFS_WRITE: {
|
||||||
|
@ -1702,18 +1702,18 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
uint32_t size = packet->oldarg[1];
|
uint32_t size = packet->oldarg[1];
|
||||||
uint8_t *data = packet->data.asBytes;
|
uint8_t *data = packet->data.asBytes;
|
||||||
|
|
||||||
//rdv40_spiffs_lazy_mount();
|
//rdv40_spiffs_lazy_mount();
|
||||||
|
|
||||||
uint8_t *pfilename = packet->data.asBytes;
|
uint8_t *pfilename = packet->data.asBytes;
|
||||||
memcpy(filename,pfilename,SPIFFS_OBJ_NAME_LEN);
|
memcpy(filename, pfilename, SPIFFS_OBJ_NAME_LEN);
|
||||||
data+=SPIFFS_OBJ_NAME_LEN;
|
data += SPIFFS_OBJ_NAME_LEN;
|
||||||
|
|
||||||
if (DBGLEVEL > 1) Dbprintf("> Filename received for spiffs WRITE : %s with APPEND SET TO : %d", filename, append);
|
if (DBGLEVEL > 1) Dbprintf("> Filename received for spiffs WRITE : %s with APPEND SET TO : %d", filename, append);
|
||||||
if (!append) {
|
if (!append) {
|
||||||
rdv40_spiffs_write((char *) filename,(uint8_t *)data, size, RDV40_SPIFFS_SAFETY_SAFE);
|
rdv40_spiffs_write((char *) filename, (uint8_t *)data, size, RDV40_SPIFFS_SAFETY_SAFE);
|
||||||
} else {
|
} else {
|
||||||
rdv40_spiffs_append((char *) filename,(uint8_t *)data, size, RDV40_SPIFFS_SAFETY_SAFE);
|
rdv40_spiffs_append((char *) filename, (uint8_t *)data, size, RDV40_SPIFFS_SAFETY_SAFE);
|
||||||
}
|
}
|
||||||
reply_old(CMD_ACK, 1, 0, 0, 0, 0);
|
reply_old(CMD_ACK, 1, 0, 0, 0, 0);
|
||||||
LED_B_OFF();
|
LED_B_OFF();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -107,13 +107,13 @@ int rdv40_spiffs_mounted() {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
switch (RDV40_SPIFFS_MOUNT_STATUS) {
|
switch (RDV40_SPIFFS_MOUNT_STATUS) {
|
||||||
case RDV40_SPIFFS_MOUNTED:
|
case RDV40_SPIFFS_MOUNTED:
|
||||||
ret = 1;
|
ret = 1;
|
||||||
break;
|
break;
|
||||||
case RDV40_SPIFFS_UNMOUNTED:
|
case RDV40_SPIFFS_UNMOUNTED:
|
||||||
case RDV40_SPIFFS_UNKNOWN:
|
case RDV40_SPIFFS_UNKNOWN:
|
||||||
default:
|
default:
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -240,18 +240,18 @@ RDV40SpiFFSFileType filetype_in_spiffs(const char *filename) {
|
||||||
}
|
}
|
||||||
if (DBGLEVEL > 1) {
|
if (DBGLEVEL > 1) {
|
||||||
switch (filetype) {
|
switch (filetype) {
|
||||||
case RDV40_SPIFFS_FILETYPE_REAL:
|
case RDV40_SPIFFS_FILETYPE_REAL:
|
||||||
Dbprintf("Filetype is : RDV40_SPIFFS_FILETYPE_REAL");
|
Dbprintf("Filetype is : RDV40_SPIFFS_FILETYPE_REAL");
|
||||||
break;
|
break;
|
||||||
case RDV40_SPIFFS_FILETYPE_SYMLINK:
|
case RDV40_SPIFFS_FILETYPE_SYMLINK:
|
||||||
Dbprintf("Filetype is : RDV40_SPIFFS_FILETYPE_SYMLINK");
|
Dbprintf("Filetype is : RDV40_SPIFFS_FILETYPE_SYMLINK");
|
||||||
break;
|
break;
|
||||||
case RDV40_SPIFFS_FILETYPE_BOTH:
|
case RDV40_SPIFFS_FILETYPE_BOTH:
|
||||||
Dbprintf("Filetype is : RDV40_SPIFFS_FILETYPE_BOTH");
|
Dbprintf("Filetype is : RDV40_SPIFFS_FILETYPE_BOTH");
|
||||||
break;
|
break;
|
||||||
case RDV40_SPIFFS_FILETYPE_UNKNOWN:
|
case RDV40_SPIFFS_FILETYPE_UNKNOWN:
|
||||||
Dbprintf("Filetype is : RDV40_SPIFFS_FILETYPE_UNKNOWN");
|
Dbprintf("Filetype is : RDV40_SPIFFS_FILETYPE_UNKNOWN");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filetype;
|
return filetype;
|
||||||
|
@ -426,13 +426,13 @@ int rdv40_spiffs_copy(char *src, char *dst, RDV40SpiFFSSafetyLevel level) {
|
||||||
|
|
||||||
int rdv40_spiffs_stat(char *filename, uint32_t *buf, RDV40SpiFFSSafetyLevel level) {
|
int rdv40_spiffs_stat(char *filename, uint32_t *buf, RDV40SpiFFSSafetyLevel level) {
|
||||||
RDV40_SPIFFS_SAFE_FUNCTION( //
|
RDV40_SPIFFS_SAFE_FUNCTION( //
|
||||||
*buf = size_in_spiffs((char *)filename); //
|
*buf = size_in_spiffs((char *)filename); //
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
int rdv40_spiffs_getfsinfo(rdv40_spiffs_fsinfo *fsinfo, RDV40SpiFFSSafetyLevel level) {
|
int rdv40_spiffs_getfsinfo(rdv40_spiffs_fsinfo *fsinfo, RDV40SpiFFSSafetyLevel level) {
|
||||||
RDV40_SPIFFS_SAFE_FUNCTION( //
|
RDV40_SPIFFS_SAFE_FUNCTION( //
|
||||||
*fsinfo = info_of_spiffs(); //
|
*fsinfo = info_of_spiffs(); //
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,9 +465,9 @@ int rdv40_spiffs_read_as_symlink(char *filename, uint8_t *dst, uint32_t size, RD
|
||||||
if (DBGLEVEL > 1) Dbprintf("Linkk real filename is destination is : %s", linkfilename);
|
if (DBGLEVEL > 1) Dbprintf("Linkk real filename is destination is : %s", linkfilename);
|
||||||
read_from_spiffs((char *)linkfilename, (uint8_t *)linkdest, SPIFFS_OBJ_NAME_LEN);
|
read_from_spiffs((char *)linkfilename, (uint8_t *)linkdest, SPIFFS_OBJ_NAME_LEN);
|
||||||
if (DBGLEVEL > 1) Dbprintf("Symlink destination is : %s", linkdest);
|
if (DBGLEVEL > 1) Dbprintf("Symlink destination is : %s", linkdest);
|
||||||
read_from_spiffs((char *)linkdest, (uint8_t *)dst, size); //
|
read_from_spiffs((char *)linkdest, (uint8_t *)dst, size); //
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BEWARE ! This function is DESTRUCTIVE as it will UPDATE an existing symlink
|
// BEWARE ! This function is DESTRUCTIVE as it will UPDATE an existing symlink
|
||||||
// Since it creates a .lnk extension file it may be minor to mistake the order of arguments
|
// Since it creates a .lnk extension file it may be minor to mistake the order of arguments
|
||||||
|
@ -498,17 +498,18 @@ int rdv40_spiffs_make_symlink(char *linkdest, char *filename, RDV40SpiFFSSafetyL
|
||||||
int rdv40_spiffs_read_as_filetype(char *filename, uint8_t *dst, uint32_t size, RDV40SpiFFSSafetyLevel level) {
|
int rdv40_spiffs_read_as_filetype(char *filename, uint8_t *dst, uint32_t size, RDV40SpiFFSSafetyLevel level) {
|
||||||
RDV40_SPIFFS_SAFE_FUNCTION( //
|
RDV40_SPIFFS_SAFE_FUNCTION( //
|
||||||
RDV40SpiFFSFileType filetype = filetype_in_spiffs((char *)filename); //
|
RDV40SpiFFSFileType filetype = filetype_in_spiffs((char *)filename); //
|
||||||
switch (filetype) {
|
switch (filetype) {
|
||||||
case RDV40_SPIFFS_FILETYPE_REAL:
|
case RDV40_SPIFFS_FILETYPE_REAL:
|
||||||
rdv40_spiffs_read((char *)filename, (uint8_t *)dst, size, level);
|
rdv40_spiffs_read((char *)filename, (uint8_t *)dst, size, level);
|
||||||
break;
|
break;
|
||||||
case RDV40_SPIFFS_FILETYPE_SYMLINK:
|
case RDV40_SPIFFS_FILETYPE_SYMLINK:
|
||||||
rdv40_spiffs_read_as_symlink((char *)filename, (uint8_t *)dst, size, level);
|
rdv40_spiffs_read_as_symlink((char *)filename, (uint8_t *)dst, size, level);
|
||||||
break;
|
break;
|
||||||
case RDV40_SPIFFS_FILETYPE_BOTH:
|
case RDV40_SPIFFS_FILETYPE_BOTH:
|
||||||
case RDV40_SPIFFS_FILETYPE_UNKNOWN:
|
case RDV40_SPIFFS_FILETYPE_UNKNOWN:
|
||||||
default:;
|
default:
|
||||||
} //
|
;
|
||||||
|
} //
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
249
armsrc/spiffs.h
249
armsrc/spiffs.h
|
@ -22,15 +22,14 @@ typedef enum spiffs_file_type {
|
||||||
RDV40_SPIFFS_FILETYPE_UNKNOWN
|
RDV40_SPIFFS_FILETYPE_UNKNOWN
|
||||||
} RDV40SpiFFSFileType;
|
} RDV40SpiFFSFileType;
|
||||||
|
|
||||||
typedef struct rdv40_spiffs_fsinfo
|
typedef struct rdv40_spiffs_fsinfo {
|
||||||
{
|
uint32_t blockSize;
|
||||||
uint32_t blockSize;
|
uint32_t pageSize;
|
||||||
uint32_t pageSize;
|
uint32_t maxOpenFiles;
|
||||||
uint32_t maxOpenFiles;
|
uint32_t maxPathLenght;
|
||||||
uint32_t maxPathLenght;
|
uint32_t totalBytes, usedBytes, freeBytes;
|
||||||
uint32_t totalBytes, usedBytes, freeBytes;
|
uint32_t usedPercent, freePercent;
|
||||||
uint32_t usedPercent, freePercent;
|
} rdv40_spiffs_fsinfo;
|
||||||
} rdv40_spiffs_fsinfo;
|
|
||||||
|
|
||||||
int rdv40_spiffs_read_as_filetype(char *filename, uint8_t *dst, uint32_t size, RDV40SpiFFSSafetyLevel level);
|
int rdv40_spiffs_read_as_filetype(char *filename, uint8_t *dst, uint32_t size, RDV40SpiFFSSafetyLevel level);
|
||||||
|
|
||||||
|
@ -145,39 +144,39 @@ typedef s32_t (*spiffs_erase)(u32_t addr, u32_t size);
|
||||||
|
|
||||||
/* file system check callback report operation */
|
/* file system check callback report operation */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SPIFFS_CHECK_LOOKUP = 0,
|
SPIFFS_CHECK_LOOKUP = 0,
|
||||||
SPIFFS_CHECK_INDEX,
|
SPIFFS_CHECK_INDEX,
|
||||||
SPIFFS_CHECK_PAGE
|
SPIFFS_CHECK_PAGE
|
||||||
} spiffs_check_type;
|
} spiffs_check_type;
|
||||||
|
|
||||||
/* file system check callback report type */
|
/* file system check callback report type */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SPIFFS_CHECK_PROGRESS = 0,
|
SPIFFS_CHECK_PROGRESS = 0,
|
||||||
SPIFFS_CHECK_ERROR,
|
SPIFFS_CHECK_ERROR,
|
||||||
SPIFFS_CHECK_FIX_INDEX,
|
SPIFFS_CHECK_FIX_INDEX,
|
||||||
SPIFFS_CHECK_FIX_LOOKUP,
|
SPIFFS_CHECK_FIX_LOOKUP,
|
||||||
SPIFFS_CHECK_DELETE_ORPHANED_INDEX,
|
SPIFFS_CHECK_DELETE_ORPHANED_INDEX,
|
||||||
SPIFFS_CHECK_DELETE_PAGE,
|
SPIFFS_CHECK_DELETE_PAGE,
|
||||||
SPIFFS_CHECK_DELETE_BAD_FILE
|
SPIFFS_CHECK_DELETE_BAD_FILE
|
||||||
} spiffs_check_report;
|
} spiffs_check_report;
|
||||||
|
|
||||||
/* file system check callback function */
|
/* file system check callback function */
|
||||||
#if SPIFFS_HAL_CALLBACK_EXTRA
|
#if SPIFFS_HAL_CALLBACK_EXTRA
|
||||||
typedef void (*spiffs_check_callback)(struct spiffs_t *fs, spiffs_check_type type, spiffs_check_report report,
|
typedef void (*spiffs_check_callback)(struct spiffs_t *fs, spiffs_check_type type, spiffs_check_report report,
|
||||||
u32_t arg1, u32_t arg2);
|
u32_t arg1, u32_t arg2);
|
||||||
#else // SPIFFS_HAL_CALLBACK_EXTRA
|
#else // SPIFFS_HAL_CALLBACK_EXTRA
|
||||||
typedef void (*spiffs_check_callback)(spiffs_check_type type, spiffs_check_report report,
|
typedef void (*spiffs_check_callback)(spiffs_check_type type, spiffs_check_report report,
|
||||||
u32_t arg1, u32_t arg2);
|
u32_t arg1, u32_t arg2);
|
||||||
#endif // SPIFFS_HAL_CALLBACK_EXTRA
|
#endif // SPIFFS_HAL_CALLBACK_EXTRA
|
||||||
|
|
||||||
/* file system listener callback operation */
|
/* file system listener callback operation */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
/* the file has been created */
|
/* the file has been created */
|
||||||
SPIFFS_CB_CREATED = 0,
|
SPIFFS_CB_CREATED = 0,
|
||||||
/* the file has been updated or moved to another page */
|
/* the file has been updated or moved to another page */
|
||||||
SPIFFS_CB_UPDATED,
|
SPIFFS_CB_UPDATED,
|
||||||
/* the file has been deleted */
|
/* the file has been deleted */
|
||||||
SPIFFS_CB_DELETED
|
SPIFFS_CB_DELETED
|
||||||
} spiffs_fileop_type;
|
} spiffs_fileop_type;
|
||||||
|
|
||||||
/* file system listener callback function */
|
/* file system listener callback function */
|
||||||
|
@ -243,141 +242,141 @@ typedef void (*spiffs_file_callback)(struct spiffs_t *fs, spiffs_fileop_type op,
|
||||||
|
|
||||||
// spiffs spi configuration struct
|
// spiffs spi configuration struct
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// physical read function
|
// physical read function
|
||||||
spiffs_read hal_read_f;
|
spiffs_read hal_read_f;
|
||||||
// physical write function
|
// physical write function
|
||||||
spiffs_write hal_write_f;
|
spiffs_write hal_write_f;
|
||||||
// physical erase function
|
// physical erase function
|
||||||
spiffs_erase hal_erase_f;
|
spiffs_erase hal_erase_f;
|
||||||
#if SPIFFS_SINGLETON == 0
|
#if SPIFFS_SINGLETON == 0
|
||||||
// physical size of the spi flash
|
// physical size of the spi flash
|
||||||
u32_t phys_size;
|
u32_t phys_size;
|
||||||
// physical offset in spi flash used for spiffs,
|
// physical offset in spi flash used for spiffs,
|
||||||
// must be on block boundary
|
// must be on block boundary
|
||||||
u32_t phys_addr;
|
u32_t phys_addr;
|
||||||
// physical size when erasing a block
|
// physical size when erasing a block
|
||||||
u32_t phys_erase_block;
|
u32_t phys_erase_block;
|
||||||
|
|
||||||
// logical size of a block, must be on physical
|
// logical size of a block, must be on physical
|
||||||
// block size boundary and must never be less than
|
// block size boundary and must never be less than
|
||||||
// a physical block
|
// a physical block
|
||||||
u32_t log_block_size;
|
u32_t log_block_size;
|
||||||
// logical size of a page, must be at least
|
// logical size of a page, must be at least
|
||||||
// log_block_size / 8
|
// log_block_size / 8
|
||||||
u32_t log_page_size;
|
u32_t log_page_size;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if SPIFFS_FILEHDL_OFFSET
|
#if SPIFFS_FILEHDL_OFFSET
|
||||||
// an integer offset added to each file handle
|
// an integer offset added to each file handle
|
||||||
u16_t fh_ix_offset;
|
u16_t fh_ix_offset;
|
||||||
#endif
|
#endif
|
||||||
} spiffs_config;
|
} spiffs_config;
|
||||||
|
|
||||||
typedef struct spiffs_t {
|
typedef struct spiffs_t {
|
||||||
// file system configuration
|
// file system configuration
|
||||||
spiffs_config cfg;
|
spiffs_config cfg;
|
||||||
// number of logical blocks
|
// number of logical blocks
|
||||||
u32_t block_count;
|
u32_t block_count;
|
||||||
|
|
||||||
// cursor for free blocks, block index
|
// cursor for free blocks, block index
|
||||||
spiffs_block_ix free_cursor_block_ix;
|
spiffs_block_ix free_cursor_block_ix;
|
||||||
// cursor for free blocks, entry index
|
// cursor for free blocks, entry index
|
||||||
int free_cursor_obj_lu_entry;
|
int free_cursor_obj_lu_entry;
|
||||||
// cursor when searching, block index
|
// cursor when searching, block index
|
||||||
spiffs_block_ix cursor_block_ix;
|
spiffs_block_ix cursor_block_ix;
|
||||||
// cursor when searching, entry index
|
// cursor when searching, entry index
|
||||||
int cursor_obj_lu_entry;
|
int cursor_obj_lu_entry;
|
||||||
|
|
||||||
// primary work buffer, size of a logical page
|
// primary work buffer, size of a logical page
|
||||||
u8_t *lu_work;
|
u8_t *lu_work;
|
||||||
// secondary work buffer, size of a logical page
|
// secondary work buffer, size of a logical page
|
||||||
u8_t *work;
|
u8_t *work;
|
||||||
// file descriptor memory area
|
// file descriptor memory area
|
||||||
u8_t *fd_space;
|
u8_t *fd_space;
|
||||||
// available file descriptors
|
// available file descriptors
|
||||||
u32_t fd_count;
|
u32_t fd_count;
|
||||||
|
|
||||||
// last error
|
// last error
|
||||||
s32_t err_code;
|
s32_t err_code;
|
||||||
|
|
||||||
// current number of free blocks
|
// current number of free blocks
|
||||||
u32_t free_blocks;
|
u32_t free_blocks;
|
||||||
// current number of busy pages
|
// current number of busy pages
|
||||||
u32_t stats_p_allocated;
|
u32_t stats_p_allocated;
|
||||||
// current number of deleted pages
|
// current number of deleted pages
|
||||||
u32_t stats_p_deleted;
|
u32_t stats_p_deleted;
|
||||||
// flag indicating that garbage collector is cleaning
|
// flag indicating that garbage collector is cleaning
|
||||||
u8_t cleaning;
|
u8_t cleaning;
|
||||||
// max erase count amongst all blocks
|
// max erase count amongst all blocks
|
||||||
spiffs_obj_id max_erase_count;
|
spiffs_obj_id max_erase_count;
|
||||||
|
|
||||||
#if SPIFFS_GC_STATS
|
#if SPIFFS_GC_STATS
|
||||||
u32_t stats_gc_runs;
|
u32_t stats_gc_runs;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if SPIFFS_CACHE
|
#if SPIFFS_CACHE
|
||||||
// cache memory
|
// cache memory
|
||||||
void *cache;
|
void *cache;
|
||||||
// cache size
|
// cache size
|
||||||
u32_t cache_size;
|
u32_t cache_size;
|
||||||
#if SPIFFS_CACHE_STATS
|
#if SPIFFS_CACHE_STATS
|
||||||
u32_t cache_hits;
|
u32_t cache_hits;
|
||||||
u32_t cache_misses;
|
u32_t cache_misses;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// check callback function
|
// check callback function
|
||||||
spiffs_check_callback check_cb_f;
|
spiffs_check_callback check_cb_f;
|
||||||
// file callback function
|
// file callback function
|
||||||
spiffs_file_callback file_cb_f;
|
spiffs_file_callback file_cb_f;
|
||||||
// mounted flag
|
// mounted flag
|
||||||
u8_t mounted;
|
u8_t mounted;
|
||||||
// user data
|
// user data
|
||||||
void *user_data;
|
void *user_data;
|
||||||
// config magic
|
// config magic
|
||||||
u32_t config_magic;
|
u32_t config_magic;
|
||||||
} spiffs;
|
} spiffs;
|
||||||
|
|
||||||
/* spiffs file status struct */
|
/* spiffs file status struct */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
spiffs_obj_id obj_id;
|
spiffs_obj_id obj_id;
|
||||||
u32_t size;
|
u32_t size;
|
||||||
spiffs_obj_type type;
|
spiffs_obj_type type;
|
||||||
spiffs_page_ix pix;
|
spiffs_page_ix pix;
|
||||||
u8_t name[SPIFFS_OBJ_NAME_LEN];
|
u8_t name[SPIFFS_OBJ_NAME_LEN];
|
||||||
#if SPIFFS_OBJ_META_LEN
|
#if SPIFFS_OBJ_META_LEN
|
||||||
u8_t meta[SPIFFS_OBJ_META_LEN];
|
u8_t meta[SPIFFS_OBJ_META_LEN];
|
||||||
#endif
|
#endif
|
||||||
} spiffs_stat;
|
} spiffs_stat;
|
||||||
|
|
||||||
struct spiffs_dirent {
|
struct spiffs_dirent {
|
||||||
spiffs_obj_id obj_id;
|
spiffs_obj_id obj_id;
|
||||||
u8_t name[SPIFFS_OBJ_NAME_LEN];
|
u8_t name[SPIFFS_OBJ_NAME_LEN];
|
||||||
spiffs_obj_type type;
|
spiffs_obj_type type;
|
||||||
u32_t size;
|
u32_t size;
|
||||||
spiffs_page_ix pix;
|
spiffs_page_ix pix;
|
||||||
#if SPIFFS_OBJ_META_LEN
|
#if SPIFFS_OBJ_META_LEN
|
||||||
u8_t meta[SPIFFS_OBJ_META_LEN];
|
u8_t meta[SPIFFS_OBJ_META_LEN];
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
spiffs *fs;
|
spiffs *fs;
|
||||||
spiffs_block_ix block;
|
spiffs_block_ix block;
|
||||||
int entry;
|
int entry;
|
||||||
} spiffs_DIR;
|
} spiffs_DIR;
|
||||||
|
|
||||||
#if SPIFFS_IX_MAP
|
#if SPIFFS_IX_MAP
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// buffer with looked up data pixes
|
// buffer with looked up data pixes
|
||||||
spiffs_page_ix *map_buf;
|
spiffs_page_ix *map_buf;
|
||||||
// precise file byte offset
|
// precise file byte offset
|
||||||
u32_t offset;
|
u32_t offset;
|
||||||
// start data span index of lookup buffer
|
// start data span index of lookup buffer
|
||||||
spiffs_span_ix start_spix;
|
spiffs_span_ix start_spix;
|
||||||
// end data span index of lookup buffer
|
// end data span index of lookup buffer
|
||||||
spiffs_span_ix end_spix;
|
spiffs_span_ix end_spix;
|
||||||
} spiffs_ix_map;
|
} spiffs_ix_map;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -434,9 +433,9 @@ s32_t SPIFFS_probe_fs(spiffs_config *config);
|
||||||
* @param check_cb_f callback function for reporting during consistency checks
|
* @param check_cb_f callback function for reporting during consistency checks
|
||||||
*/
|
*/
|
||||||
s32_t SPIFFS_mount(spiffs *fs, spiffs_config *config, u8_t *work,
|
s32_t SPIFFS_mount(spiffs *fs, spiffs_config *config, u8_t *work,
|
||||||
u8_t *fd_space, u32_t fd_space_size,
|
u8_t *fd_space, u32_t fd_space_size,
|
||||||
void *cache, u32_t cache_size,
|
void *cache, u32_t cache_size,
|
||||||
spiffs_check_callback check_cb_f);
|
spiffs_check_callback check_cb_f);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unmounts the file system. All file handles will be flushed of any
|
* Unmounts the file system. All file handles will be flushed of any
|
||||||
|
@ -779,7 +778,7 @@ s32_t SPIFFS_set_file_callback_func(spiffs *fs, spiffs_file_callback cb_func);
|
||||||
* SPIFFS_bytes_to_ix_map_entries given the length
|
* SPIFFS_bytes_to_ix_map_entries given the length
|
||||||
*/
|
*/
|
||||||
s32_t SPIFFS_ix_map(spiffs *fs, spiffs_file fh, spiffs_ix_map *map,
|
s32_t SPIFFS_ix_map(spiffs *fs, spiffs_file fh, spiffs_ix_map *map,
|
||||||
u32_t offset, u32_t len, spiffs_page_ix *map_buf);
|
u32_t offset, u32_t len, spiffs_page_ix *map_buf);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unmaps the index lookup from this filehandle. All future readings will
|
* Unmaps the index lookup from this filehandle. All future readings will
|
||||||
|
|
|
@ -12,109 +12,109 @@
|
||||||
|
|
||||||
// returns cached page for give page index, or null if no such cached page
|
// returns cached page for give page index, or null if no such cached page
|
||||||
static spiffs_cache_page *spiffs_cache_page_get(spiffs *fs, spiffs_page_ix pix) {
|
static spiffs_cache_page *spiffs_cache_page_get(spiffs *fs, spiffs_page_ix pix) {
|
||||||
spiffs_cache *cache = spiffs_get_cache(fs);
|
spiffs_cache *cache = spiffs_get_cache(fs);
|
||||||
if ((cache->cpage_use_map & cache->cpage_use_mask) == 0) return 0;
|
if ((cache->cpage_use_map & cache->cpage_use_mask) == 0) return 0;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < cache->cpage_count; i++) {
|
for (i = 0; i < cache->cpage_count; i++) {
|
||||||
spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, i);
|
spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, i);
|
||||||
if ((cache->cpage_use_map & (1<<i)) &&
|
if ((cache->cpage_use_map & (1 << i)) &&
|
||||||
(cp->flags & SPIFFS_CACHE_FLAG_TYPE_WR) == 0 &&
|
(cp->flags & SPIFFS_CACHE_FLAG_TYPE_WR) == 0 &&
|
||||||
cp->ucache.spix.pix == pix ) {
|
cp->ucache.spix.pix == pix) {
|
||||||
//SPIFFS_CACHE_DBG("CACHE_GET: have cache page "_SPIPRIi" for "_SPIPRIpg"\n", i, pix);
|
//SPIFFS_CACHE_DBG("CACHE_GET: have cache page "_SPIPRIi" for "_SPIPRIpg"\n", i, pix);
|
||||||
cp->last_access = cache->last_access;
|
cp->last_access = cache->last_access;
|
||||||
return cp;
|
return cp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
//SPIFFS_CACHE_DBG("CACHE_GET: no cache for "_SPIPRIpg"\n", pix);
|
||||||
//SPIFFS_CACHE_DBG("CACHE_GET: no cache for "_SPIPRIpg"\n", pix);
|
return 0;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// frees cached page
|
// frees cached page
|
||||||
static s32_t spiffs_cache_page_free(spiffs *fs, int ix, u8_t write_back) {
|
static s32_t spiffs_cache_page_free(spiffs *fs, int ix, u8_t write_back) {
|
||||||
s32_t res = SPIFFS_OK;
|
s32_t res = SPIFFS_OK;
|
||||||
spiffs_cache *cache = spiffs_get_cache(fs);
|
spiffs_cache *cache = spiffs_get_cache(fs);
|
||||||
spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, ix);
|
spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, ix);
|
||||||
if (cache->cpage_use_map & (1<<ix)) {
|
if (cache->cpage_use_map & (1 << ix)) {
|
||||||
if (write_back &&
|
if (write_back &&
|
||||||
(cp->flags & SPIFFS_CACHE_FLAG_TYPE_WR) == 0 &&
|
(cp->flags & SPIFFS_CACHE_FLAG_TYPE_WR) == 0 &&
|
||||||
(cp->flags & SPIFFS_CACHE_FLAG_DIRTY)) {
|
(cp->flags & SPIFFS_CACHE_FLAG_DIRTY)) {
|
||||||
u8_t *mem = spiffs_get_cache_page(fs, cache, ix);
|
u8_t *mem = spiffs_get_cache_page(fs, cache, ix);
|
||||||
SPIFFS_CACHE_DBG("CACHE_FREE: write cache page "_SPIPRIi" pix "_SPIPRIpg"\n", ix, cp->pix);
|
SPIFFS_CACHE_DBG("CACHE_FREE: write cache page "_SPIPRIi" pix "_SPIPRIpg"\n", ix, cp->pix);
|
||||||
res = SPIFFS_HAL_WRITE(fs, SPIFFS_PAGE_TO_PADDR(fs, cp->ucache.spix.pix), SPIFFS_CFG_LOG_PAGE_SZ(fs), mem);
|
res = SPIFFS_HAL_WRITE(fs, SPIFFS_PAGE_TO_PADDR(fs, cp->ucache.spix.pix), SPIFFS_CFG_LOG_PAGE_SZ(fs), mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SPIFFS_CACHE_WR
|
#if SPIFFS_CACHE_WR
|
||||||
if (cp->flags & SPIFFS_CACHE_FLAG_TYPE_WR) {
|
if (cp->flags & SPIFFS_CACHE_FLAG_TYPE_WR) {
|
||||||
SPIFFS_CACHE_DBG("CACHE_FREE: free cache page "_SPIPRIi" objid "_SPIPRIid"\n", ix, cp->obj_id);
|
SPIFFS_CACHE_DBG("CACHE_FREE: free cache page "_SPIPRIi" objid "_SPIPRIid"\n", ix, cp->obj_id);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
SPIFFS_CACHE_DBG("CACHE_FREE: free cache page "_SPIPRIi" pix "_SPIPRIpg"\n", ix, cp->pix);
|
SPIFFS_CACHE_DBG("CACHE_FREE: free cache page "_SPIPRIi" pix "_SPIPRIpg"\n", ix, cp->pix);
|
||||||
|
}
|
||||||
|
cache->cpage_use_map &= ~(1 << ix);
|
||||||
|
cp->flags = 0;
|
||||||
}
|
}
|
||||||
cache->cpage_use_map &= ~(1 << ix);
|
|
||||||
cp->flags = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// removes the oldest accessed cached page
|
// removes the oldest accessed cached page
|
||||||
static s32_t spiffs_cache_page_remove_oldest(spiffs *fs, u8_t flag_mask, u8_t flags) {
|
static s32_t spiffs_cache_page_remove_oldest(spiffs *fs, u8_t flag_mask, u8_t flags) {
|
||||||
s32_t res = SPIFFS_OK;
|
s32_t res = SPIFFS_OK;
|
||||||
spiffs_cache *cache = spiffs_get_cache(fs);
|
spiffs_cache *cache = spiffs_get_cache(fs);
|
||||||
|
|
||||||
if ((cache->cpage_use_map & cache->cpage_use_mask) != cache->cpage_use_mask) {
|
if ((cache->cpage_use_map & cache->cpage_use_mask) != cache->cpage_use_mask) {
|
||||||
// at least one free cpage
|
// at least one free cpage
|
||||||
return SPIFFS_OK;
|
return SPIFFS_OK;
|
||||||
}
|
|
||||||
|
|
||||||
// all busy, scan thru all to find the cpage which has oldest access
|
|
||||||
int i;
|
|
||||||
int cand_ix = -1;
|
|
||||||
u32_t oldest_val = 0;
|
|
||||||
for (i = 0; i < cache->cpage_count; i++) {
|
|
||||||
spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, i);
|
|
||||||
if ((cache->last_access - cp->last_access) > oldest_val &&
|
|
||||||
(cp->flags & flag_mask) == flags) {
|
|
||||||
oldest_val = cache->last_access - cp->last_access;
|
|
||||||
cand_ix = i;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (cand_ix >= 0) {
|
// all busy, scan thru all to find the cpage which has oldest access
|
||||||
res = spiffs_cache_page_free(fs, cand_ix, 1);
|
int i;
|
||||||
}
|
int cand_ix = -1;
|
||||||
|
u32_t oldest_val = 0;
|
||||||
|
for (i = 0; i < cache->cpage_count; i++) {
|
||||||
|
spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, i);
|
||||||
|
if ((cache->last_access - cp->last_access) > oldest_val &&
|
||||||
|
(cp->flags & flag_mask) == flags) {
|
||||||
|
oldest_val = cache->last_access - cp->last_access;
|
||||||
|
cand_ix = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
if (cand_ix >= 0) {
|
||||||
|
res = spiffs_cache_page_free(fs, cand_ix, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocates a new cached page and returns it, or null if all cache pages are busy
|
// allocates a new cached page and returns it, or null if all cache pages are busy
|
||||||
static spiffs_cache_page *spiffs_cache_page_allocate(spiffs *fs) {
|
static spiffs_cache_page *spiffs_cache_page_allocate(spiffs *fs) {
|
||||||
spiffs_cache *cache = spiffs_get_cache(fs);
|
spiffs_cache *cache = spiffs_get_cache(fs);
|
||||||
if (cache->cpage_use_map == 0xffffffff) {
|
if (cache->cpage_use_map == 0xffffffff) {
|
||||||
// out of cache memory
|
// out of cache memory
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < cache->cpage_count; i++) {
|
|
||||||
if ((cache->cpage_use_map & (1<<i)) == 0) {
|
|
||||||
spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, i);
|
|
||||||
cache->cpage_use_map |= (1<<i);
|
|
||||||
cp->last_access = cache->last_access;
|
|
||||||
//SPIFFS_CACHE_DBG("CACHE_ALLO: allocated cache page "_SPIPRIi"\n", i);
|
|
||||||
return cp;
|
|
||||||
}
|
}
|
||||||
}
|
int i;
|
||||||
// out of cache entries
|
for (i = 0; i < cache->cpage_count; i++) {
|
||||||
return 0;
|
if ((cache->cpage_use_map & (1 << i)) == 0) {
|
||||||
|
spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, i);
|
||||||
|
cache->cpage_use_map |= (1 << i);
|
||||||
|
cp->last_access = cache->last_access;
|
||||||
|
//SPIFFS_CACHE_DBG("CACHE_ALLO: allocated cache page "_SPIPRIi"\n", i);
|
||||||
|
return cp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// out of cache entries
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// drops the cache page for give page index
|
// drops the cache page for give page index
|
||||||
void spiffs_cache_drop_page(spiffs *fs, spiffs_page_ix pix) {
|
void spiffs_cache_drop_page(spiffs *fs, spiffs_page_ix pix) {
|
||||||
spiffs_cache_page *cp = spiffs_cache_page_get(fs, pix);
|
spiffs_cache_page *cp = spiffs_cache_page_get(fs, pix);
|
||||||
if (cp) {
|
if (cp) {
|
||||||
spiffs_cache_page_free(fs, cp->ix, 0);
|
spiffs_cache_page_free(fs, cp->ix, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------
|
// ------------------------------
|
||||||
|
@ -127,57 +127,57 @@ s32_t spiffs_phys_rd(
|
||||||
u32_t addr,
|
u32_t addr,
|
||||||
u32_t len,
|
u32_t len,
|
||||||
u8_t *dst) {
|
u8_t *dst) {
|
||||||
(void)fh;
|
(void)fh;
|
||||||
s32_t res = SPIFFS_OK;
|
s32_t res = SPIFFS_OK;
|
||||||
spiffs_cache *cache = spiffs_get_cache(fs);
|
spiffs_cache *cache = spiffs_get_cache(fs);
|
||||||
spiffs_cache_page *cp = spiffs_cache_page_get(fs, SPIFFS_PADDR_TO_PAGE(fs, addr));
|
spiffs_cache_page *cp = spiffs_cache_page_get(fs, SPIFFS_PADDR_TO_PAGE(fs, addr));
|
||||||
cache->last_access++;
|
cache->last_access++;
|
||||||
if (cp) {
|
|
||||||
// we've already got one, you see
|
|
||||||
#if SPIFFS_CACHE_STATS
|
|
||||||
fs->cache_hits++;
|
|
||||||
#endif
|
|
||||||
cp->last_access = cache->last_access;
|
|
||||||
u8_t *mem = spiffs_get_cache_page(fs, cache, cp->ix);
|
|
||||||
_SPIFFS_MEMCPY(dst, &mem[SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr)], len);
|
|
||||||
} else {
|
|
||||||
if ((op & SPIFFS_OP_TYPE_MASK) == SPIFFS_OP_T_OBJ_LU2) {
|
|
||||||
// for second layer lookup functions, we do not cache in order to prevent shredding
|
|
||||||
return SPIFFS_HAL_READ(fs, addr, len, dst);
|
|
||||||
}
|
|
||||||
#if SPIFFS_CACHE_STATS
|
|
||||||
fs->cache_misses++;
|
|
||||||
#endif
|
|
||||||
// this operation will always free one cache page (unless all already free),
|
|
||||||
// the result code stems from the write operation of the possibly freed cache page
|
|
||||||
res = spiffs_cache_page_remove_oldest(fs, SPIFFS_CACHE_FLAG_TYPE_WR, 0);
|
|
||||||
|
|
||||||
cp = spiffs_cache_page_allocate(fs);
|
|
||||||
if (cp) {
|
if (cp) {
|
||||||
cp->flags = SPIFFS_CACHE_FLAG_WRTHRU;
|
// we've already got one, you see
|
||||||
cp->ucache.spix.pix = SPIFFS_PADDR_TO_PAGE(fs, addr);
|
#if SPIFFS_CACHE_STATS
|
||||||
SPIFFS_CACHE_DBG("CACHE_ALLO: allocated cache page "_SPIPRIi" for pix "_SPIPRIpg "\n", cp->ix, cp->pix);
|
fs->cache_hits++;
|
||||||
|
#endif
|
||||||
s32_t res2 = SPIFFS_HAL_READ(fs,
|
cp->last_access = cache->last_access;
|
||||||
addr - SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr),
|
u8_t *mem = spiffs_get_cache_page(fs, cache, cp->ix);
|
||||||
SPIFFS_CFG_LOG_PAGE_SZ(fs),
|
_SPIFFS_MEMCPY(dst, &mem[SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr)], len);
|
||||||
spiffs_get_cache_page(fs, cache, cp->ix));
|
|
||||||
if (res2 != SPIFFS_OK) {
|
|
||||||
// honor read failure before possible write failure (bad idea?)
|
|
||||||
res = res2;
|
|
||||||
}
|
|
||||||
u8_t *mem = spiffs_get_cache_page(fs, cache, cp->ix);
|
|
||||||
_SPIFFS_MEMCPY(dst, &mem[SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr)], len);
|
|
||||||
} else {
|
} else {
|
||||||
// this will never happen, last resort for sake of symmetry
|
if ((op & SPIFFS_OP_TYPE_MASK) == SPIFFS_OP_T_OBJ_LU2) {
|
||||||
s32_t res2 = SPIFFS_HAL_READ(fs, addr, len, dst);
|
// for second layer lookup functions, we do not cache in order to prevent shredding
|
||||||
if (res2 != SPIFFS_OK) {
|
return SPIFFS_HAL_READ(fs, addr, len, dst);
|
||||||
// honor read failure before possible write failure (bad idea?)
|
}
|
||||||
res = res2;
|
#if SPIFFS_CACHE_STATS
|
||||||
}
|
fs->cache_misses++;
|
||||||
|
#endif
|
||||||
|
// this operation will always free one cache page (unless all already free),
|
||||||
|
// the result code stems from the write operation of the possibly freed cache page
|
||||||
|
res = spiffs_cache_page_remove_oldest(fs, SPIFFS_CACHE_FLAG_TYPE_WR, 0);
|
||||||
|
|
||||||
|
cp = spiffs_cache_page_allocate(fs);
|
||||||
|
if (cp) {
|
||||||
|
cp->flags = SPIFFS_CACHE_FLAG_WRTHRU;
|
||||||
|
cp->ucache.spix.pix = SPIFFS_PADDR_TO_PAGE(fs, addr);
|
||||||
|
SPIFFS_CACHE_DBG("CACHE_ALLO: allocated cache page "_SPIPRIi" for pix "_SPIPRIpg "\n", cp->ix, cp->pix);
|
||||||
|
|
||||||
|
s32_t res2 = SPIFFS_HAL_READ(fs,
|
||||||
|
addr - SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr),
|
||||||
|
SPIFFS_CFG_LOG_PAGE_SZ(fs),
|
||||||
|
spiffs_get_cache_page(fs, cache, cp->ix));
|
||||||
|
if (res2 != SPIFFS_OK) {
|
||||||
|
// honor read failure before possible write failure (bad idea?)
|
||||||
|
res = res2;
|
||||||
|
}
|
||||||
|
u8_t *mem = spiffs_get_cache_page(fs, cache, cp->ix);
|
||||||
|
_SPIFFS_MEMCPY(dst, &mem[SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr)], len);
|
||||||
|
} else {
|
||||||
|
// this will never happen, last resort for sake of symmetry
|
||||||
|
s32_t res2 = SPIFFS_HAL_READ(fs, addr, len, dst);
|
||||||
|
if (res2 != SPIFFS_OK) {
|
||||||
|
// honor read failure before possible write failure (bad idea?)
|
||||||
|
res = res2;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return res;
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// writes to spi flash and/or the cache
|
// writes to spi flash and/or the cache
|
||||||
|
@ -188,132 +188,132 @@ s32_t spiffs_phys_wr(
|
||||||
u32_t addr,
|
u32_t addr,
|
||||||
u32_t len,
|
u32_t len,
|
||||||
u8_t *src) {
|
u8_t *src) {
|
||||||
(void)fh;
|
(void)fh;
|
||||||
spiffs_page_ix pix = SPIFFS_PADDR_TO_PAGE(fs, addr);
|
spiffs_page_ix pix = SPIFFS_PADDR_TO_PAGE(fs, addr);
|
||||||
spiffs_cache *cache = spiffs_get_cache(fs);
|
spiffs_cache *cache = spiffs_get_cache(fs);
|
||||||
spiffs_cache_page *cp = spiffs_cache_page_get(fs, pix);
|
spiffs_cache_page *cp = spiffs_cache_page_get(fs, pix);
|
||||||
|
|
||||||
if (cp && (op & SPIFFS_OP_COM_MASK) != SPIFFS_OP_C_WRTHRU) {
|
if (cp && (op & SPIFFS_OP_COM_MASK) != SPIFFS_OP_C_WRTHRU) {
|
||||||
// have a cache page
|
// have a cache page
|
||||||
// copy in data to cache page
|
// copy in data to cache page
|
||||||
|
|
||||||
if ((op & SPIFFS_OP_COM_MASK) == SPIFFS_OP_C_DELE &&
|
if ((op & SPIFFS_OP_COM_MASK) == SPIFFS_OP_C_DELE &&
|
||||||
(op & SPIFFS_OP_TYPE_MASK) != SPIFFS_OP_T_OBJ_LU) {
|
(op & SPIFFS_OP_TYPE_MASK) != SPIFFS_OP_T_OBJ_LU) {
|
||||||
// page is being deleted, wipe from cache - unless it is a lookup page
|
// page is being deleted, wipe from cache - unless it is a lookup page
|
||||||
spiffs_cache_page_free(fs, cp->ix, 0);
|
spiffs_cache_page_free(fs, cp->ix, 0);
|
||||||
return SPIFFS_HAL_WRITE(fs, addr, len, src);
|
return SPIFFS_HAL_WRITE(fs, addr, len, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
u8_t *mem = spiffs_get_cache_page(fs, cache, cp->ix);
|
u8_t *mem = spiffs_get_cache_page(fs, cache, cp->ix);
|
||||||
_SPIFFS_MEMCPY(&mem[SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr)], src, len);
|
_SPIFFS_MEMCPY(&mem[SPIFFS_PADDR_TO_PAGE_OFFSET(fs, addr)], src, len);
|
||||||
|
|
||||||
cache->last_access++;
|
cache->last_access++;
|
||||||
cp->last_access = cache->last_access;
|
cp->last_access = cache->last_access;
|
||||||
|
|
||||||
if (cp->flags & SPIFFS_CACHE_FLAG_WRTHRU) {
|
if (cp->flags & SPIFFS_CACHE_FLAG_WRTHRU) {
|
||||||
// page is being updated, no write-cache, just pass thru
|
// page is being updated, no write-cache, just pass thru
|
||||||
return SPIFFS_HAL_WRITE(fs, addr, len, src);
|
return SPIFFS_HAL_WRITE(fs, addr, len, src);
|
||||||
|
} else {
|
||||||
|
return SPIFFS_OK;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return SPIFFS_OK;
|
// no cache page, no write cache - just write thru
|
||||||
|
return SPIFFS_HAL_WRITE(fs, addr, len, src);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// no cache page, no write cache - just write thru
|
|
||||||
return SPIFFS_HAL_WRITE(fs, addr, len, src);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SPIFFS_CACHE_WR
|
#if SPIFFS_CACHE_WR
|
||||||
// returns the cache page that this fd refers, or null if no cache page
|
// returns the cache page that this fd refers, or null if no cache page
|
||||||
spiffs_cache_page *spiffs_cache_page_get_by_fd(spiffs *fs, spiffs_fd *fd) {
|
spiffs_cache_page *spiffs_cache_page_get_by_fd(spiffs *fs, spiffs_fd *fd) {
|
||||||
spiffs_cache *cache = spiffs_get_cache(fs);
|
spiffs_cache *cache = spiffs_get_cache(fs);
|
||||||
|
|
||||||
if ((cache->cpage_use_map & cache->cpage_use_mask) == 0) {
|
if ((cache->cpage_use_map & cache->cpage_use_mask) == 0) {
|
||||||
// all cpages free, no cpage cannot be assigned to obj_id
|
// all cpages free, no cpage cannot be assigned to obj_id
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < cache->cpage_count; i++) {
|
|
||||||
spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, i);
|
|
||||||
if ((cache->cpage_use_map & (1<<i)) &&
|
|
||||||
(cp->flags & SPIFFS_CACHE_FLAG_TYPE_WR) &&
|
|
||||||
cp->ucache.swrc.obj_id == fd->obj_id) {
|
|
||||||
return cp;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
int i;
|
||||||
|
for (i = 0; i < cache->cpage_count; i++) {
|
||||||
|
spiffs_cache_page *cp = spiffs_get_cache_page_hdr(fs, cache, i);
|
||||||
|
if ((cache->cpage_use_map & (1 << i)) &&
|
||||||
|
(cp->flags & SPIFFS_CACHE_FLAG_TYPE_WR) &&
|
||||||
|
cp->ucache.swrc.obj_id == fd->obj_id) {
|
||||||
|
return cp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocates a new cache page and refers this to given fd - flushes an old cache
|
// allocates a new cache page and refers this to given fd - flushes an old cache
|
||||||
// page if all cache is busy
|
// page if all cache is busy
|
||||||
spiffs_cache_page *spiffs_cache_page_allocate_by_fd(spiffs *fs, spiffs_fd *fd) {
|
spiffs_cache_page *spiffs_cache_page_allocate_by_fd(spiffs *fs, spiffs_fd *fd) {
|
||||||
// before this function is called, it is ensured that there is no already existing
|
// before this function is called, it is ensured that there is no already existing
|
||||||
// cache page with same object id
|
// cache page with same object id
|
||||||
spiffs_cache_page_remove_oldest(fs, SPIFFS_CACHE_FLAG_TYPE_WR, 0);
|
spiffs_cache_page_remove_oldest(fs, SPIFFS_CACHE_FLAG_TYPE_WR, 0);
|
||||||
spiffs_cache_page *cp = spiffs_cache_page_allocate(fs);
|
spiffs_cache_page *cp = spiffs_cache_page_allocate(fs);
|
||||||
if (cp == 0) {
|
if (cp == 0) {
|
||||||
// could not get cache page
|
// could not get cache page
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cp->flags = SPIFFS_CACHE_FLAG_TYPE_WR;
|
cp->flags = SPIFFS_CACHE_FLAG_TYPE_WR;
|
||||||
cp->ucache.swrc.obj_id = fd->obj_id;
|
cp->ucache.swrc.obj_id = fd->obj_id;
|
||||||
fd->cache_page = cp;
|
fd->cache_page = cp;
|
||||||
SPIFFS_CACHE_DBG("CACHE_ALLO: allocated cache page "_SPIPRIi" for fd "_SPIPRIfd ":"_SPIPRIid "\n", cp->ix, fd->file_nbr, fd->obj_id);
|
SPIFFS_CACHE_DBG("CACHE_ALLO: allocated cache page "_SPIPRIi" for fd "_SPIPRIfd ":"_SPIPRIid "\n", cp->ix, fd->file_nbr, fd->obj_id);
|
||||||
return cp;
|
return cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// unrefers all fds that this cache page refers to and releases the cache page
|
// unrefers all fds that this cache page refers to and releases the cache page
|
||||||
void spiffs_cache_fd_release(spiffs *fs, spiffs_cache_page *cp) {
|
void spiffs_cache_fd_release(spiffs *fs, spiffs_cache_page *cp) {
|
||||||
if (cp == 0) return;
|
if (cp == 0) return;
|
||||||
u32_t i;
|
u32_t i;
|
||||||
spiffs_fd *fds = (spiffs_fd *)fs->fd_space;
|
spiffs_fd *fds = (spiffs_fd *)fs->fd_space;
|
||||||
for (i = 0; i < fs->fd_count; i++) {
|
for (i = 0; i < fs->fd_count; i++) {
|
||||||
spiffs_fd *cur_fd = &fds[i];
|
spiffs_fd *cur_fd = &fds[i];
|
||||||
if (cur_fd->file_nbr != 0 && cur_fd->cache_page == cp) {
|
if (cur_fd->file_nbr != 0 && cur_fd->cache_page == cp) {
|
||||||
cur_fd->cache_page = 0;
|
cur_fd->cache_page = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
spiffs_cache_page_free(fs, cp->ix, 0);
|
||||||
spiffs_cache_page_free(fs, cp->ix, 0);
|
|
||||||
|
|
||||||
cp->ucache.swrc.obj_id = 0;
|
cp->ucache.swrc.obj_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// initializes the cache
|
// initializes the cache
|
||||||
void spiffs_cache_init(spiffs *fs) {
|
void spiffs_cache_init(spiffs *fs) {
|
||||||
if (fs->cache == 0) return;
|
if (fs->cache == 0) return;
|
||||||
u32_t sz = fs->cache_size;
|
u32_t sz = fs->cache_size;
|
||||||
u32_t cache_mask = 0;
|
u32_t cache_mask = 0;
|
||||||
int i;
|
int i;
|
||||||
int cache_entries =
|
int cache_entries =
|
||||||
(sz - sizeof(spiffs_cache)) / (SPIFFS_CACHE_PAGE_SIZE(fs));
|
(sz - sizeof(spiffs_cache)) / (SPIFFS_CACHE_PAGE_SIZE(fs));
|
||||||
if (cache_entries <= 0) return;
|
if (cache_entries <= 0) return;
|
||||||
|
|
||||||
for (i = 0; i < cache_entries; i++) {
|
for (i = 0; i < cache_entries; i++) {
|
||||||
cache_mask <<= 1;
|
cache_mask <<= 1;
|
||||||
cache_mask |= 1;
|
cache_mask |= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
spiffs_cache cache;
|
spiffs_cache cache;
|
||||||
memset(&cache, 0, sizeof(spiffs_cache));
|
memset(&cache, 0, sizeof(spiffs_cache));
|
||||||
cache.cpage_count = cache_entries;
|
cache.cpage_count = cache_entries;
|
||||||
cache.cpages = (u8_t *)((u8_t *)fs->cache + sizeof(spiffs_cache));
|
cache.cpages = (u8_t *)((u8_t *)fs->cache + sizeof(spiffs_cache));
|
||||||
|
|
||||||
cache.cpage_use_map = 0xffffffff;
|
cache.cpage_use_map = 0xffffffff;
|
||||||
cache.cpage_use_mask = cache_mask;
|
cache.cpage_use_mask = cache_mask;
|
||||||
_SPIFFS_MEMCPY(fs->cache, &cache, sizeof(spiffs_cache));
|
_SPIFFS_MEMCPY(fs->cache, &cache, sizeof(spiffs_cache));
|
||||||
|
|
||||||
spiffs_cache *c = spiffs_get_cache(fs);
|
spiffs_cache *c = spiffs_get_cache(fs);
|
||||||
|
|
||||||
memset(c->cpages, 0, c->cpage_count * SPIFFS_CACHE_PAGE_SIZE(fs));
|
memset(c->cpages, 0, c->cpage_count * SPIFFS_CACHE_PAGE_SIZE(fs));
|
||||||
|
|
||||||
c->cpage_use_map &= ~(c->cpage_use_mask);
|
c->cpage_use_map &= ~(c->cpage_use_mask);
|
||||||
for (i = 0; i < cache.cpage_count; i++) {
|
for (i = 0; i < cache.cpage_count; i++) {
|
||||||
spiffs_get_cache_page_hdr(fs, c, i)->ix = i;
|
spiffs_get_cache_page_hdr(fs, c, i)->ix = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // SPIFFS_CACHE
|
#endif // SPIFFS_CACHE
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -25,12 +25,12 @@ void Dbprintf(const char *fmt, ...);
|
||||||
// ----------- >8 ------------
|
// ----------- >8 ------------
|
||||||
|
|
||||||
|
|
||||||
typedef int s32_t;
|
typedef int s32_t;
|
||||||
typedef uint32_t u32_t;
|
typedef uint32_t u32_t;
|
||||||
typedef int16_t s16_t;
|
typedef int16_t s16_t;
|
||||||
typedef uint16_t u16_t;
|
typedef uint16_t u16_t;
|
||||||
typedef int8_t s8_t;
|
typedef int8_t s8_t;
|
||||||
typedef uint8_t u8_t;
|
typedef uint8_t u8_t;
|
||||||
|
|
||||||
// compile time switches
|
// compile time switches
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -144,15 +144,15 @@
|
||||||
|
|
||||||
|
|
||||||
#if defined(__GNUC__) || defined(__clang__) || defined(__TI_COMPILER_VERSION__)
|
#if defined(__GNUC__) || defined(__clang__) || defined(__TI_COMPILER_VERSION__)
|
||||||
/* For GCC, clang and TI compilers */
|
/* For GCC, clang and TI compilers */
|
||||||
#define SPIFFS_PACKED __attribute__((packed))
|
#define SPIFFS_PACKED __attribute__((packed))
|
||||||
#elif defined(__ICCARM__) || defined(__CC_ARM)
|
#elif defined(__ICCARM__) || defined(__CC_ARM)
|
||||||
/* For IAR ARM and Keil MDK-ARM compilers */
|
/* For IAR ARM and Keil MDK-ARM compilers */
|
||||||
#define SPIFFS_PACKED
|
#define SPIFFS_PACKED
|
||||||
|
|
||||||
#else
|
#else
|
||||||
/* Unknown compiler */
|
/* Unknown compiler */
|
||||||
#define SPIFFS_PACKED
|
#define SPIFFS_PACKED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -338,7 +338,7 @@
|
||||||
if (((ph).flags & SPIFFS_PH_FLAG_INDEX) != 0) return SPIFFS_ERR_NOT_INDEX; \
|
if (((ph).flags & SPIFFS_PH_FLAG_INDEX) != 0) return SPIFFS_ERR_NOT_INDEX; \
|
||||||
if (((objid) & SPIFFS_OBJ_ID_IX_FLAG) == 0) return SPIFFS_ERR_NOT_INDEX; \
|
if (((objid) & SPIFFS_OBJ_ID_IX_FLAG) == 0) return SPIFFS_ERR_NOT_INDEX; \
|
||||||
if ((ph).span_ix != (spix)) return SPIFFS_ERR_INDEX_SPAN_MISMATCH;
|
if ((ph).span_ix != (spix)) return SPIFFS_ERR_INDEX_SPAN_MISMATCH;
|
||||||
//if ((spix) == 0 && ((ph).flags & SPIFFS_PH_FLAG_IXDELE) == 0) return SPIFFS_ERR_DELETED;
|
//if ((spix) == 0 && ((ph).flags & SPIFFS_PH_FLAG_IXDELE) == 0) return SPIFFS_ERR_DELETED;
|
||||||
|
|
||||||
#define SPIFFS_VALIDATE_DATA(ph, objid, spix) \
|
#define SPIFFS_VALIDATE_DATA(ph, objid, spix) \
|
||||||
if (((ph).flags & SPIFFS_PH_FLAG_USED) != 0) return SPIFFS_ERR_IS_FREE; \
|
if (((ph).flags & SPIFFS_PH_FLAG_USED) != 0) return SPIFFS_ERR_IS_FREE; \
|
||||||
|
@ -399,39 +399,39 @@
|
||||||
|
|
||||||
// cache page struct
|
// cache page struct
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// cache flags
|
// cache flags
|
||||||
u8_t flags;
|
u8_t flags;
|
||||||
// cache page index
|
// cache page index
|
||||||
u8_t ix;
|
u8_t ix;
|
||||||
// last access of this cache page
|
// last access of this cache page
|
||||||
u32_t last_access;
|
u32_t last_access;
|
||||||
union {
|
union {
|
||||||
// type read cache
|
// type read cache
|
||||||
struct spix {
|
struct spix {
|
||||||
// read cache page index
|
// read cache page index
|
||||||
spiffs_page_ix pix;
|
spiffs_page_ix pix;
|
||||||
} spix;
|
} spix;
|
||||||
#if SPIFFS_CACHE_WR
|
#if SPIFFS_CACHE_WR
|
||||||
// type write cache
|
// type write cache
|
||||||
struct swrc {
|
struct swrc {
|
||||||
// write cache
|
// write cache
|
||||||
spiffs_obj_id obj_id;
|
spiffs_obj_id obj_id;
|
||||||
// offset in cache page
|
// offset in cache page
|
||||||
u32_t offset;
|
u32_t offset;
|
||||||
// size of cache page
|
// size of cache page
|
||||||
u16_t size;
|
u16_t size;
|
||||||
} swrc;
|
} swrc;
|
||||||
#endif
|
#endif
|
||||||
} ucache;
|
} ucache;
|
||||||
} spiffs_cache_page;
|
} spiffs_cache_page;
|
||||||
|
|
||||||
// cache struct
|
// cache struct
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u8_t cpage_count;
|
u8_t cpage_count;
|
||||||
u32_t last_access;
|
u32_t last_access;
|
||||||
u32_t cpage_use_map;
|
u32_t cpage_use_map;
|
||||||
u32_t cpage_use_mask;
|
u32_t cpage_use_mask;
|
||||||
u8_t *cpages;
|
u8_t *cpages;
|
||||||
} spiffs_cache;
|
} spiffs_cache;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -439,38 +439,38 @@ typedef struct {
|
||||||
|
|
||||||
// spiffs nucleus file descriptor
|
// spiffs nucleus file descriptor
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// the filesystem of this descriptor
|
// the filesystem of this descriptor
|
||||||
spiffs *fs;
|
spiffs *fs;
|
||||||
// number of file descriptor - if 0, the file descriptor is closed
|
// number of file descriptor - if 0, the file descriptor is closed
|
||||||
spiffs_file file_nbr;
|
spiffs_file file_nbr;
|
||||||
// object id - if SPIFFS_OBJ_ID_ERASED, the file was deleted
|
// object id - if SPIFFS_OBJ_ID_ERASED, the file was deleted
|
||||||
spiffs_obj_id obj_id;
|
spiffs_obj_id obj_id;
|
||||||
// size of the file
|
// size of the file
|
||||||
u32_t size;
|
u32_t size;
|
||||||
// cached object index header page index
|
// cached object index header page index
|
||||||
spiffs_page_ix objix_hdr_pix;
|
spiffs_page_ix objix_hdr_pix;
|
||||||
// cached offset object index page index
|
// cached offset object index page index
|
||||||
spiffs_page_ix cursor_objix_pix;
|
spiffs_page_ix cursor_objix_pix;
|
||||||
// cached offset object index span index
|
// cached offset object index span index
|
||||||
spiffs_span_ix cursor_objix_spix;
|
spiffs_span_ix cursor_objix_spix;
|
||||||
// current absolute offset
|
// current absolute offset
|
||||||
u32_t offset;
|
u32_t offset;
|
||||||
// current file descriptor offset (cached)
|
// current file descriptor offset (cached)
|
||||||
u32_t fdoffset;
|
u32_t fdoffset;
|
||||||
// fd flags
|
// fd flags
|
||||||
spiffs_flags flags;
|
spiffs_flags flags;
|
||||||
#if SPIFFS_CACHE_WR
|
#if SPIFFS_CACHE_WR
|
||||||
spiffs_cache_page *cache_page;
|
spiffs_cache_page *cache_page;
|
||||||
#endif
|
#endif
|
||||||
#if SPIFFS_TEMPORAL_FD_CACHE
|
#if SPIFFS_TEMPORAL_FD_CACHE
|
||||||
// djb2 hash of filename
|
// djb2 hash of filename
|
||||||
u32_t name_hash;
|
u32_t name_hash;
|
||||||
// hit score (score == 0 indicates never used fd)
|
// hit score (score == 0 indicates never used fd)
|
||||||
u16_t score;
|
u16_t score;
|
||||||
#endif
|
#endif
|
||||||
#if SPIFFS_IX_MAP
|
#if SPIFFS_IX_MAP
|
||||||
// spiffs index map, if 0 it means unmapped
|
// spiffs index map, if 0 it means unmapped
|
||||||
spiffs_ix_map *ix_map;
|
spiffs_ix_map *ix_map;
|
||||||
#endif
|
#endif
|
||||||
} spiffs_fd;
|
} spiffs_fd;
|
||||||
|
|
||||||
|
@ -481,45 +481,46 @@ typedef struct {
|
||||||
// NB: this is always aligned when the data page is an object index,
|
// NB: this is always aligned when the data page is an object index,
|
||||||
// as in this case struct spiffs_page_object_ix is used
|
// as in this case struct spiffs_page_object_ix is used
|
||||||
typedef struct SPIFFS_PACKED {
|
typedef struct SPIFFS_PACKED {
|
||||||
// object id
|
// object id
|
||||||
spiffs_obj_id obj_id;
|
spiffs_obj_id obj_id;
|
||||||
// object span index
|
// object span index
|
||||||
spiffs_span_ix span_ix;
|
spiffs_span_ix span_ix;
|
||||||
// flags
|
// flags
|
||||||
u8_t flags;
|
u8_t flags;
|
||||||
} spiffs_page_header;
|
} spiffs_page_header;
|
||||||
|
|
||||||
// object index header page header
|
// object index header page header
|
||||||
typedef struct SPIFFS_PACKED
|
typedef struct SPIFFS_PACKED
|
||||||
#if SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
|
#if SPIFFS_ALIGNED_OBJECT_INDEX_TABLES
|
||||||
__attribute(( aligned(sizeof(spiffs_page_ix)) ))
|
__attribute((aligned(sizeof(spiffs_page_ix))))
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
// common page header
|
// common page header
|
||||||
spiffs_page_header p_hdr;
|
spiffs_page_header p_hdr;
|
||||||
// alignment
|
// alignment
|
||||||
u8_t _align[4 - ((sizeof(spiffs_page_header)&3)==0 ? 4 : (sizeof(spiffs_page_header)&3))];
|
u8_t _align[4 - ((sizeof(spiffs_page_header) & 3) == 0 ? 4 : (sizeof(spiffs_page_header) & 3))];
|
||||||
// size of object
|
// size of object
|
||||||
u32_t size;
|
u32_t size;
|
||||||
// type of object
|
// type of object
|
||||||
spiffs_obj_type type;
|
spiffs_obj_type type;
|
||||||
// name of object
|
// name of object
|
||||||
u8_t name[SPIFFS_OBJ_NAME_LEN];
|
u8_t name[SPIFFS_OBJ_NAME_LEN];
|
||||||
#if SPIFFS_OBJ_META_LEN
|
#if SPIFFS_OBJ_META_LEN
|
||||||
// metadata. not interpreted by SPIFFS in any way.
|
// metadata. not interpreted by SPIFFS in any way.
|
||||||
u8_t meta[SPIFFS_OBJ_META_LEN];
|
u8_t meta[SPIFFS_OBJ_META_LEN];
|
||||||
#endif
|
#endif
|
||||||
} spiffs_page_object_ix_header;
|
}
|
||||||
|
spiffs_page_object_ix_header;
|
||||||
|
|
||||||
// object index page header
|
// object index page header
|
||||||
typedef struct SPIFFS_PACKED {
|
typedef struct SPIFFS_PACKED {
|
||||||
spiffs_page_header p_hdr;
|
spiffs_page_header p_hdr;
|
||||||
u8_t _align[4 - ((sizeof(spiffs_page_header)&3)==0 ? 4 : (sizeof(spiffs_page_header)&3))];
|
u8_t _align[4 - ((sizeof(spiffs_page_header) & 3) == 0 ? 4 : (sizeof(spiffs_page_header) & 3))];
|
||||||
} spiffs_page_object_ix;
|
} spiffs_page_object_ix;
|
||||||
|
|
||||||
// callback func for object lookup visitor
|
// callback func for object lookup visitor
|
||||||
typedef s32_t (*spiffs_visitor_f)(spiffs *fs, spiffs_obj_id id, spiffs_block_ix bix, int ix_entry,
|
typedef s32_t (*spiffs_visitor_f)(spiffs *fs, spiffs_obj_id id, spiffs_block_ix bix, int ix_entry,
|
||||||
const void *user_const_p, void *user_var_p);
|
const void *user_const_p, void *user_var_p);
|
||||||
|
|
||||||
|
|
||||||
#if SPIFFS_CACHE
|
#if SPIFFS_CACHE
|
||||||
|
|
135
armsrc/string.c
135
armsrc/string.c
|
@ -109,98 +109,89 @@ void itoa(int n, char s[]) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char *strcpy(char *dst, const char *src)
|
char *strcpy(char *dst, const char *src) {
|
||||||
{
|
char *save = dst;
|
||||||
char *save = dst;
|
|
||||||
|
|
||||||
for (; (*dst = *src) != '\0'; ++src, ++dst);
|
for (; (*dst = *src) != '\0'; ++src, ++dst);
|
||||||
return save;
|
return save;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *strncpy(char *dst, const char *src, size_t n)
|
char *strncpy(char *dst, const char *src, size_t n) {
|
||||||
{
|
if (n != 0) {
|
||||||
if (n != 0) {
|
char *d = dst;
|
||||||
char *d = dst;
|
const char *s = src;
|
||||||
const char *s = src;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if ((*d++ = *s++) == 0) {
|
if ((*d++ = *s++) == 0) {
|
||||||
/* NUL pad the remaining n-1 bytes */
|
/* NUL pad the remaining n-1 bytes */
|
||||||
while (--n) {
|
while (--n) {
|
||||||
*d++ = 0;
|
*d++ = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (--n);
|
} while (--n);
|
||||||
}
|
}
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
int strcmp(const char *s1, const char *s2)
|
int strcmp(const char *s1, const char *s2) {
|
||||||
{
|
|
||||||
while (*s1 == *s2++) {
|
while (*s1 == *s2++) {
|
||||||
if (*s1++ == 0) {
|
if (*s1++ == 0) {
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (*(unsigned char *) s1 - *(unsigned char *) --s2);
|
return (*(unsigned char *) s1 - * (unsigned char *) --s2);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* __strtok_r(char*, const char*, char**);
|
char *__strtok_r(char *, const char *, char **);
|
||||||
|
|
||||||
char* __strtok_r(char* s, const char* delim, char** last)
|
char *__strtok_r(char *s, const char *delim, char **last) {
|
||||||
{
|
char *spanp, *tok;
|
||||||
char *spanp, *tok;
|
int c, sc;
|
||||||
int c, sc;
|
|
||||||
|
|
||||||
if(s == NULL && (s = *last) == NULL)
|
if (s == NULL && (s = *last) == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Skip (span) leading delimiters (s += strspn(s, delim), sort of).
|
* Skip (span) leading delimiters (s += strspn(s, delim), sort of).
|
||||||
*/
|
*/
|
||||||
cont:
|
cont:
|
||||||
c = *s++;
|
c = *s++;
|
||||||
for(spanp = (char*)delim; (sc = *spanp++) != 0;)
|
for (spanp = (char *)delim; (sc = *spanp++) != 0;) {
|
||||||
{
|
if (c == sc)
|
||||||
if(c == sc)
|
goto cont;
|
||||||
goto cont;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(c == 0)
|
if (c == 0) {
|
||||||
{ /* no non-delimiter characters */
|
/* no non-delimiter characters */
|
||||||
*last = NULL;
|
*last = NULL;
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
tok = s - 1;
|
tok = s - 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
|
* Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
|
||||||
* Note that delim must have one NUL; we stop if we see that, too.
|
* Note that delim must have one NUL; we stop if we see that, too.
|
||||||
*/
|
*/
|
||||||
for(;;)
|
for (;;) {
|
||||||
{
|
c = *s++;
|
||||||
c = *s++;
|
spanp = (char *)delim;
|
||||||
spanp = (char*)delim;
|
do {
|
||||||
do
|
if ((sc = *spanp++) == c) {
|
||||||
{
|
if (c == 0)
|
||||||
if((sc = *spanp++) == c)
|
s = NULL;
|
||||||
{
|
else
|
||||||
if(c == 0)
|
s[-1] = '\0';
|
||||||
s = NULL;
|
*last = s;
|
||||||
else
|
return (tok);
|
||||||
s[-1] = '\0';
|
}
|
||||||
*last = s;
|
} while (sc != 0);
|
||||||
return (tok);
|
}
|
||||||
}
|
/* NOTREACHED */
|
||||||
} while(sc != 0);
|
|
||||||
}
|
|
||||||
/* NOTREACHED */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char* strtok(char* s, const char* delim)
|
char *strtok(char *s, const char *delim) {
|
||||||
{
|
static char *last;
|
||||||
static char* last;
|
|
||||||
|
|
||||||
return (__strtok_r(s, delim, &last));
|
return (__strtok_r(s, delim, &last));
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@ char *strcat(char *dest, const char *src);
|
||||||
void strreverse(char s[]);
|
void strreverse(char s[]);
|
||||||
void itoa(int n, char s[]);
|
void itoa(int n, char s[]);
|
||||||
char *strcpy(char *dst, const char *src);
|
char *strcpy(char *dst, const char *src);
|
||||||
char* strncpy(char* destination, const char* source, size_t num);
|
char *strncpy(char *destination, const char *source, size_t num);
|
||||||
int strcmp(const char *s1, const char *s2);
|
int strcmp(const char *s1, const char *s2);
|
||||||
char* strtok(char* s, const char* delim);
|
char *strtok(char *s, const char *delim);
|
||||||
|
|
||||||
#endif /* __STRING_H */
|
#endif /* __STRING_H */
|
||||||
|
|
|
@ -865,7 +865,7 @@ static int CmdBitsamples(const char *Cmd) {
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
uint8_t got[12288];
|
uint8_t got[12288];
|
||||||
|
|
||||||
if (!GetFromDevice(BIG_BUF, got, sizeof(got), 0,NULL,0, NULL, 2500, false)) {
|
if (!GetFromDevice(BIG_BUF, got, sizeof(got), 0, NULL, 0, NULL, 2500, false)) {
|
||||||
PrintAndLogEx(WARNING, "command execution time out");
|
PrintAndLogEx(WARNING, "command execution time out");
|
||||||
return PM3_ETIMEOUT;
|
return PM3_ETIMEOUT;
|
||||||
}
|
}
|
||||||
|
@ -1397,7 +1397,7 @@ static int CmdHexsamples(const char *Cmd) {
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GetFromDevice(BIG_BUF, got, requested, offset,NULL,0, NULL, 2500, false)) {
|
if (!GetFromDevice(BIG_BUF, got, requested, offset, NULL, 0, NULL, 2500, false)) {
|
||||||
PrintAndLogEx(WARNING, "command execution time out");
|
PrintAndLogEx(WARNING, "command execution time out");
|
||||||
return PM3_ESOFT;
|
return PM3_ESOFT;
|
||||||
}
|
}
|
||||||
|
@ -1470,7 +1470,7 @@ int getSamples(uint32_t n, bool silent) {
|
||||||
if (!silent) PrintAndLogEx(NORMAL, "Reading %d bytes from device memory\n", n);
|
if (!silent) PrintAndLogEx(NORMAL, "Reading %d bytes from device memory\n", n);
|
||||||
|
|
||||||
PacketResponseNG response;
|
PacketResponseNG response;
|
||||||
if (!GetFromDevice(BIG_BUF, got, n, 0,NULL,0, &response, 10000, true)) {
|
if (!GetFromDevice(BIG_BUF, got, n, 0, NULL, 0, &response, 10000, true)) {
|
||||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
return PM3_ETIMEOUT;
|
return PM3_ETIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
|
@ -315,7 +315,7 @@ static int CmdFlashMemDump(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintAndLogEx(INFO, "downloading "_YELLOW_("%u")"bytes from flashmem", len);
|
PrintAndLogEx(INFO, "downloading "_YELLOW_("%u")"bytes from flashmem", len);
|
||||||
if (!GetFromDevice(FLASH_MEM, dump, len, start_index,NULL,0, NULL, -1, true)) {
|
if (!GetFromDevice(FLASH_MEM, dump, len, start_index, NULL, 0, NULL, -1, true)) {
|
||||||
PrintAndLogEx(FAILED, "ERROR; downloading from flashmemory");
|
PrintAndLogEx(FAILED, "ERROR; downloading from flashmemory");
|
||||||
free(dump);
|
free(dump);
|
||||||
return PM3_EFLASH;
|
return PM3_EFLASH;
|
||||||
|
|
|
@ -216,37 +216,37 @@ static int CmdFlashMemSpiFFSDump(const char *Cmd) {
|
||||||
|
|
||||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||||
case 'h':
|
case 'h':
|
||||||
return usage_flashmemspiffs_dump();
|
return usage_flashmemspiffs_dump();
|
||||||
/*case 'l':
|
/*case 'l':
|
||||||
len = param_get32ex(Cmd, cmdp + 1, FLASH_MEM_MAX_SIZE, 10);
|
len = param_get32ex(Cmd, cmdp + 1, FLASH_MEM_MAX_SIZE, 10);
|
||||||
cmdp += 2;
|
cmdp += 2;
|
||||||
break;*/
|
break;*/
|
||||||
case 'o':
|
case 'o':
|
||||||
param_getstr(Cmd, cmdp + 1, destfilename, 32);
|
param_getstr(Cmd, cmdp + 1, destfilename, 32);
|
||||||
cmdp += 2;
|
cmdp += 2;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
print = true;
|
print = true;
|
||||||
cmdp += 1;
|
cmdp += 1;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
eml = true;
|
eml = true;
|
||||||
cmdp += 1;
|
cmdp += 1;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
// File handling
|
// File handling
|
||||||
if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) {
|
if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) {
|
||||||
PrintAndLogEx(FAILED, "Filename too long");
|
PrintAndLogEx(FAILED, "Filename too long");
|
||||||
|
errors = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cmdp += 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||||
errors = true;
|
errors = true;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
cmdp += 2;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
|
||||||
errors = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,24 +314,24 @@ static int CmdFlashMemSpiFFSLoad(const char *Cmd) {
|
||||||
|
|
||||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||||
case 'h':
|
case 'h':
|
||||||
return usage_flashmemspiffs_load();
|
return usage_flashmemspiffs_load();
|
||||||
case 'f':
|
case 'f':
|
||||||
if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) {
|
if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) {
|
||||||
PrintAndLogEx(FAILED, "Filename too long");
|
PrintAndLogEx(FAILED, "Filename too long");
|
||||||
|
errors = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cmdp += 2;
|
||||||
|
break;
|
||||||
|
case 'o':
|
||||||
|
param_getstr(Cmd, cmdp + 1, destfilename, 32);
|
||||||
|
cmdp += 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||||
errors = true;
|
errors = true;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
cmdp += 2;
|
|
||||||
break;
|
|
||||||
case 'o':
|
|
||||||
param_getstr(Cmd, cmdp + 1, destfilename, 32);
|
|
||||||
cmdp += 2;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
|
||||||
errors = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -432,8 +432,10 @@ static int CmdFlashMemSpiFFSLoad(const char *Cmd) {
|
||||||
static command_t CommandTable[] = {
|
static command_t CommandTable[] = {
|
||||||
|
|
||||||
{"help", CmdHelp, AlwaysAvailable, "This help"},
|
{"help", CmdHelp, AlwaysAvailable, "This help"},
|
||||||
{"copy", CmdFlashMemSpiFFSCopy, IfPm3Flash,
|
{
|
||||||
"Copy a file to another (destructively) in SPIFFS FileSystem in FlashMEM (spiffs)"},
|
"copy", CmdFlashMemSpiFFSCopy, IfPm3Flash,
|
||||||
|
"Copy a file to another (destructively) in SPIFFS FileSystem in FlashMEM (spiffs)"
|
||||||
|
},
|
||||||
{"dump", CmdFlashMemSpiFFSDump, IfPm3Flash, "Dump a file from SPIFFS FileSystem in FlashMEM (spiffs)"},
|
{"dump", CmdFlashMemSpiFFSDump, IfPm3Flash, "Dump a file from SPIFFS FileSystem in FlashMEM (spiffs)"},
|
||||||
{"info", CmdFlashMemSpiFFSInfo, IfPm3Flash, "Print filesystem info and usage statistics (spiffs)"},
|
{"info", CmdFlashMemSpiFFSInfo, IfPm3Flash, "Print filesystem info and usage statistics (spiffs)"},
|
||||||
{"load", CmdFlashMemSpiFFSLoad, IfPm3Flash, "Upload file into SPIFFS Filesystem (spiffs)"},
|
{"load", CmdFlashMemSpiFFSLoad, IfPm3Flash, "Upload file into SPIFFS Filesystem (spiffs)"},
|
||||||
|
@ -443,7 +445,8 @@ static command_t CommandTable[] = {
|
||||||
{"test", CmdFlashMemSpiFFSTest, IfPm3Flash, "Test SPIFFS Functionning (require wiping pages 0 and 1)"},
|
{"test", CmdFlashMemSpiFFSTest, IfPm3Flash, "Test SPIFFS Functionning (require wiping pages 0 and 1)"},
|
||||||
{"tree", CmdFlashMemSpiFFSTree, IfPm3Flash, "Print the Flash Memory FileSystem Tree (spiffs)"},
|
{"tree", CmdFlashMemSpiFFSTree, IfPm3Flash, "Print the Flash Memory FileSystem Tree (spiffs)"},
|
||||||
{"unmount", CmdFlashMemSpiFFSUnmount, IfPm3Flash, "Un-mount the SPIFFS Filesystem if not already mounted (spiffs)"},
|
{"unmount", CmdFlashMemSpiFFSUnmount, IfPm3Flash, "Un-mount the SPIFFS Filesystem if not already mounted (spiffs)"},
|
||||||
{NULL, NULL, NULL, NULL}};
|
{NULL, NULL, NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
static int CmdHelp(const char *Cmd) {
|
static int CmdHelp(const char *Cmd) {
|
||||||
(void)Cmd; // Cmd is not used so far
|
(void)Cmd; // Cmd is not used so far
|
||||||
|
|
|
@ -383,7 +383,7 @@ static int CmdHFFelicaDumpLite(const char *Cmd) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GetFromDevice(BIG_BUF, trace, tracelen, 0,NULL,0, NULL, 2500, false)) {
|
if (!GetFromDevice(BIG_BUF, trace, tracelen, 0, NULL, 0, NULL, 2500, false)) {
|
||||||
PrintAndLogEx(WARNING, "command execution time out");
|
PrintAndLogEx(WARNING, "command execution time out");
|
||||||
free(trace);
|
free(trace);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -990,7 +990,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// response ok - now get bigbuf content of the dump
|
// response ok - now get bigbuf content of the dump
|
||||||
if (!GetFromDevice(BIG_BUF, tag_data + (blockno * 8), blocksRead * 8, startindex,NULL,0, NULL, 2500, false)) {
|
if (!GetFromDevice(BIG_BUF, tag_data + (blockno * 8), blocksRead * 8, startindex, NULL, 0, NULL, 2500, false)) {
|
||||||
PrintAndLogEx(WARNING, "command execution time out");
|
PrintAndLogEx(WARNING, "command execution time out");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1033,7 +1033,7 @@ static int CmdHFiClassReader_Dump(const char *Cmd) {
|
||||||
blocksRead = (sizeof(tag_data) - gotBytes) / 8;
|
blocksRead = (sizeof(tag_data) - gotBytes) / 8;
|
||||||
}
|
}
|
||||||
// get dumped data from bigbuf
|
// get dumped data from bigbuf
|
||||||
if (!GetFromDevice(BIG_BUF, tag_data + gotBytes, blocksRead * 8, startindex,NULL,0, NULL, 2500, false)) {
|
if (!GetFromDevice(BIG_BUF, tag_data + gotBytes, blocksRead * 8, startindex, NULL, 0, NULL, 2500, false)) {
|
||||||
PrintAndLogEx(WARNING, "command execution time out");
|
PrintAndLogEx(WARNING, "command execution time out");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -781,7 +781,7 @@ int legic_read_mem(uint32_t offset, uint32_t len, uint32_t iv, uint8_t *out, uin
|
||||||
PrintAndLogEx(WARNING, "Fail, only managed to read %u bytes", *outlen);
|
PrintAndLogEx(WARNING, "Fail, only managed to read %u bytes", *outlen);
|
||||||
|
|
||||||
// copy data from device
|
// copy data from device
|
||||||
if (!GetFromDevice(BIG_BUF_EML, out, *outlen, 0,NULL,0, NULL, 2500, false)) {
|
if (!GetFromDevice(BIG_BUF_EML, out, *outlen, 0, NULL, 0, NULL, 2500, false)) {
|
||||||
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
@ -930,7 +930,7 @@ static int CmdLegicDump(const char *Cmd) {
|
||||||
PrintAndLogEx(WARNING, "Fail, only managed to read 0x%02X bytes of 0x%02X", readlen, dumplen);
|
PrintAndLogEx(WARNING, "Fail, only managed to read 0x%02X bytes of 0x%02X", readlen, dumplen);
|
||||||
|
|
||||||
// copy data from device
|
// copy data from device
|
||||||
if (!GetFromDevice(BIG_BUF_EML, data, readlen, 0,NULL,0, NULL, 2500, false)) {
|
if (!GetFromDevice(BIG_BUF_EML, data, readlen, 0, NULL, 0, NULL, 2500, false)) {
|
||||||
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
||||||
free(data);
|
free(data);
|
||||||
return 4;
|
return 4;
|
||||||
|
@ -1200,7 +1200,7 @@ static int CmdLegicESave(const char *Cmd) {
|
||||||
|
|
||||||
// download emulator memory
|
// download emulator memory
|
||||||
PrintAndLogEx(SUCCESS, "Reading emulator memory...");
|
PrintAndLogEx(SUCCESS, "Reading emulator memory...");
|
||||||
if (!GetFromDevice(BIG_BUF_EML, data, numofbytes, 0,NULL,0, NULL, 2500, false)) {
|
if (!GetFromDevice(BIG_BUF_EML, data, numofbytes, 0, NULL, 0, NULL, 2500, false)) {
|
||||||
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
||||||
free(data);
|
free(data);
|
||||||
return 4;
|
return 4;
|
||||||
|
|
|
@ -2693,7 +2693,7 @@ static int CmdHF14AMfESave(const char *Cmd) {
|
||||||
memset(dump, 0, bytes);
|
memset(dump, 0, bytes);
|
||||||
|
|
||||||
PrintAndLogEx(INFO, "downloading from emulator memory");
|
PrintAndLogEx(INFO, "downloading from emulator memory");
|
||||||
if (!GetFromDevice(BIG_BUF_EML, dump, bytes, 0,NULL,0, NULL, 2500, false)) {
|
if (!GetFromDevice(BIG_BUF_EML, dump, bytes, 0, NULL, 0, NULL, 2500, false)) {
|
||||||
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
PrintAndLogEx(WARNING, "Fail, transfer from device time-out");
|
||||||
free(dump);
|
free(dump);
|
||||||
return PM3_ETIMEOUT;
|
return PM3_ETIMEOUT;
|
||||||
|
|
|
@ -1931,7 +1931,7 @@ static int CmdHF14AMfUDump(const char *Cmd) {
|
||||||
bufferSize = sizeof(data);
|
bufferSize = sizeof(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GetFromDevice(BIG_BUF, data, bufferSize, startindex,NULL,0, NULL, 2500, false)) {
|
if (!GetFromDevice(BIG_BUF, data, bufferSize, startindex, NULL, 0, NULL, 2500, false)) {
|
||||||
PrintAndLogEx(WARNING, "command execution time out");
|
PrintAndLogEx(WARNING, "command execution time out");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ static int CmdCOTAGRead(const char *Cmd) {
|
||||||
}
|
}
|
||||||
case 1: {
|
case 1: {
|
||||||
|
|
||||||
if (!GetFromDevice(BIG_BUF, DemodBuffer, COTAG_BITS, 0,NULL,0, NULL, 1000, false)) {
|
if (!GetFromDevice(BIG_BUF, DemodBuffer, COTAG_BITS, 0, NULL, 0, NULL, 1000, false)) {
|
||||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
return PM3_ETIMEOUT;
|
return PM3_ETIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
|
@ -986,7 +986,7 @@ static bool downloadSamplesEM() {
|
||||||
|
|
||||||
// 8 bit preamble + 32 bit word response (max clock (128) * 40bits = 5120 samples)
|
// 8 bit preamble + 32 bit word response (max clock (128) * 40bits = 5120 samples)
|
||||||
uint8_t got[6000];
|
uint8_t got[6000];
|
||||||
if (!GetFromDevice(BIG_BUF, got, sizeof(got), 0,NULL,0, NULL, 2500, false)) {
|
if (!GetFromDevice(BIG_BUF, got, sizeof(got), 0, NULL, 0, NULL, 2500, false)) {
|
||||||
PrintAndLogEx(WARNING, "command execution time out");
|
PrintAndLogEx(WARNING, "command execution time out");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1804,7 +1804,7 @@ static int CmdResetRead(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t got[BIGBUF_SIZE - 1];
|
uint8_t got[BIGBUF_SIZE - 1];
|
||||||
if (!GetFromDevice(BIG_BUF, got, sizeof(got), 0,NULL,0, NULL, 2500, false)) {
|
if (!GetFromDevice(BIG_BUF, got, sizeof(got), 0, NULL, 0, NULL, 2500, false)) {
|
||||||
PrintAndLogEx(WARNING, "command execution time out");
|
PrintAndLogEx(WARNING, "command execution time out");
|
||||||
return PM3_ETIMEOUT;
|
return PM3_ETIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
|
@ -759,7 +759,7 @@ int CmdTraceList(const char *Cmd) {
|
||||||
if (isOnline) {
|
if (isOnline) {
|
||||||
// Query for the size of the trace, downloading PM3_CMD_DATA_SIZE
|
// Query for the size of the trace, downloading PM3_CMD_DATA_SIZE
|
||||||
PacketResponseNG response;
|
PacketResponseNG response;
|
||||||
if (!GetFromDevice(BIG_BUF, trace, PM3_CMD_DATA_SIZE, 0,NULL,0, &response, 4000, true)) {
|
if (!GetFromDevice(BIG_BUF, trace, PM3_CMD_DATA_SIZE, 0, NULL, 0, &response, 4000, true)) {
|
||||||
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -773,7 +773,7 @@ int CmdTraceList(const char *Cmd) {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
trace = p;
|
trace = p;
|
||||||
if (!GetFromDevice(BIG_BUF, trace, traceLen, 0,NULL,0, NULL, 2500, false)) {
|
if (!GetFromDevice(BIG_BUF, trace, traceLen, 0, NULL, 0, NULL, 2500, false)) {
|
||||||
PrintAndLogEx(WARNING, "command execution time out");
|
PrintAndLogEx(WARNING, "command execution time out");
|
||||||
free(trace);
|
free(trace);
|
||||||
return 3;
|
return 3;
|
||||||
|
|
|
@ -761,9 +761,9 @@ bool GetFromDevice(DeviceMemType_t memtype, uint8_t *dest, uint32_t bytes, uint3
|
||||||
return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_EML_BIGBUF);
|
return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_DOWNLOADED_EML_BIGBUF);
|
||||||
}
|
}
|
||||||
case SPIFFS: {
|
case SPIFFS: {
|
||||||
SendCommandMIX(CMD_SPIFFS_DOWNLOAD, start_index, bytes, 0, data, datalen);
|
SendCommandMIX(CMD_SPIFFS_DOWNLOAD, start_index, bytes, 0, data, datalen);
|
||||||
return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_SPIFFS_DOWNLOADED);
|
return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_SPIFFS_DOWNLOADED);
|
||||||
}
|
}
|
||||||
case FLASH_MEM: {
|
case FLASH_MEM: {
|
||||||
SendCommandMIX(CMD_FLASHMEM_DOWNLOAD, start_index, bytes, 0, NULL, 0);
|
SendCommandMIX(CMD_FLASHMEM_DOWNLOAD, start_index, bytes, 0, NULL, 0);
|
||||||
return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_FLASHMEM_DOWNLOADED);
|
return dl_it(dest, bytes, start_index, response, ms_timeout, show_warning, CMD_FLASHMEM_DOWNLOADED);
|
||||||
|
|
|
@ -415,7 +415,7 @@ int flash_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t
|
||||||
version = BL_VERSION_INVALID;
|
version = BL_VERSION_INVALID;
|
||||||
PrintAndLogEx(ERR, _RED_("Note: Your bootloader reported an invalid version number"));
|
PrintAndLogEx(ERR, _RED_("Note: Your bootloader reported an invalid version number"));
|
||||||
flash_suggest_update_bootloader();
|
flash_suggest_update_bootloader();
|
||||||
//
|
//
|
||||||
} else if (BL_VERSION_MAJOR(version) < BL_VERSION_MAJOR(FLASHER_VERSION)) {
|
} else if (BL_VERSION_MAJOR(version) < BL_VERSION_MAJOR(FLASHER_VERSION)) {
|
||||||
PrintAndLogEx(ERR, _RED_("Note: Your bootloader reported a version older than this flasher"));
|
PrintAndLogEx(ERR, _RED_("Note: Your bootloader reported a version older than this flasher"));
|
||||||
flash_suggest_update_bootloader();
|
flash_suggest_update_bootloader();
|
||||||
|
@ -448,7 +448,7 @@ int flash_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t
|
||||||
PrintAndLogEx(ERR, _RED_("Note: Your bootloader does not understand the new CHIP_INFO command"));
|
PrintAndLogEx(ERR, _RED_("Note: Your bootloader does not understand the new CHIP_INFO command"));
|
||||||
flash_suggest_update_bootloader();
|
flash_suggest_update_bootloader();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enable_bl_writes) {
|
if (enable_bl_writes) {
|
||||||
PrintAndLogEx(INFO, "Permitted flash range: 0x%08x-0x%08x", FLASH_START, flash_end);
|
PrintAndLogEx(INFO, "Permitted flash range: 0x%08x-0x%08x", FLASH_START, flash_end);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -223,7 +223,7 @@ static int l_GetFromBigBuf(lua_State *L) {
|
||||||
return returnToLuaWithError(L, "Allocating memory failed");
|
return returnToLuaWithError(L, "Allocating memory failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GetFromDevice(BIG_BUF, data, len, startindex,NULL,0, NULL, 2500, false)) {
|
if (!GetFromDevice(BIG_BUF, data, len, startindex, NULL, 0, NULL, 2500, false)) {
|
||||||
free(data);
|
free(data);
|
||||||
return returnToLuaWithError(L, "command execution time out");
|
return returnToLuaWithError(L, "command execution time out");
|
||||||
}
|
}
|
||||||
|
@ -263,7 +263,7 @@ static int l_GetFromFlashMem(lua_State *L) {
|
||||||
if (!data)
|
if (!data)
|
||||||
return returnToLuaWithError(L, "Allocating memory failed");
|
return returnToLuaWithError(L, "Allocating memory failed");
|
||||||
|
|
||||||
if (!GetFromDevice(FLASH_MEM, data, len, startindex,NULL,0, NULL, -1, false)) {
|
if (!GetFromDevice(FLASH_MEM, data, len, startindex, NULL, 0, NULL, -1, false)) {
|
||||||
free(data);
|
free(data);
|
||||||
return returnToLuaWithError(L, "command execution time out");
|
return returnToLuaWithError(L, "command execution time out");
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,8 +238,8 @@ typedef struct {
|
||||||
#define CMD_FLASHMEM_INFO 0x0125
|
#define CMD_FLASHMEM_INFO 0x0125
|
||||||
#define CMD_FLASHMEM_SET_SPIBAUDRATE 0x0126
|
#define CMD_FLASHMEM_SET_SPIBAUDRATE 0x0126
|
||||||
|
|
||||||
// RDV40, High level flashmem SPIFFS Manipulation
|
// RDV40, High level flashmem SPIFFS Manipulation
|
||||||
// ALL function will have a lazy or Safe version
|
// ALL function will have a lazy or Safe version
|
||||||
// that will be handled as argument of safety level [0..2] respectiveley normal / lazy / safe
|
// that will be handled as argument of safety level [0..2] respectiveley normal / lazy / safe
|
||||||
// However as how design is, MOUNT and UNMOUNT only need/have lazy as safest level so a safe level will still execute a lazy version
|
// However as how design is, MOUNT and UNMOUNT only need/have lazy as safest level so a safe level will still execute a lazy version
|
||||||
// see spiffs.c for more about the normal/lazy/safety information)
|
// see spiffs.c for more about the normal/lazy/safety information)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue