]> git.ozlabs.org Git - petitboot/log
petitboot
7 years agodiscover: add handler reference to struct discover_context
Jeremy Kerr [Mon, 12 Dec 2016 11:58:32 +0000 (19:58 +0800)]
discover: add handler reference to struct discover_context

Since the device handler provides the status message functions, we need
a pointer to it for device discovery (which we use a struct
discover_context for).

This change adds a 'handler' member to struct discover_context, to allow
status reporting. Since we now have a handler, there's no need for the
network pointer, so provide an accessor function instead.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
7 years agodiscover: Use device_handler_status_dev_* for device-specific status
Jeremy Kerr [Mon, 12 Dec 2016 07:58:57 +0000 (15:58 +0800)]
discover: Use device_handler_status_dev_* for device-specific status

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
7 years agodiscover: Add device-specific status reporting functions
Jeremy Kerr [Mon, 12 Dec 2016 07:43:21 +0000 (15:43 +0800)]
discover: Add device-specific status reporting functions

Most of our status reporting is against a specific device, so add
status reporting functions that take a struct discover_device and use a
stnadard prefix.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
7 years agodiscover: use helpers for status reporting
Jeremy Kerr [Mon, 12 Dec 2016 07:26:32 +0000 (15:26 +0800)]
discover: use helpers for status reporting

Now that we have helpers for simpler status reporting, use those instead
of constructing a struct status everywhere.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
7 years agodiscover: Add helpers for status reporting
Jeremy Kerr [Thu, 8 Dec 2016 02:08:15 +0000 (13:08 +1100)]
discover: Add helpers for status reporting

This change adds a couple of helpers for the status reporting API,
allowing callers to provide just a set of printf-style arguments, rather
than having to build up a struct status.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
7 years agodiscover: separate status-reporting function from boot() callback
Jeremy Kerr [Wed, 7 Dec 2016 00:43:08 +0000 (11:43 +1100)]
discover: separate status-reporting function from boot() callback

Currently, the device_discover_boot_status function is both used for
internal status updates, as well as the callback passed to boot().

This change splits this into two functions; one for the latter and one
for the former. The latter just has a void * for its first argument, to
match the boot_status_fn type.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
7 years agoui/ncurses: remove "Info:" / "Error:" prefix from status area
Jeremy Kerr [Tue, 13 Dec 2016 02:00:22 +0000 (10:00 +0800)]
ui/ncurses: remove "Info:" / "Error:" prefix from status area

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
7 years agoui/ncurses: Add status log UI
Jeremy Kerr [Tue, 6 Dec 2016 06:23:28 +0000 (17:23 +1100)]
ui/ncurses: Add status log UI

Currently, status messages from the server are displayed in a single
line at the bottom of the main menu UI, and are lost once a new status
is reported.

This change adds a facility for the UI to collect and display the status
messages from the server, in a dedicated UI screen. This allows a user
to look back through the discovery & boot process.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
7 years agotypes: Remove detail and progress from struct status
Jeremy Kerr [Wed, 7 Dec 2016 00:30:27 +0000 (11:30 +1100)]
types: Remove detail and progress from struct status

Nothing used these, and the serialisation was buggy anyway.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
7 years agotypes: shorten boot_status definitions
Jeremy Kerr [Wed, 7 Dec 2016 00:13:36 +0000 (11:13 +1100)]
types: shorten boot_status definitions

struct boot_status is a bit misnamed; we report status on things that
aren't just the boot status (eg, discovery).

This change refactors struct boot_status into just struct status. We
give the type enum a name, and shorten the enum values to suit.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoui/ncurses: Make server connect message more clear v1.3.2
Samuel Mendoza-Jonas [Thu, 3 Nov 2016 05:46:20 +0000 (16:46 +1100)]
ui/ncurses: Make server connect message more clear

The current message mentions a "server" which can give the misleading
impression that the UI is waiting for a remote network server. The delay
is actually in waiting for the pb-discover process to be ready, so
update the message to reflect that.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/platform-powerpc: Reject bootdevs with empty UUIDs
Samuel Mendoza-Jonas [Tue, 22 Nov 2016 00:00:42 +0000 (11:00 +1100)]
discover/platform-powerpc: Reject bootdevs with empty UUIDs

If a "uuid:" label is set in the petitboot,bootdevs parameter without a
matching UUID, the UUID is unintentionally accepted and set to NULL.
This can cause a segfault in nc-config when device UUIDs are compared
against the autoboot option. Instead treat options like this as
malformed.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/platform-powerpc: Deprecate petitboot,bootdev parameter
Samuel Mendoza-Jonas [Tue, 22 Nov 2016 00:00:01 +0000 (11:00 +1100)]
discover/platform-powerpc: Deprecate petitboot,bootdev parameter

The "petitboot,bootdevs" parameter has been around long enough now that
there shouldn't be anyone still transitioning over from the old
"petitboot,bootdev" parameter. Drop this parameter to simplify the
populate_bootdev_config() logic.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/platform-powerpc: Remove unused max_partition_size
Samuel Mendoza-Jonas [Thu, 27 Oct 2016 05:24:56 +0000 (16:24 +1100)]
discover/platform-powerpc: Remove unused max_partition_size

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoSupport HTTP(S) proxies when downloading resources
Samuel Mendoza-Jonas [Thu, 27 Oct 2016 03:56:05 +0000 (14:56 +1100)]
Support HTTP(S) proxies when downloading resources

Allow the user to specify a HTTP and HTTPS proxy server. The discover
server will set the http_proxy and https_proxy environment variables,
enabling the proxy servers for any further HTTP(S) requests.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoui/ncurses: Spin child to ensure autoboot cancelled on exit
Samuel Mendoza-Jonas [Wed, 23 Nov 2016 00:48:07 +0000 (11:48 +1100)]
ui/ncurses: Spin child to ensure autoboot cancelled on exit

If the client is not connected to the server instance when exiting, fork
and have the child process spin until the server is available and can be
told to cancel autoboot. This prevents the scenario of a user exiting
the UI and having the server continue to autoboot while they are using
the command line.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoutils: Rename 30-dtb_updates to 30-dtb-updates
Arthur Heymans [Tue, 18 Oct 2016 11:21:06 +0000 (13:21 +0200)]
utils: Rename 30-dtb_updates to 30-dtb-updates

This is more consistent with other files in utils/hooks.

Signed-off-by: Arthur Heymans <arthur@aheymans.xyz>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/pxe-parser: Parse only the first config v1.3.1
Samuel Mendoza-Jonas [Fri, 23 Sep 2016 03:06:48 +0000 (13:06 +1000)]
discover/pxe-parser: Parse only the first config

Commit 2163af5 "discover/pxe-parser: Retrieve configs asynchronously"
added asynchronous loading of remote pxe filenames, but made an
unintended change in behaviour to the PXE parser. Previously the parser
would try a list of possible filenames, and parse the first one it
found. However the above commit spawns an asynchronous job for every
filename, and parses any that can be retrieved. It is a common
configuration to have a machine-specific config and a 'fallback' default
config, and the change means we could erroneously retrieve and parse
both configs.

Update the PXE parser so that asynchronous jobs are spawned
sequentially. That is, spawn a job for the first filename and if not
successful spawn another job for the next filename, and so on. Once a
remote config is successfully retrieved, parse it and stop.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agolib/file: Fix errors found by Coverity scan
Samuel Mendoza-Jonas [Wed, 7 Sep 2016 05:36:40 +0000 (15:36 +1000)]
lib/file: Fix errors found by Coverity scan

Fix several errors in copy_file_secure_dest() found by Coverity and some
minor formatting issues:

143603: Correctly handle mkstemp() return value
143605: Avoid accessing dest_filename[-1] on readlink() error
143606, 143610: Avoid accessing dest_filename[sizeof(dest_filename)]
143607: Fix incorrectly passing sizeof(pointer) to fread()
143608, 143611: Cleanup resources on early exit
143609: Explicitly set umask before calling mkstemp()

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoutils/hooks: Rename 30-add-offb to 30-dtb-updates v1.3.0
Samuel Mendoza-Jonas [Thu, 8 Sep 2016 01:45:21 +0000 (11:45 +1000)]
utils/hooks: Rename 30-add-offb to 30-dtb-updates

30-add-offb now performs functions other than just setting offb
information, so rename it to a more accurate '30-dtb-updates'.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoConsolidate petitboot,tty and petitboot,console
Samuel Mendoza-Jonas [Tue, 9 Aug 2016 06:16:48 +0000 (16:16 +1000)]
Consolidate petitboot,tty and petitboot,console

Commit ce54f86 "Add petitboot,tty and track available consoles" added
the petitboot,tty parameter, but the petitboot,console parameter is also
recognised by Petitboot. These are ultimately handled by the 30-add-offb
and 80-set-stdout hooks respectively, but exist for mostly the same
purpose.

We consolidate these down to just the original petitboot,console
parameter. If the contents of petitboot,console have been configured by
Petitboot (ie. it is of the form /dev/dev# [ Description ]) we behave as
normal, otherwise we assume that petitboot,console contains a full
OF path to the intended console device and do not allow it to be
modified. This follows petitboot,console's original intent to be a debug
aid, and takes precedence over any other use.
The 80-set-stdout hook is removed as 30-add-offb now accounts for both
use cases.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoUse 'consoles' instead of 'tty' to refer to interfaces
Samuel Mendoza-Jonas [Tue, 9 Aug 2016 06:01:49 +0000 (16:01 +1000)]
Use 'consoles' instead of 'tty' to refer to interfaces

'Console' is more readily understandable and technically more correct
than 'tty' for referring to the interfaces that Petitboot starts a UI on.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoui/ncurses: Display warning when net override active
Samuel Mendoza-Jonas [Tue, 6 Sep 2016 03:30:39 +0000 (13:30 +1000)]
ui/ncurses: Display warning when net override active

If the current interface config has been set by an IPMI network
override, display a warning in nc-config that saving the current config
will overwrite any saved interface config.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover: Avoid writing network overrides to NVRAM
Samuel Mendoza-Jonas [Tue, 6 Sep 2016 03:30:30 +0000 (13:30 +1000)]
discover: Avoid writing network overrides to NVRAM

Explicitly keep track of whether the current interface config was set by
an IPMI network override, and avoid overwriting any saved config unless
the override was marked persistent.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/network: Add find_interface_by_uuid
Samuel Mendoza-Jonas [Mon, 5 Sep 2016 04:22:07 +0000 (14:22 +1000)]
discover/network: Add find_interface_by_uuid

Currently in network_register_device() and network_unregister_device()
the appropriate interface is searched for by name. However it is
possible in some scenarios for multiple interfaces to have the same
name, so instead search by UUID to be sure that the correct interface is
being selected.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover: Pass UUID to discover_device_create()
Samuel Mendoza-Jonas [Mon, 5 Sep 2016 04:21:23 +0000 (14:21 +1000)]
discover: Pass UUID to discover_device_create()

Currently discover_device_create() will search for existing discover
devices by id to determine if a new device is required. However it is
possible under some circumstances for distinct devices to have the same
name. This is especially troublesome if the following network events are
seen in network_handle_nlmsg():

- New interface, 'foo' with uuid x:x:x:x:x:x
-> new discover device created with
dev->device->id = 'foo'
dev->uuid = x:x:x:x:x:x
- New interface, 'foo' with uuid y:y:y:y:y:y
-> existing device 'foo' found
dev->uuid = y:y:y:y:y:y

This can occur if an interface rename event arrives *after* an old name
is reused, where temporarily Petitboot will see two distinct network
interfaces with the same name. Now the two interfaces point to the same
discover device, which can quickly result in a segfault if a 'remove'
event occurs for one of the interfaces and the discover device is freed.

To generally avoid this a 'uuid' parameter is added to
discover_device_create(), which if present allows existing devices to be
looked up by UUID rather than just their name.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoutils: Always pass MAC address in pb-udhcpc
Samuel Mendoza-Jonas [Mon, 5 Sep 2016 04:21:44 +0000 (14:21 +1000)]
utils: Always pass MAC address in pb-udhcpc

pb-udhcpc currently only passes the interface's MAC address for an 'add'
event, however it is useful to know it for any user event concerning a
network interface. Pass it to pb-event in all cases.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover: Deprecate 'conf' user event
Samuel Mendoza-Jonas [Mon, 5 Sep 2016 04:18:18 +0000 (14:18 +1000)]
discover: Deprecate 'conf' user event

The 'conf' user event is functionally very similar to the 'url' event,
in that both events result in downloading a specified configuration file
and passing it to iterate_parsers().
The 'url' event additionally allows downloading files from a directory
path and is also accessed by the UI via pb-protocol, so remove the
'conf' event and associated functions in favour of 'url' and
device_handler_process_url().

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/event: Ensure event struct exists for async callers
Samuel Mendoza-Jonas [Thu, 1 Sep 2016 04:32:03 +0000 (14:32 +1000)]
discover/event: Ensure event struct exists for async callers

When handling an event, user_event_handle_message() creates an event
struct with relevant parameters. Once user_event_handle_message() is
finished it frees the struct.
However in the case of a dhcp or add_url event, asynchronous jobs may be
spawned that will later reference the event struct. In particular this
becomes a problem when pxe_process_pair() handles an IPAPPEND name/value
pair and tries to access event->device.

In the case of dhcp and add_url events, we avoid this by changing the
event struct's talloc parent to the discover_context struct which
persists until all async pxe jobs have completed.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoAdd encrypted file support
tpearson@raptorengineering.com [Thu, 18 Aug 2016 09:46:47 +0000 (04:46 -0500)]
Add encrypted file support

In certain cases, such as network booting over an untrusted connection,
it may be useful to fully encrypt and sign the kernel files.

Enable fully encrypted boot using builtin keyring via the addition of
the string "ENCRYPTED" to the first line of the /etc/pb-lockdown file.
This disables detached (plaintext) signature verification.

Signed-off-by: Timothy Pearson <tpearson@raptorengineering.com>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoDisable shell access when lockdown is active
tpearson@raptorengineering.com [Thu, 18 Aug 2016 09:46:14 +0000 (04:46 -0500)]
Disable shell access when lockdown is active

This patch disables direct command line access when the /etc/pb-lockdown
file is present.

Signed-off-by: Timothy Pearson <tpearson@raptorengineering.com>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoAdd support for GPG signature enforcement on booted
tpearson@raptorengineering.com [Thu, 18 Aug 2016 09:45:47 +0000 (04:45 -0500)]
Add support for GPG signature enforcement on booted

kernels and related blobs

This can be used to implement a form of organization-controlled secure boot,
whereby kernels may be loaded from a variety of sources but they will only
boot if a valid signature file is found for each component, and only if the
signature is listed in the /etc/pb-lockdown file.

Signed-off-by: Timothy Pearson <tpearson@raptorengineering.com>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
(Minor build fixes and gpgme.m4, comment on secure boot in gpg.c)

8 years agodiscover/network: Ignore tun devices v1.2.3
Samuel Mendoza-Jonas [Thu, 30 Jun 2016 06:13:58 +0000 (16:13 +1000)]
discover/network: Ignore tun devices

In some environments a default 'tun' device is created. Petitboot
doesn't use this and it clutters up the list of network devices, so
ignore it if it is encountered.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoui/ncurses: Treat left/right arrow keys properly
Samuel Mendoza-Jonas [Fri, 19 Aug 2016 01:55:57 +0000 (11:55 +1000)]
ui/ncurses: Treat left/right arrow keys properly

It turns out ncurses helpfully provides REQ_LEFT_FIELD and
REQ_RIGHT_FIELD to navigate between visually horizontal fields. Update
widgetset_process_key() to use these for KEY_LEFT and KEY_RIGHT
respectively.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/boot: Always pass --append to kexec
Samuel Mendoza-Jonas [Fri, 19 Aug 2016 04:39:28 +0000 (14:39 +1000)]
discover/boot: Always pass --append to kexec

If we don't specify command line arguments for the next kernel, kexec
will add the contents of /chosen/bootargs if present. This is unintended
and not obvious to the user, so explicitly add append="" to the kexec
arguments if we have none to add instead.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agohooks/set-stdout: move hook to after automatic stdout settings v1.2.2
Jeremy Kerr [Fri, 5 Aug 2016 07:05:12 +0000 (15:05 +0800)]
hooks/set-stdout: move hook to after automatic stdout settings

If a console is defined in NVRAM, we want it to take precedence over
anything that 30-add-offb calculates automatically. This change shifts
the 20-set-stdout script to later in the hook processing, so that it
will override any automatic settings.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agohooks/add-offb: Add leading slash to HVC node paths
Jeremy Kerr [Fri, 5 Aug 2016 07:05:11 +0000 (15:05 +0800)]
hooks/add-offb: Add leading slash to HVC node paths

We need an absolute path to the serial@N device. It looks like some
kernels aren't reading the current path correctly, leading to no console
output.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Acked-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoREADME.md: Add README file
Samuel Mendoza-Jonas [Fri, 20 May 2016 07:01:44 +0000 (17:01 +1000)]
README.md: Add README file

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover: Add 'sync' user event
Samuel Mendoza-Jonas [Tue, 26 Jul 2016 05:45:37 +0000 (15:45 +1000)]
discover: Add 'sync' user event

Add a user event named 'sync' that causes the discover server to merge
the devicemapper snapshots of mounted devices. This is particularly
useful as a debug aid (for example, when copying logs to a USB device),
as the server will otherwise only sync changes to mounted devices in
response to parser actions.

The command can be called as

pb-event sync@device

to sync a particular device, or as

pb-event sync@all

to sync all devices with snapshots.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoui/ncurses: Call widget process_key handlers first
Samuel Mendoza-Jonas [Thu, 21 Jul 2016 03:03:28 +0000 (13:03 +1000)]
ui/ncurses: Call widget process_key handlers first

Adding KEY_LEFT and KEY_RIGHT brought to light the problem that
widgetset_process_keys() may handle keystrokes that would have also been
handled by a widget's process_keys function. In particular the cursor
in a textbox widget could no longer be moved with the left/right keys.

This updates widgetset_process_keys() to call the focussed widget's
process_keys function before handling the key in any other way. All of
the widget process_keys functions correctly return false if the key is
not relevant to the widget except for textbox_process_key() which is
updated to ignore the main navigational keys.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/device-handler: Remove default option if device removed v1.2.1
Samuel Mendoza-Jonas [Wed, 29 Jun 2016 05:43:20 +0000 (15:43 +1000)]
discover/device-handler: Remove default option if device removed

If one of a device's boot options is the current default boot option,
make sure the default boot is cancelled before the device is removed.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/network: Mark interfaces configured once configured
Samuel Mendoza-Jonas [Thu, 16 Jun 2016 05:18:30 +0000 (15:18 +1000)]
discover/network: Mark interfaces configured once configured

In some cases additional netlink messages can be received for an
already-configured interface without any relevant changes. This can
result in multiple DHCP requests for the same interface.
Once an interface has been configured mark it as IFSTATE_CONFIGURED
to avoid configuring it again.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/platform-powerpc: Use IPMI on BMC-based machines only
Samuel Mendoza-Jonas [Wed, 13 Jul 2016 03:49:11 +0000 (13:49 +1000)]
discover/platform-powerpc: Use IPMI on BMC-based machines only

With a kernel that has IPMI support Petitboot will try to use direct
IPMI, however on FSP machines this is not fully functional. Use direct
IPMI only on BMC-based machines, and use sysparams otherwise.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/device-handler: Ignore options without kernel
Samuel Mendoza-Jonas [Wed, 6 Jul 2016 06:05:46 +0000 (16:05 +1000)]
discover/device-handler: Ignore options without kernel

All boot options must at least have a boot image; ignore any options
that do not before trying to resolve them.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoui/ncurses: Properly set focus when updating subset
Samuel Mendoza-Jonas [Wed, 13 Jul 2016 06:43:22 +0000 (16:43 +1000)]
ui/ncurses: Properly set focus when updating subset

When a subset widget is made empty focus is switched to the first
visible field. It should actually be set to the first visible and active
field, otherwise we can try to focus an un-selectable label.

While we're here, also properly set the visibility for the autoboot
enable/disable widget.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoui/ncurses: Update keybindings for subsets
Samuel Mendoza-Jonas [Tue, 12 Jul 2016 04:18:18 +0000 (14:18 +1000)]
ui/ncurses: Update keybindings for subsets

We now use KEY_LEFT and KEY_RIGHT for general navigation; update
subset_process_key() to use the following keybindings:

Reorder items up/down: Minus/Plus keys (-/+)
Delete item: Delete or Backspace

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoui/ncurses: define KEY_DC (delete key)
Samuel Mendoza-Jonas [Tue, 12 Jul 2016 06:24:20 +0000 (16:24 +1000)]
ui/ncurses: define KEY_DC (delete key)

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoutils/hooks: Set linux,stdout-path for primary console v1.2.0
Samuel Mendoza-Jonas [Tue, 7 Jun 2016 06:25:09 +0000 (16:25 +1000)]
utils/hooks: Set linux,stdout-path for primary console

If the boot_tty environment variable is set, determine which device path
to set in the linux,stdout-path property, which will instruct the next
kernel to use it as the primary console.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoui/ncurses: List available consoles in nc-config
Samuel Mendoza-Jonas [Wed, 8 Jun 2016 04:11:10 +0000 (14:11 +1000)]
ui/ncurses: List available consoles in nc-config

Include a list of available consoles as specified by the discover server
in nc-config from which the user can select a default. The selected
console specifies the which console to be set as the primary console
when a kernel is kexec'd.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoui/common: Set current console on boot command
Samuel Mendoza-Jonas [Wed, 8 Jun 2016 04:10:28 +0000 (14:10 +1000)]
ui/common: Set current console on boot command

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/boot: Set boot_tty variable before kexec
Samuel Mendoza-Jonas [Wed, 8 Jun 2016 03:51:37 +0000 (13:51 +1000)]
discover/boot: Set boot_tty variable before kexec

If boot_tty is set or a boot command is sent manually from a certain
console, set the boot_tty environment variable to be used by a boot hook
before kexec.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover: Add petitboot,tty and track available consoles
Samuel Mendoza-Jonas [Wed, 8 Jun 2016 03:51:28 +0000 (13:51 +1000)]
discover: Add petitboot,tty and track available consoles

Add the NVRAM parameter petitboot,tty which sets the default console to
use when booting a kernel.
In load_config() construct a list of available consoles depending on the
current platform. A future patch depending on firmware changes will
allow this list to be constructed dynamically.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agolib: Add support for tracking boot consoles
Samuel Mendoza-Jonas [Tue, 7 Jun 2016 06:23:52 +0000 (16:23 +1000)]
lib: Add support for tracking boot consoles

Add tty_list and boot_tty to the config struct to keep track of
available console interfaces and the default console to set as primary
respectively.
Also add a tty field to the boot_command struct so that the current
console can be sent to the discover server during a manual boot command.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/pxe-parser: Retrieve configs asynchronously
Samuel Mendoza-Jonas [Mon, 16 May 2016 06:06:30 +0000 (16:06 +1000)]
discover/pxe-parser: Retrieve configs asynchronously

Depending on the configuration of the DHCP server and the network, tftp
requests made by the pxe parser can timeout. The pxe parser makes these
requests synchronously so several timeouts can block the server
completely for several minutes, leaving the server unresponsive to UI
requests.

Rework the pxe parser such that it handles the result of each tftp
request in a callback, which can complete after iterate_parsers() has
returned. Each callback is allocated its own conf_context which takes a
talloc reference on the discover_context so that each callback can
commit new boot options after the initial iterate loop has completed.
This also means talloc_unlink must be used instead by the original
parent of the discover_context.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoUpdate tests to support changes to pxe_parser
Samuel Mendoza-Jonas [Mon, 23 May 2016 05:56:22 +0000 (15:56 +1000)]
Update tests to support changes to pxe_parser

Substitute load_url_async() when running tests to support direct
callers of load_url_async() who will expect to read a file in a
callback.
Stub out device_handler_discover_context_commit() since it will remove
discover_options from the given discover_context, but the tests will
check the discover_context to count boot_options.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/device-handler: Make boot_status() public
Samuel Mendoza-Jonas [Thu, 9 Jun 2016 01:47:20 +0000 (11:47 +1000)]
discover/device-handler: Make boot_status() public

Rename boot_status() to device_handler_boot_status() and make it
accessible by files that include device-handler.h. This enables the boot
status to be updated from additional callers, in particular within
parser functions.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agolib/pb-config: Properly initialise interface_config
Samuel Mendoza-Jonas [Mon, 27 Jun 2016 04:42:29 +0000 (14:42 +1000)]
lib/pb-config: Properly initialise interface_config

The addition of the "url" field is not reflected in
config_copy_interface() which leaves the pointer uninitialised, causing
a potential segfault later on.

Copy the field from the source config, and use talloc_zero() for the
interface_config struct to prevent this more generally.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/platform-powerpc: Return bootdev error correctly v1.1.1
Samuel Mendoza-Jonas [Wed, 1 Jun 2016 06:39:18 +0000 (16:39 +1000)]
discover/platform-powerpc: Return bootdev error correctly

In one case get_ipmi_bootdev_ipmi() can return 0 on an error, which
leads to bootdev being treated as a valid bootdev despite being
uninitialised. If the planets line up correctly and bootdev is less than
or equal to IPMI_BOOTDEV_SETUP, Petitboot will incorrectly apply an IPMI
override.

Update the error return value in get_ipmi_bootdev_ipmi(), and properly
initialise bootdev.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoui/ncurses: Remember to abort boot on server connect
Samuel Mendoza-Jonas [Thu, 26 May 2016 06:08:19 +0000 (16:08 +1000)]
ui/ncurses: Remember to abort boot on server connect

The UI can now come up before the server, but in order for a key press
to cancel autoboot a key has to be pressed once the server connects.
Instead remember to cancel autoboot if a key has been pressed at any
point.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoutils: Add diagnostic script v1.1.0
Samuel Mendoza-Jonas [Thu, 28 May 2015 04:02:34 +0000 (14:02 +1000)]
utils: Add diagnostic script

Add a simple script to gather up useful information in the unlikely
event a user runs into trouble.

Usage:
pb-sos [-v] [-f file] [-d user@host:/path]

Options
 -v verbose output
 -f file Supply filename for tar archive (default pb-sos.tar)
 -d host Supply user, hostname, and path to transfer archive to a
remote host

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoExtend the "add url" function to allow file:// URLs
Samuel Mendoza-Jonas [Wed, 4 May 2016 05:06:45 +0000 (15:06 +1000)]
Extend the "add url" function to allow file:// URLs

This allows URLs of the form file:///path/to/local/file.conf to be used
in nc-add-url, in order to access configuration files relative
to the root directory. This is primarily a debugging tool aimed at
developers rather than an expected use case.

The DEVICE_TYPE_ANY enum is used in this case to represent that a
resulting boot option is not associated with any device in the
traditional sense, and in the UI is represented as a "Custom Local
Option".

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoui/ncurses: Interpret left/right keys as up/down
Samuel Mendoza-Jonas [Mon, 9 May 2016 01:41:30 +0000 (11:41 +1000)]
ui/ncurses: Interpret left/right keys as up/down

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agopb-discover: add dtb support for PXE config
Oliver O'Halloran [Mon, 9 May 2016 05:38:47 +0000 (15:38 +1000)]
pb-discover: add dtb support for PXE config

Currently there is no way to manually specify a DTB file when with a PXE
network boot configuration file. This makes it difficult when you need
to work with or emulate a special snowflake machines with special snowflake
hardware.

Some ARM systems provide this feature with the "fdt" option so this patch
adds support for using the ftd or dtb configuration options to the PXE
config parser.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agolib/flash: fix resource leak in flash_setup_buffer() error paths
Andrew Donnellan [Wed, 4 May 2016 01:22:57 +0000 (11:22 +1000)]
lib/flash: fix resource leak in flash_setup_buffer() error paths

Some error paths in flash_setup_buffer() fail to free the flash_info struct
or close the open ffs before they return. Change them to goto the cleanup
code at the end. Separate the cleanup code into separate labels depending
on whether we need to call ffs_close(), arch_flash_close() and
talloc_free().

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agopb-event: Add 'boot' user event
Samuel Mendoza-Jonas [Fri, 22 Apr 2016 04:20:49 +0000 (14:20 +1000)]
pb-event: Add 'boot' user event

Add a user event to send a boot command to the discover server.
The format of the boot command is similar to the add command, eg:

pb-event boot@eth0 image="http://host/image" initrd="http://host/initrd"

and also recognises "id", "dtb", and "args" arguments.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agopb-console: Reduce kernel log output before starting UI
Samuel Mendoza-Jonas [Mon, 2 May 2016 03:54:54 +0000 (13:54 +1000)]
pb-console: Reduce kernel log output before starting UI

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoui/ncurses: Start UI before connected to server
Samuel Mendoza-Jonas [Mon, 2 May 2016 03:18:39 +0000 (13:18 +1000)]
ui/ncurses: Start UI before connected to server

If petitboot-nc starts before the discover server it will try to
connect for a short while waiting for the server to appear. However in
some scenarios the server can take longer than expected to come up, for
example if the kernel is compiled with modules and the system has many
disks, and the process will timeout and exit before the server is ready.
The UI does not appear during this time so it can appear as if Petitboot
failed to start at all.

Change the default behaviour to start the UI first, and then wait for
the server to appear. The UI will not timeout in this mode. The
"--timeout" option is added to start with the old behaviour.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoui: Fix typo: 'deamon' -> 'daemon'
Samuel Mendoza-Jonas [Mon, 2 May 2016 03:18:31 +0000 (13:18 +1000)]
ui: Fix typo: 'deamon' -> 'daemon'

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/platform-powerpc: Zero-pad BMC aux-version v1.0.1
Samuel Mendoza-Jonas [Fri, 22 Apr 2016 01:43:15 +0000 (11:43 +1000)]
discover/platform-powerpc: Zero-pad BMC aux-version

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/grub2: Do not set $0 in functions
Alan Dunn [Wed, 2 Mar 2016 16:59:04 +0000 (08:59 -0800)]
discover/grub2: Do not set $0 in functions

GRUB2 does not set $0 in functions, so don't set it in our GRUB2
script parser.  (As it doesn't have a value in GRUB2 scripts, probably
no GRUB2 script depends on the value of $0.)  Additionally, dash and
bash set environment variable 0 to the name of the script (even in
functions), so the current behavior of $0 doesn't really match shell
scripts either.

Tested:
 Existing tests pass.

Signed-off-by: Alan Dunn <amdunn@google.com>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoAllow evaluation of arbitrarily-positioned arguments in GRUB2 parser
Alan Dunn [Wed, 2 Mar 2016 16:59:03 +0000 (08:59 -0800)]
Allow evaluation of arbitrarily-positioned arguments in GRUB2 parser

GRUB2 allows essentially arbitrary numbers of positional arguments, so
ensure that they can be evaluated within scripts.  GRUB2 also appears
to support arbitrary numbers of leading 0's in positional parameters
(i.e., $01 should evalute the same as $1), but this doesn't seem like
a particularly important case to support.

Tested:
 Modified test-grub2-pos-param to cover higher-numbered positional
 arguments.

Signed-off-by: Alan Dunn <amdunn@google.com>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoFix sparse warnings
Andrew Donnellan [Mon, 18 Apr 2016 07:05:12 +0000 (17:05 +1000)]
Fix sparse warnings

Fix some sparse warnings by using NULL instead of 0 and static-ifying a
variable not used outside its file.

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoui/ncurses: Increase timeout when waiting for pb-discover
Samuel Mendoza-Jonas [Wed, 20 Apr 2016 04:29:00 +0000 (14:29 +1000)]
ui/ncurses: Increase timeout when waiting for pb-discover

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/udev: Don't call udev_set_log_fn()
Samuel Mendoza-Jonas [Fri, 8 Apr 2016 06:31:36 +0000 (16:31 +1000)]
discover/udev: Don't call udev_set_log_fn()

As of libudev 218 udev_set_log_fn() is deprecated, causing a
-Wdeprecated-declarations warning when building, and is otherwise a
noop.
Add a configure check for libudev, and only call udev_set_log_fn() if
using a version older than 218.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover: Perform pre-boot steps when timeout expires
Samuel Mendoza-Jonas [Wed, 13 Apr 2016 05:07:38 +0000 (15:07 +1000)]
discover: Perform pre-boot steps when timeout expires

When a default boot timeout expires boot() is called via
default_timeout() rather than device_handler_boot(). default_timeout()
doesn't call platform_pre_boot() beforehand, which means steps such as
clearing a temporary boot device override are skipped.
Add a call to platform_pre_boot() immediately before boot() to ensure
these steps are performed regardless of boot type.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/devmapper: Read device size from sysfs
Samuel Mendoza-Jonas [Thu, 7 Apr 2016 05:29:02 +0000 (15:29 +1000)]
discover/devmapper: Read device size from sysfs

If udev doesn't export the ID_PART_ENTRY_SIZE variable for a device we
skip creating a snapshot for it. However in most cases the sysfs
attribute which udev reads to find ID_PART_ENTRY_SIZE is still
available. Therefore if we don't have access to ID_PART_ENTRY_SIZE try
to find the size in sysfs directly.
This allows us to create snapshots for devices which often don't have
this udev variable set, such as software raid (md) devices and NVMe
devices.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoconfigure.ac: Add checks for libflash and libdevmapper
Samuel Mendoza-Jonas [Tue, 5 Apr 2016 04:46:14 +0000 (14:46 +1000)]
configure.ac: Add checks for libflash and libdevmapper

libdevmapper is a hard dependency since snapshots were introduced, so
add an unconditional configure-time check for it.
Also add a check for libflash library and headers if --enable-mtd is
set.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoui/ncurses: Disable autoboot if boot list is empty
Samuel Mendoza-Jonas [Mon, 4 Apr 2016 05:14:07 +0000 (15:14 +1000)]
ui/ncurses: Disable autoboot if boot list is empty

If an empty boot order is saved disable autoboot. However don't set
autoboot_enabled to false by clearing the list, as this will hide the
list when it is likely the user wants to make changes.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoui/ncurses: Define extra key codes encountered in QEMU
Samuel Mendoza-Jonas [Thu, 31 Mar 2016 03:03:08 +0000 (14:03 +1100)]
ui/ncurses: Define extra key codes encountered in QEMU

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agoversion.sh: Fix in-tree case and allow external variables
Samuel Mendoza-Jonas [Mon, 4 Apr 2016 03:23:43 +0000 (13:23 +1000)]
version.sh: Fix in-tree case and allow external variables

"$(basename $0)" would return the name of the script, when what is
needed is the name of the directory; use 'dirname' instead.
If PETITBOOT_VERSION is set, as in a buildroot environment, use this
variable instead of the default case.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/grub2: Ignore sign-compare warning for generated code
Samuel Mendoza-Jonas [Fri, 1 Apr 2016 00:38:19 +0000 (11:38 +1100)]
discover/grub2: Ignore sign-compare warning for generated code

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover: Respect persistent flag for network overrides v1.0.0
Samuel Mendoza-Jonas [Mon, 21 Mar 2016 05:35:05 +0000 (16:35 +1100)]
discover: Respect persistent flag for network overrides

If the persistent bit is set in a IPMI network override, overwrite any
existing interface config in NVRAM with the new network override.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/device-handler: Attempt to retry failed mounts
Sam Mendoza-Jonas [Tue, 15 Mar 2016 05:30:17 +0000 (16:30 +1100)]
discover/device-handler: Attempt to retry failed mounts

Commit 6c1a9dd, "discover: Allow fs recovery if snapshot available",
forced the use of 'norecovery' for all XFS mounts to avoid failing when
a cross-endian journal existed. This is a bit heavy handed, healthy XFS
file systems can still be safely mounted, as can dirty filesystems in
the same endian as Petitboot.

This adds try_mount() which opportunistically mounts devices and falls
back to using 'norecovery' where possible on failure. This enables XFS
filesystems to be mounted read-write when possible. try_mount() contains
the logic previously described by fs_parameters(), and should be used in
place of any existing calls to mount().

Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
8 years agopo: Update Makevars to match Makevars.template
Samuel Mendoza-Jonas [Mon, 21 Mar 2016 00:15:29 +0000 (11:15 +1100)]
po: Update Makevars to match Makevars.template

When building under buildroot the following message appears:

"Please update po/Makevars so that it defines all the variables
mentioned in po/Makevars.template."

Update Makevars to include definitions for these extra variables, and
set MSGMERGE_OPTIONS to --add-location=never to avoid adding noise to
the .po files.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/boot: Safely cleanup after failed load
Sam Mendoza-Jonas [Tue, 15 Mar 2016 02:35:21 +0000 (13:35 +1100)]
discover/boot: Safely cleanup after failed load

If a call to load_url_async() fails immediately, boot() will free the
boot task and return. If other jobs started by load_url_async()
are still running they will attempt to free their task struct in
load_url_process_exit(), however the original boot task is the parent
context of this process task, resulting in a double-free.

Instead call cleanup_cancellations if an error immediately occurs to
cancel any pending load operations safely before freeing the boot task.

Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
8 years agoui/ncurses: Re-add autoboot selection to config screen
Sam Mendoza-Jonas [Fri, 11 Mar 2016 05:11:31 +0000 (16:11 +1100)]
ui/ncurses: Re-add autoboot selection to config screen

The new boot order interface removed the autoboot enable/disable buttons.
However this means the only way to disable autoboot is to remove all
options from the boot order list, or know that you can manually set the
`auto-boot?` flag in nvram.

This re-introduces an autoboot enable/disable widget so that autoboot
can be disabled without losing an existing boot order. The translated
strings for "Autoboot" are salvaged from earlier use, and two new
untranslated strings are introduced.

Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
8 years agotest/lib: Avoid array overflow of child_argv[]
Anton Blanchard [Sun, 3 Jan 2016 10:37:52 +0000 (21:37 +1100)]
test/lib: Avoid array overflow of child_argv[]

We allocate 3 elements in child_argv, but write 4.

Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
8 years agolib/fold: Catch error case from mbrtowc()
Sam Mendoza-Jonas [Thu, 3 Mar 2016 02:31:18 +0000 (13:31 +1100)]
lib/fold: Catch error case from mbrtowc()

The assert() statement in fold_text() only evaluates in a debug build.
If mbrtowc() encounters an error return the portion of the string that
has been parsed and stop.

This avoids an issue with glibc 2.22 where previous calls to
setlocale() failed and set an unsuitable locale. Since the error was not
caught this resulted in an infinite loop when trying to access the
Language screen.

Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
8 years agoui/ncurses: Check wcstombs() for error in nc-lang
Sam Mendoza-Jonas [Wed, 2 Mar 2016 04:36:36 +0000 (15:36 +1100)]
ui/ncurses: Check wcstombs() for error in nc-lang

If we are unable to correctly parse wide-character strings for display
in the Language screen (eg. due to an incorrect locale) display an
error string instead of continuing to try to display the string.

Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover/grub2: Fix handling of positional parameters
Alan Dunn [Wed, 2 Mar 2016 16:59:02 +0000 (08:59 -0800)]
discover/grub2: Fix handling of positional parameters

Positional parameters are set in the environment with '$' prepended to
the name.  This causes lookups to fail because parameter lookups don't
include the '$'.

TESTED:
 Added a test that covers positional parameters in GRUB2 parser.
 Build succeeds, tests pass.

Bootstrapped-by: Nancy Yuen <yuenn@google.com>
Signed-off-by: Alan Dunn <amdunn@google.com>
Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
8 years agoChange parser interface to allow stat
Alan Dunn [Wed, 24 Feb 2016 16:12:25 +0000 (08:12 -0800)]
Change parser interface to allow stat

Currently, the GRUB2 parser incorrectly reports "[ -f <path> ]" as
false if the size of the file is above 1 MB.  This patch changes the
parser interface to allow stating files (with parser_stat_file).  Then
in the implementation of "[ -f <path> ]", we can use parser_stat_file
instead of parser_request_file which has the size limitation.  I
eliminate parser_check_dir in lieu of this new interface, which has
the side effect of making "[ -d <path> ]" work (the error code for
stat was not checked correctly before).

I add a basic test for the test file operations -f, -s, and -d (to
show that my changes to test file operations do not break them) and
minorly modify the test framework to ensure it has enough fidelity to
cause the expected results.  Unfortunately the test wouldn't have
caught the issue with -d, since the test framework stubs out the
parser interface itself.  Nor can the test framework catch the initial
problem with -f because the imposed limit is (transitively) in
function parser_request_file.

Note that -f and -d follow symlinks despite the fact that GRUB does
not (see
http://lists.gnu.org/archive/html/grub-devel/2016-02/msg00142.html
discussing GRUB's behavior).  This is not a change to Petitboot's
behavior though.

Tested:
 The test test-grub2-test-file-ops passes.  I booted Petitboot against
 a GRUB snippet:

status=success

if [ ! -f /large_file -a $status = success ]
then status=fail_large_file
fi
if [ ! -d /a_directory -a $status = success ]
then status=fail_dir
fi

menuentry $status {
  linux /vmlinux
}

 (after making /large_file a file of size > 1 MiB and /a_directory a
 directory) and the menuentry had title "success", as desired.

Signed-off-by: Alan Dunn <amdunn@google.com>
Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
8 years agoIn GRUB2 parser save_env, treat unset variable value as empty
Alan Dunn [Tue, 15 Mar 2016 00:40:47 +0000 (17:40 -0700)]
In GRUB2 parser save_env, treat unset variable value as empty

It seems better to treat unset variable values as empty rather than
crashing in save_env.  While GRUB's behavior is actually to delete the
variable from the environment block, it seems useful to at least not
crash while later on someone can do further work to improve GRUB
compatibility if desired.

Tested:
 Modified test-grub2-save-env to cover this case.

Signed-off-by: Alan Dunn <amdunn@google.com>
Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
8 years agopo: Update help string and add untranslated strings
Sam Mendoza-Jonas [Sun, 6 Mar 2016 23:42:46 +0000 (10:42 +1100)]
po: Update help string and add untranslated strings

Update the nc-lang help string translation to reflect the change
introduced in the previous commit, "Remove "h=help" hint in language page".
Also update each .po file with any new strings lacking a translation.

Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
8 years agoMerge pull request #13 from johnhihi/master
Sam Mendoza-Jonas [Sun, 6 Mar 2016 23:52:06 +0000 (10:52 +1100)]
Merge pull request #13 from johnhihi/master

Remove "h=help" hint in language page

8 years agolib/flash: Fix version side being interpreted backwards
Sam Mendoza-Jonas [Fri, 4 Mar 2016 23:20:33 +0000 (10:20 +1100)]
lib/flash: Fix version side being interpreted backwards

Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
8 years agoRemove "h=help" hint in language page
Johnny [Wed, 2 Mar 2016 07:52:22 +0000 (15:52 +0800)]
Remove "h=help" hint in language page

Signed-off-by: Johnny <johnny.cl.chang@foxconn.com>
8 years agoUse 'Primary' instead of 'Current' for flash sides
Sam Mendoza-Jonas [Thu, 25 Feb 2016 23:39:55 +0000 (10:39 +1100)]
Use 'Primary' instead of 'Current' for flash sides

When queried libflash will return the 'first' flash side (ie. the one
with the lowest TOC address), however we label this the 'Current' side
which is incorrect if the machine has booted from the alternate side.

A future fix will inlcude additional platform logic to determine which
flash side is current; in the interim label the first flash side as
'Primary' instead of 'Current'.

Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover: Include leading zero in firmware version string
Sam Mendoza-Jonas [Wed, 24 Feb 2016 23:40:59 +0000 (10:40 +1100)]
discover: Include leading zero in firmware version string

Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
8 years agodiscover: Add support for IPMI network override
Sam Mendoza-Jonas [Mon, 15 Feb 2016 05:47:01 +0000 (16:47 +1100)]
discover: Add support for IPMI network override

On BMC platforms the 'Get System Boot Options' command can also be used
to check for a temporary network interface config override. This is
implemented via the optional 'OEM Parameters' field defined in the IPMI
v2 spec. We define the actual format of the field as:
- 4 byte cookie value
- 2 byte version value
- 1 byte hardware address size
- 1 byte IP address size
- Hardware address
- 1 byte flags for 'ignore' and 'method'
And for static configs:
- IP Address
- 1 byte subnet value
- Gateway address

If set the config override replaces any other interface config, forcing
the use of the specified configuration.

Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
8 years agoutils/hooks: Write offb device address to device tree
Sam Mendoza-Jonas [Tue, 22 Dec 2015 02:39:28 +0000 (10:39 +0800)]
utils/hooks: Write offb device address to device tree

On OpenPOWER machines, kernels missing the AST video driver can use the
existing 'Open Firmware' framebuffer device code to inherit an existing
framebuffer from Petitboot. This requires us to translate the 64-bit
address of the framebuffer 'back' into a PCI address and write it into
an assigned-addresses property in the device tree.

Bootstrapped-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>