blob: e16663435142ce59fc43a02c66faab89a42a82f8 [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
77 @printf "\n** WARNING **\n"
78 @printf "Build generated an unsigned BPM image: build/bpm_unsigned.bin.\n"
79 @printf "The resulting image will not work with CBnT.\n"
80 @printf "After you have externally signed the image you can add it to the coreboot image:\n"
81 @printf "$$ cbfstool build/coreboot.rom add -f bpm.bin -n boot_policy_manifest.bin -t raw -a 16\n"
82 @printf "$$ ifittool -r COREBOOT -a -n boot_policy_manifest.bin -t 12 -s 12 -f build/coreboot.rom\n"
83else
Arthur Heymans53164ba2021-05-06 11:15:32 +020084$(obj)/bpm.bin: $(obj)/bpm_unsigned.bin $(CBNT_PROV) $(call strip_quotes, $(CONFIG_INTEL_CBNT_BPM_PRIV_KEY_FILE))
85 printf " CBNT_PROV signing real BPM\n"
86 $(CBNT_PROV) bpm-sign $< $@ $(CONFIG_INTEL_CBNT_BPM_PRIV_KEY_FILE) ""
Arthur Heymans15412c02021-02-08 22:38:40 +010087
88# Add BPM at the end of the build when all files have been added
Arthur Heymans8ae248e2021-07-06 16:21:24 +020089$(call add_intermediate, add_bpm, $(obj)/bpm.bin)
Arthur Heymans15412c02021-02-08 22:38:40 +010090 printf " CBNT Adding BPM\n"
Arthur Heymans8ae248e2021-07-06 16:21:24 +020091 -$(CBFSTOOL) $< remove -n boot_policy_manifest.bin 2>/dev/null
92 $(CBFSTOOL) $< add -f $(obj)/bpm.bin -n boot_policy_manifest.bin -a 0x10 -t raw
93
94$(call add_intermediate, fit_bpm, set_fit_ptr add_bpm $(IFITTOOL))
Arthur Heymans15412c02021-02-08 22:38:40 +010095 printf " IFITTOOL Adding BPM\n"
Arthur Heymans8ae248e2021-07-06 16:21:24 +020096 $(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 +010097
Arthur Heymans6362df32021-03-17 12:23:20 +010098endif # CONFIG_INTEL_CBNT_BPM_ONLY_UNSIGNED
99
Arthur Heymans15412c02021-02-08 22:38:40 +0100100else # CONFIG_INTEL_CBNT_GENERATE_BPM
Arthur Heymans6362df32021-03-17 12:23:20 +0100101
Arthur Heymans94fe0862020-10-15 13:57:52 +0200102ifneq ($(CONFIG_INTEL_CBNT_BOOT_POLICY_MANIFEST_BINARY),"")
103cbfs-files-y += boot_policy_manifest.bin
104boot_policy_manifest.bin-file := $(CONFIG_INTEL_CBNT_BOOT_POLICY_MANIFEST_BINARY)
105boot_policy_manifest.bin-type := raw
106boot_policy_manifest.bin-align := 0x10
107
Arthur Heymanseeacd832021-02-19 17:14:23 +0100108$(call add_intermediate, add_bpm_fit, $(IFITTOOL) set_fit_ptr)
Arthur Heymans94fe0862020-10-15 13:57:52 +0200109 $(IFITTOOL) -r COREBOOT -a -n boot_policy_manifest.bin -t 12 -s $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES) -f $<
110endif
Arthur Heymans15412c02021-02-08 22:38:40 +0100111endif # CONFIG_INTEL_CBNT_GENERATE_BPM
Arthur Heymans94fe0862020-10-15 13:57:52 +0200112
Arthur Heymans2ef2e472021-02-08 14:28:03 +0100113ifeq ($(CONFIG_INTEL_CBNT_GENERATE_KM),y)
Arthur Heymans53164ba2021-05-06 11:15:32 +0200114ifeq ($(CONFIG_INTEL_CBNT_CBNT_PROV_KM_USE_CFG_FILE),y)
115$(obj)/km_unsigned.bin: $(obj)/km_pub.pem $(CBNT_PROV) $(CBNT_CFG)
116 printf " CBNT_PROV creating unsigned KM using config file\n"
117 $(CBNT_PROV) km-gen $@ $< --config=$(CBNT_CFG)
Arthur Heymans05143242021-02-08 19:41:23 +0100118else
Arthur Heymans53164ba2021-05-06 11:15:32 +0200119$(obj)/km_unsigned.bin: $(obj)/km_pub.pem $(obj)/bpm_pub.pem $(CBNT_PROV)
120 printf " CBNT_PROV creating unsigned KM\n"
121 $(CBNT_PROV) km-gen $@ $< --revision=$(CONFIG_INTEL_CBNT_KM_REVISION) \
Arthur Heymans05143242021-02-08 19:41:23 +0100122 --svn=$(CONFIG_INTEL_CBNT_KM_SVN) \
123 --id=$(CONFIG_INTEL_CBNT_KM_ID) \
124 --pkhashalg=$(PK_HASH_ALG_SHA256) \
125 --bpmpubkey=$(obj)/bpm_pub.pem \
126 --bpmhashalgo=$(PK_HASH_ALG_SHA256) \
127 --out=$(obj)/km_cfg.json
128endif
Arthur Heymans2ef2e472021-02-08 14:28:03 +0100129
Arthur Heymans53164ba2021-05-06 11:15:32 +0200130$(obj)/km.bin: $(obj)/km_unsigned.bin $(CBNT_PROV) $(call strip_quotes, $(CONFIG_INTEL_CBNT_KM_PRIV_KEY_FILE))
131 printf " CBNT_PROV signing KM\n"
132 $(CBNT_PROV) km-sign $< $@ $(CONFIG_INTEL_CBNT_KM_PRIV_KEY_FILE) ""
Arthur Heymans2ef2e472021-02-08 14:28:03 +0100133
134KM_FILE=$(obj)/km.bin
135else
136KM_FILE=$(CONFIG_INTEL_CBNT_KEY_MANIFEST_BINARY)
137endif
138
139ifneq ($(KM_FILE),"")
Arthur Heymans5e0119e2021-03-17 12:03:39 +0100140ifeq ($(CONFIG_INTEL_CBNT_KM_ONLY_UNSIGNED),y)
141$(call add_intermediate, gen_unsigned_km, $(obj)/km_unsigned.bin)
142 @printf "Generating unsgined KM\n"
143
144build_complete::
145 @printf "\n** WARNING **\n"
146 @printf "Build generated an unsigned KM image: build/km_unsiged.bin.\n"
147 @printf "The resulting image will not work with CBnT.\n"
148 @printf "After you have externally signed the image you can add it to the coreboot image:\n"
149 @printf "$$ cbfstool build/coreboot.rom add -f km.bin -n key_manifest.bin -t raw -a 16\n"
150 @printf "$$ ifittool -r COREBOOT -a -n key_manifest.bin -t 11 -s 12 -f build/coreboot.rom\n"
151
152else
Arthur Heymans94fe0862020-10-15 13:57:52 +0200153cbfs-files-y += key_manifest.bin
Arthur Heymans2ef2e472021-02-08 14:28:03 +0100154key_manifest.bin-file := $(KM_FILE)
Arthur Heymans94fe0862020-10-15 13:57:52 +0200155key_manifest.bin-type := raw
156key_manifest.bin-align := 0x10
157
Arthur Heymanseeacd832021-02-19 17:14:23 +0100158$(call add_intermediate, add_km_fit, $(IFITTOOL) set_fit_ptr)
Arthur Heymans94fe0862020-10-15 13:57:52 +0200159 $(IFITTOOL) -r COREBOOT -a -n key_manifest.bin -t 11 -s $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES) -f $<
160endif
161
Arthur Heymans5e0119e2021-03-17 12:03:39 +0100162endif # CONFIG_INTEL_CBNT_KM_ONLY_UNSIGNED
Arthur Heymans94fe0862020-10-15 13:57:52 +0200163endif # CONFIG_INTEL_CBNT_SUPPORT