blob: 50198b078d31ef584d8b158f7513b52f0bb1a81f [file] [log] [blame]
Randall Spanglerda8d32d2012-08-03 12:48:24 -07001/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Randall Spanglereb591952011-04-07 10:02:00 -07002 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 *
5 * Architecture-specific APIs for crossystem
6 */
7
8#ifndef VBOOT_REFERENCE_CROSSYSTEM_ARCH_H_
9#define VBOOT_REFERENCE_CROSSYSTEM_ARCH_H_
10
J. Richard Barnettea3d70a32013-10-30 11:36:45 -070011#include <stddef.h>
12
Randall Spanglereb591952011-04-07 10:02:00 -070013#include "vboot_nvstorage.h"
14#include "vboot_struct.h"
15
Vadim Bendeburyc3574082011-05-02 16:23:30 -070016/* Firmware types from BINF.3. Placed in the common file because both x86 and
17 * arm use this. The constants are defined in "Chrome OS Main Processor
18 * Firmware Spec"
19 */
20#define BINF3_RECOVERY 0
21#define BINF3_NORMAL 1
22#define BINF3_DEVELOPER 2
Vadim Bendeburyfcec9e72012-04-20 10:53:40 -070023#define BINF3_NETBOOT 3
Vadim Bendeburyc3574082011-05-02 16:23:30 -070024
Randall Spanglereb591952011-04-07 10:02:00 -070025
26/* INTERNAL APIS FOR CROSSYSTEM AVAILABLE TO ARCH-SPECIFIC FUNCTIONS */
27
28/* Read an integer property from VbNvStorage.
29 *
30 * Returns the parameter value, or -1 if error. */
31int VbGetNvStorage(VbNvParam param);
32
33/* Write an integer property to VbNvStorage.
34 *
35 * Returns 0 if success, -1 if error. */
36int VbSetNvStorage(VbNvParam param, int value);
37
38/* Return true if the FWID starts with the specified string. */
39int FwidStartsWith(const char *start);
40
Randall Spanglerda8d32d2012-08-03 12:48:24 -070041/* Return version of VbSharedData struct or -1 if not found. */
42int VbSharedDataVersion(void);
Randall Spanglereb591952011-04-07 10:02:00 -070043
Randall Spanglerda8d32d2012-08-03 12:48:24 -070044/* Apis WITH ARCH-SPECIFIC IMPLEMENTATIONS */
Randall Spanglereb591952011-04-07 10:02:00 -070045
46/* Read the non-volatile context from NVRAM.
47 *
48 * Returns 0 if success, -1 if error. */
49int VbReadNvStorage(VbNvContext* vnc);
50
51/* Write the non-volatile context to NVRAM.
52 *
53 * Returns 0 if success, -1 if error. */
54int VbWriteNvStorage(VbNvContext* vnc);
55
56/* Read the VbSharedData buffer.
57 *
58 * Verifies the buffer contains at least enough data for the
59 * VbSharedDataHeader; if not, this is an error.
60 *
61 * If less data is read than expected, sets the returned structure's data_size
62 * to the actual amount of data read. If this is less than data_used, then
63 * some data was not returned; callers must handle this; this is not considered
64 * an error.
65 *
Randall Spangler7adcc602011-06-24 16:11:45 -070066 * Returns the data buffer, which must be freed by the caller using
67 * free(), or NULL if error. */
Randall Spanglereb591952011-04-07 10:02:00 -070068VbSharedDataHeader* VbSharedDataRead(void);
69
70/* Read an architecture-specific system property integer.
71 *
72 * Returns the property value, or -1 if error. */
73int VbGetArchPropertyInt(const char* name);
74
75/* Read an architecture-specific system property string into a
76 * destination buffer of the specified size. Returned string will be
77 * null-terminated. If the buffer is too small, the returned string
78 * will be truncated.
79 *
80 * Returns the passed buffer, or NULL if error. */
J. Richard Barnettea3d70a32013-10-30 11:36:45 -070081const char* VbGetArchPropertyString(const char* name, char* dest, size_t size);
Randall Spanglereb591952011-04-07 10:02:00 -070082
83/* Set an architecture-specific system property integer.
84 *
85 * Returns 0 if success, -1 if error. */
86int VbSetArchPropertyInt(const char* name, int value);
87
88/* Set an architecture-specific system property string.
89 *
90 * Returns 0 if success, -1 if error. */
91int VbSetArchPropertyString(const char* name, const char* value);
92
93#endif /* VBOOT_REFERENCE__CROSSYSTEM_ARCH_H_ */