diff options
author | Simon Glass <sjg@chromium.org> | 2018-10-16 03:50:10 -0600 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-10-19 08:58:00 -0700 |
commit | 7fb621f3f8432dd3f171c9477f8940574142c76b (patch) | |
tree | 3c56d4ec45d2f1dc4710526aff5b72908e2c99f4 | |
parent | 47fb4ae31dd10fe004e52068c3624849c01b0684 (diff) | |
download | vboot-7fb621f3f8432dd3f171c9477f8940574142c76b.tar.gz |
Split out functions which handle alternative firmware
At present we have all the logic for this feature in VbTryLegacy(). In
preparation for adding a new menu for alternative firmware, split the
logic into two pieces: preparing to start alternative firware, and
cleaning up afterwards if nothing booted.
Also export these functions so that they can be used by the detachable
UI.
BUG=chromium:837018
BRANCH=none
TEST=FEATURES=test emerge-grunt --nodeps vboot_reference
Change-Id: I560634ebb03a7f02a488defa32b83e51001d018e
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1286219
Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r-- | firmware/lib/include/vboot_kernel.h | 34 | ||||
-rw-r--r-- | firmware/lib/vboot_ui.c | 41 |
2 files changed, 58 insertions, 17 deletions
diff --git a/firmware/lib/include/vboot_kernel.h b/firmware/lib/include/vboot_kernel.h index c3c4585b..15c27101 100644 --- a/firmware/lib/include/vboot_kernel.h +++ b/firmware/lib/include/vboot_kernel.h @@ -88,4 +88,38 @@ uint32_t vb2_get_fwmp_flags(void); */ void vb2_nv_commit(struct vb2_context *ctx); +/** + * Prepare to start a bootloader + * + * Get ready to jump into a bootloader if allowed, calling RollbackKernelLock(). + * + * @param allowed 1 if allowed, 0 if not allowed (in which case this function + * prints a debug error) + * @return 0 if allowed, -1 if not allowed + * + */ +int vb2_prepare_alt_fw(int allowed); + +/** + * Tidy up after failing to start a bootloader + * + * This beeps twice to indicate failure + */ +void vb2_exit_altfw(void); + +/** + * Jump to a bootloader if possible + * + * This calls vb2_prepare_alt_fw() to check the operation is permitted. If it + * is, then it jumps to the selected bootloader and execution continues there, + * never returning. + * + * If the operation is not permitted, or it is permitted but the bootloader + * cannot be found, it calls vb2_exit_altfw() and returns. + * + * @allowed 1 if allowed, 0 if not allowed + * @altfw_num Number of bootloader to start (0=any, 1=first, etc.) + */ +void vb2_try_alt_fw(int allowed, int altfw_num); + #endif /* VBOOT_REFERENCE_VBOOT_KERNEL_H_ */ diff --git a/firmware/lib/vboot_ui.c b/firmware/lib/vboot_ui.c index 289e0009..0c4c03dc 100644 --- a/firmware/lib/vboot_ui.c +++ b/firmware/lib/vboot_ui.c @@ -72,29 +72,36 @@ static int VbWantShutdown(struct vb2_context *ctx, uint32_t key) return !!shutdown_request; } -/** - * Call out to firmware to boot a numbered boot loader - * - * Provided that it is permitted, this function starts up the numbered boot - * loader. - * - * @param altfw_num Boot loader number to boot (0=any, 1=first, etc.) - */ -static void VbTryLegacy(int allowed, int altfw_num) +int vb2_prepare_alt_fw(int allowed) { - if (!allowed) + if (!allowed) { VB2_DEBUG("VbBootDeveloper() - Legacy boot is disabled\n"); - else if (0 != RollbackKernelLock(0)) + VbExDisplayDebugInfo("WARNING: Booting legacy BIOS has not " + "been enabled. Refer to the developer" + "-mode documentation for details.\n"); + return -1; + } else if (0 != RollbackKernelLock(0)) { VB2_DEBUG("Error locking kernel versions on legacy boot.\n"); - else - VbExLegacy(altfw_num); /* will not return if successful */ + return -1; + } - /* If legacy boot fails, beep and return to calling UI loop. */ + return 0; +} + +void vb2_exit_altfw(void) +{ VbExBeep(120, 400); VbExSleepMs(120); VbExBeep(120, 400); } +void vb2_try_alt_fw(int allowed, int altfw_num) +{ + if (!vb2_prepare_alt_fw(allowed)) + VbExLegacy(altfw_num); /* will not return if found */ + vb2_exit_altfw(); +} + uint32_t VbTryUsb(struct vb2_context *ctx) { uint32_t retval = VbTryLoadKernel(ctx, VB_DISK_FLAG_REMOVABLE); @@ -348,7 +355,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx) case 0x0c: VB2_DEBUG("VbBootDeveloper() - " "user pressed Ctrl+L; Try legacy boot\n"); - VbTryLegacy(allow_legacy, 0); + vb2_try_alt_fw(allow_legacy, 0); break; case VB_KEY_CTRL_ENTER: @@ -390,7 +397,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx) VB2_DEBUG("VbBootDeveloper() - " "user pressed key '%c': Boot alternative " "firmware\n", key); - VbTryLegacy(allow_legacy, key - '0'); + vb2_try_alt_fw(allow_legacy, key - '0'); break; default: VB2_DEBUG("VbBootDeveloper() - pressed key %d\n", key); @@ -406,7 +413,7 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx) /* If defaulting to legacy boot, try that unless Ctrl+D was pressed */ if (use_legacy && !ctrl_d_pressed) { VB2_DEBUG("VbBootDeveloper() - defaulting to legacy\n"); - VbTryLegacy(allow_legacy, 0); + vb2_try_alt_fw(allow_legacy, 0); } if ((use_usb && !ctrl_d_pressed) && allow_usb) { |