]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/BdsLib: Added support for TFTP servers without 'tsize' extension
authorOlivier Martin <olivier.martin@arm.com>
Mon, 19 May 2014 16:41:25 +0000 (16:41 +0000)
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 19 May 2014 16:41:25 +0000 (16:41 +0000)
Some TFTP servers do not have 'tsize' extension.
This change allows to download files from TFTP servers that do not have
this extension by trying to download the file into a pre-allocated buffer.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15539 6f19259b-4bc3-4df7-8a09-765794883524

ArmPkg/ArmPkg.dec
ArmPkg/Library/BdsLib/BdsFilePath.c
ArmPkg/Library/BdsLib/BdsLib.inf

index 5efef7c9d61bd7a02313718cdb6ee1415ab8c282..14f16b85169a4d845503057185fc8aa5c8bca4b7 100644 (file)
   gArmTokenSpaceGuid.PcdArmMachineType|0|UINT32|0x0000001E\r
   # The compressed Linux kernel is expected to be under 128MB from the beginning of the System Memory\r
   gArmTokenSpaceGuid.PcdArmLinuxKernelMaxOffset|0x08000000|UINT32|0x0000001F\r
+  # Maximum file size for TFTP servers that do not support 'tsize' extension\r
+  gArmTokenSpaceGuid.PcdMaxTftpFileSize|0x01000000|UINT32|0x00000000\r
 \r
   #\r
   # ARM Architectural Timer\r
index 90be9c1e117895282f106a47abb2dd21d80012c1..f3fa4456555b76c8982390e4463b959826d632c0 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 *\r
-*  Copyright (c) 2011-2013, 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
@@ -817,6 +817,7 @@ BdsTftpLoadImage (
   }\r
   UnicodeStrToAsciiStr (FilePathDevicePath->PathName, AsciiPathName);\r
 \r
+  // Try to get the size (required the TFTP server to have "tsize" extension)\r
   Status = Pxe->Mtftp (\r
                   Pxe,\r
                   EFI_PXE_BASE_CODE_TFTP_GET_FILE_SIZE,\r
@@ -829,41 +830,82 @@ BdsTftpLoadImage (
                   NULL,\r
                   FALSE\r
                   );\r
-  if (EFI_ERROR(Status)) {\r
+  // Pxe.Mtftp replies EFI_PROTOCOL_ERROR if tsize is not supported by the TFTP server\r
+  if (EFI_ERROR (Status) && (Status != EFI_PROTOCOL_ERROR)) {\r
     if (Status == EFI_TFTP_ERROR) {\r
       DEBUG((EFI_D_ERROR, "TFTP Error: Fail to get the size of the file\n"));\r
     }\r
     goto EXIT;\r
   }\r
 \r
-  // Allocate a buffer to hold the whole file.\r
-  Status = gBS->AllocatePages (\r
-                  Type,\r
-                  EfiBootServicesCode,\r
-                  EFI_SIZE_TO_PAGES (TftpBufferSize),\r
-                  Image\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    DEBUG ((EFI_D_ERROR, "Failed to allocate space for kernel image: %r\n", Status));\r
-    goto EXIT;\r
-  }\r
+  //\r
+  // Two cases:\r
+  //   1) the file size is unknown (tsize extension not supported)\r
+  //   2) tsize returned the file size\r
+  //\r
+  if (Status == EFI_PROTOCOL_ERROR) {\r
+    for (TftpBufferSize = SIZE_8MB; TftpBufferSize <= FixedPcdGet32 (PcdMaxTftpFileSize); TftpBufferSize += SIZE_8MB) {\r
+      // Allocate a buffer to hold the whole file.\r
+      Status = gBS->AllocatePages (\r
+                      Type,\r
+                      EfiBootServicesCode,\r
+                      EFI_SIZE_TO_PAGES (TftpBufferSize),\r
+                      Image\r
+                      );\r
+      if (EFI_ERROR (Status)) {\r
+        DEBUG ((EFI_D_ERROR, "Failed to allocate space for image: %r\n", Status));\r
+        goto EXIT;\r
+      }\r
 \r
-  Status = Pxe->Mtftp (\r
-                  Pxe,\r
-                  EFI_PXE_BASE_CODE_TFTP_READ_FILE,\r
-                  (VOID *)(UINTN)*Image,\r
-                  FALSE,\r
-                  &TftpBufferSize,\r
-                  NULL,\r
-                  &ServerIp,\r
-                  (UINT8*)AsciiPathName,\r
-                  NULL,\r
-                  FALSE\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    gBS->FreePages (*Image, EFI_SIZE_TO_PAGES (TftpBufferSize));\r
+      Status = Pxe->Mtftp (\r
+                      Pxe,\r
+                      EFI_PXE_BASE_CODE_TFTP_READ_FILE,\r
+                      (VOID *)(UINTN)*Image,\r
+                      FALSE,\r
+                      &TftpBufferSize,\r
+                      NULL,\r
+                      &ServerIp,\r
+                      (UINT8*)AsciiPathName,\r
+                      NULL,\r
+                      FALSE\r
+                      );\r
+      if (EFI_ERROR (Status)) {\r
+        gBS->FreePages (*Image, EFI_SIZE_TO_PAGES (TftpBufferSize));\r
+      } else {\r
+        *ImageSize = (UINTN)TftpBufferSize;\r
+        break;\r
+      }\r
+    }\r
   } else {\r
-    *ImageSize = (UINTN)TftpBufferSize;\r
+    // Allocate a buffer to hold the whole file.\r
+    Status = gBS->AllocatePages (\r
+                    Type,\r
+                    EfiBootServicesCode,\r
+                    EFI_SIZE_TO_PAGES (TftpBufferSize),\r
+                    Image\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_ERROR, "Failed to allocate space for kernel image: %r\n", Status));\r
+      goto EXIT;\r
+    }\r
+\r
+    Status = Pxe->Mtftp (\r
+                    Pxe,\r
+                    EFI_PXE_BASE_CODE_TFTP_READ_FILE,\r
+                    (VOID *)(UINTN)*Image,\r
+                    FALSE,\r
+                    &TftpBufferSize,\r
+                    NULL,\r
+                    &ServerIp,\r
+                    (UINT8*)AsciiPathName,\r
+                    NULL,\r
+                    FALSE\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      gBS->FreePages (*Image, EFI_SIZE_TO_PAGES (TftpBufferSize));\r
+    } else {\r
+      *ImageSize = (UINTN)TftpBufferSize;\r
+    }\r
   }\r
 \r
 EXIT:\r
index 30746f69a7cc7049ead78f56ae0a61b29803d866..6158fba5919a290d8f6b76cbf18f2e745c2b5a5c 100644 (file)
@@ -1,6 +1,6 @@
 #/* @file\r
 #  \r
-#  Copyright (c) 2011-2013, 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
@@ -86,6 +86,8 @@
   gArmTokenSpaceGuid.PcdArmLinuxFdtAlignment\r
   gArmTokenSpaceGuid.PcdArmLinuxKernelMaxOffset\r
 \r
+  gArmTokenSpaceGuid.PcdMaxTftpFileSize\r
+\r
 [FixedPcd.ARM]\r
   gArmTokenSpaceGuid.PcdArmLinuxAtagMaxOffset\r
 \r