Commit Graph

271 Commits

Author SHA1 Message Date
Kyle Evans
48230b85ac lualoader: Bring in local.lua module if it exists
Provide a way for out-of-tree users of lualoader to patch into the loader
system without having to modify our distributed scripts.

Do note that we can't really offer any API compatibility guarantees at this
time due to the evolving nature of lualoader right now.

This still has some utility as local modules may add commands at the loader
prompt without relying heavily on lualoader features- this specific
functionality is less likely to change without more careful consideration.

Reviewed by:	cem (earlier version)
Differential Revision:	https://reviews.freebsd.org/D14439
2018-02-21 02:35:13 +00:00
Kyle Evans
d66c741396 lualoader: Output "Failed to parse" messages
I can't find any good reason these aren't enabled, so enable them.

The silent runs will only return false on actual parse errors, so it's ok to
be loud about those failures.
2018-02-21 01:52:42 +00:00
Kyle Evans
062d62c9b3 lualoader: Don't return false for failure to open config on silent parse 2018-02-21 01:50:46 +00:00
Kyle Evans
4955048946 lualoader: Drop explicit boolean tests; b or not b 2018-02-21 01:39:33 +00:00
Kyle Evans
9f71d421c8 lualoader: Drop excessive parenthesizing
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.
2018-02-21 01:35:19 +00:00
Kyle Evans
aedd6be5c7 lualoader: Drop terminating semicolons
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.
2018-02-21 01:10:03 +00:00
Kyle Evans
e73c944fc0 lualoader: When restoring environment, only restore unchanged vars
Track the latest value we've set an environment variable to, and only
restore those that are unchanged from that.

This gives us some leeway to make sure we're not clobbering variables
overwritten by menu changes.
2018-02-20 22:47:49 +00:00
Kyle Evans
6d3bcc06e2 lualoader: Intercept the 'autoboot' cli command 2018-02-20 21:37:55 +00:00
Kyle Evans
f0cb3b6b25 lualoader: Intercept boot cli command
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.
2018-02-20 21:32:36 +00:00
Kyle Evans
6d4ed94d98 lualoader: Prepare for interception of "boot" CLI cmd
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.
2018-02-20 21:23:01 +00:00
Kyle Evans
df9e50a99c lualoader: Don't try so hard to load a kernel
If the user's selected a kernel, we really should be trying to load that one
instead of falling back to some default kernel.

This should generally be a no-op and most desirable, unless you really
enjoyed surprises.
2018-02-20 21:15:43 +00:00
Kyle Evans
ebddeb04e2 lualoader: Prefer selected kernel to currently loaded 2018-02-20 21:13:21 +00:00
Kyle Evans
62daefa548 lualoader: Replace invalid construct with valid construct
It only worked by coincidence, but it did work. Store varargs in a table
instead and work off of that.
2018-02-20 20:29:41 +00:00
Conrad Meyer
f91f3926e0 loader.lua: Expose errno table to lua
Reviewed by:	kevans
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D14454
2018-02-20 19:39:48 +00:00
Kyle Evans
c1ab36f54d lualoader: Ignore ACPI bits on !i386 2018-02-20 19:21:34 +00:00
Kyle Evans
2630b89b56 liblua: Add loader.machine and loader.machine_arch properties
Provisioned from MACHINE/MACHINE_ARCH on the system, expose loader.machine
and loader.machine_arch respectively.

These may be used to hide ACPI option on non-applicable archs.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D14446
2018-02-20 18:24:20 +00:00
Conrad Meyer
f2b32f473e Lua lfs.attributes: Provide a more consistent error return
In the remaining error case, return a 3-tuple consistent with the other
error return case.

Document how to invoke lfs.attributes() and detect/decode error return in
example comments.

Reviewed by:	kevans
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D14451
2018-02-20 18:21:30 +00:00
Kyle Evans
2765f3ac26 lualoader: Eliminate global namespace pollution in loader.lua 2018-02-20 18:05:21 +00:00
Kyle Evans
25c4c7a5f3 lualoader: Move carousel storage out into config
Carousel storage doesn't need to happen in the menu module, and indeed
storing it there introduces a circular reference between drawer and menu
that only works because of global pollution in loader.lua.

Carousel choices generally map to config entries anyways, making it as good
of place as any to store these. Move {get,set}CarouselIndex functionality
out into config so that drawer and menu may both use it. If we had more
carousel functionality, it might make sense to create a carousel module, but
this is not the case.
2018-02-20 18:04:08 +00:00
Kyle Evans
afad05b233 lualoader: Add ability to intercept cli commands
If we failed to execute the input line as pure lua, run the command through
parse for consistent argument parsing. Pass the parsed arguments through to
a global "cli_execute" written in Lua, which is expected to either handle it
or pass it back through to interp_builtin_cmd (via loader.command).

lua-handled cli commands will then exist as globals in whatever module they
most belong in, and invocations at the loader prompt will magically dispatch
to them if they exist.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D14450
2018-02-20 17:46:50 +00:00
Warner Losh
a83546e591 Implement loader.command
This is just like loader.perform, except it takes pre-parsed arguments.

Review: https://reviews.freebsd.org/D14448
2018-02-20 17:28:59 +00:00
Kyle Evans
b57465454b stand/lua: Consistently organize modules
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.
2018-02-20 14:45:58 +00:00
Kyle Evans
e15abd1f16 stand/lua: Consistently declare local functions at module scope
Declare these adjacent to the local definitions at the top of the module,
and make sure they're actually declared local to pollute global namespace a
little bit less.
2018-02-20 14:36:28 +00:00
Kyle Evans
699578a6b8 stand/lua: Insert helpful comment for drawer.branddefs 2018-02-20 05:12:39 +00:00
Kyle Evans
df74a61f09 stand/lua: Stick a copyright notice on drawer.lua 2018-02-20 05:11:17 +00:00
Kyle Evans
752b2d40e4 stand/lua: Use 'graphic' instead of 'logo' for table depicting graphics
This is a more sensible name that offers less redundancy when referring to
it (vs. logodef.logo). Switch to it while the getting is good.
2018-02-20 05:10:26 +00:00
Kyle Evans
29aa5794d0 stand/lua: Refactor brands into drawer.branddefs 2018-02-20 05:06:11 +00:00
Kyle Evans
bb26c57ded stand/lua: Refactor logos into drawer.logodefs table
This refactor makes it straightforward to add new logos for drawing and
organizes logo definitions in a logical manner.

The graphic to be drawn for each logo may again be modified outside of
drawer, but it must be done on a case-by-case basis as a modification to the
loader_logo.
2018-02-20 04:56:03 +00:00
Kyle Evans
02122e53a8 stand/lua: Reduce exposure of the drawer module
As part of an effort to slowly reduce our exports overall to a set of stable
properties/functions, go ahead and reduce what drawer exposes to others.

The graphics should generally not be modified on their own, but their
position could be modified if additional grahics also need to be drawn.
Export position/shift information, but leave the actual graphic local to
the module.

The next step will be to create a 'menudef' that gets exported instead, with
each entry in the menudef table describing the graphic to be drawn along
with specific positioning information.
2018-02-20 04:23:43 +00:00
Kyle Evans
da56fe38d5 stand/lua: Move drawer.menu_name_handlers further up
As a good candidate for modification, move this table further up in the
module to improve visibility.
2018-02-20 04:11:48 +00:00
Kyle Evans
2413c411f8 stand/lua: Add and use drawer.menu_name_handlers
Pull out specialized naming behavior into drawer.menu_name_handlers. This is
currently only needed for the carousel entry, where naming is based on the
current choice and the menu item purposefully does not store this state.

The setup was designed so that every type can have a special name handler,
and the default action is to simply use the result of entry.name().
2018-02-20 03:58:45 +00:00
Kyle Evans
8d415029e1 stand/lua: Extract menu handlers out into menu.handlers table
This is a bit cleaner than our former method of an if ... else chain of
handlers. Store handlers in the menu.handlers table so that they may be
added to or removed dynamically.

All handlers take the current menu and selected entry as parameters, and
their return value indicates whether the menu processor should continue or
not. An omitted return value or 'true' will indicate that we should
continue, while returning 'false' will indicate that we should exit the
current menu.

The omitted return value behavior is due to continuing the loop being the
more common situation.
2018-02-20 03:40:16 +00:00
Kyle Evans
6f412147b2 stand/lua: Don't set ACPI off just because we can't detect it.
This should unbreak EFI/!i386 cases.

Reported by:	Peter Lei <peter.lei@ieee.org>
2018-02-20 02:03:29 +00:00
Kyle Evans
4b6da14cfa stand/lua: Wrap tuple assignment earlier for readability 2018-02-19 22:56:04 +00:00
Kyle Evans
9a0904b0e0 stand/lua: Cache swapped menu, and don't create locals for swapping
Building the swapped welcome menu (first two items swapped) is kind of a
sluggish, because it requires a full (recrusive) shallow copy of the welcome
menu. Cache the result of that and re-use it later, instead of building it
everytime.

While here, don't create temporary locals just for swapping. The following
is just as good:

x, y = y, x;

Reported by:	Alexander Nasonov <alnsn@yandex.ru> (swapping)
2018-02-19 22:29:16 +00:00
Kyle Evans
21d5bcbe67 stand/lua: Add copyright notice in places
I've made some not-insignificant changes to config, menu, and password bits
of our lua scripts. Add a copyright notice to them to reflect.
2018-02-19 18:11:35 +00:00
Kyle Evans
c851839897 stand/lua: Re-order locals after copyright notice; require comes first 2018-02-19 17:54:22 +00:00
Kyle Evans
1f5696c7fd stand/lua: Round up some more style.lua(9) concerns 2018-02-19 17:51:33 +00:00
Kyle Evans
5c1b516581 stand/lua: Change boot menu items' names when swapped
[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.
2018-02-19 17:40:19 +00:00
Kyle Evans
e6db469bfa stand/lua: Remove inaccurate comment after r329590
lualoader does a pretty good job of reverting any environment changes now.
It will even wipe out boot_verbose if it's set explicitly in loader.conf(5)
and overwritten in the boot options menu.

Future work will likely change this, as explicit choices made in the menu
should probably override the new loader.conf(5). I don't suspect this will
cause much grief, though, so it is not a high priority until boot
environment support actually lands.
2018-02-19 17:09:29 +00:00
Kyle Evans
ce4a5da5a9 stand/lua: Restore environment upon config reload
This restores environment to whatever defaults we had coming into lualoader.
2018-02-19 17:01:21 +00:00
Kyle Evans
df8a9d464a stand/lua: Track env changes that come in via loader.conf(5)
This will be used when boot environment support lands to make a good-faith
effort to apply any new loader.conf(5) environment settings atop the default
configuration that we started with.
2018-02-19 16:59:28 +00:00
Kyle Evans
fd2b19b3ee stand/lua: Re-wrap menu.lua now that I've added indentation... 2018-02-19 16:42:06 +00:00
Kyle Evans
303253e55c stand/lua: Swap single-/multi- user boot entries as needed 2018-02-19 16:36:29 +00:00
Kyle Evans
2e716cec23 stand/lua: Call menu_entries if it's a function
If we've fetched menu.entries and it turns out it's a function, call it to
get the actual menu entries.

This will be used to swap multi-/single- user boot options if we're booting
single user by default (boot_single="YES" in loader.conf(5)). It can also be
used fairly easily for other non-standard situations.
2018-02-19 16:35:46 +00:00
Kyle Evans
e07fc39c14 stand/lua: Add core.isSingleUserBoot 2018-02-19 16:34:23 +00:00
Kyle Evans
d87577468f stand/lua: Store menu entries in an "entries" table
Instead of directly listing them in menu.welcome and menu.boot_options,
store them at menu.welcome.entries and welcome.boot_options.entries.

This will come into play later when we need to re-order the welcome menu if
boot_single is specified.
2018-02-19 16:25:43 +00:00
Kyle Evans
280e990ba7 stand/lua: Remove some unused local declarations
Menus are actually defined as entries in the 'menu' table. These local
declarations have not been used in the history of our in-tree lua scripts,
so give them the boot.
2018-02-19 15:49:27 +00:00
Kyle Evans
57099121d5 stand/lua: Menu style.lua(9) nits 2018-02-19 15:47:09 +00:00
Kyle Evans
b140d14b02 stand/lua: Rename bootserial for clarity 2018-02-19 15:42:20 +00:00