blob: 9ade1cdce95e211862a569b7d158090d8ea7a564 [file] [log] [blame]
Arthur Heymans94fe0862020-10-15 13:57:52 +02001ifeq ($(CONFIG_INTEL_CBNT_SUPPORT),y)
2
Arthur Heymans23907542021-03-16 19:28:50 +01003ramstage-y += cmos.c
4
Arthur Heymans8b91c9f2021-03-31 12:21:32 +02005# As specified in Intel Trusted Execution Technology and Boot Guard Server BIOS
6# Specification, document number # 558294
7PK_HASH_ALG_SHA1:=4
8PK_HASH_ALG_SHA256:=11
9PK_HASH_ALG_SHA384:=12
10
Arthur Heymans21176dd2021-03-17 15:33:26 +010011# The private key also contains the public key, so use that if a private key is provided.
12ifeq ($(CONFIG_INTEL_CBNT_NEED_KM_PRIV_KEY),y)
13$(obj)/km_pub.pem: $(call strip_quotes, $(CONFIG_INTEL_CBNT_KM_PRIV_KEY_FILE))
14 openssl pkey -in $< -pubout > $@
15else ifeq ($(CONFIG_INTEL_CBNT_NEED_KM_PUB_KEY),y)
16$(obj)/km_pub.pem: $(call strip_quotes, $(CONFIG_INTEL_CBNT_KM_PUB_KEY_FILE))
17 cp $< $@
18endif
19
20# The private key also contains the public key, so use that if a private key is provided.
21ifeq ($(CONFIG_INTEL_CBNT_NEED_BPM_PRIV_KEY),y)
22$(obj)/bpm_pub.pem: $(call strip_quotes, $(CONFIG_INTEL_CBNT_BPM_PRIV_KEY_FILE))
23 openssl pkey -in $< -pubout > $@
24else ifeq ($(CONFIG_INTEL_CBNT_NEED_BPM_PUB_KEY),y)
25$(obj)/bpm_pub.pem: $(call strip_quotes, $(CONFIG_INTEL_CBNT_BPM_PUB_KEY_FILE))
26 cp $< $@
27endif
28
Arthur Heymans53164ba2021-05-06 11:15:32 +020029CBNT_PROV:=$(obj)/cbnt-prov
Arthur Heymans2ef2e472021-02-08 14:28:03 +010030CBNT_CFG:=$(obj)/cbnt.json
31
Arthur Heymans0250a782021-03-31 16:54:37 +020032ifneq ($(CONFIG_INTEL_CBNT_PROV_EXTERNAL_BIN),y)
Arthur Heymans53164ba2021-05-06 11:15:32 +020033$(CBNT_PROV):
34 printf " CBNT_PROV building tool\n"
Arthur Heymans2ef2e472021-02-08 14:28:03 +010035 cd 3rdparty/intel-sec-tools; \
36 GO111MODULE=on go mod download; \
37 GO111MODULE=on go mod verify; \
Arthur Heymanse76aac62021-06-18 09:40:31 +020038 GO111MODULE=on go build -o $(abspath $@) cmd/cbnt-prov/*.go
Arthur Heymans0250a782021-03-31 16:54:37 +020039else
40$(CBNT_PROV): $(call strip_quotes, $(CONFIG_INTEL_CBNT_PROV_EXTERNAL_BIN_PATH))
41 cp $< $@
42endif
Arthur Heymans2ef2e472021-02-08 14:28:03 +010043
Arthur Heymans53164ba2021-05-06 11:15:32 +020044$(CBNT_CFG): $(call strip_quotes, $(CONFIG_INTEL_CBNT_CBNT_PROV_CFG_FILE))
45 cp $(CONFIG_INTEL_CBNT_CBNT_PROV_CFG_FILE) $@
Arthur Heymans2ef2e472021-02-08 14:28:03 +010046
Arthur Heymans15412c02021-02-08 22:38:40 +010047ifeq ($(CONFIG_INTEL_CBNT_GENERATE_BPM),y)
Arthur Heymans53164ba2021-05-06 11:15:32 +020048ifeq ($(CONFIG_INTEL_CBNT_CBNT_PROV_BPM_USE_CFG_FILE),y)
49$(obj)/bpm_unsigned.bin: $(obj)/coreboot.rom $(CBNT_PROV) $(CBNT_CFG)
50 printf " CBNT_PROV creating unsigned BPM using config file\n"
51 $(CBNT_PROV) bpm-gen $@ $< --config=$(CBNT_CFG) --cut
Arthur Heymans3d5319e2021-02-19 19:39:56 +010052else
Arthur Heymans53164ba2021-05-06 11:15:32 +020053$(obj)/bpm_unsigned.bin: $(obj)/coreboot.rom $(CBNT_PROV)
54 printf " CBNT_PROV creating unsigned BPM\n"
Arthur Heymans53164ba2021-05-06 11:15:32 +020055 $(CBNT_PROV) bpm-gen $@ $< --revision=$(CONFIG_INTEL_CBNT_BPM_REVISION) \
Arthur Heymans3d5319e2021-02-19 19:39:56 +010056 --svn=$(CONFIG_INTEL_CBNT_BPM_SVN) \
57 --acmsvn=$(CONFIG_INTEL_CBNT_ACM_SVN) \
58 --nems=$(CONFIG_INTEL_CBNT_NUM_NEM_PAGES) \
59 --pbet=$(CONFIG_INTEL_CBNT_PBET) \
60 --ibbflags=$(CONFIG_INTEL_CBNT_IBB_FLAGS) \
61 --entrypoint=$(shell printf "%d" 0xfffffff0) \
Arthur Heymans8b91c9f2021-03-31 12:21:32 +020062 --ibbhash=$(PK_HASH_ALG_SHA256),$(PK_HASH_ALG_SHA1),$(PK_HASH_ALG_SHA384) \
Arthur Heymansf69cece2021-05-04 08:15:22 +020063 --sinitmin=$(CONFIG_INTEL_CBNT_SINIT_SVN) \
Arthur Heymans3d5319e2021-02-19 19:39:56 +010064 --txtflags=0 \
65 --powerdowninterval=$(CONFIG_INTEL_CBNT_PD_INTERVAL) \
66 --acpibaseoffset=$(shell printf "%d" $(CONFIG_INTEL_ACPI_BASE_ADDRESS)) \
67 --powermbaseoffset=$(shell printf "%d" $(CONFIG_INTEL_PCH_PWRM_BASE_ADDRESS)) \
68 --cmosoff0=$(shell printf "%d" $(CONFIG_INTEL_CBNT_CMOS_OFFSET)) \
69 --cmosoff1=$(call int-add, $(CONFIG_INTEL_CBNT_CMOS_OFFSET) 1) \
70 --cut \
71 --out=$(obj)/bpm_cfg.json
72endif
Arthur Heymans15412c02021-02-08 22:38:40 +010073
Arthur Heymans6362df32021-03-17 12:23:20 +010074ifeq ($(CONFIG_INTEL_CBNT_BPM_ONLY_UNSIGNED),y)
75build_complete:: $(obj)/bpm_unsigned.bin
76 @printf "\n** WARNING **\n"
77 @printf "Build generated an unsigned BPM image: build/bpm_unsigned.bin.\n"
78 @printf "The resulting image will not work with CBnT.\n"
79 @printf "After you have externally signed the image you can add it to the coreboot image:\n"
80 @printf "$$ cbfstool build/coreboot.rom add -f bpm.bin -n boot_policy_manifest.bin -t raw -a 16\n"
81 @printf "$$ ifittool -r COREBOOT -a -n boot_policy_manifest.bin -t 12 -s 12 -f build/coreboot.rom\n"
82else
Arthur Heymans53164ba2021-05-06 11:15:32 +020083$(obj)/bpm.bin: $(obj)/bpm_unsigned.bin $(CBNT_PROV) $(call strip_quotes, $(CONFIG_INTEL_CBNT_BPM_PRIV_KEY_FILE))
84 printf " CBNT_PROV signing real BPM\n"
85 $(CBNT_PROV) bpm-sign $< $@ $(CONFIG_INTEL_CBNT_BPM_PRIV_KEY_FILE) ""
Arthur Heymans15412c02021-02-08 22:38:40 +010086
87# Add BPM at the end of the build when all files have been added
88files_added:: $(obj)/bpm.bin
89 printf " CBNT Adding BPM\n"
90 $(CBFSTOOL) $(obj)/coreboot.rom add -f $< -n boot_policy_manifest.bin -a 0x10 -t raw
91 printf " IFITTOOL Adding BPM\n"
92 $(IFITTOOL) -r COREBOOT -a -n boot_policy_manifest.bin -t 12 -s $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES) -f $(obj)/coreboot.rom
93
Arthur Heymans6362df32021-03-17 12:23:20 +010094endif # CONFIG_INTEL_CBNT_BPM_ONLY_UNSIGNED
95
Arthur Heymans15412c02021-02-08 22:38:40 +010096else # CONFIG_INTEL_CBNT_GENERATE_BPM
Arthur Heymans6362df32021-03-17 12:23:20 +010097
Arthur Heymans94fe0862020-10-15 13:57:52 +020098ifneq ($(CONFIG_INTEL_CBNT_BOOT_POLICY_MANIFEST_BINARY),"")
99cbfs-files-y += boot_policy_manifest.bin
100boot_policy_manifest.bin-file := $(CONFIG_INTEL_CBNT_BOOT_POLICY_MANIFEST_BINARY)
101boot_policy_manifest.bin-type := raw
102boot_policy_manifest.bin-align := 0x10
103
Arthur Heymanseeacd832021-02-19 17:14:23 +0100104$(call add_intermediate, add_bpm_fit, $(IFITTOOL) set_fit_ptr)
Arthur Heymans94fe0862020-10-15 13:57:52 +0200105 $(IFITTOOL) -r COREBOOT -a -n boot_policy_manifest.bin -t 12 -s $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES) -f $<
106endif
Arthur Heymans15412c02021-02-08 22:38:40 +0100107endif # CONFIG_INTEL_CBNT_GENERATE_BPM
Arthur Heymans94fe0862020-10-15 13:57:52 +0200108
Arthur Heymans2ef2e472021-02-08 14:28:03 +0100109ifeq ($(CONFIG_INTEL_CBNT_GENERATE_KM),y)
Arthur Heymans53164ba2021-05-06 11:15:32 +0200110ifeq ($(CONFIG_INTEL_CBNT_CBNT_PROV_KM_USE_CFG_FILE),y)
111$(obj)/km_unsigned.bin: $(obj)/km_pub.pem $(CBNT_PROV) $(CBNT_CFG)
112 printf " CBNT_PROV creating unsigned KM using config file\n"
113 $(CBNT_PROV) km-gen $@ $< --config=$(CBNT_CFG)
Arthur Heymans05143242021-02-08 19:41:23 +0100114else
Arthur Heymans53164ba2021-05-06 11:15:32 +0200115$(obj)/km_unsigned.bin: $(obj)/km_pub.pem $(obj)/bpm_pub.pem $(CBNT_PROV)
116 printf " CBNT_PROV creating unsigned KM\n"
117 $(CBNT_PROV) km-gen $@ $< --revision=$(CONFIG_INTEL_CBNT_KM_REVISION) \
Arthur Heymans05143242021-02-08 19:41:23 +0100118 --svn=$(CONFIG_INTEL_CBNT_KM_SVN) \
119 --id=$(CONFIG_INTEL_CBNT_KM_ID) \
120 --pkhashalg=$(PK_HASH_ALG_SHA256) \
121 --bpmpubkey=$(obj)/bpm_pub.pem \
122 --bpmhashalgo=$(PK_HASH_ALG_SHA256) \
123 --out=$(obj)/km_cfg.json
124endif
Arthur Heymans2ef2e472021-02-08 14:28:03 +0100125
Arthur Heymans53164ba2021-05-06 11:15:32 +0200126$(obj)/km.bin: $(obj)/km_unsigned.bin $(CBNT_PROV) $(call strip_quotes, $(CONFIG_INTEL_CBNT_KM_PRIV_KEY_FILE))
127 printf " CBNT_PROV signing KM\n"
128 $(CBNT_PROV) km-sign $< $@ $(CONFIG_INTEL_CBNT_KM_PRIV_KEY_FILE) ""
Arthur Heymans2ef2e472021-02-08 14:28:03 +0100129
130KM_FILE=$(obj)/km.bin
131else
132KM_FILE=$(CONFIG_INTEL_CBNT_KEY_MANIFEST_BINARY)
133endif
134
135ifneq ($(KM_FILE),"")
Arthur Heymans5e0119e2021-03-17 12:03:39 +0100136ifeq ($(CONFIG_INTEL_CBNT_KM_ONLY_UNSIGNED),y)
137$(call add_intermediate, gen_unsigned_km, $(obj)/km_unsigned.bin)
138 @printf "Generating unsgined KM\n"
139
140build_complete::
141 @printf "\n** WARNING **\n"
142 @printf "Build generated an unsigned KM image: build/km_unsiged.bin.\n"
143 @printf "The resulting image will not work with CBnT.\n"
144 @printf "After you have externally signed the image you can add it to the coreboot image:\n"
145 @printf "$$ cbfstool build/coreboot.rom add -f km.bin -n key_manifest.bin -t raw -a 16\n"
146 @printf "$$ ifittool -r COREBOOT -a -n key_manifest.bin -t 11 -s 12 -f build/coreboot.rom\n"
147
148else
Arthur Heymans94fe0862020-10-15 13:57:52 +0200149cbfs-files-y += key_manifest.bin
Arthur Heymans2ef2e472021-02-08 14:28:03 +0100150key_manifest.bin-file := $(KM_FILE)
Arthur Heymans94fe0862020-10-15 13:57:52 +0200151key_manifest.bin-type := raw
152key_manifest.bin-align := 0x10
153
Arthur Heymanseeacd832021-02-19 17:14:23 +0100154$(call add_intermediate, add_km_fit, $(IFITTOOL) set_fit_ptr)
Arthur Heymans94fe0862020-10-15 13:57:52 +0200155 $(IFITTOOL) -r COREBOOT -a -n key_manifest.bin -t 11 -s $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES) -f $<
156endif
157
Arthur Heymans5e0119e2021-03-17 12:03:39 +0100158endif # CONFIG_INTEL_CBNT_KM_ONLY_UNSIGNED
Arthur Heymans94fe0862020-10-15 13:57:52 +0200159endif # CONFIG_INTEL_CBNT_SUPPORT