region-fw.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. static VbError_t VbGbbReadKey(VbCommonParams *cparams, uint32_t offset,
  18. VbPublicKey **keyp)
  19. {
  20. VbPublicKey hdr, *key;
  21. VbError_t ret;
  22. uint32_t size;
  23. ret = VbRegionReadData(cparams, VB_REGION_GBB, offset,
  24. sizeof(VbPublicKey), &hdr);
  25. if (ret)
  26. return ret;
  27. /* Deal with a zero-size key (used in testing) */
  28. size = hdr.key_offset + hdr.key_size;
  29. if (size < sizeof(hdr))
  30. size = sizeof(hdr);
  31. key = malloc(size);
  32. ret = VbRegionReadData(cparams, VB_REGION_GBB, offset, size, key);
  33. if (ret) {
  34. free(key);
  35. return ret;
  36. }
  37. *keyp = key;
  38. return VBERROR_SUCCESS;
  39. }
  40. VbError_t VbGbbReadRootKey(VbCommonParams *cparams, VbPublicKey **keyp)
  41. {
  42. return VbGbbReadKey(cparams, cparams->gbb->rootkey_offset, keyp);
  43. }
  44. VbError_t VbGbbReadRecoveryKey(VbCommonParams *cparams, VbPublicKey **keyp)
  45. {
  46. return VbGbbReadKey(cparams, cparams->gbb->recovery_key_offset, keyp);
  47. }