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.
 
 
 
 
 

580 lines
14 KiB

  1. # Hey Emacs, this is a -*- makefile -*-
  2. #
  3. # Makefile for the AVRProg-compatible Bootloader
  4. #
  5. # based on the
  6. # WinAVR Sample makefile written by Eric B. Weddington, Jörg Wunsch, et al.
  7. # Released to the Public Domain
  8. # Please read the make user manual!
  9. #
  10. # Additional material for this makefile was submitted by:
  11. # Tim Henigan
  12. # Peter Fleury
  13. # Reiner Patommel
  14. # Sander Pool
  15. # Frederik Rouleau
  16. # Markus Pfaff
  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 (for use with AVR Studio 3.x or VMLAB).
  25. #
  26. # make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio
  27. # 4.07 or greater).
  28. #
  29. # make program = Download the hex file to the device, using avrdude. Please
  30. # customize the avrdude settings below first!
  31. #
  32. # make filename.s = Just compile filename.c into the assembler code only
  33. #
  34. # To rebuild project do "make clean" then "make all".
  35. #
  36. # user defined values
  37. # MCU name
  38. ## MCU = atmega8
  39. ## MCU = atmega16
  40. MCU = atmega32
  41. ## MCU = atmega128
  42. ## MCU = at90can128
  43. #/* Select Boot Size in Words (select one, comment out the others) */
  44. ## NO! BOOTSIZE=128
  45. ## NO! BOOTSIZE=256
  46. BOOTSIZE=512
  47. ## BOOTSIZE=1024
  48. ## BOOTSIZE=2048
  49. # /* Select if bootloader should include the inverrupt-vectors
  50. # when selecting 'no' here, the bootloader must not use
  51. # any interrupts and the modified linker-scripts are used. */
  52. ##BOOTINTVEC=yes
  53. BOOTINTVEC=no
  54. ################## BOOTLOADER ######################
  55. # mt: Boot loader support. So far not done with a separate section
  56. # to get the interrupt vector into the bootloader area.
  57. # Bootloader address in datasheet and stk500 is given as
  58. # "word", gcc toolchain needs "byte"-address
  59. # (see LDFLAGS further down)
  60. ##
  61. ifeq ($(MCU), atmega8)
  62. BFD_MACH=avr4
  63. ifeq ($(BOOTSIZE), 128)
  64. MT_BOOTLOADER_ADDRESS = 0x1F00
  65. endif
  66. ifeq ($(BOOTSIZE), 256)
  67. MT_BOOTLOADER_ADDRESS = 0x1E00
  68. endif
  69. ifeq ($(BOOTSIZE), 512)
  70. MT_BOOTLOADER_ADDRESS = 0x1C00
  71. endif
  72. ifeq ($(BOOTSIZE), 1024)
  73. MT_BOOTLOADER_ADDRESS = 0x1800
  74. endif
  75. endif
  76. ##
  77. ifeq ($(MCU), atmega16)
  78. BFD_MACH=avr5
  79. ifeq ($(BOOTSIZE), 128)
  80. MT_BOOTLOADER_ADDRESS = 0x3F00
  81. endif
  82. ifeq ($(BOOTSIZE), 256)
  83. MT_BOOTLOADER_ADDRESS = 0x3E00
  84. endif
  85. ifeq ($(BOOTSIZE), 512)
  86. MT_BOOTLOADER_ADDRESS = 0x3C00
  87. endif
  88. ifeq ($(BOOTSIZE), 1024)
  89. MT_BOOTLOADER_ADDRESS = 0x3800
  90. endif
  91. endif
  92. ##
  93. ifeq ($(MCU), atmega169)
  94. BFD_MACH=avr5
  95. ifeq ($(BOOTSIZE), 128)
  96. MT_BOOTLOADER_ADDRESS = 0x3F00
  97. endif
  98. ifeq ($(BOOTSIZE), 256)
  99. MT_BOOTLOADER_ADDRESS = 0x3E00
  100. endif
  101. ifeq ($(BOOTSIZE), 512)
  102. MT_BOOTLOADER_ADDRESS = 0x3C00
  103. endif
  104. ifeq ($(BOOTSIZE), 1024)
  105. MT_BOOTLOADER_ADDRESS = 0x3800
  106. endif
  107. endif
  108. ##
  109. ifeq ($(MCU), atmega32)
  110. BFD_MACH=avr5
  111. ifeq ($(BOOTSIZE), 256)
  112. MT_BOOTLOADER_ADDRESS = 0x7E00
  113. endif
  114. ifeq ($(BOOTSIZE), 512)
  115. MT_BOOTLOADER_ADDRESS = 0x7C00
  116. endif
  117. ifeq ($(BOOTSIZE), 1024)
  118. MT_BOOTLOADER_ADDRESS = 0x7800
  119. endif
  120. ifeq ($(BOOTSIZE), 2048)
  121. MT_BOOTLOADER_ADDRESS = 0x7000
  122. endif
  123. endif
  124. ##
  125. ifeq ($(MCU), atmega128)
  126. BFD_MACH=avr5
  127. ifeq ($(BOOTSIZE), 512)
  128. MT_BOOTLOADER_ADDRESS = 0x1FC00
  129. endif
  130. ifeq ($(BOOTSIZE), 1024)
  131. MT_BOOTLOADER_ADDRESS = 0x1F800
  132. endif
  133. ifeq ($(BOOTSIZE), 2048)
  134. MT_BOOTLOADER_ADDRESS = 0x1F000
  135. endif
  136. ifeq ($(BOOTSIZE), 4096)
  137. MT_BOOTLOADER_ADDRESS = 0x1E000
  138. endif
  139. endif
  140. ##
  141. ifeq ($(MCU), at90can128)
  142. BFD_MACH=avr5
  143. ifeq ($(BOOTSIZE), 512)
  144. MT_BOOTLOADER_ADDRESS = 0x1FC00
  145. endif
  146. ifeq ($(BOOTSIZE), 1024)
  147. MT_BOOTLOADER_ADDRESS = 0x1F800
  148. endif
  149. ifeq ($(BOOTSIZE), 2048)
  150. MT_BOOTLOADER_ADDRESS = 0x1F000
  151. endif
  152. ifeq ($(BOOTSIZE), 4096)
  153. MT_BOOTLOADER_ADDRESS = 0x1E000
  154. endif
  155. endif
  156. # Output format. (can be srec, ihex, binary)
  157. FORMAT = ihex
  158. #FORMAT = srec
  159. # Target file name (without extension).
  160. TARGET = main
  161. # List C source files here. (C dependencies are automatically generated.)
  162. SRC = $(TARGET).c
  163. # List Assembler source files here.
  164. # Make them always end in a capital .S. Files ending in a lowercase .s
  165. # will not be considered source files but generated files (assembler
  166. # output from the compiler), and will be deleted upon "make clean"!
  167. # Even though the DOS/Win* filesystem matches both .s and .S the same,
  168. # it will preserve the spelling of the filenames, and gcc itself does
  169. # care about how the name is spelled on its command-line.
  170. ASRC =
  171. # Optimization level, can be [0, 1, 2, 3, s].
  172. # 0 = turn off optimization. s = optimize for size.
  173. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
  174. OPT = s
  175. # Debugging format.
  176. # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
  177. # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
  178. DEBUG = stabs
  179. # List any extra directories to look for include files here.
  180. # Each directory must be seperated by a space.
  181. EXTRAINCDIRS =
  182. # Compiler flag to set the C Standard level.
  183. # c89 - "ANSI" C
  184. # gnu89 - c89 plus GCC extensions
  185. # c99 - ISO C99 standard (not yet fully implemented)
  186. # gnu99 - c99 plus GCC extensions
  187. CSTANDARD = -std=gnu99
  188. # Place -D or -U options here
  189. CDEFS = -DBOOTSIZE=$(BOOTSIZE)
  190. # Place -I options here
  191. CINCS =
  192. # Compiler flags.
  193. # -g*: generate debugging information
  194. # -O*: optimization level
  195. # -f...: tuning, see GCC manual and avr-libc documentation
  196. # -Wall...: warning level
  197. # -Wa,...: tell GCC to pass this to the assembler.
  198. # -adhlns...: create assembler listing
  199. CFLAGS = -g$(DEBUG)
  200. CFLAGS += $(CDEFS) $(CINCS)
  201. CFLAGS += -O$(OPT)
  202. CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  203. CFLAGS += -Wall -Wstrict-prototypes
  204. CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
  205. CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
  206. CFLAGS += $(CSTANDARD)
  207. # Assembler flags.
  208. # -Wa,...: tell GCC to pass this to the assembler.
  209. # -ahlms: create listing
  210. # -gstabs: have the assembler create line number information; note that
  211. # for use in COFF files, additional information about filenames
  212. # and function names needs to be present in the assembler source
  213. # files -- see avr-libc docs [FIXME: not yet described there]
  214. ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
  215. #Additional libraries.
  216. # Minimalistic printf version
  217. PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
  218. # Floating point printf version (requires MATH_LIB = -lm below)
  219. PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
  220. PRINTF_LIB =
  221. # Minimalistic scanf version
  222. SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
  223. # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
  224. SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
  225. SCANF_LIB =
  226. MATH_LIB = -lm
  227. # External memory options
  228. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  229. # used for variables (.data/.bss) and heap (malloc()).
  230. #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
  231. # 64 KB of external RAM, starting after internal RAM (ATmega128!),
  232. # only used for heap (malloc()).
  233. #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
  234. EXTMEMOPTS =
  235. # Linker flags.
  236. # -Wl,...: tell GCC to pass this to linker.
  237. # -Map: create map file
  238. # --cref: add cross reference to map file
  239. LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
  240. LDFLAGS += $(EXTMEMOPTS)
  241. LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
  242. ################## BOOTLOADER ######################
  243. # MT_BOOTLOADER_ADDRESS (=Start of Boot Loader section
  244. # in bytes - not words) as defined above.
  245. LDFLAGS += -Wl,--section-start=.text=$(MT_BOOTLOADER_ADDRESS)
  246. # check if linker-scripts without interrupt-vectors should
  247. # be used and set linker-option, announce to C-code by define
  248. ifeq ($(BOOTINTVEC), no)
  249. LDFLAGS += -T./ldscripts_no_vector/$(BFD_MACH).x
  250. CFLAGS += -DBOOTLOADERHASNOVECTORS
  251. endif
  252. # Programming support using avrdude. Settings and variables.
  253. # Programming hardware: alf avr910 avrisp bascom bsd
  254. # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
  255. #
  256. # Type: avrdude -c ?
  257. # to get a full listing.
  258. #
  259. AVRDUDE_PROGRAMMER = stk500v2
  260. # com1 = serial port. Use lpt1 to connect to parallel port.
  261. AVRDUDE_PORT = com1 # programmer connected to serial device
  262. #AVRDUDE_PORT = /dev/ttyS0 # programmer connected to serial device
  263. AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
  264. #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
  265. # Uncomment the following if you want avrdude's erase cycle counter.
  266. # Note that this counter needs to be initialized first using -Yn,
  267. # see avrdude manual.
  268. #AVRDUDE_ERASE_COUNTER = -y
  269. # Uncomment the following if you do /not/ wish a verification to be
  270. # performed after programming the device.
  271. #AVRDUDE_NO_VERIFY = -V
  272. # Increase verbosity level. Please use this when submitting bug
  273. # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
  274. # to submit bug reports.
  275. #AVRDUDE_VERBOSE = -v -v
  276. AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
  277. AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
  278. AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
  279. AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
  280. # ---------------------------------------------------------------------------
  281. # Define directories, if needed.
  282. #DIRAVR = c:/winavr
  283. #DIRAVRBIN = $(DIRAVR)/bin
  284. #DIRAVRUTILS = $(DIRAVR)/utils/bin
  285. #DIRINC = .
  286. #DIRLIB = $(DIRAVR)/avr/lib
  287. # Define programs and commands.
  288. #SHELL = $(DIRAVRUTILS)/sh
  289. #NM = $(DIRAVRBIN)/avr-nm
  290. #CC = $(DIRAVRBIN)/avr-gcc
  291. #OBJCOPY = $(DIRAVRBIN)/avr-objcopy
  292. #OBJDUMP= $(DIRAVRBIN)/avr-objdump
  293. #SIZE = $(DIRAVRBIN)/avr-size
  294. #AVRDUDE = $(DIRAVRBIN)/avrdude.sh
  295. #REMOVE = rm -f
  296. #COPY = cp
  297. # Define programs and commands.
  298. SHELL = sh
  299. CC = avr-gcc
  300. OBJCOPY = avr-objcopy
  301. OBJDUMP = avr-objdump
  302. SIZE = avr-size
  303. NM = avr-nm
  304. AVRDUDE = avrdude
  305. REMOVE = rm -f
  306. COPY = cp
  307. WINSHELL = cmd
  308. # Define Messages
  309. # English
  310. MSG_ERRORS_NONE = Errors: none
  311. MSG_BEGIN = -------- begin --------
  312. MSG_END = -------- end --------
  313. MSG_SIZE_BEFORE = Size before:
  314. MSG_SIZE_AFTER = Size after:
  315. MSG_COFF = Converting to AVR COFF:
  316. MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
  317. MSG_FLASH = Creating load file for Flash:
  318. MSG_EEPROM = Creating load file for EEPROM:
  319. MSG_EXTENDED_LISTING = Creating Extended Listing:
  320. MSG_SYMBOL_TABLE = Creating Symbol Table:
  321. MSG_LINKING = Linking:
  322. MSG_COMPILING = Compiling:
  323. MSG_ASSEMBLING = Assembling:
  324. MSG_CLEANING = Cleaning project:
  325. # Define all object files.
  326. OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
  327. # Define all listing files.
  328. LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
  329. # Compiler flags to generate dependency files.
  330. ### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
  331. GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
  332. # Combine all necessary flags and optional flags.
  333. # Add target processor to flags.
  334. ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
  335. ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
  336. # Default target.
  337. all: begin gccversion sizebefore build sizeafter finished end
  338. build: elf hex eep lss sym
  339. elf: $(TARGET).elf
  340. hex: $(TARGET).hex
  341. eep: $(TARGET).eep
  342. lss: $(TARGET).lss
  343. sym: $(TARGET).sym
  344. # Eye candy.
  345. # AVR Studio 3.x does not check make's exit code but relies on
  346. # the following magic strings to be generated by the compile job.
  347. begin:
  348. @echo
  349. @echo $(MSG_BEGIN)
  350. finished:
  351. @echo $(MSG_ERRORS_NONE)
  352. end:
  353. @echo $(MSG_END)
  354. @echo
  355. # Display size of file.
  356. HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
  357. ELFSIZE = $(SIZE) -x -A $(TARGET).elf
  358. sizebefore:
  359. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
  360. sizeafter:
  361. @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
  362. # Display compiler version information.
  363. gccversion :
  364. @$(CC) --version
  365. # Program the device.
  366. program: $(TARGET).hex $(TARGET).eep
  367. $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
  368. # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
  369. COFFCONVERT=$(OBJCOPY) --debugging \
  370. --change-section-address .data-0x800000 \
  371. --change-section-address .bss-0x800000 \
  372. --change-section-address .noinit-0x800000 \
  373. --change-section-address .eeprom-0x810000
  374. coff: $(TARGET).elf
  375. @echo
  376. @echo $(MSG_COFF) $(TARGET).cof
  377. $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
  378. extcoff: $(TARGET).elf
  379. @echo
  380. @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
  381. $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
  382. # Create final output files (.hex, .eep) from ELF output file.
  383. %.hex: %.elf
  384. @echo
  385. @echo $(MSG_FLASH) $@
  386. $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
  387. %.eep: %.elf
  388. @echo
  389. @echo $(MSG_EEPROM) $@
  390. -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  391. --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
  392. # Create extended listing file from ELF output file.
  393. %.lss: %.elf
  394. @echo
  395. @echo $(MSG_EXTENDED_LISTING) $@
  396. $(OBJDUMP) -h -S $< > $@
  397. # Create a symbol table from ELF output file.
  398. %.sym: %.elf
  399. @echo
  400. @echo $(MSG_SYMBOL_TABLE) $@
  401. $(NM) -n $< > $@
  402. # Link: create ELF output file from object files.
  403. .SECONDARY : $(TARGET).elf
  404. .PRECIOUS : $(OBJ)
  405. %.elf: $(OBJ)
  406. @echo
  407. @echo $(MSG_LINKING) $@
  408. $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
  409. # Compile: create object files from C source files.
  410. %.o : %.c
  411. @echo
  412. @echo $(MSG_COMPILING) $<
  413. $(CC) -c $(ALL_CFLAGS) $< -o $@
  414. # Compile: create assembler files from C source files.
  415. %.s : %.c
  416. $(CC) -S $(ALL_CFLAGS) $< -o $@
  417. # Assemble: create object files from assembler source files.
  418. %.o : %.S
  419. @echo
  420. @echo $(MSG_ASSEMBLING) $<
  421. $(CC) -c $(ALL_ASFLAGS) $< -o $@
  422. # Target: clean project.
  423. clean: begin clean_list finished end
  424. clean_list :
  425. @echo
  426. @echo $(MSG_CLEANING)
  427. $(REMOVE) $(TARGET).hex
  428. $(REMOVE) $(TARGET).eep
  429. $(REMOVE) $(TARGET).obj
  430. $(REMOVE) $(TARGET).cof
  431. $(REMOVE) $(TARGET).elf
  432. $(REMOVE) $(TARGET).map
  433. $(REMOVE) $(TARGET).obj
  434. $(REMOVE) $(TARGET).a90
  435. $(REMOVE) $(TARGET).sym
  436. $(REMOVE) $(TARGET).lnk
  437. $(REMOVE) $(TARGET).lss
  438. $(REMOVE) $(OBJ)
  439. $(REMOVE) $(LST)
  440. $(REMOVE) $(SRC:.c=.s)
  441. $(REMOVE) $(SRC:.c=.d)
  442. $(REMOVE) .dep/*
  443. # Include the dependency files.
  444. -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
  445. # Listing of phony targets.
  446. .PHONY : all begin finish end sizebefore sizeafter gccversion \
  447. build elf hex eep lss sym coff extcoff \
  448. clean clean_list program