blob: e26390dc19063dd1a4b786f1f0065a32498ae559 [file] [log] [blame]
Randall Spangler93943262013-02-26 11:03:57 -08001/* 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
Randall Spangler93943262013-02-26 11:03:57 -08008
9#include <stdarg.h>
Randall Spangler559a1102016-10-18 14:41:22 -070010#include <stdint.h>
Randall Spangler93943262013-02-26 11:03:57 -080011#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14#include <sys/time.h>
15
16#include "vboot_api.h"
17
Randall Spangler93943262013-02-26 11:03:57 -080018/* U-Boot's printf uses '%L' for uint64_t. gcc uses '%l'. */
19#define MAX_FMT 255
20static char fmtbuf[MAX_FMT+1];
21
22static const char *fixfmt(const char *format)
23{
24 int i;
Randall Spangler1589f942016-09-02 12:10:31 -070025 for(i=0; i<sizeof(fmtbuf)-1 && format[i]; i++) {
Randall Spangler93943262013-02-26 11:03:57 -080026 fmtbuf[i] = format[i];
27 if(format[i] == '%' && format[i+1] == 'L') {
28 fmtbuf[i+1] = 'l';
29 i++;
30 }
31 }
32 fmtbuf[i] = '\0';
33 return fmtbuf;
34}
35
36void VbExError(const char *format, ...)
37{
38 va_list ap;
39 va_start(ap, format);
40 fprintf(stderr, "ERROR: ");
41 vfprintf(stderr, fixfmt(format), ap);
42 va_end(ap);
43 exit(1);
44}
45
46void VbExDebug(const char *format, ...)
47{
48 va_list ap;
49 va_start(ap, format);
50 fprintf(stderr, "DEBUG: ");
51 vfprintf(stderr, fixfmt(format), ap);
52 va_end(ap);
53}
54
55uint64_t VbExGetTimer(void)
56{
57 struct timeval tv;
58 gettimeofday(&tv, NULL);
59 return (uint64_t)tv.tv_sec * 1000000 + (uint64_t)tv.tv_usec;
60}
61
Yunlian Jiang637ff032015-06-09 16:21:56 -070062VbError_t test_mockable VbExNvStorageRead(uint8_t *buf)
Randall Spangler93943262013-02-26 11:03:57 -080063{
64 return VBERROR_SUCCESS;
65}
66
67VbError_t VbExNvStorageWrite(const uint8_t *buf)
68{
69 return VBERROR_SUCCESS;
70}