Makefile.inc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. # Hey Emacs, this is a -*- makefile -*-
  2. #----------------------------------------------------------------------------
  3. #
  4. # Makefile for ChipWhisperer Victims
  5. #
  6. #----------------------------------------------------------------------------
  7. # On command line:
  8. #
  9. # make all = Make software.
  10. #
  11. # make clean = Clean out built project files.
  12. #
  13. # make program = Download the hex file to the device, using avrdude.
  14. # Please customize the avrdude settings below first!
  15. #
  16. # make debug = Start either simulavr or avarice as specified for debugging,
  17. # with avr-gdb or avr-insight as the front end for debugging.
  18. #
  19. # make filename.s = Just compile filename.c into the assembler code only.
  20. #
  21. # make filename.i = Create a preprocessed source file for use in submitting
  22. # bug reports to the GCC project.
  23. #
  24. # To rebuild project do "make clean" then "make all".
  25. #----------------------------------------------------------------------------
  26. ifeq ($(PLATFORM),)
  27. -include Makefile.platform
  28. ifeq ($(PLATFORM),)
  29. PLATFORM=NONE
  30. else
  31. ${info using saved PLATFORM '$(PLATFORM)'}
  32. endif
  33. endif
  34. include $(FIRMWAREPATH)/hal/Makefile.hal
  35. #include $(FIRMWAREPATH)/crypto/Makefile.crypto
  36. #Debug - can be useful to see variables
  37. #${info '$(.VARIABLES)'}
  38. # Add the platform to the output filenames
  39. TARGET-PLAT = $(TARGET)-$(PLATFORM)
  40. # Also get target names for all platforms (for make clean)
  41. TARGET-ALL = $(foreach PLAT,$(PLATFORM_LIST), $(TARGET)-$(PLAT))
  42. # Object files directory
  43. # To put object files in current directory, use a dot (.), do NOT make
  44. # this an empty or blank macro!
  45. OBJDIR = objdir-$(PLATFORM)
  46. # List C source files here. (C dependencies are automatically generated.)
  47. SRC +=
  48. # List C++ source files here. (C dependencies are automatically generated.)
  49. CPPSRC +=
  50. # List Assembler source files here.
  51. # Make them always end in a capital .S. Files ending in a lowercase .s
  52. # will not be considered source files but generated files (assembler
  53. # output from the compiler), and will be deleted upon "make clean"!
  54. # Even though the DOS/Win* filesystem matches both .s and .S the same,
  55. # it will preserve the spelling of the filenames, and gcc itself does
  56. # care about how the name is spelled on its command-line.
  57. ASRC +=
  58. ##########################################################################
  59. ##########################################################################
  60. #VPATH +=
  61. # Optimization level, can be [0, 1, 2, 3, s].
  62. # 0 = turn off optimization. s = optimize for size.
  63. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  64. ifeq ($(OPT),)
  65. OPT = s
  66. endif
  67. # Debugging format.
  68. # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
  69. # AVR Studio 4.10 requires dwarf-2.
  70. # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
  71. DEBUG = dwarf-2
  72. # List any extra directories to look for include files here.
  73. # Each directory must be seperated by a space.
  74. # Use forward slashes for directory separators.
  75. # For a directory that has spaces, enclose it in quotes.
  76. EXTRAINCDIRS +=
  77. # Compiler flag to set the C Standard level.
  78. # c89 = "ANSI" C
  79. # gnu89 = c89 plus GCC extensions
  80. # c99 = ISO C99 standard (not yet fully implemented)
  81. # gnu99 = c99 plus GCC extensions
  82. CSTANDARD = -std=gnu99
  83. # Place -D or -U options here for C sources
  84. CDEFS += -DF_CPU=$(F_CPU)UL -DSS_VER_2_0=2 -DSS_VER_2_1=3 -DSS_VER_1_1=1 -DSS_VER_1_0=0
  85. CDEFS += -DARM=1
  86. # Place -D or -U options here for ASM sources
  87. ADEFS += -DF_CPU=$(F_CPU)
  88. # Place -D or -U options here for C++ sources
  89. CPPDEFS += -DF_CPU=$(F_CPU)UL
  90. #CPPDEFS += -D__STDC_LIMIT_MACROS
  91. #CPPDEFS += -D__STDC_CONSTANT_MACROS
  92. #---------------- Compiler Options C ----------------
  93. # -g*: generate debugging information
  94. # -O*: optimization level
  95. # -f...: tuning, see GCC manual and avr-libc documentation
  96. # -Wall...: warning level
  97. # -Wa,...: tell GCC to pass this to the assembler.
  98. # -adhlns...: create assembler listing
  99. CFLAGS += -g$(DEBUG)
  100. CFLAGS += $(CDEFS)
  101. CFLAGS += -O$(OPT)
  102. CFLAGS += -funsigned-char
  103. CFLAGS += -funsigned-bitfields
  104. # Note: -fpack-struct is dangerous! This is only included in XMEGA/AVR HAL
  105. #CFLAGS += -fpack-struct
  106. CFLAGS += -fshort-enums
  107. CFLAGS += -Wall
  108. CFLAGS += -Wstrict-prototypes
  109. #CFLAGS += -mshort-calls
  110. #CFLAGS += -fno-unit-at-a-time
  111. #CFLAGS += -Wundef
  112. #CFLAGS += -Wunreachable-code
  113. #CFLAGS += -Wsign-compare
  114. CFLAGS += -Wa,-adhlns=$(addprefix $(OBJDIR)/,$(notdir $(<:%.c=%.lst)))
  115. CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  116. CFLAGS += $(CSTANDARD)
  117. #---------------- Compiler Options C++ ----------------
  118. # -g*: generate debugging information
  119. # -O*: optimization level
  120. # -f...: tuning, see GCC manual and avr-libc documentation
  121. # -Wall...: warning level
  122. # -Wa,...: tell GCC to pass this to the assembler.
  123. # -adhlns...: create assembler listing
  124. CPPFLAGS += -g$(DEBUG)
  125. CPPFLAGS += $(CPPDEFS)
  126. CPPFLAGS += -O$(OPT)
  127. CPPFLAGS += -funsigned-char
  128. CPPFLAGS += -funsigned-bitfields
  129. CPPFLAGS += -fpack-struct
  130. CPPFLAGS += -fshort-enums
  131. CPPFLAGS += -fno-exceptions
  132. CPPFLAGS += -Wall
  133. CPPFLAGS += -Wundef
  134. #CPPFLAGS += -mshort-calls
  135. #CPPFLAGS += -fno-unit-at-a-time
  136. #CPPFLAGS += -Wstrict-prototypes
  137. #CPPFLAGS += -Wunreachable-code
  138. #CPPFLAGS += -Wsign-compare
  139. CPPFLAGS += -Wa,-adhlns=$(addprefix $(OBJDIR)/,$(notdir $(<:%.cpp=%.lst)))
  140. CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  141. #CPPFLAGS += $(CSTANDARD)
  142. #Flags that must come at end of list can be specified with CFLAGS_LAST
  143. CFLAGS += $(CFLAGS_LAST)
  144. #---------------- Assembler Options ----------------
  145. # -Wa,...: tell GCC to pass this to the assembler.
  146. # -adhlns: create listing
  147. # -gstabs: have the assembler create line number information; note that
  148. # for use in COFF files, additional information about filenames
  149. # and function names needs to be present in the assembler source
  150. # files -- see avr-libc docs [FIXME: not yet described there]
  151. # -listing-cont-lines: Sets the maximum number of continuation lines of hex
  152. # dump that will be displayed for a given single line of source input.
  153. #-adhlns=$(<:%.S=$(OBJDIR)/%.lst),
  154. #,--listing-cont-lines=100
  155. ASFLAGS += $(ADEFS) -Wa,-gstabs,-adhlns=$(addprefix $(OBJDIR)/,$(notdir $(<:%.S=%.lst)))
  156. ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  157. #---------------- Library Options ----------------
  158. # Minimalistic printf version
  159. PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
  160. # Floating point printf version (requires MATH_LIB = -lm below)
  161. PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
  162. # If this is left blank, then it will use the Standard printf version.
  163. PRINTF_LIB =
  164. #PRINTF_LIB = $(PRINTF_LIB_MIN)
  165. #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
  166. # Minimalistic scanf version
  167. SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
  168. # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
  169. SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
  170. # If this is left blank, then it will use the Standard scanf version.
  171. SCANF_LIB =
  172. #SCANF_LIB = $(SCANF_LIB_MIN)
  173. #SCANF_LIB = $(SCANF_LIB_FLOAT)
  174. MATH_LIB = -lm
  175. # List any extra directories to look for libraries here.
  176. # Each directory must be seperated by a space.
  177. # Use forward slashes for directory separators.
  178. # For a directory that has spaces, enclose it in quotes.
  179. EXTRALIBDIRS =
  180. #---------------- External Memory Options ----------------
  181. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  182. # used for variables (.data/.bss) and heap (malloc()).
  183. #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
  184. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  185. # only used for heap (malloc()).
  186. #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
  187. EXTMEMOPTS =
  188. #---------------- Linker Options ----------------
  189. # -Wl,...: tell GCC to pass this to linker.
  190. # -Map: create map file
  191. # --cref: add cross reference to map file
  192. LDFLAGS += -Wl,-Map=$(TARGET-PLAT).map,--cref
  193. LDFLAGS += $(EXTMEMOPTS)
  194. LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
  195. LDFLAGS += $(MATH_LIB)
  196. LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB)
  197. #LDFLAGS += -T linker_script.x
  198. #============================================================================
  199. # Define programs and commands.
  200. SHELL = sh
  201. REMOVE = rm -f --
  202. REMOVEDIR = rm -rf
  203. COPY = cp
  204. WINSHELL = cmd
  205. #Depending on if echo is unix or windows, they respond differently to no arguments. Windows will annoyingly
  206. #print "echo OFF", so instead we're forced to give it something to echo. The windows one will also print
  207. #passed ' or " symbols, so we use a . as it's pretty small...
  208. ECHO_BLANK = echo .
  209. ifeq ($(OS),Windows_NT)
  210. AdjustPath = $(addprefix $1\, $(subst /,\,$2 ) )
  211. MAKEDIR = mkdir
  212. else
  213. AdjustPath = $(addprefix $1/, $2)
  214. MAKEDIR = mkdir -p
  215. endif
  216. # Define Messages
  217. # English
  218. MSG_ERRORS_NONE = Errors: none
  219. MSG_SIZE_BEFORE = Size before:
  220. MSG_SIZE_AFTER = Size after:
  221. MSG_FLASH = Creating load file for Flash:
  222. MSG_EEPROM = Creating load file for EEPROM:
  223. MSG_EXTENDED_LISTING = Creating Extended Listing:
  224. MSG_SYMBOL_TABLE = Creating Symbol Table:
  225. MSG_LINKING = Linking:
  226. MSG_COMPILING = Compiling C:
  227. MSG_COMPILING_CPP = Compiling C++:
  228. MSG_ASSEMBLING = Assembling:
  229. MSG_CLEANING = Cleaning project:
  230. MSG_CREATING_LIBRARY = Creating library:
  231. # Define all object files.
  232. OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
  233. # Define all listing files.
  234. LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
  235. # Compiler flags to generate dependency files.
  236. GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
  237. # Combine all necessary flags and optional flags.
  238. # Add target processor to flags.
  239. ALL_CFLAGS = $(MCU_FLAGS) -I. $(CFLAGS) $(GENDEPFLAGS)
  240. ALL_CPPFLAGS = $(MCU_FLAGS) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
  241. ALL_ASFLAGS = $(MCU_FLAGS) -I. -x assembler-with-cpp $(ASFLAGS)
  242. # Default target.
  243. all: clean_objs .dep begin gccversion build sizeafter fastnote end
  244. allquick: begin gccversion build sizeafter end
  245. # Change the build target to build a HEX file or a library.
  246. build: elf hex eep lss sym
  247. #build: lib
  248. elf: $(TARGET-PLAT).elf
  249. hex: $(TARGET-PLAT).hex
  250. eep: $(TARGET-PLAT).eep
  251. lss: $(TARGET-PLAT).lss
  252. sym: $(TARGET-PLAT).sym
  253. map: $(TARGET-PLAT).map
  254. LIBNAME=lib$(TARGET-PLAT).a
  255. lib: $(LIBNAME)
  256. begin:
  257. @$(ECHO_BLANK)
  258. @echo Welcome to another exciting ChipWhisperer target build!!
  259. end:
  260. @echo +--------------------------------------------------------
  261. @echo + Built for platform "$(PLTNAME)" with:
  262. @echo + CRYPTO_TARGET = "$(CRYPTO_TARGET)"
  263. @echo + CRYPTO_OPTIONS = "$(CRYPTO_OPTIONS)"
  264. @echo +--------------------------------------------------------
  265. fastnote:
  266. @echo +--------------------------------------------------------
  267. @echo + Default target does full rebuild each time.
  268. @echo + Specify buildtarget == allquick == to avoid full rebuild
  269. @echo +--------------------------------------------------------
  270. # Display size of file.
  271. HEXSIZE = $(SIZE) --target=ihex $(TARGET-PLAT).hex
  272. # Note: custom ELFSIZE command can be specified in Makefile.platform
  273. # See avr/Makefile.avr for example
  274. ifeq ($(ELFSIZE),)
  275. ELFSIZE = $(SIZE) $(TARGET-PLAT).elf
  276. endif
  277. sizeafter: build
  278. @echo $(MSG_SIZE_AFTER)
  279. @$(ELFSIZE)
  280. $(OBJ): | $(OBJDIR)
  281. $(OBJDIR):
  282. $(MAKEDIR) $(OBJDIR) $(call AdjustPath,$(OBJDIR),$(MKDIR_LIST) )
  283. .dep:
  284. $(MAKEDIR) .dep
  285. # Display compiler version information.
  286. gccversion :
  287. @$(CC) --version
  288. # Program the device.
  289. program: $(TARGET-PLAT).hex $(TARGET-PLAT).eep
  290. $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
  291. # Generate avr-gdb config/init file which does the following:
  292. # define the reset signal, load the target file, connect to target, and set
  293. # a breakpoint at main().
  294. gdb-config:
  295. @$(REMOVE) $(GDBINIT_FILE)
  296. @echo define reset >> $(GDBINIT_FILE)
  297. @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
  298. @echo end >> $(GDBINIT_FILE)
  299. @echo file $(TARGET-PLAT).elf >> $(GDBINIT_FILE)
  300. @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
  301. ifeq ($(DEBUG_BACKEND),simulavr)
  302. @echo load >> $(GDBINIT_FILE)
  303. endif
  304. @echo break main >> $(GDBINIT_FILE)
  305. debug: gdb-config $(TARGET-PLAT).elf
  306. ifeq ($(DEBUG_BACKEND), avarice)
  307. @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
  308. @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
  309. $(TARGET-PLAT).elf $(DEBUG_HOST):$(DEBUG_PORT)
  310. @$(WINSHELL) /c pause
  311. else
  312. @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
  313. $(DEBUG_MFREQ) --port $(DEBUG_PORT)
  314. endif
  315. @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
  316. # Create final output files (.hex, .eep) from ELF output file.
  317. %.hex: %.elf
  318. @$(ECHO_BLANK)
  319. @echo $(MSG_FLASH) $@
  320. $(OBJCOPY) -O ihex -R .eeprom -R .fuse -R .lock -R .signature $< $@
  321. %.eep: %.elf
  322. @$(ECHO_BLANK)
  323. @echo $(MSG_EEPROM) $@
  324. -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  325. --change-section-lma .eeprom=0 --no-change-warnings -O ihex $< $@ || exit 0
  326. # Create extended listing file from ELF output file.
  327. %.lss: %.elf
  328. @$(ECHO_BLANK)
  329. @echo $(MSG_EXTENDED_LISTING) $@
  330. $(OBJDUMP) -h -S -z $< > $@
  331. # Create a symbol table from ELF output file.
  332. %.sym: %.elf
  333. @$(ECHO_BLANK)
  334. @echo $(MSG_SYMBOL_TABLE) $@
  335. $(NM) -n $< > $@
  336. # Create library from object files.
  337. .SECONDARY : $(TARGET-PLAT).a
  338. .PRECIOUS : $(OBJ)
  339. %.a: $(OBJ)
  340. @$(ECHO_BLANK)
  341. @echo $(MSG_CREATING_LIBRARY) $@
  342. $(AR) $@ $(OBJ)
  343. # Link: create ELF output file from object files.
  344. .SECONDARY : $(TARGET-PLAT).elf
  345. .PRECIOUS : $(OBJ)
  346. %.elf: $(OBJ)
  347. @$(ECHO_BLANK)
  348. @echo $(MSG_LINKING) $@
  349. $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
  350. # Compile: create object files from C source files.
  351. $(OBJDIR)/%.o : %.c
  352. @$(ECHO_BLANK)
  353. @echo $(MSG_COMPILING) $<
  354. $(CC) -c $(ALL_CFLAGS) $< -o $@
  355. # Compile: create object files from C++ source files.
  356. $(OBJDIR)/%.o : %.cpp
  357. @$(ECHO_BLANK)
  358. @echo $(MSG_COMPILING_CPP) $<
  359. $(CC) -c $(ALL_CPPFLAGS) $< -o $@
  360. # Compile: create assembler files from C source files.
  361. %.s : %.c
  362. $(CC) -S $(ALL_CFLAGS) $< -o $@
  363. # Compile: create assembler files from C++ source files.
  364. %.s : %.cpp
  365. $(CC) -S $(ALL_CPPFLAGS) $< -o $@
  366. # Assemble: create object files from assembler source files.
  367. $(OBJDIR)/%.o : %.S
  368. @$(ECHO_BLANK)
  369. @echo $(MSG_ASSEMBLING) $<
  370. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  371. # Create preprocessed source for use in sending a bug report.
  372. %.i : %.c
  373. $(CC) -E $(MCU_FLAGS) -I. $(CFLAGS) $< -o $@
  374. # Clean all object files specific to this platform
  375. clean_objs :
  376. $(REMOVE) *.map
  377. $(REMOVE) $(TARGET-PLAT).hex
  378. $(REMOVE) $(TARGET-PLAT).eep
  379. $(REMOVE) $(TARGET-PLAT).cof
  380. $(REMOVE) $(TARGET-PLAT).elf
  381. $(REMOVE) $(TARGET-PLAT).sym
  382. $(REMOVE) $(TARGET-PLAT).lss
  383. $(REMOVE) $(OBJDIR)/*.o
  384. $(REMOVE) $(OBJDIR)/*.lst
  385. $(REMOVE) $(SRC:.c=.s)
  386. $(REMOVE) $(SRC:.c=.d)
  387. $(REMOVE) $(SRC:.c=.i)
  388. # Target: clean project.
  389. clean: begin clean_print clean_all_objs clean_list end
  390. clean_print :
  391. @$(ECHO_BLANK)
  392. @echo $(MSG_CLEANING)
  393. # Clean all object files related to any of the platforms
  394. clean_all_objs :
  395. $(REMOVE) $(addsuffix .hex,$(TARGET-ALL))
  396. $(REMOVE) $(addsuffix .eep,$(TARGET-ALL))
  397. $(REMOVE) $(addsuffix .cof,$(TARGET-ALL))
  398. $(REMOVE) $(addsuffix .elf,$(TARGET-ALL))
  399. $(REMOVE) $(addsuffix .map,$(TARGET-ALL))
  400. $(REMOVE) $(addsuffix .sym,$(TARGET-ALL))
  401. $(REMOVE) $(addsuffix .lss,$(TARGET-ALL))
  402. $(REMOVE) $(OBJDIR)/*.o
  403. $(REMOVE) $(OBJDIR)/*.lst
  404. $(REMOVEDIR) $(OBJDIR)
  405. $(REMOVE) $(SRC:.c=.s)
  406. $(REMOVE) $(SRC:.c=.d)
  407. $(REMOVE) $(SRC:.c=.i)
  408. clean_list :
  409. $(REMOVEDIR) .dep
  410. # Create object files directory
  411. #$(shell mkdir $(OBJDIR) 2>/dev/null)
  412. # Include the dependency files.
  413. #-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
  414. -include $(wildcard .dep/*)
  415. # Listing of phony targets.
  416. .PHONY : all allquick begin finish end sizeafter gccversion \
  417. build elf hex eep lss sym coff extcoff \
  418. clean clean_list clean_print clean_objs program debug gdb-config \
  419. fastnote
  420. # saveplatform: Save the platform into the file Makefile.target
  421. saveplatform:
  422. -@rm -f Makefile.platform
  423. @echo "Saving Makefile.platform"
  424. @echo >Makefile.platform "PLATFORM = $(PLATFORM)"