petitboot
6 years agodiscover/udev: Register udev monitor before enumerating devices
Jeremy Kerr [Fri, 7 Mar 2014 05:46:49 +0000 (13:46 +0800)]
discover/udev: Register udev monitor before enumerating devices

Currently, we enumerate udev devices before setting up our monitor. This
means that we may lose devices that udev discovers after we start the
enumeration, but before the monitor is registered.

This change enables the monitor before enumeration, so we don't lose
devices. We add a filter to the enumeration code to only parse
completely initialised devices.

This means we may need to handle change events as the main source of
device notifications. We keep the existing CDROM event handler, but
check for new devices and handle those as an add.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: Print error message on mount failure
Jeremy Kerr [Fri, 7 Mar 2014 01:10:16 +0000 (09:10 +0800)]
discover: Print error message on mount failure

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: don't retry mount without ro option
Jeremy Kerr [Fri, 7 Mar 2014 01:05:00 +0000 (09:05 +0800)]
discover: don't retry mount without ro option

Currently, if the read-only mount fails during device discovery, we
retry without the '-o ro' option. This was originally due to the
read-only mount failing when a device was already mounted elsewhere.

Since we check for exsiting mounts now, we can drop this retry.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: fix return value for discover_device_get_param
Jeremy Kerr [Thu, 6 Mar 2014 10:14:00 +0000 (18:14 +0800)]
discover: fix return value for discover_device_get_param

We're incorrectly returning the name, we need the value.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/udev: Separate block-specific udev discovery
Jeremy Kerr [Wed, 5 Mar 2014 02:19:55 +0000 (10:19 +0800)]
discover/udev: Separate block-specific udev discovery

We'd like to trigger network device discovery from udev code, but most
of the device_add code path assumes block devices.

This change adds a subsystem check, and moves the block-specific code to
udev_handle_block_add.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Ensure that the selected menu item is visible
Jeremy Kerr [Mon, 3 Mar 2014 10:15:31 +0000 (18:15 +0800)]
ui/ncurses: Ensure that the selected menu item is visible

When adding new items to the petitboot menu, we need to ensure that the
scroll position of the menu includes the currently-selected item.

This change adds a call to set_top_row, calculated from the selected
item index, and the number of rows in the menu.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotest/parser: Add pxe discovery tests
Jeremy Kerr [Thu, 27 Feb 2014 08:52:20 +0000 (16:52 +0800)]
test/parser: Add pxe discovery tests

Add tests to cover pxlinux-style configuration autodiscovery.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/pxe: pxe parser should only treat "::" paths as absolute
Jeremy Kerr [Thu, 27 Feb 2014 05:54:32 +0000 (13:54 +0800)]
discover/pxe: pxe parser should only treat "::" paths as absolute

PXELinux treats all paths as relative, requiring a "::/path" syntax for
truly absolute URLs.

This change implements the same behaviour in petitboot, and updates the
testcases to suit.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/pxe: Fix prefix autodetection when bootfile is in the root dir
Jeremy Kerr [Thu, 27 Feb 2014 03:39:41 +0000 (11:39 +0800)]
discover/pxe: Fix prefix autodetection when bootfile is in the root dir

Currently, if the bootfile doesn't contain a directory, the path we use
for config file resolution will use the bootfile as the first component
of path.

For example, if bootfile is:

  pxelinux.0

the config files requested will be:

  pxelinux.0/<mac>
  pxelinux.0/<ips>
  pxelinux.0/default

For cases where bootfile is a single file, we need to use a blank
prefix.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/pxe: Add pxelinux.cfg/ directory to autodiscovered pxe paths
Jeremy Kerr [Thu, 27 Feb 2014 02:33:13 +0000 (10:33 +0800)]
discover/pxe: Add pxelinux.cfg/ directory to autodiscovered pxe paths

The pxelinux project will perform autodiscovery by looking for files
under the pxelinux.cfg/ prefix (in addition to any pxepathprefix from
DHCP option 210)

This change unifies petitboot's behaviour with pxelinux.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/network: Fix incorrect static DNS servers in resolv.conf
Jeremy Kerr [Tue, 25 Feb 2014 09:04:17 +0000 (17:04 +0800)]
discover/network: Fix incorrect static DNS servers in resolv.conf

We currently have a bug where we write NUL characters into
/etc/resolv.conf, when using static DNS server configurations:

With a network setting of: dns,9.0.6.11,9.0.7.1

We generate a resolv.conf containing:

 nameserver 9.0.6.11^@nameserver 9.0.7.1^@

This is due to an off-by-one bug when terminating the nameserver
entries.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agolib/process: Don't abort stdout reads on EINTR
Jeremy Kerr [Thu, 20 Feb 2014 01:22:58 +0000 (09:22 +0800)]
lib/process: Don't abort stdout reads on EINTR

If our read() of the process stdout pipe fails with EINTR (eg, if we
receive a SIGCHLD because the process exited), then
process_read_stdout_once will return a non-zero exit code, and we'll
abort any further stdout collection.

Instead, we should check for EINTR, and allow the reads to continue.

This change normalises the return value from process_read_stdout_once to
return positive on success, negative on failure, and zero on competion.
We use a positive return value for the non-error EINTR case.

Also, add a pb_log if the read fails for non-EINTR reasons.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoutils: Add all hooks to Makefile
Jeremy Kerr [Fri, 14 Feb 2014 09:45:53 +0000 (17:45 +0800)]
utils: Add all hooks to Makefile

We were missing a couple of the later hooks from the Makefile.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Unify key bindings & key help text
Jeremy Kerr [Fri, 31 Jan 2014 02:53:57 +0000 (10:53 +0800)]
ui/ncurses: Unify key bindings & key help text

This change is a small cleanup of the key bindings; we ensure that the
general key bindings are available (and documented) on all screens.

In order to keep things consistent, this change adds an initial UI
guidelines text file, which documents the general key bindings.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Add help to boot editor screen
Jeremy Kerr [Fri, 13 Dec 2013 08:02:12 +0000 (16:02 +0800)]
ui/ncurses: Add help to boot editor screen

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Add help to system configuration screen
Jeremy Kerr [Fri, 13 Dec 2013 07:20:22 +0000 (15:20 +0800)]
ui/ncurses: Add help to system configuration screen

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Add help to sysinfo screen
Jeremy Kerr [Fri, 13 Dec 2013 07:18:07 +0000 (15:18 +0800)]
ui/ncurses: Add help to sysinfo screen

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Add help facility to text screens
Jeremy Kerr [Fri, 13 Dec 2013 07:15:06 +0000 (15:15 +0800)]
ui/ncurses: Add help facility to text screens

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Add help text to nc-menu & generic-main
Jeremy Kerr [Tue, 10 Dec 2013 07:08:47 +0000 (15:08 +0800)]
ui/ncurses: Add help text to nc-menu & generic-main

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Add support for help screens
Jeremy Kerr [Tue, 10 Dec 2013 03:48:25 +0000 (11:48 +0800)]
ui/ncurses: Add support for help screens

Add a textscreen-based help screen system, triggered from the cui
module's cui_show_help()

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Add text_screen_set_text()
Jeremy Kerr [Mon, 9 Dec 2013 03:52:57 +0000 (11:52 +0800)]
ui/ncurses: Add text_screen_set_text()

When we have a large chunk of text, we'll want to add it all in one go.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Abstract text-screen code from sysinfo screen
Jeremy Kerr [Mon, 9 Dec 2013 03:30:19 +0000 (11:30 +0800)]
ui/ncurses: Abstract text-screen code from sysinfo screen

We want to implement help screens, which are very similar to the sysinfo
screen - show a set of lines, and allow scrolling.

This change splits the text-screen rendering code into a new nc-textinfo
module.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: do all config screen updates in config_screen_post
Jeremy Kerr [Fri, 13 Dec 2013 02:09:06 +0000 (10:09 +0800)]
ui/ncurses: do all config screen updates in config_screen_post

We call _post when the config screen is to be displayed, so do all
drawing here. This means we get the same drawing code on both init and
update.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agolib/fold: Add text fold utility
Jeremy Kerr [Tue, 10 Dec 2013 06:12:48 +0000 (14:12 +0800)]
lib/fold: Add text fold utility

We want to fold help text into the ncurses UI, so add a little module to
split text into lines.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Use descriptive field labels for boot editor
Jeremy Kerr [Thu, 30 Jan 2014 13:53:30 +0000 (21:53 +0800)]
ui/ncurses: Use descriptive field labels for boot editor

Rather than the brief names for the boot editor field label, expand (and
capitalise) for a more-friendly form.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoplatforms/powerpc: Add support for OPAL sysparams
Jeremy Kerr [Thu, 30 Jan 2014 08:59:56 +0000 (16:59 +0800)]
platforms/powerpc: Add support for OPAL sysparams

PowerPC OPAL firmware's sysparam interface allows us to read the boot
device set over IPMI. This change implements support for IPMI bootdev
selection over the sysparams interface, using the new boot_priority
infrastructure.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: Add DEVICE_TYPE_ANY for matching any device
Jeremy Kerr [Thu, 30 Jan 2014 08:32:21 +0000 (16:32 +0800)]
discover: Add DEVICE_TYPE_ANY for matching any device

Currently, If we want disable all but a specific device type from
default boot, we need to add a negative priority for all other devices.

This change adds a DEVICE_TYPE_ANY definition, to allow a simpler way to
express "only boot a specific type" by default behaviour.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: Make boot_priorities more flexible
Jeremy Kerr [Thu, 30 Jan 2014 08:19:20 +0000 (16:19 +0800)]
discover: Make boot_priorities more flexible

Rather than rely on the ordering of the boot_priorities array to define
which device types have a higher "default boot" priority, this change
introduces a slightly more flexible way of priority lookups, by adding a
separate priority field to struct boot_priority.

This means we can have an unordered array, change priorities without
re-writing the array, and implementing a disable mechanism.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/network: Use platform definition for DHCP architecture ID
Jeremy Kerr [Fri, 17 Jan 2014 08:12:42 +0000 (16:12 +0800)]
discover/network: Use platform definition for DHCP architecture ID

Allow a platform to specify a DHCP architecture ID, as this is
platform-specific.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoplatforms/powerpc: Check for a powerpc platform in the probe function
Jeremy Kerr [Wed, 29 Jan 2014 09:41:04 +0000 (17:41 +0800)]
platforms/powerpc: Check for a powerpc platform in the probe function

Currently, we're always assuming a powerpc platform, as the powerpc
probe() function always returns true.

This change adds a check for some bits we need to work on a powerpc
platform.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agopb-config: Move config storage modules to "platform" modules in discover code
Jeremy Kerr [Wed, 29 Jan 2014 05:28:06 +0000 (13:28 +0800)]
pb-config: Move config storage modules to "platform" modules in discover code

There's no need to include the config storage code in lib/ as only the
discover server should be using it.

This change moves the config-storage code to discover/, with the
platform-specific parts moved to a 'struct platform'. Each platform has
a probe function, which is called during init. The first probe function
to return a platform is used.

At present we only have the one platform, but it's now non-intrusive to
add others.

We keep an array of platform pointers in a separate ("platforms")
section, to allow the test module to drop-in its own test "platform".

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agolib/pb-config: Add config_copy
Jeremy Kerr [Tue, 28 Jan 2014 05:01:19 +0000 (13:01 +0800)]
lib/pb-config: Add config_copy

At the moment, UIs have the config_set_defaults function to estabilish
an initial configuration when performing an update.

Rather than using the defaults, this change provides a config_copy()
function, so that the updated configuration can be initialised from the
current config.

With this in place, the UI/server-common pb-config module can be reduced
to just the one function.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotest/parser: Add Fedora 20 ppc64 parser testcase
Jeremy Kerr [Tue, 28 Jan 2014 01:42:28 +0000 (09:42 +0800)]
test/parser: Add Fedora 20 ppc64 parser testcase

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Add support for for-loops
Jeremy Kerr [Fri, 24 Jan 2014 06:40:46 +0000 (14:40 +0800)]
discover/grub2: Add support for for-loops

GRUB2 syntax allows for for-loops; this change adds supoprt in the
parser grammar and script execution code to implement them. In the
execution code, we simply update the for-loop variable and re-execute
the body statements.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Perform word-expansion non-destructively
Jeremy Kerr [Tue, 28 Jan 2014 01:38:13 +0000 (09:38 +0800)]
discover/grub2: Perform word-expansion non-destructively

In order to implement for-loops, we may need to evaluate the same chunk
of script more than once, and perform that evaluation in a different
context (particularly, with different environment variables).

Currently, the process_expansion code destroys the result of the
parse-tree (ie, the token list) when performing expansions. This means
that we can only perform the expansions once.

This change preserves the token list while creating the argv array. This
means that we can expand the list multiple times.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: Add support for checking directories in parser API
Jeremy Kerr [Fri, 24 Jan 2014 06:39:37 +0000 (14:39 +0800)]
discover: Add support for checking directories in parser API

This change adds a function to the parser API:

  int parser_check_dir(struct discover_context *ctx,
   struct discover_device *dev, const char *dirname)

- which allows parsers to check for the presence of a directory (path of
'dirname') on the device ('dev'). We use this in the GRUB2 parser to
implement the `test -d` check.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: skip menuentries that don't define a boot option
Jeremy Kerr [Fri, 24 Jan 2014 05:45:24 +0000 (13:45 +0800)]
discover/grub2: skip menuentries that don't define a boot option

menuentries may perform arbitrary commands; we only want ones that
define a boot option.

This change doesn't add a boot option if we haven't seen at least a boot
image defined in the menuentry.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub: Add feature variable for --id support.
Jeremy Kerr [Wed, 15 Jan 2014 23:10:25 +0000 (15:10 -0800)]
discover/grub: Add feature variable for --id support.

Since we support --id arguments on menuentries, add the corresponding
feature variable.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Use script_env_set when initialising the environment
Jeremy Kerr [Tue, 28 Jan 2014 01:48:48 +0000 (09:48 +0800)]
discover/grub2: Use script_env_set when initialising the environment

No need to duplicate the environment-adding code in init_env, as we can
just use script_env_set.

Since script_env_set does its own talloc, we don't need to talloc our
strings here either.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agopb-config/powerpc: fix default option handling
Jeremy Kerr [Thu, 23 Jan 2014 05:31:56 +0000 (13:31 +0800)]
pb-config/powerpc: fix default option handling

Currently, we don't update nvram if an NVRAM parameter is set to the
default. This means we can never revert a configuration to its default
value.

This change fixes the default setting behaviour; instead of checking for
a default, we want to check if it's a default and the option is absent.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: Use lowercase hex chars for MAC-address-based conf requests
Jeremy Kerr [Tue, 21 Jan 2014 23:53:46 +0000 (07:53 +0800)]
discover: Use lowercase hex chars for MAC-address-based conf requests

The de-facto PXELINUX standard specifies lowercase characters for the
MAC addresses, so change our reuqests to suit.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agolib/process: Add helper for check process clean exit
Jeremy Kerr [Tue, 21 Jan 2014 02:00:49 +0000 (10:00 +0800)]
lib/process: Add helper for check process clean exit

We have a few incorrect checks for the exit status of a process; this
change adds a helper with the correct WIFEXITED && WEXITSTATUS==0 logic.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/paths: Check process exit status when loading URLs
Jeremy Kerr [Tue, 21 Jan 2014 00:27:48 +0000 (08:27 +0800)]
discover/paths: Check process exit status when loading URLs

Currently, we may report incorrect success when loading a URL, as we
only check the return value of process_run_sync() (and not the process
exit status itself) in load_process_to_local_file.

This fix adds a check to the synchronous load.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoutils/hooks: Add dtb-sort hook
Jeremy Kerr [Mon, 20 Jan 2014 07:12:46 +0000 (15:12 +0800)]
utils/hooks: Add dtb-sort hook

The boot hooks may have altered the DTB in various ways, so add a final
(90-) boot hook to re-sort the dtb with `dtc -s`.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoutils/pb-udhcpc: Unify references to DHCP bootfile parameter
Jeremy Kerr [Mon, 20 Jan 2014 00:58:49 +0000 (08:58 +0800)]
utils/pb-udhcpc: Unify references to DHCP bootfile parameter

udhcpc may pass the bootfile parameter as either $bootfile or
$boot_file, depending on whether the option is present in the BOOTP
header, or as a DHCP vendor option. We have code in pb-udhcpc to unify
this to $bootfile, but we only use the unified value in one of the user
events.

This change uses the correct value of bootfile, and fixes the check to
conditionally generate the explicit add event. We also need to update
the user-event code to use the right event parameter name.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoutils/pb-udhcpc: Fix incorrect reference to $interface
Jeremy Kerr [Mon, 20 Jan 2014 00:51:11 +0000 (08:51 +0800)]
utils/pb-udhcpc: Fix incorrect reference to $interface

We have a typo in the udhcpc hook, where we're not referncing the
interface variable correctly. This means we'll get the same device
identifier for all netboot options.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoutils/pb-udhcpc: remove bashism when reading mac address
Jeremy Kerr [Mon, 20 Jan 2014 00:42:44 +0000 (08:42 +0800)]
utils/pb-udhcpc: remove bashism when reading mac address

The $(< FILE) syntax we use to read an interface's MAC address doesn't
work in dash or busybox sh. Instead, use cat.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/network: Send DHCP client architecture type
Jeremy Kerr [Fri, 17 Jan 2014 08:12:42 +0000 (16:12 +0800)]
discover/network: Send DHCP client architecture type

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: Support DHCP "pathprefix" configuration option
Jeremy Kerr [Fri, 17 Jan 2014 07:51:54 +0000 (15:51 +0800)]
discover: Support DHCP "pathprefix" configuration option

This change implements support for the DHCP "pathprefix" option. We use
the following logic:

 - If pathprefix is present and a full URL, we base the config file
   location on pathprefix + conffile

 - If pathprefix is present but not a full URL, we use it as the path
   component of the URL, and pick up the host from other parameters in
   the DHCP response

 - If no pathprefix is present, we determine the configuration prefix
   from the DHCP bootfile parameter.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotest/parser: Check for full URLs in parser tests
Jeremy Kerr [Fri, 17 Jan 2014 08:36:41 +0000 (16:36 +0800)]
test/parser: Check for full URLs in parser tests

At present, we only match the 'file' portion of a URL in the parser
tests, so we "serve" a file if just the filename (but not the scheme,
hostname or path) matches the file we set with test_read_conf_embedded.

This change introduces test_read_conf_embedded_url, which we can use to
specify a full URL. In this case, the fake parser_request_file matches
the entire URL before returning the file data.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: Don't rely on ctx->conf_url side-effect in user_event_parse_conf_url
Jeremy Kerr [Fri, 17 Jan 2014 06:50:54 +0000 (14:50 +0800)]
discover: Don't rely on ctx->conf_url side-effect in user_event_parse_conf_url

Currently, user_event_parse_conf_url sets dc->conf_url if it detects we
have a full URL (rather than a base URL). This is a little too subtle,
so replace it with an explicit output parameter.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub: Use --id values for default option detection
Ben Stoltz [Wed, 15 Jan 2014 23:10:25 +0000 (15:10 -0800)]
discover/grub: Use --id values for default option detection

Fix Petitboot's grub.cfg parser to handle --id=label argument to
menuentry, and use it (in preference to the option name) when looking
for a default option.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: Bring down configured interfaces on discover server exit.
Jeremy Kerr [Thu, 16 Jan 2014 01:13:20 +0000 (09:13 +0800)]
discover: Bring down configured interfaces on discover server exit.

We want to down the interfaces that we brought up, so hook up the
network_shutdown function to the discover exit path. Also, we only want
to down interfaces that we've configured, and exclude lo.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoutils: Add boot hook to set stdout property on DT machines
Jeremy Kerr [Wed, 15 Jan 2014 07:59:27 +0000 (15:59 +0800)]
utils: Add boot hook to set stdout property on DT machines

On machines that use device-tree boot, they'll often set an early
console, defined by the linux,stdout property in the /chosen/ device
tree node.

This hook adds a facility for petitboot to set this, based on an NVRAM
setting.

6 years agodiscover: we need stderr for the BusyBox TFTP type check
Jeremy Kerr [Tue, 14 Jan 2014 07:58:31 +0000 (15:58 +0800)]
discover: we need stderr for the BusyBox TFTP type check

Busybox tftp doesn't support -V, so prints an error to stderr. We'll
only see the Busybox identifier if we capture stderr too.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agolib/process: Add add_stderr flag to process module
Jeremy Kerr [Tue, 14 Jan 2014 07:44:10 +0000 (15:44 +0800)]
lib/process: Add add_stderr flag to process module

For some process execution functions, we'd like to capture stderr as
well as stdout. Currently, we unconditionally redirect subprocess stderr
to the petitboot log file.

This change adds an add_stderr flag to struct process, which indicates
to the process library that we want stderr as well as stdout. If this is
specified, the subprocess' stderr is captured to stdout_buf.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotest/parser: Add yaboot leftovers test
Jeremy Kerr [Tue, 14 Jan 2014 03:15:03 +0000 (11:15 +0800)]
test/parser: Add yaboot leftovers test

Add a test to ensure that boot option parameters don't leak into later
options.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/yaboot: Remove known_names list
Jeremy Kerr [Tue, 14 Jan 2014 03:04:54 +0000 (11:04 +0800)]
discover/yaboot: Remove known_names list

The known_names list only duplicates the arg matching we do in the body
of the parser, and so introduces a problem when the array becomes out of
sync.

We drop the priority of the "unknown name" messages to pb_debug, as this
isn't really imporant unless we're debugging.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/yaboot: Clear globals_done when we see an image definition
Jeremy Kerr [Tue, 14 Jan 2014 02:56:41 +0000 (10:56 +0800)]
discover/yaboot: Clear globals_done when we see an image definition

Currently, we have a bug where a 'known_name' that appears before an
image section will cause globals_done to be set, and we don't see any
further global variables.

This change sets globals_done only once we see an image section.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/udev: Set device type for optical media correctly
Jeremy Kerr [Mon, 13 Jan 2014 08:06:01 +0000 (16:06 +0800)]
discover/udev: Set device type for optical media correctly

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoconfig/powerpc: Always call update_network_config
Jeremy Kerr [Mon, 23 Dec 2013 08:42:21 +0000 (16:42 +0800)]
config/powerpc: Always call update_network_config

Currently, we have a bug when setting the default network configuration
(ie, no devices have any specific config), as we won't call
update_network_config to clear out the value of the petitboot,network
parameter.

This change always invokes update_network_config, regardless of the
number of interfaces configured. This ensures we clear out the
petitboot,network param, which is then synced to nvram if the param has
changed.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses/nc-config: Add validation for network settings
Jeremy Kerr [Wed, 18 Dec 2013 05:06:36 +0000 (13:06 +0800)]
ui/ncurses/nc-config: Add validation for network settings

Use the new widget validators, plus a bit of whole-form logic, to
implement some basic validation on the config UI.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses/nc-widgets: Add initial textbox validation functions
Jeremy Kerr [Wed, 18 Dec 2013 05:05:01 +0000 (13:05 +0800)]
ui/ncurses/nc-widgets: Add initial textbox validation functions

We'd like to do some validation of the system configuration parameters,
so add a few validation types to the widget code. We currently need
integer, ipv4 address and multiple ipv4 address types. These are
implemented as small wrappers around the ncurses form validator code.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses/nc-config: expand mask field
Jeremy Kerr [Wed, 18 Dec 2013 02:31:10 +0000 (10:31 +0800)]
ui/ncurses/nc-config: expand mask field

This makes it obvious if there's more than two characters in the field.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoconfigure: Use AC_GNU_SOURCE
Jeremy Kerr [Mon, 16 Dec 2013 08:21:50 +0000 (16:21 +0800)]
configure: Use AC_GNU_SOURCE

Rather than #defining _GNU_SOURCE in our .c files, we can define this
from config.h instead.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Add link status to system info & system config screens
Jeremy Kerr [Mon, 16 Dec 2013 05:20:01 +0000 (13:20 +0800)]
ui/ncurses: Add link status to system info & system config screens

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agolib/util: Avoid sprintf in mac_str
Jeremy Kerr [Mon, 16 Dec 2013 03:21:22 +0000 (11:21 +0800)]
lib/util: Avoid sprintf in mac_str

The conversion is simple, no need for sprintf.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agolib/util: Move mac_buf from nc code to util library
Jeremy Kerr [Mon, 16 Dec 2013 03:12:03 +0000 (11:12 +0800)]
lib/util: Move mac_buf from nc code to util library

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agosysinfo: Add interface link status to sysinfo data
Jeremy Kerr [Mon, 16 Dec 2013 02:49:29 +0000 (10:49 +0800)]
sysinfo: Add interface link status to sysinfo data

This changes adds a 'link' parameter to the interface information sent
in sysinfo messages. The discover network code populates this from the
incoming netlink messages.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotest/lib: Add parent stdout test
Jeremy Kerr [Mon, 16 Dec 2013 07:16:36 +0000 (15:16 +0800)]
test/lib: Add parent stdout test

Looks like we missed adding a test source file.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/yaboot: Fix assertion failure on empty yaboot files
Jeremy Kerr [Tue, 10 Dec 2013 00:54:17 +0000 (08:54 +0800)]
discover/yaboot: Fix assertion failure on empty yaboot files

yaboot configuration files with no option will cause an assertion
failure (or segfault), as we unconditionally call yaboot_finish().

Check for the presence of an option in yaboot_finish() instead of
asserting.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/boot: Copy local paths before running boot hooks
Jeremy Kerr [Thu, 5 Dec 2013 06:54:13 +0000 (14:54 +0800)]
discover/boot: Copy local paths before running boot hooks

We're seeing a crash when boot hooks are specifying new resources, as
boot_hook_update_param will write to a NULL struct load_url_result.

Instead of writing the updated values to the struct, copy the local
parts of the result to a separate string, which the boot hooks are free
to update.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/boot: Fix condition for updating boot params
Jeremy Kerr [Thu, 5 Dec 2013 06:32:28 +0000 (14:32 +0800)]
discover/boot: Fix condition for updating boot params

In commit 823958fb, we change to use struct process, but left in the
check for rc == BOOT_HOOK_EXIT_UPDATE. We actually want to check
process->exit_status here, not rc.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/udev: Use UUIDs for multipath check
Jeremy Kerr [Wed, 4 Dec 2013 06:49:40 +0000 (14:49 +0800)]
discover/udev: Use UUIDs for multipath check

Partitions will share a serial number.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses/boot-editor: Fix (null) when non-device resources are shown
Jeremy Kerr [Tue, 3 Dec 2013 11:28:10 +0000 (19:28 +0800)]
ui/ncurses/boot-editor: Fix (null) when non-device resources are shown

We're seeing the following in the boot editor:

 image:  (null)ftp://...

the (null) is due to the sep in conditional_prefix, which should be
blank, not NULL.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Fixes for bison 3.x
Jeremy Kerr [Tue, 3 Dec 2013 07:14:53 +0000 (15:14 +0800)]
discover/grub2: Fixes for bison 3.x

YYLEX_PARAM is removed in bison 3.0, so we need to pass the scanner
param directly through yyparse (rather than referencing
parser->scanner). Unfortunately, we don't have the lexer header
available at the time we declare yyparse, so we need to pass a void *
here.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover: Fix CDROM handling
Jeremy Kerr [Fri, 29 Nov 2013 02:47:10 +0000 (10:47 +0800)]
discover: Fix CDROM handling

Currently, we don't handle CDROM devices well; we'll try to mount on
boot, and not detect any media changes. Also, the default rules shipping
with udev will put the CDROM tray into a locked state, blocking eject
from working.

This change adds a set of cdrom utility functions, which the udev code
can use to properly initialise cdrom devices and handle eject and media
change requests.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Add key debug
Jeremy Kerr [Mon, 2 Dec 2013 08:03:54 +0000 (16:03 +0800)]
ui/ncurses: Add key debug

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/device-handler: Ensure we free unresolved boot options on remove
Jeremy Kerr [Mon, 2 Dec 2013 03:20:04 +0000 (11:20 +0800)]
discover/device-handler: Ensure we free unresolved boot options on remove

When we remove a device, some options may still be unresolved, and so
won't be deallocated through freeing the device.

This chagne explicitly removes & frees any currently-unresolved options
for this device.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/udev: copy dev->device path from udev devnode
Jeremy Kerr [Fri, 29 Nov 2013 05:44:54 +0000 (13:44 +0800)]
discover/udev: copy dev->device path from udev devnode

We're seeing a use-after-free, as the udev path is freed before the
discover device.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Populate $prefix from config file location
Jeremy Kerr [Wed, 27 Nov 2013 11:51:49 +0000 (19:51 +0800)]
discover/grub2: Populate $prefix from config file location

Rather than always using the default prefix, we should determine it from
the location of the grub2 config file.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agotest/parser/grub2: Fix inconsistent conf/env paths
Jeremy Kerr [Wed, 27 Nov 2013 12:00:11 +0000 (20:00 +0800)]
test/parser/grub2: Fix inconsistent conf/env paths

In an upcoming change, we'll populate $prefix (which is used to locate
the environment file) based on the location of the config file, so these
paths will need to be consistent.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Use parser for a single parse
Jeremy Kerr [Wed, 27 Nov 2013 11:47:37 +0000 (19:47 +0800)]
discover/grub2: Use parser for a single parse

Currently, we re-use a grub2 parser for different filenames, and will
create one even if we find no matching files.

This change only creates a parser if parser_request_file succeeds, and
free() (and exits the parse) immediately after.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Fix free in load_env command
Jeremy Kerr [Wed, 27 Nov 2013 11:43:25 +0000 (19:43 +0800)]
discover/grub2: Fix free in load_env command

We only need to free the buf if parser_request_file returned success.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Fix indentation error
Jeremy Kerr [Wed, 27 Nov 2013 10:58:52 +0000 (18:58 +0800)]
discover/grub2: Fix indentation error

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/grub2: Add support for -s and -f commands
Jeremy Kerr [Wed, 27 Nov 2013 10:56:16 +0000 (18:56 +0800)]
discover/grub2: Add support for -s and -f commands

Implement -s and -f checks for grub, and test with the standard GRUB2
saved_default config.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agodiscover/network: In static config mode, only configure defined interfaces
Jeremy Kerr [Wed, 27 Nov 2013 10:52:37 +0000 (18:52 +0800)]
discover/network: In static config mode, only configure defined interfaces

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agolib/pb-config/powerpc-nvram: Fix format of dns config
Jeremy Kerr [Tue, 26 Nov 2013 05:29:04 +0000 (13:29 +0800)]
lib/pb-config/powerpc-nvram: Fix format of dns config

It should be dns,<server> not dns=<server>

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses/nc-widgets: Unify select key
Jeremy Kerr [Fri, 22 Nov 2013 06:12:59 +0000 (14:12 +0800)]
ui/ncurses/nc-widgets: Unify select key

We have a few instances where we check for a 'select' action (enter or
space key event), and some are inconsistent. Unify these with a
key_is_select() function.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Redraw entire screen with ctrl+L
Jeremy Kerr [Tue, 19 Nov 2013 23:03:42 +0000 (10:03 +1100)]
ui/ncurses: Redraw entire screen with ctrl+L

Use wrefresh(curscr) to clean and repaint the entire screen.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Ensure boot editor window is properly painted
Jeremy Kerr [Tue, 19 Nov 2013 07:03:40 +0000 (18:03 +1100)]
ui/ncurses: Ensure boot editor window is properly painted

We're not currently drawing the window title correctly; we need to draw
the main_ncw for this to hit the terminal.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Fix use-after-free when exiting boot option editor
Jeremy Kerr [Tue, 19 Nov 2013 06:39:41 +0000 (17:39 +1100)]
ui/ncurses: Fix use-after-free when exiting boot option editor

After we've called on_exit, we can no longer use the boot editor. This
change moves individual button callbacks into process_key, which returns
to the main loop.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Allow boot editor sysinfo updates
Jeremy Kerr [Tue, 19 Nov 2013 05:08:35 +0000 (16:08 +1100)]
ui/ncurses: Allow boot editor sysinfo updates

We may start a boot editor (via 'New') before we have the sysinfo. To
allow this, we redraw the device select.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Add widgetset_set_window
Jeremy Kerr [Wed, 20 Nov 2013 03:18:35 +0000 (14:18 +1100)]
ui/ncurses: Add widgetset_set_window

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Add widget_select_drop_options
Jeremy Kerr [Wed, 20 Nov 2013 03:17:31 +0000 (14:17 +1100)]
ui/ncurses: Add widget_select_drop_options

We want to be able to re-set the options in a select widget.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Implement intra-field scrolling
Jeremy Kerr [Tue, 19 Nov 2013 03:20:30 +0000 (14:20 +1100)]
ui/ncurses: Implement intra-field scrolling

Now that we can calculate the focus within a field, ensure that the
focussed-element remains scrolled.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses/widgets: Add widget focus offset query
Jeremy Kerr [Tue, 19 Nov 2013 03:18:28 +0000 (14:18 +1100)]
ui/ncurses/widgets: Add widget focus offset query

When we have widgets that are larger than the screen, we'd like to
scroll to the currently-focussed component of that widget.

This change introduces a widget_focus_y function, which returns the y
offset of the field's focus.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Draw boot editor into a scrollable pad
Jeremy Kerr [Tue, 19 Nov 2013 00:52:49 +0000 (11:52 +1100)]
ui/ncurses: Draw boot editor into a scrollable pad

Like the config editor, draw the boot editor into a pad instead of
directly into the sub window. This means that long device lists will be
handled correctly.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Make boot editor paths relative to device
Jeremy Kerr [Sun, 17 Nov 2013 09:54:46 +0000 (20:54 +1100)]
ui/ncurses: Make boot editor paths relative to device

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
6 years agoui/ncurses: Add device selector to boot editor
Jeremy Kerr [Sun, 17 Nov 2013 08:36:55 +0000 (19:36 +1100)]
ui/ncurses: Add device selector to boot editor

Rather than expecting users to enter full (prefixed) mount paths, add a
select widget to pick a device, and we automatically add the prefix when
the form is submitted.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>