summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/lib/include/vboot_kernel.h34
-rw-r--r--firmware/lib/vboot_ui.c41
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) {