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. 64621dae89SWarner Losh.It Fn interpret str 65621dae89SWarner LoshExecute the loader builtin command 66621dae89SWarner Losh.Va str 67621dae89SWarner Loshas if it were typed by the user. 68621dae89SWarner LoshThis will first try to execute 69621dae89SWarner Losh.Va str 70621dae89SWarner Loshas Lua. 71621dae89SWarner LoshIf that fails, it will attempt to execute it as a cli command, 72621dae89SWarner Loshincluding those defined by the 73621dae89SWarner Losh.Xr cli.lua 8 74621dae89SWarner Loshmechanism. 75621dae89SWarner LoshIf that fails, it will attempt to execute it as a builtin command 76621dae89SWarner Loshand return the same values as 77621dae89SWarner Losh.Fn perform . 78621dae89SWarner Losh.It Fn parse str 79621dae89SWarner LoshParses the command 80621dae89SWarner Losh.Va str 81621dae89SWarner Loshinto its words and return those words on the stack. 82621dae89SWarner Losh.It Fn getenv name 83621dae89SWarner LoshObtains the value of the environment variable 84621dae89SWarner Losh.Va name . 85621dae89SWarner Losh.It Fn has_command cmd 86621dae89SWarner Loshreturns 87621dae89SWarner Losh.Va true 88621dae89SWarner Loshif 89621dae89SWarner Losh.Va commmand 90621dae89SWarner Loshis present in the interpreter as a builtin. 91621dae89SWarner LoshOtherwise it returns 92621dae89SWarner Losh.Va nil 93621dae89SWarner Loshand an error string. 94621dae89SWarner LoshIt does not check the 95621dae89SWarner Losh.Dq cli 96621dae89SWarner Loshtable to see if a user defined command has been created. 97621dae89SWarner Losh.It Fn has_feature feature 98621dae89SWarner Loshreturns 99621dae89SWarner Losh.Va true 100621dae89SWarner Loshif the 101621dae89SWarner Losh.Va feature 102621dae89SWarner Loshis enabled. 103621dae89SWarner LoshOtherwise it returns 104621dae89SWarner Losh.Va nil 105621dae89SWarner Loshand an error string. 106621dae89SWarner Losh.It Fn perform str 107621dae89SWarner LoshExecute the loader builtin command 108621dae89SWarner Losh.Va str . 109621dae89SWarner LoshReturns the result of the command, one of the following values: 110621dae89SWarner Losh.Bl -tag -width loader -offset indent 111621dae89SWarner Losh.It loader.CMD_OK 112621dae89SWarner LoshThe command completed successfully. 113621dae89SWarner Losh.It loader.CMD_WARN 114621dae89SWarner LoshThe command was successful, but the user stopped its output 115621dae89SWarner Loshprematurely. 116621dae89SWarner Losh.It loader.CMD_ERROR 117621dae89SWarner LoshThe command did not complete successfully. 118621dae89SWarner LoshUse 119621dae89SWarner Losh.Va command_error 120621dae89SWarner Loshto retrieve the error. 121621dae89SWarner Losh.It loader.CMD_CRIT 122621dae89SWarner LoshThe command returned a critical error that was already printed. 123621dae89SWarner Losh.It loader.CMD_FATAL 124621dae89SWarner LoshThe command determined continuation was not possible 125621dae89SWarner Loshand the loader panicked. 126621dae89SWarner LoshIn practice, though, 127621dae89SWarner Losh.Fn panic 128621dae89SWarner Loshdoes not return. 129621dae89SWarner Losh.El 130621dae89SWarner Losh.It Fn printc str 131621dae89SWarner LoshOutputs the string using the loader's 132621dae89SWarner Losh.Fn putchar 133621dae89SWarner Loshfunction. 134621dae89SWarner LoshThis function is also available globally as 135621dae89SWarner Losh.Fn printc . 136621dae89SWarner Losh.It Fn setenv name value 137621dae89SWarner LoshInsert or reset the environment variable 138621dae89SWarner Losh.Va name 139621dae89SWarner Loshinto the loader's environment list. 140621dae89SWarner LoshIf no environment variable with this name exists, one is created. 141621dae89SWarner LoshIf one exists, its value is replaced. 142621dae89SWarner Losh.It Fn time 143621dae89SWarner LoshReturns the loader's notion of time, in seconds since 1970. 144621dae89SWarner LoshThe value of loader's notion varies somewhat between different loading 145621dae89SWarner Loshenvironments. 146621dae89SWarner Losh.It Fn unsetenv name 147621dae89SWarner LoshRemoves the environment variable 148621dae89SWarner Losh.Va name 149621dae89SWarner Loshfrom the loader's environment list. 150621dae89SWarner Losh.El 151*a8f8c537SWarner Losh.Ss Compatibility 152*a8f8c537SWarner LoshThe functions 153*a8f8c537SWarner Losh.Fn fb_bezier , 154*a8f8c537SWarner Losh.Fn fb_drawrect , 155*a8f8c537SWarner Losh.Fn fb_line , 156*a8f8c537SWarner Losh.Fn fb_putimage , 157*a8f8c537SWarner Losh.Fn fb_set_pixel , 158*a8f8c537SWarner Losh.Fn term_drawrect , 159621dae89SWarner Loshand 160*a8f8c537SWarner Losh.Fn term_putimage 161*a8f8c537SWarner Loshhave moved to the 162*a8f8c537SWarner Losh.Ic gfx 163*a8f8c537SWarner Loshtable. 164*a8f8c537SWarner LoshThey remain in the 165*a8f8c537SWarner Losh.Ic loader 166*a8f8c537SWarner Loshtable for a transition period and are documented in 167*a8f8c537SWarner Losh.Xr gfx.lua 8 . 168621dae89SWarner Losh.Ss Default File 169621dae89SWarner LoshIn addition, the Lua interpreters start with the file 170621dae89SWarner Losh.Pa /boot/lua/loader.lua 171621dae89SWarner Loshwhen they start to boot the system. 172621dae89SWarner LoshThe default one will fixup the screen, load the configuration files, check for a 173621dae89SWarner Loshpassword, and then load the menu or load the kernel file and then return. 174621dae89SWarner LoshIf autoboot is enabled, the loaded files will boot. 175621dae89SWarner Losh.Sh SEE ALSO 176621dae89SWarner Losh.Xr loader.conf 5 , 177621dae89SWarner Losh.Xr core.lua 8 , 178*a8f8c537SWarner Losh.Xr gfx.lua 8 , 179621dae89SWarner Losh.Xr loader 8 , 180621dae89SWarner Losh.Xr sysctl 8 181621dae89SWarner Losh.Sh AUTHORS 182621dae89SWarner LoshThe 183621dae89SWarner Losh.Nm 184621dae89SWarner Loshman page was written by 185621dae89SWarner Losh.An Warner Losh Aq Mt imp@FreeBSD.org . 186621dae89SWarner Losh.Sh BUGS 187621dae89SWarner Losh.Fn command 188621dae89SWarner Loshand 189621dae89SWarner Losh.Fn perform 190621dae89SWarner Loshshould return a tuple when there's 191621dae89SWarner Losh.Va CMD_ERROR 192621dae89SWarner Loshor worse. 193