2012-11-17 00:22:23 +02:00
|
|
|
#
|
2012-11-19 17:30:57 +02:00
|
|
|
# Makefile - Makefile of the Tornado firmware
|
2012-11-17 00:22:23 +02:00
|
|
|
#
|
|
|
|
# Written 2012 by Werner Almesberger
|
|
|
|
# Copyright 2012 by Werner Almesberger
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
|
|
|
|
SHELL = /bin/bash
|
|
|
|
|
2012-11-19 17:30:57 +02:00
|
|
|
NAME = tornado
|
2012-11-17 00:22:23 +02:00
|
|
|
|
|
|
|
CFLAGS = -g -mmcu=$(CHIP) \
|
|
|
|
-DBOOT_ADDR=$(BOOT_ADDR) \
|
2012-11-17 20:39:18 +02:00
|
|
|
-Wall -Wextra -Wshadow -Wno-unused-parameter \
|
2012-11-17 00:22:23 +02:00
|
|
|
-Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes \
|
|
|
|
-I../../ben-wpan/atusb/fw/include/
|
2012-11-17 20:39:18 +02:00
|
|
|
# -Wall -Wextra -Wshadow -Werror -Wno-unused-parameter \
|
2012-11-17 00:22:23 +02:00
|
|
|
|
|
|
|
CHIP = atmega168
|
|
|
|
HOST = jlime
|
|
|
|
BOOT_ADDR = 0x3800
|
|
|
|
|
|
|
|
AVR_PREFIX = $(BIN_PATH) avr-
|
|
|
|
CC = $(AVR_PREFIX)gcc
|
|
|
|
OBJCOPY = $(AVR_PREFIX)objcopy
|
|
|
|
#OBJDUMP = $(AVR_PREFIX)objdump
|
|
|
|
SIZE = $(AVR_PREFIX)size
|
|
|
|
|
2012-12-04 15:52:15 +02:00
|
|
|
OBJS = $(NAME).o accel.o led.o mmc.o mmc-hw.o $(COMMON_OBJS)
|
2012-11-17 00:22:23 +02:00
|
|
|
BOOT_OBJS = boot.o $(COMMON_OBJS)
|
|
|
|
COMMON_OBJS =
|
|
|
|
|
|
|
|
# ----- Verbosity control -----------------------------------------------------
|
|
|
|
|
|
|
|
CC_normal := $(CC)
|
|
|
|
BUILD_normal :=
|
|
|
|
DEPEND_normal := $(CPP) $(CFLAGS) -MM -MG
|
|
|
|
|
|
|
|
CC_quiet = @echo " CC " $@ && $(CC_normal)
|
|
|
|
BUILD_quiet = @echo " BUILD " $@ && $(BUILD_normal)
|
|
|
|
DEPEND_quiet = @$(DEPEND_normal)
|
|
|
|
|
|
|
|
ifeq ($(V),1)
|
|
|
|
CC = $(CC_normal)
|
|
|
|
BUILD = $(BUILD_normal)
|
|
|
|
DEPEND = $(DEPEND_normal)
|
|
|
|
else
|
|
|
|
CC = $(CC_quiet)
|
|
|
|
BUILD = $(BUILD_quiet)
|
|
|
|
DEPEND = $(DEPEND_quiet)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# ----- Rules -----------------------------------------------------------------
|
|
|
|
|
|
|
|
.PHONY: all clean nosecrets upload prog version.c
|
|
|
|
.PHONY: prog-app prog-read
|
|
|
|
|
|
|
|
all: $(NAME).bin boot.bin
|
|
|
|
|
|
|
|
$(NAME).elf: $(OBJS)
|
|
|
|
$(MAKE) version.o
|
|
|
|
$(CC) $(CFLAGS) -o $@ $(OBJS) version.o
|
|
|
|
|
|
|
|
boot.elf: $(BOOT_OBJS)
|
|
|
|
$(CC) $(CFLAGS) -o $@ $(BOOT_OBJS) \
|
|
|
|
-Wl,--section-start=.text=$(BOOT_ADDR)
|
|
|
|
|
|
|
|
%.bin: %.elf
|
|
|
|
$(BUILD) $(OBJCOPY) -j .text -j .data -O binary $< $@
|
|
|
|
@echo "build #`cat .version`, `ls -l $@`"
|
|
|
|
|
|
|
|
%.hex: %.elf
|
|
|
|
$(BUILD) $(OBJCOPY) -j .text -j .data -O ihex $< $@
|
|
|
|
$(SIZE) $@
|
|
|
|
|
2012-12-04 12:28:55 +02:00
|
|
|
tornado.o: img.inc
|
|
|
|
|
|
|
|
img.inc: txt/t
|
|
|
|
(cd txt; ./t) >$@ || { rm -f $@; exit 1; }
|
|
|
|
|
2012-11-17 00:22:23 +02:00
|
|
|
# ----- Cleanup ---------------------------------------------------------------
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -f $(NAME).bin $(NAME).elf
|
|
|
|
rm -f $(OBJS) $(OBJS:.o=.d)
|
|
|
|
rm -f boot.hex boot.elf
|
|
|
|
rm -f $(BOOT_OBJS) $(BOOT_OBJS:.o=.d)
|
|
|
|
rm -f version.c version.d version.o
|
2012-12-04 12:28:55 +02:00
|
|
|
rm -f img.inc
|
2012-11-17 00:22:23 +02:00
|
|
|
|
|
|
|
# ----- Build version ---------------------------------------------------------
|
|
|
|
|
|
|
|
version.c:
|
|
|
|
@if [ -f .version ]; then \
|
|
|
|
v=`cat .version`; \
|
|
|
|
expr $$v + 1 >.version; \
|
|
|
|
else \
|
|
|
|
echo 0 >.version; \
|
|
|
|
fi
|
|
|
|
@[ -s .version ] || echo 0 >.version
|
|
|
|
@echo '/* MACHINE-GENERATED. DO NOT EDIT ! */' >version.c
|
|
|
|
@echo '#include "version.h"' >>version.c
|
|
|
|
@echo "const char *build_date = \"`date`\";" >>version.c
|
|
|
|
@echo "const uint16_t build_number = `cat .version`;" \
|
|
|
|
>>version.c
|
|
|
|
|
|
|
|
# ----- Dependencies ----------------------------------------------------------
|
|
|
|
|
|
|
|
MKDEP = \
|
|
|
|
$(DEPEND) $< | \
|
|
|
|
sed \
|
|
|
|
-e 's|^$(basename $(notdir $<)).o:|$@:|' \
|
|
|
|
-e '/^\(.*:\)\? */{p;s///;s/ *\\\?$$/ /;s/ */:\n/g;H;}' \
|
|
|
|
-e '$${g;p;}' \
|
|
|
|
-e d >$(basename $@).d; \
|
|
|
|
[ "$${PIPESTATUS[*]}" = "0 0" ] || \
|
|
|
|
{ rm -f $(basename $@).d; exit 1; }
|
|
|
|
|
|
|
|
%.o: %.c
|
|
|
|
$(CC) $(CFLAGS) -Os -c $<
|
|
|
|
$(MKDEP)
|
|
|
|
|
|
|
|
-include $(OBJS:.o=.d)
|
|
|
|
|
|
|
|
# ----- Programming and device control ----------------------------------------
|
|
|
|
|
|
|
|
upload: $(NAME).bin boot.hex
|
2012-11-17 21:04:52 +02:00
|
|
|
scp $(NAME).bin boot.hex ../../common/avrdude-antorcha.conf \
|
|
|
|
$(HOST):
|
2012-11-17 00:22:23 +02:00
|
|
|
|
|
|
|
# lfuse: external clock, slow start-up
|
|
|
|
# hfuse: 4 kB boot loader, reset into boot loader
|
|
|
|
# lock: allow everything but SPM to the boot loader
|
|
|
|
# Note: when trying to program 0xef, we get back 0x2f, failing
|
|
|
|
# verification. So we just program 0x2f.
|
|
|
|
|
|
|
|
prog-app:
|
|
|
|
ssh $(HOST) avrdude -F -p $(CHIP) \
|
|
|
|
-L avrdude-antorcha.conf -c nanonote_antorcha -e \
|
2012-11-17 21:13:14 +02:00
|
|
|
-U flash:w:$(NAME).bin:r \
|
|
|
|
-U efuse:w:0x01:m \
|
|
|
|
-U lfuse:w:0xe2:m
|
2012-11-17 00:22:23 +02:00
|
|
|
|
|
|
|
prog:
|
|
|
|
ssh $(HOST) avrdude -F -p $(CHIP) \
|
|
|
|
-L avrdude-antorcha.conf -c nanonote_antorcha -e \
|
|
|
|
-U flash:w:boot.hex:i \
|
|
|
|
-U efuse:w:0x00:m \
|
|
|
|
-U lfuse:w:0xe2:m
|
|
|
|
# -U lfuse:w:0x60:m \
|
|
|
|
# -U hfuse:w:0xd8:m \
|
|
|
|
# -U lock:w:0x2f:m
|
|
|
|
|
|
|
|
prog-read:
|
|
|
|
ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_antorcha \
|
|
|
|
-U flash:r:mcu.bin:r
|