]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpBootDxe/HttpBootClient.c
NetworkPkg: Add RAM disk boot support to HTTP Boot driver.
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootClient.c
index 0c472938a068145200089aee59ae25db0a80c17c..9d445e3c8e7c59f8698c029b91a53d4f9e41d498 100644 (file)
@@ -570,6 +570,7 @@ HttpBootFreeCacheList (
   @param[out]         Buffer          The memory buffer to transfer the file to. IF Buffer is NULL,\r
                                       then the size of the requested file is returned in\r
                                       BufferSize.\r
+  @param[out]         ImageType       The image type of the downloaded file.\r
 \r
   @retval EFI_SUCCESS          Successfully created.\r
   @retval Others               Failed to create HttpIo.\r
@@ -580,7 +581,8 @@ HttpBootGetFileFromCache (
   IN     HTTP_BOOT_PRIVATE_DATA   *Private,\r
   IN     CHAR16                   *Uri,\r
   IN OUT UINTN                    *BufferSize,\r
-     OUT UINT8                    *Buffer\r
+     OUT UINT8                    *Buffer,\r
+     OUT HTTP_BOOT_IMAGE_TYPE     *ImageType\r
   )\r
 {\r
   LIST_ENTRY                  *Entry;\r
@@ -589,7 +591,7 @@ HttpBootGetFileFromCache (
   HTTP_BOOT_ENTITY_DATA       *EntityData;\r
   UINTN                       CopyedSize;\r
   \r
-  if (Uri == NULL || BufferSize == 0 || Buffer == NULL) {\r
+  if (Uri == NULL || BufferSize == 0 || Buffer == NULL || ImageType == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -603,7 +605,12 @@ HttpBootGetFileFromCache (
         (StrCmp (Uri, Cache->RequestData->Url) == 0)) \r
     {\r
       //\r
-      // Hit cache, check buffer size.\r
+      // Hit in cache, record image type.\r
+      //\r
+      *ImageType  = Cache->ImageType;\r
+\r
+      //\r
+      // Check buffer size.\r
       //\r
       if (*BufferSize < Cache->EntityLength) {\r
         *BufferSize = Cache->EntityLength;\r
@@ -712,6 +719,7 @@ HttpBootGetBootFileCallback (
   @param[out]      Buffer          The memory buffer to transfer the file to. IF Buffer is NULL,\r
                                    then the size of the requested file is returned in\r
                                    BufferSize.\r
+  @param[out]      ImageType       The image type of the downloaded file.\r
 \r
   @retval EFI_SUCCESS              The file was loaded.\r
   @retval EFI_INVALID_PARAMETER    BufferSize is NULL or Buffer Size is not NULL but Buffer is NULL.\r
@@ -727,7 +735,8 @@ HttpBootGetBootFile (
   IN     HTTP_BOOT_PRIVATE_DATA   *Private,\r
   IN     BOOLEAN                  HeaderOnly,\r
   IN OUT UINTN                    *BufferSize,\r
-     OUT UINT8                    *Buffer\r
+     OUT UINT8                    *Buffer,\r
+     OUT HTTP_BOOT_IMAGE_TYPE     *ImageType\r
   )\r
 {\r
   EFI_STATUS                 Status;\r
@@ -750,7 +759,7 @@ HttpBootGetBootFile (
   ASSERT (Private != NULL);\r
   ASSERT (Private->HttpCreated);\r
 \r
-  if (BufferSize == NULL) {\r
+  if (BufferSize == NULL || ImageType == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -767,7 +776,7 @@ HttpBootGetBootFile (
   }\r
   AsciiStrToUnicodeStr (Private->BootFileUri, Url);\r
   if (!HeaderOnly) {\r
-    Status = HttpBootGetFileFromCache (Private, Url, BufferSize, Buffer);\r
+    Status = HttpBootGetFileFromCache (Private, Url, BufferSize, Buffer, ImageType);\r
     if (Status != EFI_NOT_FOUND) {\r
       FreePool (Url);\r
       return Status;\r
@@ -788,6 +797,7 @@ HttpBootGetBootFile (
       Status = EFI_OUT_OF_RESOURCES;\r
       goto ERROR_1;\r
     }\r
+    Cache->ImageType = ImageTypeMax;\r
     InitializeListHead (&Cache->EntityDataList);\r
   }\r
 \r
@@ -918,11 +928,26 @@ HttpBootGetBootFile (
     goto ERROR_5;\r
   }\r
 \r
+  //\r
+  // Check the image type according to server's response.\r
+  //\r
+  Status = HttpBootCheckImageType (\r
+             Private->BootFileUri,\r
+             Private->BootFileUriParser,\r
+             ResponseData->HeaderCount,\r
+             ResponseData->Headers,\r
+             ImageType\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ERROR_5;\r
+  }\r
+\r
   //\r
   // 3.2 Cache the response header.\r
   //\r
   if (Cache != NULL) {\r
     Cache->ResponseData = ResponseData;\r
+    Cache->ImageType = *ImageType;\r
   }\r
   \r
   //\r