Arthur Heymans | 94fe086 | 2020-10-15 13:57:52 +0200 | [diff] [blame] | 1 | ifeq ($(CONFIG_INTEL_CBNT_SUPPORT),y) |
| 2 | |
Arthur Heymans | 2390754 | 2021-03-16 19:28:50 +0100 | [diff] [blame] | 3 | ramstage-y += cmos.c |
| 4 | |
Arthur Heymans | 21176dd | 2021-03-17 15:33:26 +0100 | [diff] [blame] | 5 | # The private key also contains the public key, so use that if a private key is provided. |
| 6 | ifeq ($(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 > $@ |
| 9 | else 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 $< $@ |
| 12 | endif |
| 13 | |
| 14 | # The private key also contains the public key, so use that if a private key is provided. |
| 15 | ifeq ($(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 > $@ |
| 18 | else 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 $< $@ |
| 21 | endif |
| 22 | |
Arthur Heymans | 2ef2e47 | 2021-02-08 14:28:03 +0100 | [diff] [blame] | 23 | BG_PROV:=$(obj)/bg-prov |
| 24 | CBNT_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 Heymans | 15412c0 | 2021-02-08 22:38:40 +0100 | [diff] [blame] | 36 | ifeq ($(CONFIG_INTEL_CBNT_GENERATE_BPM),y) |
Arthur Heymans | 3d5319e | 2021-02-19 19:39:56 +0100 | [diff] [blame] | 37 | ifeq ($(CONFIG_INTEL_CBNT_BG_PROV_BPM_USE_CFG_FILE),y) |
Arthur Heymans | 15412c0 | 2021-02-08 22:38:40 +0100 | [diff] [blame] | 38 | $(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 Heymans | 3d5319e | 2021-02-19 19:39:56 +0100 | [diff] [blame] | 41 | else |
| 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) \ |
Christian Walter | 647e2c9 | 2021-03-31 12:04:43 +0200 | [diff] [blame] | 52 | --ibbhash=11,4,12 \ |
Arthur Heymans | 3d5319e | 2021-02-19 19:39:56 +0100 | [diff] [blame] | 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 |
| 65 | endif |
Arthur Heymans | 15412c0 | 2021-02-08 22:38:40 +0100 | [diff] [blame] | 66 | |
Arthur Heymans | 6362df3 | 2021-03-17 12:23:20 +0100 | [diff] [blame] | 67 | ifeq ($(CONFIG_INTEL_CBNT_BPM_ONLY_UNSIGNED),y) |
| 68 | build_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" |
| 75 | else |
Arthur Heymans | 15412c0 | 2021-02-08 22:38:40 +0100 | [diff] [blame] | 76 | $(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 |
| 81 | files_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 Heymans | 6362df3 | 2021-03-17 12:23:20 +0100 | [diff] [blame] | 87 | endif # CONFIG_INTEL_CBNT_BPM_ONLY_UNSIGNED |
| 88 | |
Arthur Heymans | 15412c0 | 2021-02-08 22:38:40 +0100 | [diff] [blame] | 89 | else # CONFIG_INTEL_CBNT_GENERATE_BPM |
Arthur Heymans | 6362df3 | 2021-03-17 12:23:20 +0100 | [diff] [blame] | 90 | |
Arthur Heymans | 94fe086 | 2020-10-15 13:57:52 +0200 | [diff] [blame] | 91 | ifneq ($(CONFIG_INTEL_CBNT_BOOT_POLICY_MANIFEST_BINARY),"") |
| 92 | cbfs-files-y += boot_policy_manifest.bin |
| 93 | boot_policy_manifest.bin-file := $(CONFIG_INTEL_CBNT_BOOT_POLICY_MANIFEST_BINARY) |
| 94 | boot_policy_manifest.bin-type := raw |
| 95 | boot_policy_manifest.bin-align := 0x10 |
| 96 | |
Arthur Heymans | eeacd83 | 2021-02-19 17:14:23 +0100 | [diff] [blame] | 97 | $(call add_intermediate, add_bpm_fit, $(IFITTOOL) set_fit_ptr) |
Arthur Heymans | 94fe086 | 2020-10-15 13:57:52 +0200 | [diff] [blame] | 98 | $(IFITTOOL) -r COREBOOT -a -n boot_policy_manifest.bin -t 12 -s $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES) -f $< |
| 99 | endif |
Arthur Heymans | 15412c0 | 2021-02-08 22:38:40 +0100 | [diff] [blame] | 100 | endif # CONFIG_INTEL_CBNT_GENERATE_BPM |
Arthur Heymans | 94fe086 | 2020-10-15 13:57:52 +0200 | [diff] [blame] | 101 | |
Arthur Heymans | 2ef2e47 | 2021-02-08 14:28:03 +0100 | [diff] [blame] | 102 | ifeq ($(CONFIG_INTEL_CBNT_GENERATE_KM),y) |
Arthur Heymans | 0514324 | 2021-02-08 19:41:23 +0100 | [diff] [blame] | 103 | ifeq ($(CONFIG_INTEL_CBNT_BG_PROV_KM_USE_CFG_FILE),y) |
Arthur Heymans | 2ef2e47 | 2021-02-08 14:28:03 +0100 | [diff] [blame] | 104 | $(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 Heymans | 0514324 | 2021-02-08 19:41:23 +0100 | [diff] [blame] | 107 | else |
| 108 | PK_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 |
| 118 | endif |
Arthur Heymans | 2ef2e47 | 2021-02-08 14:28:03 +0100 | [diff] [blame] | 119 | |
| 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 | |
| 124 | KM_FILE=$(obj)/km.bin |
| 125 | else |
| 126 | KM_FILE=$(CONFIG_INTEL_CBNT_KEY_MANIFEST_BINARY) |
| 127 | endif |
| 128 | |
| 129 | ifneq ($(KM_FILE),"") |
Arthur Heymans | 5e0119e | 2021-03-17 12:03:39 +0100 | [diff] [blame] | 130 | ifeq ($(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 | |
| 134 | build_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 | |
| 142 | else |
Arthur Heymans | 94fe086 | 2020-10-15 13:57:52 +0200 | [diff] [blame] | 143 | cbfs-files-y += key_manifest.bin |
Arthur Heymans | 2ef2e47 | 2021-02-08 14:28:03 +0100 | [diff] [blame] | 144 | key_manifest.bin-file := $(KM_FILE) |
Arthur Heymans | 94fe086 | 2020-10-15 13:57:52 +0200 | [diff] [blame] | 145 | key_manifest.bin-type := raw |
| 146 | key_manifest.bin-align := 0x10 |
| 147 | |
Arthur Heymans | eeacd83 | 2021-02-19 17:14:23 +0100 | [diff] [blame] | 148 | $(call add_intermediate, add_km_fit, $(IFITTOOL) set_fit_ptr) |
Arthur Heymans | 94fe086 | 2020-10-15 13:57:52 +0200 | [diff] [blame] | 149 | $(IFITTOOL) -r COREBOOT -a -n key_manifest.bin -t 11 -s $(CONFIG_CPU_INTEL_NUM_FIT_ENTRIES) -f $< |
| 150 | endif |
| 151 | |
Arthur Heymans | 5e0119e | 2021-03-17 12:03:39 +0100 | [diff] [blame] | 152 | endif # CONFIG_INTEL_CBNT_KM_ONLY_UNSIGNED |
Arthur Heymans | 94fe086 | 2020-10-15 13:57:52 +0200 | [diff] [blame] | 153 | endif # CONFIG_INTEL_CBNT_SUPPORT |