]> git.proxmox.com Git - mirror_edk2.git/commitdiff
EmbeddedPkg/Ebl: Fix EBL copy file command
authoroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 22 Sep 2011 22:52:16 +0000 (22:52 +0000)
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 22 Sep 2011 22:52:16 +0000 (22:52 +0000)
In the previous version, this command was not working:
cp fs0:\zImage fs1:\

This change uses the source filename is the destination
filename is not specified.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12406 6f19259b-4bc3-4df7-8a09-765794883524

EmbeddedPkg/Ebl/EfiDevice.c

index dfdbc3fe789a69c1185ca16544c3bef9f9ef24aa..c623bd8b7e17782e030a2cead28c301a2fbb8cda 100644 (file)
@@ -732,19 +732,64 @@ EblFileCopyCmd (
   VOID          *Buffer      = NULL;\r
   UINTN         Size;\r
   UINTN         Offset;\r
-  UINTN         Chunk = FILE_COPY_CHUNK;\r
+  UINTN         Chunk        = FILE_COPY_CHUNK;\r
+  UINTN         FileNameLen;\r
+  CHAR8*        DestFileName;\r
+  CHAR8*        SrcFileName;\r
+  CHAR8*        SrcPtr;\r
 \r
   if (Argc < 3) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   \r
+  DestFileName = Argv[2];\r
+  FileNameLen = AsciiStrLen (DestFileName);\r
+\r
+  // Check if the destination file name looks like a directory\r
+  if ((DestFileName[FileNameLen-1] == '\\') || (DestFileName[FileNameLen-1] == ':')) {\r
+    // Set the pointer after the source drive (eg: after fs1:)\r
+    SrcPtr = AsciiStrStr (Argv[1], ":");\r
+    if (SrcPtr == NULL) {\r
+      SrcPtr = Argv[1];\r
+    } else {\r
+      SrcPtr++;\r
+      if (*SrcPtr == '\\') {\r
+        SrcPtr++;\r
+      }\r
+    }\r
+\r
+    if (*SrcPtr == '\0') {\r
+      AsciiPrint("Source file incorrect.\n");\r
+    }\r
+\r
+    // Skip the Source Directories\r
+    while (1) {\r
+      SrcFileName = SrcPtr;\r
+      SrcPtr = AsciiStrStr (SrcPtr,"\\");\r
+      if (SrcPtr != NULL) {\r
+        SrcPtr++;\r
+      } else {\r
+        break;\r
+      }\r
+    }\r
+\r
+    if (*SrcFileName == '\0') {\r
+      AsciiPrint("Source file incorrect (Error 2).\n");\r
+    }\r
+\r
+    // Construct the destination filepath\r
+    DestFileName = (CHAR8*)AllocatePool (FileNameLen + AsciiStrLen (SrcFileName) + 1);\r
+    AsciiStrCpy (DestFileName, Argv[2]);\r
+    AsciiStrCat (DestFileName, SrcFileName);\r
+  }\r
+\r
   Source = EfiOpen(Argv[1], EFI_FILE_MODE_READ, 0);\r
   if (Source == NULL) {\r
     AsciiPrint("Source file open error.\n");\r
     return EFI_NOT_FOUND;\r
   }\r
   \r
-  Destination = EfiOpen(Argv[2], EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0);\r
+  Destination = EfiOpen(DestFileName, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0);\r
   if (Destination == NULL) {\r
     AsciiPrint("Destination file open error.\n");\r
     return EFI_NOT_FOUND;\r
@@ -803,6 +848,11 @@ Exit:
     if (EFI_ERROR(Status)) {\r
       AsciiPrint("Destination close error %r\n", Status);\r
     }\r
+\r
+    // Case when we have concated the filename to the destination directory\r
+    if (DestFileName != Argv[2]) {\r
+      FreePool (DestFileName);\r
+    }\r
   }\r
   \r
   if (Buffer != NULL) {\r
@@ -972,7 +1022,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mCmdDeviceTemplate[] =
   },\r
   {\r
     "cp",\r
-    " file1 file2; copy file",\r
+    " file1 file2; copy file only.",\r
     NULL,\r
     EblFileCopyCmd\r
   },\r