2011-02-14 04:46:36 +02:00
|
|
|
#
|
|
|
|
# Makefile - Makefile of the ATUSB firmware
|
|
|
|
#
|
|
|
|
# Written 2010-2011 by Werner Almesberger
|
|
|
|
# Copyright 2010-2011 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
|
|
|
|
|
|
|
|
NAME = atusb
|
|
|
|
|
2011-03-11 21:21:39 +02:00
|
|
|
CFLAGS = -g -mmcu=$(CHIP) -DBOOT_ADDR=$(BOOT_ADDR) \
|
2011-03-09 06:45:35 +02:00
|
|
|
-Wall -Wextra -Wshadow -Werror -Wno-unused-parameter \
|
2011-02-14 04:46:36 +02:00
|
|
|
-Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes
|
|
|
|
|
|
|
|
CHIP=atmega32u2
|
2011-03-05 02:50:01 +02:00
|
|
|
HOST=jlime
|
2011-03-11 21:21:39 +02:00
|
|
|
BOOT_ADDR=0x7000
|
2011-02-14 04:46:36 +02:00
|
|
|
|
|
|
|
AVR_PREFIX = $(BIN_PATH) avr-
|
|
|
|
CC = $(AVR_PREFIX)gcc
|
|
|
|
OBJCOPY = $(AVR_PREFIX)objcopy
|
|
|
|
#OBJDUMP = $(AVR_PREFIX)objdump
|
2011-03-09 05:41:32 +02:00
|
|
|
SIZE = $(AVR_PREFIX)size
|
2011-02-14 04:46:36 +02:00
|
|
|
|
2011-05-11 11:29:54 +03:00
|
|
|
USB_ID = 20b7:1540
|
|
|
|
|
|
|
|
USB_OBJS = usb.o atu2.o
|
2011-06-11 05:26:36 +03:00
|
|
|
OBJS = atusb.o board.o board_app.o sernum.o spi.o descr.o ep0.o dfu_common.o \
|
|
|
|
$(USB_OBJS)
|
2011-06-11 04:04:12 +03:00
|
|
|
BOOT_OBJS = boot.o board.o sernum.o spi.o flash.o dfu.o dfu_common.o \
|
|
|
|
$(USB_OBJS)
|
2011-02-14 04:46:36 +02:00
|
|
|
|
2011-02-14 15:14:06 +02:00
|
|
|
vpath %.c usb/
|
2011-02-14 04:46:36 +02:00
|
|
|
|
2011-02-22 05:24:53 +02:00
|
|
|
CFLAGS += -Iinclude -Iusb
|
2011-02-14 04:46:36 +02:00
|
|
|
|
|
|
|
# ----- 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 -----------------------------------------------------------------
|
|
|
|
|
2011-05-11 11:29:54 +03:00
|
|
|
.PHONY: all clean upload prog dfu update version.c
|
2011-05-10 03:12:26 +03:00
|
|
|
.PHONY: prog-app prog-read on off reset
|
2011-02-14 04:46:36 +02:00
|
|
|
|
2011-03-09 05:41:32 +02:00
|
|
|
all: $(NAME).bin boot.hex
|
2011-02-14 04:46:36 +02:00
|
|
|
|
|
|
|
$(NAME).elf: $(OBJS)
|
2011-02-14 16:26:17 +02:00
|
|
|
$(MAKE) version.o
|
2011-03-09 06:45:35 +02:00
|
|
|
$(CC) $(CFLAGS) -o $@ $(OBJS) version.o
|
2011-02-14 04:46:36 +02:00
|
|
|
|
2011-03-09 05:41:32 +02:00
|
|
|
boot.elf: $(BOOT_OBJS)
|
2011-03-09 06:45:35 +02:00
|
|
|
$(CC) $(CFLAGS) -o $@ $(BOOT_OBJS) \
|
2011-03-11 21:21:39 +02:00
|
|
|
-Wl,--section-start=.text=$(BOOT_ADDR)
|
2011-03-09 05:41:32 +02:00
|
|
|
|
2011-02-14 04:46:36 +02:00
|
|
|
%.bin: %.elf
|
|
|
|
$(BUILD) $(OBJCOPY) -j .text -j .data -O binary $< $@
|
2011-02-14 16:26:17 +02:00
|
|
|
@echo "build #`cat .version`, `ls -l $@`"
|
2011-02-14 04:46:36 +02:00
|
|
|
|
2011-03-09 05:41:32 +02:00
|
|
|
%.hex: %.elf
|
|
|
|
$(BUILD) $(OBJCOPY) -j .text -j .data -O ihex $< $@
|
|
|
|
$(SIZE) $@
|
|
|
|
|
2011-02-14 04:46:36 +02:00
|
|
|
# ----- Cleanup ---------------------------------------------------------------
|
|
|
|
|
|
|
|
clean:
|
2011-03-09 05:41:32 +02:00
|
|
|
rm -f $(NAME).bin $(NAME).elf
|
|
|
|
rm -f $(OBJS) $(OBJS:.o=.d)
|
2011-03-09 05:57:01 +02:00
|
|
|
rm -f boot.hex boot.elf
|
2011-03-09 05:41:32 +02:00
|
|
|
rm -f $(BOOT_OBJS) $(BOOT_OBJS:.o=.d)
|
2011-02-14 16:26:17 +02:00
|
|
|
rm -f version.c version.d version.o
|
|
|
|
|
|
|
|
# ----- 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
|
2011-02-14 04:46:36 +02:00
|
|
|
|
|
|
|
# ----- Dependencies ----------------------------------------------------------
|
|
|
|
|
|
|
|
%.o: %.c
|
2011-03-09 06:45:35 +02:00
|
|
|
$(CC) $(CFLAGS) -Os -c $<
|
2011-02-14 04:46:36 +02:00
|
|
|
$(DEPEND) $< | \
|
|
|
|
sed -e \
|
|
|
|
'/^\(.*:\)\? */{p;s///;s/ *\\\?$$/ /;s/ */:\n/g;H;}' \
|
|
|
|
-e '$${g;p;}' -e d >$*.d; \
|
|
|
|
[ "$${PIPESTATUS[*]}" = "0 0" ] || { rm -f $*.d; exit 1; }
|
|
|
|
|
|
|
|
-include $(OBJS:.o=.d)
|
|
|
|
|
|
|
|
# ----- Programming and device control ----------------------------------------
|
|
|
|
|
2011-03-09 05:41:32 +02:00
|
|
|
upload: $(NAME).bin boot.hex
|
|
|
|
scp $(NAME).bin boot.hex $(HOST):
|
|
|
|
|
|
|
|
# lfuse: external clock, slow start-up
|
|
|
|
# hfuse: 4 kB boot loader, reset into boot loader
|
|
|
|
# lock: allow everything but SPM to the boot loader
|
2011-03-09 08:11:15 +02:00
|
|
|
# Note: when trying to program 0xef, we get back 0x2f, failing
|
|
|
|
# verification. So we just program 0x2f.
|
2011-02-14 04:46:36 +02:00
|
|
|
|
2011-03-11 21:24:49 +02:00
|
|
|
prog-app:
|
|
|
|
ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb -e \
|
|
|
|
-U flash:w:atusb.bin:r \
|
|
|
|
-U lfuse:w:0x60:m
|
|
|
|
|
2011-02-14 04:46:36 +02:00
|
|
|
prog:
|
2011-03-05 02:50:01 +02:00
|
|
|
ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb -e \
|
2011-03-09 05:41:32 +02:00
|
|
|
-U flash:w:boot.hex:i \
|
|
|
|
-U lfuse:w:0x60:m \
|
2011-03-11 21:23:42 +02:00
|
|
|
-U hfuse:w:0xd8:m \
|
2011-03-09 08:11:15 +02:00
|
|
|
-U lock:w:0x2f:m
|
2011-03-09 05:41:32 +02:00
|
|
|
|
2011-03-11 21:24:49 +02:00
|
|
|
prog-read:
|
|
|
|
ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb \
|
|
|
|
-U flash:r:mcu.bin:r
|
|
|
|
|
2011-05-10 03:13:41 +03:00
|
|
|
dfu: $(NAME).bin
|
2011-05-11 11:29:54 +03:00
|
|
|
dfu-util -d $(USB_ID) -D $(NAME).bin
|
|
|
|
|
|
|
|
update: $(NAME).bin
|
|
|
|
-atrf-reset -a
|
|
|
|
usbwait -r -i 0.01 -t 5 $(USB_ID)
|
|
|
|
$(MAKE) dfu
|
2011-05-10 03:13:41 +03:00
|
|
|
|
2011-02-14 04:46:36 +02:00
|
|
|
on:
|
2011-03-05 02:50:01 +02:00
|
|
|
ssh $(HOST) poke 0x10010318 4
|
2011-02-14 04:46:36 +02:00
|
|
|
|
|
|
|
off:
|
2011-03-05 02:50:01 +02:00
|
|
|
ssh $(HOST) poke 0x10010314 4
|
2011-02-14 04:46:36 +02:00
|
|
|
|
|
|
|
reset:
|
2011-03-05 02:50:01 +02:00
|
|
|
ssh $(HOST) poke 0x10010318 2048
|
|
|
|
ssh $(HOST) poke 0x10010314 2048
|