vboot_api_stub_init.c 1.4 KB

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