From 6f7731bb6deac290575c5173ea17381951637a57 Mon Sep 17 00:00:00 2001 From: WestfW Date: Thu, 9 Jun 2011 22:36:05 -0700 Subject: [PATCH] Makefile modification to allow building optiboot in more environments. Allows building within the Arduino Source tree, and within the Arduino IDE tree, as well as using CrossPack on Mac. Adds README.TXT to track arduino-specific changes (and documents the new build options.) This addresses Arduino issue: http://code.google.com/p/arduino/issues/detail?id=487 And optiboot issue http://code.google.com/p/optiboot/issues/detail?id=1 (which can be thought of as a subset of the Arduno issue.) Note that the binaries produced after these Makefile changes (using any of the compile environments) are identical to those produced by the crosspack-20100115 environment on a Mac. (cherry picked from commit 2d2ed324b48e709f59a002cb274ed60bb0ebc911) --- bootloaders/optiboot/Makefile | 77 ++++++++++++++++++--- bootloaders/optiboot/README.TXT | 55 +++++++++++++++ bootloaders/optiboot/omake | 2 + bootloaders/optiboot/omake.bat | 1 + bootloaders/optiboot/optiboot_atmega328.lst | 22 +++--- 5 files changed, 138 insertions(+), 19 deletions(-) create mode 100644 bootloaders/optiboot/README.TXT create mode 100644 bootloaders/optiboot/omake create mode 100644 bootloaders/optiboot/omake.bat diff --git a/bootloaders/optiboot/Makefile b/bootloaders/optiboot/Makefile index 0fd6005..92f9c61 100644 --- a/bootloaders/optiboot/Makefile +++ b/bootloaders/optiboot/Makefile @@ -19,6 +19,17 @@ # program name should not be changed... PROGRAM = optiboot +# The default behavior is to build using tools that are in the users +# current path variables, but we can also build using an installed +# Arduino user IDE setup, or the Arduino source tree. +# Uncomment this next lines to build within the arduino environment, +# using the arduino-included avrgcc toolset (mac and pc) +# ENV ?= arduino +# ENV ?= arduinodev +# OS ?= macosx +# OS ?= windows + + # enter the parameters for the avrdude isp tool ISPTOOL = stk500v2 ISPPORT = usb @@ -27,6 +38,50 @@ ISPSPEED = -b 115200 MCU_TARGET = atmega168 LDSECTION = --section-start=.text=0x3e00 +# Build environments +# Start of some ugly makefile-isms to allow optiboot to be built +# in several different environments. See the README.TXT file for +# details. + +# default +fixpath = $(1) + +ifeq ($(ENV), arduino) +# For Arduino, we assume that we're connected to the optiboot directory +# included with the arduino distribution, which means that the full set +# of avr-tools are "right up there" in standard places. +TOOLROOT = ../../../tools +GCCROOT = $(TOOLROOT)/avr/bin/ +AVRDUDE_CONF = -C$(TOOLROOT)/avr/etc/avrdude.conf + +ifeq ($(OS), windows) +# On windows, SOME of the tool paths will need to have backslashes instead +# of forward slashes (because they use windows cmd.exe for execution instead +# of a unix/mingw shell?) +fixpath = $(subst /,\,$1) +endif + +else ifeq ($(ENV), arduinodev) +# Arduino IDE source code environment. Use the unpacked compilers created +# by the build (you'll need to do "ant build" first.) +ifeq ($(OS), macosx) +TOOLROOT = ../../../../build/macosx/work/Arduino.app/Contents/Resources/Java/hardware/tools +endif +ifeq ($(OS), windows) +TOOLROOT = ../../../../build/windows/work/hardware/tools +endif + +GCCROOT = $(TOOLROOT)/avr/bin/ +AVRDUDE_CONF = -C$(TOOLROOT)/avr/etc/avrdude.conf + +else +GCCROOT = +AVRDUDE_CONF = +endif +# +# End of build environment code. + + # the efuse should really be 0xf8; since, however, only the lower # three bits of that byte are used on the atmega168, avrdude gets # confused if you specify 1's for the higher bits, see: @@ -37,10 +92,13 @@ LDSECTION = --section-start=.text=0x3e00 # lock it), but since the high two bits of the lock byte are # unused, avrdude would get confused. -ISPFUSES = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \ --e -u -U lock:w:0x3f:m -U efuse:w:0x$(EFUSE):m -U hfuse:w:0x$(HFUSE):m -U lfuse:w:0x$(LFUSE):m -ISPFLASH = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \ --U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x0f:m +ISPFUSES = $(GCCROOT)avrdude $(AVRDUDE_CONF) -c $(ISPTOOL) \ + -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \ + -e -u -U lock:w:0x3f:m -U efuse:w:0x$(EFUSE):m \ + -U hfuse:w:0x$(HFUSE):m -U lfuse:w:0x$(LFUSE):m +ISPFLASH = $(GCCROOT)avrdude $(AVRDUDE_CONF) -c $(ISPTOOL) \ + -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \ + -U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x0f:m STK500 = "C:\Program Files\Atmel\AVR Tools\STK500\Stk500.exe" STK500-1 = $(STK500) -e -d$(MCU_TARGET) -pf -vf -if$(PROGRAM)_$(TARGET).hex \ @@ -53,15 +111,17 @@ OPTIMIZE = -Os -fno-inline-small-functions -fno-split-wide-types -mshort-calls DEFS = LIBS = -CC = avr-gcc +CC = $(GCCROOT)avr-gcc # Override is only needed by avr-lib build system. override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(AVR_FREQ) $(DEFS) -override LDFLAGS = -Wl,$(LDSECTION) -Wl,--relax -nostartfiles +override LDFLAGS = -Wl,$(LDSECTION) -Wl,--relax -Wl,--gc-sections -nostartfiles -nostdlib -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump +OBJCOPY = $(GCCROOT)avr-objcopy +OBJDUMP = $(call fixpath,$(GCCROOT)avr-objdump) + +SIZE = $(GCCROOT)avr-size # 20MHz clocked platforms # @@ -222,6 +282,7 @@ isp-stk500: $(PROGRAM)_$(TARGET).hex %.elf: $(OBJ) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) + $(SIZE) $@ clean: rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex diff --git a/bootloaders/optiboot/README.TXT b/bootloaders/optiboot/README.TXT new file mode 100644 index 0000000..9a68e23 --- /dev/null +++ b/bootloaders/optiboot/README.TXT @@ -0,0 +1,55 @@ +This directory contains the Optiboot small bootloader for AVR +microcontrollers, somewhat modified specifically for the Arduino +environment. + +Optiboot is more fully described here: http://code.google.com/p/optiboot/ +and is the work of Peter Knight (aka Cathedrow), building on work of Jason P +Kyle, Spiff, and Ladyada. Arduino-specific modification are by Bill +Westfield (aka WestfW) + +Arduino-specific issues are tracked as part of the Arduino project +at http://code.google.com/p/arduino + + +------------------------------------------------------------ +Building optiboot for Arduino. + +Production builds of optiboot for Arduino are done on a Mac in "unix mode" +using CrossPack-AVR-20100115. CrossPack tracks WINAVR (for windows), which +is just a package of avr-gcc and related utilities, so similar builds should +work on Windows or Linux systems. + +One of the Arduino-specific changes is modifications to the makefile to +allow building optiboot using only the tools installed as part of the +Arduino environment, or the Arduino source development tree. All three +build procedures should yield identical binaries (.hex files) (although +this may change if compiler versions drift apart between CrossPack and +the Arduino IDE.) + + +Building optiboot in the arduino IDE install. + +Work in the .../hardware/arduino/bootloaders/optiboot/ and use the +"omake " command, which just generates a command that uses +the arduino-included "make" utility with a command like: + make OS=windows ENV=arduino +or make OS=macosx ENV=arduino +On windows, this assumes you're using the windows command shell. If +you're using a cygwin or mingw shell, or have one of those in your +path, the build will probably break due to slash vs backslash issues. +On a Mac, if you have the developer tools installed, you can use the +Apple-supplied version of make. +The makefile uses relative paths ("../../../tools/" and such) to find +the programs it needs, so you need to work in the existing optiboot +directory (or something created at the same "level") for it to work. + + +Building optiboot in the arduino source development install. + +In this case, there is no special shell script, and you're assumed to +have "make" installed somewhere in your path. +Build the Arduino source ("ant build") to unpack the tools into the +expected directory. +Work in Arduino/hardware/arduino/bootloaders/optiboot and use + make OS=windows ENV=arduinodev +or make OS=macosx ENV=arduinodev diff --git a/bootloaders/optiboot/omake b/bootloaders/optiboot/omake new file mode 100644 index 0000000..cc7c6bc --- /dev/null +++ b/bootloaders/optiboot/omake @@ -0,0 +1,2 @@ +echo ../../../tools/avr/bin/make OS=macosx ENV=arduino $* +../../../tools/avr/bin/make OS=macosx ENV=arduino $* diff --git a/bootloaders/optiboot/omake.bat b/bootloaders/optiboot/omake.bat new file mode 100644 index 0000000..f6815da --- /dev/null +++ b/bootloaders/optiboot/omake.bat @@ -0,0 +1 @@ +..\..\..\tools\avr\utils\bin\make OS=windows ENV=arduino %* diff --git a/bootloaders/optiboot/optiboot_atmega328.lst b/bootloaders/optiboot/optiboot_atmega328.lst index dd879dc..104799f 100644 --- a/bootloaders/optiboot/optiboot_atmega328.lst +++ b/bootloaders/optiboot/optiboot_atmega328.lst @@ -13,15 +13,15 @@ Idx Name Size VMA LMA File off Algn CONTENTS, READONLY, DEBUGGING 4 .debug_abbrev 00000196 00000000 00000000 0000053d 2**0 CONTENTS, READONLY, DEBUGGING - 5 .debug_line 000003db 00000000 00000000 000006d3 2**0 + 5 .debug_line 0000043f 00000000 00000000 000006d3 2**0 CONTENTS, READONLY, DEBUGGING - 6 .debug_frame 00000090 00000000 00000000 00000ab0 2**2 + 6 .debug_frame 00000090 00000000 00000000 00000b14 2**2 CONTENTS, READONLY, DEBUGGING - 7 .debug_str 00000124 00000000 00000000 00000b40 2**0 + 7 .debug_str 00000136 00000000 00000000 00000ba4 2**0 CONTENTS, READONLY, DEBUGGING - 8 .debug_loc 000001d1 00000000 00000000 00000c64 2**0 + 8 .debug_loc 000001d1 00000000 00000000 00000cda 2**0 CONTENTS, READONLY, DEBUGGING - 9 .debug_ranges 00000068 00000000 00000000 00000e35 2**0 + 9 .debug_ranges 00000068 00000000 00000000 00000eab 2**0 CONTENTS, READONLY, DEBUGGING Disassembly of section .text: @@ -153,7 +153,7 @@ void watchdogReset() { // GET PARAMETER returns a generic 0x03 reply - enough to keep Avrdude happy getNch(1); 7e5e: 81 e0 ldi r24, 0x01 ; 1 - 7e60: be d0 rcall .+380 ; 0x7fde + 7e60: be d0 rcall .+380 ; 0x7fde putch(0x03); 7e62: 83 e0 ldi r24, 0x03 ; 3 7e64: 24 c0 rjmp .+72 ; 0x7eae @@ -172,7 +172,7 @@ void watchdogReset() { // SET DEVICE EXT is ignored getNch(5); 7e72: 85 e0 ldi r24, 0x05 ; 5 - 7e74: b4 d0 rcall .+360 ; 0x7fde + 7e74: b4 d0 rcall .+360 ; 0x7fde 7e76: 8a c0 rjmp .+276 ; 0x7f8c } else if(ch == STK_LOAD_ADDRESS) { @@ -206,7 +206,7 @@ void watchdogReset() { // UNIVERSAL command is ignored getNch(4); 7ea8: 84 e0 ldi r24, 0x04 ; 4 - 7eaa: 99 d0 rcall .+306 ; 0x7fde + 7eaa: 99 d0 rcall .+306 ; 0x7fde putch(0x00); 7eac: 80 e0 ldi r24, 0x00 ; 0 7eae: 71 d0 rcall .+226 ; 0x7f92 @@ -503,6 +503,8 @@ void verifySpace() { 7fda: 84 e1 ldi r24, 0x14 ; 20 } 7fdc: da cf rjmp .-76 ; 0x7f92 + +00007fde : ::[count] "M" (UART_B_VALUE) ); } @@ -511,12 +513,10 @@ void verifySpace() { void getNch(uint8_t count) { 7fde: 1f 93 push r17 7fe0: 18 2f mov r17, r24 - -00007fe2 : do getch(); while (--count); 7fe2: df df rcall .-66 ; 0x7fa2 7fe4: 11 50 subi r17, 0x01 ; 1 - 7fe6: e9 f7 brne .-6 ; 0x7fe2 + 7fe6: e9 f7 brne .-6 ; 0x7fe2 verifySpace(); 7fe8: f4 df rcall .-24 ; 0x7fd2 }