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 
     74 #some help for bootloader
     75 SRCS_bl += src/printf.c
     76 
     77 ifndef PLATFORM_HAS_HARDWARE_CRC
     78 SRCS_os += ../lib/nanohub/softcrc.c
     79 endif
     80 
     81 #app code
     82 include $(wildcard app/*/Makefile)
     83 
     84 
     85 #extra deps
     86 DEPS += $(wildcard app/*.h)
     87 DEPS += $(wildcard inc/*.h)
     88 DEPS += Makefile $(MAKE_PLAT) $(MAKE_CPU) $(MAKE_VAR)
     89 
     90 all: symlinks $(DELIVERABLES)
     91 
     92 symlinks: links/p_$(PLATFORM) links/c_$(CPU) links/v_$(VARIANT)
     93 
     94 links/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 
    102 links/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 
    110 links/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) -lgcc -nostdlib
    120 
    121 %.checked.elf : %.unchecked.elf  symcheck.sh
    122 	./symcheck.sh $< $@ $(BADWORDS)
    123 
    124 full.bin: $(BL_FILE) $(OS_FILE)
    125 	cat $(BL_FILE) $(OS_FILE) > $@
    126 
    127 clean:
    128 	rm -rf $(DELIVERABLES) os.elf bootloader.elf links $(CLEANFILES)
    129 
    130