]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Bds/Bds.c
ArmPlatformPkg/Bds: Check if the assumed requirements are set before to use it
[mirror_edk2.git] / ArmPlatformPkg / Bds / Bds.c
index 415f0a9cb28771a0fb1a743559e20742e76f328a..7b49be4c114e0e6f8c3ec22792edecfd0e73cca5 100644 (file)
@@ -117,13 +117,16 @@ InitializeConsolePipe (
         // We convert back to the text representation of the device Path
         EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;
         CHAR16* DevicePathTxt;
+        EFI_STATUS Status;
+       
+        Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);
+        if (!EFI_ERROR(Status)) {
+          DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (DevicePath, TRUE, TRUE);
 
-        ASSERT_EFI_ERROR(gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol));
-        DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (DevicePath, TRUE, TRUE);
+          DEBUG((EFI_D_ERROR,"Fail to start the console with the Device Path '%s'. (Error '%r')\n", DevicePathTxt, Status));
 
-        DEBUG((EFI_D_ERROR,"Fail to start the console with the Device Path '%s'. (Error '%r')\n", DevicePathTxt, Status));
-
-        FreePool (DevicePathTxt);
+          FreePool (DevicePathTxt);
+        }
       }
     DEBUG_CODE_END();
 
@@ -195,11 +198,11 @@ DefineDefaultBootEntries (
   VOID
   )
 {
-  BDS_LOAD_OPTION     *BdsLoadOption;
-  UINTN               Size;
-  EFI_STATUS          Status;
-  EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL  *EfiDevicePathFromTextProtocol;
-  EFI_DEVICE_PATH*    BootDevicePath;
+  BDS_LOAD_OPTION*                    BdsLoadOption;
+  UINTN                               Size;
+  EFI_STATUS                          Status;
+  EFI_DEVICE_PATH_FROM_TEXT_PROTOCOLEfiDevicePathFromTextProtocol;
+  EFI_DEVICE_PATH*                    BootDevicePath;
 
   //
   // If Boot Order does not exist then create a default entry
@@ -207,8 +210,16 @@ DefineDefaultBootEntries (
   Size = 0;
   Status = gRT->GetVariable (L"BootOrder", &gEfiGlobalVariableGuid, NULL, &Size, NULL);
   if (Status == EFI_NOT_FOUND) {
+    if ((PcdGetPtr(PcdDefaultBootDevicePath) == NULL) || (StrLen ((CHAR16*)PcdGetPtr(PcdDefaultBootDevicePath)) == 0)) {
+      return EFI_UNSUPPORTED;
+    }
+
     Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);
-    ASSERT_EFI_ERROR(Status);
+    if (EFI_ERROR(Status)) {
+      // You must provide an implementation of DevicePathFromTextProtocol in your firmware (eg: DevicePathDxe)
+      DEBUG((EFI_D_ERROR,"Error: Bds requires DevicePathFromTextProtocol\n"));
+      return Status;
+    }
     BootDevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdDefaultBootDevicePath));
 
     DEBUG_CODE_BEGIN();
@@ -235,6 +246,8 @@ DefineDefaultBootEntries (
         &BdsLoadOption
         );
       FreePool (BdsLoadOption);
+    } else {
+      Status = EFI_UNSUPPORTED;
     }
   }
 
@@ -338,10 +351,12 @@ BdsEntry (
   //
   // Declare the Firmware Vendor
   //
-  Size = 0x100;
-  gST->FirmwareVendor = AllocateRuntimePool (Size);
-  ASSERT (gST->FirmwareVendor != NULL);
-  UnicodeSPrint (gST->FirmwareVendor, Size, L"%a EFI %a %a", PcdGetPtr(PcdFirmwareVendor), __DATE__, __TIME__);
+  if (PcdGetPtr(PcdFirmwareVendor)) {
+    Size = 0x100;
+    gST->FirmwareVendor = AllocateRuntimePool (Size);
+    ASSERT (gST->FirmwareVendor != NULL);
+    UnicodeSPrint (gST->FirmwareVendor, Size, L"%a EFI %a %a", PcdGetPtr(PcdFirmwareVendor), __DATE__, __TIME__);
+  }
 
   // If BootNext environment variable is defined then we just load it !
   Status = BdsStartBootOption (L"BootNext");