OK, fair enough. I got it to compile at the command line on my Mac using this shell script:
avr-gcc -mmcu=atmega328p \
-D__AVR_ATmega328P__ \
-DF_CPU=16000000L \
-Os \
-gdwarf-2 \
-fno-inline-small-functions \
-fno-split-wide-types \
-fno-tree-scev-cprop \
-fno-exceptions -ffunction-sections -fdata-sections \
-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -mno-tablejump \
-fno-keep-inline-functions -fno-common \
-std=gnu99 \
-Wl,--section-start=.text=7C00 \
-Wl,--relax -nostartfiles \
-Wl,--gc-sections \
-oaudioboot.elf chAudioBoot.c
rm audioboot.hex
avr-objcopy -O ihex --set-section-flags=.eeprom=alloc,load \
--no-change-warnings \
--change-section-lma \
.eeprom=0 \
-R .eeprom audioboot.elf audioboot.hex
avr-objdump -j .sec1 -d -m avr5 audioboot.hex > audioboot.lst
I modified the source file slightly to get it to compile. The diffs are:
*** chAudioBoot.c 2012-12-25 18:08:02.000000000 +1100
--- /Users/nick/Documents/AudioBoot/chaudioboot.c 2012-12-30 07:57:42.000000000 +1100
***************
*** 124,134 ****
// here starts the code for the stand alone microcontroller
//***************************************************************************************
#ifdef UNSPECIFIED_PLATTFORM
#include <avr/io.h>
#include <avr/interrupt.h>
- #include <avr/signal.h>
#include <stdlib.h>
#include <avr/boot.h>
--- 124,136 ----
// here starts the code for the stand alone microcontroller
//***************************************************************************************
+ void a_main();
+ int main(void) __attribute__ ((naked)) __attribute__ ((section (".init9")));
+
#ifdef UNSPECIFIED_PLATTFORM
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include <avr/boot.h>
***************
*** 177,183 ****
#define PINVALUE (PIND&INPUTAUDIOPIN)
//turn on pull up and set Poti GND
! #define INITPORT { PORTD|=INPUTAUDIOPIN;\
DDRD|=(1<<PD2);}
#define PINLOW (PINVALUE==0)
--- 179,185 ----
#define PINVALUE (PIND&INPUTAUDIOPIN)
//turn on pull up and set Poti GND
! #define INITPORT { PORTD|=INPUTAUDIOPIN;\
DDRD|=(1<<PD2);}
#define PINLOW (PINVALUE==0)
Basically:
- Removed an obsolete include for signal.h
- Did a function prototype for a_main
- Did a prototype for main which put it in .init9 section and made it naked
- Got rid of a space after a backslash
The amended file is attached (as well as the build script).
Compile by using the shell script:
$ ./build.sh
Resulting files:
$ ls -l
total 104
-rwxr-xr-x 1 nick staff 5714 30 Dec 08:05 audioboot.elf
-rw-r--r-- 1 nick staff 2055 30 Dec 08:05 audioboot.hex
-rw-r--r-- 1 nick staff 13306 30 Dec 08:05 audioboot.lst
-rwxr-xr-x@ 1 nick staff 805 30 Dec 07:44 build.sh
-rwxr-xr-x@ 1 nick staff 16992 30 Dec 07:57 chAudioBoot.c
The resulting file indeed seems to start at 0x7C00:
audioboot.hex: file format ihex
Disassembly of section .sec1:
00007c00 <.sec1>:
7c00: 11 e0 ldi r17, 0x01 ; 1
7c02: a0 e0 ldi r26, 0x00 ; 0
7c04: b1 e0 ldi r27, 0x01 ; 1
7c06: 01 c0 rjmp .+2 ; 0x7c0a
7c08: 1d 92 st X+, r1
7c0a: a5 38 cpi r26, 0x85 ; 133
7c0c: b1 07 cpc r27, r17
7c0e: e1 f7 brne .-8 ; 0x7c08
7c10: 25 9a sbi 0x04, 5 ; 4
7c12: 59 9a sbi 0x0b, 1 ; 11
7c14: fa d0 rcall .+500 ; 0x7e0a
I haven't tested it - I don't have the audio hardware set up - but this is closer to what you want. Now you want the fuses for a 1024 byte (512 word) bootloader (high fuse = 0xDC, I think).
I attach the .hex file as well just in case you don't plan to modify the bootloader. But I can't guarantee it works, as I said.
chAudioBoot.c (16.6 KB)
build.sh (805 Bytes)
audioboot.hex (2.01 KB)