Merge pull request #2700 from piotrva/extend-spiffs-partition-last-page

Extend SPIFFS partition to last SPI FLASH page
This commit is contained in:
Iceman 2024-12-31 21:39:31 +01:00 committed by GitHub
commit 4b2414f1d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 28 additions and 18 deletions

View file

@ -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... 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] ## [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 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 `lf em 410x sim` to use default gap value of 0 and extended help (@piotrva)
- Changed `hf 14a info` - now identifies MIAFRE Duox (@iceman1001) - Changed `hf 14a info` - now identifies MIAFRE Duox (@iceman1001)

View file

@ -28,6 +28,7 @@
#include "printf.h" #include "printf.h"
#include "string.h" #include "string.h"
#include "flashmem.h" #include "flashmem.h"
#include "pmflash.h"
//#include <stddef.h> //#include <stddef.h>
//#include <unistd.h> //#include <unistd.h>
@ -236,7 +237,7 @@ typedef uint8_t u8_t;
// Instead of giving parameters in config struct, singleton build must // Instead of giving parameters in config struct, singleton build must
// give parameters in defines below. // give parameters in defines below.
#ifndef SPIFFS_CFG_PHYS_SZ #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 #endif
#ifndef SPIFFS_CFG_PHYS_ERASE_SZ #ifndef SPIFFS_CFG_PHYS_ERASE_SZ
#define SPIFFS_CFG_PHYS_ERASE_SZ(ignore) (4*1024) #define SPIFFS_CFG_PHYS_ERASE_SZ(ignore) (4*1024)

View file

@ -283,7 +283,7 @@ static int l_GetFromFlashMemSpiffs(lua_State *L) {
return returnToLuaWithError(L, "No FLASH MEM support"); 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}; char destfilename[32] = {0};
size_t size; size_t size;

View file

@ -19,7 +19,7 @@ External 256kbytes flash is a unique feature of the RDV4 edition.
Flash memory is Flash memory is
* 256KB (0x40000= 262144) * 256KB (0x40000 = 262144)
* divided into 4 pages of 64KB (0x10000 = 65536) * divided into 4 pages of 64KB (0x10000 = 65536)
* 4 pages divided into 16 sectors of 4KB (0x1000 = 4096), so last sector is at 0x3F000 * 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 ^^^ 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 ## Layout
^[Top](#top) ^[Top](#top)
@ -49,7 +51,7 @@ Page 2:
* to dump it: `mem dump -f page2_dump -o 131072 -l 65536` * to dump it: `mem dump -f page2_dump -o 131072 -l 65536`
* to erase it: `mem wipe -p 2` * 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 * 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 dump it: `mem dump -f page3_dump -o 196608 -l 65536`
* to erase it: * to erase it:
@ -60,13 +62,19 @@ Page 3:
## Page3 Layout ## Page3 Layout
^[Top](#top) ^[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 * **RSA SIGNATURE**, see below for details
* offset: page 3 sector 15 (0xF) offset 0xF7F @ 3*0x10000+15*0x1000+0xF7F=0x3FF7F (decimal 262015) * offset: page 3 sector 15 (0xF) offset 0xF7F @ 3*0x10000+15*0x1000+0xF7F=0x3FF7F (decimal 262015)
* length: 128 bytes * 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 * 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 ## RSA signature
^[Top](#top) ^[Top](#top)

View file

@ -22,29 +22,32 @@
#include "common.h" #include "common.h"
// RDV40 Section // RDV40 Section
// 256kb divided into 4k sectors. // 256KB divided into 4K sectors.
// // +--------+-------------+---------+--------------------------+
// 0x3F000 - 1 4kb sector = signature // | Sector | 256KB addr* | Size | Description |
// 0x3E000 - 1 4kb sector = settings // +--------+-------------+---------+--------------------------+
// | 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 #ifndef FLASH_MEM_BLOCK_SIZE
# define FLASH_MEM_BLOCK_SIZE 256 # define FLASH_MEM_BLOCK_SIZE 256
#endif #endif
#ifndef FLASH_MEM_MAX_SIZE
# define FLASH_MEM_MAX_SIZE 0x40000 // (262144)
#endif
#ifndef FLASH_MEM_MAX_SIZE_P #ifndef FLASH_MEM_MAX_SIZE_P
# define FLASH_MEM_MAX_SIZE_P(p64k) (1024 * 64 * (p64k)) # define FLASH_MEM_MAX_SIZE_P(p64k) (1024 * 64 * (p64k))
#endif #endif
#ifndef FLASH_MEM_MAX_4K_SECTOR
# define FLASH_MEM_MAX_4K_SECTOR 0x3F000
#endif
#ifndef FLASH_MEM_MAX_4K_SECTOR_P #ifndef FLASH_MEM_MAX_4K_SECTOR_P
# define FLASH_MEM_MAX_4K_SECTOR_P(p64k) (FLASH_MEM_MAX_SIZE_P(p64k) - 4096) # define FLASH_MEM_MAX_4K_SECTOR_P(p64k) (FLASH_MEM_MAX_SIZE_P(p64k) - 4096)
#endif #endif
#define FLASH_RESERVED_TRAILING_4K_SECTORS 2
#ifndef FLASH_MEM_ID_LEN #ifndef FLASH_MEM_ID_LEN
# define FLASH_MEM_ID_LEN 8 # define FLASH_MEM_ID_LEN 8
#endif #endif
@ -53,10 +56,7 @@
# define FLASH_MEM_SIGNATURE_LEN 128 # define FLASH_MEM_SIGNATURE_LEN 128
#endif #endif
#ifndef FLASH_MEM_SIGNATURE_OFFSET
// -1 for historical compatibility with already released Proxmark3 RDV4.0 devices // -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 #ifndef FLASH_MEM_SIGNATURE_OFFSET_P
# define FLASH_MEM_SIGNATURE_OFFSET_P(p64k) (FLASH_MEM_MAX_SIZE_P(p64k) - FLASH_MEM_SIGNATURE_LEN - 1) # define FLASH_MEM_SIGNATURE_OFFSET_P(p64k) (FLASH_MEM_MAX_SIZE_P(p64k) - FLASH_MEM_SIGNATURE_LEN - 1)
#endif #endif