Makefile.inc 16 KB

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