Root/atusb/fw/Makefile

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

Archive Download this file



interactive