vboot/ui: Fix to_dev action initialization error

Add an entry storing previous status of physical presence button
to vb2_ui_context and reset it when recovery_to_dev_init is called.

BUG=b:146399181,b:157390248
TEST=make clean && make runtests
BRANCH=none

Signed-off-by: Hsuan Ting Chen <roccochen@chromium.org>
Change-Id: Ia0294a189713f1f99db7309937ea80ff90849bd8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2214457
Reviewed-by: Yu-Ping Wu <yupingso@chromium.org>
Commit-Queue: Yu-Ping Wu <yupingso@chromium.org>
diff --git a/firmware/2lib/2ui_screens.c b/firmware/2lib/2ui_screens.c
index c4465a4..90a1020 100644
--- a/firmware/2lib/2ui_screens.c
+++ b/firmware/2lib/2ui_screens.c
@@ -147,12 +147,13 @@
 		ui->state.selected_item = RECOVERY_TO_DEV_ITEM_CANCEL;
 	}
 
+	ui->physical_presence_button_pressed = 0;
+
 	return VB2_REQUEST_UI_CONTINUE;
 }
 
 vb2_error_t vb2_ui_recovery_to_dev_action(struct vb2_ui_context *ui)
 {
-	static int pressed_last;
 	int pressed;
 
 	if (ui->state.screen->id != VB2_SCREEN_RECOVERY_TO_DEV) {
@@ -180,10 +181,10 @@
 		if (pressed) {
 			VB2_DEBUG("Physical presence button pressed, "
 				 "awaiting release\n");
-			pressed_last = 1;
+			ui->physical_presence_button_pressed = 1;
 			return VB2_REQUEST_UI_CONTINUE;
 		}
-		if (!pressed_last)
+		if (!ui->physical_presence_button_pressed)
 			return VB2_REQUEST_UI_CONTINUE;
 		VB2_DEBUG("Physical presence button released\n");
 	}
diff --git a/firmware/2lib/include/2ui.h b/firmware/2lib/include/2ui.h
index 0d4df42..73dd1c7 100644
--- a/firmware/2lib/include/2ui.h
+++ b/firmware/2lib/include/2ui.h
@@ -70,6 +70,9 @@
 
 	/* For manual recovery. */
 	vb2_error_t recovery_rv;
+
+	/* For to_dev transition flow. */
+	int physical_presence_button_pressed;
 };
 
 vb2_error_t vb2_ui_change_screen(struct vb2_ui_context *ui, enum vb2_screen id);