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

Archive Download this file



interactive