1/* Copyright (c) 2013 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 implementations of firmware-provided API functions.
6 */
7
8#include <stdint.h>
9
10#define _STUB_IMPLEMENTATION_
11
12#include <stdarg.h>
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16#include <sys/time.h>
17
18#include "vboot_api.h"
19
20static enum VbEcBootMode_t vboot_mode;
21
22void VbExSleepMs(uint32_t msec)
23{
24}
25
26VbError_t VbExBeep(uint32_t msec, uint32_t frequency)
27{
28	return VBERROR_SUCCESS;
29}
30
31VbError_t VbExDisplayInit(uint32_t *width, uint32_t *height)
32{
33	return VBERROR_SUCCESS;
34}
35
36VbError_t VbExDisplayBacklight(uint8_t enable)
37{
38	return VBERROR_SUCCESS;
39}
40
41VbError_t VbExDisplaySetDimension(uint32_t width, uint32_t height)
42{
43	return VBERROR_SUCCESS;
44}
45
46VbError_t VbExDisplayScreen(uint32_t screen_type)
47{
48	return VBERROR_SUCCESS;
49}
50
51VbError_t VbExDisplayImage(uint32_t x, uint32_t y,
52                           void *buffer, uint32_t buffersize)
53{
54	return VBERROR_SUCCESS;
55}
56
57VbError_t VbExDisplayDebugInfo(const char *info_str)
58{
59	return VBERROR_SUCCESS;
60}
61
62uint32_t VbExKeyboardRead(void)
63{
64	return 0;
65}
66
67uint32_t VbExKeyboardReadWithFlags(uint32_t *flags_ptr)
68{
69	return 0;
70}
71
72uint32_t VbExGetSwitches(uint32_t mask)
73{
74	return 0;
75}
76
77uint32_t VbExIsShutdownRequested(void)
78{
79	return 0;
80}
81
82VbError_t VbExDecompress(void *inbuf, uint32_t in_size,
83                         uint32_t compression_type,
84                         void *outbuf, uint32_t *out_size)
85{
86	return VBERROR_SUCCESS;
87}
88
89int VbExTrustEC(int devidx)
90{
91	return 1;
92}
93
94VbError_t VbExEcRunningRW(int devidx, int *in_rw)
95{
96	*in_rw = 0;
97	return VBERROR_SUCCESS;
98}
99
100VbError_t VbExEcJumpToRW(int devidx)
101{
102	return VBERROR_SUCCESS;
103}
104
105VbError_t VbExEcRebootToRO(int devidx)
106{
107	/* Nothing to reboot, so all we can do is return failure. */
108	return VBERROR_UNKNOWN;
109}
110
111VbError_t VbExEcDisableJump(int devidx)
112{
113	return VBERROR_SUCCESS;
114}
115
116#define SHA256_HASH_SIZE 32
117
118VbError_t VbExEcHashRW(int devidx, const uint8_t **hash, int *hash_size)
119{
120	static const uint8_t fake_hash[32] = {1, 2, 3, 4};
121
122	*hash = fake_hash;
123	*hash_size = sizeof(fake_hash);
124	return VBERROR_SUCCESS;
125}
126
127VbError_t VbExEcGetExpectedRW(int devidx, enum VbSelectFirmware_t select,
128                              const uint8_t **image, int *image_size)
129{
130	static uint8_t fake_image[64] = {5, 6, 7, 8};
131	*image = fake_image;
132	*image_size = sizeof(fake_image);
133	return VBERROR_SUCCESS;
134}
135
136VbError_t VbExEcGetExpectedRWHash(int devidx, enum VbSelectFirmware_t select,
137				  const uint8_t **hash, int *hash_size)
138{
139	static const uint8_t fake_hash[32] = {1, 2, 3, 4};
140
141	*hash = fake_hash;
142	*hash_size = sizeof(fake_hash);
143	return VBERROR_SUCCESS;
144}
145
146VbError_t VbExEcUpdateRW(int devidx, const uint8_t *image, int image_size)
147{
148	return VBERROR_SUCCESS;
149}
150
151VbError_t VbExEcProtectRW(int devidx)
152{
153	return VBERROR_SUCCESS;
154}
155
156VbError_t VbExEcEnteringMode(int devidx, enum VbEcBootMode_t mode)
157{
158	vboot_mode = mode;
159	return VBERROR_SUCCESS;
160}
161
162enum VbEcBootMode_t VbGetMode(void)
163{
164	return vboot_mode;
165}
166
167int VbExLegacy(void)
168{
169	return 1;
170}
171