Skip to content

Commit

Permalink
Moved the flash memory related stuff in the firmware to armsrc/flash
Browse files Browse the repository at this point in the history
  • Loading branch information
jlitewski committed May 30, 2024
1 parent 1e9f69e commit 41c711a
Show file tree
Hide file tree
Showing 36 changed files with 58 additions and 45 deletions.
2 changes: 1 addition & 1 deletion armsrc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ SRC_NFCBARCODE = thinfilm.c
# RDV40 related hardware support
ifneq (,$(findstring WITH_FLASH,$(APP_CFLAGS)))
SRC_FLASH = flashmem.c
SRC_SPIFFS = spiffs.c spiffs_cache.c spiffs_check.c spiffs_gc.c spiffs_nucleus.c spiffs_hydrogen.c
SRC_SPIFFS = flash/spiffs.c flash/spiffs_cache.c flash/spiffs_check.c flash/spiffs_gc.c flash/spiffs_nucleus.c flash/spiffs_hydrogen.c
else
SRC_FLASH =
SRC_SPIFFS =
Expand Down
2 changes: 1 addition & 1 deletion armsrc/Standalone/hf_14asniff.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
#include "proxmark3_arm.h"
#include "iso14443a.h"
#include "util.h"
#include "spiffs.h"
#include "flash/spiffs.h"
#include "appmain.h"
#include "dbprint.h"
#include "ticks.h"
Expand Down
2 changes: 1 addition & 1 deletion armsrc/Standalone/hf_14bsniff.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "proxmark3_arm.h"
#include "iso14443b.h"
#include "util.h"
#include "spiffs.h"
#include "flash/spiffs.h"
#include "appmain.h"
#include "dbprint.h"
#include "ticks.h"
Expand Down
2 changes: 1 addition & 1 deletion armsrc/Standalone/hf_15sim.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "protocols.h"
#include "iso15693tools.h"
#include "util.h"
#include "spiffs.h"
#include "flash/spiffs.h"
#include "appmain.h"
#include "dbprint.h"
#include "ticks.h"
Expand Down
2 changes: 1 addition & 1 deletion armsrc/Standalone/hf_15sniff.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
#include "iso15693.h"
#include "iso15.h"
#include "util.h"
#include "spiffs.h"
#include "flash/spiffs.h"
#include "appmain.h"
#include "dbprint.h"
#include "ticks.h"
Expand Down
2 changes: 1 addition & 1 deletion armsrc/Standalone/hf_bog.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ from the client to view the stored quadlets.
#include "iso14443a.h"
#include "protocols.h"
#include "util.h"
#include "spiffs.h"
#include "flash/spiffs.h"
#include "appmain.h"
#include "fpgaloader.h"
#include "dbprint.h"
Expand Down
2 changes: 1 addition & 1 deletion armsrc/Standalone/hf_colin.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "mifareutil.h"
#include "mifaresim.h"
#include "vtsend.h"
#include "spiffs.h"
#include "flash/spiffs.h"
#include "frozen.h"

#define MF1KSZ 1024
Expand Down
2 changes: 1 addition & 1 deletion armsrc/Standalone/hf_iceclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "util.h"
#include "ticks.h"
#include "dbprint.h"
#include "spiffs.h"
#include "flash/spiffs.h"
#include "iclass.h"
#include "iso15693.h"
#include "../common/loclass/cipher.h"
Expand Down
2 changes: 1 addition & 1 deletion armsrc/Standalone/hf_legic.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "legicrf.h"
#include "legicrfsim.h"
#include "legic.h" // legic_card_select_t struct
#include "spiffs.h" // flashmem
#include "flash/spiffs.h" // flashmem

/*
* To list all dump files from flash:
Expand Down
2 changes: 1 addition & 1 deletion armsrc/Standalone/hf_legicsim.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "fpgaloader.h"
#include "util.h"
#include "dbprint.h"
#include "spiffs.h"
#include "flash/spiffs.h"
#include "standalone.h" // standalone definitions
#include "appmain.h"
#include "string.h"
Expand Down
2 changes: 1 addition & 1 deletion armsrc/Standalone/hf_mfcsim.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "fpgaloader.h"
#include "util.h"
#include "dbprint.h"
#include "spiffs.h"
#include "flash/spiffs.h"
#include "standalone.h" // standalone definitions
#include "appmain.h"
#include "string.h"
Expand Down
2 changes: 1 addition & 1 deletion armsrc/Standalone/hf_unisniff.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
#include "iso15.h"
#include "util.h"
#include "commonutil.h"
#include "spiffs.h"
#include "flash/spiffs.h"
#include "appmain.h"
#include "dbprint.h"
#include "ticks.h"
Expand Down
2 changes: 1 addition & 1 deletion armsrc/Standalone/lf_em4100rswb.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#include "string.h"
#include "cardemu.h"
#include "palloc.h"
#include "spiffs.h"
#include "flash/spiffs.h"
#include "inttypes.h"
#include "parity.h"
#include "lfops.h"
Expand Down
2 changes: 1 addition & 1 deletion armsrc/Standalone/lf_em4100rsww.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@
#include "string.h"
#include "palloc.h"
#include "cardemu.h"
#include "spiffs.h"
#include "inttypes.h"
#include "parity.h"
#include "lfops.h"
#include "commonutil.h"

#ifdef WITH_FLASH
#include "flashmem.h"
#include "flash/spiffs.h"
char *filename = "lf";
char *filenameLast = "lf-last";
#endif
Expand Down
2 changes: 1 addition & 1 deletion armsrc/Standalone/lf_em4100rwc.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "string.h"
#include "palloc.h"
#include "cardemu.h"
#include "spiffs.h"
#include "flash/spiffs.h"
#include "commonutil.h"

#ifdef WITH_FLASH
Expand Down
2 changes: 1 addition & 1 deletion armsrc/Standalone/lf_hidfcbrute.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include "lfsampling.h"
#include "util.h"
#include "dbprint.h"
#include "spiffs.h"
#include "flash/spiffs.h"
#include "ticks.h"
#include "lfops.h"
#include "fpgaloader.h"
Expand Down
2 changes: 1 addition & 1 deletion armsrc/Standalone/lf_icehid.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "util.h"
#include "dbprint.h"
#include "printf.h"
#include "spiffs.h"
#include "flash/spiffs.h"
#include "ticks.h"
#include "lfdemod.h"
/*
Expand Down
2 changes: 1 addition & 1 deletion armsrc/Standalone/lf_nexid.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "util.h"
#include "dbprint.h"
#include "printf.h"
#include "spiffs.h"
#include "flash/spiffs.h"
#include "ticks.h"
#include "lfdemod.h"
#include "commonutil.h"
Expand Down
2 changes: 1 addition & 1 deletion armsrc/Standalone/lf_tharexde.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "fpgaloader.h"
#include "util.h"
#include "dbprint.h"
#include "spiffs.h"
#include "flash/spiffs.h"
#include "../em4x50.h"

/*
Expand Down
2 changes: 1 addition & 1 deletion armsrc/appmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
#ifdef WITH_FLASH
#include "pmflash.h"
#include "flashmem.h"
#include "spiffs.h"
#include "flash/spiffs.h"
#endif

#ifdef WITH_ISO15693
Expand Down
8 changes: 4 additions & 4 deletions armsrc/desfire_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,8 @@ void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes
if (0 != memcmp((uint8_t *)data + *nbytes - 1, edata + edl - 8, 4)) {
#ifdef DEBUG_ARM
if(PRINT_DEBUG) Dbprintf("MACing not verified");
hexdump((uint8_t *)data + *nbytes - 1, key_macing_length(key), "Expect ", 0);
hexdump(edata + edl - 8, key_macing_length(key), "Actual ", 0);
//hexdump((uint8_t *)data + *nbytes - 1, key_macing_length(key), "Expect ", 0);
//hexdump(edata + edl - 8, key_macing_length(key), "Actual ", 0);
#endif
DESFIRE(tag)->last_pcd_error = CRYPTO_ERROR;
*nbytes = -1;
Expand Down Expand Up @@ -640,8 +640,8 @@ void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes
if (0 != memcmp(DESFIRE(tag)->cmac, (uint8_t *)data + *nbytes - 9, 8)) {
#ifdef DEBUG_ARM
if(PRINT_DEBUG) Dbprintf("CMAC NOT verified :-(");
hexdump((uint8_t *)data + *nbytes - 9, 8, "Expect ", 0);
hexdump(DESFIRE(tag)->cmac, 8, "Actual ", 0);
//hexdump((uint8_t *)data + *nbytes - 9, 8, "Expect ", 0);
//hexdump(DESFIRE(tag)->cmac, 8, "Actual ", 0);
#endif
DESFIRE(tag)->last_pcd_error = CRYPTO_ERROR;
*nbytes = -1;
Expand Down
2 changes: 1 addition & 1 deletion armsrc/em4x50.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "bruteforce.h"

#ifdef WITH_FLASH
#include "spiffs.h"
#include "flash/spiffs.h"
#endif

// Sam7s has several timers, we will use the source TIMER_CLOCK1 (aka AT91C_TC_CLKS_TIMER_DIV1_CLOCK)
Expand Down
31 changes: 18 additions & 13 deletions armsrc/spiffs.c → armsrc/flash/spiffs.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
// SPIFFS api for RDV40 Integration
//-----------------------------------------------------------------------------

#define SPIFFS_CFG_PHYS_SZ (1024 * 192)
#define SPIFFS_CFG_PHYS_ERASE_SZ (4 * 1024)
#define SPIFFS_CFG_PHYS_ADDR (0)
#define SPIFFS_CFG_LOG_PAGE_SZ (256)
#define SPIFFS_CFG_LOG_BLOCK_SZ (4 * 1024)
#include "spiffs.h"

#include <stdbool.h>

#include "../../include/common.h"
#include "spiffs_config.h"
#include "palloc.h"
#include "dbprint.h"

#define LOG_PAGE_SIZE 256
#define RDV40_SPIFFS_WORKBUF_SZ (LOG_PAGE_SIZE * 2)
// Experimental : 4 full pages(LOG_PAGE_SIZE + file descript size) of cache for
Expand Down Expand Up @@ -54,9 +58,6 @@
RDV40_SPIFFS_LLFUNCT \
RDV40_SPIFFS_SAFE_FOOTER

#include "spiffs.h"
#include "palloc.h"
#include "dbprint.h"

///// FLASH LEVEL R/W/E operations for feeding SPIFFS Driver/////////////////
static s32_t rdv40_spiffs_llread(u32_t addr, u32_t size, u8_t *dst) {
Expand Down Expand Up @@ -91,7 +92,7 @@ static s32_t rdv40_spiffs_llerase(u32_t addr, u32_t size) {

if (PRINT_DEBUG) Dbprintf("LLERASEDBG : Result addr : %d\n", addr);

sector = addr / SPIFFS_CFG_LOG_BLOCK_SZ;
sector = addr / SPIFFS_CFG_LOG_BLOCK_SZ();
Flash_CheckBusy(BUSY_TIMEOUT);
Flash_WriteEnable();

Expand Down Expand Up @@ -245,7 +246,7 @@ uint32_t size_in_spiffs(const char *filename) {

static rdv40_spiffs_fsinfo info_of_spiffs(void) {
rdv40_spiffs_fsinfo fsinfo;
fsinfo.blockSize = SPIFFS_CFG_LOG_BLOCK_SZ;
fsinfo.blockSize = SPIFFS_CFG_LOG_BLOCK_SZ();
fsinfo.pageSize = LOG_PAGE_SIZE;
fsinfo.maxOpenFiles = RDV40_SPIFFS_MAX_FD;
fsinfo.maxPathLength = SPIFFS_OBJ_NAME_LEN;
Expand Down Expand Up @@ -640,8 +641,8 @@ void rdv40_spiffs_safe_print_tree(void) {
struct spiffs_dirent e;
struct spiffs_dirent *pe = &e;

char *resolvedlink = (char *)BigBuf_calloc(11 + SPIFFS_OBJ_NAME_LEN);
char *linkdest = (char *)BigBuf_calloc(SPIFFS_OBJ_NAME_LEN);
char *resolvedlink = (char *)palloc(1, 11 + SPIFFS_OBJ_NAME_LEN);
char *linkdest = (char *)palloc(1, SPIFFS_OBJ_NAME_LEN);
bool printed = false;

SPIFFS_opendir(&fs, "/", &d);
Expand All @@ -660,12 +661,16 @@ void rdv40_spiffs_safe_print_tree(void) {
Dbprintf("[%04x] " _YELLOW_("%5i") " B |-- %s%s", pe->obj_id, pe->size, pe->name, resolvedlink);
printed = true;
}

if (printed == false) {
DbpString("<empty>");
}

SPIFFS_closedir(&d);
rdv40_spiffs_lazy_mount_rollback(changed);
BigBuf_free();

palloc_free(resolvedlink);
palloc_free(linkdest);
}

void rdv40_spiffs_safe_wipe(void) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion armsrc/mifarecmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "dbprint.h"
#include "ticks.h"
#include "usb_cdc.h" // usb_poll_validate_length
#include "spiffs.h" // spiffs
#include "flash/spiffs.h" // spiffs
#include "appmain.h" // print_stack_usage

#ifndef HARDNESTED_AUTHENTICATION_TIMEOUT
Expand Down
6 changes: 6 additions & 0 deletions common/loclass/cipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ void doMAC_N(uint8_t *address_data_p, uint8_t address_data_size, uint8_t *div_ke
void doMAC(uint8_t *cc_nr_p, uint8_t *div_key_p, uint8_t mac[4]);

int testMAC(void);

#define opt_doTagMAC_1(cc_p, div_key_p) (cipher_state_t){0,0,0,0}
#define opt_doTagMAC_2(_init, nr, mac, div_key_p)
#define iclass_calc_div_key(csn, key, div_key, elite)
#define opt_doReaderMAC(ccnr, div_key, pmac)

#else
/**
* @brief
Expand Down
6 changes: 5 additions & 1 deletion common_arm/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ OBJDIR = obj
INCLUDE = -I../include -I../common_arm -I../common_fpga -I../common -I.

# Also search prerequisites in the common directory (for usb.c), the fpga directory (for fpga.bit), and the lz4 directory
VPATH = . ../common_arm ../common ../common/loclass ../common/crapto1 ../common/mbedtls ../common/lz4 ../fpga ../armsrc/Standalone ../common/hitag2
#FIND_DIRS = $(shell find ../common -type d)
#FIND_DIRS += $(shell find ../armsrc -type d)

#VPATH = . ../common_arm $(FIND_DIRS) ../fpga # WHY DOESN'T THIS WORK?
VPATH = . ../common_arm ../common ../common/loclass ../common/crapto1 ../common/mbedtls ../common/lz4 ../fpga ../armsrc/Standalone ../armsrc/flash ../common/hitag2

INCLUDES = ../include/proxmark3_arm.h ../include/at91sam7s512.h ../include/config_gpio.h ../include/pm3_cmd.h

Expand Down
5 changes: 0 additions & 5 deletions common_arm/Makefile.hal
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,6 @@ endif

$(info $(findstring WITH_STANDALONE_*,$(PLATFORM_DEFS)))

# Misc (LCD support)
ifneq (,$(findstring WITH_LCD,$(PLATFORM_DEFS)))
#PLATFORM_DEFS += -DWITH_LCD
endif

# Add flags dependencies :

# WITH_FPC_USART_* needs WITH_FPC_USART :
Expand Down
3 changes: 3 additions & 0 deletions common_arm/flashmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

#include "common.h"

#include <stdbool.h>
#include <stdint.h>

// Used Command
#define ID 0x90
#define MANID 0x90
Expand Down

0 comments on commit 41c711a

Please sign in to comment.