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 /* U-Boot's printf uses '%L' for uint64_t. gcc uses '%l'. */
21 #define MAX_FMT 255
22 static char fmtbuf[MAX_FMT+1];
23
fixfmt(const char * format)24 static const char *fixfmt(const char *format)
25 {
26 int i;
27 for(i=0; i<MAX_FMT && format[i]; i++) {
28 fmtbuf[i] = format[i];
29 if(format[i] == '%' && format[i+1] == 'L') {
30 fmtbuf[i+1] = 'l';
31 i++;
32 }
33 }
34 fmtbuf[i] = '\0';
35 return fmtbuf;
36 }
37
VbExError(const char * format,...)38 void VbExError(const char *format, ...)
39 {
40 va_list ap;
41 va_start(ap, format);
42 fprintf(stderr, "ERROR: ");
43 vfprintf(stderr, fixfmt(format), ap);
44 va_end(ap);
45 exit(1);
46 }
47
VbExDebug(const char * format,...)48 void VbExDebug(const char *format, ...)
49 {
50 va_list ap;
51 va_start(ap, format);
52 fprintf(stderr, "DEBUG: ");
53 vfprintf(stderr, fixfmt(format), ap);
54 va_end(ap);
55 }
56
VbExGetTimer(void)57 uint64_t VbExGetTimer(void)
58 {
59 struct timeval tv;
60 gettimeofday(&tv, NULL);
61 return (uint64_t)tv.tv_sec * 1000000 + (uint64_t)tv.tv_usec;
62 }
63
VbExNvStorageRead(uint8_t * buf)64 VbError_t VbExNvStorageRead(uint8_t *buf)
65 {
66 return VBERROR_SUCCESS;
67 }
68
VbExNvStorageWrite(const uint8_t * buf)69 VbError_t VbExNvStorageWrite(const uint8_t *buf)
70 {
71 return VBERROR_SUCCESS;
72 }
73