]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Bds/BootMenu.c
ArmPlatformPkg/Bds: Fixed adding support for new boot entry when the generated Device...
[mirror_edk2.git] / ArmPlatformPkg / Bds / BootMenu.c
index 7d1010bac274469ecc3a3c5898cc5bcb72f4b54b..1b101d45c1f7972038b55649cb1b85270363b76a 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 *\r
-*  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+*  Copyright (c) 2011-2013, ARM Limited. All rights reserved.\r
 *\r
 *  This program and the accompanying materials\r
 *  are licensed and made available under the terms and conditions of the BSD License\r
 \r
 #include "BdsInternal.h"\r
 \r
+#include <Guid/ArmGlobalVariableHob.h>\r
+\r
 extern EFI_HANDLE mImageHandle;\r
 extern BDS_LOAD_OPTION_SUPPORT *BdsLoadOptionSupportList;\r
 \r
+\r
 EFI_STATUS\r
 SelectBootDevice (\r
   OUT BDS_SUPPORTED_DEVICE** SupportedBootDevice\r
@@ -102,7 +105,7 @@ SelectBootDevice (
     }\r
     Index++;\r
   }\r
-  \r
+\r
 EXIT:\r
   BootDeviceListSupportedFree (&SupportedDeviceList, *SupportedBootDevice);\r
   return Status;\r
@@ -122,10 +125,11 @@ BootMenuAddBootOption (
   ARM_BDS_LOADER_TYPE       BootType;\r
   BDS_LOAD_OPTION_ENTRY     *BdsLoadOptionEntry;\r
   EFI_DEVICE_PATH           *DevicePath;\r
-  EFI_DEVICE_PATH_PROTOCOL  *DevicePathNode;\r
-  EFI_DEVICE_PATH_PROTOCOL  *InitrdPathNode;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePathNodes;\r
+  EFI_DEVICE_PATH_PROTOCOL  *InitrdPathNodes;\r
   EFI_DEVICE_PATH_PROTOCOL  *InitrdPath;\r
   UINTN                     CmdLineSize;\r
+  BOOLEAN                   InitrdSupport;\r
   UINTN                     InitrdSize;\r
 \r
   Attributes                = 0;\r
@@ -139,27 +143,44 @@ BootMenuAddBootOption (
   }\r
 \r
   // Create the specific device path node\r
-  Print(L"File path of the EFI Application or the kernel: ");\r
-  Status = SupportedBootDevice->Support->CreateDevicePathNode (SupportedBootDevice, &DevicePathNode, &BootType, &Attributes);\r
+  Status = SupportedBootDevice->Support->CreateDevicePathNode (L"EFI Application or the kernel", &DevicePathNodes, &BootType, &Attributes);\r
   if (EFI_ERROR(Status)) {\r
     Status = EFI_ABORTED;\r
     goto EXIT;\r
   }\r
-  // Append the Device Path node to the select device path\r
-  DevicePath = AppendDevicePathNode (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)DevicePathNode);\r
+  // Append the Device Path to the selected device path\r
+  DevicePath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)DevicePathNodes);\r
+  if (DevicePath == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto EXIT;\r
+  }\r
 \r
   if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
-    // Create the specific device path node\r
-    Print(L"File path of the initrd: ");\r
-    Status = SupportedBootDevice->Support->CreateDevicePathNode (SupportedBootDevice, &InitrdPathNode, NULL, NULL);\r
-    if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) { // EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd\r
+    Print(L"Add an initrd: ");\r
+    Status = GetHIInputBoolean (&InitrdSupport);\r
+    if (EFI_ERROR(Status)) {\r
       Status = EFI_ABORTED;\r
       goto EXIT;\r
     }\r
 \r
-    if (InitrdPathNode != NULL) {\r
-      // Append the Device Path node to the select device path\r
-      InitrdPath = AppendDevicePathNode (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNode);\r
+    if (InitrdSupport) {\r
+      // Create the specific device path node\r
+      Status = SupportedBootDevice->Support->CreateDevicePathNode (L"initrd", &InitrdPathNodes, NULL, NULL);\r
+      if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) { // EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd\r
+        Status = EFI_ABORTED;\r
+        goto EXIT;\r
+      }\r
+\r
+      if (InitrdPathNodes != NULL) {\r
+        // Append the Device Path to the selected device path\r
+        InitrdPath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNodes);\r
+        if (InitrdPath == NULL) {\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          goto EXIT;\r
+        }\r
+      } else {\r
+        InitrdPath = NULL;\r
+      }\r
     } else {\r
       InitrdPath = NULL;\r
     }\r
@@ -175,7 +196,7 @@ BootMenuAddBootOption (
     InitrdSize = GetDevicePathSize (InitrdPath);\r
 \r
     BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize);\r
-    \r
+\r
     BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;\r
     BootArguments->LinuxArguments.InitrdSize = InitrdSize;\r
     CopyMem ((VOID*)(&BootArguments->LinuxArguments + 1), CmdLine, CmdLineSize);\r
@@ -201,7 +222,6 @@ BootMenuAddBootOption (
 FREE_DEVICE_PATH:\r
   FreePool (DevicePath);\r
 \r
-  \r
 EXIT:\r
   if (Status == EFI_ABORTED) {\r
     Print(L"\n");\r
@@ -268,7 +288,7 @@ BootMenuSelectBootOption (
   if (BootOptionCount == 0) {\r
     if (StrCmp (InputStatement, DELETE_BOOT_ENTRY) == 0) {\r
       Print (L"Nothing to remove!\n");\r
-    }else if (StrCmp (InputStatement, UPDATE_BOOT_ENTRY) == 0) {\r
+    } else if (StrCmp (InputStatement, UPDATE_BOOT_ENTRY) == 0) {\r
       Print (L"Couldn't find valid boot entries\n");\r
     } else{\r
       Print (L"No supported Boot Entry.\n");\r
@@ -344,13 +364,16 @@ BootMenuUpdateBootOption (
   ARM_BDS_LOADER_ARGUMENTS*     BootArguments;\r
   CHAR16                        BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];\r
   CHAR8                         CmdLine[BOOT_DEVICE_OPTION_MAX];\r
-  EFI_DEVICE_PATH*              DevicePath;\r
+  EFI_DEVICE_PATH               *DevicePath;\r
+  EFI_DEVICE_PATH               *TempInitrdPath;\r
   ARM_BDS_LOADER_TYPE           BootType;\r
   ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r
   ARM_BDS_LINUX_ARGUMENTS*      LinuxArguments;\r
-  EFI_DEVICE_PATH*              InitrdPathList;\r
+  EFI_DEVICE_PATH               *InitrdPathNodes;\r
+  EFI_DEVICE_PATH               *InitrdPath;\r
   UINTN                         InitrdSize;\r
   UINTN                         CmdLineSize;\r
+  BOOLEAN                       InitrdSupport;\r
 \r
   Status = BootMenuSelectBootOption (BootOptionsList, UPDATE_BOOT_ENTRY, TRUE, &BootOptionEntry);\r
   if (EFI_ERROR(Status)) {\r
@@ -359,14 +382,13 @@ BootMenuUpdateBootOption (
   BootOption = BootOptionEntry->BdsLoadOption;\r
 \r
   // Get the device support for this Boot Option\r
-  Status = BootDeviceGetDeviceSupport (BootOption, &DeviceSupport);\r
+  Status = BootDeviceGetDeviceSupport (BootOption->FilePathList, &DeviceSupport);\r
   if (EFI_ERROR(Status)) {\r
     Print(L"Not possible to retrieve the supported device for the update\n");\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  Print(L"File path of the EFI Application or the kernel: ");\r
-  Status = DeviceSupport->UpdateDevicePathNode (BootOption->FilePathList, &DevicePath, NULL, NULL);\r
+  Status = DeviceSupport->UpdateDevicePathNode (BootOption->FilePathList, L"EFI Application or the kernel", &DevicePath, NULL, NULL);\r
   if (EFI_ERROR(Status)) {\r
     Status = EFI_ABORTED;\r
     goto EXIT;\r
@@ -375,7 +397,6 @@ BootMenuUpdateBootOption (
   OptionalData = BootOption->OptionalData;\r
   BootType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((UINT32 *)(&OptionalData->Header.LoaderType));\r
 \r
-  // TODO: Allow adding an initrd to a boot entry without one\r
   if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
     LinuxArguments = &OptionalData->Arguments.LinuxArguments;\r
 \r
@@ -383,16 +404,56 @@ BootMenuUpdateBootOption (
 \r
     InitrdSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->InitrdSize);\r
     if (InitrdSize > 0) {\r
-      Print(L"File path of the initrd: ");\r
-      Status = DeviceSupport->UpdateDevicePathNode ((EFI_DEVICE_PATH*)((LinuxArguments + 1) + CmdLineSize), &InitrdPathList, NULL, NULL);\r
-      if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) {// EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd\r
-        Status = EFI_ABORTED;\r
-        goto EXIT;\r
+      Print(L"Keep the initrd: ");\r
+    } else {\r
+      Print(L"Add an initrd: ");\r
+    }\r
+    Status = GetHIInputBoolean (&InitrdSupport);\r
+    if (EFI_ERROR(Status)) {\r
+      Status = EFI_ABORTED;\r
+      goto EXIT;\r
+    }\r
+\r
+    if (InitrdSupport) {\r
+      if (InitrdSize > 0) {\r
+        // Case we update the initrd device path\r
+        Status = DeviceSupport->UpdateDevicePathNode ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize), L"initrd", &InitrdPath, NULL, NULL);\r
+        if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) {// EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd\r
+          Status = EFI_ABORTED;\r
+          goto EXIT;\r
+        }\r
+        InitrdSize = GetDevicePathSize (InitrdPath);\r
+      } else {\r
+        // Case we create the initrd device path\r
+\r
+        Status = DeviceSupport->CreateDevicePathNode (L"initrd", &InitrdPathNodes, NULL, NULL);\r
+        if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) { // EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd\r
+          Status = EFI_ABORTED;\r
+          goto EXIT;\r
+        }\r
+\r
+        if (InitrdPathNodes != NULL) {\r
+          // Duplicate Linux kernel Device Path\r
+          TempInitrdPath = DuplicateDevicePath (BootOption->FilePathList);\r
+          // Replace Linux kernel Node by EndNode\r
+          SetDevicePathEndNode (GetLastDevicePathNode (TempInitrdPath));\r
+          // Append the Device Path to the selected device path\r
+          InitrdPath = AppendDevicePath (TempInitrdPath, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNodes);\r
+          FreePool (TempInitrdPath);\r
+          if (InitrdPath == NULL) {\r
+            Status = EFI_OUT_OF_RESOURCES;\r
+            goto EXIT;\r
+          }\r
+          InitrdSize = GetDevicePathSize (InitrdPath);\r
+        } else {\r
+          InitrdPath = NULL;\r
+        }\r
       }\r
-      InitrdSize = GetDevicePathSize (InitrdPathList);\r
+    } else {\r
+      InitrdSize = 0;\r
     }\r
 \r
-    Print(L"Arguments to pass to the binary: "); \r
+    Print(L"Arguments to pass to the binary: ");\r
     if (CmdLineSize > 0) {\r
       AsciiStrnCpy(CmdLine, (CONST CHAR8*)(LinuxArguments + 1), CmdLineSize);\r
     } else {\r
@@ -410,7 +471,7 @@ BootMenuUpdateBootOption (
     BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;\r
     BootArguments->LinuxArguments.InitrdSize = InitrdSize;\r
     CopyMem (&BootArguments->LinuxArguments + 1, CmdLine, CmdLineSize);\r
-    CopyMem ((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLine, InitrdPathList, InitrdSize);\r
+    CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);\r
   } else {\r
     BootArguments = NULL;\r
   }\r
@@ -441,11 +502,11 @@ UpdateFdtPath (
   IN LIST_ENTRY *BootOptionsList\r
   )\r
 {\r
-  EFI_STATUS Status;\r
-\r
-  BDS_SUPPORTED_DEVICE *SupportedBootDevice;\r
-  EFI_DEVICE_PATH_PROTOCOL *FdtDevicePathNode;\r
-  EFI_DEVICE_PATH_PROTOCOL *FdtDevicePath;\r
+  EFI_STATUS                Status;\r
+  UINTN                     FdtDevicePathSize;\r
+  BDS_SUPPORTED_DEVICE      *SupportedBootDevice;\r
+  EFI_DEVICE_PATH_PROTOCOL  *FdtDevicePathNodes;\r
+  EFI_DEVICE_PATH_PROTOCOL  *FdtDevicePath;\r
 \r
   Status = SelectBootDevice (&SupportedBootDevice);\r
   if (EFI_ERROR(Status)) {\r
@@ -454,20 +515,32 @@ UpdateFdtPath (
   }\r
 \r
   // Create the specific device path node\r
-  Print(L"File path of the FDT blob: ");\r
-  Status = SupportedBootDevice->Support->CreateDevicePathNode (SupportedBootDevice, &FdtDevicePathNode, NULL, NULL);\r
+  Status = SupportedBootDevice->Support->CreateDevicePathNode (L"FDT blob", &FdtDevicePathNodes, NULL, NULL);\r
   if (EFI_ERROR(Status)) {\r
     Status = EFI_ABORTED;\r
     goto EXIT;\r
   }\r
 \r
-  if (FdtDevicePathNode != NULL) {\r
+  if (FdtDevicePathNodes != NULL) {\r
     // Append the Device Path node to the select device path\r
-    FdtDevicePath = AppendDevicePathNode (SupportedBootDevice->DevicePathProtocol, FdtDevicePathNode);\r
-    Status = gRT->SetVariable ((CHAR16*)L"FDT", &gEfiGlobalVariableGuid, (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS ), 4, &FdtDevicePath);\r
+    FdtDevicePath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, FdtDevicePathNodes);\r
+    FdtDevicePathSize = GetDevicePathSize (FdtDevicePath);\r
+    Status = gRT->SetVariable (\r
+                    (CHAR16*)L"Fdt",\r
+                    &gArmGlobalVariableGuid,\r
+                    EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+                    FdtDevicePathSize,\r
+                    FdtDevicePath\r
+                    );\r
     ASSERT_EFI_ERROR(Status);\r
   } else {\r
-    gRT->SetVariable ((CHAR16*)L"FDT", &gEfiGlobalVariableGuid, (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS ), 0, NULL);\r
+    gRT->SetVariable (\r
+           (CHAR16*)L"Fdt",\r
+           &gArmGlobalVariableGuid,\r
+           EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+           0,\r
+           NULL\r
+           );\r
     ASSERT_EFI_ERROR(Status);\r
   }\r
 \r
@@ -524,14 +597,14 @@ BootMenuManager (
 }\r
 \r
 EFI_STATUS\r
-BootEBL (\r
+BootShell (\r
   IN LIST_ENTRY *BootOptionsList\r
   )\r
 {\r
   EFI_STATUS Status;\r
 \r
   // Start EFI Shell\r
-  Status = BdsLoadApplication (mImageHandle, L"Ebl", 0, NULL);\r
+  Status = BdsLoadApplication (mImageHandle, L"Shell", 0, NULL);\r
   if (Status == EFI_NOT_FOUND) {\r
     Print (L"Error: EFI Application not found.\n");\r
   } else if (EFI_ERROR(Status)) {\r
@@ -545,7 +618,7 @@ struct BOOT_MAIN_ENTRY {
   CONST CHAR16* Description;\r
   EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);\r
 } BootMainEntries[] = {\r
-    { L"EBL", BootEBL },\r
+    { L"Shell", BootShell },\r
     { L"Boot Manager", BootMenuManager },\r
 };\r
 \r
@@ -614,7 +687,23 @@ BootMenuMain (
             }\r
             Print(L"\t- Arguments: %a\n", (&OptionalData->Arguments.LinuxArguments + 1));\r
           }\r
-          Print(L"\t- LoaderType: %d\n", LoaderType);\r
+\r
+          switch (LoaderType) {\r
+            case BDS_LOADER_EFI_APPLICATION:\r
+              Print(L"\t- LoaderType: EFI Application\n");\r
+              break;\r
+\r
+            case BDS_LOADER_KERNEL_LINUX_ATAG:\r
+              Print(L"\t- LoaderType: Linux kernel with ATAG support\n");\r
+              break;\r
+\r
+            case BDS_LOADER_KERNEL_LINUX_FDT:\r
+              Print(L"\t- LoaderType: Linux kernel with FDT support\n");\r
+              break;\r
+\r
+            default:\r
+              Print(L"\t- LoaderType: Not recognized (%d)\n", LoaderType);\r
+          }\r
         }\r
         FreePool(DevicePathTxt);\r
       DEBUG_CODE_END();\r