From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Sohaib Mohamed <sohaib.amhmd@gmail.com>
Subject: [PATCH] environment: prefer non-removable over removable devices for autoprobe
Date: Thu, 27 Nov 2025 13:41:34 +0100 [thread overview]
Message-ID: <20251127124140.2229718-1-a.fatoum@pengutronix.de> (raw)
From: Ahmad Fatoum <a.fatoum@barebox.org>
On systems with only 1-2 MiB of boot flash, it can be sensible to locate
the barebox environment outside of the boot medium.
In that case, it's sensible to give preference to non-removable devices,
so e.g. an eMMC is used instead of the SD-Card when booting from
neither, so adapt the scoring accordingly.
This could be further refined to make use of the eMMC non_removable
attribute, but this is already arguably an improvement.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
common/environment.c | 8 ++++++--
include/block.h | 11 +++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/common/environment.c b/common/environment.c
index 62b8120cbd7d..d7f5f51cfc6d 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -104,10 +104,14 @@ static struct cdev *default_environment_path_search(void)
if (IS_ERR(part))
continue;
- score++;
+ /* Prefer eMMC over SD if neither is the boot medium */
+ if (blockdevice_is_removable(blk))
+ score += 1;
+ else
+ score += 2;
if (boot_node && boot_node == blk->cdev.device_node)
- score++;
+ score += 4;
if (score > max_score) {
max_score = score;
diff --git a/include/block.h b/include/block.h
index fc7a0a32fb2d..84c247cee3a3 100644
--- a/include/block.h
+++ b/include/block.h
@@ -82,6 +82,17 @@ static inline int block_flush(struct block_device *blk)
return cdev_flush(&blk->cdev);
}
+static inline bool blockdevice_is_removable(struct block_device *blk)
+{
+ switch (blk->type) {
+ case BLK_TYPE_USB:
+ case BLK_TYPE_SD:
+ return true;
+ default:
+ return false;
+ }
+}
+
#ifdef CONFIG_BLOCK
unsigned file_list_add_blockdevs(struct file_list *files);
char *cdev_get_linux_rootarg(const struct cdev *partcdev);
--
2.47.3
next reply other threads:[~2025-11-27 12:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-27 12:41 Ahmad Fatoum [this message]
2025-11-28 7:08 ` Sascha Hauer
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=20251127124140.2229718-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=sohaib.amhmd@gmail.com \
/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