Root/
| Source at commit 0f17c404d2bf724b17d8443d6b76701f50be673d created 11 years 6 days ago. By Werner Almesberger, BOOKSHELF: add data sheets of parts for next Tornado iteration | |
|---|---|
| 1 | # |
| 2 | # Makefile - Makefile of the Antorcha 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 | |
| 13 | SHELL = /bin/bash |
| 14 | |
| 15 | NAME = antorcha |
| 16 | |
| 17 | CFLAGS = -g -mmcu=$(CHIP) \ |
| 18 | -DBOOT_ADDR=$(BOOT_ADDR) \ |
| 19 | -Wall -Wextra -Wshadow -Werror -Wno-unused-parameter \ |
| 20 | -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes \ |
| 21 | -I../../ben-wpan/atusb/fw/include/ |
| 22 | |
| 23 | CHIP = atmega168 |
| 24 | HOST = jlime |
| 25 | BOOT_ADDR = 0x3800 |
| 26 | |
| 27 | AVR_PREFIX = $(BIN_PATH) avr- |
| 28 | CC = $(AVR_PREFIX)gcc |
| 29 | OBJCOPY = $(AVR_PREFIX)objcopy |
| 30 | #OBJDUMP = $(AVR_PREFIX)objdump |
| 31 | SIZE = $(AVR_PREFIX)size |
| 32 | |
| 33 | OBJS = $(NAME).o accel.o diag.o dispatch.o hash.o image.o param.o \ |
| 34 | reset.o sample.o secret.o sweep.o \ |
| 35 | $(COMMON_OBJS) |
| 36 | BOOT_OBJS = boot.o flash.o fw.o $(COMMON_OBJS) |
| 37 | COMMON_OBJS = rf.o spi.o |
| 38 | |
| 39 | # ----- Verbosity control ----------------------------------------------------- |
| 40 | |
| 41 | CC_normal := $(CC) |
| 42 | BUILD_normal := |
| 43 | DEPEND_normal := $(CPP) $(CFLAGS) -MM -MG |
| 44 | |
| 45 | CC_quiet = @echo " CC " $@ && $(CC_normal) |
| 46 | BUILD_quiet = @echo " BUILD " $@ && $(BUILD_normal) |
| 47 | DEPEND_quiet = @$(DEPEND_normal) |
| 48 | |
| 49 | ifeq ($(V),1) |
| 50 | CC = $(CC_normal) |
| 51 | BUILD = $(BUILD_normal) |
| 52 | DEPEND = $(DEPEND_normal) |
| 53 | else |
| 54 | CC = $(CC_quiet) |
| 55 | BUILD = $(BUILD_quiet) |
| 56 | DEPEND = $(DEPEND_quiet) |
| 57 | endif |
| 58 | |
| 59 | # ----- Rules ----------------------------------------------------------------- |
| 60 | |
| 61 | .PHONY: all clean nosecrets upload prog version.c |
| 62 | .PHONY: prog-app prog-read |
| 63 | |
| 64 | all: $(NAME).bin boot.bin |
| 65 | |
| 66 | $(NAME).elf: $(OBJS) |
| 67 | $(MAKE) version.o |
| 68 | $(CC) $(CFLAGS) -o $@ $(OBJS) version.o |
| 69 | |
| 70 | boot.elf: $(BOOT_OBJS) |
| 71 | $(CC) $(CFLAGS) -o $@ $(BOOT_OBJS) \ |
| 72 | -Wl,--section-start=.text=$(BOOT_ADDR) |
| 73 | |
| 74 | %.bin: %.elf |
| 75 | $(BUILD) $(OBJCOPY) -j .text -j .data -O binary $< $@ |
| 76 | @echo "build #`cat .version`, `ls -l $@`" |
| 77 | |
| 78 | %.hex: %.elf |
| 79 | $(BUILD) $(OBJCOPY) -j .text -j .data -O ihex $< $@ |
| 80 | $(SIZE) $@ |
| 81 | |
| 82 | # ----- Cleanup --------------------------------------------------------------- |
| 83 | |
| 84 | clean: |
| 85 | rm -f $(NAME).bin $(NAME).elf |
| 86 | rm -f $(OBJS) $(OBJS:.o=.d) |
| 87 | rm -f boot.hex boot.elf |
| 88 | rm -f $(BOOT_OBJS) $(BOOT_OBJS:.o=.d) |
| 89 | rm -f version.c version.d version.o |
| 90 | |
| 91 | nosecrets: |
| 92 | rm -f unlock-secret.inc image-secret.inc |
| 93 | |
| 94 | # ----- Build version --------------------------------------------------------- |
| 95 | |
| 96 | version.c: |
| 97 | @if [ -f .version ]; then \ |
| 98 | v=`cat .version`; \ |
| 99 | expr $$v + 1 >.version; \ |
| 100 | else \ |
| 101 | echo 0 >.version; \ |
| 102 | fi |
| 103 | @[ -s .version ] || echo 0 >.version |
| 104 | @echo '/* MACHINE-GENERATED. DO NOT EDIT ! */' >version.c |
| 105 | @echo '#include "version.h"' >>version.c |
| 106 | @echo "const char *build_date = \"`date`\";" >>version.c |
| 107 | @echo "const uint16_t build_number = `cat .version`;" \ |
| 108 | >>version.c |
| 109 | |
| 110 | # ----- Secrets --------------------------------------------------------------- |
| 111 | |
| 112 | # |
| 113 | # Linux has two sources of randomness: |
| 114 | # |
| 115 | # /dev/random delivers bits of high randomness but may take a while to |
| 116 | # collect them |
| 117 | # /dev/urandom delivers bits of high randomness if available and "stretches" |
| 118 | # the pool with pseudo-randomness to deliver the rest of the bits |
| 119 | # that are requested |
| 120 | # |
| 121 | # Use /dev/random if you're paranoid. /dev/urandom is more than adequate for |
| 122 | # the level of security we try to achieve here. |
| 123 | # |
| 124 | |
| 125 | RANDOM = /dev/urandom |
| 126 | |
| 127 | SECRET = { dd if=$(RANDOM) iflag=fullblock bs=$(1) count=1 status=noxfer | \ |
| 128 | hexdump -e '"\t" "/* %3_ad */" 8/1 " 0x%02x," "\n"'; \ |
| 129 | [ "$${PIPESTATUS[*]}" = "0 0" ]; } |
| 130 | |
| 131 | unlock-secret.inc: |
| 132 | $(BUILD) $(call SECRET,64) >$@ || { rm -f $@; exit 1; } |
| 133 | |
| 134 | image-secret.inc: |
| 135 | $(BUILD) $(call SECRET,128) >$@ || { rm -f $@; exit 1; } |
| 136 | |
| 137 | fw.o: unlock-secret.inc |
| 138 | reset.o: unlock-secret.inc |
| 139 | image.o: image-secret.inc |
| 140 | |
| 141 | # ----- Dependencies ---------------------------------------------------------- |
| 142 | |
| 143 | MKDEP = \ |
| 144 | $(DEPEND) $< | \ |
| 145 | sed \ |
| 146 | -e 's|^$(basename $(notdir $<)).o:|$@:|' \ |
| 147 | -e '/^\(.*:\)\? */{p;s///;s/ *\\\?$$/ /;s/ */:\n/g;H;}' \ |
| 148 | -e '$${g;p;}' \ |
| 149 | -e d >$(basename $@).d; \ |
| 150 | [ "$${PIPESTATUS[*]}" = "0 0" ] || \ |
| 151 | { rm -f $(basename $@).d; exit 1; } |
| 152 | |
| 153 | %.o: %.c |
| 154 | $(CC) $(CFLAGS) -Os -c $< |
| 155 | $(MKDEP) |
| 156 | |
| 157 | -include $(OBJS:.o=.d) |
| 158 | |
| 159 | # ----- Programming and device control ---------------------------------------- |
| 160 | |
| 161 | upload: $(NAME).bin boot.hex |
| 162 | scp $(NAME).bin boot.hex ../common/avrdude-antorcha.conf \ |
| 163 | $(HOST): |
| 164 | |
| 165 | # lfuse: external clock, slow start-up |
| 166 | # hfuse: 4 kB boot loader, reset into boot loader |
| 167 | # lock: allow everything but SPM to the boot loader |
| 168 | # Note: when trying to program 0xef, we get back 0x2f, failing |
| 169 | # verification. So we just program 0x2f. |
| 170 | |
| 171 | prog-app: |
| 172 | ssh $(HOST) avrdude -F -p $(CHIP) \ |
| 173 | -L avrdude-antorcha.conf -c nanonote_antorcha -e \ |
| 174 | -U flash:w:antorcha.bin:r |
| 175 | # -U lfuse:w:0x60:m |
| 176 | |
| 177 | prog: |
| 178 | ssh $(HOST) avrdude -F -p $(CHIP) \ |
| 179 | -L avrdude-antorcha.conf -c nanonote_antorcha -e \ |
| 180 | -U flash:w:boot.hex:i \ |
| 181 | -U efuse:w:0x00:m \ |
| 182 | -U lfuse:w:0xe2:m |
| 183 | # -U lfuse:w:0x60:m \ |
| 184 | # -U hfuse:w:0xd8:m \ |
| 185 | # -U lock:w:0x2f:m |
| 186 | |
| 187 | prog-read: |
| 188 | ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_antorcha \ |
| 189 | -U flash:r:mcu.bin:r |
| 190 | |
Branches:
master
tornado-v1
