From: Bin Meng Date: Tue, 26 Sep 2023 08:43:33 +0000 (+0800) Subject: blk: sandbox: Support binding a device with a given logical block size X-Git-Url: http://git.dujemihanovic.xyz/img/static/git-favicon.png?a=commitdiff_plain;h=8897faba2d1d2e6802cd066580100685baa46f7f;p=u-boot.git blk: sandbox: Support binding a device with a given logical block size Allow optionally set the logical block size of the host device to bind in the "host bind" command. If not given, defaults to 512. Signed-off-by: Bin Meng --- diff --git a/cmd/host.c b/cmd/host.c index b924940ffb..2334ccd9bc 100644 --- a/cmd/host.c +++ b/cmd/host.c @@ -13,6 +13,7 @@ #include #include #include +#include static int do_host_load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) @@ -45,6 +46,7 @@ static int do_host_bind(struct cmd_tbl *cmdtp, int flag, int argc, struct udevice *dev; const char *label; char *file; + unsigned long blksz = DEFAULT_BLKSZ; int ret; /* Skip 'bind' */ @@ -59,12 +61,19 @@ static int do_host_bind(struct cmd_tbl *cmdtp, int flag, int argc, argv++; } - if (argc != 2) + if (argc < 2 || argc > 3) return CMD_RET_USAGE; label = argv[0]; file = argv[1]; + if (argc > 2) { + blksz = dectoul(argv[2], NULL); + if (blksz < DEFAULT_BLKSZ || !is_power_of_2(blksz)) { + printf("blksz must be >= 512 and power of 2\n"); + return CMD_RET_FAILURE; + } + } - ret = host_create_attach_file(label, file, removable, &dev); + ret = host_create_attach_file(label, file, removable, blksz, &dev); if (ret) { printf("Cannot create device / bind file\n"); return CMD_RET_FAILURE; @@ -253,7 +262,8 @@ U_BOOT_CMD( "host save hostfs - [] - " "save a file to host\n" "host size hostfs - - determine size of file on host\n" - "host bind [-r]