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

Elf sections size check before flashing #284

Merged
merged 3 commits into from
Oct 19, 2020
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
29 changes: 22 additions & 7 deletions Firmware/Chameleon-Mini/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ SETTINGS += -DCONFIG_MF_CLASSIC_1K_7B_SUPPORT
SETTINGS += -DCONFIG_MF_CLASSIC_4K_SUPPORT
SETTINGS += -DCONFIG_MF_CLASSIC_4K_7B_SUPPORT
SETTINGS += -DCONFIG_MF_ULTRALIGHT_SUPPORT
SETTINGS += -DCONFIG_ISO14443A_SNIFF_SUPPORT
SETTINGS += -DCONFIG_ISO14443A_READER_SUPPORT
# SETTINGS += -DCONFIG_ISO14443A_SNIFF_SUPPORT
# SETTINGS += -DCONFIG_ISO14443A_READER_SUPPORT
SETTINGS += -DCONFIG_NTAG215_SUPPORT
SETTINGS += -DCONFIG_VICINITY_SUPPORT
SETTINGS += -DCONFIG_SL2S2002_SUPPORT
SETTINGS += -DCONFIG_TITAGITSTANDARD_SUPPORT
SETTINGS += -DCONFIG_ISO15693_SNIFF_SUPPORT
# SETTINGS += -DCONFIG_ISO15693_SNIFF_SUPPORT
SETTINGS += -DCONFIG_EM4233_SUPPORT

#Support magic mode on mifare classic configuration
Expand Down Expand Up @@ -125,6 +125,7 @@ AVRDUDE_FLAGS = -p $(AVRDUDE_MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_WRITE_APP_LATEST = -U application:w:Latest/Chameleon-Mini.hex
AVRDUDE_WRITE_EEPROM_LATEST = -U eeprom:w:Latest/Chameleon-Mini.eep

.PHONY: program program-latest dfu-flip dfu-prog check_size style

# Default target
all:
Expand Down Expand Up @@ -155,27 +156,41 @@ spmhelper: $(TARGET).elf
$(CROSS)-objcopy -O ihex -j .spmhelper $(SPM_HELPER_OBJCOPY) $(TARGET).elf $(TARGET).hex

# Program the device using avrdude
program: $(TARGET).hex $(TARGET).eep
program: $(TARGET).hex $(TARGET).eep check_size
avrdude $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_APP) $(AVRDUDE_WRITE_EEPROM)

# Program the device using avrdude with the latest official firmware
program-latest:
program-latest: check_size
avrdude $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_APP_LATEST) $(AVRDUDE_WRITE_EEPROM_LATEST)

# Program the device using batchisp and the DFU bootloader
# Note that the device has to be in bootloader mode already
dfu-flip: $(TARGET).hex $(TARGET).eep
dfu-flip: $(TARGET).hex $(TARGET).eep check_size
cp $(TARGET).eep EEPROM.hex
batchisp -hardware usb -device $(MCU) -operation erase f memory FLASH loadbuffer $(TARGET).hex program verify memory EEPROM loadbuffer EEPROM.hex program verify start reset 0
rm EEPROM.hex

# Program the device using dfu-programmer
dfu-prog: $(TARGET).hex $(TARGET).eep
dfu-prog: $(TARGET).hex $(TARGET).eep check_size
dfu-programmer $(MCU) erase
dfu-programmer $(MCU) flash-eeprom $(TARGET).eep
dfu-programmer $(MCU) flash $(TARGET).hex
dfu-programmer $(MCU) reset

check_size:
@{ \
set -e; \
if [ ! -f $(TARGET).elf ]; then \
exit 0; \
fi; \
PROGMEM_SIZE=$$(avr-size $(TARGET).elf | grep -oP "\d+" | sed -n 4p); \
MAX_PRGMEM_SIZE=$$(printf "%d\n" $(FLASH_DATA_ADDR)); \
if [ $$PROGMEM_SIZE -gt $$MAX_PRGMEM_SIZE ]; then \
echo "make: *** $(TARGET).elf Application Section size $$PROGMEM_SIZE excedes maximum allowed $$MAX_PRGMEM_SIZE. Please disable some features in Makefile"; \
exit 1; \
fi; \
}

style:
# Make sure astyle is installed
@which astyle >/dev/null || ( echo "Please install 'astyle' package first" ; exit 1 )
Expand Down
4 changes: 4 additions & 0 deletions Firmware/Chameleon-Mini/Terminal/CommandLine.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ const PROGMEM CommandEntryType CommandTable[] = {
.SetFunc = NO_FUNCTION,
.GetFunc = CommandGetSysTick
},
#ifdef CONFIG_ISO14443A_READER_SUPPORT
{
.Command = COMMAND_SEND_RAW,
.ExecFunc = NO_FUNCTION,
Expand Down Expand Up @@ -295,6 +296,7 @@ const PROGMEM CommandEntryType CommandTable[] = {
.SetFunc = NO_FUNCTION,
.GetFunc = NO_FUNCTION
},
#endif
{
.Command = COMMAND_TIMEOUT,
.ExecFunc = NO_FUNCTION,
Expand Down Expand Up @@ -323,13 +325,15 @@ const PROGMEM CommandEntryType CommandTable[] = {
.SetFunc = CommandSetField,
.GetFunc = CommandGetField
},
#ifdef CONFIG_ISO14443A_READER_SUPPORT
{
.Command = COMMAND_CLONE,
.ExecFunc = CommandExecClone,
.ExecParamFunc = NO_FUNCTION,
.SetFunc = NO_FUNCTION,
.GetFunc = NO_FUNCTION
},
#endif
{
/* This has to be last element */
.Command = COMMAND_LIST_END,
Expand Down
15 changes: 11 additions & 4 deletions Firmware/Chameleon-Mini/Terminal/Commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ CommandStatusIdType CommandGetSysTick(char *OutParam) {
return COMMAND_INFO_OK_WITH_TEXT_ID;
}

#ifdef CONFIG_ISO14443A_READER_SUPPORT
CommandStatusIdType CommandExecParamSend(char *OutMessage, const char *InParams) {
if (GlobalSettings.ActiveSettingPtr->Configuration != CONFIG_ISO14443A_READER)
return COMMAND_ERR_INVALID_USAGE_ID;
Expand Down Expand Up @@ -540,6 +541,7 @@ CommandStatusIdType CommandExecIdentifyCard(char *OutMessage) {
CommandLinePendingTaskTimeout = &Reader14443AAppTimeout;
return TIMEOUT_COMMAND;
}
#endif

CommandStatusIdType CommandGetTimeout(char *OutParam) {
snprintf_P(OutParam, TERMINAL_BUFFER_SIZE, PSTR("%u ms"), GlobalSettings.ActiveSettingPtr->PendingTaskTimeout * 100);
Expand Down Expand Up @@ -604,6 +606,7 @@ CommandStatusIdType CommandGetField(char *OutMessage) {


CommandStatusIdType CommandExecAutocalibrate(char *OutMessage) {
#ifdef CONFIG_ISO14443A_READER_SUPPORT
if (GlobalSettings.ActiveSettingPtr->Configuration == CONFIG_ISO14443A_READER) {
ApplicationReset();

Expand All @@ -612,19 +615,22 @@ CommandStatusIdType CommandExecAutocalibrate(char *OutMessage) {
Reader14443ACodecStart();
CommandLinePendingTaskTimeout = &Reader14443AAppTimeout;
return TIMEOUT_COMMAND;
} else if (GlobalSettings.ActiveSettingPtr->Configuration == CONFIG_ISO14443A_SNIFF) {
}
#endif
#ifdef CONFIG_ISO14443A_SNIFF_SUPPORT
if (GlobalSettings.ActiveSettingPtr->Configuration == CONFIG_ISO14443A_SNIFF) {
ApplicationReset();

Sniff14443CurrentCommand = Sniff14443_Autocalibrate;
Sniff14443AAppInit();
CommandLinePendingTaskTimeout = &Sniff14443AAppTimeout;
return TIMEOUT_COMMAND;
} else {
return COMMAND_ERR_INVALID_USAGE_ID;
}

#endif
return COMMAND_ERR_INVALID_USAGE_ID;
}

#ifdef CONFIG_ISO14443A_READER_SUPPORT
CommandStatusIdType CommandExecClone(char *OutMessage) {
ConfigurationSetById(CONFIG_ISO14443A_READER);

Expand All @@ -637,3 +643,4 @@ CommandStatusIdType CommandExecClone(char *OutMessage) {

return TIMEOUT_COMMAND;
}
#endif