summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2017-08-26 17:39:42 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-08-29 19:37:04 -0700
commitff87bfac4e4883dff6076887f28358e2ea51b11e (patch)
tree6a8147f5cef6a7bc00016e35258d9b78a1fb3eb2
parent472d50b7296630d1ff15e7f69425f83dd7ca3d9f (diff)
downloadchrome-ec-ff87bfac4e4883dff6076887f28358e2ea51b11e.tar.gz
EFS: Add error codes
This patch defines more error codes to make the consle more descriptive. BUG=none BRANCH=none TEST=Boot Fizz. Change-Id: I84cc6cd7f309bb2f2e1f36dea6cf5a7f0f862f50 Reviewed-on: https://chromium-review.googlesource.com/639160 Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--common/vboot/common.c8
-rw-r--r--common/vboot/vb21_lib.c18
-rw-r--r--common/vboot/vboot.c27
-rw-r--r--include/common.h20
-rw-r--r--test/vboot.c16
5 files changed, 57 insertions, 32 deletions
diff --git a/common/vboot/common.c b/common/vboot/common.c
index 3a75a297e6..3a4af244a2 100644
--- a/common/vboot/common.c
+++ b/common/vboot/common.c
@@ -40,10 +40,8 @@ int vboot_verify(const uint8_t *data, int len,
uint32_t *workbuf;
int err = EC_SUCCESS;
- if (shared_mem_acquire(3 * RSANUMBYTES, (char **)&workbuf)) {
- CPRINTS("Failed to allocate memory");
- return EC_ERROR_UNKNOWN;
- }
+ if (shared_mem_acquire(3 * RSANUMBYTES, (char **)&workbuf))
+ return EC_ERROR_MEMORY_ALLOCATION;
/* Compute hash of the RW firmware */
SHA256_init(&ctx);
@@ -52,7 +50,7 @@ int vboot_verify(const uint8_t *data, int len,
/* Verify the data */
if (rsa_verify(key, sig, hash, workbuf) != 1)
- err = EC_ERROR_INVAL;
+ err = EC_ERROR_VBOOT_DATA_VERIFY;
shared_mem_release(workbuf);
diff --git a/common/vboot/vb21_lib.c b/common/vboot/vb21_lib.c
index 11242a3038..c85ecbbd75 100644
--- a/common/vboot/vb21_lib.c
+++ b/common/vboot/vb21_lib.c
@@ -16,9 +16,9 @@
int vb21_is_packed_key_valid(const struct vb21_packed_key *key)
{
if (key->c.magic != VB21_MAGIC_PACKED_KEY)
- return EC_ERROR_INVAL;
+ return EC_ERROR_VBOOT_KEY_MAGIC;
if (key->key_size != sizeof(struct rsa_public_key))
- return EC_ERROR_INVAL;
+ return EC_ERROR_VBOOT_KEY_SIZE;
return EC_SUCCESS;
}
@@ -26,19 +26,19 @@ int vb21_is_signature_valid(const struct vb21_signature *sig,
const struct vb21_packed_key *key)
{
if (sig->c.magic != VB21_MAGIC_SIGNATURE)
- return EC_ERROR_INVAL;
+ return EC_ERROR_VBOOT_SIG_MAGIC;
if (sig->sig_size != RSANUMBYTES)
- return EC_ERROR_INVAL;
+ return EC_ERROR_VBOOT_SIG_SIZE;
if (key->sig_alg != sig->sig_alg)
- return EC_ERROR_INVAL;
+ return EC_ERROR_VBOOT_SIG_ALGORITHM;
if (key->hash_alg != sig->hash_alg)
- return EC_ERROR_INVAL;
+ return EC_ERROR_VBOOT_HASH_ALGORITHM;
/* Sanity check signature offset and data size. */
if (sig->sig_offset < sizeof(*sig))
- return EC_ERROR_INVAL;
+ return EC_ERROR_VBOOT_SIG_OFFSET;
if (sig->sig_offset + RSANUMBYTES > CONFIG_RW_SIG_SIZE)
- return EC_ERROR_INVAL;
+ return EC_ERROR_VBOOT_SIG_OFFSET;
if (sig->data_size > CONFIG_RW_SIZE - CONFIG_RW_SIG_SIZE)
- return EC_ERROR_INVAL;
+ return EC_ERROR_VBOOT_DATA_SIZE;
return EC_SUCCESS;
}
diff --git a/common/vboot/vboot.c b/common/vboot/vboot.c
index 27a47fd125..9affcf4592 100644
--- a/common/vboot/vboot.c
+++ b/common/vboot/vboot.c
@@ -57,16 +57,18 @@ static int verify_slot(int slot)
const uint8_t *sig;
const uint8_t *data;
int len;
+ int rv;
- CPRINTS("Verifying RW_%c", slot == VBOOT_EC_SLOT_A ? 'A' : 'B');
+ CPRINTS("Verifying RW_%c", slot ? 'B' : 'A');
vb21_key = (const struct vb21_packed_key *)(
CONFIG_MAPPED_STORAGE_BASE +
CONFIG_EC_PROTECTED_STORAGE_OFF +
CONFIG_RO_PUBKEY_STORAGE_OFF);
- if (vb21_is_packed_key_valid(vb21_key)) {
- CPRINTS("Invalid key");
- return EC_ERROR_INVAL;
+ rv = vb21_is_packed_key_valid(vb21_key);
+ if (rv) {
+ CPRINTS("Invalid key (%d)", rv);
+ return EC_ERROR_VBOOT_KEY;
}
key = (const struct rsa_public_key *)
((const uint8_t *)vb21_key + vb21_key->key_offset);
@@ -89,8 +91,9 @@ static int verify_slot(int slot)
CONFIG_RW_B_SIGN_STORAGE_OFF);
}
- if (vb21_is_signature_valid(vb21_sig, vb21_key)) {
- CPRINTS("Invalid signature");
+ rv = vb21_is_signature_valid(vb21_sig, vb21_key);
+ if (rv) {
+ CPRINTS("Invalid signature (%d)", rv);
return EC_ERROR_INVAL;
}
sig = (const uint8_t *)vb21_sig + vb21_sig->sig_offset;
@@ -102,11 +105,14 @@ static int verify_slot(int slot)
return EC_ERROR_INVAL;
}
- if (vboot_verify(data, len, key, sig)) {
- CPRINTS("Invalid data");
+ rv = vboot_verify(data, len, key, sig);
+ if (rv) {
+ CPRINTS("Invalid data (%d)", rv);
return EC_ERROR_INVAL;
}
+ CPRINTS("Verified RW_%c", slot ? 'B' : 'A');
+
return EC_SUCCESS;
}
@@ -136,10 +142,11 @@ static int verify_and_jump(void)
}
/* 3. Jump (and reboot) */
- system_run_image_copy(slot == VBOOT_EC_SLOT_A ?
+ rv = system_run_image_copy(slot == VBOOT_EC_SLOT_A ?
SYSTEM_IMAGE_RW : SYSTEM_IMAGE_RW_B);
+ CPRINTS("Failed to jump (%d)", rv);
- return EC_ERROR_UNKNOWN;
+ return rv;
}
/* Request more power: charging battery or more powerful AC adapter */
diff --git a/include/common.h b/include/common.h
index 6f6b964c5f..fff9415240 100644
--- a/include/common.h
+++ b/include/common.h
@@ -143,6 +143,26 @@ enum ec_error_list {
EC_ERROR_NOT_HANDLED = 21,
/* Data has not changed */
EC_ERROR_UNCHANGED = 22,
+ /* Memory allocation */
+ EC_ERROR_MEMORY_ALLOCATION = 23,
+
+ /* Verified boot errors */
+ EC_ERROR_VBOOT_SIGNATURE = 0x1000, /* 4096 */
+ EC_ERROR_VBOOT_SIG_MAGIC = 0x1001,
+ EC_ERROR_VBOOT_SIG_SIZE = 0x1002,
+ EC_ERROR_VBOOT_SIG_ALGORITHM = 0x1003,
+ EC_ERROR_VBOOT_HASH_ALGORITHM = 0x1004,
+ EC_ERROR_VBOOT_SIG_OFFSET = 0x1005,
+ EC_ERROR_VBOOT_DATA_SIZE = 0x1006,
+
+ /* Verified boot key errors */
+ EC_ERROR_VBOOT_KEY = 0x1100,
+ EC_ERROR_VBOOT_KEY_MAGIC = 0x1101,
+ EC_ERROR_VBOOT_KEY_SIZE = 0x1102,
+
+ /* Verified boot data errors */
+ EC_ERROR_VBOOT_DATA = 0x1200,
+ EC_ERROR_VBOOT_DATA_VERIFY = 0x1201,
/* Module-internal error codes may use this range. */
EC_ERROR_INTERNAL_FIRST = 0x10000,
diff --git a/test/vboot.c b/test/vboot.c
index 3d4be10308..69521eff6e 100644
--- a/test/vboot.c
+++ b/test/vboot.c
@@ -63,49 +63,49 @@ static int test_vboot(void)
reset_data(&k, &s);
k.vb21_key.c.magic = VB21_MAGIC_SIGNATURE;
err = vb21_is_packed_key_valid(&k.vb21_key);
- TEST_ASSERT(err == EC_ERROR_INVAL);
+ TEST_ASSERT(err == EC_ERROR_VBOOT_KEY_MAGIC);
/* Invalid key size */
reset_data(&k, &s);
k.vb21_key.key_size--;
err = vb21_is_packed_key_valid(&k.vb21_key);
- TEST_ASSERT(err == EC_ERROR_INVAL);
+ TEST_ASSERT(err == EC_ERROR_VBOOT_KEY_SIZE);
/* Invalid magic */
reset_data(&k, &s);
s.vb21_sig.c.magic = VB21_MAGIC_PACKED_KEY;
err = vb21_is_signature_valid(&s.vb21_sig, &k.vb21_key);
- TEST_ASSERT(err == EC_ERROR_INVAL);
+ TEST_ASSERT(err == EC_ERROR_VBOOT_SIG_MAGIC);
/* Invalid sig size */
reset_data(&k, &s);
s.vb21_sig.sig_size--;
err = vb21_is_signature_valid(&s.vb21_sig, &k.vb21_key);
- TEST_ASSERT(err == EC_ERROR_INVAL);
+ TEST_ASSERT(err == EC_ERROR_VBOOT_SIG_SIZE);
/* Sig algorithm mismatch */
reset_data(&k, &s);
s.vb21_sig.sig_alg++;
err = vb21_is_signature_valid(&s.vb21_sig, &k.vb21_key);
- TEST_ASSERT(err == EC_ERROR_INVAL);
+ TEST_ASSERT(err == EC_ERROR_VBOOT_SIG_ALGORITHM);
/* Hash algorithm mismatch */
reset_data(&k, &s);
s.vb21_sig.hash_alg++;
err = vb21_is_signature_valid(&s.vb21_sig, &k.vb21_key);
- TEST_ASSERT(err == EC_ERROR_INVAL);
+ TEST_ASSERT(err == EC_ERROR_VBOOT_HASH_ALGORITHM);
/* Invalid sig_offset */
reset_data(&k, &s);
s.vb21_sig.sig_offset--;
err = vb21_is_signature_valid(&s.vb21_sig, &k.vb21_key);
- TEST_ASSERT(err == EC_ERROR_INVAL);
+ TEST_ASSERT(err == EC_ERROR_VBOOT_SIG_OFFSET);
/* Invalid data size */
reset_data(&k, &s);
s.vb21_sig.data_size = CONFIG_RW_SIZE;
err = vb21_is_signature_valid(&s.vb21_sig, &k.vb21_key);
- TEST_ASSERT(err == EC_ERROR_INVAL);
+ TEST_ASSERT(err == EC_ERROR_VBOOT_DATA_SIZE);
/* Invalid padding */
reset_data(&k, &s);