1 /* Copyright (c) 2013 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 * Common functions between firmware and kernel verified boot. 6 * (Firmware portion) 7 */ 8 9 #include "sysincludes.h" 10 11 #include "vboot_api.h" 12 #include "vboot_common.h" 13 #include "utility.h" 14 VbSharedDataInit(VbSharedDataHeader * header,uint64_t size)15int VbSharedDataInit(VbSharedDataHeader *header, uint64_t size) 16 { 17 VBDEBUG(("VbSharedDataInit, %d bytes, header %d bytes\n", (int)size, 18 (int)sizeof(VbSharedDataHeader))); 19 20 if (size < sizeof(VbSharedDataHeader)) { 21 VBDEBUG(("Not enough data for header.\n")); 22 return VBOOT_SHARED_DATA_INVALID; 23 } 24 if (size < VB_SHARED_DATA_MIN_SIZE) { 25 VBDEBUG(("Shared data buffer too small.\n")); 26 return VBOOT_SHARED_DATA_INVALID; 27 } 28 29 if (!header) 30 return VBOOT_SHARED_DATA_INVALID; 31 32 /* Zero the header */ 33 Memset(header, 0, sizeof(VbSharedDataHeader)); 34 35 /* Initialize fields */ 36 header->magic = VB_SHARED_DATA_MAGIC; 37 header->struct_version = VB_SHARED_DATA_VERSION; 38 header->struct_size = sizeof(VbSharedDataHeader); 39 header->data_size = size; 40 header->data_used = sizeof(VbSharedDataHeader); 41 header->firmware_index = 0xFF; 42 43 /* Success */ 44 return VBOOT_SUCCESS; 45 } 46