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