summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Kitching <kitching@google.com>2019-03-06 18:41:33 +0800
committerchrome-bot <chrome-bot@chromium.org>2019-03-11 23:52:13 -0700
commit6988559fb77e99a6ac2fc420cf83922ea162081e (patch)
tree72335cef7c2c4026a9e67a3d06ea50774f2b01fe
parent9e53b92e50165b777111f159daa2b4e3b3c8b355 (diff)
downloadvboot-6988559fb77e99a6ac2fc420cf83922ea162081e.tar.gz
vboot: move general constants to a separate header
coreboot uses the C preprocessor on its linker scripts to allow evaluation of macros when defining memory layout. Move constants from 2api.h to an independent file in order to allow for coreboot to use these constants in its memlayout file, without needing to include the entire vboot API. Note this commit creates two new header files: - firmware/2lib/include/2constants.h: contains the constants - firmware/include/vb2_constants.h: externally importable header Also, rename VB2_WORKBUF_RECOMMENDED_SIZE to VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE for clarity. BUG=b:124141368, b:124192753 TEST=Build locally TEST=/work/vboot/src/repohooks/pre-upload.py TEST=make clean && make runtests TEST=make clean && COV=1 make coverage && make coverage_html BRANCH=none Change-Id: Id17c6955b67e51cb048b10b4be0901c0e9110a1f Signed-off-by: Joel Kitching <kitching@google.com> Reviewed-on: https://chromium-review.googlesource.com/1504490 Commit-Ready: Joel Kitching <kitching@chromium.org> Tested-by: Joel Kitching <kitching@chromium.org> Reviewed-by: Hung-Te Lin <hungte@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
-rw-r--r--firmware/2lib/include/2api.h37
-rw-r--r--firmware/2lib/include/2constants.h50
-rw-r--r--firmware/include/vb2_constants.h14
-rw-r--r--futility/cmd_vbutil_firmware.c2
-rw-r--r--futility/cmd_vbutil_keyblock.c2
-rw-r--r--futility/file_type_bios.c2
-rw-r--r--futility/file_type_usbpd1.c2
-rw-r--r--futility/updater.c2
-rw-r--r--host/lib/host_keyblock.c2
-rw-r--r--tests/vb20_api_tests.c2
-rw-r--r--tests/vb20_misc_tests.c2
-rw-r--r--tests/vb21_api_tests.c2
-rw-r--r--tests/vb21_misc_tests.c2
-rw-r--r--tests/vb2_api_tests.c2
-rw-r--r--tests/vb2_misc_tests.c2
-rw-r--r--tests/vb2_nvstorage_tests.c2
-rw-r--r--tests/vb2_secdata_tests.c2
-rw-r--r--tests/vb2_secdatak_tests.c2
18 files changed, 80 insertions, 51 deletions
diff --git a/firmware/2lib/include/2api.h b/firmware/2lib/include/2api.h
index 34eb779d..f228fb30 100644
--- a/firmware/2lib/include/2api.h
+++ b/firmware/2lib/include/2api.h
@@ -22,48 +22,13 @@
#include <stdint.h>
#include "2common.h"
+#include "2constants.h"
#include "2crypto.h"
#include "2fw_hash_tags.h"
#include "2id.h"
#include "2recovery_reasons.h"
#include "2return_codes.h"
-/*
- * Size of non-volatile data used by vboot.
- *
- * If you only support non-volatile data format V1, then use VB2_NVDATA_SIZE.
- * If you support V2, use VB2_NVDATA_SIZE_V2 and set context flag
- * VB2_CONTEXT_NVDATA_V2.
- */
-#define VB2_NVDATA_SIZE 16
-#define VB2_NVDATA_SIZE_V2 64
-
-/* Size of secure data spaces used by vboot */
-#define VB2_SECDATA_SIZE 10
-#define VB2_SECDATAK_SIZE 14
-
-/*
- * Recommended size of work buffer for firmware verification stage
- *
- * TODO: The recommended size really depends on which key algorithms are
- * used. Should have a better / more accurate recommendation than this.
- */
-#define VB2_WORKBUF_RECOMMENDED_SIZE (12 * 1024)
-
-/*
- * Recommended size of work buffer for kernel verification stage
- *
- * This is bigger because vboot 2.0 kernel preambles are usually padded to
- * 64 KB.
- *
- * TODO: The recommended size really depends on which key algorithms are
- * used. Should have a better / more accurate recommendation than this.
- */
-#define VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE (80 * 1024)
-
-/* Recommended buffer size for vb2api_get_pcr_digest */
-#define VB2_PCR_DIGEST_RECOMMENDED_SIZE 32
-
/* Flags for vb2_context.
*
* Unless otherwise noted, flags are set by verified boot and may be read (but
diff --git a/firmware/2lib/include/2constants.h b/firmware/2lib/include/2constants.h
new file mode 100644
index 00000000..aa9e99e2
--- /dev/null
+++ b/firmware/2lib/include/2constants.h
@@ -0,0 +1,50 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * General vboot-related constants.
+ *
+ * Constants that need to be exposed to assembly files or linker scripts
+ * may be placed here and imported via vb2_constants.h.
+ */
+
+#ifndef VBOOT_REFERENCE_2CONSTANTS_H_
+#define VBOOT_REFERENCE_2CONSTANTS_H_
+
+/*
+ * Size of non-volatile data used by vboot.
+ *
+ * If you only support non-volatile data format V1, then use VB2_NVDATA_SIZE.
+ * If you support V2, use VB2_NVDATA_SIZE_V2 and set context flag
+ * VB2_CONTEXT_NVDATA_V2.
+ */
+#define VB2_NVDATA_SIZE 16
+#define VB2_NVDATA_SIZE_V2 64
+
+/* Size of secure data spaces used by vboot */
+#define VB2_SECDATA_SIZE 10
+#define VB2_SECDATAK_SIZE 14
+
+/*
+ * Recommended size of work buffer for firmware verification stage.
+ *
+ * TODO: The recommended size really depends on which key algorithms are
+ * used. Should have a better / more accurate recommendation than this.
+ */
+#define VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE (12 * 1024)
+
+/*
+ * Recommended size of work buffer for kernel verification stage.
+ *
+ * This is bigger because vboot 2.0 kernel preambles are usually padded to
+ * 64 KB.
+ *
+ * TODO: The recommended size really depends on which key algorithms are
+ * used. Should have a better / more accurate recommendation than this.
+ */
+#define VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE (80 * 1024)
+
+/* Recommended buffer size for vb2api_get_pcr_digest. */
+#define VB2_PCR_DIGEST_RECOMMENDED_SIZE 32
+
+#endif /* VBOOT_REFERENCE_2CONSTANTS_H_ */
diff --git a/firmware/include/vb2_constants.h b/firmware/include/vb2_constants.h
new file mode 100644
index 00000000..204bca97
--- /dev/null
+++ b/firmware/include/vb2_constants.h
@@ -0,0 +1,14 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * This header may be imported to expose a limited set of constants to
+ * assembly files or linker scripts without including the entire vboot API.
+ */
+
+#ifndef VBOOT_REFERENCE_VB2_CONSTANTS_H_
+#define VBOOT_REFERENCE_VB2_CONSTANTS_H_
+
+#include "../2lib/include/2constants.h"
+
+#endif /* VBOOT_REFERENCE_VB2_CONSTANTS_H_ */
diff --git a/futility/cmd_vbutil_firmware.c b/futility/cmd_vbutil_firmware.c
index ef1148ed..cf901706 100644
--- a/futility/cmd_vbutil_firmware.c
+++ b/futility/cmd_vbutil_firmware.c
@@ -188,7 +188,7 @@ vblock_cleanup:
static int do_verify(const char *infile, const char *signpubkey,
const char *fv_file, const char *kernelkey_file)
{
- uint8_t workbuf[VB2_WORKBUF_RECOMMENDED_SIZE];
+ uint8_t workbuf[VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE];
struct vb2_workbuf wb;
vb2_workbuf_init(&wb, workbuf, sizeof(workbuf));
diff --git a/futility/cmd_vbutil_keyblock.c b/futility/cmd_vbutil_keyblock.c
index 61053497..43811610 100644
--- a/futility/cmd_vbutil_keyblock.c
+++ b/futility/cmd_vbutil_keyblock.c
@@ -178,7 +178,7 @@ static int Unpack(const char *infile, const char *datapubkey,
/* If the signing public key is provided, then verify the block
* signature, since vb2_read_keyblock() only verified the hash. */
if (signpubkey) {
- static uint8_t workbuf[VB2_WORKBUF_RECOMMENDED_SIZE];
+ static uint8_t workbuf[VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE];
static struct vb2_workbuf wb;
if (block->keyblock_signature.sig_size == 0) {
diff --git a/futility/file_type_bios.c b/futility/file_type_bios.c
index e9e0b772..d9d132a5 100644
--- a/futility/file_type_bios.c
+++ b/futility/file_type_bios.c
@@ -262,7 +262,7 @@ static int fmap_sign_fw_main(const char *name, uint8_t *buf, uint32_t len,
static int fmap_sign_fw_preamble(const char *name, uint8_t *buf, uint32_t len,
void *data)
{
- static uint8_t workbuf[VB2_WORKBUF_RECOMMENDED_SIZE];
+ static uint8_t workbuf[VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE];
static struct vb2_workbuf wb;
vb2_workbuf_init(&wb, workbuf, sizeof(workbuf));
diff --git a/futility/file_type_usbpd1.c b/futility/file_type_usbpd1.c
index d285ff86..197466b7 100644
--- a/futility/file_type_usbpd1.c
+++ b/futility/file_type_usbpd1.c
@@ -375,7 +375,7 @@ static int try_our_own(enum vb2_signature_algorithm sig_alg,
{
struct vb2_public_key pubkey;
struct vb21_signature *sig;
- uint8_t buf[VB2_WORKBUF_RECOMMENDED_SIZE]
+ uint8_t buf[VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE]
__attribute__ ((aligned (VB2_WORKBUF_ALIGN)));
struct vb2_workbuf wb = {
.buf = buf,
diff --git a/futility/updater.c b/futility/updater.c
index a7179dac..a4e8a996 100644
--- a/futility/updater.c
+++ b/futility/updater.c
@@ -1236,7 +1236,7 @@ static struct vb2_keyblock *dupe_keyblock(const struct vb2_keyblock *block)
static int verify_keyblock(const struct vb2_keyblock *block,
const struct vb2_packed_key *sign_key) {
int r;
- uint8_t workbuf[VB2_WORKBUF_RECOMMENDED_SIZE];
+ uint8_t workbuf[VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE];
struct vb2_workbuf wb;
struct vb2_public_key key;
struct vb2_keyblock *new_block;
diff --git a/host/lib/host_keyblock.c b/host/lib/host_keyblock.c
index b8c9af3a..08f2b768 100644
--- a/host/lib/host_keyblock.c
+++ b/host/lib/host_keyblock.c
@@ -144,7 +144,7 @@ struct vb2_keyblock *vb2_create_keyblock_external(
struct vb2_keyblock *vb2_read_keyblock(const char *filename)
{
- uint8_t workbuf[VB2_WORKBUF_RECOMMENDED_SIZE];
+ uint8_t workbuf[VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE];
struct vb2_workbuf wb;
vb2_workbuf_init(&wb, workbuf, sizeof(workbuf));
diff --git a/tests/vb20_api_tests.c b/tests/vb20_api_tests.c
index e9dff9fe..3a5d4968 100644
--- a/tests/vb20_api_tests.c
+++ b/tests/vb20_api_tests.c
@@ -17,7 +17,7 @@
#include "test_common.h"
/* Common context for tests */
-static uint8_t workbuf[VB2_WORKBUF_RECOMMENDED_SIZE]
+static uint8_t workbuf[VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE]
__attribute__ ((aligned (VB2_WORKBUF_ALIGN)));
static struct vb2_context cc;
static struct vb2_shared_data *sd;
diff --git a/tests/vb20_misc_tests.c b/tests/vb20_misc_tests.c
index 9442aa0a..995e0fc6 100644
--- a/tests/vb20_misc_tests.c
+++ b/tests/vb20_misc_tests.c
@@ -18,7 +18,7 @@
#include "test_common.h"
/* Common context for tests */
-static uint8_t workbuf[VB2_WORKBUF_RECOMMENDED_SIZE]
+static uint8_t workbuf[VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE]
__attribute__ ((aligned (VB2_WORKBUF_ALIGN)));
static struct vb2_context cc;
static struct vb2_shared_data *sd;
diff --git a/tests/vb21_api_tests.c b/tests/vb21_api_tests.c
index e9eab10d..89e683b0 100644
--- a/tests/vb21_api_tests.c
+++ b/tests/vb21_api_tests.c
@@ -23,7 +23,7 @@
#include "test_common.h"
/* Common context for tests */
-static uint8_t workbuf[VB2_WORKBUF_RECOMMENDED_SIZE]
+static uint8_t workbuf[VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE]
__attribute__ ((aligned (VB2_WORKBUF_ALIGN)));
static struct vb2_context ctx;
static struct vb2_shared_data *sd;
diff --git a/tests/vb21_misc_tests.c b/tests/vb21_misc_tests.c
index 8bf2a6e8..c33432d9 100644
--- a/tests/vb21_misc_tests.c
+++ b/tests/vb21_misc_tests.c
@@ -19,7 +19,7 @@
#include "test_common.h"
/* Common context for tests */
-static uint8_t workbuf[VB2_WORKBUF_RECOMMENDED_SIZE]
+static uint8_t workbuf[VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE]
__attribute__ ((aligned (VB2_WORKBUF_ALIGN)));
static struct vb2_context ctx;
static struct vb2_shared_data *sd;
diff --git a/tests/vb2_api_tests.c b/tests/vb2_api_tests.c
index 88dfa967..64995591 100644
--- a/tests/vb2_api_tests.c
+++ b/tests/vb2_api_tests.c
@@ -17,7 +17,7 @@
#include "test_common.h"
/* Common context for tests */
-static uint8_t workbuf[VB2_WORKBUF_RECOMMENDED_SIZE]
+static uint8_t workbuf[VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE]
__attribute__ ((aligned (VB2_WORKBUF_ALIGN)));
static struct vb2_context cc;
static struct vb2_shared_data *sd;
diff --git a/tests/vb2_misc_tests.c b/tests/vb2_misc_tests.c
index fddd49df..1bb9686f 100644
--- a/tests/vb2_misc_tests.c
+++ b/tests/vb2_misc_tests.c
@@ -15,7 +15,7 @@
#include "test_common.h"
/* Common context for tests */
-static uint8_t workbuf[VB2_WORKBUF_RECOMMENDED_SIZE]
+static uint8_t workbuf[VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE]
__attribute__ ((aligned (VB2_WORKBUF_ALIGN)));
static struct vb2_context cc;
static struct vb2_shared_data *sd;
diff --git a/tests/vb2_nvstorage_tests.c b/tests/vb2_nvstorage_tests.c
index 9d1b1bb0..fe73216a 100644
--- a/tests/vb2_nvstorage_tests.c
+++ b/tests/vb2_nvstorage_tests.c
@@ -86,7 +86,7 @@ static void nv_storage_test(uint32_t ctxflags)
{
struct nv_field *vnf;
uint8_t goodcrc;
- uint8_t workbuf[VB2_WORKBUF_RECOMMENDED_SIZE]
+ uint8_t workbuf[VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE]
__attribute__ ((aligned (VB2_WORKBUF_ALIGN)));
struct vb2_context c = {
.flags = ctxflags,
diff --git a/tests/vb2_secdata_tests.c b/tests/vb2_secdata_tests.c
index 1abfcb2e..823efab5 100644
--- a/tests/vb2_secdata_tests.c
+++ b/tests/vb2_secdata_tests.c
@@ -32,7 +32,7 @@ static void test_changed(struct vb2_context *ctx, int changed, const char *why)
static void secdata_test(void)
{
- uint8_t workbuf[VB2_WORKBUF_RECOMMENDED_SIZE]
+ uint8_t workbuf[VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE]
__attribute__ ((aligned (VB2_WORKBUF_ALIGN)));
struct vb2_context c = {
.flags = 0,
diff --git a/tests/vb2_secdatak_tests.c b/tests/vb2_secdatak_tests.c
index 4bc15cf9..c0207a3a 100644
--- a/tests/vb2_secdatak_tests.c
+++ b/tests/vb2_secdatak_tests.c
@@ -33,7 +33,7 @@ static void test_changed(struct vb2_context *ctx, int changed, const char *why)
static void secdatak_test(void)
{
- uint8_t workbuf[VB2_WORKBUF_RECOMMENDED_SIZE]
+ uint8_t workbuf[VB2_FIRMWARE_WORKBUF_RECOMMENDED_SIZE]
__attribute__ ((aligned (VB2_WORKBUF_ALIGN)));
struct vb2_context c = {
.flags = 0,