summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Crews <ncrews@google.com>2018-11-09 15:51:17 -0700
committerchrome-bot <chrome-bot@chromium.org>2018-12-13 19:27:59 -0800
commitf07ea5490bab8a2972e3b6d77ac67ca7cbf5cad0 (patch)
treed20ca2ad75085fe88d0b969428a992ee4efc0811
parent48d08d76c3cee2fb4ea3a7d965c64550d02f3bbd (diff)
downloadvboot-f07ea5490bab8a2972e3b6d77ac67ca7cbf5cad0.tar.gz
vboot_reference: Merge error beeping, printing, and logging
Added a vb2_error_notify() function that bundles a log message, screen notification message, beep, and flash into one function, since callers were often calling these three things separately. BUG=chromium:899762 TEST=Image still builds and runs on an Aleena, function works on at least one of the calls, the others are harder to test. TEST=make runtests BRANCH=none Change-Id: I82224f8ffa1c326c5e7293a2c00db4dc5d80bf3a Reviewed-on: https://chromium-review.googlesource.com/1330013 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Eugene Hermann <yherman@google.com> Reviewed-by: Nick Crews <ncrews@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
-rw-r--r--firmware/lib/include/vboot_ui_common.h12
-rw-r--r--firmware/lib/vboot_ui.c40
-rw-r--r--firmware/lib/vboot_ui_common.c26
-rw-r--r--firmware/lib/vboot_ui_menu.c54
4 files changed, 84 insertions, 48 deletions
diff --git a/firmware/lib/include/vboot_ui_common.h b/firmware/lib/include/vboot_ui_common.h
index 30ade5a6..cc130a67 100644
--- a/firmware/lib/include/vboot_ui_common.h
+++ b/firmware/lib/include/vboot_ui_common.h
@@ -19,6 +19,18 @@ enum vb2_beep_type {
void vb2_error_beep(enum vb2_beep_type beep);
/**
+ * Prints a message to screen, logs a possibly different message to log,
+ * and beeps to notify user.
+ *
+ * @print_msg Display message. NULL message will be ignored.
+ * @log_msg Log message. If NULL, uses @print_msg (if that's not NULL).
+ * @beep Type of beep sound.
+ */
+void vb2_error_notify(const char *print_msg,
+ const char *log_msg,
+ enum vb2_beep_type beep);
+
+/**
* Run alternative firmware if allowed
*
* This will only return if it is not allowed, or the bootloader fails to
diff --git a/firmware/lib/vboot_ui.c b/firmware/lib/vboot_ui.c
index 71a7ceb3..a866e10b 100644
--- a/firmware/lib/vboot_ui.c
+++ b/firmware/lib/vboot_ui.c
@@ -79,8 +79,9 @@ uint32_t VbTryUsb(struct vb2_context *ctx)
if (VBERROR_SUCCESS == retval) {
VB2_DEBUG("VbBootDeveloper() - booting USB\n");
} else {
- VB2_DEBUG("VbBootDeveloper() - no kernel found on USB\n");
- vb2_error_beep(VB_BEEP_FAILED);
+ vb2_error_notify("Could not boot from USB",
+ "VbBootDeveloper() - no kernel found on USB\n",
+ VB_BEEP_FAILED);
/*
* Clear recovery requests from failed
* kernel loading, so that powering off
@@ -119,7 +120,11 @@ int VbUserConfirms(struct vb2_context *ctx, uint32_t confirm_flags)
*/
if (confirm_flags & VB_CONFIRM_MUST_TRUST_KEYBOARD &&
!(key_flags & VB_KEY_FLAG_TRUSTED_KEYBOARD)) {
- vb2_error_beep(VB_BEEP_NOT_ALLOWED);
+ vb2_error_notify("Please use internal keyboard "
+ "to confirm\n",
+ "VbUserConfirms() - "
+ "Trusted keyboard is requierd\n",
+ VB_BEEP_NOT_ALLOWED);
break;
}
VB2_DEBUG("Yes (1)\n");
@@ -329,12 +334,11 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx)
* TONORM won't work (only for
* non-shipping devices).
*/
- VB2_DEBUG("TONORM rejected by "
- "FORCE_DEV_SWITCH_ON\n");
- VbExDisplayDebugInfo(
+ vb2_error_notify(
"WARNING: TONORM prohibited by "
- "GBB FORCE_DEV_SWITCH_ON.\n\n");
- vb2_error_beep(VB_BEEP_NOT_ALLOWED);
+ "GBB FORCE_DEV_SWITCH_ON.\n",
+ NULL,
+ VB_BEEP_NOT_ALLOWED);
break;
}
VbDisplayScreen(ctx,
@@ -401,14 +405,14 @@ VbError_t vb2_developer_ui(struct vb2_context *ctx)
VB2_DEBUG("VbBootDeveloper() - "
"user pressed Ctrl+U; try USB\n");
if (!allow_usb) {
- VB2_DEBUG("VbBootDeveloper() - "
- "USB booting is disabled\n");
- VbExDisplayDebugInfo(
+ vb2_error_notify(
"WARNING: Booting from external media "
"(USB/SD) has not been enabled. Refer "
"to the developer-mode documentation "
- "for details.\n");
- vb2_error_beep(VB_BEEP_NOT_ALLOWED);
+ "for details.\n",
+ "VbBootDeveloper() - "
+ "USB booting is disabled\n",
+ VB_BEEP_NOT_ALLOWED);
} else {
/*
* Clear the screen to show we get the Ctrl+U
@@ -479,6 +483,10 @@ static VbError_t recovery_ui(struct vb2_context *ctx)
uint32_t retval;
uint32_t key;
int i;
+ const char release_button_msg[] =
+ "Release the recovery button and try again\n";
+ const char recovery_pressed_msg[] =
+ "^D but recovery switch is pressed\n";
VB2_DEBUG("VbBootRecovery() start\n");
@@ -562,9 +570,9 @@ static VbError_t recovery_ui(struct vb2_context *ctx)
* any case we don't like this. Beep
* and ignore.
*/
- VB2_DEBUG("^D but rec switch "
- "is pressed\n");
- vb2_error_beep(VB_BEEP_NOT_ALLOWED);
+ vb2_error_notify(release_button_msg,
+ recovery_pressed_msg,
+ VB_BEEP_NOT_ALLOWED);
continue;
}
diff --git a/firmware/lib/vboot_ui_common.c b/firmware/lib/vboot_ui_common.c
index df1615d1..af9c4951 100644
--- a/firmware/lib/vboot_ui_common.c
+++ b/firmware/lib/vboot_ui_common.c
@@ -14,7 +14,7 @@
#include "vboot_api.h"
#include "vboot_ui_common.h"
-/* Two short beeps to notify the user that attempted action was disallowed. */
+/* One or two beeps to notify that attempted action was disallowed. */
void vb2_error_beep(enum vb2_beep_type beep)
{
switch (beep) {
@@ -30,13 +30,29 @@ void vb2_error_beep(enum vb2_beep_type beep)
}
}
+void vb2_error_notify(const char *print_msg,
+ const char *log_msg,
+ enum vb2_beep_type beep)
+{
+ if (print_msg)
+ VbExDisplayDebugInfo(print_msg);
+ if (!log_msg)
+ log_msg = print_msg;
+ if (log_msg)
+ VB2_DEBUG(log_msg);
+ vb2_error_beep(beep);
+}
+
void vb2_run_altfw(int altfw_num)
{
- if (RollbackKernelLock(0))
- VB2_DEBUG("Error locking kernel versions on legacy boot.\n");
- else
+ if (RollbackKernelLock(0)) {
+ vb2_error_notify("Error locking kernel versions on legacy "
+ "boot.\n", NULL, VB_BEEP_FAILED);
+ } else {
VbExLegacy(altfw_num); /* will not return if found */
- vb2_error_beep(VB_BEEP_FAILED);
+ vb2_error_notify("Legacy boot failed. Missing BIOS?\n", NULL,
+ VB_BEEP_FAILED);
+ }
}
void vb2_error_no_altfw(void)
diff --git a/firmware/lib/vboot_ui_menu.c b/firmware/lib/vboot_ui_menu.c
index e547f38a..c0246462 100644
--- a/firmware/lib/vboot_ui_menu.c
+++ b/firmware/lib/vboot_ui_menu.c
@@ -121,7 +121,8 @@ static VbError_t boot_disk_action(struct vb2_context *ctx)
{
if (disable_dev_boot) {
vb2_flash_screen(ctx);
- vb2_error_beep(VB_BEEP_NOT_ALLOWED);
+ vb2_error_notify("Developer mode disabled\n", NULL,
+ VB_BEEP_NOT_ALLOWED);
return VBERROR_KEEP_LOOPING;
}
VB2_DEBUG("trying fixed disk\n");
@@ -133,24 +134,23 @@ static VbError_t boot_legacy_action(struct vb2_context *ctx)
{
if (disable_dev_boot) {
vb2_flash_screen(ctx);
- vb2_error_beep(VB_BEEP_NOT_ALLOWED);
+ vb2_error_notify("Developer mode disabled\n", NULL,
+ VB_BEEP_NOT_ALLOWED);
return VBERROR_KEEP_LOOPING;
}
if (!altfw_allowed) {
vb2_flash_screen(ctx);
- VB2_DEBUG("Legacy boot is disabled\n");
- VbExDisplayDebugInfo("WARNING: Booting legacy BIOS has not "
- "been enabled. Refer to the developer"
- "-mode documentation for details.\n");
- vb2_error_beep(VB_BEEP_NOT_ALLOWED);
+ vb2_error_notify("WARNING: Booting legacy BIOS has not "
+ "been enabled. Refer to the developer"
+ "-mode documentation for details.\n",
+ "Legacy boot is disabled\n",
+ VB_BEEP_NOT_ALLOWED);
return VBERROR_KEEP_LOOPING;
}
vb2_run_altfw(0);
vb2_flash_screen(ctx);
- VB2_DEBUG(no_legacy);
- VbExDisplayDebugInfo(no_legacy);
return VBERROR_KEEP_LOOPING;
}
@@ -161,7 +161,8 @@ static VbError_t boot_usb_action(struct vb2_context *ctx)
if (disable_dev_boot) {
vb2_flash_screen(ctx);
- vb2_error_beep(VB_BEEP_NOT_ALLOWED);
+ vb2_error_notify("Developer mode disabled\n", NULL,
+ VB_BEEP_NOT_ALLOWED);
return VBERROR_KEEP_LOOPING;
}
@@ -169,12 +170,12 @@ static VbError_t boot_usb_action(struct vb2_context *ctx)
!(vb2_get_sd(ctx)->gbb_flags & VB2_GBB_FLAG_FORCE_DEV_BOOT_USB) &&
!(vb2_get_fwmp_flags() & FWMP_DEV_ENABLE_USB)) {
vb2_flash_screen(ctx);
- VB2_DEBUG("USB booting is disabled\n");
- VbExDisplayDebugInfo("WARNING: Booting from external media "
- "(USB/SD) has not been enabled. Refer "
- "to the developer-mode documentation "
- "for details.\n");
- vb2_error_beep(VB_BEEP_NOT_ALLOWED);
+ vb2_error_notify("WARNING: Booting from external media "
+ "(USB/SD) has not been enabled. Refer "
+ "to the developer-mode documentation "
+ "for details.\n",
+ "USB booting is disabled\n",
+ VB_BEEP_NOT_ALLOWED);
return VBERROR_KEEP_LOOPING;
}
@@ -186,9 +187,7 @@ static VbError_t boot_usb_action(struct vb2_context *ctx)
/* Loading kernel failed. Clear recovery request from that. */
vb2_nv_set(ctx, VB2_NV_RECOVERY_REQUEST, VB2_RECOVERY_NOT_REQUESTED);
vb2_flash_screen(ctx);
- VB2_DEBUG(no_kernel);
- VbExDisplayDebugInfo(no_kernel);
- vb2_error_beep(VB_BEEP_FAILED);
+ vb2_error_notify(no_kernel, NULL, VB_BEEP_FAILED);
return VBERROR_KEEP_LOOPING;
}
@@ -252,9 +251,7 @@ static VbError_t enter_to_dev_menu(struct vb2_context *ctx)
"WARNING: TODEV rejected, developer mode is already on.\n";
if (vb2_get_sd(ctx)->vbsd->flags & VBSD_BOOT_DEV_SWITCH_ON) {
vb2_flash_screen(ctx);
- VB2_DEBUG(dev_already_on);
- VbExDisplayDebugInfo(dev_already_on);
- vb2_error_beep(VB_BEEP_NOT_ALLOWED);
+ vb2_error_notify(dev_already_on, NULL, VB_BEEP_NOT_ALLOWED);
return VBERROR_KEEP_LOOPING;
}
vb2_change_menu(VB_MENU_TO_DEV, VB_TO_DEV_CANCEL);
@@ -368,10 +365,9 @@ static VbError_t to_norm_action(struct vb2_context *ctx)
{
if (vb2_get_sd(ctx)->gbb_flags & VB2_GBB_FLAG_FORCE_DEV_SWITCH_ON) {
vb2_flash_screen(ctx);
- VB2_DEBUG("TONORM rejected by FORCE_DEV_SWITCH_ON\n");
- VbExDisplayDebugInfo("WARNING: TONORM prohibited by "
- "GBB FORCE_DEV_SWITCH_ON.\n\n");
- vb2_error_beep(VB_BEEP_NOT_ALLOWED);
+ vb2_error_notify("WARNING: TONORM prohibited by "
+ "GBB FORCE_DEV_SWITCH_ON.\n", NULL,
+ VB_BEEP_NOT_ALLOWED);
return VBERROR_KEEP_LOOPING;
}
@@ -449,7 +445,11 @@ static VbError_t vb2_handle_menu_input(struct vb2_context *ctx,
if (current_menu == VB_MENU_TO_DEV &&
!(key_flags & VB_KEY_FLAG_TRUSTED_KEYBOARD)) {
vb2_flash_screen(ctx);
- vb2_error_beep(VB_BEEP_NOT_ALLOWED);
+ vb2_error_notify("Please use the on-device volume "
+ "buttons to navigate\n",
+ "vb2_handle_menu_input() - Untrusted "
+ "(USB keyboard) input disabled\n",
+ VB_BEEP_NOT_ALLOWED);
break;
}