From patchwork Thu Sep 20 19:37:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Herrmann X-Patchwork-Id: 185456 X-Patchwork-Delegate: marek.vasut@gmail.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 8A15D2C009D for ; Fri, 21 Sep 2012 05:40:13 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F028C280B6; Thu, 20 Sep 2012 21:40:02 +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 ntLFi0nV5g0e; Thu, 20 Sep 2012 21:40:02 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 297E5280DC; Thu, 20 Sep 2012 21:38:55 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1D43628094; Thu, 20 Sep 2012 21:38:29 +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 JbZjP95jHwE9; Thu, 20 Sep 2012 21:38:28 +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) 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-wi0-f180.google.com (mail-wi0-f180.google.com [209.85.212.180]) by theia.denx.de (Postfix) with ESMTPS id DF39528097; Thu, 20 Sep 2012 21:38:16 +0200 (CEST) Received: by mail-wi0-f180.google.com with SMTP id hm6so897860wib.9 for ; Thu, 20 Sep 2012 12:38:15 -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:in-reply-to:references; bh=MUl3cohoEU+BXqI8sJe2lGGzC3X2eJeYMRHwnWXN3pc=; b=n6Y5SYoKtzi1618L47LjpEyUbneh9vpdW+ZgfEWznR//RQfnD3MNH/gkLJZJpXnVBS 2ECZThlRg4W7hb7KEZRvhwyenRxJ8pnlLZjlPNdsXfN7dKggIZqDoLOGbqxTsKFm6fPn 5JyXpHqVVnqtY9V1lIt06/tPixrTm15iNQV4IEIn6VoNaQC49Xa4YD2BOSgVEJ1Lu2jL GrGFBvVf7f1F0OrJzdxhp41hoHJWe4xCCJV8Dps29sFy0jHld/XJcC3vqHaLxg58jDpV 4+E4xiwVifpL1+gc/bxe++AsMOx0TM+PL+LYdv4+i/7lgo9V16X5mJEtyfeS3eTMq1mj Eimg== Received: by 10.180.90.201 with SMTP id by9mr7705162wib.5.1348169895812; Thu, 20 Sep 2012 12:38:15 -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 k2sm12265794wiz.7.2012.09.20.12.38.14 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 20 Sep 2012 12:38:14 -0700 (PDT) From: Pavel Herrmann To: U-Boot DM Date: Thu, 20 Sep 2012 21:37:45 +0200 Message-Id: <1348169867-2917-10-git-send-email-morpheus.ibis@gmail.com> X-Mailer: git-send-email 1.7.12 In-Reply-To: <1348169867-2917-1-git-send-email-morpheus.ibis@gmail.com> References: <1348169867-2917-1-git-send-email-morpheus.ibis@gmail.com> Cc: Marek Vasut , u-boot@lists.denx.de Subject: [U-Boot] [PATCH 09/11] DM: use new blockdev API in reiserfs 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 cmd_reiserdm.c is a copy of cmd_reiser.c with just trivial changes, but those touch large portion of the lines due to different number of parameters (old API has a separate parameter for interface and for disk number, new API has this as one) Signed-off-by: Pavel Herrmann --- common/Makefile | 4 ++ common/cmd_reiserdm.c | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++ fs/reiserfs/Makefile | 8 ++- fs/reiserfs/dev_dm.c | 104 +++++++++++++++++++++++++++ include/reiserfs.h | 8 ++- 5 files changed, 315 insertions(+), 2 deletions(-) create mode 100644 common/cmd_reiserdm.c create mode 100644 fs/reiserfs/dev_dm.c diff --git a/common/Makefile b/common/Makefile index 22f9234..d83c66e 100644 --- a/common/Makefile +++ b/common/Makefile @@ -142,7 +142,11 @@ COBJS-y += cmd_pcmcia.o COBJS-$(CONFIG_CMD_PORTIO) += cmd_portio.o COBJS-$(CONFIG_CMD_PXE) += cmd_pxe.o COBJS-$(CONFIG_CMD_REGINFO) += cmd_reginfo.o +ifdef CONFIG_DM +COBJS-$(CONFIG_CMD_REISER) += cmd_reiserdm.o +else COBJS-$(CONFIG_CMD_REISER) += cmd_reiser.o +endif COBJS-$(CONFIG_CMD_SATA) += cmd_sata.o COBJS-$(CONFIG_CMD_SF) += cmd_sf.o COBJS-$(CONFIG_CMD_SCSI) += cmd_scsi.o diff --git a/common/cmd_reiserdm.c b/common/cmd_reiserdm.c new file mode 100644 index 0000000..ed16563 --- /dev/null +++ b/common/cmd_reiserdm.c @@ -0,0 +1,193 @@ +/* + * (C) Copyright 2003 - 2004 + * Sysgo Real-Time Solutions, AG + * Pavel Bartusek + * + * 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 + * + */ + +/* + * Reiserfs support + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* #define REISER_DEBUG */ + +#ifdef REISER_DEBUG +#define PRINTF(fmt, args...) printf(fmt, ##args) +#else +#define PRINTF(fmt, args...) +#endif + +int do_reiserls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + char *filename = "/"; + int part_length; + struct instance *bdev; + + if (argc < 2) + return CMD_RET_USAGE; + + bdev = get_blockdev_by_name(argv[1]); + if (!bdev) { + printf("\n** Block device %s not supported\n", argv[1]); + return 1; + } + + if (argc == 3) + filename = argv[2]; + + PRINTF("Using device %s, directory: %s\n", argv[1], filename); + + part_length = reiserfs_set_blk_dev(bdev); + if (part_length == 0) { + printf("** Bad partition - %s **\n", argv[1]); + return 1; + } + + if (!reiserfs_mount(part_length)) { + printf("** Bad Reiserfs partition or disk - %s **\n", argv[1]); + return 1; + } + + if (reiserfs_ls(filename)) { + printf("** Error reiserfs_ls() **\n"); + return 1; + }; + + return 0; +} + +U_BOOT_CMD( + reiserls, 3, 1, do_reiserls, + "list files in a directory (default /)", + " [directory]\n" + " - list files from 'dev' on 'interface' in a 'directory'" +); + +/****************************************************************************** + * Reiserfs boot command intepreter. Derived from diskboot + */ +int do_reiserload(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + char *filename = NULL; + ulong addr = 0, part_length, filelen; + char buf[12]; + unsigned long count; + char *addr_str; + struct instance *bdev; + + switch (argc) { + case 2: + addr_str = getenv("loadaddr"); + if (addr_str != NULL) + addr = simple_strtoul(addr_str, NULL, 16); + else + addr = CONFIG_SYS_LOAD_ADDR; + filename = getenv("bootfile"); + count = 0; + break; + case 3: + addr = simple_strtoul(argv[2], NULL, 16); + filename = getenv("bootfile"); + count = 0; + break; + case 4: + addr = simple_strtoul(argv[2], NULL, 16); + filename = argv[3]; + count = 0; + break; + case 5: + addr = simple_strtoul(argv[2], NULL, 16); + filename = argv[3]; + count = simple_strtoul(argv[4], NULL, 16); + break; + + default: + return CMD_RET_USAGE; + } + + if (!filename) { + puts("\n** No boot file defined **\n"); + return 1; + } + + bdev = get_blockdev_by_name(argv[1]); + if (!bdev) { + printf("\n** Block device %s not supported\n", argv[1]); + return 1; + } + + PRINTF("Using device %s\n", argv[1]); + + PRINTF("\nLoading from block device %s, File:%s\n", + argv[1], filename); + + + part_length = reiserfs_set_blk_dev(bdev); + if (part_length == 0) { + printf("** Bad partition - %s **\n", argv[1]); + return 1; + } + + if (!reiserfs_mount(part_length)) { + printf("** Bad Reiserfs partition or disk - %s **\n", argv[1]); + return 1; + } + + filelen = reiserfs_open(filename); + if (filelen < 0) { + printf("** File not found %s\n", filename); + return 1; + } + if ((count < filelen) && (count != 0)) + filelen = count; + + if (reiserfs_read((char *)addr, filelen) != filelen) { + printf("\n** Unable to read \"%s\" from %s **\n", filename, + argv[1]); + return 1; + } + + /* Loading ok, update default load address */ + load_addr = addr; + + printf("\n%ld bytes read\n", filelen); + sprintf(buf, "%lX", filelen); + setenv("filesize", buf); + + return filelen; +} + +U_BOOT_CMD( + reiserload, 5, 0, do_reiserload, + "load binary file from a Reiser filesystem", + " [addr] [filename] [bytes]\n" + " - load binary file 'filename' from 'dev' on 'interface'\n" + " to address 'addr' from dos filesystem" +); diff --git a/fs/reiserfs/Makefile b/fs/reiserfs/Makefile index 495759c..bb30101 100644 --- a/fs/reiserfs/Makefile +++ b/fs/reiserfs/Makefile @@ -30,7 +30,13 @@ include $(TOPDIR)/config.mk LIB = $(obj)libreiserfs.o AOBJS = -COBJS-$(CONFIG_CMD_REISER) := reiserfs.o dev.o mode_string.o +COBJS-$(CONFIG_CMD_REISER) := reiserfs.o mode_string.o + +ifdef CONFIG_DM +COBJS-${CONFIG_CMD_REISER} += dev_dm.o +else +COBJS-${CONFIG_CMD_REISER} += dev.o +endif SRCS := $(AOBJS:.o=.S) $(COBJS-y:.o=.c) OBJS := $(addprefix $(obj),$(AOBJS) $(COBJS-y)) diff --git a/fs/reiserfs/dev_dm.c b/fs/reiserfs/dev_dm.c new file mode 100644 index 0000000..4dad499 --- /dev/null +++ b/fs/reiserfs/dev_dm.c @@ -0,0 +1,104 @@ +/* + * (C) Copyright 2003 - 2004 + * Sysgo AG, , Pavel Bartusek + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +#include +#include +#include + +#include "reiserfs_private.h" + +#include +#include + +static struct instance *bdev; + +int reiserfs_set_blk_dev(struct instance *dev) +{ + struct option op; + int error; + + if (!dev) + return 0; + + error = blockdev_get_option(dev, BLKD_OPT_BLOCKCOUNT, &op); + if (error || (OPTION_TYPE(op) != OPTION_TYPE_U)) + return 0; + bdev = dev; + + return op.data.data_u; +} + + +int reiserfs_devread(int sector, int byte_offset, int byte_len, char *buf) +{ + char sec_buf[SECTOR_SIZE]; + unsigned block_len; + + /* + * Get the read to the beginning of a partition. + */ + sector += byte_offset >> SECTOR_BITS; + byte_offset &= SECTOR_SIZE - 1; + +#if defined(DEBUG) + printf(" <%d, %d, %d> ", sector, byte_offset, byte_len); +#endif + + + if (!bdev) + return 0; + + + if (byte_offset != 0) { + /* read first part which isn't aligned with start of sector */ + if (blockdev_read(bdev, sector, 1, sec_buf) != 1) { + printf(" ** reiserfs_devread() read error\n"); + return 0; + } + memcpy(buf, sec_buf+byte_offset, + min(SECTOR_SIZE-byte_offset, byte_len)); + buf += min(SECTOR_SIZE-byte_offset, byte_len); + byte_len -= min(SECTOR_SIZE-byte_offset, byte_len); + sector++; + } + + /* read sector aligned part */ + block_len = byte_len & ~(SECTOR_SIZE-1); + if (blockdev_read(bdev, sector, block_len / SECTOR_SIZE, buf) != + block_len / SECTOR_SIZE) { + printf(" ** reiserfs_devread() read error - block\n"); + return 0; + } + buf += block_len; + byte_len -= block_len; + sector += block_len/SECTOR_SIZE; + + if (byte_len != 0) { + /* read rest of data which are not in whole sector */ + if (blockdev_read(bdev, sector, 1, sec_buf) != 1) { + printf(" ** reiserfs_devread() read error - " + "last part\n"); + return 0; + } + memcpy(buf, sec_buf, byte_len); + } + + return 1; +} diff --git a/include/reiserfs.h b/include/reiserfs.h index c465b3c..e0ce2c1 100644 --- a/include/reiserfs.h +++ b/include/reiserfs.h @@ -27,6 +27,9 @@ * from the original reiser fs code, as found in the linux kernel. */ +#ifdef CONFIG_DM +#include +#endif #define SECTOR_SIZE 0x200 #define SECTOR_BITS 9 @@ -74,8 +77,11 @@ typedef enum MAX_ERR_NUM } reiserfs_error_t; - +#ifdef CONFIG_DM +extern int reiserfs_set_blk_dev(struct instance *bdev); +#else extern int reiserfs_set_blk_dev(block_dev_desc_t *rbdd, int part); +#endif extern int reiserfs_ls (char *dirname); extern int reiserfs_open (char *filename); extern int reiserfs_read (char *buf, unsigned len);