Add Google ChromeOS vendor support
[coreboot.git] / src / vendorcode / google / chromeos / gnvs.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2011 The ChromiumOS Authors.  All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19
20 #include <types.h>
21 #include <cbfs.h>
22 #include <console/console.h>
23 #include "gnvs.h"
24
25 chromeos_acpi_t *vboot_data;
26 static u32 me_hash_saved[8];
27
28 void chromeos_init_vboot(chromeos_acpi_t *chromeos)
29 {
30         vboot_data = chromeos;
31
32         /* Copy saved ME hash into NVS */
33         memcpy(vboot_data->mehh, me_hash_saved, sizeof(vboot_data->mehh));
34 }
35
36 void chromeos_set_vboot_data_ptr(void *blob)
37 {
38         /* This code has to be rewritten to pass the vboot table
39          * pointer through the coreboot table instead of the 
40          * FDT, since FDT support was rejected upstream. For now
41          * just make the code available for reference.
42          */
43 #if 0 // CONFIG_ADD_FDT
44         int node_offset, addr_cell_len;
45         const u32 *cell;
46         uintptr_t table_addr = (uintptr_t)vboot_data;
47         u32 table_addr32;
48         u64 table_addr64;
49         void *table_ptr;
50
51         cell = fdt_getprop(blob, 0, "#address-cells", NULL);
52         if (cell && *cell == 2) {
53                 addr_cell_len = 8;
54                 table_addr64 = cpu_to_fdt64(table_addr);
55                 table_ptr = &table_addr64;
56         } else {
57                 addr_cell_len = 4;
58                 table_addr32 = cpu_to_fdt32(table_addr);
59                 table_ptr = &table_addr32;
60         }
61
62         node_offset = fdt_path_offset(blob, "/chromeos-config");
63         if (node_offset < 0) {
64                 printk(BIOS_ERR,
65                         "Couldn't find /chromeos-config in the fdt.\n");
66                 return;
67         }
68
69         if (fdt_setprop(blob, node_offset, "gnvs-vboot-table",
70                         table_ptr, addr_cell_len) < 0) {
71                 printk(BIOS_ERR, "Couldn't set gnvs-vboot-table.\n");
72         }
73 #else
74         printk(BIOS_ERR, "Can't set gnvs-vboot-table.\n");
75 #endif
76 }
77
78 void chromeos_set_me_hash(u32 *hash, int len)
79 {
80         if ((len*sizeof(u32)) > sizeof(vboot_data->mehh))
81                 return;
82
83         /* Copy to NVS or save until it is ready */
84         if (vboot_data)
85                 memcpy(vboot_data->mehh, hash, len*sizeof(u32));
86         else
87                 memcpy(me_hash_saved, hash, len*sizeof(u32));
88 }