Skip to content

Commit

Permalink
*Should* finally be working now -- Problem was that the SETTINGS memo…
Browse files Browse the repository at this point in the history
…ry remapped the FLASH memory space used by avr-gcc\'s __flash to a custom .flashdata section after the LUFA build by a second call to avr-objcopy -- Clever way to maximize slot space, but the previous code was not aware of that causing apparently quasi-non-deterministic behavior with some readers -- Cf. emsec#313 and emsec#315
  • Loading branch information
maxieds committed Feb 14, 2022
1 parent 2d54740 commit 8f5053f
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static uint16_t ISO7816CmdAppendRecord(uint8_t *Buffer, uint16_t ByteCount);
* handlers to the end of the array, or insert them haphazardly in
* the middle !!!
*/
const DESFIRE_FIRMWARE_ALIGNAT DESFireCommand DESFireCommandSet[] DESFIRE_DFFRAM_SECTION = {
static const DESFireCommand DESFireCommandSet[] = {
{
.insCode = CMD_AUTHENTICATE,
.insFunc = &EV0CmdAuthenticateLegacy1
Expand Down Expand Up @@ -325,8 +325,7 @@ uint16_t CallInstructionHandler(uint8_t *Buffer, uint16_t ByteCount) {
DESFireCommand dfCmd;
while (curInsUpper >= curInsLower) {
curInsIndex = curInsLower + (curInsUpper + 1 - curInsLower) / 2;
MemoryReadBlock(&dfCmd, DESFireCommandSet[curInsIndex], sizeof(DESFireCommand));
nextDESFireFRAMBaseAddr += sizeof(DESFireCommand);
dfCmd = DESFireCommandSet[curInsIndex];
if (dfCmd.insCode == insCode) {
if (dfCmd.insFunc == NULL) {
return CmdNotImplemented(Buffer, ByteCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ typedef struct {
InsCodeHandlerFunc insFunc;
} DESFireCommand DESFIRE_FIRMWARE_ALIGNAT;

extern const DESFIRE_FIRMWARE_ALIGNAT DESFireCommand DESFireCommandSet[];

/* Helper and batch process functions */
uint16_t CallInstructionHandler(uint8_t *Buffer, uint16_t ByteCount);

Expand Down
9 changes: 0 additions & 9 deletions Firmware/Chameleon-Mini/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,9 @@
#else
#define LOG_SIZE 2048
#endif
#ifdef DESFIRE_FRAM_LOG_START
/* This is separated so we can store the large DESFire (native) and ISO7816 command subset
* oragnized in a sorted lookup table by command (byte) ID in the FLASH -> FRAM memory space.
*/
#define FRAM_LOG_ADDR_ADDR DESFIRE_FRAM_LOG_START // start of the second half of FRAM
#define FRAM_LOG_START_ADDR (DESFIRE_FRAM_LOG_START + 0x002) // directly after the address
#define FRAM_LOG_SIZE (DESFIRE_FRAM_LOG_SIZE) // the whole second half (minus the 2 Bytes of Address)
#else
#define FRAM_LOG_ADDR_ADDR 0x4000 // start of the second half of FRAM
#define FRAM_LOG_START_ADDR 0x4002 // directly after the address
#define FRAM_LOG_SIZE 0x3FFE // the whole second half (minus the 2 Bytes of Address)
#endif

extern uint8_t LogMem[LOG_SIZE];
extern uint8_t *LogMemPtr;
Expand Down
16 changes: 2 additions & 14 deletions Firmware/Chameleon-Mini/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,12 @@ DESFIRE_DFFRAM_SECTION_START=0x6048
DESFIRE_DFFRAM_DATA_ADDR=0x16048
DESFIRE_DFFRAM_MAX_SIZE=0x0FFF
DESFIRE_DFFRAM_SECTION_NAME=\".dffram\"
DESFIRE_CONFIG_SETTINGS_BASE=$(SETTINGS) -DCONFIG_MF_DESFIRE_SUPPORT -DMEMORY_LIMITED_TESTING -DDESFIRE_CRYPTO1_SAVE_SPACE -UDEFAULT_CONFIGURATION \
-DDESFIRE_FRAM_LOG_START=$(DESFIRE_FRAM_LOG_START) -DDESFIRE_FRAM_LOG_SIZE=$(DESFIRE_FRAM_LOG_SIZE) \
-DDESFIRE_DFFRAM_MAX_SIZE=$(DESFIRE_DFFRAM_MAX_SIZE) \
-DDESFIRE_DFFRAM_SECTION_START=$(DESFIRE_DFFRAM_SECTION_START) \
-DDESFIRE_DFFRAM_DATA_ADDR=$(DESFIRE_DFFRAM_DATA_ADDR) \
-DDESFIRE_DFFRAM_SECTION_NAME=$(DESFIRE_DFFRAM_SECTION_NAME)
DESFIRE_CONFIG_SETTINGS_BASE=$(SETTINGS) -DCONFIG_MF_DESFIRE_SUPPORT -DMEMORY_LIMITED_TESTING -DDESFIRE_CRYPTO1_SAVE_SPACE -UDEFAULT_CONFIGURATION
DESFIRE_DFFRAM_OBJCOPY= --set-section-flags=.dffram="alloc,load,readonly"

#Memory definitions and objcopy flags to include sections in binaries
FLASH_DATA_ADDR = 0x10000 #Start of data section in flash
FLASH_DATA_SIZE = 0x10000 #Size of data section in flash
#FLASH_DATA_ADDR = 0x12046
#FLASH_DATA_SIZE = 0xF001
FLASH_DATA_OBJCOPY = --set-section-flags=.flashdata="alloc,load"
SPM_HELPER_ADDR = 0x21FE0 #Start of SPM helper section. Should be last 32Byte in bootloader section
SPM_HELPER_OBJCOPY = --set-section-flags=.spmhelper="alloc,load"
Expand Down Expand Up @@ -314,15 +307,10 @@ git-add-dev:
## Defining custom targets for the DESFire build (normal/user mode) and
## developer mode for use with the Android CMLD application that enables
## the printing of LIVE logs to the phone's console by default:
desfire-objcopy: $(TARGET).elf
@echo $(MSG_OBJCPY_CMD) RE-Extracting HEX file data from \"$<\"
$(CROSS)-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $(FLASH_DATA_OBJCOPY) $(DESFIRE_DFFRAM_OBJCOPY) $< $(TARGET).hex
@echo $(MSG_OBJCPY_CMD) RE-Extracting BIN file data from \"$<\"
$(CROSS)-objcopy -O binary -R .eeprom -R .fuse -R .lock -R .signature $(FLASH_DATA_OBJCOPY) $< $(TARGET).bin
desfire-build: local-clean $(TARGET).elf $(TARGET).hex $(TARGET).eep $(TARGET).bin check_size
@cp $(TARGET).hex $(TARGET)-DESFire.hex
@cp $(TARGET).eep $(TARGET)-DESFire.eep
@cp $(TARGET).bin $(TARGET)-DESFire.bin
desfire-build: local-clean $(TARGET).elf $(TARGET).hex $(TARGET).eep $(TARGET).bin desfire-objcopy check_size
@echo -e "\n"
@avr-size -A -x $(TARGET).elf
@avr-size -B -x $(TARGET).elf
Expand Down
6 changes: 0 additions & 6 deletions Firmware/Chameleon-Mini/MemoryAsm.S
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,3 @@ FlashCommonSPM:
.section .flashdata
.align 1
.skip MEMORY_SIZE, MEMORY_INIT_VALUE

#ifdef DESFIRE_FRAM_LOG_SIZE
.section .dffram
.align 1
.skip DESFIRE_FRAM_LOG_SIZE, MEMORY_INIT_VALUE
#endif

0 comments on commit 8f5053f

Please sign in to comment.