summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ec/google/chromeec/ec.c34
-rw-r--r--src/ec/google/chromeec/ec.h1
-rw-r--r--src/mainboard/google/pit/chromeos.c4
-rw-r--r--src/vendorcode/google/chromeos/Makefile.inc7
-rw-r--r--src/vendorcode/google/chromeos/vbnv_cmos.c (renamed from src/vendorcode/google/chromeos/vbnv.c)0
-rw-r--r--src/vendorcode/google/chromeos/vbnv_ec.c140
6 files changed, 181 insertions, 5 deletions
diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c
index ab4db545fc..24f9693735 100644
--- a/src/ec/google/chromeec/ec.c
+++ b/src/ec/google/chromeec/ec.c
@@ -18,6 +18,7 @@
*/
#include <stdint.h>
+#include <string.h>
#include <console/console.h>
#include <bootmode.h>
#include <arch/io.h>
@@ -26,7 +27,6 @@
#include <reset.h>
#include <elog.h>
#include <stdlib.h>
-#include <string.h>
#include "chip.h"
#include "ec.h"
@@ -154,6 +154,38 @@ u16 google_chromeec_get_board_version(void)
return board_v.board_version;
}
+
+int google_chromeec_vbnv_context(int is_read, uint8_t *data, int len)
+{
+ struct chromeec_command cec_cmd;
+ struct ec_params_vbnvcontext cmd_vbnvcontext;
+ struct ec_response_vbnvcontext rsp_vbnvcontext;
+
+ if (len != EC_VBNV_BLOCK_SIZE)
+ return -1;
+
+
+ cec_cmd.cmd_code = EC_CMD_VBNV_CONTEXT;
+ cec_cmd.cmd_version = EC_VER_VBNV_CONTEXT;
+ cec_cmd.cmd_data_in = &cmd_vbnvcontext;
+ cec_cmd.cmd_data_out = &rsp_vbnvcontext;
+ cec_cmd.cmd_size_in = sizeof(cmd_vbnvcontext);
+ cec_cmd.cmd_size_out = sizeof(rsp_vbnvcontext);
+
+ cmd_vbnvcontext.op = is_read ? EC_VBNV_CONTEXT_OP_READ :
+ EC_VBNV_CONTEXT_OP_WRITE;
+
+ if (!is_read)
+ memcpy(&cmd_vbnvcontext.block, data, EC_VBNV_BLOCK_SIZE);
+
+ google_chromeec_command(&cec_cmd);
+
+ if (is_read)
+ memcpy(data, &rsp_vbnvcontext.block, EC_VBNV_BLOCK_SIZE);
+
+ return cec_cmd.cmd_code;
+}
+
#endif /* ! __SMM__ */
#ifndef __PRE_RAM__
diff --git a/src/ec/google/chromeec/ec.h b/src/ec/google/chromeec/ec.h
index d033bab73a..cf77b692f7 100644
--- a/src/ec/google/chromeec/ec.h
+++ b/src/ec/google/chromeec/ec.h
@@ -46,6 +46,7 @@ u32 google_chromeec_get_events_b(void);
int google_chromeec_kbbacklight(int percent);
void google_chromeec_post(u8 postcode);
void google_chromeec_log_events(u32 mask);
+int google_chromeec_vbnv_context(int is_read, uint8_t *data, int len);
enum usb_charge_mode {
USB_CHARGE_MODE_DISABLED,
diff --git a/src/mainboard/google/pit/chromeos.c b/src/mainboard/google/pit/chromeos.c
index 28ec2b5c01..c2db165834 100644
--- a/src/mainboard/google/pit/chromeos.c
+++ b/src/mainboard/google/pit/chromeos.c
@@ -95,7 +95,7 @@ int get_recovery_mode_switch(void)
EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEYBOARD_RECOVERY));
}
-int get_recovery_mode_from_vbnv(void)
+int get_write_protect_state(void)
{
- return 0;
+ return 0; // FIXME what GPIO? // WP hard coded to disabled
}
diff --git a/src/vendorcode/google/chromeos/Makefile.inc b/src/vendorcode/google/chromeos/Makefile.inc
index ccde71a102..b9e42da92c 100644
--- a/src/vendorcode/google/chromeos/Makefile.inc
+++ b/src/vendorcode/google/chromeos/Makefile.inc
@@ -17,9 +17,12 @@
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
##
-romstage-$(CONFIG_ARCH_ROMSTAGE_X86_32) += vbnv.c
-ramstage-$(CONFIG_ARCH_RAMSTAGE_X86_32) += vbnv.c
+romstage-$(CONFIG_ARCH_ROMSTAGE_X86_32) += vbnv_cmos.c
+ramstage-$(CONFIG_ARCH_RAMSTAGE_X86_32) += vbnv_cmos.c
+romstage-$(CONFIG_ARCH_ROMSTAGE_ARMV7) += vbnv_ec.c
+ramstage-$(CONFIG_ARCH_RAMSTAGE_ARMV7) += vbnv_ec.c
romstage-$(CONFIG_ARCH_ROMSTAGE_X86_32) += vboot.c
+
ramstage-y += gnvs.c
romstage-y += fmap.c
ramstage-y += fmap.c
diff --git a/src/vendorcode/google/chromeos/vbnv.c b/src/vendorcode/google/chromeos/vbnv_cmos.c
index a13726d04b..a13726d04b 100644
--- a/src/vendorcode/google/chromeos/vbnv.c
+++ b/src/vendorcode/google/chromeos/vbnv_cmos.c
diff --git a/src/vendorcode/google/chromeos/vbnv_ec.c b/src/vendorcode/google/chromeos/vbnv_ec.c
new file mode 100644
index 0000000000..78da5414d4
--- /dev/null
+++ b/src/vendorcode/google/chromeos/vbnv_ec.c
@@ -0,0 +1,140 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2011 The ChromiumOS Authors. 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 as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <types.h>
+#include <string.h>
+#include <console/console.h>
+#include <arch/early_variables.h>
+#include <ec/google/chromeec/ec.h>
+#include "chromeos.h"
+
+#define VBNV_BLOCK_SIZE 16 /* Size of NV storage block in bytes */
+
+/* Constants for NV storage. We use this rather than structs and
+ * bitfields so the data format is consistent across platforms and
+ * compilers.
+ */
+#define HEADER_OFFSET 0
+#define HEADER_MASK 0xC0
+#define HEADER_SIGNATURE 0x40
+#define HEADER_FIRMWARE_SETTINGS_RESET 0x20
+#define HEADER_KERNEL_SETTINGS_RESET 0x10
+
+#define BOOT_OFFSET 1
+#define BOOT_DEBUG_RESET_MODE 0x80
+#define BOOT_DISABLE_DEV_REQUEST 0x40
+#define BOOT_OPROM_NEEDED 0x20
+#define BOOT_TRY_B_COUNT_MASK 0x0F
+
+#define RECOVERY_OFFSET 2
+#define LOCALIZATION_OFFSET 3
+
+#define DEV_FLAGS_OFFSET 4
+#define DEV_BOOT_USB_MASK 0x01
+#define DEV_BOOT_SIGNED_ONLY_MASK 0x02
+
+#define KERNEL_FIELD_OFFSET 11
+#define CRC_OFFSET 15
+
+static int vbnv_initialized CAR_GLOBAL;
+static uint8_t vbnv[VBNV_BLOCK_SIZE] CAR_GLOBAL;
+
+/* Wrappers for accessing the variables marked as CAR_GLOBAL. */
+static inline int is_vbnv_initialized(void)
+{
+ return car_get_var(vbnv_initialized);
+}
+
+static inline uint8_t *vbnv_data_addr(int index)
+{
+ uint8_t *vbnv_arr = car_get_var_ptr(vbnv);
+
+ return &vbnv_arr[index];
+}
+
+static inline uint8_t vbnv_data(int index)
+{
+ return *vbnv_data_addr(index);
+}
+
+/* Return CRC-8 of the data, using x^8 + x^2 + x + 1 polynomial. A
+ * table-based algorithm would be faster, but for only 15 bytes isn't
+ * worth the code size.
+ */
+
+static uint8_t crc8(const uint8_t * data, int len)
+{
+ unsigned crc = 0;
+ int i, j;
+
+ for (j = len; j; j--, data++) {
+ crc ^= (*data << 8);
+ for (i = 8; i; i--) {
+ if (crc & 0x8000)
+ crc ^= (0x1070 << 3);
+ crc <<= 1;
+ }
+ }
+
+ return (uint8_t) (crc >> 8);
+}
+
+void read_vbnv(uint8_t *vbnv_copy)
+{
+ google_chromeec_vbnv_context(1, vbnv_copy, VBNV_BLOCK_SIZE);
+
+ /* Check data for consistency */
+ if ((HEADER_SIGNATURE != (vbnv_copy[HEADER_OFFSET] & HEADER_MASK))
+ || (crc8(vbnv_copy, CRC_OFFSET) != vbnv_copy[CRC_OFFSET])) {
+
+ /* Data is inconsistent (bad CRC or header),
+ * so reset to defaults
+ */
+ memset(vbnv_copy, 0, VBNV_BLOCK_SIZE);
+ vbnv_copy[HEADER_OFFSET] =
+ (HEADER_SIGNATURE | HEADER_FIRMWARE_SETTINGS_RESET |
+ HEADER_KERNEL_SETTINGS_RESET);
+ }
+}
+
+void save_vbnv(const uint8_t *vbnv_copy)
+{
+ google_chromeec_vbnv_context(0, (uint8_t *)vbnv_copy, VBNV_BLOCK_SIZE);
+}
+
+static void vbnv_setup(void)
+{
+ read_vbnv(vbnv_data_addr(0));
+ car_set_var(vbnv_initialized, 1);
+}
+
+int get_recovery_mode_from_vbnv(void)
+{
+ if (!is_vbnv_initialized())
+ vbnv_setup();
+ return vbnv_data(RECOVERY_OFFSET);
+}
+
+int vboot_wants_oprom(void)
+{
+ if (!is_vbnv_initialized())
+ vbnv_setup();
+
+ return (vbnv_data(BOOT_OFFSET) & BOOT_OPROM_NEEDED) ? 1 : 0;
+}