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 <[email protected]> --- 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
