ec_sync_all.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. * EC software sync routines for vboot
  6. */
  7. #include "2sysincludes.h"
  8. #include "2common.h"
  9. #include "2misc.h"
  10. #include "2nvstorage.h"
  11. #include "sysincludes.h"
  12. #include "ec_sync.h"
  13. #include "vboot_api.h"
  14. #include "vboot_common.h"
  15. #include "vboot_display.h"
  16. #include "vboot_kernel.h"
  17. VbError_t ec_sync_all(struct vb2_context *ctx, struct VbCommonParams *cparams)
  18. {
  19. VbSharedDataHeader *shared =
  20. (VbSharedDataHeader *)cparams->shared_data_blob;
  21. /* Do EC sync phase 1; this determines if we need an update */
  22. VbError_t phase1_rv = ec_sync_phase1(ctx, cparams);
  23. int need_wait_screen = ec_will_update_slowly(ctx, cparams);
  24. /*
  25. * Check if we need to reboot to load the VGA Option ROM before we can
  26. * display the WAIT screen.
  27. *
  28. * Do this before we check if ec_sync_phase1() requires a reboot for
  29. * some other reason, since there's no reason to reboot twice.
  30. */
  31. int reboot_for_oprom = (need_wait_screen &&
  32. shared->flags & VBSD_OPROM_MATTERS &&
  33. !(shared->flags & VBSD_OPROM_LOADED));
  34. if (reboot_for_oprom) {
  35. VB2_DEBUG("Reboot to load VGA Option ROM\n");
  36. vb2_nv_set(ctx, VB2_NV_OPROM_NEEDED, 1);
  37. }
  38. /* Reboot if phase 1 needed it, or if we need to load VGA Option ROM */
  39. if (phase1_rv)
  40. return VBERROR_EC_REBOOT_TO_RO_REQUIRED;
  41. if (reboot_for_oprom)
  42. return VBERROR_VGA_OPROM_MISMATCH;
  43. /* Display the wait screen if we need it */
  44. if (need_wait_screen) {
  45. VB2_DEBUG("EC is slow. Show WAIT screen.\n");
  46. VbDisplayScreen(ctx, cparams, VB_SCREEN_WAIT, 0);
  47. }
  48. /*
  49. * Do EC sync phase 2; this applies the update and/or jumps to the
  50. * correct EC image.
  51. */
  52. VbError_t rv = ec_sync_phase2(ctx, cparams);
  53. if (rv)
  54. return rv;
  55. /*
  56. * Reboot to unload VGA Option ROM if:
  57. * - we displayed the wait screen
  58. * - the system has slow EC update flag set
  59. * - the VGA Option ROM was needed and loaded
  60. * - the system is NOT in developer mode (that'll also need the ROM)
  61. */
  62. if (need_wait_screen &&
  63. (shared->flags & VBSD_OPROM_MATTERS) &&
  64. (shared->flags & VBSD_OPROM_LOADED) &&
  65. !(shared->flags & VBSD_BOOT_DEV_SWITCH_ON)) {
  66. VB2_DEBUG("Reboot to unload VGA Option ROM\n");
  67. vb2_nv_set(ctx, VB2_NV_OPROM_NEEDED, 0);
  68. return VBERROR_VGA_OPROM_MISMATCH;
  69. }
  70. /* Do EC sync phase 3; this completes synd and handles battery cutoff */
  71. rv = ec_sync_phase3(ctx, cparams);
  72. if (rv)
  73. return rv;
  74. return VBERROR_SUCCESS;
  75. }