Home | History | Annotate | Download | only in include
      1 /* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
      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 "vboot_nvstorage.h"
     14 #include "vboot_struct.h"
     15 
     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
     23 #define BINF3_NETBOOT    3
     24 
     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 
     41 /* Return version of VbSharedData struct or -1 if not found. */
     42 int VbSharedDataVersion(void);
     43 
     44 /* Apis WITH ARCH-SPECIFIC IMPLEMENTATIONS */
     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  *
     66  * Returns the data buffer, which must be freed by the caller using
     67  * free(), or NULL if error. */
     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. */
     81 const char* VbGetArchPropertyString(const char* name, char* dest, size_t size);
     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_ */
     94