Randall Spangler | da2b49c | 2014-06-10 17:03:40 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2014 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 | * Stub API implementations which should be implemented by the caller. |
| 6 | */ |
| 7 | |
Bill Richardson | 40890c5 | 2015-01-26 13:48:32 -0800 | [diff] [blame] | 8 | #include <stdarg.h> |
Julius Werner | ac15a15 | 2020-09-01 15:31:14 -0700 | [diff] [blame] | 9 | #include <stdlib.h> |
Bill Richardson | 40890c5 | 2015-01-26 13:48:32 -0800 | [diff] [blame] | 10 | #include <stdio.h> |
Joel Kitching | c768a70 | 2021-01-18 16:11:13 +0800 | [diff] [blame] | 11 | #include <sys/time.h> |
Bill Richardson | 40890c5 | 2015-01-26 13:48:32 -0800 | [diff] [blame] | 12 | |
Randall Spangler | da2b49c | 2014-06-10 17:03:40 -0700 | [diff] [blame] | 13 | #include "2api.h" |
Joel Kitching | c768a70 | 2021-01-18 16:11:13 +0800 | [diff] [blame] | 14 | #include "2common.h" |
Joel Kitching | ffd42a8 | 2019-08-29 13:58:52 +0800 | [diff] [blame] | 15 | #include "2sysincludes.h" |
Randall Spangler | da2b49c | 2014-06-10 17:03:40 -0700 | [diff] [blame] | 16 | |
Joel Kitching | c768a70 | 2021-01-18 16:11:13 +0800 | [diff] [blame] | 17 | /*****************************************************************************/ |
| 18 | /* General utility stubs */ |
| 19 | |
Julius Werner | f10e909 | 2014-12-16 19:24:54 -0800 | [diff] [blame] | 20 | __attribute__((weak)) |
Bill Richardson | 40890c5 | 2015-01-26 13:48:32 -0800 | [diff] [blame] | 21 | void vb2ex_printf(const char *func, const char *fmt, ...) |
| 22 | { |
Julius Werner | 5160e69 | 2019-03-05 13:56:41 -0800 | [diff] [blame] | 23 | #ifdef VBOOT_DEBUG |
Bill Richardson | 40890c5 | 2015-01-26 13:48:32 -0800 | [diff] [blame] | 24 | va_list ap; |
| 25 | va_start(ap, fmt); |
Randall Spangler | a609478 | 2017-01-20 14:54:47 -0800 | [diff] [blame] | 26 | if (func) |
| 27 | fprintf(stderr, "%s: ", func); |
Bill Richardson | 40890c5 | 2015-01-26 13:48:32 -0800 | [diff] [blame] | 28 | vfprintf(stderr, fmt, ap); |
| 29 | va_end(ap); |
Julius Werner | 5160e69 | 2019-03-05 13:56:41 -0800 | [diff] [blame] | 30 | #endif |
Bill Richardson | 40890c5 | 2015-01-26 13:48:32 -0800 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | __attribute__((weak)) |
Joel Kitching | b139517 | 2021-01-18 16:05:19 +0800 | [diff] [blame] | 34 | void vb2ex_abort(void) |
| 35 | { |
| 36 | /* Stub simply exits. */ |
| 37 | abort(); |
| 38 | } |
| 39 | |
| 40 | __attribute__((weak)) |
Joel Kitching | c768a70 | 2021-01-18 16:11:13 +0800 | [diff] [blame] | 41 | uint32_t vb2ex_mtime(void) |
Randall Spangler | da2b49c | 2014-06-10 17:03:40 -0700 | [diff] [blame] | 42 | { |
Joel Kitching | c768a70 | 2021-01-18 16:11:13 +0800 | [diff] [blame] | 43 | struct timeval tv; |
| 44 | gettimeofday(&tv, NULL); |
| 45 | return tv.tv_sec * VB2_MSEC_PER_SEC + tv.tv_usec / VB2_USEC_PER_MSEC; |
Randall Spangler | da2b49c | 2014-06-10 17:03:40 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Julius Werner | f10e909 | 2014-12-16 19:24:54 -0800 | [diff] [blame] | 48 | __attribute__((weak)) |
Joel Kitching | e6700f4 | 2019-07-31 14:12:30 +0800 | [diff] [blame] | 49 | vb2_error_t vb2ex_read_resource(struct vb2_context *ctx, |
| 50 | enum vb2_resource_index index, uint32_t offset, |
| 51 | void *buf, uint32_t size) |
Randall Spangler | da2b49c | 2014-06-10 17:03:40 -0700 | [diff] [blame] | 52 | { |
Joel Kitching | 231112a | 2019-04-25 18:16:06 +0800 | [diff] [blame] | 53 | fprintf(stderr, "%s: function not implemented\n", __func__); |
Joel Kitching | a1df89d | 2018-12-03 14:39:57 +0800 | [diff] [blame] | 54 | return VB2_ERROR_EX_UNIMPLEMENTED; |
Randall Spangler | da2b49c | 2014-06-10 17:03:40 -0700 | [diff] [blame] | 55 | } |
Julius Werner | f10e909 | 2014-12-16 19:24:54 -0800 | [diff] [blame] | 56 | |
Joel Kitching | c768a70 | 2021-01-18 16:11:13 +0800 | [diff] [blame] | 57 | /*****************************************************************************/ |
| 58 | /* TPM-related stubs */ |
| 59 | |
| 60 | __attribute__((weak)) |
| 61 | vb2_error_t vb2ex_tpm_clear_owner(struct vb2_context *ctx) |
| 62 | { |
| 63 | fprintf(stderr, "%s: function not implemented\n", __func__); |
| 64 | return VB2_ERROR_EX_UNIMPLEMENTED; |
| 65 | } |
| 66 | |
Julius Werner | f10e909 | 2014-12-16 19:24:54 -0800 | [diff] [blame] | 67 | __attribute__((weak)) |
Joel Kitching | e6700f4 | 2019-07-31 14:12:30 +0800 | [diff] [blame] | 68 | vb2_error_t vb2ex_tpm_set_mode(enum vb2_tpm_mode mode_val) |
Matt Delco | 08bf680 | 2019-02-13 15:54:24 -0800 | [diff] [blame] | 69 | { |
Joel Kitching | 231112a | 2019-04-25 18:16:06 +0800 | [diff] [blame] | 70 | fprintf(stderr, "%s: function not implemented\n", __func__); |
Joel Kitching | a1df89d | 2018-12-03 14:39:57 +0800 | [diff] [blame] | 71 | return VB2_ERROR_EX_UNIMPLEMENTED; |
Matt Delco | 08bf680 | 2019-02-13 15:54:24 -0800 | [diff] [blame] | 72 | } |
Joel Kitching | aaf3943 | 2019-09-11 14:15:45 +0800 | [diff] [blame] | 73 | |
Joel Kitching | b139517 | 2021-01-18 16:05:19 +0800 | [diff] [blame] | 74 | /*****************************************************************************/ |
| 75 | /* auxfw and EC-related stubs */ |
| 76 | |
| 77 | __attribute__((weak)) |
| 78 | int vb2ex_ec_trusted(void) |
| 79 | { |
| 80 | return 1; |
| 81 | } |
| 82 | |
| 83 | __attribute__((weak)) |
| 84 | vb2_error_t vb2ex_ec_running_rw(int *in_rw) |
| 85 | { |
| 86 | *in_rw = 0; |
| 87 | return VB2_SUCCESS; |
| 88 | } |
| 89 | |
| 90 | __attribute__((weak)) |
| 91 | vb2_error_t vb2ex_ec_jump_to_rw(void) |
| 92 | { |
| 93 | return VB2_SUCCESS; |
| 94 | } |
| 95 | |
| 96 | __attribute__((weak)) |
| 97 | vb2_error_t vb2ex_ec_disable_jump(void) |
| 98 | { |
| 99 | return VB2_SUCCESS; |
| 100 | } |
| 101 | |
| 102 | __attribute__((weak)) |
| 103 | vb2_error_t vb2ex_ec_hash_image(enum vb2_firmware_selection select, |
| 104 | const uint8_t **hash, int *hash_size) |
| 105 | { |
| 106 | static const uint8_t fake_hash[32] = {1, 2, 3, 4}; |
| 107 | |
| 108 | *hash = fake_hash; |
| 109 | *hash_size = sizeof(fake_hash); |
| 110 | return VB2_SUCCESS; |
| 111 | } |
| 112 | |
| 113 | __attribute__((weak)) |
| 114 | vb2_error_t vb2ex_ec_get_expected_image_hash(enum vb2_firmware_selection select, |
| 115 | const uint8_t **hash, int *hash_size) |
| 116 | { |
| 117 | static const uint8_t fake_hash[32] = {1, 2, 3, 4}; |
| 118 | |
| 119 | *hash = fake_hash; |
| 120 | *hash_size = sizeof(fake_hash); |
| 121 | return VB2_SUCCESS; |
| 122 | } |
| 123 | |
| 124 | __attribute__((weak)) |
| 125 | vb2_error_t vb2ex_ec_update_image(enum vb2_firmware_selection select) |
| 126 | { |
| 127 | return VB2_SUCCESS; |
| 128 | } |
| 129 | |
| 130 | __attribute__((weak)) |
| 131 | vb2_error_t vb2ex_ec_protect(enum vb2_firmware_selection select) |
| 132 | { |
| 133 | return VB2_SUCCESS; |
| 134 | } |
| 135 | |
| 136 | __attribute__((weak)) |
| 137 | vb2_error_t vb2ex_ec_vboot_done(struct vb2_context *ctx) |
| 138 | { |
| 139 | return VB2_SUCCESS; |
| 140 | } |
| 141 | |
| 142 | __attribute__((weak)) |
| 143 | vb2_error_t vb2ex_ec_battery_cutoff(void) |
| 144 | { |
| 145 | return VB2_SUCCESS; |
| 146 | } |
| 147 | |
Joel Kitching | aaf3943 | 2019-09-11 14:15:45 +0800 | [diff] [blame] | 148 | __attribute__((weak)) |
Tim Wawrzynczak | 5d874c2 | 2019-10-22 15:36:59 -0600 | [diff] [blame] | 149 | vb2_error_t vb2ex_auxfw_check(enum vb2_auxfw_update_severity *severity) |
| 150 | { |
Joel Kitching | a5c13bc | 2020-09-24 17:13:31 +0800 | [diff] [blame] | 151 | *severity = VB2_AUXFW_NO_UPDATE; |
| 152 | return VB2_SUCCESS; |
Tim Wawrzynczak | 5d874c2 | 2019-10-22 15:36:59 -0600 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | __attribute__((weak)) |
| 156 | vb2_error_t vb2ex_auxfw_update(void) |
| 157 | { |
Joel Kitching | a5c13bc | 2020-09-24 17:13:31 +0800 | [diff] [blame] | 158 | return VB2_SUCCESS; |
Tim Wawrzynczak | 5d874c2 | 2019-10-22 15:36:59 -0600 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | __attribute__((weak)) |
| 162 | vb2_error_t vb2ex_auxfw_finalize(struct vb2_context *ctx) |
| 163 | { |
Joel Kitching | a5c13bc | 2020-09-24 17:13:31 +0800 | [diff] [blame] | 164 | return VB2_SUCCESS; |
Tim Wawrzynczak | 5d874c2 | 2019-10-22 15:36:59 -0600 | [diff] [blame] | 165 | } |
| 166 | |
Joel Kitching | 37ae620 | 2021-01-18 15:56:42 +0800 | [diff] [blame] | 167 | /*****************************************************************************/ |
| 168 | /* UI-related stubs */ |
| 169 | |
Hsuan Ting Chen | b92543c | 2020-06-19 13:28:06 +0800 | [diff] [blame] | 170 | __attribute__((weak)) |
| 171 | const char *vb2ex_get_debug_info(struct vb2_context *ctx) |
| 172 | { |
| 173 | return NULL; |
| 174 | } |
| 175 | |
| 176 | __attribute__((weak)) |
Hsuan Ting Chen | 4e5ce42 | 2020-09-15 15:30:00 +0800 | [diff] [blame] | 177 | const char *vb2ex_get_firmware_log(int reset) |
Hsuan Ting Chen | 8196d4e | 2020-07-30 13:52:34 +0800 | [diff] [blame] | 178 | { |
| 179 | return NULL; |
| 180 | } |
| 181 | |
| 182 | __attribute__((weak)) |
Yu-Ping Wu | abcd6d2 | 2020-11-06 11:24:22 +0800 | [diff] [blame] | 183 | uint32_t vb2ex_prepare_log_screen(enum vb2_screen screen, uint32_t locale_id, |
| 184 | const char *str) |
Hsuan Ting Chen | b92543c | 2020-06-19 13:28:06 +0800 | [diff] [blame] | 185 | { |
| 186 | return 1; |
| 187 | } |
Meng-Huan Yu | 2fb7683 | 2020-08-24 16:17:56 +0800 | [diff] [blame] | 188 | |
| 189 | __attribute__((weak)) |
Chung-Sheng Wu | cd77cd0 | 2021-02-25 13:54:20 +0800 | [diff] [blame] | 190 | vb2_error_t vb2ex_diag_get_storage_health(const char **out) |
Meng-Huan Yu | 2fb7683 | 2020-08-24 16:17:56 +0800 | [diff] [blame] | 191 | { |
Chung-Sheng Wu | cd77cd0 | 2021-02-25 13:54:20 +0800 | [diff] [blame] | 192 | *out = "mock"; |
| 193 | return VB2_SUCCESS; |
Meng-Huan Yu | 2fb7683 | 2020-08-24 16:17:56 +0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | __attribute__((weak)) |
| 197 | vb2_error_t vb2ex_diag_memory_quick_test(int reset, const char **out) |
| 198 | { |
| 199 | *out = "mock"; |
| 200 | return VB2_SUCCESS; |
| 201 | } |
| 202 | |
| 203 | __attribute__((weak)) |
| 204 | vb2_error_t vb2ex_diag_memory_full_test(int reset, const char **out) |
| 205 | { |
| 206 | *out = "mock"; |
| 207 | return VB2_SUCCESS; |
| 208 | } |
Joel Kitching | 37ae620 | 2021-01-18 15:56:42 +0800 | [diff] [blame] | 209 | |
| 210 | __attribute__((weak)) |
| 211 | void vb2ex_msleep(uint32_t msec) |
| 212 | { |
| 213 | } |
| 214 | |
| 215 | __attribute__((weak)) |
| 216 | void vb2ex_beep(uint32_t msec, uint32_t frequency) |
| 217 | { |
| 218 | } |
| 219 | |
| 220 | __attribute__((weak)) |
| 221 | uint32_t vb2ex_get_locale_count(void) |
| 222 | { |
| 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | __attribute__((weak)) |
Joel Kitching | 5b1e2e7 | 2021-01-20 17:54:15 +0800 | [diff] [blame] | 227 | uint32_t vb2ex_get_altfw_count(void) |
Joel Kitching | 37ae620 | 2021-01-18 15:56:42 +0800 | [diff] [blame] | 228 | { |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | __attribute__((weak)) |
| 233 | int vb2ex_physical_presence_pressed(void) |
| 234 | { |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | __attribute__((weak)) |
| 239 | vb2_error_t vb2ex_commit_data(struct vb2_context *ctx) |
| 240 | { |
| 241 | ctx->flags &= ~VB2_CONTEXT_SECDATA_FIRMWARE_CHANGED; |
| 242 | ctx->flags &= ~VB2_CONTEXT_SECDATA_KERNEL_CHANGED; |
| 243 | ctx->flags &= ~VB2_CONTEXT_NVDATA_CHANGED; |
| 244 | return VB2_SUCCESS; |
| 245 | } |