USBaspLoader v0.97 stable release
[pub/USBaspLoader.git] / updater / Makefile
1 # Name: Makefile
2 # Project: USBaspLoader (updater)
3 # Author: Stephan Bärwolf
4 # Creation Date: 2012-09-01
5 # Tabsize: 4
6 # License: GNU GPL v2 (see License.txt)
7
8 include ../Makefile.inc
9
10 # elsewise gcc would complain unnecessary
11 CFLAGS = -Wall -Wno-pointer-to-int-cast -Os -g3 -ggdb -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) -DFLASHADDRESS=$(FLASHADDRESS) $(DEFINES)
12 LDFLAGS = -Wl,--relax,--gc-sections
13
14 DEPENDS = ../firmware/bootloaderconfig.h ../Makefile.inc
15
16 ifneq ($(FLASHADDRESS), 0)
17 ifneq ($(FLASHADDRESS), 00)
18 ifneq ($(FLASHADDRESS), 000)
19 ifneq ($(FLASHADDRESS), 0000)
20 ifneq ($(FLASHADDRESS), 00000)
21 ifneq ($(FLASHADDRESS), 0x0)
22 ifneq ($(FLASHADDRESS), 0x00)
23 ifneq ($(FLASHADDRESS), 0x000)
24 ifneq ($(FLASHADDRESS), 0x0000)
25 ifneq ($(FLASHADDRESS), 0x00000)
26 FLASHPREAMBLE = 0x0000
27 LDFLAGS += -Wl,--section-start=.text=$(FLASHADDRESS)
28 endif
29 endif
30 endif
31 endif
32 endif
33 endif
34 endif
35 endif
36 endif
37 endif
38
39 all: updater.hex $(DEPENDS)
40
41 flash: all
42 $(ECHO) "."
43 $(AVRDUDE) -D -U flash:w:updater.hex:i
44 $(ECHO) "."
45 $(ECHO) "."
46
47
48 ../firmware/main.elf: $(DEPENDS)
49 $(MAKE) -C ../firmware main.hex
50
51
52 usbasploader.raw: ../firmware/main.elf $(DEPENDS)
53 $(OBC) -j .text -j .data -O binary ../firmware/main.elf usbasploader.raw
54
55 usbasploader.o: usbasploader.raw $(DEPENDS)
56 $(OBC) -B $(MCUARCH) -I binary -O elf32-avr --rename-section .data=.text --redefine-sym _binary_usbasploader_raw_start=usbasploader usbasploader.raw usbasploader.o
57
58
59 updater.o: updater.c usbasploader.h usbasploader.raw usbasploader.o $(DEPENDS)
60 ifndef UPDATECRC32
61 $(CC) updater.c -c -o updater.o -DSIZEOF_new_firmware=$(shell stat -c %s usbasploader.raw) $(CFLAGS)
62 else
63 ifeq ($(UPDATECRC32), 0)
64 $(CC) updater.c -c -o updater.o -DSIZEOF_new_firmware=$(shell stat -c %s usbasploader.raw) -DUPDATECRC32=0x$(shell crc32 usbasploader.raw) $(CFLAGS)
65 else
66 $(CC) updater.c -c -o updater.o -DSIZEOF_new_firmware=$(shell stat -c %s usbasploader.raw) -DUPDATECRC32=$(UPDATECRC32) $(CFLAGS)
67 endif
68 endif
69 # $(CC) updater.c -c -o updater.o $(CFLAGS)
70
71 updater.elf: updater.o usbasploader.o $(DEPENDS)
72 $(CC) updater.o usbasploader.o -o updater.elf -Wl,-Map,updater.map $(CFLAGS) $(LDFLAGS)
73
74 updater.asm: updater.elf $(DEPENDS)
75 $(OBD) -Stdr updater.elf > updater.asm
76
77 updater.hex: updater.elf updater.asm $(DEPENDS)
78 $(OBC) -j .text -j .data -O ihex updater.elf updater.hex
79 $(ECHO) "."
80 $(ECHO) "."
81 $(SIZ) updater.elf
82 $(ECHO) "."
83
84 deepclean: clean
85 $(RM) *~
86
87 clean:
88 $(RM) usbasploader.o
89 $(RM) updater.o
90 $(RM) usbasploader.raw
91 $(RM) updater.hex
92 $(RM) updater.asm
93 $(RM) updater.elf
94 $(RM) updater.map
95 $(RM) usbasploader.raw