vboot/ui: decouple error beep from error message

Some error such as VB2_UI_ERROR_DEV_EXTERNAL_BOOT_FAILED only requires a
beep sound to notify the user. No dialog box will be shown for these
errors.

Instead of defining them in the vb2_ui_error enum and ignore them in
vb2ex_display_ui() in depthcharge, add a new field 'error_beep' to
vb2_ui_context and use it for playing error beep sound in the UI loop.
Then these beep-only errors can be removed from the enum.

Also remove VB2_UI_ERROR_DEV_INTERNAL_NOT_ALLOWED because it is not used
everywhere.

BRANCH=puff
BUG=b:146399181, b:161375587
TEST=emerge-puff depthcharge
TEST=b/161375587 is not reproducible

Cq-Depend: chromium:2299925
Change-Id: Ia90d1c8a164334d4cfec84281722eb6f2623b111
Signed-off-by: Yu-Ping Wu <yupingso@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2299968
Reviewed-by: Joel Kitching <kitching@chromium.org>
diff --git a/firmware/2lib/2ui.c b/firmware/2lib/2ui.c
index 23b7b0d..fea3b4a 100644
--- a/firmware/2lib/2ui.c
+++ b/firmware/2lib/2ui.c
@@ -327,13 +327,10 @@
 					 ui.state->disabled_item_mask,
 					 ui.disable_timer,
 					 ui.error_code);
-			/*
-			 * Only beep if we're transitioning from no
-			 * error to an error.
-			 */
-			if (prev_error_code == VB2_UI_ERROR_NONE &&
-			    ui.error_code != VB2_UI_ERROR_NONE)
+			if (ui.error_beep) {
 				vb2ex_beep(250, 400);
+				ui.error_beep = 0;
+			}
 
 			/* Update prev variables. */
 			memcpy(&prev_state, ui.state, sizeof(*ui.state));
diff --git a/firmware/2lib/2ui_screens.c b/firmware/2lib/2ui_screens.c
index 97c9b5e..ab15a2b 100644
--- a/firmware/2lib/2ui_screens.c
+++ b/firmware/2lib/2ui_screens.c
@@ -490,7 +490,7 @@
 	    !vb2_dev_boot_allowed(ui->ctx) ||
 	    !vb2_dev_boot_external_allowed(ui->ctx)) {
 		VB2_DEBUG("ERROR: Dev mode external boot not allowed\n");
-		ui->error_code = VB2_UI_ERROR_DEV_EXTERNAL_NOT_ALLOWED;
+		ui->error_beep = 1;
 		return VB2_REQUEST_UI_CONTINUE;
 	}
 
@@ -501,7 +501,7 @@
 		if (ui->state->screen->id !=
 		    VB2_SCREEN_DEVELOPER_BOOT_EXTERNAL) {
 			VB2_DEBUG("No external disk found\n");
-			ui->error_code = VB2_UI_ERROR_DEV_EXTERNAL_BOOT_FAILED;
+			ui->error_beep = 1;
 		}
 		return vb2_ui_screen_change(
 			ui, VB2_SCREEN_DEVELOPER_BOOT_EXTERNAL);
@@ -509,7 +509,7 @@
 		if (ui->state->screen->id !=
 		    VB2_SCREEN_DEVELOPER_INVALID_DISK) {
 			VB2_DEBUG("Invalid external disk: %#x\n", rv);
-			ui->error_code = VB2_UI_ERROR_DEV_EXTERNAL_BOOT_FAILED;
+			ui->error_beep = 1;
 		}
 		return vb2_ui_screen_change(
 			ui, VB2_SCREEN_DEVELOPER_INVALID_DISK);
diff --git a/firmware/2lib/include/2api.h b/firmware/2lib/include/2api.h
index e001230..b6c9bea 100644
--- a/firmware/2lib/include/2api.h
+++ b/firmware/2lib/include/2api.h
@@ -1297,12 +1297,6 @@
 	VB2_UI_ERROR_NONE = 0,
 	/* Dev mode already enabled */
 	VB2_UI_ERROR_DEV_MODE_ALREADY_ENABLED,
-	/* Dev mode internal boot not allowed */
-	VB2_UI_ERROR_DEV_INTERNAL_NOT_ALLOWED,
-	/* Dev mode external boot not allowed */
-	VB2_UI_ERROR_DEV_EXTERNAL_NOT_ALLOWED,
-	/* Dev mode external boot failed */
-	VB2_UI_ERROR_DEV_EXTERNAL_BOOT_FAILED,
 };
 
 /**
diff --git a/firmware/2lib/include/2ui.h b/firmware/2lib/include/2ui.h
index 35dddb8..fa8c66a 100644
--- a/firmware/2lib/include/2ui.h
+++ b/firmware/2lib/include/2ui.h
@@ -89,8 +89,11 @@
 	/* For language selection screen. */
 	struct vb2_menu language_menu;
 
+	/* For error beep sound. */
+	int error_beep;
+
 	/* For displaying error messages. */
-  	enum vb2_ui_error error_code;
+	enum vb2_ui_error error_code;
 };
 
 vb2_error_t vb2_ui_developer_mode_boot_internal_action(