diff options
author | Joel Kitching <kitching@google.com> | 2019-07-31 14:12:30 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-08-13 04:36:52 +0000 |
commit | e6700f4c70fe72850ae4f3f5df19c9281ebcefc8 (patch) | |
tree | 0f2abff7be99bc140e288058fb2eeab6f8bb8b64 /firmware/lib | |
parent | a5afd01feb0b4b45adbcd8ab38ab8a2ef2a2ef67 (diff) | |
download | vboot-e6700f4c70fe72850ae4f3f5df19c9281ebcefc8.tar.gz |
vboot: update vboot2 functions to use new vb2_error_t
To make explicit when vboot2 error codes should be returned,
use the new vb2_error_t type on all functions which return
VB2_ERROR_* constants.
BUG=b:124141368, chromium:988410
TEST=make clean && make runtests
BRANCH=none
Change-Id: Idd3ee8afe8c78347783ce5fa829cb78f1e5719e2
Signed-off-by: Joel Kitching <kitching@google.com>
Cq-Depend: chromium:1728113, chromium:1728499
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1728292
Reviewed-by: Joel Kitching <kitching@chromium.org>
Commit-Queue: Joel Kitching <kitching@chromium.org>
Tested-by: Joel Kitching <kitching@chromium.org>
Diffstat (limited to 'firmware/lib')
-rw-r--r-- | firmware/lib/ec_sync.c | 16 | ||||
-rw-r--r-- | firmware/lib/include/rollback_index.h | 3 | ||||
-rw-r--r-- | firmware/lib/include/vboot_common.h | 28 | ||||
-rw-r--r-- | firmware/lib/include/vboot_kernel.h | 2 | ||||
-rw-r--r-- | firmware/lib/mocked_rollback_index.c | 2 | ||||
-rw-r--r-- | firmware/lib/rollback_index.c | 2 | ||||
-rw-r--r-- | firmware/lib/vboot_api_kernel.c | 4 | ||||
-rw-r--r-- | firmware/lib/vboot_common.c | 24 | ||||
-rw-r--r-- | firmware/lib/vboot_common_init.c | 2 | ||||
-rw-r--r-- | firmware/lib/vboot_display.c | 2 | ||||
-rw-r--r-- | firmware/lib/vboot_kernel.c | 28 | ||||
-rw-r--r-- | firmware/lib/vboot_ui.c | 6 |
12 files changed, 58 insertions, 61 deletions
diff --git a/firmware/lib/ec_sync.c b/firmware/lib/ec_sync.c index 23951aff..bdea2f9a 100644 --- a/firmware/lib/ec_sync.c +++ b/firmware/lib/ec_sync.c @@ -46,7 +46,7 @@ static void request_recovery(struct vb2_context *ctx, uint32_t recovery_request) static vb2_error_t protect_ec(struct vb2_context *ctx, int devidx, enum VbSelectFirmware_t select) { - int rv = VbExEcProtect(devidx, select); + vb2_error_t rv = VbExEcProtect(devidx, select); if (rv == VBERROR_EC_REBOOT_TO_RO_REQUIRED) { VB2_DEBUG("VbExEcProtect() needs reboot\n"); @@ -97,15 +97,16 @@ static const char *image_name_to_string(enum VbSelectFirmware_t select) * @param select Which firmware image to check * @return VB2_SUCCESS, or non-zero error code. */ -static int check_ec_hash(struct vb2_context *ctx, int devidx, - enum VbSelectFirmware_t select) +static vb2_error_t check_ec_hash(struct vb2_context *ctx, int devidx, + enum VbSelectFirmware_t select) { struct vb2_shared_data *sd = vb2_get_sd(ctx); /* Get current EC hash. */ const uint8_t *ec_hash = NULL; int ec_hash_size; - int rv = VbExEcHashImage(devidx, select, &ec_hash, &ec_hash_size); + vb2_error_t rv = VbExEcHashImage(devidx, select, &ec_hash, + &ec_hash_size); if (rv) { VB2_DEBUG("VbExEcHashImage() returned %d\n", rv); request_recovery(ctx, VB2_RECOVERY_EC_HASH_FAILED); @@ -155,7 +156,8 @@ static vb2_error_t update_ec(struct vb2_context *ctx, int devidx, /* Get expected EC image */ const uint8_t *want = NULL; int want_size; - int rv = VbExEcGetExpectedImage(devidx, select, &want, &want_size); + vb2_error_t rv = VbExEcGetExpectedImage(devidx, select, &want, + &want_size); if (rv) { VB2_DEBUG("VbExEcGetExpectedImage() returned %d\n", rv); request_recovery(ctx, VB2_RECOVERY_EC_EXPECTED_IMAGE); @@ -211,7 +213,7 @@ static vb2_error_t check_ec_active(struct vb2_context *ctx, int devidx) * trust what EC-RW says. If it lies it's in RO, we'll flash RW while * it's in RW. */ - int rv = VbExEcRunningRW(devidx, &in_rw); + vb2_error_t rv = VbExEcRunningRW(devidx, &in_rw); /* If we couldn't determine where the EC was, reboot to recovery. */ if (rv != VBERROR_SUCCESS) { @@ -239,7 +241,7 @@ static vb2_error_t sync_one_ec(struct vb2_context *ctx, int devidx) { struct vb2_shared_data *sd = vb2_get_sd(ctx); int is_rw_ab = ctx->flags & RW_AB(devidx); - int rv; + vb2_error_t rv; const enum VbSelectFirmware_t select_rw = is_rw_ab ? VB_SELECT_FIRMWARE_EC_UPDATE : diff --git a/firmware/lib/include/rollback_index.h b/firmware/lib/include/rollback_index.h index ff369114..c5b119e2 100644 --- a/firmware/lib/include/rollback_index.h +++ b/firmware/lib/include/rollback_index.h @@ -9,6 +9,7 @@ #ifndef VBOOT_REFERENCE_ROLLBACK_INDEX_H_ #define VBOOT_REFERENCE_ROLLBACK_INDEX_H_ +#include "2return_codes.h" #include "sysincludes.h" #include "tss_constants.h" @@ -164,6 +165,6 @@ uint32_t SafeWrite(uint32_t index, const void *data, uint32_t length); /** * Utility function to turn the virtual dev-mode flag on or off. 0=off, 1=on. */ -uint32_t SetVirtualDevMode(int val); +vb2_error_t SetVirtualDevMode(int val); #endif /* VBOOT_REFERENCE_ROLLBACK_INDEX_H_ */ diff --git a/firmware/lib/include/vboot_common.h b/firmware/lib/include/vboot_common.h index 95916488..ac020cc3 100644 --- a/firmware/lib/include/vboot_common.h +++ b/firmware/lib/include/vboot_common.h @@ -55,14 +55,14 @@ const uint8_t *GetSignatureDataC(const VbSignature *sig); /* * Helper functions to verify the data pointed to by a subfield is inside the - * parent data. Returns 0 if inside, 1 if error. + * parent data. */ -int VerifyPublicKeyInside(const void *parent, uint64_t parent_size, - const struct vb2_packed_key *key); +vb2_error_t VerifyPublicKeyInside(const void *parent, uint64_t parent_size, + const struct vb2_packed_key *key); -int VerifySignatureInside(const void *parent, uint64_t parent_size, - const VbSignature *sig); +vb2_error_t VerifySignatureInside(const void *parent, uint64_t parent_size, + const VbSignature *sig); /** * Initialize a public key to refer to [key_data]. @@ -86,9 +86,9 @@ int PublicKeyCopy(struct vb2_packed_key *dest, * * Returns VBOOT_SUCCESS if successful. */ -int VbGetKernelVmlinuzHeader(const VbKernelPreambleHeader *preamble, - uint64_t *vmlinuz_header_address, - uint64_t *vmlinuz_header_size); +vb2_error_t VbGetKernelVmlinuzHeader(const VbKernelPreambleHeader *preamble, + uint64_t *vmlinuz_header_address, + uint64_t *vmlinuz_header_size); /** * Checks if the kernel preamble has flags field. This is available only if the @@ -97,21 +97,21 @@ int VbGetKernelVmlinuzHeader(const VbKernelPreambleHeader *preamble, * * Returns VBOOT_SUCCESS if version is >=2.2. */ -int VbKernelHasFlags(const VbKernelPreambleHeader *preamble); +vb2_error_t VbKernelHasFlags(const VbKernelPreambleHeader *preamble); /** * Verify that the Vmlinuz Header is contained inside of the kernel blob. * * Returns VBOOT_SUCCESS or VBOOT_PREAMBLE_INVALID on error */ -int VerifyVmlinuzInsideKBlob(uint64_t kblob, uint64_t kblob_size, - uint64_t header, uint64_t header_size); +vb2_error_t VerifyVmlinuzInsideKBlob(uint64_t kblob, uint64_t kblob_size, + uint64_t header, uint64_t header_size); /** * Initialize a verified boot shared data structure. * * Returns 0 if success, non-zero if error. */ -int VbSharedDataInit(VbSharedDataHeader *header, uint64_t size); +vb2_error_t VbSharedDataInit(VbSharedDataHeader *header, uint64_t size); /** * Reserve [size] bytes of the shared data area. Returns the offset of the @@ -124,8 +124,8 @@ uint64_t VbSharedDataReserve(VbSharedDataHeader *header, uint64_t size); * * Returns 0 if success, non-zero if error. */ -int VbSharedDataSetKernelKey(VbSharedDataHeader *header, - const struct vb2_packed_key *src); +vb2_error_t VbSharedDataSetKernelKey(VbSharedDataHeader *header, + const struct vb2_packed_key *src); /** * Check whether recovery is allowed or not. diff --git a/firmware/lib/include/vboot_kernel.h b/firmware/lib/include/vboot_kernel.h index 61ce2c93..7044ba10 100644 --- a/firmware/lib/include/vboot_kernel.h +++ b/firmware/lib/include/vboot_kernel.h @@ -27,7 +27,7 @@ struct vb2_context; * @return VBERROR_SUCCESS, VBERROR_NO_DISK_FOUND if no disks of the specified * type were found, or other non-zero VBERROR_ codes for other failures. */ -uint32_t VbTryLoadKernel(struct vb2_context *ctx, uint32_t get_info_flags); +vb2_error_t VbTryLoadKernel(struct vb2_context *ctx, uint32_t get_info_flags); /* Flags for VbUserConfirms() */ #define VB_CONFIRM_MUST_TRUST_KEYBOARD (1 << 0) diff --git a/firmware/lib/mocked_rollback_index.c b/firmware/lib/mocked_rollback_index.c index a4b0ceb0..733b0a54 100644 --- a/firmware/lib/mocked_rollback_index.c +++ b/firmware/lib/mocked_rollback_index.c @@ -14,7 +14,7 @@ #include "tss_constants.h" -uint32_t SetVirtualDevMode(int val) +vb2_error_t SetVirtualDevMode(int val) { return TPM_SUCCESS; } diff --git a/firmware/lib/rollback_index.c b/firmware/lib/rollback_index.c index f52c8b59..41df72bb 100644 --- a/firmware/lib/rollback_index.c +++ b/firmware/lib/rollback_index.c @@ -143,7 +143,7 @@ uint32_t WriteSpaceFirmware(RollbackSpaceFirmware *rsf) return TPM_E_CORRUPTED_STATE; } -uint32_t SetVirtualDevMode(int val) +vb2_error_t SetVirtualDevMode(int val) { RollbackSpaceFirmware rsf; diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c index 9202c6b8..6187655b 100644 --- a/firmware/lib/vboot_api_kernel.c +++ b/firmware/lib/vboot_api_kernel.c @@ -66,7 +66,7 @@ uint32_t vb2_get_fwmp_flags(void) return fwmp.flags; } -uint32_t VbTryLoadKernel(struct vb2_context *ctx, uint32_t get_info_flags) +vb2_error_t VbTryLoadKernel(struct vb2_context *ctx, uint32_t get_info_flags) { vb2_error_t retval = VBERROR_UNKNOWN; VbDiskInfo* disk_info = NULL; @@ -473,7 +473,7 @@ vb2_error_t VbVerifyMemoryBootImage(struct vb2_context *ctx, uint32_t allow_fastboot_full_cap = 0; struct vb2_workbuf wb; vb2_error_t retval; - int rv; + vb2_error_t rv; /* Allocate work buffer */ vb2_workbuf_from_ctx(ctx, &wb); diff --git a/firmware/lib/vboot_common.c b/firmware/lib/vboot_common.c index e9516476..87500452 100644 --- a/firmware/lib/vboot_common.c +++ b/firmware/lib/vboot_common.c @@ -55,16 +55,16 @@ const uint8_t *GetSignatureDataC(const VbSignature *sig) * the parent data. */ -int VerifyPublicKeyInside(const void *parent, uint64_t parent_size, - const struct vb2_packed_key *key) +vb2_error_t VerifyPublicKeyInside(const void *parent, uint64_t parent_size, + const struct vb2_packed_key *key) { return vb2_verify_member_inside(parent, parent_size, key, sizeof(struct vb2_packed_key), key->key_offset, key->key_size); } -int VerifySignatureInside(const void *parent, uint64_t parent_size, - const VbSignature *sig) +vb2_error_t VerifySignatureInside(const void *parent, uint64_t parent_size, + const VbSignature *sig) { return vb2_verify_member_inside(parent, parent_size, sig, sizeof(VbSignature), @@ -92,9 +92,9 @@ int PublicKeyCopy(struct vb2_packed_key *dest, const struct vb2_packed_key *src) return 0; } -int VbGetKernelVmlinuzHeader(const VbKernelPreambleHeader *preamble, - uint64_t *vmlinuz_header_address, - uint64_t *vmlinuz_header_size) +vb2_error_t VbGetKernelVmlinuzHeader(const VbKernelPreambleHeader *preamble, + uint64_t *vmlinuz_header_address, + uint64_t *vmlinuz_header_size) { *vmlinuz_header_address = 0; *vmlinuz_header_size = 0; @@ -111,7 +111,7 @@ int VbGetKernelVmlinuzHeader(const VbKernelPreambleHeader *preamble, return VBOOT_SUCCESS; } -int VbKernelHasFlags(const VbKernelPreambleHeader *preamble) +vb2_error_t VbKernelHasFlags(const VbKernelPreambleHeader *preamble) { if (preamble->header_version_minor > 1) return VBOOT_SUCCESS; @@ -119,8 +119,8 @@ int VbKernelHasFlags(const VbKernelPreambleHeader *preamble) return VBOOT_KERNEL_PREAMBLE_NO_FLAGS; } -int VerifyVmlinuzInsideKBlob(uint64_t kblob, uint64_t kblob_size, - uint64_t header, uint64_t header_size) +vb2_error_t VerifyVmlinuzInsideKBlob(uint64_t kblob, uint64_t kblob_size, + uint64_t header, uint64_t header_size) { uint64_t end = header-kblob; if (end > kblob_size) @@ -147,8 +147,8 @@ uint64_t VbSharedDataReserve(VbSharedDataHeader *header, uint64_t size) return offs; } -int VbSharedDataSetKernelKey(VbSharedDataHeader *header, - const struct vb2_packed_key *src) +vb2_error_t VbSharedDataSetKernelKey(VbSharedDataHeader *header, + const struct vb2_packed_key *src) { struct vb2_packed_key *kdest; diff --git a/firmware/lib/vboot_common_init.c b/firmware/lib/vboot_common_init.c index b85c3cc3..44b3eb26 100644 --- a/firmware/lib/vboot_common_init.c +++ b/firmware/lib/vboot_common_init.c @@ -14,7 +14,7 @@ #include "vboot_common.h" #include "utility.h" -int VbSharedDataInit(VbSharedDataHeader *header, uint64_t size) +vb2_error_t VbSharedDataInit(VbSharedDataHeader *header, uint64_t size) { VB2_DEBUG("VbSharedDataInit, %d bytes, header %d bytes\n", (int)size, (int)sizeof(VbSharedDataHeader)); diff --git a/firmware/lib/vboot_display.c b/firmware/lib/vboot_display.c index a2b57ef4..364cd131 100644 --- a/firmware/lib/vboot_display.c +++ b/firmware/lib/vboot_display.c @@ -278,7 +278,7 @@ vb2_error_t VbDisplayDebugInfo(struct vb2_context *ctx) char buf[DEBUG_INFO_SIZE] = ""; char sha1sum[VB2_SHA1_DIGEST_SIZE * 2 + 1]; uint32_t used = 0; - int ret; + vb2_error_t ret; uint32_t i; vb2_workbuf_from_ctx(ctx, &wb); diff --git a/firmware/lib/vboot_kernel.c b/firmware/lib/vboot_kernel.c index 96461d9f..a8c536d5 100644 --- a/firmware/lib/vboot_kernel.c +++ b/firmware/lib/vboot_kernel.c @@ -126,14 +126,11 @@ static uint32_t get_body_offset(uint8_t *kbuf) * VB2_VERIFY_KERNEL_PREAMBLE_WORKBUF_BYTES bytes. * @return VB2_SUCCESS, or non-zero error code. */ -static int vb2_verify_kernel_vblock(struct vb2_context *ctx, - uint8_t *kbuf, - uint32_t kbuf_size, - const struct vb2_packed_key *kernel_subkey, - const LoadKernelParams *params, - uint32_t min_version, - VbSharedDataKernelPart *shpart, - struct vb2_workbuf *wb) +static vb2_error_t vb2_verify_kernel_vblock( + struct vb2_context *ctx, uint8_t *kbuf, uint32_t kbuf_size, + const struct vb2_packed_key *kernel_subkey, + const LoadKernelParams *params, uint32_t min_version, + VbSharedDataKernelPart *shpart, struct vb2_workbuf *wb) { /* Unpack kernel subkey */ struct vb2_public_key kernel_subkey2; @@ -311,14 +308,11 @@ enum vb2_load_partition_flags { * @param wb Workbuf for data storage * @return VB2_SUCCESS, or non-zero error code. */ -static int vb2_load_partition(struct vb2_context *ctx, - VbExStream_t stream, - const struct vb2_packed_key *kernel_subkey, - uint32_t flags, - LoadKernelParams *params, - uint32_t min_version, - VbSharedDataKernelPart *shpart, - struct vb2_workbuf *wb) +static vb2_error_t vb2_load_partition( + struct vb2_context *ctx, VbExStream_t stream, + const struct vb2_packed_key *kernel_subkey, uint32_t flags, + LoadKernelParams *params, uint32_t min_version, + VbSharedDataKernelPart *shpart, struct vb2_workbuf *wb) { uint64_t read_us = 0, start_ts; struct vb2_workbuf wblocal = *wb; @@ -444,7 +438,7 @@ vb2_error_t LoadKernel(struct vb2_context *ctx, LoadKernelParams *params) uint32_t lowest_version = LOWEST_TPM_VERSION; vb2_error_t retval = VBERROR_UNKNOWN; int recovery = VB2_RECOVERY_LK_UNSPECIFIED; - int rv; + vb2_error_t rv; vb2_workbuf_from_ctx(ctx, &wb); diff --git a/firmware/lib/vboot_ui.c b/firmware/lib/vboot_ui.c index acce8ca9..cbf653d9 100644 --- a/firmware/lib/vboot_ui.c +++ b/firmware/lib/vboot_ui.c @@ -83,7 +83,7 @@ static int VbWantShutdown(struct vb2_context *ctx, uint32_t key) return shutdown_request; } -static uint32_t VbTryUsb(struct vb2_context *ctx) +static vb2_error_t VbTryUsb(struct vb2_context *ctx) { uint32_t retval = VbTryLoadKernel(ctx, VB_DISK_FLAG_REMOVABLE); if (VBERROR_SUCCESS == retval) { @@ -677,7 +677,7 @@ static vb2_error_t vb2_developer_ui(struct vb2_context *ctx) VB2_DEBUG("VbBootDeveloper() - " "user pressed Ctrl+L; Try alt firmware\n"); if (allow_legacy) { - int ret; + vb2_error_t ret; ret = vb2_altfw_ui(ctx); if (ret) @@ -693,7 +693,7 @@ static vb2_error_t vb2_developer_ui(struct vb2_context *ctx) * Only show the vendor data ui if it is tag is settable */ if (ctx->flags & VB2_CONTEXT_VENDOR_DATA_SETTABLE) { - int ret; + vb2_error_t ret; VB2_DEBUG("VbBootDeveloper() - user pressed " "Ctrl+S; Try set vendor data\n"); |