/** This function uses policy data from the platform to determine what operating system or system utility should be loaded and invoked. This function call also optionally make the use of user input to determine the operating system or system utility to be loaded and invoked. When the DXE Core has dispatched all the drivers on the dispatch queue, this function is called. This function will attempt to connect the boot devices required to load and invoke the selected operating system or system utility. During this process, additional firmware volumes may be discovered that may contain addition DXE drivers that can be dispatched by the DXE Core. If a boot device cannot be fully connected, this function calls the DXE Service Dispatch() to allow the DXE drivers from any newly discovered firmware volumes to be dispatched. Then the boot device connection can be attempted again. If the same boot device connection operation fails twice in a row, then that boot device has failed, and should be skipped. This function should never return. @param This The EFI_BDS_ARCH_PROTOCOL instance. @return None. **/ VOID EFIAPI BdsEntry ( IN EFI_BDS_ARCH_PROTOCOL *This ) { UINTN Size; EFI_STATUS Status; UINT16 *BootNext; UINTN BootNextSize; CHAR16 BootVariableName[9]; EFI_EVENT EndOfDxeEvent; // // Signal EndOfDxe PI Event // Status = gBS->CreateEventEx ( EVT_NOTIFY_SIGNAL, TPL_NOTIFY, EmptyCallbackFunction, NULL, &gEfiEndOfDxeEventGroupGuid, &EndOfDxeEvent ); if (!EFI_ERROR (Status)) { gBS->SignalEvent (EndOfDxeEvent); } PERF_END (NULL, "DXE", NULL, 0); // // Declare the Firmware Vendor // if (FixedPcdGetPtr(PcdFirmwareVendor) != NULL) { Size = 0x100; gST->FirmwareVendor = AllocateRuntimePool (Size); ASSERT (gST->FirmwareVendor != NULL); UnicodeSPrint (gST->FirmwareVendor, Size, L"%a EFI %a %a", PcdGetPtr(PcdFirmwareVendor), __DATE__, __TIME__); } // // Fixup Table CRC after we updated Firmware Vendor // gST->Hdr.CRC32 = 0; Status = gBS->CalculateCrc32 ((VOID*)gST, gST->Hdr.HeaderSize, &gST->Hdr.CRC32); ASSERT_EFI_ERROR (Status); // If BootNext environment variable is defined then we just load it ! BootNextSize = sizeof(UINT16); Status = GetGlobalEnvironmentVariable (L"BootNext", NULL, &BootNextSize, (VOID**)&BootNext); if (!EFI_ERROR(Status)) { ASSERT(BootNextSize == sizeof(UINT16)); // Generate the requested Boot Entry variable name UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", *BootNext); // Set BootCurrent variable gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, BootNextSize, BootNext); FreePool (BootNext); // Start the requested Boot Entry Status = BdsStartBootOption (BootVariableName); if (Status != EFI_NOT_FOUND) { // BootNext has not been succeeded launched if (EFI_ERROR(Status)) { Print(L"Fail to start BootNext.\n"); } // Delete the BootNext environment variable gRT->SetVariable (L"BootNext", &gEfiGlobalVariableGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, 0, NULL); } // Clear BootCurrent variable gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, 0, NULL); } // If Boot Order does not exist then create a default entry DefineDefaultBootEntries (); // Now we need to setup the EFI System Table with information about the console devices. InitializeConsole (); // // Update the CRC32 in the EFI System Table header // gST->Hdr.CRC32 = 0; Status = gBS->CalculateCrc32 ((VOID*)gST, gST->Hdr.HeaderSize, &gST->Hdr.CRC32); ASSERT_EFI_ERROR (Status); // Timer before initiating the default boot selection StartDefaultBootOnTimeout (); // Start the Boot Menu Status = BootMenuMain (); ASSERT_EFI_ERROR (Status); }
/** This function uses policy data from the platform to determine what operating system or system utility should be loaded and invoked. This function call also optionally make the use of user input to determine the operating system or system utility to be loaded and invoked. When the DXE Core has dispatched all the drivers on the dispatch queue, this function is called. This function will attempt to connect the boot devices required to load and invoke the selected operating system or system utility. During this process, additional firmware volumes may be discovered that may contain addition DXE drivers that can be dispatched by the DXE Core. If a boot device cannot be fully connected, this function calls the DXE Service Dispatch() to allow the DXE drivers from any newly discovered firmware volumes to be dispatched. Then the boot device connection can be attempted again. If the same boot device connection operation fails twice in a row, then that boot device has failed, and should be skipped. This function should never return. @param This The EFI_BDS_ARCH_PROTOCOL instance. @return None. **/ VOID EFIAPI BdsEntry ( IN EFI_BDS_ARCH_PROTOCOL *This ) { UINTN Size; EFI_STATUS Status; UINT16 *BootNext; UINTN BootNextSize; CHAR16 BootVariableName[9]; EFI_EVENT EndOfDxeEvent; VOID *NewBase; // // Signal EndOfDxe PI Event // Status = gBS->CreateEventEx ( EVT_NOTIFY_SIGNAL, TPL_NOTIFY, EmptyCallbackFunction, NULL, &gEfiEndOfDxeEventGroupGuid, &EndOfDxeEvent ); if (!EFI_ERROR (Status)) { gBS->SignalEvent (EndOfDxeEvent); } PERF_END (NULL, "DXE", NULL, 0); OemPostEndIndicator(); //?им1??и▓бф?иж?б└бзиви┤и║б└1?б└и╣бд?бу?бъ?ж╠б└ижи║??2G?и▓бф?и║б└бъ??и▓бф?2?1?ио?бъ??ик?ив??HOB?D //memory reserved идидDикимивижy?asystem memory идидDик NewBase = AllocatePages (EFI_SIZE_TO_PAGES(SIZE_2GB)); if (NULL == NewBase) { DEBUG ((EFI_D_ERROR, "There are not enough memory space..........\n")); } else { FreePages(NewBase,EFI_SIZE_TO_PAGES(SIZE_2GB)); } // // Declare the Firmware Vendor // if (FixedPcdGetPtr(PcdFirmwareVendor) != NULL) { Size = 0x100; gST->FirmwareVendor = AllocateRuntimePool (Size); ASSERT (gST->FirmwareVendor != NULL); UnicodeSPrint (gST->FirmwareVendor, Size, L"%a EFI %a %a", PcdGetPtr(PcdFirmwareVendor), __DATE__, __TIME__); } // // Fixup Table CRC after we updated Firmware Vendor // gST->Hdr.CRC32 = 0; Status = gBS->CalculateCrc32 ((VOID*)gST, gST->Hdr.HeaderSize, &gST->Hdr.CRC32); ASSERT_EFI_ERROR (Status); if (EFI_ERROR (Status)) { //for fortify } // If BootNext environment variable is defined then we just load it ! BootNextSize = sizeof(UINT16); Status = GetGlobalEnvironmentVariable (L"BootNext", NULL, &BootNextSize, (VOID**)&BootNext); if (!EFI_ERROR(Status)) { ASSERT(BootNextSize == sizeof(UINT16)); // Generate the requested Boot Entry variable name UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", *BootNext); // Set BootCurrent variable gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, BootNextSize, BootNext); FreePool (BootNext); // Start the requested Boot Entry Status = BdsStartBootOption (BootVariableName); if (Status != EFI_NOT_FOUND) { // BootNext has not been succeeded launched if (EFI_ERROR(Status)) { Print(L"Fail to start BootNext.\n"); } // Delete the BootNext environment variable gRT->SetVariable (L"BootNext", &gEfiGlobalVariableGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, 0, NULL); } // Clear BootCurrent variable gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, 0, NULL); } // If Boot Order does not exist then create a default entry DefineDefaultBootEntries (); // Now we need to setup the EFI System Table with information about the console devices. InitializeConsole (); // // Update the CRC32 in the EFI System Table header // gST->Hdr.CRC32 = 0; Status = gBS->CalculateCrc32 ((VOID*)gST, gST->Hdr.HeaderSize, &gST->Hdr.CRC32); ASSERT_EFI_ERROR (Status); if (EFI_ERROR (Status)) { //for fortify } // Timer before initiating the default boot selection StartDefaultBootOnTimeout (); Status = VerifyBootLineEntry (); if(EFI_ERROR(Status)) { DEBUG((EFI_D_ERROR,"Input Password Error, Boot failed!\n")); return; } // Start the Boot Menu Status = BootMenuMain (); ASSERT_EFI_ERROR (Status); if (EFI_ERROR (Status)) { //for fortify } }
EFI_STATUS StartDefaultBootOnTimeout ( VOID ) { UINTN Size; UINT16 Timeout; UINT16 *TimeoutPtr; EFI_EVENT WaitList[2]; UINTN WaitIndex; UINT16 *BootOrder; UINTN BootOrderSize; UINTN Index; CHAR16 BootVariableName[9]; EFI_STATUS Status; EFI_INPUT_KEY Key; Size = sizeof(UINT16); Timeout = (UINT16)PcdGet16 (PcdPlatformBootTimeOut); Status = GetGlobalEnvironmentVariable (L"Timeout", &Timeout, &Size, (VOID**)&TimeoutPtr); if (!EFI_ERROR (Status)) { Timeout = *TimeoutPtr; FreePool (TimeoutPtr); } if (Timeout != 0xFFFF) { if (Timeout > 0) { // Create the waiting events (keystroke and 1sec timer) gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &WaitList[0]); gBS->SetTimer (WaitList[0], TimerPeriodic, EFI_SET_TIMER_TO_SECOND); WaitList[1] = gST->ConIn->WaitForKey; // Start the timer WaitIndex = 0; Print(L"The default boot selection will start in "); while ((Timeout > 0) && (WaitIndex == 0)) { Print(L"%3d seconds",Timeout); gBS->WaitForEvent (2, WaitList, &WaitIndex); if (WaitIndex == 0) { Print(L"\b\b\b\b\b\b\b\b\b\b\b"); Timeout--; } } // Discard key in the buffer do { Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); } while(!EFI_ERROR(Status)); gBS->CloseEvent (WaitList[0]); Print(L"\n\r"); } // In case of Timeout we start the default boot selection if (Timeout == 0) { // Get the Boot Option Order from the environment variable (a default value should have been created) GetGlobalEnvironmentVariable (L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder); for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) { UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", BootOrder[Index]); Status = BdsStartBootOption (BootVariableName); if(!EFI_ERROR(Status)){ // Boot option returned successfully, hence don't need to start next boot option break; } // In case of success, we should not return from this call. } FreePool (BootOrder); } } return EFI_SUCCESS; }
EFI_STATUS StartDefaultBootOnTimeout ( VOID ) { UINTN Size; UINT16 Timeout; UINT16 *TimeoutPtr; EFI_EVENT WaitList[2]; UINTN WaitIndex; UINT16 *BootOrder = NULL; UINTN BootOrderSize = 0; UINTN Index; CHAR16 BootVariableName[9]; EFI_STATUS Status; EFI_INPUT_KEY Key; LIST_ENTRY BootOptionsList; BOOLEAN IsFlashBootFirst = FALSE; BOOLEAN FlashBootSupport = FALSE; // Get the Boot Option Order from the environment variable (a default value should have been created) Status = GetGlobalEnvironmentVariable (L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder); if (EFI_ERROR(Status)) { DEBUG((EFI_D_ERROR, "%a(%d):Return a error Status\n", __FUNCTION__,__LINE__)); } Status = GetBootDeviceTypeInfo(); if (EFI_ERROR(Status)) { DEBUG((EFI_D_ERROR, "%a(%d):Return a error Status\n", __FUNCTION__,__LINE__)); } Status = OemBootOrderSeting(BootOrder,BootOrderSize,&IsFlashBootFirst,&FlashBootSupport); if (EFI_ERROR(Status)) { DEBUG((EFI_D_ERROR, "%a(%d):Return a error Status\n", __FUNCTION__,__LINE__)); } // Update (or Create) the BootOrder environment variable Status = gRT->SetVariable ( L"BootOrder", &gEfiGlobalVariableGuid, EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, BootOrderSize, BootOrder ); if (EFI_ERROR(Status)) { DEBUG((EFI_D_ERROR, "%a(%d):SetVariable failed!\n", __FUNCTION__,__LINE__)); } Size = sizeof(UINT16); Timeout = (UINT16)PcdGet16 (PcdPlatformBootTimeOut); Status = GetGlobalEnvironmentVariable (L"Timeout", &Timeout, &Size, (VOID**)&TimeoutPtr); if (!EFI_ERROR (Status)) { Timeout = *TimeoutPtr; FreePool (TimeoutPtr); } if (Timeout != 0xFFFF) { if (Timeout > 0) { // Create the waiting events (keystroke and 1sec timer) gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &WaitList[0]); gBS->SetTimer (WaitList[0], TimerPeriodic, EFI_SET_TIMER_TO_SECOND); WaitList[1] = gST->ConIn->WaitForKey; // Start the timer WaitIndex = 0; Print(L"The default boot selection will start in "); while ((Timeout > 0) && (WaitIndex == 0)) { Print(L"%3d seconds",Timeout); gBS->WaitForEvent (2, WaitList, &WaitIndex); if (WaitIndex == 0) { Print(L"\b\b\b\b\b\b\b\b\b\b\b"); Timeout--; } } // Discard key in the buffer do { Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); } while(!EFI_ERROR(Status)); gBS->CloseEvent (WaitList[0]); Print(L"\n\r"); } // In case of Timeout we start the default boot selection if (Timeout == 0) { // Get the Boot Option Order from the environment variable (a default value should have been created) Status = GetGlobalEnvironmentVariable (L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder); if (EFI_ERROR(Status)) { DEBUG((EFI_D_ERROR, "%a(%d):Return a error Status\n", __FUNCTION__,__LINE__)); } //display the final BootOrder EnviromentVariable, we'll start OS with it! BootOptionList (&BootOptionsList); DisplayBootOptions(&BootOptionsList); if(FlashBootSupport) { if(IsFlashBootFirst) { Print(L"Bds TimeOut First Start Boot Option [FLASH] ....Begin!...\n\r"); Flash_Start_OS (); Print(L"Bds TimeOut First Start Boot Option [FLASH] ....Fail!...\n\r"); } } for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) { UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", BootOrder[Index]); OemPreStartBootOptionAction(BootOrder[Index]); Print(L"Bds TimeOut Start Boot Option [%s] ....Begin!...\n\r",BootVariableName); Status = BdsStartBootOption (BootVariableName); if(!EFI_ERROR(Status)){ // Boot option returned successfully, hence don't need to start next boot option break; } Print(L"Bds TimeOut Start Boot Option [%s] ....Fail!...\n\r",BootVariableName); } if(FlashBootSupport) { if(!IsFlashBootFirst) { Print(L"Bds TimeOut Start Boot Option [FLASH] ....Begin!...\n\r"); Flash_Start_OS (); Print(L"Bds TimeOut Start Boot Option [FLASH] ....Fail!...\n\r"); } }else{} // We only free it if the UEFI Variable 'BootOrder' was already existing if (BootOrderSize > sizeof(UINT16)) { FreePool (BootOrder); } OpenAlarmLed(); Print(L"[WARNING]Bds TimeOut: All Boot Option Start Fail! Lighting The Alarm Led!!! \n\r"); } } return EFI_SUCCESS; }