blob: 90edae68ef45927227802d01bdbd4a84637b1ea2 [file] [log] [blame]
Randall Spangler93943262013-02-26 11:03:57 -08001/* 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
Bill Richardson0c3ba242013-03-29 11:09:30 -07009#include "sysincludes.h"
10
Randall Spangler93943262013-02-26 11:03:57 -080011#include "vboot_api.h"
12#include "vboot_common.h"
13#include "utility.h"
14
15int VbSharedDataInit(VbSharedDataHeader *header, uint64_t size)
16{
17 VBDEBUG(("VbSharedDataInit, %d bytes, header %d bytes\n", (int)size,
Simon Glass981cb2a2013-08-12 15:12:47 -060018 (int)sizeof(VbSharedDataHeader)));
Randall Spangler93943262013-02-26 11:03:57 -080019
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 */
Randall Spangler664096b2016-10-13 16:16:41 -070033 memset(header, 0, sizeof(VbSharedDataHeader));
Randall Spangler93943262013-02-26 11:03:57 -080034
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}