* [U-Boot] [PATCH 0/3] common, menu: enhancements
@ 2012-01-15 7:53 Heiko Schocher
2012-01-15 7:53 ` [U-Boot] [PATCH 1/3] common: add possibility for readline_into_buffer timeout Heiko Schocher
` (2 more replies)
0 siblings, 3 replies; 19+ messages in thread
From: Heiko Schocher @ 2012-01-15 7:53 UTC (permalink / raw)
To: u-boot
- add possibility to read a line with defining a timeout
- add possibility to define a statusline in the menu,
which is printed for every menu
- show menu instead starting the u-boot shell
Heiko Schocher (3):
common: add possibility for readline_into_buffer timeout
common, menu: add statusline support
common, menu: show menu on startup if CONFIG_MENU_SHOW is defined
common/cmd_nvedit.c | 2 +-
common/main.c | 25 +++++++++++++++++++++----
common/menu.c | 11 ++++++++++-
doc/README.menu | 5 +++++
include/common.h | 3 ++-
include/menu.h | 3 +++
6 files changed, 42 insertions(+), 7 deletions(-)
---
- This patchserie is needed for the cam_enc_4xx menu update
patch (send soon)
- checkpatch shows no error/warnings
--
1.7.7.4
^ permalink raw reply [flat|nested] 19+ messages in thread
* [U-Boot] [PATCH 1/3] common: add possibility for readline_into_buffer timeout
2012-01-15 7:53 [U-Boot] [PATCH 0/3] common, menu: enhancements Heiko Schocher
@ 2012-01-15 7:53 ` Heiko Schocher
2012-01-15 17:35 ` Mike Frysinger
2012-01-17 7:13 ` [U-Boot] [PATCH 1/3 v2] " Heiko Schocher
2012-01-15 7:53 ` [U-Boot] [PATCH 2/3] common, menu: add statusline support Heiko Schocher
2012-01-15 7:53 ` [U-Boot] [PATCH 3/3] common, menu: show menu on startup if CONFIG_MENU_SHOW is defined Heiko Schocher
2 siblings, 2 replies; 19+ messages in thread
From: Heiko Schocher @ 2012-01-15 7:53 UTC (permalink / raw)
To: u-boot
add possibility to add a timeout when reading a line
into a buffer.
Signed-off-by: Heiko Schocher <hs@denx.de>
---
common/cmd_nvedit.c | 2 +-
common/main.c | 21 +++++++++++++++++----
| 3 ++-
include/common.h | 3 ++-
4 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 63afc82..20080dc 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -502,7 +502,7 @@ int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
else
buffer[0] = '\0';
- readline_into_buffer("edit: ", buffer);
+ readline_into_buffer("edit: ", buffer, 0);
return setenv(argv[1], buffer);
}
diff --git a/common/main.c b/common/main.c
index e96c95a..08070f3 100644
--- a/common/main.c
+++ b/common/main.c
@@ -685,7 +685,8 @@ static void cread_add_str(char *str, int strsize, int insert, unsigned long *num
}
}
-static int cread_line(const char *const prompt, char *buf, unsigned int *len)
+static int cread_line(const char *const prompt, char *buf, unsigned int *len,
+ int timeout)
{
unsigned long num = 0;
unsigned long eol_num = 0;
@@ -695,6 +696,7 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len)
int esc_len = 0;
char esc_save[8];
int init_len = strlen(buf);
+ int first = 1;
if (init_len)
cread_add_str(buf, init_len, 1, &num, &eol_num, buf, *len);
@@ -707,6 +709,17 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len)
WATCHDOG_RESET();
}
#endif
+ if ((first) && (timeout)) {
+ ulong start = get_timer(0);
+ ulong delay = timeout * CONFIG_SYS_HZ;
+
+ while (!tstc()) { /* while no incoming data */
+ if (get_timer(start) > delay)
+ return -2; /* timed out */
+ WATCHDOG_RESET();
+ }
+ first = 0;
+ }
ichar = getcmd_getch();
@@ -922,11 +935,11 @@ int readline (const char *const prompt)
*/
console_buffer[0] = '\0';
- return readline_into_buffer(prompt, console_buffer);
+ return readline_into_buffer(prompt, console_buffer, 0);
}
-int readline_into_buffer (const char *const prompt, char * buffer)
+int readline_into_buffer(const char *const prompt, char *buffer, int timeout)
{
char *p = buffer;
#ifdef CONFIG_CMDLINE_EDITING
@@ -949,7 +962,7 @@ int readline_into_buffer (const char *const prompt, char * buffer)
if (prompt)
puts (prompt);
- rc = cread_line(prompt, p, &len);
+ rc = cread_line(prompt, p, &len, timeout);
return rc < 0 ? rc : len;
} else {
--git a/common/menu.c b/common/menu.c
index 5e0817c..3b1e0d0 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -222,7 +222,8 @@ static inline int menu_interactive_choice(struct menu *m, void **choice)
menu_display(m);
- readret = readline_into_buffer("Enter choice: ", cbuf);
+ readret = readline_into_buffer("Enter choice: ", cbuf,
+ m->timeout);
if (readret >= 0) {
choice_item = menu_item_by_key(m, cbuf);
diff --git a/include/common.h b/include/common.h
index 3df1def..7a9b3a2 100644
--- a/include/common.h
+++ b/include/common.h
@@ -265,7 +265,8 @@ int run_command (const char *cmd, int flag);
int run_command2(const char *cmd, int flag);
#endif
int readline (const char *const prompt);
-int readline_into_buffer (const char *const prompt, char * buffer);
+int readline_into_buffer(const char *const prompt, char *buffer,
+ int timeout);
int parse_line (char *, char *[]);
void init_cmd_timeout(void);
void reset_cmd_timeout(void);
--
1.7.7.4
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [U-Boot] [PATCH 2/3] common, menu: add statusline support
2012-01-15 7:53 [U-Boot] [PATCH 0/3] common, menu: enhancements Heiko Schocher
2012-01-15 7:53 ` [U-Boot] [PATCH 1/3] common: add possibility for readline_into_buffer timeout Heiko Schocher
@ 2012-01-15 7:53 ` Heiko Schocher
2012-01-15 17:36 ` Mike Frysinger
2012-01-17 7:13 ` [U-Boot] [PATCH 2/3 v2] " Heiko Schocher
2012-01-15 7:53 ` [U-Boot] [PATCH 3/3] common, menu: show menu on startup if CONFIG_MENU_SHOW is defined Heiko Schocher
2 siblings, 2 replies; 19+ messages in thread
From: Heiko Schocher @ 2012-01-15 7:53 UTC (permalink / raw)
To: u-boot
add the possibility to show a statusline when printing a menu
Signed-off-by: Heiko Schocher <hs@denx.de>
Cc: Jason Hobbs <jason.hobbs@calxeda.com>
---
| 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
--git a/common/menu.c b/common/menu.c
index 3b1e0d0..754a9f9 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -113,6 +113,13 @@ static inline void *menu_item_destroy(struct menu *m,
return NULL;
}
+void __menu_display_statusline(struct menu *m)
+{
+ return;
+}
+void menu_display_statusline(struct menu *m)
+ __attribute__ ((weak, alias("__menu_display_statusline")));
+
/*
* Display a menu so the user can make a choice of an item. First display its
* title, if any, and then each item in the menu.
@@ -123,6 +130,7 @@ static inline void menu_display(struct menu *m)
puts(m->title);
putc('\n');
}
+ menu_display_statusline(m);
menu_items_iter(m, menu_item_print, NULL);
}
--
1.7.7.4
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [U-Boot] [PATCH 3/3] common, menu: show menu on startup if CONFIG_MENU_SHOW is defined
2012-01-15 7:53 [U-Boot] [PATCH 0/3] common, menu: enhancements Heiko Schocher
2012-01-15 7:53 ` [U-Boot] [PATCH 1/3] common: add possibility for readline_into_buffer timeout Heiko Schocher
2012-01-15 7:53 ` [U-Boot] [PATCH 2/3] common, menu: add statusline support Heiko Schocher
@ 2012-01-15 7:53 ` Heiko Schocher
2012-01-15 17:38 ` Mike Frysinger
2012-01-17 7:13 ` [U-Boot] [PATCH 3/3 v2] " Heiko Schocher
2 siblings, 2 replies; 19+ messages in thread
From: Heiko Schocher @ 2012-01-15 7:53 UTC (permalink / raw)
To: u-boot
show a menu on startup instead running the shell.
Signed-off-by: Heiko Schocher <hs@denx.de>
Cc: Jason Hobbs <jason.hobbs@calxeda.com>
---
common/main.c | 4 ++++
| 5 +++++
| 3 +++
3 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/common/main.c b/common/main.c
index 08070f3..2199ae7 100644
--- a/common/main.c
+++ b/common/main.c
@@ -41,6 +41,7 @@
#include <post.h>
#include <linux/ctype.h>
+#include <menu.h>
#if defined(CONFIG_SILENT_CONSOLE) || defined(CONFIG_POST) || defined(CONFIG_CMDLINE_EDITING)
DECLARE_GLOBAL_DATA_PTR;
@@ -372,6 +373,9 @@ void main_loop (void)
debug ("### main_loop entered: bootdelay=%d\n\n", bootdelay);
+#if defined(CONFIG_MENU_SHOW)
+ bootdelay = menu_show();
+#endif
# ifdef CONFIG_BOOT_RETRY_TIME
init_cmd_timeout ();
# endif /* CONFIG_BOOT_RETRY_TIME */
--git a/doc/README.menu b/doc/README.menu
index 0dad6a2..ba7dcad 100644
--- a/doc/README.menu
+++ b/doc/README.menu
@@ -25,6 +25,11 @@ the interfaces should be available.
Menus are composed of items. Each item has a key used to identify it in
the menu, and an opaque pointer to data controlled by the consumer.
+If you want to show a menu, instead starting the shell, define
+CONFIG_MENU_SHOW. You have to code the int menu_show(void) function,
+which handle your menu. This function returns the remaining
+bootdelay.
+
Interfaces
----------
#include "menu.h"
--git a/include/menu.h b/include/menu.h
index cf14a9c..4cda33d 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -27,4 +27,7 @@ int menu_get_choice(struct menu *m, void **choice);
int menu_item_add(struct menu *m, char *item_key, void *item_data);
int menu_destroy(struct menu *m);
+#if defined(CONFIG_MENU_SHOW)
+int menu_show(void);
+#endif
#endif /* __MENU_H__ */
--
1.7.7.4
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [U-Boot] [PATCH 1/3] common: add possibility for readline_into_buffer timeout
2012-01-15 7:53 ` [U-Boot] [PATCH 1/3] common: add possibility for readline_into_buffer timeout Heiko Schocher
@ 2012-01-15 17:35 ` Mike Frysinger
2012-01-16 6:43 ` Heiko Schocher
2012-01-17 7:13 ` [U-Boot] [PATCH 1/3 v2] " Heiko Schocher
1 sibling, 1 reply; 19+ messages in thread
From: Mike Frysinger @ 2012-01-15 17:35 UTC (permalink / raw)
To: u-boot
On Sunday 15 January 2012 02:53:40 Heiko Schocher wrote:
> --- a/common/main.c
> +++ b/common/main.c
>
> + if ((first) && (timeout)) {
those inner parens make no sense
> + ulong start = get_timer(0);
> + ulong delay = timeout * CONFIG_SYS_HZ;
what do you want the timeout to be in ? milliseconds ? then make that part
of the API (add comments to the relevant funcs), and drop the CONFIG_SYS_HZ
usage.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120115/347da045/attachment.pgp>
^ permalink raw reply [flat|nested] 19+ messages in thread
* [U-Boot] [PATCH 2/3] common, menu: add statusline support
2012-01-15 7:53 ` [U-Boot] [PATCH 2/3] common, menu: add statusline support Heiko Schocher
@ 2012-01-15 17:36 ` Mike Frysinger
2012-01-16 6:54 ` Heiko Schocher
2012-01-17 7:13 ` [U-Boot] [PATCH 2/3 v2] " Heiko Schocher
1 sibling, 1 reply; 19+ messages in thread
From: Mike Frysinger @ 2012-01-15 17:36 UTC (permalink / raw)
To: u-boot
On Sunday 15 January 2012 02:53:41 Heiko Schocher wrote:
> add the possibility to show a statusline when printing a menu
do you have any examples ?
> +void menu_display_statusline(struct menu *m)
a prototype needs to be in menu.h, and documented
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120115/42689b88/attachment.pgp>
^ permalink raw reply [flat|nested] 19+ messages in thread
* [U-Boot] [PATCH 3/3] common, menu: show menu on startup if CONFIG_MENU_SHOW is defined
2012-01-15 7:53 ` [U-Boot] [PATCH 3/3] common, menu: show menu on startup if CONFIG_MENU_SHOW is defined Heiko Schocher
@ 2012-01-15 17:38 ` Mike Frysinger
2012-01-16 6:55 ` Heiko Schocher
2012-01-17 7:13 ` [U-Boot] [PATCH 3/3 v2] " Heiko Schocher
1 sibling, 1 reply; 19+ messages in thread
From: Mike Frysinger @ 2012-01-15 17:38 UTC (permalink / raw)
To: u-boot
On Sunday 15 January 2012 02:53:42 Heiko Schocher wrote:
> --- a/common/main.c
> +++ b/common/main.c
>
> +#if defined(CONFIG_MENU_SHOW)
> + bootdelay = menu_show();
> +#endif
should the current bootdelay get passed in ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120115/7f752804/attachment.pgp>
^ permalink raw reply [flat|nested] 19+ messages in thread
* [U-Boot] [PATCH 1/3] common: add possibility for readline_into_buffer timeout
2012-01-15 17:35 ` Mike Frysinger
@ 2012-01-16 6:43 ` Heiko Schocher
0 siblings, 0 replies; 19+ messages in thread
From: Heiko Schocher @ 2012-01-16 6:43 UTC (permalink / raw)
To: u-boot
Hello Mike,
Mike Frysinger wrote:
> On Sunday 15 January 2012 02:53:40 Heiko Schocher wrote:
>> --- a/common/main.c
>> +++ b/common/main.c
>>
>> + if ((first) && (timeout)) {
>
> those inner parens make no sense
Yep, fixed.
>> + ulong start = get_timer(0);
>> + ulong delay = timeout * CONFIG_SYS_HZ;
>
> what do you want the timeout to be in ? milliseconds ? then make that part
seconds, similiar to bootdelay.
> of the API (add comments to the relevant funcs), and drop the CONFIG_SYS_HZ
> usage.
Fix this (Do it like bootdelay is done, using endticks())
Thanks for the review.
bye,
Heiko
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
^ permalink raw reply [flat|nested] 19+ messages in thread
* [U-Boot] [PATCH 2/3] common, menu: add statusline support
2012-01-15 17:36 ` Mike Frysinger
@ 2012-01-16 6:54 ` Heiko Schocher
0 siblings, 0 replies; 19+ messages in thread
From: Heiko Schocher @ 2012-01-16 6:54 UTC (permalink / raw)
To: u-boot
Hello Mike,
Mike Frysinger wrote:
> On Sunday 15 January 2012 02:53:41 Heiko Schocher wrote:
>> add the possibility to show a statusline when printing a menu
>
> do you have any examples ?
Used in the cam_enc_4xx update patch, see:
[U-Boot] arm, davinci: cam_enc_4xx board updates
http://patchwork.ozlabs.org/patch/136165/
>> +void menu_display_statusline(struct menu *m)
>
> a prototype needs to be in menu.h, and documented
Fixed.
bye,
Heiko
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
^ permalink raw reply [flat|nested] 19+ messages in thread
* [U-Boot] [PATCH 3/3] common, menu: show menu on startup if CONFIG_MENU_SHOW is defined
2012-01-15 17:38 ` Mike Frysinger
@ 2012-01-16 6:55 ` Heiko Schocher
0 siblings, 0 replies; 19+ messages in thread
From: Heiko Schocher @ 2012-01-16 6:55 UTC (permalink / raw)
To: u-boot
Hello Mike,
Mike Frysinger wrote:
> On Sunday 15 January 2012 02:53:42 Heiko Schocher wrote:
>> --- a/common/main.c
>> +++ b/common/main.c
>>
>> +#if defined(CONFIG_MENU_SHOW)
>> + bootdelay = menu_show();
>> +#endif
>
> should the current bootdelay get passed in ?
Yep, fixed.
bye,
Heiko
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
^ permalink raw reply [flat|nested] 19+ messages in thread
* [U-Boot] [PATCH 1/3 v2] common: add possibility for readline_into_buffer timeout
2012-01-15 7:53 ` [U-Boot] [PATCH 1/3] common: add possibility for readline_into_buffer timeout Heiko Schocher
2012-01-15 17:35 ` Mike Frysinger
@ 2012-01-17 7:13 ` Heiko Schocher
2012-01-17 19:14 ` Mike Frysinger
2012-02-17 21:33 ` Stephan Linz
1 sibling, 2 replies; 19+ messages in thread
From: Heiko Schocher @ 2012-01-17 7:13 UTC (permalink / raw)
To: u-boot
add possibility to add a timeout when reading a line
into a buffer.
Signed-off-by: Heiko Schocher <hs@denx.de>
Cc: Mike Frysinger <vapier@gentoo.org>
---
- changes for v2:
- add comments from Mike Frysinger <vapier@gentoo.org>:
- remove useless inner parens
- rework timeout handling in readline_into_buffer():
use endtick(), drop CONIG_SYS_HZ usage
common/cmd_nvedit.c | 2 +-
common/main.c | 20 ++++++++++++++++----
| 3 ++-
include/common.h | 3 ++-
4 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 63afc82..20080dc 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -502,7 +502,7 @@ int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
else
buffer[0] = '\0';
- readline_into_buffer("edit: ", buffer);
+ readline_into_buffer("edit: ", buffer, 0);
return setenv(argv[1], buffer);
}
diff --git a/common/main.c b/common/main.c
index e96c95a..248744b 100644
--- a/common/main.c
+++ b/common/main.c
@@ -685,7 +685,8 @@ static void cread_add_str(char *str, int strsize, int insert, unsigned long *num
}
}
-static int cread_line(const char *const prompt, char *buf, unsigned int *len)
+static int cread_line(const char *const prompt, char *buf, unsigned int *len,
+ int timeout)
{
unsigned long num = 0;
unsigned long eol_num = 0;
@@ -695,6 +696,7 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len)
int esc_len = 0;
char esc_save[8];
int init_len = strlen(buf);
+ int first = 1;
if (init_len)
cread_add_str(buf, init_len, 1, &num, &eol_num, buf, *len);
@@ -707,6 +709,16 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len)
WATCHDOG_RESET();
}
#endif
+ if (first && timeout) {
+ uint64_t etime = endtick(timeout);
+
+ while (!tstc()) { /* while no incoming data */
+ if (get_ticks() >= etime)
+ return -2; /* timed out */
+ WATCHDOG_RESET();
+ }
+ first = 0;
+ }
ichar = getcmd_getch();
@@ -922,11 +934,11 @@ int readline (const char *const prompt)
*/
console_buffer[0] = '\0';
- return readline_into_buffer(prompt, console_buffer);
+ return readline_into_buffer(prompt, console_buffer, 0);
}
-int readline_into_buffer (const char *const prompt, char * buffer)
+int readline_into_buffer(const char *const prompt, char *buffer, int timeout)
{
char *p = buffer;
#ifdef CONFIG_CMDLINE_EDITING
@@ -949,7 +961,7 @@ int readline_into_buffer (const char *const prompt, char * buffer)
if (prompt)
puts (prompt);
- rc = cread_line(prompt, p, &len);
+ rc = cread_line(prompt, p, &len, timeout);
return rc < 0 ? rc : len;
} else {
--git a/common/menu.c b/common/menu.c
index 5e0817c..3b1e0d0 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -222,7 +222,8 @@ static inline int menu_interactive_choice(struct menu *m, void **choice)
menu_display(m);
- readret = readline_into_buffer("Enter choice: ", cbuf);
+ readret = readline_into_buffer("Enter choice: ", cbuf,
+ m->timeout);
if (readret >= 0) {
choice_item = menu_item_by_key(m, cbuf);
diff --git a/include/common.h b/include/common.h
index 3df1def..7a9b3a2 100644
--- a/include/common.h
+++ b/include/common.h
@@ -265,7 +265,8 @@ int run_command (const char *cmd, int flag);
int run_command2(const char *cmd, int flag);
#endif
int readline (const char *const prompt);
-int readline_into_buffer (const char *const prompt, char * buffer);
+int readline_into_buffer(const char *const prompt, char *buffer,
+ int timeout);
int parse_line (char *, char *[]);
void init_cmd_timeout(void);
void reset_cmd_timeout(void);
--
1.7.7.4
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [U-Boot] [PATCH 2/3 v2] common, menu: add statusline support
2012-01-15 7:53 ` [U-Boot] [PATCH 2/3] common, menu: add statusline support Heiko Schocher
2012-01-15 17:36 ` Mike Frysinger
@ 2012-01-17 7:13 ` Heiko Schocher
2012-01-17 19:14 ` Mike Frysinger
1 sibling, 1 reply; 19+ messages in thread
From: Heiko Schocher @ 2012-01-17 7:13 UTC (permalink / raw)
To: u-boot
add the possibility to show a statusline when printing a menu
Signed-off-by: Heiko Schocher <hs@denx.de>
Cc: Jason Hobbs <jason.hobbs@calxeda.com>
Cc: Mike Frysinger <vapier@gentoo.org>
---
- changes for v2:
- add comments from Mike Frysinger <vapier@gentoo.org>:
- add a prototype for the new function menu_display_statusline
in menu.h and document it in doc/README.menu
| 8 ++++++++
| 5 +++++
| 1 +
3 files changed, 14 insertions(+), 0 deletions(-)
--git a/common/menu.c b/common/menu.c
index 3b1e0d0..754a9f9 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -113,6 +113,13 @@ static inline void *menu_item_destroy(struct menu *m,
return NULL;
}
+void __menu_display_statusline(struct menu *m)
+{
+ return;
+}
+void menu_display_statusline(struct menu *m)
+ __attribute__ ((weak, alias("__menu_display_statusline")));
+
/*
* Display a menu so the user can make a choice of an item. First display its
* title, if any, and then each item in the menu.
@@ -123,6 +130,7 @@ static inline void menu_display(struct menu *m)
puts(m->title);
putc('\n');
}
+ menu_display_statusline(m);
menu_items_iter(m, menu_item_print, NULL);
}
--git a/doc/README.menu b/doc/README.menu
index 0dad6a2..4ddf914 100644
--- a/doc/README.menu
+++ b/doc/README.menu
@@ -69,6 +69,11 @@ int menu_get_choice(struct menu *m, void **choice);
*/
int menu_destroy(struct menu *m);
+/*
+ * menu_display_statusline(struct menu *m);
+ * shows a statusline for every menu_display call.
+ */
+void menu_display_statusline(struct menu *m);
Example Code
------------
--git a/include/menu.h b/include/menu.h
index cf14a9c..b806a02 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -26,5 +26,6 @@ int menu_default_set(struct menu *m, char *item_key);
int menu_get_choice(struct menu *m, void **choice);
int menu_item_add(struct menu *m, char *item_key, void *item_data);
int menu_destroy(struct menu *m);
+void menu_display_statusline(struct menu *m);
#endif /* __MENU_H__ */
--
1.7.7.4
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [U-Boot] [PATCH 3/3 v2] common, menu: show menu on startup if CONFIG_MENU_SHOW is defined
2012-01-15 7:53 ` [U-Boot] [PATCH 3/3] common, menu: show menu on startup if CONFIG_MENU_SHOW is defined Heiko Schocher
2012-01-15 17:38 ` Mike Frysinger
@ 2012-01-17 7:13 ` Heiko Schocher
2012-01-17 12:55 ` Jason Hobbs
2012-01-18 6:05 ` [U-Boot] [PATCH 3/3 v3] " Heiko Schocher
1 sibling, 2 replies; 19+ messages in thread
From: Heiko Schocher @ 2012-01-17 7:13 UTC (permalink / raw)
To: u-boot
show a menu on startup instead running the shell.
Signed-off-by: Heiko Schocher <hs@denx.de>
Cc: Jason Hobbs <jason.hobbs@calxeda.com>
Cc: Mike Frysinger <vapier@gentoo.org>
---
- changes for v2:
- add comments from Mike Frysinger <vapier@gentoo.org>
- pass current bootdelay to menu_show
common/main.c | 4 ++++
| 5 +++++
| 3 +++
3 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/common/main.c b/common/main.c
index 248744b..91e888f 100644
--- a/common/main.c
+++ b/common/main.c
@@ -41,6 +41,7 @@
#include <post.h>
#include <linux/ctype.h>
+#include <menu.h>
#if defined(CONFIG_SILENT_CONSOLE) || defined(CONFIG_POST) || defined(CONFIG_CMDLINE_EDITING)
DECLARE_GLOBAL_DATA_PTR;
@@ -372,6 +373,9 @@ void main_loop (void)
debug ("### main_loop entered: bootdelay=%d\n\n", bootdelay);
+#if defined(CONFIG_MENU_SHOW)
+ bootdelay = menu_show(bootdelay);
+#endif
# ifdef CONFIG_BOOT_RETRY_TIME
init_cmd_timeout ();
# endif /* CONFIG_BOOT_RETRY_TIME */
--git a/doc/README.menu b/doc/README.menu
index 4ddf914..6ce6bba 100644
--- a/doc/README.menu
+++ b/doc/README.menu
@@ -25,6 +25,11 @@ the interfaces should be available.
Menus are composed of items. Each item has a key used to identify it in
the menu, and an opaque pointer to data controlled by the consumer.
+If you want to show a menu, instead starting the shell, define
+CONFIG_MENU_SHOW. You have to code the int menu_show(int bootdelay)
+function, which handle your menu. This function returns the remaining
+bootdelay.
+
Interfaces
----------
#include "menu.h"
--git a/include/menu.h b/include/menu.h
index b806a02..7af5fdb 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -28,4 +28,7 @@ int menu_item_add(struct menu *m, char *item_key, void *item_data);
int menu_destroy(struct menu *m);
void menu_display_statusline(struct menu *m);
+#if defined(CONFIG_MENU_SHOW)
+int menu_show(int bootdelay);
+#endif
#endif /* __MENU_H__ */
--
1.7.7.4
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [U-Boot] [PATCH 3/3 v2] common, menu: show menu on startup if CONFIG_MENU_SHOW is defined
2012-01-17 7:13 ` [U-Boot] [PATCH 3/3 v2] " Heiko Schocher
@ 2012-01-17 12:55 ` Jason Hobbs
2012-01-18 6:05 ` [U-Boot] [PATCH 3/3 v3] " Heiko Schocher
1 sibling, 0 replies; 19+ messages in thread
From: Jason Hobbs @ 2012-01-17 12:55 UTC (permalink / raw)
To: u-boot
Dear Heiko,
On Tue, Jan 17, 2012 at 02:13:35AM -0500, Heiko Schocher wrote:
> show a menu on startup instead running the shell.
>
> Signed-off-by: Heiko Schocher <hs@denx.de>
> Cc: Jason Hobbs <jason.hobbs@calxeda.com>
> Cc: Mike Frysinger <vapier@gentoo.org>
A couple of minor fixes in your README addition below, otherwise:
Acked-by: Jason Hobbs <jason.hobbs@calxeda.com>
> ---
> - changes for v2:
> - add comments from Mike Frysinger <vapier@gentoo.org>
> - pass current bootdelay to menu_show
>
> common/main.c | 4 ++++
> doc/README.menu | 5 +++++
> include/menu.h | 3 +++
> 3 files changed, 12 insertions(+), 0 deletions(-)
>
...
> diff --git a/doc/README.menu b/doc/README.menu
> index 4ddf914..6ce6bba 100644
> --- a/doc/README.menu
> +++ b/doc/README.menu
> @@ -25,6 +25,11 @@ the interfaces should be available.
> Menus are composed of items. Each item has a key used to identify it in
> the menu, and an opaque pointer to data controlled by the consumer.
>
> +If you want to show a menu, instead starting the shell, define
"instead of starting the shell"
> +CONFIG_MENU_SHOW. You have to code the int menu_show(int bootdelay)
> +function, which handle your menu. This function returns the remaining
"which handles"
> +bootdelay.
> +
> Interfaces
> ----------
> #include "menu.h"
> diff --git a/include/menu.h b/include/menu.h
> index b806a02..7af5fdb 100644
> --- a/include/menu.h
> +++ b/include/menu.h
> @@ -28,4 +28,7 @@ int menu_item_add(struct menu *m, char *item_key, void *item_data);
> int menu_destroy(struct menu *m);
> void menu_display_statusline(struct menu *m);
>
> +#if defined(CONFIG_MENU_SHOW)
> +int menu_show(int bootdelay);
> +#endif
> #endif /* __MENU_H__ */
> --
> 1.7.7.4
>
^ permalink raw reply [flat|nested] 19+ messages in thread
* [U-Boot] [PATCH 1/3 v2] common: add possibility for readline_into_buffer timeout
2012-01-17 7:13 ` [U-Boot] [PATCH 1/3 v2] " Heiko Schocher
@ 2012-01-17 19:14 ` Mike Frysinger
2012-02-17 21:33 ` Stephan Linz
1 sibling, 0 replies; 19+ messages in thread
From: Mike Frysinger @ 2012-01-17 19:14 UTC (permalink / raw)
To: u-boot
Acked-by: Mike Frysinger <vapier@gentoo.org>
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120117/7de6d364/attachment.pgp>
^ permalink raw reply [flat|nested] 19+ messages in thread
* [U-Boot] [PATCH 2/3 v2] common, menu: add statusline support
2012-01-17 7:13 ` [U-Boot] [PATCH 2/3 v2] " Heiko Schocher
@ 2012-01-17 19:14 ` Mike Frysinger
0 siblings, 0 replies; 19+ messages in thread
From: Mike Frysinger @ 2012-01-17 19:14 UTC (permalink / raw)
To: u-boot
Acked-by: Mike Frysinger <vapier@gentoo.org>
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120117/8534e099/attachment.pgp>
^ permalink raw reply [flat|nested] 19+ messages in thread
* [U-Boot] [PATCH 3/3 v3] common, menu: show menu on startup if CONFIG_MENU_SHOW is defined
2012-01-17 7:13 ` [U-Boot] [PATCH 3/3 v2] " Heiko Schocher
2012-01-17 12:55 ` Jason Hobbs
@ 2012-01-18 6:05 ` Heiko Schocher
1 sibling, 0 replies; 19+ messages in thread
From: Heiko Schocher @ 2012-01-18 6:05 UTC (permalink / raw)
To: u-boot
show a menu on startup instead running the shell.
Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Jason Hobbs <jason.hobbs@calxeda.com>
Cc: Mike Frysinger <vapier@gentoo.org>
---
- changes for v2:
- add comments from Mike Frysinger <vapier@gentoo.org>
- pass current bootdelay to menu_show
- changes for v3:
- add Acked-by: Jason Hobbs <jason.hobbs@calxeda.com>
- add comment from Jason Hobbs <jason.hobbs@calxeda.com>
- spelling fixes in README
---
common/main.c | 4 ++++
| 5 +++++
| 3 +++
3 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/common/main.c b/common/main.c
index 248744b..91e888f 100644
--- a/common/main.c
+++ b/common/main.c
@@ -41,6 +41,7 @@
#include <post.h>
#include <linux/ctype.h>
+#include <menu.h>
#if defined(CONFIG_SILENT_CONSOLE) || defined(CONFIG_POST) || defined(CONFIG_CMDLINE_EDITING)
DECLARE_GLOBAL_DATA_PTR;
@@ -372,6 +373,9 @@ void main_loop (void)
debug ("### main_loop entered: bootdelay=%d\n\n", bootdelay);
+#if defined(CONFIG_MENU_SHOW)
+ bootdelay = menu_show(bootdelay);
+#endif
# ifdef CONFIG_BOOT_RETRY_TIME
init_cmd_timeout ();
# endif /* CONFIG_BOOT_RETRY_TIME */
--git a/doc/README.menu b/doc/README.menu
index 4ddf914..bc33012 100644
--- a/doc/README.menu
+++ b/doc/README.menu
@@ -25,6 +25,11 @@ the interfaces should be available.
Menus are composed of items. Each item has a key used to identify it in
the menu, and an opaque pointer to data controlled by the consumer.
+If you want to show a menu, instead of starting the shell, define
+CONFIG_MENU_SHOW. You have to code the int menu_show(int bootdelay)
+function, which handles your menu. This function returns the remaining
+bootdelay.
+
Interfaces
----------
#include "menu.h"
--git a/include/menu.h b/include/menu.h
index b806a02..7af5fdb 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -28,4 +28,7 @@ int menu_item_add(struct menu *m, char *item_key, void *item_data);
int menu_destroy(struct menu *m);
void menu_display_statusline(struct menu *m);
+#if defined(CONFIG_MENU_SHOW)
+int menu_show(int bootdelay);
+#endif
#endif /* __MENU_H__ */
--
1.7.7.4
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [U-Boot] [PATCH 1/3 v2] common: add possibility for readline_into_buffer timeout
2012-01-17 7:13 ` [U-Boot] [PATCH 1/3 v2] " Heiko Schocher
2012-01-17 19:14 ` Mike Frysinger
@ 2012-02-17 21:33 ` Stephan Linz
2012-02-17 23:18 ` Mike Frysinger
1 sibling, 1 reply; 19+ messages in thread
From: Stephan Linz @ 2012-02-17 21:33 UTC (permalink / raw)
To: u-boot
Hello Heiko,
it seems there is a problem with this patch for some architectures. On
Microblaze I run into linker errors:
common/libcommon.o: In function `cread_line':
u-boot-bref/common/main.c:717: undefined reference to `get_ticks'
u-boot-mbref/common/main.c:717: undefined reference to `get_tbclk'
u-boot-mbref/common/main.c:720: undefined reference to `get_ticks'
AFAICS some architectures lacking these symbols. What is the default
U-Boot design line here. Should we implement the missing symbols for
Microblaze or can you introduce a CONFIG_ option to disable this new
feature?
br,
Stephan
Am Dienstag, den 17.01.2012, 08:13 +0100 schrieb Heiko Schocher:
> add possibility to add a timeout when reading a line
> into a buffer.
>
> Signed-off-by: Heiko Schocher <hs@denx.de>
> Cc: Mike Frysinger <vapier@gentoo.org>
>
> ---
> - changes for v2:
> - add comments from Mike Frysinger <vapier@gentoo.org>:
> - remove useless inner parens
> - rework timeout handling in readline_into_buffer():
> use endtick(), drop CONIG_SYS_HZ usage
>
> common/cmd_nvedit.c | 2 +-
> common/main.c | 20 ++++++++++++++++----
> common/menu.c | 3 ++-
> include/common.h | 3 ++-
> 4 files changed, 21 insertions(+), 7 deletions(-)
>
> diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
> index 63afc82..20080dc 100644
> --- a/common/cmd_nvedit.c
> +++ b/common/cmd_nvedit.c
> @@ -502,7 +502,7 @@ int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
> else
> buffer[0] = '\0';
>
> - readline_into_buffer("edit: ", buffer);
> + readline_into_buffer("edit: ", buffer, 0);
>
> return setenv(argv[1], buffer);
> }
> diff --git a/common/main.c b/common/main.c
> index e96c95a..248744b 100644
> --- a/common/main.c
> +++ b/common/main.c
> @@ -685,7 +685,8 @@ static void cread_add_str(char *str, int strsize, int insert, unsigned long *num
> }
> }
>
> -static int cread_line(const char *const prompt, char *buf, unsigned int *len)
> +static int cread_line(const char *const prompt, char *buf, unsigned int *len,
> + int timeout)
> {
> unsigned long num = 0;
> unsigned long eol_num = 0;
> @@ -695,6 +696,7 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len)
> int esc_len = 0;
> char esc_save[8];
> int init_len = strlen(buf);
> + int first = 1;
>
> if (init_len)
> cread_add_str(buf, init_len, 1, &num, &eol_num, buf, *len);
> @@ -707,6 +709,16 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len)
> WATCHDOG_RESET();
> }
> #endif
> + if (first && timeout) {
> + uint64_t etime = endtick(timeout);
> +
> + while (!tstc()) { /* while no incoming data */
> + if (get_ticks() >= etime)
> + return -2; /* timed out */
> + WATCHDOG_RESET();
> + }
> + first = 0;
> + }
>
> ichar = getcmd_getch();
>
> @@ -922,11 +934,11 @@ int readline (const char *const prompt)
> */
> console_buffer[0] = '\0';
>
> - return readline_into_buffer(prompt, console_buffer);
> + return readline_into_buffer(prompt, console_buffer, 0);
> }
>
>
> -int readline_into_buffer (const char *const prompt, char * buffer)
> +int readline_into_buffer(const char *const prompt, char *buffer, int timeout)
> {
> char *p = buffer;
> #ifdef CONFIG_CMDLINE_EDITING
> @@ -949,7 +961,7 @@ int readline_into_buffer (const char *const prompt, char * buffer)
> if (prompt)
> puts (prompt);
>
> - rc = cread_line(prompt, p, &len);
> + rc = cread_line(prompt, p, &len, timeout);
> return rc < 0 ? rc : len;
>
> } else {
> diff --git a/common/menu.c b/common/menu.c
> index 5e0817c..3b1e0d0 100644
> --- a/common/menu.c
> +++ b/common/menu.c
> @@ -222,7 +222,8 @@ static inline int menu_interactive_choice(struct menu *m, void **choice)
>
> menu_display(m);
>
> - readret = readline_into_buffer("Enter choice: ", cbuf);
> + readret = readline_into_buffer("Enter choice: ", cbuf,
> + m->timeout);
>
> if (readret >= 0) {
> choice_item = menu_item_by_key(m, cbuf);
> diff --git a/include/common.h b/include/common.h
> index 3df1def..7a9b3a2 100644
> --- a/include/common.h
> +++ b/include/common.h
> @@ -265,7 +265,8 @@ int run_command (const char *cmd, int flag);
> int run_command2(const char *cmd, int flag);
> #endif
> int readline (const char *const prompt);
> -int readline_into_buffer (const char *const prompt, char * buffer);
> +int readline_into_buffer(const char *const prompt, char *buffer,
> + int timeout);
> int parse_line (char *, char *[]);
> void init_cmd_timeout(void);
> void reset_cmd_timeout(void);
^ permalink raw reply [flat|nested] 19+ messages in thread
* [U-Boot] [PATCH 1/3 v2] common: add possibility for readline_into_buffer timeout
2012-02-17 21:33 ` Stephan Linz
@ 2012-02-17 23:18 ` Mike Frysinger
0 siblings, 0 replies; 19+ messages in thread
From: Mike Frysinger @ 2012-02-17 23:18 UTC (permalink / raw)
To: u-boot
On Friday 17 February 2012 16:33:32 Stephan Linz wrote:
> Hello Heiko,
please don't top post
> it seems there is a problem with this patch for some architectures. On
> Microblaze I run into linker errors:
>
> common/libcommon.o: In function `cread_line':
> u-boot-bref/common/main.c:717: undefined reference to `get_ticks'
> u-boot-mbref/common/main.c:717: undefined reference to `get_tbclk'
> u-boot-mbref/common/main.c:720: undefined reference to `get_ticks'
>
> AFAICS some architectures lacking these symbols. What is the default
> U-Boot design line here. Should we implement the missing symbols for
> Microblaze or can you introduce a CONFIG_ option to disable this new
> feature?
to keep your sanity, you should implement get_{ticks,tbclk}. look at the
Blackfin implementation ... i think you should be able to copy & paste those
into your own.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120217/b1116077/attachment.pgp>
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2012-02-17 23:18 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-15 7:53 [U-Boot] [PATCH 0/3] common, menu: enhancements Heiko Schocher
2012-01-15 7:53 ` [U-Boot] [PATCH 1/3] common: add possibility for readline_into_buffer timeout Heiko Schocher
2012-01-15 17:35 ` Mike Frysinger
2012-01-16 6:43 ` Heiko Schocher
2012-01-17 7:13 ` [U-Boot] [PATCH 1/3 v2] " Heiko Schocher
2012-01-17 19:14 ` Mike Frysinger
2012-02-17 21:33 ` Stephan Linz
2012-02-17 23:18 ` Mike Frysinger
2012-01-15 7:53 ` [U-Boot] [PATCH 2/3] common, menu: add statusline support Heiko Schocher
2012-01-15 17:36 ` Mike Frysinger
2012-01-16 6:54 ` Heiko Schocher
2012-01-17 7:13 ` [U-Boot] [PATCH 2/3 v2] " Heiko Schocher
2012-01-17 19:14 ` Mike Frysinger
2012-01-15 7:53 ` [U-Boot] [PATCH 3/3] common, menu: show menu on startup if CONFIG_MENU_SHOW is defined Heiko Schocher
2012-01-15 17:38 ` Mike Frysinger
2012-01-16 6:55 ` Heiko Schocher
2012-01-17 7:13 ` [U-Boot] [PATCH 3/3 v2] " Heiko Schocher
2012-01-17 12:55 ` Jason Hobbs
2012-01-18 6:05 ` [U-Boot] [PATCH 3/3 v3] " Heiko Schocher
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.