summaryrefslogtreecommitdiff
path: root/firmware/2lib/2misc.c
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2014-05-14 11:37:52 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-06-05 23:14:27 +0000
commit3333e578497aafc4eb8c6e1e359f6e2b1dee633a (patch)
treef4c62ed293d9605559c09cb1b0607b4210a3d839 /firmware/2lib/2misc.c
parente166d04e797b605dd2f6784bc863a262c418c0c4 (diff)
downloadvboot-3333e578497aafc4eb8c6e1e359f6e2b1dee633a.tar.gz
vboot2: Add nvstorage and secdata functions
This is the second of several CLs adding a more memory- and code-efficient firmware verification library. BUG=chromium:370082 BRANCH=none TEST=make clean && COV=1 make Change-Id: I1dd571e7511bff18469707d5a2e90068e68e0d6f Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/199841 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'firmware/2lib/2misc.c')
-rw-r--r--firmware/2lib/2misc.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/firmware/2lib/2misc.c b/firmware/2lib/2misc.c
new file mode 100644
index 00000000..760d234d
--- /dev/null
+++ b/firmware/2lib/2misc.c
@@ -0,0 +1,39 @@
+/* Copyright (c) 2014 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.
+ *
+ * Misc functions which need access to vb2_context but are not public APIs
+ */
+
+#include "2sysincludes.h"
+#include "2api.h"
+#include "2common.h"
+#include "2misc.h"
+#include "2nvstorage.h"
+#include "2secdata.h"
+#include "2sha.h"
+#include "2rsa.h"
+
+int vb2_init_context(struct vb2_context *ctx)
+{
+ struct vb2_shared_data *sd = vb2_get_sd(ctx);
+
+ /* Don't do anything if the context has already been initialized */
+ if (ctx->workbuf_used)
+ return VB2_SUCCESS;
+
+ /*
+ * Workbuf had better be big enough for our shared data struct and
+ * aligned. Not much we can do if it isn't; we'll die before we can
+ * store a recovery reason.
+ */
+ if (ctx->workbuf_size < sizeof(*sd))
+ return VB2_ERROR_WORKBUF_TOO_SMALL;
+ if (!vb_aligned(ctx->workbuf, sizeof(uint32_t)))
+ return VB2_ERROR_BUFFER_UNALIGNED;
+
+ /* Initialize the shared data at the start of the work buffer */
+ memset(sd, 0, sizeof(*sd));
+ ctx->workbuf_used = sizeof(*sd);
+ return VB2_SUCCESS;
+}