SANTHOSH JANARDHANA HASSAN has uploaded this change for review.

View Change

google/mistral: Support triggering Recovery/FDR.

Implement triggering factory data reset and recovery mechanism
based on Recovery/FDR switch(GPIO77) value.

Change-Id: Ifdbd696ee3fd9f073cc44a49ad341cad7e33845e
Signed-off-by: Santhosh Hassan <sahassan@google.com>
---
M src/mainboard/google/mistral/Kconfig
A src/mainboard/google/mistral/board.h
M src/mainboard/google/mistral/chromeos.c
M src/mainboard/google/mistral/verstage.c
4 files changed, 142 insertions(+), 13 deletions(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/73/31173/1
diff --git a/src/mainboard/google/mistral/Kconfig b/src/mainboard/google/mistral/Kconfig
index 5e97bb6..f28a382 100644
--- a/src/mainboard/google/mistral/Kconfig
+++ b/src/mainboard/google/mistral/Kconfig
@@ -23,6 +23,7 @@
select GBB_FLAG_DEV_SCREEN_SHORT_DELAY
select GBB_FLAG_FORCE_DEV_SWITCH_ON
select GBB_FLAG_FORCE_MANUAL_RECOVERY
+ select VBOOT_WIPEOUT_SUPPORTED

config MAINBOARD_DIR
string
diff --git a/src/mainboard/google/mistral/board.h b/src/mainboard/google/mistral/board.h
new file mode 100644
index 0000000..2e23ce3
--- /dev/null
+++ b/src/mainboard/google/mistral/board.h
@@ -0,0 +1,29 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2018, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __COREBOOT_SRC_MAINBOARD_GOOGLE_MISTRAL_BOARD_H
+#define __COREBOOT_SRC_MAINBOARD_GOOGLE_MISTRAL_BOARD_H
+
+#include <gpio.h>
+#include <soc/gpio.h>
+
+
+#define GPIO_H1_AP_INT GPIO(53)
+#define GPIO_WP_STATE GPIO(54)
+#define GPIO_REC_STATE GPIO(77)
+
+void setup_chromeos_gpios(void);
+
+#endif /* ! __COREBOOT_SRC_MAINBOARD_GOOGLE_MISTRAL_BOARD_H */
diff --git a/src/mainboard/google/mistral/chromeos.c b/src/mainboard/google/mistral/chromeos.c
index ba0b1da..0405c4e 100644
--- a/src/mainboard/google/mistral/chromeos.c
+++ b/src/mainboard/google/mistral/chromeos.c
@@ -14,11 +14,18 @@
*/

#include <boot/coreboot_tables.h>
-#include <gpio.h>
#include <security/tpm/tis.h>
-#include <soc/gpio.h>
+#include <bootmode.h>
+#include <timer.h>
+#include <console/console.h>
+#include "board.h"

-#define GPIO_H1_AP_INT GPIO(53)
+void setup_chromeos_gpios(void)
+{
+ gpio_input_pullup(GPIO_H1_AP_INT);
+ gpio_input(GPIO_WP_STATE);
+ gpio_input(GPIO_REC_STATE);
+}

void fill_lb_gpios(struct lb_gpios *gpios)
{
@@ -27,9 +34,109 @@
{GPIO_H1_AP_INT.addr, ACTIVE_LOW, gpio_get(GPIO_H1_AP_INT),
"TPM interrupt"},
};
+#endif
+ struct lb_gpio chromeos_gpios[] = {
+ {GPIO_REC_STATE.addr, ACTIVE_LOW,
+ gpio_get(GPIO_REC_STATE), "recovery"},
+ {GPIO_WP_STATE.addr, ACTIVE_LOW,
+ gpio_get(GPIO_WP_STATE), "write protect"},
+ {-1, ACTIVE_LOW, 1, "power"},
+ {-1, ACTIVE_LOW, 0, "lid"},
+ };

lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
-#endif
+}
+
+#define WIPEOUT_MODE_DELAY_MS (8 * 1000)
+#define RECOVERY_MODE_EXTRA_DELAY_MS (8 * 1000)
+
+/*
+ * The recovery switch: it needs to be pressed for a
+ * certain duration at startup to signal different requests:
+ *
+ * - keeping it pressed for 8 to 16 seconds after startup signals the need for
+ * factory reset (wipeout);
+ * - keeping it pressed for longer than 16 seconds signals the need for Chrome
+ * OS recovery.
+ *
+ * The state is read once and cached for following inquiries. The below enum
+ * lists possible states.
+ */
+enum switch_state {
+ not_probed = -1,
+ no_req,
+ recovery_req,
+ wipeout_req
+};
+
+static enum switch_state get_rec_sw_state(void)
+{
+ struct stopwatch sw;
+ int sampled_value;
+ gpio_t rec_sw;
+ static enum switch_state saved_state = not_probed;
+
+ if (saved_state != not_probed)
+ return saved_state;
+
+ rec_sw = GPIO_REC_STATE;
+ sampled_value = !gpio_get(rec_sw);
+
+ if (!sampled_value) {
+ saved_state = no_req;
+ //display_pattern(WWR_NORMAL_BOOT);
+ return saved_state;
+ }
+
+ //display_pattern(WWR_RECOVERY_PUSHED);
+ printk(BIOS_INFO, "recovery button pressed\n");
+
+ stopwatch_init_msecs_expire(&sw, WIPEOUT_MODE_DELAY_MS);
+
+ do {
+ sampled_value = !gpio_get(rec_sw);
+ if (!sampled_value)
+ break;
+ } while (!stopwatch_expired(&sw));
+
+ if (sampled_value) {
+ //display_pattern(WWR_WIPEOUT_REQUEST);
+ printk(BIOS_INFO, "wipeout requested, checking recovery\n");
+ stopwatch_init_msecs_expire(&sw, RECOVERY_MODE_EXTRA_DELAY_MS);
+ do {
+ sampled_value = !gpio_get(rec_sw);
+ if (!sampled_value)
+ break;
+ } while (!stopwatch_expired(&sw));
+
+ if (sampled_value) {
+ saved_state = recovery_req;
+ //display_pattern(WWR_RECOVERY_REQUEST);
+ printk(BIOS_INFO, "recovery requested\n");
+ } else {
+ saved_state = wipeout_req;
+ }
+ } else {
+ saved_state = no_req;
+ //display_pattern(WWR_NORMAL_BOOT);
+ }
+
+ return saved_state;
+}
+
+int get_recovery_mode_switch(void)
+{
+ return get_rec_sw_state() == recovery_req;
+}
+
+int get_wipeout_mode_switch(void)
+{
+ return get_rec_sw_state() == wipeout_req;
+}
+
+int get_write_protect_state(void)
+{
+ return !gpio_get(GPIO_WP_STATE);
}

#if 0
diff --git a/src/mainboard/google/mistral/verstage.c b/src/mainboard/google/mistral/verstage.c
index 7ea21c7..a63f61e 100644
--- a/src/mainboard/google/mistral/verstage.c
+++ b/src/mainboard/google/mistral/verstage.c
@@ -15,18 +15,10 @@
*/

#include <console/console.h>
-#include <gpio.h>
#include <security/vboot/vboot_common.h>
#include <spi-generic.h>
#include <soc/clock.h>
-#include <soc/gpio.h>
-
-#define GPIO_H1_AP_INT GPIO(53)
-
-static void setup_chromeos_gpios(void)
-{
- gpio_input_pullup(GPIO_H1_AP_INT);
-}
+#include "board.h"

void verstage_mainboard_init(void)
{

To view, visit change 31173. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Ifdbd696ee3fd9f073cc44a49ad341cad7e33845e
Gerrit-Change-Number: 31173
Gerrit-PatchSet: 1
Gerrit-Owner: SANTHOSH JANARDHANA HASSAN <sahassan@google.com>
Gerrit-MessageType: newchange