BdsEntry.c revision a2b35995cac983b676296fcb95fde0e9121319f6
15c08e1173703234cc2913757f237ee916087498aklu/** @file
25c08e1173703234cc2913757f237ee916087498aklu  This module produce main entry for BDS phase - BdsEntry.
35c08e1173703234cc2913757f237ee916087498aklu  When this module was dispatched by DxeCore, gEfiBdsArchProtocolGuid will be installed
45c08e1173703234cc2913757f237ee916087498aklu  which contains interface of BdsEntry.
55c08e1173703234cc2913757f237ee916087498aklu  After DxeCore finish DXE phase, gEfiBdsArchProtocolGuid->BdsEntry will be invoked
65c08e1173703234cc2913757f237ee916087498aklu  to enter BDS phase.
75c08e1173703234cc2913757f237ee916087498aklu
85c08e1173703234cc2913757f237ee916087498akluCopyright (c) 2004 - 2008, Intel Corporation. <BR>
95c08e1173703234cc2913757f237ee916087498akluAll rights reserved. This program and the accompanying materials
105c08e1173703234cc2913757f237ee916087498akluare licensed and made available under the terms and conditions of the BSD License
115c08e1173703234cc2913757f237ee916087498akluwhich accompanies this distribution.  The full text of the license may be found at
125c08e1173703234cc2913757f237ee916087498akluhttp://opensource.org/licenses/bsd-license.php
135c08e1173703234cc2913757f237ee916087498aklu
145c08e1173703234cc2913757f237ee916087498akluTHE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
155c08e1173703234cc2913757f237ee916087498akluWITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
165c08e1173703234cc2913757f237ee916087498aklu
175c08e1173703234cc2913757f237ee916087498aklu**/
185c08e1173703234cc2913757f237ee916087498aklu
195c08e1173703234cc2913757f237ee916087498aklu#include "Bds.h"
205c08e1173703234cc2913757f237ee916087498aklu#include "Language.h"
215c08e1173703234cc2913757f237ee916087498aklu#include "FrontPage.h"
225c08e1173703234cc2913757f237ee916087498aklu#include "Hotkey.h"
235c08e1173703234cc2913757f237ee916087498aklu#include "HwErrRecSupport.h"
245c08e1173703234cc2913757f237ee916087498aklu
255c08e1173703234cc2913757f237ee916087498aklu///
265c08e1173703234cc2913757f237ee916087498aklu/// BDS arch protocol instance initial value.
275c08e1173703234cc2913757f237ee916087498aklu///
285c08e1173703234cc2913757f237ee916087498aklu/// Note: Current BDS not directly get the BootMode, DefaultBoot,
295c08e1173703234cc2913757f237ee916087498aklu/// TimeoutDefault, MemoryTestLevel value from the BDS arch protocol.
305c08e1173703234cc2913757f237ee916087498aklu/// Please refer to the library useage of BdsLibGetBootMode, BdsLibGetTimeout
315c08e1173703234cc2913757f237ee916087498aklu/// and PlatformBdsDiagnostics in BdsPlatform.c
325c08e1173703234cc2913757f237ee916087498aklu///
335c08e1173703234cc2913757f237ee916087498akluEFI_BDS_ARCH_PROTOCOL_INSTANCE  gBdsInstanceTemplate = {
345c08e1173703234cc2913757f237ee916087498aklu  EFI_BDS_ARCH_PROTOCOL_INSTANCE_SIGNATURE,
355c08e1173703234cc2913757f237ee916087498aklu  NULL,
365c08e1173703234cc2913757f237ee916087498aklu  {BdsEntry},
375c08e1173703234cc2913757f237ee916087498aklu  0xFFFF,
385c08e1173703234cc2913757f237ee916087498aklu  TRUE,
395c08e1173703234cc2913757f237ee916087498aklu  0,
405c08e1173703234cc2913757f237ee916087498aklu  EXTENSIVE
415c08e1173703234cc2913757f237ee916087498aklu};
425c08e1173703234cc2913757f237ee916087498aklu
435c08e1173703234cc2913757f237ee916087498akluUINT16                          *mBootNext = NULL;
445c08e1173703234cc2913757f237ee916087498aklu
455c08e1173703234cc2913757f237ee916087498akluEFI_HANDLE                      mBdsImageHandle;
465c08e1173703234cc2913757f237ee916087498aklu
475c08e1173703234cc2913757f237ee916087498aklu/**
485c08e1173703234cc2913757f237ee916087498aklu
495c08e1173703234cc2913757f237ee916087498aklu  Install Boot Device Selection Protocol
505c08e1173703234cc2913757f237ee916087498aklu
515c08e1173703234cc2913757f237ee916087498aklu  @param ImageHandle     The image handle.
525c08e1173703234cc2913757f237ee916087498aklu  @param SystemTable     The system table.
535c08e1173703234cc2913757f237ee916087498aklu
545c08e1173703234cc2913757f237ee916087498aklu  @retval  EFI_SUCEESS  BDS has finished initializing.
555c08e1173703234cc2913757f237ee916087498aklu                        Return the dispatcher and recall BDS.Entry
565c08e1173703234cc2913757f237ee916087498aklu  @retval  Other        Return status from AllocatePool() or gBS->InstallProtocolInterface
575c08e1173703234cc2913757f237ee916087498aklu
585c08e1173703234cc2913757f237ee916087498aklu**/
595c08e1173703234cc2913757f237ee916087498akluEFI_STATUS
605c08e1173703234cc2913757f237ee916087498akluEFIAPI
615c08e1173703234cc2913757f237ee916087498akluBdsInitialize (
625c08e1173703234cc2913757f237ee916087498aklu  IN EFI_HANDLE                            ImageHandle,
635c08e1173703234cc2913757f237ee916087498aklu  IN EFI_SYSTEM_TABLE                      *SystemTable
645c08e1173703234cc2913757f237ee916087498aklu  )
655c08e1173703234cc2913757f237ee916087498aklu{
665c08e1173703234cc2913757f237ee916087498aklu  EFI_STATUS  Status;
675c08e1173703234cc2913757f237ee916087498aklu
685c08e1173703234cc2913757f237ee916087498aklu  mBdsImageHandle = ImageHandle;
695c08e1173703234cc2913757f237ee916087498aklu
705c08e1173703234cc2913757f237ee916087498aklu  //
715c08e1173703234cc2913757f237ee916087498aklu  // Install protocol interface
725c08e1173703234cc2913757f237ee916087498aklu  //
735c08e1173703234cc2913757f237ee916087498aklu  Status = gBS->InstallProtocolInterface (
745c08e1173703234cc2913757f237ee916087498aklu                  &gBdsInstanceTemplate.Handle,
755c08e1173703234cc2913757f237ee916087498aklu                  &gEfiBdsArchProtocolGuid,
765c08e1173703234cc2913757f237ee916087498aklu                  EFI_NATIVE_INTERFACE,
775c08e1173703234cc2913757f237ee916087498aklu                  &gBdsInstanceTemplate.Bds
785c08e1173703234cc2913757f237ee916087498aklu                  );
795c08e1173703234cc2913757f237ee916087498aklu  ASSERT_EFI_ERROR (Status);
805c08e1173703234cc2913757f237ee916087498aklu
815c08e1173703234cc2913757f237ee916087498aklu  return Status;
825c08e1173703234cc2913757f237ee916087498aklu}
835c08e1173703234cc2913757f237ee916087498aklu
845c08e1173703234cc2913757f237ee916087498aklu/**
855c08e1173703234cc2913757f237ee916087498aklu
865c08e1173703234cc2913757f237ee916087498aklu  This function attempts to boot for the boot order specified
875c08e1173703234cc2913757f237ee916087498aklu  by platform policy.
885c08e1173703234cc2913757f237ee916087498aklu
895c08e1173703234cc2913757f237ee916087498aklu**/
905c08e1173703234cc2913757f237ee916087498akluVOID
915c08e1173703234cc2913757f237ee916087498akluBdsBootDeviceSelect (
925c08e1173703234cc2913757f237ee916087498aklu  VOID
935c08e1173703234cc2913757f237ee916087498aklu  )
945c08e1173703234cc2913757f237ee916087498aklu{
955c08e1173703234cc2913757f237ee916087498aklu  EFI_STATUS        Status;
965c08e1173703234cc2913757f237ee916087498aklu  LIST_ENTRY        *Link;
975c08e1173703234cc2913757f237ee916087498aklu  BDS_COMMON_OPTION *BootOption;
985c08e1173703234cc2913757f237ee916087498aklu  UINTN             ExitDataSize;
995c08e1173703234cc2913757f237ee916087498aklu  CHAR16            *ExitData;
1005c08e1173703234cc2913757f237ee916087498aklu  UINT16            Timeout;
1015c08e1173703234cc2913757f237ee916087498aklu  LIST_ENTRY        BootLists;
1025c08e1173703234cc2913757f237ee916087498aklu  CHAR16            Buffer[20];
1035c08e1173703234cc2913757f237ee916087498aklu  BOOLEAN           BootNextExist;
1045c08e1173703234cc2913757f237ee916087498aklu  LIST_ENTRY        *LinkBootNext;
1055c08e1173703234cc2913757f237ee916087498aklu
1065c08e1173703234cc2913757f237ee916087498aklu  //
1075c08e1173703234cc2913757f237ee916087498aklu  // Got the latest boot option
1085c08e1173703234cc2913757f237ee916087498aklu  //
1095c08e1173703234cc2913757f237ee916087498aklu  BootNextExist = FALSE;
1105c08e1173703234cc2913757f237ee916087498aklu  LinkBootNext  = NULL;
1115c08e1173703234cc2913757f237ee916087498aklu  InitializeListHead (&BootLists);
1125c08e1173703234cc2913757f237ee916087498aklu
1135c08e1173703234cc2913757f237ee916087498aklu  //
1145c08e1173703234cc2913757f237ee916087498aklu  // First check the boot next option
1155c08e1173703234cc2913757f237ee916087498aklu  //
1165c08e1173703234cc2913757f237ee916087498aklu  ZeroMem (Buffer, sizeof (Buffer));
1175c08e1173703234cc2913757f237ee916087498aklu
1185c08e1173703234cc2913757f237ee916087498aklu  if (mBootNext != NULL) {
1195c08e1173703234cc2913757f237ee916087498aklu    //
1205c08e1173703234cc2913757f237ee916087498aklu    // Indicate we have the boot next variable, so this time
1215c08e1173703234cc2913757f237ee916087498aklu    // boot will always have this boot option
1225c08e1173703234cc2913757f237ee916087498aklu    //
1235c08e1173703234cc2913757f237ee916087498aklu    BootNextExist = TRUE;
1245c08e1173703234cc2913757f237ee916087498aklu
1255c08e1173703234cc2913757f237ee916087498aklu    //
1265c08e1173703234cc2913757f237ee916087498aklu    // Clear the this variable so it's only exist in this time boot
1275c08e1173703234cc2913757f237ee916087498aklu    //
1285c08e1173703234cc2913757f237ee916087498aklu    gRT->SetVariable (
1295c08e1173703234cc2913757f237ee916087498aklu          L"BootNext",
1305c08e1173703234cc2913757f237ee916087498aklu          &gEfiGlobalVariableGuid,
1315c08e1173703234cc2913757f237ee916087498aklu          EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
1325c08e1173703234cc2913757f237ee916087498aklu          0,
1335c08e1173703234cc2913757f237ee916087498aklu          mBootNext
1345c08e1173703234cc2913757f237ee916087498aklu          );
1355c08e1173703234cc2913757f237ee916087498aklu
1365c08e1173703234cc2913757f237ee916087498aklu    //
1375c08e1173703234cc2913757f237ee916087498aklu    // Add the boot next boot option
1385c08e1173703234cc2913757f237ee916087498aklu    //
1395c08e1173703234cc2913757f237ee916087498aklu    UnicodeSPrint (Buffer, sizeof (Buffer), L"Boot%04x", *mBootNext);
1405c08e1173703234cc2913757f237ee916087498aklu    BootOption = BdsLibVariableToOption (&BootLists, Buffer);
1415c08e1173703234cc2913757f237ee916087498aklu
1425c08e1173703234cc2913757f237ee916087498aklu    //
1435c08e1173703234cc2913757f237ee916087498aklu    // If fail to get boot option from variable, just return and do nothing.
1445c08e1173703234cc2913757f237ee916087498aklu    //
1455c08e1173703234cc2913757f237ee916087498aklu    if (BootOption == NULL) {
1465c08e1173703234cc2913757f237ee916087498aklu      return;
1475c08e1173703234cc2913757f237ee916087498aklu    }
1485c08e1173703234cc2913757f237ee916087498aklu
1495c08e1173703234cc2913757f237ee916087498aklu    BootOption->BootCurrent = *mBootNext;
1505c08e1173703234cc2913757f237ee916087498aklu  }
1515c08e1173703234cc2913757f237ee916087498aklu  //
1525c08e1173703234cc2913757f237ee916087498aklu  // Parse the boot order to get boot option
1535c08e1173703234cc2913757f237ee916087498aklu  //
1545c08e1173703234cc2913757f237ee916087498aklu  BdsLibBuildOptionFromVar (&BootLists, L"BootOrder");
1555c08e1173703234cc2913757f237ee916087498aklu  Link = BootLists.ForwardLink;
1565c08e1173703234cc2913757f237ee916087498aklu
1575c08e1173703234cc2913757f237ee916087498aklu  //
1585c08e1173703234cc2913757f237ee916087498aklu  // Parameter check, make sure the loop will be valid
1595c08e1173703234cc2913757f237ee916087498aklu  //
1605c08e1173703234cc2913757f237ee916087498aklu  if (Link == NULL) {
1615c08e1173703234cc2913757f237ee916087498aklu    return ;
1625c08e1173703234cc2913757f237ee916087498aklu  }
1635c08e1173703234cc2913757f237ee916087498aklu  //
1645c08e1173703234cc2913757f237ee916087498aklu  // Here we make the boot in a loop, every boot success will
1655c08e1173703234cc2913757f237ee916087498aklu  // return to the front page
1665c08e1173703234cc2913757f237ee916087498aklu  //
1675c08e1173703234cc2913757f237ee916087498aklu  for (;;) {
1685c08e1173703234cc2913757f237ee916087498aklu    //
1695c08e1173703234cc2913757f237ee916087498aklu    // Check the boot option list first
1705c08e1173703234cc2913757f237ee916087498aklu    //
1715c08e1173703234cc2913757f237ee916087498aklu    if (Link == &BootLists) {
1725c08e1173703234cc2913757f237ee916087498aklu      //
1735c08e1173703234cc2913757f237ee916087498aklu      // There are two ways to enter here:
1745c08e1173703234cc2913757f237ee916087498aklu      // 1. There is no active boot option, give user chance to
1755c08e1173703234cc2913757f237ee916087498aklu      //    add new boot option
1765c08e1173703234cc2913757f237ee916087498aklu      // 2. All the active boot option processed, and there is no
1775c08e1173703234cc2913757f237ee916087498aklu      //    one is success to boot, then we back here to allow user
1785c08e1173703234cc2913757f237ee916087498aklu      //    add new active boot option
1795c08e1173703234cc2913757f237ee916087498aklu      //
1805c08e1173703234cc2913757f237ee916087498aklu      Timeout = 0xffff;
1815c08e1173703234cc2913757f237ee916087498aklu      PlatformBdsEnterFrontPage (Timeout, FALSE);
1825c08e1173703234cc2913757f237ee916087498aklu      InitializeListHead (&BootLists);
1835c08e1173703234cc2913757f237ee916087498aklu      BdsLibBuildOptionFromVar (&BootLists, L"BootOrder");
1845c08e1173703234cc2913757f237ee916087498aklu      Link = BootLists.ForwardLink;
1855c08e1173703234cc2913757f237ee916087498aklu      continue;
1865c08e1173703234cc2913757f237ee916087498aklu    }
1875c08e1173703234cc2913757f237ee916087498aklu    //
1885c08e1173703234cc2913757f237ee916087498aklu    // Get the boot option from the link list
1895c08e1173703234cc2913757f237ee916087498aklu    //
1905c08e1173703234cc2913757f237ee916087498aklu    BootOption = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);
1915c08e1173703234cc2913757f237ee916087498aklu
1925c08e1173703234cc2913757f237ee916087498aklu    //
1935c08e1173703234cc2913757f237ee916087498aklu    // According to EFI Specification, if a load option is not marked
1945c08e1173703234cc2913757f237ee916087498aklu    // as LOAD_OPTION_ACTIVE, the boot manager will not automatically
1955c08e1173703234cc2913757f237ee916087498aklu    // load the option.
1965c08e1173703234cc2913757f237ee916087498aklu    //
1975c08e1173703234cc2913757f237ee916087498aklu    if (!IS_LOAD_OPTION_TYPE (BootOption->Attribute, LOAD_OPTION_ACTIVE)) {
1985c08e1173703234cc2913757f237ee916087498aklu      //
1995c08e1173703234cc2913757f237ee916087498aklu      // skip the header of the link list, becuase it has no boot option
2005c08e1173703234cc2913757f237ee916087498aklu      //
2015c08e1173703234cc2913757f237ee916087498aklu      Link = Link->ForwardLink;
2025c08e1173703234cc2913757f237ee916087498aklu      continue;
2035c08e1173703234cc2913757f237ee916087498aklu    }
2045c08e1173703234cc2913757f237ee916087498aklu    //
2055c08e1173703234cc2913757f237ee916087498aklu    // Make sure the boot option device path connected,
2065c08e1173703234cc2913757f237ee916087498aklu    // but ignore the BBS device path
2075c08e1173703234cc2913757f237ee916087498aklu    //
2085c08e1173703234cc2913757f237ee916087498aklu    if (DevicePathType (BootOption->DevicePath) != BBS_DEVICE_PATH) {
2095c08e1173703234cc2913757f237ee916087498aklu      //
2105c08e1173703234cc2913757f237ee916087498aklu      // Notes: the internal shell can not been connected with device path
2115c08e1173703234cc2913757f237ee916087498aklu      // so we do not check the status here
2125c08e1173703234cc2913757f237ee916087498aklu      //
2135c08e1173703234cc2913757f237ee916087498aklu      BdsLibConnectDevicePath (BootOption->DevicePath);
2145c08e1173703234cc2913757f237ee916087498aklu    }
2155c08e1173703234cc2913757f237ee916087498aklu    //
2165c08e1173703234cc2913757f237ee916087498aklu    // All the driver options should have been processed since
2175c08e1173703234cc2913757f237ee916087498aklu    // now boot will be performed.
2185c08e1173703234cc2913757f237ee916087498aklu    //
2195c08e1173703234cc2913757f237ee916087498aklu    Status = BdsLibBootViaBootOption (BootOption, BootOption->DevicePath, &ExitDataSize, &ExitData);
2205c08e1173703234cc2913757f237ee916087498aklu    if (EFI_ERROR (Status)) {
2215c08e1173703234cc2913757f237ee916087498aklu      //
2225c08e1173703234cc2913757f237ee916087498aklu      // Call platform action to indicate the boot fail
2235c08e1173703234cc2913757f237ee916087498aklu      //
2245c08e1173703234cc2913757f237ee916087498aklu      BootOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_FAILED));
2255c08e1173703234cc2913757f237ee916087498aklu      PlatformBdsBootFail (BootOption, Status, ExitData, ExitDataSize);
2265c08e1173703234cc2913757f237ee916087498aklu
2275c08e1173703234cc2913757f237ee916087498aklu      //
2285c08e1173703234cc2913757f237ee916087498aklu      // Check the next boot option
2295c08e1173703234cc2913757f237ee916087498aklu      //
2305c08e1173703234cc2913757f237ee916087498aklu      Link = Link->ForwardLink;
2315c08e1173703234cc2913757f237ee916087498aklu
2325c08e1173703234cc2913757f237ee916087498aklu    } else {
2335c08e1173703234cc2913757f237ee916087498aklu      //
2345c08e1173703234cc2913757f237ee916087498aklu      // Call platform action to indicate the boot success
2355c08e1173703234cc2913757f237ee916087498aklu      //
2365c08e1173703234cc2913757f237ee916087498aklu      BootOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED));
2375c08e1173703234cc2913757f237ee916087498aklu      PlatformBdsBootSuccess (BootOption);
2385c08e1173703234cc2913757f237ee916087498aklu
2395c08e1173703234cc2913757f237ee916087498aklu      //
2405c08e1173703234cc2913757f237ee916087498aklu      // Boot success, then stop process the boot order, and
2415c08e1173703234cc2913757f237ee916087498aklu      // present the boot manager menu, front page
2425c08e1173703234cc2913757f237ee916087498aklu      //
2435c08e1173703234cc2913757f237ee916087498aklu      Timeout = 0xffff;
2445c08e1173703234cc2913757f237ee916087498aklu      PlatformBdsEnterFrontPage (Timeout, FALSE);
2455c08e1173703234cc2913757f237ee916087498aklu
2465c08e1173703234cc2913757f237ee916087498aklu      //
2475c08e1173703234cc2913757f237ee916087498aklu      // Rescan the boot option list, avoid pertential risk of the boot
2485c08e1173703234cc2913757f237ee916087498aklu      // option change in front page
2495c08e1173703234cc2913757f237ee916087498aklu      //
2505c08e1173703234cc2913757f237ee916087498aklu      if (BootNextExist) {
2515c08e1173703234cc2913757f237ee916087498aklu        LinkBootNext = BootLists.ForwardLink;
2525c08e1173703234cc2913757f237ee916087498aklu      }
2535c08e1173703234cc2913757f237ee916087498aklu
2545c08e1173703234cc2913757f237ee916087498aklu      InitializeListHead (&BootLists);
2555c08e1173703234cc2913757f237ee916087498aklu      if (LinkBootNext != NULL) {
2565c08e1173703234cc2913757f237ee916087498aklu        //
2575c08e1173703234cc2913757f237ee916087498aklu        // Reserve the boot next option
2585c08e1173703234cc2913757f237ee916087498aklu        //
2595c08e1173703234cc2913757f237ee916087498aklu        InsertTailList (&BootLists, LinkBootNext);
2605c08e1173703234cc2913757f237ee916087498aklu      }
2615c08e1173703234cc2913757f237ee916087498aklu
2625c08e1173703234cc2913757f237ee916087498aklu      BdsLibBuildOptionFromVar (&BootLists, L"BootOrder");
2635c08e1173703234cc2913757f237ee916087498aklu      Link = BootLists.ForwardLink;
2645c08e1173703234cc2913757f237ee916087498aklu    }
2655c08e1173703234cc2913757f237ee916087498aklu  }
2665c08e1173703234cc2913757f237ee916087498aklu
2675c08e1173703234cc2913757f237ee916087498aklu}
2685c08e1173703234cc2913757f237ee916087498aklu
2695c08e1173703234cc2913757f237ee916087498aklu/**
2705c08e1173703234cc2913757f237ee916087498aklu
2715c08e1173703234cc2913757f237ee916087498aklu  Service routine for BdsInstance->Entry(). Devices are connected, the
2725c08e1173703234cc2913757f237ee916087498aklu  consoles are initialized, and the boot options are tried.
2735c08e1173703234cc2913757f237ee916087498aklu
2745c08e1173703234cc2913757f237ee916087498aklu  @param This             Protocol Instance structure.
2755c08e1173703234cc2913757f237ee916087498aklu
2765c08e1173703234cc2913757f237ee916087498aklu**/
2775c08e1173703234cc2913757f237ee916087498akluVOID
2785c08e1173703234cc2913757f237ee916087498akluEFIAPI
2795c08e1173703234cc2913757f237ee916087498akluBdsEntry (
2805c08e1173703234cc2913757f237ee916087498aklu  IN EFI_BDS_ARCH_PROTOCOL  *This
2815c08e1173703234cc2913757f237ee916087498aklu  )
2825c08e1173703234cc2913757f237ee916087498aklu{
2835c08e1173703234cc2913757f237ee916087498aklu  EFI_BDS_ARCH_PROTOCOL_INSTANCE  *PrivateData;
2845c08e1173703234cc2913757f237ee916087498aklu  LIST_ENTRY                      DriverOptionList;
2855c08e1173703234cc2913757f237ee916087498aklu  LIST_ENTRY                      BootOptionList;
2865c08e1173703234cc2913757f237ee916087498aklu  UINTN                           BootNextSize;
2875c08e1173703234cc2913757f237ee916087498aklu
2885c08e1173703234cc2913757f237ee916087498aklu  //
2895c08e1173703234cc2913757f237ee916087498aklu  // Insert the performance probe
2905c08e1173703234cc2913757f237ee916087498aklu  //
2916aa22a177c32344ff1d5f765183d0da416fcc252qhuang  PERF_END (0, "DXE", NULL, 0);
2926aa22a177c32344ff1d5f765183d0da416fcc252qhuang  PERF_START (0, "BDS", NULL, 0);
2935c08e1173703234cc2913757f237ee916087498aklu
2945c08e1173703234cc2913757f237ee916087498aklu  //
2955c08e1173703234cc2913757f237ee916087498aklu  // Initialize the global system boot option and driver option
2965c08e1173703234cc2913757f237ee916087498aklu  //
2975c08e1173703234cc2913757f237ee916087498aklu  InitializeListHead (&DriverOptionList);
2985c08e1173703234cc2913757f237ee916087498aklu  InitializeListHead (&BootOptionList);
2995c08e1173703234cc2913757f237ee916087498aklu
3005c08e1173703234cc2913757f237ee916087498aklu  //
3015c08e1173703234cc2913757f237ee916087498aklu  // Initialize hotkey service
3025c08e1173703234cc2913757f237ee916087498aklu  //
3035c08e1173703234cc2913757f237ee916087498aklu  InitializeHotkeyService ();
3045c08e1173703234cc2913757f237ee916087498aklu
3055c08e1173703234cc2913757f237ee916087498aklu  //
3065c08e1173703234cc2913757f237ee916087498aklu  // Get the BDS private data
3075c08e1173703234cc2913757f237ee916087498aklu  //
3085c08e1173703234cc2913757f237ee916087498aklu  PrivateData = EFI_BDS_ARCH_PROTOCOL_INSTANCE_FROM_THIS (This);
3095c08e1173703234cc2913757f237ee916087498aklu
3105c08e1173703234cc2913757f237ee916087498aklu  //
3115c08e1173703234cc2913757f237ee916087498aklu  // Do the platform init, can be customized by OEM/IBV
3125c08e1173703234cc2913757f237ee916087498aklu  //
3135c08e1173703234cc2913757f237ee916087498aklu  PERF_START (0, "PlatformBds", "BDS", 0);
3145c08e1173703234cc2913757f237ee916087498aklu  PlatformBdsInit (PrivateData);
3155c08e1173703234cc2913757f237ee916087498aklu
316a2b35995cac983b676296fcb95fde0e9121319f6klu  InitializeHwErrRecSupport();
317a2b35995cac983b676296fcb95fde0e9121319f6klu
3185c08e1173703234cc2913757f237ee916087498aklu  //
3195c08e1173703234cc2913757f237ee916087498aklu  // bugbug: platform specific code
3205c08e1173703234cc2913757f237ee916087498aklu  // Initialize the platform specific string and language
3215c08e1173703234cc2913757f237ee916087498aklu  //
3225c08e1173703234cc2913757f237ee916087498aklu  InitializeStringSupport ();
3235c08e1173703234cc2913757f237ee916087498aklu  InitializeLanguage (TRUE);
3245c08e1173703234cc2913757f237ee916087498aklu  InitializeFrontPage (TRUE);
3255c08e1173703234cc2913757f237ee916087498aklu
3265c08e1173703234cc2913757f237ee916087498aklu  //
3275c08e1173703234cc2913757f237ee916087498aklu  // Set up the device list based on EFI 1.1 variables
3285c08e1173703234cc2913757f237ee916087498aklu  // process Driver#### and Load the driver's in the
3295c08e1173703234cc2913757f237ee916087498aklu  // driver option list
3305c08e1173703234cc2913757f237ee916087498aklu  //
3315c08e1173703234cc2913757f237ee916087498aklu  BdsLibBuildOptionFromVar (&DriverOptionList, L"DriverOrder");
3325c08e1173703234cc2913757f237ee916087498aklu  if (!IsListEmpty (&DriverOptionList)) {
3335c08e1173703234cc2913757f237ee916087498aklu    BdsLibLoadDrivers (&DriverOptionList);
3345c08e1173703234cc2913757f237ee916087498aklu  }
3355c08e1173703234cc2913757f237ee916087498aklu  //
3365c08e1173703234cc2913757f237ee916087498aklu  // Check if we have the boot next option
3375c08e1173703234cc2913757f237ee916087498aklu  //
3385c08e1173703234cc2913757f237ee916087498aklu  mBootNext = BdsLibGetVariableAndSize (
3395c08e1173703234cc2913757f237ee916087498aklu                L"BootNext",
3405c08e1173703234cc2913757f237ee916087498aklu                &gEfiGlobalVariableGuid,
3415c08e1173703234cc2913757f237ee916087498aklu                &BootNextSize
3425c08e1173703234cc2913757f237ee916087498aklu                );
3435c08e1173703234cc2913757f237ee916087498aklu
3445c08e1173703234cc2913757f237ee916087498aklu  //
3455c08e1173703234cc2913757f237ee916087498aklu  // Setup some platform policy here
3465c08e1173703234cc2913757f237ee916087498aklu  //
3475c08e1173703234cc2913757f237ee916087498aklu  PlatformBdsPolicyBehavior (PrivateData, &DriverOptionList, &BootOptionList);
3485c08e1173703234cc2913757f237ee916087498aklu  PERF_END (0, "PlatformBds", "BDS", 0);
3495c08e1173703234cc2913757f237ee916087498aklu
3505c08e1173703234cc2913757f237ee916087498aklu  //
3515c08e1173703234cc2913757f237ee916087498aklu  // BDS select the boot device to load OS
3525c08e1173703234cc2913757f237ee916087498aklu  //
3535c08e1173703234cc2913757f237ee916087498aklu  BdsBootDeviceSelect ();
3545c08e1173703234cc2913757f237ee916087498aklu
3555c08e1173703234cc2913757f237ee916087498aklu  //
3565c08e1173703234cc2913757f237ee916087498aklu  // Only assert here since this is the right behavior, we should never
3575c08e1173703234cc2913757f237ee916087498aklu  // return back to DxeCore.
3585c08e1173703234cc2913757f237ee916087498aklu  //
3595c08e1173703234cc2913757f237ee916087498aklu  ASSERT (FALSE);
3605c08e1173703234cc2913757f237ee916087498aklu
3615c08e1173703234cc2913757f237ee916087498aklu  return ;
3625c08e1173703234cc2913757f237ee916087498aklu}
363