xref: /freebsd-14.2/stand/lua/loader.lua.8 (revision 5e850907)
1cfe4f061SWarner Losh.\"
2cfe4f061SWarner Losh.\" Copyright (c) 2024 Netflix, Inc.
3cfe4f061SWarner Losh.\"
4cfe4f061SWarner Losh.\" SPDX-License-Identifier: BSD-2-Clause
5cfe4f061SWarner Losh.\"
6cfe4f061SWarner Losh.Dd February 6, 2024
7cfe4f061SWarner Losh.Dt LOADER.LUA 8
8cfe4f061SWarner Losh.Os
9cfe4f061SWarner Losh.Sh NAME
10cfe4f061SWarner Losh.Nm loader.lua
11cfe4f061SWarner Losh.Nd Fx Lua loader module
12cfe4f061SWarner Losh.Sh DESCRIPTION
13cfe4f061SWarner LoshThe built-in Lua bindings for the
14cfe4f061SWarner Losh.Fx
15cfe4f061SWarner Loshboot loaders using the Lua interpreter
16cfe4f061SWarner Loshare available via the
17cfe4f061SWarner Losh.Ic loader
18cfe4f061SWarner Loshtable.
19cfe4f061SWarner Losh.Pp
20cfe4f061SWarner LoshThe
21cfe4f061SWarner Losh.Ic loader
22cfe4f061SWarner Loshtable is always available in Lua scripts.
23cfe4f061SWarner LoshThere is no need to require it like other loader-specific modules.
24cfe4f061SWarner Losh.Ss Exported Variables
25cfe4f061SWarner LoshThe following variables are provided by the Lua interpreter in the
26cfe4f061SWarner Losh.Nm loader
27cfe4f061SWarner Loshtable:
28cfe4f061SWarner Losh.Bl -tag -width machine_arch
29cfe4f061SWarner Losh.It Ic machine
30cfe4f061SWarner LoshThe target's
31cfe4f061SWarner Losh.Va hw.machine
32cfe4f061SWarner Losh.Xr sysctl 8
33cfe4f061SWarner Loshvalue.
34cfe4f061SWarner Losh.It Ic machine_arch
35cfe4f061SWarner LoshThe target's
36cfe4f061SWarner Losh.Va hw.machine_arch
37cfe4f061SWarner Losh.Xr sysctl 8
38cfe4f061SWarner Loshvalue.
39cfe4f061SWarner LoshSome boot loaders are 32-bit applications that then load a 64-bit
40cfe4f061SWarner Loshkernel.
41cfe4f061SWarner LoshIn these cases,
42cfe4f061SWarner Losh.Ic machine_arch
43cfe4f061SWarner Loshrepresents the 32-bit architecture, not the 64-bit architecture.
44cfe4f061SWarner Losh.It Ic lua_path
45cfe4f061SWarner LoshThe current lua loading path.
46cfe4f061SWarner Losh.It Ic version
47cfe4f061SWarner LoshThe version of the boot program.
48cfe4f061SWarner Losh.El
49cfe4f061SWarner Losh.Ss Exported Functions
50cfe4f061SWarner LoshThe following functions are exported in the
51cfe4f061SWarner Losh.Nm loader
52cfe4f061SWarner Loshtable.
53cfe4f061SWarner Losh.Bl -tag -width term_putimage
54cfe4f061SWarner Losh.It Fn delay usec
55cfe4f061SWarner LoshDelay for
56cfe4f061SWarner Losh.Va usec
57cfe4f061SWarner Loshmicroseconds.
58cfe4f061SWarner Losh.It Fn command_error
59cfe4f061SWarner LoshReturns the error string from the last command to fail.
60cfe4f061SWarner Losh.It Fn command argc argv
61cfe4f061SWarner LoshLike
62cfe4f061SWarner Losh.Fn perform
63cfe4f061SWarner Loshbut the arguments are already parsed onto the stack.
64*5e850907SWarner Losh.It Fn exit status
65*5e850907SWarner LoshExit the boot loader back to the firmware with a status of
66*5e850907SWarner Losh.Va status .
67*5e850907SWarner LoshThe interpretation of this value is firmware specific.
68cfe4f061SWarner Losh.It Fn interpret str
69cfe4f061SWarner LoshExecute the loader builtin command
70cfe4f061SWarner Losh.Va str
71cfe4f061SWarner Loshas if it were typed by the user.
72cfe4f061SWarner LoshThis will first try to execute
73cfe4f061SWarner Losh.Va str
74cfe4f061SWarner Loshas Lua.
75cfe4f061SWarner LoshIf that fails, it will attempt to execute it as a cli command,
76cfe4f061SWarner Loshincluding those defined by the
77cfe4f061SWarner Losh.Xr cli.lua 8
78cfe4f061SWarner Loshmechanism.
79cfe4f061SWarner LoshIf that fails, it will attempt to execute it as a builtin command
80cfe4f061SWarner Loshand return the same values as
81cfe4f061SWarner Losh.Fn perform .
82cfe4f061SWarner Losh.It Fn parse str
83cfe4f061SWarner LoshParses the command
84cfe4f061SWarner Losh.Va str
85cfe4f061SWarner Loshinto its words and return those words on the stack.
86cfe4f061SWarner Losh.It Fn getenv name
87cfe4f061SWarner LoshObtains the value of the environment variable
88cfe4f061SWarner Losh.Va name .
89cfe4f061SWarner Losh.It Fn has_command cmd
90cfe4f061SWarner Loshreturns
91cfe4f061SWarner Losh.Va true
92cfe4f061SWarner Loshif
93cfe4f061SWarner Losh.Va commmand
94cfe4f061SWarner Loshis present in the interpreter as a builtin.
95cfe4f061SWarner LoshOtherwise it returns
96cfe4f061SWarner Losh.Va nil
97cfe4f061SWarner Loshand an error string.
98cfe4f061SWarner LoshIt does not check the
99cfe4f061SWarner Losh.Dq cli
100cfe4f061SWarner Loshtable to see if a user defined command has been created.
101cfe4f061SWarner Losh.It Fn has_feature feature
102cfe4f061SWarner Loshreturns
103cfe4f061SWarner Losh.Va true
104cfe4f061SWarner Loshif the
105cfe4f061SWarner Losh.Va feature
106cfe4f061SWarner Loshis enabled.
107cfe4f061SWarner LoshOtherwise it returns
108cfe4f061SWarner Losh.Va nil
109cfe4f061SWarner Loshand an error string.
110cfe4f061SWarner Losh.It Fn perform str
111cfe4f061SWarner LoshExecute the loader builtin command
112cfe4f061SWarner Losh.Va str .
113cfe4f061SWarner LoshReturns the result of the command, one of the following values:
114cfe4f061SWarner Losh.Bl -tag -width loader -offset indent
115cfe4f061SWarner Losh.It loader.CMD_OK
116cfe4f061SWarner LoshThe command completed successfully.
117cfe4f061SWarner Losh.It loader.CMD_WARN
118cfe4f061SWarner LoshThe command was successful, but the user stopped its output
119cfe4f061SWarner Loshprematurely.
120cfe4f061SWarner Losh.It loader.CMD_ERROR
121cfe4f061SWarner LoshThe command did not complete successfully.
122cfe4f061SWarner LoshUse
123cfe4f061SWarner Losh.Va command_error
124cfe4f061SWarner Loshto retrieve the error.
125cfe4f061SWarner Losh.It loader.CMD_CRIT
126cfe4f061SWarner LoshThe command returned a critical error that was already printed.
127cfe4f061SWarner Losh.It loader.CMD_FATAL
128cfe4f061SWarner LoshThe command determined continuation was not possible
129cfe4f061SWarner Loshand the loader panicked.
130cfe4f061SWarner LoshIn practice, though,
131cfe4f061SWarner Losh.Fn panic
132cfe4f061SWarner Loshdoes not return.
133cfe4f061SWarner Losh.El
134cfe4f061SWarner Losh.It Fn printc str
135cfe4f061SWarner LoshOutputs the string using the loader's
136cfe4f061SWarner Losh.Fn putchar
137cfe4f061SWarner Loshfunction.
138cfe4f061SWarner LoshThis function is also available globally as
139cfe4f061SWarner Losh.Fn printc .
140cfe4f061SWarner Losh.It Fn setenv name value
141cfe4f061SWarner LoshInsert or reset the environment variable
142cfe4f061SWarner Losh.Va name
143cfe4f061SWarner Loshinto the loader's environment list.
144cfe4f061SWarner LoshIf no environment variable with this name exists, one is created.
145cfe4f061SWarner LoshIf one exists, its value is replaced.
146cfe4f061SWarner Losh.It Fn time
147cfe4f061SWarner LoshReturns the loader's notion of time, in seconds since 1970.
148cfe4f061SWarner LoshThe value of loader's notion varies somewhat between different loading
149cfe4f061SWarner Loshenvironments.
150cfe4f061SWarner Losh.It Fn unsetenv name
151cfe4f061SWarner LoshRemoves the environment variable
152cfe4f061SWarner Losh.Va name
153cfe4f061SWarner Loshfrom the loader's environment list.
154cfe4f061SWarner Losh.El
15532c08f49SWarner Losh.Ss Compatibility
15632c08f49SWarner LoshThe functions
15732c08f49SWarner Losh.Fn fb_bezier ,
15832c08f49SWarner Losh.Fn fb_drawrect ,
15932c08f49SWarner Losh.Fn fb_line ,
16032c08f49SWarner Losh.Fn fb_putimage ,
16132c08f49SWarner Losh.Fn fb_set_pixel ,
16232c08f49SWarner Losh.Fn term_drawrect ,
163cfe4f061SWarner Loshand
16432c08f49SWarner Losh.Fn term_putimage
16532c08f49SWarner Loshhave moved to the
16632c08f49SWarner Losh.Ic gfx
16732c08f49SWarner Loshtable.
16832c08f49SWarner LoshThey remain in the
16932c08f49SWarner Losh.Ic loader
17032c08f49SWarner Loshtable for a transition period and are documented in
17132c08f49SWarner Losh.Xr gfx.lua 8 .
172cfe4f061SWarner Losh.Ss Default File
173cfe4f061SWarner LoshIn addition, the Lua interpreters start with the file
174cfe4f061SWarner Losh.Pa /boot/lua/loader.lua
175cfe4f061SWarner Loshwhen they start to boot the system.
176cfe4f061SWarner LoshThe default one will fixup the screen, load the configuration files, check for a
177cfe4f061SWarner Loshpassword, and then load the menu or load the kernel file and then return.
178cfe4f061SWarner LoshIf autoboot is enabled, the loaded files will boot.
179cfe4f061SWarner Losh.Sh SEE ALSO
180cfe4f061SWarner Losh.Xr loader.conf 5 ,
181cfe4f061SWarner Losh.Xr core.lua 8 ,
18232c08f49SWarner Losh.Xr gfx.lua 8 ,
183cfe4f061SWarner Losh.Xr loader 8 ,
184cfe4f061SWarner Losh.Xr sysctl 8
185cfe4f061SWarner Losh.Sh AUTHORS
186cfe4f061SWarner LoshThe
187cfe4f061SWarner Losh.Nm
188cfe4f061SWarner Loshman page was written by
189cfe4f061SWarner Losh.An Warner Losh Aq Mt [email protected] .
190cfe4f061SWarner Losh.Sh BUGS
191cfe4f061SWarner Losh.Fn command
192cfe4f061SWarner Loshand
193cfe4f061SWarner Losh.Fn perform
194cfe4f061SWarner Loshshould return a tuple when there's
195cfe4f061SWarner Losh.Va CMD_ERROR
196cfe4f061SWarner Loshor worse.
197