From: Ahmad Fatoum <[email protected]> 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 <[email protected]> --- 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
