Commit Graph

319 Commits

Author SHA1 Message Date
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
82c85a42b4 liblua: Implement write support
Write support (even if it only works on UFS) will be needed for nextboot
functionality.

Reviewed by:	cem, imp
Differential Revision:	https://reviews.freebsd.org/D14478
2018-02-24 02:57:24 +00:00
Conrad Meyer
061577c5fe libsa: Change write(2)-alike prototype to match definition
Broken in r329879.

Apparently old GCC detects this, but modern GCC didn't.  Mea culpa.

Reported by:	np
Sponsored by:	Dell EMC Isilon
2018-02-24 01:58:53 +00:00
Conrad Meyer
2e7e6fbce5 libsa: Const-ify buffer argument of write(2) analog
Reported by:	kevans
Reviewed by:	delphij, eadler, imp, kevans
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D14482
2018-02-23 20:18:09 +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
Warner Losh
e52cfb3eff Floaty McFloatface is funnier...
Submitted by: emaste@
2018-02-23 04:06:15 +00:00
Warner Losh
ef1fcaf0f5 Do not include float interfaces when using libsa.
We don't support float in the boot loaders, so don't include
interfaces for float or double in systems headers. In addition, take
the unusual step of spiking double and float to prevent any more
accidental seepage.
2018-02-23 04:04:25 +00:00
Warner Losh
ff4cd9bfb1 Centralize lua defines
We need to ensure that we defined Numbers as int64_t everywhere we
build for lua. Previously, we were compiling part of the code with
Numbers as int64_t and part as double. Move lua number definition to a
more-central location
2018-02-23 04:04:03 +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
b0d9fbf070 Fix userboot w/ ZFS after r329725
r329725 cleaned up ZFS commands duplicated in multiple places, but userboot
was not setting HAVE_ZFS when MK_ZFS != "no". This resulted in a failure to
boot (as seen in PR 226118) in bhyve, with the following message:

/boot/userboot.so: Undefined symbol "ldi_get_size"

PR:		226118
Glanced at by:	imp
2018-02-22 18:49:53 +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
Marius Strobl
603fe87c56 Fix compilation with LOADER_DEBUG defined after r329725. 2018-02-21 22:24:49 +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
Ed Maste
6b6324985a load_elf.c: Use consistent indentation
As noted in D14267 load_elf.c has a variety of indentation styles.  Move
to standard 8 column hard tab indents, 4 space second level indents.
Also includes some whitespace cleanups found by clang-format.
2018-02-21 19:42:54 +00:00
Benno Rice
921b60da6f Further style(9) changes.
Tested by:	objdump -d | md5 (both in-tree clang and lang/gcc6)
2018-02-21 18:32:06 +00:00
Benno Rice
50d519d9fb Purely whitespace changes bringing this file closer to style(9).
Curiously, changing whitespace seems to cause the md5 of the .o files to differ
these days hence the following testing strategy:

Tested by:	objdump -d | md5 (both in-tree clang and lang/gcc6)
2018-02-21 18:10:50 +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
a39d359d85 stand/zfs: Unbreak build, 'truct' ~= 'struct' 2018-02-21 16:33:08 +00:00
Kyle Evans
97875f4aa9 stand/zfs: Add all bootenvs to environment
For the benefit of lualoader, add all bootenvs to environment when
init_zfs_bootenv is invoked. All of the boot environment logic can then be
implemented in pure lua, rather than going back and forth with C to
implement paging.

This stores all boot environments in bootenvs[idx] and the final count of
bootenvs in bootenvs_count.

While here, make a copy of currdev for init_zfs_bootenv since it will be
modifying it and the caller may not necessarily want that. Some of the logic
was shifted around so that the 'currdev' pointer remains at the beginning of
the string and 'beroot' is moved around as needed to modify it or ultimately
store it in zfs_be_root.

The original zfs_bootenv that this was copied from will be able to go away
only if/when forth eventually goes away.

Tested with:	lualoader (and local changes to add boot env. support)
Tested with:	forth
Reviewed by:	cem (earlier version), imp
Differential Revision:	https://reviews.freebsd.org/D14435
2018-02-21 16:26:16 +00:00
Warner Losh
8f46043b21 Honor settings for including / excluding cd9660, ufs, ext2fs and msdos.
The Makefile gives the impression that ext2fs and msdos were excluded
(they weren't) and that you could exclude cd9660 and ufs support (you
couldn't). Allow those to be excluded.

We need to look, in the future, at trimming the number of supported
filesystems, and this will make that easier.
2018-02-21 15:58:00 +00:00
Warner Losh
4784aef9f5 Consolidate three copies of ZFS commands into a central location.
There's no reason to have multiple copies of lszfs and
reloadbe. Consolidate them into one location. Also ldi_get_size is the
same everywhere (except sparc64). Make it the same everywhere as the
common definition is more general and will work on spar64.
2018-02-21 15:57:36 +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