text
[RRG-proxmark3.git] / armsrc / Makefile
blob233af73e293708aded8b23253a8500b07d3da897
1 # This code is licensed to you under the terms of the GNU GPL, version 2 or,
2 # at your option, any later version. See the LICENSE.txt file for the text of
3 # the license.
4 #-----------------------------------------------------------------------------
5 # Makefile for armsrc, see ../common_arm/Makefile.common for common settings
6 #-----------------------------------------------------------------------------
8 # This Makefile might have been called directly, not via the root Makefile, so:
9 ifeq ($(PLTNAME),)
10 -include ../Makefile.platform
11 -include ../.Makefile.options.cache
12 include ../common_arm/Makefile.hal
13 # detect if there were changes in the platform definitions, requiring a clean
14 ifeq ($(PLATFORM_CHANGED), true)
15 $(error platform definitions have been changed, please "make clean" at the root of the project)
16 endif
17 endif
19 #remove one of the following defines and comment out the relevant line
20 #in the next section to remove that particular feature from compilation.
21 # NO space,TABs after the "\" sign.
22 APP_CFLAGS = $(PLATFORM_DEFS) \
23 -ffunction-sections -fdata-sections
25 SRC_LF = lfops.c lfsampling.c pcf7931.c lfdemod.c lfadc.c
26 SRC_ISO15693 = iso15693.c iso15693tools.c
27 SRC_ISO14443a = iso14443a.c mifareutil.c mifarecmd.c epa.c mifaresim.c
28 #UNUSED: mifaresniff.c
29 SRC_ISO14443b = iso14443b.c
30 SRC_FELICA = felica.c
31 SRC_CRAPTO1 = crypto1.c des.c desfire_crypto.c mifaredesfire.c aes.c platform_util.c
32 SRC_CRC = crc.c crc16.c crc32.c
33 SRC_ICLASS = iclass.c optimized_cipherutils.c optimized_ikeys.c optimized_elite.c optimized_cipher.c
34 SRC_LEGIC = legicrf.c legicrfsim.c legic_prng.c
35 SRC_NFCBARCODE = thinfilm.c
37 # SRC_BEE = bee.c
39 # RDV40 related hardware support
40 ifneq (,$(findstring WITH_FLASH,$(APP_CFLAGS)))
41 SRC_FLASH = flashmem.c
42 SRC_SPIFFS = spiffs.c spiffs_cache.c spiffs_check.c spiffs_gc.c spiffs_nucleus.c spiffs_hydrogen.c
43 else
44 SRC_FLASH =
45 SRC_SPIFFS =
46 endif
48 ifneq (,$(findstring WITH_SMARTCARD,$(APP_CFLAGS)))
49 SRC_SMARTCARD = i2c.c
50 else
51 SRC_SMARTCARD =
52 endif
54 ifneq (,$(findstring WITH_FPC_USART,$(APP_CFLAGS)))
55 SRC_FPC = usart.c
56 else
57 SRC_FPC =
58 endif
60 ifneq (,$(findstring WITH_HITAG,$(APP_CFLAGS)))
61 SRC_HITAG = hitag2_crypto.c hitag2.c hitagS.c
62 else
63 SRC_HITAG =
64 endif
66 ifneq (,$(findstring WITH_EM4x50,$(APP_CFLAGS)))
67 SRC_EM4x50 = em4x50.c
68 else
69 SRC_EM4x50 =
70 endif
72 ifneq (,$(findstring WITH_EM4x70,$(APP_CFLAGS)))
73 SRC_EM4x70 = em4x70.c
74 else
75 SRC_EM4x70 =
76 endif
78 ifneq (,$(findstring WITH_LCD,$(APP_CFLAGS)))
79 SRC_LCD = fonts.c LCD.c
80 else
81 SRC_LCD =
82 endif
84 # Generic standalone Mode injection of source code
85 include Standalone/Makefile.inc
87 #the FPGA bitstream files. Note: order matters!
88 FPGA_BITSTREAMS = fpga_lf.bit fpga_hf.bit fpga_felica.bit
90 #the lz4 source files required for decompressing the fpga config at run time
91 SRC_LZ4 = lz4.c
92 #additional defines required to compile lz4
93 LZ4_CFLAGS = -DLZ4_MEMORY_USAGE=8
94 APP_CFLAGS += $(LZ4_CFLAGS)
95 # lz4 includes:
96 APP_CFLAGS += -I../common/lz4
98 # stdint.h provided locally until GCC 4.5 becomes C99 compliant,
99 # stack-protect , no-pie reduces size on Gentoo Hardened 8.2 gcc
100 APP_CFLAGS += -I. -fno-stack-protector -fno-pie
102 # Compile these in thumb mode (small size)
103 THUMBSRC = start.c \
104 $(SRC_LCD) \
105 $(SRC_ISO15693) \
106 $(SRC_NFCBARCODE) \
107 $(SRC_LF) \
108 $(SRC_LZ4) \
109 $(SRC_LEGIC) \
110 $(SRC_FLASH) \
111 $(SRC_SMARTCARD) \
112 $(SRC_FPC) \
113 $(SRC_HITAG) \
114 $(SRC_EM4x50) \
115 $(SRC_EM4x70) \
116 $(SRC_SPIFFS) \
117 $(SRC_ISO14443a) \
118 $(SRC_ISO14443b) \
119 $(SRC_CRAPTO1) \
120 $(SRC_ICLASS) \
121 $(SRC_EMV) \
122 $(SRC_CRC) \
123 $(SRC_FELICA) \
124 $(SRC_STANDALONE) \
125 appmain.c \
126 printf.c \
127 dbprint.c \
128 commonutil.c \
129 util.c \
130 string.c \
131 BigBuf.c \
132 ticks.c \
133 clocks.c \
134 hfsnoop.c
137 # These are to be compiled in ARM mode
138 ARMSRC = fpgaloader.c \
139 parity.c \
140 usb_cdc.c \
141 cmd.c
143 VERSIONSRC = version_pm3.c \
144 fpga_version_info.c
146 # Do not move this inclusion before the definition of {THUMB,ASM,ARM}SRC
147 include ../common_arm/Makefile.common
149 INSTALLFW = $(OBJDIR)/fullimage.elf
150 ifneq (,$(FWTAG))
151 INSTALLFWTAG = $(notdir $(INSTALLFW:%.elf=%-$(FWTAG).elf))
152 else
153 INSTALLFWTAG = $(notdir $(INSTALLFW))
154 endif
156 OBJS = $(OBJDIR)/fullimage.s19
157 FPGA_COMPRESSOR = ../tools/fpga_compress/fpga_compress
159 all: showinfo $(OBJS)
161 showinfo:
162 $(info compiler version: $(shell $(CC) --version|head -n 1))
164 .DELETE_ON_ERROR:
166 # version_pm3.c should be remade on every time fullimage.stage1.elf should be remade
167 version_pm3.c: default_version_pm3.c $(OBJDIR)/fpga_version_info.o $(OBJDIR)/fpga_all.o $(THUMBOBJ) $(ARMOBJ)
168 $(info [-] GEN $@)
169 $(Q)$(SH) ../tools/mkversion.sh > $@ || $(PERL) ../tools/mkversion.pl > $@ || $(CP) $< $@
171 fpga_version_info.c: $(FPGA_BITSTREAMS) $(FPGA_COMPRESSOR)
172 $(info [-] GEN $@)
173 $(Q)$(FPGA_COMPRESSOR) -v $(filter %.bit,$^) $@
175 $(OBJDIR)/fpga_all.o: $(OBJDIR)/fpga_all.bit.z
176 $(info [-] GEN $@)
177 $(Q)$(OBJCOPY) -O elf32-littlearm -I binary -B arm --prefix-sections=fpga_all_bit $^ $@
179 $(OBJDIR)/fpga_all.bit.z: $(FPGA_BITSTREAMS) | $(FPGA_COMPRESSOR)
180 $(info [-] GEN $@)
181 ifeq ($(Q),@)
182 @$(FPGA_COMPRESSOR) $(filter %.bit,$^) $@ >/dev/null
183 else
184 $(FPGA_COMPRESSOR) $(filter %.bit,$^) $@
185 endif
187 $(FPGA_COMPRESSOR):
188 $(error [!] MISSING $@ => To build it, go the root of the repo and do "make $(notdir $@)")
189 $(error [!] MISSING $@)
191 $(OBJDIR)/fullimage.stage1.elf: $(VERSIONOBJ) $(OBJDIR)/fpga_all.o $(THUMBOBJ) $(ARMOBJ)
192 $(info [=] LD $@)
193 $(Q)$(CC) $(CROSS_LDFLAGS) -Wl,-T,ldscript,-Map,$(patsubst %.elf,%.map,$@) -o $@ $^ $(LIBS)
195 $(OBJDIR)/fullimage.nodata.bin: $(OBJDIR)/fullimage.stage1.elf
196 $(info [-] GEN $@)
197 $(Q)$(OBJCOPY) -O binary -I elf32-littlearm --remove-section .data $^ $@
199 $(OBJDIR)/fullimage.nodata.o: $(OBJDIR)/fullimage.nodata.bin
200 $(info [-] GEN $@)
201 $(Q)$(OBJCOPY) -O elf32-littlearm -I binary -B arm --rename-section .data=stage1_image $^ $@
203 $(OBJDIR)/fullimage.data.bin: $(OBJDIR)/fullimage.stage1.elf
204 $(info [-] GEN $@)
205 $(Q)$(OBJCOPY) -O binary -I elf32-littlearm --only-section .data $^ $@
207 $(OBJDIR)/fullimage.data.bin.z: $(OBJDIR)/fullimage.data.bin | $(FPGA_COMPRESSOR)
208 $(info [-] GEN $@)
209 ifeq ($(Q),@)
210 @$(FPGA_COMPRESSOR) $(filter %.bin,$^) $@ >/dev/null
211 else
212 $(FPGA_COMPRESSOR) $(filter %.bin,$^) $@
213 endif
215 $(OBJDIR)/fullimage.data.o: $(OBJDIR)/fullimage.data.bin.z
216 $(info [-] GEN $@)
217 $(Q)$(OBJCOPY) -O elf32-littlearm -I binary -B arm --rename-section .data=compressed_data $^ $@
219 $(OBJDIR)/fullimage.elf: $(OBJDIR)/fullimage.nodata.o $(OBJDIR)/fullimage.data.o
220 ifeq (,$(findstring WITH_NO_COMPRESSION,$(APP_CFLAGS)))
221 $(info [=] LD $@)
222 $(Q)$(CC) $(CROSS_LDFLAGS) -Wl,-T,ldscript,-e,_osimage_entry,-Map,$(patsubst %.elf,%.map,$@) -o $@ $^
223 else
224 $(Q)$(CP) $(OBJDIR)/fullimage.stage1.elf $@
225 endif
227 tarbin: $(OBJS)
228 $(info TAR $@)
229 $(Q)$(TAR) $(TARFLAGS) ../proxmark3-$(platform)-bin.tar $(OBJS:%=armsrc/%) $(OBJS:%.s19=armsrc/%.elf)
231 clean:
232 $(Q)$(RM) $(DEPENDENCY_FILES)
233 $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.o
234 $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.elf
235 $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.s19
236 $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.map
237 $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.d
238 $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.z
239 $(Q)$(RM) $(OBJDIR)$(PATHSEP)*.bin
240 $(Q)$(RM) version_pm3.c version.c
242 install: all
243 $(info [@] Installing fullimage to $(DESTDIR)$(PREFIX)...)
244 $(Q)$(MKDIR) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH)
245 $(Q)$(CP) $(INSTALLFW) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH)$(PATHSEP)$(INSTALLFWTAG)
247 uninstall:
248 $(info [@] Uninstalling fullimage from $(DESTDIR)$(PREFIX)...)
249 $(Q)$(RM) $(DESTDIR)$(PREFIX)$(PATHSEP)$(INSTALLFWRELPATH)$(PATHSEP)$(INSTALLFWTAG)
251 .PHONY: all clean help install uninstall
252 help:
253 @echo Multi-OS Makefile, you are running on $(DETECTED_OS)
254 @echo Possible targets:
255 @echo + all - Build the full image $(OBJDIR)/fullimage.s19
256 @echo + clean - Clean $(OBJDIR)