1 // SPDX-License-Identifier: GPL-2.0+
12 #include <sandbox_host.h>
13 #include <asm/global_data.h>
14 #include <dm/device_compat.h>
15 #include <dm/device-internal.h>
16 #include <linux/errno.h>
18 DECLARE_GLOBAL_DATA_PTR;
20 static unsigned long host_block_read(struct udevice *dev,
21 unsigned long start, lbaint_t blkcnt,
24 struct blk_desc *desc = dev_get_uclass_plat(dev);
25 struct udevice *host_dev = dev_get_parent(dev);
26 struct host_sb_plat *plat = dev_get_plat(host_dev);
28 if (os_lseek(plat->fd, start * desc->blksz, OS_SEEK_SET) < 0) {
29 printf("ERROR: Invalid block %lx\n", start);
32 ssize_t len = os_read(plat->fd, buffer, blkcnt * desc->blksz);
34 return len / desc->blksz;
39 static unsigned long host_block_write(struct udevice *dev,
40 unsigned long start, lbaint_t blkcnt,
43 struct blk_desc *desc = dev_get_uclass_plat(dev);
44 struct udevice *host_dev = dev_get_parent(dev);
45 struct host_sb_plat *plat = dev_get_plat(host_dev);
47 if (os_lseek(plat->fd, start * desc->blksz, OS_SEEK_SET) < 0) {
48 printf("ERROR: Invalid block %lx\n", start);
51 ssize_t len = os_write(plat->fd, buffer, blkcnt * desc->blksz);
53 return len / desc->blksz;
58 static const struct blk_ops sandbox_host_blk_ops = {
59 .read = host_block_read,
60 .write = host_block_write,
63 U_BOOT_DRIVER(sandbox_host_blk) = {
64 .name = "sandbox_host_blk",
66 .ops = &sandbox_host_blk_ops,