Root/atusb/fw/Makefile

Source at commit f87bdce41f2b24efa3de561ecaa1ff2fcbe78906 created 8 years 7 months ago.
By Werner Almesberger, atusb/fw/Makefile: added auxiliary Flash programming target (for development)
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 version.c
62
63all: $(NAME).bin boot.hex
64
65$(NAME).elf: $(OBJS)
66        $(MAKE) version.o
67        $(CC) $(CFLAGS) -o $@ $(OBJS) version.o
68
69boot.elf: $(BOOT_OBJS)
70        $(CC) $(CFLAGS) -o $@ $(BOOT_OBJS) \
71          -Wl,--section-start=.text=$(BOOT_ADDR)
72
73%.bin: %.elf
74        $(BUILD) $(OBJCOPY) -j .text -j .data -O binary $< $@
75        @echo "build #`cat .version`, `ls -l $@`"
76
77%.hex: %.elf
78        $(BUILD) $(OBJCOPY) -j .text -j .data -O ihex $< $@
79        $(SIZE) $@
80
81# ----- Cleanup ---------------------------------------------------------------
82
83clean:
84        rm -f $(NAME).bin $(NAME).elf
85        rm -f $(OBJS) $(OBJS:.o=.d)
86        rm -f boot.hex boot.elf
87        rm -f $(BOOT_OBJS) $(BOOT_OBJS:.o=.d)
88        rm -f version.c version.d version.o
89
90# ----- Build version ---------------------------------------------------------
91
92version.c:
93        @if [ -f .version ]; then \
94            v=`cat .version`; \
95            expr $$v + 1 >.version; \
96        else \
97            echo 0 >.version; \
98        fi
99        @[ -s .version ] || echo 0 >.version
100        @echo '/* MACHINE-GENERATED. DO NOT EDIT ! */' >version.c
101        @echo '#include "version.h"' >>version.c
102        @echo "const char *build_date = \"`date`\";" >>version.c
103        @echo "const uint16_t build_number = `cat .version`;" \
104          >>version.c
105
106# ----- Dependencies ----------------------------------------------------------
107
108%.o: %.c
109        $(CC) $(CFLAGS) -Os -c $<
110        $(DEPEND) $< | \
111          sed -e \
112            '/^\(.*:\)\? */{p;s///;s/ *\\\?$$/ /;s/ */:\n/g;H;}' \
113            -e '$${g;p;}' -e d >$*.d; \
114          [ "$${PIPESTATUS[*]}" = "0 0" ] || { rm -f $*.d; exit 1; }
115
116-include $(OBJS:.o=.d)
117
118# ----- Programming and device control ----------------------------------------
119
120upload: $(NAME).bin boot.hex
121        scp $(NAME).bin boot.hex $(HOST):
122
123# lfuse: external clock, slow start-up
124# hfuse: 4 kB boot loader, reset into boot loader
125# lock: allow everything but SPM to the boot loader
126# Note: when trying to program 0xef, we get back 0x2f, failing
127# verification. So we just program 0x2f.
128
129prog-app:
130        ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb -e \
131          -U flash:w:atusb.bin:r \
132          -U lfuse:w:0x60:m
133
134prog:
135        ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb -e \
136          -U flash:w:boot.hex:i \
137          -U lfuse:w:0x60:m \
138          -U hfuse:w:0xd8:m \
139          -U lock:w:0x2f:m
140
141prog-read:
142        ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb \
143          -U flash:r:mcu.bin:r
144
145on:
146        ssh $(HOST) poke 0x10010318 4
147
148off:
149        ssh $(HOST) poke 0x10010314 4
150
151reset:
152        ssh $(HOST) poke 0x10010318 2048
153        ssh $(HOST) poke 0x10010314 2048
154

Archive Download this file



interactive