blob: 1454f77e1b5a619b48a736c927f7519574c932bf [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>
11
Randall Spanglerda2b49c2014-06-10 17:03:40 -070012#include "2api.h"
Joel Kitchingffd42a82019-08-29 13:58:52 +080013#include "2sysincludes.h"
Randall Spanglerda2b49c2014-06-10 17:03:40 -070014
Julius Wernerf10e9092014-12-16 19:24:54 -080015__attribute__((weak))
Bill Richardson40890c52015-01-26 13:48:32 -080016void vb2ex_printf(const char *func, const char *fmt, ...)
17{
Julius Werner5160e692019-03-05 13:56:41 -080018#ifdef VBOOT_DEBUG
Bill Richardson40890c52015-01-26 13:48:32 -080019 va_list ap;
20 va_start(ap, fmt);
Randall Spanglera6094782017-01-20 14:54:47 -080021 if (func)
22 fprintf(stderr, "%s: ", func);
Bill Richardson40890c52015-01-26 13:48:32 -080023 vfprintf(stderr, fmt, ap);
24 va_end(ap);
Julius Werner5160e692019-03-05 13:56:41 -080025#endif
Bill Richardson40890c52015-01-26 13:48:32 -080026}
27
28__attribute__((weak))
Joel Kitchingb1395172021-01-18 16:05:19 +080029void vb2ex_abort(void)
30{
31 /* Stub simply exits. */
32 abort();
33}
34
35__attribute__((weak))
Joel Kitchinge6700f42019-07-31 14:12:30 +080036vb2_error_t vb2ex_tpm_clear_owner(struct vb2_context *ctx)
Randall Spanglerda2b49c2014-06-10 17:03:40 -070037{
Joel Kitching231112a2019-04-25 18:16:06 +080038 fprintf(stderr, "%s: function not implemented\n", __func__);
Joel Kitchinga1df89d2018-12-03 14:39:57 +080039 return VB2_ERROR_EX_UNIMPLEMENTED;
Randall Spanglerda2b49c2014-06-10 17:03:40 -070040}
41
Julius Wernerf10e9092014-12-16 19:24:54 -080042__attribute__((weak))
Joel Kitchinge6700f42019-07-31 14:12:30 +080043vb2_error_t vb2ex_read_resource(struct vb2_context *ctx,
44 enum vb2_resource_index index, uint32_t offset,
45 void *buf, uint32_t size)
Randall Spanglerda2b49c2014-06-10 17:03:40 -070046{
Joel Kitching231112a2019-04-25 18:16:06 +080047 fprintf(stderr, "%s: function not implemented\n", __func__);
Joel Kitchinga1df89d2018-12-03 14:39:57 +080048 return VB2_ERROR_EX_UNIMPLEMENTED;
Randall Spanglerda2b49c2014-06-10 17:03:40 -070049}
Julius Wernerf10e9092014-12-16 19:24:54 -080050
51__attribute__((weak))
Joel Kitchinge6700f42019-07-31 14:12:30 +080052vb2_error_t vb2ex_tpm_set_mode(enum vb2_tpm_mode mode_val)
Matt Delco08bf6802019-02-13 15:54:24 -080053{
Joel Kitching231112a2019-04-25 18:16:06 +080054 fprintf(stderr, "%s: function not implemented\n", __func__);
Joel Kitchinga1df89d2018-12-03 14:39:57 +080055 return VB2_ERROR_EX_UNIMPLEMENTED;
Matt Delco08bf6802019-02-13 15:54:24 -080056}
Joel Kitchingaaf39432019-09-11 14:15:45 +080057
Joel Kitchingb1395172021-01-18 16:05:19 +080058/*****************************************************************************/
59/* auxfw and EC-related stubs */
60
61__attribute__((weak))
62int vb2ex_ec_trusted(void)
63{
64 return 1;
65}
66
67__attribute__((weak))
68vb2_error_t vb2ex_ec_running_rw(int *in_rw)
69{
70 *in_rw = 0;
71 return VB2_SUCCESS;
72}
73
74__attribute__((weak))
75vb2_error_t vb2ex_ec_jump_to_rw(void)
76{
77 return VB2_SUCCESS;
78}
79
80__attribute__((weak))
81vb2_error_t vb2ex_ec_disable_jump(void)
82{
83 return VB2_SUCCESS;
84}
85
86__attribute__((weak))
87vb2_error_t vb2ex_ec_hash_image(enum vb2_firmware_selection select,
88 const uint8_t **hash, int *hash_size)
89{
90 static const uint8_t fake_hash[32] = {1, 2, 3, 4};
91
92 *hash = fake_hash;
93 *hash_size = sizeof(fake_hash);
94 return VB2_SUCCESS;
95}
96
97__attribute__((weak))
98vb2_error_t vb2ex_ec_get_expected_image_hash(enum vb2_firmware_selection select,
99 const uint8_t **hash, int *hash_size)
100{
101 static const uint8_t fake_hash[32] = {1, 2, 3, 4};
102
103 *hash = fake_hash;
104 *hash_size = sizeof(fake_hash);
105 return VB2_SUCCESS;
106}
107
108__attribute__((weak))
109vb2_error_t vb2ex_ec_update_image(enum vb2_firmware_selection select)
110{
111 return VB2_SUCCESS;
112}
113
114__attribute__((weak))
115vb2_error_t vb2ex_ec_protect(enum vb2_firmware_selection select)
116{
117 return VB2_SUCCESS;
118}
119
120__attribute__((weak))
121vb2_error_t vb2ex_ec_vboot_done(struct vb2_context *ctx)
122{
123 return VB2_SUCCESS;
124}
125
126__attribute__((weak))
127vb2_error_t vb2ex_ec_battery_cutoff(void)
128{
129 return VB2_SUCCESS;
130}
131
Joel Kitchingaaf39432019-09-11 14:15:45 +0800132__attribute__((weak))
Tim Wawrzynczak5d874c22019-10-22 15:36:59 -0600133vb2_error_t vb2ex_auxfw_check(enum vb2_auxfw_update_severity *severity)
134{
Joel Kitchinga5c13bc2020-09-24 17:13:31 +0800135 *severity = VB2_AUXFW_NO_UPDATE;
136 return VB2_SUCCESS;
Tim Wawrzynczak5d874c22019-10-22 15:36:59 -0600137}
138
139__attribute__((weak))
140vb2_error_t vb2ex_auxfw_update(void)
141{
Joel Kitchinga5c13bc2020-09-24 17:13:31 +0800142 return VB2_SUCCESS;
Tim Wawrzynczak5d874c22019-10-22 15:36:59 -0600143}
144
145__attribute__((weak))
146vb2_error_t vb2ex_auxfw_finalize(struct vb2_context *ctx)
147{
Joel Kitchinga5c13bc2020-09-24 17:13:31 +0800148 return VB2_SUCCESS;
Tim Wawrzynczak5d874c22019-10-22 15:36:59 -0600149}
150
Joel Kitching37ae6202021-01-18 15:56:42 +0800151/*****************************************************************************/
152/* UI-related stubs */
153
Hsuan Ting Chenb92543c2020-06-19 13:28:06 +0800154__attribute__((weak))
155const char *vb2ex_get_debug_info(struct vb2_context *ctx)
156{
157 return NULL;
158}
159
160__attribute__((weak))
Hsuan Ting Chen4e5ce422020-09-15 15:30:00 +0800161const char *vb2ex_get_firmware_log(int reset)
Hsuan Ting Chen8196d4e2020-07-30 13:52:34 +0800162{
163 return NULL;
164}
165
166__attribute__((weak))
Yu-Ping Wuabcd6d22020-11-06 11:24:22 +0800167uint32_t vb2ex_prepare_log_screen(enum vb2_screen screen, uint32_t locale_id,
168 const char *str)
Hsuan Ting Chenb92543c2020-06-19 13:28:06 +0800169{
170 return 1;
171}
Meng-Huan Yu2fb76832020-08-24 16:17:56 +0800172
173__attribute__((weak))
174const char *vb2ex_get_diagnostic_storage(void)
175{
176 return "mock";
177}
178
179__attribute__((weak))
180vb2_error_t vb2ex_diag_memory_quick_test(int reset, const char **out)
181{
182 *out = "mock";
183 return VB2_SUCCESS;
184}
185
186__attribute__((weak))
187vb2_error_t vb2ex_diag_memory_full_test(int reset, const char **out)
188{
189 *out = "mock";
190 return VB2_SUCCESS;
191}
Joel Kitching37ae6202021-01-18 15:56:42 +0800192
193__attribute__((weak))
194void vb2ex_msleep(uint32_t msec)
195{
196}
197
198__attribute__((weak))
199void vb2ex_beep(uint32_t msec, uint32_t frequency)
200{
201}
202
203__attribute__((weak))
204uint32_t vb2ex_get_locale_count(void)
205{
206 return 0;
207}
208
209__attribute__((weak))
210uint32_t vb2ex_get_bootloader_count(void)
211{
212 return 0;
213}
214
215__attribute__((weak))
216int vb2ex_physical_presence_pressed(void)
217{
218 return 0;
219}
220
221__attribute__((weak))
222vb2_error_t vb2ex_commit_data(struct vb2_context *ctx)
223{
224 ctx->flags &= ~VB2_CONTEXT_SECDATA_FIRMWARE_CHANGED;
225 ctx->flags &= ~VB2_CONTEXT_SECDATA_KERNEL_CHANGED;
226 ctx->flags &= ~VB2_CONTEXT_NVDATA_CHANGED;
227 return VB2_SUCCESS;
228}