2011-02-14 04:46:36 +02:00
|
|
|
#
|
2017-09-11 14:58:32 +03:00
|
|
|
# Makefile - Makefile of the ATUSB firmware
|
2011-02-14 04:46:36 +02:00
|
|
|
#
|
2013-07-24 23:18:33 +03:00
|
|
|
# Written 2010-2011, 2013 by Werner Almesberger
|
|
|
|
# Copyright 2010-2011, 2013 by Werner Almesberger
|
2011-02-14 04:46:36 +02:00
|
|
|
#
|
|
|
|
# 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
|
2017-09-11 14:58:32 +03:00
|
|
|
DEBUG = false
|
2011-02-14 04:46:36 +02:00
|
|
|
|
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
|
|
|
|
|
2017-09-11 14:58:32 +03:00
|
|
|
ifeq ($(DEBUG),true)
|
|
|
|
CFLAGS += -DDEBUG
|
|
|
|
endif
|
|
|
|
|
2015-05-24 15:37:38 +03:00
|
|
|
ifeq ($(NAME),rzusb)
|
|
|
|
CHIP=at90usb1287
|
2016-03-30 23:12:10 +03:00
|
|
|
CFLAGS += -DRZUSB -DAT86RF230
|
2017-09-11 14:58:33 +03:00
|
|
|
else ifeq ($(NAME),hulusb)
|
|
|
|
CHIP=at90usb1287
|
|
|
|
CFLAGS += -DHULUSB -DAT86RF212
|
2015-05-24 15:37:38 +03:00
|
|
|
else
|
2011-02-14 04:46:36 +02:00
|
|
|
CHIP=atmega32u2
|
2016-03-30 23:12:10 +03:00
|
|
|
CFLAGS += -DATUSB -DAT86RF231
|
2015-05-24 15:37:38 +03:00
|
|
|
endif
|
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
|
|
|
|
2015-05-20 12:56:15 +03:00
|
|
|
# BCD notion is 0xJJMM with JJ being major and MM being minor. Thus 0x0020 is
|
|
|
|
# version 0.2 */
|
2015-12-30 12:55:24 +02:00
|
|
|
USB_BCD_VERSION = 0030
|
2015-05-20 12:56:15 +03:00
|
|
|
USB_VENDOR_ID = 20b7
|
|
|
|
USB_PRODUCT_ID = 1540
|
|
|
|
USB_ID = $(USB_VENDOR_ID):$(USB_PRODUCT_ID)
|
2011-05-11 11:29:54 +03:00
|
|
|
|
2011-06-26 12:56:01 +03:00
|
|
|
OBJS = atusb.o board.o board_app.o sernum.o spi.o descr.o ep0.o \
|
2011-07-12 17:23:21 +03:00
|
|
|
dfu_common.o usb.o app-atu2.o mac.o
|
2011-06-26 12:56:01 +03:00
|
|
|
BOOT_OBJS = boot.o board.o sernum.o spi.o flash.o dfu.o \
|
|
|
|
dfu_common.o usb.o boot-atu2.o
|
2011-02-14 04:46:36 +02:00
|
|
|
|
2017-09-11 14:58:32 +03:00
|
|
|
ifeq ($(DEBUG),true)
|
|
|
|
OBJS += uart.o
|
|
|
|
endif
|
2016-03-30 01:03:48 +03:00
|
|
|
|
|
|
|
ifeq ($(NAME),rzusb)
|
|
|
|
OBJS += board_rzusb.o
|
|
|
|
BOOT_OBJS += board_rzusb.o
|
2017-09-11 14:58:33 +03:00
|
|
|
else ifeq ($(NAME),hulusb)
|
|
|
|
OBJS += board_hulusb.o
|
|
|
|
BOOT_OBJS += board_hulusb.o
|
2016-03-30 01:03:48 +03:00
|
|
|
else
|
|
|
|
OBJS += board_atusb.o
|
|
|
|
BOOT_OBJS += board_atusb.o
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
2011-02-14 15:14:06 +02:00
|
|
|
vpath %.c usb/
|
2011-02-14 04:46:36 +02:00
|
|
|
|
2013-10-28 16:17:48 +02:00
|
|
|
CFLAGS += -Iinclude -Iusb -I.
|
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-07-12 11:39:49 +03:00
|
|
|
.PHONY: all clean upload prog dfu update version.c bindist
|
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
|
2013-07-24 23:18:33 +03:00
|
|
|
$(SIZE) $@
|
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)
|
2013-07-24 23:18:33 +03:00
|
|
|
$(SIZE) $@
|
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
|
|
|
|
2015-05-20 12:56:15 +03:00
|
|
|
%.dfu: %.bin
|
|
|
|
cp $(NAME).bin $(NAME).dfu
|
|
|
|
dfu-suffix -a $(NAME).dfu -d 0x$(USB_BCD_VERSION) \
|
|
|
|
-p 0x$(USB_PRODUCT_ID) -v 0x$(USB_VENDOR_ID)
|
|
|
|
|
2011-03-09 05:41:32 +02:00
|
|
|
%.hex: %.elf
|
|
|
|
$(BUILD) $(OBJCOPY) -j .text -j .data -O ihex $< $@
|
2013-07-24 23:18:33 +03:00
|
|
|
@echo "Size: `$(SIZE) -A boot.hex | sed '/Total */s///p;d'` B"
|
2011-03-09 05:41:32 +02:00
|
|
|
|
2011-02-14 04:46:36 +02:00
|
|
|
# ----- Cleanup ---------------------------------------------------------------
|
|
|
|
|
|
|
|
clean:
|
2015-05-20 12:56:15 +03:00
|
|
|
rm -f $(NAME).bin $(NAME).elf $(NAME).dfu
|
2011-03-09 05:41:32 +02:00
|
|
|
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 ----------------------------------------------------------
|
|
|
|
|
2011-06-26 12:56:01 +03:00
|
|
|
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; }
|
|
|
|
|
2011-02-14 04:46:36 +02:00
|
|
|
%.o: %.c
|
2011-03-09 06:45:35 +02:00
|
|
|
$(CC) $(CFLAGS) -Os -c $<
|
2011-06-26 12:56:01 +03:00
|
|
|
$(MKDEP)
|
2011-02-14 04:46:36 +02:00
|
|
|
|
|
|
|
-include $(OBJS:.o=.d)
|
|
|
|
|
2011-06-26 12:56:01 +03:00
|
|
|
# ----- Object file variants --------------------------------------------------
|
|
|
|
|
|
|
|
app-%.o: usb/%.c
|
|
|
|
$(CC) $(CFLAGS) -Os -o $@ -c $<
|
|
|
|
$(MKDEP)
|
|
|
|
|
|
|
|
boot-%.o: usb/%.c
|
|
|
|
$(CC) $(CFLAGS) -DBOOT_LOADER -Os -o $@ -c $<
|
|
|
|
$(MKDEP)
|
|
|
|
|
2011-07-12 11:39:49 +03:00
|
|
|
# ----- Distribution ----------------------------------------------------------
|
|
|
|
|
|
|
|
BINDIST_BASE=http://downloads.qi-hardware.com/people/werner/wpan/bindist
|
|
|
|
ATUSB_BIN_NAME=atusb-`git rev-parse HEAD | cut -c 1-7`.bin
|
|
|
|
|
|
|
|
bindist:
|
|
|
|
qippl atusb.bin wpan/bindist/$(ATUSB_BIN_NAME)
|
|
|
|
@echo $(BINDIST_BASE)/$(ATUSB_BIN_NAME)
|
|
|
|
@echo md5sum: `md5sum atusb.bin | sed 's/ .*//'`
|
|
|
|
@echo atrf-id: \
|
|
|
|
`sed '/.*number = \(.*\);/s//#\1/p;d' version.c` \
|
|
|
|
`sed '/.*date = "\(.*\)";/s//\1/p;d' version.c`
|
|
|
|
|
2011-02-14 04:46:36 +02:00
|
|
|
# ----- 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
|
|
|
|
|
2015-05-20 12:56:15 +03:00
|
|
|
dfu: $(NAME).dfu
|
|
|
|
dfu-util -d $(USB_ID) -D $(NAME).dfu
|
2011-05-11 11:29:54 +03:00
|
|
|
|
|
|
|
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
|