Root/atusb/fw/Makefile

Source at commit fd91546c590942729fc6c74260fe9b2c3fff4f60 created 12 years 10 months ago.
By Werner Almesberger, atusb/fw/Makefile (dfu): our functional descriptor is fine, no need for -t
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_OBJS = usb.o atu2.o
32OBJS = atusb.o board.o spi.o descr.o ep0.o $(USB_OBJS)
33BOOT_OBJS = boot.o board.o spi.o flash.o dfu.o $(USB_OBJS)
34
35vpath %.c usb/
36
37CFLAGS += -Iinclude -Iusb
38
39# ----- Verbosity control -----------------------------------------------------
40
41CC_normal := $(CC)
42BUILD_normal :=
43DEPEND_normal := $(CPP) $(CFLAGS) -MM -MG
44
45CC_quiet = @echo " CC " $@ && $(CC_normal)
46BUILD_quiet = @echo " BUILD " $@ && $(BUILD_normal)
47DEPEND_quiet = @$(DEPEND_normal)
48
49ifeq ($(V),1)
50    CC = $(CC_normal)
51    BUILD = $(BUILD_normal)
52    DEPEND = $(DEPEND_normal)
53else
54    CC = $(CC_quiet)
55    BUILD = $(BUILD_quiet)
56    DEPEND = $(DEPEND_quiet)
57endif
58
59# ----- Rules -----------------------------------------------------------------
60
61.PHONY: all clean upload prog dfu version.c
62.PHONY: prog-app prog-read on off reset
63
64all: $(NAME).bin boot.hex
65
66$(NAME).elf: $(OBJS)
67        $(MAKE) version.o
68        $(CC) $(CFLAGS) -o $@ $(OBJS) version.o
69
70boot.elf: $(BOOT_OBJS)
71        $(CC) $(CFLAGS) -o $@ $(BOOT_OBJS) \
72          -Wl,--section-start=.text=$(BOOT_ADDR)
73
74%.bin: %.elf
75        $(BUILD) $(OBJCOPY) -j .text -j .data -O binary $< $@
76        @echo "build #`cat .version`, `ls -l $@`"
77
78%.hex: %.elf
79        $(BUILD) $(OBJCOPY) -j .text -j .data -O ihex $< $@
80        $(SIZE) $@
81
82# ----- Cleanup ---------------------------------------------------------------
83
84clean:
85        rm -f $(NAME).bin $(NAME).elf
86        rm -f $(OBJS) $(OBJS:.o=.d)
87        rm -f boot.hex boot.elf
88        rm -f $(BOOT_OBJS) $(BOOT_OBJS:.o=.d)
89        rm -f version.c version.d version.o
90
91# ----- Build version ---------------------------------------------------------
92
93version.c:
94        @if [ -f .version ]; then \
95            v=`cat .version`; \
96            expr $$v + 1 >.version; \
97        else \
98            echo 0 >.version; \
99        fi
100        @[ -s .version ] || echo 0 >.version
101        @echo '/* MACHINE-GENERATED. DO NOT EDIT ! */' >version.c
102        @echo '#include "version.h"' >>version.c
103        @echo "const char *build_date = \"`date`\";" >>version.c
104        @echo "const uint16_t build_number = `cat .version`;" \
105          >>version.c
106
107# ----- Dependencies ----------------------------------------------------------
108
109%.o: %.c
110        $(CC) $(CFLAGS) -Os -c $<
111        $(DEPEND) $< | \
112          sed -e \
113            '/^\(.*:\)\? */{p;s///;s/ *\\\?$$/ /;s/ */:\n/g;H;}' \
114            -e '$${g;p;}' -e d >$*.d; \
115          [ "$${PIPESTATUS[*]}" = "0 0" ] || { rm -f $*.d; exit 1; }
116
117-include $(OBJS:.o=.d)
118
119# ----- Programming and device control ----------------------------------------
120
121upload: $(NAME).bin boot.hex
122        scp $(NAME).bin boot.hex $(HOST):
123
124# lfuse: external clock, slow start-up
125# hfuse: 4 kB boot loader, reset into boot loader
126# lock: allow everything but SPM to the boot loader
127# Note: when trying to program 0xef, we get back 0x2f, failing
128# verification. So we just program 0x2f.
129
130prog-app:
131        ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb -e \
132          -U flash:w:atusb.bin:r \
133          -U lfuse:w:0x60:m
134
135prog:
136        ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb -e \
137          -U flash:w:boot.hex:i \
138          -U lfuse:w:0x60:m \
139          -U hfuse:w:0xd8:m \
140          -U lock:w:0x2f:m
141
142prog-read:
143        ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb \
144          -U flash:r:mcu.bin:r
145
146dfu: $(NAME).bin
147        dfu-util -d 20b7:1540 -D $(NAME).bin
148
149on:
150        ssh $(HOST) poke 0x10010318 4
151
152off:
153        ssh $(HOST) poke 0x10010314 4
154
155reset:
156        ssh $(HOST) poke 0x10010318 2048
157        ssh $(HOST) poke 0x10010314 2048
158

Archive Download this file



interactive