summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2019-11-14 11:42:53 -0800
committerCommit Bot <commit-bot@chromium.org>2019-11-20 06:51:01 +0000
commitdd42910a704c1bf7e9663fe22140817858ae7cec (patch)
tree51548af0e7154b1d607b916b8582974f407c060a
parenta44cbfbb006a0b7fd8e2edfe10dcc3dc7d01685c (diff)
downloadvboot-dd42910a704c1bf7e9663fe22140817858ae7cec.tar.gz
2lib: Move context-related functions from 2misc.c into 2context.c
This patch separates out some code into an extra file so that it's easier to link into hostlib without pulling in all additional dependencies from the random 2misc.c crap. The functions are copied wholesale with no changes. BRANCH=None BUG=chromium:1024732 TEST=make runtests Change-Id: Ia00d1da277e5fc0956c8a1ae608d842224016c91 Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1917819 Tested-by: Brian Norris <briannorris@chromium.org> Reviewed-by: Brian Norris <briannorris@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Queue: Randall Spangler <rspangler@chromium.org> Commit-Queue: Brian Norris <briannorris@chromium.org> (cherry picked from commit 54fc81cf692dbcb4496fa9664103564a9c386c05) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1924295 Reviewed-by: Shelley Chen <shchen@chromium.org> Commit-Queue: Shelley Chen <shchen@chromium.org> Tested-by: Shelley Chen <shchen@chromium.org>
-rw-r--r--Makefile1
-rw-r--r--firmware/2lib/2context.c100
-rw-r--r--firmware/2lib/2misc.c89
3 files changed, 101 insertions, 89 deletions
diff --git a/Makefile b/Makefile
index 4751336c..3519b7e7 100644
--- a/Makefile
+++ b/Makefile
@@ -351,6 +351,7 @@ FWLIB2X_SRCS = \
firmware/2lib/2api.c \
firmware/2lib/2auxfw_sync.c \
firmware/2lib/2common.c \
+ firmware/2lib/2context.c \
firmware/2lib/2crc8.c \
firmware/2lib/2ec_sync.c \
firmware/2lib/2gbb.c \
diff --git a/firmware/2lib/2context.c b/firmware/2lib/2context.c
new file mode 100644
index 00000000..1ee5a3cc
--- /dev/null
+++ b/firmware/2lib/2context.c
@@ -0,0 +1,100 @@
+/* Copyright (c) 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.
+ *
+ * Functions for initializing the vboot workbuffer and vb2_context.
+ */
+
+#include "2api.h"
+#include "2common.h"
+#include "2misc.h"
+#include "2sysincludes.h"
+
+void vb2_workbuf_from_ctx(struct vb2_context *ctx, struct vb2_workbuf *wb)
+{
+ struct vb2_shared_data *sd = vb2_get_sd(ctx);
+ vb2_workbuf_init(wb, (void *)sd + sd->workbuf_used,
+ sd->workbuf_size - sd->workbuf_used);
+}
+
+void vb2_set_workbuf_used(struct vb2_context *ctx, uint32_t used)
+{
+ struct vb2_shared_data *sd = vb2_get_sd(ctx);
+ sd->workbuf_used = vb2_wb_round_up(used);
+}
+
+vb2_error_t vb2api_init(void *workbuf, uint32_t size,
+ struct vb2_context **ctxptr)
+{
+ struct vb2_shared_data *sd = workbuf;
+ *ctxptr = NULL;
+
+ if (!vb2_aligned(workbuf, VB2_WORKBUF_ALIGN))
+ return VB2_ERROR_WORKBUF_ALIGN;
+
+ if (size < vb2_wb_round_up(sizeof(*sd)))
+ return VB2_ERROR_WORKBUF_SMALL;
+
+ /* Zero out vb2_shared_data (which includes vb2_context). */
+ memset(sd, 0, sizeof(*sd));
+
+ /* Initialize shared data. */
+ sd->magic = VB2_SHARED_DATA_MAGIC;
+ sd->struct_version_major = VB2_SHARED_DATA_VERSION_MAJOR;
+ sd->struct_version_minor = VB2_SHARED_DATA_VERSION_MINOR;
+ sd->workbuf_size = size;
+ sd->workbuf_used = vb2_wb_round_up(sizeof(*sd));
+
+ *ctxptr = &sd->ctx;
+ return VB2_SUCCESS;
+}
+
+#pragma GCC diagnostic push
+/* Don't warn for the version_minor check even if the checked version is 0. */
+#pragma GCC diagnostic ignored "-Wtype-limits"
+vb2_error_t vb2api_relocate(void *new_workbuf, void *cur_workbuf, uint32_t size,
+ struct vb2_context **ctxptr)
+{
+ struct vb2_shared_data *sd = cur_workbuf;
+
+ if (!vb2_aligned(new_workbuf, VB2_WORKBUF_ALIGN))
+ return VB2_ERROR_WORKBUF_ALIGN;
+
+ /* Check magic and version. */
+ if (sd->magic != VB2_SHARED_DATA_MAGIC)
+ return VB2_ERROR_SHARED_DATA_MAGIC;
+
+ if (sd->struct_version_major != VB2_SHARED_DATA_VERSION_MAJOR ||
+ sd->struct_version_minor < VB2_SHARED_DATA_VERSION_MINOR)
+ return VB2_ERROR_SHARED_DATA_VERSION;
+
+ /* Check workbuf integrity. */
+ if (sd->workbuf_used < vb2_wb_round_up(sizeof(*sd)))
+ return VB2_ERROR_WORKBUF_INVALID;
+
+ if (sd->workbuf_size < sd->workbuf_used)
+ return VB2_ERROR_WORKBUF_INVALID;
+
+ if (sd->workbuf_used > size)
+ return VB2_ERROR_WORKBUF_SMALL;
+
+ /* Relocate if necessary. */
+ if (cur_workbuf != new_workbuf)
+ memmove(new_workbuf, cur_workbuf, sd->workbuf_used);
+
+ /* Set the new size, and return the context pointer. */
+ sd = new_workbuf;
+ sd->workbuf_size = size;
+ *ctxptr = &sd->ctx;
+
+ return VB2_SUCCESS;
+}
+#pragma GCC diagnostic pop
+
+vb2_error_t vb2api_reinit(void *workbuf, struct vb2_context **ctxptr)
+{
+ /* Blindly retrieve workbuf_size. vb2api_relocate() will
+ perform workbuf validation checks. */
+ struct vb2_shared_data *sd = workbuf;
+ return vb2api_relocate(workbuf, workbuf, sd->workbuf_size, ctxptr);
+}
diff --git a/firmware/2lib/2misc.c b/firmware/2lib/2misc.c
index deb4f885..3775dcee 100644
--- a/firmware/2lib/2misc.c
+++ b/firmware/2lib/2misc.c
@@ -33,19 +33,6 @@ struct vb2_gbb_header *vb2_get_gbb(struct vb2_context *ctx)
return (struct vb2_gbb_header *)((void *)sd + sd->gbb_offset);
}
-void vb2_workbuf_from_ctx(struct vb2_context *ctx, struct vb2_workbuf *wb)
-{
- struct vb2_shared_data *sd = vb2_get_sd(ctx);
- vb2_workbuf_init(wb, (void *)sd + sd->workbuf_used,
- sd->workbuf_size - sd->workbuf_used);
-}
-
-void vb2_set_workbuf_used(struct vb2_context *ctx, uint32_t used)
-{
- struct vb2_shared_data *sd = vb2_get_sd(ctx);
- sd->workbuf_used = vb2_wb_round_up(used);
-}
-
vb2_error_t vb2_read_gbb_header(struct vb2_context *ctx,
struct vb2_gbb_header *gbb)
{
@@ -128,82 +115,6 @@ void vb2api_fail(struct vb2_context *ctx, uint8_t reason, uint8_t subcode)
}
}
-vb2_error_t vb2api_init(void *workbuf, uint32_t size,
- struct vb2_context **ctxptr)
-{
- struct vb2_shared_data *sd = workbuf;
- *ctxptr = NULL;
-
- if (!vb2_aligned(workbuf, VB2_WORKBUF_ALIGN))
- return VB2_ERROR_WORKBUF_ALIGN;
-
- if (size < vb2_wb_round_up(sizeof(*sd)))
- return VB2_ERROR_WORKBUF_SMALL;
-
- /* Zero out vb2_shared_data (which includes vb2_context). */
- memset(sd, 0, sizeof(*sd));
-
- /* Initialize shared data. */
- sd->magic = VB2_SHARED_DATA_MAGIC;
- sd->struct_version_major = VB2_SHARED_DATA_VERSION_MAJOR;
- sd->struct_version_minor = VB2_SHARED_DATA_VERSION_MINOR;
- sd->workbuf_size = size;
- sd->workbuf_used = vb2_wb_round_up(sizeof(*sd));
-
- *ctxptr = &sd->ctx;
- return VB2_SUCCESS;
-}
-
-#pragma GCC diagnostic push
-/* Don't warn for the version_minor check even if the checked version is 0. */
-#pragma GCC diagnostic ignored "-Wtype-limits"
-vb2_error_t vb2api_relocate(void *new_workbuf, void *cur_workbuf, uint32_t size,
- struct vb2_context **ctxptr)
-{
- struct vb2_shared_data *sd = cur_workbuf;
-
- if (!vb2_aligned(new_workbuf, VB2_WORKBUF_ALIGN))
- return VB2_ERROR_WORKBUF_ALIGN;
-
- /* Check magic and version. */
- if (sd->magic != VB2_SHARED_DATA_MAGIC)
- return VB2_ERROR_SHARED_DATA_MAGIC;
-
- if (sd->struct_version_major != VB2_SHARED_DATA_VERSION_MAJOR ||
- sd->struct_version_minor < VB2_SHARED_DATA_VERSION_MINOR)
- return VB2_ERROR_SHARED_DATA_VERSION;
-
- /* Check workbuf integrity. */
- if (sd->workbuf_used < vb2_wb_round_up(sizeof(*sd)))
- return VB2_ERROR_WORKBUF_INVALID;
-
- if (sd->workbuf_size < sd->workbuf_used)
- return VB2_ERROR_WORKBUF_INVALID;
-
- if (sd->workbuf_used > size)
- return VB2_ERROR_WORKBUF_SMALL;
-
- /* Relocate if necessary. */
- if (cur_workbuf != new_workbuf)
- memmove(new_workbuf, cur_workbuf, sd->workbuf_used);
-
- /* Set the new size, and return the context pointer. */
- sd = new_workbuf;
- sd->workbuf_size = size;
- *ctxptr = &sd->ctx;
-
- return VB2_SUCCESS;
-}
-#pragma GCC diagnostic pop
-
-vb2_error_t vb2api_reinit(void *workbuf, struct vb2_context **ctxptr)
-{
- /* Blindly retrieve workbuf_size. vb2api_relocate() will
- perform workbuf validation checks. */
- struct vb2_shared_data *sd = workbuf;
- return vb2api_relocate(workbuf, workbuf, sd->workbuf_size, ctxptr);
-}
-
void vb2_check_recovery(struct vb2_context *ctx)
{
struct vb2_shared_data *sd = vb2_get_sd(ctx);