aboutsummaryrefslogtreecommitdiff
path: root/stand/lua/core.lua
Commit message (Collapse)AuthorAgeFilesLines
* loader_lua: consider userboot console as serialToomas Soome2021-09-121-1/+4
| | | | | | | | We use ascii box chars with serial console because we do not know if terminal can draw unixode box chars. Same problem is about userboot console. (cherry picked from commit 5d8c062fe3ee7b2d6aed0b46d22f62c7771c0af8)
* stand: lua: enhance lfs.dir() to speed up kernels_autodetectKyle Evans2021-02-031-2/+6
| | | | | | | | | | | | | | This eliminates a lot of stat() calls that happen when lualoader renders the menu with the default settings, and greatly speeds up rendering on my laptop. ftype is nil if loader/loader.efi hasn't been updated yet, falling back to lfs.attributes() to test. This is technically incompatible with lfs, but not in a particularly terrible way. (cherry picked from commit e25ee296c919d6567aa76058a7049eac974797fb)
* MFC: r366228Warner Losh2020-10-041-0/+34
| | | | | | | | | | | | | Report the kernel console on the boot screen Report what console the boot loader is telling the kernel to use: o Dual (Serial Primary) o Dual (Video Primary) o Serial o Video and allow toggling between them. Notes: svn path=/stable/12/; revision=366422
* MFC r359371Ryan Moeller2020-04-031-0/+1
| | | | | | | | | | loader: Fully reset terminal settings, not just colors Reviewed by: kevans, tsoome Approved by: mav (mentor) Notes: svn path=/stable/12/; revision=359586
* MFC r354247, r355349: lualoader try_include improvementKyle Evans2019-12-121-5/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | r354247: lualoader: rewrite try_include using lfs + dofile Actual modules get require()'d in, rather than try_include(). All instances of try_include should be provided with proper hooks/API in the rest of loader to do the work they need to do, since we can't rely on them to exist. Convert this now to lfs + dofile since we won't really be treating them as modules. lfs is required because dofile will properly throw an error if the file doesn't exist, which is not in the spirit of 'optionally included'. Getting out of the pcall game allows us to provide a loader.exit() style call that backs out to the common bits of loader (autoboot sequence unless disabled with a loader.setenv("autoboot_delay", "NO")). The most ideal way identified so far to implement loader.exit() is to throw a special abort-style error that indicates to the caller in interp_lua that we've not actually errored out, just continue execution. Otherwise, we have to hack in logic to bubble up and return from loader.lua without continuing further, which gets kind of ugly depending on the context in which we're aborting. A compat shim is provided temporarily in case the executing loader doesn't yet have loader.lua_path, which was just added in r354246. r355349: lualoader: correct a typo from r354247 r354247 converted try_include to lfs + dofile with the loader.lua_path added just before. Fortunately, there was a hardcoded /boot/lua fallback in case loader.lua_path wasn't being set yet- I typo'd it as loader.lua_paths. Fix the typo. Notes: svn path=/stable/12/; revision=355661
* MFC r352194: lualoader: Revert to ASCII menu frame for serial consoleKyle Evans2019-09-151-0/+10
| | | | | | | | | | | | | | | The box drawing characters we use aren't necessarily safe with a serial console; for instance, in the report by npn@, these were causing his xterm to send back a sequence that lua picked up as input and halted the boot. This is less than ideal. Fallback to ASCII frames for console with 'comconsole' in it. This is a partial revert r338108 by imp@ -- instead of removing the menu entirely and disabling color/cursor sequences, just reverting the default frame to ASCII is enough to not break in this setup. Notes: svn path=/stable/12/; revision=352349
* MFC r339849: lualoader: Fix try_include error handlingKyle Evans2018-11-011-11/+3
| | | | | | | | | | | | | | | The previous iteration of try_include attempted to be 'friendly' and error() out if we hit an error that wasn't ENOENT. This was semi-OK, but fragile as it relied on pattern matching the error message. Move the responsibility for handling failure to the caller. Following a common lua pattern, we'll return the return value of the underlying require() on success, or false and an error message. Approved by: re (gjb) Notes: svn path=/stable/12/; revision=340012
* lualoader: Honor boot_* variables at lua initKyle Evans2018-10-071-11/+28
| | | | | | | | | | | | | | For non-UEFI systems, boot.config(5) may have -s or -v specified for single-user and verbose boot respectively. These were not being properly taken into account and reflected in the "Boot Options" submenu. When we initialize core.lua, we'll record boot_single and boot_verbose as we do ACPI and consider these the system defaults. Reported by: David Wolfskill <david@catwhisker.org> Approved by: re (kib) Notes: svn path=/head/; revision=339222
* lualoader: Handle comma-separated kernels as wellKyle Evans2018-09-031-1/+1
| | | | | | | | | | | | | | The format for kernels is documented as being space-delimited, but forthloader was more lenient on this and so people began to depend on it. A later pass will be made to document all of the fun features that forthloader allowed that may not be immediately obvious. Reported by: mmacy Approved by: re (kib) Notes: svn path=/head/; revision=338438
* lualoader: Just compare expression directlyKyle Evans2018-08-211-2/+1
| | | | Notes: svn path=/head/; revision=338167
* Serial console menus for lua.Warner Losh2018-08-201-16/+0
| | | | | | | | | | | Remove a bunch of special cases for UEFI and serial consoles. We do want to do curses and menu things here. This makes us match what we do in FORTH, with the possible exception of boxes around menus. Differential Revision: https://reviews.freebsd.org/D16816 Notes: svn path=/head/; revision=338108
* lualoader: Actually re-raise error in try_includeKyle Evans2018-03-261-1/+1
| | | | | | | | | | | | | | | | It was previously only printed, but we do actually want to raise it as a full blown error so that things don't look OK when they've actually gone wrong. The second parameter to error, level, is set to 2 here so that the error message reflects the position of the try_include caller, rather than the try_include itself. Example: LUA ERROR: /boot/lua/loader.lua:46: /boot/lua/local.lua:1: attempt to call a nil value (global 'cxcint'). Notes: svn path=/head/; revision=331564
* lualoader: Implement try_include and use it for including the local moduleKyle Evans2018-03-261-0/+20
| | | | | | | | | | | | | | | | | | | | This provides a way to optionally include a module without having to wrap it in filesystem checks. try_include is a little more robust, using the lua search path instead of forcing us to explicitly consider all of the places we could want to include a module. Errors are still generally raised from trying to load the module, but ENOENT will not get raised unless we're doing a verbose load. This will also be used to split out logo/brand graphics into their own files so that we can safely scale up the number of graphics included without worrying about the extra memory consumption- opting to lazily load graphics instead. Reviewed by: cem Differential Revision: https://reviews.freebsd.org/D14658 Notes: svn path=/head/; revision=331563
* UEFI: Ditch console mode setting, choose optimal GOP mode later in bootKyle Evans2018-03-211-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | boot1 is too early to be deciding a good resolution. Console modes don't map cleanly/predictably to actual screen resolutions, and GOP does not reflect the actual screen resolution after a console mode change. Rip it out. Add an efi-autoresizecons command to loader to choose an optimal screen resolution based on the current environment. We'll explicitly execute this later, preferably before we draw anything of value but after we load config and pick up any tunables we may need to decide where we're going. This method also allows us to actually pass the correct framebuffer information on to the kernel. UGA autoresizing is not implemented because it doesn't have the kind of mode enumeration that GOP does. If an interested person with relevant hardware could get in contact, we can take a look at implementing UGA autoresize. This effectively "fixes" the breakage caused by r327058, but doesn't actually set the resolution correctly until the interpreter calls efi-autoresizcons. The lualoader version of this has been included for reference; the forth equivalent will follow. Reviewed by: imp (with some hestitation), manu Differential Revision: https://reviews.freebsd.org/D14788 Notes: svn path=/head/; revision=331321
* lualoader: Add primitive hook module, use it to untangle bogus referenceKyle Evans2018-03-211-1/+4
| | | | | | | | | | | | | | | | See: comments in the hook module about intended usage, as well as the introduced use for config.reloaded. Use the newly introduced hook module to define a "config.reloaded" hook. This is currently used to register core's clearKernelCache as a reload hook to avoid a circular dependency and fix this functionality- it didn't actually work out, and it isn't immediately obvious how it slipped into src. Other hook types will be introduced into the core lualoader as useful hook points are identified. Notes: svn path=/head/; revision=331281
* lualoader: Cache kernel listKyle Evans2018-03-091-2/+15
| | | | | | | | | | | | With autodetection turned on, hitting the filesystem everytime we need to calculate choices for the kernel carousel is kind of slow. Cache once on the first listing and reload it anytime the config is reloaded in case any of the loader.conf(5) changes that affect this (kernel, kernels, kernels_autodetect) have changed. This also picks up the case where we've changed currdev and the autodetected kernels could change. Notes: svn path=/head/; revision=330703
* lualoader: Only loadelf before boot/autoboot if no kernel loadedKyle Evans2018-03-071-2/+8
| | | | | | | | | | | | | | Back when I "fixed" the loading of kernel/modules to be deferred until booting, I inadvertently broke the ability to manually load a set of kernels and modules in case of something bad having happened. lualoader would instead happily load whatever is specified in loader.conf(5) and go about the boot, leading to a panic loop as you try to rediscover a way to stop the panicky efirt module from loading and fail miserably. Reported by: me, sadly Notes: svn path=/head/; revision=330564
* lualoader: Add note that \027 is a decimal representationKyle Evans2018-02-281-0/+2
| | | | | | | | | | We've included an extra '0' in there (which might get removed later, but it's maintained for the moment for legacy purposes) which oftentimes indicate that the following number should be treated as octal. This is not the case, so note that to prevent future confusion (of myself and others). Notes: svn path=/head/; revision=330101
* lualoader: Convert instances of KEYSTR_ESCAPE .. "[" -> KEYSTR_CSIKyle Evans2018-02-271-0/+1
| | | | Notes: svn path=/head/; revision=330087
* lualoader: Re-work menu skipping bitsKyle Evans2018-02-261-0/+14
| | | | | | | | | | | | | | | | | | | | | | This is motivated by a want to reduce heap usage if the menu is being skipped. Currently, the menu module must be loaded regardless of whether it's being skipped or not, which adds a cool ~50-100KB worth of memory usage. Move the menu skip logic out to core (and remove a debug print), then check in loader.lua if we should be skipping the menu and avoid loading the menu module entirely if so. This keeps our memory usage below ~115KB for a boot with the menu stripped. Also worth noting: with this change, we no longer explicitly invoke autoboot if we're skipping the menu. Instead, we let the standard loader behavior apply: try to autoboot if we need to, then drop to a loader prompt if not or if the autoboot sequence is interrupted. The only thing we still handle before dropping to the loader autoboot sequence is loadelf(), so that we can still apply any of our kernel loading behavior. Notes: svn path=/head/; revision=330020
* lualoader: More argument name expansion, part 2Kyle Evans2018-02-261-22/+22
| | | | | | | | screen also has some instances, but it also has other cleanup to go with it. Because of this, I will be committing the screen changes separately. Notes: svn path=/head/; revision=330009
* lualoader: Clean up naming conventions a little bitKyle Evans2018-02-241-3/+3
| | | | | | | | We mostly use camel case for function names, but some local functions got mixed in using internal underscores. Doubles down on camel case. Notes: svn path=/head/; revision=329927
* lualoader: Use "local function x()" instead of "local x = function()"Kyle Evans2018-02-231-1/+1
| | | | | | | | | The latter is good, but the former is more elegant and clear about what 'x' is. Adopt it, preferably only using the latter kind of notation where needed as values for tables. Notes: svn path=/head/; revision=329856
* lualoader: shallowCopyTable => deepCopyTableKyle Evans2018-02-231-2/+2
| | | | | | | I called it a shallow copy, but it wasn't really a shallow copy at all. Notes: svn path=/head/; revision=329854
* Add copyright notice to core.luaKyle Evans2018-02-231-0/+1
| | | | | | | | | I've also made some not-insignificant changes/additions to this file, to include the added constants, ACPI changes, boot environment listing, and some utility functions. Notes: svn path=/head/; revision=329852
* Add SPDX tags to lua filesKyle Evans2018-02-231-0/+2
| | | | Notes: svn path=/head/; revision=329851
* lualoader: Address some 'luacheck' concernsKyle Evans2018-02-221-1/+0
| | | | | | | | | | | | | | | luacheck pointed out an assortment of issues, ranging from non-standard globals being created as well as unused parameters, variables, and redundant assignments. Using '_' as a placeholder for values unused (whether it be parameters unused or return values unused, assuming multiple return values) feels clean and gets the point across, so I've adopted it. It also helps flag candidates for cleanup later in some of the lambdas I've created, giving me an easy way to re-evaluate later if we're still not using some of these features. Notes: svn path=/head/; revision=329809
* lualoader: Consistently use double quotesKyle Evans2018-02-221-1/+1
| | | | Notes: svn path=/head/; revision=329806
* lualoader: Split cli bits out into a cli moduleKyle Evans2018-02-221-54/+0
| | | | | | | | | This module will, in the not-so-distant future, grow functionality for reducing boilerplate in functions that implement cli commands. It will likely also house most in-tree cli commands. Notes: svn path=/head/; revision=329779
* lualoader: Make kernel autodetection contingent on loader.conf(5) varKyle Evans2018-02-211-2/+6
| | | | | | | | | | Instead of based it off of whether 'kernels' was specified, base it off of a new variable: kernels_autodetect. If set to yes, we'll run the autodetection bits and add any detected kernels to the already existing list *after* both 'kernel' and 'kernels'. Notes: svn path=/head/; revision=329733
* lualoader: Add boot environment supportKyle Evans2018-02-211-0/+44
| | | | | | | | | | | | This looks a little bit differently than the forth version for the time being, just to get off the ground- rather than a paging system, it's implemented as a simple carousel like the kernel selector. Reviewed by: cem Differential Revision: https://reviews.freebsd.org/D14436 Notes: svn path=/head/; revision=329731
* lualoader: Don't autodetect kernels if 'kernels' is explicitly setKyle Evans2018-02-211-6/+12
| | | | Notes: svn path=/head/; revision=329709
* lualoader: Return only argstr if with_kernel not requestedKyle Evans2018-02-211-3/+7
| | | | Notes: svn path=/head/; revision=329693
* lualoader: Drop explicit boolean tests; b or not bKyle Evans2018-02-211-5/+5
| | | | Notes: svn path=/head/; revision=329687
* lualoader: Drop excessive parenthesizingKyle Evans2018-02-211-33/+33
| | | | | | | | | | | This was also a convenience convention (for me) that is not very lua-tic. Drop it. I've maintained some parentheses where I'd prefer them, for example, 'if x or y or (z and w) then', but these situations are far and few between. Notes: svn path=/head/; revision=329685
* lualoader: Drop terminating semicolonsKyle Evans2018-02-211-118/+118
| | | | | | | | | | | This was previously chosen out of convenience, as we had a mixed style and needed to be consistent. I started learning Lua on Friday, so I switched everything over. It is not a very lua-nic convention, though, so drop it. Excessive parenthesizing around conditionals is next on the chopping block. Notes: svn path=/head/; revision=329684
* lualoader: Intercept the 'autoboot' cli commandKyle Evans2018-02-201-3/+21
| | | | Notes: svn path=/head/; revision=329674
* lualoader: Intercept boot cli commandKyle Evans2018-02-201-0/+32
| | | | | | | | | | This should be functional and roughly equivalent to the Forth version. Stop doing a loadelf() on menu exit now that we can DTRT with boot invocations. autoboot interception will follow not long after. Notes: svn path=/head/; revision=329673
* lualoader: Prepare for interception of "boot" CLI cmdKyle Evans2018-02-201-4/+34
| | | | | | | | | | | | | core.boot and core.autoboot may both take arguments; add a helper to cleanly append an argstring to the given loader command. Also provide a popFrontTable() that we'll use pop the command name off of an argv table. We don't have the table library included, and including it is non-trivial, so we'll implement this one function that we need in lua for the time being. Notes: svn path=/head/; revision=329671
* lualoader: Ignore ACPI bits on !i386Kyle Evans2018-02-201-1/+5
| | | | Notes: svn path=/head/; revision=329654
* stand/lua: Consistently organize modulesKyle Evans2018-02-201-0/+1
| | | | | | | | | | | | | | | | | We follow pretty closely the following structure of a module: 1. Copyright notice 2. Module requires 3. Module local declarations 4. Module local definitions 5. Module exports 6. return Re-organize the one-offs (config/drawer) and denote the start of module exports with a comment. Notes: svn path=/head/; revision=329641
* stand/lua: Don't set ACPI off just because we can't detect it.Kyle Evans2018-02-201-1/+7
| | | | | | | | | This should unbreak EFI/!i386 cases. Reported by: Peter Lei <peter.lei@ieee.org> Notes: svn path=/head/; revision=329614
* stand/lua: Change boot menu items' names when swappedKyle Evans2018-02-191-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | [Enter] should be moved to the single user menu item when we swap them. Define a non-standard menu entry function "alternate_name" to use for this purpose for ultimate flexibility if we change our minds later. When we're booting single user, make a shallow copy of the menu that we'd normally display and swap the items and their name functions to use alternate_name instead. Toggling single user in the options menu and going back to the main menu will now correctly reflect the current boot setting with the first two menu options and "[Enter]" will always be on the right one. This shallow copy technique has the chance of being quite slow since it's done on every redraw, but in my testing it does not seem to make any obvious difference. shallowCopyTable could likely belong better in a general-purpose utility module, but this (and the key constnats) are the only candidates we have at the moment so we'll drop it into our core stuff for the moment and consider re-organization at a later date. Notes: svn path=/head/; revision=329593
* stand/lua: Add core.isSingleUserBootKyle Evans2018-02-191-0/+5
| | | | Notes: svn path=/head/; revision=329585
* stand/lua: Rename bootserial for clarityKyle Evans2018-02-191-1/+1
| | | | Notes: svn path=/head/; revision=329577
* stand/lua: Defer kernel/module loading until boot or menu escapeKyle Evans2018-02-191-0/+4
| | | | | | | | | | | | | | | | | | | | Loading the kernel and modules can be really slow. Loading before the menu draws and every time one changes kernel/boot environment is even more painful. Defer loading until we either boot, auto-boot, or escape to loader prompt. We still need to deal with configuration changes as the boot environment changes, but this is generally much quicker. This commit strips all ELF loading out of config.load/config.reload so that these are purely for configuration. config.loadelf has been created to deal with kernel/module loads. Unloading logic has been ripped out, as we won't need to deal with it in the menu anymore. Discussed in part with: allanjude Notes: svn path=/head/; revision=329576
* lua loader: Auto detect eligible list of kernels to bootConrad Meyer2018-02-181-1/+31
| | | | | | | | | Reviewed by: imp, kevans Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D14419 Notes: svn path=/head/; revision=329501
* stand/lua: Style passKyle Evans2018-02-171-8/+8
| | | | | | | | | | | | | These are the style points that I'd like to try and maintain in our lua scripts: - Parentheses around conditionals - Trailing semicolons, except on block terminators - s:method(...) instead of string.method(s, ...) where applicable There's likely more, but that'll get hammered out as we continue. Notes: svn path=/head/; revision=329435
* stand/lua: Correct usage and acceptance of BACKSPACE/DELETE keysKyle Evans2018-02-161-1/+2
| | | | Notes: svn path=/head/; revision=329386
* stand/lua: Remove sneaky kernel assignmentKyle Evans2018-02-161-1/+0
| | | | Notes: svn path=/head/; revision=329369