2 * ChromeOS platform support code. Glue layer between higher level functions
3 * and per-platform firmware interfaces.
5 * Copyright (C) 2010 The Chromium OS Authors
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/types.h>
23 #include <linux/chromeos_platform.h>
24 #include <linux/module.h>
25 #include <linux/platform_device.h>
26 #include <linux/ramoops.h>
29 static struct chromeos_vbc *chromeos_vbc_ptr;
31 static int vbc_write_byte(unsigned offset, u8 value);
33 /* the following defines are copied from
34 * vboot_reference:firmware/lib/vboot_nvstorage.c.
36 #define RECOVERY_OFFSET 2
37 #define VBNV_RECOVERY_RW_INVALID_OS 0x43
39 int chromeos_set_need_recovery(void)
41 if (!chromeos_legacy_set_need_recovery())
44 return vbc_write_byte(RECOVERY_OFFSET, VBNV_RECOVERY_RW_INVALID_OS);
47 int chromeos_set_dev_usb(void)
49 return vbc_write_byte(4, 0x01);
53 * Lifted from vboot_reference:firmware/lib/vboot_nvstorage.c and formatted.
55 * Return CRC-8 of the data, using x^8 + x^2 + x + 1 polynomial. A table-based
56 * algorithm would be faster, but for only 15 bytes isn't worth the code size.
58 static u8 crc8(const u8 *data, int len)
63 for (j = len; j; j--, data++) {
71 return (u8)(crc >> 8);
74 int chromeos_vbc_write(const u8 *buf, ssize_t size)
76 return chromeos_vbc_ptr->write(buf, size);
79 static int vbc_write_byte(unsigned offset, u8 value)
81 u8 buf[MAX_VBOOT_CONTEXT_BUFFER_SIZE];
84 if (!chromeos_vbc_ptr)
87 size = chromeos_vbc_read(buf, sizeof(buf));
91 if (offset >= (size - 1))
94 if (buf[offset] == value)
98 buf[size - 1] = crc8(buf, size - 1);
100 return chromeos_vbc_ptr->write(buf, size);
104 * Read vboot context and verify it. If everything checks out, return number
105 * of bytes in the vboot context buffer, -1 on any error (uninitialized
106 * subsystem, corrupted crc8 value, not enough room in the buffer, etc.).
108 int chromeos_vbc_read(u8 *buf, int buf_size)
112 if (!chromeos_vbc_ptr)
115 size = chromeos_vbc_ptr->read(buf, buf_size);
119 if (buf[size - 1] != crc8(buf, size - 1)) {
120 pr_err("%s: vboot context contents corrupted\n", __func__);
126 int chromeos_vbc_register(struct chromeos_vbc *chromeos_vbc)
128 chromeos_vbc_ptr = chromeos_vbc;
132 #ifndef CONFIG_USE_OF
134 /* Set the platform dependent parameters using kernel config parameters */
135 static struct ramoops_platform_data chromeos_ramoops_data = {
136 .mem_size = CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE,
137 .mem_address = CONFIG_CHROMEOS_RAMOOPS_RAM_START,
138 .record_size = CONFIG_CHROMEOS_RAMOOPS_RECORD_SIZE,
139 .dump_oops = CONFIG_CHROMEOS_RAMOOPS_DUMP_OOPS,
142 static struct platform_device chromeos_ramoops = {
145 .platform_data = &chromeos_ramoops_data,
150 * If you don't set the ramoops module parameters then ramoops needs a
151 * platform device in order to run. So a platform device is registered
152 * which sets the needed parameters.
154 static int __init chromeos_ramoops_init(void)
158 ret = platform_device_register(&chromeos_ramoops);
160 printk(KERN_ERR "unable to register platform device\n");
167 subsys_initcall(chromeos_ramoops_init);