loader: Add loader.exit

Add loader.exit(status). While one can get alomst this behavior with
loader.perform("quit"), quit doesn't allow a value to be returned to the
firmware. The interpretation of 'status' is firmware specific. This can
be used when autobooting doesn't work in scripts, for example, to allow
the firmware to try something else...

Sponsored by:		Netflix

Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D44094
This commit is contained in:
Warner Losh 2024-02-26 20:19:58 -07:00
parent 8bfb23abf8
commit 9398a495eb
2 changed files with 16 additions and 4 deletions

View File

@ -109,6 +109,13 @@ lua_perform(lua_State *L)
return 1;
}
static int
lua_exit(lua_State *L)
{
exit(luaL_checkinteger(L, 1));
return 0;
}
static int
lua_command_error(lua_State *L)
{
@ -380,14 +387,15 @@ lua_writefile(lua_State *L)
#define REG_SIMPLE(n) { #n, lua_ ## n }
static const struct luaL_Reg loaderlib[] = {
REG_SIMPLE(delay),
REG_SIMPLE(command_error),
REG_SIMPLE(command),
REG_SIMPLE(interpret),
REG_SIMPLE(parse),
REG_SIMPLE(command_error),
REG_SIMPLE(delay),
REG_SIMPLE(exit),
REG_SIMPLE(getenv),
REG_SIMPLE(has_command),
REG_SIMPLE(has_feature),
REG_SIMPLE(interpret),
REG_SIMPLE(parse),
REG_SIMPLE(perform),
REG_SIMPLE(printc), /* Also registered as the global 'printc' */
REG_SIMPLE(setenv),

View File

@ -61,6 +61,10 @@ Returns the error string from the last command to fail.
Like
.Fn perform
but the arguments are already parsed onto the stack.
.It Fn exit status
Exit the boot loader back to the firmware with a status of
.Va status .
The interpretation of this value is firmware specific.
.It Fn interpret str
Execute the loader builtin command
.Va str