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