mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] commands: boot: create boot entries on demand
Date: Wed, 12 Feb 2020 15:16:38 +0100	[thread overview]
Message-ID: <20200212141638.11114-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20200212141638.11114-1-a.fatoum@pengutronix.de>

We currently create all boot entries before attempting boot. This is
less than optimal, because this may involve probing devices that won't
be used for actual boot.

Fix this by not creating boot entries till the previous boot argument
(command line argument or boot.default word) was found to be unbootable.

This means that "boot mmc1 mmc0" will now not touch mmc0 if mmc1 had a
bootable entry. This is only done when no menu or list was requested.

As the boot entries are in a linked list, the allocation done for each
boot argument could be omitted, but as the saving from skipping an
allocation is easily dwarfed by the boot medium access, we just
reallocate and enjoy the improved code clarity.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 commands/boot.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/commands/boot.c b/commands/boot.c
index ce4eeac6534c..aeaba3992e1d 100644
--- a/commands/boot.c
+++ b/commands/boot.c
@@ -90,6 +90,18 @@ static int do_boot(int argc, char *argv[])
 		ret = bootentry_create_from_name(entries, name);
 		if (ret <= 0)
 			printf("Nothing bootable found on '%s'\n", name);
+
+		if (do_list || do_menu)
+			continue;
+
+		bootentries_for_each_entry(entries, entry) {
+			ret = boot_entry(entry, verbose, dryrun);
+			if (!ret)
+				break;
+		}
+
+		bootentries_free(entries);
+		entries = bootentries_alloc();
 	}
 
 	if (list_empty(&entries->entries)) {
@@ -107,12 +119,6 @@ static int do_boot(int argc, char *argv[])
 		goto out;
 	}
 
-	bootentries_for_each_entry(entries, entry) {
-		ret = boot_entry(entry, verbose, dryrun);
-		if (!ret)
-			break;
-	}
-
 out:
 	bootentries_free(entries);
 	free(freep);
-- 
2.25.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2020-02-12 14:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-12 14:16 [PATCH 1/2] commands: boot: refactor boot entry creation to use iterators Ahmad Fatoum
2020-02-12 14:16 ` Ahmad Fatoum [this message]
2020-02-14  7:56 ` Sascha Hauer
2020-02-14  8:12   ` Ahmad Fatoum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200212141638.11114-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox