#include <os.h>
#include <malloc.h>
#include <sandboxblockdev.h>
+#include <asm/global_data.h>
#include <dm/device_compat.h>
#include <linux/errno.h>
#include <dm/device-internal.h>
DECLARE_GLOBAL_DATA_PTR;
#ifndef CONFIG_BLK
-static struct host_block_dev host_devices[CONFIG_HOST_MAX_DEVICES];
+static struct host_block_dev host_devices[SANDBOX_HOST_MAX_DEVICES];
static struct host_block_dev *find_host_device(int dev)
{
- if (dev >= 0 && dev < CONFIG_HOST_MAX_DEVICES)
+ if (dev >= 0 && dev < SANDBOX_HOST_MAX_DEVICES)
return &host_devices[dev];
return NULL;
unsigned long start, lbaint_t blkcnt,
void *buffer)
{
- struct host_block_dev *host_dev = dev_get_platdata(dev);
- struct blk_desc *block_dev = dev_get_uclass_platdata(dev);
+ struct host_block_dev *host_dev = dev_get_plat(dev);
+ struct blk_desc *block_dev = dev_get_uclass_plat(dev);
#else
static unsigned long host_block_read(struct blk_desc *block_dev,
unsigned long start, lbaint_t blkcnt,
const void *buffer)
{
- struct host_block_dev *host_dev = dev_get_platdata(dev);
- struct blk_desc *block_dev = dev_get_uclass_platdata(dev);
+ struct host_block_dev *host_dev = dev_get_plat(dev);
+ struct blk_desc *block_dev = dev_get_uclass_plat(dev);
#else
static unsigned long host_block_write(struct blk_desc *block_dev,
unsigned long start, lbaint_t blkcnt,
}
#ifdef CONFIG_BLK
-int host_dev_bind(int devnum, char *filename)
+int host_dev_bind(int devnum, char *filename, bool removable)
{
struct host_block_dev *host_dev;
struct udevice *dev;
+ struct blk_desc *desc;
char dev_name[20], *str, *fname;
int ret, fd;
if (ret)
goto err_file;
- host_dev = dev_get_platdata(dev);
+ host_dev = dev_get_plat(dev);
host_dev->fd = fd;
host_dev->filename = fname;
goto err_file;
}
+ desc = blk_get_devnum_by_type(IF_TYPE_HOST, devnum);
+ desc->removable = removable;
+ snprintf(desc->vendor, BLK_VEN_SIZE, "U-Boot");
+ snprintf(desc->product, BLK_PRD_SIZE, "hostfile");
+ snprintf(desc->revision, BLK_REV_SIZE, "1.0");
+
return 0;
err_file:
os_close(fd);
return ret;
}
#else
-int host_dev_bind(int dev, char *filename)
+int host_dev_bind(int dev, char *filename, bool removable)
{
struct host_block_dev *host_dev = find_host_device(dev);
blk_dev->block_write = host_block_write;
blk_dev->devnum = dev;
blk_dev->part_type = PART_TYPE_UNKNOWN;
+ blk_dev->removable = removable;
+ snprintf(blk_dev->vendor, BLK_VEN_SIZE, "U-Boot");
+ snprintf(blk_dev->product, BLK_PRD_SIZE, "hostfile");
+ snprintf(blk_dev->revision, BLK_REV_SIZE, "1.0");
part_init(blk_dev);
return 0;
ret = blk_get_device(IF_TYPE_HOST, devnum, &dev);
if (ret)
return ret;
- *blk_devp = dev_get_uclass_platdata(dev);
+ *blk_devp = dev_get_uclass_plat(dev);
#else
struct host_block_dev *host_dev = find_host_device(devnum);
}
#ifdef CONFIG_BLK
+
+int sandbox_host_unbind(struct udevice *dev)
+{
+ struct host_block_dev *host_dev;
+
+ /* Data validity is checked in host_dev_bind() */
+ host_dev = dev_get_plat(dev);
+ os_close(host_dev->fd);
+
+ return 0;
+}
+
static const struct blk_ops sandbox_host_blk_ops = {
.read = host_block_read,
.write = host_block_write,
.name = "sandbox_host_blk",
.id = UCLASS_BLK,
.ops = &sandbox_host_blk_ops,
- .platdata_auto = sizeof(struct host_block_dev),
+ .unbind = sandbox_host_unbind,
+ .plat_auto = sizeof(struct host_block_dev),
};
#else
U_BOOT_LEGACY_BLK(sandbox_host) = {
.if_typename = "host",
.if_type = IF_TYPE_HOST,
- .max_devs = CONFIG_HOST_MAX_DEVICES,
+ .max_devs = SANDBOX_HOST_MAX_DEVICES,
.get_dev = host_get_dev_err,
};
#endif