summaryrefslogtreecommitdiff
path: root/firmware/lib/region-init.c
blob: bec0450df0ecd4f6fd7eb77de7424d6ff40b1c70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 *
 * High-level firmware API for loading and verifying rewritable firmware.
 * (Firmware portion)
 */

#include "sysincludes.h"

#include "bmpblk_header.h"
#include "region.h"
#include "gbb_access.h"
#include "gbb_header.h"
#include "load_kernel_fw.h"
#include "utility.h"
#include "vboot_api.h"
#include "vboot_struct.h"

VbError_t VbRegionReadData(VbCommonParams *cparams,
			   enum vb_firmware_region region, uint32_t offset,
			   uint32_t size, void *buf)
{
	/* This is the old API, for backwards compatibility */
	if (region == VB_REGION_GBB && cparams->gbb_data) {
		if (offset + size > cparams->gbb_size)
			return VBERROR_INVALID_GBB;
		Memcpy(buf, cparams->gbb_data + offset, size);
	} else
#ifdef REGION_READ
	{
		VbError_t ret;

		ret = VbExRegionRead(cparams, region, offset, size, buf);
		if (ret)
			return ret;
	}
#else
	return VBERROR_INVALID_GBB;
#endif

	return VBERROR_SUCCESS;
}

VbError_t VbGbbReadHeader_static(VbCommonParams *cparams,
				 GoogleBinaryBlockHeader *gbb)
{
	return VbRegionReadData(cparams, VB_REGION_GBB, 0,
				sizeof(GoogleBinaryBlockHeader), gbb);
}