* [PATCH v2 2/5] command: timeout: add documentation for option '-v'
2015-04-22 8:20 [PATCH v2 1/5] command: timeout: remove unhandled '-t' option Marc Kleine-Budde
@ 2015-04-22 8:20 ` Marc Kleine-Budde
2015-04-22 8:20 ` [PATCH v2 3/5] timeout: factor out wait-for-key-press loop into separate file Marc Kleine-Budde
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2015-04-22 8:20 UTC (permalink / raw)
To: barebox
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
commands/timeout.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/commands/timeout.c b/commands/timeout.c
index 3dee9606eb5d..c8e930cd5b5b 100644
--- a/commands/timeout.c
+++ b/commands/timeout.c
@@ -110,12 +110,13 @@ BAREBOX_CMD_HELP_OPT("-a", "interrupt on any key")
BAREBOX_CMD_HELP_OPT("-c", "interrupt on Ctrl-C")
BAREBOX_CMD_HELP_OPT("-r", "interrupt on RETURN")
BAREBOX_CMD_HELP_OPT("-s", "silent mode")
+BAREBOX_CMD_HELP_OPT("-v <VARIABLE>", "export pressed key to environment")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(timeout)
.cmd = do_timeout,
BAREBOX_CMD_DESC("wait for a specified timeout")
- BAREBOX_CMD_OPTS("[-acrs] SECONDS")
+ BAREBOX_CMD_OPTS("[-acrsv] SECONDS")
BAREBOX_CMD_GROUP(CMD_GRP_CONSOLE)
BAREBOX_CMD_HELP(cmd_timeout_help)
BAREBOX_CMD_END
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 3/5] timeout: factor out wait-for-key-press loop into separate file
2015-04-22 8:20 [PATCH v2 1/5] command: timeout: remove unhandled '-t' option Marc Kleine-Budde
2015-04-22 8:20 ` [PATCH v2 2/5] command: timeout: add documentation for option '-v' Marc Kleine-Budde
@ 2015-04-22 8:20 ` Marc Kleine-Budde
2015-04-22 8:20 ` [PATCH v2 4/5] ubi: cdev: remove trailing newline from debug messages Marc Kleine-Budde
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2015-04-22 8:20 UTC (permalink / raw)
To: barebox
This patch factors out the wait-for-key-press loop from the shell command
"timeout" into a sparate file, so that it can be used from C, too.
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
commands/timeout.c | 62 +++++++++--------------------------------
common/Makefile | 1 +
common/console_countdown.c | 67 +++++++++++++++++++++++++++++++++++++++++++++
include/console_countdown.h | 11 ++++++++
4 files changed, 92 insertions(+), 49 deletions(-)
create mode 100644 common/console_countdown.c
create mode 100644 include/console_countdown.h
diff --git a/commands/timeout.c b/commands/timeout.c
index c8e930cd5b5b..2b99d4f74968 100644
--- a/commands/timeout.c
+++ b/commands/timeout.c
@@ -16,40 +16,35 @@
* GNU General Public License for more details.
*
*/
-#include <common.h>
+
#include <command.h>
-#include <linux/stat.h>
#include <errno.h>
#include <getopt.h>
-#include <clock.h>
#include <environment.h>
+#include <console_countdown.h>
-#define TIMEOUT_RETURN (1 << 0)
-#define TIMEOUT_CTRLC (1 << 1)
-#define TIMEOUT_ANYKEY (1 << 2)
-#define TIMEOUT_SILENT (1 << 3)
+#include <linux/kernel.h>
static int do_timeout(int argc, char *argv[])
{
- int timeout = 3, ret = 1;
- int flags = 0, opt, countdown;
- int key = 0;
- uint64_t start, second;
+ int timeout, ret, opt;
+ unsigned flags = 0;
+ char str[2] = { };
const char *varname = NULL;
while((opt = getopt(argc, argv, "crsav:")) > 0) {
switch(opt) {
case 'r':
- flags |= TIMEOUT_RETURN;
+ flags |= CONSOLE_COUNTDOWN_RETURN;
break;
case 'c':
- flags |= TIMEOUT_CTRLC;
+ flags |= CONSOLE_COUNTDOWN_CTRLC;
break;
case 'a':
- flags |= TIMEOUT_ANYKEY;
+ flags |= CONSOLE_COUNTDOWN_ANYKEY;
break;
case 's':
- flags |= TIMEOUT_SILENT;
+ flags |= CONSOLE_COUNTDOWN_SILENT;
break;
case 'v':
varname = optarg;
@@ -63,43 +58,12 @@ static int do_timeout(int argc, char *argv[])
return COMMAND_ERROR_USAGE;
timeout = simple_strtoul(argv[optind], NULL, 0);
+ ret = console_countdown(timeout, flags, str);
- start = get_time_ns();
- second = start;
-
- countdown = timeout;
-
- if (!(flags & TIMEOUT_SILENT))
- printf("%2d", countdown--);
-
- do {
- if (tstc()) {
- key = getc();
- if (flags & TIMEOUT_CTRLC && key == 3)
- goto out;
- if (flags & TIMEOUT_ANYKEY)
- goto out;
- if (flags & TIMEOUT_RETURN && key == '\n')
- goto out;
- key = 0;
- }
- if (!(flags & TIMEOUT_SILENT) && is_timeout(second, SECOND)) {
- printf("\b\b%2d", countdown--);
- second += SECOND;
- }
- } while (!is_timeout(start, timeout * SECOND));
-
- ret = 0;
-out:
- if (varname && key) {
- char str[2] = { };
- str[0] = key;
+ if (varname && str[0])
setenv(varname, str);
- }
- if (!(flags & TIMEOUT_SILENT))
- printf("\n");
- return ret;
+ return ret ? 1 : 0;
}
BAREBOX_CMD_HELP_START(timeout)
diff --git a/common/Makefile b/common/Makefile
index eca1e3533c3f..2738238c67a8 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_CMD_MEMTEST) += memtest.o
obj-$(CONFIG_COMMAND_SUPPORT) += command.o
obj-$(CONFIG_CONSOLE_FULL) += console.o
obj-$(CONFIG_CONSOLE_SIMPLE) += console_simple.o
+obj-y += console_countdown.o
obj-$(CONFIG_DDR_SPD) += ddr_spd.o
obj-$(CONFIG_ENV_HANDLING) += environment.o
obj-$(CONFIG_ENVIRONMENT_VARIABLES) += env.o
diff --git a/common/console_countdown.c b/common/console_countdown.c
new file mode 100644
index 000000000000..ffbdb4fa2d63
--- /dev/null
+++ b/common/console_countdown.c
@@ -0,0 +1,67 @@
+/*
+ * console_countdown - contdown on the console - interruptible by a keypress
+ *
+ * Copyright (c) 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * 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 version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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 <clock.h>
+#include <command.h>
+#include <errno.h>
+#include <console_countdown.h>
+#include <stdio.h>
+
+int console_countdown(int timeout_s, unsigned flags, char *out_key)
+{
+ uint64_t start, second;
+ int countdown, ret = -EINTR;
+ int key = 0;
+
+ start = get_time_ns();
+ second = start;
+
+ countdown = timeout_s;
+
+ if (!(flags & CONSOLE_COUNTDOWN_SILENT))
+ printf("%2d", countdown--);
+
+ do {
+ if (tstc()) {
+ key = getc();
+ if (flags & CONSOLE_COUNTDOWN_ANYKEY)
+ goto out;
+ if (flags & CONSOLE_COUNTDOWN_RETURN && key == '\n')
+ goto out;
+ if (flags & CONSOLE_COUNTDOWN_CTRLC && key == 3)
+ goto out;
+ key = 0;
+ }
+ if (!(flags & CONSOLE_COUNTDOWN_SILENT) &&
+ is_timeout(second, SECOND)) {
+ printf("\b\b%2d", countdown--);
+ second += SECOND;
+ }
+ } while (!is_timeout(start, timeout_s * SECOND));
+
+ ret = 0;
+
+ out:
+ if (!(flags & CONSOLE_COUNTDOWN_SILENT))
+ printf("\n");
+ if (key && out_key)
+ *out_key = key;
+
+ return ret;
+}
diff --git a/include/console_countdown.h b/include/console_countdown.h
new file mode 100644
index 000000000000..cb46964bc4cd
--- /dev/null
+++ b/include/console_countdown.h
@@ -0,0 +1,11 @@
+#ifndef __CONSOLE_COUNTDOWN_H
+#define __CONSOLE_COUNTDOWN_H
+
+#define CONSOLE_COUNTDOWN_SILENT (1 << 0)
+#define CONSOLE_COUNTDOWN_ANYKEY (1 << 1)
+#define CONSOLE_COUNTDOWN_RETURN (1 << 3)
+#define CONSOLE_COUNTDOWN_CTRLC (1 << 4)
+
+int console_countdown(int timeout_s, unsigned flags, char *out_key);
+
+#endif /* __CONSOLE_COUNTDOWN_H */
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 4/5] ubi: cdev: remove trailing newline from debug messages
2015-04-22 8:20 [PATCH v2 1/5] command: timeout: remove unhandled '-t' option Marc Kleine-Budde
2015-04-22 8:20 ` [PATCH v2 2/5] command: timeout: add documentation for option '-v' Marc Kleine-Budde
2015-04-22 8:20 ` [PATCH v2 3/5] timeout: factor out wait-for-key-press loop into separate file Marc Kleine-Budde
@ 2015-04-22 8:20 ` Marc Kleine-Budde
2015-04-22 8:20 ` [PATCH v2 5/5] of_path: of_find_path(): add possibility to return .bb device Marc Kleine-Budde
2015-04-23 6:12 ` [PATCH v2 1/5] command: timeout: remove unhandled '-t' option Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2015-04-22 8:20 UTC (permalink / raw)
To: barebox
This patch removes the trailing newline "\n" from the ubi/cdev.c debug
messages, as the macro ifself already adds a newine.
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/mtd/ubi/cdev.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index dcd138f55382..90d5b2dd6627 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -25,7 +25,7 @@ static ssize_t ubi_volume_cdev_read(struct cdev *cdev, void *buf, size_t size,
loff_t offp = offset;
int usable_leb_size = vol->usable_leb_size;
- ubi_debug("%s: %zd @ 0x%08llx\n", __func__, size, offset);
+ ubi_debug("%s: %zd @ 0x%08llx", __func__, size, offset);
len = size > usable_leb_size ? usable_leb_size : size;
@@ -38,7 +38,7 @@ static ssize_t ubi_volume_cdev_read(struct cdev *cdev, void *buf, size_t size,
err = ubi_eba_read_leb(ubi, vol, lnum, buf, off, len, 0);
if (err) {
- ubi_err("read error: %s\n", strerror(-err));
+ ubi_err("read error: %s", strerror(-err));
break;
}
off += len;
@@ -68,14 +68,14 @@ static ssize_t ubi_volume_cdev_write(struct cdev* cdev, const void *buf,
if (!priv->written) {
err = ubi_start_update(ubi, vol, vol->used_bytes);
if (err < 0) {
- ubi_err("Cannot start volume update\n");
+ ubi_err("Cannot start volume update");
return err;
}
}
err = ubi_more_update_data(ubi, vol, buf, size);
if (err < 0) {
- ubi_err("Couldnt or partially wrote data \n");
+ ubi_err("Couldnt or partially wrote data");
return err;
}
@@ -117,7 +117,7 @@ static int ubi_volume_cdev_close(struct cdev *cdev)
kfree(buf);
if (err < 0) {
- ubi_err("Couldnt or partially wrote data \n");
+ ubi_err("Couldnt or partially wrote data");
return err;
}
}
@@ -128,7 +128,7 @@ static int ubi_volume_cdev_close(struct cdev *cdev)
err = ubi_check_volume(ubi, vol->vol_id);
if (err < 0) {
- ubi_err("ubi volume check failed: %s\n", strerror(err));
+ ubi_err("ubi volume check failed: %s", strerror(err));
return err;
}
@@ -180,7 +180,7 @@ int ubi_volume_cdev_add(struct ubi_device *ubi, struct ubi_volume *vol)
cdev->priv = priv;
cdev->size = vol->used_bytes;
cdev->dev = &vol->dev;
- ubi_msg("registering %s as /dev/%s\n", vol->name, cdev->name);
+ ubi_msg("registering %s as /dev/%s", vol->name, cdev->name);
ret = devfs_create(cdev);
if (ret) {
kfree(priv);
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 5/5] of_path: of_find_path(): add possibility to return .bb device
2015-04-22 8:20 [PATCH v2 1/5] command: timeout: remove unhandled '-t' option Marc Kleine-Budde
` (2 preceding siblings ...)
2015-04-22 8:20 ` [PATCH v2 4/5] ubi: cdev: remove trailing newline from debug messages Marc Kleine-Budde
@ 2015-04-22 8:20 ` Marc Kleine-Budde
2015-04-23 6:12 ` [PATCH v2 1/5] command: timeout: remove unhandled '-t' option Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2015-04-22 8:20 UTC (permalink / raw)
To: barebox
This patch adds a flags argument to the of_find_path() function. The only flag
defined for now is OF_FIND_PATH_FLAGS_BB. When used on NAND devices, the
function returns the bad block aware device (the ".bb" device).
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/misc/state.c | 2 +-
drivers/of/barebox.c | 20 +-------------------
drivers/of/of_path.c | 12 ++++++++++--
include/of.h | 3 ++-
4 files changed, 14 insertions(+), 23 deletions(-)
diff --git a/drivers/misc/state.c b/drivers/misc/state.c
index f066a836cb93..3b07bb93d725 100644
--- a/drivers/misc/state.c
+++ b/drivers/misc/state.c
@@ -41,7 +41,7 @@ static int state_probe(struct device_d *dev)
if (IS_ERR(state))
return PTR_ERR(state);
- ret = of_find_path(np, "backend", &path);
+ ret = of_find_path(np, "backend", &path, 0);
if (ret)
return ret;
diff --git a/drivers/of/barebox.c b/drivers/of/barebox.c
index 0220bc6b3123..1b3078eb4757 100644
--- a/drivers/of/barebox.c
+++ b/drivers/of/barebox.c
@@ -31,28 +31,10 @@ static int environment_probe(struct device_d *dev)
char *path;
int ret;
- ret = of_find_path(dev->device_node, "device-path", &path);
+ ret = of_find_path(dev->device_node, "device-path", &path, OF_FIND_PATH_FLAGS_BB);
if (ret)
return ret;
- /*
- * The environment support is not bad block aware, hence we
- * have to use the .bb device. Test if we have a nand device
- * and if yes, append .bb to the filename.
- */
- if (!strncmp(path, "/dev/", 5)) {
- struct cdev *cdev;
- char *cdevname;
-
- cdevname = path + 5;
- cdev = cdev_by_name(cdevname);
- if (cdev && cdev->mtd && mtd_can_have_bb(cdev->mtd)) {
- char *bbpath = asprintf("%s.bb", path);
- free(path);
- path = bbpath;
- }
- }
-
dev_info(dev, "setting default environment path to %s\n", path);
default_environment_path_set(path);
diff --git a/drivers/of/of_path.c b/drivers/of/of_path.c
index df63c5782a02..2dc784851de8 100644
--- a/drivers/of/of_path.c
+++ b/drivers/of/of_path.c
@@ -21,6 +21,8 @@
#include <malloc.h>
#include <of.h>
+#include <linux/mtd/mtd.h>
+
struct of_path {
struct cdev *cdev;
struct device_d *dev;
@@ -112,6 +114,7 @@ out:
* @propname: the property name of the path description
* @outpath: if this function returns 0 outpath will contain the path belonging
* to the input path description. Must be freed with free().
+ * @flags: use OF_FIND_PATH_FLAGS_BB to return the .bb device if available
*
* paths in the devicetree have the form of a multistring property. The first
* string contains the full path to the physical device containing the path.
@@ -127,11 +130,12 @@ out:
* device-path = &mmc0, "partname:0";
* device-path = &norflash, "partname:barebox-environment";
*/
-int of_find_path(struct device_node *node, const char *propname, char **outpath)
+int of_find_path(struct device_node *node, const char *propname, char **outpath, unsigned flags)
{
struct of_path op = {};
struct device_node *rnode;
const char *path, *str;
+ bool add_bb = false;
int i, ret;
path = of_get_property(node, propname, NULL);
@@ -166,7 +170,11 @@ int of_find_path(struct device_node *node, const char *propname, char **outpath)
if (!op.cdev)
return -ENOENT;
- *outpath = asprintf("/dev/%s", op.cdev->name);
+ if ((flags & OF_FIND_PATH_FLAGS_BB) && op.cdev->mtd &&
+ mtd_can_have_bb(op.cdev->mtd))
+ add_bb = true;
+
+ *outpath = asprintf("/dev/%s%s", op.cdev->name, add_bb ? ".bb" : "");
return 0;
}
diff --git a/include/of.h b/include/of.h
index 7235138f30bf..2dcb613a77ba 100644
--- a/include/of.h
+++ b/include/of.h
@@ -240,7 +240,8 @@ int of_add_memory(struct device_node *node, bool dump);
void of_add_memory_bank(struct device_node *node, bool dump, int r,
u64 base, u64 size);
struct device_d *of_find_device_by_node_path(const char *path);
-int of_find_path(struct device_node *node, const char *propname, char **outpath);
+#define OF_FIND_PATH_FLAGS_BB 1 /* return .bb device if available */
+int of_find_path(struct device_node *node, const char *propname, char **outpath, unsigned flags);
int of_register_fixup(int (*fixup)(struct device_node *, void *), void *context);
struct device_node *of_find_node_by_alias(struct device_node *root,
const char *alias);
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/5] command: timeout: remove unhandled '-t' option
2015-04-22 8:20 [PATCH v2 1/5] command: timeout: remove unhandled '-t' option Marc Kleine-Budde
` (3 preceding siblings ...)
2015-04-22 8:20 ` [PATCH v2 5/5] of_path: of_find_path(): add possibility to return .bb device Marc Kleine-Budde
@ 2015-04-23 6:12 ` Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2015-04-23 6:12 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: barebox
On Wed, Apr 22, 2015 at 10:20:08AM +0200, Marc Kleine-Budde wrote:
> This patch removes the option '-t', as it's unhandled in the code since it was
> added to barebox.
>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Applied, thanks
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread