blob: 878b0684c05f64d2820126a367062823a4240bbc [file] [log] [blame]
Stefan Reinauer9aea04a2012-03-30 12:01:06 -07001##
2## This file is part of the coreboot project.
3##
4## Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
5##
6## This program is free software; you can redistribute it and/or modify
7## it under the terms of the GNU General Public License as published by
8## the Free Software Foundation; version 2 of the License.
9##
10## This program is distributed in the hope that it will be useful,
11## but WITHOUT ANY WARRANTY; without even the implied warranty of
12## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13## GNU General Public License for more details.
14##
Stefan Reinauer9aea04a2012-03-30 12:01:06 -070015
Daisuke Nojiri54af6252014-11-04 12:32:29 -080016bootblock-y += chromeos.c
17verstage-y += chromeos.c
18romstage-y += chromeos.c
19ramstage-y += chromeos.c
20
David Hendricks739e6a82014-05-13 20:28:49 -070021ramstage-$(CONFIG_ELOG) += elog.c
Furquan Shaikhaed887f2014-11-08 17:32:38 -080022ramstage-$(CONFIG_HAVE_ACPI_TABLES) += gnvs.c
Aaron Durbinb0f81512016-07-25 21:31:41 -050023ramstage-$(CONFIG_HAVE_ACPI_TABLES) += acpi.c
Aaron Durbin06ece7d2014-02-14 00:30:04 -060024ramstage-$(CONFIG_CHROMEOS_RAMOOPS) += ramoops.c
Hung-Te Linb15a0d02015-07-13 15:49:57 +080025romstage-y += vpd_decode.c
Stephen Barberb396a662015-03-11 15:53:10 -070026ramstage-y += vpd_decode.c cros_vpd.c vpd_mac.c vpd_serialno.c vpd_calibration.c
Felix Durairaj5d935b32015-11-20 16:18:42 -080027ramstage-$(CONFIG_HAVE_REGULATORY_DOMAIN) += wrdd.c
Robbie Zhanged840022016-12-23 11:43:07 -080028ramstage-$(CONFIG_USE_SAR) += sar.c
Furquan Shaikh0d9cd922016-07-25 17:00:07 -070029ifeq ($(CONFIG_ARCH_MIPS),)
Julius Werner105f5b72015-01-21 17:39:49 -080030bootblock-y += watchdog.c
31ramstage-y += watchdog.c
32endif
Aaron Durbinfd795622013-03-01 17:12:26 -060033
Aaron Durbin0703ec42013-03-27 00:16:11 -050034ifeq ($(MOCK_TPM),1)
Furquan Shaikh99ac98f2014-04-23 10:18:48 -070035CFLAGS_common += -DMOCK_TPM=1
Aaron Durbin0703ec42013-03-27 00:16:11 -050036else
Furquan Shaikh99ac98f2014-04-23 10:18:48 -070037CFLAGS_common += -DMOCK_TPM=0
Aaron Durbin0703ec42013-03-27 00:16:11 -050038endif
39
Patrick Georgi0db0e612016-02-02 14:43:56 +010040CONFIG_GBB_HWID := $(call strip_quotes,$(CONFIG_GBB_HWID))
41CONFIG_GBB_BMPFV_FILE := $(call strip_quotes,$(CONFIG_GBB_BMPFV_FILE))
Patrick Georgi71ea7172016-02-02 17:52:09 +010042CONFIG_VBOOT_KEYBLOCK := $(call strip_quotes,$(CONFIG_VBOOT_KEYBLOCK))
43CONFIG_VBOOT_FIRMWARE_PRIVKEY := $(call strip_quotes,$(CONFIG_VBOOT_FIRMWARE_PRIVKEY))
44CONFIG_VBOOT_KERNEL_KEY := $(call strip_quotes,$(CONFIG_VBOOT_KERNEL_KEY))
Patrick Georgi4399b852016-12-06 21:59:23 +010045CONFIG_CHROMEOS_FWID_MODEL := $(call strip_quotes,$(CONFIG_CHROMEOS_FWID_MODEL))
46CONFIG_CHROMEOS_FWID_VERSION := $(call strip_quotes,$(CONFIG_CHROMEOS_FWID_VERSION))
Patrick Georgi0db0e612016-02-02 14:43:56 +010047
Patrick Georgi5ea87ff2016-02-02 15:05:57 +010048# bool-to-mask(var, value)
49# return "value" if var is "y", 0 otherwise
50bool-to-mask = $(if $(filter y,$(1)),$(2),0)
51
52GBB_FLAGS := $(call int-add, \
53 $(call bool-to-mask,$(CONFIG_GBB_FLAG_DEV_SCREEN_SHORT_DELAY),0x1) \
54 $(call bool-to-mask,$(CONFIG_GBB_FLAG_LOAD_OPTION_ROMS),0x2) \
55 $(call bool-to-mask,$(CONFIG_GBB_FLAG_ENABLE_ALTERNATE_OS),0x4) \
56 $(call bool-to-mask,$(CONFIG_GBB_FLAG_FORCE_DEV_SWITCH_ON),0x8) \
57 $(call bool-to-mask,$(CONFIG_GBB_FLAG_FORCE_DEV_BOOT_USB),0x10) \
58 $(call bool-to-mask,$(CONFIG_GBB_FLAG_DISABLE_FW_ROLLBACK_CHECK),0x20) \
59 $(call bool-to-mask,$(CONFIG_GBB_FLAG_ENTER_TRIGGERS_TONORM),0x40) \
60 $(call bool-to-mask,$(CONFIG_GBB_FLAG_FORCE_DEV_BOOT_LEGACY),0x80) \
61 $(call bool-to-mask,$(CONFIG_GBB_FLAG_FAFT_KEY_OVERIDE),0x100) \
62 $(call bool-to-mask,$(CONFIG_GBB_FLAG_DISABLE_EC_SOFTWARE_SYNC),0x200) \
63 $(call bool-to-mask,$(CONFIG_GBB_FLAG_DEFAULT_DEV_BOOT_LEGACY),0x400) \
64 $(call bool-to-mask,$(CONFIG_GBB_FLAG_DISABLE_PD_SOFTWARE_SYNC),0x800) \
65 $(call bool-to-mask,$(CONFIG_GBB_FLAG_DISABLE_LID_SHUTDOWN),0x1000) \
Patrick Georgi85cc5fd2016-03-31 12:34:32 +020066 $(call bool-to-mask,$(CONFIG_GBB_FLAG_FORCE_DEV_BOOT_FASTBOOT_FULL_CAP),0x2000) \
67 $(call bool-to-mask,$(CONFIG_GBB_FLAG_ENABLE_SERIAL),0x4000) \
68 )
Patrick Georgi5ea87ff2016-02-02 15:05:57 +010069
Patrick Georgi0db0e612016-02-02 14:43:56 +010070ifneq ($(CONFIG_GBB_BMPFV_FILE),)
Patrick Georgifcc43472016-03-31 13:08:42 +020071$(obj)/gbb.sizetmp: $(obj)/coreboot.rom
72 $(CBFSTOOL) $< read -r GBB -f $@
73
74$(obj)/gbb.stub: $(obj)/coreboot.rom $(FUTILITY) $(obj)/gbb.sizetmp
Patrick Georgi0db0e612016-02-02 14:43:56 +010075 @printf " CREATE GBB (with BMPFV)\n"
Patrick Georgifcc43472016-03-31 13:08:42 +020076 $(FUTILITY) gbb_utility -c 0x100,0x1000,$(call int-subtract,$(call file-size,$(obj)/gbb.sizetmp) 0x2180),0x1000 $@.tmp
Patrick Georgi0db0e612016-02-02 14:43:56 +010077 mv $@.tmp $@
78else
79$(obj)/gbb.stub: $(obj)/coreboot.rom $(FUTILITY)
80 @printf " CREATE GBB (without BMPFV)\n"
81 $(FUTILITY) gbb_utility -c 0x100,0x1000,0,0x1000 $@.tmp
82 mv $@.tmp $@
83endif
84
85$(obj)/gbb.region: $(obj)/gbb.stub
86 @printf " SETUP GBB\n"
87 cp $< $@.tmp
88 $(FUTILITY) gbb_utility -s \
89 --hwid="$(CONFIG_GBB_HWID)" \
90 --rootkey="$(CONFIG_VBOOT_ROOT_KEY)" \
91 --recoverykey="$(CONFIG_VBOOT_RECOVERY_KEY)" \
Patrick Georgi5ea87ff2016-02-02 15:05:57 +010092 --flags=$(GBB_FLAGS) \
Patrick Georgi0db0e612016-02-02 14:43:56 +010093 $@.tmp
Patrick Georgifcc43472016-03-31 13:08:42 +020094ifneq ($(CONFIG_GBB_BMPFV_FILE),)
95 $(FUTILITY) gbb_utility -s \
96 --bmpfv="$(CONFIG_GBB_BMPFV_FILE)" \
97 $@.tmp
98endif
Patrick Georgi0db0e612016-02-02 14:43:56 +010099 mv $@.tmp $@
100
Patrick Georgi4399b852016-12-06 21:59:23 +0100101$(obj)/fwid.region:
102 printf "$(CONFIG_CHROMEOS_FWID_MODEL)$(CONFIG_CHROMEOS_FWID_VERSION)\0" > $@
103
104build_complete:: $(obj)/gbb.region $(obj)/fwid.region
Patrick Georgi0db0e612016-02-02 14:43:56 +0100105 @printf " WRITE GBB\n"
Patrick Georgi4399b852016-12-06 21:59:23 +0100106 $(CBFSTOOL) $(obj)/coreboot.rom write -u -r GBB -i 0 -f $(obj)/gbb.region
107 $(CBFSTOOL) $(obj)/coreboot.rom write -u -r RO_FRID -i 0 -f $(obj)/fwid.region
108 $(CBFSTOOL) $(obj)/coreboot.rom write -u -r RW_FWID_A -i 0 -f $(obj)/fwid.region
109 $(CBFSTOOL) $(obj)/coreboot.rom write -u -r RW_FWID_B -i 0 -f $(obj)/fwid.region
Patrick Georgi71ea7172016-02-02 17:52:09 +0100110
Patrick Georgi0803ba42016-12-07 12:12:59 +0100111ifneq ($(shell grep "SHARED_DATA" "$(CONFIG_FMDFILE)"),)
112build_complete::
113 printf "\0" > $(obj)/shared_data.region
114 $(CBFSTOOL) $(obj)/coreboot.rom write -u -r SHARED_DATA -i 0 -f $(obj)/shared_data.region
115endif
116
Patrick Georgi71ea7172016-02-02 17:52:09 +0100117# Extract FW_MAIN_? region and minimize it if the last file is empty, so it
118# doesn't contain this empty file (that can have a significant size),
119# improving a lot on hash times due to a smaller amount of data loaded from
120# firmware storage.
121# When passing the minimized image to vbutil_firmware, its length is recorded
122# in the keyblock, and coreboot's vboot code clips the region_device to match,
123# which prevents any potential extension attacks.
124$(obj)/FW_MAIN_%.bin: $(obj)/coreboot.rom
125 $(CBFSTOOL) $< read -r $(basename $(notdir $@)) -f $@.tmp
126 $(CBFSTOOL) $(obj)/coreboot.rom print -k -r $(basename $(notdir $@)) | \
127 tail -1 | \
128 sed "s,^(empty)[[:space:]]\(0x[0-9a-f]*\)\tnull\t.*$$,\1," \
129 > $@.tmp.size
Paul Kocialkowski36d74182016-04-22 11:10:03 +0200130 if [ -n "$$(cat $@.tmp.size)" ] && [ $$( printf "%d" $$(cat $@.tmp.size)) -gt 0 ]; then \
Patrick Georgi71ea7172016-02-02 17:52:09 +0100131 head -c $$( printf "%d" $$(cat $@.tmp.size)) $@.tmp > $@.tmp2 && \
132 mv $@.tmp2 $@; \
133 else \
134 mv $@.tmp $@; \
135 fi
136
137$(obj)/VBLOCK_%.bin: $(obj)/FW_MAIN_%.bin $(FUTILITY)
138 $(FUTILITY) vbutil_firmware \
139 --vblock $@ \
140 --keyblock "$(CONFIG_VBOOT_KEYBLOCK)" \
141 --signprivate "$(CONFIG_VBOOT_FIRMWARE_PRIVKEY)" \
142 --version $(CONFIG_VBOOT_KEYBLOCK_VERSION) \
143 --fv $< \
144 --kernelkey "$(CONFIG_VBOOT_KERNEL_KEY)" \
145 --flags $(CONFIG_VBOOT_KEYBLOCK_PREAMBLE_FLAGS)
146
Paul Kocialkowski580db7f2016-07-12 00:29:37 +0200147$(obj)/RO_FRID.bin: $(obj)/coreboot.rom
148 $(CBFSTOOL) $(obj)/coreboot.rom read -r $(basename $(notdir $@)) -f $@
149 printf $(KERNELVERSION) > $@.tmp
150 objcopy -I binary -O binary --pad-to=$$( stat --printf="%s" $@ ) --gap-fill=0 $@.tmp $@
151
152$(obj)/RW_FWID_%.bin: $(obj)/coreboot.rom
153 $(CBFSTOOL) $(obj)/coreboot.rom read -r $(basename $(notdir $@)) -f $@
154 printf $(KERNELVERSION) > $@.tmp
155 objcopy -I binary -O binary --pad-to=$$( stat --printf="%s" $@ ) --gap-fill=0 $@.tmp $@
156
157files_added:: $(obj)/VBLOCK_A.bin $(obj)/VBLOCK_B.bin $(obj)/RO_FRID.bin $(obj)/RW_FWID_A.bin $(obj)/RW_FWID_B.bin
Patrick Georgi71ea7172016-02-02 17:52:09 +0100158 $(CBFSTOOL) $(obj)/coreboot.rom write -u -r VBLOCK_A -f $(obj)/VBLOCK_A.bin
159 $(CBFSTOOL) $(obj)/coreboot.rom write -u -r VBLOCK_B -f $(obj)/VBLOCK_B.bin
Paul Kocialkowski580db7f2016-07-12 00:29:37 +0200160 $(CBFSTOOL) $(obj)/coreboot.rom write -u -r RO_FRID -f $(obj)/RO_FRID.bin
161 $(CBFSTOOL) $(obj)/coreboot.rom write -u -r RW_FWID_A -f $(obj)/RW_FWID_A.bin
162 $(CBFSTOOL) $(obj)/coreboot.rom write -u -r RW_FWID_B -f $(obj)/RW_FWID_B.bin