summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2013-10-07 08:00:25 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2013-10-07 08:00:25 +0200
commit33c56e21eb3bf841c79d9c8a40dedc8b16b774f2 (patch)
treefc0e871d5fc9020e0c4bb01ef0a5cf4ece6060a1 /commands
parentd32008b2797a7c1bb13ec0cb3273de2dfcc97d02 (diff)
parentce8f489122e8390360e87c84888aacfc87743a83 (diff)
downloadbarebox-33c56e21eb3bf841c79d9c8a40dedc8b16b774f2.tar.gz
barebox-33c56e21eb3bf841c79d9c8a40dedc8b16b774f2.tar.xz
Merge branch 'for-next/misc'
Conflicts: commands/Makefile
Diffstat (limited to 'commands')
-rw-r--r--commands/Makefile1
-rw-r--r--commands/crc.c20
-rw-r--r--commands/devinfo.c158
-rw-r--r--commands/ubi.c20
4 files changed, 194 insertions, 5 deletions
diff --git a/commands/Makefile b/commands/Makefile
index f4e0ac63a6..58d27fa905 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -92,3 +92,4 @@ obj-$(CONFIG_CMD_BAREBOX_UPDATE)+= barebox-update.o
obj-$(CONFIG_CMD_MIITOOL) += miitool.o
obj-$(CONFIG_CMD_DETECT) += detect.o
obj-$(CONFIG_CMD_BOOT) += boot.o
+obj-$(CONFIG_CMD_DEVINFO) += devinfo.o
diff --git a/commands/crc.c b/commands/crc.c
index a0071b0e8b..ee8dacff0b 100644
--- a/commands/crc.c
+++ b/commands/crc.c
@@ -82,6 +82,19 @@ out:
return ret;
}
+static int crc_from_file(const char* file, ulong *crc)
+{
+ char * buf;
+
+ buf= read_file(file, NULL);
+
+ if (!buf)
+ return -ENOMEM;
+
+ *crc = simple_strtoul(buf, NULL, 16);
+ return 0;
+}
+
static int do_crc(int argc, char *argv[])
{
loff_t start = 0, size = ~0;
@@ -92,7 +105,7 @@ static int do_crc(int argc, char *argv[])
#endif
int opt, err = 0, filegiven = 0, verify = 0;
- while((opt = getopt(argc, argv, "f:F:v:")) > 0) {
+ while((opt = getopt(argc, argv, "f:F:v:V:")) > 0) {
switch(opt) {
case 'f':
filename = optarg;
@@ -108,6 +121,10 @@ static int do_crc(int argc, char *argv[])
verify = 1;
vcrc = simple_strtoul(optarg, NULL, 0);
break;
+ case 'V':
+ if (!crc_from_file(optarg, &vcrc))
+ verify = 1;
+ break;
default:
return COMMAND_ERROR_USAGE;
}
@@ -153,6 +170,7 @@ BAREBOX_CMD_HELP_OPT ("-f <file>", "Use file instead of memory.\n")
BAREBOX_CMD_HELP_OPT ("-F <file>", "Use file to compare.\n")
#endif
BAREBOX_CMD_HELP_OPT ("-v <crc>", "Verify\n")
+BAREBOX_CMD_HELP_OPT ("-V <file>", "Verify with crc read from <file>\n")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(crc32)
diff --git a/commands/devinfo.c b/commands/devinfo.c
new file mode 100644
index 0000000000..806e45c9ba
--- /dev/null
+++ b/commands/devinfo.c
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2013 Sascha Hauer, Pengutronix
+ *
+ * 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.
+ *
+ */
+
+#include <command.h>
+#include <common.h>
+#include <complete.h>
+#include <driver.h>
+
+static int do_devinfo_subtree(struct device_d *dev, int depth)
+{
+ struct device_d *child;
+ struct cdev *cdev;
+ int i;
+
+ for (i = 0; i < depth; i++)
+ printf(" ");
+
+ printf("`---- %s", dev_name(dev));
+ if (!list_empty(&dev->cdevs)) {
+ printf("\n");
+ list_for_each_entry(cdev, &dev->cdevs, devices_list) {
+ for (i = 0; i < depth + 1; i++)
+ printf(" ");
+ printf("`---- 0x%08llx-0x%08llx: /dev/%s\n",
+ cdev->offset,
+ cdev->offset + cdev->size - 1,
+ cdev->name);
+ }
+ } else {
+ printf("\n");
+ }
+
+ if (!list_empty(&dev->children)) {
+ device_for_each_child(dev, child) {
+ do_devinfo_subtree(child, depth + 1);
+ }
+ }
+
+ return 0;
+}
+
+static int do_devinfo(int argc, char *argv[])
+{
+ struct device_d *dev;
+ struct driver_d *drv;
+ struct param_d *param;
+ int i;
+ struct resource *res;
+
+ if (argc == 1) {
+ printf("devices:\n");
+
+ for_each_device(dev) {
+ if (!dev->parent)
+ do_devinfo_subtree(dev, 0);
+ }
+
+ printf("\ndrivers:\n");
+ for_each_driver(drv)
+ printf("%s\n",drv->name);
+ } else {
+ dev = get_device_by_name(argv[1]);
+
+ if (!dev) {
+ printf("no such device: %s\n",argv[1]);
+ return -1;
+ }
+
+ printf("resources:\n");
+ for (i = 0; i < dev->num_resources; i++) {
+ res = &dev->resource[i];
+ printf("num : %d\n", i);
+ if (res->name)
+ printf("name : %s\n", res->name);
+ printf("start : " PRINTF_CONVERSION_RESOURCE "\nsize : "
+ PRINTF_CONVERSION_RESOURCE "\n",
+ res->start, resource_size(res));
+ }
+
+ printf("driver: %s\n", dev->driver ?
+ dev->driver->name : "none");
+
+ printf("bus: %s\n\n", dev->bus ?
+ dev->bus->name : "none");
+
+ if (dev->info)
+ dev->info(dev);
+
+ printf("%s\n", list_empty(&dev->parameters) ?
+ "no parameters available" : "Parameters:");
+
+ list_for_each_entry(param, &dev->parameters, list) {
+ printf("%16s = %s", param->name, dev_get_param(dev, param->name));
+ if (param->info)
+ param->info(param);
+ printf("\n");
+ }
+#ifdef CONFIG_OFDEVICE
+ if (dev->device_node) {
+ printf("\ndevice node: %s\n", dev->device_node->full_name);
+ of_print_nodes(dev->device_node, 0);
+ }
+#endif
+ }
+
+ return 0;
+}
+
+BAREBOX_CMD_HELP_START(devinfo)
+BAREBOX_CMD_HELP_USAGE("devinfo [DEVICE]\n")
+BAREBOX_CMD_HELP_SHORT("Output device information.\n")
+BAREBOX_CMD_HELP_END
+
+/**
+ * @page devinfo_command
+
+If called without arguments, devinfo shows a summary of the known
+devices and drivers.
+
+If called with a device path being the argument, devinfo shows more
+default information about this device and its parameters.
+
+Example from an MPC5200 based system:
+
+@verbatim
+ barebox:/ devinfo /dev/eth0
+ base : 0x1002b000
+ size : 0x00000000
+ driver: fec_mpc5xxx
+
+ no info available for eth0
+ Parameters:
+ ipaddr = 192.168.23.197
+ ethaddr = 80:81:82:83:84:86
+ gateway = 192.168.23.1
+ netmask = 255.255.255.0
+ serverip = 192.168.23.2
+@endverbatim
+ */
+
+BAREBOX_CMD_START(devinfo)
+ .cmd = do_devinfo,
+ .usage = "Show information about devices and drivers.",
+ BAREBOX_CMD_HELP(cmd_devinfo_help)
+ BAREBOX_CMD_COMPLETE(device_complete)
+BAREBOX_CMD_END
diff --git a/commands/ubi.c b/commands/ubi.c
index 2041df3fd5..57ae79025d 100644
--- a/commands/ubi.c
+++ b/commands/ubi.c
@@ -58,13 +58,25 @@ BAREBOX_CMD_END
static int do_ubiattach(int argc, char *argv[])
{
+ int opt;
struct mtd_info_user user;
int fd, ret;
+ int vid_hdr_offset = 0;
+
+ while((opt = getopt(argc, argv, "O:")) > 0) {
+ switch(opt) {
+ case 'O':
+ vid_hdr_offset = simple_strtoul(optarg, NULL, 0);
+ break;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
- if (argc != 2)
+ if (optind == argc)
return COMMAND_ERROR_USAGE;
- fd = open(argv[1], O_RDWR);
+ fd = open(argv[optind], O_RDWR);
if (fd < 0) {
perror("open");
return 1;
@@ -76,7 +88,7 @@ static int do_ubiattach(int argc, char *argv[])
goto err;
}
- ret = ubi_attach_mtd_dev(user.mtd, UBI_DEV_NUM_AUTO, 0, 20);
+ ret = ubi_attach_mtd_dev(user.mtd, UBI_DEV_NUM_AUTO, vid_hdr_offset, 20);
if (ret < 0)
printf("failed to attach: %s\n", strerror(-ret));
else
@@ -88,7 +100,7 @@ err:
}
static const __maybe_unused char cmd_ubiattach_help[] =
-"Usage: ubiattach <mtddev>\n"
+"Usage: ubiattach [-O vid-hdr-offset] <mtddev>\n"
"Attach <mtddev> to ubi\n";
BAREBOX_CMD_START(ubiattach)