forked from Lauszus/TM4C-MSC-bootloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
179 lines (152 loc) · 5.96 KB
/
Makefile
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# Copyright (c) 2012, Mauro Scomparin
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of Mauro Scomparin nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY Mauro Scomparin ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL Mauro Scomparin BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# File: Makefile
# Author: Mauro Scomparin <http://scompoprojects.worpress.com>
# Version: 1.0.0
# Description: Sample makefile
#==============================================================================
# Cross compiling toolchain / tools specifications
#==============================================================================
DEBUGUART ?= 0
NOREAD ?= 0
CRYPTO ?= 0
# Prefix for the arm-eabi-none toolchain.
# I'm using codesourcery g++ lite compilers available here:
# http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/
PREFIX_ARM = arm-none-eabi
# Microcontroller properties.
#PART=LM4F120H5QR
PART=TM4C123GH6PM
#TARGET=TARGET_IS_BLIZZARD_RA1
TARGET=TARGET_IS_BLIZZARD_RB1
CPU=-mcpu=cortex-m4
FPU=-mfpu=fpv4-sp-d16 -mfloat-abi=hard
# Stellarisware path
STELLARISWARE_PATH=../TivaWare_C_Series-2.1.4.178
# Program name definition for ARM GNU C compiler.
CC = ${PREFIX_ARM}-gcc
# Program name definition for ARM GNU Linker.
LD = ${PREFIX_ARM}-ld
# Program name definition for ARM GNU Object copy.
CP = ${PREFIX_ARM}-objcopy
# Program name definition for ARM GNU Object dump.
OD = ${PREFIX_ARM}-objdump
# Option arguments for C compiler.
CFLAGS=-mthumb ${CPU} ${FPU} -ffunction-sections -fdata-sections -MD -std=c99 -Wall -pedantic -c -g
ifdef DEBUG
CFLAGS+=-DDEBUG -O0
else
CFLAGS+=-Os
endif
# Library stuff passed as flags!
CFLAGS+= -I ${STELLARISWARE_PATH} -DPART_$(PART) -c -D$(TARGET) -Dgcc
# Set this to enable debug via UART
ifeq ($(DEBUGUART),1)
CFLAGS+= -DDEBUGUART -DUART_BUFFERED
endif
# Set this to disable firmware dumping (i.e. reading via MSC)
ifeq ($(NOREAD),1)
CFLAGS+= -DNOREAD
endif
# Set this to enable check at start whether the firmware has been cryptographically signed
ifeq ($(CRYPTO),1)
CFLAGS+= -DCRYPTO
endif
# Flags for LD
LFLAGS = --gc-sections
# Flags for objcopy
CPFLAGS = -Obinary
# flags for objectdump
ODFLAGS = -S
# I want to save the path to libgcc, libc.a and libm.a for linking.
# I can get them from the gcc frontend, using some options.
# See gcc documentation
LIB_GCC_PATH=${shell ${CC} ${CFLAGS} -print-libgcc-file-name}
LIBC_PATH=${shell ${CC} ${CFLAGS} -print-file-name=libc.a}
LIBM_PATH=${shell ${CC} ${CFLAGS} -print-file-name=libm.a}
# Uploader tool path.
# Set a relative or absolute path to the upload tool program.
# I used this project: https://github.com/utzig/lm4tools
FLASHER=lm4flash
# Flags for the uploader program.
FLASHER_FLAGS=
#==============================================================================
# Project properties
#==============================================================================
# Project name (W/O .c extension eg. "main")
PROJECT_NAME = boot_msc_usb
# Startup file name (W/O .c extension eg. "LM4F_startup")
STARTUP_FILE = LM4F_startup
# Linker file name
LINKER_FILE = LM4F.ld
SRC = boot_usb_msc.c LM4F_startup.c ramdisk.c usb_config.c
ifeq ($(DEBUGUART),1)
SRC += ${STELLARISWARE_PATH}/utils/uartstdio.c
endif
ifeq ($(CRYPTO),1)
SRC += crypto/crypto.c crypto/imath.c crypto/newlib_stubs.c crypto/rsa.c crypto/rsa_key.c crypto/sha256.c
endif
OBJS = $(SRC:.c=.o)
#==============================================================================
# Rules to make the target
#==============================================================================
#make all rule
all: $(OBJS) ${PROJECT_NAME}.axf ${PROJECT_NAME}
%.o: %.c
@echo
@echo Compiling $<...
$(CC) -c $(CFLAGS) ${<} -o ${@}
${PROJECT_NAME}.axf: $(OBJS)
@echo
@echo Making driverlib
$(MAKE) -C ${STELLARISWARE_PATH}/driverlib/
@echo
@echo Making usblib
$(MAKE) -C ${STELLARISWARE_PATH}/usblib/
@echo
@echo Linking...
$(LD) -T $(LINKER_FILE) $(LFLAGS) -o ${PROJECT_NAME}.axf $(OBJS) ${STELLARISWARE_PATH}/usblib/gcc/libusb.a ${STELLARISWARE_PATH}/driverlib/gcc/libdriver.a $(LIBM_PATH) $(LIBC_PATH) $(LIB_GCC_PATH)
${PROJECT_NAME}: ${PROJECT_NAME}.axf
@echo
@echo Copying...
$(CP) $(CPFLAGS) ${PROJECT_NAME}.axf ${PROJECT_NAME}.bin
@echo
@echo Creating list file...
$(OD) $(ODFLAGS) ${PROJECT_NAME}.axf > ${PROJECT_NAME}.lst
@echo
@echo Binary size:
${PREFIX_ARM}-size ${PROJECT_NAME}.axf
# make clean rule
clean:
rm -f *.bin *.o *.d *.axf *.lst
rm -f crypto/*.o crypto/*.d
$(MAKE) -C ${STELLARISWARE_PATH}/driverlib clean
$(MAKE) -C ${STELLARISWARE_PATH}/usblib clean
# Rule to load the project to the board
flash: all
${FLASHER} ${FLASHER_FLAGS} ${PROJECT_NAME}.bin
# Rebuild everything when makefile changes.
$(OBJS): Makefile