aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorBin Meng <bmeng@tinylab.org>2023-09-26 16:43:33 +0800
committerTom Rini <trini@konsulko.com>2023-10-10 16:19:43 -0400
commit8897faba2d1d2e6802cd066580100685baa46f7f (patch)
tree2589c2bb478a4c1f50c5b4e6d0f6fdf3c616406b /cmd
parent77ca9d74571e92969591d39df134ccd72296f4d9 (diff)
downloadu-boot-8897faba2d1d2e6802cd066580100685baa46f7f.zip
u-boot-8897faba2d1d2e6802cd066580100685baa46f7f.tar.gz
u-boot-8897faba2d1d2e6802cd066580100685baa46f7f.tar.bz2
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 <bmeng@tinylab.org>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/host.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/cmd/host.c b/cmd/host.c
index b924940..2334ccd 100644
--- a/cmd/host.c
+++ b/cmd/host.c
@@ -13,6 +13,7 @@
#include <dm/device-internal.h>
#include <dm/uclass-internal.h>
#include <linux/errno.h>
+#include <linux/log2.h>
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 - <addr> <filename> <bytes> [<offset>] - "
"save a file to host\n"
"host size hostfs - <filename> - determine size of file on host\n"
- "host bind [-r] <label> <filename> - bind \"host\" device to file\n"
+ "host bind [-r] <label> <filename> [<blksz>] - bind \"host\" device to file,\n"
+ " and optionally set the device's logical block size\n"
" -r = mark as removable\n"
"host unbind <label> - unbind file from \"host\" device\n"
"host info [<label>] - show device binding & info\n"