mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-01 13:43:49 +00:00
vboot: use vb2_crc8 instead of Crc8
No need to have two implementations of this now. BUG=chromium:611535 BRANCH=none TEST=make runtests; emerge-kevin coreboot depthcharge Change-Id: Id3348eae80c5d85451981a44729164ff59f88648 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/399121 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
This commit is contained in:
committed by
chrome-bot
parent
664096bd1a
commit
bf6263d529
4
Makefile
4
Makefile
@@ -317,7 +317,6 @@ BDBLIB = ${BUILD}/bdb.a
|
|||||||
|
|
||||||
# Firmware library sources needed by VbInit() call
|
# Firmware library sources needed by VbInit() call
|
||||||
VBINIT_SRCS = \
|
VBINIT_SRCS = \
|
||||||
firmware/lib/crc8.c \
|
|
||||||
firmware/lib/utility.c \
|
firmware/lib/utility.c \
|
||||||
firmware/lib/vboot_common_init.c \
|
firmware/lib/vboot_common_init.c \
|
||||||
firmware/lib/vboot_nvstorage.c \
|
firmware/lib/vboot_nvstorage.c \
|
||||||
@@ -498,9 +497,9 @@ HOSTLIB_SRCS = \
|
|||||||
cgpt/cgpt_common.c \
|
cgpt/cgpt_common.c \
|
||||||
cgpt/cgpt_create.c \
|
cgpt/cgpt_create.c \
|
||||||
cgpt/cgpt_prioritize.c \
|
cgpt/cgpt_prioritize.c \
|
||||||
|
firmware/2lib/2crc8.c \
|
||||||
firmware/lib/cgptlib/cgptlib_internal.c \
|
firmware/lib/cgptlib/cgptlib_internal.c \
|
||||||
firmware/lib/cgptlib/crc32.c \
|
firmware/lib/cgptlib/crc32.c \
|
||||||
firmware/lib/crc8.c \
|
|
||||||
firmware/lib/gpt_misc.c \
|
firmware/lib/gpt_misc.c \
|
||||||
${TLCL_SRCS} \
|
${TLCL_SRCS} \
|
||||||
firmware/lib/utility_string.c \
|
firmware/lib/utility_string.c \
|
||||||
@@ -531,6 +530,7 @@ TINYHOSTLIB_SRCS = \
|
|||||||
cgpt/cgpt_common.c \
|
cgpt/cgpt_common.c \
|
||||||
cgpt/cgpt_create.c \
|
cgpt/cgpt_create.c \
|
||||||
cgpt/cgpt_prioritize.c \
|
cgpt/cgpt_prioritize.c \
|
||||||
|
firmware/2lib/2crc8.c \
|
||||||
firmware/lib/cgptlib/cgptlib_internal.c \
|
firmware/lib/cgptlib/cgptlib_internal.c \
|
||||||
firmware/lib/cgptlib/crc32.c \
|
firmware/lib/cgptlib/crc32.c \
|
||||||
firmware/lib/gpt_misc.c \
|
firmware/lib/gpt_misc.c \
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
/* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "sysincludes.h"
|
|
||||||
|
|
||||||
#include "crc8.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return CRC-8 of the data, using x^8 + x^2 + x + 1 polynomial. A table-based
|
|
||||||
* algorithm would be faster, but for only a few bytes it isn't worth the code
|
|
||||||
* size. */
|
|
||||||
uint8_t Crc8(const void *vptr, int len)
|
|
||||||
{
|
|
||||||
const uint8_t *data = vptr;
|
|
||||||
unsigned crc = 0;
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
for (j = len; j; j--, data++) {
|
|
||||||
crc ^= (*data << 8);
|
|
||||||
for(i = 8; i; i--) {
|
|
||||||
if (crc & 0x8000)
|
|
||||||
crc ^= (0x1070 << 3);
|
|
||||||
crc <<= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (uint8_t)(crc >> 8);
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
/* 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.
|
|
||||||
*
|
|
||||||
* Very simple 8-bit CRC function.
|
|
||||||
*/
|
|
||||||
#ifndef VBOOT_REFERENCE_CRC8_H_
|
|
||||||
#define VBOOT_REFERENCE_CRC8_H_
|
|
||||||
#include "sysincludes.h"
|
|
||||||
|
|
||||||
uint8_t Crc8(const void *data, int len);
|
|
||||||
|
|
||||||
#endif /* VBOOT_REFERENCE_CRC8_H_ */
|
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include "sysincludes.h"
|
#include "sysincludes.h"
|
||||||
|
|
||||||
#include "crc8.h"
|
#include "2crc8.h"
|
||||||
#include "rollback_index.h"
|
#include "rollback_index.h"
|
||||||
#include "tlcl.h"
|
#include "tlcl.h"
|
||||||
#include "tss_constants.h"
|
#include "tss_constants.h"
|
||||||
@@ -99,7 +99,7 @@ uint32_t ReadSpaceFirmware(RollbackSpaceFirmware *rsf)
|
|||||||
* more times to see if it gets better before we give up. It
|
* more times to see if it gets better before we give up. It
|
||||||
* could just be noise.
|
* could just be noise.
|
||||||
*/
|
*/
|
||||||
if (rsf->crc8 == Crc8(rsf,
|
if (rsf->crc8 == vb2_crc8(rsf,
|
||||||
offsetof(RollbackSpaceFirmware, crc8)))
|
offsetof(RollbackSpaceFirmware, crc8)))
|
||||||
return TPM_SUCCESS;
|
return TPM_SUCCESS;
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ uint32_t WriteSpaceFirmware(RollbackSpaceFirmware *rsf)
|
|||||||
/* All writes should use struct_version 2 or greater. */
|
/* All writes should use struct_version 2 or greater. */
|
||||||
if (rsf->struct_version < 2)
|
if (rsf->struct_version < 2)
|
||||||
rsf->struct_version = 2;
|
rsf->struct_version = 2;
|
||||||
rsf->crc8 = Crc8(rsf, offsetof(RollbackSpaceFirmware, crc8));
|
rsf->crc8 = vb2_crc8(rsf, offsetof(RollbackSpaceFirmware, crc8));
|
||||||
|
|
||||||
while (attempts--) {
|
while (attempts--) {
|
||||||
r = SafeWrite(FIRMWARE_NV_INDEX, rsf,
|
r = SafeWrite(FIRMWARE_NV_INDEX, rsf,
|
||||||
@@ -195,7 +195,8 @@ uint32_t ReadSpaceKernel(RollbackSpaceKernel *rsk)
|
|||||||
* more times to see if it gets better before we give up. It
|
* more times to see if it gets better before we give up. It
|
||||||
* could just be noise.
|
* could just be noise.
|
||||||
*/
|
*/
|
||||||
if (rsk->crc8 == Crc8(rsk, offsetof(RollbackSpaceKernel, crc8)))
|
if (rsk->crc8 ==
|
||||||
|
vb2_crc8(rsk, offsetof(RollbackSpaceKernel, crc8)))
|
||||||
return TPM_SUCCESS;
|
return TPM_SUCCESS;
|
||||||
|
|
||||||
VBDEBUG(("TPM: %s() - bad CRC\n", __func__));
|
VBDEBUG(("TPM: %s() - bad CRC\n", __func__));
|
||||||
@@ -214,7 +215,7 @@ uint32_t WriteSpaceKernel(RollbackSpaceKernel *rsk)
|
|||||||
/* All writes should use struct_version 2 or greater. */
|
/* All writes should use struct_version 2 or greater. */
|
||||||
if (rsk->struct_version < 2)
|
if (rsk->struct_version < 2)
|
||||||
rsk->struct_version = 2;
|
rsk->struct_version = 2;
|
||||||
rsk->crc8 = Crc8(rsk, offsetof(RollbackSpaceKernel, crc8));
|
rsk->crc8 = vb2_crc8(rsk, offsetof(RollbackSpaceKernel, crc8));
|
||||||
|
|
||||||
while (attempts--) {
|
while (attempts--) {
|
||||||
r = SafeWrite(KERNEL_NV_INDEX, rsk,
|
r = SafeWrite(KERNEL_NV_INDEX, rsk,
|
||||||
@@ -371,7 +372,7 @@ uint32_t RollbackFwmpRead(struct RollbackSpaceFwmp *fwmp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Verify CRC */
|
/* Verify CRC */
|
||||||
if (u.bf.crc != Crc8(u.buf + 2, u.bf.struct_size - 2)) {
|
if (u.bf.crc != vb2_crc8(u.buf + 2, u.bf.struct_size - 2)) {
|
||||||
VBDEBUG(("TPM: %s() - bad CRC\n", __func__));
|
VBDEBUG(("TPM: %s() - bad CRC\n", __func__));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "sysincludes.h"
|
#include "sysincludes.h"
|
||||||
|
|
||||||
#include "crc8.h"
|
#include "2crc8.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
#include "vboot_common.h"
|
#include "vboot_common.h"
|
||||||
#include "vboot_nvstorage.h"
|
#include "vboot_nvstorage.h"
|
||||||
@@ -79,7 +79,7 @@ int VbNvSetup(VbNvContext *context)
|
|||||||
|
|
||||||
/* Check data for consistency */
|
/* Check data for consistency */
|
||||||
if ((HEADER_SIGNATURE != (raw[HEADER_OFFSET] & HEADER_MASK))
|
if ((HEADER_SIGNATURE != (raw[HEADER_OFFSET] & HEADER_MASK))
|
||||||
|| (Crc8(raw, CRC_OFFSET) != raw[CRC_OFFSET])) {
|
|| (vb2_crc8(raw, CRC_OFFSET) != raw[CRC_OFFSET])) {
|
||||||
/* Data is inconsistent (bad CRC or header); reset defaults */
|
/* Data is inconsistent (bad CRC or header); reset defaults */
|
||||||
memset(raw, 0, VBNV_BLOCK_SIZE);
|
memset(raw, 0, VBNV_BLOCK_SIZE);
|
||||||
raw[HEADER_OFFSET] = (HEADER_SIGNATURE |
|
raw[HEADER_OFFSET] = (HEADER_SIGNATURE |
|
||||||
@@ -96,7 +96,7 @@ int VbNvSetup(VbNvContext *context)
|
|||||||
int VbNvTeardown(VbNvContext *context)
|
int VbNvTeardown(VbNvContext *context)
|
||||||
{
|
{
|
||||||
if (context->regenerate_crc) {
|
if (context->regenerate_crc) {
|
||||||
context->raw[CRC_OFFSET] = Crc8(context->raw, CRC_OFFSET);
|
context->raw[CRC_OFFSET] = vb2_crc8(context->raw, CRC_OFFSET);
|
||||||
context->regenerate_crc = 0;
|
context->regenerate_crc = 0;
|
||||||
context->raw_changed = 1;
|
context->raw_changed = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#define _STUB_IMPLEMENTATION_ /* So we can use memset() ourselves */
|
#define _STUB_IMPLEMENTATION_ /* So we can use memset() ourselves */
|
||||||
|
|
||||||
#include "crc8.h"
|
#include "2crc8.h"
|
||||||
#include "rollback_index.h"
|
#include "rollback_index.h"
|
||||||
#include "test_common.h"
|
#include "test_common.h"
|
||||||
#include "tlcl.h"
|
#include "tlcl.h"
|
||||||
@@ -64,7 +64,7 @@ static uint32_t mock_permissions;
|
|||||||
/* Recalculate CRC of FWMP data */
|
/* Recalculate CRC of FWMP data */
|
||||||
static void RecalcFwmpCrc(void)
|
static void RecalcFwmpCrc(void)
|
||||||
{
|
{
|
||||||
mock_fwmp.fwmp.crc = Crc8(mock_fwmp.buf + 2,
|
mock_fwmp.fwmp.crc = vb2_crc8(mock_fwmp.buf + 2,
|
||||||
mock_fwmp.fwmp.struct_size - 2);
|
mock_fwmp.fwmp.struct_size - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,7 +296,8 @@ static void CrcTestFirmware(void)
|
|||||||
/* If the CRC is good and some noise happens, it should recover. */
|
/* If the CRC is good and some noise happens, it should recover. */
|
||||||
ResetMocks(0, 0);
|
ResetMocks(0, 0);
|
||||||
mock_rsf.struct_version = 2;
|
mock_rsf.struct_version = 2;
|
||||||
mock_rsf.crc8 = Crc8(&mock_rsf, offsetof(RollbackSpaceFirmware, crc8));
|
mock_rsf.crc8 = vb2_crc8(&mock_rsf,
|
||||||
|
offsetof(RollbackSpaceFirmware, crc8));
|
||||||
noise_on[0] = 1;
|
noise_on[0] = 1;
|
||||||
TEST_EQ(ReadSpaceFirmware(&rsf), 0,
|
TEST_EQ(ReadSpaceFirmware(&rsf), 0,
|
||||||
"ReadSpaceFirmware(), v2, good CRC");
|
"ReadSpaceFirmware(), v2, good CRC");
|
||||||
@@ -399,7 +400,8 @@ static void CrcTestKernel(void)
|
|||||||
/* If the CRC is good and some noise happens, it should recover. */
|
/* If the CRC is good and some noise happens, it should recover. */
|
||||||
ResetMocks(0, 0);
|
ResetMocks(0, 0);
|
||||||
mock_rsk.struct_version = 2;
|
mock_rsk.struct_version = 2;
|
||||||
mock_rsk.crc8 = Crc8(&mock_rsk, offsetof(RollbackSpaceKernel, crc8));
|
mock_rsk.crc8 = vb2_crc8(&mock_rsk,
|
||||||
|
offsetof(RollbackSpaceKernel, crc8));
|
||||||
noise_on[0] = 1;
|
noise_on[0] = 1;
|
||||||
TEST_EQ(ReadSpaceKernel(&rsk), 0, "ReadSpaceKernel(), v2, good CRC");
|
TEST_EQ(ReadSpaceKernel(&rsk), 0, "ReadSpaceKernel(), v2, good CRC");
|
||||||
TEST_STR_EQ(mock_calls,
|
TEST_STR_EQ(mock_calls,
|
||||||
|
|||||||
Reference in New Issue
Block a user