1#
2# Copyright (C) 2016 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17#find build target
18PLATFORM ?= stm32
19CHIP ?= stm32f411
20CPU ?= cortexm4
21VARIANT ?= lunchbox
22DEBUG ?= -DDEBUG
23OUT := out/nanohub/$(VARIANT)
24
25#bad words
26BADWORDS += strcpy strcat atoi
27BADWORDS += "rsaPrivOp=RSA private ops must never be compiled into firmware."
28
29#find makefiles
30MAKE_PLAT = os/platform/$(PLATFORM)/$(PLATFORM).mk
31MAKE_CPU = os/cpu/$(CPU)/$(CPU).mk
32
33ifndef VARIANT_PATH
34VARIANT_PATH := variant/$(VARIANT)
35endif
36
37MAKE_VAR = $(VARIANT_PATH)/$(VARIANT).mk
38
39#top make target
40SRCS_os :=
41SRCS_bl :=
42DELIVERABLES :=
43
44.PHONY: real all
45real: all
46
47#include makefiles for plat and cpu
48include $(MAKE_PLAT)
49include $(MAKE_CPU)
50include $(MAKE_VAR)
51
52FLAGS += -Ios/algos
53FLAGS += -Ios/cpu/$(CPU)/inc
54FLAGS += -Ios/inc
55FLAGS += -Ios/platform/$(PLATFORM)/inc
56FLAGS += -I$(VARIANT_PATH)/inc
57FLAGS += -Iexternal/freebsd/inc
58FLAGS += -I../lib/include
59FLAGS += -I../../../../system/chre/chre_api/include/chre_api
60FLAGS += -I../../../../system/chre/util/include
61
62FLAGS += -Wall -Werror
63#help avoid commmon embedded C mistakes
64FLAGS += -Wmissing-declarations -Wlogical-op -Waddress -Wempty-body -Wpointer-arith -Wenum-compare -Wdouble-promotion -Wfloat-equal -Wshadow -fno-strict-aliasing
65
66OSFLAGS += -g -ggdb3 -D_OS_BUILD_ -O2
67OSFLAGS_os += -DUSE_PRINTF_FLAG_CHARS
68
69#debug mode
70FLAGS += $(DEBUG)
71
72include firmware_conf.mk
73
74FLAGS += $(COMMON_FLAGS)
75
76#bootloader pieces
77SRCS_bl += ../lib/nanohub/sha2.c ../lib/nanohub/rsa.c ../lib/nanohub/aes.c os/core/seos.c
78
79#frameworks
80SRCS_os += os/core/printf.c os/core/timer.c os/core/seos.c os/core/heap.c os/core/slab.c os/core/spi.c os/core/trylock.c
81SRCS_os += os/core/hostIntf.c os/core/hostIntfI2c.c os/core/hostIntfSpi.c os/core/nanohubCommand.c os/core/sensors.c os/core/syscall.c
82SRCS_os += os/core/eventQ.c os/core/osApi.c os/core/appSec.c os/core/simpleQ.c os/core/floatRt.c os/core/nanohub_chre.c
83SRCS_os += os/algos/ap_hub_sync.c
84SRCS_bl += os/core/bl.c
85
86#some help for bootloader
87SRCS_bl += os/core/printf.c
88
89SRCS_os += ../lib/nanohub/softcrc.c
90
91#extra deps
92DEPS += $(wildcard inc/*.h)
93DEPS += $(wildcard ../inc/*.h)
94DEPS += $(wildcard ../inc/chre/*.h)
95DEPS += $(wildcard $(VARIANT_PATH)/inc/variant/*.h)
96DEPS += firmware.mk firmware_conf.mk $(MAKE_PLAT) $(MAKE_CPU) $(MAKE_VAR)
97DELIVERABLES += $(OUT)/full.bin
98
99all: $(DELIVERABLES)
100
101$(OUT)/bl.unchecked.elf: $(SRCS_bl) $(DEPS)
102	mkdir -p $(dir $@)
103	$(GCC) -o $@ $(SRCS_bl) $(OSFLAGS) $(OSFLAGS_bl) $(FLAGS)
104
105$(OUT)/os.unchecked.elf: $(SRCS_os) $(DEPS)
106	mkdir -p $(dir $@)
107	$(GCC) -o $@ $(SRCS_os) $(OSFLAGS) $(OSFLAGS_os) $(FLAGS)
108
109$(OUT)/%.checked.elf : $(OUT)/%.unchecked.elf  symcheck.sh
110	mkdir -p $(dir $@)
111	./symcheck.sh $< $@ $(BADWORDS)
112
113$(OUT)/full.bin: $(BL_FILE) $(OS_FILE)
114	mkdir -p $(dir $@)
115	cat $(BL_FILE) $(OS_FILE) > $@
116
117clean:
118	rm -rf $(OUT)
119
120.SECONDARY: $(OUT)/os.checked.elf
121