1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2013 Henrik Nordstrom <henrik@henriknordstrom.net>
13 #include <sandbox_host.h>
14 #include <asm/global_data.h>
15 #include <dm/device_compat.h>
16 #include <dm/device-internal.h>
17 #include <linux/errno.h>
19 DECLARE_GLOBAL_DATA_PTR;
21 static unsigned long host_block_read(struct udevice *dev,
22 unsigned long start, lbaint_t blkcnt,
25 struct blk_desc *desc = dev_get_uclass_plat(dev);
26 struct udevice *host_dev = dev_get_parent(dev);
27 struct host_sb_plat *plat = dev_get_plat(host_dev);
29 if (os_lseek(plat->fd, start * desc->blksz, OS_SEEK_SET) == -1) {
30 printf("ERROR: Invalid block %lx\n", start);
33 ssize_t len = os_read(plat->fd, buffer, blkcnt * desc->blksz);
35 return len / desc->blksz;
40 static unsigned long host_block_write(struct udevice *dev,
41 unsigned long start, lbaint_t blkcnt,
44 struct blk_desc *desc = dev_get_uclass_plat(dev);
45 struct udevice *host_dev = dev_get_parent(dev);
46 struct host_sb_plat *plat = dev_get_plat(host_dev);
48 if (os_lseek(plat->fd, start * desc->blksz, OS_SEEK_SET) == -1) {
49 printf("ERROR: Invalid block %lx\n", start);
52 ssize_t len = os_write(plat->fd, buffer, blkcnt * desc->blksz);
54 return len / desc->blksz;
59 static const struct blk_ops sandbox_host_blk_ops = {
60 .read = host_block_read,
61 .write = host_block_write,
64 U_BOOT_DRIVER(sandbox_host_blk) = {
65 .name = "sandbox_host_blk",
67 .ops = &sandbox_host_blk_ops,