X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=EmbeddedPkg%2FEbl%2FEfiDevice.c;h=c623bd8b7e17782e030a2cead28c301a2fbb8cda;hb=b4fdedc2543c6d193c70ae5339a56824a9729e68;hp=e129a3cb8caad84fdb68b542dfaca993cabbb442;hpb=6f72e28d04348ad4539679949609675b114896e1;p=mirror_edk2.git diff --git a/EmbeddedPkg/Ebl/EfiDevice.c b/EmbeddedPkg/Ebl/EfiDevice.c index e129a3cb8c..c623bd8b7e 100644 --- a/EmbeddedPkg/Ebl/EfiDevice.c +++ b/EmbeddedPkg/Ebl/EfiDevice.c @@ -1,10 +1,10 @@ /** @file EBL commands for EFI and PI Devices - Copyright (c) 2007, Intel Corporation
- Portions copyright (c) 2008-2009, Apple Inc. All rights reserved. + Copyright (c) 2007, Intel Corporation. All rights reserved.
+ Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
- All rights reserved. This program and the accompanying materials + This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -31,13 +31,22 @@ EblPrintFsInfo ( IN EFI_OPEN_FILE *File ) { + CHAR16 *Str; + if (File == NULL) { return; } AsciiPrint (" %a: ", File->DeviceName); if (File->FsInfo != NULL) { - AsciiPrint ("%s: ", File->FsInfo->VolumeLabel); + for (Str = File->FsInfo->VolumeLabel; *Str != '\0'; Str++) { + if (*Str == ' ') { + // UI makes you enter _ for space, so make the printout match that + *Str = '_'; + } + AsciiPrint ("%c", *Str); + } + AsciiPrint (":"); if (File->FsInfo->ReadOnly) { AsciiPrint ("ReadOnly"); } @@ -102,24 +111,24 @@ EblPrintBlkIoInfo ( EfiClose (FsFile); break; } + EfiClose (FsFile); } - EfiClose (FsFile); } } // Print out useful Block IO media properties - if (File->FsBlockIoMedia.RemovableMedia) { + if (File->FsBlockIoMedia->RemovableMedia) { AsciiPrint ("Removable "); } - if (!File->FsBlockIoMedia.MediaPresent) { - AsciiPrint ("No Media "); - } - if (File->FsBlockIoMedia.LogicalPartition) { - AsciiPrint ("Partition "); + if (!File->FsBlockIoMedia->MediaPresent) { + AsciiPrint ("No Media\n"); + } else { + if (File->FsBlockIoMedia->LogicalPartition) { + AsciiPrint ("Partition "); + } + DeviceSize = MultU64x32 (File->FsBlockIoMedia->LastBlock + 1, File->FsBlockIoMedia->BlockSize); + AsciiPrint ("Size = 0x%lX\n", DeviceSize); } - DeviceSize = MultU64x32 (File->FsBlockIoMedia.LastBlock + 1, File->FsBlockIoMedia.BlockSize); - AsciiPrint ("Size = 0x%lX\n", DeviceSize); - EfiClose (File); } @@ -187,7 +196,7 @@ EblPrintLoadFileInfo ( @param Argc Number of command arguments in Argv @param Argv Array of strings that represent the parsed command line. - Argv[0] is the comamnd name + Argv[0] is the command name @return EFI_SUCCESS @@ -203,10 +212,11 @@ EblDeviceCmd ( UINTN Max; CurrentRow = 0; - + // Need to call here to make sure Device Counts are valid EblUpdateDeviceLists (); + // Now we can print out the info... Max = EfiGetDeviceCounts (EfiOpenFirmwareVolume); if (Max != 0) { AsciiPrint ("Firmware Volume Devices:\n"); @@ -269,7 +279,7 @@ EblDeviceCmd ( @param Argc Number of command arguments in Argv @param Argv Array of strings that represent the parsed command line. - Argv[0] is the comamnd name + Argv[0] is the command name @return EFI_SUCCESS @@ -343,7 +353,7 @@ EblStartCmd ( /** Load a Firmware Volume (FV) into memory from a device. This causes drivers in - the FV to be dispatched if the dependancies of the drivers are met. + the FV to be dispatched if the dependencies of the drivers are met. Argv[0] - "loadfv" Argv[1] - device name and path @@ -354,7 +364,7 @@ EblStartCmd ( @param Argc Number of command arguments in Argv @param Argv Array of strings that represent the parsed command line. - Argv[0] is the comamnd name + Argv[0] is the command name @return EFI_SUCCESS @@ -393,7 +403,9 @@ EblLoadFvCmd ( } Status = gDS->ProcessFirmwareVolume (FvStart, FvSize, &FvHandle); - FreePool (FvStart); + if (EFI_ERROR (Status)) { + FreePool (FvStart); + } } return Status; } @@ -402,13 +414,13 @@ EblLoadFvCmd ( /** Perform an EFI connect to connect devices that follow the EFI driver model. If it is a PI system also call the dispatcher in case a new FV was made - availible by one of the connect EFI drivers (this is not a common case). + available by one of the connect EFI drivers (this is not a common case). Argv[0] - "connect" @param Argc Number of command arguments in Argv @param Argv Array of strings that represent the parsed command line. - Argv[0] is the comamnd name + Argv[0] is the command name @return EFI_SUCCESS @@ -530,7 +542,7 @@ CHAR8 *gMemMapType[] = { @param Argc Number of command arguments in Argv @param Argv Array of strings that represent the parsed command line. - Argv[0] is the comamnd name + Argv[0] is the command name @return EFI_SUCCESS @@ -616,7 +628,7 @@ EblMemMapCmd ( /** - Load a file into memory and optionally jump to it. A load addres can be + Load a file into memory and optionally jump to it. A load address can be specified or automatically allocated. A quoted command line can optionally be passed into the image. @@ -632,14 +644,14 @@ EblMemMapCmd ( in "EblCmdX Arg2 Arg3 Arg4" as the arguments. go fv0:\EblCmdX * 0x10 "EblCmdX Arg2 Arg3 Arg4"; - load EblCmdX from FS0 - to location allocated by this comamnd and call the entry point at offset 0x10 + to location allocated by this command and call the entry point at offset 0x10 passing in "EblCmdX Arg2 Arg3 Arg4" as the arguments. go fv1:\EblCmdX 0x10000; Load EblCmdX to address 0x10000 and return @param Argc Number of command arguments in Argv @param Argv Array of strings that represent the parsed command line. - Argv[0] is the comamnd name + Argv[0] is the command name @return EFI_SUCCESS @@ -675,7 +687,7 @@ EblGoCmd ( // * Means allocate the buffer Status = EfiReadAllocatePool (File, &Address, &Size); - // EntryPoint is relatvie to the start of the image + // EntryPoint is relative to the start of the image EntryPoint = (EBL_COMMMAND)((UINTN)EntryPoint + (UINTN)Address); } else { @@ -720,19 +732,64 @@ EblFileCopyCmd ( VOID *Buffer = NULL; UINTN Size; UINTN Offset; - UINTN Chunk = FILE_COPY_CHUNK; - + UINTN Chunk = FILE_COPY_CHUNK; + UINTN FileNameLen; + CHAR8* DestFileName; + CHAR8* SrcFileName; + CHAR8* SrcPtr; + if (Argc < 3) { return EFI_INVALID_PARAMETER; } + DestFileName = Argv[2]; + FileNameLen = AsciiStrLen (DestFileName); + + // Check if the destination file name looks like a directory + if ((DestFileName[FileNameLen-1] == '\\') || (DestFileName[FileNameLen-1] == ':')) { + // Set the pointer after the source drive (eg: after fs1:) + SrcPtr = AsciiStrStr (Argv[1], ":"); + if (SrcPtr == NULL) { + SrcPtr = Argv[1]; + } else { + SrcPtr++; + if (*SrcPtr == '\\') { + SrcPtr++; + } + } + + if (*SrcPtr == '\0') { + AsciiPrint("Source file incorrect.\n"); + } + + // Skip the Source Directories + while (1) { + SrcFileName = SrcPtr; + SrcPtr = AsciiStrStr (SrcPtr,"\\"); + if (SrcPtr != NULL) { + SrcPtr++; + } else { + break; + } + } + + if (*SrcFileName == '\0') { + AsciiPrint("Source file incorrect (Error 2).\n"); + } + + // Construct the destination filepath + DestFileName = (CHAR8*)AllocatePool (FileNameLen + AsciiStrLen (SrcFileName) + 1); + AsciiStrCpy (DestFileName, Argv[2]); + AsciiStrCat (DestFileName, SrcFileName); + } + Source = EfiOpen(Argv[1], EFI_FILE_MODE_READ, 0); if (Source == NULL) { AsciiPrint("Source file open error.\n"); return EFI_NOT_FOUND; } - Destination = EfiOpen(Argv[2], EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0); + Destination = EfiOpen(DestFileName, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0); if (Destination == NULL) { AsciiPrint("Destination file open error.\n"); return EFI_NOT_FOUND; @@ -750,13 +807,13 @@ EblFileCopyCmd ( Status = EfiRead(Source, Buffer, &Chunk); if (EFI_ERROR(Status)) { - AsciiPrint("Read file error\n"); + AsciiPrint("Read file error %r\n", Status); goto Exit; } Status = EfiWrite(Destination, Buffer, &Chunk); if (EFI_ERROR(Status)) { - AsciiPrint("Write file error\n"); + AsciiPrint("Write file error %r\n", Status); goto Exit; } } @@ -767,17 +824,18 @@ EblFileCopyCmd ( Status = EfiRead(Source, Buffer, &Chunk); if (EFI_ERROR(Status)) { - AsciiPrint("Read file error\n"); + AsciiPrint("Read file error %r\n", Status); goto Exit; } Status = EfiWrite(Destination, Buffer, &Chunk); if (EFI_ERROR(Status)) { - AsciiPrint("Write file error\n"); + AsciiPrint("Write file error %r\n", Status); goto Exit; } } + Exit: if (Source != NULL) { Status = EfiClose(Source); @@ -785,12 +843,16 @@ Exit: AsciiPrint("Source close error %r\n", Status); } } - if (Destination != NULL) { Status = EfiClose(Destination); if (EFI_ERROR(Status)) { AsciiPrint("Destination close error %r\n", Status); } + + // Case when we have concated the filename to the destination directory + if (DestFileName != Argv[2]) { + FreePool (DestFileName); + } } if (Buffer != NULL) { @@ -960,7 +1022,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mCmdDeviceTemplate[] = }, { "cp", - " file1 file2; copy file", + " file1 file2; copy file only.", NULL, EblFileCopyCmd },