Build works on Snow Leopard, using Arduino toolchain
authorMichel <michel@yelp.buserror.com>
Wed, 2 Dec 2009 00:02:16 +0000 (00:02 +0000)
committerMichel Pollet <buserror@gmail.com>
Wed, 2 Dec 2009 00:16:45 +0000 (00:16 +0000)
Tried the make system on Snow Leopard with a change in the
Makefiles to go and get avr-gcc and such in the Arduino.app
bundle.
Also fixed the .mmcu ELF header to be compatible with x86_64

Signed-off-by: Michel Pollet <buserror@gmail.com>
include/avr_mcu_section.h
simavr/Makefile
simavr/sim/sim_elf.c
simavr/sim/sim_elf.h
simavr/sim/simavr.c
tests/Makefile

index b20d501..c7a6a2e 100644 (file)
  *
  */
 
-typedef struct avr_mcu_t {
-       long f_cpu;                             // avr is little endian
-       unsigned char id[4];    // signature bytes
-       unsigned char fuse[4];  // optional
+#include <stdint.h>
+
+struct avr_mcu_t
+{
+       uint32_t  f_cpu;                        // avr is little endian
+       uint32_t  reserved;
+       uint8_t mid[4];                         // signature bytes
+       uint8_t fuse[4];                        // optional
        char name[16];
-} avr_mcu_t;
+} __attribute__((__packed__));
 
 #define AVR_MCU(_speed, _name) \
-const avr_mcu_t _mmcu __attribute__((section(".mmcu"))) = {\
+const struct avr_mcu_t _mmcu __attribute__((section(".mmcu"))) = {\
        .f_cpu = _speed, \
-       .id = {SIGNATURE_0, SIGNATURE_1, SIGNATURE_2}, \
+       .mid = {SIGNATURE_0, SIGNATURE_1, SIGNATURE_2}, \
        .name = _name,\
 }
 
index ee25d00..6138d99 100644 (file)
 
 target = simavr
 
+ifeq (${shell uname}, Darwin)
+AVR_ROOT := "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/avr-4/"
+else
+AVR_ROOT := /usr/lib/avr
+endif
+
 CFLAGS =  -g -std=gnu99 -Wall
 CFLAGS += -O3  -mfpmath=sse -msse2
 
@@ -48,7 +54,7 @@ obj:
 obj/sim_%.o : cores/sim_%.h ${wildcard cores/*.h} ${wildcard sim/*.h}
 obj/sim_%.o : cores/sim_%.c
        @gcc $(CFLAGS) \
-               -I/usr/lib/avr/include/ \
+               -I${AVR_ROOT}/include/ \
                $<  -c -o $@
        @echo CORE $<
 
index 32b2334..1270d67 100644 (file)
@@ -88,8 +88,8 @@ int elf_read_firmware(const char * file, elf_firmware_t * firmware)
                        firmware->bsssize = s->d_size;
                } else if (!strcmp(name, ".mmcu")) {
                        Elf_Data *s = elf_getdata(scn, NULL);
-                       firmware->mmcu = *((avr_mcu_t*)s->d_buf);
-               //      printf("%s: setting speed to %ld\n", __FUNCTION__, f_cpu);
+                       firmware->mmcu = *((struct avr_mcu_t*)s->d_buf);
+               //      printf("%s: avr_mcu_t size %ld / read %ld\n", __FUNCTION__, sizeof(avr_mcu_t), s->d_size);
                //      avr->frequency = f_cpu;
                }
 #if ELF_SYMBOLS
index 05af0a7..7b13e51 100644 (file)
@@ -33,7 +33,7 @@
 #endif
 
 typedef struct elf_firmware_t {
-       avr_mcu_t mmcu;
+       struct avr_mcu_t mmcu;
        uint8_t * flash;
        uint32_t flashsize;
        uint32_t datasize;
index ff253c9..7cb73fa 100644 (file)
@@ -252,7 +252,7 @@ int main(int argc, char *argv[])
        if (f_cpu)
                f.mmcu.f_cpu = f_cpu;
 
-       printf("firmware %s f=%ld mmcu=%s\n", argv[argc-1], f.mmcu.f_cpu, f.mmcu.name);
+       printf("firmware %s f=%d mmcu=%s\n", argv[argc-1], f.mmcu.f_cpu, f.mmcu.name);
 
        avr_kind_t * maker = NULL;
        for (int i = 0; avr_kind[i] && !maker; i++) {
index ff2ede5..1de514e 100644 (file)
 #      You should have received a copy of the GNU General Public License
 #      along with simavr.  If not, see <http://www.gnu.org/licenses/>.
 
+ifeq (${shell uname}, Darwin)
+AVR_ROOT := "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/"
+else
+AVR_ROOT :=
+endif
+AVR := ${AVR_ROOT}avr-
+
+SHELL   = /bin/bash
+
 sources                := $(wildcard at*.c)
 
 all :  ${sources:.c=.axf} ${sources:.c=.hex}  ${sources:.c=.s}  
 
 %.hex: %.axf
-               @avr-objcopy -j .text -j .data -O ihex ${<} ${@}
+               @${AVR}objcopy -j .text -j .data -O ihex ${<} ${@}
 
 %.s: %.axf
-               @avr-objdump -j .text -j .data -j .bss -d  ${<} > ${@}
+               @${AVR}objdump -j .text -j .data -j .bss -d  ${<} > ${@}
 
 %.axf: %.c 
                @echo CC ${<}
                @part=${<} ; part=$${part/_*}; \
-               avr-gcc -Wall -g -Os -std=gnu99 \
+               ${AVR}gcc -Wall -g -Os -std=gnu99 \
                                -mmcu=$$part \
                                -DF_CPU=8000000 \
                                -mcall-prologues -fno-inline-small-functions \
@@ -48,7 +57,7 @@ all :  ${sources:.c=.axf} ${sources:.c=.hex}  ${sources:.c=.s}
                                -Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000 \
                                -I../include \
                                ${<} -o ${@}
-               @avr-size ${@}|sed '1d'
+               @${AVR}size ${@}|sed '1d'
 
 clean:
        rm -f *.hex *.o *.axf *.s