summaryrefslogtreecommitdiff
path: root/lib/vboot/main_entry.c
blob: c6b67d5ba825a29fd538ac1b9e22744093916bc4 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * Copyright (c) 2011 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.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 */

#include <common.h>
#include <chromeos/common.h>
#include <vboot/boot_kernel.h>
#include <vboot/entry_points.h>
#include <vboot/global_data.h>
#include <vboot_api.h>

#define PREFIX		"main: "

static void prepare_cparams(vb_global_t *global, VbCommonParams *cparams)
{
	cparams->gbb_data = global->gbb_data;
	cparams->gbb_size = global->gbb_size;
	cparams->shared_data_blob = global->cdata_blob.vb_shared_data;
	cparams->shared_data_size = VB_SHARED_DATA_REC_SIZE;
}

static void prepare_kparams(VbSelectAndLoadKernelParams *kparams)
{
	kparams->kernel_buffer = (void *)CONFIG_CHROMEOS_KERNEL_LOADADDR;
	kparams->kernel_buffer_size = CONFIG_CHROMEOS_KERNEL_BUFSIZE;
}

static VbError_t call_VbSelectAndLoadKernel(VbCommonParams* cparams,
					VbSelectAndLoadKernelParams* kparams)
{
        VbError_t ret;

        VBDEBUG("VbCommonParams:\n");
        VBDEBUG("    gbb_data         : %p\n", cparams->gbb_data);
        VBDEBUG("    gbb_size         : %u\n", cparams->gbb_size);
        VBDEBUG("    shared_data_blob : %p\n", cparams->shared_data_blob);
        VBDEBUG("    shared_data_size : %u\n", cparams->shared_data_size);
        VBDEBUG("    caller_context   : %p\n", cparams->caller_context);
        VBDEBUG("VbSelectAndLoadKernelParams:\n");
        VBDEBUG("    kernel_buffer      : %p\n", kparams->kernel_buffer);
        VBDEBUG("    kernel_buffer_size : %u\n",
						kparams->kernel_buffer_size);
        VBDEBUG("Calling VbSelectAndLoadKernel()...\n");

        ret = VbSelectAndLoadKernel(cparams, kparams);
        VBDEBUG("Returned %#x\n", ret);

	if (!ret) {
		int i;
	        VBDEBUG("VbSelectAndLoadKernelParams:\n");
		VBDEBUG("    disk_handle        : %p\n",
						kparams->disk_handle);
		VBDEBUG("    partition_number   : %u\n",
						kparams->partition_number);
		VBDEBUG("    bootloader_address : %#llx\n",
						kparams->bootloader_address);
		VBDEBUG("    bootloader_size    : %u\n",
						kparams->bootloader_size);
		VBDEBUG("    partition_guid     :");
		for (i = 0; i < 16; i++)
			VBDEBUG(" %02x", kparams->partition_guid[i]);
		VBDEBUG("\n");
	}

	return ret;
}

void main_entry(void)
{
	vb_global_t *global;
	VbCommonParams cparams;
	VbSelectAndLoadKernelParams kparams;
	VbError_t ret;

	/* Get VBoot Global Data which was initialized by bootstub. */
	global = get_vboot_global();
	if (!is_vboot_global_valid(global))
		VbExError(PREFIX "VBoot Global Data is not initialized!\n");

	prepare_cparams(global, &cparams);
	prepare_kparams(&kparams);

	ret = call_VbSelectAndLoadKernel(&cparams, &kparams);

	if (ret)
		VbExError(PREFIX "Failed to select and load kernel!\n");

	/* Do boot partition substitution in kernel cmdline and boot */
	ret = boot_kernel(&kparams, &global->cdata_blob);

	VbExError(PREFIX "boot_kernel_helper returned, %u\n", ret);
}