Root/tornado/fw/Makefile

1#
2# Makefile - Makefile of the Tornado firmware
3#
4# Written 2012 by Werner Almesberger
5# Copyright 2012 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 = tornado
16
17CFLAGS = -g -mmcu=$(CHIP) \
18     -DBOOT_ADDR=$(BOOT_ADDR) \
19     -Wall -Wextra -Wshadow -Wno-unused-parameter \
20     -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes \
21     -Iavr
22# -Wall -Wextra -Wshadow -Werror -Wno-unused-parameter \
23
24CHIP = atmega168
25HOST = jlime
26BOOT_ADDR = 0x3800
27
28AVR_PREFIX = $(BIN_PATH) avr-
29CC = $(AVR_PREFIX)gcc
30OBJCOPY = $(AVR_PREFIX)objcopy
31#OBJDUMP = $(AVR_PREFIX)objdump
32SIZE = $(AVR_PREFIX)size
33
34OBJS = $(NAME).o accel.o led.o mmc.o mmc-hw.o $(COMMON_OBJS)
35BOOT_OBJS = boot.o $(COMMON_OBJS)
36COMMON_OBJS =
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 nosecrets upload prog version.c
61.PHONY: prog-app prog-read
62
63all: $(NAME).bin boot.bin
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
81tornado.o: img.inc
82
83img.inc: txt/t
84        (cd txt; ./t) >$@ || { rm -f $@; exit 1; }
85
86# ----- Cleanup ---------------------------------------------------------------
87
88clean:
89        rm -f $(NAME).bin $(NAME).elf
90        rm -f $(OBJS) $(OBJS:.o=.d)
91        rm -f boot.hex boot.elf
92        rm -f $(BOOT_OBJS) $(BOOT_OBJS:.o=.d)
93        rm -f version.c version.d version.o
94        rm -f img.inc
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# ----- Programming and device control ----------------------------------------
131
132upload: $(NAME).bin boot.hex
133        scp $(NAME).bin boot.hex ../../common/avrdude-antorcha.conf \
134          $(HOST):
135
136# lfuse: external clock, slow start-up
137# hfuse: 4 kB boot loader, reset into boot loader
138# lock: allow everything but SPM to the boot loader
139# Note: when trying to program 0xef, we get back 0x2f, failing
140# verification. So we just program 0x2f.
141
142prog-app:
143        ssh $(HOST) avrdude -F -p $(CHIP) \
144          -L avrdude-antorcha.conf -c nanonote_antorcha -e \
145          -U flash:w:$(NAME).bin:r \
146          -U efuse:w:0x01:m \
147          -U lfuse:w:0xe2:m
148
149prog:
150        ssh $(HOST) avrdude -F -p $(CHIP) \
151          -L avrdude-antorcha.conf -c nanonote_antorcha -e \
152          -U flash:w:boot.hex:i \
153          -U efuse:w:0x00:m \
154          -U lfuse:w:0xe2:m
155# -U lfuse:w:0x60:m \
156# -U hfuse:w:0xd8:m \
157# -U lock:w:0x2f:m
158
159prog-read:
160        ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_antorcha \
161          -U flash:r:mcu.bin:r
162

Archive Download this file

Branches:
master
tornado-v1



interactive