Commit Graph

228 Commits

Author SHA1 Message Date
Kyle Evans
ca3b8c9fc4 lualoader: Fix name, cli.execute_unparsed -> cli_execute_unparsed 2018-03-07 18:28:41 +00:00
Kyle Evans
697f127dd6 lualoader: Expose loader.parse and add cli_execute_unparsed
This will be used for scenarios where the command to execute is coming in
via the environment (from, for example, loader.conf(5)) and is thus not
necessarily trusted.

cli_execute_unparsed will immediately be used for handling
module_{before,after,error} as well as menu_timeout_command. We still want
to offer these variables the ability to execute Lua-intercepted loader
commands, but we don't want them to be able to execute arbitrary Lua.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D14580
2018-03-07 18:25:27 +00:00
Kyle Evans
a2a7830eb1 lualoader: Only loadelf before boot/autoboot if no kernel loaded
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
2018-03-07 04:11:14 +00:00
Kyle Evans
15920907ba lualoader: Use FILESDIR instead of BINDIR
Minor nit: We're not installing binaries, we're installing scripts/files
that are documented to be installed based on FILESDIR.
2018-03-05 01:18:32 +00:00
Kyle Evans
ee15e552d0 lualoader: Add note about importance of including the cli module early 2018-03-05 00:59:55 +00:00
Kyle Evans
2ed9eb5dae lualoader: logdef -> logodef typo 2018-03-04 03:23:19 +00:00
Kyle Evans
c6d9f133b3 lualoader: Return meaningful value in cli_execute
loader.command(...) will return whatever the executed function returns, so
follow suit and return whatever loader.command() returned or whatever the
Lua function returns.
2018-03-04 03:21:12 +00:00
Kyle Evans
2d36799a7e lualoader: Shift menu+brand even for logo=none with customized pos 2018-03-03 18:25:50 +00:00
Kyle Evans
1495c98f0b lualoader: Tweak positioning and fix an off-by-one
- All of our default positions were offset from forth
- Our menu frame size was smaller than in forth
- Logo/brand drawing had an off-by-one, drawing one column lower on the
  screen than they should have been.
- While here, switch a print() to printc() as it's expected that logos may
  contain color and other escpae sequences that we'll need to honor.
2018-03-03 18:13:14 +00:00
Kyle Evans
b435332653 lualoader: Respect loader_menu_title_align
It may be set to "left" or "right" -- any other value will cause the title
to be centered.

I've chosen to position these things just inside the vertical borders,
rather than overlapping the corners. This is an arbitrary choice and easily
amendable if this looks terrible.
2018-03-03 17:38:25 +00:00
Kyle Evans
953d8937d5 lualoader: Respect loader_menu_title, prepare for align 2018-03-03 17:25:49 +00:00
Kyle Evans
a76f8a5bc2 lualoader: Execute menu_timeout_command at the end of menu autoboot
Instead of hardcoding "boot", respect menu_timeout_command from Forth. It
still defaults to 'boot', so this will not be a functional change for most.
2018-03-03 17:18:40 +00:00
Kyle Evans
decacd9170 lualoader: Reset the cursor position after the menu is drawn
Rather than before the menu is drawn. The drawer is going to reset the
crusor position as soon as it draws anything anyways, so doing it before
serves no purpose. Setting it after is needed so we don't clobber the menu
when we start booting.
2018-03-02 17:07:08 +00:00
Kyle Evans
223e9874b6 lualoader: Use global printc instead of loader.printc
r330282 registered loader.printc as printc, so use it instead. This makes
sense for a couple reasons, the major point being that it reads a little bit
easier and pairs nicely with the global 'print'.

Similar cases can not really be made for other loader.* functions as most of
them are either highly specific to our use-case or usually available in
other modules, such as `os`. printc does not have a standard implementation
in the Lua world(*), so we have a little more leeway with it, and it's kind
of a special case of the globally available 'print'.

(*) I've been in the Lua world for all of two weeks, so this could be wrong.
2018-03-02 16:06:20 +00:00
Kyle Evans
379e652e1b lualoader: Steamroll the box-drawing
- Add drawer.frame_styles to map out the kinds of characters we need for the
  different loader_menu_frame values
- Respect loader_menu_frame, default to double[*]
- (imp) Use loader.printc instead of print- print adds a newline to the
  output, which is not the right thing we want to be doing.
- (imp) Draw horizontal frames a little more efficiently- setting the cursor
  after every line segment is horribly inefficient, especially on serial
  consoles. Halve the number of characters written at the expense of an
  additional loop to draw the bottom frame, which is likely more efficient
  in the long run for some of less ideal scenarios.

[*] menu.4th(8) claims that the default here was single, but unset
loader_menu_frame yielded double and we didn't have any overrides in the
default loader.conf(5), so double it is.
2018-03-02 15:28:08 +00:00
Kyle Evans
9eded7f476 core.lua(8): Add missing note about core.KEYSTR_CSI 2018-03-02 05:38:08 +00:00
Kyle Evans
f520b4afd2 Add menu.lua(8), but do not add to distribution
Distribution will be done after all of the lualoader manpages are created.

Reviewed by:	rpokala
Differential Revision:	https://reviews.freebsd.org/D14480
2018-03-02 05:36:04 +00:00
Kyle Evans
913bd09810 Add core.lua(8), but do not add to distribution
Distribution will be done after all of the lualoader manpages are created.

Reviewed by:	rpokala
Differential Revision:	https://reviews.freebsd.org/D14479
2018-03-02 05:35:14 +00:00
Kyle Evans
972c7fcd3f lualoader: Use string literal \xNN instead of string.char() 2018-03-02 03:05:36 +00:00
Kyle Evans
cb4fbe4ebb lualoader: Use #str instead of tracking length with 'n'
We really gain almost nothing by tracking length separately, especially when
it's as easy as "#str", so reduce complexity.
2018-03-02 02:39:41 +00:00
Kyle Evans
2f3ecc87bf lualoader: Fix some lint-mentioned errors
- nextbootfile is not a variable, but nextboot_file is
- pstatus was explicitly initialized but later clobbered, so don't
  initialize it.
2018-03-02 02:39:16 +00:00
Kyle Evans
fdabb5f55e lualoader: config: Pull some messages out into constants
Rather than hardcoding these things. This could lead to some form of loader
localization later, but the main goal at the moment is to get a clear view
of the strings we're outputting and strive to use more string.format() and
less wild concatenation all over the place.
2018-03-01 02:31:28 +00:00
Kyle Evans
43f7d9d1b2 lualoader: Dedup these "Return to main menu" entries 2018-03-01 02:04:26 +00:00
Kyle Evans
230061c53d lualoader: Add note that \027 is a decimal representation
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).
2018-02-28 05:11:10 +00:00
Kyle Evans
eda2d36b18 lualoader: Remove debug function
Our module bits ended up more stable than I anticipated, so this turns out
to be no longer useful.

If things like this need to come back, we should do it in a separate 'debug'
module to serve as a collection of debugging aides. As a rule, this 'debug'
module would *not* be allowed as a requirement of any other modules in-tree.
2018-02-28 05:02:05 +00:00
Kyle Evans
ed1d0954ca lualoader: Further screen cleanup
- Add screen.default_x and screen.default_y to determine where
  screen.defcursor resets the cursor to.
- Use screen.setcursor in screen.defcursor instead of rewriting the escape
  sequence.
- Use screen.default_y when resetting the cursor after writing the new
  twiddle character, add a comment verbally describing the position just in
  case.
2018-02-28 04:31:19 +00:00
Kyle Evans
0901ba3aa1 lualoader: Re-do twiddle
It worked on my test setup, but is clearly non-functional on others.

Further examination of check-password.4th showed that it actually reset the
cursor to 0,25 every time and overwrote the previous password prompt. Do
that, and also clear the "Incorrect Password" text if the correct password
gets entered.
2018-02-28 04:23:28 +00:00
Kyle Evans
fb7275bedb lualoader: Correct test sense, comments, and add some more comments 2018-02-27 22:07:41 +00:00
Kyle Evans
2bb86aefec lualoader: Convert instances of KEYSTR_ESCAPE .. "[" -> KEYSTR_CSI 2018-02-27 22:02:39 +00:00
Kyle Evans
d5b2439e5d lualoader: Replace instances of \027 with KEYSTR_ESCAPE
With exception to drawing bits, which should probably be kept as-is to not
make a mess out of things.

Reported by:	rpokala (a while ago)
2018-02-27 21:52:22 +00:00
Kyle Evans
8620ae0187 lualoader: Remove remnants of testing...
twiddle_pos didn't need to be a module-scope local, since it's going to get
reset with every read anyways- it was left-over from other things.

screen.movecursor with a y=-1 setting was from a test of movecursor,
resulting in the twiddle characters being drawn going up the console and
looking quite funky.
2018-02-27 21:30:24 +00:00
Kyle Evans
a6f1506f1a lualoader: Add a twiddle at password prompt
This gives some form of feedback while typing, and matches-(ish*) Forth
behavior. The cursor generally rests two column after the password prompt,
then the twiddle is drawn three columns later and the cursor reset to
resting position after being drawn.

I've removed the note about re-evaluating it for security considerations and
instead set it up as a module-local variable that we can set later depending
on environment or something. It's set to false with no chance of changing at
the moment.

*As close as I can tell from reading check-password.4th, because I don't
have an easy test (or deployed) setup for forth loader to check how close
it is. Please do mention if it's not close enough.
2018-02-27 21:22:57 +00:00
Kyle Evans
9937e97979 lualoader: Re-work menu skipping bits
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.
2018-02-26 15:37:32 +00:00
Kyle Evans
5495d73c35 lualoader: screen argument fixes
screen was also guilty of not-so-great argument names, but it was also
guilty of handling color sequences on its own. Change those bits to using
the color module instead.

As a side note, between color and screen, I'm not 100% sure that returning
the color_value is the right thing to do if we won't generate the escape
sequences. This should be re-evaluated at a later time, and they should
likely return nil instead.
2018-02-26 04:12:54 +00:00
Kyle Evans
04af422907 lualoader: More argument name expansion, part 2
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.
2018-02-26 04:08:54 +00:00
Kyle Evans
2a11b81090 lualoader: A little more general menu cleanup
Instead of a single-letter parameter ('m'), use something a little more
descriptive and meaningful: 'menudef' ("menu definition") -- these functions
expect to be passed a menudef, so call it what it is.

While here, throw an assertion in that we have a handler for the selected
menu item. This is more of a debugging aide so that it's more obvious when
one is testing a menudef that they've added an entry item that we don't
handle.

This is an improvement over the past behavior of ignoring the unknown menu
entry.
2018-02-26 03:46:17 +00:00
Kyle Evans
beafe96147 lualoader: Track the menu currently drawn, instead of validity
This cleans up the odd approach to menu drawing. Instead of tracking
validity, we track the menu that was drawn on the screen. Whenever we draw a
menu, we'll set this to that menu.

Anything that invalidates the screen should go ahead and trigger an explicit
redraw, rather than finding a wy to set screen_invalid.

The currently drawn menu is then reset in menu.run as we exit the menu
system, so that dropping to the loader prompt or leaving menu.run() will
just behave as expected without doing redundant work every time we leave a
menu.
2018-02-25 17:02:50 +00:00
Kyle Evans
fe226a72cb lualoader: Invalidate the screen from menu perspective upon mnu exit
In the common case, this will effectively do nothing as the menu will get
redrawn as we leave submenus regardless of whether the screen has been
marked invalid or not

However, upon escape to the loader prompt, one could do either of the
following to re-enter the menu system:

-- Method 1
require('menu').run()

-- Method 2
require('menu').process(menu.default)

With method 1, the menu will get redrawn anyways as we do this before
autoboot checking upon entry. With method 2, however, the menu will not be
redrawn without this invalidation.

Both methods are acceptable for re-entering the menu system, although the
latter method in the local module for processing new and interesting menus
is more expected.
2018-02-25 16:29:02 +00:00
Kyle Evans
22ae8ae1f4 lualoader: Explain deviation from naming guidelines
cli_execute is likely the only exception that we should make, due to it
being a global. We don't really need other globals, so this won't really end
up an epidemic.
2018-02-25 05:14:06 +00:00
Kyle Evans
ca16d83fd4 lualoader: Pull autoboot handling out into menu.run()
There's no reason for autoboot handling to be mixed in with menu processing.
It is a distinct process that should only be done once when entering the
menu system.

menu.process has been modified to take an initial keypress to process and to
only draw the screen initially if it's been invalidated. The keypress is
kind of a kludge, although it could be argued to be a potentially useful
kludge if there are other processes that may need to feed a keypress into
the menu system.
2018-02-25 05:00:54 +00:00
Kyle Evans
28384160a7 lualoader: Pull menu redrawing specifics out of menu.process
In general, every menu redraw is going to require a screen clear and cursor
reset. Each redraw also has the potential to invalidate the alias table, so
we move the alias table being used out into a module variable. This allows
third party consumers to also inspect or update the alias table if they need
to.

While here, stop searching the alias table once we've found a match.
2018-02-25 04:44:45 +00:00
Kyle Evans
da9ab82706 lualoader: Clean up menu handling a little bit
This is driven by an urge to separate out the bits that really only need to
happen when the menu system starts up. Key points:

- menu.process now does the bulk of menu handling. It retains autoboot
  handling for dubious reasons, and it no longer accepts a 'nil' menu to
  process as 'the default'. Its return value is insignificant.
- The MENU_SUBMENU handler now returns nothing. If menu.process has exited,
  then we continue processing menu items on the parent menu as expected.
- menu.run is now the entry point of the menu system. It checks whether the
  menu should be skipped, processes the default menu, then returns.
2018-02-25 04:11:08 +00:00
Kyle Evans
3cd5547b1b lualoader: menu: Terminate final values in tables with a comma 2018-02-25 03:33:25 +00:00
Kyle Evans
e1a8835aa8 lualoader: Don't explicitly index tables without reason
These indices were assigned the same values as they would've been implicitly
assigned anyways.

While here, throw terminating commas after the last value of tables.
2018-02-25 03:30:24 +00:00
Kyle Evans
67eae5035b lualoader: Remove inaccurate part of comment 2018-02-24 20:24:57 +00:00
Kyle Evans
322a2dddba lualoader: Clean up naming conventions a little bit
We mostly use camel case for function names, but some local functions got
mixed in using internal underscores. Doubles down on camel case.
2018-02-24 20:21:21 +00:00
Kyle Evans
ddfae7e314 lualoader: throw out nextboot's usage of standard config processing
It should use the common parser, but it should not be processed like a
standard file. Rewite check_nextboot to read the file in, check whether it
should continue, then parse as needed.

This allows us to throw the recently introduced check_and_halt callback
swiftly out the window.
2018-02-24 20:07:39 +00:00
Kyle Evans
4adde50db2 lualoader: Strip config.parse of its I/O privileges
config.parse is now purely a parser, rather than a whole proccessor. The
standard process for loading a config file has been split out into
config.processFile.

This clears the way for having nextboot read its own config file and decide
there whether it should parse the rest of the file.
2018-02-24 20:00:31 +00:00
Kyle Evans
164b58fdd3 lualoader: Split config file I/O out into a separate function
This is step 1 towards revoking config.parse of it I/O privileges. Ideally,
all reading would be done before config.parse and config.parse would just
take text and parse it rather than being charged with the entire process.
2018-02-24 19:51:18 +00:00
Kyle Evans
eed91cae68 lualoader: Explain nextboot stuff a little bit more 2018-02-24 04:02:06 +00:00
Kyle Evans
d709f254c2 lualoader: Remove unused variable; we now use the effective line number 2018-02-24 03:48:52 +00:00
Kyle Evans
d930cdc295 lualoader: Add comment on trailing space, don't operate on nil
Functionally, the latter error wouldn't necessarily hurt anything. io.write
will just error out as it's not passed a valid file handle. Still, we can do
better than that.
2018-02-24 03:47:04 +00:00
Kyle Evans
483f0a33f3 lualoader: Correct test and name
The functionality was correct, but our style guidelines tend to request that
we shy away from using boolean operations in place of explicit comparisons
to nil.
2018-02-24 03:43:10 +00:00
Kyle Evans
e83d7bf208 lualoader: Plug file handle not properly closed 2018-02-24 03:38:51 +00:00
Kyle Evans
3dcb764877 lualoader: Add nextboot support
config.parse now takes an extra callback that is invoked on the full text of
the config file. This callback dictates where we should actually try to
parse this file or not.

For nextboot, we use this to halt parsing if we see 'nextboot_enable="NO"'.
If we don't, parse it and write 'nextboot_enable="NO" ' to it. The same
caveat as with forth still applies- writing is only supported by UFS.
2018-02-24 03:35:35 +00:00
Kyle Evans
1afbc37a1f lualoader: Track effective line number, use it for drawing
Takes into account hidden entries, so that we don't draw blank lines in
place of a hidden item.
2018-02-23 04:12:19 +00:00
Kyle Evans
9ed6f9efda lualoader: Use "local function x()" instead of "local x = function()"
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.
2018-02-23 04:03:07 +00:00
Kyle Evans
ee4e69f1b9 lualoader: shallowCopyTable => deepCopyTable
I called it a shallow copy, but it wasn't really a shallow copy at all.
2018-02-23 03:18:24 +00:00
Kyle Evans
beaafe4f86 Add copyright notice to core.lua
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.
2018-02-23 02:53:50 +00:00
Kyle Evans
72e39d711d Add SPDX tags to lua files 2018-02-23 02:51:35 +00:00
Kyle Evans
5144243aca lualoader: Drop unused return values; we'll only use the first 2018-02-23 02:47:51 +00:00
Kyle Evans
66964bbc36 lualoader: Attend to some 80-col issues, pointed out by luacheck
Graphics have a tendency to cause 80-col issues, so make an exception to our
standard indentation guidelines for these graphics. This does not hamper
readability too badly.

Two 40-column strings of spaces is trivially replaced with
string.rep(" ", 80)
2018-02-22 20:10:23 +00:00
Kyle Evans
3c6b387ad1 lualoader: Clear up an empty conditional branch
We will likely uncomment this whole monster in the near future.
2018-02-22 04:30:52 +00:00
Kyle Evans
e2df27e363 lualoader: Address some 'luacheck' concerns
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.
2018-02-22 04:15:02 +00:00
Kyle Evans
011eae6c57 lualoader: Consistently use double quotes 2018-02-22 03:55:02 +00:00
Kyle Evans
4ab039b57f lualoader: Eliminate some unused locals 2018-02-22 03:53:49 +00:00
Kyle Evans
2e4dad82c7 lualoader: Attach cli command functions to cli module
Instead of the global namespace, let's attach these to the cli module. Other
users, including the "local" module, can attach functions to the cli module
at will to add other cli commands and things will still Just Work.

This distills down the candidates for functions that may be invoked via the
cli to a minimal set (boot, autoboot, arguments), rather than any function
that happens to live in the global lua namespace.
2018-02-22 01:57:38 +00:00
Kyle Evans
eca5ca66d0 lualoader: Pull argument extraction for cli functions into cli.arguments
This will be the translation layer for varargs -> cmd_name, argv for cli
commands. We reserve the right to break exactly what the varargs inclulde,
but this gives us a stable way to pull the arguments out of varargs.
2018-02-22 01:44:30 +00:00
Kyle Evans
3e6c7d5436 lualoader: Unbreak 'boot [kernel]' by including config 2018-02-22 01:31:05 +00:00
Kyle Evans
e37f4622df lualoader: Split cli bits out into a cli module
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.
2018-02-22 01:21:39 +00:00
Kyle Evans
1ea2995427 lualoader: Remove nasty hack for not printing out ".0"
luaconf.h has a LUA_COMPAT_FLOATSTRING option that may be defined to do this
instead of needing intstring.

Reported by:	Dan Nelson
2018-02-21 21:39:47 +00:00
Kyle Evans
a5e2e5c724 lualoader: Drop password length restrictions
This seems to have been arbitrary; bootlock_password and password don't seem
to have any documented length restrictions, and loader(8) probably shouldn't
care about whatever GELI passphrase length restrictions might exist.

Reported by:	Kalle Carlbark <kalle.carlbark+freebsd@kcbark.net>
2018-02-21 20:17:08 +00:00
Kyle Evans
1f6c6d86e0 lualoader: Replace 8-space indentation with a single tab 2018-02-21 19:56:34 +00:00
Kyle Evans
7dcffa9042 lualoader: Don't execute menu.autoboot() for every opened menu
Attempt to autoboot when we open the default menu, and only when we open the
default menu. This alleviates the need for checking menu.already_autoboot,
because we're not trying to autoboot every time we open a submenu.

I note that escaping to loader prompt and going back to the menu (by running
require('menu').run() at the loader prompt) will happily work and not
re-initiate the autoboot sequence since "Escape to loader prompt" disables
the autoboot_delay.
2018-02-21 17:33:01 +00:00
Kyle Evans
3889e6cd04 lualoader: Make kernel autodetection contingent on loader.conf(5) var
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'.
2018-02-21 16:57:03 +00:00
Kyle Evans
7efc058f76 lualoader: Add boot environment support
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
2018-02-21 16:50:41 +00:00
Kyle Evans
12b95c8489 lualoader: Use the key that interrupts autoboot as a menu choice
This matches forth behavior. Hitting "6" when autobooting at the welcome
menu will now take you directly to the "Boot Options" menu.

We likely have some slight optimizations we should make, like not checking
autoboot every time we open a new menu and things of this nature. Further
work will go towards this end.
2018-02-21 14:37:49 +00:00
Kyle Evans
3f4eb56bde lualoader: Don't autodetect kernels if 'kernels' is explicitly set 2018-02-21 14:07:53 +00:00
Kyle Evans
4f437f9eab lualoader: Allow carousel 'items' to be a table as well as a function
We don't have any in-tree users of this, but for a static set of carousel
options having to define a callback is excessive.
2018-02-21 05:04:58 +00:00
Kyle Evans
a51f9f0c48 lualoader: Simplify menu definitions a little further
Allow "name" entries to be simple strings, instead of just functions. We
know whether we support colors or not by the time any of this is setup, so
all menu names that are basically static with colors sprinkled in are good
candidates for simplification.

Also simplify "func" in many cases where it's just invoking another function
with no arguments. The downside to this simplification is that the functions
called can no longer be trivially replaced by a local module. The upside is
that it removes another layer of indirection that we likely don't need.

These can be re-evaluated later if a compelling argument is raised, on a
case-by-case basis, for replacement.
2018-02-21 04:48:37 +00:00
Kyle Evans
9a28f948ee lualoader: Directly reference submenu definition with submenu key 2018-02-21 04:23:13 +00:00
Kyle Evans
dd65496a04 lualoader: Drop name requirement for menu separators 2018-02-21 04:14:32 +00:00
Kyle Evans
20a8167664 lualoader: Add "menu.default", initialized to menu.welcome
The intent here is to abstract away the name of the default menu. The
default menu is still the welcome menu, but this detail doesn't need to
matter to things outside of the menu module. You may change the default
menu, but one would need to modify a specific menu.
2018-02-21 03:37:46 +00:00
Kyle Evans
1d38e553eb lualoader: Return only argstr if with_kernel not requested 2018-02-21 03:06:36 +00:00
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
Kyle Evans
c1ab36f54d lualoader: Ignore ACPI bits on !i386 2018-02-20 19:21:34 +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