blob: 788b1b75672942110bcae42e106b642178056d45 [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 Heymans21176dd2021-03-17 15:33:26 +01005# The private key also contains the public key, so use that if a private key is provided.
6ifeq ($(CONFIG_INTEL_CBNT_NEED_KM_PRIV_KEY),y)
7$(obj)/km_pub.pem: $(call strip_quotes, $(CONFIG_INTEL_CBNT_KM_PRIV_KEY_FILE))
8 openssl pkey -in $< -pubout > $@
9else ifeq ($(CONFIG_INTEL_CBNT_NEED_KM_PUB_KEY),y)
10$(obj)/km_pub.pem: $(call strip_quotes, $(CONFIG_INTEL_CBNT_KM_PUB_KEY_FILE))
11 cp $< $@
12endif
13
14# The private key also contains the public key, so use that if a private key is provided.
15ifeq ($(CONFIG_INTEL_CBNT_NEED_BPM_PRIV_KEY),y)
16$(obj)/bpm_pub.pem: $(call strip_quotes, $(CONFIG_INTEL_CBNT_BPM_PRIV_KEY_FILE))
17 openssl pkey -in $< -pubout > $@
18else ifeq ($(CONFIG_INTEL_CBNT_NEED_BPM_PUB_KEY),y)
19$(obj)/bpm_pub.pem: $(call strip_quotes, $(CONFIG_INTEL_CBNT_BPM_PUB_KEY_FILE))
20 cp $< $@
21endif
22
Arthur Heymans2ef2e472021-02-08 14:28:03 +010023BG_PROV:=$(obj)/bg-prov
24CBNT_CFG:=$(obj)/cbnt.json
25
26$(BG_PROV):
27 printf " BG_PROV building tool\n"
28 cd 3rdparty/intel-sec-tools; \
29 GO111MODULE=on go mod download; \
30 GO111MODULE=on go mod verify; \
31 GO111MODULE=on go build -o $(top)/$@ cmd/bg-prov/*.go
32
33$(CBNT_CFG): $(call strip_quotes, $(CONFIG_INTEL_CBNT_BG_PROV_CFG_FILE))
34 cp $(CONFIG_INTEL_CBNT_BG_PROV_CFG_FILE) $@
35
Arthur Heymans15412c02021-02-08 22:38:40 +010036ifeq ($(CONFIG_INTEL_CBNT_GENERATE_BPM),y)
Arthur Heymans3d5319e2021-02-19 19:39:56 +010037ifeq ($(CONFIG_INTEL_CBNT_BG_PROV_BPM_USE_CFG_FILE),y)
Arthur Heymans15412c02021-02-08 22:38:40 +010038$(obj)/bpm_unsigned.bin: $(obj)/coreboot.rom $(BG_PROV) $(CBNT_CFG)
39 printf " BG_PROV creating unsigned BPM using config file\n"
40 $(BG_PROV) bpm-gen $@ $< --config=$(CBNT_CFG) --cut
Arthur Heymans3d5319e2021-02-19 19:39:56 +010041else
42$(obj)/bpm_unsigned.bin: $(obj)/coreboot.rom $(BG_PROV)
43 printf " BG_PROV creating unsigned BPM\n"
44 # SHA256, SHA1, SHA384 for digest
45 $(BG_PROV) bpm-gen $@ $< --revision=$(CONFIG_INTEL_CBNT_BPM_REVISION) \
46 --svn=$(CONFIG_INTEL_CBNT_BPM_SVN) \
47 --acmsvn=$(CONFIG_INTEL_CBNT_ACM_SVN) \
48 --nems=$(CONFIG_INTEL_CBNT_NUM_NEM_PAGES) \
49 --pbet=$(CONFIG_INTEL_CBNT_PBET) \
50 --ibbflags=$(CONFIG_INTEL_CBNT_IBB_FLAGS) \
51 --entrypoint=$(shell printf "%d" 0xfffffff0) \
52 --ibbhash={11,4,12} \
53 --ibbsegbase=$(call int-add, $(call int-subtract, 0xffffffff $(CONFIG_C_ENV_BOOTBLOCK_SIZE)) 1) \
54 --ibbsegsize=$(shell printf "%d" $(CONFIG_C_ENV_BOOTBLOCK_SIZE)) \
55 --ibbsegflag=0 \
56 --sintmin=$(CONFIG_INTEL_CBNT_SINIT_SVN) \
57 --txtflags=0 \
58 --powerdowninterval=$(CONFIG_INTEL_CBNT_PD_INTERVAL) \
59 --acpibaseoffset=$(shell printf "%d" $(CONFIG_INTEL_ACPI_BASE_ADDRESS)) \
60 --powermbaseoffset=$(shell printf "%d" $(CONFIG_INTEL_PCH_PWRM_BASE_ADDRESS)) \
61 --cmosoff0=$(shell printf "%d" $(CONFIG_INTEL_CBNT_CMOS_OFFSET)) \
62 --cmosoff1=$(call int-add, $(CONFIG_INTEL_CBNT_CMOS_OFFSET) 1) \
63 --cut \
64 --out=$(obj)/bpm_cfg.json
65endif
Arthur Heymans15412c02021-02-08 22:38:40 +010066
Arthur Heymans6362df32021-03-17 12:23:20 +010067ifeq ($(CONFIG_INTEL_CBNT_BPM_ONLY_UNSIGNED),y)
68build_complete:: $(obj)/bpm_unsigned.bin
69 @printf "\n** WARNING **\n"
70 @printf "Build generated an unsigned BPM image: build/bpm_unsigned.bin.\n"
71 @printf "The resulting image will not work with CBnT.\n"
72 @printf "After you have externally signed the image you can add it to the coreboot image:\n"
73 @printf "$$ cbfstool build/coreboot.rom add -f bpm.bin -n boot_policy_manifest.bin -t raw -a 16\n"
74 @printf "$$ ifittool -r COREBOOT -a -n boot_policy_manifest.bin -t 12 -s 12 -f build/coreboot.rom\n"
75else
Arthur Heymans15412c02021-02-08 22:38:40 +010076$(obj)/bpm.bin: $(obj)/bpm_unsigned.bin $(BG_PROV) $(call strip_quotes, $(CONFIG_INTEL_CBNT_BPM_PRIV_KEY_FILE))
77 printf " BG_PROV signing real BPM\n"
78 $(BG_PROV) bpm-sign $< $@ $(CONFIG_INTEL_CBNT_BPM_PRIV_KEY_FILE) ""
79
80# Add BPM at the end of the build when all files have been added
81files_added:: $(obj)/bpm.bin
82 printf " CBNT Adding BPM\n"
83 $(CBFSTOOL) $(obj)/coreboot.rom add -f $< -n boot_policy_manifest.bin -a 0x10 -t raw
84 printf " IFITTOOL Adding BPM\n"
85 $(IFITTOOL) -r COREBOOT -a -n boot_policy_manifest.bin -t 12 -s $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES) -f $(obj)/coreboot.rom
86
Arthur Heymans6362df32021-03-17 12:23:20 +010087endif # CONFIG_INTEL_CBNT_BPM_ONLY_UNSIGNED
88
Arthur Heymans15412c02021-02-08 22:38:40 +010089else # CONFIG_INTEL_CBNT_GENERATE_BPM
Arthur Heymans6362df32021-03-17 12:23:20 +010090
Arthur Heymans94fe0862020-10-15 13:57:52 +020091ifneq ($(CONFIG_INTEL_CBNT_BOOT_POLICY_MANIFEST_BINARY),"")
92cbfs-files-y += boot_policy_manifest.bin
93boot_policy_manifest.bin-file := $(CONFIG_INTEL_CBNT_BOOT_POLICY_MANIFEST_BINARY)
94boot_policy_manifest.bin-type := raw
95boot_policy_manifest.bin-align := 0x10
96
Arthur Heymanseeacd832021-02-19 17:14:23 +010097$(call add_intermediate, add_bpm_fit, $(IFITTOOL) set_fit_ptr)
Arthur Heymans94fe0862020-10-15 13:57:52 +020098 $(IFITTOOL) -r COREBOOT -a -n boot_policy_manifest.bin -t 12 -s $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES) -f $<
99endif
Arthur Heymans15412c02021-02-08 22:38:40 +0100100endif # CONFIG_INTEL_CBNT_GENERATE_BPM
Arthur Heymans94fe0862020-10-15 13:57:52 +0200101
Arthur Heymans2ef2e472021-02-08 14:28:03 +0100102ifeq ($(CONFIG_INTEL_CBNT_GENERATE_KM),y)
Arthur Heymans05143242021-02-08 19:41:23 +0100103ifeq ($(CONFIG_INTEL_CBNT_BG_PROV_KM_USE_CFG_FILE),y)
Arthur Heymans2ef2e472021-02-08 14:28:03 +0100104$(obj)/km_unsigned.bin: $(obj)/km_pub.pem $(BG_PROV) $(CBNT_CFG)
105 printf " BG_PROV creating unsigned KM using config file\n"
106 $(BG_PROV) km-gen $@ $< --config=$(CBNT_CFG)
Arthur Heymans05143242021-02-08 19:41:23 +0100107else
108PK_HASH_ALG_SHA256:=11 # Hardcode as no other options are available for CBnT
109$(obj)/km_unsigned.bin: $(obj)/km_pub.pem $(obj)/bpm_pub.pem $(BG_PROV)
110 printf " BG_PROV creating unsigned KM\n"
111 $(BG_PROV) km-gen $@ $< --revision=$(CONFIG_INTEL_CBNT_KM_REVISION) \
112 --svn=$(CONFIG_INTEL_CBNT_KM_SVN) \
113 --id=$(CONFIG_INTEL_CBNT_KM_ID) \
114 --pkhashalg=$(PK_HASH_ALG_SHA256) \
115 --bpmpubkey=$(obj)/bpm_pub.pem \
116 --bpmhashalgo=$(PK_HASH_ALG_SHA256) \
117 --out=$(obj)/km_cfg.json
118endif
Arthur Heymans2ef2e472021-02-08 14:28:03 +0100119
120$(obj)/km.bin: $(obj)/km_unsigned.bin $(BG_PROV) $(call strip_quotes, $(CONFIG_INTEL_CBNT_KM_PRIV_KEY_FILE))
121 printf " BG_PROV signing KM\n"
122 $(BG_PROV) km-sign $< $@ $(CONFIG_INTEL_CBNT_KM_PRIV_KEY_FILE) ""
123
124KM_FILE=$(obj)/km.bin
125else
126KM_FILE=$(CONFIG_INTEL_CBNT_KEY_MANIFEST_BINARY)
127endif
128
129ifneq ($(KM_FILE),"")
Arthur Heymans5e0119e2021-03-17 12:03:39 +0100130ifeq ($(CONFIG_INTEL_CBNT_KM_ONLY_UNSIGNED),y)
131$(call add_intermediate, gen_unsigned_km, $(obj)/km_unsigned.bin)
132 @printf "Generating unsgined KM\n"
133
134build_complete::
135 @printf "\n** WARNING **\n"
136 @printf "Build generated an unsigned KM image: build/km_unsiged.bin.\n"
137 @printf "The resulting image will not work with CBnT.\n"
138 @printf "After you have externally signed the image you can add it to the coreboot image:\n"
139 @printf "$$ cbfstool build/coreboot.rom add -f km.bin -n key_manifest.bin -t raw -a 16\n"
140 @printf "$$ ifittool -r COREBOOT -a -n key_manifest.bin -t 11 -s 12 -f build/coreboot.rom\n"
141
142else
Arthur Heymans94fe0862020-10-15 13:57:52 +0200143cbfs-files-y += key_manifest.bin
Arthur Heymans2ef2e472021-02-08 14:28:03 +0100144key_manifest.bin-file := $(KM_FILE)
Arthur Heymans94fe0862020-10-15 13:57:52 +0200145key_manifest.bin-type := raw
146key_manifest.bin-align := 0x10
147
Arthur Heymanseeacd832021-02-19 17:14:23 +0100148$(call add_intermediate, add_km_fit, $(IFITTOOL) set_fit_ptr)
Arthur Heymans94fe0862020-10-15 13:57:52 +0200149 $(IFITTOOL) -r COREBOOT -a -n key_manifest.bin -t 11 -s $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES) -f $<
150endif
151
Arthur Heymans5e0119e2021-03-17 12:03:39 +0100152endif # CONFIG_INTEL_CBNT_KM_ONLY_UNSIGNED
Arthur Heymans94fe0862020-10-15 13:57:52 +0200153endif # CONFIG_INTEL_CBNT_SUPPORT