diff mbox series

[1/4] boot: pxe_utils: Add fallback support

Message ID 20241002132633.246942-1-martyn.welch@collabora.com
State New
Delegated to: Tom Rini
Headers show
Series [1/4] boot: pxe_utils: Add fallback support | expand

Commit Message

Martyn Welch Oct. 2, 2024, 1:26 p.m. UTC
When configured correctly, we can detect when boot fails after the boot
process has been handed over to the kernel through the use of U-Boot's
bootcount support. In some instances, such as when we are performing
atomic updates via a system such as OSTree, it is desirable to provide a
fallback option so that we can return to a previous (hopefully working)
state.

Add a "fallback" option to the supported extlinux configuration options
that points to a label like "default" so that we can utilise this in
later commits.

Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
---
 boot/pxe_utils.c    | 15 +++++++++++++++
 doc/README.pxe      |  5 +++++
 include/pxe_utils.h |  2 ++
 3 files changed, 22 insertions(+)

Comments

Tom Rini Oct. 2, 2024, 7:16 p.m. UTC | #1
On Wed, Oct 02, 2024 at 02:26:30PM +0100, Martyn Welch wrote:
> When configured correctly, we can detect when boot fails after the boot
> process has been handed over to the kernel through the use of U-Boot's
> bootcount support. In some instances, such as when we are performing
> atomic updates via a system such as OSTree, it is desirable to provide a
> fallback option so that we can return to a previous (hopefully working)
> state.
> 
> Add a "fallback" option to the supported extlinux configuration options
> that points to a label like "default" so that we can utilise this in
> later commits.
> 
> Signed-off-by: Martyn Welch <martyn.welch@collabora.com>

Is "fallback" part of the nominal extlinux specification?
Martyn Welch Oct. 3, 2024, 9 a.m. UTC | #2
On Wed, 2024-10-02 at 13:16 -0600, Tom Rini wrote:
> On Wed, Oct 02, 2024 at 02:26:30PM +0100, Martyn Welch wrote:
> > When configured correctly, we can detect when boot fails after the
> > boot
> > process has been handed over to the kernel through the use of U-
> > Boot's
> > bootcount support. In some instances, such as when we are
> > performing
> > atomic updates via a system such as OSTree, it is desirable to
> > provide a
> > fallback option so that we can return to a previous (hopefully
> > working)
> > state.
> > 
> > Add a "fallback" option to the supported extlinux configuration
> > options
> > that points to a label like "default" so that we can utilise this
> > in
> > later commits.
> > 
> > Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
> 
> Is "fallback" part of the nominal extlinux specification?
> 

When looking at options to implement this functionality, I did spend
some time looking for an extlinux specification. The best I could find
was:

https://wiki.syslinux.org/wiki/index.php

Putting aside the difference in syntax from that used by the syslinux
project, of the 22 keywords currently supported by U-Boot, only 13 of
them are mentioned there (surprisingly the syslinux documentation
doesn't include "title" as an option).

I'd come to the conclusion that U-Boot already provides a greatly
extended version of the syntax, made suitable for booting in a wider
variety of instances than catered for by the syslinux project.

Though I admit, I could have missed another better source to
documentation. Is that the one you're thinking of or is there a better
one?

Martyn
Tom Rini Oct. 3, 2024, 2:39 p.m. UTC | #3
On Thu, Oct 03, 2024 at 10:00:33AM +0100, Martyn Welch wrote:
> On Wed, 2024-10-02 at 13:16 -0600, Tom Rini wrote:
> > On Wed, Oct 02, 2024 at 02:26:30PM +0100, Martyn Welch wrote:
> > > When configured correctly, we can detect when boot fails after the
> > > boot
> > > process has been handed over to the kernel through the use of U-
> > > Boot's
> > > bootcount support. In some instances, such as when we are
> > > performing
> > > atomic updates via a system such as OSTree, it is desirable to
> > > provide a
> > > fallback option so that we can return to a previous (hopefully
> > > working)
> > > state.
> > > 
> > > Add a "fallback" option to the supported extlinux configuration
> > > options
> > > that points to a label like "default" so that we can utilise this
> > > in
> > > later commits.
> > > 
> > > Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
> > 
> > Is "fallback" part of the nominal extlinux specification?
> > 
> 
> When looking at options to implement this functionality, I did spend
> some time looking for an extlinux specification. The best I could find
> was:
> 
> https://wiki.syslinux.org/wiki/index.php
> 
> Putting aside the difference in syntax from that used by the syslinux
> project, of the 22 keywords currently supported by U-Boot, only 13 of
> them are mentioned there (surprisingly the syslinux documentation
> doesn't include "title" as an option).
> 
> I'd come to the conclusion that U-Boot already provides a greatly
> extended version of the syntax, made suitable for booting in a wider
> variety of instances than catered for by the syslinux project.
> 
> Though I admit, I could have missed another better source to
> documentation. Is that the one you're thinking of or is there a better
> one?

I was thinking of https://systemd.io/BOOT_LOADER_SPECIFICATION/ which is
now https://uapi-group.org/specifications/specs/boot_loader_specification/
and only has 11 keywords. So, yeah, I guess this is another place where
we'll keep doing what's needed to make things more useful and see what
happens down the road. I'm fine with what's being added in this series.
Thanks!
diff mbox series

Patch

diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
index 4e27842b08..a80119c9a3 100644
--- a/boot/pxe_utils.c
+++ b/boot/pxe_utils.c
@@ -781,6 +781,7 @@  enum token_type {
 	T_IPAPPEND,
 	T_BACKGROUND,
 	T_KASLRSEED,
+	T_FALLBACK,
 	T_INVALID
 };
 
@@ -814,6 +815,7 @@  static const struct token keywords[] = {
 	{"ipappend", T_IPAPPEND,},
 	{"background", T_BACKGROUND,},
 	{"kaslrseed", T_KASLRSEED,},
+	{"fallback", T_FALLBACK,},
 	{NULL, T_INVALID}
 };
 
@@ -1356,6 +1358,18 @@  static int parse_pxefile_top(struct pxe_context *ctx, char *p, unsigned long bas
 
 			break;
 
+		case T_FALLBACK:
+			err = parse_sliteral(&p, &label_name);
+
+			if (label_name) {
+				if (cfg->fallback_label)
+					free(cfg->fallback_label);
+
+				cfg->fallback_label = label_name;
+			}
+
+			break;
+
 		case T_INCLUDE:
 			err = handle_include(ctx, &p,
 					     base + ALIGN(strlen(b), 4), cfg,
@@ -1395,6 +1409,7 @@  void destroy_pxe_menu(struct pxe_menu *cfg)
 
 	free(cfg->title);
 	free(cfg->default_label);
+	free(cfg->fallback_label);
 
 	list_for_each_safe(pos, n, &cfg->labels) {
 		label = list_entry(pos, struct pxe_label, list);
diff --git a/doc/README.pxe b/doc/README.pxe
index 172201093d..af2e64a577 100644
--- a/doc/README.pxe
+++ b/doc/README.pxe
@@ -120,6 +120,11 @@  Unrecognized commands are ignored.
 default <label>	    - the label named here is treated as the default and is
 		      the first label 'pxe boot' attempts to boot.
 
+fallback <label>    - the label named here is treated as a fallback option that
+		      may be attempted should it be detected that booting of
+		      the default has failed to complete, for example via
+		      U-Boot's boot count limit functionality.
+
 menu title <string> - sets a title for the menu of labels being displayed.
 
 menu include <path> - use tftp to retrieve the pxe file at <path>, which
diff --git a/include/pxe_utils.h b/include/pxe_utils.h
index 9f19593048..a408fb7f13 100644
--- a/include/pxe_utils.h
+++ b/include/pxe_utils.h
@@ -62,6 +62,7 @@  struct pxe_label {
  *
  * title - the name of the menu as given by a 'menu title' line.
  * default_label - the name of the default label, if any.
+ * fallback_label - the name of the fallback label, if any.
  * bmp - the bmp file name which is displayed in background
  * timeout - time in tenths of a second to wait for a user key-press before
  *           booting the default label.
@@ -73,6 +74,7 @@  struct pxe_label {
 struct pxe_menu {
 	char *title;
 	char *default_label;
+	char *fallback_label;
 	char *bmp;
 	int timeout;
 	int prompt;