Root/atusb/fw/Makefile

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

Archive Download this file



interactive