UEFI shell下的脚本文件的命名格式为: ****.nsh
脚本的语法和规范参考:
- 《EFI Shell User’s Guide》
- 《UEFI原理与编程》
1. 写一个简单的脚本测试下:
脚本名为test.nsh,内容如下:
pci
2.开机自启动脚本
UEFI shell有一个开机自启动脚本,命名startup.nsh
编辑下startup.nsh,内容为
date
开启虚拟机,不做任何操作,结果如下:
3.开机自启动脚本的代码实现
参考
edk2/ShellPkg/Application/Shell/Shell.c
...
STATIC CONST CHAR16 mStartupScript[] = L"startup.nsh";
...
{
.......
//
// Try to find 'Startup.nsh' in the execution path defined by the environment variable PATH.
//
if ((StartupScriptPath == NULL) || EFI_ERROR (ShellIsFile (StartupScriptPath))) {
SHELL_FREE_NON_NULL (StartupScriptPath);
StartupScriptPath = ShellFindFilePath (mStartupScript);
}
......
/**
Find a file by searching the CWD and then the path.
If FileName is NULL then ASSERT.
If the return value is not NULL then the memory must be caller freed.
@param FileName Filename string.
@retval NULL the file was not found
@return !NULL the full path to the file.
**/
CHAR16 *
EFIAPI
ShellFindFilePath (
IN CONST CHAR16 *FileName
);
};