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 ?= stm32f4xx 19CPU ?= cortexm4f 20VARIANT ?= lunchbox 21DEBUG ?= -DDEBUG 22 23#bad words 24BADWORDS += strcpy strcat atoi 25BADWORDS += "rsaPrivOp=RSA private ops must never be compiled into firmware." 26 27#find makefiles 28MAKE_PLAT = misc/platform/$(PLATFORM)/Makefile 29MAKE_CPU = misc/cpu/$(CPU)/Makefile 30 31#link paths 32ifdef VARIANT_PATH 33LINK_PATH_MISC = $(VARIANT_PATH)/misc 34LINK_PATH_SRC = $(VARIANT_PATH)/src 35LINK_PATH_INC = $(VARIANT_PATH)/inc 36else 37LINK_PATH_MISC = misc/variant/$(VARIANT) 38LINK_PATH_SRC = src/variant/$(VARIANT) 39LINK_PATH_INC = inc/variant/$(VARIANT) 40endif 41 42#variant makefile 43MAKE_VAR = $(LINK_PATH_MISC)/Makefile 44 45#top make target 46SRCS_os := 47SRCS_bl := 48DELIVERABLES := 49real: all 50 51#include makefiles for plat and cpu 52include $(MAKE_PLAT) 53include $(MAKE_CPU) 54include $(MAKE_VAR) 55 56FLAGS += -Wall -Werror -Iinc -Ilinks -Iexternal/freebsd/inc -I../lib/include -fshort-double 57#help avoid commmon embedded C mistakes 58FLAGS += -Wmissing-declarations -Wlogical-op -Waddress -Wempty-body -Wpointer-arith -Wenum-compare -Wdouble-promotion -Wfloat-equal -Wshadow -fno-strict-aliasing 59 60OSFLAGS += -g -ggdb3 -D_OS_BUILD_ -O2 61APPFLAGS += -Os 62 63#debug mode 64FLAGS += $(DEBUG) 65 66#bootloader pieces 67SRCS_bl += ../lib/nanohub/sha2.c ../lib/nanohub/rsa.c ../lib/nanohub/aes.c src/seos.c 68 69#frameworks 70SRCS_os += src/printf.c src/timer.c src/seos.c src/heap.c src/slab.c src/spi.c src/trylock.c 71SRCS_os += src/hostIntf.c src/hostIntfI2c.c src/hostIntfSpi.c src/nanohubCommand.c src/sensors.c src/syscall.c 72SRCS_os += src/eventQ.c src/osApi.c src/appSec.c src/simpleQ.c src/floatRt.c 73 74#some help for bootloader 75SRCS_bl += src/printf.c 76 77ifndef PLATFORM_HAS_HARDWARE_CRC 78SRCS_os += ../lib/nanohub/softcrc.c 79endif 80 81#app code 82include $(wildcard app/*/Makefile) 83 84 85#extra deps 86DEPS += $(wildcard app/*.h) 87DEPS += $(wildcard inc/*.h) 88DEPS += Makefile $(MAKE_PLAT) $(MAKE_CPU) $(MAKE_VAR) 89 90all: symlinks $(DELIVERABLES) 91 92symlinks: links/p_$(PLATFORM) links/c_$(CPU) links/v_$(VARIANT) 93 94links/p_$(PLATFORM): 95 rm -rf links/plat links/p_* 96 mkdir -p links/plat 97 ln -s ../../misc/platform/$(PLATFORM) links/plat/misc 98 ln -s ../../src/platform/$(PLATFORM) links/plat/src 99 ln -s ../../inc/platform/$(PLATFORM) links/plat/inc 100 touch links/p_$(PLATFORM) 101 102links/c_$(CPU): 103 rm -rf links/cpu links/c_* 104 mkdir -p links/cpu 105 ln -s ../../misc/cpu/$(CPU) links/cpu/misc 106 ln -s ../../src/cpu/$(CPU) links/cpu/src 107 ln -s ../../inc/cpu/$(CPU) links/cpu/inc 108 touch links/c_$(CPU) 109 110links/v_$(VARIANT): 111 rm -rf links/variant links/v_* 112 mkdir -p links/variant 113 ln -s ../../$(LINK_PATH_MISC) links/variant/misc 114 ln -s ../../$(LINK_PATH_SRC) links/variant/src 115 ln -s ../../$(LINK_PATH_INC) links/variant/inc 116 touch links/v_$(VARIANT) 117 118%.unchecked.elf: symlinks $(SRCS_$*) $(DEPS) 119 $(GCC) -o $@ $(SRCS_$*) $(OSFLAGS) $(OSFLAGS_$*) $(FLAGS) -lm -lc -lgcc 120 121%.checked.elf : %.unchecked.elf symcheck.sh 122 ./symcheck.sh $< $@ $(BADWORDS) 123 124full.bin: $(BL_FILE) $(OS_FILE) 125 cat $(BL_FILE) $(OS_FILE) > $@ 126 127clean: 128 rm -rf $(DELIVERABLES) os.elf bootloader.elf links $(CLEANFILES) 129 130