change the build-process of the updater (do some linker magic)
authorStephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
Mon, 17 Sep 2012 21:44:37 +0000 (23:44 +0200)
committerStephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
Mon, 17 Sep 2012 23:45:56 +0000 (23:45 +0000)
Signed-off-by: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
updater/Makefile
updater/updater.c
updater/usbasploader.h [new file with mode: 0644]

index de347cd..a3aa145 100644 (file)
@@ -8,7 +8,7 @@
 include ../Makefile.inc
 
 # elsewise gcc would complain unnecessary
 include ../Makefile.inc
 
 # elsewise gcc would complain unnecessary
-CFLAGS = -Wall -Wno-pointer-to-int-cast -Os -fno-move-loop-invariants -fno-tree-scev-cprop -fno-inline-small-functions -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) -DNEW_BOOTLOADER_ADDRESS=$(NEW_BOOTLOADER_ADDRESS) $(DEFINES)
+CFLAGS = -Wall -Wno-pointer-to-int-cast -Os -fno-move-loop-invariants -fno-tree-scev-cprop -fno-inline-small-functions -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) -DBOOTLOADER_ADDRESS=$(BOOTLOADER_ADDRESS) -DNEW_BOOTLOADER_ADDRESS=$(NEW_BOOTLOADER_ADDRESS) $(DEFINES)
 LDFLAGS = -Wl,--relax,--gc-sections
 
 ifneq ($(FLASHADDRESS), 0)
 LDFLAGS = -Wl,--relax,--gc-sections
 
 ifneq ($(FLASHADDRESS), 0)
@@ -39,11 +39,20 @@ all:  updater.hex
 ../firmware/main.bin:
        $(MAKE) -C ../firmware main.hex
 
 ../firmware/main.bin:
        $(MAKE) -C ../firmware main.hex
 
-updater.o: updater.c firmware.h
-       $(CC) updater.c -c -o updater.o $(CFLAGS)
 
 
-updater.elf: updater.o
-       $(CC) updater.o -o updater.elf $(CFLAGS) $(LDFLAGS)
+usbasploader.raw:
+       $(OBC) -j .text -j .data -O binary ../firmware/main.bin usbasploader.raw
+
+usbasploader.o: usbasploader.raw
+       $(OBC) -I binary -O elf32-avr --rename-section .data=.text --redefine-sym _binary_usbasploader_raw_start=usbasploader  usbasploader.raw usbasploader.o
+
+
+updater.o: updater.c usbasploader.h usbasploader.raw usbasploader.o
+       $(CC) updater.c -c -o updater.o -DSIZEOF_new_firmware=$(shell stat -c %s usbasploader.raw) $(CFLAGS)
+#      $(CC) updater.c -c -o updater.o $(CFLAGS)
+
+updater.elf: updater.o usbasploader.o
+       $(CC) updater.o usbasploader.o -o updater.elf $(CFLAGS) $(LDFLAGS)
 
 updater.hex: updater.elf
        $(OBC) -j .text -j .data -O ihex updater.elf updater.hex
 
 updater.hex: updater.elf
        $(OBC) -j .text -j .data -O ihex updater.elf updater.hex
@@ -54,18 +63,6 @@ updater.hex: updater.elf
        $(ECHO) "."
 
 
        $(ECHO) "."
 
 
-
-firmware_gen.o: firmware_gen.c
-       $(GCC) firmware_gen.c -c -o firmware_gen.o
-
-firmware_gen: firmware_gen.o
-       $(GCC) firmware_gen.o -o firmware_gen
-
-firmware.h: firmware_gen ../firmware/main.bin
-       $(OBC) -j .text -j .data -O binary ../firmware/main.bin usbasploader.raw
-       @./firmware_gen > firmware.h
-
-
 deepclean: clean
        $(RM) *~
 
 deepclean: clean
        $(RM) *~
 
@@ -74,5 +71,4 @@ clean:
        $(RM) *.raw
        $(RM) updater.hex
        $(RM) updater.elf
        $(RM) *.raw
        $(RM) updater.hex
        $(RM) updater.elf
-       $(RM) firmware_gen
-       $(RM) firmware.h
\ No newline at end of file
+       $(RM) usbasploader.raw
\ No newline at end of file
index 6b9cde3..c1ff17d 100644 (file)
@@ -7,7 +7,7 @@
 // #define mypgmdebug 1
 
 #include "../firmware/spminterface.h"
 // #define mypgmdebug 1
 
 #include "../firmware/spminterface.h"
-#include "firmware.h"
+#include "usbasploader.h"
 
 #include <avr/io.h>
 #include <avr/interrupt.h>
 
 #include <avr/io.h>
 #include <avr/interrupt.h>
diff --git a/updater/usbasploader.h b/updater/usbasploader.h
new file mode 100644 (file)
index 0000000..1ff4764
--- /dev/null
@@ -0,0 +1,23 @@
+
+#ifndef FIRMWARE_H_5f27a7e9840141b1aa57eef07c1d939f
+#define FIRMWARE_H_5f27a7e9840141b1aa57eef07c1d939f 1
+
+#include <stdint.h>
+#include <avr/io.h>
+#include <avr/pgmspace.h>
+#include "../firmware/spminterface.h"
+
+#ifndef SIZEOF_new_firmware
+  #ifdef BOOTLOADER_ADDRESS
+    #define SIZEOF_new_firmware (((FLASHEND)+1)-(BOOTLOADER_ADDRESS))
+  #else
+    #error unable to determine binary size of firmware
+  #endif
+#endif
+
+
+extern const const uint16_t usbasploader[SIZEOF_new_firmware>>1] PROGMEM;
+const uint8_t *new_firmware    =       (void*)&usbasploader;
+
+#endif
+