When downloading a big image as ram disk iso,we can
print the progress message on screen to enhance the
user experience.

Cc: Ye Ting <[email protected]>
Cc: Fu Siyuan <[email protected]>
Cc: Wu Jiaxin <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Zhang Lubo <[email protected]>
---
 NetworkPkg/HttpBootDxe/HttpBootClient.c  | 29 +++++++++++++++++++++++++++++
 NetworkPkg/HttpBootDxe/HttpBootSupport.c |  4 ++--
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/NetworkPkg/HttpBootDxe/HttpBootClient.c 
b/NetworkPkg/HttpBootDxe/HttpBootClient.c
index 46cf9ca..9b2a8bd 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootClient.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootClient.c
@@ -753,10 +753,12 @@ HttpBootGetBootFile (
   HTTP_BOOT_CACHE_CONTENT    *Cache;
   UINT8                      *Block;
   CHAR16                     *Url;
   BOOLEAN                    IdentityMode;
   UINTN                      ReceivedSize;
+  UINTN                      Ratio;
+  UINTN                      NewRatio;
   
   ASSERT (Private != NULL);
   ASSERT (Private->HttpCreated);
 
   if (BufferSize == NULL || ImageType == NULL) {
@@ -992,10 +994,13 @@ HttpBootGetBootFile (
     //
     // 3.4.2, start the message-body download, the identity and chunked 
transfer-coding
     // is handled in different path here.
     //
     ZeroMem (&ResponseBody, sizeof (HTTP_IO_RESPONSE_DATA));
+    AsciiPrint ("\n");
+    AsciiPrint ("\n  Downloading NBP file... ");
+    Ratio = 0;
     if (IdentityMode) {
       //
       // In identity transfer-coding there is no need to parse the message 
body,
       // just download the message body to the user provided buffer directly.
       //
@@ -1010,10 +1015,25 @@ HttpBootGetBootFile (
                    );
         if (EFI_ERROR (Status)) {
           goto ERROR_6;
         }
         ReceivedSize += ResponseBody.BodyLength;
+        //
+        // Display the download progress.
+        //
+        NewRatio = (ReceivedSize * 100) / ContentLength;
+        if (NewRatio != Ratio) {
+          if (Ratio !=0) {
+            if (Ratio >=10) {
+              AsciiPrint ("\b\b\b");
+            } else {
+              AsciiPrint ("\b\b");
+            }
+          }
+          Ratio = NewRatio;
+          AsciiPrint ("%d%%", NewRatio);
+        }
       }
     } else {
       //
       // In "chunked" transfer-coding mode, so we need to parse the received
       // data to get the real entity content.
@@ -1058,10 +1078,19 @@ HttpBootGetBootFile (
                    ResponseBody.Body
                    );
         if (EFI_ERROR (Status)) {
           goto ERROR_6;
         }
+
+        //
+        // Print '.' when using chunked mode to download bootfile.
+        //
+        Ratio ++;
+        if ((Ratio % 1024) == 0) {
+          AsciiPrint (".");
+        }
+
       }
     }
   }
 
   //
diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.c 
b/NetworkPkg/HttpBootDxe/HttpBootSupport.c
index 66eca78..71e4826 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootSupport.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.c
@@ -1121,11 +1121,11 @@ HttpBootRegisterRamDisk (
   ASSERT (Buffer != NULL);
   ASSERT (BufferSize != 0);
 
   Status = gBS->LocateProtocol (&gEfiRamDiskProtocolGuid, NULL, (VOID**) 
&RamDisk);
   if (EFI_ERROR (Status)) {
-    DEBUG ((EFI_D_ERROR, "HTTP Boot: Couldn't find the RAM Disk protocol - 
%r\n", Status));
+    AsciiPrint ("\n  HTTP Boot: Couldn't find the RAM Disk protocol - %r\n", 
Status);
     return Status;
   }
 
   if (ImageType == ImageTypeVirtualCd) {
     RamDiskType = &gEfiVirtualCdGuid;
@@ -1141,11 +1141,11 @@ HttpBootRegisterRamDisk (
              RamDiskType,
              Private->UsingIpv6 ? Private->Ip6Nic->DevicePath : 
Private->Ip4Nic->DevicePath,
              &DevicePath
              );
   if (EFI_ERROR (Status)) {
-    DEBUG ((EFI_D_ERROR, "HTTP Boot: Failed to register RAM Disk - %r\n", 
Status));
+    AsciiPrint ("\n  HTTP Boot: Failed to register RAM Disk - %r\n", Status);
   }
 
   return Status;
 }
 
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to