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_read(u8 *buf, int buf_size);
32 static int vbc_write_byte(unsigned offset, u8 value);
34 /* the following defines are copied from
35 * vboot_reference:firmware/lib/vboot_nvstorage.c.
37 #define RECOVERY_OFFSET 2
38 #define VBNV_RECOVERY_RW_INVALID_OS 0x43
40 int chromeos_set_need_recovery(void)
42 if (!chromeos_legacy_set_need_recovery())
45 return vbc_write_byte(RECOVERY_OFFSET, VBNV_RECOVERY_RW_INVALID_OS);
49 * Lifted from vboot_reference:firmware/lib/vboot_nvstorage.c and formatted.
51 * Return CRC-8 of the data, using x^8 + x^2 + x + 1 polynomial. A table-based
52 * algorithm would be faster, but for only 15 bytes isn't worth the code size.
54 static u8 crc8(const u8 *data, int len)
59 for (j = len; j; j--, data++) {
67 return (u8)(crc >> 8);
70 static int vbc_write_byte(unsigned offset, u8 value)
72 u8 buf[MAX_VBOOT_CONTEXT_BUFFER_SIZE];
75 if (!chromeos_vbc_ptr)
78 size = vbc_read(buf, sizeof(buf));
82 if (offset >= (size - 1))
85 if (buf[offset] == value)
89 buf[size - 1] = crc8(buf, size - 1);
91 return chromeos_vbc_ptr->write(buf, size);
95 * Read vboot context and verify it. If everything checks out, return number
96 * of bytes in the vboot context buffer, -1 on any error (uninitialized
97 * subsystem, corrupted crc8 value, not enough room in the buffer, etc.).
99 static int vbc_read(u8 *buf, int buf_size)
103 if (!chromeos_vbc_ptr)
106 size = chromeos_vbc_ptr->read(buf, buf_size);
110 if (buf[size - 1] != crc8(buf, size - 1)) {
111 pr_err("%s: vboot context contents corrupted\n", __func__);
117 int chromeos_vbc_register(struct chromeos_vbc *chromeos_vbc)
119 chromeos_vbc_ptr = chromeos_vbc;
123 #ifndef CONFIG_USE_OF
125 /* Set the platform dependent parameters using kernel config parameters */
126 static struct ramoops_platform_data chromeos_ramoops_data = {
127 .mem_size = CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE,
128 .mem_address = CONFIG_CHROMEOS_RAMOOPS_RAM_START,
129 .record_size = CONFIG_CHROMEOS_RAMOOPS_RECORD_SIZE,
130 .dump_oops = CONFIG_CHROMEOS_RAMOOPS_DUMP_OOPS,
133 static struct platform_device chromeos_ramoops = {
136 .platform_data = &chromeos_ramoops_data,
141 * If you don't set the ramoops module parameters then ramoops needs a
142 * platform device in order to run. So a platform device is registered
143 * which sets the needed parameters.
145 static int __init chromeos_ramoops_init(void)
149 ret = platform_device_register(&chromeos_ramoops);
151 printk(KERN_ERR "unable to register platform device\n");
158 subsys_initcall(chromeos_ramoops_init);