Makefile 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552
  1. # Copyright 2013 The Chromium OS Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. # This Makefile normally builds in a 'build' subdir, but use
  5. #
  6. # make BUILD=<dir>
  7. #
  8. # to put the output somewhere else.
  9. ##############################################################################
  10. # Make variables come in two flavors, immediate or deferred.
  11. #
  12. # Variable definitions are parsed like this:
  13. #
  14. # IMMEDIATE = DEFERRED
  15. # or
  16. # IMMEDIATE := IMMEDIATE
  17. #
  18. # Rules are parsed this way:
  19. #
  20. # IMMEDIATE : IMMEDIATE
  21. # DEFERRED
  22. #
  23. # So you can assign variables in any order if they're only to be used in
  24. # actions, but if you use a variable in either the target or prerequisite of a
  25. # rule, the rule will be constructed using only the top-down, immediate value.
  26. #
  27. # So we'll try to define all the variables first. Then the rules.
  28. #
  29. ##############################################################################
  30. # Configuration variables come first.
  31. #
  32. # Our convention is that we only use := for variables that will never be
  33. # changed or appended. They must be defined before being used anywhere.
  34. # We should only run pwd once, not every time we refer to ${BUILD}.
  35. SRCDIR := $(shell pwd)
  36. export SRCDIR
  37. BUILD = ${SRCDIR}/build
  38. export BUILD
  39. # Stuff for 'make install'
  40. INSTALL = install
  41. DESTDIR = /usr/local
  42. LIBDIR ?= lib
  43. # Default values
  44. DEV_DEBUG_FORCE=
  45. # Where exactly do the pieces go?
  46. # UB_DIR = utility binary directory
  47. # ULP_DIR = pkgconfig directory, usually /usr/lib/pkgconfig
  48. # UI_DIR = include directory for library headers
  49. # US_DIR = shared data directory (for static content like devkeys)
  50. # DF_DIR = utility defaults directory
  51. # VB_DIR = vboot binary directory for dev-mode-only scripts
  52. ifeq (${MINIMAL},)
  53. # Host install just puts everything where it's told
  54. UB_DIR=${DESTDIR}/bin
  55. UL_DIR=${DESTDIR}/${LIBDIR}
  56. ULP_DIR=${UL_DIR}/pkgconfig
  57. UI_DIR=${DESTDIR}/include/vboot
  58. US_DIR=${DESTDIR}/share/vboot
  59. DF_DIR=${DESTDIR}/default
  60. VB_DIR=${DESTDIR}/bin
  61. else
  62. # Target install puts things into different places
  63. UB_DIR=${DESTDIR}/usr/bin
  64. UL_DIR=${DESTDIR}/usr/${LIBDIR}
  65. ULP_DIR=${UL_DIR}/pkgconfig
  66. UI_DIR=${DESTDIR}/usr/include/vboot
  67. US_DIR=${DESTDIR}/usr/share/vboot
  68. DF_DIR=${DESTDIR}/etc/default
  69. VB_DIR=${US_DIR}/bin
  70. endif
  71. # Where to install the (exportable) executables for testing?
  72. TEST_INSTALL_DIR = ${BUILD}/install_for_test
  73. # Verbose? Use V=1
  74. ifeq (${V},)
  75. Q := @
  76. endif
  77. # Quiet? Use QUIET=1
  78. ifeq (${QUIET},)
  79. PRINTF := printf
  80. else
  81. PRINTF := :
  82. endif
  83. # Architecture detection
  84. _machname := $(shell uname -m)
  85. HOST_ARCH ?= ${_machname}
  86. # ARCH and/or FIRMWARE_ARCH are defined by the Chromium OS ebuild.
  87. # Pick a sane target architecture if none is defined.
  88. ifeq (${ARCH},)
  89. ARCH := ${HOST_ARCH}
  90. endif
  91. ifeq (${ARCH},armv7l)
  92. override ARCH := arm
  93. else ifeq (${ARCH},i386)
  94. override ARCH := x86
  95. else ifeq (${ARCH},amd64)
  96. override ARCH := x86_64
  97. endif
  98. # FIRMWARE_ARCH is only defined by the Chromium OS ebuild if compiling
  99. # for a firmware target (such as u-boot or depthcharge). It must map
  100. # to the same consistent set of architectures as the host.
  101. ifeq (${FIRMWARE_ARCH},i386)
  102. override FIRMWARE_ARCH := x86
  103. else ifeq (${FIRMWARE_ARCH},amd64)
  104. override FIRMWARE_ARCH := x86_64
  105. else ifeq (${FIRMWARE_ARCH},armv7)
  106. override FIRMWARE_ARCH := arm
  107. endif
  108. # Provide default CC and CFLAGS for firmware builds; if you have any -D flags,
  109. # please add them after this point (e.g., -DVBOOT_DEBUG).
  110. #
  111. # TODO(crosbug.com/16808) We hard-code u-boot's compiler flags here just
  112. # temporarily. As we are still investigating which flags are necessary for
  113. # maintaining a compatible ABI, etc. between u-boot and vboot_reference.
  114. #
  115. # As a first step, this makes the setting of CC and CFLAGS here optional, to
  116. # permit a calling script or Makefile to set these.
  117. #
  118. # Flag ordering: arch, then -f, then -m, then -W
  119. DEBUG_FLAGS := $(if ${DEBUG},-g -O0,-Os)
  120. WERROR := -Werror
  121. COMMON_FLAGS := -nostdinc -pipe \
  122. -ffreestanding -fno-builtin -fno-stack-protector \
  123. ${WERROR} -Wall -Wstrict-prototypes ${DEBUG_FLAGS}
  124. # Note: FIRMWARE_ARCH is defined by the Chromium OS ebuild.
  125. ifeq (${FIRMWARE_ARCH}, arm)
  126. CC ?= armv7a-cros-linux-gnueabi-gcc
  127. CFLAGS ?= -march=armv5 \
  128. -fno-common -ffixed-r8 \
  129. -mfloat-abi=hard -marm -mabi=aapcs-linux -mno-thumb-interwork \
  130. ${COMMON_FLAGS}
  131. else ifeq (${FIRMWARE_ARCH}, x86)
  132. CC ?= i686-pc-linux-gnu-gcc
  133. # Drop -march=i386 to permit use of SSE instructions
  134. CFLAGS ?= \
  135. -ffunction-sections -fvisibility=hidden -fno-strict-aliasing \
  136. -fomit-frame-pointer -fno-toplevel-reorder -fno-dwarf2-cfi-asm \
  137. -mpreferred-stack-boundary=2 \
  138. ${COMMON_FLAGS}
  139. else ifeq (${FIRMWARE_ARCH}, x86_64)
  140. CFLAGS ?= ${COMMON_FLAGS} \
  141. -fvisibility=hidden -fno-strict-aliasing -fomit-frame-pointer
  142. else
  143. # FIRMWARE_ARCH not defined; assuming local compile.
  144. CC ?= gcc
  145. CFLAGS += -DCHROMEOS_ENVIRONMENT -Wall ${WERROR} ${DEBUG_FLAGS}
  146. endif
  147. ifneq (${CUSTOM_MUSIC},)
  148. CFLAGS += -DCUSTOM_MUSIC
  149. endif
  150. ifneq (${DEBUG},)
  151. CFLAGS += -DVBOOT_DEBUG
  152. endif
  153. ifeq (${DISABLE_NDEBUG},)
  154. CFLAGS += -DNDEBUG
  155. endif
  156. ifneq (${FORCE_LOGGING_ON},)
  157. CFLAGS += -DFORCE_LOGGING_ON=${FORCE_LOGGING_ON}
  158. endif
  159. ifneq (${PD_SYNC},)
  160. CFLAGS += -DPD_SYNC
  161. endif
  162. ifneq (${USE_MTD},)
  163. CFLAGS += -DUSE_MTD
  164. LDLIBS += -lmtdutils
  165. endif
  166. ifneq (${TPM2_MODE},)
  167. CFLAGS += -DTPM2_MODE
  168. endif
  169. # NOTE: We don't use these files but they are useful for other packages to
  170. # query about required compiling/linking flags.
  171. PC_IN_FILES = vboot_host.pc.in
  172. # Create / use dependency files
  173. CFLAGS += -MMD -MF $@.d
  174. ifeq (${FIRMWARE_ARCH},)
  175. # Creates position independent code for non firmware target.
  176. CFLAGS += -fPIE
  177. endif
  178. # These are required to access large disks and files on 32-bit systems.
  179. CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
  180. # Code coverage
  181. ifneq (${COV},)
  182. COV_FLAGS = -O0 --coverage -DCOVERAGE
  183. CFLAGS += ${COV_FLAGS}
  184. LDFLAGS += ${COV_FLAGS}
  185. COV_INFO = ${BUILD}/coverage.info
  186. endif
  187. ifdef HAVE_MACOS
  188. CFLAGS += -DHAVE_MACOS -Wno-deprecated-declarations
  189. endif
  190. # Musl doesn't have execinfo.h.
  191. ifndef HAVE_MUSL
  192. CFLAGS += -DHAVE_EXECINFO_H
  193. endif
  194. # And a few more default utilities
  195. LD = ${CC}
  196. CXX ?= g++
  197. PKG_CONFIG ?= pkg-config
  198. # Static?
  199. ifneq (${STATIC},)
  200. LDFLAGS += -static
  201. PKG_CONFIG += --static
  202. endif
  203. # Determine QEMU architecture needed, if any
  204. ifeq (${ARCH},${HOST_ARCH})
  205. # Same architecture; no need for QEMU
  206. QEMU_ARCH :=
  207. else ifeq (${HOST_ARCH}-${ARCH},x86_64-x86)
  208. # 64-bit host can run 32-bit targets directly
  209. QEMU_ARCH :=
  210. else
  211. QEMU_ARCH := ${ARCH}
  212. endif
  213. # The top of the chroot for qemu must be passed in via the SYSROOT environment
  214. # variable. In the Chromium OS chroot, this is done automatically by the
  215. # ebuild.
  216. ifeq (${QEMU_ARCH},)
  217. # Path to build output for running tests is same as for building
  218. BUILD_RUN = ${BUILD}
  219. SRC_RUN = ${SRCDIR}
  220. else
  221. $(info Using qemu for testing.)
  222. # Path to build output for running tests is different in the chroot
  223. BUILD_RUN = $(subst ${SYSROOT},,${BUILD})
  224. SRC_RUN = $(subst ${SYSROOT},,${SRCDIR})
  225. QEMU_BIN = qemu-${QEMU_ARCH}
  226. QEMU_RUN = ${BUILD_RUN}/${QEMU_BIN}
  227. export QEMU_RUN
  228. RUNTEST = tests/test_using_qemu.sh
  229. endif
  230. export BUILD_RUN
  231. ##############################################################################
  232. # The default target is here, to allow dependencies to be expressed below
  233. # without accidentally changing the default target.
  234. # Default target.
  235. .PHONY: all
  236. all: fwlib fwlib2x fwlib20 fwlib21 \
  237. $(if ${FIRMWARE_ARCH},,host_stuff) \
  238. $(if ${COV},coverage)
  239. ##############################################################################
  240. # Now we need to describe everything we might want or need to build
  241. # Everything wants these headers.
  242. INCLUDES += \
  243. -Ifirmware/include \
  244. -Ifirmware/lib/include \
  245. -Ifirmware/lib/cgptlib/include \
  246. -Ifirmware/lib/cryptolib/include \
  247. -Ifirmware/lib/tpm_lite/include \
  248. -Ifirmware/2lib/include \
  249. -Ifirmware/lib20/include
  250. # If we're not building for a specific target, just stub out things like the
  251. # TPM commands and various external functions that are provided by the BIOS.
  252. ifeq (${FIRMWARE_ARCH},)
  253. INCLUDES += -Ihost/include -Ihost/lib/include
  254. INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include
  255. endif
  256. # Firmware library, used by the other firmware components (depthcharge,
  257. # coreboot, etc.). It doesn't need exporting to some other place; they'll build
  258. # this source tree locally and link to it directly.
  259. FWLIB = ${BUILD}/vboot_fw.a
  260. # Smaller firmware library common to all vboot 2.x, used only for
  261. # 1) compile-time tests of the public API or
  262. # 2) linking with an actual 2.0 or 2.1 implementation
  263. FWLIB2X = ${BUILD}/vboot_fw2x.a
  264. # Vboot 2.0 (deprecated - see firmware/README)
  265. FWLIB20 = ${BUILD}/vboot_fw20.a
  266. # Vboot 2.1 (not yet ready - see firmware/README)
  267. FWLIB21 = ${BUILD}/vboot_fw21.a
  268. # Static library containing firmware APIs for common boot flow
  269. BDBLIB = ${BUILD}/bdb.a
  270. # Firmware library sources needed by VbInit() call
  271. VBINIT_SRCS = \
  272. firmware/lib/vboot_common_init.c \
  273. firmware/lib/vboot_nvstorage.c \
  274. firmware/lib/region-init.c \
  275. # Additional firmware library sources needed by VbSelectFirmware() call
  276. VBSF_SRCS = \
  277. firmware/lib/vboot_common.c \
  278. firmware/lib/region-fw.c \
  279. # Additional firmware library sources needed by VbSelectAndLoadKernel() call
  280. VBSLK_SRCS = \
  281. firmware/lib/cgptlib/cgptlib.c \
  282. firmware/lib/cgptlib/cgptlib_internal.c \
  283. firmware/lib/cgptlib/crc32.c \
  284. firmware/lib/ec_sync.c \
  285. firmware/lib/ec_sync_all.c \
  286. firmware/lib/gpt_misc.c \
  287. firmware/lib/utility_string.c \
  288. firmware/lib/vboot_api_kernel.c \
  289. firmware/lib/vboot_audio.c \
  290. firmware/lib/vboot_display.c \
  291. firmware/lib/vboot_kernel.c \
  292. firmware/lib/vboot_ui.c \
  293. firmware/lib/vboot_ui_menu.c \
  294. firmware/lib/region-kernel.c \
  295. # Code common to both vboot 2.0 (old structs) and 2.1 (new structs)
  296. FWLIB2X_SRCS = \
  297. firmware/2lib/2api.c \
  298. firmware/2lib/2common.c \
  299. firmware/2lib/2crc8.c \
  300. firmware/2lib/2misc.c \
  301. firmware/2lib/2nvstorage.c \
  302. firmware/2lib/2rsa.c \
  303. firmware/2lib/2secdata.c \
  304. firmware/2lib/2secdatak.c \
  305. firmware/2lib/2sha1.c \
  306. firmware/2lib/2sha256.c \
  307. firmware/2lib/2sha512.c \
  308. firmware/2lib/2sha_utility.c \
  309. firmware/2lib/2tpm_bootmode.c \
  310. firmware/2lib/2hmac.c
  311. FWLIB20_SRCS = \
  312. firmware/lib20/api.c \
  313. firmware/lib20/api_kernel.c \
  314. firmware/lib20/common.c \
  315. firmware/lib20/kernel.c \
  316. firmware/lib20/misc.c \
  317. firmware/lib20/packed_key.c
  318. FWLIB21_SRCS = \
  319. firmware/lib21/api.c \
  320. firmware/lib21/common.c \
  321. firmware/lib21/misc.c \
  322. firmware/lib21/packed_key.c
  323. BDBLIB_SRCS = \
  324. firmware/bdb/bdb.c \
  325. firmware/bdb/ecdsa.c \
  326. firmware/bdb/misc.c \
  327. firmware/bdb/rsa.c \
  328. firmware/bdb/secrets.c \
  329. firmware/bdb/sha.c \
  330. firmware/bdb/stub.c \
  331. firmware/bdb/nvm.c
  332. # TPM lightweight command library
  333. ifeq (${TPM2_MODE},)
  334. TLCL_SRCS = \
  335. firmware/lib/tpm_lite/tlcl.c
  336. else
  337. TLCL_SRCS = \
  338. firmware/lib/tpm2_lite/tlcl.c \
  339. firmware/lib/tpm2_lite/marshaling.c
  340. endif
  341. TLCL_OBJS_FOR_TEST = $(TLCL_SRCS:%.c=${BUILD}/%_for_test.o)
  342. # Support real TPM unless BIOS sets MOCK_TPM
  343. ifeq (${MOCK_TPM},)
  344. VBINIT_SRCS += \
  345. firmware/lib/rollback_index.c \
  346. ${TLCL_SRCS}
  347. else
  348. VBINIT_SRCS += \
  349. firmware/lib/mocked_rollback_index.c \
  350. firmware/lib/tpm_lite/mocked_tlcl.c
  351. endif
  352. ifeq (${FIRMWARE_ARCH},)
  353. # Include BIOS stubs in the firmware library when compiling for host
  354. # TODO: split out other stub funcs too
  355. VBINIT_SRCS += \
  356. firmware/stub/tpm_lite_stub.c \
  357. firmware/stub/vboot_api_stub_init.c \
  358. firmware/stub/vboot_api_stub_region.c
  359. VBSLK_SRCS += \
  360. firmware/stub/vboot_api_stub.c \
  361. firmware/stub/vboot_api_stub_disk.c \
  362. firmware/stub/vboot_api_stub_stream.c
  363. FWLIB2X_SRCS += \
  364. firmware/2lib/2stub.c
  365. endif
  366. VBSF_SRCS += ${VBINIT_SRCS}
  367. FWLIB_SRCS += ${VBSF_SRCS} ${VBSLK_SRCS}
  368. VBINIT_OBJS = ${VBINIT_SRCS:%.c=${BUILD}/%.o}
  369. VBSF_OBJS = ${VBSF_SRCS:%.c=${BUILD}/%.o}
  370. ALL_OBJS += ${VBINIT_OBJS} ${VBSF_OBJS}
  371. FWLIB_OBJS = ${FWLIB_SRCS:%.c=${BUILD}/%.o}
  372. FWLIB2X_OBJS = ${FWLIB2X_SRCS:%.c=${BUILD}/%.o}
  373. FWLIB20_OBJS = ${FWLIB20_SRCS:%.c=${BUILD}/%.o}
  374. FWLIB21_OBJS = ${FWLIB21_SRCS:%.c=${BUILD}/%.o}
  375. BDBLIB_OBJS = ${BDBLIB_SRCS:%.c=${BUILD}/%.o}
  376. ALL_OBJS += ${FWLIB_OBJS} ${FWLIB2X_OBJS} ${FWLIB20_OBJS} ${FWLIB21_OBJS} \
  377. $(BDBLIB_OBJS}
  378. # Intermediate library for the vboot_reference utilities to link against.
  379. UTILLIB = ${BUILD}/libvboot_util.a
  380. # Static library containing both host and firmware APIs
  381. UTILBDB = ${BUILD}/libvboot_utilbdb.a
  382. UTILLIB_SRCS = \
  383. cgpt/cgpt_create.c \
  384. cgpt/cgpt_add.c \
  385. cgpt/cgpt_boot.c \
  386. cgpt/cgpt_show.c \
  387. cgpt/cgpt_repair.c \
  388. cgpt/cgpt_prioritize.c \
  389. cgpt/cgpt_common.c \
  390. futility/dump_kernel_config_lib.c \
  391. host/arch/${ARCH}/lib/crossystem_arch.c \
  392. host/lib/crossystem.c \
  393. host/lib/file_keys.c \
  394. host/lib/fmap.c \
  395. host/lib/host_common.c \
  396. host/lib/host_key.c \
  397. host/lib/host_key2.c \
  398. host/lib/host_keyblock.c \
  399. host/lib/host_misc.c \
  400. host/lib/util_misc.c \
  401. host/lib/host_signature.c \
  402. host/lib/host_signature2.c \
  403. host/lib/signature_digest.c \
  404. host/lib21/host_fw_preamble.c \
  405. host/lib21/host_key.c \
  406. host/lib21/host_keyblock.c \
  407. host/lib21/host_misc.c \
  408. host/lib21/host_signature.c
  409. UTILLIB_OBJS = ${UTILLIB_SRCS:%.c=${BUILD}/%.o}
  410. ALL_OBJS += ${UTILLIB_OBJS}
  411. # Source files containing host side APIs for common boot flow
  412. UTILBDB_SRCS += \
  413. firmware/bdb/host.c
  414. UTILBDB_OBJS = ${UTILBDB_SRCS:%.c=${BUILD}/%.o}
  415. ALL_OBJS += ${UTILBDB_OBJS}
  416. # Externally exported library for some target userspace apps to link with
  417. # (cryptohome, updater, etc.)
  418. HOSTLIB = ${BUILD}/libvboot_host.a
  419. HOSTLIB_SRCS = \
  420. cgpt/cgpt_add.c \
  421. cgpt/cgpt_boot.c \
  422. cgpt/cgpt_common.c \
  423. cgpt/cgpt_create.c \
  424. cgpt/cgpt_prioritize.c \
  425. firmware/2lib/2crc8.c \
  426. firmware/2lib/2stub.c \
  427. firmware/lib/cgptlib/cgptlib_internal.c \
  428. firmware/lib/cgptlib/crc32.c \
  429. firmware/lib/gpt_misc.c \
  430. ${TLCL_SRCS} \
  431. firmware/lib/utility_string.c \
  432. firmware/lib/vboot_nvstorage.c \
  433. firmware/stub/tpm_lite_stub.c \
  434. firmware/stub/vboot_api_stub.c \
  435. firmware/stub/vboot_api_stub_disk.c \
  436. firmware/stub/vboot_api_stub_init.c \
  437. futility/dump_kernel_config_lib.c \
  438. host/arch/${ARCH}/lib/crossystem_arch.c \
  439. host/lib/crossystem.c \
  440. host/lib/extract_vmlinuz.c \
  441. host/lib/fmap.c \
  442. host/lib/host_misc.c
  443. HOSTLIB_OBJS = ${HOSTLIB_SRCS:%.c=${BUILD}/%.o}
  444. ALL_OBJS += ${HOSTLIB_OBJS}
  445. # Sigh. For historical reasons, the autoupdate installer must sometimes be a
  446. # 32-bit executable, even when everything else is 64-bit. But it only needs a
  447. # few functions, so let's just build those.
  448. TINYHOSTLIB = ${BUILD}/libtinyvboot_host.a
  449. TINYHOSTLIB_SRCS = \
  450. cgpt/cgpt_add.c \
  451. cgpt/cgpt_boot.c \
  452. cgpt/cgpt_common.c \
  453. cgpt/cgpt_create.c \
  454. cgpt/cgpt_prioritize.c \
  455. firmware/2lib/2crc8.c \
  456. firmware/lib/cgptlib/cgptlib_internal.c \
  457. firmware/lib/cgptlib/crc32.c \
  458. firmware/lib/gpt_misc.c \
  459. firmware/lib/utility_string.c \
  460. firmware/stub/vboot_api_stub.c \
  461. firmware/stub/vboot_api_stub_disk.c \
  462. futility/dump_kernel_config_lib.c \
  463. host/lib/extract_vmlinuz.c
  464. TINYHOSTLIB_OBJS = ${TINYHOSTLIB_SRCS:%.c=${BUILD}/%.o}
  465. # ----------------------------------------------------------------------------
  466. # Now for the userspace binaries
  467. CGPT = ${BUILD}/cgpt/cgpt
  468. CGPT_SRCS = \
  469. cgpt/cgpt.c \
  470. cgpt/cgpt_add.c \
  471. cgpt/cgpt_boot.c \
  472. cgpt/cgpt_common.c \
  473. cgpt/cgpt_create.c \
  474. cgpt/cgpt_find.c \
  475. cgpt/cgpt_legacy.c \
  476. cgpt/cgpt_nor.c \
  477. cgpt/cgpt_prioritize.c \
  478. cgpt/cgpt_repair.c \
  479. cgpt/cgpt_show.c \
  480. cgpt/cmd_add.c \
  481. cgpt/cmd_boot.c \
  482. cgpt/cmd_create.c \
  483. cgpt/cmd_find.c \
  484. cgpt/cmd_legacy.c \
  485. cgpt/cmd_prioritize.c \
  486. cgpt/cmd_repair.c \
  487. cgpt/cmd_show.c
  488. CGPT_OBJS = ${CGPT_SRCS:%.c=${BUILD}/%.o}
  489. ALL_OBJS += ${CGPT_OBJS}
  490. CGPT_WRAPPER = ${BUILD}/cgpt/cgpt_wrapper
  491. CGPT_WRAPPER_SRCS = \
  492. cgpt/cgpt_nor.c \
  493. cgpt/cgpt_wrapper.c
  494. CGPT_WRAPPER_OBJS = ${CGPT_WRAPPER_SRCS:%.c=${BUILD}/%.o}
  495. ALL_OBJS += ${CGPT_WRAPPER_OBJS}
  496. # Utility defaults
  497. UTIL_DEFAULTS = ${BUILD}/default/vboot_reference
  498. # Scripts to install directly (not compiled)
  499. UTIL_SCRIPTS = \
  500. utility/dev_debug_vboot \
  501. utility/enable_dev_usb_boot
  502. ifeq (${MINIMAL},)
  503. UTIL_SCRIPTS += \
  504. utility/dev_make_keypair \
  505. utility/vbutil_what_keys
  506. endif
  507. # These utilities should be linked statically.
  508. UTIL_NAMES_STATIC = \
  509. utility/crossystem
  510. UTIL_NAMES = ${UTIL_NAMES_STATIC} \
  511. utility/dumpRSAPublicKey \
  512. utility/tpmc
  513. ifeq (${TPM2_MODE},)
  514. UTIL_NAMES += utility/tpm_init_temp_fix
  515. endif
  516. # TODO: Do we still need eficompress and efidecompress for anything?
  517. ifeq (${MINIMAL},)
  518. UTIL_NAMES += \
  519. utility/bdb_extend \
  520. utility/bmpblk_font \
  521. utility/bmpblk_utility \
  522. utility/eficompress \
  523. utility/efidecompress \
  524. utility/load_kernel_test \
  525. utility/pad_digest_utility \
  526. utility/signature_digest_utility \
  527. utility/verify_data
  528. LZMA_LIBS := $(shell ${PKG_CONFIG} --libs liblzma)
  529. YAML_LIBS := $(shell ${PKG_CONFIG} --libs yaml-0.1)
  530. endif
  531. UTIL_BINS_STATIC := $(addprefix ${BUILD}/,${UTIL_NAMES_STATIC})
  532. UTIL_BINS = $(addprefix ${BUILD}/,${UTIL_NAMES})
  533. ALL_OBJS += $(addsuffix .o,${UTIL_BINS} ${UTIL_BINS_STATIC})
  534. # Scripts for signing stuff.
  535. SIGNING_SCRIPTS = \
  536. utility/tpm-nvsize \
  537. utility/chromeos-tpm-recovery
  538. # These go in a different place.
  539. SIGNING_SCRIPTS_DEV = \
  540. scripts/image_signing/resign_firmwarefd.sh \
  541. scripts/image_signing/make_dev_firmware.sh \
  542. scripts/image_signing/make_dev_ssd.sh \
  543. scripts/image_signing/set_gbb_flags.sh
  544. # Installed, but not made executable.
  545. SIGNING_COMMON = scripts/image_signing/common_minimal.sh
  546. # The unified firmware utility will eventually replace all the others
  547. FUTIL_BIN = ${BUILD}/futility/futility
  548. # But we still need both static (tiny) and dynamic (with openssl) versions.
  549. FUTIL_STATIC_BIN = ${FUTIL_BIN}_s
  550. # These are the executables that are now built in to futility. We'll create
  551. # symlinks for these so the old names will still work.
  552. FUTIL_SYMLINKS = \
  553. dump_fmap \
  554. dump_kernel_config \
  555. gbb_utility \
  556. vbutil_firmware \
  557. vbutil_kernel \
  558. vbutil_key \
  559. vbutil_keyblock
  560. FUTIL_STATIC_SRCS = \
  561. futility/futility.c \
  562. futility/cmd_dump_fmap.c \
  563. futility/cmd_gbb_utility.c \
  564. futility/misc.c \
  565. futility/ryu_root_header.c
  566. FUTIL_SRCS = \
  567. ${FUTIL_STATIC_SRCS} \
  568. futility/cmd_bdb.c \
  569. futility/cmd_create.c \
  570. futility/cmd_dump_kernel_config.c \
  571. futility/cmd_load_fmap.c \
  572. futility/cmd_pcr.c \
  573. futility/cmd_show.c \
  574. futility/cmd_sign.c \
  575. futility/cmd_validate_rec_mrc.c \
  576. futility/cmd_vbutil_firmware.c \
  577. futility/cmd_vbutil_kernel.c \
  578. futility/cmd_vbutil_key.c \
  579. futility/cmd_vbutil_keyblock.c \
  580. futility/file_type.c \
  581. futility/file_type_bios.c \
  582. futility/file_type_rwsig.c \
  583. futility/file_type_usbpd1.c \
  584. futility/vb1_helper.c \
  585. futility/vb2_helper.c \
  586. futility/bdb_helper.c
  587. # List of commands built in futility and futility_s.
  588. FUTIL_STATIC_CMD_LIST = ${BUILD}/gen/futility_static_cmds.c
  589. FUTIL_CMD_LIST = ${BUILD}/gen/futility_cmds.c
  590. FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o} \
  591. ${FUTIL_STATIC_CMD_LIST:%.c=%.o}
  592. FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o} ${FUTIL_CMD_LIST:%.c=%.o}
  593. ${FUTIL_OBJS}: INCLUDES += -Ihost/lib21/include -Ifirmware/lib21/include \
  594. -Ifirmware/bdb
  595. ALL_OBJS += ${FUTIL_OBJS}
  596. # Library of handy test functions.
  597. TESTLIB = ${BUILD}/tests/test.a
  598. TESTLIB_SRCS = \
  599. tests/test_common.c \
  600. tests/timer_utils.c \
  601. tests/crc32_test.c
  602. TESTLIB_OBJS = ${TESTLIB_SRCS:%.c=${BUILD}/%.o}
  603. TEST_OBJS += ${TESTLIB_OBJS}
  604. # And some compiled tests.
  605. TEST_NAMES = \
  606. tests/cgptlib_test \
  607. tests/ec_sync_tests \
  608. tests/rollback_index3_tests \
  609. tests/sha_benchmark \
  610. tests/utility_string_tests \
  611. tests/utility_tests \
  612. tests/vboot_api_devmode_tests \
  613. tests/vboot_api_kernel_tests \
  614. tests/vboot_api_kernel2_tests \
  615. tests/vboot_api_kernel4_tests \
  616. tests/vboot_api_kernel5_tests \
  617. tests/vboot_api_kernel6_tests \
  618. tests/vboot_audio_tests \
  619. tests/vboot_common_tests \
  620. tests/vboot_display_tests \
  621. tests/vboot_kernel_tests \
  622. tests/vboot_nvstorage_test \
  623. tests/verify_kernel
  624. ifeq (${TPM2_MODE},)
  625. # TODO(apronin): tests for TPM2 case?
  626. TEST_NAMES += \
  627. tests/tlcl_tests \
  628. tests/rollback_index2_tests
  629. endif
  630. ifdef REGION_READ
  631. TEST_NAMES += tests/vboot_region_tests
  632. endif
  633. TEST_FUTIL_NAMES = \
  634. tests/futility/binary_editor \
  635. tests/futility/test_file_types \
  636. tests/futility/test_not_really
  637. TEST_NAMES += ${TEST_FUTIL_NAMES}
  638. TEST2X_NAMES = \
  639. tests/vb2_api_tests \
  640. tests/vb2_common_tests \
  641. tests/vb2_misc_tests \
  642. tests/vb2_nvstorage_tests \
  643. tests/vb2_rsa_utility_tests \
  644. tests/vb2_secdata_tests \
  645. tests/vb2_secdatak_tests \
  646. tests/vb2_sha_tests \
  647. tests/hmac_test
  648. TEST20_NAMES = \
  649. tests/vb20_api_tests \
  650. tests/vb20_api_kernel_tests \
  651. tests/vb20_common_tests \
  652. tests/vb20_common2_tests \
  653. tests/vb20_verify_fw.c \
  654. tests/vb20_common3_tests \
  655. tests/vb20_kernel_tests \
  656. tests/vb20_misc_tests \
  657. tests/vb20_rsa_padding_tests \
  658. tests/vb20_verify_fw
  659. TEST21_NAMES = \
  660. tests/vb21_api_tests \
  661. tests/vb21_common_tests \
  662. tests/vb21_common2_tests \
  663. tests/vb21_misc_tests \
  664. tests/vb21_host_fw_preamble_tests \
  665. tests/vb21_host_key_tests \
  666. tests/vb21_host_keyblock_tests \
  667. tests/vb21_host_misc_tests \
  668. tests/vb21_host_sig_tests
  669. TESTBDB_NAMES = \
  670. tests/bdb_test \
  671. tests/bdb_nvm_test \
  672. tests/bdb_sprw_test
  673. TEST_NAMES += ${TEST2X_NAMES} ${TEST20_NAMES} ${TEST21_NAMES} ${TESTBDB_NAMES}
  674. # And a few more...
  675. ifeq (${TPM2_MODE},)
  676. TLCL_TEST_NAMES = \
  677. tests/tpm_lite/tpmtest_earlyextend \
  678. tests/tpm_lite/tpmtest_earlynvram \
  679. tests/tpm_lite/tpmtest_earlynvram2 \
  680. tests/tpm_lite/tpmtest_enable \
  681. tests/tpm_lite/tpmtest_fastenable \
  682. tests/tpm_lite/tpmtest_globallock \
  683. tests/tpm_lite/tpmtest_redefine_unowned \
  684. tests/tpm_lite/tpmtest_spaceperm \
  685. tests/tpm_lite/tpmtest_testsetup \
  686. tests/tpm_lite/tpmtest_timing \
  687. tests/tpm_lite/tpmtest_writelimit
  688. else
  689. # TODO(apronin): tests for TPM2 case?
  690. TLCL_TEST_NAMES =
  691. endif
  692. TEST_NAMES += ${TLCL_TEST_NAMES}
  693. # Finally
  694. TEST_BINS = $(addprefix ${BUILD}/,${TEST_NAMES})
  695. TEST_OBJS += $(addsuffix .o,${TEST_BINS})
  696. TEST_FUTIL_BINS = $(addprefix ${BUILD}/,${TEST_FUTIL_NAMES})
  697. TEST2X_BINS = $(addprefix ${BUILD}/,${TEST2X_NAMES})
  698. TEST20_BINS = $(addprefix ${BUILD}/,${TEST20_NAMES})
  699. TEST21_BINS = $(addprefix ${BUILD}/,${TEST21_NAMES})
  700. TESTBDB_BINS = $(addprefix ${BUILD}/,${TESTBDB_NAMES})
  701. # Directory containing test keys
  702. TEST_KEYS = ${SRC_RUN}/tests/testkeys
  703. ##############################################################################
  704. # Finally, some targets. High-level ones first.
  705. # Create output directories if necessary. Do this via explicit shell commands
  706. # so it happens before trying to generate/include dependencies.
  707. SUBDIRS := firmware host cgpt utility futility tests tests/tpm_lite
  708. _dir_create := $(foreach d, \
  709. $(shell find ${SUBDIRS} -name '*.c' -exec dirname {} \; | sort -u), \
  710. $(shell [ -d ${BUILD}/${d} ] || mkdir -p ${BUILD}/${d}))
  711. # Host targets
  712. .PHONY: host_stuff
  713. host_stuff: utillib hostlib cgpt utils futil tests
  714. .PHONY: clean
  715. clean:
  716. ${Q}/bin/rm -rf ${BUILD}
  717. .PHONY: install
  718. install: cgpt_install utils_install signing_install futil_install \
  719. pc_files_install
  720. .PHONY: install_dev
  721. install_dev: headers_install lib_install
  722. .PHONY: install_mtd
  723. install_mtd: install cgpt_wrapper_install
  724. .PHONY: install_for_test
  725. install_for_test: override DESTDIR = ${TEST_INSTALL_DIR}
  726. install_for_test: install
  727. # Don't delete intermediate object files
  728. .SECONDARY:
  729. # ----------------------------------------------------------------------------
  730. # Firmware library
  731. # TPM-specific flags. These depend on the particular TPM we're targeting for.
  732. # They are needed here only for compiling parts of the firmware code into
  733. # user-level tests.
  734. # TPM_BLOCKING_CONTINUESELFTEST is defined if TPM_ContinueSelfTest blocks until
  735. # the self test has completed.
  736. ${FWLIB_OBJS}: CFLAGS += -DTPM_BLOCKING_CONTINUESELFTEST
  737. # TPM_MANUAL_SELFTEST is defined if the self test must be started manually
  738. # (with a call to TPM_ContinueSelfTest) instead of starting automatically at
  739. # power on.
  740. #
  741. # We sincerely hope that TPM_BLOCKING_CONTINUESELFTEST and TPM_MANUAL_SELFTEST
  742. # are not both defined at the same time. (See comment in code.)
  743. # CFLAGS += -DTPM_MANUAL_SELFTEST
  744. ifeq (${FIRMWARE_ARCH},i386)
  745. # Unrolling loops in cryptolib makes it faster
  746. ${FWLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
  747. ${FWLIB2X_OBJS}: CFLAGS += -DUNROLL_LOOPS
  748. ${FWLIB20_OBJS}: CFLAGS += -DUNROLL_LOOPS
  749. ${FWLIB21_OBJS}: CFLAGS += -DUNROLL_LOOPS
  750. ${BDBLIB_OBJS}: CFLAGS += -DUNROLL_LOOPS
  751. # Workaround for coreboot on x86, which will power off asynchronously
  752. # without giving us a chance to react. This is not an example of the Right
  753. # Way to do things. See chrome-os-partner:7689, and the commit message
  754. # that made this change.
  755. ${FWLIB_OBJS}: CFLAGS += -DSAVE_LOCALE_IMMEDIATELY
  756. # On x86 we don't actually read the GBB data into RAM until it is needed.
  757. # Therefore it makes sense to cache it rather than reading it each time.
  758. # Enable this feature.
  759. ${FWLIB_OBJS}: CFLAGS += -DCOPY_BMP_DATA
  760. endif
  761. ifdef REGION_READ
  762. ${FWLIB_OBJS}: CFLAGS += -DREGION_READ
  763. endif
  764. ifeq (${FIRMWARE_ARCH},)
  765. # Disable rollback TPM when compiling locally, since otherwise
  766. # load_kernel_test attempts to talk to the TPM.
  767. ${FWLIB_OBJS}: CFLAGS += -DDISABLE_ROLLBACK_TPM
  768. endif
  769. ${FWLIB21_OBJS}: INCLUDES += -Ifirmware/lib21/include
  770. ${BDBLIB_OBJS}: INCLUDES += -Ifirmware/bdb
  771. # Linktest ensures firmware lib doesn't rely on outside libraries
  772. ${BUILD}/firmware/linktest/main: ${FWLIB}
  773. ${BUILD}/firmware/linktest/main: LIBS = ${FWLIB}
  774. TEST_OBJS += ${BUILD}/firmware/linktest/main.o
  775. .PHONY: fwlinktest
  776. fwlinktest: ${BUILD}/firmware/linktest/main
  777. .PHONY: fwlib
  778. fwlib: $(if ${FIRMWARE_ARCH},${FWLIB},fwlinktest)
  779. ${FWLIB}: ${FWLIB_OBJS} ${FWLIB2X_OBJS} ${FWLIB20_OBJS}
  780. @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
  781. ${Q}rm -f $@
  782. @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
  783. ${Q}ar qc $@ $^
  784. .PHONY: fwlib2x
  785. fwlib2x: ${FWLIB2X}
  786. ${FWLIB2X}: ${FWLIB2X_OBJS}
  787. @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
  788. ${Q}rm -f $@
  789. @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
  790. ${Q}ar qc $@ $^
  791. .PHONY: fwlib20
  792. fwlib20: ${FWLIB20}
  793. ${FWLIB20}: ${FWLIB2X_OBJS} ${FWLIB20_OBJS}
  794. @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
  795. ${Q}rm -f $@
  796. @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
  797. ${Q}ar qc $@ $^
  798. .PHONY: fwlib21
  799. fwlib21: ${FWLIB21}
  800. ${FWLIB21}: ${FWLIB2X_OBJS} ${FWLIB21_OBJS}
  801. @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
  802. ${Q}rm -f $@
  803. @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
  804. ${Q}ar qc $@ $^
  805. .PHONY: bdblib
  806. bdblib: ${BDBLIB}
  807. ${BDBLIB}: ${FWLIB2X_OBJS} ${BDBLIB_OBJS}
  808. @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
  809. ${Q}rm -f $@
  810. @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
  811. ${Q}ar qc $@ $^
  812. # ----------------------------------------------------------------------------
  813. # Host library(s)
  814. # Link tests for local utilities
  815. ${BUILD}/host/linktest/main: ${UTILLIB}
  816. ${BUILD}/host/linktest/main: LIBS = ${UTILLIB}
  817. TEST_OBJS += ${BUILD}/host/linktest/main.o
  818. .PHONY: utillib
  819. utillib: ${UTILLIB} \
  820. ${BUILD}/host/linktest/main
  821. # TODO: better way to make .a than duplicating this recipe each time?
  822. ${UTILLIB}: ${UTILLIB_OBJS} ${FWLIB_OBJS} ${FWLIB2X_OBJS} ${FWLIB20_OBJS} \
  823. ${FWLIB21_OBJS}
  824. @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
  825. ${Q}rm -f $@
  826. @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
  827. ${Q}ar qc $@ $^
  828. ${UTILBDB}: ${UTILBDB_OBJS} ${BDBLIB_OBJS}
  829. @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
  830. ${Q}rm -f $@
  831. @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
  832. ${Q}ar qc $@ $^
  833. # Link tests for external repos
  834. ${BUILD}/host/linktest/extern: ${HOSTLIB}
  835. ${BUILD}/host/linktest/extern: LIBS = ${HOSTLIB}
  836. ${BUILD}/host/linktest/extern: LDLIBS += -static
  837. TEST_OBJS += ${BUILD}/host/linktest/extern.o
  838. .PHONY: hostlib
  839. hostlib: ${HOSTLIB} \
  840. ${BUILD}/host/linktest/extern
  841. # TODO: better way to make .a than duplicating this recipe each time?
  842. ${HOSTLIB}: ${HOSTLIB_OBJS}
  843. @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
  844. ${Q}rm -f $@
  845. @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
  846. ${Q}ar qc $@ $^
  847. # Ugh. This is a very cut-down version of HOSTLIB just for the installer.
  848. .PHONY: tinyhostlib
  849. tinyhostlib: ${TINYHOSTLIB}
  850. ${Q}cp -f ${TINYHOSTLIB} ${HOSTLIB}
  851. ${TINYHOSTLIB}: ${TINYHOSTLIB_OBJS}
  852. @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
  853. ${Q}rm -f $@
  854. @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
  855. ${Q}ar qc $@ $^
  856. .PHONY: headers_install
  857. headers_install:
  858. @${PRINTF} " INSTALL HEADERS\n"
  859. ${Q}mkdir -p ${UI_DIR}
  860. ${Q}${INSTALL} -t ${UI_DIR} -m644 \
  861. host/include/* \
  862. firmware/include/gpt.h \
  863. firmware/include/tlcl.h \
  864. firmware/include/tss_constants.h
  865. .PHONY: lib_install
  866. lib_install: ${HOSTLIB}
  867. @${PRINTF} " INSTALL HOSTLIB\n"
  868. ${Q}mkdir -p ${UL_DIR}
  869. ${Q}${INSTALL} -t ${UL_DIR} -m644 $^
  870. .PHONY: devkeys_install
  871. devkeys_install:
  872. @${PRINTF} " INSTALL DEVKEYS\n"
  873. ${Q}mkdir -p ${US_DIR}/devkeys
  874. ${Q}${INSTALL} -t ${US_DIR}/devkeys -m644 tests/devkeys/*
  875. # ----------------------------------------------------------------------------
  876. # CGPT library and utility
  877. .PHONY: cgpt_wrapper
  878. cgpt_wrapper: ${CGPT_WRAPPER}
  879. ${CGPT_WRAPPER}: ${CGPT_WRAPPER_OBJS} ${UTILLIB}
  880. @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n"
  881. ${Q}${LD} -o ${CGPT_WRAPPER} ${CFLAGS} $^
  882. .PHONY: cgpt
  883. cgpt: ${CGPT} ${CGPT_WRAPPER}
  884. ${CGPT}: LDLIBS += -luuid
  885. ${CGPT}: ${CGPT_OBJS} ${UTILLIB}
  886. @${PRINTF} " LDcgpt $(subst ${BUILD}/,,$@)\n"
  887. ${Q}${LD} -o ${CGPT} ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
  888. .PHONY: cgpt_install
  889. cgpt_install: ${CGPT}
  890. @${PRINTF} " INSTALL CGPT\n"
  891. ${Q}mkdir -p ${UB_DIR}
  892. ${Q}${INSTALL} -t ${UB_DIR} $^
  893. .PHONY: cgpt_wrapper_install
  894. cgpt_wrapper_install: cgpt_install ${CGPT_WRAPPER}
  895. @$(PRINTF) " INSTALL cgpt_wrapper\n"
  896. ${Q}${INSTALL} -t ${UB_DIR} ${CGPT_WRAPPER}
  897. ${Q}mv ${UB_DIR}/$(notdir ${CGPT}) \
  898. ${UB_DIR}/$(notdir ${CGPT}).bin
  899. ${Q}mv ${UB_DIR}/$(notdir ${CGPT_WRAPPER}) \
  900. ${UB_DIR}/$(notdir ${CGPT})
  901. # ----------------------------------------------------------------------------
  902. # Utilities
  903. # These have their own headers too.
  904. ${BUILD}/utility/%: INCLUDES += -Iutility/include
  905. ${UTIL_BINS} ${UTIL_BINS_STATIC}: ${UTILLIB}
  906. ${UTIL_BINS} ${UTIL_BINS_STATIC}: LIBS = ${UTILLIB}
  907. # Utilities for auto-update toolkits must be statically linked.
  908. ${UTIL_BINS_STATIC}: LDFLAGS += -static
  909. .PHONY: utils
  910. utils: ${UTIL_BINS} ${UTIL_SCRIPTS}
  911. ${Q}cp -f ${UTIL_SCRIPTS} ${BUILD}/utility
  912. ${Q}chmod a+rx $(patsubst %,${BUILD}/%,${UTIL_SCRIPTS})
  913. .PHONY: utils_install
  914. utils_install: ${UTIL_BINS} ${UTIL_SCRIPTS} ${UTIL_DEFAULTS}
  915. @${PRINTF} " INSTALL UTILS\n"
  916. ${Q}mkdir -p ${UB_DIR}
  917. ${Q}${INSTALL} -t ${UB_DIR} ${UTIL_BINS} ${UTIL_SCRIPTS}
  918. ${Q}mkdir -p ${DF_DIR}
  919. ${Q}${INSTALL} -t ${DF_DIR} -m 'u=rw,go=r,a-s' ${UTIL_DEFAULTS}
  920. # And some signing stuff for the target
  921. .PHONY: signing_install
  922. signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON}
  923. @${PRINTF} " INSTALL SIGNING\n"
  924. ${Q}mkdir -p ${UB_DIR} ${VB_DIR}
  925. ${Q}${INSTALL} -t ${UB_DIR} ${SIGNING_SCRIPTS}
  926. ${Q}${INSTALL} -t ${VB_DIR} ${SIGNING_SCRIPTS_DEV}
  927. ${Q}${INSTALL} -t ${VB_DIR} -m 'u=rw,go=r,a-s' ${SIGNING_COMMON}
  928. # ----------------------------------------------------------------------------
  929. # new Firmware Utility
  930. .PHONY: futil
  931. futil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN}
  932. ${FUTIL_STATIC_BIN}: ${FUTIL_STATIC_OBJS} ${UTILLIB}
  933. @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
  934. ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS}
  935. ${FUTIL_BIN}: LDLIBS += ${CRYPTO_LIBS} ${FWLIB20}
  936. ${FUTIL_BIN}: ${FUTIL_OBJS} ${UTILLIB} ${FWLIB20} ${UTILBDB}
  937. @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
  938. ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS}
  939. .PHONY: futil_install
  940. futil_install: ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
  941. @${PRINTF} " INSTALL futility\n"
  942. ${Q}mkdir -p ${UB_DIR}
  943. ${Q}${INSTALL} -t ${UB_DIR} ${FUTIL_BIN} ${FUTIL_STATIC_BIN}
  944. ${Q}for prog in ${FUTIL_SYMLINKS}; do \
  945. ln -sf futility "${UB_DIR}/$$prog"; done
  946. # ----------------------------------------------------------------------------
  947. # Utility to generate TLCL structure definition header file.
  948. ${BUILD}/utility/tlcl_generator: CFLAGS += -fpack-struct
  949. STRUCTURES_TMP=${BUILD}/tlcl_structures.tmp
  950. STRUCTURES_SRC=firmware/lib/tpm_lite/include/tlcl_structures.h
  951. .PHONY: update_tlcl_structures
  952. update_tlcl_structures: ${BUILD}/utility/tlcl_generator
  953. @${PRINTF} " Rebuilding TLCL structures\n"
  954. ${Q}${BUILD}/utility/tlcl_generator > ${STRUCTURES_TMP}
  955. ${Q}cmp -s ${STRUCTURES_TMP} ${STRUCTURES_SRC} || \
  956. ( echo "%% Updating structures.h %%" && \
  957. cp ${STRUCTURES_TMP} ${STRUCTURES_SRC} )
  958. # ----------------------------------------------------------------------------
  959. # Tests
  960. .PHONY: tests
  961. tests: ${TEST_BINS}
  962. ${TEST_BINS}: ${UTILLIB} ${TESTLIB}
  963. ${TEST_BINS}: INCLUDES += -Itests
  964. ${TEST_BINS}: LIBS = ${TESTLIB} ${UTILLIB}
  965. # Futility tests need almost everything that futility needs.
  966. ${TEST_FUTIL_BINS}: ${FUTIL_OBJS} ${UTILLIB} ${UTILBDB}
  967. ${TEST_FUTIL_BINS}: INCLUDES += -Ifutility
  968. ${TEST_FUTIL_BINS}: OBJS += ${FUTIL_OBJS} ${UTILLIB} ${UTILBDB}
  969. ${TEST_FUTIL_BINS}: LDLIBS += ${CRYPTO_LIBS}
  970. ${TEST2X_BINS}: ${FWLIB2X}
  971. ${TEST2X_BINS}: LIBS += ${FWLIB2X}
  972. ${TEST20_BINS}: ${FWLIB20}
  973. ${TEST20_BINS}: LIBS += ${FWLIB20}
  974. ${TEST20_BINS}: LDLIBS += ${CRYPTO_LIBS}
  975. ${TESTBDB_BINS}: ${FWLIB2X} ${UTILBDB}
  976. ${TESTBDB_BINS}: INCLUDES += -Ifirmware/bdb
  977. ${TESTBDB_BINS}: LIBS += ${UTILBDB} ${FWLIB2X}
  978. ${TESTLIB}: ${TESTLIB_OBJS}
  979. @${PRINTF} " RM $(subst ${BUILD}/,,$@)\n"
  980. ${Q}rm -f $@
  981. @${PRINTF} " AR $(subst ${BUILD}/,,$@)\n"
  982. ${Q}ar qc $@ $^
  983. # ----------------------------------------------------------------------------
  984. # Generic build rules. LIBS and OBJS can be overridden to tweak the generic
  985. # rules for specific targets.
  986. ${BUILD}/%: ${BUILD}/%.o ${OBJS} ${LIBS}
  987. @${PRINTF} " LD $(subst ${BUILD}/,,$@)\n"
  988. ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $< ${OBJS} ${LIBS} ${LDLIBS}
  989. ${BUILD}/%.o: %.c
  990. @${PRINTF} " CC $(subst ${BUILD}/,,$@)\n"
  991. ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
  992. ${BUILD}/%.o: ${BUILD}/%.c
  993. @${PRINTF} " CC $(subst ${BUILD}/,,$@)\n"
  994. ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
  995. # Rules to recompile a single source file for library and test
  996. # TODO: is there a tidier way to do this?
  997. ${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY
  998. ${BUILD}/%_for_lib.o: %.c
  999. @${PRINTF} " CC-for-lib $(subst ${BUILD}/,,$@)\n"
  1000. ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
  1001. ${BUILD}/%_for_test.o: CFLAGS += -DFOR_TEST
  1002. ${BUILD}/%_for_test.o: %.c
  1003. @${PRINTF} " CC-for-test $(subst ${BUILD}/,,$@)\n"
  1004. ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
  1005. # TODO: C++ files don't belong in vboot reference at all. Convert to C.
  1006. ${BUILD}/%.o: %.cc
  1007. @${PRINTF} " CXX $(subst ${BUILD}/,,$@)\n"
  1008. ${Q}${CXX} ${CFLAGS} ${INCLUDES} -c -o $@ $<
  1009. # ----------------------------------------------------------------------------
  1010. # Here are the special tweaks to the generic rules.
  1011. # Always create the defaults file, since it depends on input variables
  1012. .PHONY: ${UTIL_DEFAULTS}
  1013. ${UTIL_DEFAULTS}:
  1014. @${PRINTF} " CREATE $(subst ${BUILD}/,,$@)\n"
  1015. ${Q}rm -f $@
  1016. ${Q}mkdir -p $(dir $@)
  1017. ${Q}echo '# Generated file. Do not edit.' > $@.tmp
  1018. ${Q}echo "DEV_DEBUG_FORCE=${DEV_DEBUG_FORCE}" >> $@.tmp
  1019. ${Q}mv -f $@.tmp $@
  1020. # Some utilities need external crypto functions
  1021. CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto)
  1022. ${BUILD}/utility/dumpRSAPublicKey: LDLIBS += ${CRYPTO_LIBS}
  1023. ${BUILD}/utility/pad_digest_utility: LDLIBS += ${CRYPTO_LIBS}
  1024. ${BUILD}/utility/signature_digest_utility: LDLIBS += ${CRYPTO_LIBS}
  1025. ${BUILD}/utility/verify_data: LDLIBS += ${CRYPTO_LIBS}
  1026. ${BUILD}/utility/bdb_extend: ${FWLIB2X} ${UTILBDB}
  1027. ${BUILD}/utility/bdb_extend.o: INCLUDES += -Ifirmware/bdb
  1028. ${BUILD}/utility/bdb_extend: LDLIBS += ${CRYPTO_LIBS}
  1029. ${BUILD}/utility/bdb_extend: LIBS += ${UTILBDB} ${FWLIB2X}
  1030. ${BUILD}/host/linktest/main: LDLIBS += ${CRYPTO_LIBS}
  1031. ${BUILD}/tests/vb20_common2_tests: LDLIBS += ${CRYPTO_LIBS}
  1032. ${BUILD}/tests/vb20_common3_tests: LDLIBS += ${CRYPTO_LIBS}
  1033. ${BUILD}/tests/verify_kernel: LDLIBS += ${CRYPTO_LIBS}
  1034. ${BUILD}/tests/bdb_test: LDLIBS += ${CRYPTO_LIBS}
  1035. ${BUILD}/tests/bdb_nvm_test: LDLIBS += ${CRYPTO_LIBS}
  1036. ${BUILD}/tests/bdb_sprw_test: LDLIBS += ${CRYPTO_LIBS}
  1037. ${BUILD}/tests/hmac_test: LDLIBS += ${CRYPTO_LIBS}
  1038. ${TEST21_BINS}: LDLIBS += ${CRYPTO_LIBS}
  1039. ${BUILD}/utility/bmpblk_utility: LD = ${CXX}
  1040. ${BUILD}/utility/bmpblk_utility: LDLIBS = ${LZMA_LIBS} ${YAML_LIBS}
  1041. BMPBLK_UTILITY_DEPS = \
  1042. ${BUILD}/utility/bmpblk_util.o \
  1043. ${BUILD}/utility/image_types.o \
  1044. ${BUILD}/utility/eficompress_for_lib.o \
  1045. ${BUILD}/utility/efidecompress_for_lib.o
  1046. ${BUILD}/utility/bmpblk_utility: OBJS = ${BMPBLK_UTILITY_DEPS}
  1047. ${BUILD}/utility/bmpblk_utility: ${BMPBLK_UTILITY_DEPS}
  1048. ALL_OBJS += ${BMPBLK_UTILITY_DEPS}
  1049. ${BUILD}/utility/bmpblk_font: OBJS += ${BUILD}/utility/image_types.o
  1050. ${BUILD}/utility/bmpblk_font: ${BUILD}/utility/image_types.o
  1051. ALL_OBJS += ${BUILD}/utility/image_types.o
  1052. # Allow multiple definitions, so tests can mock functions from other libraries
  1053. ${BUILD}/tests/%: CFLAGS += -Xlinker --allow-multiple-definition
  1054. ${BUILD}/tests/%: LDLIBS += -lrt -luuid
  1055. ${BUILD}/tests/%: LIBS += ${TESTLIB}
  1056. ifeq (${TPM2_MODE},)
  1057. # TODO(apronin): tests for TPM2 case?
  1058. ${BUILD}/tests/rollback_index2_tests: OBJS += \
  1059. ${BUILD}/firmware/lib/rollback_index_for_test.o
  1060. ${BUILD}/tests/rollback_index2_tests: \
  1061. ${BUILD}/firmware/lib/rollback_index_for_test.o
  1062. TEST_OBJS += ${BUILD}/firmware/lib/rollback_index_for_test.o
  1063. endif
  1064. ${BUILD}/tests/tlcl_tests: OBJS += \
  1065. ${TLCL_OBJS_FOR_TEST}
  1066. ${BUILD}/tests/tlcl_tests: \
  1067. ${TLCL_OBJS_FOR_TEST}
  1068. TEST_OBJS += ${TLCL_OBJS_FOR_TEST}
  1069. ${BUILD}/tests/vboot_audio_tests: OBJS += \
  1070. ${BUILD}/firmware/lib/vboot_audio_for_test.o
  1071. ${BUILD}/tests/vboot_audio_tests: \
  1072. ${BUILD}/firmware/lib/vboot_audio_for_test.o
  1073. TEST_OBJS += ${BUILD}/firmware/lib/vboot_audio_for_test.o
  1074. ifeq (${TPM2_MODE},)
  1075. # TODO(apronin): tests for TPM2 case?
  1076. TLCL_TEST_BINS = $(addprefix ${BUILD}/,${TLCL_TEST_NAMES})
  1077. ${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
  1078. ${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o
  1079. TEST_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o
  1080. endif
  1081. # ----------------------------------------------------------------------------
  1082. # Here are the special rules that don't fit in the generic rules.
  1083. # Generates the list of commands defined in futility by running grep in the
  1084. # source files looking for the DECLARE_FUTIL_COMMAND() macro usage.
  1085. ${FUTIL_STATIC_CMD_LIST}: ${FUTIL_STATIC_SRCS}
  1086. ${FUTIL_CMD_LIST}: ${FUTIL_SRCS}
  1087. ${FUTIL_CMD_LIST} ${FUTIL_STATIC_CMD_LIST}:
  1088. @${PRINTF} " GEN $(subst ${BUILD}/,,$@)\n"
  1089. ${Q}rm -f $@ $@_t $@_commands
  1090. ${Q}mkdir -p ${BUILD}/gen
  1091. ${Q}grep -hoRE '^DECLARE_FUTIL_COMMAND\([^,]+' $^ \
  1092. | sed 's/DECLARE_FUTIL_COMMAND(\(.*\)/_CMD(\1)/' \
  1093. | sort >>$@_commands
  1094. ${Q}./scripts/getversion.sh >> $@_t
  1095. ${Q}echo '#define _CMD(NAME) extern const struct' \
  1096. 'futil_cmd_t __cmd_##NAME;' >> $@_t
  1097. ${Q}cat $@_commands >> $@_t
  1098. ${Q}echo '#undef _CMD' >> $@_t
  1099. ${Q}echo '#define _CMD(NAME) &__cmd_##NAME,' >> $@_t
  1100. ${Q}echo 'const struct futil_cmd_t *const futil_cmds[] = {' >> $@_t
  1101. ${Q}cat $@_commands >> $@_t
  1102. ${Q}echo '0}; /* null-terminated */' >> $@_t
  1103. ${Q}echo '#undef _CMD' >> $@_t
  1104. ${Q}mv $@_t $@
  1105. ${Q}rm -f $@_commands
  1106. ##############################################################################
  1107. # Targets that exist just to run tests
  1108. # Frequently-run tests
  1109. .PHONY: test_targets
  1110. test_targets:: runcgpttests runmisctests run2tests runbdbtests
  1111. ifeq (${MINIMAL},)
  1112. # Bitmap utility isn't compiled for minimal variant
  1113. test_targets:: runbmptests runfutiltests
  1114. # Scripts don't work under qemu testing
  1115. # TODO: convert scripts to makefile so they can be called directly
  1116. test_targets:: runtestscripts
  1117. endif
  1118. .PHONY: test_setup
  1119. test_setup:: cgpt utils futil tests install_for_test
  1120. # Qemu setup for cross-compiled tests. Need to copy qemu binary into the
  1121. # sysroot.
  1122. ifneq (${QEMU_ARCH},)
  1123. test_setup:: qemu_install
  1124. .PHONY: qemu_install
  1125. qemu_install:
  1126. ifeq (${SYSROOT},)
  1127. $(error SYSROOT must be set to the top of the target-specific root \
  1128. when cross-compiling for qemu-based tests to run properly.)
  1129. endif
  1130. @${PRINTF} " Copying qemu binary.\n"
  1131. ${Q}cp -fu /usr/bin/${QEMU_BIN} ${BUILD}/${QEMU_BIN}
  1132. ${Q}chmod a+rx ${BUILD}/${QEMU_BIN}
  1133. endif
  1134. .PHONY: runtests
  1135. runtests: test_setup test_targets
  1136. # Generate test keys
  1137. .PHONY: genkeys
  1138. genkeys: utils test_setup
  1139. tests/gen_test_keys.sh
  1140. # Generate test cases for fuzzing
  1141. .PHONY: genfuzztestcases
  1142. genfuzztestcases: utils test_setup
  1143. tests/gen_fuzz_test_cases.sh
  1144. .PHONY: runbmptests
  1145. runbmptests: test_setup
  1146. cd tests/bitmaps && BMPBLK=${BUILD_RUN}/utility/bmpblk_utility \
  1147. ./TestBmpBlock.py -v
  1148. .PHONY: runcgpttests
  1149. runcgpttests: test_setup
  1150. ${RUNTEST} ${BUILD_RUN}/tests/cgptlib_test
  1151. .PHONY: runtestscripts
  1152. runtestscripts: test_setup genfuzztestcases
  1153. tests/load_kernel_tests.sh
  1154. tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt
  1155. tests/run_cgpt_tests.sh ${BUILD_RUN}/cgpt/cgpt -D 358400
  1156. tests/run_preamble_tests.sh
  1157. tests/run_vbutil_kernel_arg_tests.sh
  1158. tests/run_vbutil_tests.sh
  1159. tests/vb2_rsa_tests.sh
  1160. tests/vb2_firmware_tests.sh
  1161. .PHONY: runmisctests
  1162. runmisctests: test_setup
  1163. ${RUNTEST} ${BUILD_RUN}/tests/ec_sync_tests
  1164. ifeq (${TPM2_MODE},)
  1165. ${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
  1166. ${RUNTEST} ${BUILD_RUN}/tests/rollback_index2_tests
  1167. endif
  1168. ${RUNTEST} ${BUILD_RUN}/tests/rollback_index3_tests
  1169. ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
  1170. ${RUNTEST} ${BUILD_RUN}/tests/utility_tests
  1171. ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_devmode_tests
  1172. ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
  1173. ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel2_tests
  1174. ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
  1175. ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel5_tests
  1176. ${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel6_tests
  1177. ${RUNTEST} ${BUILD_RUN}/tests/vboot_audio_tests
  1178. ${RUNTEST} ${BUILD_RUN}/tests/vboot_common_tests
  1179. ${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
  1180. ${RUNTEST} ${BUILD_RUN}/tests/vboot_kernel_tests
  1181. ${RUNTEST} ${BUILD_RUN}/tests/vboot_nvstorage_test
  1182. .PHONY: run2tests
  1183. run2tests: test_setup
  1184. ${RUNTEST} ${BUILD_RUN}/tests/vb2_api_tests
  1185. ${RUNTEST} ${BUILD_RUN}/tests/vb2_common_tests
  1186. ${RUNTEST} ${BUILD_RUN}/tests/vb2_misc_tests
  1187. ${RUNTEST} ${BUILD_RUN}/tests/vb2_nvstorage_tests
  1188. ${RUNTEST} ${BUILD_RUN}/tests/vb2_rsa_utility_tests
  1189. ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdata_tests
  1190. ${RUNTEST} ${BUILD_RUN}/tests/vb2_secdatak_tests
  1191. ${RUNTEST} ${BUILD_RUN}/tests/vb2_sha_tests
  1192. ${RUNTEST} ${BUILD_RUN}/tests/vb20_api_tests
  1193. ${RUNTEST} ${BUILD_RUN}/tests/vb20_api_kernel_tests
  1194. ${RUNTEST} ${BUILD_RUN}/tests/vb20_common_tests
  1195. ${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS}
  1196. ${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS}
  1197. ${RUNTEST} ${BUILD_RUN}/tests/vb20_kernel_tests
  1198. ${RUNTEST} ${BUILD_RUN}/tests/vb20_misc_tests
  1199. ${RUNTEST} ${BUILD_RUN}/tests/vb21_api_tests
  1200. ${RUNTEST} ${BUILD_RUN}/tests/vb21_common_tests
  1201. ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS}
  1202. ${RUNTEST} ${BUILD_RUN}/tests/vb21_misc_tests
  1203. ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_fw_preamble_tests ${TEST_KEYS}
  1204. ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_key_tests ${TEST_KEYS} ${BUILD}
  1205. ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_keyblock_tests ${TEST_KEYS}
  1206. ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_misc_tests ${BUILD}
  1207. ${RUNTEST} ${BUILD_RUN}/tests/vb21_host_sig_tests ${TEST_KEYS}
  1208. ${RUNTEST} ${BUILD_RUN}/tests/hmac_test
  1209. .PHONY: runbdbtests
  1210. runbdbtests: test_setup
  1211. ${RUNTEST} ${BUILD_RUN}/tests/bdb_test ${TEST_KEYS}
  1212. ${RUNTEST} ${BUILD_RUN}/tests/bdb_sprw_test ${TEST_KEYS}
  1213. .PHONY: runfutiltests
  1214. runfutiltests: test_setup
  1215. tests/futility/run_test_scripts.sh ${TEST_INSTALL_DIR}/bin
  1216. ${RUNTEST} ${BUILD_RUN}/tests/futility/test_file_types
  1217. ${RUNTEST} ${BUILD_RUN}/tests/futility/test_not_really
  1218. # Run long tests, including all permutations of encryption keys (instead of
  1219. # just the ones we use) and tests of currently-unused code.
  1220. # Not run by automated build.
  1221. .PHONY: runlongtests
  1222. runlongtests: test_setup genkeys genfuzztestcases
  1223. ${RUNTEST} ${BUILD_RUN}/tests/vb20_common2_tests ${TEST_KEYS} --all
  1224. ${RUNTEST} ${BUILD_RUN}/tests/vb20_common3_tests ${TEST_KEYS} --all
  1225. ${RUNTEST} ${BUILD_RUN}/tests/vb21_common2_tests ${TEST_KEYS} --all
  1226. tests/run_preamble_tests.sh --all
  1227. tests/run_vbutil_tests.sh --all
  1228. # TODO: There were a number of ancient tests that hadn't been run in years.
  1229. # They were removed with https://chromium-review.googlesource.com/#/c/214610/
  1230. # Some day it might be nice to see what they were supposed to do.
  1231. .PHONY: runalltests
  1232. runalltests: runtests runfutiltests runlongtests
  1233. # Code coverage
  1234. .PHONY: coverage_init
  1235. coverage_init: test_setup
  1236. rm -f ${COV_INFO}*
  1237. lcov -c -i -d . -b . -o ${COV_INFO}.initial
  1238. .PHONY: coverage_html
  1239. coverage_html:
  1240. lcov -c -d . -b . -o ${COV_INFO}.tests
  1241. lcov -a ${COV_INFO}.initial -a ${COV_INFO}.tests -o ${COV_INFO}.total
  1242. lcov -r ${COV_INFO}.total '/usr/*' '*/linktest/*' -o ${COV_INFO}.local
  1243. genhtml ${COV_INFO}.local -o ${BUILD}/coverage
  1244. # Generate addtional coverage stats just for firmware subdir, because the stats
  1245. # for the whole project don't include subdirectory summaries. This will print
  1246. # the summary for just the firmware sources.
  1247. lcov -r ${COV_INFO}.local '*/stub/*' -o ${COV_INFO}.nostub
  1248. lcov -e ${COV_INFO}.nostub '${SRCDIR}/firmware/*' \
  1249. -o ${COV_INFO}.firmware
  1250. .PHONY: coverage
  1251. ifeq (${COV},)
  1252. coverage:
  1253. $(error Build coverage like this: make clean && COV=1 make coverage)
  1254. else
  1255. coverage: coverage_init runtests coverage_html
  1256. endif
  1257. # Include generated dependencies
  1258. ALL_DEPS += ${ALL_OBJS:%.o=%.o.d}
  1259. TEST_DEPS += ${TEST_OBJS:%.o=%.o.d}
  1260. -include ${ALL_DEPS}
  1261. -include ${TEST_DEPS}
  1262. # We want to use only relative paths in cscope.files, especially since the
  1263. # paths inside and outside the chroot are different.
  1264. SRCDIRPAT=$(subst /,\/,${SRCDIR}/)
  1265. # Note: vboot 2.0 is deprecated, so don't index those files
  1266. ${BUILD}/cscope.files: all test_setup
  1267. ${Q}rm -f $@
  1268. ${Q}cat ${ALL_DEPS} | tr -d ':\\' | tr ' ' '\012' | \
  1269. grep -v /lib20/ | \
  1270. sed -e "s/${SRCDIRPAT}//" | \
  1271. egrep '\.[chS]$$' | sort | uniq > $@
  1272. cmd_etags = etags -o ${BUILD}/TAGS $(shell cat ${BUILD}/cscope.files)
  1273. cmd_ctags = ctags -o ${BUILD}/tags $(shell cat ${BUILD}/cscope.files)
  1274. run_if_prog = $(if $(shell which $(1) 2>/dev/null),$(2),)
  1275. .PHONY: tags TAGS xrefs
  1276. tags TAGS xrefs: ${BUILD}/cscope.files
  1277. ${Q}\rm -f ${BUILD}/tags ${BUILD}/TAGS
  1278. ${Q}$(call run_if_prog,etags,${cmd_etags})
  1279. ${Q}$(call run_if_prog,ctags,${cmd_ctags})
  1280. PC_FILES = ${PC_IN_FILES:%.pc.in=${BUILD}/%.pc}
  1281. ${PC_FILES}: ${PC_IN_FILES}
  1282. ${Q}sed \
  1283. -e 's:@LDLIBS@:${LDLIBS}:' \
  1284. -e 's:@LIBDIR@:${LIBDIR}:' \
  1285. $< > $@
  1286. .PHONY: pc_files_install
  1287. pc_files_install: ${PC_FILES}
  1288. ${Q}mkdir -p ${ULP_DIR}
  1289. ${Q}${INSTALL} -D -m 0644 $< ${ULP_DIR}/$(notdir $<)