OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | |
3 * Use of this source code is governed by a BSD-style license that can be | |
4 * found in the LICENSE file. | |
5 * | |
6 * Alternatively, this software may be distributed under the terms of the | |
7 * GNU General Public License ("GPL") version 2 as published by the Free | |
8 * Software Foundation. | |
9 */ | |
10 | |
11 #include <common.h> | |
12 #include <malloc.h> | |
13 #include <chromeos/boot_device_impl.h> | |
14 #include <chromeos/firmware_storage.h> | |
15 #include <chromeos/load_util.h> | |
16 | |
17 /* vboot_reference interface */ | |
18 #include <vboot_struct.h> | |
19 | |
20 #define PREFIX "load_kernel_wrapper: " | |
21 | |
22 int load_kernel_wrapper(LoadKernelParams *params, uint64_t boot_flags) | |
23 { | |
24 int status = LOAD_KERNEL_NOT_FOUND; | |
25 firmware_storage_t file; | |
26 block_dev_desc_t *dev_desc; | |
27 VbNvContext vnc; | |
28 | |
29 if (init_firmware_storage(&file)) { | |
30 debug(PREFIX "init_firmware_storage fail\n"); | |
31 return LOAD_KERNEL_NOT_FOUND; | |
32 } | |
33 | |
34 dev_desc = get_bootdev(); | |
35 if (!dev_desc) { | |
36 debug(PREFIX "get_bootdev fail\n"); | |
37 goto EXIT; | |
38 } | |
39 | |
40 if (boot_flags | BOOT_FLAG_RECOVERY) { | |
41 params->shared_data_blob = NULL; | |
42 params->shared_data_size = 0; | |
43 } else { | |
44 params->shared_data_blob = | |
45 (uint8_t *) CONFIG_VB_SHARED_DATA_BLOB; | |
46 params->shared_data_size = CONFIG_VB_SHARED_DATA_SIZE; | |
47 } | |
48 | |
49 params->bytes_per_lba = (uint64_t) dev_desc->blksz; | |
50 params->ending_lba = (uint64_t) get_limit() - 1; | |
51 | |
52 params->kernel_buffer = (uint8_t *) CONFIG_LOADADDR; | |
53 params->kernel_buffer_size = CONFIG_MAX_KERNEL_SIZE; | |
54 | |
55 params->boot_flags = boot_flags; | |
56 | |
57 /* read gbb */ | |
58 params->gbb_size = CONFIG_LENGTH_GBB; | |
59 params->gbb_data = malloc(CONFIG_LENGTH_GBB); | |
60 if (!params->gbb_data) { | |
61 debug(PREFIX "cannot malloc gbb\n"); | |
62 goto EXIT; | |
63 } | |
64 if (read_firmware_device(&file, CONFIG_OFFSET_GBB, | |
65 params->gbb_data, | |
66 params->gbb_size)) { | |
67 debug(PREFIX "read gbb fail\n"); | |
68 goto EXIT; | |
69 } | |
70 | |
71 /* TODO: load vnc.raw from NV storage */ | |
72 params->nv_context = &vnc; | |
73 | |
74 debug(PREFIX "call LoadKernel() with parameters...\n"); | |
75 debug(PREFIX "header_sign_key_blob: 0x%p\n", | |
76 params.header_sign_key_blob); | |
77 debug(PREFIX "bytes_per_lba: %d\n", | |
78 (int) params.bytes_per_lba); | |
79 debug(PREFIX "ending_lba: 0x%08x\n", | |
80 (int) params.ending_lba); | |
81 debug(PREFIX "kernel_buffer: 0x%p\n", | |
82 params.kernel_buffer); | |
83 debug(PREFIX "kernel_buffer_size: 0x%08x\n", | |
84 (int) params.kernel_buffer_size); | |
85 debug(PREFIX "boot_flags: 0x%08x\n", | |
86 (int) params.boot_flags); | |
87 | |
88 status = LoadKernel(params); | |
89 | |
90 debug(PREFIX "LoadKernel status: %d\n", status); | |
91 if (status == LOAD_KERNEL_SUCCESS) { | |
92 debug(PREFIX "partition_number: 0x%08x\n", | |
93 (int) params->partition_number); | |
94 debug(PREFIX "bootloader_address: 0x%08x\n", | |
95 (int) params->bootloader_address); | |
96 debug(PREFIX "bootloader_size: 0x%08x\n", | |
97 (int) params->bootloader_size); | |
98 } | |
99 | |
100 if (vnc.raw_changed) { | |
101 /* TODO: save vnc.raw to NV storage */ | |
102 } | |
103 | |
104 EXIT: | |
105 release_firmware_storage(&file); | |
robotboy
2011/03/11 18:56:18
Should the malloced gbb_data be freed here if the
Che-Liang Chiou
2011/03/14 05:51:40
Good point. Change the logic here to 'not fee gbb
| |
106 return status; | |
107 } | |
OLD | NEW |