makefile 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. ifeq ($(MAKECMDGOALS),spotless)
  2. spotless:
  3. rm -rf build-*
  4. else
  5. -include local.mk
  6. include make/macros.mk
  7. # If one of our goals (from the commandline) happens to have a
  8. # matching project/goal.mk, then we should re-invoke make with
  9. # that project name specified...
  10. project-name := $(firstword $(MAKECMDGOALS))
  11. ifneq ($(project-name),)
  12. ifneq ($(wildcard project/$(project-name).mk),)
  13. do-nothing := 1
  14. $(MAKECMDGOALS) _all: make-make
  15. make-make:
  16. @PROJECT=$(project-name) $(MAKE) $(filter-out $(project-name), $(MAKECMDGOALS))
  17. endif
  18. endif
  19. ifeq ($(do-nothing),)
  20. ifeq ($(PROJECT),)
  21. $(error No project specified. Use "make projectname" or put "PROJECT := projectname" in local.mk)
  22. endif
  23. DEBUG ?= 0
  24. HOST_OS ?= $(shell uname | tr '[A-Z]' '[a-z]')
  25. ifndef BOOTLOADER_OUT
  26. BOOTLOADER_OUT := .
  27. endif
  28. LK_TOP_DIR:= .
  29. BUILDDIR := $(BOOTLOADER_OUT)/build-$(PROJECT)
  30. OUTBIN := $(BUILDDIR)/lk.img
  31. OUTELF := $(BUILDDIR)/lk
  32. CONFIGHEADER := $(BUILDDIR)/config.h
  33. VERSIONHEADER := $(BUILDDIR)/version.h
  34. #Initialize the command-line flag ENABLE_TRUSTZONE. Value for flag passed in at command-line will take precedence
  35. ENABLE_TRUSTZONE := 0
  36. ifeq ($(ENABLE_TRUSTZONE),1)
  37. INPUT_TZ_BIN := tzbsp/tzbsp.bin
  38. OUTPUT_TZ_BIN := $(BUILDDIR)/tzbsp_bin.o
  39. endif
  40. INCLUDES := -I$(BUILDDIR) -Iinclude
  41. CFLAGS := -O2 -g -gdwarf-2 -fno-builtin -finline -W -Wall -Wno-multichar -Wno-unused-parameter -Wno-unused-function -include $(CONFIGHEADER) -include $(VERSIONHEADER)
  42. #CFLAGS += -Werror
  43. ifeq ($(EMMC_BOOT),1)
  44. CFLAGS += -D_EMMC_BOOT=1
  45. endif
  46. ifeq ($(SIGNED_KERNEL),1)
  47. CFLAGS += -D_SIGNED_KERNEL=1
  48. endif
  49. ###############################################################################
  50. # Turn on stack-protector for userdebug and eng load.
  51. ###############################################################################
  52. ifneq ($(filter user, $(TARGET_BUILD_VARIANT)),)
  53. # Do nothing!
  54. else ifneq ($(filter userdebug, $(TARGET_BUILD_VARIANT)),)
  55. CFLAGS += -fstack-protector-strong
  56. else ifneq ($(filter eng, $(TARGET_BUILD_VARIANT)),)
  57. CFLAGS += -fstack-protector-strong
  58. endif
  59. # When the host arch is ARM, ensure stack protection code is not emitted since
  60. # it's not supported by the bootloader's libc
  61. #ifneq ($(shell uname -m | grep "arm.*"),)
  62. # CFLAGS += -fno-stack-protector
  63. #endif
  64. CPPFLAGS := -fno-exceptions -fno-rtti -fno-threadsafe-statics
  65. #CPPFLAGS += -Weffc++
  66. ASMFLAGS := -DASSEMBLY
  67. LDFLAGS :=
  68. CFLAGS += -ffunction-sections -fdata-sections
  69. LDFLAGS += -gc-sections
  70. # top level rule
  71. all:: $(OUTBIN) $(OUTELF)-sign.img $(OUTELF).lst $(OUTELF).debug.lst $(OUTELF).sym $(OUTELF).size
  72. # the following three object lists are identical except for the ordering
  73. # which is bootobjs, kobjs, objs
  74. BOOTOBJS :=
  75. OBJS :=
  76. # a linker script needs to be declared in one of the project/target/platform files
  77. LINKER_SCRIPT :=
  78. # anything you add here will be deleted in make clean
  79. GENERATED := $(CONFIGHEADER)
  80. GENERATED += $(VERSIONHEADER)
  81. # anything added to DEFINES will be put into $(BUILDDIR)/config.h
  82. DEFINES := LK=1
  83. # Anything added to SRCDEPS will become a dependency of every source file in the system.
  84. # Useful for header files that may be included by one or more source files.
  85. SRCDEPS := $(CONFIGHEADER)
  86. SRCDEPS += $(VERSIONHEADER)
  87. # these need to be filled out by the project/target/platform rules.mk files
  88. TARGET :=
  89. PLATFORM :=
  90. ARCH :=
  91. MACH_TYPE :=
  92. ALLMODULES :=
  93. MODULES :=
  94. # any rules you put here will also be built by the system before considered being complete
  95. EXTRA_BUILDDEPS :=
  96. # any rules you put here will be depended on in clean builds
  97. EXTRA_CLEANDEPS :=
  98. DRVGEN_OUT := $(BUILDDIR)
  99. PTGEN_OUT := $(BOOTLOADER_OUT)
  100. include project/$(PROJECT).mk
  101. include make/rat_config.mk
  102. include target/$(TARGET)/rules.mk
  103. include dev/rules.mk
  104. include platform/$(PLATFORM)/rules.mk
  105. ifeq ($(MTK_EMMC_SUPPORT), yes)
  106. ifneq ($(filter MTK_NEW_COMBO_EMMC_SUPPORT, $(strip $(DEFINES))),)
  107. DEFINES += PART_DEV_API_V2
  108. #72/82 is old combo, use V1.
  109. else
  110. DEFINES += PART_DEV_API_V1
  111. endif
  112. else ifeq ($(MTK_UFS_SUPPORT), yes)
  113. DEFINES += PART_DEV_API_V2
  114. #nand is only used for mt6580 now, 80 also use V2.
  115. else ifeq ($(MTK_NAND_UBIFS_SUPPORT), yes)
  116. DEFINES += PART_DEV_API_V2
  117. else
  118. DEFINES += PART_DEV_API_V2
  119. endif
  120. ifneq ($(USE_DTB_NO_DWS),yes)
  121. $(info **************** Use DWS ****************)
  122. -include scripts/drvgen/drvgen.mk
  123. else
  124. $(info **************** Use DTB ****************)
  125. endif
  126. -include scripts/ptgen/$(PLATFORM)/ptgen.mk
  127. include arch/$(ARCH)/rules.mk
  128. include platform/pal/rules.mk
  129. include platform/common/rules.mk
  130. include platform/rules.mk
  131. include target/rules.mk
  132. include kernel/rules.mk
  133. include app/rules.mk
  134. # recursively include any modules in the MODULE variable, leaving a trail of included
  135. # modules in the ALLMODULES list
  136. include make/module.mk
  137. # build internal repo(source not release to customer)
  138. include make/build_nonrelease.mk
  139. # any extra top level build dependencies that someone declared
  140. all:: $(EXTRA_BUILDDEPS)
  141. ALLOBJS := \
  142. $(BOOTOBJS) \
  143. $(OBJS)
  144. # add some automatic configuration defines
  145. ifeq ($(findstring MACH_TYPE, $(strip $(DEFINES))),)
  146. DEFINES += MACH_TYPE=$(shell echo $(MACH_TYPE) | tr -dc '0-9')
  147. endif
  148. DEFINES += \
  149. BOARD=$(PROJECT) \
  150. PROJECT_$(PROJECT)=1 \
  151. TARGET_$(TARGET)=1 \
  152. PLATFORM_$(PLATFORM)=1 \
  153. ARCH_$(ARCH)=1 \
  154. MACH_TYPE_$(MACH_TYPE)=1 \
  155. $(addsuffix =1,$(addprefix WITH_,$(ALLMODULES)))
  156. ifeq ($(USE_DTB_NO_DWS),yes)
  157. DEFINES += USE_DTB_NO_DWS
  158. endif
  159. ifeq ($(MTK_EMMC_SUPPORT),yes)
  160. DEFINES += MTK_EMMC_SUPPORT
  161. ifeq ($(MTK_MMC_COMBO_DRV),yes)
  162. DEFINES += MTK_MMC_COMBO_DRV
  163. endif
  164. endif
  165. ifeq ($(MTK_UFS_SUPPORT),yes)
  166. DEFINES += MTK_UFS_SUPPORT
  167. endif
  168. ifeq ($(MNTL_SUPPORT),yes)
  169. DEFINES += MNTL_SUPPORT
  170. ifeq ($(MTK_TLC_NAND_SUPPORT),yes)
  171. DEFINES += MTK_TLC_NAND_SUPPORT
  172. endif
  173. ifeq ($(MTK_MMC_COMBO_DRV),yes)
  174. DEFINES += MTK_MMC_COMBO_DRV
  175. endif
  176. endif
  177. ifeq ($(MTK_UFS_OTP),yes)
  178. DEFINES += MTK_UFS_OTP
  179. endif
  180. ifeq ($(MTK_SECURITY_SW_SUPPORT),yes)
  181. DEFINES += MTK_SECURITY_SW_SUPPORT
  182. endif
  183. ifeq ($(MTK_VERIFIED_BOOT_SUPPORT),yes)
  184. DEFINES += MTK_VERIFIED_BOOT_SUPPORT
  185. endif
  186. ifeq ($(CUSTOM_LK_USB_UNIQUE_SERIAL),yes)
  187. CFLAGS += -DCONFIG_MTK_USB_UNIQUE_SERIAL
  188. endif
  189. # debug build?
  190. ifneq ($(DEBUG),)
  191. DEFINES += \
  192. DEBUG=$(DEBUG)
  193. endif
  194. ALLOBJS := $(addprefix $(BUILDDIR)/,$(ALLOBJS))
  195. ALLOBJS += $(NON_ROBJS)
  196. DEPS := $(ALLOBJS:%o=%d)
  197. INCLUDEDEPS := $(filter-out $(DEPS),$(MAKEFILE_LIST))
  198. SRCDEPS += $(INCLUDEDEPS) make/build.mk arch/$(ARCH)/compile.mk
  199. SRCDEPS += $(EMIGEN_FILE_LIST)
  200. SRCDEPS += $(DRVGEN_FILE_LIST)
  201. SRCDEPS += $(PTGEN_FILE_LIST)
  202. SRCDEPS += $(LOGO_IMAGE)
  203. # default to no ccache
  204. CCACHE ?=
  205. CC := $(CCACHE) $(TOOLCHAIN_PREFIX)gcc
  206. #LD := $(TOOLCHAIN_PREFIX)ld
  207. LD := $(TOOLCHAIN_PREFIX)ld.bfd
  208. OBJDUMP := $(TOOLCHAIN_PREFIX)objdump
  209. OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy
  210. CPPFILT := $(TOOLCHAIN_PREFIX)c++filt
  211. SIZE := $(TOOLCHAIN_PREFIX)size
  212. NM := $(TOOLCHAIN_PREFIX)nm
  213. # comment out or override if you want to see the full output of each command
  214. NOECHO ?= @
  215. # the logic to compile and link stuff is in here
  216. include make/build.mk
  217. cc-option = $(shell set -e; \
  218. TMP=".$$$$.tmp"; \
  219. TMPO=".$$$$.o"; \
  220. if ($(CC) -Werror $(1) -c -x c /dev/null -o "$$TMP") >/dev/null 2>&1; \
  221. then echo "$(1)"; \
  222. else echo "$(2)"; \
  223. fi; \
  224. rm -f "$$TMP" "$$TMPO")
  225. ifeq ("$(UBSAN_SUPPORT)", "yes")
  226. CFLAGS += $(call cc-option, -fsanitize=shift)
  227. CFLAGS += $(call cc-option, -fsanitize=integer-divide-by-zero)
  228. CFLAGS += $(call cc-option, -fsanitize=unreachable)
  229. CFLAGS += $(call cc-option, -fsanitize=signed-integer-overflow)
  230. CFLAGS += $(call cc-option, -fsanitize=bounds)
  231. CFLAGS += $(call cc-option, -fsanitize=object-size)
  232. CFLAGS += $(call cc-option, -fsanitize=returns-nonnull-attribute)
  233. CFLAGS += $(call cc-option, -fsanitize=bool)
  234. CFLAGS += $(call cc-option, -fsanitize=enum)
  235. CFLAGS += $(call cc-option, -fsanitize=alignment)
  236. #CFLAGS += $(call cc-option, -fsanitize=null) # cause lk size enlarge 1.3x
  237. CFLAGS += $(call cc-option, -Wno-maybe-uninitialized)
  238. endif
  239. clean: $(EXTRA_CLEANDEPS)
  240. rm -f $(ALLOBJS) $(DEPS) $(GENERATED) $(OUTBIN) $(OUTELF) $(OUTELF).lst
  241. install: all
  242. scp $(OUTBIN) 192.168.0.4:/tftproot
  243. # generate a config.h file with all of the DEFINES laid out in #define format
  244. configheader:
  245. $(CONFIGHEADER): configheader
  246. @$(MKDIR)
  247. @echo generating $@
  248. @rm -f $(CONFIGHEADER).tmp; \
  249. echo \#ifndef __CONFIG_H > $(CONFIGHEADER).tmp; \
  250. echo \#define __CONFIG_H >> $(CONFIGHEADER).tmp; \
  251. for d in `echo $(DEFINES) | tr [:lower:] [:upper:]`; do \
  252. echo "#define $$d" | sed "s/=/\ /g;s/-/_/g;s/\//_/g" >> $(CONFIGHEADER).tmp; \
  253. done; \
  254. echo \#endif >> $(CONFIGHEADER).tmp; \
  255. if [ -f "$(CONFIGHEADER)" ]; then \
  256. if cmp "$(CONFIGHEADER).tmp" "$(CONFIGHEADER)"; then \
  257. rm -f $(CONFIGHEADER).tmp; \
  258. else \
  259. mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \
  260. fi \
  261. else \
  262. mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \
  263. fi
  264. LAST_COMMIT_HASH := $(shell git log -1 --pretty=format:%h)
  265. LAST_COMMIT_DATE := $(shell git log -1 --date=format:'%Y%m%d%H%M%S' --pretty=format:"%cd")
  266. BUILD_DATE := $(shell date +'%Y%m%d%H%M%S')
  267. $(VERSIONHEADER): versionheader
  268. @$(MKDIR)
  269. @echo generating $@
  270. @rm -f $(VERSIONHEADER).tmp; \
  271. echo \#ifndef __VERSION_H > $(VERSIONHEADER).tmp; \
  272. echo \#define __VERSION_H >> $(VERSIONHEADER).tmp; \
  273. echo "/* LK_VER_TAG = <PROJECT>-<LAST_COMMIT_HASH>-<LAST_COMMIT_DATE>-<BUILD_DATE> */" >> $(VERSIONHEADER).tmp; \
  274. echo "#define LK_VER_TAG \"$(PROJECT)-$(LAST_COMMIT_HASH)-$(LAST_COMMIT_DATE)-$(BUILD_DATE)\"" >> $(VERSIONHEADER).tmp; \
  275. echo "#define PROJECT \"$(PROJECT)\"" >> $(VERSIONHEADER).tmp; \
  276. echo \#endif >> $(VERSIONHEADER).tmp; \
  277. if [ -f "$(VERSIONHEADER)" ]; then \
  278. if cmp "$(VERSIONHEADER).tmp" "$(VERSIONHEADER)"; then \
  279. rm -f $(VERSIONHEADER).tmp; \
  280. else \
  281. mv $(VERSIONHEADER).tmp $(VERSIONHEADER); \
  282. fi \
  283. else \
  284. mv $(VERSIONHEADER).tmp $(VERSIONHEADER); \
  285. fi
  286. # Empty rule for the .d files. The above rules will build .d files as a side
  287. # effect. Only works on gcc 3.x and above, however.
  288. %.d:
  289. ifeq ($(filter $(MAKECMDGOALS), clean), )
  290. -include $(DEPS)
  291. endif
  292. .PHONY: configheader versionheader
  293. endif
  294. endif # make spotless