summaryrefslogtreecommitdiff
path: root/firmware/firmware.mk
blob: c35756a4a5c290a83fd37d63872f248cd7abb1a0 (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
#
# Copyright (C) 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#find build target
PLATFORM ?= stm32
CHIP ?= stm32f411
CPU ?= cortexm4
VARIANT ?= lunchbox
DEBUG ?= -DDEBUG
OUT := out/nanohub/$(VARIANT)

#bad words
BADWORDS += strcpy strcat atoi
BADWORDS += "rsaPrivOp=RSA private ops must never be compiled into firmware."

#find makefiles
MAKE_PLAT = os/platform/$(PLATFORM)/$(PLATFORM).mk
MAKE_CPU = os/cpu/$(CPU)/$(CPU).mk

ifndef VARIANT_PATH
VARIANT_PATH := variant/$(VARIANT)
endif

MAKE_VAR = $(VARIANT_PATH)/$(VARIANT).mk

#top make target
SRCS_os :=
SRCS_bl :=
DELIVERABLES :=

.PHONY: real all
real: all

#include makefiles for plat and cpu
include $(MAKE_PLAT)
include $(MAKE_CPU)
include $(MAKE_VAR)

FLAGS += -Ios/algos
FLAGS += -Ios/cpu/$(CPU)/inc
FLAGS += -Ios/inc
FLAGS += -Ios/platform/$(PLATFORM)/inc
FLAGS += -I$(VARIANT_PATH)/inc
FLAGS += -Iexternal/freebsd/inc
FLAGS += -I../lib/include
FLAGS += -I../../../../system/chre/chre_api/include/chre_api
FLAGS += -I../../../../system/chre/util/include

FLAGS += -Wall -Werror
#help avoid commmon embedded C mistakes
FLAGS += -Wmissing-declarations -Wlogical-op -Waddress -Wempty-body -Wpointer-arith -Wenum-compare -Wdouble-promotion -Wfloat-equal -Wshadow -fno-strict-aliasing

OSFLAGS += -g -ggdb3 -D_OS_BUILD_ -O2
OSFLAGS_os += -DUSE_PRINTF_FLAG_CHARS

#debug mode
FLAGS += $(DEBUG)

include firmware_conf.mk

FLAGS += $(COMMON_FLAGS)

#bootloader pieces
SRCS_bl += ../lib/nanohub/sha2.c ../lib/nanohub/rsa.c ../lib/nanohub/aes.c os/core/seos.c

#frameworks
SRCS_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
SRCS_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
SRCS_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
SRCS_os += os/algos/ap_hub_sync.c
SRCS_bl += os/core/bl.c

#some help for bootloader
SRCS_bl += os/core/printf.c

SRCS_os += ../lib/nanohub/softcrc.c

#extra deps
DEPS += $(wildcard inc/*.h)
DEPS += $(wildcard ../inc/*.h)
DEPS += $(wildcard ../inc/chre/*.h)
DEPS += $(wildcard $(VARIANT_PATH)/inc/variant/*.h)
DEPS += firmware.mk firmware_conf.mk $(MAKE_PLAT) $(MAKE_CPU) $(MAKE_VAR)
DELIVERABLES += $(OUT)/full.bin

all: $(DELIVERABLES)

$(OUT)/bl.unchecked.elf: $(SRCS_bl) $(DEPS)
	mkdir -p $(dir $@)
	$(GCC) -o $@ $(SRCS_bl) $(OSFLAGS) $(OSFLAGS_bl) $(FLAGS)

$(OUT)/os.unchecked.elf: $(SRCS_os) $(DEPS)
	mkdir -p $(dir $@)
	$(GCC) -o $@ $(SRCS_os) $(OSFLAGS) $(OSFLAGS_os) $(FLAGS)

$(OUT)/%.checked.elf : $(OUT)/%.unchecked.elf  symcheck.sh
	mkdir -p $(dir $@)
	./symcheck.sh $< $@ $(BADWORDS)

$(OUT)/full.bin: $(BL_FILE) $(OS_FILE)
	mkdir -p $(dir $@)
	cat $(BL_FILE) $(OS_FILE) > $@

clean:
	rm -rf $(OUT)

.SECONDARY: $(OUT)/os.checked.elf