mirror of
https://source.denx.de/u-boot/u-boot.git
synced 2026-06-13 15:03:58 +03:00
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>
This commit is contained in:
16
cmd/host.c
16
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"
|
||||
|
||||
Reference in New Issue
Block a user