summaryrefslogtreecommitdiff
path: root/include/chromeos/crossystem_data.h
blob: 08805fc9538de26272c6e80922a64b3bc9e8a4c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
 * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 */

#ifndef __CHROMEOS_CROSSYSTEM_DATA_H__
#define __CHROMEOS_CROSSYSTEM_DATA_H__

#include <chromeos/cros_gpio.h>
#include <vboot_nvstorage.h>
#include <vboot_struct.h>

#define ID_LEN		256

#define RECOVERY_FIRMWARE	0
#define REWRITABLE_FIRMWARE_A	1
#define REWRITABLE_FIRMWARE_B	2

#define RECOVERY_TYPE		0
#define NORMAL_TYPE		1
#define DEVELOPER_TYPE		2

/* the data blob format */
typedef struct {
	uint32_t	total_size;
	char		signature[10];
	uint16_t	version;
	uint64_t	nvcxt_lba;
	uint16_t	vbnv[2];
	uint8_t		nvcxt_cache[VBNV_BLOCK_SIZE];
	uint8_t		write_protect_sw;
	uint8_t		recovery_sw;
	uint8_t		developer_sw;
	int		gpio_port_write_protect_sw;
	int		gpio_port_recovery_sw;
	int		gpio_port_developer_sw;
	uint8_t		polarity_write_protect_sw;
	uint8_t		polarity_recovery_sw;
	uint8_t		polarity_developer_sw;
	uint8_t		binf[5];
	uint32_t	chsw;
	char 		hwid[ID_LEN];
	char		fwid[ID_LEN];
	char		frid[ID_LEN];
	uint32_t	fmap_base;
	uint8_t		vbshared_data[VB_SHARED_DATA_REC_SIZE];
} crossystem_data_t;

/**
 * This initializes the data blob that we will pass to kernel, and later be
 * used by crossystem. Note that:
 * - It does not initialize information of the main firmware, e.g., fwid. This
 *   information must be initialized in subsequent calls to the setters below.
 * - The recovery reason is default to VBNV_RECOVERY_NOT_REQUESTED.
 *
 * @param cdata is the data blob shared with crossystem
 * @param frid r/o firmware id; a zero-terminated string shorter than ID_LEN
 * @param fmap_data is the address of fmap in firmware
 * @param gbb_data points to gbb blob
 * @param nvcxt_raw points to the VbNvContext raw data
 * @param wpsw stores the value of write protect gpio
 * @param recsw stores the value of recovery mode gpio
 * @param devsw stores the value of developer mode gpio
 * @return 0 if it succeeds; non-zero if it fails
 */
int crossystem_data_init(crossystem_data_t *cdata, char *frid,
		uint32_t fmap_data, void *gbb_data, void *nvcxt_raw,
		cros_gpio_t *wpsw, cros_gpio_t *recsw, cros_gpio_t *devsw);

/**
 * This sets rewritable firmware id. It should only be called in non-recovery
 * boots.
 *
 * @param cdata is the data blob shared with crossystem
 * @param fwid r/w firmware id; a zero-terminated string shorter than ID_LEN
 * @return 0 if it succeeds; non-zero if it fails
 */
int crossystem_data_set_fwid(crossystem_data_t *cdata, char *fwid);

/**
 * This sets active main firmware and its type.
 *
 * @param cdata is the data blob shared with crossystem
 * @param which - recovery: 0; rewritable A: 1; rewritable B: 2
 * @param type - recovery: 0; normal: 1; developer: 2
 * @return 0 if it succeeds; non-zero if it fails
 */
int crossystem_data_set_active_main_firmware(crossystem_data_t *cdata,
		int which, int type);

int crossystem_data_get_active_main_firmware(crossystem_data_t *cdata);
int crossystem_data_get_active_main_firmware_type(crossystem_data_t *cdata);

/**
 * This sets recovery reason.
 *
 * @param cdata is the data blob shared with crossystem
 * @param reason - the recovery reason
 * @return 0 if it succeeds; non-zero if it fails
 */
int crossystem_data_set_recovery_reason(crossystem_data_t *cdata,
		uint32_t reason);

/**
 * This embeds kernel shared data into fdt.
 *
 * @param cdata is the data blob shared with crossystem
 * @param fdt points to a device tree
 * @param size_ptr stores the new size of fdt
 * @return 0 if it succeeds, non-zero if it fails
 */
int crossystem_data_embed_into_fdt(crossystem_data_t *cdata, void *fdt,
		uint32_t *size_ptr);

/**
 * This prints out the data blob content to debug output.
 */
void crossystem_data_dump(crossystem_data_t *cdata);

#endif /* __CHROMEOS_CROSSYSTEM_DATA_H__ */