summaryrefslogtreecommitdiff
path: root/Makefile
blob: 43df1cc2b305701d1aa6ed067574df2e67896e4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#
# Makefile for the Embedded Controller Firmware of the XIOH board
#
# Note that there are multiple board variants: BOARD=XIOH_V5 or BOARD=XIOH_V6.
# One "make" invocation only builds for one variant.
# The build result files include $(BOARD) in their names.
#
# "make" generates the following files:
#	ECF-$(BOARD).elf
#	ECF-$(BOARD).lst
#	ECF-$(BOARD).map
#	ECF-$(BOARD).txt
#
# Note that "make clean" removes files for all board targets.
#
# Note that the .txt is what must be flashed and is not 100% equivalent
# to the .elf: the .txt includes additionnal safety features in the form
# of filling of unused areas, done by the fill_titxt.py program.

# default board variant: you can override by the command line,
# e.g.: "make BOARD=XIOH_V6"
BOARD = XIOH_V5

BASE_TARGET = ECF
TARGET = $(BASE_TARGET)-$(BOARD)
MCU     = msp430f2274
SOURCES = main.c serial.c
#######################################################################################
CFLAGS   = -mmcu=$(MCU) -D$(BOARD) -funsigned-char -g3 -O2 -Wall -Wextra
ASFLAGS  = -mmcu=$(MCU) -x assembler-with-cpp -Wa,-gstabs
LDFLAGS  = -mmcu=$(MCU) -Wl,-Map=$(TARGET).map
########################################################################################
CC       = msp430-gcc
LD       = msp430-ld
AR       = msp430-ar
AS       = msp430-gcc
GASP     = msp430-gasp
NM       = msp430-nm
OBJCOPY  = msp430-objcopy
OBJDUMP  = msp430-objdump
RANLIB   = msp430-ranlib
STRIP    = msp430-strip
SIZE     = msp430-size
READELF  = msp430-readelf
MAKETXT  = srec_cat
CP       = cp -p
RM       = rm -f
MV       = mv
########################################################################################
# the file which will include dependencies
DEPEND = $(SOURCES:.c=.$(BOARD).d)
# all the object files
OBJECTS = $(SOURCES:.c=.$(BOARD).o)

all: $(TARGET).txt $(TARGET).lst

$(TARGET).elf: $(OBJECTS)
	echo "Linking $@"
	$(CC) $(OBJECTS) $(LDFLAGS) $(LIBS) -o $@
	echo
	echo ">>>> Size of Firmware <<<<"
	$(SIZE) $(TARGET).elf
	echo

%.hex: %.elf
	$(OBJCOPY) -O ihex $< $@

%.unsafe: %.hex
	$(MAKETXT) -O $@ -TITXT $< -I
	unix2dos $@
#  The above line is required for the DOS based TI BSL tool to be able to read the txt file generated from linux/unix systems.

# ./fill_titxt.py:
#       -n 4 -x 0xff3f: Put 4 words 3fff just before the vectors.
#                       Each decodes as an infinite loop instruction.
#       -d 0x82432001:  Put aligned 4382 0120 instructions
#                       (reboot using WD) everywhere it is possible.
#       -w 0x0020:      If word gaps remain, put 0200 instructions
#                       there (jump next instruction).
#
# The goal is to make a firmware more robust in case the PC gets
# corrupted. We fill most of the unprogrammed area with instructions
# that will trigger a reboot (write of a bad value to WDTCTL). Just
# before the vector, we put 4 single word infinite loop instructions:
# this is better than double words instructions because we can't put
# arbitrary words in the vector area, so if PC/2 is odd the result
# will still be completely defined if we land there, 3fff is an
# acceptable BSLSKEY, and the application provides a watchdog timeout.
# In remaining single word spaces, we put "jmp next" instructions to
# hopefully get to the next 4382 0120 instruction.
#
%.txt: %.unsafe
	./fill_titxt.py -n 4 -x 0xff3f  -d 0x82432001 -w 0x0020 -o $@ $<
	echo
	echo '>>>'
	echo '>>>>>>' FINAL RESULT IS IN $@ '<<<<<<'
	echo '>>>'
	echo

%.lst: %.elf
	$(OBJDUMP) -S -d $< > $@ && $(OBJDUMP) -s -j .rodata $< >> $@

%.$(BOARD).o: %.c
	echo "Compiling $<"
	$(CC) -c $(CFLAGS) -o $@ $<

# include the dependencies unless we're going to clean, then forget about them.
ifneq ($(MAKECMDGOALS), clean)
-include $(DEPEND)
endif

# dependencies file
# includes also considered, since some of these are our own
# (otherwise use -MM instead of -M)
%.$(BOARD).d: %.c
	echo "Generating dependencies $@ from $<"
	$(CC) -M ${CFLAGS} $< >$@

.SILENT:

.PHONY:	clean

clean:
	-$(RM) *.o *.d *.elf *.hex *.map *.unsafe
	-$(RM) $(BASE_TARGET)*.txt $(BASE_TARGET)*.lst
	-$(RM) path.txt include.txt source.txt file.r43 *.dep