• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
9 #include "sysincludes.h"
10 
11 #include "bmpblk_header.h"
12 #include "region.h"
13 #include "gbb_access.h"
14 #include "gbb_header.h"
15 #include "load_kernel_fw.h"
16 #include "utility.h"
17 #include "vboot_api.h"
18 #include "vboot_struct.h"
19 
VbRegionReadData(VbCommonParams * cparams,enum vb_firmware_region region,uint32_t offset,uint32_t size,void * buf)20 VbError_t VbRegionReadData(VbCommonParams *cparams,
21 			   enum vb_firmware_region region, uint32_t offset,
22 			   uint32_t size, void *buf)
23 {
24 	/* This is the old API, for backwards compatibility */
25 	if (region == VB_REGION_GBB && cparams->gbb_data) {
26 		if (offset + size > cparams->gbb_size)
27 			return VBERROR_INVALID_GBB;
28 		Memcpy(buf, cparams->gbb_data + offset, size);
29 	} else
30 #ifdef REGION_READ
31 	{
32 		VbError_t ret;
33 
34 		ret = VbExRegionRead(cparams, region, offset, size, buf);
35 		if (ret)
36 			return ret;
37 	}
38 #else
39 	return VBERROR_INVALID_GBB;
40 #endif
41 
42 	return VBERROR_SUCCESS;
43 }
44 
VbGbbReadHeader_static(VbCommonParams * cparams,GoogleBinaryBlockHeader * gbb)45 VbError_t VbGbbReadHeader_static(VbCommonParams *cparams,
46 				 GoogleBinaryBlockHeader *gbb)
47 {
48 	return VbRegionReadData(cparams, VB_REGION_GBB, 0,
49 				sizeof(GoogleBinaryBlockHeader), gbb);
50 }
51