vboot/ui: Always beep when error dialog is shown

Setting error_code always implies we need to beep.

BUG=b:146399181
TEST=Build locally
BRANCH=zork

Signed-off-by: Hsuan Ting Chen <roccochen@chromium.org>
Change-Id: I65d790a63739f36dc1db8e22321adbff26d70893
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2397017
Commit-Queue: Yu-Ping Wu <yupingso@chromium.org>
Reviewed-by: Joel Kitching <kitching@chromium.org>
Reviewed-by: Yu-Ping Wu <yupingso@chromium.org>
diff --git a/firmware/2lib/2ui.c b/firmware/2lib/2ui.c
index 4ddbcef..07254c6 100644
--- a/firmware/2lib/2ui.c
+++ b/firmware/2lib/2ui.c
@@ -80,7 +80,7 @@
 	 * key press clears that error.  Unset the key so that it is
 	 * not processed by other action functions.
 	 */
-	if (ui->key && ui->error_code != VB2_UI_ERROR_NONE) {
+	if (ui->key && ui->error_code) {
 		ui->error_code = VB2_UI_ERROR_NONE;
 		ui->key = 0;
 	}
@@ -335,7 +335,9 @@
 					 ui.disable_timer,
 					 ui.state->current_page,
 					 ui.error_code);
-			if (ui.error_beep) {
+			if (ui.error_beep ||
+			    (ui.error_code &&
+			     prev_error_code != ui.error_code)) {
 				vb2ex_beep(250, 400);
 				ui.error_beep = 0;
 			}
diff --git a/firmware/2lib/2ui_screens.c b/firmware/2lib/2ui_screens.c
index ec5aa08..d0e44ee 100644
--- a/firmware/2lib/2ui_screens.c
+++ b/firmware/2lib/2ui_screens.c
@@ -818,7 +818,6 @@
 	/* Don't allow to-norm if GBB forces dev mode */
 	if (vb2_get_gbb(ui->ctx)->flags & VB2_GBB_FLAG_FORCE_DEV_SWITCH_ON) {
 		VB2_DEBUG("ERROR: to-norm not allowed\n");
-		ui->error_beep = 1;
 		ui->error_code = VB2_UI_ERROR_TO_NORM_NOT_ALLOWED;
 		return vb2_ui_screen_back(ui);
 	}
@@ -905,7 +904,6 @@
 static vb2_error_t developer_select_bootloader_init(struct vb2_ui_context *ui)
 {
 	if (get_menu(ui)->num_items == 0) {
-		ui->error_beep = 1;
 		ui->error_code = VB2_UI_ERROR_NO_BOOTLOADER;
 		return vb2_ui_screen_back(ui);
 	}
@@ -926,14 +924,12 @@
 	    !vb2_dev_boot_allowed(ui->ctx) ||
 	    !vb2_dev_boot_legacy_allowed(ui->ctx)) {
 		VB2_DEBUG("ERROR: Dev mode alternate bootloader not allowed\n");
-		ui->error_beep = 1;
 		ui->error_code = VB2_UI_ERROR_ALTERNATE_BOOT_DISABLED;
 		return VB2_REQUEST_UI_CONTINUE;
 	}
 
 	if (vb2ex_get_bootloader_count() == 0) {
 		VB2_DEBUG("ERROR: No alternate bootloader was found\n");
-		ui->error_beep = 1;
 		ui->error_code = VB2_UI_ERROR_NO_BOOTLOADER;
 		return VB2_REQUEST_UI_CONTINUE;
 	}
@@ -950,7 +946,6 @@
 	VbExLegacy(altfw_num);
 
 	VB2_DEBUG("ERROR: Alternate bootloader failed\n");
-	ui->error_beep = 1;
 	ui->error_code = VB2_UI_ERROR_ALTERNATE_BOOT_FAILED;
 	return VB2_REQUEST_UI_CONTINUE;
 }
@@ -1049,7 +1044,6 @@
 	if (!log_string) {
 		VB2_DEBUG("ERROR: Failed to retrieve storage log message\n");
 		ui->error_code = VB2_UI_ERROR_DIAGNOSTICS;
-		ui->error_beep = 1;
 		return vb2_ui_screen_back(ui);
 	}
 
@@ -1057,7 +1051,6 @@
 	if (ui->state->page_count == 0) {
 		VB2_DEBUG("ERROR: Failed to prepare storage log screen\n");
 		ui->error_code = VB2_UI_ERROR_DIAGNOSTICS;
-		ui->error_beep = 1;
 		return vb2_ui_screen_back(ui);
 	}
 	return log_page_init(ui, DIAGNOSTICS_STORAGE_ITEM_PAGE_DOWN,
@@ -1102,7 +1095,6 @@
 	if ((rv && rv != VB2_ERROR_EX_DIAG_TEST_RUNNING) || !log_string) {
 		VB2_DEBUG("ERROR: Failed to retrieve memory test status\n");
 		ui->error_code = VB2_UI_ERROR_DIAGNOSTICS;
-		ui->error_beep = 1;
 		return vb2_ui_screen_back(ui);
 	}
 
@@ -1111,7 +1103,6 @@
 		VB2_DEBUG("ERROR: Failed to prepare memory log screen, error: "
 			  "%#x\n", rv);
 		ui->error_code = VB2_UI_ERROR_DIAGNOSTICS;
-		ui->error_beep = 1;
 		return vb2_ui_screen_back(ui);
 	}
 	if (ui->state->current_page >= ui->state->page_count)