* [PATCH 2/5] command: timeout: add documentation for option '-v'
2015-04-20 8:43 [PATCH 1/5] command: timeout: remove unhandled '-t' option Marc Kleine-Budde
@ 2015-04-20 8:43 ` Marc Kleine-Budde
2015-04-20 8:43 ` [PATCH 3/5] timeout: factor out wait-for-key-press loop into separate file Marc Kleine-Budde
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Marc Kleine-Budde @ 2015-04-20 8:43 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] 9+ messages in thread
* [PATCH 3/5] timeout: factor out wait-for-key-press loop into separate file
2015-04-20 8:43 [PATCH 1/5] command: timeout: remove unhandled '-t' option Marc Kleine-Budde
2015-04-20 8:43 ` [PATCH 2/5] command: timeout: add documentation for option '-v' Marc Kleine-Budde
@ 2015-04-20 8:43 ` Marc Kleine-Budde
2015-04-20 11:13 ` Sascha Hauer
2015-04-20 8:43 ` [PATCH 4/5] ubi: cdev: remove trailing newline from debug messages Marc Kleine-Budde
2015-04-20 8:43 ` [PATCH 5/5] of_path: of_find_path(): add possibility to return .bb device Marc Kleine-Budde
3 siblings, 1 reply; 9+ messages in thread
From: Marc Kleine-Budde @ 2015-04-20 8:43 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/Kconfig | 1 +
commands/timeout.c | 62 ++++++++++-----------------------------------
common/Kconfig | 3 +++
common/Makefile | 1 +
common/simple_timeout.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++
include/simple_timeout.h | 11 ++++++++
6 files changed, 95 insertions(+), 49 deletions(-)
create mode 100644 common/simple_timeout.c
create mode 100644 include/simple_timeout.h
diff --git a/commands/Kconfig b/commands/Kconfig
index 847ff76d1d8b..1c9083381fac 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -1487,6 +1487,7 @@ config CMD_READLINE
config CMD_TIMEOUT
tristate
prompt "timeout"
+ select SIMPLE_TIMEOUT
help
Usage: timeout [-acrs] SECONDS
diff --git a/commands/timeout.c b/commands/timeout.c
index c8e930cd5b5b..23ee753d209b 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 <simple_timeout.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 |= SIMPLE_TIMEOUT_RETURN;
break;
case 'c':
- flags |= TIMEOUT_CTRLC;
+ flags |= SIMPLE_TIMEOUT_CTRLC;
break;
case 'a':
- flags |= TIMEOUT_ANYKEY;
+ flags |= SIMPLE_TIMEOUT_ANYKEY;
break;
case 's':
- flags |= TIMEOUT_SILENT;
+ flags |= SIMPLE_TIMEOUT_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 = is_simple_timeout(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 ? 0 : 1;
}
BAREBOX_CMD_HELP_START(timeout)
diff --git a/common/Kconfig b/common/Kconfig
index 1c5d14c1c0a4..b7a7b2cf8dcc 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -721,6 +721,9 @@ config RESET_SOURCE
of the reset and why the bootloader is currently running. It can be
useful for any kind of system recovery or repair.
+config SIMPLE_TIMEOUT
+ bool
+
endmenu
menu "Debugging"
diff --git a/common/Makefile b/common/Makefile
index eca1e3533c3f..89a2bf50bd90 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -51,6 +51,7 @@ lwl-$(CONFIG_IMD) += imd-barebox.o
obj-$(CONFIG_IMD) += imd.o
obj-$(CONFIG_FILE_LIST) += file-list.o
obj-$(CONFIG_FIRMWARE) += firmware.o
+obj-$(CONFIG_SIMPLE_TIMEOUT) += simple_timeout.o
quiet_cmd_pwd_h = PWDH $@
ifdef CONFIG_PASSWORD
diff --git a/common/simple_timeout.c b/common/simple_timeout.c
new file mode 100644
index 000000000000..d253476251a5
--- /dev/null
+++ b/common/simple_timeout.c
@@ -0,0 +1,66 @@
+/*
+ * timeout - wait for timeout
+ *
+ * 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 <simple_timeout.h>
+#include <stdio.h>
+
+int is_simple_timeout(int timeout_s, unsigned flags, char *out_key)
+{
+ uint64_t start, second;
+ int countdown, ret = false;
+ int key = 0;
+
+ start = get_time_ns();
+ second = start;
+
+ countdown = timeout_s;
+
+ if (!(flags & SIMPLE_TIMEOUT_SILENT))
+ printf("%2d", countdown--);
+
+ do {
+ if (tstc()) {
+ key = getc();
+ if (flags & SIMPLE_TIMEOUT_ANYKEY)
+ goto out;
+ if (flags & SIMPLE_TIMEOUT_RETURN && key == '\n')
+ goto out;
+ if (flags & SIMPLE_TIMEOUT_CTRLC && key == 3)
+ goto out;
+ key = 0;
+ }
+ if (!(flags & SIMPLE_TIMEOUT_SILENT) && is_timeout(second, SECOND)) {
+ printf("\b\b%2d", countdown--);
+ second += SECOND;
+ }
+ } while (!is_timeout(start, timeout_s * SECOND));
+
+ ret = true;
+
+ out:
+ if (!(flags & SIMPLE_TIMEOUT_SILENT))
+ printf("\n");
+ if (key && out_key)
+ *out_key = key;
+
+ return ret;
+}
diff --git a/include/simple_timeout.h b/include/simple_timeout.h
new file mode 100644
index 000000000000..c1deb360955f
--- /dev/null
+++ b/include/simple_timeout.h
@@ -0,0 +1,11 @@
+#ifndef __SIMPLE_TIMEOUT_H
+#define __SIMPLE_TIMEOUT_H
+
+#define SIMPLE_TIMEOUT_SILENT (1 << 0)
+#define SIMPLE_TIMEOUT_ANYKEY (1 << 1)
+#define SIMPLE_TIMEOUT_RETURN (1 << 3)
+#define SIMPLE_TIMEOUT_CTRLC (1 << 4)
+
+int is_simple_timeout(int timeout_s, unsigned flags, char *out_key);
+
+#endif /* __SIMPLE_TIMEOUT_H */
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/5] timeout: factor out wait-for-key-press loop into separate file
2015-04-20 8:43 ` [PATCH 3/5] timeout: factor out wait-for-key-press loop into separate file Marc Kleine-Budde
@ 2015-04-20 11:13 ` Sascha Hauer
2015-04-22 7:49 ` Marc Kleine-Budde
0 siblings, 1 reply; 9+ messages in thread
From: Sascha Hauer @ 2015-04-20 11:13 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: barebox
On Mon, Apr 20, 2015 at 10:43:37AM +0200, Marc Kleine-Budde wrote:
> 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/Kconfig | 1 +
> commands/timeout.c | 62 ++++++++++-----------------------------------
> common/Kconfig | 3 +++
> common/Makefile | 1 +
> common/simple_timeout.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++
> include/simple_timeout.h | 11 ++++++++
> 6 files changed, 95 insertions(+), 49 deletions(-)
> create mode 100644 common/simple_timeout.c
> create mode 100644 include/simple_timeout.h
>
> diff --git a/commands/Kconfig b/commands/Kconfig
> index 847ff76d1d8b..1c9083381fac 100644
> --- a/commands/Kconfig
> +++ b/commands/Kconfig
> @@ -1487,6 +1487,7 @@ config CMD_READLINE
> config CMD_TIMEOUT
> tristate
> prompt "timeout"
> + select SIMPLE_TIMEOUT
Since the linker throws away unused functions anyway I think we don't
need an option for this.
> +#include <clock.h>
> +#include <command.h>
> +#include <errno.h>
> +#include <simple_timeout.h>
> +#include <stdio.h>
> +
> +int is_simple_timeout(int timeout_s, unsigned flags, char *out_key)
I don't like the name very much since we already have a is_timeout
function which does something completely different. Also is_xxx_timeout
seems to imply that this function doesn't wait but only returns a
status.
How about console_countdown() or similar?
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] 9+ messages in thread
* Re: [PATCH 3/5] timeout: factor out wait-for-key-press loop into separate file
2015-04-20 11:13 ` Sascha Hauer
@ 2015-04-22 7:49 ` Marc Kleine-Budde
2015-04-22 8:23 ` Sascha Hauer
0 siblings, 1 reply; 9+ messages in thread
From: Marc Kleine-Budde @ 2015-04-22 7:49 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
[-- Attachment #1.1: Type: text/plain, Size: 2090 bytes --]
On 04/20/2015 01:13 PM, Sascha Hauer wrote:
> On Mon, Apr 20, 2015 at 10:43:37AM +0200, Marc Kleine-Budde wrote:
>> 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/Kconfig | 1 +
>> commands/timeout.c | 62 ++++++++++-----------------------------------
>> common/Kconfig | 3 +++
>> common/Makefile | 1 +
>> common/simple_timeout.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++
>> include/simple_timeout.h | 11 ++++++++
>> 6 files changed, 95 insertions(+), 49 deletions(-)
>> create mode 100644 common/simple_timeout.c
>> create mode 100644 include/simple_timeout.h
>>
>> diff --git a/commands/Kconfig b/commands/Kconfig
>> index 847ff76d1d8b..1c9083381fac 100644
>> --- a/commands/Kconfig
>> +++ b/commands/Kconfig
>> @@ -1487,6 +1487,7 @@ config CMD_READLINE
>> config CMD_TIMEOUT
>> tristate
>> prompt "timeout"
>> + select SIMPLE_TIMEOUT
>
> Since the linker throws away unused functions anyway I think we don't
> need an option for this.
>
>> +#include <clock.h>
>> +#include <command.h>
>> +#include <errno.h>
>> +#include <simple_timeout.h>
>> +#include <stdio.h>
>> +
>> +int is_simple_timeout(int timeout_s, unsigned flags, char *out_key)
>
> I don't like the name very much since we already have a is_timeout
> function which does something completely different. Also is_xxx_timeout
> seems to imply that this function doesn't wait but only returns a
> status.
>
> How about console_countdown() or similar?
What about the return value?
Return -EINTR + set out_key on interruption by user, return 0 otherwise?
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 801 bytes --]
[-- Attachment #2: Type: text/plain, Size: 149 bytes --]
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/5] timeout: factor out wait-for-key-press loop into separate file
2015-04-22 7:49 ` Marc Kleine-Budde
@ 2015-04-22 8:23 ` Sascha Hauer
2015-04-22 8:27 ` Marc Kleine-Budde
0 siblings, 1 reply; 9+ messages in thread
From: Sascha Hauer @ 2015-04-22 8:23 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: barebox
On Wed, Apr 22, 2015 at 09:49:53AM +0200, Marc Kleine-Budde wrote:
> On 04/20/2015 01:13 PM, Sascha Hauer wrote:
> > On Mon, Apr 20, 2015 at 10:43:37AM +0200, Marc Kleine-Budde wrote:
> >> 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/Kconfig | 1 +
> >> commands/timeout.c | 62 ++++++++++-----------------------------------
> >> common/Kconfig | 3 +++
> >> common/Makefile | 1 +
> >> common/simple_timeout.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++
> >> include/simple_timeout.h | 11 ++++++++
> >> 6 files changed, 95 insertions(+), 49 deletions(-)
> >> create mode 100644 common/simple_timeout.c
> >> create mode 100644 include/simple_timeout.h
> >>
> >> diff --git a/commands/Kconfig b/commands/Kconfig
> >> index 847ff76d1d8b..1c9083381fac 100644
> >> --- a/commands/Kconfig
> >> +++ b/commands/Kconfig
> >> @@ -1487,6 +1487,7 @@ config CMD_READLINE
> >> config CMD_TIMEOUT
> >> tristate
> >> prompt "timeout"
> >> + select SIMPLE_TIMEOUT
> >
> > Since the linker throws away unused functions anyway I think we don't
> > need an option for this.
> >
> >> +#include <clock.h>
> >> +#include <command.h>
> >> +#include <errno.h>
> >> +#include <simple_timeout.h>
> >> +#include <stdio.h>
> >> +
> >> +int is_simple_timeout(int timeout_s, unsigned flags, char *out_key)
> >
> > I don't like the name very much since we already have a is_timeout
> > function which does something completely different. Also is_xxx_timeout
> > seems to imply that this function doesn't wait but only returns a
> > status.
> >
> > How about console_countdown() or similar?
>
> What about the return value?
>
> Return -EINTR + set out_key on interruption by user, return 0 otherwise?
Sounds good.
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] 9+ messages in thread
* [PATCH 4/5] ubi: cdev: remove trailing newline from debug messages
2015-04-20 8:43 [PATCH 1/5] command: timeout: remove unhandled '-t' option Marc Kleine-Budde
2015-04-20 8:43 ` [PATCH 2/5] command: timeout: add documentation for option '-v' Marc Kleine-Budde
2015-04-20 8:43 ` [PATCH 3/5] timeout: factor out wait-for-key-press loop into separate file Marc Kleine-Budde
@ 2015-04-20 8:43 ` Marc Kleine-Budde
2015-04-20 8:43 ` [PATCH 5/5] of_path: of_find_path(): add possibility to return .bb device Marc Kleine-Budde
3 siblings, 0 replies; 9+ messages in thread
From: Marc Kleine-Budde @ 2015-04-20 8:43 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] 9+ messages in thread
* [PATCH 5/5] of_path: of_find_path(): add possibility to return .bb device
2015-04-20 8:43 [PATCH 1/5] command: timeout: remove unhandled '-t' option Marc Kleine-Budde
` (2 preceding siblings ...)
2015-04-20 8:43 ` [PATCH 4/5] ubi: cdev: remove trailing newline from debug messages Marc Kleine-Budde
@ 2015-04-20 8:43 ` Marc Kleine-Budde
3 siblings, 0 replies; 9+ messages in thread
From: Marc Kleine-Budde @ 2015-04-20 8:43 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] 9+ messages in thread