mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-08 00:21:46 +00:00
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>
This commit is contained in:
committed by
chrome-bot
parent
472d50b729
commit
ff87bfac4e
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user