mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] fixup! environment: prefer non-removable over removable devices for autoprobe
@ 2025-12-08 10:32 Ahmad Fatoum
  2025-12-08 12:11 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2025-12-08 10:32 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Instead of ad-hoc determination in an inline function in the header, let
every user decide for itself, it the device is removable or not.

This changes the implementation slightly: SD-Cards with the
non-removable device tree property are now reported as such to the block
layer, whereas before, they were always removable.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/environment.c      |  2 +-
 drivers/mci/mci-core.c    |  4 ++++
 drivers/usb/storage/usb.c |  1 +
 include/block.h           | 12 +-----------
 4 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/common/environment.c b/common/environment.c
index d7f5f51cfc6d..0e551c90352e 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -105,7 +105,7 @@ static struct cdev *default_environment_path_search(void)
 			continue;
 
 		/* Prefer eMMC over SD if neither is the boot medium */
-		if (blockdevice_is_removable(blk))
+		if (blk->removable)
 			score += 1;
 		else
 			score += 2;
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 206147cb93e2..82864d710417 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -2795,6 +2795,10 @@ static int mci_register_partition(struct mci_part *part)
 	part->blk.type = IS_SD(mci) ? BLK_TYPE_SD : BLK_TYPE_MMC;
 	part->blk.rootwait = true;
 
+	part->blk.removable = IS_SD(mci);
+	if (host->non_removable)
+		part->blk.removable = false;
+
 	if (part->area_type == MMC_BLK_DATA_AREA_RPMB)
 		return 0;
 
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index e106174f37d8..b3116dc6e6c2 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -422,6 +422,7 @@ static int usb_stor_add_blkdev(struct us_data *us, unsigned char lun)
 	pblk_dev->blk.cdev.name = basprintf("disk%d", result);
 	pblk_dev->blk.blockbits = SECTOR_SHIFT;
 	pblk_dev->blk.type = BLK_TYPE_USB;
+	pblk_dev->blk.removable = true;
 	pblk_dev->blk.rootwait = true;
 
 	result = blockdevice_register(&pblk_dev->blk);
diff --git a/include/block.h b/include/block.h
index 6810684ff49b..9f388ae67133 100644
--- a/include/block.h
+++ b/include/block.h
@@ -46,6 +46,7 @@ struct block_device {
 	u8 blockbits;
 	u8 type; /* holds enum blk_type */
 	u8 rootwait:1;
+	u8 removable:1;
 	blkcnt_t num_blocks;
 	int rdbufsize;
 	int blkmask;
@@ -82,17 +83,6 @@ 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




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] fixup! environment: prefer non-removable over removable devices for autoprobe
  2025-12-08 10:32 [PATCH] fixup! environment: prefer non-removable over removable devices for autoprobe Ahmad Fatoum
@ 2025-12-08 12:11 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2025-12-08 12:11 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Mon, 08 Dec 2025 11:32:29 +0100, Ahmad Fatoum wrote:
> Instead of ad-hoc determination in an inline function in the header, let
> every user decide for itself, it the device is removable or not.
> 
> This changes the implementation slightly: SD-Cards with the
> non-removable device tree property are now reported as such to the block
> layer, whereas before, they were always removable.
> 
> [...]

Applied, thanks!

[1/1] fixup! environment: prefer non-removable over removable devices for autoprobe
      https://git.pengutronix.de/cgit/barebox/commit/?id=37f8562b571b (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-12-08 12:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-08 10:32 [PATCH] fixup! environment: prefer non-removable over removable devices for autoprobe Ahmad Fatoum
2025-12-08 12:11 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox