From patchwork Wed Aug 29 15:46:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Herrmann X-Patchwork-Id: 180717 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 8CA5A2C00B0 for ; Thu, 30 Aug 2012 01:47:33 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 386B02808A; Wed, 29 Aug 2012 17:47:30 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rk765Sbaxr-v; Wed, 29 Aug 2012 17:47:30 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B58862808B; Wed, 29 Aug 2012 17:47:25 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3F05F2808B for ; Wed, 29 Aug 2012 17:47:20 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xWL7X+C2WPPF for ; Wed, 29 Aug 2012 17:47:18 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-bk0-f44.google.com (mail-bk0-f44.google.com [209.85.214.44]) by theia.denx.de (Postfix) with ESMTPS id A6E662808A for ; Wed, 29 Aug 2012 17:47:16 +0200 (CEST) Received: by bkty12 with SMTP id y12so441479bkt.3 for ; Wed, 29 Aug 2012 08:47:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=0jVlQkVPZBzJlKjhPa6sZH3U13Dg9Sfbu/t5cLzIoM4=; b=YsyH/hxgSHw/MtyMwT+qw6hdh+xYpI5QaEefcigsh4GOSGDMNfzlzgskrnespGwD8V kZo/sLecw244DqSe4NG3eC/Dbz6OScVXfsWl5Wu28GhHnhyEbSeUac2qnSut0hT8M/P2 ig+CKwe/0n9HO2cMNeawxt/SGOaO5tEDpsa6H6Y7uiZMvrDsiuYqFdhJ6Jpk0yrilL+P 9f1EpZNT/280uuzmjdA5kbU6DnA8jd2fRJ/7OXpDK2FV7wOPwgnseRgy7Js17lt4zRUs byae2JVKsaySmphirWaOSa4I4750UteYRbtnE7s9JdNE2ULKjvn5BfLmfKAyrqqSzrp1 ZwRw== Received: by 10.204.149.86 with SMTP id s22mr1279038bkv.1.1346255236023; Wed, 29 Aug 2012 08:47:16 -0700 (PDT) Received: from Bloomfield.kolej.mff.cuni.cz (pavelherrmann.kolej.mff.cuni.cz. [78.128.197.20]) by mx.google.com with ESMTPS id t23sm15943041bks.4.2012.08.29.08.47.11 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 29 Aug 2012 08:47:13 -0700 (PDT) From: Pavel Herrmann To: u-boot@lists.denx.de Date: Wed, 29 Aug 2012 17:46:43 +0200 Message-Id: <1346255203-1225-1-git-send-email-morpheus.ibis@gmail.com> X-Mailer: git-send-email 1.7.12 Cc: Marek Vasut Subject: [U-Boot] [PATCH] Loop block device for sandbox X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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 CC: Marek Vasut --- drivers/block/Makefile | 1 + drivers/block/loop.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++ include/configs/sandbox.h | 9 ++++ 3 files changed, 117 insertions(+) create mode 100644 drivers/block/loop.c diff --git a/drivers/block/Makefile b/drivers/block/Makefile index f1ebdcc..5eecf37 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} += loop.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c) diff --git a/drivers/block/loop.c b/drivers/block/loop.c new file mode 100644 index 0000000..c9edfc3 --- /dev/null +++ b/drivers/block/loop.c @@ -0,0 +1,107 @@ +/* + * (C) Copyright 2012 + * Pavel Herrmann + * + * 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 +#include +#include +#include +#include +#include + +static const char revision[] = "0.0"; +static const char vendor[] = "loopback"; + +static const char * const filenames[] = CONFIG_SATA_LOOP_DISKS; +static int max_devs = CONFIG_SYS_SATA_MAX_DEVICE; + +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 retval; + + os_lseek(fd, start*ATA_SECT_SIZE, OS_SEEK_SET); + retval = os_read(fd, buffer, ATA_SECT_SIZE * blkcnt); + + 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 retval; + + os_lseek(fd, start*ATA_SECT_SIZE, OS_SEEK_SET); + retval = os_write(fd, buffer, ATA_SECT_SIZE * blkcnt); + + 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; + lbaint_t bytes = 0; + memcpy(pdev->vendor, vendor, sizeof(vendor)); + memcpy(pdev->revision, revision, sizeof(revision)); + namelen = sizeof(filenames[dev]); + if (namelen > 20) + namelen = 20; + memcpy(pdev->product, filenames[dev], namelen); + pdev->product[20] = 0; + + if (fd != -1) { + pdev->type = DEV_TYPE_HARDDISK; + pdev->blksz = ATA_SECT_SIZE; + pdev->lun = 0; + + bytes = os_lseek(fd, 0, OS_SEEK_END); + 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; +} diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index 0220386..412341f 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -93,4 +93,13 @@ "stdout=serial\0" \ "stderr=serial\0" +/* SATA loopback device */ +#define CONFIG_CMD_SATA +#define CONFIG_SATA_LOOP +#define CONFIG_SATA_LOOP_DISKS {"disk1", "disk2"} +#define CONFIG_SYS_SATA_MAX_DEVICE 2 +#define CONFIG_DOS_PARTITION +#define CONFIG_CMD_FAT +#define CONFIG_CMD_EXT2 + #endif