| 1 |
|
| 2 |
|
| 3 |
obj ?= build |
| 4 |
src ?= src |
| 5 |
build-dir = $(obj)/sbom |
| 6 |
src-dir = $(src)/sbom |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
CONFIG_ME_BIN_PATH := $(call strip_quotes, $(CONFIG_ME_BIN_PATH)) |
| 16 |
CONFIG_SBOM_ME_PATH := $(call strip_quotes, $(CONFIG_SBOM_ME_PATH)) |
| 17 |
CONFIG_FSP_S_FILE := $(call strip_quotes, $(CONFIG_FSP_S_FILE)) |
| 18 |
CONFIG_FSP_M_FILE := $(call strip_quotes, $(CONFIG_FSP_M_FILE)) |
| 19 |
CONFIG_FSP_T_FILE := $(call strip_quotes, $(CONFIG_FSP_T_FILE)) |
| 20 |
CONFIG_SBOM_FSP_PATH := $(call strip_quotes, $(CONFIG_SBOM_FSP_PATH)) |
| 21 |
CONFIG_PAYLOAD_FILE := $(call strip_quotes, $(CONFIG_PAYLOAD_FILE)) |
| 22 |
CONFIG_SBOM_PAYLOAD_PATH := $(call strip_quotes, $(CONFIG_SBOM_PAYLOAD_PATH)) |
| 23 |
CONFIG_EC_PATH := $(call strip_quotes, $(CONFIG_EC_PATH)) |
| 24 |
CONFIG_SBOM_EC_PATH := $(call strip_quotes, $(CONFIG_SBOM_EC_PATH)) |
| 25 |
CONFIG_SBOM_BIOS_ACM_PATH := $(call strip_quotes, $(CONFIG_SBOM_BIOS_ACM_PATH)) |
| 26 |
CONFIG_SBOM_SINIT_ACM_PATH := $(call strip_quotes, $(CONFIG_SBOM_SINIT_ACM_PATH)) |
| 27 |
CONFIG_SBOM_COMPILER_PATH := $(call strip_quotes, $(CONFIG_SBOM_COMPILER_PATH)) |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
ifeq ($(CONFIG_SBOM_PAYLOAD_GENERATE), y) |
| 33 |
payload-git-dir-$(CONFIG_PAYLOAD_BOOTBOOT) = payloads/external/BOOTBOOT/bootboot |
| 34 |
payload-git-dir-$(CONFIG_PAYLOAD_DEPTHCHARGE) = payloads/external/depthcharge/depthcharge |
| 35 |
payload-git-dir-$(CONFIG_PAYLOAD_FILO) = payloads/external/FILO/filo |
| 36 |
payload-git-dir-$(CONFIG_PAYLOAD_GRUB2) = payloads/external/GRUB2/grub2 |
| 37 |
payload-git-dir-$(CONFIG_PAYLOAD_LINUXBOOT) = payloads/external/LinuxBoot/linuxboot |
| 38 |
payload-git-dir-$(CONFIG_PAYLOAD_SEABIOS) = payloads/external/SeaBIOS/seabios |
| 39 |
payload-git-dir-$(CONFIG_PAYLOAD_SKIBOOT) = payloads/external/skiboot/skiboot |
| 40 |
|
| 41 |
payload-git-dir-$(CONFIG_PAYLOAD_UBOOT) = payloads/external/U-Boot/u-boot |
| 42 |
payload-git-dir-$(CONFIG_PAYLOAD_IPXE) = payloads/external/iPXE/ipxe |
| 43 |
ifneq ($(payload-git-dir-y),) |
| 44 |
|
| 45 |
|
| 46 |
payload-swid = $(build-dir)/payload-$(subst /,,$(dir $(patsubst payloads/external/%,%,$(payload-git-dir-y)))).json |
| 47 |
payload-swid-template = $(patsubst $(build-dir)/%.json,$(src-dir)/%.json,$(payload-swid)) |
| 48 |
endif |
| 49 |
endif |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
swid-files-$(CONFIG_SBOM_ME) += $(if $(CONFIG_SBOM_ME_GENERATE), $(build-dir)/intel-me.json, $(CONFIG_SBOM_ME_PATH)) |
| 57 |
swid-files-$(CONFIG_SBOM_PAYLOAD) += $(if $(CONFIG_SBOM_PAYLOAD_GENERATE), $(payload-swid), $(CONFIG_SBOM_PAYLOAD_PATH)) |
| 58 |
|
| 59 |
swid-files-$(CONFIG_SBOM_MICROCODE) += $(patsubst 3rdparty/intel-microcode/intel-ucode/%, $(build-dir)/intel-microcode-%.json, $(filter 3rdparty/intel-microcode/intel-ucode/%, $(cpu_microcode_bins))) |
| 60 |
swid-files-$(CONFIG_SBOM_MICROCODE) += $(patsubst ${FIRMWARE_LOCATION}/UcodePatch_%.bin, $(build-dir)/amd-microcode-%.json, $(filter ${FIRMWARE_LOCATION}/UcodePatch_%.bin, $(cpu_microcode_bins))) |
| 61 |
swid-files-$(CONFIG_SBOM_FSP) += $(CONFIG_SBOM_FSP_PATH) |
| 62 |
swid-files-$(CONFIG_SBOM_EC) += $(CONFIG_SBOM_EC_PATH) |
| 63 |
swid-files-$(CONFIG_SBOM_BIOS_ACM) += $(CONFIG_BIOS_ACM_PATH) |
| 64 |
swid-files-$(CONFIG_SBOM_SINIT_ACM) += $(CONFIG_SINIT_ACM_PATH) |
| 65 |
|
| 66 |
vboot-pkgconfig-files = $(obj)/external/vboot_reference-bootblock/vboot_host.pc $(obj)/external/vboot_reference-ramstage/vboot_host.pc $(obj)/external/vboot_reference-postcar/vboot_host.pc |
| 67 |
ifeq ($(CONFIG_SEPARATE_ROMSTAGE),y) |
| 68 |
vboot-pkgconfig-files += $(obj)/external/vboot_reference-romstage/vboot_host.pc |
| 69 |
endif |
| 70 |
swid-files-$(CONFIG_SBOM_VBOOT) += $(vboot-pkgconfig-files) |
| 71 |
$(vboot-pkgconfig-files): $(VBOOT_LIB_bootblock) $(VBOOT_LIB_romstage) $(VBOOT_LIB_ramstage) $(VBOOT_LIB_postcar) |
| 72 |
|
| 73 |
ifeq ($(CONFIG_SBOM_COMPILER),y) |
| 74 |
compiler-toolchain = $(CC_bootblock) $(CC_romstage) $(CC_ramstage) $(CC_postcar) $(CC_verstage) $(LD_bootblock) $(LD_romstage) $(LD_ramstage) $(LD_postcar) $(LD_verstage) $(AS_bootblock) $(AS_romstage) $(AS_ramstage) $(AS_postcar) $(AS_verstage) |
| 75 |
swid-files-compiler = $(CONFIG_SBOM_COMPILER_PATH) |
| 76 |
endif |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
coreboot-licenses = $(foreach license, $(patsubst %.txt, %, $(filter-out retained-copyrights.txt, $(patsubst LICENSES/%, %, $(wildcard LICENSES/*)))), https://spdx.org/licenses/$(license).html) |
| 81 |
|
| 82 |
|
| 83 |
ifeq ($(CONFIG_SBOM),y) |
| 84 |
cbfs-files-y += sbom |
| 85 |
sbom-file = $(build-dir)/sbom.uswid |
| 86 |
sbom-type = raw |
| 87 |
endif |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
$(build-dir)/sbom.uswid: $(build-dir)/coreboot.json $$(swid-files-y) $(swid-files-compiler) | $(build-dir)/goswid $(build-dir) |
| 92 |
echo " SBOM " $^ |
| 93 |
$(build-dir)/goswid convert -o $@ \ |
| 94 |
--parent $(build-dir)/coreboot.json \ |
| 95 |
$(if $(swid-files-y), --requires $$(echo $(swid-files-y) | tr ' ' ','),) \ |
| 96 |
$(if $(swid-files-compiler), --compiler $(swid-files-compiler),) |
| 97 |
|
| 98 |
|
| 99 |
$(build-dir): |
| 100 |
mkdir -p $(build-dir) |
| 101 |
|
| 102 |
$(build-dir)/goswid: | $(build-dir) |
| 103 |
echo " SBOM building goswid tool" |
| 104 |
cd util/goswid; \ |
| 105 |
GOPATH=$(abspath build/go) GO111MODULE=on go build -modcacherw -o $(abspath $@) ./cmd/goswid |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
$(build-dir)/compiler-%.json: $(src-dir)/compiler-%.json | $(build-dir)/goswid |
| 110 |
cp $< $@ |
| 111 |
for tool in $$(echo $(compiler-toolchain) | tr ' ' '\n' | sort | uniq); do \ |
| 112 |
version=$$($$tool --version 2>&1 | head -n 1 | grep -Eo '([0-9]+\.[0-9]+\.*[0-9]*)'); \ |
| 113 |
$(build-dir)/goswid add-payload-file -o $@ -i $@ --name $$(basename $$tool) --version $$version; \ |
| 114 |
done |
| 115 |
|
| 116 |
$(build-dir)/coreboot.json: $(src-dir)/coreboot.json $(obj)/build.h | $(build-dir)/goswid |
| 117 |
cp $< $@ |
| 118 |
git_tree_hash=$$(grep 'COREBOOT_ORIGIN_TREE_REVISION' $(obj)/build.h | sed 's/.*"\(.*\)".*/\1/');\ |
| 119 |
git_comm_hash=$$(grep 'COREBOOT_ORIGIN_GIT_REVISION' $(obj)/build.h | sed 's/.*"\(.*\)".*/\1/');\ |
| 120 |
sed -i -e "s/<colloquial_version>/$$git_tree_hash/" -e "s/<software_version>/$$git_comm_hash/" $@;\ |
| 121 |
$(build-dir)/goswid add-license -o $@ -i $@ $(coreboot-licenses) |
| 122 |
|
| 123 |
$(build-dir)/intel-me.json: $(src-dir)/intel-me.json $(CONFIG_ME_BIN_PATH) | $(build-dir) |
| 124 |
cp $< $@ |
| 125 |
#TODO put more Intel Management Engine metadata in sbom file |
| 126 |
|
| 127 |
|
| 128 |
$(build-dir)/generic-fsp.json: $(src-dir)/generic-fsp.json $(CONFIG_FSP_S_FILE) $(CONFIG_FSP_T_FILE) $(CONFIG_FSP_M_FILE) | $(build-dir)/goswid |
| 129 |
cp $(src-dir)/generic-fsp.json $@ |
| 130 |
ifneq ($(CONFIG_FSP_S_FILE),) |
| 131 |
echo " SBOM Adding FSP-S" |
| 132 |
$(build-dir)/goswid add-payload-file -o $@ -i $@ --name "FSP-S" |
| 133 |
endif |
| 134 |
ifneq ($(CONFIG_FSP_T_FILE),) |
| 135 |
echo " SBOM Adding FSP-T" |
| 136 |
$(build-dir)/goswid add-payload-file -o $@ -i $@ --name "FSP-T" |
| 137 |
endif |
| 138 |
ifneq ($(CONFIG_FSP_M_FILE),) |
| 139 |
echo " SBOM Adding FSP-M" |
| 140 |
$(build-dir)/goswid add-payload-file -o $@ -i $@ --name "FSP-M" |
| 141 |
endif |
| 142 |
|
| 143 |
$(build-dir)/intel-microcode-%.json: $(src-dir)/intel-microcode.json 3rdparty/intel-microcode/intel-ucode/% | $(build-dir) $(build-dir)/goswid |
| 144 |
cp $< $@ |
| 145 |
year=$$(hexdump --skip 8 --length 2 --format '"%04x"' $(word 2,$^));\ |
| 146 |
day=$$(hexdump --skip 10 --length 1 --format '"%02x"' $(word 2,$^));\ |
| 147 |
month=$$(hexdump --skip 11 --length 1 --format '"%02x"' $(word 2,$^));\ |
| 148 |
sed -i "s/<software_version>/$$year-$$month-$$day/" $@ |
| 149 |
#TODO add cpuid (processor family, model, stepping) as extra attribute |
| 150 |
|
| 151 |
$(build-dir)/amd-microcode-%.json: $(src-dir)/amd-microcode.json ${FIRMWARE_LOCATION}/UcodePatch_%.bin | $(build-dir) $(build-dir)/goswid |
| 152 |
cp $< $@ |
| 153 |
year=$$(hexdump --skip 0 --length 2 --format '"%04x"' $(word 2,$^));\ |
| 154 |
day=$$(hexdump --skip 2 --length 1 --format '"%02x"' $(word 2,$^));\ |
| 155 |
month=$$(hexdump --skip 3 --length 1 --format '"%02x"' $(word 2,$^));\ |
| 156 |
sed -i "s/<software_version>/$$year-$$month-$$day/" $@ |
| 157 |
|
| 158 |
$(payload-swid): $(payload-swid-template) $(CONFIG_PAYLOAD_FILE) | $(build-dir) |
| 159 |
cp $< $@;\ |
| 160 |
git_tree_hash=$$(git --git-dir $(payload-git-dir-y)/.git log -n 1 --format=%T);\ |
| 161 |
git_comm_hash=$$(git --git-dir $(payload-git-dir-y)/.git log -n 1 --format=%H);\ |
| 162 |
sed -i -e "s/<colloquial_version>/$$git_tree_hash/" -e "s/<software_version>/$$git_comm_hash/" $@; |