summaryrefslogtreecommitdiff
path: root/Makefile
blob: bb90effdbc84fb7da1c8eab27b8fda758d28ad24 (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
#
# Makefile for msp430
#
# 'make' builds everything
# 'make clean' deletes everything except source files and Makefile
# You need to set TARGET, MCU and SOURCES for your project.
# TARGET is the name of the executable file to be produced 
# $(TARGET).elf $(TARGET).hex and $(TARGET).txt nad $(TARGET).map are all generated.
# The TXT file is used for BSL loading, the ELF can be used for JTAG use
# 
BASE_TARGET  = PwrSeq
BOARD = XIOH_V5
TARGET = $(BASE_TARGET).$(BOARD)
MCU     = msp430f2274
SOURCES = main.c serial.c
# Add or subtract whatever MSPGCC flags you want. There are plenty more
#######################################################################################
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).elf $(TARGET).hex $(TARGET).txt.unsafe $(TARGET).safe.txt $(TARGET).gcc.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 $< $@
%.txt.unsafe: %.hex
	$(MAKETXT) -O $@ -TITXT $< -I
	unix2dos $(TARGET).txt.unsafe
#  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.
%.safe.txt: %.txt.unsafe
	# ./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.
	#
	./fill_titxt.py -n 4 -x 0xff3f  -d 0x82432001 -w 0x0020 -o $@ $<
	echo
	echo '>>>'
	echo '>>>>>>' FINAL RESULT IS IN $@ '<<<<<<'
	echo '>>>'
	echo
%.gcc.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 *.lst *.map $(BASE_TARGET).*.txt *.unsafe
	-$(RM) $(BASE_TARGET).txt
	-$(RM) path.txt include.txt source.txt file.r43 *.dep