diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e1c60b98c..75318a55ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] +- Changed (extended) area accessible by spiffs into last page of FLASH (@piotrva) - Changed flash-stored key dictionaries (Mifare, iClass, T55XX) and T55XX configurations to SPIFFS files (@piotrva) - Changed `lf em 410x sim` to use default gap value of 0 and extended help (@piotrva) - Changed `hf 14a info` - now identifies MIAFRE Duox (@iceman1001) diff --git a/armsrc/spiffs_config.h b/armsrc/spiffs_config.h index 4f8a5dd26c..d0d4eb1d71 100644 --- a/armsrc/spiffs_config.h +++ b/armsrc/spiffs_config.h @@ -28,6 +28,7 @@ #include "printf.h" #include "string.h" #include "flashmem.h" +#include "pmflash.h" //#include //#include @@ -236,7 +237,7 @@ typedef uint8_t u8_t; // Instead of giving parameters in config struct, singleton build must // give parameters in defines below. #ifndef SPIFFS_CFG_PHYS_SZ -#define SPIFFS_CFG_PHYS_SZ(ignore) (1024 * 64 * (spi_flash_pages64k - 1)) +#define SPIFFS_CFG_PHYS_SZ(ignore) ((1024 * 64 * spi_flash_pages64k) - (1024 * 4 * (FLASH_RESERVED_TRAILING_4K_SECTORS + 1))) #endif #ifndef SPIFFS_CFG_PHYS_ERASE_SZ #define SPIFFS_CFG_PHYS_ERASE_SZ(ignore) (4*1024) diff --git a/client/src/scripting.c b/client/src/scripting.c index 0657ae8d67..4f7705eb3f 100644 --- a/client/src/scripting.c +++ b/client/src/scripting.c @@ -283,7 +283,7 @@ static int l_GetFromFlashMemSpiffs(lua_State *L) { return returnToLuaWithError(L, "No FLASH MEM support"); } - uint32_t start_index = 0, len = 0x40000; //FLASH_MEM_MAX_SIZE + uint32_t start_index = 0, len = 0x40000; // 256KB FLASH_MEM_MAX_SIZE as default value char destfilename[32] = {0}; size_t size; diff --git a/doc/ext_flash_notes.md b/doc/ext_flash_notes.md index d54c2be538..25ba2be14c 100644 --- a/doc/ext_flash_notes.md +++ b/doc/ext_flash_notes.md @@ -19,7 +19,7 @@ External 256kbytes flash is a unique feature of the RDV4 edition. Flash memory is -* 256KB (0x40000= 262144) +* 256KB (0x40000 = 262144) * divided into 4 pages of 64KB (0x10000 = 65536) * 4 pages divided into 16 sectors of 4KB (0x1000 = 4096), so last sector is at 0x3F000 @@ -31,6 +31,8 @@ Therefore a flash address can be interpreted as such: ^^^ offset ^^^ offset 0xF7F ``` +Please note that for other flash memory sizes than 256KB a "Page 3" will be the last page of the memory, and address offsets would be dependant on the memory size. + ## Layout ^[Top](#top) @@ -49,7 +51,7 @@ Page 2: * to dump it: `mem dump -f page2_dump -o 131072 -l 65536` * to erase it: `mem wipe -p 2` -Page 3: +Page 3 (or the last page for memories other than 256KB): * used by Proxmark3 RDV4 specific functions: flash signature, see below for details * to dump it: `mem dump -f page3_dump -o 196608 -l 65536` * to erase it: @@ -60,13 +62,19 @@ Page 3: ## Page3 Layout ^[Top](#top) -Page3 is used as follows by the Proxmark3 RDV4 firmware: +Page3 (or the last page for memories other than 256KB) is used as follows by the Proxmark3 RDV4 firmware: * **RSA SIGNATURE**, see below for details * offset: page 3 sector 15 (0xF) offset 0xF7F @ 3*0x10000+15*0x1000+0xF7F=0x3FF7F (decimal 262015) * length: 128 bytes * offset should have been 0x3FF80 but historically it's one byte off and therefore the last byte of the flash is unused +* **Reserved for future use** + * offset: page 3 sector 14 (0xE) + +* **SPIFFS sectors** + * offset: page 3 sectors 13..0 (0xD..0x0) + ## RSA signature ^[Top](#top) diff --git a/include/pmflash.h b/include/pmflash.h index 67f5b350a3..7820ad4e2e 100644 --- a/include/pmflash.h +++ b/include/pmflash.h @@ -22,29 +22,32 @@ #include "common.h" // RDV40 Section -// 256kb divided into 4k sectors. -// -// 0x3F000 - 1 4kb sector = signature -// 0x3E000 - 1 4kb sector = settings +// 256KB divided into 4K sectors. +// +--------+-------------+---------+--------------------------+ +// | Sector | 256KB addr* | Size | Description | +// +--------+-------------+---------+--------------------------+ +// | N | 0x3F000 | 1 * 4KB | signature | +// | N-1 | 0x3E000 | 1 * 4KB | reserved for future use | +// +--------+-------------+---------+--------------------------+ // +// * For different memory size than 256KB the address is not valid. +// Please instead refer to Sector number, where N is the last +// 4KB secotr of the memory in question. + #ifndef FLASH_MEM_BLOCK_SIZE # define FLASH_MEM_BLOCK_SIZE 256 #endif -#ifndef FLASH_MEM_MAX_SIZE -# define FLASH_MEM_MAX_SIZE 0x40000 // (262144) -#endif #ifndef FLASH_MEM_MAX_SIZE_P # define FLASH_MEM_MAX_SIZE_P(p64k) (1024 * 64 * (p64k)) #endif -#ifndef FLASH_MEM_MAX_4K_SECTOR -# define FLASH_MEM_MAX_4K_SECTOR 0x3F000 -#endif #ifndef FLASH_MEM_MAX_4K_SECTOR_P # define FLASH_MEM_MAX_4K_SECTOR_P(p64k) (FLASH_MEM_MAX_SIZE_P(p64k) - 4096) #endif +#define FLASH_RESERVED_TRAILING_4K_SECTORS 2 + #ifndef FLASH_MEM_ID_LEN # define FLASH_MEM_ID_LEN 8 #endif @@ -53,10 +56,7 @@ # define FLASH_MEM_SIGNATURE_LEN 128 #endif -#ifndef FLASH_MEM_SIGNATURE_OFFSET // -1 for historical compatibility with already released Proxmark3 RDV4.0 devices -# define FLASH_MEM_SIGNATURE_OFFSET (FLASH_MEM_MAX_SIZE - FLASH_MEM_SIGNATURE_LEN - 1) -#endif #ifndef FLASH_MEM_SIGNATURE_OFFSET_P # define FLASH_MEM_SIGNATURE_OFFSET_P(p64k) (FLASH_MEM_MAX_SIZE_P(p64k) - FLASH_MEM_SIGNATURE_LEN - 1) #endif