Skip to content

Compiling Xboot for TinyG

Alden Hart edited this page Nov 7, 2013 · 16 revisions

Huge thanks to Kevin Osborn who got this working

Use these instructions if you want to change the xboot.hex file. If all you want to do is flash it onto TinyG see here

The tg-xboot boot loader is derived from Alex Forencich's xboot This version xboot has the settings and modifications for use on TinyG.

Editing and Compiling Xboot

These instructions are for Windows. For some reason we have not been able to make this work in other environments, and have not debugged what's preventing that. It enters an infinite loop in Linux and generates this error in OSX

macintosh-3:xboot your-user-dir$ make conf\x192a3.conf.mk
.dep/fifo.o.d:1: *** multiple target patterns.  Stop.
macintosh-3:xboot your-user-dir$

####Step 1 - Edit Go to the project directory and edit in whatever editor you are comfortable with. We have set up an AVR Studio4 project, but in this stage it's only useful for editing (is not used for compiling) (See End Notes about compiling and debugging under AS4 if you are so inclined).

It's most likely that any changes you want will be made to x192a3.conf.mk. This file auto-generates all the others. You may also be editing the xboot.c file or other sources if you want to change actual code, but that's less likely than just changing the configuration in the conf file.

The x192a3.conf.mk file file is copied to the parent directory as config.mk and is then used to auto-generate a bunch of other files used in the compilation.

You can also edit (and make) one of the other configs in the conf directory if you are using something other than an Xmega192 chip, but all TinyGs (except some experiments) ship with the Xmega192 chip.

####Step 2 - Compile Bring up a cmd window and navigate to the working directory. Compile by running the command: make conf\x192a3.conf.mk

You should see something like this:

Z:\Alden\Projects\TinyG\tg-xboot\xboot>make conf/x192a3.conf.mk
cp conf/x192a3.conf.mk config.mk
make
make[1]: Entering directory `Z:/Alden/Projects/proj38_TinyG/TinyG/xboot/xboot'

-------- begin --------
avr-gcc (AVR_8_bit_GNU_Toolchain_3.3.0_364) 4.5.1
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Size before:
xboot.elf  :
section       size       addr
.text       0x1066    0x30000
.bss         0x206   0x802000
.stab       0x5b68        0x0
.stabstr   0x17403        0x0
Total      0x1e1d7



Generating config.h for atxmega192a3

Compiling: xboot.c
avr-gcc -c -mmcu=atxmega192a3 -I. -gstabs   -Os -funsigned-char -funsigned-bitfi
elds -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -fno-jump-t
ables -Wall -Wa,-adhlns=xboot.lst  -Wstrict-prototypes -std=gnu99 -MD -MP -MF .d
ep/xboot.o.d -DF_CPU=32000000L -DUSE_CONFIG_H xboot.c -o xboot.o

Compiling: uart.c
avr-gcc -c -mmcu=atxmega192a3 -I. -gstabs   -Os -funsigned-char -funsigned-bitfi
elds -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -fno-jump-t
ables -Wall -Wa,-adhlns=uart.lst  -Wstrict-prototypes -std=gnu99 -MD -MP -MF .de
p/uart.o.d -DF_CPU=32000000L -DUSE_CONFIG_H uart.c -o uart.o

Compiling: api.c
avr-gcc -c -mmcu=atxmega192a3 -I. -gstabs   -Os -funsigned-char -funsigned-bitfi
elds -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -fno-jump-t
ables -Wall -Wa,-adhlns=api.lst  -Wstrict-prototypes -std=gnu99 -MD -MP -MF .dep
/api.o.d -DF_CPU=32000000L -DUSE_CONFIG_H api.c -o api.o

Linking: xboot.elf
avr-gcc -mmcu=atxmega192a3 -I. -gstabs   -Os -funsigned-char -funsigned-bitfield
s -fpack-struct -fshort-enums -ffunction-sections -fdata-sections -fno-jump-tabl
es -Wall -Wa,-adhlns=config.lst  -Wstrict-prototypes -std=gnu99 -MD -MP -MF .dep
/xboot.elf.d -DF_CPU=32000000L -DUSE_CONFIG_H xboot.o flash.o eeprom_driver.o ua
rt.o i2c.o fifo.o watchdog.o api.o sp_driver.o --output xboot.elf -Wl,-Map=xboot
.map,--cref -Wl,--gc-sections    -lm -Wl,--section-start=.text=0x030000

Creating load file for Flash: xboot.hex
avr-objcopy -O ihex -R .eeprom xboot.elf xboot.hex

Creating load file for boot section: xboot-boot.hex
avr-objcopy -O ihex --change-addresses -0x030000 xboot.hex xboot-boot.hex

Creating load file for EEPROM: xboot.eep
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
        --change-section-lma .eeprom=0 -O ihex xboot.elf xboot.eep
c:\Program Files\Atmel\AVR Tools\AVR Toolchain\bin\avr-objcopy.exe: --change-sec
tion-lma .eeprom=0x00000000 never used

Creating Extended Listing: xboot.lss
avr-objdump -h -S xboot.elf > xboot.lss

Creating Symbol Table: xboot.sym
avr-nm -n xboot.elf > xboot.sym

Size after:
xboot.elf  :
section       size       addr
.text       0x1066    0x30000
.bss         0x206   0x802000
.stab       0x5b68        0x0
.stabstr   0x17403        0x0
Total      0x1e1d7

Errors: none
-------- end --------

make[1]: Leaving directory `Z:/Alden/Projects/proj38_TinyG/TinyG/xboot/xboot'

Z:\Alden\Projects\proj38_TinyG\TinyG\xboot\xboot>

You should now be ready to flash xboot.hex onto the xmega192. Refer to the Flashing... section, above.

END NOTES: Setting up Xboot as an AVRStudio4 Project - and using AS4 to compile and debug

Xboot has been set up as an AVRStudio4 project (Windows only). use the xboot.aps project file.

Note: We abandoned trying to get it running under Studio 6 as it simply doesn't work. Xboot seems to only compile under the AVRGCC 4.3.3 (WinAVR 20100110). Studio 6 runs the AVR_8_bit_GNU_Toolchain_3.4.0_663 (4.6.2). For some reason code generated by the the newer compiler doesn't function - it fails during EEPROM write. Evidently this is a known bug - but it's not our bug, so time to move on. These are not the droids we are looking for.

You can either use the native makefile or have AS4 auto generate a makefile. The auto-generated option allows you to use the AVR simulator to debug - otherwise there is no functional difference.

Be aware that in order to generate the config.h file you must change x192a3.conf.mk and make it with the native makefile. The AVRStudio4 project does not run the config.h target.

Native Makefile

To use the native makefile check Use External Makefile in Project / Configuration Options.

Running the external make from AS4 does not create the config.h file. Manually run make conf/x192a3.conf.mk from a windows command line. You will have to do this initially and each time you change x192a3.conf.mk.

You want to use the xboot.hex in the xboot working directory.

Auto-generated Makefile

To use the auto-generated makefile do the following:

  1. Generate config.h by running make conf/x192a3.conf.mk from a windows command line (as above). You will have to do this initially and each time you change x192a3.conf.mk.
  2. Setup the xboot project configuration in Project \ Configuration Options
in the General section:
uncheck `Use External Makefile`
frequency = 32000000   (32 Mhz)
optimization = -Os
add the following to Custom Options, [All files]:
-DUSE_CONFIG_H
-ffunction-sections
-fdata-sections
add the following to Custom Options, [Linker Options]:
-Wl,--section-start=.text=0x030000
-Wl,-Map=xboot.map,--cref
-Wl,--gc-sections

You will want to use the xboot.hex file found in the default directory