summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChe-Liang Chiou <clchiou@chromium.org>2011-08-03 14:57:09 +0800
committerSimon Glass <sjg@chromium.org>2011-08-29 10:59:21 -0700
commit134eeb15b52efb15164619293d14404f1748f3a3 (patch)
tree9b2781c40c53d3b9287a1eafabb5381dc0a58235
parent744345a6dcf4864d86a20f26993234b02ab0d30c (diff)
CHROMIUM: move VbExHashFirmwareBody() to lib/vbexport/
This patch only moves code around. BUG=chromium-os:16542 TEST=build okay Change-Id: Idc908fd2e652c114ae8029c120386fb44e63b4f9 Reviewed-on: http://gerrit.chromium.org/gerrit/5204 Tested-by: Che-Liang Chiou <clchiou@chromium.org> Reviewed-by: Gabe Black <gabeblack@chromium.org>
-rw-r--r--common/cmd_vboot_twostop.c52
-rw-r--r--include/chromeos/hasher_state.h26
-rw-r--r--lib/vbexport/load_firmware.c61
3 files changed, 54 insertions, 85 deletions
diff --git a/common/cmd_vboot_twostop.c b/common/cmd_vboot_twostop.c
index d956c528cd4..593fdbde5f2 100644
--- a/common/cmd_vboot_twostop.c
+++ b/common/cmd_vboot_twostop.c
@@ -20,6 +20,7 @@
#include <chromeos/fdt_decode.h>
#include <chromeos/firmware_storage.h>
#include <chromeos/gbb.h>
+#include <chromeos/hasher_state.h>
#include <chromeos/memory_wipe.h>
#include <chromeos/power_management.h>
@@ -144,57 +145,6 @@ int twostop_init_cparams(struct fdt_twostop_fmap *fmap,
return 0;
}
-typedef struct {
- firmware_storage_t *file;
- struct {
- void *vblock;
- uint32_t offset;
- uint32_t size;
- void *cache;
- } fw[2];
-} hasher_state_t;
-
-/* This can only be called after key block has been verified */
-uintptr_t firmware_body_size(const uintptr_t vblock_address)
-{
- const VbKeyBlockHeader const *keyblock;
- const VbFirmwarePreambleHeader const *preamble;
-
- keyblock = (VbKeyBlockHeader *)vblock_address;
- preamble = (VbFirmwarePreambleHeader *)
- (vblock_address + (uintptr_t)keyblock->key_block_size);
-
- return preamble->body_signature.data_size;
-}
-
-VbError_t VbExHashFirmwareBody(VbCommonParams* cparams, uint32_t firmware_index)
-{
- hasher_state_t *s = cparams->caller_context;
- const int i = (firmware_index == VB_SELECT_FIRMWARE_A ? 0 : 1);
- firmware_storage_t *file = s->file;
-
- if (firmware_index != VB_SELECT_FIRMWARE_A &&
- firmware_index != VB_SELECT_FIRMWARE_B) {
- VBDEBUG(PREFIX "incorrect firmware index: %d\n",
- firmware_index);
- return 1;
- }
-
- /*
- * The key block has been verified. It is safe now to infer the actual
- * firmware body size from the key block.
- */
- s->fw[i].size = firmware_body_size((uintptr_t)s->fw[i].vblock);
-
- if (file->read(file, s->fw[i].offset, s->fw[i].size, s->fw[i].cache)) {
- VBDEBUG(PREFIX "fail to read firmware: %d\n", firmware_index);
- return 1;
- }
-
- VbUpdateFirmwareBodyHash(cparams, s->fw[i].cache, s->fw[i].size);
- return 0;
-}
-
#ifdef CONFIG_OF_CONTROL
static uintptr_t get_current_sp(void)
{
diff --git a/include/chromeos/hasher_state.h b/include/chromeos/hasher_state.h
new file mode 100644
index 00000000000..322ed93bb61
--- /dev/null
+++ b/include/chromeos/hasher_state.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2011 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.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ */
+
+#ifndef CHROMEOS_HASHER_STATE_H_
+#define CHROMEOS_HASHER_STATE_H_
+
+#include <chromeos/firmware_storage.h>
+
+typedef struct {
+ firmware_storage_t *file;
+ struct {
+ void *vblock;
+ uint32_t offset;
+ uint32_t size;
+ void *cache;
+ } fw[2];
+} hasher_state_t;
+
+#endif /* CHROMEOS_HASHER_STATE_H_ */
diff --git a/lib/vbexport/load_firmware.c b/lib/vbexport/load_firmware.c
index 426c55c300d..847418293e1 100644
--- a/lib/vbexport/load_firmware.c
+++ b/lib/vbexport/load_firmware.c
@@ -10,57 +10,50 @@
#include <common.h>
#include <chromeos/common.h>
-#include <chromeos/firmware_storage.h>
-#include <vboot/firmware_cache.h>
+#include <chromeos/hasher_state.h>
-/* Import the header files from vboot_reference. */
#include <vboot_api.h>
+#include <vboot_struct.h>
-#define PREFIX "load_firmware: "
+#define PREFIX "load_firmware: "
-/*
- * Amount of bytes we read each time we call read().
- * See the commit log for more detail about the benchmark results.
- */
-#define BLOCK_SIZE (8 * 1024)
+/* This can only be called after key block has been verified */
+static uintptr_t firmware_body_size(const uintptr_t vblock_address)
+{
+ const VbKeyBlockHeader const *keyblock;
+ const VbFirmwarePreambleHeader const *preamble;
+
+ keyblock = (VbKeyBlockHeader *)vblock_address;
+ preamble = (VbFirmwarePreambleHeader *)
+ (vblock_address + (uintptr_t)keyblock->key_block_size);
-VbError_t VbExHashFirmwareBody(VbCommonParams* cparams,
- uint32_t firmware_index)
+ return preamble->body_signature.data_size;
+}
+
+VbError_t VbExHashFirmwareBody(VbCommonParams* cparams, uint32_t firmware_index)
{
- firmware_cache_t *cache = (firmware_cache_t *)cparams->caller_context;
- firmware_storage_t *file = cache->file;
- firmware_info_t *info;
- int index;
- uint8_t *buffer;
- size_t offset, leftover, n;
+ hasher_state_t *s = cparams->caller_context;
+ const int i = (firmware_index == VB_SELECT_FIRMWARE_A ? 0 : 1);
+ firmware_storage_t *file = s->file;
if (firmware_index != VB_SELECT_FIRMWARE_A &&
firmware_index != VB_SELECT_FIRMWARE_B) {
- VBDEBUG(PREFIX "Incorrect firmware index: %08x\n",
+ VBDEBUG(PREFIX "incorrect firmware index: %d\n",
firmware_index);
return 1;
}
- index = (firmware_index == VB_SELECT_FIRMWARE_A ? 0 : 1);
- info = &cache->infos[index];
- buffer = info->buffer;
- offset = info->offset;
-
/*
- * This loop feeds firmware body into VbUpdateFirmwareBodyHash.
+ * The key block has been verified. It is safe now to infer the actual
+ * firmware body size from the key block.
*/
- for (leftover = info->size;
- leftover > 0;
- leftover -= n, offset += n, buffer += n) {
- n = min(BLOCK_SIZE, leftover);
- if (file->read(file, offset, n, buffer)) {
- VBDEBUG(PREFIX "an error has occured "
- "while reading firmware");
- return 1;
- }
+ s->fw[i].size = firmware_body_size((uintptr_t)s->fw[i].vblock);
- VbUpdateFirmwareBodyHash(cparams, buffer, n);
+ if (file->read(file, s->fw[i].offset, s->fw[i].size, s->fw[i].cache)) {
+ VBDEBUG(PREFIX "fail to read firmware: %d\n", firmware_index);
+ return 1;
}
+ VbUpdateFirmwareBodyHash(cparams, s->fw[i].cache, s->fw[i].size);
return 0;
}