region-init.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. * High-level firmware API for loading and verifying rewritable firmware.
  6. * (Firmware portion)
  7. */
  8. #include "sysincludes.h"
  9. #include "bmpblk_header.h"
  10. #include "region.h"
  11. #include "gbb_access.h"
  12. #include "gbb_header.h"
  13. #include "load_kernel_fw.h"
  14. #include "utility.h"
  15. #include "vboot_api.h"
  16. #include "vboot_struct.h"
  17. VbError_t VbRegionReadData(VbCommonParams *cparams,
  18. enum vb_firmware_region region, uint32_t offset,
  19. uint32_t size, void *buf)
  20. {
  21. /* This is the old API, for backwards compatibility */
  22. if (region == VB_REGION_GBB && cparams->gbb_data) {
  23. if (offset + size > cparams->gbb_size)
  24. return VBERROR_INVALID_GBB;
  25. memcpy(buf, cparams->gbb_data + offset, size);
  26. } else
  27. #ifdef REGION_READ
  28. {
  29. VbError_t ret;
  30. ret = VbExRegionRead(cparams, region, offset, size, buf);
  31. if (ret)
  32. return ret;
  33. }
  34. #else
  35. return VBERROR_INVALID_GBB;
  36. #endif
  37. return VBERROR_SUCCESS;
  38. }
  39. VbError_t VbGbbReadHeader_static(VbCommonParams *cparams,
  40. GoogleBinaryBlockHeader *gbb)
  41. {
  42. return VbRegionReadData(cparams, VB_REGION_GBB, 0,
  43. sizeof(GoogleBinaryBlockHeader), gbb);
  44. }