2009-12-06 02:57:05 +01:00
|
|
|
/** @file
|
|
|
|
Dir for EBL (Embedded Boot Loader)
|
|
|
|
|
2010-04-29 14:40:51 +02:00
|
|
|
Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
|
|
|
|
Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
|
2015-10-29 13:59:06 +01:00
|
|
|
(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
|
2010-04-29 14:40:51 +02:00
|
|
|
This program and the accompanying materials
|
2009-12-06 02:57:05 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
Module Name: CmdTemplate.c
|
|
|
|
|
|
|
|
Search/Replace Dir with the name of your new command
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "Ebl.h"
|
|
|
|
|
|
|
|
|
|
|
|
GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *gFvFileType[] = {
|
|
|
|
"All",
|
2010-02-12 01:12:14 +01:00
|
|
|
"Bin",
|
|
|
|
"section",
|
2009-12-06 02:57:05 +01:00
|
|
|
"SEC",
|
|
|
|
"PeiCore",
|
|
|
|
"DxeCore",
|
|
|
|
"PEIM",
|
|
|
|
"Driver",
|
2010-02-12 01:12:14 +01:00
|
|
|
"Combo",
|
|
|
|
"App",
|
2009-12-06 02:57:05 +01:00
|
|
|
"NULL",
|
|
|
|
"FV"
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Perform a dir on a device. The device must support Simple File System Protocol
|
2014-08-19 15:29:52 +02:00
|
|
|
or the FV protocol.
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
Argv[0] - "dir"
|
2014-08-19 15:29:52 +02:00
|
|
|
Argv[1] - Device Name:path. Path is optional
|
2009-12-06 02:57:05 +01:00
|
|
|
Argv[2] - Optional filename to match on. A leading * means match substring
|
|
|
|
Argv[3] - Optional FV file type
|
|
|
|
|
|
|
|
dir fs1:\efi ; perform a dir on fs1: device in the efi directory
|
2014-08-19 15:29:52 +02:00
|
|
|
dir fs1:\efi *.efi; perform a dir on fs1: device in the efi directory but
|
2009-12-06 02:57:05 +01:00
|
|
|
only print out files that contain the string *.efi
|
2014-08-19 15:29:52 +02:00
|
|
|
dir fv1:\ ; perform a dir on fv1: device in the efi directory
|
2011-08-08 20:29:14 +02:00
|
|
|
NOTE: fv devices do not contain subdirs
|
2010-02-10 01:46:41 +01:00
|
|
|
dir fv1:\ * PEIM ; will match all files of type PEIM
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
@param Argc Number of command arguments in Argv
|
2014-08-19 15:29:52 +02:00
|
|
|
@param Argv Array of strings that represent the parsed command line.
|
2011-08-08 20:29:14 +02:00
|
|
|
Argv[0] is the command name
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
@return EFI_SUCCESS
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
2015-10-29 13:59:06 +01:00
|
|
|
EFIAPI
|
2009-12-06 02:57:05 +01:00
|
|
|
EblDirCmd (
|
|
|
|
IN UINTN Argc,
|
|
|
|
IN CHAR8 **Argv
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_OPEN_FILE *File;
|
|
|
|
EFI_FILE_INFO *DirInfo;
|
|
|
|
UINTN ReadSize;
|
2014-08-19 15:29:52 +02:00
|
|
|
UINTN CurrentRow;
|
2009-12-06 02:57:05 +01:00
|
|
|
CHAR16 *MatchSubString;
|
|
|
|
EFI_STATUS GetNextFileStatus;
|
|
|
|
UINTN Key;
|
|
|
|
EFI_FV_FILETYPE SearchType;
|
|
|
|
EFI_FV_FILETYPE Type;
|
|
|
|
EFI_FV_FILE_ATTRIBUTES Attributes;
|
|
|
|
UINTN Size;
|
|
|
|
EFI_GUID NameGuid;
|
|
|
|
EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
|
|
|
|
UINT32 AuthenticationStatus;
|
|
|
|
VOID *Section;
|
|
|
|
UINTN SectionSize;
|
|
|
|
EFI_FV_FILETYPE Index;
|
|
|
|
UINTN Length;
|
|
|
|
UINTN BestMatchCount;
|
|
|
|
CHAR16 UnicodeFileName[MAX_CMD_LINE];
|
2010-02-10 01:46:41 +01:00
|
|
|
CHAR8 *Path;
|
2010-02-12 01:12:14 +01:00
|
|
|
CHAR8 *TypeStr;
|
2010-02-12 21:13:55 +01:00
|
|
|
UINTN TotalSize;
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
if (Argc <= 1) {
|
2010-02-10 01:46:41 +01:00
|
|
|
Path = EfiGetCwd ();
|
|
|
|
if (Path == NULL) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Path = Argv[1];
|
2009-12-06 02:57:05 +01:00
|
|
|
}
|
|
|
|
|
2010-02-10 01:46:41 +01:00
|
|
|
File = EfiOpen (Path, EFI_FILE_MODE_READ, 0);
|
2009-12-06 02:57:05 +01:00
|
|
|
if (File == NULL) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (File->Type == EfiOpenFirmwareVolume) {
|
|
|
|
// FV Dir
|
|
|
|
|
|
|
|
SearchType = EFI_FV_FILETYPE_ALL;
|
|
|
|
UnicodeFileName[0] = '\0';
|
|
|
|
MatchSubString = &UnicodeFileName[0];
|
|
|
|
if (Argc > 2) {
|
|
|
|
AsciiStrToUnicodeStr (Argv[2], UnicodeFileName);
|
|
|
|
if (UnicodeFileName[0] == '*') {
|
|
|
|
// Handle *Name substring matching
|
|
|
|
MatchSubString = &UnicodeFileName[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle file type matchs
|
|
|
|
if (Argc > 3) {
|
|
|
|
// match a specific file type, always last argument
|
|
|
|
Length = AsciiStrLen (Argv[3]);
|
|
|
|
for (Index = 1, BestMatchCount = 0; Index < sizeof (gFvFileType)/sizeof (CHAR8 *); Index++) {
|
|
|
|
if (AsciiStriCmp (gFvFileType[Index], Argv[3]) == 0) {
|
|
|
|
// exact match
|
|
|
|
SearchType = Index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AsciiStrniCmp (Argv[3], gFvFileType[Index], Length) == 0) {
|
|
|
|
// partial match, so keep looking to make sure there is only one partial match
|
|
|
|
BestMatchCount++;
|
|
|
|
SearchType = Index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BestMatchCount > 1) {
|
|
|
|
SearchType = EFI_FV_FILETYPE_ALL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-12 21:13:55 +01:00
|
|
|
TotalSize = 0;
|
2009-12-06 02:57:05 +01:00
|
|
|
Fv = File->Fv;
|
|
|
|
Key = 0;
|
|
|
|
CurrentRow = 0;
|
|
|
|
do {
|
|
|
|
Type = SearchType;
|
|
|
|
GetNextFileStatus = Fv->GetNextFile (
|
2014-08-19 15:29:52 +02:00
|
|
|
Fv,
|
2009-12-06 02:57:05 +01:00
|
|
|
&Key,
|
2014-08-19 15:29:52 +02:00
|
|
|
&Type,
|
|
|
|
&NameGuid,
|
|
|
|
&Attributes,
|
2009-12-06 02:57:05 +01:00
|
|
|
&Size
|
|
|
|
);
|
|
|
|
if (!EFI_ERROR (GetNextFileStatus)) {
|
2010-02-12 21:13:55 +01:00
|
|
|
TotalSize += Size;
|
2010-02-12 01:12:14 +01:00
|
|
|
// Calculate size of entire file
|
|
|
|
Section = NULL;
|
|
|
|
Size = 0;
|
|
|
|
Status = Fv->ReadFile (
|
2009-12-06 02:57:05 +01:00
|
|
|
Fv,
|
2014-08-19 15:29:52 +02:00
|
|
|
&NameGuid,
|
2009-12-06 02:57:05 +01:00
|
|
|
Section,
|
|
|
|
&Size,
|
|
|
|
&Type,
|
|
|
|
&Attributes,
|
|
|
|
&AuthenticationStatus
|
|
|
|
);
|
2010-02-12 01:12:14 +01:00
|
|
|
if (!((Status == EFI_BUFFER_TOO_SMALL) || !EFI_ERROR (Status))) {
|
2014-08-19 15:29:52 +02:00
|
|
|
// EFI_SUCCESS or EFI_BUFFER_TOO_SMALL mean size is valid
|
2010-02-12 21:13:55 +01:00
|
|
|
Size = 0;
|
2010-02-12 01:12:14 +01:00
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2010-02-12 01:12:14 +01:00
|
|
|
TypeStr = (Type <= EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) ? gFvFileType[Type] : "UNKNOWN";
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
// read the UI seciton to do a name match.
|
|
|
|
Section = NULL;
|
|
|
|
Status = Fv->ReadSection (
|
|
|
|
Fv,
|
|
|
|
&NameGuid,
|
|
|
|
EFI_SECTION_USER_INTERFACE,
|
|
|
|
0,
|
|
|
|
&Section,
|
|
|
|
&SectionSize,
|
|
|
|
&AuthenticationStatus
|
|
|
|
);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
if (StrStr (Section, MatchSubString) != NULL) {
|
2010-02-12 21:13:55 +01:00
|
|
|
AsciiPrint ("%,9d %7a %g %s\n", Size, TypeStr, &NameGuid, Section);
|
2009-12-06 02:57:05 +01:00
|
|
|
if (EblAnyKeyToContinueQtoQuit (&CurrentRow, FALSE)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FreePool (Section);
|
|
|
|
} else {
|
|
|
|
if (*MatchSubString == '\0') {
|
2010-02-12 21:13:55 +01:00
|
|
|
AsciiPrint ("%,9d %7a %g\n", Size, TypeStr, &NameGuid);
|
2009-12-06 02:57:05 +01:00
|
|
|
if (EblAnyKeyToContinueQtoQuit (&CurrentRow, FALSE)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (!EFI_ERROR (GetNextFileStatus));
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2010-02-12 21:13:55 +01:00
|
|
|
if (SearchType == EFI_FV_FILETYPE_ALL) {
|
|
|
|
AsciiPrint ("%,20d bytes in files %,d bytes free\n", TotalSize, File->FvSize - File->FvHeaderSize - TotalSize);
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
} else if ((File->Type == EfiOpenFileSystem) || (File->Type == EfiOpenBlockIo)) {
|
|
|
|
// Simple File System DIR
|
|
|
|
|
|
|
|
if (File->FsFileInfo == NULL) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(File->FsFileInfo->Attribute & EFI_FILE_DIRECTORY)) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle *Name substring matching
|
|
|
|
MatchSubString = NULL;
|
|
|
|
UnicodeFileName[0] = '\0';
|
|
|
|
if (Argc > 2) {
|
|
|
|
AsciiStrToUnicodeStr (Argv[2], UnicodeFileName);
|
|
|
|
if (UnicodeFileName[0] == '*') {
|
|
|
|
MatchSubString = &UnicodeFileName[1];
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
}
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
File->FsFileHandle->SetPosition (File->FsFileHandle, 0);
|
|
|
|
for (CurrentRow = 0;;) {
|
|
|
|
// First read gets the size
|
|
|
|
DirInfo = NULL;
|
|
|
|
ReadSize = 0;
|
|
|
|
Status = File->FsFileHandle->Read (File->FsFileHandle, &ReadSize, DirInfo);
|
|
|
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
|
|
|
// Allocate the buffer for the real read
|
|
|
|
DirInfo = AllocatePool (ReadSize);
|
|
|
|
if (DirInfo == NULL) {
|
|
|
|
goto Done;
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
// Read the data
|
|
|
|
Status = File->FsFileHandle->Read (File->FsFileHandle, &ReadSize, DirInfo);
|
|
|
|
if ((EFI_ERROR (Status)) || (ReadSize == 0)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
if (MatchSubString != NULL) {
|
|
|
|
if (StrStr (&DirInfo->FileName[0], MatchSubString) == NULL) {
|
|
|
|
// does not match *name argument, so skip
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else if (UnicodeFileName[0] != '\0') {
|
|
|
|
// is not an exact match for name argument, so skip
|
|
|
|
if (StrCmp (&DirInfo->FileName[0], UnicodeFileName) != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DirInfo->Attribute & EFI_FILE_DIRECTORY) {
|
|
|
|
AsciiPrint (" <DIR> %s\n", &DirInfo->FileName[0]);
|
|
|
|
} else {
|
|
|
|
AsciiPrint ("%,14ld %s\n", DirInfo->FileSize, &DirInfo->FileName[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EblAnyKeyToContinueQtoQuit (&CurrentRow, FALSE)) {
|
|
|
|
break;
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
FreePool (DirInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
Done:
|
|
|
|
if (DirInfo != NULL) {
|
|
|
|
FreePool (DirInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EfiClose (File);
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2010-02-10 01:46:41 +01:00
|
|
|
/**
|
|
|
|
Change the Current Working Directory
|
|
|
|
|
|
|
|
Argv[0] - "cd"
|
2014-08-19 15:29:52 +02:00
|
|
|
Argv[1] - Device Name:path. Path is optional
|
2010-02-10 01:46:41 +01:00
|
|
|
|
|
|
|
@param Argc Number of command arguments in Argv
|
2014-08-19 15:29:52 +02:00
|
|
|
@param Argv Array of strings that represent the parsed command line.
|
2011-08-08 20:29:14 +02:00
|
|
|
Argv[0] is the command name
|
2010-02-10 01:46:41 +01:00
|
|
|
|
|
|
|
@return EFI_SUCCESS
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
2015-10-29 13:59:06 +01:00
|
|
|
EFIAPI
|
2010-02-10 01:46:41 +01:00
|
|
|
EblCdCmd (
|
|
|
|
IN UINTN Argc,
|
|
|
|
IN CHAR8 **Argv
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (Argc <= 1) {
|
|
|
|
return EFI_SUCCESS;
|
2014-08-19 15:29:52 +02:00
|
|
|
}
|
|
|
|
|
2010-02-10 01:46:41 +01:00
|
|
|
return EfiSetCwd (Argv[1]);
|
|
|
|
}
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mCmdDirTemplate[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"dir",
|
|
|
|
" dirdev [*match]; directory listing of dirdev. opt match a substring",
|
|
|
|
NULL,
|
|
|
|
EblDirCmd
|
2010-02-10 01:46:41 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"cd",
|
|
|
|
" device - set the current working directory",
|
|
|
|
NULL,
|
|
|
|
EblCdCmd
|
2009-12-06 02:57:05 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initialize the commands in this in this file
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EblInitializeDirCmd (
|
|
|
|
VOID
|
|
|
|
)
|
2014-08-19 15:29:52 +02:00
|
|
|
{
|
2009-12-06 02:57:05 +01:00
|
|
|
if (FeaturePcdGet (PcdEmbeddedDirCmd)) {
|
|
|
|
EblAddCommands (mCmdDirTemplate, sizeof (mCmdDirTemplate)/sizeof (EBL_COMMAND_TABLE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|