]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/BdsLib/BdsFilePath.c
ArmPkg: Move IS_DEVICE_PATH_NODE for sharing
[mirror_edk2.git] / ArmPkg / Library / BdsLib / BdsFilePath.c
index a0a949d0147a37d4765aa86780d95c620fb104d7..41557bb91816e7df488298e72e44994090b2af6b 100644 (file)
@@ -24,9 +24,6 @@
 #include <Protocol/Dhcp4.h>\r
 #include <Protocol/Mtftp4.h>\r
 \r
-\r
-#define IS_DEVICE_PATH_NODE(node,type,subtype) (((node)->Type == (type)) && ((node)->SubType == (subtype)))\r
-\r
 /* Type and defines to set up the DHCP4 options */\r
 \r
 typedef struct {\r
@@ -697,7 +694,7 @@ BdsFirmwareVolumeLoadImage (
         Status = FwVol->ReadFile (\r
                                 FwVol,\r
                                 FvNameGuid,\r
-                                (VOID*)(UINTN)(*Image),\r
+                                (VOID**)Image,\r
                                 ImageSize,\r
                                 &FvType,\r
                                 &Attrib,\r
@@ -752,14 +749,14 @@ BdsPxeLoadImage (
     return Status;\r
   }\r
 \r
-  Status = LoadFileProtocol->LoadFile (LoadFileProtocol, *DevicePath, TRUE, &BufferSize, NULL);\r
+  Status = LoadFileProtocol->LoadFile (LoadFileProtocol, RemainingDevicePath, TRUE, &BufferSize, NULL);\r
   if (Status == EFI_BUFFER_TOO_SMALL) {\r
     Status = gBS->AllocatePages (Type, EfiBootServicesCode, EFI_SIZE_TO_PAGES(BufferSize), Image);\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
 \r
-    Status = LoadFileProtocol->LoadFile (LoadFileProtocol, *DevicePath, TRUE, &BufferSize, (VOID*)(UINTN)(*Image));\r
+    Status = LoadFileProtocol->LoadFile (LoadFileProtocol, RemainingDevicePath, TRUE, &BufferSize, (VOID*)(UINTN)(*Image));\r
     if (!EFI_ERROR (Status) && (ImageSize != NULL)) {\r
       *ImageSize = BufferSize;\r
     }\r
@@ -964,7 +961,7 @@ Mtftp4CheckPacket (
       Step      = (Context->DownloadedNbOfBytes   * TFTP_PROGRESS_SLIDER_STEPS) / Context->FileSize;\r
       if (Step > LastStep) {\r
         Print (mTftpProgressDelete);\r
-        StrCpy (Progress, mTftpProgressFrame);\r
+        CopyMem (Progress, mTftpProgressFrame, sizeof mTftpProgressFrame);\r
         for (Index = 1; Index < Step; Index++) {\r
           Progress[Index] = L'=';\r
         }\r
@@ -1038,12 +1035,13 @@ BdsTftpLoadImage (
   EFI_DHCP4_MODE_DATA      Dhcp4Mode;\r
   EFI_MTFTP4_CONFIG_DATA   Mtftp4CfgData;\r
   IPv4_DEVICE_PATH         *IPv4DevicePathNode;\r
-  FILEPATH_DEVICE_PATH     *FilePathDevicePathNode;\r
+  CHAR16                   *PathName;\r
   CHAR8                    *AsciiFilePath;\r
   EFI_MTFTP4_TOKEN         Mtftp4Token;\r
   UINT64                   FileSize;\r
   UINT64                   TftpBufferSize;\r
   BDS_TFTP_CONTEXT         *TftpContext;\r
+  UINTN                    PathNameLen;\r
 \r
   ASSERT(IS_DEVICE_PATH_NODE (RemainingDevicePath, MESSAGING_DEVICE_PATH, MSG_IPv4_DP));\r
   IPv4DevicePathNode = (IPv4_DEVICE_PATH*)RemainingDevicePath;\r
@@ -1185,17 +1183,11 @@ BdsTftpLoadImage (
     goto Error;\r
   }\r
 \r
-  //\r
-  // Convert the Unicode path of the file to Ascii\r
-  //\r
-\r
-  FilePathDevicePathNode = (FILEPATH_DEVICE_PATH*)(IPv4DevicePathNode + 1);\r
-  AsciiFilePath = AllocatePool ((StrLen (FilePathDevicePathNode->PathName) + 1) * sizeof (CHAR8));\r
-  if (AsciiFilePath == NULL) {\r
-    Status = EFI_OUT_OF_RESOURCES;\r
-    goto Error;\r
-  }\r
-  UnicodeStrToAsciiStr (FilePathDevicePathNode->PathName, AsciiFilePath);\r
+  // The Device Path might contain multiple FilePath nodes\r
+  PathName      = ConvertDevicePathToText ((EFI_DEVICE_PATH_PROTOCOL*)(IPv4DevicePathNode + 1), FALSE, FALSE);\r
+  PathNameLen   = StrLen (PathName) + 1;\r
+  AsciiFilePath = AllocatePool (PathNameLen);\r
+  UnicodeStrToAsciiStrS (PathName, AsciiFilePath, PathNameLen);\r
 \r
   //\r
   // Try to get the size of the file in bytes from the server. If it fails,\r
@@ -1205,7 +1197,7 @@ BdsTftpLoadImage (
   if (Mtftp4GetFileSize (Mtftp4, AsciiFilePath, &FileSize) == EFI_SUCCESS) {\r
     TftpBufferSize = FileSize;\r
   } else {\r
-    TftpBufferSize = SIZE_8MB;\r
+    TftpBufferSize = SIZE_16MB;\r
   }\r
 \r
   TftpContext = AllocatePool (sizeof (BDS_TFTP_CONTEXT));\r
@@ -1216,7 +1208,7 @@ BdsTftpLoadImage (
   TftpContext->FileSize = FileSize;\r
 \r
   for (; TftpBufferSize <= FixedPcdGet32 (PcdMaxTftpFileSize);\r
-         TftpBufferSize = (TftpBufferSize + SIZE_8MB) & (~(SIZE_8MB-1))) {\r
+         TftpBufferSize = (TftpBufferSize + SIZE_16MB) & (~(SIZE_16MB-1))) {\r
     //\r
     // Allocate a buffer to hold the whole file.\r
     //\r
@@ -1241,7 +1233,7 @@ BdsTftpLoadImage (
     Mtftp4Token.CheckPacket = Mtftp4CheckPacket;\r
     Mtftp4Token.Context     = (VOID*)TftpContext;\r
 \r
-    Print (L"Downloading the file <%s> from the TFTP server\n", FilePathDevicePathNode->PathName);\r
+    Print (L"Downloading the file <%a> from the TFTP server\n", AsciiFilePath);\r
     Status = Mtftp4->ReadFile (Mtftp4, &Mtftp4Token);\r
     Print (L"\n");\r
     if (EFI_ERROR (Status)) {\r
@@ -1303,6 +1295,7 @@ Error:
   }\r
 \r
   if (EFI_ERROR (Status)) {\r
+    *Image = 0;\r
     Print (L"Failed to download the file - Error=%r\n", Status);\r
   }\r
 \r