OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 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 | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 * | 5 * |
6 * Alternatively, this software may be distributed under the terms of the | 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 | 7 * GNU General Public License ("GPL") version 2 as published by the Free |
8 * Software Foundation. | 8 * Software Foundation. |
9 */ | 9 */ |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 #action, return_code); \ | 28 #action, return_code); \ |
29 } while (0) | 29 } while (0) |
30 #else | 30 #else |
31 #define WARN_ON_FAILURE(action) action | 31 #define WARN_ON_FAILURE(action) action |
32 #endif | 32 #endif |
33 | 33 |
34 #define FIRMWARE_RECOVERY 0 | 34 #define FIRMWARE_RECOVERY 0 |
35 #define FIRMWARE_A 1 | 35 #define FIRMWARE_A 1 |
36 #define FIRMWARE_B 2 | 36 #define FIRMWARE_B 2 |
37 | 37 |
| 38 /* |
| 39 * verified_firmware_t is used for storing returned data of LoadFirmware() and |
| 40 * GetFirmwareBody(). |
| 41 */ |
| 42 typedef struct { |
| 43 /* |
| 44 * This field is output of LoadFirmware(). See |
| 45 * vboot_reference/firmware/include/load_firmware_fw.h for |
| 46 * documentation. |
| 47 */ |
| 48 int firmware_index; |
| 49 |
| 50 /* Rewritable firmware data loaded by GetFirmwareBody(). */ |
| 51 uint8_t *firmware_body[2]; |
| 52 } verified_firmware_t; |
| 53 |
| 54 /* |
| 55 * Load and verify rewritable firmware. A wrapper of LoadFirmware() function. |
| 56 * |
| 57 * Returns what is returned by LoadFirmware(). |
| 58 * |
| 59 * For documentation of return values of LoadFirmware(), <primary_firmware>, and |
| 60 * <boot_flags>, please refer to |
| 61 * vboot_reference/firmware/include/load_firmware_fw.h |
| 62 * |
| 63 * The kernel key found in firmware image is stored in <kernel_sign_key_blob> |
| 64 * and <kernel_sign_key_size>. |
| 65 * |
| 66 * Output of LoadFirmware() and GetFirmwareBody() is stored in |
| 67 * struct pointed by <verified_firmware>. |
| 68 */ |
| 69 int load_firmware(int primary_firmware, int boot_flags, |
| 70 void *kernel_sign_key_blob, uint64_t kernel_sign_key_size, |
| 71 verified_firmware_t *verified_firmware) |
| 72 { |
| 73 return LOAD_FIRMWARE_RECOVERY; |
| 74 } |
| 75 |
| 76 void jump_to_firmware(void (*rwfw_entry_point)(void)) |
| 77 { |
| 78 debug(PREFIX "jump to firmware %p\n", rwfw_entry_point); |
| 79 } |
| 80 |
38 int do_cros_bootstub(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) | 81 int do_cros_bootstub(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
39 { | 82 { |
40 » int firmware_index, primary_firmware; | 83 » int status = LOAD_FIRMWARE_RECOVERY; |
41 | 84 » int primary_firmware, boot_flags = 0; |
42 » /* Boot Stub ******************************************************** */ | 85 » verified_firmware_t vf; |
| 86 » uint8_t *kernel_sign_key_blob = (uint8_t *) CONFIG_KERNEL_SIGN_KEY_BLOB; |
| 87 » uint64_t kernel_sign_key_size = CONFIG_KERNEL_SIGN_KEY_SIZE; |
43 | 88 |
44 /* TODO Start initializing chipset */ | 89 /* TODO Start initializing chipset */ |
45 | 90 |
46 if (is_firmware_write_protect_gpio_asserted()) | 91 if (is_firmware_write_protect_gpio_asserted()) |
47 WARN_ON_FAILURE(lock_down_eeprom()); | 92 WARN_ON_FAILURE(lock_down_eeprom()); |
48 | 93 |
49 WARN_ON_FAILURE(initialize_tpm()); | 94 WARN_ON_FAILURE(initialize_tpm()); |
50 | 95 |
51 if (is_s3_resume() && !is_debug_reset_mode_field_containing_cookie()) { | 96 if (is_s3_resume() && !is_debug_reset_mode_field_containing_cookie()) { |
52 WARN_ON_FAILURE(lock_tpm()); | 97 WARN_ON_FAILURE(lock_tpm()); |
53 /* TODO Jump to S3 resume pointer and should never return */ | 98 /* TODO Jump to S3 resume pointer and should never return */ |
54 return 0; | 99 return 0; |
55 } | 100 } |
56 | 101 |
57 if (is_recovery_mode_gpio_asserted() || | 102 if (is_recovery_mode_gpio_asserted() || |
58 is_recovery_mode_field_containing_cookie()) { | 103 is_recovery_mode_field_containing_cookie()) { |
59 » » firmware_index = FIRMWARE_RECOVERY; | 104 » » debug(PREFIX "boot recovery firmware\n"); |
60 } else { | 105 } else { |
61 if (is_try_firmware_b_field_containing_cookie()) | 106 if (is_try_firmware_b_field_containing_cookie()) |
62 primary_firmware = FIRMWARE_B; | 107 primary_firmware = FIRMWARE_B; |
63 else | 108 else |
64 primary_firmware = FIRMWARE_A; | 109 primary_firmware = FIRMWARE_A; |
65 | 110 |
66 » » /* TODO call LoadFirmware */ | 111 » » if (is_developer_mode_gpio_asserted()) |
| 112 » » » boot_flags |= BOOT_FLAG_DEVELOPER; |
| 113 |
| 114 » » status = load_firmware(primary_firmware, boot_flags, |
| 115 » » » » kernel_sign_key_blob, kernel_sign_key_size, |
| 116 » » » » &vf); |
67 } | 117 } |
68 | 118 |
69 debug(PREFIX "load firmware of index %d\n", firmware_index); | |
70 | |
71 WARN_ON_FAILURE(lock_tpm_rewritable_firmware_index()); | 119 WARN_ON_FAILURE(lock_tpm_rewritable_firmware_index()); |
72 | 120 |
73 » if (firmware_index == FIRMWARE_A) { | 121 » if (status == LOAD_FIRMWARE_SUCCESS) { |
74 » » /* TODO Jump to firmware A and should never return */ | 122 » » debug(PREFIX "jump to rewritable firmware %d " |
| 123 » » » » "and never return\n", |
| 124 » » » » vf.firmware_index); |
| 125 » » jump_to_firmware((void (*)(void)) |
| 126 » » » » vf.firmware_body[vf.firmware_index]); |
| 127 |
| 128 » » debug(PREFIX "error: should never reach here! " |
| 129 » » » » "jump to recovery firmware\n"); |
75 } | 130 } |
76 | 131 |
77 » if (firmware_index == FIRMWARE_B) { | 132 » /* TODO Jump to recovery firmware and never return */ |
78 » » /* TODO Jump to firmware B and should never return */ | |
79 » } | |
80 | 133 |
81 » /* assert(firmware_index == FIRMWARE_RECOVERY); */ | 134 » debug(PREFIX "error: should never reach here!\n"); |
82 | 135 » return 1; |
83 » /* Recovery Firmware ************************************************ */ | |
84 | |
85 » return 0; | |
86 } | 136 } |
87 | 137 |
88 U_BOOT_CMD(cros_bootstub, 1, 1, do_cros_bootstub, NULL, NULL); | 138 U_BOOT_CMD(cros_bootstub, 1, 1, do_cros_bootstub, "verified boot stub firmware", |
| 139 » » NULL); |
OLD | NEW |