blob: e912bf0726d36312d7bdfc0ccd6d4babeadbdb20 [file] [log] [blame]
Martin Rothf362bbd2023-08-04 12:24:24 -06001## SPDX-License-Identifier: GPL-2.0-only
2
Arthur Heymans94fe0862020-10-15 13:57:52 +02003ifeq ($(CONFIG_INTEL_CBNT_SUPPORT),y)
4
Arthur Heymansee55d712021-05-12 16:22:05 +02005all-y += logging.c
Arthur Heymans23907542021-03-16 19:28:50 +01006ramstage-y += cmos.c
7
Arthur Heymans8b91c9f2021-03-31 12:21:32 +02008# As specified in Intel Trusted Execution Technology and Boot Guard Server BIOS
9# Specification, document number # 558294
10PK_HASH_ALG_SHA1:=4
11PK_HASH_ALG_SHA256:=11
12PK_HASH_ALG_SHA384:=12
13
Arthur Heymans21176dd2021-03-17 15:33:26 +010014# The private key also contains the public key, so use that if a private key is provided.
15ifeq ($(CONFIG_INTEL_CBNT_NEED_KM_PRIV_KEY),y)
16$(obj)/km_pub.pem: $(call strip_quotes, $(CONFIG_INTEL_CBNT_KM_PRIV_KEY_FILE))
17 openssl pkey -in $< -pubout > $@
18else ifeq ($(CONFIG_INTEL_CBNT_NEED_KM_PUB_KEY),y)
19$(obj)/km_pub.pem: $(call strip_quotes, $(CONFIG_INTEL_CBNT_KM_PUB_KEY_FILE))
20 cp $< $@
21endif
22
23# The private key also contains the public key, so use that if a private key is provided.
24ifeq ($(CONFIG_INTEL_CBNT_NEED_BPM_PRIV_KEY),y)
25$(obj)/bpm_pub.pem: $(call strip_quotes, $(CONFIG_INTEL_CBNT_BPM_PRIV_KEY_FILE))
26 openssl pkey -in $< -pubout > $@
27else ifeq ($(CONFIG_INTEL_CBNT_NEED_BPM_PUB_KEY),y)
28$(obj)/bpm_pub.pem: $(call strip_quotes, $(CONFIG_INTEL_CBNT_BPM_PUB_KEY_FILE))
29 cp $< $@
30endif
31
Arthur Heymans53164ba2021-05-06 11:15:32 +020032CBNT_PROV:=$(obj)/cbnt-prov
Arthur Heymans2ef2e472021-02-08 14:28:03 +010033CBNT_CFG:=$(obj)/cbnt.json
34
Arthur Heymans0250a782021-03-31 16:54:37 +020035ifneq ($(CONFIG_INTEL_CBNT_PROV_EXTERNAL_BIN),y)
Arthur Heymans53164ba2021-05-06 11:15:32 +020036$(CBNT_PROV):
37 printf " CBNT_PROV building tool\n"
Arthur Heymans2ef2e472021-02-08 14:28:03 +010038 cd 3rdparty/intel-sec-tools; \
Elyes Haouasd985e9d2023-06-15 19:09:51 +020039 GO111MODULE=on go build -o $(abspath $@) cmd/cbnt-prov/main.go cmd/cbnt-prov/cmd.go
Arthur Heymans0250a782021-03-31 16:54:37 +020040else
41$(CBNT_PROV): $(call strip_quotes, $(CONFIG_INTEL_CBNT_PROV_EXTERNAL_BIN_PATH))
42 cp $< $@
43endif
Arthur Heymans2ef2e472021-02-08 14:28:03 +010044
Arthur Heymans53164ba2021-05-06 11:15:32 +020045$(CBNT_CFG): $(call strip_quotes, $(CONFIG_INTEL_CBNT_CBNT_PROV_CFG_FILE))
46 cp $(CONFIG_INTEL_CBNT_CBNT_PROV_CFG_FILE) $@
Arthur Heymans2ef2e472021-02-08 14:28:03 +010047
Arthur Heymans15412c02021-02-08 22:38:40 +010048ifeq ($(CONFIG_INTEL_CBNT_GENERATE_BPM),y)
Arthur Heymans53164ba2021-05-06 11:15:32 +020049ifeq ($(CONFIG_INTEL_CBNT_CBNT_PROV_BPM_USE_CFG_FILE),y)
Arthur Heymans8ae248e2021-07-06 16:21:24 +020050$(obj)/bpm_unsigned.bin: $(obj)/coreboot.pre $(CBNT_PROV) $(CBNT_CFG)
Arthur Heymans53164ba2021-05-06 11:15:32 +020051 printf " CBNT_PROV creating unsigned BPM using config file\n"
52 $(CBNT_PROV) bpm-gen $@ $< --config=$(CBNT_CFG) --cut
Arthur Heymans3d5319e2021-02-19 19:39:56 +010053else
Arthur Heymans8ae248e2021-07-06 16:21:24 +020054$(obj)/bpm_unsigned.bin: $(obj)/coreboot.pre $(CBNT_PROV) set_fit_ptr
Arthur Heymans53164ba2021-05-06 11:15:32 +020055 printf " CBNT_PROV creating unsigned BPM\n"
Arthur Heymans53164ba2021-05-06 11:15:32 +020056 $(CBNT_PROV) bpm-gen $@ $< --revision=$(CONFIG_INTEL_CBNT_BPM_REVISION) \
Arthur Heymans3d5319e2021-02-19 19:39:56 +010057 --svn=$(CONFIG_INTEL_CBNT_BPM_SVN) \
58 --acmsvn=$(CONFIG_INTEL_CBNT_ACM_SVN) \
59 --nems=$(CONFIG_INTEL_CBNT_NUM_NEM_PAGES) \
60 --pbet=$(CONFIG_INTEL_CBNT_PBET) \
61 --ibbflags=$(CONFIG_INTEL_CBNT_IBB_FLAGS) \
62 --entrypoint=$(shell printf "%d" 0xfffffff0) \
Arthur Heymans8b91c9f2021-03-31 12:21:32 +020063 --ibbhash=$(PK_HASH_ALG_SHA256),$(PK_HASH_ALG_SHA1),$(PK_HASH_ALG_SHA384) \
Arthur Heymansf69cece2021-05-04 08:15:22 +020064 --sinitmin=$(CONFIG_INTEL_CBNT_SINIT_SVN) \
Arthur Heymans3d5319e2021-02-19 19:39:56 +010065 --txtflags=0 \
66 --powerdowninterval=$(CONFIG_INTEL_CBNT_PD_INTERVAL) \
67 --acpibaseoffset=$(shell printf "%d" $(CONFIG_INTEL_ACPI_BASE_ADDRESS)) \
68 --powermbaseoffset=$(shell printf "%d" $(CONFIG_INTEL_PCH_PWRM_BASE_ADDRESS)) \
69 --cmosoff0=$(shell printf "%d" $(CONFIG_INTEL_CBNT_CMOS_OFFSET)) \
70 --cmosoff1=$(call int-add, $(CONFIG_INTEL_CBNT_CMOS_OFFSET) 1) \
71 --cut \
72 --out=$(obj)/bpm_cfg.json
73endif
Arthur Heymans15412c02021-02-08 22:38:40 +010074
Arthur Heymans6362df32021-03-17 12:23:20 +010075ifeq ($(CONFIG_INTEL_CBNT_BPM_ONLY_UNSIGNED),y)
76build_complete:: $(obj)/bpm_unsigned.bin
Martin Roth372503f2023-12-08 00:43:23 -070077
78show_notices::
Arthur Heymans6362df32021-03-17 12:23:20 +010079 @printf "\n** WARNING **\n"
80 @printf "Build generated an unsigned BPM image: build/bpm_unsigned.bin.\n"
81 @printf "The resulting image will not work with CBnT.\n"
82 @printf "After you have externally signed the image you can add it to the coreboot image:\n"
83 @printf "$$ cbfstool build/coreboot.rom add -f bpm.bin -n boot_policy_manifest.bin -t raw -a 16\n"
84 @printf "$$ ifittool -r COREBOOT -a -n boot_policy_manifest.bin -t 12 -s 12 -f build/coreboot.rom\n"
85else
Arthur Heymans53164ba2021-05-06 11:15:32 +020086$(obj)/bpm.bin: $(obj)/bpm_unsigned.bin $(CBNT_PROV) $(call strip_quotes, $(CONFIG_INTEL_CBNT_BPM_PRIV_KEY_FILE))
87 printf " CBNT_PROV signing real BPM\n"
88 $(CBNT_PROV) bpm-sign $< $@ $(CONFIG_INTEL_CBNT_BPM_PRIV_KEY_FILE) ""
Arthur Heymans15412c02021-02-08 22:38:40 +010089
90# Add BPM at the end of the build when all files have been added
Arthur Heymans8ae248e2021-07-06 16:21:24 +020091$(call add_intermediate, add_bpm, $(obj)/bpm.bin)
Arthur Heymans15412c02021-02-08 22:38:40 +010092 printf " CBNT Adding BPM\n"
Arthur Heymans8ae248e2021-07-06 16:21:24 +020093 -$(CBFSTOOL) $< remove -n boot_policy_manifest.bin 2>/dev/null
94 $(CBFSTOOL) $< add -f $(obj)/bpm.bin -n boot_policy_manifest.bin -a 0x10 -t raw
95
96$(call add_intermediate, fit_bpm, set_fit_ptr add_bpm $(IFITTOOL))
Arthur Heymans15412c02021-02-08 22:38:40 +010097 printf " IFITTOOL Adding BPM\n"
Arthur Heymans8ae248e2021-07-06 16:21:24 +020098 $(IFITTOOL) -r COREBOOT -a -n boot_policy_manifest.bin -t 12 -s $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES) -f $<
Arthur Heymans15412c02021-02-08 22:38:40 +010099
Arthur Heymans6362df32021-03-17 12:23:20 +0100100endif # CONFIG_INTEL_CBNT_BPM_ONLY_UNSIGNED
101
Arthur Heymans15412c02021-02-08 22:38:40 +0100102else # CONFIG_INTEL_CBNT_GENERATE_BPM
Arthur Heymans6362df32021-03-17 12:23:20 +0100103
Arthur Heymans94fe0862020-10-15 13:57:52 +0200104ifneq ($(CONFIG_INTEL_CBNT_BOOT_POLICY_MANIFEST_BINARY),"")
105cbfs-files-y += boot_policy_manifest.bin
106boot_policy_manifest.bin-file := $(CONFIG_INTEL_CBNT_BOOT_POLICY_MANIFEST_BINARY)
107boot_policy_manifest.bin-type := raw
108boot_policy_manifest.bin-align := 0x10
109
Arthur Heymanseeacd832021-02-19 17:14:23 +0100110$(call add_intermediate, add_bpm_fit, $(IFITTOOL) set_fit_ptr)
Arthur Heymans94fe0862020-10-15 13:57:52 +0200111 $(IFITTOOL) -r COREBOOT -a -n boot_policy_manifest.bin -t 12 -s $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES) -f $<
112endif
Arthur Heymans15412c02021-02-08 22:38:40 +0100113endif # CONFIG_INTEL_CBNT_GENERATE_BPM
Arthur Heymans94fe0862020-10-15 13:57:52 +0200114
Arthur Heymans2ef2e472021-02-08 14:28:03 +0100115ifeq ($(CONFIG_INTEL_CBNT_GENERATE_KM),y)
Arthur Heymans53164ba2021-05-06 11:15:32 +0200116ifeq ($(CONFIG_INTEL_CBNT_CBNT_PROV_KM_USE_CFG_FILE),y)
117$(obj)/km_unsigned.bin: $(obj)/km_pub.pem $(CBNT_PROV) $(CBNT_CFG)
118 printf " CBNT_PROV creating unsigned KM using config file\n"
119 $(CBNT_PROV) km-gen $@ $< --config=$(CBNT_CFG)
Arthur Heymans05143242021-02-08 19:41:23 +0100120else
Arthur Heymans53164ba2021-05-06 11:15:32 +0200121$(obj)/km_unsigned.bin: $(obj)/km_pub.pem $(obj)/bpm_pub.pem $(CBNT_PROV)
122 printf " CBNT_PROV creating unsigned KM\n"
123 $(CBNT_PROV) km-gen $@ $< --revision=$(CONFIG_INTEL_CBNT_KM_REVISION) \
Arthur Heymans05143242021-02-08 19:41:23 +0100124 --svn=$(CONFIG_INTEL_CBNT_KM_SVN) \
125 --id=$(CONFIG_INTEL_CBNT_KM_ID) \
126 --pkhashalg=$(PK_HASH_ALG_SHA256) \
127 --bpmpubkey=$(obj)/bpm_pub.pem \
128 --bpmhashalgo=$(PK_HASH_ALG_SHA256) \
129 --out=$(obj)/km_cfg.json
130endif
Arthur Heymans2ef2e472021-02-08 14:28:03 +0100131
Arthur Heymans53164ba2021-05-06 11:15:32 +0200132$(obj)/km.bin: $(obj)/km_unsigned.bin $(CBNT_PROV) $(call strip_quotes, $(CONFIG_INTEL_CBNT_KM_PRIV_KEY_FILE))
133 printf " CBNT_PROV signing KM\n"
134 $(CBNT_PROV) km-sign $< $@ $(CONFIG_INTEL_CBNT_KM_PRIV_KEY_FILE) ""
Arthur Heymans2ef2e472021-02-08 14:28:03 +0100135
136KM_FILE=$(obj)/km.bin
137else
138KM_FILE=$(CONFIG_INTEL_CBNT_KEY_MANIFEST_BINARY)
139endif
140
141ifneq ($(KM_FILE),"")
Arthur Heymans5e0119e2021-03-17 12:03:39 +0100142ifeq ($(CONFIG_INTEL_CBNT_KM_ONLY_UNSIGNED),y)
143$(call add_intermediate, gen_unsigned_km, $(obj)/km_unsigned.bin)
144 @printf "Generating unsgined KM\n"
145
Martin Roth372503f2023-12-08 00:43:23 -0700146show_notices::
Arthur Heymans5e0119e2021-03-17 12:03:39 +0100147 @printf "\n** WARNING **\n"
148 @printf "Build generated an unsigned KM image: build/km_unsiged.bin.\n"
149 @printf "The resulting image will not work with CBnT.\n"
150 @printf "After you have externally signed the image you can add it to the coreboot image:\n"
151 @printf "$$ cbfstool build/coreboot.rom add -f km.bin -n key_manifest.bin -t raw -a 16\n"
152 @printf "$$ ifittool -r COREBOOT -a -n key_manifest.bin -t 11 -s 12 -f build/coreboot.rom\n"
153
154else
Arthur Heymans94fe0862020-10-15 13:57:52 +0200155cbfs-files-y += key_manifest.bin
Arthur Heymans2ef2e472021-02-08 14:28:03 +0100156key_manifest.bin-file := $(KM_FILE)
Arthur Heymans94fe0862020-10-15 13:57:52 +0200157key_manifest.bin-type := raw
158key_manifest.bin-align := 0x10
159
Arthur Heymanseeacd832021-02-19 17:14:23 +0100160$(call add_intermediate, add_km_fit, $(IFITTOOL) set_fit_ptr)
Arthur Heymans94fe0862020-10-15 13:57:52 +0200161 $(IFITTOOL) -r COREBOOT -a -n key_manifest.bin -t 11 -s $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES) -f $<
162endif
163
Arthur Heymans5e0119e2021-03-17 12:03:39 +0100164endif # CONFIG_INTEL_CBNT_KM_ONLY_UNSIGNED
Arthur Heymans94fe0862020-10-15 13:57:52 +0200165endif # CONFIG_INTEL_CBNT_SUPPORT