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 
20 static enum VbEcBootMode_t vboot_mode;
21 
VbExSleepMs(uint32_t msec)22 void VbExSleepMs(uint32_t msec)
23 {
24 }
25 
VbExBeep(uint32_t msec,uint32_t frequency)26 VbError_t VbExBeep(uint32_t msec, uint32_t frequency)
27 {
28 	return VBERROR_SUCCESS;
29 }
30 
VbExDisplayInit(uint32_t * width,uint32_t * height)31 VbError_t VbExDisplayInit(uint32_t *width, uint32_t *height)
32 {
33 	return VBERROR_SUCCESS;
34 }
35 
VbExDisplayBacklight(uint8_t enable)36 VbError_t VbExDisplayBacklight(uint8_t enable)
37 {
38 	return VBERROR_SUCCESS;
39 }
40 
VbExDisplaySetDimension(uint32_t width,uint32_t height)41 VbError_t VbExDisplaySetDimension(uint32_t width, uint32_t height)
42 {
43 	return VBERROR_SUCCESS;
44 }
45 
VbExDisplayScreen(uint32_t screen_type)46 VbError_t VbExDisplayScreen(uint32_t screen_type)
47 {
48 	return VBERROR_SUCCESS;
49 }
50 
VbExDisplayImage(uint32_t x,uint32_t y,void * buffer,uint32_t buffersize)51 VbError_t VbExDisplayImage(uint32_t x, uint32_t y,
52                            void *buffer, uint32_t buffersize)
53 {
54 	return VBERROR_SUCCESS;
55 }
56 
VbExDisplayDebugInfo(const char * info_str)57 VbError_t VbExDisplayDebugInfo(const char *info_str)
58 {
59 	return VBERROR_SUCCESS;
60 }
61 
VbExKeyboardRead(void)62 uint32_t VbExKeyboardRead(void)
63 {
64 	return 0;
65 }
66 
VbExKeyboardReadWithFlags(uint32_t * flags_ptr)67 uint32_t VbExKeyboardReadWithFlags(uint32_t *flags_ptr)
68 {
69 	return 0;
70 }
71 
VbExGetSwitches(uint32_t mask)72 uint32_t VbExGetSwitches(uint32_t mask)
73 {
74 	return 0;
75 }
76 
VbExIsShutdownRequested(void)77 uint32_t VbExIsShutdownRequested(void)
78 {
79 	return 0;
80 }
81 
VbExDecompress(void * inbuf,uint32_t in_size,uint32_t compression_type,void * outbuf,uint32_t * out_size)82 VbError_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 
VbExTrustEC(int devidx)89 int VbExTrustEC(int devidx)
90 {
91 	return 1;
92 }
93 
VbExEcRunningRW(int devidx,int * in_rw)94 VbError_t VbExEcRunningRW(int devidx, int *in_rw)
95 {
96 	*in_rw = 0;
97 	return VBERROR_SUCCESS;
98 }
99 
VbExEcJumpToRW(int devidx)100 VbError_t VbExEcJumpToRW(int devidx)
101 {
102 	return VBERROR_SUCCESS;
103 }
104 
VbExEcRebootToRO(int devidx)105 VbError_t VbExEcRebootToRO(int devidx)
106 {
107 	/* Nothing to reboot, so all we can do is return failure. */
108 	return VBERROR_UNKNOWN;
109 }
110 
VbExEcDisableJump(int devidx)111 VbError_t VbExEcDisableJump(int devidx)
112 {
113 	return VBERROR_SUCCESS;
114 }
115 
116 #define SHA256_HASH_SIZE 32
117 
VbExEcHashRW(int devidx,const uint8_t ** hash,int * hash_size)118 VbError_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 
VbExEcGetExpectedRW(int devidx,enum VbSelectFirmware_t select,const uint8_t ** image,int * image_size)127 VbError_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 
VbExEcGetExpectedRWHash(int devidx,enum VbSelectFirmware_t select,const uint8_t ** hash,int * hash_size)136 VbError_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 
VbExEcUpdateRW(int devidx,const uint8_t * image,int image_size)146 VbError_t VbExEcUpdateRW(int devidx, const uint8_t *image, int image_size)
147 {
148 	return VBERROR_SUCCESS;
149 }
150 
VbExEcProtectRW(int devidx)151 VbError_t VbExEcProtectRW(int devidx)
152 {
153 	return VBERROR_SUCCESS;
154 }
155 
VbExEcEnteringMode(int devidx,enum VbEcBootMode_t mode)156 VbError_t VbExEcEnteringMode(int devidx, enum VbEcBootMode_t mode)
157 {
158 	vboot_mode = mode;
159 	return VBERROR_SUCCESS;
160 }
161 
VbGetMode(void)162 enum VbEcBootMode_t VbGetMode(void)
163 {
164 	return vboot_mode;
165 }
166 
VbExLegacy(void)167 int VbExLegacy(void)
168 {
169 	return 1;
170 }
171