Randall Spangler | da8d32d | 2012-08-03 12:48:24 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Randall Spangler | eb59195 | 2011-04-07 10:02:00 -0700 | [diff] [blame] | 2 | * 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 Barnette | a3d70a3 | 2013-10-30 11:36:45 -0700 | [diff] [blame] | 11 | #include <stddef.h> |
| 12 | |
Randall Spangler | eb59195 | 2011-04-07 10:02:00 -0700 | [diff] [blame] | 13 | #include "vboot_nvstorage.h" |
| 14 | #include "vboot_struct.h" |
| 15 | |
Vadim Bendebury | c357408 | 2011-05-02 16:23:30 -0700 | [diff] [blame] | 16 | /* 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 Bendebury | fcec9e7 | 2012-04-20 10:53:40 -0700 | [diff] [blame] | 23 | #define BINF3_NETBOOT 3 |
Vadim Bendebury | c357408 | 2011-05-02 16:23:30 -0700 | [diff] [blame] | 24 | |
Randall Spangler | eb59195 | 2011-04-07 10:02:00 -0700 | [diff] [blame] | 25 | |
| 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. */ |
| 31 | int VbGetNvStorage(VbNvParam param); |
| 32 | |
| 33 | /* Write an integer property to VbNvStorage. |
| 34 | * |
| 35 | * Returns 0 if success, -1 if error. */ |
| 36 | int VbSetNvStorage(VbNvParam param, int value); |
| 37 | |
| 38 | /* Return true if the FWID starts with the specified string. */ |
| 39 | int FwidStartsWith(const char *start); |
| 40 | |
Randall Spangler | da8d32d | 2012-08-03 12:48:24 -0700 | [diff] [blame] | 41 | /* Return version of VbSharedData struct or -1 if not found. */ |
| 42 | int VbSharedDataVersion(void); |
Randall Spangler | eb59195 | 2011-04-07 10:02:00 -0700 | [diff] [blame] | 43 | |
Randall Spangler | da8d32d | 2012-08-03 12:48:24 -0700 | [diff] [blame] | 44 | /* Apis WITH ARCH-SPECIFIC IMPLEMENTATIONS */ |
Randall Spangler | eb59195 | 2011-04-07 10:02:00 -0700 | [diff] [blame] | 45 | |
| 46 | /* Read the non-volatile context from NVRAM. |
| 47 | * |
| 48 | * Returns 0 if success, -1 if error. */ |
| 49 | int VbReadNvStorage(VbNvContext* vnc); |
| 50 | |
| 51 | /* Write the non-volatile context to NVRAM. |
| 52 | * |
| 53 | * Returns 0 if success, -1 if error. */ |
| 54 | int 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 Spangler | 7adcc60 | 2011-06-24 16:11:45 -0700 | [diff] [blame] | 66 | * Returns the data buffer, which must be freed by the caller using |
| 67 | * free(), or NULL if error. */ |
Randall Spangler | eb59195 | 2011-04-07 10:02:00 -0700 | [diff] [blame] | 68 | VbSharedDataHeader* VbSharedDataRead(void); |
| 69 | |
| 70 | /* Read an architecture-specific system property integer. |
| 71 | * |
| 72 | * Returns the property value, or -1 if error. */ |
| 73 | int 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 Barnette | a3d70a3 | 2013-10-30 11:36:45 -0700 | [diff] [blame] | 81 | const char* VbGetArchPropertyString(const char* name, char* dest, size_t size); |
Randall Spangler | eb59195 | 2011-04-07 10:02:00 -0700 | [diff] [blame] | 82 | |
| 83 | /* Set an architecture-specific system property integer. |
| 84 | * |
| 85 | * Returns 0 if success, -1 if error. */ |
| 86 | int VbSetArchPropertyInt(const char* name, int value); |
| 87 | |
| 88 | /* Set an architecture-specific system property string. |
| 89 | * |
| 90 | * Returns 0 if success, -1 if error. */ |
| 91 | int VbSetArchPropertyString(const char* name, const char* value); |
| 92 | |
| 93 | #endif /* VBOOT_REFERENCE__CROSSYSTEM_ARCH_H_ */ |