]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Bds/BootOptionSupport.c
ArmPlatformPkg/Bds: Added TFTP boot option update
[mirror_edk2.git] / ArmPlatformPkg / Bds / BootOptionSupport.c
index 4c37c9de8831e00d8c96ecff2a02828aa79c1b47..3eab0da83bfd5aea535238d0eb3173bca95089aa 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 *\r
-*  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+*  Copyright (c) 2011-2014, 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
@@ -33,23 +33,20 @@ BdsLoadOptionFileSystemList (
 \r
 EFI_STATUS\r
 BdsLoadOptionFileSystemCreateDevicePath (\r
-  IN  BDS_SUPPORTED_DEVICE* BdsLoadOption,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNode,\r
-  OUT ARM_BDS_LOADER_TYPE   *BootType,\r
-  OUT UINT32      *Attributes\r
+  IN CHAR16*                    FileName,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes\r
   );\r
 \r
 EFI_STATUS\r
 BdsLoadOptionFileSystemUpdateDevicePath (\r
-  IN EFI_DEVICE_PATH *OldDevicePath,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL** NewDevicePath,\r
-  OUT ARM_BDS_LOADER_TYPE *BootType,\r
-  OUT UINT32 *Attributes\r
+  IN EFI_DEVICE_PATH            *OldDevicePath,\r
+  IN CHAR16*                    FileName,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath\r
   );\r
 \r
 BOOLEAN\r
 BdsLoadOptionFileSystemIsSupported (\r
-  IN BDS_LOAD_OPTION* BdsLoadOption\r
+  IN  EFI_DEVICE_PATH           *DevicePath\r
   );\r
 \r
 EFI_STATUS\r
@@ -59,23 +56,20 @@ BdsLoadOptionMemMapList (
 \r
 EFI_STATUS\r
 BdsLoadOptionMemMapCreateDevicePath (\r
-  IN  BDS_SUPPORTED_DEVICE* BdsLoadOption,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNode,\r
-  OUT ARM_BDS_LOADER_TYPE   *BootType,\r
-  OUT UINT32      *Attributes\r
+  IN CHAR16*                    FileName,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes\r
   );\r
 \r
 EFI_STATUS\r
 BdsLoadOptionMemMapUpdateDevicePath (\r
-  IN EFI_DEVICE_PATH *OldDevicePath,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL** NewDevicePath,\r
-  OUT ARM_BDS_LOADER_TYPE *BootType,\r
-  OUT UINT32 *Attributes\r
+  IN EFI_DEVICE_PATH            *OldDevicePath,\r
+  IN CHAR16*                    FileName,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath\r
   );\r
 \r
 BOOLEAN\r
 BdsLoadOptionMemMapIsSupported (\r
-  IN BDS_LOAD_OPTION* BdsLoadOption\r
+  IN  EFI_DEVICE_PATH           *DevicePath\r
   );\r
 \r
 EFI_STATUS\r
@@ -85,23 +79,20 @@ BdsLoadOptionPxeList (
 \r
 EFI_STATUS\r
 BdsLoadOptionPxeCreateDevicePath (\r
-  IN  BDS_SUPPORTED_DEVICE* BdsLoadOption,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNode,\r
-  OUT ARM_BDS_LOADER_TYPE   *BootType,\r
-  OUT UINT32      *Attributes\r
+  IN CHAR16*                    FileName,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes\r
   );\r
 \r
 EFI_STATUS\r
 BdsLoadOptionPxeUpdateDevicePath (\r
-  IN EFI_DEVICE_PATH *OldDevicePath,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL** NewDevicePath,\r
-  OUT ARM_BDS_LOADER_TYPE *BootType,\r
-  OUT UINT32 *Attributes\r
+  IN EFI_DEVICE_PATH            *OldDevicePath,\r
+  IN CHAR16*                    FileName,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath\r
   );\r
 \r
 BOOLEAN\r
 BdsLoadOptionPxeIsSupported (\r
-  IN BDS_LOAD_OPTION* BdsLoadOption\r
+  IN  EFI_DEVICE_PATH           *DevicePath\r
   );\r
 \r
 EFI_STATUS\r
@@ -111,23 +102,20 @@ BdsLoadOptionTftpList (
 \r
 EFI_STATUS\r
 BdsLoadOptionTftpCreateDevicePath (\r
-  IN  BDS_SUPPORTED_DEVICE* BdsLoadOption,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNode,\r
-  OUT ARM_BDS_LOADER_TYPE   *BootType,\r
-  OUT UINT32      *Attributes\r
+  IN CHAR16*                    FileName,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes\r
   );\r
 \r
 EFI_STATUS\r
 BdsLoadOptionTftpUpdateDevicePath (\r
-  IN EFI_DEVICE_PATH *OldDevicePath,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL** NewDevicePath,\r
-  OUT ARM_BDS_LOADER_TYPE *BootType,\r
-  OUT UINT32 *Attributes\r
+  IN EFI_DEVICE_PATH            *OldDevicePath,\r
+  IN CHAR16*                    FileName,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath\r
   );\r
 \r
 BOOLEAN\r
 BdsLoadOptionTftpIsSupported (\r
-  IN BDS_LOAD_OPTION* BdsLoadOption\r
+  IN  EFI_DEVICE_PATH           *DevicePath\r
   );\r
 \r
 BDS_LOAD_OPTION_SUPPORT BdsLoadOptionSupportList[] = {\r
@@ -136,28 +124,32 @@ BDS_LOAD_OPTION_SUPPORT BdsLoadOptionSupportList[] = {
     BdsLoadOptionFileSystemList,\r
     BdsLoadOptionFileSystemIsSupported,\r
     BdsLoadOptionFileSystemCreateDevicePath,\r
-    BdsLoadOptionFileSystemUpdateDevicePath\r
+    BdsLoadOptionFileSystemUpdateDevicePath,\r
+    TRUE\r
   },\r
   {\r
     BDS_DEVICE_MEMMAP,\r
     BdsLoadOptionMemMapList,\r
     BdsLoadOptionMemMapIsSupported,\r
     BdsLoadOptionMemMapCreateDevicePath,\r
-    BdsLoadOptionMemMapUpdateDevicePath\r
+    BdsLoadOptionMemMapUpdateDevicePath,\r
+    TRUE\r
   },\r
   {\r
     BDS_DEVICE_PXE,\r
     BdsLoadOptionPxeList,\r
     BdsLoadOptionPxeIsSupported,\r
     BdsLoadOptionPxeCreateDevicePath,\r
-    BdsLoadOptionPxeUpdateDevicePath\r
+    BdsLoadOptionPxeUpdateDevicePath,\r
+    FALSE\r
   },\r
   {\r
     BDS_DEVICE_TFTP,\r
     BdsLoadOptionTftpList,\r
     BdsLoadOptionTftpIsSupported,\r
     BdsLoadOptionTftpCreateDevicePath,\r
-    BdsLoadOptionTftpUpdateDevicePath\r
+    BdsLoadOptionTftpUpdateDevicePath,\r
+    TRUE\r
   }\r
 };\r
 \r
@@ -201,15 +193,15 @@ BootDeviceListSupportedFree (
 \r
 EFI_STATUS\r
 BootDeviceGetDeviceSupport (\r
-  IN  BDS_LOAD_OPTION *BootOption,\r
-  OUT BDS_LOAD_OPTION_SUPPORT**  DeviceSupport\r
+  IN  EFI_DEVICE_PATH           *DevicePath,\r
+  OUT BDS_LOAD_OPTION_SUPPORT   **DeviceSupport\r
   )\r
 {\r
   UINTN Index;\r
 \r
   // Find which supported device is the most appropriate\r
   for (Index = 0; Index < BDS_DEVICE_MAX; Index++) {\r
-    if (BdsLoadOptionSupportList[Index].IsSupported(BootOption)) {\r
+    if (BdsLoadOptionSupportList[Index].IsSupported (DevicePath)) {\r
       *DeviceSupport = &BdsLoadOptionSupportList[Index];\r
       return EFI_SUCCESS;\r
     }\r
@@ -218,18 +210,44 @@ BootDeviceGetDeviceSupport (
   return EFI_UNSUPPORTED;\r
 }\r
 \r
-STATIC\r
 EFI_STATUS\r
 BootDeviceGetType (\r
-  IN  CHAR16* FileName,\r
+  IN  EFI_DEVICE_PATH* DevicePath,\r
   OUT ARM_BDS_LOADER_TYPE *BootType,\r
   OUT UINT32 *Attributes\r
   )\r
 {\r
-  EFI_STATUS Status;\r
-  BOOLEAN IsEfiApp;\r
-  BOOLEAN IsBootLoader;\r
-  BOOLEAN     HasFDTSupport;\r
+  EFI_STATUS              Status;\r
+  BOOLEAN                 IsEfiApp;\r
+  BOOLEAN                 IsBootLoader;\r
+  BOOLEAN                 HasFDTSupport;\r
+  CHAR16*                 FileName;\r
+  EFI_DEVICE_PATH*        PrevDevicePathNode;\r
+  EFI_DEVICE_PATH*        DevicePathNode;\r
+  EFI_PHYSICAL_ADDRESS    Image;\r
+  UINTN                   FileSize;\r
+  EFI_IMAGE_DOS_HEADER*   DosHeader;\r
+  UINTN                   PeCoffHeaderOffset;\r
+  EFI_IMAGE_NT_HEADERS32* NtHeader;\r
+\r
+  //\r
+  // Check if the last node of the device path is a FilePath node\r
+  //\r
+  PrevDevicePathNode = NULL;\r
+  DevicePathNode = DevicePath;\r
+  while ((DevicePathNode != NULL) && !IsDevicePathEnd (DevicePathNode)) {\r
+    PrevDevicePathNode = DevicePathNode;\r
+    DevicePathNode = NextDevicePathNode (DevicePathNode);\r
+  }\r
+\r
+  if ((PrevDevicePathNode != NULL) &&\r
+      (PrevDevicePathNode->Type == MEDIA_DEVICE_PATH) &&\r
+      (PrevDevicePathNode->SubType == MEDIA_FILEPATH_DP))\r
+  {\r
+    FileName = ((FILEPATH_DEVICE_PATH*)PrevDevicePathNode)->PathName;\r
+  } else {\r
+    FileName = NULL;\r
+  }\r
 \r
   if (FileName == NULL) {\r
     Print(L"Is an EFI Application? ");\r
@@ -240,7 +258,41 @@ BootDeviceGetType (
   } else if (HasFilePathEfiExtension(FileName)) {\r
     IsEfiApp = TRUE;\r
   } else {\r
-    IsEfiApp = FALSE;\r
+    // Check if the file exist\r
+    Status = BdsLoadImage (DevicePath, AllocateAnyPages, &Image, &FileSize);\r
+    if (!EFI_ERROR (Status)) {\r
+\r
+      DosHeader = (EFI_IMAGE_DOS_HEADER *)(UINTN) Image;\r
+      if (DosHeader->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
+        //\r
+        // DOS image header is present,\r
+        // so read the PE header after the DOS image header.\r
+        //\r
+        PeCoffHeaderOffset = DosHeader->e_lfanew;\r
+      } else {\r
+        PeCoffHeaderOffset = 0;\r
+      }\r
+\r
+      //\r
+      // Check PE/COFF image.\r
+      //\r
+      NtHeader = (EFI_IMAGE_NT_HEADERS32 *)(UINTN) (Image + PeCoffHeaderOffset);\r
+      if (NtHeader->Signature != EFI_IMAGE_NT_SIGNATURE) {\r
+        IsEfiApp = FALSE;\r
+      } else {\r
+        IsEfiApp = TRUE;\r
+      }\r
+\r
+      // Free memory\r
+      gBS->FreePages (Image, EFI_SIZE_TO_PAGES(FileSize));\r
+    } else {\r
+      // If we did not manage to open it then ask for the type\r
+      Print(L"Is an EFI Application? ");\r
+      Status = GetHIInputBoolean (&IsEfiApp);\r
+      if (EFI_ERROR(Status)) {\r
+        return EFI_ABORTED;\r
+      }\r
+    }\r
   }\r
 \r
   if (IsEfiApp) {\r
@@ -327,10 +379,8 @@ BdsLoadOptionFileSystemList (
 \r
 EFI_STATUS\r
 BdsLoadOptionFileSystemCreateDevicePath (\r
-  IN  BDS_SUPPORTED_DEVICE* BdsLoadOption,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNode,\r
-  OUT ARM_BDS_LOADER_TYPE   *BootType,\r
-  OUT UINT32      *Attributes\r
+  IN CHAR16*                    FileName,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -338,6 +388,7 @@ BdsLoadOptionFileSystemCreateDevicePath (
   CHAR16      BootFilePath[BOOT_DEVICE_FILEPATH_MAX];\r
   UINTN       BootFilePathSize;\r
 \r
+  Print(L"File path of the %s: ", FileName);\r
   Status = GetHIInputStr (BootFilePath, BOOT_DEVICE_FILEPATH_MAX);\r
   if (EFI_ERROR(Status)) {\r
     return EFI_ABORTED;\r
@@ -345,36 +396,27 @@ BdsLoadOptionFileSystemCreateDevicePath (
 \r
   BootFilePathSize = StrSize (BootFilePath);\r
   if (BootFilePathSize == 2) {\r
-    *DevicePathNode = NULL;\r
+    *DevicePathNodes = NULL;\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
   // Create the FilePath Device Path node\r
-  FilePathDevicePath = (FILEPATH_DEVICE_PATH*)AllocatePool(SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize);\r
+  FilePathDevicePath = (FILEPATH_DEVICE_PATH*)AllocatePool(SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize + END_DEVICE_PATH_LENGTH);\r
   FilePathDevicePath->Header.Type = MEDIA_DEVICE_PATH;\r
   FilePathDevicePath->Header.SubType = MEDIA_FILEPATH_DP;\r
   SetDevicePathNodeLength (FilePathDevicePath, SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize);\r
   CopyMem (FilePathDevicePath->PathName, BootFilePath, BootFilePathSize);\r
-\r
-  if (BootType != NULL || Attributes != NULL) {\r
-    Status = BootDeviceGetType (FilePathDevicePath->PathName, BootType, Attributes);\r
-  }\r
-\r
-  if (EFI_ERROR(Status)) {\r
-    FreePool (FilePathDevicePath);\r
-  } else {\r
-    *DevicePathNode = (EFI_DEVICE_PATH_PROTOCOL*)FilePathDevicePath;\r
-  }\r
+  SetDevicePathEndNode ((VOID*)((UINTN)FilePathDevicePath + SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize));\r
+  *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)FilePathDevicePath;\r
 \r
   return Status;\r
 }\r
 \r
 EFI_STATUS\r
 BdsLoadOptionFileSystemUpdateDevicePath (\r
-  IN EFI_DEVICE_PATH *OldDevicePath,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL** NewDevicePath,\r
-  OUT ARM_BDS_LOADER_TYPE *BootType,\r
-  OUT UINT32 *Attributes\r
+  IN EFI_DEVICE_PATH            *OldDevicePath,\r
+  IN CHAR16*                    FileName,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -384,10 +426,11 @@ BdsLoadOptionFileSystemUpdateDevicePath (
   FILEPATH_DEVICE_PATH* FilePathDevicePath;\r
   EFI_DEVICE_PATH*  DevicePath;\r
 \r
-  DevicePath = DuplicateDevicePath(OldDevicePath);\r
+  DevicePath = DuplicateDevicePath (OldDevicePath);\r
 \r
   EndingDevicePath = (FILEPATH_DEVICE_PATH*)GetLastDevicePathNode (DevicePath);\r
  \r
+  Print(L"File path of the %s: ", FileName);\r
   StrnCpy (BootFilePath, EndingDevicePath->PathName, BOOT_DEVICE_FILEPATH_MAX);\r
   Status = EditHIInputStr (BootFilePath, BOOT_DEVICE_FILEPATH_MAX);\r
   if (EFI_ERROR(Status)) {\r
@@ -412,21 +455,17 @@ BdsLoadOptionFileSystemUpdateDevicePath (
   *NewDevicePath = AppendDevicePathNode (DevicePath, (CONST EFI_DEVICE_PATH_PROTOCOL *)FilePathDevicePath);\r
   FreePool(DevicePath);\r
 \r
-  if (BootType != NULL || Attributes != NULL) {\r
-    return BootDeviceGetType (FilePathDevicePath->PathName, BootType, Attributes);\r
-  }\r
-\r
   return EFI_SUCCESS;\r
 }\r
 \r
 BOOLEAN\r
 BdsLoadOptionFileSystemIsSupported (\r
-  IN BDS_LOAD_OPTION* BdsLoadOption\r
+  IN  EFI_DEVICE_PATH           *DevicePath\r
   )\r
 {\r
   EFI_DEVICE_PATH*  DevicePathNode;\r
 \r
-  DevicePathNode = GetLastDevicePathNode (BdsLoadOption->FilePathList);\r
+  DevicePathNode = GetLastDevicePathNode (DevicePath);\r
 \r
   return IS_DEVICE_PATH_NODE(DevicePathNode,MEDIA_DEVICE_PATH,MEDIA_FILEPATH_DP);\r
 }\r
@@ -525,53 +564,48 @@ BdsLoadOptionMemMapList (
 \r
 EFI_STATUS\r
 BdsLoadOptionMemMapCreateDevicePath (\r
-  IN  BDS_SUPPORTED_DEVICE* BdsLoadOption,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNode,\r
-  OUT ARM_BDS_LOADER_TYPE   *BootType,\r
-  OUT UINT32      *Attributes\r
+  IN CHAR16*                    FileName,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-  MEMMAP_DEVICE_PATHMemMapDevicePath;\r
-  CHAR16       StrStartingAddress[BOOT_DEVICE_ADDRESS_MAX];\r
-  CHAR16       StrEndingAddress[BOOT_DEVICE_ADDRESS_MAX];\r
+  EFI_STATUS              Status;\r
+  MEMMAP_DEVICE_PATH      *MemMapDevicePath;\r
+  CHAR16                  StrStartingAddress[BOOT_DEVICE_ADDRESS_MAX];\r
+  CHAR16                  StrEndingAddress[BOOT_DEVICE_ADDRESS_MAX];\r
 \r
-  Print(L"Starting Address of the binary: ");\r
-  Status = GetHIInputStr (StrStartingAddress,BOOT_DEVICE_ADDRESS_MAX);\r
+  Print(L"Starting Address of the %s: ", FileName);\r
+  Status = GetHIInputStr (StrStartingAddress, BOOT_DEVICE_ADDRESS_MAX);\r
   if (EFI_ERROR(Status)) {\r
     return EFI_ABORTED;\r
   }\r
 \r
-  Print(L"Ending Address of the binary: ");\r
-  Status = GetHIInputStr (StrEndingAddress,BOOT_DEVICE_ADDRESS_MAX);\r
+  Print(L"Ending Address of the %s: ", FileName);\r
+  Status = GetHIInputStr (StrEndingAddress, BOOT_DEVICE_ADDRESS_MAX);\r
   if (EFI_ERROR(Status)) {\r
     return EFI_ABORTED;\r
   }\r
 \r
   // Create the MemMap Device Path Node\r
-  MemMapDevicePath = (MEMMAP_DEVICE_PATH*)AllocatePool (sizeof(MEMMAP_DEVICE_PATH));\r
+  MemMapDevicePath = (MEMMAP_DEVICE_PATH*)AllocatePool (sizeof(MEMMAP_DEVICE_PATH) + END_DEVICE_PATH_LENGTH);\r
   MemMapDevicePath->Header.Type = HARDWARE_DEVICE_PATH;\r
   MemMapDevicePath->Header.SubType = HW_MEMMAP_DP;\r
+  SetDevicePathNodeLength (MemMapDevicePath, sizeof(MEMMAP_DEVICE_PATH));\r
   MemMapDevicePath->MemoryType = EfiBootServicesData;\r
   MemMapDevicePath->StartingAddress = StrHexToUint64 (StrStartingAddress);\r
   MemMapDevicePath->EndingAddress = StrHexToUint64 (StrEndingAddress);\r
 \r
-  Status = BootDeviceGetType (NULL, BootType, Attributes);\r
-  if (EFI_ERROR(Status)) {\r
-    FreePool (MemMapDevicePath);\r
-  } else {\r
-    *DevicePathNode = (EFI_DEVICE_PATH_PROTOCOL*)MemMapDevicePath;\r
-  }\r
+  // Set a Device Path End Node after the Memory Map Device Path Node\r
+  SetDevicePathEndNode (MemMapDevicePath + 1);\r
+  *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)MemMapDevicePath;\r
 \r
   return Status;\r
 }\r
 \r
 EFI_STATUS\r
 BdsLoadOptionMemMapUpdateDevicePath (\r
-  IN EFI_DEVICE_PATH *OldDevicePath,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL** NewDevicePath,\r
-  OUT ARM_BDS_LOADER_TYPE *BootType,\r
-  OUT UINT32 *Attributes\r
+  IN EFI_DEVICE_PATH            *OldDevicePath,\r
+  IN CHAR16*                    FileName,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath\r
   )\r
 {\r
   EFI_STATUS          Status;\r
@@ -583,14 +617,14 @@ BdsLoadOptionMemMapUpdateDevicePath (
   DevicePath = DuplicateDevicePath (OldDevicePath);\r
   EndingDevicePath = (MEMMAP_DEVICE_PATH*)GetLastDevicePathNode (DevicePath);\r
 \r
-  Print(L"Starting Address of the binary: ");\r
+  Print(L"Starting Address of the %s: ", FileName);\r
   UnicodeSPrint (StrStartingAddress, BOOT_DEVICE_ADDRESS_MAX, L"0x%X", (UINTN)EndingDevicePath->StartingAddress);\r
   Status = EditHIInputStr (StrStartingAddress, BOOT_DEVICE_ADDRESS_MAX);\r
   if (EFI_ERROR(Status)) {\r
     return EFI_ABORTED;\r
   }\r
 \r
-  Print(L"Ending Address of the binary: ");\r
+  Print(L"Ending Address of the %s: ", FileName);\r
   UnicodeSPrint (StrEndingAddress, BOOT_DEVICE_ADDRESS_MAX, L"0x%X", (UINTN)EndingDevicePath->EndingAddress);\r
   Status = EditHIInputStr (StrEndingAddress, BOOT_DEVICE_ADDRESS_MAX);\r
   if (EFI_ERROR(Status)) {\r
@@ -600,7 +634,6 @@ BdsLoadOptionMemMapUpdateDevicePath (
   EndingDevicePath->StartingAddress = StrHexToUint64 (StrStartingAddress);\r
   EndingDevicePath->EndingAddress = StrHexToUint64 (StrEndingAddress);\r
 \r
-  Status = BootDeviceGetType (NULL, BootType, Attributes);\r
   if (EFI_ERROR(Status)) {\r
     FreePool(DevicePath);\r
   } else {\r
@@ -612,12 +645,12 @@ BdsLoadOptionMemMapUpdateDevicePath (
 \r
 BOOLEAN\r
 BdsLoadOptionMemMapIsSupported (\r
-  IN BDS_LOAD_OPTION* BdsLoadOption\r
+  IN  EFI_DEVICE_PATH           *DevicePath\r
   )\r
 {\r
   EFI_DEVICE_PATH*  DevicePathNode;\r
 \r
-  DevicePathNode = GetLastDevicePathNode (BdsLoadOption->FilePathList);\r
+  DevicePathNode = GetLastDevicePathNode (DevicePath);\r
 \r
   return IS_DEVICE_PATH_NODE(DevicePathNode,HARDWARE_DEVICE_PATH,HW_MEMMAP_DP);\r
 }\r
@@ -672,33 +705,50 @@ BdsLoadOptionPxeList (
 \r
 EFI_STATUS\r
 BdsLoadOptionPxeCreateDevicePath (\r
-  IN  BDS_SUPPORTED_DEVICE* BdsLoadOption,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNode,\r
-  OUT ARM_BDS_LOADER_TYPE   *BootType,\r
-  OUT UINT32      *Attributes\r
+  IN CHAR16*                    FileName,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes\r
   )\r
 {\r
-  *DevicePathNode = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);\r
-  SetDevicePathEndNode (*DevicePathNode);\r
-  *BootType = BDS_LOADER_EFI_APPLICATION;\r
+  *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL *) AllocatePool (END_DEVICE_PATH_LENGTH);\r
+  SetDevicePathEndNode (*DevicePathNodes);\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Update the parameters of a Pxe boot option\r
+\r
+  @param[in]   OldDevicePath  Current complete device path of the Pxe boot option.\r
+                              This has to be a valid complete Pxe boot option path.\r
+  @param[in]   FileName       Description of the file the path is asked for\r
+  @param[out]  NewDevicePath  Pointer to the new complete device path.\r
+\r
+  @retval  EFI_SUCCESS            Update completed\r
+  @retval  EFI_OUT_OF_RESOURCES   Fail to perform the update due to lack of resource\r
+**/\r
 EFI_STATUS\r
 BdsLoadOptionPxeUpdateDevicePath (\r
-  IN EFI_DEVICE_PATH *OldDevicePath,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL** NewDevicePath,\r
-  OUT ARM_BDS_LOADER_TYPE *BootType,\r
-  OUT UINT32 *Attributes\r
+  IN EFI_DEVICE_PATH            *OldDevicePath,\r
+  IN CHAR16*                    FileName,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath\r
   )\r
 {\r
-  ASSERT (0);\r
-  return EFI_SUCCESS;\r
+  //\r
+  // Make a copy of the complete device path that is made of :\r
+  // the device path of the device supporting the Pxe base code protocol\r
+  // followed by an end node.\r
+  //\r
+  *NewDevicePath = DuplicateDevicePath (OldDevicePath);\r
+  if (*NewDevicePath == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  } else {\r
+    return EFI_SUCCESS;\r
+  }\r
 }\r
 \r
 BOOLEAN\r
 BdsLoadOptionPxeIsSupported (\r
-  IN BDS_LOAD_OPTION* BdsLoadOption\r
+  IN  EFI_DEVICE_PATH           *DevicePath\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -706,7 +756,7 @@ BdsLoadOptionPxeIsSupported (
   EFI_DEVICE_PATH_PROTOCOL  *RemainingDevicePath;\r
   EFI_PXE_BASE_CODE_PROTOCOL  *PxeBcProtocol;\r
 \r
-  Status = BdsConnectDevicePath (BdsLoadOption->FilePathList, &Handle, &RemainingDevicePath);\r
+  Status = BdsConnectDevicePath (DevicePath, &Handle, &RemainingDevicePath);\r
   if (EFI_ERROR(Status)) {\r
     return FALSE;\r
   }\r
@@ -759,7 +809,7 @@ BdsLoadOptionTftpList (
         Status = GenerateDeviceDescriptionName (HandleBuffer[Index], DeviceDescription);\r
         ASSERT_EFI_ERROR (Status);\r
       }\r
-      UnicodeSPrint (SupportedDevice->Description,BOOT_DEVICE_DESCRIPTION_MAX,L"TFP on %s",DeviceDescription);\r
+      UnicodeSPrint (SupportedDevice->Description,BOOT_DEVICE_DESCRIPTION_MAX,L"TFTP on %s",DeviceDescription);\r
 \r
       SupportedDevice->DevicePathProtocol = DevicePathProtocol;\r
       SupportedDevice->Support = &BdsLoadOptionSupportList[BDS_DEVICE_TFTP];\r
@@ -773,10 +823,8 @@ BdsLoadOptionTftpList (
 \r
 EFI_STATUS\r
 BdsLoadOptionTftpCreateDevicePath (\r
-  IN  BDS_SUPPORTED_DEVICE* BdsLoadOption,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNode,\r
-  OUT ARM_BDS_LOADER_TYPE   *BootType,\r
-  OUT UINT32      *Attributes\r
+  IN CHAR16*                    FileName,\r
+  OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePathNodes\r
   )\r
 {\r
   EFI_STATUS    Status;\r
@@ -808,7 +856,7 @@ BdsLoadOptionTftpCreateDevicePath (
     return EFI_ABORTED;\r
   }\r
 \r
-  Print(L"File path of the EFI Application or the kernel : ");\r
+  Print(L"File path of the %s : ", FileName);\r
   Status = GetHIInputStr (BootFilePath, BOOT_DEVICE_FILEPATH_MAX);\r
   if (EFI_ERROR(Status)) {\r
     return EFI_ABORTED;\r
@@ -820,7 +868,7 @@ BdsLoadOptionTftpCreateDevicePath (
   }\r
 \r
   // Allocate the memory for the IPv4 + File Path Device Path Nodes\r
-  IPv4DevicePathNode = (IPv4_DEVICE_PATH*)AllocatePool(sizeof(IPv4_DEVICE_PATH) + SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize);\r
+  IPv4DevicePathNode = (IPv4_DEVICE_PATH*)AllocatePool(sizeof(IPv4_DEVICE_PATH) + SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize + END_DEVICE_PATH_LENGTH);\r
 \r
   // Create the IPv4 Device Path\r
   IPv4DevicePathNode->Header.Type    = MESSAGING_DEVICE_PATH;\r
@@ -840,31 +888,196 @@ BdsLoadOptionTftpCreateDevicePath (
   SetDevicePathNodeLength (FilePathDevicePath, SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize);\r
   CopyMem (FilePathDevicePath->PathName, BootFilePath, BootFilePathSize);\r
 \r
-  Status = BootDeviceGetType (NULL, BootType, Attributes);\r
-  if (EFI_ERROR(Status)) {\r
-    FreePool (IPv4DevicePathNode);\r
-  } else {\r
-    *DevicePathNode = (EFI_DEVICE_PATH_PROTOCOL*)IPv4DevicePathNode;\r
-  }\r
+  // Set the End Device Path Node\r
+  SetDevicePathEndNode ((VOID*)((UINTN)FilePathDevicePath + SIZE_OF_FILEPATH_DEVICE_PATH + BootFilePathSize));\r
+  *DevicePathNodes = (EFI_DEVICE_PATH_PROTOCOL*)IPv4DevicePathNode;\r
 \r
   return Status;\r
 }\r
 \r
+/**\r
+  Update the parameters of a TFTP boot option\r
+\r
+  The function asks sequentially to update the IPv4 parameters as well as the boot file path,\r
+  providing the previously set value if any.\r
+\r
+  @param[in]   OldDevicePath  Current complete device path of the Tftp boot option.\r
+                              This has to be a valid complete Tftp boot option path.\r
+                              By complete, we mean that it is not only the Tftp\r
+                              specific end part built by the\r
+                              "BdsLoadOptionTftpCreateDevicePath()" function.\r
+                              This path is handled as read only.\r
+  @param[in]   FileName       Description of the file the path is asked for\r
+  @param[out]  NewDevicePath  Pointer to the new complete device path.\r
+\r
+  @retval  EFI_SUCCESS            Update completed\r
+  @retval  EFI_ABORTED            Update aborted by the user\r
+  @retval  EFI_OUT_OF_RESOURCES   Fail to perform the update due to lack of resource\r
+**/\r
 EFI_STATUS\r
 BdsLoadOptionTftpUpdateDevicePath (\r
-  IN EFI_DEVICE_PATH *OldDevicePath,\r
-  OUT EFI_DEVICE_PATH_PROTOCOL** NewDevicePath,\r
-  OUT ARM_BDS_LOADER_TYPE *BootType,\r
-  OUT UINT32 *Attributes\r
+  IN   EFI_DEVICE_PATH            *OldDevicePath,\r
+  IN   CHAR16                     *FileName,\r
+  OUT  EFI_DEVICE_PATH_PROTOCOL  **NewDevicePath\r
   )\r
 {\r
-  ASSERT (0);\r
-  return EFI_SUCCESS;\r
+  EFI_STATUS             Status;\r
+  EFI_DEVICE_PATH       *DevicePath;\r
+  EFI_DEVICE_PATH       *DevicePathNode;\r
+  UINT8                 *Ipv4NodePtr;\r
+  IPv4_DEVICE_PATH       Ipv4Node;\r
+  BOOLEAN                IsDHCP;\r
+  EFI_IP_ADDRESS         OldIp;\r
+  EFI_IP_ADDRESS         LocalIp;\r
+  EFI_IP_ADDRESS         RemoteIp;\r
+  UINT8                 *FileNodePtr;\r
+  CHAR16                 BootFilePath[BOOT_DEVICE_FILEPATH_MAX];\r
+  UINTN                  PathSize;\r
+  UINTN                  BootFilePathSize;\r
+  FILEPATH_DEVICE_PATH  *NewFilePathNode;\r
+\r
+  Ipv4NodePtr = NULL;\r
+\r
+  //\r
+  // Make a copy of the complete device path that is made of :\r
+  // the device path of the device that support the Simple Network protocol\r
+  // followed by an IPv4 node (type IPv4_DEVICE_PATH),\r
+  // followed by a file path node (type FILEPATH_DEVICE_PATH) and ended up\r
+  // by an end node. The IPv6 case is not handled yet.\r
+  //\r
+\r
+  DevicePath = DuplicateDevicePath (OldDevicePath);\r
+  if (DevicePath == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ErrorExit;\r
+  }\r
+\r
+  //\r
+  // Because of the check done by "BdsLoadOptionTftpIsSupported()" prior to the\r
+  // call to this function, we know that the device path ends with an IPv4 node\r
+  // followed by a file path node and finally an end node. To get the address of\r
+  // the last IPv4 node, we loop over the whole device path, noting down the\r
+  // address of each encountered IPv4 node.\r
+  //\r
+\r
+  for (DevicePathNode = DevicePath;\r
+       !IsDevicePathEnd (DevicePathNode);\r
+       DevicePathNode = NextDevicePathNode (DevicePathNode))\r
+  {\r
+    if (IS_DEVICE_PATH_NODE (DevicePathNode, MESSAGING_DEVICE_PATH, MSG_IPv4_DP)) {\r
+      Ipv4NodePtr = (UINT8*)DevicePathNode;\r
+    }\r
+  }\r
+\r
+  // Copy for alignment of the IPv4 node data\r
+  CopyMem (&Ipv4Node, Ipv4NodePtr, sizeof (IPv4_DEVICE_PATH));\r
+\r
+  Print (L"Get the IP address from DHCP: ");\r
+  Status = GetHIInputBoolean (&IsDHCP);\r
+  if (EFI_ERROR (Status)) {\r
+    goto ErrorExit;\r
+  }\r
+\r
+  if (!IsDHCP) {\r
+    Print (L"Local static IP address: ");\r
+    if (Ipv4Node.StaticIpAddress) {\r
+      // Copy local IPv4 address into IPv4 or IPv6 union\r
+      CopyMem (&OldIp.v4, &Ipv4Node.LocalIpAddress, sizeof (EFI_IPv4_ADDRESS));\r
+\r
+      Status = EditHIInputIP (&OldIp, &LocalIp);\r
+    } else {\r
+      Status = GetHIInputIP (&LocalIp);\r
+    }\r
+    if (EFI_ERROR (Status)) {\r
+      goto ErrorExit;\r
+    }\r
+  }\r
+\r
+  Print (L"TFTP server IP address: ");\r
+  // Copy remote IPv4 address into IPv4 or IPv6 union\r
+  CopyMem (&OldIp.v4, &Ipv4Node.RemoteIpAddress, sizeof (EFI_IPv4_ADDRESS));\r
+\r
+  Status = EditHIInputIP (&OldIp, &RemoteIp);\r
+  if (EFI_ERROR (Status)) {\r
+    goto ErrorExit;\r
+  }\r
+\r
+  // Get the path of the boot file and its size in number of bytes\r
+  FileNodePtr = Ipv4NodePtr + sizeof (IPv4_DEVICE_PATH);\r
+  BootFilePathSize = DevicePathNodeLength (FileNodePtr) - SIZE_OF_FILEPATH_DEVICE_PATH;\r
+\r
+  //\r
+  // Ask for update of the boot file path\r
+  //\r
+  do {\r
+    // Copy for 2-byte alignment of the Unicode string\r
+    CopyMem (\r
+      BootFilePath, FileNodePtr + SIZE_OF_FILEPATH_DEVICE_PATH,\r
+      MIN (BootFilePathSize, BOOT_DEVICE_FILEPATH_MAX)\r
+      );\r
+    BootFilePath[BOOT_DEVICE_FILEPATH_MAX - 1] = L'\0';\r
+\r
+    Print (L"File path of the %s: ", FileName);\r
+    Status = EditHIInputStr (BootFilePath, BOOT_DEVICE_FILEPATH_MAX);\r
+    if (EFI_ERROR (Status)) {\r
+      goto ErrorExit;\r
+    }\r
+    PathSize = StrSize (BootFilePath);\r
+    if (PathSize > 2) {\r
+      break;\r
+    }\r
+    // Empty string, give the user another try\r
+    Print (L"Empty string - Invalid path\n");\r
+  } while (PathSize <= 2) ;\r
+\r
+  //\r
+  // Update the IPv4 node. IPv6 case not handled yet.\r
+  //\r
+  if (IsDHCP == TRUE) {\r
+    Ipv4Node.StaticIpAddress = FALSE;\r
+  } else {\r
+    Ipv4Node.StaticIpAddress = TRUE;\r
+  }\r
+  CopyMem (&Ipv4Node.LocalIpAddress, &LocalIp.v4, sizeof (EFI_IPv4_ADDRESS));\r
+  CopyMem (&Ipv4Node.RemoteIpAddress, &RemoteIp.v4, sizeof (EFI_IPv4_ADDRESS));\r
+  CopyMem (Ipv4NodePtr, &Ipv4Node, sizeof (IPv4_DEVICE_PATH));\r
+\r
+  //\r
+  // Create the new file path node\r
+  //\r
+  NewFilePathNode = (FILEPATH_DEVICE_PATH*)AllocatePool (\r
+                                             SIZE_OF_FILEPATH_DEVICE_PATH +\r
+                                             PathSize\r
+                                             );\r
+  NewFilePathNode->Header.Type    = MEDIA_DEVICE_PATH;\r
+  NewFilePathNode->Header.SubType = MEDIA_FILEPATH_DP;\r
+  SetDevicePathNodeLength (\r
+    NewFilePathNode,\r
+    SIZE_OF_FILEPATH_DEVICE_PATH + PathSize\r
+    );\r
+  CopyMem (NewFilePathNode->PathName, BootFilePath, PathSize);\r
+\r
+  //\r
+  // Generate the new Device Path by replacing the file path node at address\r
+  // "FileNodePtr" by the new one "NewFilePathNode" and return its address.\r
+  //\r
+  SetDevicePathEndNode (FileNodePtr);\r
+  *NewDevicePath = AppendDevicePathNode (\r
+                     DevicePath,\r
+                     (CONST EFI_DEVICE_PATH_PROTOCOL*)NewFilePathNode\r
+                     );\r
+\r
+ErrorExit:\r
+  if (DevicePath != NULL) {\r
+    FreePool (DevicePath) ;\r
+  }\r
+\r
+  return Status;\r
 }\r
 \r
 BOOLEAN\r
 BdsLoadOptionTftpIsSupported (\r
-  IN BDS_LOAD_OPTION* BdsLoadOption\r
+  IN  EFI_DEVICE_PATH           *DevicePath\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -873,7 +1086,7 @@ BdsLoadOptionTftpIsSupported (
   EFI_DEVICE_PATH  *NextDevicePath;\r
   EFI_PXE_BASE_CODE_PROTOCOL  *PxeBcProtocol;\r
 \r
-  Status = BdsConnectDevicePath (BdsLoadOption->FilePathList, &Handle, &RemainingDevicePath);\r
+  Status = BdsConnectDevicePath (DevicePath, &Handle, &RemainingDevicePath);\r
   if (EFI_ERROR(Status)) {\r
     return FALSE;\r
   }\r