| 1 | /* Copyright 2012 The ChromiumOS Authors |
| 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 | |
| 11 | #include <stddef.h> |
| 12 | |
| 13 | #include "2sysincludes.h" |
| 14 | #include "2api.h" |
| 15 | #include "2nvstorage.h" |
| 16 | #include "vboot_struct.h" |
| 17 | |
| 18 | /* Firmware types from BINF.3. Placed in the common file because both x86 and |
| 19 | * arm use this. The constants are defined in "Chrome OS Main Processor |
| 20 | * Firmware Spec" |
| 21 | */ |
| 22 | #define BINF3_RECOVERY 0 |
| 23 | #define BINF3_NORMAL 1 |
| 24 | #define BINF3_DEVELOPER 2 |
| 25 | #define BINF3_NETBOOT 3 |
| 26 | #define BINF3_LEGACY 4 |
| 27 | |
| 28 | |
| 29 | /* INTERNAL APIS FOR CROSSYSTEM AVAILABLE TO ARCH-SPECIFIC FUNCTIONS */ |
| 30 | |
| 31 | /* Read an integer property from VbNvStorage. |
| 32 | * |
| 33 | * Returns the parameter value, or -1 if error. */ |
| 34 | int vb2_get_nv_storage(enum vb2_nv_param param); |
| 35 | |
| 36 | /* Write an integer property to VbNvStorage. |
| 37 | * |
| 38 | * Returns 0 if success, -1 if error. */ |
| 39 | int vb2_set_nv_storage(enum vb2_nv_param param, int value); |
| 40 | |
| 41 | /* Return true if the FWID starts with the specified string. */ |
| 42 | int FwidStartsWith(const char *start); |
| 43 | |
| 44 | /* Return version of VbSharedData struct or -1 if not found. */ |
| 45 | int VbSharedDataVersion(void); |
| 46 | |
| 47 | /* Apis WITH ARCH-SPECIFIC IMPLEMENTATIONS */ |
| 48 | |
| 49 | /* Read the non-volatile context from NVRAM. |
| 50 | * |
| 51 | * Returns 0 if success, -1 if error. */ |
| 52 | int vb2_read_nv_storage(struct vb2_context *ctx); |
| 53 | |
| 54 | /* Write the non-volatile context to NVRAM. |
| 55 | * |
| 56 | * Returns 0 if success, -1 if error. */ |
| 57 | int vb2_write_nv_storage(struct vb2_context *ctx); |
| 58 | |
| 59 | /* Read the VbSharedData buffer. |
| 60 | * |
| 61 | * Verifies the buffer contains at least enough data for the |
| 62 | * VbSharedDataHeader; if not, this is an error. |
| 63 | * |
| 64 | * If less data is read than expected, sets the returned structure's data_size |
| 65 | * to the actual amount of data read. If this is less than data_used, then |
| 66 | * some data was not returned; callers must handle this; this is not considered |
| 67 | * an error. |
| 68 | * |
| 69 | * Returns the data buffer, which must be freed by the caller using |
| 70 | * free(), or NULL if error. */ |
| 71 | VbSharedDataHeader* VbSharedDataRead(void); |
| 72 | |
| 73 | /* Read an architecture-specific system property integer. |
| 74 | * |
| 75 | * Returns the property value, or -1 if error. */ |
| 76 | int VbGetArchPropertyInt(const char* name); |
| 77 | |
| 78 | /* Read an architecture-specific system property string into a |
| 79 | * destination buffer of the specified size. Returned string will be |
| 80 | * null-terminated. If the buffer is too small, the returned string |
| 81 | * will be truncated. |
| 82 | * |
| 83 | * Returns the passed buffer, or NULL if error. */ |
| 84 | const char* VbGetArchPropertyString(const char* name, char* dest, size_t size); |
| 85 | |
| 86 | /* Set an architecture-specific system property integer. |
| 87 | * |
| 88 | * Returns 0 if success, -1 if error. */ |
| 89 | int VbSetArchPropertyInt(const char* name, int value); |
| 90 | |
| 91 | /* Set an architecture-specific system property string. |
| 92 | * |
| 93 | * Returns 0 if success, -1 if error. */ |
| 94 | int VbSetArchPropertyString(const char* name, const char* value); |
| 95 | |
| 96 | #endif /* VBOOT_REFERENCE_CROSSYSTEM_ARCH_H_ */ |