diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2017-08-26 17:39:42 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-08-29 19:37:04 -0700 |
commit | ff87bfac4e4883dff6076887f28358e2ea51b11e (patch) | |
tree | 6a8147f5cef6a7bc00016e35258d9b78a1fb3eb2 /common/vboot | |
parent | 472d50b7296630d1ff15e7f69425f83dd7ca3d9f (diff) | |
download | chrome-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>
Diffstat (limited to 'common/vboot')
-rw-r--r-- | common/vboot/common.c | 8 | ||||
-rw-r--r-- | common/vboot/vb21_lib.c | 18 | ||||
-rw-r--r-- | common/vboot/vboot.c | 27 |
3 files changed, 29 insertions, 24 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 */ |