]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Bds/BootMenu.c
ArmPlatformPkg/Bds: Get User inputs in Unicode
[mirror_edk2.git] / ArmPlatformPkg / Bds / BootMenu.c
index 853ef09fa8e3ec4ce618fbb79c69d9367f2863c3..591e7e683b8382759be6b92c3cda25686857d060 100644 (file)
@@ -18,28 +18,16 @@ extern EFI_HANDLE mImageHandle;
 extern BDS_LOAD_OPTION_SUPPORT *BdsLoadOptionSupportList;\r
 \r
 EFI_STATUS\r
-BootMenuAddBootOption (\r
-  IN LIST_ENTRY *BootOptionsList\r
+SelectBootDevice (\r
+  OUT BDS_SUPPORTED_DEVICE** SupportedBootDevice\r
   )\r
 {\r
-  EFI_STATUS    Status;\r
+  EFI_STATUS  Status;\r
   LIST_ENTRY  SupportedDeviceList;\r
   UINTN       SupportedDeviceCount;\r
-  BDS_SUPPORTED_DEVICE* SupportedBootDevice;\r
   LIST_ENTRY* Entry;\r
   UINTN       SupportedDeviceSelected;\r
-  CHAR8       AsciiBootOption[BOOT_DEVICE_OPTION_MAX];\r
-  CHAR8       AsciiBootDescription[BOOT_DEVICE_DESCRIPTION_MAX];\r
-  CHAR16      *BootDescription;\r
-  UINT32      Attributes;\r
-  BDS_LOADER_TYPE   BootType;\r
   UINTN       Index;\r
-  BDS_LOAD_OPTION *BdsLoadOption;\r
-  EFI_DEVICE_PATH*  DevicePath;\r
-  EFI_DEVICE_PATH_PROTOCOL *DevicePathNode;\r
-\r
-  Attributes                = 0;\r
-  SupportedBootDevice = NULL;\r
 \r
   //\r
   // List the Boot Devices supported\r
@@ -58,8 +46,8 @@ BootMenuAddBootOption (
        Entry = GetNextNode (&SupportedDeviceList,Entry)\r
        )\r
   {\r
-    SupportedBootDevice = SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry);\r
-    Print(L"[%d] %s\n",SupportedDeviceCount+1,SupportedBootDevice->Description);\r
+    *SupportedBootDevice = SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry);\r
+    Print(L"[%d] %s\n",SupportedDeviceCount+1,(*SupportedBootDevice)->Description);\r
 \r
     DEBUG_CODE_BEGIN();\r
       CHAR16*                           DevicePathTxt;\r
@@ -67,7 +55,7 @@ BootMenuAddBootOption (
 \r
       Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
       ASSERT_EFI_ERROR(Status);\r
-      DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText(SupportedBootDevice->DevicePathProtocol,TRUE,TRUE);\r
+      DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText((*SupportedBootDevice)->DevicePathProtocol,TRUE,TRUE);\r
 \r
       Print(L"\t- %s\n",DevicePathTxt);\r
 \r
@@ -109,13 +97,45 @@ BootMenuAddBootOption (
        )\r
   {\r
     if (Index == SupportedDeviceSelected) {\r
-      SupportedBootDevice = SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry);\r
+      *SupportedBootDevice = SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry);\r
       break;\r
     }\r
     Index++;\r
   }\r
+  \r
+EXIT:\r
+  BootDeviceListSupportedFree (&SupportedDeviceList, *SupportedBootDevice);\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+BootMenuAddBootOption (\r
+  IN LIST_ENTRY *BootOptionsList\r
+  )\r
+{\r
+  EFI_STATUS               Status;\r
+  BDS_SUPPORTED_DEVICE*    SupportedBootDevice;\r
+  BDS_LOADER_ARGUMENTS     BootArguments;\r
+  CHAR16                    BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];\r
+  UINT32                   Attributes;\r
+  BDS_LOADER_TYPE          BootType;\r
+  BDS_LOAD_OPTION          *BdsLoadOption;\r
+  EFI_DEVICE_PATH          *DevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL *DevicePathNode;\r
+  EFI_DEVICE_PATH_PROTOCOL *InitrdPathNode;\r
+\r
+  Attributes                = 0;\r
+  SupportedBootDevice = NULL;\r
+\r
+  // List the Boot Devices supported\r
+  Status = SelectBootDevice(&SupportedBootDevice);\r
+  if (EFI_ERROR(Status)) {\r
+    Status = EFI_ABORTED;\r
+    goto EXIT;\r
+  }\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
   if (EFI_ERROR(Status)) {\r
     Status = EFI_ABORTED;\r
@@ -124,37 +144,53 @@ BootMenuAddBootOption (
   // Append the Device Path node to the select device path\r
   DevicePath = AppendDevicePathNode (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)DevicePathNode);\r
 \r
-  Print(L"Arguments to pass to the binary: ");\r
-  Status = GetHIInputAscii (AsciiBootOption,BOOT_DEVICE_OPTION_MAX);\r
-  if (EFI_ERROR(Status)) {\r
-    Status = EFI_ABORTED;\r
-    goto FREE_DEVICE_PATH;\r
+  if (BootType == BDS_LOADER_KERNEL_LINUX_ATAG) {\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
+      Status = EFI_ABORTED;\r
+      goto EXIT;\r
+    }\r
+\r
+    if (InitrdPathNode != NULL) {\r
+      // Append the Device Path node to the select device path\r
+      BootArguments.LinuxAtagArguments.InitrdPathList = AppendDevicePathNode (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNode);\r
+    } else {\r
+      BootArguments.LinuxAtagArguments.InitrdPathList = NULL;\r
+    }\r
+\r
+    Print(L"Arguments to pass to the binary: ");\r
+    Status = GetHIInputAscii (BootArguments.LinuxAtagArguments.CmdLine,BOOT_DEVICE_OPTION_MAX);\r
+    if (EFI_ERROR(Status)) {\r
+      Status = EFI_ABORTED;\r
+      goto FREE_DEVICE_PATH;\r
+    }\r
+    BootArguments.LinuxAtagArguments.CmdLine[BOOT_DEVICE_OPTION_MAX]= '\0';\r
   }\r
 \r
   Print(L"Description for this new Entry: ");\r
-  Status = GetHIInputAscii (AsciiBootDescription,BOOT_DEVICE_DESCRIPTION_MAX);\r
+  Status = GetHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);\r
   if (EFI_ERROR(Status)) {\r
     Status = EFI_ABORTED;\r
     goto FREE_DEVICE_PATH;\r
   }\r
 \r
-  // Convert Ascii into Unicode\r
-  BootDescription = (CHAR16*)AllocatePool(AsciiStrSize(AsciiBootDescription) * sizeof(CHAR16));\r
-  AsciiStrToUnicodeStr (AsciiBootDescription, BootDescription);\r
-\r
   // Create new entry\r
-  Status = BootOptionCreate (Attributes, BootDescription, DevicePath, BootType, AsciiBootOption, &BdsLoadOption);\r
+  Status = BootOptionCreate (Attributes, BootDescription, DevicePath, BootType, &BootArguments, &BdsLoadOption);\r
   if (!EFI_ERROR(Status)) {\r
     InsertTailList (BootOptionsList,&BdsLoadOption->Link);\r
   }\r
 \r
-  FreePool (BootDescription);\r
-\r
 FREE_DEVICE_PATH:\r
   FreePool (DevicePath);\r
 \r
+  \r
 EXIT:\r
-  BootDeviceListSupportedFree (&SupportedDeviceList);\r
+  if (Status == EFI_ABORTED) {\r
+    Print(L"\n");\r
+  }\r
+  FreePool(SupportedBootDevice);\r
   return Status;\r
 }\r
 \r
@@ -192,8 +228,8 @@ BootMenuSelectBootOption (
       DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText(BootOption->FilePathList,TRUE,TRUE);\r
 \r
       Print(L"\t- %s\n",DevicePathTxt);\r
-      if ((BootOption->OptionalData != NULL) && (BootOption->OptionalData->Arguments != NULL)) {\r
-        Print(L"\t- Arguments: %a\n",BootOption->OptionalData->Arguments);\r
+      if ((BDS_LOADER_TYPE)ReadUnaligned32(&BootOption->OptionalData->LoaderType) == BDS_LOADER_KERNEL_LINUX_ATAG) {\r
+        Print(L"\t- Arguments: %a\n",BootOption->OptionalData->Arguments.LinuxAtagArguments.CmdLine);\r
       }\r
 \r
       FreePool(DevicePathTxt);\r
@@ -210,7 +246,7 @@ BootMenuSelectBootOption (
     if (EFI_ERROR(Status)) {\r
       return Status;\r
     } else if ((BootOptionSelected == 0) || (BootOptionSelected >= BootOptionCount)) {\r
-      Print(L"Invalid input (max %d)\n",BootOptionCount);\r
+      Print(L"Invalid input (max %d)\n",BootOptionCount-1);\r
       BootOptionSelected = 0;\r
     }\r
   }\r
@@ -256,15 +292,13 @@ BootMenuUpdateBootOption (
   IN LIST_ENTRY *BootOptionsList\r
   )\r
 {\r
-  EFI_STATUS    Status;\r
-  BDS_LOAD_OPTION *BootOption;\r
-  BDS_LOAD_OPTION_SUPPORT*  DeviceSupport;\r
-  CHAR8       AsciiBootOption[BOOT_DEVICE_OPTION_MAX];\r
-  CHAR8       AsciiBootDescription[BOOT_DEVICE_DESCRIPTION_MAX];\r
-  CHAR16      *BootDescription;\r
-  EFI_DEVICE_PATH* DevicePath;\r
-  UINT32      Attributes;\r
-  BDS_LOADER_TYPE   BootType;\r
+  EFI_STATUS                Status;\r
+  BDS_LOAD_OPTION           *BootOption;\r
+  BDS_LOAD_OPTION_SUPPORT   *DeviceSupport;\r
+  BDS_LOADER_ARGUMENTS      BootArguments;\r
+  CHAR16                        BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];\r
+  EFI_DEVICE_PATH*          DevicePath;\r
+  BDS_LOADER_TYPE           BootType;\r
 \r
   Status = BootMenuSelectBootOption (BootOptionsList,L"Update entry: ",&BootOption);\r
   if (EFI_ERROR(Status)) {\r
@@ -278,40 +312,59 @@ BootMenuUpdateBootOption (
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  Status = DeviceSupport->UpdateDevicePathNode (BootOption,&DevicePath,&BootType,&Attributes);\r
+  Print(L"File path of the EFI Application or the kernel: ");\r
+  Status = DeviceSupport->UpdateDevicePathNode (BootOption->FilePathList, &DevicePath, NULL, NULL);\r
   if (EFI_ERROR(Status)) {\r
     Status = EFI_ABORTED;\r
     goto EXIT;\r
   }\r
 \r
-  Print(L"Arguments to pass to the binary: ");\r
-  if (BootOption->OptionalData) {\r
-    AsciiStrnCpy(AsciiBootOption,BootOption->OptionalData->Arguments,BOOT_DEVICE_FILEPATH_MAX);\r
-  } else {\r
-    AsciiBootOption[0] = '\0';\r
-  }\r
-  Status = EditHIInputAscii (AsciiBootOption,BOOT_DEVICE_OPTION_MAX);\r
-  if (EFI_ERROR(Status)) {\r
-    Status = EFI_ABORTED;\r
-    goto FREE_DEVICE_PATH;\r
+  BootType = (BDS_LOADER_TYPE)ReadUnaligned32((UINT32 *)(&BootOption->OptionalData->LoaderType));\r
+\r
+  // TODO: Allow adding an initrd to a boot entry without one\r
+  if (BootType == BDS_LOADER_KERNEL_LINUX_ATAG) {\r
+    if (ReadUnaligned16(&BootOption->OptionalData->Arguments.LinuxAtagArguments.InitrdPathListLength) > 0\r
+        && (EFI_DEVICE_PATH_PROTOCOL *)ReadUnaligned32((UINT32 *)(&BootOption->OptionalData->Arguments.LinuxAtagArguments.InitrdPathList)) != NULL) {\r
+\r
+      Print(L"File path of the initrd: ");\r
+      Status = DeviceSupport->UpdateDevicePathNode (\r
+                (EFI_DEVICE_PATH_PROTOCOL *)ReadUnaligned32((UINT32 *)(&BootOption->OptionalData->Arguments.LinuxAtagArguments.InitrdPathList)),\r
+                &BootArguments.LinuxAtagArguments.InitrdPathList,\r
+                NULL,\r
+                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
+    } else {\r
+      BootArguments.LinuxAtagArguments.InitrdPathList = NULL;\r
+      BootArguments.LinuxAtagArguments.InitrdPathListLength = 0;\r
+    }\r
+\r
+    Print(L"Arguments to pass to the binary: ");\r
+    if (ReadUnaligned32((CONST UINT32*)&BootOption->OptionalData->Arguments.LinuxAtagArguments.CmdLine)) {\r
+      AsciiStrnCpy(BootArguments.LinuxAtagArguments.CmdLine,\r
+                   BootOption->OptionalData->Arguments.LinuxAtagArguments.CmdLine,\r
+                   BOOT_DEVICE_OPTION_MAX+1);\r
+    } else {\r
+      BootArguments.LinuxAtagArguments.CmdLine[0] = '\0';\r
+    }\r
+    Status = EditHIInputAscii (BootArguments.LinuxAtagArguments.CmdLine, BOOT_DEVICE_OPTION_MAX);\r
+    if (EFI_ERROR(Status)) {\r
+      Status = EFI_ABORTED;\r
+      goto FREE_DEVICE_PATH;\r
+    }\r
   }\r
 \r
   Print(L"Description for this new Entry: ");\r
-  UnicodeStrToAsciiStr (BootOption->Description,AsciiBootDescription);\r
-  Status = EditHIInputAscii (AsciiBootDescription,BOOT_DEVICE_DESCRIPTION_MAX);\r
+  Status = EditHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);\r
   if (EFI_ERROR(Status)) {\r
     Status = EFI_ABORTED;\r
     goto FREE_DEVICE_PATH;\r
   }\r
 \r
-  // Convert Ascii into Unicode\r
-  BootDescription = (CHAR16*)AllocatePool(AsciiStrSize(AsciiBootDescription) * sizeof(CHAR16));\r
-  AsciiStrToUnicodeStr (AsciiBootDescription, BootDescription);\r
-\r
   // Update the entry\r
-  Status = BootOptionUpdate (BootOption, Attributes, BootDescription, DevicePath, BootType, AsciiBootOption);\r
-\r
-  FreePool (BootDescription);\r
+  Status = BootOptionUpdate (BootOption, BootOption->Attributes, BootDescription, DevicePath, BootType, &BootArguments);\r
 \r
 FREE_DEVICE_PATH:\r
   FreePool (DevicePath);\r
@@ -441,13 +494,18 @@ BootMenuMain (
         DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText(BootOption->FilePathList,TRUE,TRUE);\r
 \r
         Print(L"\t- %s\n",DevicePathTxt);\r
-        if (BootOption->OptionalData != NULL) {\r
-          Print(L"\t- LoaderType: %d\n", ReadUnaligned32 (&BootOption->OptionalData->LoaderType));\r
-          if (BootOption->OptionalData->Arguments != NULL) {\r
-            Print(L"\t- Arguments: %a\n",BootOption->OptionalData->Arguments);\r
+        if (ReadUnaligned32(&BootOption->OptionalData->LoaderType) == BDS_LOADER_KERNEL_LINUX_ATAG) {\r
+          if (ReadUnaligned16(&BootOption->OptionalData->Arguments.LinuxAtagArguments.InitrdPathListLength) > 0\r
+              && (EFI_DEVICE_PATH_PROTOCOL *)ReadUnaligned32((UINT32 *)(&BootOption->OptionalData->Arguments.LinuxAtagArguments.InitrdPathList)) != NULL) {\r
+            DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL *)ReadUnaligned32((UINT32 *)(&BootOption->OptionalData->Arguments.LinuxAtagArguments.InitrdPathList)),TRUE,TRUE);\r
+            Print(L"\t- Initrd: %s\n", DevicePathTxt);\r
           }\r
+        \r
+          Print(L"\t- Arguments: %a\n", BootOption->OptionalData->Arguments.LinuxAtagArguments.CmdLine);\r
         }\r
 \r
+        Print(L"\t- LoaderType: %d\n", ReadUnaligned32 (&BootOption->OptionalData->LoaderType));\r
+\r
         FreePool(DevicePathTxt);\r
       DEBUG_CODE_END();\r
 \r