Root/atusb/fw/Makefile

Source at commit c5f9cc125907a638304fc6d872e4f6af5e4baf82 created 10 years 4 months ago.
By Werner Almesberger, atusb/fw/: let include path find board.h instead of using ../board.h
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
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 mac.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 -I.
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        $(SIZE) $@
73
74boot.elf: $(BOOT_OBJS)
75        $(CC) $(CFLAGS) -o $@ $(BOOT_OBJS) \
76          -Wl,--section-start=.text=$(BOOT_ADDR)
77        $(SIZE) $@
78
79%.bin: %.elf
80        $(BUILD) $(OBJCOPY) -j .text -j .data -O binary $< $@
81        @echo "build #`cat .version`, `ls -l $@`"
82
83%.hex: %.elf
84        $(BUILD) $(OBJCOPY) -j .text -j .data -O ihex $< $@
85        @echo "Size: `$(SIZE) -A boot.hex | sed '/Total */s///p;d'` B"
86
87# ----- Cleanup ---------------------------------------------------------------
88
89clean:
90        rm -f $(NAME).bin $(NAME).elf
91        rm -f $(OBJS) $(OBJS:.o=.d)
92        rm -f boot.hex boot.elf
93        rm -f $(BOOT_OBJS) $(BOOT_OBJS:.o=.d)
94        rm -f version.c version.d version.o
95
96# ----- Build version ---------------------------------------------------------
97
98version.c:
99        @if [ -f .version ]; then \
100            v=`cat .version`; \
101            expr $$v + 1 >.version; \
102        else \
103            echo 0 >.version; \
104        fi
105        @[ -s .version ] || echo 0 >.version
106        @echo '/* MACHINE-GENERATED. DO NOT EDIT ! */' >version.c
107        @echo '#include "version.h"' >>version.c
108        @echo "const char *build_date = \"`date`\";" >>version.c
109        @echo "const uint16_t build_number = `cat .version`;" \
110          >>version.c
111
112# ----- Dependencies ----------------------------------------------------------
113
114MKDEP = \
115    $(DEPEND) $< | \
116      sed \
117        -e 's|^$(basename $(notdir $<)).o:|$@:|' \
118        -e '/^\(.*:\)\? */{p;s///;s/ *\\\?$$/ /;s/ */:\n/g;H;}' \
119        -e '$${g;p;}' \
120        -e d >$(basename $@).d; \
121      [ "$${PIPESTATUS[*]}" = "0 0" ] || \
122      { rm -f $(basename $@).d; exit 1; }
123
124%.o: %.c
125        $(CC) $(CFLAGS) -Os -c $<
126        $(MKDEP)
127
128-include $(OBJS:.o=.d)
129
130# ----- Object file variants --------------------------------------------------
131
132app-%.o: usb/%.c
133        $(CC) $(CFLAGS) -Os -o $@ -c $<
134        $(MKDEP)
135
136boot-%.o: usb/%.c
137        $(CC) $(CFLAGS) -DBOOT_LOADER -Os -o $@ -c $<
138        $(MKDEP)
139
140# ----- Distribution ----------------------------------------------------------
141
142BINDIST_BASE=http://downloads.qi-hardware.com/people/werner/wpan/bindist
143ATUSB_BIN_NAME=atusb-`git rev-parse HEAD | cut -c 1-7`.bin
144
145bindist:
146        qippl atusb.bin wpan/bindist/$(ATUSB_BIN_NAME)
147        @echo $(BINDIST_BASE)/$(ATUSB_BIN_NAME)
148        @echo md5sum: `md5sum atusb.bin | sed 's/ .*//'`
149        @echo atrf-id: \
150          `sed '/.*number = \(.*\);/s//#\1/p;d' version.c` \
151          `sed '/.*date = "\(.*\)";/s//\1/p;d' version.c`
152
153# ----- Programming and device control ----------------------------------------
154
155upload: $(NAME).bin boot.hex
156        scp $(NAME).bin boot.hex $(HOST):
157
158# lfuse: external clock, slow start-up
159# hfuse: 4 kB boot loader, reset into boot loader
160# lock: allow everything but SPM to the boot loader
161# Note: when trying to program 0xef, we get back 0x2f, failing
162# verification. So we just program 0x2f.
163
164prog-app:
165        ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb -e \
166          -U flash:w:atusb.bin:r \
167          -U lfuse:w:0x60:m
168
169prog:
170        ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb -e \
171          -U flash:w:boot.hex:i \
172          -U lfuse:w:0x60:m \
173          -U hfuse:w:0xd8:m \
174          -U lock:w:0x2f:m
175
176prog-read:
177        ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb \
178          -U flash:r:mcu.bin:r
179
180dfu: $(NAME).bin
181        dfu-util -d $(USB_ID) -D $(NAME).bin
182
183update: $(NAME).bin
184        -atrf-reset -a
185        usbwait -r -i 0.01 -t 5 $(USB_ID)
186        $(MAKE) dfu
187
188on:
189        ssh $(HOST) poke 0x10010318 4
190
191off:
192        ssh $(HOST) poke 0x10010314 4
193
194reset:
195        ssh $(HOST) poke 0x10010318 2048
196        ssh $(HOST) poke 0x10010314 2048
197

Archive Download this file



interactive