From b2cf6bdf2b6443199a36526915b4486efe3d7b0f Mon Sep 17 00:00:00 2001 From: Michel Date: Wed, 2 Dec 2009 00:02:16 +0000 Subject: [PATCH] Build works on Snow Leopard, using Arduino toolchain 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 --- include/avr_mcu_section.h | 18 +++++++++++------- simavr/Makefile | 8 +++++++- simavr/sim/sim_elf.c | 4 ++-- simavr/sim/sim_elf.h | 2 +- simavr/sim/simavr.c | 2 +- tests/Makefile | 17 +++++++++++++---- 6 files changed, 35 insertions(+), 16 deletions(-) diff --git a/include/avr_mcu_section.h b/include/avr_mcu_section.h index b20d501..c7a6a2e 100644 --- a/include/avr_mcu_section.h +++ b/include/avr_mcu_section.h @@ -38,17 +38,21 @@ * */ -typedef struct avr_mcu_t { - long f_cpu; // avr is little endian - unsigned char id[4]; // signature bytes - unsigned char fuse[4]; // optional +#include + +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,\ } diff --git a/simavr/Makefile b/simavr/Makefile index ee25d00..6138d99 100644 --- a/simavr/Makefile +++ b/simavr/Makefile @@ -18,6 +18,12 @@ 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 $< diff --git a/simavr/sim/sim_elf.c b/simavr/sim/sim_elf.c index 32b2334..1270d67 100644 --- a/simavr/sim/sim_elf.c +++ b/simavr/sim/sim_elf.c @@ -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 diff --git a/simavr/sim/sim_elf.h b/simavr/sim/sim_elf.h index 05af0a7..7b13e51 100644 --- a/simavr/sim/sim_elf.h +++ b/simavr/sim/sim_elf.h @@ -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; diff --git a/simavr/sim/simavr.c b/simavr/sim/simavr.c index ff253c9..7cb73fa 100644 --- a/simavr/sim/simavr.c +++ b/simavr/sim/simavr.c @@ -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++) { diff --git a/tests/Makefile b/tests/Makefile index ff2ede5..1de514e 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -26,20 +26,29 @@ # You should have received a copy of the GNU General Public License # along with simavr. If not, see . +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 -- 2.39.5