This repository has been archived by the owner on Mar 16, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
310 lines (265 loc) · 12 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# This makefile uses sh in order to build the project.
# Note when using AVR-Toolchain, you have to install cygwin and
# append cygwin's bin directory to the PATH environment variable
# because Atmel does not ship sh.exe anymore with the toolchain.
SHELL = /bin/bash
#Supported configurations
#CONFIG_SETTINGS += -DCONFIG_MF_CLASSIC_1K_SUPPORT
#CONFIG_SETTINGS += -DCONFIG_MF_CLASSIC_1K_7B_SUPPORT
#CONFIG_SETTINGS += -DCONFIG_MF_CLASSIC_4K_SUPPORT
#CONFIG_SETTINGS += -DCONFIG_MF_CLASSIC_4K_7B_SUPPORT
#CONFIG_SETTINGS += -DCONFIG_MF_ULTRALIGHT_SUPPORT
CONFIG_SETTINGS += -DCONFIG_MF_DESFIRE_SUPPORT
#CONFIG_SETTINGS += -DCONFIG_ISO14443A_SNIFF_SUPPORT
#CONFIG_SETTINGS += -DCONFIG_ISO15693_SNIFF_SUPPORT
#CONFIG_SETTINGS += -DCONFIG_ISO14443A_READER_SUPPORT
#Default configuration
CONFIG_SETTINGS += -DDEFAULT_CONFIGURATION=CONFIG_NONE
#Support magic mode on mifare classic configuration
SETTINGS += -DSUPPORT_MF_CLASSIC_MAGIC_MODE
#Don't touch manufacturer byte with BUTTON_ACTION_UID_LEFT_(DE/IN)CREMENT
SETTINGS += -DSUPPORT_UID7_FIX_MANUFACTURER_BYTE
#Support activating firmware upgrade mode through command-line
SETTINGS += -DSUPPORT_FIRMWARE_UPGRADE
#Default button actions
#SETTINGS += -DDEFAULT_RBUTTON_ACTION=BUTTON_ACTION_UID_RANDOM
#SETTINGS += -DDEFAULT_RBUTTON_ACTION=BUTTON_ACTION_UID_LEFT_INCREMENT
#SETTINGS += -DDEFAULT_RBUTTON_ACTION=BUTTON_ACTION_UID_RIGHT_INCREMENT
#SETTINGS += -DDEFAULT_RBUTTON_ACTION=BUTTON_ACTION_UID_LEFT_DECREMENT
#SETTINGS += -DDEFAULT_RBUTTON_ACTION=BUTTON_ACTION_UID_RIGHT_DECREMENT
SETTINGS += -DDEFAULT_RBUTTON_ACTION=BUTTON_ACTION_CYCLE_SETTINGS
#SETTINGS += -DDEFAULT_RBUTTON_ACTION=BUTTON_ACTION_STORE_MEM
SETTINGS += -DDEFAULT_LBUTTON_ACTION=BUTTON_ACTION_RECALL_MEM
#SETTINGS += -DDEFAULT_LBUTTON_ACTION=BUTTON_ACTION_PRINT_STATE
#Define if button action setting should be independent of active setting
SETTINGS += -DBUTTON_SETTING_GLOBAL
#Default LED functions
SETTINGS += -DDEFAULT_RED_LED_ACTION=LED_SETTING_CHANGE
SETTINGS += -DDEFAULT_GREEN_LED_ACTION=LED_POWERED
#Define if LED function setting should be independent of active setting
SETTINGS += -DLED_SETTING_GLOBAL
#Default logging mode
SETTINGS += -DDEFAULT_LOG_MODE=LOG_MODE_OFF
#SETTINGS += -DDEFAULT_LOG_MODE=LOG_MODE_MEMORY
#SETTINGS += -DDEFAULT_LOG_MODE=LOG_MODE_LIVE
#Define if log settings should be global
SETTINGS += -DLOG_SETTING_GLOBAL
#Default setting
SETTINGS += -DDEFAULT_SETTING=SETTINGS_FIRST
#Default pending task timeout
SETTINGS += -DDEFAULT_PENDING_TASK_TIMEOUT=50#* 100ms=
#Default reader threshold
SETTINGS += -DDEFAULT_READER_THRESHOLD=400
#Use EEPROM to store settings
SETTINGS += -DENABLE_EEPROM_SETTINGS
#Enable tests for DES/2KTDEA/3DES/AES128 crypto schemes:
#SETTINGS += -DENABLE_CRYPTO_TESTS
#Enable a command to run any tests added by developers, e.g., the
#crypto scheme tests that can be enabled above:
#SETTINGS += -DENABLE_RUNTESTS_TERMINAL_COMMAND
#Whether or not to customize the USB identifier settings in the firmware:
SETTINGS += -DENABLE_LUFAUSB_CUSTOM_VERSIONS
#Whether or not to allow users Chameleon terminal access to change the DESFire configuration's
#sensitive settings like manufacturer, serial number, etc.
#SETTINGS += -DDISABLE_PERMISSIVE_DESFIRE_SETTINGS
#SETTINGS += -DDISABLE_DESFIRE_TERMINAL_COMMANDS
#Set a default logging mode for debugging with the DESFire
#emulation code:
SETTINGS += -DDESFIRE_DEFAULT_LOGGING_MODE=DEBUGGING
#SETTINGS += -DDESFIRE_DEFAULT_LOGGING_MODE=OFF
#Set a default testing mode setting (0 = OFF, non-NULL = ON):
SETTINGS += -DDESFIRE_DEFAULT_TESTING_MODE=1
#Feature: Use randomized UIDs that mask the actual secret UID until
#the tag has been issued a successful authentication sequence:
#SETTINGS += -DDESFIRE_RANDOMIZE_UIDS_PREAUTH
#Anticipating that the implementation overhead is high with the
#maximum storage allocations for the number of possible keys per
#application directory, and/or the total number of AID numbered
#directory slots, the following options will tweak this limitation:
# -> Set DESFIRE_MEMORY_LIMITED_TESTING to shrink the defaults
# -> Or explicitly define DESFIRE_CUSTOM_MAX_KEYS=##UINT## (per AID),
# -> And/Or define DESFIRE_CUSTOM_MAX_APPS=##UINT##
# (total number of AID spaces available, not including the master 0x00)
SETTINGS += -DDESFIRE_MEMORY_LIMITED_TESTING
#SETTINGS += -DDESFIRE_CUSTOM_MAX_APPS=8
#SETTINGS += -DDESFIRE_CUSTOM_MAX_KEYS=6
#SETTINGS += -DDESFIRE_CUSTOM_MAX_FILES=6
#SETTINGS += -DDESFIRE_USE_FACTORY_SIZES
#SETTINGS += -DDESFIRE_MAXIMIZE_SIZES_FOR_STORAGE
#Set a minimum incoming/outgoing log size so we do not spam the
#Chameleon Mini logs to much by logging everything:
SETTINGS += -DDESFIRE_MIN_INCOMING_LOGSIZE=0
SETTINGS += -DDESFIRE_MIN_OUTGOING_LOGSIZE=0
#If we are planning on logging mostly to a live debugging console at runtime,
#there is *a lot* of data space to be saved by minimizing the LogMem
#buffer size. Define the following to optimize this space in the event of
#live logging sessions:
SETTINGS += -DDESFIRE_OPTIMIZE_LIVE_LOGGING_SPACE
#Enable printing of crypto tests when a new DESFire emulation instance is started:
#SETTINGS += -DDESFIRE_RUN_CRYPTO_TESTING_PROCEDURE
#Option to save space with the "Application/Crypto1.c" code by storing large tables
#in PROGMEM. Note that this will slow down the read times when accessing these tables:
SETTINGS += -DDESFIRE_CRYPTO1_SAVE_SPACE
#Memory definitions and objcopy flags to include sections in binaries
#FLASH_DATA_ADDR = 0x01000 #Start of data section in flash
#FLASH_DATA_SIZE = 0x0FFFF #Size of data section in flash
FLASH_DATA_ADDR = 0x10000 #Start of data section in flash
FLASH_DATA_SIZE = 0x0FFFF #Size of data section in flash
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"
#Build configuration
ifeq ($(OS),Windows_NT)
BUILD_DATE = "\"$(shell date /t)\""
else
HOST_PLATFORM:=$(shell uname -s)
DATECMD=`which date`
ifeq "$(HOST_PLATFORM)" "Darwin"
DATECMD=`which gdate`
endif
DATECMD:=$(shell $(DATECMD) '+%Y.%m.%d-%H%M%S')
BUILD_DATE = "\"$(DATECMD)\""
endif
COMMIT_ID = $(shell git rev-parse --short HEAD)
MCU = atxmega128a4u
ARCH = XMEGA
BOARD = NONE
F_CPU = 27120000
F_USB = 48000000
TARGET = Chameleon-Mini
OPTIMIZATION = s
DESFIRE_MAINSRC = Application/DESFire
SRC += $(TARGET).c \
LUFADescriptors.c \
System.c \
Configuration.c \
Random.c \
Common.c \
Memory.c \
Button.c \
Log.c \
Settings.c \
LED.c \
Map.c \
AntennaLevel.c
SRC += Terminal/Terminal.c \
Terminal/Commands.c \
Terminal/XModem.c \
Terminal/CommandLine.c
SRC += Codec/Codec.c \
Codec/ISO14443-2A.c \
Codec/Reader14443-2A.c \
Codec/SniffISO14443-2A.c \
Codec/ISO15693.c
SRC += Application/MifareUltralight.c \
Application/MifareClassic.c \
Application/ISO14443-3A.c \
Application/Crypto1.c \
Application/CryptoAES128.c \
Application/CryptoTDEA.c \
Application/Reader14443A.c \
Application/Sniff14443A.c \
Application/ISO15693-A.c
SRC += $(DESFIRE_MAINSRC)/../MifareDESFire.c \
$(DESFIRE_MAINSRC)/DESFireApplicationDirectory.c \
$(DESFIRE_MAINSRC)/DESFireChameleonTerminal.c \
$(DESFIRE_MAINSRC)/DESFireCrypto.c \
$(DESFIRE_MAINSRC)/DESFireFile.c \
$(DESFIRE_MAINSRC)/DESFireISO14443Support.c \
$(DESFIRE_MAINSRC)/DESFireISO7816Support.c \
$(DESFIRE_MAINSRC)/DESFireInstructions.c \
$(DESFIRE_MAINSRC)/DESFireLogging.c \
$(DESFIRE_MAINSRC)/DESFireMemoryOperations.c \
$(DESFIRE_MAINSRC)/DESFirePICCControl.c \
$(DESFIRE_MAINSRC)/DESFirePICCHeaderLayout.c \
$(DESFIRE_MAINSRC)/DESFireUtils.c
SRC += Tests/CryptoTests.c \
Tests/ChameleonTerminal.c
SRC += $(LUFA_SRC_USB) $(LUFA_SRC_USBCLASS)
ASRC = MemoryAsm.S \
Codec/Reader14443-ISR.S
ASRC += Applications/CryptoTDEA-HWAccelerated.S
SRC += $(ASRC)
LUFA_PATH = ../LUFA
CC_FLAGS = -g0 -std=gnu99 -D__PROG_TYPES_COMPAT__ \
-DUSE_LUFA_CONFIG_HEADER -DFLASH_DATA_ADDR=$(FLASH_DATA_ADDR) \
-DFLASH_DATA_SIZE=$(FLASH_DATA_SIZE) -DSPM_HELPER_ADDR=$(SPM_HELPER_ADDR) \
-DBUILD_DATE=$(BUILD_DATE) -DCOMMIT_ID=\"$(COMMIT_ID)\" $(CONFIG_SETTINGS) $(SETTINGS) \
-D__AVR_ATxmega128A4U__ -Werror=implicit-function-declaration \
-D__MAX_ENDPOINT_INDEX=4 \
-fno-inline-small-functions -fshort-enums -fpack-struct \
-ffunction-sections -Wl,--gc-sections --data-sections -ffunction-sections \
-Wl,-relax -fno-split-wide-types -fno-tree-scev-cprop \
-fno-aggressive-loop-optimizations
LD_FLAGS = $(CC_FLAGS) \
-Wl,--section-start=.flashdata=$(FLASH_DATA_ADDR) \
-Wl,--section-start=.spmhelper=$(SPM_HELPER_ADDR)
OBJDIR = Bin
OBJECT_FILES =
#AVRDUDE settings
AVRDUDE_PROGRAMMER = flip2
AVRDUDE_MCU = atxmega128a4u
AVRDUDE_PORT = usb
AVRDUDE_WRITE_APP = -U application:w:$(TARGET).hex
AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
AVRDUDE_FLAGS = -p $(AVRDUDE_MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
#AVRDUDE settings to program the precompiled firmware
AVRDUDE_WRITE_APP_LATEST = -U application:w:Latest/Chameleon-Mini-DESFire.hex
AVRDUDE_WRITE_EEPROM_LATEST = -U eeprom:w:Latest/Chameleon-Mini-DESFire.eep
# Default target
all:
$(CROSS)-size --mcu=atmega128 -C $(TARGET).elf
# Include LUFA build script makefiles
include $(LUFA_PATH)/Build/lufa_core.mk
include $(LUFA_PATH)/Build/lufa_sources.mk
include $(LUFA_PATH)/Build/lufa_build.mk
include $(LUFA_PATH)/Build/lufa_cppcheck.mk
# include $(LUFA_PATH)/Build/lufa_doxygen.mk
# include $(LUFA_PATH)/Build/lufa_dfu.mk
# include $(LUFA_PATH)/Build/lufa_hid.mk
# include $(LUFA_PATH)/Build/lufa_avrdude.mk
# include $(LUFA_PATH)/Build/lufa_atprogram.mk
#Overwrite the LUFA versions of hex/bin file generation to include spmhelper and flashdata sections
%.hex: %.elf
@echo $(MSG_OBJCPY_CMD) "(Chameleon) Extracting HEX file data from \"$<\""
$(CROSS)-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $(FLASH_DATA_OBJCOPY) $< $@
%.eep: %.elf
@echo $(MSG_OBJCPY_CMD) "(Chameleon) Extracting EEP file data from \"$<\""
$(CROSS)-objcopy -j .eeprom --set-section-flags=.eeprom=alloc,load \
--change-section-lma .eeprom=0 --no-change-warnings -O ihex \
$(TARGET).elf $(TARGET).eep
%.bin: %.elf
@echo $(MSG_OBJCPY_CMD) "(Chameleon) Extracting BIN file data from \"$<\""
$(CROSS)-objcopy -O binary -R .eeprom -R .fuse -R .lock -R .signature $(FLASH_DATA_OBJCOPY) $< $@
# Extract SPMHelper in the last 32 Byte of the bootloader section to externally combine it with any bootloader
spmhelper: $(TARGET).elf
@echo $(MSG_OBJCPY_CMD) "(Chameleon) Extracting SPM helper HEX file from $(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
avrdude $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_APP) $(AVRDUDE_WRITE_EEPROM)
# Program the device using avrdude with the latest official firmware
program-latest:
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
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-programmer $(MCU) erase
dfu-programmer $(MCU) flash-eeprom $(TARGET).eep
dfu-programmer $(MCU) flash $(TARGET).hex
dfu-programmer $(MCU) reset
desfire: CONFIG_SETTINGS:= -DCONFIG_MF_DESFIRE_SUPPORT -DDEFAULT_CONFIGURATION=CONFIG_NONE
desfire: $(TARGET).elf $(TARGET).hex $(TARGET).eep
@cp $(TARGET).hex $(TARGET)-DESFire.hex
@cp $(TARGET).eep $(TARGET)-DESFire.eep
local-clean:
@rm -f $(TARGET).{elf,hex,eep,bin,lss,map} $(TARGET)-DESFire.{hex,eep}
@rm -rf $(OBJDIR)
@mkdir $(OBJDIR)
@rm -f Application/DESFire/*.code