2009-12-06 02:57:05 +01:00
|
|
|
/** @file
|
|
|
|
Script command allows the execution of commands from a text file
|
|
|
|
|
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: EfiDevice.c
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "Ebl.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Execute the passed in file like a series of commands. The ; can be used on
|
2014-08-19 15:29:52 +02:00
|
|
|
a single line to indicate multiple commands per line. The Ascii text file
|
|
|
|
can contain any number of lines. The following line termination forms are
|
2009-12-06 02:57:05 +01:00
|
|
|
supported:
|
|
|
|
LF : Unix, Mac OS X*, BeOS
|
|
|
|
CR+LF: MS-DOS*, Microsoft Windows*
|
2011-08-08 20:29:14 +02:00
|
|
|
CR : Commodore, Apple II, and really Mac OS
|
2014-08-19 15:29:52 +02:00
|
|
|
LF+CR: for simplicity and completeness
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
Argv[0] - "script"
|
|
|
|
Argv[1] - Device Name:path for the file to load
|
|
|
|
|
|
|
|
script fv1:\script.txt
|
|
|
|
|
|
|
|
@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
|
|
|
EblScriptCmd (
|
|
|
|
IN UINTN Argc,
|
|
|
|
IN CHAR8 **Argv
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_OPEN_FILE *File;
|
|
|
|
VOID *Address;
|
|
|
|
UINTN Size;
|
|
|
|
CHAR8 *Ptr;
|
|
|
|
CHAR8 *ScanPtr;
|
|
|
|
UINTN CmdLineSize;
|
2014-08-19 15:29:52 +02:00
|
|
|
|
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
|
|
|
|
if (Argc < 2) {
|
|
|
|
// file name required
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
File = EfiOpen (Argv[1], EFI_FILE_MODE_READ, 0);
|
|
|
|
if (File == NULL) {
|
|
|
|
AsciiPrint (" %a is not a valid path\n", Argv[1]);
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = EfiReadAllocatePool (File, &Address, &Size);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
// Loop through each line in the text file
|
|
|
|
for (Ptr = (CHAR8 *)Address; (Ptr < (((CHAR8 *)Address) + Size)) && !EFI_ERROR (Status); Ptr += CmdLineSize) {
|
|
|
|
for (CmdLineSize = 0, ScanPtr = Ptr; ; CmdLineSize++, ScanPtr++) {
|
|
|
|
// look for the end of the line
|
|
|
|
if ((*ScanPtr == EBL_CR) || (*ScanPtr == EBL_LF)) {
|
|
|
|
// convert to NULL as this is what input routine would do
|
|
|
|
*ScanPtr = 0;
|
|
|
|
if ((*(ScanPtr + 1) == EBL_CR) || (*(ScanPtr + 1) == EBL_LF)) {
|
|
|
|
// if its a set get the 2nd EOL char
|
|
|
|
CmdLineSize++;
|
|
|
|
*(ScanPtr + 1) = 0;
|
|
|
|
}
|
|
|
|
CmdLineSize++;
|
|
|
|
break;
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Status = ProcessCmdLine (Ptr, CmdLineSize);
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
FreePool (Address);
|
|
|
|
}
|
2014-08-19 15:29:52 +02:00
|
|
|
|
2009-12-06 02:57:05 +01:00
|
|
|
EfiClose (File);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GLOBAL_REMOVE_IF_UNREFERENCED const EBL_COMMAND_TABLE mScriptTemplate[] = {
|
|
|
|
{
|
|
|
|
"script",
|
2014-08-19 15:29:52 +02:00
|
|
|
" device:path; load an ascii file and execute it like commands",
|
2009-12-06 02:57:05 +01:00
|
|
|
NULL,
|
|
|
|
EblScriptCmd
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initialize the commands in this in this file
|
|
|
|
**/
|
|
|
|
|
|
|
|
VOID
|
|
|
|
EblInitializeScriptCmd (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (FeaturePcdGet (PcdEmbeddedScriptCmd)) {
|
|
|
|
EblAddCommands (mScriptTemplate, sizeof (mScriptTemplate)/sizeof (EBL_COMMAND_TABLE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|