makefile 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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 := -O3 -fno-builtin -finline -Wno-multichar -Wno-unused-parameter -Wno-unused-function -include $(CONFIGHEADER) -include $(VERSIONHEADER)
  42. ifeq ($(EMMC_BOOT),1)
  43. CFLAGS += -D_EMMC_BOOT=1
  44. endif
  45. ifeq ($(SIGNED_KERNEL),1)
  46. CFLAGS += -D_SIGNED_KERNEL=1
  47. endif
  48. ###############################################################################
  49. # Turn on stack-protector for userdebug and eng load.
  50. ###############################################################################
  51. ifneq ($(filter user, $(TARGET_BUILD_VARIANT)),)
  52. # Do nothing!
  53. else ifneq ($(filter userdebug, $(TARGET_BUILD_VARIANT)),)
  54. CFLAGS += -fstack-protector-strong
  55. else ifneq ($(filter eng, $(TARGET_BUILD_VARIANT)),)
  56. CFLAGS += -fstack-protector-strong
  57. endif
  58. # When the host arch is ARM, ensure stack protection code is not emitted since
  59. # it's not supported by the bootloader's libc
  60. #ifneq ($(shell uname -m | grep "arm.*"),)
  61. # CFLAGS += -fno-stack-protector
  62. #endif
  63. CPPFLAGS := -fno-exceptions -fno-rtti -fno-threadsafe-statics
  64. #CPPFLAGS += -Weffc++
  65. ASMFLAGS := -DASSEMBLY
  66. LDFLAGS :=
  67. CFLAGS += -ffunction-sections -fdata-sections
  68. LDFLAGS += -gc-sections
  69. # top level rule
  70. all:: $(OUTBIN) $(OUTELF)-sign.img $(OUTELF).lst $(OUTELF).debug.lst $(OUTELF).sym $(OUTELF).size
  71. # the following three object lists are identical except for the ordering
  72. # which is bootobjs, kobjs, objs
  73. BOOTOBJS :=
  74. OBJS :=
  75. # a linker script needs to be declared in one of the project/target/platform files
  76. LINKER_SCRIPT :=
  77. # anything you add here will be deleted in make clean
  78. GENERATED := $(CONFIGHEADER)
  79. GENERATED += $(VERSIONHEADER)
  80. # anything added to DEFINES will be put into $(BUILDDIR)/config.h
  81. DEFINES := LK=1
  82. # Anything added to SRCDEPS will become a dependency of every source file in the system.
  83. # Useful for header files that may be included by one or more source files.
  84. SRCDEPS := $(CONFIGHEADER)
  85. SRCDEPS += $(VERSIONHEADER)
  86. # these need to be filled out by the project/target/platform rules.mk files
  87. TARGET :=
  88. PLATFORM :=
  89. ARCH :=
  90. MACH_TYPE :=
  91. ALLMODULES :=
  92. MODULES :=
  93. # any rules you put here will also be built by the system before considered being complete
  94. EXTRA_BUILDDEPS :=
  95. # any rules you put here will be depended on in clean builds
  96. EXTRA_CLEANDEPS :=
  97. DRVGEN_OUT := $(BUILDDIR)
  98. PTGEN_OUT := $(BOOTLOADER_OUT)
  99. include project/$(PROJECT).mk
  100. include make/rat_config.mk
  101. include target/$(TARGET)/rules.mk
  102. include dev/rules.mk
  103. include platform/$(PLATFORM)/rules.mk
  104. ifeq ($(MTK_EMMC_SUPPORT), yes)
  105. ifneq ($(filter MTK_NEW_COMBO_EMMC_SUPPORT, $(strip $(DEFINES))),)
  106. DEFINES += PART_DEV_API_V2
  107. #72/82 is old combo, use V1.
  108. else
  109. DEFINES += PART_DEV_API_V1
  110. endif
  111. else ifeq ($(MTK_UFS_SUPPORT), yes)
  112. DEFINES += PART_DEV_API_V2
  113. #nand is only used for mt6580 now, 80 also use V2.
  114. else ifeq ($(MTK_NAND_UBIFS_SUPPORT), yes)
  115. DEFINES += PART_DEV_API_V2
  116. else
  117. DEFINES += PART_DEV_API_V2
  118. endif
  119. ifneq ($(USE_DTB_NO_DWS),yes)
  120. $(info **************** Use DWS ****************)
  121. -include scripts/drvgen/drvgen.mk
  122. else
  123. $(info **************** Use DTB ****************)
  124. endif
  125. -include scripts/ptgen/$(PLATFORM)/ptgen.mk
  126. include arch/$(ARCH)/rules.mk
  127. include platform/pal/rules.mk
  128. include platform/common/rules.mk
  129. include platform/rules.mk
  130. include target/rules.mk
  131. include kernel/rules.mk
  132. include app/rules.mk
  133. # recursively include any modules in the MODULE variable, leaving a trail of included
  134. # modules in the ALLMODULES list
  135. include make/module.mk
  136. # build internal repo(source not release to customer)
  137. include make/build_nonrelease.mk
  138. # any extra top level build dependencies that someone declared
  139. all:: $(EXTRA_BUILDDEPS)
  140. ALLOBJS := \
  141. $(BOOTOBJS) \
  142. $(OBJS)
  143. # add some automatic configuration defines
  144. ifeq ($(findstring MACH_TYPE, $(strip $(DEFINES))),)
  145. DEFINES += MACH_TYPE=$(shell echo $(MACH_TYPE) | tr -dc '0-9')
  146. endif
  147. DEFINES += \
  148. BOARD=$(PROJECT) \
  149. PROJECT_$(PROJECT)=1 \
  150. TARGET_$(TARGET)=1 \
  151. PLATFORM_$(PLATFORM)=1 \
  152. ARCH_$(ARCH)=1 \
  153. MACH_TYPE_$(MACH_TYPE)=1 \
  154. $(addsuffix =1,$(addprefix WITH_,$(ALLMODULES)))
  155. ifeq ($(USE_DTB_NO_DWS),yes)
  156. DEFINES += USE_DTB_NO_DWS
  157. endif
  158. ifeq ($(MTK_EMMC_SUPPORT),yes)
  159. DEFINES += MTK_EMMC_SUPPORT
  160. ifeq ($(MTK_MMC_COMBO_DRV),yes)
  161. DEFINES += MTK_MMC_COMBO_DRV
  162. endif
  163. endif
  164. ifeq ($(MTK_UFS_SUPPORT),yes)
  165. DEFINES += MTK_UFS_SUPPORT
  166. endif
  167. ifeq ($(MNTL_SUPPORT),yes)
  168. DEFINES += MNTL_SUPPORT
  169. ifeq ($(MTK_TLC_NAND_SUPPORT),yes)
  170. DEFINES += MTK_TLC_NAND_SUPPORT
  171. endif
  172. ifeq ($(MTK_MMC_COMBO_DRV),yes)
  173. DEFINES += MTK_MMC_COMBO_DRV
  174. endif
  175. endif
  176. ifeq ($(MTK_UFS_OTP),yes)
  177. DEFINES += MTK_UFS_OTP
  178. endif
  179. ifeq ($(MTK_SECURITY_SW_SUPPORT),yes)
  180. DEFINES += MTK_SECURITY_SW_SUPPORT
  181. endif
  182. ifeq ($(MTK_VERIFIED_BOOT_SUPPORT),yes)
  183. DEFINES += MTK_VERIFIED_BOOT_SUPPORT
  184. endif
  185. ifeq ($(CUSTOM_LK_USB_UNIQUE_SERIAL),yes)
  186. CFLAGS += -DCONFIG_MTK_USB_UNIQUE_SERIAL
  187. endif
  188. # debug build?
  189. ifneq ($(DEBUG),)
  190. DEFINES += \
  191. DEBUG=$(DEBUG)
  192. endif
  193. ALLOBJS := $(addprefix $(BUILDDIR)/,$(ALLOBJS))
  194. ALLOBJS += $(NON_ROBJS)
  195. DEPS := $(ALLOBJS:%o=%d)
  196. INCLUDEDEPS := $(filter-out $(DEPS),$(MAKEFILE_LIST))
  197. SRCDEPS += $(INCLUDEDEPS) make/build.mk arch/$(ARCH)/compile.mk
  198. SRCDEPS += $(EMIGEN_FILE_LIST)
  199. SRCDEPS += $(DRVGEN_FILE_LIST)
  200. SRCDEPS += $(PTGEN_FILE_LIST)
  201. SRCDEPS += $(LOGO_IMAGE)
  202. # default to no ccache
  203. CCACHE ?=
  204. TOOLCHAIN_PREFIX =gcc/bin/arm-linux-androideabi-
  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. clean: $(EXTRA_CLEANDEPS)
  218. rm -f $(ALLOBJS) $(DEPS) $(GENERATED) $(OUTBIN) $(OUTELF) $(OUTELF).lst
  219. install: all
  220. scp $(OUTBIN) 192.168.0.4:/tftproot
  221. # generate a config.h file with all of the DEFINES laid out in #define format
  222. configheader:
  223. $(CONFIGHEADER): configheader
  224. @$(MKDIR)
  225. @echo generating $@
  226. @rm -f $(CONFIGHEADER).tmp; \
  227. echo \#ifndef __CONFIG_H > $(CONFIGHEADER).tmp; \
  228. echo \#define __CONFIG_H >> $(CONFIGHEADER).tmp; \
  229. for d in `echo $(DEFINES) | tr [:lower:] [:upper:]`; do \
  230. echo "#define $$d" | sed "s/=/\ /g;s/-/_/g;s/\//_/g" >> $(CONFIGHEADER).tmp; \
  231. done; \
  232. echo \#endif >> $(CONFIGHEADER).tmp; \
  233. if [ -f "$(CONFIGHEADER)" ]; then \
  234. if cmp "$(CONFIGHEADER).tmp" "$(CONFIGHEADER)"; then \
  235. rm -f $(CONFIGHEADER).tmp; \
  236. else \
  237. mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \
  238. fi \
  239. else \
  240. mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \
  241. fi
  242. LAST_COMMIT_HASH := $(shell git log -1 --pretty=format:%h)
  243. LAST_COMMIT_DATE := $(shell git log -1 --date=format:'%Y%m%d%H%M%S' --pretty=format:"%cd")
  244. BUILD_DATE := $(shell date +'%Y%m%d%H%M%S')
  245. $(VERSIONHEADER): versionheader
  246. @$(MKDIR)
  247. @echo generating $@
  248. @rm -f $(VERSIONHEADER).tmp; \
  249. echo \#ifndef __VERSION_H > $(VERSIONHEADER).tmp; \
  250. echo \#define __VERSION_H >> $(VERSIONHEADER).tmp; \
  251. echo "/* LK_VER_TAG = <PROJECT>-<LAST_COMMIT_HASH>-<LAST_COMMIT_DATE>-<BUILD_DATE> */" >> $(VERSIONHEADER).tmp; \
  252. echo "#define LK_VER_TAG \"$(PROJECT)-$(LAST_COMMIT_HASH)-$(LAST_COMMIT_DATE)-$(BUILD_DATE)\"" >> $(VERSIONHEADER).tmp; \
  253. echo "#define PROJECT \"$(PROJECT)\"" >> $(VERSIONHEADER).tmp; \
  254. echo \#endif >> $(VERSIONHEADER).tmp; \
  255. if [ -f "$(VERSIONHEADER)" ]; then \
  256. if cmp "$(VERSIONHEADER).tmp" "$(VERSIONHEADER)"; then \
  257. rm -f $(VERSIONHEADER).tmp; \
  258. else \
  259. mv $(VERSIONHEADER).tmp $(VERSIONHEADER); \
  260. fi \
  261. else \
  262. mv $(VERSIONHEADER).tmp $(VERSIONHEADER); \
  263. fi
  264. # Empty rule for the .d files. The above rules will build .d files as a side
  265. # effect. Only works on gcc 3.x and above, however.
  266. %.d:
  267. ifeq ($(filter $(MAKECMDGOALS), clean), )
  268. -include $(DEPS)
  269. endif
  270. .PHONY: configheader versionheader
  271. endif
  272. endif # make spotless