Merge branch '2023-10-10-blk-sandbox-support-binding-a-device-with-a-given-logical-block-size'

To quote the author:
At present on Sandbox when binding to a host backing file, the host
block device is created with a hard-coded 512 bytes block size.

Such assumption works for most cases, but for situation that with a raw
image file dump from a pre-formatted GPT partitioned disk image from a
4KiB block size device, when binding this file to a host device and mapping
this device to a blkmap, "blkmap" command like "blkmap part" won't work
correctly, due to block size mismatch during parsing the partition table.

This series updates Sandbox block driver, as well as the blkmap driver,
to get rid of the hard-coded 512 bytes block size assumption.

This series is available at u-boot-x86/blk for testing.

Test log (512 block size):

  => host bind 0 test.img
  => host info
  dev       blocks  blksz label           path
    0       262144    512 0               test.img
  => blkmap create 0
  Created "0"
  => blkmap map 0 0 40000 linear host 0 0
  Block 0x0+0x40000 mapped to block 0x0 of "host 0"
  => blkmap info
  Device 0: Vendor: U-Boot Rev: 1.0 Prod: blkmap
              Type: Hard Disk
              Capacity: 128.0 MB = 0.1 GB (262144 x 512)
  => blkmap part

  Partition Map for BLKMAP device 0  --   Partition Type: EFI

  Part    Start LBA       End LBA         Name
          Attributes
          Type GUID
          Partition GUID
    1     0x00000022      0x000000bd      "u-boot-spl"
          attrs:  0x0000000000000000
          type:   5b193300-fc78-40cd-8002-e86c45580b47
                  (5b193300-fc78-40cd-8002-e86c45580b47)
          guid:   0bb6bb6e-4aac-4c27-be03-016b01e7b941
    2     0x00000822      0x00000c84      "u-boot"
          attrs:  0x0000000000000000
          type:   2e54b353-1271-4842-806f-e436d6af6985
                  (2e54b353-1271-4842-806f-e436d6af6985)
          guid:   91d50814-8e31-4cc0-97dc-779e1dc59056
    3     0x00000c85      0x0000cc84      "rootfs"
          attrs:  0x0000000000000004
          type:   0fc63daf-8483-4772-8e79-3d69d8477de4
                  (linux)
          guid:   42799722-6e55-46e6-afa9-529e7af3f03b

Test log (4096 block size):

  => host bind 0 test.img 4096
  => host info
  dev       blocks  blksz label           path
    0        32768   4096 0               test.img
  => blkmap create 0
  Created "0"
  => blkmap map 0 0 8000 linear host 0 0
  Block 0x0+0x8000 mapped to block 0x0 of "host 0"
  => blkmap info
  Device 0: Vendor: U-Boot Rev: 1.0 Prod: blkmap
              Type: Hard Disk
              Capacity: 128.0 MB = 0.1 GB (32768 x 4096)
  => blkmap part

  Partition Map for BLKMAP device 0  --   Partition Type: EFI

  Part    Start LBA       End LBA         Name
          Attributes
          Type GUID
          Partition GUID
    1     0x00000100      0x00001fff      "primary"
          attrs:  0x0000000000000000
          type:   0fc63daf-8483-4772-8e79-3d69d8477de4
                  (linux)
          guid:   eba904d7-72c1-4dbd-bb4e-36be49cba5e3
    2     0x00002000      0x00007ffa      "primary"
          attrs:  0x0000000000000000
          type:   0fc63daf-8483-4772-8e79-3d69d8477de4
                  (linux)
          guid:   c48c360e-db47-46da-ab87-26416fad3cd3
This commit is contained in:
Tom Rini 2023-10-10 21:47:50 -04:00
commit be98a786b6
19 changed files with 129 additions and 135 deletions

View file

@ -25,18 +25,18 @@ int blk_common_cmd(int argc, char *const argv[], enum uclass_id uclass_id,
case 2:
if (strncmp(argv[1], "inf", 3) == 0) {
blk_list_devices(uclass_id);
return 0;
return CMD_RET_SUCCESS;
} else if (strncmp(argv[1], "dev", 3) == 0) {
if (blk_print_device_num(uclass_id, *cur_devnump)) {
printf("\nno %s devices available\n", if_name);
return CMD_RET_FAILURE;
}
return 0;
return CMD_RET_SUCCESS;
} else if (strncmp(argv[1], "part", 4) == 0) {
if (blk_list_part(uclass_id))
printf("\nno %s partition table available\n",
if_name);
return 0;
return CMD_RET_SUCCESS;
}
return CMD_RET_USAGE;
case 3:
@ -49,7 +49,7 @@ int blk_common_cmd(int argc, char *const argv[], enum uclass_id uclass_id,
} else {
return CMD_RET_FAILURE;
}
return 0;
return CMD_RET_SUCCESS;
} else if (strncmp(argv[1], "part", 4) == 0) {
int dev = (int)dectoul(argv[2], NULL);
@ -58,7 +58,7 @@ int blk_common_cmd(int argc, char *const argv[], enum uclass_id uclass_id,
if_name, dev);
return CMD_RET_FAILURE;
}
return 0;
return CMD_RET_SUCCESS;
}
return CMD_RET_USAGE;
@ -67,38 +67,46 @@ int blk_common_cmd(int argc, char *const argv[], enum uclass_id uclass_id,
phys_addr_t paddr = hextoul(argv[2], NULL);
lbaint_t blk = hextoul(argv[3], NULL);
ulong cnt = hextoul(argv[4], NULL);
struct blk_desc *desc;
void *vaddr;
ulong n;
int ret;
printf("\n%s read: device %d block # "LBAFU", count %lu ... ",
if_name, *cur_devnump, blk, cnt);
vaddr = map_sysmem(paddr, 512 * cnt);
n = blk_read_devnum(uclass_id, *cur_devnump, blk, cnt,
vaddr);
ret = blk_get_desc(uclass_id, *cur_devnump, &desc);
if (ret)
return CMD_RET_FAILURE;
vaddr = map_sysmem(paddr, desc->blksz * cnt);
n = blk_dread(desc, blk, cnt, vaddr);
unmap_sysmem(vaddr);
printf("%ld blocks read: %s\n", n,
n == cnt ? "OK" : "ERROR");
return n == cnt ? 0 : 1;
return n == cnt ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
} else if (strcmp(argv[1], "write") == 0) {
phys_addr_t paddr = hextoul(argv[2], NULL);
lbaint_t blk = hextoul(argv[3], NULL);
ulong cnt = hextoul(argv[4], NULL);
struct blk_desc *desc;
void *vaddr;
ulong n;
int ret;
printf("\n%s write: device %d block # "LBAFU", count %lu ... ",
if_name, *cur_devnump, blk, cnt);
vaddr = map_sysmem(paddr, 512 * cnt);
n = blk_write_devnum(uclass_id, *cur_devnump, blk, cnt,
vaddr);
ret = blk_get_desc(uclass_id, *cur_devnump, &desc);
if (ret)
return CMD_RET_FAILURE;
vaddr = map_sysmem(paddr, desc->blksz * cnt);
n = blk_dwrite(desc, blk, cnt, vaddr);
unmap_sysmem(vaddr);
printf("%ld blocks written: %s\n", n,
n == cnt ? "OK" : "ERROR");
return n == cnt ? 0 : 1;
return n == cnt ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
} else {
return CMD_RET_USAGE;
}

View file

@ -25,7 +25,8 @@ struct map_handler {
map_parser_fn fn;
};
int do_blkmap_map_linear(struct map_ctx *ctx, int argc, char *const argv[])
static int do_blkmap_map_linear(struct map_ctx *ctx, int argc,
char *const argv[])
{
struct blk_desc *lbd;
int err, ldevnum;
@ -58,7 +59,7 @@ int do_blkmap_map_linear(struct map_ctx *ctx, int argc, char *const argv[])
return CMD_RET_SUCCESS;
}
int do_blkmap_map_mem(struct map_ctx *ctx, int argc, char *const argv[])
static int do_blkmap_map_mem(struct map_ctx *ctx, int argc, char *const argv[])
{
phys_addr_t addr;
int err;
@ -80,7 +81,7 @@ int do_blkmap_map_mem(struct map_ctx *ctx, int argc, char *const argv[])
return CMD_RET_SUCCESS;
}
struct map_handler map_handlers[] = {
static struct map_handler map_handlers[] = {
{ .name = "linear", .fn = do_blkmap_map_linear },
{ .name = "mem", .fn = do_blkmap_map_mem },

View file

@ -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 = argc > 1 ? argv[1] : NULL;
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;
@ -151,8 +160,8 @@ static void show_host_dev(struct udevice *dev)
return;
desc = dev_get_uclass_plat(blk);
printf("%12lu %-15s %s\n", (unsigned long)desc->lba, plat->label,
plat->filename);
printf("%12lu %6lu %-15s %s\n", (unsigned long)desc->lba, desc->blksz,
plat->label, plat->filename);
}
static int do_host_info(struct cmd_tbl *cmdtp, int flag, int argc,
@ -170,7 +179,8 @@ static int do_host_info(struct cmd_tbl *cmdtp, int flag, int argc,
return CMD_RET_FAILURE;
}
printf("%3s %12s %-15s %s\n", "dev", "blocks", "label", "path");
printf("%3s %12s %6s %-15s %s\n",
"dev", "blocks", "blksz", "label", "path");
if (dev) {
show_host_dev(dev);
} else {
@ -253,7 +263,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"

View file

@ -219,8 +219,8 @@ static int usb_stor_probe_device(struct usb_device *udev)
snprintf(str, sizeof(str), "lun%d", lun);
ret = blk_create_devicef(udev->dev, "usb_storage_blk", str,
UCLASS_USB, usb_max_devs, 512, 0,
&dev);
UCLASS_USB, usb_max_devs,
DEFAULT_BLKSZ, 0, &dev);
if (ret) {
debug("Cannot bind driver\n");
return ret;

View file

@ -336,8 +336,11 @@ static void print_part_header(const char *type, struct blk_desc *desc)
case UCLASS_EFI_MEDIA:
puts("EFI");
break;
case UCLASS_BLKMAP:
puts("BLKMAP");
break;
default:
puts("UNKNOWN");
printf("UNKNOWN(%d)", desc->uclass_id);
break;
}
printf (" device %d -- Partition Type: %s\n\n",

View file

@ -880,7 +880,8 @@ int dwc_ahsata_scan(struct udevice *dev)
device_find_first_child(dev, &blk);
if (!blk) {
ret = blk_create_devicef(dev, "dwc_ahsata_blk", "blk",
UCLASS_AHCI, -1, 512, 0, &blk);
UCLASS_AHCI, -1, DEFAULT_BLKSZ,
0, &blk);
if (ret) {
debug("Can't create device\n");
return ret;

View file

@ -888,7 +888,8 @@ static int fsl_ata_probe(struct udevice *dev)
for (i = 0; i < nr_ports; i++) {
snprintf(sata_name, sizeof(sata_name), "fsl_sata%d", i);
ret = blk_create_devicef(dev, "sata_fsl_blk", sata_name,
UCLASS_AHCI, -1, 512, 0, &blk);
UCLASS_AHCI, -1, DEFAULT_BLKSZ,
0, &blk);
if (ret) {
debug("Can't create device\n");
return ret;

View file

@ -1076,7 +1076,8 @@ static int sata_mv_probe(struct udevice *dev)
for (i = 0; i < nr_ports; i++) {
ret = blk_create_devicef(dev, "sata_mv_blk", "blk",
UCLASS_AHCI, -1, 512, 0, &blk);
UCLASS_AHCI, -1, DEFAULT_BLKSZ,
0, &blk);
if (ret) {
debug("Can't create device\n");
continue;

View file

@ -730,7 +730,8 @@ static int sil_pci_probe(struct udevice *dev)
for (i = sata_info.portbase; i < sata_info.maxport; i++) {
snprintf(sata_name, sizeof(sata_name), "sil_sata%d", i);
ret = blk_create_devicef(dev, "sata_sil_blk", sata_name,
UCLASS_AHCI, -1, 512, 0, &blk);
UCLASS_AHCI, -1, DEFAULT_BLKSZ,
0, &blk);
if (ret) {
debug("Can't create device\n");
return ret;

View file

@ -178,17 +178,7 @@ struct blk_desc *blk_get_by_device(struct udevice *dev)
return NULL;
}
/**
* get_desc() - Get the block device descriptor for the given device number
*
* @uclass_id: Interface type
* @devnum: Device number (0 = first)
* @descp: Returns block device descriptor on success
* Return: 0 on success, -ENODEV if there is no such device and no device
* with a higher device number, -ENOENT if there is no such device but there
* is one with a higher number, or other -ve on other error.
*/
static int get_desc(enum uclass_id uclass_id, int devnum, struct blk_desc **descp)
int blk_get_desc(enum uclass_id uclass_id, int devnum, struct blk_desc **descp)
{
bool found_more = false;
struct udevice *dev;
@ -240,7 +230,7 @@ int blk_list_part(enum uclass_id uclass_id)
int ret;
for (ok = 0, devnum = 0;; ++devnum) {
ret = get_desc(uclass_id, devnum, &desc);
ret = blk_get_desc(uclass_id, devnum, &desc);
if (ret == -ENODEV)
break;
else if (ret)
@ -263,7 +253,7 @@ int blk_print_part_devnum(enum uclass_id uclass_id, int devnum)
struct blk_desc *desc;
int ret;
ret = get_desc(uclass_id, devnum, &desc);
ret = blk_get_desc(uclass_id, devnum, &desc);
if (ret)
return ret;
if (desc->type == DEV_TYPE_UNKNOWN)
@ -280,7 +270,7 @@ void blk_list_devices(enum uclass_id uclass_id)
int i;
for (i = 0;; ++i) {
ret = get_desc(uclass_id, i, &desc);
ret = blk_get_desc(uclass_id, i, &desc);
if (ret == -ENODEV)
break;
else if (ret)
@ -297,7 +287,7 @@ int blk_print_device_num(enum uclass_id uclass_id, int devnum)
struct blk_desc *desc;
int ret;
ret = get_desc(uclass_id, devnum, &desc);
ret = blk_get_desc(uclass_id, devnum, &desc);
if (ret)
return ret;
printf("\nIDE device %d: ", devnum);
@ -312,7 +302,7 @@ int blk_show_device(enum uclass_id uclass_id, int devnum)
int ret;
printf("\nDevice %d: ", devnum);
ret = get_desc(uclass_id, devnum, &desc);
ret = blk_get_desc(uclass_id, devnum, &desc);
if (ret == -ENODEV || ret == -ENOENT) {
printf("unknown device\n");
return -ENODEV;
@ -327,35 +317,6 @@ int blk_show_device(enum uclass_id uclass_id, int devnum)
return 0;
}
ulong blk_read_devnum(enum uclass_id uclass_id, int devnum, lbaint_t start,
lbaint_t blkcnt, void *buffer)
{
struct blk_desc *desc;
ulong n;
int ret;
ret = get_desc(uclass_id, devnum, &desc);
if (ret)
return ret;
n = blk_dread(desc, start, blkcnt, buffer);
if (IS_ERR_VALUE(n))
return n;
return n;
}
ulong blk_write_devnum(enum uclass_id uclass_id, int devnum, lbaint_t start,
lbaint_t blkcnt, const void *buffer)
{
struct blk_desc *desc;
int ret;
ret = get_desc(uclass_id, devnum, &desc);
if (ret)
return ret;
return blk_dwrite(desc, start, blkcnt, buffer);
}
int blk_select_hwpart(struct udevice *dev, int hwpart)
{
const struct blk_ops *ops = blk_get_ops(dev);

View file

@ -171,11 +171,11 @@ int blkmap_map_linear(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
bd = dev_get_uclass_plat(bm->blk);
lbd = dev_get_uclass_plat(lblk);
if (lbd->blksz != bd->blksz)
/* We could support block size translation, but we
* don't yet.
*/
return -EINVAL;
if (lbd->blksz != bd->blksz) {
/* update to match the mapped device */
bd->blksz = lbd->blksz;
bd->log2blksz = LOG2(bd->blksz);
}
linear = malloc(sizeof(*linear));
if (!linear)
@ -383,14 +383,14 @@ U_BOOT_DRIVER(blkmap_blk) = {
.ops = &blkmap_blk_ops,
};
int blkmap_dev_bind(struct udevice *dev)
static int blkmap_dev_bind(struct udevice *dev)
{
struct blkmap *bm = dev_get_plat(dev);
struct blk_desc *bd;
int err;
err = blk_create_devicef(dev, "blkmap_blk", "blk", UCLASS_BLKMAP,
dev_seq(dev), 512, 0, &bm->blk);
dev_seq(dev), DEFAULT_BLKSZ, 0, &bm->blk);
if (err)
return log_msg_ret("blk", err);
@ -410,7 +410,7 @@ int blkmap_dev_bind(struct udevice *dev)
return 0;
}
int blkmap_dev_unbind(struct udevice *dev)
static int blkmap_dev_unbind(struct udevice *dev)
{
struct blkmap *bm = dev_get_plat(dev);
struct blkmap_slice *bms, *tmp;

View file

@ -13,6 +13,7 @@
#include <blk.h>
#include <dm.h>
#include <malloc.h>
#include <part.h>
#include <sandbox_host.h>
#include <dm/device-internal.h>
#include <dm/lists.h>
@ -29,7 +30,8 @@ struct host_priv {
struct udevice *cur_dev;
};
int host_create_device(const char *label, bool removable, struct udevice **devp)
int host_create_device(const char *label, bool removable, unsigned long blksz,
struct udevice **devp)
{
char dev_name[30], *str, *label_new;
struct host_sb_plat *plat;
@ -68,6 +70,12 @@ int host_create_device(const char *label, bool removable, struct udevice **devp)
struct blk_desc *desc = dev_get_uclass_plat(blk);
desc->removable = removable;
/* update blk device's block size with the provided one */
if (blksz != desc->blksz) {
desc->blksz = blksz;
desc->log2blksz = LOG2(desc->blksz);
}
}
plat = dev_get_plat(dev);
@ -95,12 +103,13 @@ int host_attach_file(struct udevice *dev, const char *filename)
}
int host_create_attach_file(const char *label, const char *filename,
bool removable, struct udevice **devp)
bool removable, unsigned long blksz,
struct udevice **devp)
{
struct udevice *dev;
int ret;
ret = host_create_device(label, removable, &dev);
ret = host_create_device(label, removable, blksz, &dev);
if (ret)
return log_msg_ret("cre", ret);

View file

@ -58,6 +58,11 @@ static int host_sb_attach_file(struct udevice *dev, const char *filename)
size = os_filesize(fd);
desc = dev_get_uclass_plat(blk);
if (size % desc->blksz) {
printf("The size of host backing file '%s' is not multiple of "
"the device block size\n", filename);
goto err_fname;
}
desc->lba = size / desc->blksz;
/* write this in last, when nothing can go wrong */
@ -73,7 +78,7 @@ err_fname:
return ret;
}
int host_sb_detach_file(struct udevice *dev)
static int host_sb_detach_file(struct udevice *dev)
{
struct host_sb_plat *plat = dev_get_plat(dev);
int ret;
@ -105,7 +110,7 @@ static int host_sb_bind(struct udevice *dev)
int ret;
ret = blk_create_devicef(dev, "sandbox_host_blk", "blk", UCLASS_HOST,
dev_seq(dev), 512, 0, &blk);
dev_seq(dev), DEFAULT_BLKSZ, 0, &blk);
if (ret)
return log_msg_ret("blk", ret);
@ -123,7 +128,7 @@ static int host_sb_bind(struct udevice *dev)
return 0;
}
struct host_ops host_sb_ops = {
static struct host_ops host_sb_ops = {
.attach_file = host_sb_attach_file,
.detach_file = host_sb_detach_file,
};

View file

@ -412,7 +412,7 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg)
debug("%s: alias devnum=%d\n", __func__, dev_seq(dev));
ret = blk_create_devicef(dev, "mmc_blk", "blk", UCLASS_MMC,
dev_seq(dev), 512, 0, &bdev);
dev_seq(dev), DEFAULT_BLKSZ, 0, &bdev);
if (ret) {
debug("Cannot create block device\n");
return ret;

View file

@ -906,7 +906,7 @@ int nvme_init(struct udevice *udev)
/* The real blksz and size will be set by nvme_blk_probe() */
ret = blk_create_devicef(udev, "nvme-blk", name, UCLASS_NVME,
-1, 512, 0, &ns_udev);
-1, DEFAULT_BLKSZ, 0, &ns_udev);
if (ret)
goto free_id;

View file

@ -21,6 +21,8 @@ typedef ulong lbaint_t;
#define LBAF "%" LBAFlength "x"
#define LBAFU "%" LBAFlength "u"
#define DEFAULT_BLKSZ 512
struct udevice;
static inline bool blk_enabled(void)
@ -513,6 +515,18 @@ const char *blk_get_devtype(struct udevice *dev);
*/
struct blk_desc *blk_get_by_device(struct udevice *dev);
/**
* blk_get_desc() - Get the block device descriptor for the given device number
*
* @uclass_id: Interface type
* @devnum: Device number (0 = first)
* @descp: Returns block device descriptor on success
* Return: 0 on success, -ENODEV if there is no such device and no device
* with a higher device number, -ENOENT if there is no such device but there
* is one with a higher number, or other -ve on other error.
*/
int blk_get_desc(enum uclass_id uclass_id, int devnum, struct blk_desc **descp);
#else
#include <errno.h>
/*
@ -715,32 +729,6 @@ int blk_print_device_num(enum uclass_id uclass_id, int devnum);
*/
int blk_print_part_devnum(enum uclass_id uclass_id, int devnum);
/**
* blk_read_devnum() - read blocks from a device
*
* @uclass_id: Block device type
* @devnum: Device number
* @start: Start block number to read (0=first)
* @blkcnt: Number of blocks to read
* @buffer: Address to write data to
* Return: number of blocks read, or -ve error number on error
*/
ulong blk_read_devnum(enum uclass_id uclass_id, int devnum, lbaint_t start,
lbaint_t blkcnt, void *buffer);
/**
* blk_write_devnum() - write blocks to a device
*
* @uclass_id: Block device type
* @devnum: Device number
* @start: Start block number to write (0=first)
* @blkcnt: Number of blocks to write
* @buffer: Address to read data from
* Return: number of blocks written, or -ve error number on error
*/
ulong blk_write_devnum(enum uclass_id uclass_id, int devnum, lbaint_t start,
lbaint_t blkcnt, const void *buffer);
/**
* blk_select_hwpart_devnum() - select a hardware partition
*

View file

@ -74,10 +74,11 @@ int host_detach_file(struct udevice *dev);
* @label: Label of the attachment, e.g. "test1"
* @removable: true if the device should be marked as removable, false
* if it is fixed. See enum blk_flag_t
* @blksz: logical block size of the device
* @devp: Returns the device created, on success
* Returns: 0 if OK, -ve on error
*/
int host_create_device(const char *label, bool removable,
int host_create_device(const char *label, bool removable, unsigned long blksz,
struct udevice **devp);
/**
@ -87,11 +88,13 @@ int host_create_device(const char *label, bool removable,
* @filename: Name of the file, e.g. "/path/to/disk.img"
* @removable: true if the device should be marked as removable, false
* if it is fixed. See enum blk_flag_t
* @blksz: logical block size of the device
* @devp: Returns the device created, on success
* Returns: 0 if OK, -ve on error
*/
int host_create_attach_file(const char *label, const char *filename,
bool removable, struct udevice **devp);
bool removable, unsigned long blksz,
struct udevice **devp);
/**
* host_find_by_label() - Find a host by label

View file

@ -4,6 +4,7 @@
*/
#include <common.h>
#include <blk.h>
#include <dm.h>
#include <part.h>
#include <sandbox_host.h>
@ -22,8 +23,8 @@ static int dm_test_blk_base(struct unit_test_state *uts)
struct udevice *blk0, *blk1, *dev0, *dev1, *dev, *chk0, *chk1;
/* Create two, one the parent of the other */
ut_assertok(host_create_device("test0", false, &dev0));
ut_assertok(host_create_device("test1", false, &dev1));
ut_assertok(host_create_device("test0", false, DEFAULT_BLKSZ, &dev0));
ut_assertok(host_create_device("test1", false, DEFAULT_BLKSZ, &dev1));
/* Check we can find them */
ut_assertok(blk_get_device(UCLASS_HOST, 0, &blk0));
@ -99,7 +100,7 @@ static int dm_test_blk_find(struct unit_test_state *uts)
{
struct udevice *blk, *chk, *dev;
ut_assertok(host_create_device("test0", false, &dev));
ut_assertok(host_create_device("test0", false, DEFAULT_BLKSZ, &dev));
ut_assertok(blk_find_device(UCLASS_HOST, 0, &chk));
ut_assertok(device_find_first_child_by_uclass(dev, UCLASS_BLK, &blk));

View file

@ -31,7 +31,7 @@ static int dm_test_host(struct unit_test_state *uts)
ut_asserteq(-ENODEV, uclass_first_device_err(UCLASS_PARTITION, &part));
mem_start = ut_check_delta(0);
ut_assertok(host_create_device(label, true, &dev));
ut_assertok(host_create_device(label, true, DEFAULT_BLKSZ, &dev));
/* Check that the plat data has been allocated */
plat = dev_get_plat(dev);
@ -83,7 +83,7 @@ static int dm_test_host_dup(struct unit_test_state *uts)
char fname[256];
ut_asserteq(0, uclass_id_count(UCLASS_HOST));
ut_assertok(host_create_device(label, true, &dev));
ut_assertok(host_create_device(label, true, DEFAULT_BLKSZ, &dev));
/* Attach a file created in test_ut_dm_init */
ut_assertok(os_persistent_file(fname, sizeof(fname), "2MB.ext2.img"));
@ -93,7 +93,7 @@ static int dm_test_host_dup(struct unit_test_state *uts)
ut_asserteq(1, uclass_id_count(UCLASS_HOST));
/* Create another device with the same label (should remove old one) */
ut_assertok(host_create_device(label, true, &dev));
ut_assertok(host_create_device(label, true, DEFAULT_BLKSZ, &dev));
/* Attach a different file created in test_ut_dm_init */
ut_assertok(os_persistent_file(fname, sizeof(fname), "1MB.fat32.img"));
@ -120,7 +120,7 @@ static int dm_test_cmd_host(struct unit_test_state *uts)
/* first check 'host info' with binding */
ut_assertok(run_command("host info", 0));
ut_assert_nextline("dev blocks label path");
ut_assert_nextline("dev blocks blksz label path");
ut_assert_console_end();
ut_assertok(os_persistent_file(fname, sizeof(fname), "2MB.ext2.img"));
@ -133,8 +133,8 @@ static int dm_test_cmd_host(struct unit_test_state *uts)
ut_asserteq(true, desc->removable);
ut_assertok(run_command("host info", 0));
ut_assert_nextline("dev blocks label path");
ut_assert_nextlinen(" 0 4096 test2");
ut_assert_nextline("dev blocks blksz label path");
ut_assert_nextlinen(" 0 4096 512 test2");
ut_assert_console_end();
ut_assertok(os_persistent_file(fname, sizeof(fname), "1MB.fat32.img"));
@ -147,9 +147,9 @@ static int dm_test_cmd_host(struct unit_test_state *uts)
ut_asserteq(false, desc->removable);
ut_assertok(run_command("host info", 0));
ut_assert_nextline("dev blocks label path");
ut_assert_nextlinen(" 0 4096 test2");
ut_assert_nextlinen(" 1 2048 fat");
ut_assert_nextline("dev blocks blksz label path");
ut_assert_nextlinen(" 0 4096 512 test2");
ut_assert_nextlinen(" 1 2048 512 fat");
ut_assert_console_end();
ut_asserteq(1, run_command("host info test", 0));
@ -157,8 +157,8 @@ static int dm_test_cmd_host(struct unit_test_state *uts)
ut_assert_console_end();
ut_assertok(run_command("host info fat", 0));
ut_assert_nextline("dev blocks label path");
ut_assert_nextlinen(" 1 2048 fat");
ut_assert_nextline("dev blocks blksz label path");
ut_assert_nextlinen(" 1 2048 512 fat");
ut_assert_console_end();
/* check 'host dev' */
@ -194,8 +194,8 @@ static int dm_test_cmd_host(struct unit_test_state *uts)
ut_assert_console_end();
ut_assertok(run_command("host info", 0));
ut_assert_nextline("dev blocks label path");
ut_assert_nextlinen(" 1 2048 fat");
ut_assert_nextline("dev blocks blksz label path");
ut_assert_nextlinen(" 1 2048 512 fat");
ut_assert_console_end();
return 0;