diff options
author | Randall Spangler <rspangler@chromium.org> | 2016-06-03 14:00:27 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-08-03 17:47:13 -0700 |
commit | 158b29672a17c1d11e182f0285e0009dd39e5204 (patch) | |
tree | d15e4c2e873de2dede00a9cc5cc662b1a7a4c8a0 /firmware | |
parent | 46b77fb2f04941c869c3a98cd17e9209c36b2917 (diff) | |
download | vboot-158b29672a17c1d11e182f0285e0009dd39e5204.tar.gz |
futility: cmd_show uses only vboot 2.0 APIs
This removes the remaining vboot 1.0 API calls from cmd_show.
BUG=chromium:611535
BRANCH=none
TEST=make runtests
Change-Id: I03c4260aa034100efbbea1005367cd85dfff273d
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/350173
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/lib20/include/vb2_common.h | 22 | ||||
-rw-r--r-- | firmware/lib20/include/vb2_struct.h | 4 | ||||
-rw-r--r-- | firmware/lib20/kernel.c | 46 |
3 files changed, 65 insertions, 7 deletions
diff --git a/firmware/lib20/include/vb2_common.h b/firmware/lib20/include/vb2_common.h index 0ab89cab..536fbbb0 100644 --- a/firmware/lib20/include/vb2_common.h +++ b/firmware/lib20/include/vb2_common.h @@ -204,4 +204,26 @@ int vb2_verify_kernel_preamble(struct vb2_kernel_preamble *preamble, const struct vb2_public_key *key, const struct vb2_workbuf *wb); +/** + * Retrieve the 16-bit vmlinuz header address and size from the preamble. + * + * Size 0 means there is no 16-bit vmlinuz header present. Old preamble + * versions (<2.1) return 0 for both fields. + * + * @param preamble Preamble to check + * @param vmlinuz_header_address Destination for header address + * @param vmlinuz_header_size Destination for header size + */ +void vb2_kernel_get_vmlinuz_header(const struct vb2_kernel_preamble *preamble, + uint64_t *vmlinuz_header_address, + uint32_t *vmlinuz_header_size); + +/** + * Get the flags for the kernel preamble. + * + * @param preamble Preamble to check + * @return Flags for the preamble. Old preamble versions (<2.2) return 0. + */ +uint32_t vb2_kernel_get_flags(const struct vb2_kernel_preamble *preamble); + #endif /* VBOOT_REFERENCE_VB2_COMMON_H_ */ diff --git a/firmware/lib20/include/vb2_struct.h b/firmware/lib20/include/vb2_struct.h index f644a5fa..eeaf0cec 100644 --- a/firmware/lib20/include/vb2_struct.h +++ b/firmware/lib20/include/vb2_struct.h @@ -268,6 +268,8 @@ struct vb2_kernel_preamble { uint32_t flags; } __attribute__((packed)); -#define EXPECTED_VB2_KERNEL_PREAMBLE_SIZE 116 +#define EXPECTED_VB2_KERNEL_PREAMBLE_2_0_SIZE 96 +#define EXPECTED_VB2_KERNEL_PREAMBLE_2_1_SIZE 112 +#define EXPECTED_VB2_KERNEL_PREAMBLE_2_2_SIZE 116 #endif /* VBOOT_REFERENCE_VB2_STRUCT_H_ */ diff --git a/firmware/lib20/kernel.c b/firmware/lib20/kernel.c index 609f2461..4ded5d55 100644 --- a/firmware/lib20/kernel.c +++ b/firmware/lib20/kernel.c @@ -249,11 +249,12 @@ int vb2_verify_kernel_preamble(struct vb2_kernel_preamble *preamble, const struct vb2_workbuf *wb) { struct vb2_signature *sig = &preamble->preamble_signature; + uint32_t min_size = EXPECTED_VB2_KERNEL_PREAMBLE_2_0_SIZE; VB2_DEBUG("Verifying kernel preamble.\n"); - /* Sanity checks before attempting signature of data */ - if(size < sizeof(*preamble)) { + /* Make sure it's even safe to look at the struct */ + if(size < min_size) { VB2_DEBUG("Not enough data for preamble header.\n"); return VB2_ERROR_PREAMBLE_TOO_SMALL_FOR_HEADER; } @@ -262,9 +263,14 @@ int vb2_verify_kernel_preamble(struct vb2_kernel_preamble *preamble, VB2_DEBUG("Incompatible kernel preamble header version.\n"); return VB2_ERROR_PREAMBLE_HEADER_VERSION; } - if (preamble->header_version_minor < 2) { - VB2_DEBUG("Old preamble header format not supported\n"); - return VB2_ERROR_PREAMBLE_HEADER_OLD; + + if (preamble->header_version_minor >= 2) + min_size = EXPECTED_VB2_KERNEL_PREAMBLE_2_2_SIZE; + else if (preamble->header_version_minor == 1) + min_size = EXPECTED_VB2_KERNEL_PREAMBLE_2_1_SIZE; + if(preamble->preamble_size < min_size) { + VB2_DEBUG("Preamble size too small for header.\n"); + return VB2_ERROR_PREAMBLE_TOO_SMALL_FOR_HEADER; } if (size < preamble->preamble_size) { VB2_DEBUG("Not enough data for preamble.\n"); @@ -325,7 +331,8 @@ int vb2_verify_kernel_preamble(struct vb2_kernel_preamble *preamble, * If vmlinuz header is present, verify it's covered by the body * signature. */ - if (preamble->vmlinuz_header_size) { + if (preamble->header_version_minor >= 1 && + preamble->vmlinuz_header_size) { const void *body_ptr = (const void *)(uintptr_t)preamble->body_load_address; const void *vmlinuz_header_ptr = (const void *) @@ -442,3 +449,30 @@ int vb2_load_kernel_preamble(struct vb2_context *ctx) return VB2_SUCCESS; } + +void vb2_kernel_get_vmlinuz_header(const struct vb2_kernel_preamble *preamble, + uint64_t *vmlinuz_header_address, + uint32_t *vmlinuz_header_size) +{ + if (preamble->header_version_minor < 1) { + *vmlinuz_header_address = 0; + *vmlinuz_header_size = 0; + } else { + /* + * Set header and size only if the preamble header version is > + * 2.1 as they don't exist in version 2.0 (Note that we don't + * need to check header_version_major; if that's not 2 then + * VerifyKernelPreamble() would have already failed. + */ + *vmlinuz_header_address = preamble->vmlinuz_header_address; + *vmlinuz_header_size = preamble->vmlinuz_header_size; + } +} + +uint32_t vb2_kernel_get_flags(const struct vb2_kernel_preamble *preamble) +{ + if (preamble->header_version_minor < 2) + return 0; + + return preamble->flags; +} |