xref: /aosp_15_r20/external/vboot_reference/Android.bp (revision 8617a60d3594060b7ecbd21bc622a7c14f3cf2bc)
1// Copyright 2024 The ChromiumOS Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5cc_defaults {
6    name: "vboot_defaults",
7    visibility: ["//visibility:public"],
8    init_rc: ["vboot.rc"],
9
10    cflags: [
11        "-Wall",
12        "-Werror",
13        "-Wstrict-prototypes",
14        "-Wtype-limits",
15        "-Wundef",
16        "-Wmissing-prototypes",
17        "-Wno-trigraphs",
18        "-Wredundant-decls",
19        "-Wshadow",
20        "-Wwrite-strings",
21        "-Wstrict-aliasing",
22        "-Wdate-time",
23        "-Wno-format-security",
24        "-Wimplicit-fallthrough",
25        "-Wno-address-of-packed-member",
26        "-Wincompatible-function-pointer-types",
27        "-Wno-error=deprecated-declarations",
28        "-D_GNU_SOURCE",
29        "-DCHROMEOS_ENVIRONMENT", // FIRMWARE_ARCH=""
30        "-DUSE_FLASHROM",
31        "-DEXTERNAL_TPM_CLEAR_REQUEST=0",
32        "-Wno-gnu-pointer-arith",
33        "-Wno-ignored-qualifiers",
34        "-Wno-missing-field-initializers",
35        "-Wno-unused-parameter",
36        "-Wno-macro-redefined",
37        "-DTPM2_MODE",
38        "-DEC_EFS=0",
39    ],
40
41    local_include_dirs: [
42        "firmware/include",
43        "firmware/lib/include",
44        "firmware/lib/cgptlib/include",
45        "firmware/lib/tpm_lite/include",
46        "firmware/2lib/include",
47
48        // FIRMWARE_STUB
49        "host/include",
50        "host/lib/include",
51        "host/lib21/include",
52    ],
53
54    export_include_dirs: [
55        "host/include",
56        "firmware/include",
57        "firmware/2lib/include",
58    ],
59
60    shared_libs: [
61        "libcrypto",
62        "libflashrom",
63        "libssl",
64    ],
65
66    target: {
67        android: {
68            cflags: [
69                "-DCROSSYSTEM_LOCK_DIR=\"/data/vendor/vboot/tmp\"",
70                "-DVBOOT_TMP_DIR=\"/data/vendor/vboot/tmp\"",
71            ],
72        },
73        darwin: {
74            cflags: [
75                "-DHAVE_MACOS",
76                "-DCROSSYSTEM_LOCK_DIR=\"/tmp\"",
77                "-DVBOOT_TMP_DIR=\"/tmp\"",
78            ],
79        },
80        linux: {
81            cflags: [
82                "-DCROSSYSTEM_LOCK_DIR=\"/run/lock\"",
83                "-DVBOOT_TMP_DIR=\"/tmp\"",
84            ],
85        },
86        windows: {
87            cflags: [
88                "-DCROSSYSTEM_LOCK_DIR=\"c:\\windows\\temp\"",
89                "-DVBOOT_TMP_DIR=\"c:\\windows\\temp\"",
90            ],
91        },
92    },
93}
94
95filegroup {
96    name: "tlcl_srcs",
97    srcs: [
98        "firmware/lib/tpm2_lite/tlcl.c",
99        "firmware/lib/tpm2_lite/marshaling.c",
100    ],
101}
102
103cc_library_static {
104    name: "tlcl",
105    defaults: ["vboot_defaults"],
106    host_supported: true,
107    vendor_available: true,
108    srcs: [":tlcl_srcs"],
109}
110
111filegroup {
112    name: "vboot_fw_srcs",
113    srcs: [
114        "firmware/2lib/2api.c",
115        "firmware/2lib/2auxfw_sync.c",
116        "firmware/2lib/2common.c",
117        "firmware/2lib/2context.c",
118        "firmware/2lib/2crc8.c",
119        "firmware/2lib/2crypto.c",
120        "firmware/2lib/2ec_sync.c",
121        "firmware/2lib/2firmware.c",
122        "firmware/2lib/2gbb.c",
123        "firmware/2lib/2hmac.c",
124        "firmware/2lib/2kernel.c",
125        "firmware/2lib/2load_kernel.c",
126        "firmware/2lib/2misc.c",
127        "firmware/2lib/2nvstorage.c",
128        "firmware/2lib/2packed_key.c",
129        "firmware/2lib/2recovery_reasons.c",
130        "firmware/2lib/2rsa.c",
131        "firmware/2lib/2secdata_firmware.c",
132        "firmware/2lib/2secdata_fwmp.c",
133        "firmware/2lib/2secdata_kernel.c",
134        "firmware/2lib/2sha1.c",
135        "firmware/2lib/2sha256.c",
136        "firmware/2lib/2sha512.c",
137        "firmware/2lib/2sha_utility.c",
138        "firmware/2lib/2struct.c",
139        "firmware/2lib/2stub_hwcrypto.c",
140        "firmware/2lib/2tpm_bootmode.c",
141        "firmware/lib/cgptlib/cgptlib.c",
142        "firmware/lib/cgptlib/cgptlib_internal.c",
143        "firmware/lib/cgptlib/crc32.c",
144        "firmware/lib/gpt_misc.c",
145        "firmware/lib20/api_kernel.c",
146        "firmware/lib20/kernel.c",
147
148        // FIRMWARE_STUB
149        "firmware/stub/tpm_lite_stub.c",
150        "firmware/stub/vboot_api_stub_disk.c",
151        "firmware/stub/vboot_api_stub_stream.c",
152        "firmware/2lib/2stub.c",
153    ],
154}
155
156cc_library_static {
157    name: "vboot_fw",
158    defaults: ["vboot_defaults"],
159    host_supported: true,
160    vendor_available: true,
161    srcs: [":vboot_fw_srcs"],
162}
163
164cc_defaults {
165    name: "libvboot_defaults",
166    defaults: ["vboot_defaults"],
167    srcs: [
168        // USE_FLASHROM
169        "host/lib/flashrom.c",
170        "host/lib/flashrom_drv.c",
171
172        "host/lib/subprocess.c",
173        "host/lib/cbfstool.c",
174    ],
175}
176
177filegroup {
178    name: "cgpt_common",
179    srcs: [
180        "cgpt/cgpt_add.c",
181        "cgpt/cgpt_boot.c",
182        "cgpt/cgpt_common.c",
183        "cgpt/cgpt_create.c",
184        "cgpt/cgpt_edit.c",
185        "cgpt/cgpt_prioritize.c",
186        "cgpt/cgpt_repair.c",
187        "cgpt/cgpt_show.c",
188    ],
189}
190
191cc_library_static {
192    name: "libvboot_util",
193    defaults: ["libvboot_defaults"],
194    host_supported: true,
195    vendor_available: true,
196
197    srcs: [
198        ":cgpt_common",
199        "futility/dump_kernel_config_lib.c",
200        "host/lib/chromeos_config.c",
201        "host/lib/crossystem.c",
202        "host/lib/crypto.c",
203        "host/lib/file_keys.c",
204        "host/lib/fmap.c",
205        "host/lib/host_common.c",
206        "host/lib/host_key2.c",
207        "host/lib/host_keyblock.c",
208        "host/lib/host_misc.c",
209        "host/lib/host_p11_stub.c",
210        "host/lib/host_signature.c",
211        "host/lib/host_signature2.c",
212        "host/lib/signature_digest.c",
213        "host/lib/util_misc.c",
214        "host/lib21/host_common.c",
215        "host/lib21/host_key.c",
216        "host/lib21/host_misc.c",
217        "host/lib21/host_signature.c",
218        ":vboot_fw_srcs",
219        ":tlcl_srcs",
220    ],
221
222    arch: {
223        arm: {
224            srcs: [
225                "host/arch/arm/lib/crossystem_arch.c",
226            ],
227        },
228        arm64: {
229            srcs: [
230                "host/arch/arm/lib/crossystem_arch.c",
231            ],
232        },
233        x86: {
234            srcs: [
235                "host/arch/x86/lib/crossystem_arch.c",
236            ],
237        },
238        x86_64: {
239            srcs: [
240                "host/arch/x86/lib/crossystem_arch.c",
241            ],
242        },
243    },
244}
245
246cc_library_static {
247    name: "libvboot_host",
248    defaults: ["libvboot_defaults"],
249    host_supported: true,
250    vendor_available: true,
251
252    srcs: [
253        ":cgpt_common",
254        "firmware/2lib/2common.c",
255        "firmware/2lib/2context.c",
256        "firmware/2lib/2crc8.c",
257        "firmware/2lib/2crypto.c",
258        "firmware/2lib/2hmac.c",
259        "firmware/2lib/2nvstorage.c",
260        "firmware/2lib/2recovery_reasons.c",
261        "firmware/2lib/2rsa.c",
262        "firmware/2lib/2sha1.c",
263        "firmware/2lib/2sha256.c",
264        "firmware/2lib/2sha512.c",
265        "firmware/2lib/2sha_utility.c",
266        "firmware/2lib/2struct.c",
267        "firmware/2lib/2stub.c",
268        "firmware/2lib/2stub_hwcrypto.c",
269        "firmware/lib/cgptlib/cgptlib_internal.c",
270        "firmware/lib/cgptlib/crc32.c",
271        "firmware/lib/gpt_misc.c",
272        "firmware/stub/tpm_lite_stub.c",
273        "firmware/stub/vboot_api_stub_disk.c",
274        "futility/dump_kernel_config_lib.c",
275        "host/lib/chromeos_config.c",
276        "host/lib/crossystem.c",
277        "host/lib/crypto.c",
278        "host/lib/extract_vmlinuz.c",
279        "host/lib/fmap.c",
280        "host/lib/host_misc.c",
281        "host/lib21/host_misc.c",
282        ":tlcl_srcs",
283    ],
284
285    arch: {
286        arm: {
287            srcs: [
288                "host/arch/arm/lib/crossystem_arch.c",
289            ],
290        },
291        arm64: {
292            srcs: [
293                "host/arch/arm/lib/crossystem_arch.c",
294            ],
295        },
296        x86: {
297            srcs: [
298                "host/arch/x86/lib/crossystem_arch.c",
299            ],
300        },
301        x86_64: {
302            srcs: [
303                "host/arch/x86/lib/crossystem_arch.c",
304            ],
305        },
306    },
307}
308
309cc_binary {
310    name: "cgpt",
311    defaults: ["vboot_defaults"],
312    host_supported: true,
313    vendor: true,
314
315    srcs: [
316        "cgpt/cgpt.c",
317        ":cgpt_common",
318        "cgpt/cgpt_find.c",
319        "cgpt/cgpt_legacy.c",
320        "cgpt/cmd_add.c",
321        "cgpt/cmd_boot.c",
322        "cgpt/cmd_create.c",
323        "cgpt/cmd_edit.c",
324        "cgpt/cmd_find.c",
325        "cgpt/cmd_legacy.c",
326        "cgpt/cmd_prioritize.c",
327        "cgpt/cmd_repair.c",
328        "cgpt/cmd_show.c",
329    ],
330
331    include_dirs: [
332        "external/e2fsprogs/lib/",
333    ],
334
335    static_libs: [
336        "libext2_uuid",
337        "libvboot_util",
338    ],
339}
340
341filegroup {
342    name: "futility_srcs",
343    srcs: [
344        "futility/futility.c",
345        "futility/cmd_create.c",
346        "futility/cmd_dump_fmap.c",
347        "futility/cmd_dump_kernel_config.c",
348        "futility/cmd_flash_util.c",
349        "futility/cmd_gbb_utility.c",
350        "futility/cmd_gscvd.c",
351        "futility/cmd_load_fmap.c",
352        "futility/cmd_pcr.c",
353        "futility/cmd_read.c",
354        "futility/cmd_show.c",
355        "futility/cmd_sign.c",
356        "futility/cmd_update.c",
357        "futility/cmd_vbutil_firmware.c",
358        "futility/cmd_vbutil_kernel.c",
359        "futility/cmd_vbutil_key.c",
360        "futility/cmd_vbutil_keyblock.c",
361        "futility/file_type_bios.c",
362        "futility/file_type.c",
363        "futility/file_type_rwsig.c",
364        "futility/file_type_usbpd1.c",
365        "futility/flash_helpers.c",
366        "futility/platform_csme.c",
367        "futility/misc.c",
368        "futility/vb1_helper.c",
369        "futility/vb2_helper.c",
370
371        // USE_FLASHROM
372        "host/lib/flashrom_drv.c",
373        "futility/updater_archive.c",
374        "futility/updater_dut.c",
375        "futility/updater_manifest.c",
376        "futility/updater_quirks.c",
377        "futility/updater_utils.c",
378        "futility/updater.c",
379    ],
380}
381
382genrule {
383    name: "futility_cmds",
384    cmd: "grep -hoRE '^DECLARE_FUTIL_COMMAND\\([^,]+' $(locations :futility_srcs) | sed 's/DECLARE_FUTIL_COMMAND(\\(.*\\)/_CMD(\\1)/' | sort >>$(genDir)/commands" +
385        "&& $(location scripts/getversion.sh) >> $(out)" +
386        "&& echo '#define _CMD(NAME) extern const struct futil_cmd_t __cmd_##NAME;' >> $(out)" +
387        "&& cat $(genDir)/commands >> $(out)" +
388        "&& echo '#undef _CMD' >> $(out)" +
389        "&& echo '#define _CMD(NAME) &__cmd_##NAME,' >> $(out)" +
390        "&& echo 'const struct futil_cmd_t *const futil_cmds[] = {' >> $(out)" +
391        "&& cat $(genDir)/commands >> $(out)" +
392        "&& echo '0};  /* null-terminated */' >> $(out)" +
393        "&& echo '#undef _CMD' >> $(out)",
394    srcs: [
395        ":futility_srcs",
396        "scripts/getversion.sh",
397    ],
398    out: ["futility_cmds.c"],
399}
400
401cc_binary {
402    name: "futility",
403    defaults: ["vboot_defaults"],
404    host_supported: true,
405    vendor: true,
406
407    srcs: [":futility_srcs"],
408    generated_sources: ["futility_cmds"],
409
410    local_include_dirs: ["futility"],
411
412    static_libs: ["libvboot_util"],
413}
414
415cc_binary {
416    name: "crossystem",
417    defaults: ["vboot_defaults"],
418    host_supported: true,
419    vendor_available: true,
420
421    srcs: ["utility/crossystem.c"],
422    static_libs: ["libvboot_util"],
423}
424