vboot_common_init.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include "2sysincludes.h"
  9. #include "2common.h"
  10. #include "sysincludes.h"
  11. #include "vboot_api.h"
  12. #include "vboot_common.h"
  13. #include "utility.h"
  14. int VbSharedDataInit(VbSharedDataHeader *header, uint64_t size)
  15. {
  16. VB2_DEBUG("VbSharedDataInit, %d bytes, header %d bytes\n", (int)size,
  17. (int)sizeof(VbSharedDataHeader));
  18. if (size < sizeof(VbSharedDataHeader)) {
  19. VB2_DEBUG("Not enough data for header.\n");
  20. return VBOOT_SHARED_DATA_INVALID;
  21. }
  22. if (size < VB_SHARED_DATA_MIN_SIZE) {
  23. VB2_DEBUG("Shared data buffer too small.\n");
  24. return VBOOT_SHARED_DATA_INVALID;
  25. }
  26. if (!header)
  27. return VBOOT_SHARED_DATA_INVALID;
  28. /* Zero the header */
  29. memset(header, 0, sizeof(VbSharedDataHeader));
  30. /* Initialize fields */
  31. header->magic = VB_SHARED_DATA_MAGIC;
  32. header->struct_version = VB_SHARED_DATA_VERSION;
  33. header->struct_size = sizeof(VbSharedDataHeader);
  34. header->data_size = size;
  35. header->data_used = sizeof(VbSharedDataHeader);
  36. header->firmware_index = 0xFF;
  37. /* Success */
  38. return VBOOT_SUCCESS;
  39. }