Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend SPIFFS partition to last SPI FLASH page #2700

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion armsrc/spiffs_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "printf.h"
#include "string.h"
#include "flashmem.h"
#include "pmflash.h"

//#include <stddef.h>
//#include <unistd.h>
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion client/src/scripting.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
14 changes: 11 additions & 3 deletions doc/ext_flash_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand All @@ -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:
Expand All @@ -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)

Expand Down
26 changes: 13 additions & 13 deletions include/pmflash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading