Root/atusb/fw/Makefile

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

Archive Download this file



interactive