Skip to content

Commit 6f7731b

Browse files
WestfWdamellis
authored andcommitted
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)
1 parent b84c2c7 commit 6f7731b

File tree

5 files changed

+138
-19
lines changed

5 files changed

+138
-19
lines changed

bootloaders/optiboot/Makefile

+69-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919
# program name should not be changed...
2020
PROGRAM = optiboot
2121

22+
# The default behavior is to build using tools that are in the users
23+
# current path variables, but we can also build using an installed
24+
# Arduino user IDE setup, or the Arduino source tree.
25+
# Uncomment this next lines to build within the arduino environment,
26+
# using the arduino-included avrgcc toolset (mac and pc)
27+
# ENV ?= arduino
28+
# ENV ?= arduinodev
29+
# OS ?= macosx
30+
# OS ?= windows
31+
32+
2233
# enter the parameters for the avrdude isp tool
2334
ISPTOOL = stk500v2
2435
ISPPORT = usb
@@ -27,6 +38,50 @@ ISPSPEED = -b 115200
2738
MCU_TARGET = atmega168
2839
LDSECTION = --section-start=.text=0x3e00
2940

41+
# Build environments
42+
# Start of some ugly makefile-isms to allow optiboot to be built
43+
# in several different environments. See the README.TXT file for
44+
# details.
45+
46+
# default
47+
fixpath = $(1)
48+
49+
ifeq ($(ENV), arduino)
50+
# For Arduino, we assume that we're connected to the optiboot directory
51+
# included with the arduino distribution, which means that the full set
52+
# of avr-tools are "right up there" in standard places.
53+
TOOLROOT = ../../../tools
54+
GCCROOT = $(TOOLROOT)/avr/bin/
55+
AVRDUDE_CONF = -C$(TOOLROOT)/avr/etc/avrdude.conf
56+
57+
ifeq ($(OS), windows)
58+
# On windows, SOME of the tool paths will need to have backslashes instead
59+
# of forward slashes (because they use windows cmd.exe for execution instead
60+
# of a unix/mingw shell?)
61+
fixpath = $(subst /,\,$1)
62+
endif
63+
64+
else ifeq ($(ENV), arduinodev)
65+
# Arduino IDE source code environment. Use the unpacked compilers created
66+
# by the build (you'll need to do "ant build" first.)
67+
ifeq ($(OS), macosx)
68+
TOOLROOT = ../../../../build/macosx/work/Arduino.app/Contents/Resources/Java/hardware/tools
69+
endif
70+
ifeq ($(OS), windows)
71+
TOOLROOT = ../../../../build/windows/work/hardware/tools
72+
endif
73+
74+
GCCROOT = $(TOOLROOT)/avr/bin/
75+
AVRDUDE_CONF = -C$(TOOLROOT)/avr/etc/avrdude.conf
76+
77+
else
78+
GCCROOT =
79+
AVRDUDE_CONF =
80+
endif
81+
#
82+
# End of build environment code.
83+
84+
3085
# the efuse should really be 0xf8; since, however, only the lower
3186
# three bits of that byte are used on the atmega168, avrdude gets
3287
# confused if you specify 1's for the higher bits, see:
@@ -37,10 +92,13 @@ LDSECTION = --section-start=.text=0x3e00
3792
# lock it), but since the high two bits of the lock byte are
3893
# unused, avrdude would get confused.
3994

40-
ISPFUSES = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
41-
-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
42-
ISPFLASH = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
43-
-U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x0f:m
95+
ISPFUSES = $(GCCROOT)avrdude $(AVRDUDE_CONF) -c $(ISPTOOL) \
96+
-p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
97+
-e -u -U lock:w:0x3f:m -U efuse:w:0x$(EFUSE):m \
98+
-U hfuse:w:0x$(HFUSE):m -U lfuse:w:0x$(LFUSE):m
99+
ISPFLASH = $(GCCROOT)avrdude $(AVRDUDE_CONF) -c $(ISPTOOL) \
100+
-p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
101+
-U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x0f:m
44102

45103
STK500 = "C:\Program Files\Atmel\AVR Tools\STK500\Stk500.exe"
46104
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
53111
DEFS =
54112
LIBS =
55113

56-
CC = avr-gcc
114+
CC = $(GCCROOT)avr-gcc
57115

58116
# Override is only needed by avr-lib build system.
59117

60118
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(AVR_FREQ) $(DEFS)
61-
override LDFLAGS = -Wl,$(LDSECTION) -Wl,--relax -nostartfiles
119+
override LDFLAGS = -Wl,$(LDSECTION) -Wl,--relax -Wl,--gc-sections -nostartfiles -nostdlib
120+
121+
OBJCOPY = $(GCCROOT)avr-objcopy
122+
OBJDUMP = $(call fixpath,$(GCCROOT)avr-objdump)
62123

63-
OBJCOPY = avr-objcopy
64-
OBJDUMP = avr-objdump
124+
SIZE = $(GCCROOT)avr-size
65125

66126
# 20MHz clocked platforms
67127
#
@@ -222,6 +282,7 @@ isp-stk500: $(PROGRAM)_$(TARGET).hex
222282

223283
%.elf: $(OBJ)
224284
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
285+
$(SIZE) $@
225286

226287
clean:
227288
rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex

bootloaders/optiboot/README.TXT

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
This directory contains the Optiboot small bootloader for AVR
2+
microcontrollers, somewhat modified specifically for the Arduino
3+
environment.
4+
5+
Optiboot is more fully described here: http://code.google.com/p/optiboot/
6+
and is the work of Peter Knight (aka Cathedrow), building on work of Jason P
7+
Kyle, Spiff, and Ladyada. Arduino-specific modification are by Bill
8+
Westfield (aka WestfW)
9+
10+
Arduino-specific issues are tracked as part of the Arduino project
11+
at http://code.google.com/p/arduino
12+
13+
14+
------------------------------------------------------------
15+
Building optiboot for Arduino.
16+
17+
Production builds of optiboot for Arduino are done on a Mac in "unix mode"
18+
using CrossPack-AVR-20100115. CrossPack tracks WINAVR (for windows), which
19+
is just a package of avr-gcc and related utilities, so similar builds should
20+
work on Windows or Linux systems.
21+
22+
One of the Arduino-specific changes is modifications to the makefile to
23+
allow building optiboot using only the tools installed as part of the
24+
Arduino environment, or the Arduino source development tree. All three
25+
build procedures should yield identical binaries (.hex files) (although
26+
this may change if compiler versions drift apart between CrossPack and
27+
the Arduino IDE.)
28+
29+
30+
Building optiboot in the arduino IDE install.
31+
32+
Work in the .../hardware/arduino/bootloaders/optiboot/ and use the
33+
"omake <targets>" command, which just generates a command that uses
34+
the arduino-included "make" utility with a command like:
35+
make OS=windows ENV=arduino <targets>
36+
or make OS=macosx ENV=arduino <targets>
37+
On windows, this assumes you're using the windows command shell. If
38+
you're using a cygwin or mingw shell, or have one of those in your
39+
path, the build will probably break due to slash vs backslash issues.
40+
On a Mac, if you have the developer tools installed, you can use the
41+
Apple-supplied version of make.
42+
The makefile uses relative paths ("../../../tools/" and such) to find
43+
the programs it needs, so you need to work in the existing optiboot
44+
directory (or something created at the same "level") for it to work.
45+
46+
47+
Building optiboot in the arduino source development install.
48+
49+
In this case, there is no special shell script, and you're assumed to
50+
have "make" installed somewhere in your path.
51+
Build the Arduino source ("ant build") to unpack the tools into the
52+
expected directory.
53+
Work in Arduino/hardware/arduino/bootloaders/optiboot and use
54+
make OS=windows ENV=arduinodev <targets>
55+
or make OS=macosx ENV=arduinodev <targets>

bootloaders/optiboot/omake

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
echo ../../../tools/avr/bin/make OS=macosx ENV=arduino $*
2+
../../../tools/avr/bin/make OS=macosx ENV=arduino $*

bootloaders/optiboot/omake.bat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
..\..\..\tools\avr\utils\bin\make OS=windows ENV=arduino %*

bootloaders/optiboot/optiboot_atmega328.lst

+11-11
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ Idx Name Size VMA LMA File off Algn
1313
CONTENTS, READONLY, DEBUGGING
1414
4 .debug_abbrev 00000196 00000000 00000000 0000053d 2**0
1515
CONTENTS, READONLY, DEBUGGING
16-
5 .debug_line 000003db 00000000 00000000 000006d3 2**0
16+
5 .debug_line 0000043f 00000000 00000000 000006d3 2**0
1717
CONTENTS, READONLY, DEBUGGING
18-
6 .debug_frame 00000090 00000000 00000000 00000ab0 2**2
18+
6 .debug_frame 00000090 00000000 00000000 00000b14 2**2
1919
CONTENTS, READONLY, DEBUGGING
20-
7 .debug_str 00000124 00000000 00000000 00000b40 2**0
20+
7 .debug_str 00000136 00000000 00000000 00000ba4 2**0
2121
CONTENTS, READONLY, DEBUGGING
22-
8 .debug_loc 000001d1 00000000 00000000 00000c64 2**0
22+
8 .debug_loc 000001d1 00000000 00000000 00000cda 2**0
2323
CONTENTS, READONLY, DEBUGGING
24-
9 .debug_ranges 00000068 00000000 00000000 00000e35 2**0
24+
9 .debug_ranges 00000068 00000000 00000000 00000eab 2**0
2525
CONTENTS, READONLY, DEBUGGING
2626

2727
Disassembly of section .text:
@@ -153,7 +153,7 @@ void watchdogReset() {
153153
// GET PARAMETER returns a generic 0x03 reply - enough to keep Avrdude happy
154154
getNch(1);
155155
7e5e: 81 e0 ldi r24, 0x01 ; 1
156-
7e60: be d0 rcall .+380 ; 0x7fde <verifySpace+0xc>
156+
7e60: be d0 rcall .+380 ; 0x7fde <getNch>
157157
putch(0x03);
158158
7e62: 83 e0 ldi r24, 0x03 ; 3
159159
7e64: 24 c0 rjmp .+72 ; 0x7eae <main+0xae>
@@ -172,7 +172,7 @@ void watchdogReset() {
172172
// SET DEVICE EXT is ignored
173173
getNch(5);
174174
7e72: 85 e0 ldi r24, 0x05 ; 5
175-
7e74: b4 d0 rcall .+360 ; 0x7fde <verifySpace+0xc>
175+
7e74: b4 d0 rcall .+360 ; 0x7fde <getNch>
176176
7e76: 8a c0 rjmp .+276 ; 0x7f8c <main+0x18c>
177177
}
178178
else if(ch == STK_LOAD_ADDRESS) {
@@ -206,7 +206,7 @@ void watchdogReset() {
206206
// UNIVERSAL command is ignored
207207
getNch(4);
208208
7ea8: 84 e0 ldi r24, 0x04 ; 4
209-
7eaa: 99 d0 rcall .+306 ; 0x7fde <verifySpace+0xc>
209+
7eaa: 99 d0 rcall .+306 ; 0x7fde <getNch>
210210
putch(0x00);
211211
7eac: 80 e0 ldi r24, 0x00 ; 0
212212
7eae: 71 d0 rcall .+226 ; 0x7f92 <putch>
@@ -503,6 +503,8 @@ void verifySpace() {
503503
7fda: 84 e1 ldi r24, 0x14 ; 20
504504
}
505505
7fdc: da cf rjmp .-76 ; 0x7f92 <putch>
506+
507+
00007fde <getNch>:
506508
::[count] "M" (UART_B_VALUE)
507509
);
508510
}
@@ -511,12 +513,10 @@ void verifySpace() {
511513
void getNch(uint8_t count) {
512514
7fde: 1f 93 push r17
513515
7fe0: 18 2f mov r17, r24
514-
515-
00007fe2 <getNch>:
516516
do getch(); while (--count);
517517
7fe2: df df rcall .-66 ; 0x7fa2 <getch>
518518
7fe4: 11 50 subi r17, 0x01 ; 1
519-
7fe6: e9 f7 brne .-6 ; 0x7fe2 <getNch>
519+
7fe6: e9 f7 brne .-6 ; 0x7fe2 <getNch+0x4>
520520
verifySpace();
521521
7fe8: f4 df rcall .-24 ; 0x7fd2 <verifySpace>
522522
}

0 commit comments

Comments
 (0)