Commit b2cf6bdf2b6443199a36526915b4486efe3d7b0f
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>
6 files changed:
include/avr_mcu_section.h
simavr/Makefile
simavr/sim/sim_elf.c
simavr/sim/sim_elf.h
simavr/sim/simavr.c
tests/Makefile

index b20d501741fc0d1e9db52553fd8a819706cca166..c7a6a2ee9f78b7118a93c12686c45fa755dac675 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 ee25d005b95aaa2ea361fc6bc4bb28d93b8bec07..6138d99318168c934526967d0cc3e14136842bc2 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 32b233445af6f67d1fd2a90f3d650acd086297eb..1270d67d3da10cd53a5fcec9e686a69588b0a250 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 05af0a79cf2fa7431d8de77f141fe11aef5a3534..7b13e512abf1dc178cf367062c22a3a04b4d780b 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 ff253c9daf9686cbf73b4db87551995e5b4ecf37..7cb73fa9e228d7a5da15b588a5870c2ac4c4a640 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 ff2ede5f4d0da2d8c765291114ac66f592e0770e..1de514e3a029c60e598ac8134133ef37d52bb825 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