AVR Bootloader (avrboot cleanup)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

620 lines
17 KiB

  1. # Hey Emacs, this is a -*- makefile -*-
  2. #----------------------------------------------------------------------------
  3. # WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
  4. #
  5. # Released to the Public Domain
  6. #
  7. # Additional material for this makefile was written by:
  8. # Peter Fleury
  9. # Tim Henigan
  10. # Colin O'Flynn
  11. # Reiner Patommel
  12. # Markus Pfaff
  13. # Sander Pool
  14. # Frederik Rouleau
  15. # Carlos Lamas
  16. #
  17. #----------------------------------------------------------------------------
  18. # On command line:
  19. #
  20. # make all = Make software.
  21. #
  22. # make clean = Clean out built project files.
  23. #
  24. # make coff = Convert ELF to AVR COFF.
  25. #
  26. # make extcoff = Convert ELF to AVR Extended COFF.
  27. #
  28. # make program = Download the hex file to the device, using avrdude.
  29. # Please customize the avrdude settings below first!
  30. #
  31. # make debug = Start either simulavr or avarice as specified for debugging,
  32. # with avr-gdb or avr-insight as the front end for debugging.
  33. #
  34. # make filename.s = Just compile filename.c into the assembler code only.
  35. #
  36. # make filename.i = Create a preprocessed source file for use in submitting
  37. # bug reports to the GCC project.
  38. #
  39. # To rebuild project do "make clean" then "make all".
  40. #----------------------------------------------------------------------------
  41. # MCU name
  42. MCU = atmega324p
  43. # Processor frequency.
  44. # This will define a symbol, F_CPU, in all source code files equal to the
  45. # processor frequency. You can then use this symbol in your source code to
  46. # calculate timings. Do NOT tack on a 'UL' at the end, this will be done
  47. # automatically to create a 32-bit value in your source code.
  48. # Typical values are:
  49. # F_CPU = 1000000
  50. # F_CPU = 1843200
  51. # F_CPU = 2000000
  52. # F_CPU = 3686400
  53. # F_CPU = 4000000
  54. # F_CPU = 7372800
  55. # F_CPU = 8000000
  56. # F_CPU = 11059200
  57. # F_CPU = 14745600
  58. # F_CPU = 16000000
  59. # F_CPU = 18432000
  60. # F_CPU = 20000000
  61. F_CPU = 3686400
  62. # Output format. (can be srec, ihex, binary)
  63. FORMAT = ihex
  64. # Target file name (without extension).
  65. TARGET = testapp
  66. # Object files directory
  67. # To put object files in current directory, use a dot (.), do NOT make
  68. # this an empty or blank macro!
  69. OBJDIR = .
  70. # List C source files here. (C dependencies are automatically generated.)
  71. SRC = $(TARGET).c
  72. # List C++ source files here. (C dependencies are automatically generated.)
  73. CPPSRC =
  74. # List Assembler source files here.
  75. # Make them always end in a capital .S. Files ending in a lowercase .s
  76. # will not be considered source files but generated files (assembler
  77. # output from the compiler), and will be deleted upon "make clean"!
  78. # Even though the DOS/Win* filesystem matches both .s and .S the same,
  79. # it will preserve the spelling of the filenames, and gcc itself does
  80. # care about how the name is spelled on its command-line.
  81. ASRC =
  82. # Optimization level, can be [0, 1, 2, 3, s].
  83. # 0 = turn off optimization. s = optimize for size.
  84. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  85. OPT = s
  86. # Debugging format.
  87. # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
  88. # AVR Studio 4.10 requires dwarf-2.
  89. # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
  90. DEBUG = dwarf-2
  91. # List any extra directories to look for include files here.
  92. # Each directory must be seperated by a space.
  93. # Use forward slashes for directory separators.
  94. # For a directory that has spaces, enclose it in quotes.
  95. EXTRAINCDIRS =
  96. # Compiler flag to set the C Standard level.
  97. # c89 = "ANSI" C
  98. # gnu89 = c89 plus GCC extensions
  99. # c99 = ISO C99 standard (not yet fully implemented)
  100. # gnu99 = c99 plus GCC extensions
  101. CSTANDARD = -std=gnu99
  102. # Place -D or -U options here for C sources
  103. CDEFS = -DF_CPU=$(F_CPU)UL
  104. # Place -D or -U options here for ASM sources
  105. ADEFS = -DF_CPU=$(F_CPU)
  106. # Place -D or -U options here for C++ sources
  107. CPPDEFS = -DF_CPU=$(F_CPU)UL
  108. #CPPDEFS += -D__STDC_LIMIT_MACROS
  109. #CPPDEFS += -D__STDC_CONSTANT_MACROS
  110. #---------------- Compiler Options C ----------------
  111. # -g*: generate debugging information
  112. # -O*: optimization level
  113. # -f...: tuning, see GCC manual and avr-libc documentation
  114. # -Wall...: warning level
  115. # -Wa,...: tell GCC to pass this to the assembler.
  116. # -adhlns...: create assembler listing
  117. CFLAGS = -g$(DEBUG)
  118. CFLAGS += $(CDEFS)
  119. CFLAGS += -O$(OPT)
  120. CFLAGS += -funsigned-char
  121. CFLAGS += -funsigned-bitfields
  122. CFLAGS += -fpack-struct
  123. CFLAGS += -fshort-enums
  124. CFLAGS += -Wall
  125. CFLAGS += -Wstrict-prototypes
  126. #CFLAGS += -mshort-calls
  127. #CFLAGS += -fno-unit-at-a-time
  128. #CFLAGS += -Wundef
  129. #CFLAGS += -Wunreachable-code
  130. #CFLAGS += -Wsign-compare
  131. CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
  132. CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  133. CFLAGS += $(CSTANDARD)
  134. #---------------- Compiler Options C++ ----------------
  135. # -g*: generate debugging information
  136. # -O*: optimization level
  137. # -f...: tuning, see GCC manual and avr-libc documentation
  138. # -Wall...: warning level
  139. # -Wa,...: tell GCC to pass this to the assembler.
  140. # -adhlns...: create assembler listing
  141. CPPFLAGS = -g$(DEBUG)
  142. CPPFLAGS += $(CPPDEFS)
  143. CPPFLAGS += -O$(OPT)
  144. CPPFLAGS += -funsigned-char
  145. CPPFLAGS += -funsigned-bitfields
  146. CPPFLAGS += -fpack-struct
  147. CPPFLAGS += -fshort-enums
  148. CPPFLAGS += -fno-exceptions
  149. CPPFLAGS += -Wall
  150. CFLAGS += -Wundef
  151. #CPPFLAGS += -mshort-calls
  152. #CPPFLAGS += -fno-unit-at-a-time
  153. #CPPFLAGS += -Wstrict-prototypes
  154. #CPPFLAGS += -Wunreachable-code
  155. #CPPFLAGS += -Wsign-compare
  156. CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
  157. CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  158. #CPPFLAGS += $(CSTANDARD)
  159. #---------------- Assembler Options ----------------
  160. # -Wa,...: tell GCC to pass this to the assembler.
  161. # -adhlns: create listing
  162. # -gstabs: have the assembler create line number information; note that
  163. # for use in COFF files, additional information about filenames
  164. # and function names needs to be present in the assembler source
  165. # files -- see avr-libc docs [FIXME: not yet described there]
  166. # -listing-cont-lines: Sets the maximum number of continuation lines of hex
  167. # dump that will be displayed for a given single line of source input.
  168. ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
  169. #---------------- Library Options ----------------
  170. # Minimalistic printf version
  171. PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
  172. # Floating point printf version (requires MATH_LIB = -lm below)
  173. PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
  174. # If this is left blank, then it will use the Standard printf version.
  175. PRINTF_LIB =
  176. #PRINTF_LIB = $(PRINTF_LIB_MIN)
  177. #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
  178. # Minimalistic scanf version
  179. SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
  180. # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
  181. SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
  182. # If this is left blank, then it will use the Standard scanf version.
  183. SCANF_LIB =
  184. #SCANF_LIB = $(SCANF_LIB_MIN)
  185. #SCANF_LIB = $(SCANF_LIB_FLOAT)
  186. MATH_LIB = -lm
  187. # List any extra directories to look for libraries here.
  188. # Each directory must be seperated by a space.
  189. # Use forward slashes for directory separators.
  190. # For a directory that has spaces, enclose it in quotes.
  191. EXTRALIBDIRS =
  192. #---------------- External Memory Options ----------------
  193. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  194. # used for variables (.data/.bss) and heap (malloc()).
  195. #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
  196. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  197. # only used for heap (malloc()).
  198. #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
  199. EXTMEMOPTS =
  200. #---------------- Linker Options ----------------
  201. # -Wl,...: tell GCC to pass this to linker.
  202. # -Map: create map file
  203. # --cref: add cross reference to map file
  204. LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
  205. LDFLAGS += $(EXTMEMOPTS)
  206. LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
  207. LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
  208. #LDFLAGS += -T linker_script.x
  209. #---------------- Programming Options (avrdude) ----------------
  210. # Programming hardware: alf avr910 avrisp bascom bsd
  211. # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
  212. #
  213. # Type: avrdude -c ?
  214. # to get a full listing.
  215. #
  216. AVRDUDE_PROGRAMMER = stk500
  217. # com1 = serial port. Use lpt1 to connect to parallel port.
  218. AVRDUDE_PORT = com1 # programmer connected to serial device
  219. AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
  220. #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
  221. # Uncomment the following if you want avrdude's erase cycle counter.
  222. # Note that this counter needs to be initialized first using -Yn,
  223. # see avrdude manual.
  224. #AVRDUDE_ERASE_COUNTER = -y
  225. # Uncomment the following if you do /not/ wish a verification to be
  226. # performed after programming the device.
  227. #AVRDUDE_NO_VERIFY = -V
  228. # Increase verbosity level. Please use this when submitting bug
  229. # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
  230. # to submit bug reports.
  231. #AVRDUDE_VERBOSE = -v -v
  232. AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
  233. AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
  234. AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
  235. AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
  236. #---------------- Debugging Options ----------------
  237. # For simulavr only - target MCU frequency.
  238. DEBUG_MFREQ = $(F_CPU)
  239. # Set the DEBUG_UI to either gdb or insight.
  240. # DEBUG_UI = gdb
  241. DEBUG_UI = insight
  242. # Set the debugging back-end to either avarice, simulavr.
  243. DEBUG_BACKEND = avarice
  244. #DEBUG_BACKEND = simulavr
  245. # GDB Init Filename.
  246. GDBINIT_FILE = __avr_gdbinit
  247. # When using avarice settings for the JTAG
  248. JTAG_DEV = /dev/com1
  249. # Debugging port used to communicate between GDB / avarice / simulavr.
  250. DEBUG_PORT = 4242
  251. # Debugging host used to communicate between GDB / avarice / simulavr, normally
  252. # just set to localhost unless doing some sort of crazy debugging when
  253. # avarice is running on a different computer.
  254. DEBUG_HOST = localhost
  255. #============================================================================
  256. # Define programs and commands.
  257. SHELL = sh
  258. CC = avr-gcc
  259. OBJCOPY = avr-objcopy
  260. OBJDUMP = avr-objdump
  261. SIZE = avr-size
  262. AR = avr-ar rcs
  263. NM = avr-nm
  264. AVRDUDE = avrdude
  265. REMOVE = rm -f
  266. REMOVEDIR = rm -rf
  267. COPY = cp
  268. WINSHELL = cmd
  269. # Define Messages
  270. # English
  271. MSG_ERRORS_NONE = Errors: none
  272. MSG_BEGIN = -------- begin --------
  273. MSG_END = -------- end --------
  274. MSG_SIZE_BEFORE = Size before:
  275. MSG_SIZE_AFTER = Size after:
  276. MSG_COFF = Converting to AVR COFF:
  277. MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
  278. MSG_FLASH = Creating load file for Flash:
  279. MSG_EEPROM = Creating load file for EEPROM:
  280. MSG_EXTENDED_LISTING = Creating Extended Listing:
  281. MSG_SYMBOL_TABLE = Creating Symbol Table:
  282. MSG_LINKING = Linking:
  283. MSG_COMPILING = Compiling C:
  284. MSG_COMPILING_CPP = Compiling C++:
  285. MSG_ASSEMBLING = Assembling:
  286. MSG_CLEANING = Cleaning project:
  287. MSG_CREATING_LIBRARY = Creating library:
  288. # Define all object files.
  289. OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
  290. # Define all listing files.
  291. LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
  292. # Compiler flags to generate dependency files.
  293. GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
  294. # Combine all necessary flags and optional flags.
  295. # Add target processor to flags.
  296. ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
  297. ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
  298. ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  299. # Default target.
  300. all: begin gccversion sizebefore build sizeafter end
  301. # Change the build target to build a HEX file or a library.
  302. build: elf hex eep lss sym
  303. #build: lib
  304. elf: $(TARGET).elf
  305. hex: $(TARGET).hex
  306. eep: $(TARGET).eep
  307. lss: $(TARGET).lss
  308. sym: $(TARGET).sym
  309. LIBNAME=lib$(TARGET).a
  310. lib: $(LIBNAME)
  311. # Eye candy.
  312. # AVR Studio 3.x does not check make's exit code but relies on
  313. # the following magic strings to be generated by the compile job.
  314. begin:
  315. @echo
  316. @echo $(MSG_BEGIN)
  317. end:
  318. @echo $(MSG_END)
  319. @echo
  320. # Display size of file.
  321. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  322. ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
  323. sizebefore:
  324. @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
  325. 2>/dev/null; echo; fi
  326. sizeafter:
  327. @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
  328. 2>/dev/null; echo; fi
  329. # Display compiler version information.
  330. gccversion :
  331. @$(CC) --version
  332. # Program the device.
  333. program: $(TARGET).hex $(TARGET).eep
  334. $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
  335. # Generate avr-gdb config/init file which does the following:
  336. # define the reset signal, load the target file, connect to target, and set
  337. # a breakpoint at main().
  338. gdb-config:
  339. @$(REMOVE) $(GDBINIT_FILE)
  340. @echo define reset >> $(GDBINIT_FILE)
  341. @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
  342. @echo end >> $(GDBINIT_FILE)
  343. @echo file $(TARGET).elf >> $(GDBINIT_FILE)
  344. @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
  345. ifeq ($(DEBUG_BACKEND),simulavr)
  346. @echo load >> $(GDBINIT_FILE)
  347. endif
  348. @echo break main >> $(GDBINIT_FILE)
  349. debug: gdb-config $(TARGET).elf
  350. ifeq ($(DEBUG_BACKEND), avarice)
  351. @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
  352. @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
  353. $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
  354. @$(WINSHELL) /c pause
  355. else
  356. @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
  357. $(DEBUG_MFREQ) --port $(DEBUG_PORT)
  358. endif
  359. @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
  360. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  361. COFFCONVERT = $(OBJCOPY) --debugging
  362. COFFCONVERT += --change-section-address .data-0x800000
  363. COFFCONVERT += --change-section-address .bss-0x800000
  364. COFFCONVERT += --change-section-address .noinit-0x800000
  365. COFFCONVERT += --change-section-address .eeprom-0x810000
  366. coff: $(TARGET).elf
  367. @echo
  368. @echo $(MSG_COFF) $(TARGET).cof
  369. $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
  370. extcoff: $(TARGET).elf
  371. @echo
  372. @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
  373. $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
  374. # Create final output files (.hex, .eep) from ELF output file.
  375. %.hex: %.elf
  376. @echo
  377. @echo $(MSG_FLASH) $@
  378. $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  379. %.eep: %.elf
  380. @echo
  381. @echo $(MSG_EEPROM) $@
  382. -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  383. --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
  384. # Create extended listing file from ELF output file.
  385. %.lss: %.elf
  386. @echo
  387. @echo $(MSG_EXTENDED_LISTING) $@
  388. $(OBJDUMP) -h -S $< > $@
  389. # Create a symbol table from ELF output file.
  390. %.sym: %.elf
  391. @echo
  392. @echo $(MSG_SYMBOL_TABLE) $@
  393. $(NM) -n $< > $@
  394. # Create library from object files.
  395. .SECONDARY : $(TARGET).a
  396. .PRECIOUS : $(OBJ)
  397. %.a: $(OBJ)
  398. @echo
  399. @echo $(MSG_CREATING_LIBRARY) $@
  400. $(AR) $@ $(OBJ)
  401. # Link: create ELF output file from object files.
  402. .SECONDARY : $(TARGET).elf
  403. .PRECIOUS : $(OBJ)
  404. %.elf: $(OBJ)
  405. @echo
  406. @echo $(MSG_LINKING) $@
  407. $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
  408. # Compile: create object files from C source files.
  409. $(OBJDIR)/%.o : %.c
  410. @echo
  411. @echo $(MSG_COMPILING) $<
  412. $(CC) -c $(ALL_CFLAGS) $< -o $@
  413. # Compile: create object files from C++ source files.
  414. $(OBJDIR)/%.o : %.cpp
  415. @echo
  416. @echo $(MSG_COMPILING_CPP) $<
  417. $(CC) -c $(ALL_CPPFLAGS) $< -o $@
  418. # Compile: create assembler files from C source files.
  419. %.s : %.c
  420. $(CC) -S $(ALL_CFLAGS) $< -o $@
  421. # Compile: create assembler files from C++ source files.
  422. %.s : %.cpp
  423. $(CC) -S $(ALL_CPPFLAGS) $< -o $@
  424. # Assemble: create object files from assembler source files.
  425. $(OBJDIR)/%.o : %.S
  426. @echo
  427. @echo $(MSG_ASSEMBLING) $<
  428. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  429. # Create preprocessed source for use in sending a bug report.
  430. %.i : %.c
  431. $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
  432. # Target: clean project.
  433. clean: begin clean_list end
  434. clean_list :
  435. @echo
  436. @echo $(MSG_CLEANING)
  437. $(REMOVE) $(TARGET).hex
  438. $(REMOVE) $(TARGET).eep
  439. $(REMOVE) $(TARGET).cof
  440. $(REMOVE) $(TARGET).elf
  441. $(REMOVE) $(TARGET).map
  442. $(REMOVE) $(TARGET).sym
  443. $(REMOVE) $(TARGET).lss
  444. $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o)
  445. $(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst)
  446. $(REMOVE) $(SRC:.c=.s)
  447. $(REMOVE) $(SRC:.c=.d)
  448. $(REMOVE) $(SRC:.c=.i)
  449. $(REMOVEDIR) .dep
  450. # Create object files directory
  451. $(shell mkdir $(OBJDIR) 2>/dev/null)
  452. # Include the dependency files.
  453. -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
  454. # Listing of phony targets.
  455. .PHONY : all begin finish end sizebefore sizeafter gccversion \
  456. build elf hex eep lss sym coff extcoff \
  457. clean clean_list program debug gdb-config