forked from embedded2013/freertos
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
144 lines (118 loc) · 3.53 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
CROSS_COMPILE=arm-none-eabi-
QEMU_STM32 ?= ../qemu_stm32/arm-softmmu/qemu-system-arm
ARCH=CM3
VENDOR=ST
PLAT=STM32F10x
CODEBASE= freertos
CMSIS_LIB_DIR=$(CODEBASE)/libraries/CMSIS/$(ARCH)
STM32_LIB=$(CODEBASE)/libraries/STM32F10x_StdPeriph_Driver
CMSIS_PLAT_SRC_DIR = $(CMSIS_LIB_DIR)/DeviceSupport/$(VENDOR)/$(PLAT)
FREERTOS_SRC_DIR = $(CODEBASE)/libraries/FreeRTOS
FREERTOS_INC = $(FREERTOS_SRC_DIR)/include/
FREERTOS_PORT_INC = $(FREERTOS_SRC_DIR)/portable/GCC/ARM_$(ARCH)/
CMSIS_SRCS = \
$(CMSIS_LIB_DIR)/CoreSupport/core_cm3.c \
$(CMSIS_PLAT_SRC_DIR)/system_stm32f10x.c \
$(CMSIS_PLAT_SRC_DIR)/startup/gcc_ride7/startup_stm32f10x_md.s
STM32_SRCS = \
$(STM32_LIB)/src/stm32f10x_rcc.c \
$(STM32_LIB)/src/stm32f10x_gpio.c \
$(STM32_LIB)/src/stm32f10x_usart.c \
$(STM32_LIB)/src/stm32f10x_exti.c \
$(STM32_LIB)/src/misc.c
FREERTOS_SRC = \
$(FREERTOS_SRC_DIR)/croutine.c \
$(FREERTOS_SRC_DIR)/list.c \
$(FREERTOS_SRC_DIR)/queue.c \
$(FREERTOS_SRC_DIR)/tasks.c \
$(FREERTOS_SRC_DIR)/portable/GCC/ARM_CM3/port.c \
$(FREERTOS_SRC_DIR)/portable/MemMang/heap_2.c
SRCS= \
$(CMSIS_SRCS) \
$(STM32_SRCS) \
$(FREERTOS_SRC) \
stm32_p103.c \
romfs.c \
hash-djb2.c \
filesystem.c \
fio.c \
string.c \
util.c \
main.c \
memtest.c \
rand.c \
shell.c
INCS= \
-I. -I$(FREERTOS_INC) -I$(FREERTOS_PORT_INC) \
-I$(CODEBASE)/libraries/CMSIS/CM3/CoreSupport \
-I$(CODEBASE)/libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x \
-I$(CODEBASE)/libraries/STM32F10x_StdPeriph_Driver/inc
HEADERS= \
filesystem.h \
fio.h \
FreeRTOSConfig.h \
hash-djb2.h \
osdebug.h \
romfs.h \
stm32f10x_conf.h \
stm32_p103.h \
string.h \
util.h \
memtest.h \
rand.h \
shell.h
CFLAGS = \
-fno-common -O0 \
-mcpu=cortex-m3 -mthumb \
-Wall -std=c99 -pedantic \
-ffreestanding
# Options and actions
BUILD_TYPE ?= DEBUG
USE_UNIT_TEST ?= YES
USE_SEMIHOST ?= YES
ifeq ($(BUILD_TYPE), DEBUG)
CFLAGS += -gdwarf-2 -g3 -DENABLE_DEBUG
ifeq ($(USE_UNIT_TEST), YES)
CFLAGS +=-DUSE_UNIT_TEST
SRCS += unit_tests.c
HEADERS += unit_tests.h
endif
endif
ifeq ($(USE_SEMIHOST),YES)
CFLAGS += -DUSE_SEMIHOST
SRCS += host.c
HEADERS += host.h
QEMU_SMH_PARAM_SUFFIX=-semihosting
endif
# Trick to get obj file name
# Filter out path -> Renname *.c to *.o -> Rename *.s to *.o
SRC_STRIP_PATH=$(notdir $(SRCS))
C_OBJS=$(patsubst %.c,%.o,$(SRC_STRIP_PATH))
OBJS=$(patsubst %.s,%.o,$(C_OBJS))
all: main.bin
objs: $(SRCS) $(HEADERS)
$(CROSS_COMPILE)gcc $(CFLAGS) $(INCS) -c $(SRCS)
main.bin: objs test-romfs.o
$(CROSS_COMPILE)ld -Tmain.ld -nostartfiles -o main.elf $(OBJS)
$(CROSS_COMPILE)objcopy -Obinary main.elf main.bin
$(CROSS_COMPILE)objdump -S main.elf > main.list
mkromfs:
gcc -o mkromfs mkromfs.c
CPU=arm
TARGET_FORMAT = elf32-littlearm
TARGET_OBJCOPY_BIN = $(CROSS_COMPILE)objcopy -I binary -O $(TARGET_FORMAT) --binary-architecture $(CPU)
test-romfs.o: mkromfs
./mkromfs -d test-romfs test-romfs.bin
$(TARGET_OBJCOPY_BIN) --prefix-sections '.romfs' test-romfs.bin test-romfs.o
qemu: main.bin $(QEMU_STM32)
$(QEMU_STM32) -M stm32-p103 -kernel main.bin \
-monitor tcp:localhost:4444,server,nowait \
$(QEMU_SMH_PARAM_SUFFIX)
ifeq ($(BUILD_TYPE), DEBUG)
qemudbg: main.bin $(QEMU_STM32)
$(QEMU_STM32) -M stm32-p103 -gdb tcp::3333 -S \
$(QEMU_SMH_PARAM_SUFFIX) -kernel main.bin \
-monitor tcp:localhost:4444,server,nowait
endif
clean:
rm -f *.o *.elf *.bin *.list mkromfs