Root/atusb/fw/Makefile

Source at commit 1dcc83391e51890c76fc8e11aeb24300a99412a2 created 8 years 6 months ago.
By Werner Almesberger, atusb/fw/Makefile: put -mmcu into CFLAGS so that DEPEND uses it, too
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) \
18     -Wall -Wextra -Wshadow -Werror -Wno-unused-parameter \
19     -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes
20
21CHIP=atmega32u2
22HOST=jlime
23
24AVR_PREFIX = $(BIN_PATH) avr-
25CC = $(AVR_PREFIX)gcc
26OBJCOPY = $(AVR_PREFIX)objcopy
27#OBJDUMP = $(AVR_PREFIX)objdump
28SIZE = $(AVR_PREFIX)size
29
30USB_OBJS = usb.o atu2.o
31OBJS = atusb.o board.o spi.o descr.o ep0.o $(USB_OBJS)
32BOOT_OBJS = boot.o board.o spi.o flash.o dfu.o $(USB_OBJS)
33
34vpath %.c usb/
35
36CFLAGS += -Iinclude -Iusb
37
38# ----- Verbosity control -----------------------------------------------------
39
40CC_normal := $(CC)
41BUILD_normal :=
42DEPEND_normal := $(CPP) $(CFLAGS) -MM -MG
43
44CC_quiet = @echo " CC " $@ && $(CC_normal)
45BUILD_quiet = @echo " BUILD " $@ && $(BUILD_normal)
46DEPEND_quiet = @$(DEPEND_normal)
47
48ifeq ($(V),1)
49    CC = $(CC_normal)
50    BUILD = $(BUILD_normal)
51    DEPEND = $(DEPEND_normal)
52else
53    CC = $(CC_quiet)
54    BUILD = $(BUILD_quiet)
55    DEPEND = $(DEPEND_quiet)
56endif
57
58# ----- Rules -----------------------------------------------------------------
59
60.PHONY: all clean upload prog version.c
61
62all: $(NAME).bin boot.hex
63
64$(NAME).elf: $(OBJS)
65        $(MAKE) version.o
66        $(CC) $(CFLAGS) -o $@ $(OBJS) version.o
67
68boot.elf: $(BOOT_OBJS)
69        $(CC) $(CFLAGS) -o $@ $(BOOT_OBJS) \
70          -Wl,--section-start=.text=0x7000
71
72%.bin: %.elf
73        $(BUILD) $(OBJCOPY) -j .text -j .data -O binary $< $@
74        @echo "build #`cat .version`, `ls -l $@`"
75
76%.hex: %.elf
77        $(BUILD) $(OBJCOPY) -j .text -j .data -O ihex $< $@
78        $(SIZE) $@
79
80# ----- Cleanup ---------------------------------------------------------------
81
82clean:
83        rm -f $(NAME).bin $(NAME).elf
84        rm -f $(OBJS) $(OBJS:.o=.d)
85        rm -f boot.hex boot.elf
86        rm -f $(BOOT_OBJS) $(BOOT_OBJS:.o=.d)
87        rm -f version.c version.d version.o
88
89# ----- Build version ---------------------------------------------------------
90
91version.c:
92        @if [ -f .version ]; then \
93            v=`cat .version`; \
94            expr $$v + 1 >.version; \
95        else \
96            echo 0 >.version; \
97        fi
98        @[ -s .version ] || echo 0 >.version
99        @echo '/* MACHINE-GENERATED. DO NOT EDIT ! */' >version.c
100        @echo '#include "version.h"' >>version.c
101        @echo "const char *build_date = \"`date`\";" >>version.c
102        @echo "const uint16_t build_number = `cat .version`;" \
103          >>version.c
104
105# ----- Dependencies ----------------------------------------------------------
106
107%.o: %.c
108        $(CC) $(CFLAGS) -Os -c $<
109        $(DEPEND) $< | \
110          sed -e \
111            '/^\(.*:\)\? */{p;s///;s/ *\\\?$$/ /;s/ */:\n/g;H;}' \
112            -e '$${g;p;}' -e d >$*.d; \
113          [ "$${PIPESTATUS[*]}" = "0 0" ] || { rm -f $*.d; exit 1; }
114
115-include $(OBJS:.o=.d)
116
117# ----- Programming and device control ----------------------------------------
118
119upload: $(NAME).bin boot.hex
120        scp $(NAME).bin boot.hex $(HOST):
121
122# lfuse: external clock, slow start-up
123# hfuse: 4 kB boot loader, reset into boot loader
124# lock: allow everything but SPM to the boot loader
125
126prog:
127        ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb -e \
128          -U flash:w:boot.hex:i \
129          -U lfuse:w:0x60:m \
130          -U hfuse:w:0xde:m \
131          -U lock:w:0xef:m
132
133# -U flash:w:$(NAME).bin:r \
134
135on:
136        ssh $(HOST) poke 0x10010318 4
137
138off:
139        ssh $(HOST) poke 0x10010314 4
140
141reset:
142        ssh $(HOST) poke 0x10010318 2048
143        ssh $(HOST) poke 0x10010314 2048
144

Archive Download this file



interactive