\r
Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r
Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+ (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
\r
if (File->DevicePath != NULL) {\r
// Try to print out the MAC address\r
- for (DevicePathNode = File->DevicePath; \r
- !IsDevicePathEnd (DevicePathNode); \r
+ for (DevicePathNode = File->DevicePath;\r
+ !IsDevicePathEnd (DevicePathNode);\r
DevicePathNode = NextDevicePathNode (DevicePathNode)) {\r
- \r
+\r
if ((DevicePathType (DevicePathNode) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (DevicePathNode) == MSG_MAC_ADDR_DP)) {\r
MacAddr = (MAC_ADDR_DEVICE_PATH *)DevicePathNode;\r
- \r
+\r
HwAddressSize = sizeof (EFI_MAC_ADDRESS);\r
if (MacAddr->IfType == 0x01 || MacAddr->IfType == 0x00) {\r
HwAddressSize = 6;\r
}\r
- \r
+\r
AsciiPrint ("MAC ");\r
for (Index = 0; Index < HwAddressSize; Index++) {\r
AsciiPrint ("%02x", MacAddr->MacAddress.Addr[Index] & 0xff);\r
}\r
- } \r
+ }\r
}\r
}\r
\r
\r
\r
/**\r
- Dump information about devices in the system. \r
+ Dump information about devices in the system.\r
\r
fv: PI Firmware Volume\r
fs: EFI Simple File System\r
Argv[0] - "device"\r
\r
@param Argc Number of command arguments in Argv\r
- @param Argv Array of strings that represent the parsed command line. \r
- Argv[0] is the comamnd name\r
+ @param Argv Array of strings that represent the parsed command line.\r
+ Argv[0] is the command name\r
\r
@return EFI_SUCCESS\r
\r
**/\r
EFI_STATUS\r
+EFIAPI\r
EblDeviceCmd (\r
IN UINTN Argc,\r
IN CHAR8 **Argv\r
}\r
}\r
}\r
- \r
+\r
Max = EfiGetDeviceCounts (EfiOpenLoadFile);\r
if (Max != 0) {\r
AsciiPrint ("LoadFile Devices: (usually network)\n");\r
\r
\r
/**\r
- Start an EFI image (PE32+ with EFI defined entry point). \r
+ Start an EFI image (PE32+ with EFI defined entry point).\r
\r
Argv[0] - "start"\r
Argv[1] - device name and path\r
start LoadFile0: ; load an FV via a PXE boot\r
\r
@param Argc Number of command arguments in Argv\r
- @param Argv Array of strings that represent the parsed command line. \r
- Argv[0] is the comamnd name\r
+ @param Argv Array of strings that represent the parsed command line.\r
+ Argv[0] is the command name\r
\r
@return EFI_SUCCESS\r
\r
**/\r
EFI_STATUS\r
+EFIAPI\r
EblStartCmd (\r
IN UINTN Argc,\r
IN CHAR8 **Argv\r
\r
File = EfiOpen (Argv[1], EFI_FILE_MODE_READ, 0);\r
if (File == NULL) {\r
- return EFI_INVALID_PARAMETER; \r
+ return EFI_INVALID_PARAMETER;\r
}\r
\r
DevicePath = File->DevicePath;\r
\r
FreePool (Buffer);\r
}\r
- \r
+\r
EfiClose (File);\r
\r
if (!EFI_ERROR (Status)) {\r
// We don't pass Argv[0] to the EFI Application (it's name) just the args\r
Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&ImageInfo);\r
ASSERT_EFI_ERROR (Status);\r
- \r
+\r
ImageInfo->LoadOptionsSize = (UINT32)AsciiStrSize (Argv[2]);\r
ImageInfo->LoadOptions = AllocatePool (ImageInfo->LoadOptionsSize);\r
AsciiStrCpy (ImageInfo->LoadOptions, Argv[2]);\r
\r
/**\r
Load a Firmware Volume (FV) into memory from a device. This causes drivers in\r
- the FV to be dispatched if the dependancies of the drivers are met.\r
- \r
+ the FV to be dispatched if the dependencies of the drivers are met.\r
+\r
Argv[0] - "loadfv"\r
Argv[1] - device name and path\r
\r
loadfv LoadFile0: ; load an FV via a PXE boot\r
\r
@param Argc Number of command arguments in Argv\r
- @param Argv Array of strings that represent the parsed command line. \r
- Argv[0] is the comamnd name\r
+ @param Argv Array of strings that represent the parsed command line.\r
+ Argv[0] is the command name\r
\r
@return EFI_SUCCESS\r
\r
**/\r
EFI_STATUS\r
+EFIAPI\r
EblLoadFvCmd (\r
IN UINTN Argc,\r
IN CHAR8 **Argv\r
\r
File = EfiOpen (Argv[1], EFI_FILE_MODE_READ, 0);\r
if (File == NULL) {\r
- return EFI_INVALID_PARAMETER; \r
+ return EFI_INVALID_PARAMETER;\r
}\r
\r
if (File->Type == EfiOpenMemoryBuffer) {\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
- \r
+\r
Status = gDS->ProcessFirmwareVolume (FvStart, FvSize, &FvHandle);\r
- FreePool (FvStart);\r
+ if (EFI_ERROR (Status)) {\r
+ FreePool (FvStart);\r
+ }\r
}\r
return Status;\r
}\r
\r
\r
/**\r
- Perform an EFI connect to connect devices that follow the EFI driver model. \r
+ Perform an EFI connect to connect devices that follow the EFI driver model.\r
If it is a PI system also call the dispatcher in case a new FV was made\r
- availible by one of the connect EFI drivers (this is not a common case).\r
- \r
+ available by one of the connect EFI drivers (this is not a common case).\r
+\r
Argv[0] - "connect"\r
\r
@param Argc Number of command arguments in Argv\r
- @param Argv Array of strings that represent the parsed command line. \r
- Argv[0] is the comamnd name\r
+ @param Argv Array of strings that represent the parsed command line.\r
+ Argv[0] is the command name\r
\r
@return EFI_SUCCESS\r
\r
**/\r
EFI_STATUS\r
+EFIAPI\r
EblConnectCmd (\r
IN UINTN Argc,\r
IN CHAR8 **Argv\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
- \r
+\r
for (Index = 0; Index < HandleCount; Index++) {\r
gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);\r
}\r
- \r
+\r
//\r
// Given we disconnect our console we should go and do a connect now\r
//\r
\r
/**\r
Dump out the EFI memory map\r
- \r
+\r
Argv[0] - "memmap"\r
\r
@param Argc Number of command arguments in Argv\r
- @param Argv Array of strings that represent the parsed command line. \r
- Argv[0] is the comamnd name\r
+ @param Argv Array of strings that represent the parsed command line.\r
+ Argv[0] is the command name\r
\r
@return EFI_SUCCESS\r
\r
**/\r
EFI_STATUS\r
+EFIAPI\r
EblMemMapCmd (\r
IN UINTN Argc,\r
IN CHAR8 **Argv\r
ZeroMem (PageCount, sizeof (PageCount));\r
\r
AsciiPrint ("EFI Memory Map\n");\r
- \r
+\r
// First call is to figure out how big the buffer needs to be\r
MemMapSize = 0;\r
MemMap = NULL;\r
MemMap = NEXT_MEMORY_DESCRIPTOR (MemMap, DescriptorSize);\r
}\r
}\r
- \r
+\r
for (Index = 0, TotalMemory = 0; Index < EfiMaxMemoryType; Index++) {\r
if (PageCount[Index] != 0) {\r
AsciiPrint ("\n %a %,7ld Pages (%,14ld)", gMemMapType[Index], PageCount[Index], LShiftU64 (PageCount[Index], 12));\r
\r
\r
/**\r
- Load a file into memory and optionally jump to it. A load addres can be \r
+ Load a file into memory and optionally jump to it. A load address can be\r
specified or automatically allocated. A quoted command line can optionally\r
- be passed into the image. \r
+ be passed into the image.\r
\r
Argv[0] - "go"\r
Argv[1] - Device Name:path for the file to load\r
Argv[2] - Address to load to or '*' if the load address will be allocated\r
Argv[3] - Optional Entry point to the image. Image will be called if present\r
- Argv[4] - "" string that will be passed as Argc & Argv to EntryPoint. Needs \r
+ Argv[4] - "" string that will be passed as Argc & Argv to EntryPoint. Needs\r
to include the command name\r
\r
- go fv1:\EblCmdX 0x10000 0x10010 "EblCmdX Arg2 Arg3 Arg4"; - load EblCmdX \r
- from FV1 to location 0x10000 and call the entry point at 0x10010 passing \r
+ go fv1:\EblCmdX 0x10000 0x10010 "EblCmdX Arg2 Arg3 Arg4"; - load EblCmdX\r
+ from FV1 to location 0x10000 and call the entry point at 0x10010 passing\r
in "EblCmdX Arg2 Arg3 Arg4" as the arguments.\r
\r
- go fv0:\EblCmdX * 0x10 "EblCmdX Arg2 Arg3 Arg4"; - load EblCmdX from FS0 \r
- to location allocated by this comamnd and call the entry point at offset 0x10 \r
+ go fv0:\EblCmdX * 0x10 "EblCmdX Arg2 Arg3 Arg4"; - load EblCmdX from FS0\r
+ to location allocated by this command and call the entry point at offset 0x10\r
passing in "EblCmdX Arg2 Arg3 Arg4" as the arguments.\r
\r
go fv1:\EblCmdX 0x10000; Load EblCmdX to address 0x10000 and return\r
\r
@param Argc Number of command arguments in Argv\r
- @param Argv Array of strings that represent the parsed command line. \r
- Argv[0] is the comamnd name\r
+ @param Argv Array of strings that represent the parsed command line.\r
+ Argv[0] is the command name\r
\r
@return EFI_SUCCESS\r
\r
**/\r
EFI_STATUS\r
+EFIAPI\r
EblGoCmd (\r
IN UINTN Argc,\r
IN CHAR8 **Argv\r
EBL_COMMMAND EntryPoint;\r
UINTN EntryPointArgc;\r
CHAR8 *EntryPointArgv[MAX_ARGS];\r
- \r
+\r
\r
if (Argc <= 2) {\r
// device name and laod address are required\r
if (Argv[2][0] == '*') {\r
// * Means allocate the buffer\r
Status = EfiReadAllocatePool (File, &Address, &Size);\r
- \r
- // EntryPoint is relatvie to the start of the image \r
+\r
+ // EntryPoint is relative to the start of the image\r
EntryPoint = (EBL_COMMMAND)((UINTN)EntryPoint + (UINTN)Address);\r
\r
} else {\r
EntryPointArgc = 1;\r
EntryPointArgv[0] = File->FileName;\r
}\r
- \r
+\r
Status = EntryPoint (EntryPointArgc, EntryPointArgv);\r
}\r
}\r
#define FILE_COPY_CHUNK 0x20000\r
\r
EFI_STATUS\r
+EFIAPI\r
EblFileCopyCmd (\r
IN UINTN Argc,\r
IN CHAR8 **Argv\r
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
+\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
+\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
if (Buffer == NULL) {\r
goto Exit;\r
}\r
- \r
+\r
Size = EfiTell(Source, NULL);\r
\r
for (Offset = 0; Offset + FILE_COPY_CHUNK <= Size; Offset += Chunk) {\r
Chunk = FILE_COPY_CHUNK;\r
- \r
+\r
Status = EfiRead(Source, Buffer, &Chunk);\r
if (EFI_ERROR(Status)) {\r
AsciiPrint("Read file error %r\n", Status);\r
if (EFI_ERROR(Status)) {\r
AsciiPrint("Write file error %r\n", Status);\r
goto Exit;\r
- } \r
+ }\r
}\r
- \r
+\r
// Any left over?\r
if (Offset < Size) {\r
Chunk = Size - Offset;\r
- \r
+\r
Status = EfiRead(Source, Buffer, &Chunk);\r
if (EFI_ERROR(Status)) {\r
AsciiPrint("Read file error %r\n", Status);\r
if (EFI_ERROR(Status)) {\r
AsciiPrint("Write file error %r\n", Status);\r
goto Exit;\r
- } \r
+ }\r
}\r
\r
\r
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
+\r
if (Buffer != NULL) {\r
FreePool(Buffer);\r
}\r
- \r
+\r
return Status;\r
}\r
\r
EFI_STATUS\r
+EFIAPI\r
EblFileDiffCmd (\r
IN UINTN Argc,\r
IN CHAR8 **Argv\r
UINTN Size2;\r
UINTN Offset;\r
UINTN Chunk = FILE_COPY_CHUNK;\r
- \r
+\r
if (Argc != 3) {\r
return EFI_INVALID_PARAMETER;\r
}\r
- \r
+\r
File1 = EfiOpen(Argv[1], EFI_FILE_MODE_READ, 0);\r
if (File1 == NULL) {\r
AsciiPrint("File 1 open error.\n");\r
return EFI_NOT_FOUND;\r
}\r
- \r
+\r
File2 = EfiOpen(Argv[2], EFI_FILE_MODE_READ, 0);\r
if (File2 == NULL) {\r
AsciiPrint("File 2 open error.\n");\r
if (Buffer1 == NULL) {\r
goto Exit;\r
}\r
- \r
+\r
Buffer2 = AllocatePool(FILE_COPY_CHUNK);\r
if (Buffer2 == NULL) {\r
goto Exit;\r
- } \r
+ }\r
\r
for (Offset = 0; Offset + FILE_COPY_CHUNK <= Size1; Offset += Chunk) {\r
Chunk = FILE_COPY_CHUNK;\r
- \r
+\r
Status = EfiRead(File1, Buffer1, &Chunk);\r
if (EFI_ERROR(Status)) {\r
AsciiPrint("File 1 read error\n");\r
AsciiPrint("File 2 read error\n");\r
goto Exit;\r
}\r
- \r
+\r
if (CompareMem(Buffer1, Buffer2, Chunk) != 0) {\r
AsciiPrint("Files differ.\n");\r
goto Exit;\r
};\r
}\r
- \r
+\r
// Any left over?\r
if (Offset < Size1) {\r
Chunk = Size1 - Offset;\r
- \r
+\r
Status = EfiRead(File1, Buffer1, &Chunk);\r
if (EFI_ERROR(Status)) {\r
AsciiPrint("File 1 read error\n");\r
if (EFI_ERROR(Status)) {\r
AsciiPrint("File 2 read error\n");\r
goto Exit;\r
- } \r
+ }\r
}\r
- \r
+\r
if (CompareMem(Buffer1, Buffer2, Chunk) != 0) {\r
AsciiPrint("Files differ.\n");\r
} else {\r
AsciiPrint("File 1 close error %r\n", Status);\r
}\r
}\r
- \r
+\r
if (File2 != NULL) {\r
Status = EfiClose(File2);\r
if (EFI_ERROR(Status)) {\r
AsciiPrint("File 2 close error %r\n", Status);\r
}\r
}\r
- \r
+\r
if (Buffer1 != NULL) {\r
FreePool(Buffer1);\r
}\r
- \r
+\r
if (Buffer2 != NULL) {\r
FreePool(Buffer2);\r
}\r
- \r
+\r
return Status;\r
}\r
\r
},\r
{\r
"go",\r
- " dev:path loadaddress entrypoint args; load to given address and jump in", \r
+ " dev:path loadaddress entrypoint args; load to given address and jump in",\r
NULL,\r
EblGoCmd\r
},\r
{\r
"loadfv",\r
- " devname; Load PI FV from device", \r
+ " devname; Load PI FV from device",\r
NULL,\r
EblLoadFvCmd\r
},\r
{\r
"start",\r
- " path; EFI Boot Device:filepath. fs1:\\EFI\\BOOT.EFI", \r
+ " path; EFI Boot Device:filepath. fs1:\\EFI\\BOOT.EFI",\r
NULL,\r
EblStartCmd\r
},\r
{\r
"memmap",\r
- "; dump EFI memory map", \r
+ "; dump EFI memory map",\r
NULL,\r
EblMemMapCmd\r
},\r
{\r
"cp",\r
- " file1 file2; copy file",\r
+ " file1 file2; copy file only.",\r
NULL,\r
EblFileCopyCmd\r
},\r