- Status = Pxe->Mtftp (\r
- Pxe,\r
- EFI_PXE_BASE_CODE_TFTP_READ_FILE,\r
- TftpBuffer,\r
- FALSE,\r
- &TftpBufferSize,\r
- NULL,\r
- &ServerIp,\r
- (UINT8 *)FilePathDevicePath->PathName,\r
- NULL,\r
- FALSE\r
- );\r
- if (EFI_ERROR (Status)) {\r
- FreePool (TftpBuffer);\r
- } else if (ImageSize != NULL) {\r
- *ImageSize = (UINTN)TftpBufferSize;\r
+ TftpTransferSize = TftpBufferSize;\r
+ Status = Pxe->Mtftp (\r
+ Pxe,\r
+ EFI_PXE_BASE_CODE_TFTP_READ_FILE,\r
+ (VOID *)(UINTN)*Image,\r
+ FALSE,\r
+ &TftpTransferSize,\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
+ // 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