From: Pavel Herrmann <morpheus.ibis@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 06/11] DM: add cmd_block command
Date: Thu, 20 Sep 2012 21:37:42 +0200 [thread overview]
Message-ID: <1348169867-2917-7-git-send-email-morpheus.ibis@gmail.com> (raw)
In-Reply-To: <1348169867-2917-1-git-send-email-morpheus.ibis@gmail.com>
cmd_block is the equivalent of cmd_sata for DM blockdev/blockctrl devices.
Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
---
common/Makefile | 2 +
common/cmd_block.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 141 insertions(+)
create mode 100644 common/cmd_block.c
diff --git a/common/Makefile b/common/Makefile
index 3d62775..aa09f17 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -66,6 +66,7 @@ COBJS-$(CONFIG_SOURCE) += cmd_source.o
COBJS-$(CONFIG_CMD_SOURCE) += cmd_source.o
COBJS-$(CONFIG_CMD_BDI) += cmd_bdinfo.o
COBJS-$(CONFIG_CMD_BEDBUG) += bedbug.o cmd_bedbug.o
+COBJS-${CONFIG_DM_BLOCK} += cmd_block.o
COBJS-$(CONFIG_CMD_BMP) += cmd_bmp.o
COBJS-$(CONFIG_CMD_BOOTLDR) += cmd_bootldr.o
COBJS-$(CONFIG_CMD_CACHE) += cmd_cache.o
@@ -163,6 +164,7 @@ COBJS-$(CONFIG_CMD_XIMG) += cmd_ximg.o
COBJS-$(CONFIG_YAFFS2) += cmd_yaffs2.o
COBJS-$(CONFIG_CMD_SPL) += cmd_spl.o
COBJS-$(CONFIG_CMD_ZFS) += cmd_zfs.o
+endif
# others
ifdef CONFIG_DDR_SPD
diff --git a/common/cmd_block.c b/common/cmd_block.c
new file mode 100644
index 0000000..d7674c3
--- /dev/null
+++ b/common/cmd_block.c
@@ -0,0 +1,139 @@
+/*
+ * (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 <command.h>
+#include <dm/blockdev.h>
+#include <dm/blockctrl.h>
+#include <dm/manager.h>
+
+/* based on common/cmd_sata.c */
+
+int do_block(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ struct instance *dev;
+ struct option op;
+ int devcount;
+ int portcount;
+ int blocksize;
+ int error;
+
+ switch (argc) {
+ case 0:
+ case 1:
+ case 4:
+ return CMD_RET_USAGE;
+ case 2:
+ if (strncmp(argv[1], "init", 4) == 0) {
+ int i, j;
+ devcount = core_get_count(CORE_BLOCKCTRL);
+ for (i = 0; i < devcount; i++) {
+ dev = core_get_child(CORE_BLOCKCTRL, i);
+ portcount = blockctrl_get_port_count(dev);
+ for (j = 0; j < portcount; j++)
+ blockctrl_rescan_port(dev, j);
+ }
+ return 0;
+ } else if (strncmp(argv[1], "info", 4) == 0) {
+ putc('\n');
+ print_blockdev_info_all();
+ return 0;
+ }
+ return CMD_RET_USAGE;
+ case 3:
+ if (strncmp(argv[1], "info", 4) == 0) {
+ putc('\n');
+ dev = get_blockdev_by_name(argv[2]);
+ print_blockdev_info(dev);
+ return 0;
+ }
+ return CMD_RET_USAGE;
+ default: /*@least 5 args */
+ if (strncmp(argv[1], "read", 4) == 0) {
+ ulong addr = simple_strtoul(argv[3], NULL, 16);
+ ulong cnt = simple_strtoul(argv[5], NULL, 16);
+ ulong n;
+ lbaint_t blk = simple_strtoul(argv[4], NULL, 16);
+
+ dev = get_blockdev_by_name(argv[2]);
+ if (!dev) {
+ printf("\nNo such device found: %s\n", argv[2]);
+ return 0;
+ }
+
+ error = blockdev_get_option(dev, BLKD_OPT_BLOCKSIZE,
+ &op);
+ if (error || (OPTION_TYPE(op) != OPTION_TYPE_U)) {
+ printf("\nUnable to get blocksize from device "
+ "%s\n", argv[2]);
+ return 0;
+ }
+ blocksize = op.data.data_u;
+
+ printf("\nblock read: device %s block # %ld, "
+ "count %ld ... ", argv[2], blk, cnt);
+
+ n = blockdev_read(dev, blk, cnt, (u32 *)addr);
+
+ /* flush cache after read */
+ flush_cache(addr, cnt * blocksize);
+
+ printf("%ld blocks read: %s\n",
+ n, (n == cnt) ? "OK" : "ERROR");
+ return (n == cnt) ? 0 : 1;
+ } else if (strncmp(argv[1], "write", 5) == 0) {
+ ulong addr = simple_strtoul(argv[3], NULL, 16);
+ ulong cnt = simple_strtoul(argv[5], NULL, 16);
+ ulong n;
+ lbaint_t blk = simple_strtoul(argv[4], NULL, 16);
+
+ dev = get_blockdev_by_name(argv[2]);
+ if (!dev) {
+ printf("\nNo such device found: %s\n", argv[2]);
+ return 0;
+ }
+
+ printf("\nblock write: device %s block # %ld, "
+ "count %ld ... ", argv[2], blk, cnt);
+
+ n = blockdev_write(dev, blk, cnt, (u32 *)addr);
+
+ printf("%ld blocks written: %s\n",
+ n, (n == cnt) ? "OK" : "ERROR");
+ return (n == cnt) ? 0 : 1;
+ } else {
+ return CMD_RET_USAGE;
+ }
+
+ return 0;
+ }
+}
+
+U_BOOT_CMD(
+ block, 5, 1, do_block,
+ "block sub system",
+ "init\n"
+ "block info - show available block devices\n"
+ "block read devname addr blk# cnt\n"
+ "block write devname addr blk# cnt"
+);
--
1.7.12
next prev parent reply other threads:[~2012-09-20 19:37 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-20 19:37 [U-Boot] [PATCH 00/11] Add DM blockdev subsystem Pavel Herrmann
2012-09-20 19:37 ` [U-Boot] [PATCH 01/11] DM: add block device core Pavel Herrmann
2012-09-20 19:58 ` Marek Vasut
2012-09-21 7:11 ` Pavel Herrmann
2012-09-21 12:39 ` Marek Vasut
2012-09-21 13:27 ` Pavel Herrmann
2012-09-21 13:53 ` Marek Vasut
2012-09-21 14:57 ` Pavel Herrmann
2012-09-21 15:34 ` Marek Vasut
2012-09-21 15:48 ` Pavel Herrmann
2012-09-21 15:55 ` Marek Vasut
2012-09-21 17:19 ` Pavel Herrmann
2012-09-21 18:00 ` Marek Vasut
2012-09-21 18:53 ` Pavel Herrmann
2012-09-21 19:17 ` Marek Vasut
2012-09-21 19:29 ` Pavel Herrmann
2012-09-21 21:11 ` Marek Vasut
2012-09-21 23:43 ` Pavel Herrmann
2012-09-22 0:09 ` Marek Vasut
2012-09-22 9:39 ` Pavel Herrmann
2012-09-22 13:33 ` Marek Vasut
2012-09-22 13:59 ` Pavel Herrmann
2012-09-24 12:23 ` Pavel Herrmann
2012-09-20 20:49 ` [U-Boot] [U-Boot-DM] " Vikram Narayanan
2012-09-21 7:09 ` Pavel Herrmann
2012-09-21 12:39 ` Marek Vasut
2012-09-20 19:37 ` [U-Boot] [PATCH 02/11] DM: add support for scanning DOS partitions to blockdev core Pavel Herrmann
2012-09-20 20:03 ` Marek Vasut
2012-09-21 7:22 ` Pavel Herrmann
2012-09-21 12:47 ` Marek Vasut
2012-09-21 13:18 ` Pavel Herrmann
2012-09-21 13:54 ` Marek Vasut
2012-09-20 19:37 ` [U-Boot] [PATCH 03/11] DM: add block controller core Pavel Herrmann
2012-09-20 20:05 ` Marek Vasut
2012-09-21 7:21 ` Pavel Herrmann
2012-09-21 12:51 ` Marek Vasut
2012-09-21 13:14 ` Pavel Herrmann
2012-09-21 13:56 ` Marek Vasut
2012-09-21 15:04 ` Pavel Herrmann
2012-09-21 13:33 ` Pavel Herrmann
2012-09-21 13:58 ` Marek Vasut
2012-09-21 15:09 ` Pavel Herrmann
2012-09-21 15:39 ` Marek Vasut
2012-09-21 15:46 ` Pavel Herrmann
2012-09-21 16:08 ` Marek Vasut
2012-09-21 17:22 ` Pavel Herrmann
2012-09-21 18:01 ` Marek Vasut
2012-09-21 19:15 ` Pavel Herrmann
2012-09-21 19:22 ` Marek Vasut
2012-09-20 19:37 ` [U-Boot] [PATCH 04/11] DM: add sata_legacy driver for blockctrl Pavel Herrmann
2012-09-20 19:37 ` [U-Boot] [PATCH 05/11] DM: add ata and partition blockdev drivers Pavel Herrmann
2012-09-20 19:37 ` Pavel Herrmann [this message]
2012-09-20 19:37 ` [U-Boot] [PATCH 07/11] DM: use new blockdev API in FAT Pavel Herrmann
2012-09-20 19:37 ` [U-Boot] [PATCH 08/11] DM: use new blockdev API in ext2 Pavel Herrmann
2012-09-20 19:37 ` [U-Boot] [PATCH 09/11] DM: use new blockdev API in reiserfs Pavel Herrmann
2012-09-20 19:37 ` [U-Boot] [PATCH 10/11] DM: use new blockdev API in ZFS Pavel Herrmann
2012-09-20 19:37 ` [U-Boot] [PATCH 11/11] DM: switch sandbox to DM blockdev Pavel Herrmann
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=1348169867-2917-7-git-send-email-morpheus.ibis@gmail.com \
--to=morpheus.ibis@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox