From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 1/2] Loop block device for sandbox
Date: Mon, 3 Sep 2012 18:49:00 +0200 [thread overview]
Message-ID: <201209031849.00839.marex@denx.de> (raw)
In-Reply-To: <1346505549-6795-1-git-send-email-morpheus.ibis@gmail.com>
Dear Pavel Herrmann,
> This driver uses files as block devices, can be used for testing disk
> operations on sandbox. Port count and filenames are set in board config.
>
> Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
> CC: Marek Vasut <marex@denx.de>
> ---
> Changes for v2:
> split sandbox config off into separate patch (2/2)
> rename file to signify exported API
> style fixes
> show end of long filenames rather than beginning
> check for lseek errors to indicate non-regular file
>
> drivers/block/Makefile | 1 +
> drivers/block/sata_loopback.c | 122
> ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123
> insertions(+)
> create mode 100644 drivers/block/sata_loopback.c
>
> diff --git a/drivers/block/Makefile b/drivers/block/Makefile
> index f1ebdcc..c95651a 100644
> --- a/drivers/block/Makefile
> +++ b/drivers/block/Makefile
> @@ -40,6 +40,7 @@ COBJS-$(CONFIG_SATA_SIL) += sata_sil.o
> COBJS-$(CONFIG_IDE_SIL680) += sil680.o
> COBJS-$(CONFIG_SCSI_SYM53C8XX) += sym53c8xx.o
> COBJS-$(CONFIG_SYSTEMACE) += systemace.o
> +COBJS-${CONFIG_SATA_LOOP} += sata_loopback.o
>
> COBJS := $(COBJS-y)
> SRCS := $(COBJS:.o=.c)
> diff --git a/drivers/block/sata_loopback.c b/drivers/block/sata_loopback.c
> new file mode 100644
> index 0000000..7f25a4f
> --- /dev/null
> +++ b/drivers/block/sata_loopback.c
> @@ -0,0 +1,122 @@
> +/*
> + * (C) Copyright 2012
> + * Pavel Herrmann <morpheus.ibis@gmail.com>
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + */
> +
> +#include <common.h>
> +#include <part.h>
> +#include <ata.h>
> +#include <libata.h>
> +#include <errno.h>
> +#include <os.h>
> +
> +static const char revision[] = "0.0";
> +static const char vendor[] = "SATA loopback";
> +
> +static const char * const filenames[] = CONFIG_SATA_LOOP_DISKS;
> +static int max_devs = CONFIG_SYS_SATA_MAX_DEVICE;
One more thing is missing -- documentation for these (add to doc/ ).
Alternatively (which would be much better), let sandbox uboot accept params and
supply these as params.
> +extern block_dev_desc_t sata_dev_desc[];
> +
> +int init_sata(int dev)
> +{
> + block_dev_desc_t *pdev = &sata_dev_desc[dev];
> + int fd;
> +
> + if ((dev < 0) || (dev >= max_devs)) {
> + printf("File index %d is out of range.\n", dev);
> + return -EINVAL;
> + }
> +
> + fd = os_open(filenames[dev], OS_O_RDWR);
> + /* This is ugly, but saves allocation for 1 int. */
> + pdev->priv = (void *) (long) fd;
> +
> + return 0;
> +}
> +
> +lbaint_t sata_read(int dev, lbaint_t start, lbaint_t blkcnt, void *buffer)
> +{
> + block_dev_desc_t *pdev = &sata_dev_desc[dev];
> + int fd = (long) pdev->priv;
> + lbaint_t start_byte = ATA_SECT_SIZE * start;
> + lbaint_t length_byte = ATA_SECT_SIZE * blkcnt;
> + lbaint_t retval;
> +
> + if ( os_lseek(fd, start_byte, OS_SEEK_SET) != start_byte)
> + return -1;
> +
> + retval = os_read(fd, buffer, length_byte);
> +
> + return retval/ATA_SECT_SIZE;
> +}
> +
> +lbaint_t sata_write(int dev, lbaint_t start, lbaint_t blkcnt, void
> *buffer) +{
> + block_dev_desc_t *pdev = &sata_dev_desc[dev];
> + int fd = (long) pdev->priv;
> + lbaint_t start_byte = ATA_SECT_SIZE * start;
> + lbaint_t length_byte = ATA_SECT_SIZE * blkcnt;
> + lbaint_t retval;
> +
> + if ( os_lseek(fd, start_byte, OS_SEEK_SET) != start_byte)
> + return -1;
> +
> + retval = os_write(fd, buffer, length_byte);
> +
> + return retval/ATA_SECT_SIZE;
> +}
> +
> +int scan_sata(int dev)
> +{
> + block_dev_desc_t *pdev = &sata_dev_desc[dev];
> + int fd = (long) pdev->priv;
> + int namelen;
> + const char *filename = filenames[dev];
> + lbaint_t bytes = 0;
> +
> + memcpy(pdev->vendor, vendor, sizeof(vendor));
> + memcpy(pdev->revision, revision, sizeof(revision));
> + namelen = strlen(filenames[dev]);
> +
> + if (namelen > 20) {
> + /* take the last 17 chars, prepend them with "..." */
> + filename += (namelen - 17);
> + memcpy(pdev->product, "...", 3);
> + memcpy(pdev->product+3, filename, 17);
> + } else
> + memcpy(pdev->product, filename, namelen);
> +
> + pdev->product[20] = 0;
> +
> + bytes = os_lseek(fd, 0, OS_SEEK_END);
> + if (bytes != -1) {
> + pdev->type = DEV_TYPE_HARDDISK;
> + pdev->blksz = ATA_SECT_SIZE;
> + pdev->lun = 0;
> + pdev->lba = bytes/ATA_SECT_SIZE;
> + }
> +
> + printf("SATA loop info:\nfilename: %s\nsize: %lu\nblock count: %lu\n",
> + filenames[dev], bytes, pdev->lba);
> +
> + return 0;
> +}
Best regards,
Marek Vasut
next prev parent reply other threads:[~2012-09-03 16:49 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-29 15:46 [U-Boot] [PATCH] Loop block device for sandbox Pavel Herrmann
2012-08-29 15:48 ` Pavel Herrmann
2012-08-29 22:18 ` Marek Vasut
2012-08-30 17:14 ` Pavel Herrmann
2012-08-30 18:45 ` Marek Vasut
2012-08-30 19:07 ` Pavel Herrmann
2012-08-30 21:53 ` Marek Vasut
2012-08-31 9:09 ` Pavel Herrmann
2012-08-31 12:57 ` Marek Vasut
2012-08-31 14:25 ` Pavel Herrmann
2012-08-31 16:02 ` Marek Vasut
2012-08-31 17:56 ` Pavel Herrmann
2012-08-31 19:02 ` Marek Vasut
2012-09-01 13:19 ` [U-Boot] [PATCH v2 1/2] " Pavel Herrmann
2012-09-01 13:19 ` [U-Boot] [PATCH 2/2] Use loop block device in sandbox board Pavel Herrmann
2012-09-01 14:20 ` Marek Vasut
2012-09-03 17:24 ` Pavel Herrmann
2012-09-03 17:23 ` [U-Boot] [PATCH v2 " Pavel Herrmann
2012-09-03 16:49 ` Marek Vasut [this message]
2012-09-03 17:31 ` [U-Boot] [PATCH v2 1/2] Loop block device for sandbox Pavel Herrmann
2012-09-03 20:20 ` Marek Vasut
2012-09-05 11:16 ` [U-Boot] [PATCH v3 " Pavel Herrmann
2012-09-05 11:16 ` [U-Boot] [PATCH v3 2/2] Use loop block device in sandbox board Pavel Herrmann
2012-09-05 11:33 ` [U-Boot] [PATCH v3 1/2] Loop block device for sandbox Marek Vasut
2012-09-05 12:38 ` Pavel Herrmann
2012-09-05 12:48 ` Marek Vasut
2012-09-05 20:25 ` Pavel Herrmann
2012-09-06 1:08 ` Marek Vasut
2012-09-06 8:45 ` Pavel Herrmann
2012-09-06 8:48 ` Marek Vasut
2012-09-05 12:42 ` Pavel Herrmann
2012-09-05 12:52 ` Marek Vasut
2012-09-06 12:31 ` [U-Boot] [PATCH v4 " Pavel Herrmann
2012-09-06 23:29 ` Marek Vasut
2012-09-07 9:19 ` Pavel Herrmann
2012-09-07 9:26 ` Marek Vasut
2012-09-07 9:38 ` Pavel Herrmann
2012-09-07 9:42 ` Marek Vasut
2012-09-13 22:31 ` Tom Rini
2012-09-16 11:49 ` Pavel Herrmann
2012-09-16 11:58 ` [U-Boot] [PATCH v5 " Pavel Herrmann
2012-09-28 9:21 ` [U-Boot] [PATCH v6 " Pavel Herrmann
2012-09-28 18:22 ` Marek Vasut
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201209031849.00839.marex@denx.de \
--to=marex@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.