blob: 7cec2e5d46698b521c2e3db5f45e69d45852d52d [file] [log] [blame]
Randall Spanglerda2b49c2014-06-10 17:03:40 -07001/* 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 Richardson40890c52015-01-26 13:48:32 -08008#include <stdarg.h>
Julius Wernerac15a152020-09-01 15:31:14 -07009#include <stdlib.h>
Bill Richardson40890c52015-01-26 13:48:32 -080010#include <stdio.h>
Joel Kitchingc768a702021-01-18 16:11:13 +080011#include <sys/time.h>
Bill Richardson40890c52015-01-26 13:48:32 -080012
Randall Spanglerda2b49c2014-06-10 17:03:40 -070013#include "2api.h"
Joel Kitchingc768a702021-01-18 16:11:13 +080014#include "2common.h"
Joel Kitchingffd42a82019-08-29 13:58:52 +080015#include "2sysincludes.h"
Randall Spanglerda2b49c2014-06-10 17:03:40 -070016
Joel Kitchingc768a702021-01-18 16:11:13 +080017/*****************************************************************************/
18/* General utility stubs */
19
Julius Wernerf10e9092014-12-16 19:24:54 -080020__attribute__((weak))
Bill Richardson40890c52015-01-26 13:48:32 -080021void vb2ex_printf(const char *func, const char *fmt, ...)
22{
Julius Werner5160e692019-03-05 13:56:41 -080023#ifdef VBOOT_DEBUG
Bill Richardson40890c52015-01-26 13:48:32 -080024 va_list ap;
25 va_start(ap, fmt);
Randall Spanglera6094782017-01-20 14:54:47 -080026 if (func)
27 fprintf(stderr, "%s: ", func);
Bill Richardson40890c52015-01-26 13:48:32 -080028 vfprintf(stderr, fmt, ap);
29 va_end(ap);
Julius Werner5160e692019-03-05 13:56:41 -080030#endif
Bill Richardson40890c52015-01-26 13:48:32 -080031}
32
33__attribute__((weak))
Joel Kitchingb1395172021-01-18 16:05:19 +080034void vb2ex_abort(void)
35{
36 /* Stub simply exits. */
37 abort();
38}
39
40__attribute__((weak))
Joel Kitchingc768a702021-01-18 16:11:13 +080041uint32_t vb2ex_mtime(void)
Randall Spanglerda2b49c2014-06-10 17:03:40 -070042{
Joel Kitchingc768a702021-01-18 16:11:13 +080043 struct timeval tv;
44 gettimeofday(&tv, NULL);
45 return tv.tv_sec * VB2_MSEC_PER_SEC + tv.tv_usec / VB2_USEC_PER_MSEC;
Randall Spanglerda2b49c2014-06-10 17:03:40 -070046}
47
Julius Wernerf10e9092014-12-16 19:24:54 -080048__attribute__((weak))
Joel Kitchinge6700f42019-07-31 14:12:30 +080049vb2_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 Spanglerda2b49c2014-06-10 17:03:40 -070052{
Joel Kitching231112a2019-04-25 18:16:06 +080053 fprintf(stderr, "%s: function not implemented\n", __func__);
Joel Kitchinga1df89d2018-12-03 14:39:57 +080054 return VB2_ERROR_EX_UNIMPLEMENTED;
Randall Spanglerda2b49c2014-06-10 17:03:40 -070055}
Julius Wernerf10e9092014-12-16 19:24:54 -080056
Joel Kitchingc768a702021-01-18 16:11:13 +080057/*****************************************************************************/
58/* TPM-related stubs */
59
60__attribute__((weak))
61vb2_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 Wernerf10e9092014-12-16 19:24:54 -080067__attribute__((weak))
Joel Kitchinge6700f42019-07-31 14:12:30 +080068vb2_error_t vb2ex_tpm_set_mode(enum vb2_tpm_mode mode_val)
Matt Delco08bf6802019-02-13 15:54:24 -080069{
Joel Kitching231112a2019-04-25 18:16:06 +080070 fprintf(stderr, "%s: function not implemented\n", __func__);
Joel Kitchinga1df89d2018-12-03 14:39:57 +080071 return VB2_ERROR_EX_UNIMPLEMENTED;
Matt Delco08bf6802019-02-13 15:54:24 -080072}
Joel Kitchingaaf39432019-09-11 14:15:45 +080073
Joel Kitchingb1395172021-01-18 16:05:19 +080074/*****************************************************************************/
75/* auxfw and EC-related stubs */
76
77__attribute__((weak))
78int vb2ex_ec_trusted(void)
79{
80 return 1;
81}
82
83__attribute__((weak))
84vb2_error_t vb2ex_ec_running_rw(int *in_rw)
85{
86 *in_rw = 0;
87 return VB2_SUCCESS;
88}
89
90__attribute__((weak))
91vb2_error_t vb2ex_ec_jump_to_rw(void)
92{
93 return VB2_SUCCESS;
94}
95
96__attribute__((weak))
97vb2_error_t vb2ex_ec_disable_jump(void)
98{
99 return VB2_SUCCESS;
100}
101
102__attribute__((weak))
103vb2_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))
114vb2_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))
125vb2_error_t vb2ex_ec_update_image(enum vb2_firmware_selection select)
126{
127 return VB2_SUCCESS;
128}
129
130__attribute__((weak))
131vb2_error_t vb2ex_ec_protect(enum vb2_firmware_selection select)
132{
133 return VB2_SUCCESS;
134}
135
136__attribute__((weak))
137vb2_error_t vb2ex_ec_vboot_done(struct vb2_context *ctx)
138{
139 return VB2_SUCCESS;
140}
141
142__attribute__((weak))
143vb2_error_t vb2ex_ec_battery_cutoff(void)
144{
145 return VB2_SUCCESS;
146}
147
Joel Kitchingaaf39432019-09-11 14:15:45 +0800148__attribute__((weak))
Tim Wawrzynczak5d874c22019-10-22 15:36:59 -0600149vb2_error_t vb2ex_auxfw_check(enum vb2_auxfw_update_severity *severity)
150{
Joel Kitchinga5c13bc2020-09-24 17:13:31 +0800151 *severity = VB2_AUXFW_NO_UPDATE;
152 return VB2_SUCCESS;
Tim Wawrzynczak5d874c22019-10-22 15:36:59 -0600153}
154
155__attribute__((weak))
156vb2_error_t vb2ex_auxfw_update(void)
157{
Joel Kitchinga5c13bc2020-09-24 17:13:31 +0800158 return VB2_SUCCESS;
Tim Wawrzynczak5d874c22019-10-22 15:36:59 -0600159}
160
161__attribute__((weak))
162vb2_error_t vb2ex_auxfw_finalize(struct vb2_context *ctx)
163{
Joel Kitchinga5c13bc2020-09-24 17:13:31 +0800164 return VB2_SUCCESS;
Tim Wawrzynczak5d874c22019-10-22 15:36:59 -0600165}
166
Joel Kitching37ae6202021-01-18 15:56:42 +0800167/*****************************************************************************/
168/* UI-related stubs */
169
Hsuan Ting Chenb92543c2020-06-19 13:28:06 +0800170__attribute__((weak))
171const char *vb2ex_get_debug_info(struct vb2_context *ctx)
172{
173 return NULL;
174}
175
176__attribute__((weak))
Hsuan Ting Chen4e5ce422020-09-15 15:30:00 +0800177const char *vb2ex_get_firmware_log(int reset)
Hsuan Ting Chen8196d4e2020-07-30 13:52:34 +0800178{
179 return NULL;
180}
181
182__attribute__((weak))
Yu-Ping Wuabcd6d22020-11-06 11:24:22 +0800183uint32_t vb2ex_prepare_log_screen(enum vb2_screen screen, uint32_t locale_id,
184 const char *str)
Hsuan Ting Chenb92543c2020-06-19 13:28:06 +0800185{
186 return 1;
187}
Meng-Huan Yu2fb76832020-08-24 16:17:56 +0800188
189__attribute__((weak))
Chung-Sheng Wucd77cd02021-02-25 13:54:20 +0800190vb2_error_t vb2ex_diag_get_storage_health(const char **out)
Meng-Huan Yu2fb76832020-08-24 16:17:56 +0800191{
Chung-Sheng Wucd77cd02021-02-25 13:54:20 +0800192 *out = "mock";
193 return VB2_SUCCESS;
Meng-Huan Yu2fb76832020-08-24 16:17:56 +0800194}
195
196__attribute__((weak))
Chung-Sheng Wu6f3c57f2021-02-25 13:57:28 +0800197vb2_error_t vb2ex_diag_get_storage_test_log(const char **out)
198{
199 *out = "mock";
200 return VB2_SUCCESS;
201}
202
203__attribute__((weak))
204vb2_error_t vb2ex_diag_storage_test_control(enum vb2_diag_storage_test ops)
205{
206 return VB2_SUCCESS;
207}
208
209__attribute__((weak))
Meng-Huan Yu2fb76832020-08-24 16:17:56 +0800210vb2_error_t vb2ex_diag_memory_quick_test(int reset, const char **out)
211{
212 *out = "mock";
213 return VB2_SUCCESS;
214}
215
216__attribute__((weak))
217vb2_error_t vb2ex_diag_memory_full_test(int reset, const char **out)
218{
219 *out = "mock";
220 return VB2_SUCCESS;
221}
Joel Kitching37ae6202021-01-18 15:56:42 +0800222
223__attribute__((weak))
224void vb2ex_msleep(uint32_t msec)
225{
226}
227
228__attribute__((weak))
229void vb2ex_beep(uint32_t msec, uint32_t frequency)
230{
231}
232
233__attribute__((weak))
234uint32_t vb2ex_get_locale_count(void)
235{
236 return 0;
237}
238
239__attribute__((weak))
Joel Kitching5b1e2e72021-01-20 17:54:15 +0800240uint32_t vb2ex_get_altfw_count(void)
Joel Kitching37ae6202021-01-18 15:56:42 +0800241{
242 return 0;
243}
244
245__attribute__((weak))
246int vb2ex_physical_presence_pressed(void)
247{
248 return 0;
249}
250
251__attribute__((weak))
252vb2_error_t vb2ex_commit_data(struct vb2_context *ctx)
253{
254 ctx->flags &= ~VB2_CONTEXT_SECDATA_FIRMWARE_CHANGED;
255 ctx->flags &= ~VB2_CONTEXT_SECDATA_KERNEL_CHANGED;
256 ctx->flags &= ~VB2_CONTEXT_NVDATA_CHANGED;
257 return VB2_SUCCESS;
258}