summaryrefslogtreecommitdiff
path: root/firmware/lib/region-init.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/lib/region-init.c')
-rw-r--r--firmware/lib/region-init.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/firmware/lib/region-init.c b/firmware/lib/region-init.c
new file mode 100644
index 00000000..bec0450d
--- /dev/null
+++ b/firmware/lib/region-init.c
@@ -0,0 +1,50 @@
+/* Copyright (c) 2013 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.
+ *
+ * High-level firmware API for loading and verifying rewritable firmware.
+ * (Firmware portion)
+ */
+
+#include "sysincludes.h"
+
+#include "bmpblk_header.h"
+#include "region.h"
+#include "gbb_access.h"
+#include "gbb_header.h"
+#include "load_kernel_fw.h"
+#include "utility.h"
+#include "vboot_api.h"
+#include "vboot_struct.h"
+
+VbError_t VbRegionReadData(VbCommonParams *cparams,
+ enum vb_firmware_region region, uint32_t offset,
+ uint32_t size, void *buf)
+{
+ /* This is the old API, for backwards compatibility */
+ if (region == VB_REGION_GBB && cparams->gbb_data) {
+ if (offset + size > cparams->gbb_size)
+ return VBERROR_INVALID_GBB;
+ Memcpy(buf, cparams->gbb_data + offset, size);
+ } else
+#ifdef REGION_READ
+ {
+ VbError_t ret;
+
+ ret = VbExRegionRead(cparams, region, offset, size, buf);
+ if (ret)
+ return ret;
+ }
+#else
+ return VBERROR_INVALID_GBB;
+#endif
+
+ return VBERROR_SUCCESS;
+}
+
+VbError_t VbGbbReadHeader_static(VbCommonParams *cparams,
+ GoogleBinaryBlockHeader *gbb)
+{
+ return VbRegionReadData(cparams, VB_REGION_GBB, 0,
+ sizeof(GoogleBinaryBlockHeader), gbb);
+}