2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2013-11-10 17:26:56 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Henrik Nordstrom <henrik@henriknordstrom.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2016-02-29 22:25:57 +00:00
|
|
|
#include <blk.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <fdtdec.h>
|
2013-11-10 17:26:56 +00:00
|
|
|
#include <part.h>
|
|
|
|
#include <os.h>
|
|
|
|
#include <malloc.h>
|
2022-10-30 01:47:17 +00:00
|
|
|
#include <sandbox_host.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <dm/device_compat.h>
|
2016-02-29 22:25:57 +00:00
|
|
|
#include <dm/device-internal.h>
|
2022-10-30 01:47:17 +00:00
|
|
|
#include <linux/errno.h>
|
2013-11-10 17:26:56 +00:00
|
|
|
|
2016-02-29 22:25:57 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
static unsigned long host_block_read(struct udevice *dev,
|
|
|
|
unsigned long start, lbaint_t blkcnt,
|
|
|
|
void *buffer)
|
|
|
|
{
|
2022-10-30 01:47:17 +00:00
|
|
|
struct blk_desc *desc = dev_get_uclass_plat(dev);
|
|
|
|
struct udevice *host_dev = dev_get_parent(dev);
|
|
|
|
struct host_sb_plat *plat = dev_get_plat(host_dev);
|
2013-11-10 17:26:56 +00:00
|
|
|
|
2022-10-30 01:47:17 +00:00
|
|
|
if (os_lseek(plat->fd, start * desc->blksz, OS_SEEK_SET) == -1) {
|
2016-02-29 22:25:56 +00:00
|
|
|
printf("ERROR: Invalid block %lx\n", start);
|
2013-11-10 17:26:56 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2022-10-30 01:47:17 +00:00
|
|
|
ssize_t len = os_read(plat->fd, buffer, blkcnt * desc->blksz);
|
2013-11-10 17:26:56 +00:00
|
|
|
if (len >= 0)
|
2022-10-30 01:47:17 +00:00
|
|
|
return len / desc->blksz;
|
|
|
|
|
|
|
|
return -EIO;
|
2013-11-10 17:26:56 +00:00
|
|
|
}
|
|
|
|
|
2016-02-29 22:25:57 +00:00
|
|
|
static unsigned long host_block_write(struct udevice *dev,
|
|
|
|
unsigned long start, lbaint_t blkcnt,
|
|
|
|
const void *buffer)
|
|
|
|
{
|
2022-10-30 01:47:17 +00:00
|
|
|
struct blk_desc *desc = dev_get_uclass_plat(dev);
|
|
|
|
struct udevice *host_dev = dev_get_parent(dev);
|
|
|
|
struct host_sb_plat *plat = dev_get_plat(host_dev);
|
2016-02-29 22:25:56 +00:00
|
|
|
|
2022-10-30 01:47:17 +00:00
|
|
|
if (os_lseek(plat->fd, start * desc->blksz, OS_SEEK_SET) == -1) {
|
2016-02-29 22:25:56 +00:00
|
|
|
printf("ERROR: Invalid block %lx\n", start);
|
2013-11-10 17:26:56 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2022-10-30 01:47:17 +00:00
|
|
|
ssize_t len = os_write(plat->fd, buffer, blkcnt * desc->blksz);
|
2013-11-10 17:26:56 +00:00
|
|
|
if (len >= 0)
|
2022-10-30 01:47:17 +00:00
|
|
|
return len / desc->blksz;
|
2021-02-02 23:21:56 +00:00
|
|
|
|
2022-10-30 01:47:17 +00:00
|
|
|
return -EIO;
|
2021-02-02 23:21:56 +00:00
|
|
|
}
|
|
|
|
|
2016-02-29 22:25:57 +00:00
|
|
|
static const struct blk_ops sandbox_host_blk_ops = {
|
|
|
|
.read = host_block_read,
|
|
|
|
.write = host_block_write,
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(sandbox_host_blk) = {
|
|
|
|
.name = "sandbox_host_blk",
|
|
|
|
.id = UCLASS_BLK,
|
|
|
|
.ops = &sandbox_host_blk_ops,
|
|
|
|
};
|