1621dae89SWarner Losh.\" 2621dae89SWarner Losh.\" Copyright (c) 2024 Netflix, Inc. 3621dae89SWarner Losh.\" 4621dae89SWarner Losh.\" SPDX-License-Identifier: BSD-2-Clause 5621dae89SWarner Losh.\" 6621dae89SWarner Losh.Dd February 6, 2024 7621dae89SWarner Losh.Dt LOADER.LUA 8 8621dae89SWarner Losh.Os 9621dae89SWarner Losh.Sh NAME 10621dae89SWarner Losh.Nm loader.lua 11621dae89SWarner Losh.Nd Fx Lua loader module 12621dae89SWarner Losh.Sh DESCRIPTION 13621dae89SWarner LoshThe built-in Lua bindings for the 14621dae89SWarner Losh.Fx 15621dae89SWarner Loshboot loaders using the Lua interpreter 16621dae89SWarner Loshare available via the 17621dae89SWarner Losh.Ic loader 18621dae89SWarner Loshtable. 19621dae89SWarner Losh.Pp 20621dae89SWarner LoshThe 21621dae89SWarner Losh.Ic loader 22621dae89SWarner Loshtable is always available in Lua scripts. 23621dae89SWarner LoshThere is no need to require it like other loader-specific modules. 24621dae89SWarner Losh.Ss Exported Variables 25621dae89SWarner LoshThe following variables are provided by the Lua interpreter in the 26621dae89SWarner Losh.Nm loader 27621dae89SWarner Loshtable: 28621dae89SWarner Losh.Bl -tag -width machine_arch 29621dae89SWarner Losh.It Ic machine 30621dae89SWarner LoshThe target's 31621dae89SWarner Losh.Va hw.machine 32621dae89SWarner Losh.Xr sysctl 8 33621dae89SWarner Loshvalue. 34621dae89SWarner Losh.It Ic machine_arch 35621dae89SWarner LoshThe target's 36621dae89SWarner Losh.Va hw.machine_arch 37621dae89SWarner Losh.Xr sysctl 8 38621dae89SWarner Loshvalue. 39621dae89SWarner LoshSome boot loaders are 32-bit applications that then load a 64-bit 40621dae89SWarner Loshkernel. 41621dae89SWarner LoshIn these cases, 42621dae89SWarner Losh.Ic machine_arch 43621dae89SWarner Loshrepresents the 32-bit architecture, not the 64-bit architecture. 44621dae89SWarner Losh.It Ic lua_path 45621dae89SWarner LoshThe current lua loading path. 46621dae89SWarner Losh.It Ic version 47621dae89SWarner LoshThe version of the boot program. 48621dae89SWarner Losh.El 49621dae89SWarner Losh.Ss Exported Functions 50621dae89SWarner LoshThe following functions are exported in the 51621dae89SWarner Losh.Nm loader 52621dae89SWarner Loshtable. 53621dae89SWarner Losh.Bl -tag -width term_putimage 54621dae89SWarner Losh.It Fn delay usec 55621dae89SWarner LoshDelay for 56621dae89SWarner Losh.Va usec 57621dae89SWarner Loshmicroseconds. 58621dae89SWarner Losh.It Fn command_error 59621dae89SWarner LoshReturns the error string from the last command to fail. 60621dae89SWarner Losh.It Fn command argc argv 61621dae89SWarner LoshLike 62621dae89SWarner Losh.Fn perform 63621dae89SWarner Loshbut the arguments are already parsed onto the stack. 64*9398a495SWarner Losh.It Fn exit status 65*9398a495SWarner LoshExit the boot loader back to the firmware with a status of 66*9398a495SWarner Losh.Va status . 67*9398a495SWarner LoshThe interpretation of this value is firmware specific. 68621dae89SWarner Losh.It Fn interpret str 69621dae89SWarner LoshExecute the loader builtin command 70621dae89SWarner Losh.Va str 71621dae89SWarner Loshas if it were typed by the user. 72621dae89SWarner LoshThis will first try to execute 73621dae89SWarner Losh.Va str 74621dae89SWarner Loshas Lua. 75621dae89SWarner LoshIf that fails, it will attempt to execute it as a cli command, 76621dae89SWarner Loshincluding those defined by the 77621dae89SWarner Losh.Xr cli.lua 8 78621dae89SWarner Loshmechanism. 79621dae89SWarner LoshIf that fails, it will attempt to execute it as a builtin command 80621dae89SWarner Loshand return the same values as 81621dae89SWarner Losh.Fn perform . 82621dae89SWarner Losh.It Fn parse str 83621dae89SWarner LoshParses the command 84621dae89SWarner Losh.Va str 85621dae89SWarner Loshinto its words and return those words on the stack. 86621dae89SWarner Losh.It Fn getenv name 87621dae89SWarner LoshObtains the value of the environment variable 88621dae89SWarner Losh.Va name . 89621dae89SWarner Losh.It Fn has_command cmd 90621dae89SWarner Loshreturns 91621dae89SWarner Losh.Va true 92621dae89SWarner Loshif 93621dae89SWarner Losh.Va commmand 94621dae89SWarner Loshis present in the interpreter as a builtin. 95621dae89SWarner LoshOtherwise it returns 96621dae89SWarner Losh.Va nil 97621dae89SWarner Loshand an error string. 98621dae89SWarner LoshIt does not check the 99621dae89SWarner Losh.Dq cli 100621dae89SWarner Loshtable to see if a user defined command has been created. 101621dae89SWarner Losh.It Fn has_feature feature 102621dae89SWarner Loshreturns 103621dae89SWarner Losh.Va true 104621dae89SWarner Loshif the 105621dae89SWarner Losh.Va feature 106621dae89SWarner Loshis enabled. 107621dae89SWarner LoshOtherwise it returns 108621dae89SWarner Losh.Va nil 109621dae89SWarner Loshand an error string. 110621dae89SWarner Losh.It Fn perform str 111621dae89SWarner LoshExecute the loader builtin command 112621dae89SWarner Losh.Va str . 113621dae89SWarner LoshReturns the result of the command, one of the following values: 114621dae89SWarner Losh.Bl -tag -width loader -offset indent 115621dae89SWarner Losh.It loader.CMD_OK 116621dae89SWarner LoshThe command completed successfully. 117621dae89SWarner Losh.It loader.CMD_WARN 118621dae89SWarner LoshThe command was successful, but the user stopped its output 119621dae89SWarner Loshprematurely. 120621dae89SWarner Losh.It loader.CMD_ERROR 121621dae89SWarner LoshThe command did not complete successfully. 122621dae89SWarner LoshUse 123621dae89SWarner Losh.Va command_error 124621dae89SWarner Loshto retrieve the error. 125621dae89SWarner Losh.It loader.CMD_CRIT 126621dae89SWarner LoshThe command returned a critical error that was already printed. 127621dae89SWarner Losh.It loader.CMD_FATAL 128621dae89SWarner LoshThe command determined continuation was not possible 129621dae89SWarner Loshand the loader panicked. 130621dae89SWarner LoshIn practice, though, 131621dae89SWarner Losh.Fn panic 132621dae89SWarner Loshdoes not return. 133621dae89SWarner Losh.El 134621dae89SWarner Losh.It Fn printc str 135621dae89SWarner LoshOutputs the string using the loader's 136621dae89SWarner Losh.Fn putchar 137621dae89SWarner Loshfunction. 138621dae89SWarner LoshThis function is also available globally as 139621dae89SWarner Losh.Fn printc . 140621dae89SWarner Losh.It Fn setenv name value 141621dae89SWarner LoshInsert or reset the environment variable 142621dae89SWarner Losh.Va name 143621dae89SWarner Loshinto the loader's environment list. 144621dae89SWarner LoshIf no environment variable with this name exists, one is created. 145621dae89SWarner LoshIf one exists, its value is replaced. 146621dae89SWarner Losh.It Fn time 147621dae89SWarner LoshReturns the loader's notion of time, in seconds since 1970. 148621dae89SWarner LoshThe value of loader's notion varies somewhat between different loading 149621dae89SWarner Loshenvironments. 150621dae89SWarner Losh.It Fn unsetenv name 151621dae89SWarner LoshRemoves the environment variable 152621dae89SWarner Losh.Va name 153621dae89SWarner Loshfrom the loader's environment list. 154621dae89SWarner Losh.El 155a8f8c537SWarner Losh.Ss Compatibility 156a8f8c537SWarner LoshThe functions 157a8f8c537SWarner Losh.Fn fb_bezier , 158a8f8c537SWarner Losh.Fn fb_drawrect , 159a8f8c537SWarner Losh.Fn fb_line , 160a8f8c537SWarner Losh.Fn fb_putimage , 161a8f8c537SWarner Losh.Fn fb_set_pixel , 162a8f8c537SWarner Losh.Fn term_drawrect , 163621dae89SWarner Loshand 164a8f8c537SWarner Losh.Fn term_putimage 165a8f8c537SWarner Loshhave moved to the 166a8f8c537SWarner Losh.Ic gfx 167a8f8c537SWarner Loshtable. 168a8f8c537SWarner LoshThey remain in the 169a8f8c537SWarner Losh.Ic loader 170a8f8c537SWarner Loshtable for a transition period and are documented in 171a8f8c537SWarner Losh.Xr gfx.lua 8 . 172621dae89SWarner Losh.Ss Default File 173621dae89SWarner LoshIn addition, the Lua interpreters start with the file 174621dae89SWarner Losh.Pa /boot/lua/loader.lua 175621dae89SWarner Loshwhen they start to boot the system. 176621dae89SWarner LoshThe default one will fixup the screen, load the configuration files, check for a 177621dae89SWarner Loshpassword, and then load the menu or load the kernel file and then return. 178621dae89SWarner LoshIf autoboot is enabled, the loaded files will boot. 179621dae89SWarner Losh.Sh SEE ALSO 180621dae89SWarner Losh.Xr loader.conf 5 , 181621dae89SWarner Losh.Xr core.lua 8 , 182a8f8c537SWarner Losh.Xr gfx.lua 8 , 183621dae89SWarner Losh.Xr loader 8 , 184621dae89SWarner Losh.Xr sysctl 8 185621dae89SWarner Losh.Sh AUTHORS 186621dae89SWarner LoshThe 187621dae89SWarner Losh.Nm 188621dae89SWarner Loshman page was written by 189621dae89SWarner Losh.An Warner Losh Aq Mt imp@FreeBSD.org . 190621dae89SWarner Losh.Sh BUGS 191621dae89SWarner Losh.Fn command 192621dae89SWarner Loshand 193621dae89SWarner Losh.Fn perform 194621dae89SWarner Loshshould return a tuple when there's 195621dae89SWarner Losh.Va CMD_ERROR 196621dae89SWarner Loshor worse. 197