Root/atusb/fw/Makefile

Source at commit 8c574484b889c7b17d2ba4b6929947050f87d91e created 6 years 6 months ago.
By Josef Filzmaier, atusb/fw: Introduce DEBUG flag
1#
2# Makefile - Makefile of the ATUSB firmware
3#
4# Written 2010-2011, 2013 by Werner Almesberger
5# Copyright 2010-2011, 2013 by Werner Almesberger
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12
13SHELL = /bin/bash
14
15NAME = atusb
16DEBUG = false
17
18CFLAGS = -g -mmcu=$(CHIP) -DBOOT_ADDR=$(BOOT_ADDR) \
19     -Wall -Wextra -Wshadow -Werror -Wno-unused-parameter \
20     -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes
21
22ifeq ($(DEBUG),true)
23CFLAGS += -DDEBUG
24endif
25
26ifeq ($(NAME),rzusb)
27CHIP=at90usb1287
28CFLAGS += -DRZUSB -DAT86RF230
29else
30CHIP=atmega32u2
31CFLAGS += -DATUSB -DAT86RF231
32endif
33HOST=jlime
34BOOT_ADDR=0x7000
35
36AVR_PREFIX = $(BIN_PATH) avr-
37CC = $(AVR_PREFIX)gcc
38OBJCOPY = $(AVR_PREFIX)objcopy
39#OBJDUMP = $(AVR_PREFIX)objdump
40SIZE = $(AVR_PREFIX)size
41
42# BCD notion is 0xJJMM with JJ being major and MM being minor. Thus 0x0020 is
43# version 0.2 */
44USB_BCD_VERSION = 0030
45USB_VENDOR_ID = 20b7
46USB_PRODUCT_ID = 1540
47USB_ID = $(USB_VENDOR_ID):$(USB_PRODUCT_ID)
48
49OBJS = atusb.o board.o board_app.o sernum.o spi.o descr.o ep0.o \
50       dfu_common.o usb.o app-atu2.o mac.o
51BOOT_OBJS = boot.o board.o sernum.o spi.o flash.o dfu.o \
52            dfu_common.o usb.o boot-atu2.o
53
54ifeq ($(DEBUG),true)
55OBJS += uart.o
56endif
57
58ifeq ($(NAME),rzusb)
59OBJS += board_rzusb.o
60BOOT_OBJS += board_rzusb.o
61else
62OBJS += board_atusb.o
63BOOT_OBJS += board_atusb.o
64endif
65
66
67vpath %.c usb/
68
69CFLAGS += -Iinclude -Iusb -I.
70
71# ----- Verbosity control -----------------------------------------------------
72
73CC_normal := $(CC)
74BUILD_normal :=
75DEPEND_normal := $(CPP) $(CFLAGS) -MM -MG
76
77CC_quiet = @echo " CC " $@ && $(CC_normal)
78BUILD_quiet = @echo " BUILD " $@ && $(BUILD_normal)
79DEPEND_quiet = @$(DEPEND_normal)
80
81ifeq ($(V),1)
82    CC = $(CC_normal)
83    BUILD = $(BUILD_normal)
84    DEPEND = $(DEPEND_normal)
85else
86    CC = $(CC_quiet)
87    BUILD = $(BUILD_quiet)
88    DEPEND = $(DEPEND_quiet)
89endif
90
91# ----- Rules -----------------------------------------------------------------
92
93.PHONY: all clean upload prog dfu update version.c bindist
94.PHONY: prog-app prog-read on off reset
95
96all: $(NAME).bin boot.hex
97
98$(NAME).elf: $(OBJS)
99        $(MAKE) version.o
100        $(CC) $(CFLAGS) -o $@ $(OBJS) version.o
101        $(SIZE) $@
102
103boot.elf: $(BOOT_OBJS)
104        $(CC) $(CFLAGS) -o $@ $(BOOT_OBJS) \
105          -Wl,--section-start=.text=$(BOOT_ADDR)
106        $(SIZE) $@
107
108%.bin: %.elf
109        $(BUILD) $(OBJCOPY) -j .text -j .data -O binary $< $@
110        @echo "build #`cat .version`, `ls -l $@`"
111
112%.dfu: %.bin
113        cp $(NAME).bin $(NAME).dfu
114        dfu-suffix -a $(NAME).dfu -d 0x$(USB_BCD_VERSION) \
115          -p 0x$(USB_PRODUCT_ID) -v 0x$(USB_VENDOR_ID)
116
117%.hex: %.elf
118        $(BUILD) $(OBJCOPY) -j .text -j .data -O ihex $< $@
119        @echo "Size: `$(SIZE) -A boot.hex | sed '/Total */s///p;d'` B"
120
121# ----- Cleanup ---------------------------------------------------------------
122
123clean:
124        rm -f $(NAME).bin $(NAME).elf $(NAME).dfu
125        rm -f $(OBJS) $(OBJS:.o=.d)
126        rm -f boot.hex boot.elf
127        rm -f $(BOOT_OBJS) $(BOOT_OBJS:.o=.d)
128        rm -f version.c version.d version.o
129
130# ----- Build version ---------------------------------------------------------
131
132version.c:
133        @if [ -f .version ]; then \
134            v=`cat .version`; \
135            expr $$v + 1 >.version; \
136        else \
137            echo 0 >.version; \
138        fi
139        @[ -s .version ] || echo 0 >.version
140        @echo '/* MACHINE-GENERATED. DO NOT EDIT ! */' >version.c
141        @echo '#include "version.h"' >>version.c
142        @echo "const char *build_date = \"`date`\";" >>version.c
143        @echo "const uint16_t build_number = `cat .version`;" \
144          >>version.c
145
146# ----- Dependencies ----------------------------------------------------------
147
148MKDEP = \
149    $(DEPEND) $< | \
150      sed \
151        -e 's|^$(basename $(notdir $<)).o:|$@:|' \
152        -e '/^\(.*:\)\? */{p;s///;s/ *\\\?$$/ /;s/ */:\n/g;H;}' \
153        -e '$${g;p;}' \
154        -e d >$(basename $@).d; \
155      [ "$${PIPESTATUS[*]}" = "0 0" ] || \
156      { rm -f $(basename $@).d; exit 1; }
157
158%.o: %.c
159        $(CC) $(CFLAGS) -Os -c $<
160        $(MKDEP)
161
162-include $(OBJS:.o=.d)
163
164# ----- Object file variants --------------------------------------------------
165
166app-%.o: usb/%.c
167        $(CC) $(CFLAGS) -Os -o $@ -c $<
168        $(MKDEP)
169
170boot-%.o: usb/%.c
171        $(CC) $(CFLAGS) -DBOOT_LOADER -Os -o $@ -c $<
172        $(MKDEP)
173
174# ----- Distribution ----------------------------------------------------------
175
176BINDIST_BASE=http://downloads.qi-hardware.com/people/werner/wpan/bindist
177ATUSB_BIN_NAME=atusb-`git rev-parse HEAD | cut -c 1-7`.bin
178
179bindist:
180        qippl atusb.bin wpan/bindist/$(ATUSB_BIN_NAME)
181        @echo $(BINDIST_BASE)/$(ATUSB_BIN_NAME)
182        @echo md5sum: `md5sum atusb.bin | sed 's/ .*//'`
183        @echo atrf-id: \
184          `sed '/.*number = \(.*\);/s//#\1/p;d' version.c` \
185          `sed '/.*date = "\(.*\)";/s//\1/p;d' version.c`
186
187# ----- Programming and device control ----------------------------------------
188
189upload: $(NAME).bin boot.hex
190        scp $(NAME).bin boot.hex $(HOST):
191
192# lfuse: external clock, slow start-up
193# hfuse: 4 kB boot loader, reset into boot loader
194# lock: allow everything but SPM to the boot loader
195# Note: when trying to program 0xef, we get back 0x2f, failing
196# verification. So we just program 0x2f.
197
198prog-app:
199        ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb -e \
200          -U flash:w:atusb.bin:r \
201          -U lfuse:w:0x60:m
202
203prog:
204        ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb -e \
205          -U flash:w:boot.hex:i \
206          -U lfuse:w:0x60:m \
207          -U hfuse:w:0xd8:m \
208          -U lock:w:0x2f:m
209
210prog-read:
211        ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb \
212          -U flash:r:mcu.bin:r
213
214dfu: $(NAME).dfu
215        dfu-util -d $(USB_ID) -D $(NAME).dfu
216
217update: $(NAME).bin
218        -atrf-reset -a
219        usbwait -r -i 0.01 -t 5 $(USB_ID)
220        $(MAKE) dfu
221
222on:
223        ssh $(HOST) poke 0x10010318 4
224
225off:
226        ssh $(HOST) poke 0x10010314 4
227
228reset:
229        ssh $(HOST) poke 0x10010318 2048
230        ssh $(HOST) poke 0x10010314 2048
231

Archive Download this file



interactive