Skip to contentSkip to conversation

Add support for pxecfg commands

PATCH Superseded Jason Hobbs 3 participants 19 messages Jun 29, 2011 – Jul 29, 2011

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover Add support for pxecfg commands

The pxecfg commands provide a near subset of the functionality provided by the PXELINUX boot loader. This allows U-boot based systems to be controlled remotely using the same PXE based techniques that many non U-boot based servers use. To avoid identity confusion with PXELINUX, and because not all behavior is identical, we call this feature 'pxecfg'.

As an example, support for the pxecfg commands is enabled for the ca9x4_ct_vxp config.

Additional details are available in the README file added as part of this patch series.

v2 of this patch series separates the menu code from the pxecfg code, giving a reusable menu implementation. It also contains various smaller changes documented in the comment section of the patches.

v3 of this patch series adds a README for the menu, improves the menu interface, and includes other smaller changes documented in the comment section of the patches. The order of patches also changes, with all of the menu support being added first, followed by the pxecfg specific patches.

Jason Hobbs (7):
Add generic, reusable menu code
cosmetic, main: clean up declarations of abortboot common, menu: use abortboot for menu timeout cosmetic, main: correct indentation/spacing issues
common: add run_command2 for running simple or hush commands Add pxecfg command
arm: ca9x4_ct_vxp: enable pxecfg support

 common/Makefile                |    2 +
 common/cmd_pxecfg.c            |  991 ++++++++++++++++++++++++++++++++++++++++
 common/hush.c                  |    2 +-
 common/main.c                  |   62 ++--
 common/menu.c                  |  279 +++++++++++
 doc/README.menu                |  161 +++++++
 doc/README.pxecfg              |  239 ++++++++++
 include/common.h               |    7 +
 include/configs/ca9x4_ct_vxp.h |    5 +
 include/hush.h                 |    2 +-
 include/menu.h                 |   30 ++
 11 files changed, 1744 insertions(+), 36 deletions(-)
 create mode 100644 common/cmd_pxecfg.c
 create mode 100644 common/menu.c
 create mode 100644 doc/README.menu
 create mode 100644 doc/README.pxecfg
 create mode 100644 include/menu.h
#1 lore raw

PATCH v3 1/7 Add generic, reusable menu code

This will be used first by the pxecfg code, but is intended to be generic and reusable for other jobs in U-boot.

---
changes in v2:
- new in v2

changes in v3:
- move timeout support to later patch
- fix NULL case bug in menu_item_key_match
- consistently use 'item_key' instead of 'key'
- move default/prompt logic into menu code
- consistently return int for error propagation
- change option setting functions to menu_create paramaters
- add README.menu

 common/Makefile |    1 +
 common/menu.c   |  266 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 doc/README.menu |  158 ++++++++++++++++++++++++++++++++
 include/menu.h  |   30 ++++++
 4 files changed, 455 insertions(+), 0 deletions(-)
 create mode 100644 common/menu.c
 create mode 100644 doc/README.menu
 create mode 100644 include/menu.h
common/Makefile +1 -0
index 224b7cc..d5bd983 100644
@@ -170,6 +170,7 @@ COBJS-$(CONFIG_CMD_KGDB) += kgdb.o kgdb_stubs.o
 COBJS-$(CONFIG_KALLSYMS) += kallsyms.o
 COBJS-$(CONFIG_LCD) += lcd.o
 COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o
+COBJS-$(CONFIG_MENU) += menu.o
 COBJS-$(CONFIG_MODEM_SUPPORT) += modem.o
 COBJS-$(CONFIG_UPDATE_TFTP) += update.o
 COBJS-$(CONFIG_USB_KEYBOARD) += usb_kbd.o
common/menu.c new file +266 -0

266 lines not on this page · raw message

doc/README.menu new file +158 -0

158 lines not on this page · raw message

include/menu.h new file +30 -0
new file mode 100644
index 0000000..d47e1a0
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2010-2011 Calxeda, Inc.
+ *
+ * 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 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __MENU_H__
+#define __MENU_H__
+
+struct menu;
+
+struct menu *menu_create(char *title, int prompt,
+				void (*item_data_print)(void *));
+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);
+
+#endif /* __MENU_H__ */
Signature · 1 line
1.7.0.4
#2 lore raw

PATCH v3 1/7 Add generic, reusable menu code

Dear "Jason Hobbs",

Quoted 17 lines · In message <[email protected]> you…

This will be used first by the pxecfg code, but is intended to be generic and reusable for other jobs in U-boot.

---
changes in v2:
- new in v2

changes in v3:
- move timeout support to later patch
- fix NULL case bug in menu_item_key_match
- consistently use 'item_key' instead of 'key'
- move default/prompt logic into menu code
- consistently return int for error propagation
- change option setting functions to menu_create paramaters
- add README.menu

Quoted 8 lines
 common/Makefile |    1 +
 common/menu.c   |  266 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 doc/README.menu |  158 ++++++++++++++++++++++++++++++++
 include/menu.h  |   30 ++++++
 4 files changed, 455 insertions(+), 0 deletions(-)
 create mode 100644 common/menu.c
 create mode 100644 doc/README.menu
 create mode 100644 include/menu.h

I am happy that you provide documentation in doc/README.menu, but I really dislike that the code itself is basicly uncommented. It is a major pain to have to switch between the README and the source files when trying to understand the code.

Please add sufficient comments to the code to make it readable.

Thanks.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
It is practically impossible to teach good programming style to  stu-
dents that have had prior exposure to BASIC: as potential programmers
they are mentally mutilated beyond hope of regeneration.   - Dijkstra
#3 lore raw

PATCH v3 1/7 Add generic, reusable menu code

Dear Wolfgang,

Quoted 6 lines · Wolfgang Denk

I am happy that you provide documentation in doc/README.menu, but I really dislike that the code itself is basicly uncommented. It is a major pain to have to switch between the README and the source files when trying to understand the code.

Please add sufficient comments to the code to make it readable.

I don't want to duplicate the interface documentation in the README and the source file. Maybe I'll add shorter summary descriptions to the README and move the detailed interface doc into the source file. I'll also add some comments for describing the behavior of the internals.

Thanks,
Jason

#4 lore raw

PATCH v3 2/7 cosmetic, main: clean up declarations of abortboot

In reply to Jason Hobbs

Remove an unneeded prototype declaration from the top of main.c, and use plain inline instead of __inline__ to please checkpatch.

---
changes in v3:
- new in v3

 common/main.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
common/main.c +2 -6
index 2730c6f..01931a1 100644
@@ -56,10 +56,6 @@ void update_tftp (void);
 
 #define MAX_DELAY_STOP_STR 32
 
-#if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
-static int abortboot(int);
-#endif
-
 #undef DEBUG_PARSER
 
 char        console_buffer[CONFIG_SYS_CBSIZE + 1];	/* console I/O buffer	*/
@@ -91,7 +87,7 @@ extern void mdm_init(void); /* defined in board.c */
  */
 #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
 # if defined(CONFIG_AUTOBOOT_KEYED)
-static __inline__ int abortboot(int bootdelay)
+static inline int abortboot(int bootdelay)
 {
 	int abort = 0;
 	uint64_t etime = endtick(bootdelay);
@@ -205,7 +201,7 @@ static __inline__ int abortboot(int bootdelay)
 static int menukey = 0;
 #endif
 
-static __inline__ int abortboot(int bootdelay)
+static inline int abortboot(int bootdelay)
 {
 	int abort = 0;
 
Signature · 1 line
1.7.0.4
#5 lore raw

PATCH v3 2/7 cosmetic, main: clean up declarations of abortboot

Dear "Jason Hobbs",

Quoted 10 lines · In message <[email protected]> you…

Remove an unneeded prototype declaration from the top of main.c, and use plain inline instead of __inline__ to please checkpatch.

---
changes in v3:
- new in v3

 common/main.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Blast medicine anyway!  We've learned to tie into every organ in the
human body but one.  The brain!  The brain is what life is all about.
	-- McCoy, "The Menagerie", stardate 3012.4
#6 lore raw

PATCH v3 3/7 common, menu: use abortboot for menu timeout

In reply to Jason Hobbs

---
changes in v2:
- expose abortboot externally instead of using a wrapper
- expose abortboot externally when CONFIG_MENU is set

changes in v3:
- simplify the conditional export of abortboot
- add timeout support for the menu in this patch
- add doc for timeout feature

 common/main.c    |   10 ++++++++--
 common/menu.c    |   17 +++++++++++++++--
 doc/README.menu  |   25 ++++++++++++++-----------
 include/common.h |    3 +++
 include/menu.h   |    2 +-
 5 files changed, 41 insertions(+), 16 deletions(-)
common/main.c +8 -2
index 01931a1..1a371b1 100644
@@ -87,7 +87,10 @@ extern void mdm_init(void); /* defined in board.c */
  */
 #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
 # if defined(CONFIG_AUTOBOOT_KEYED)
-static inline int abortboot(int bootdelay)
+#ifndef CONFIG_MENU
+static inline
+#endif
+int abortboot(int bootdelay)
 {
 	int abort = 0;
 	uint64_t etime = endtick(bootdelay);
@@ -201,7 +204,10 @@ static inline int abortboot(int bootdelay)
 static int menukey = 0;
 #endif
 
-static inline int abortboot(int bootdelay)
+#ifndef CONFIG_MENU
+static inline
+#endif
+int abortboot(int bootdelay)
 {
 	int abort = 0;
 
common/menu.c +15 -2
index 9bcd906..507b122 100644
@@ -30,6 +30,7 @@ struct menu_item {
 
 struct menu {
 	struct menu_item *default_item;
+	int timeout;
 	char *title;
 	int prompt;
 	void (*item_data_print)(void *);
@@ -113,9 +114,20 @@ static inline struct menu_item *menu_item_by_key(struct menu *m,
 	return menu_items_iter(m, menu_item_key_match, item_key);
 }
 
+static inline int menu_interrupted(struct menu *m)
+{
+	if (!m->timeout)
+		return 0;
+
+	if (abortboot(m->timeout/10))
+		return 1;
+
+	return 0;
+}
+
 static inline int menu_use_default(struct menu *m)
 {
-	return !m->prompt;
+	return !m->prompt && !menu_interrupted(m);
 }
 
 static inline int menu_default_choice(struct menu *m, void **choice)
@@ -221,7 +233,7 @@ int menu_item_add(struct menu *m, char *item_key, void *item_data)
 	return 1;
 }
 
-struct menu *menu_create(char *title, int prompt,
+struct menu *menu_create(char *title, int timeout, int prompt,
 				void (*item_data_print)(void *))
 {
 	struct menu *m;
@@ -233,6 +245,7 @@ struct menu *menu_create(char *title, int prompt,
 
 	m->default_item = NULL;
 	m->prompt = prompt;
+	m->timeout = timeout;
 	m->item_data_print = item_data_print;
 
 	if (title) {
doc/README.menu +14 -11
index bca44be..aa48b6f 100644
@@ -31,7 +31,7 @@ Interfaces
 
 struct menu;
 
-struct menu *menu_create(char *title, int prompt,
+struct menu *menu_create(char *title, int timeout, int prompt,
 				void (*item_data_print)(void *));
 int menu_item_add(struct menu *m, char *item_key, void *item_data);
 int menu_default_set(struct menu *m, char *item_key);
@@ -44,8 +44,12 @@ menu_create() - Creates a menu handle with default settings
   the list of menu items. It will be copied to internal storage, and is
   safe to discard after passing to menu_create().
 
-  prompt - If 0, don't ask for user input. If 1, the user will be ed for
-  promptinput.
+  timeout - A delay in seconds to wait for user input. If 0, timeout is
+  disabled, and the default choice will be returned unless prompt is 1.
+
+  prompt - If 0, don't ask for user input unless there is an interrupted
+  timeout. If 1, the user will be prompted for input regardless of the
+  value of timeout.
 
   item_data_print - If not NULL, will be called for each item when
   the menu is displayed, with the pointer to the item's data passed
@@ -76,7 +80,7 @@ menu_item_add() - Adds or replaces a menu item
 
 
 menu_default_set() - Sets the default choice for the menu. This is safe
-to call more than once.
+  to call more than once.
 
   m - Points to a menu created by menu_create().
 
@@ -88,8 +92,8 @@ to call more than once.
 
 
 menu_get_choice() - Returns the user's selected menu entry, or the
-default if the menu is set to not prompt. This is safe to call more than
-once.
+  default if the menu is set to not prompt or the timeout expires.
+  This is safe to call more than once.
 
   m - Points to a menu created by menu_create().
 
@@ -97,9 +101,9 @@ once.
   selected menu item. If no item is selected or there is an error, no
   value will be written at the location it points to.
 
-  Returns 1 if successful, -EINVAL if m or choice is NULL, -ENOENT if no
-  default has been set and the menu is set to not prompt, or -EINTR if
-  the user exits the menu via ctrl+c.
+  Returns 1 if successful, -EINVAL if m or choice is NULL, -ENOENT if
+  no default has been set and the menu is set to not prompt or the
+  timeout expires, or -EINTR if the user exits the menu via ctrl+c.
 
 
 menu_destroy() - frees the memory used by a menu and its items.
@@ -108,7 +112,6 @@ menu_destroy() - frees the memory used by a menu and its items.
 
   Returns 1 if successful, or -EINVAL if m is NULL.
 
-
 Example
 -------
 This example creates a menu that always prompts, and allows the user
@@ -129,7 +132,7 @@ char *pick_a_tool(void)
 	int i;
 	char *tool = NULL;
 
-	m = menu_create("Tools", 1, NULL);
+	m = menu_create("Tools", 0, 1, NULL);
 
 	for(i = 0; tools[i]; i++) {
 		if (menu_item_add(m, tools[i], tools[i]) != 1) {
include/common.h +3 -0
index 1e21b7a..394a005 100644
@@ -233,6 +233,9 @@ int	readline_into_buffer	(const char *const prompt, char * buffer);
 int	parse_line (char *, char *[]);
 void	init_cmd_timeout(void);
 void	reset_cmd_timeout(void);
+#ifdef CONFIG_MENU
+int	abortboot(int bootdelay);
+#endif
 
 /* arch/$(ARCH)/lib/board.c */
 void	board_init_f  (ulong) __attribute__ ((noreturn));
include/menu.h +1 -1
index d47e1a0..cf14a9c 100644
@@ -20,7 +20,7 @@
 
 struct menu;
 
-struct menu *menu_create(char *title, int prompt,
+struct menu *menu_create(char *title, int timeout, int prompt,
 				void (*item_data_print)(void *));
 int menu_default_set(struct menu *m, char *item_key);
 int menu_get_choice(struct menu *m, void **choice);
Signature · 1 line
1.7.0.4
#7 lore raw

PATCH v3 4/7 cosmetic, main: correct indentation/spacing issues

In reply to Jason Hobbs

---
changes in v2:
- new in v2

 common/main.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
common/main.c +6 -6
index 1a371b1..489c9e9 100644
@@ -397,15 +397,15 @@ void main_loop (void)
 
 # ifdef CONFIG_MENUKEY
 	if (menukey == CONFIG_MENUKEY) {
-	    s = getenv("menucmd");
-	    if (s) {
+		s = getenv("menucmd");
+		if (s) {
 # ifndef CONFIG_SYS_HUSH_PARSER
-		run_command (s, 0);
+			run_command(s, 0);
 # else
-		parse_string_outer(s, FLAG_PARSE_SEMICOLON |
-				    FLAG_EXIT_FROM_LOOP);
+			parse_string_outer(s, FLAG_PARSE_SEMICOLON |
+						FLAG_EXIT_FROM_LOOP);
 # endif
-	    }
+		}
 	}
 #endif /* CONFIG_MENUKEY */
 #endif /* CONFIG_BOOTDELAY */
Signature · 1 line
1.7.0.4
#8 lore raw

PATCH v3 4/7 cosmetic, main: correct indentation/spacing issues

Dear "Jason Hobbs",

Quoted 7 lines · In message <[email protected]> you…

---
changes in v2:
- new in v2

 common/main.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
C++ was an interesting and valuable experiment, but we've learned its
lessons and it's time to move on.
                            - Peter Curran in <[email protected]>
#9 lore raw

PATCH v3 5/7 common: add run_command2 for running simple or hush commands

In reply to Jason Hobbs

---
changes in v2:
- whitespace correction

 common/hush.c    |    2 +-
 common/main.c    |   46 +++++++++++++++++++---------------------------
 include/common.h |    1 +
 include/hush.h   |    2 +-
 4 files changed, 22 insertions(+), 29 deletions(-)
common/hush.c +1 -1
index 85a6030..940889b 100644
@@ -3217,7 +3217,7 @@ int parse_stream_outer(struct in_str *inp, int flag)
 #ifndef __U_BOOT__
 static int parse_string_outer(const char *s, int flag)
 #else
-int parse_string_outer(char *s, int flag)
+int parse_string_outer(const char *s, int flag)
 #endif	/* __U_BOOT__ */
 {
 	struct in_str input;
common/main.c +19 -27

77 lines not on this page · raw message

include/common.h +1 -0
index 394a005..bd2c1a0 100644
@@ -228,6 +228,7 @@ int	print_buffer (ulong addr, void* data, uint width, uint count, uint linelen);
 /* common/main.c */
 void	main_loop	(void);
 int	run_command	(const char *cmd, int flag);
+int	run_command2	(const char *cmd, int flag);
 int	readline	(const char *const prompt);
 int	readline_into_buffer	(const char *const prompt, char * buffer);
 int	parse_line (char *, char *[]);
include/hush.h +1 -1
index 5c566cc..ecf9222 100644
@@ -29,7 +29,7 @@
 #define FLAG_REPARSING       (1 << 2)	  /* >=2nd pass */
 
 extern int u_boot_hush_start(void);
-extern int parse_string_outer(char *, int);
+extern int parse_string_outer(const char *, int);
 extern int parse_file_outer(void);
 
 int set_local_var(const char *s, int flg_export);
Signature · 1 line
1.7.0.4
#10 lore raw

PATCH v3 5/7 common: add run_command2 for running simple or hush commands

Dear "Jason Hobbs",

Quoted 4 lines · In message <[email protected]> you…

---
changes in v2:
- whitespace correction

...

common/main.c void main_loop (void) · line 336

Quoted 13 lines
common/main.c +1 -6
@@ -333,12 +333,7 @@ void main_loop (void)
 		int prev = disable_ctrlc(1);	/* disable Control C checking */
 # endif
 
-# ifndef CONFIG_SYS_HUSH_PARSER
-		run_command (p, 0);
-# else
-		parse_string_outer(p, FLAG_PARSE_SEMICOLON |
-				    FLAG_EXIT_FROM_LOOP);
-# endif
+	run_command2(p, 0);

Indentation seems wrong here - it should be one TAB more to the right?

common/main.c int run_command (const char *cmd, int flag) · line 1385

Quoted 12 lines
common/main.c +12 -0
+int run_command2(const char *cmd, int flag)
+{
+#ifndef CONFIG_SYS_HUSH_PARSER
+	if (run_command(cmd, flag) == -1)
+		return 1;
+#else
+	if (parse_string_outer(cmd,
+	    FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
+		return 1;
+#endif
+	return 0;
+}

Can we make this inline [in the normal (non-menu) case], please?

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"God is a comedian playing to an audience too afraid to laugh."
- Voltaire
#11 lore raw

PATCH v3 5/7 common: add run_command2 for running simple or hush commands

Quoted 6 lines · Wolfgang Denk

Dear "Jason Hobbs",

Quoted 3 lines

-# ifndef CONFIG_SYS_HUSH_PARSER - run_command (p, 0); -#
else - parse_string_outer(p, FLAG_PARSE_SEMICOLON | -
FLAG_EXIT_FROM_LOOP); -# endif + run_command2(p, 0);

Indentation seems wrong here - it should be one TAB more to the right?

Grr, yes. I will change and resubmit.

Quoted 15 lines

common/main.c int run_command (const char *cmd, int flag) · line 1385

Quoted 13 lines
common/main.c +12 -0
+int run_command2(const char *cmd, int flag)
+{
+#ifndef CONFIG_SYS_HUSH_PARSER
+	if (run_command(cmd, flag) == -1)
+		return 1;
+#else
+	if (parse_string_outer(cmd,
+	    FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
+		return 1;
+#endif
+	return 0;
+}

Can we make this inline [in the normal (non-menu) case], please?

Yes, I will change and resubmit.

Thanks,
Jason

#12 lore raw

PATCH v3 6/7 Add pxecfg command

In reply to Jason Hobbs

Add pxecfg command, which is intended to mimic PXELINUX functionality. 'pxecfg get' uses tftp to retrieve a file based on UUID, MAC address or IP address. 'pxecfg boot' interprets the contents of PXELINUX config like file to boot using a specific initrd, kernel and kernel command line.

This patch also adds a README.pxecfg file - see it for more details on the pxecfg command.

---
changes in v2:
- call abortboot directly instead of via a wrapper
- change the license to GPLv2+
- cleanup brace usage in multiline statements, conditionals
- allow bootfile to not exist, or to be a standalone filename
- try to clarify what's going on with get_relfile
- try cfg paths one by one instead of building an array
- refactor getenv/printfs to a new from_env function
- use the new generic menu code instead of that being integrated
- drop the ifdef from do_tftp in common.h
- use a clearer comment wrt to localcmd dup
- default to no timeout

changes in v3:
- use GPLv2+ license for the readme
- parse and create menu in separate steps
- adapt to menu interface changes

 common/Makefile     |    1 +
 common/cmd_pxecfg.c |  991 +++++++++++++++++++++++++++++++++++++++++++++++++++
 doc/README.pxecfg   |  239 +++++++++++++
 include/common.h    |    3 +
 4 files changed, 1234 insertions(+), 0 deletions(-)
 create mode 100644 common/cmd_pxecfg.c
 create mode 100644 doc/README.pxecfg
common/Makefile +1 -0
index d5bd983..6a56f9f 100644
@@ -136,6 +136,7 @@ COBJS-$(CONFIG_CMD_PCI) += cmd_pci.o
 endif
 COBJS-y += cmd_pcmcia.o
 COBJS-$(CONFIG_CMD_PORTIO) += cmd_portio.o
+COBJS-$(CONFIG_CMD_PXECFG) += cmd_pxecfg.o
 COBJS-$(CONFIG_CMD_REGINFO) += cmd_reginfo.o
 COBJS-$(CONFIG_CMD_REISER) += cmd_reiser.o
 COBJS-$(CONFIG_CMD_SATA) += cmd_sata.o
common/cmd_pxecfg.c new file +991 -0

991 lines not on this page · raw message

doc/README.pxecfg new file +239 -0

239 lines not on this page · raw message

include/common.h +3 -0
index bd2c1a0..9b60469 100644
@@ -259,6 +259,9 @@ extern ulong load_addr;		/* Default Load Address */
 /* common/cmd_doc.c */
 void	doc_probe(unsigned long physadr);
 
+/* common/cmd_net.c */
+int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+
 /* common/cmd_nvedit.c */
 int	env_init     (void);
 void	env_relocate (void);
Signature · 1 line
1.7.0.4
#13 lore raw

PATCH v3 6/7 Add pxecfg command

Dear "Jason Hobbs",

Quoted 8 lines · In message <[email protected]> you…

Add pxecfg command, which is intended to mimic PXELINUX functionality. 'pxecfg get' uses tftp to retrieve a file based on UUID, MAC address or IP address. 'pxecfg boot' interprets the contents of PXELINUX config like file to boot using a specific initrd, kernel and kernel command line.

This patch also adds a README.pxecfg file - see it for more details on the pxecfg command.

After thinking a long while about this, I came to the conclusion that my initial feeling that "pxecfg" is ugly was actually correct. Please let's call this simply "pxe" as I already suggested in my initial feedback.

Another general comment: you are adding tons of completely undocumented, uncommented code here.

This is not acceptable. Please provide sufficient comments so that the average engineer has a chance to understand what the code is (supposed to be) doing without spending needless effords.

common/cmd_pxecfg.c line 39

Quoted 11 lines
common/cmd_pxecfg.c new file +11 -0
+static char *from_env(char *envvar)
+{
+	char *ret;
+
+	ret = getenv(envvar);
+
+	if (!ret)
+		printf("missing environment variable: %s\n", envvar);
+
+	return ret;
+}

I don't like this. It just blows up the code and shifts error handling from the place where it happens. In the result, you will have to check return codes on several function call levels. I recommend to drop this function.

common/cmd_pxecfg.c line 44

Quoted 4 lines
common/cmd_pxecfg.c new file +4 -0
+/*
+ * Returns the ethaddr environment variable formated with -'s instead of :'s
+ */
+static void format_mac_pxecfg(char **outbuf)

void?

common/cmd_pxecfg.c line 48

Quoted 3 lines
common/cmd_pxecfg.c new file +3 -0
+	char *p, *ethaddr;
+
+	*outbuf = NULL;

This is redundant, please omit.

common/cmd_pxecfg.c line 53

Quoted 4 lines
common/cmd_pxecfg.c new file +4 -0
+	ethaddr = from_env("ethaddr");
+
+	if (!ethaddr)
+		return;

It makes little sense to check for errors, to report errors, and then to continue as if nothing happened.

common/cmd_pxecfg.c line 55

Quoted 1 line
common/cmd_pxecfg.c new file +1 -0
+	*outbuf = strdup(ethaddr);

Can we please al;locate the buffer in the caller, and do without this? This is only good for memory leaks.

Quoted 8 lines
common/cmd_pxecfg.c new file +8 -0
+/*
+ * Returns the directory the file specified in the bootfile env variable is
+ * in.
+ */
+static char *get_bootfile_path(void)
+{
+	char *bootfile, *bootfile_path, *last_slash;
+	size_t path_len;

common/cmd_pxecfg.c line 83

Quoted 10 lines
common/cmd_pxecfg.c new file +10 -0
+
+	bootfile = from_env("bootfile");
+
+	if (!bootfile)
+		return NULL;
+
+	last_slash = strrchr(bootfile, '/');
+
+	if (last_slash == NULL)
+		return NULL;

This looks unnecessarily stringent to me. Why can we not accept a plain file name [we can always use "./" if we need a path for the directory] ?

common/cmd_pxecfg.c line 124

Quoted 4 lines
common/cmd_pxecfg.c new file +4 -0
+	if (path_len > MAX_TFTP_PATH_LEN) {
+		printf("Base path too long (%s%s)\n",
+					bootfile_path ? bootfile_path : "",
+					file_path);

Indentation is one level only. Please fix globally.

common/cmd_pxecfg.c line 129

Quoted 4 lines
common/cmd_pxecfg.c new file +4 -0
+		if (bootfile_path)
+			free(bootfile_path);
+
+		return -ENAMETOOLONG;

All this dynamically allocated strings just blow up the code. Can we try to do without?

common/cmd_pxecfg.c line 139

Quoted 1 line
common/cmd_pxecfg.c new file +1 -0
+	printf("Retreiving file: %s\n", relfile);

Typo: s/ei/ie/

common/cmd_pxecfg.c line 148

Quoted 3 lines
common/cmd_pxecfg.c new file +3 -0
+	if (do_tftpb(NULL, 0, 3, tftp_argv)) {
+		printf("File not found\n");
+		return -ENOENT;

Does TFTP not already print an error message?

common/cmd_pxecfg.c line 165

Quoted 12 lines
common/cmd_pxecfg.c new file +12 -0
+static int get_pxecfg_file(char *file_path, void *file_addr)
+{
+	unsigned long config_file_size;
+	int err;
+
+	err = get_relfile(file_path, file_addr);
+
+	if (err < 0)
+		return err;
+
+	config_file_size = simple_strtoul(getenv("filesize"), NULL, 16);
+	*(char *)(file_addr + config_file_size) = '\0';

What exactly are you doing here?

And what happens when getenv() should return NULL?

common/cmd_pxecfg.c line 177

Quoted 8 lines
common/cmd_pxecfg.c new file +8 -0
+static int get_pxelinux_path(char *file, void *pxecfg_addr)
+{
+	size_t base_len = strlen("pxelinux.cfg/");
+	char path[MAX_TFTP_PATH_LEN+1];
+
+	if (base_len + strlen(file) > MAX_TFTP_PATH_LEN) {
+		printf("path too long, skipping\n");
+		return -ENAMETOOLONG;

In such cases it would be helpful to know _which_ exact path was too long, so please include this information in the error messages. Please check and fix globally.

...

common/cmd_pxecfg.c line 303

Quoted 5 lines
common/cmd_pxecfg.c new file +5 -0
+struct pxecfg_label *label_create(void)
+{
+	struct pxecfg_label *label;
+
+	label = malloc(sizeof *label);

You allocate space for a pointer only, but it appears you want a fuill struct here?

common/cmd_pxecfg.c line 313

Quoted 9 lines
common/cmd_pxecfg.c new file +9 -0
+	if (!label)
+		return NULL;
+
+	label->name = NULL;
+	label->kernel = NULL;
+	label->append = NULL;
+	label->initrd = NULL;
+	label->localboot = 0;
+	label->attempted = 0;

Please use:

	memset(label, 0, sizeof(label));

instead.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (label->append)
+		setenv("bootargs", label->append);

I dislike that code is messing with bootargs, completely overwriting
any user settings. Maybe you should just append instead, leaving the
user a chance to add his own needed settings?

Quoted 1 line
common/cmd_pxecfg.c new file +1 -0
+		bootm_argv[2] = getenv("initrd_ram");

...

Quoted 1 line
common/cmd_pxecfg.c new file +1 -0
+	bootm_argv[1] = getenv("kernel_ram");

...

common/cmd_pxecfg.c line 431

Quoted 1 line
common/cmd_pxecfg.c new file +1 -0
+	bootm_argv[3] = getenv("fdtaddr");

It seems you are defining here a set of "standard" environment variables. Deferring the discussion about the actual names, I agree that such definitions make sense and should have been introduced and announced long time ago. When we do it now, we must at least provide full documentation for these.

And we must check for conflicts with existing boards.

I think this part should be split off into a separate commit.

Quoted 26 lines
common/cmd_pxecfg.c new file +26 -0
+static char *get_string(char **p, struct token *t, char delim, int lower)
+{
+	char *b, *e;
+	size_t len, i;
+
+	b = e = *p;
+
+	while (*e) {
+		if ((delim == ' ' && isspace(*e)) || delim == *e)
+			break;
+		e++;
+	}
+
+	len = e - b;
+
+	t->val = malloc(len + 1);
+	if (!t->val) {
+		printf("out of memory\n");
+		return NULL;
+	}
+
+	for (i = 0; i < len; i++, b++) {
+		if (lower)
+			t->val[i] = tolower(*b);
+		else
+			t->val[i] = *b;

common/cmd_pxecfg.c line 515

Quoted 10 lines
common/cmd_pxecfg.c new file +10 -0
+	}
+
+	t->val[len] = '\0';
+
+	*p = e;
+
+	t->type = T_STRING;
+
+	return t->val;
+}

Please NEVER add such code without sufficient comments that explain what it is doing and how. Include in your explanation parameters and return codes. Please fix globally.

common/cmd_pxecfg.c line 537

Quoted 3 lines
common/cmd_pxecfg.c new file +3 -0
+	/* eat non EOL whitespace */
+	while (*c == ' ' || *c == '\t')
+		c++;

Why don't you use standard character classes (like isspace() here) ?

common/cmd_pxecfg.c line 543

Quoted 5 lines
common/cmd_pxecfg.c new file +5 -0
+	/* eat comments */
+	if (*c == '#') {
+		while (*c && *c != '\n')
+			c++;
+	}

There is no way to escape a '#' character?

...

common/cmd_pxecfg.c line 979

Quoted 12 lines
common/cmd_pxecfg.c new file +12 -0
+int do_pxecfg(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	if (argc < 2) {
+		printf("pxecfg requires at least one argument\n");
+		return EINVAL;
+	}
+
+	if (!strcmp(argv[1], "get"))
+		return get_pxecfg(argc, argv);
+
+	if (!strcmp(argv[1], "boot"))
+		return boot_pxecfg(argc, argv);

Please implement standard sub command handling here.

common/cmd_pxecfg.c

Quoted 5 lines
common/cmd_pxecfg.c new file +5 -0
+U_BOOT_CMD(
+	pxecfg, 2, 1, do_pxecfg,
+	"commands to get and boot from pxecfg files",
+	"get - try to retrieve a pxecfg file using tftp\npxecfg "
+	"boot [pxecfg_addr] - boot from the pxecfg file at pxecfg_addr\n"

Please change the command name into "pxe".

#14 lore raw

PATCH v3 6/7 Add pxecfg command

Dear Wolfgang,

Quoted 7 lines · Wolfgang Denk
Quoted 2 lines

Add pxecfg command, which is intended to mimic PXELINUX functionality.

After thinking a long while about this, I came to the conclusion that my initial feeling that "pxecfg" is ugly was actually correct. Please let's call this simply "pxe" as I already suggested in my initial feedback.

Ok. I'll also combine the dhcp PXE request options patches with this series. Though they can be used independently, it will make this publish/review cycle less work and make it easier for those who are picking up the patches off the list.

Quoted 6 lines

Another general comment: you are adding tons of completely undocumented, uncommented code here.

This is not acceptable. Please provide sufficient comments so that the average engineer has a chance to understand what the code is (supposed to be) doing without spending needless effords.

I'll add comments.

Quoted 8 lines
Quoted 8 lines
common/cmd_pxecfg.c new file +8 -0
+static char *from_env(char *envvar)
+{
+	char *ret;
+
+	ret = getenv(envvar);
+
+	if (!ret)
+		printf("missing environment variable: %s\n", envvar);
Quoted 8 lines

common/cmd_pxecfg.c line 39

Quoted 3 lines
common/cmd_pxecfg.c new file +3 -0
+
+	return ret;
+}

I don't like this. It just blows up the code and shifts error handling from the place where it happens. In the result, you will have to check return codes on several function call levels. I recommend to drop this function.

I added this in response to your suggestion to make the print 'missing environment variable' code common. From the caller's perspective, from_env as with getenv, so I don't understand your concern about handling return codes in several function call levels. Do you have another suggestion that doesn't involve going back to scattering printf's throughout the code?

Quoted 21 lines

common/cmd_pxecfg.c line 44

Quoted 4 lines
common/cmd_pxecfg.c new file +4 -0
+/*
+ * Returns the ethaddr environment variable formated with -'s instead of :'s
+ */
+static void format_mac_pxecfg(char **outbuf)

void?

common/cmd_pxecfg.c line 48

Quoted 3 lines
common/cmd_pxecfg.c new file +3 -0
+	char *p, *ethaddr;
+
+	*outbuf = NULL;

This is redundant, please omit.

common/cmd_pxecfg.c line 53

Quoted 4 lines
common/cmd_pxecfg.c new file +4 -0
+	ethaddr = from_env("ethaddr");
+
+	if (!ethaddr)
+		return;

It makes little sense to check for errors, to report errors, and then to continue as if nothing happened.

Quoted 4 lines

common/cmd_pxecfg.c line 55

Quoted 1 line
common/cmd_pxecfg.c new file +1 -0
+	*outbuf = strdup(ethaddr);

Can we please al;locate the buffer in the caller, and do without this? This is only good for memory leaks.

I'll change this to allocate in the caller, as you suggest. We didn't continue as if nothing happened, though. format_mac_pxecfg's caller can checks the value of *outbuf for NULL and doesn't use it if it's NULL. Anyhow, that will change as a result of the allocate in caller change.

Quoted 15 lines
Quoted 15 lines
common/cmd_pxecfg.c new file +14 -0
+/*
+ * Returns the directory the file specified in the bootfile env variable is
+ * in.
+ */
+static char *get_bootfile_path(void)
+{
+	char *bootfile, *bootfile_path, *last_slash;
+	size_t path_len;
+
+	bootfile = from_env("bootfile");
+
+	if (!bootfile)
+		return NULL;
+
Quoted 8 lines

common/cmd_pxecfg.c line 83

Quoted 4 lines
common/cmd_pxecfg.c new file +4 -0
+	last_slash = strrchr(bootfile, '/');
+
+	if (last_slash == NULL)
+		return NULL;

This looks unnecessarily stringent to me. Why can we not accept a plain file name [we can always use "./" if we need a path for the directory] ?

Yes, that's he behavior, as you've suggested. I'll add comments to make this clearer. This function generates a prefix if it's required, and NULL if it isn't or if bootfile isn't defined. The NULL prefix results in the plain filename being used. It's awkward to use a NULL, I thought about using a zero length string, but that was awkward too. I'll see if I can improve this when I go after eliminating the dynamic allocation.

Quoted 7 lines

common/cmd_pxecfg.c line 124

Quoted 5 lines
common/cmd_pxecfg.c new file +4 -0
+	if (path_len > MAX_TFTP_PATH_LEN) {
+		printf("Base path too long (%s%s)\n",
+					bootfile_path ? bootfile_path : "",
+					file_path);

Indentation is one level only. Please fix globally.

Moving these printf args substantially to the right follows kernel CodingStyle guidelines and is more readable than a single level of indentation. Is this a deviation from the kernel CodingStyle that should go into the U-boot coding style wiki?

Quoted 8 lines

common/cmd_pxecfg.c line 129

Quoted 5 lines
common/cmd_pxecfg.c new file +4 -0
+		if (bootfile_path)
+			free(bootfile_path);
+
+		return -ENAMETOOLONG;

All this dynamically allocated strings just blow up the code. Can we try to do without?

I'll look for a way to get rid of these.

Quoted 5 lines

common/cmd_pxecfg.c line 148

Quoted 3 lines
common/cmd_pxecfg.c new file +3 -0
+	if (do_tftpb(NULL, 0, 3, tftp_argv)) {
+		printf("File not found\n");
+		return -ENOENT;

Does TFTP not already print an error message?

It does. I'll drop this one.

Quoted 6 lines
Quoted 6 lines
common/cmd_pxecfg.c new file +6 -0
+static int get_pxecfg_file(char *file_path, void *file_addr)
+{
+	unsigned long config_file_size;
+	int err;
+
+	err = get_relfile(file_path, file_addr);
Quoted 8 lines

common/cmd_pxecfg.c line 165

Quoted 6 lines
common/cmd_pxecfg.c new file +6 -0
+
+	if (err < 0)
+		return err;
+
+	config_file_size = simple_strtoul(getenv("filesize"), NULL, 16);
+	*(char *)(file_addr + config_file_size) = '\0';

What exactly are you doing here?

Files retrieved by tftp aren't terminated with a null byte, so I'm grabbing the file size and doing so. I'll add a comment.

Quoted 1 line

And what happens when getenv() should return NULL?

It's set by the do_tftpb routine, which succeeded, or we would have bailed out after get_relfile. I can check it here to be more defensive, but if it's not set, we'll just have an empty file that the parser will skip over.

Quoted 4 lines
Quoted 4 lines
common/cmd_pxecfg.c new file +4 -0
+static int get_pxelinux_path(char *file, void *pxecfg_addr)
+{
+	size_t base_len = strlen("pxelinux.cfg/");
+	char path[MAX_TFTP_PATH_LEN+1];
Quoted 8 lines

common/cmd_pxecfg.c line 177

Quoted 4 lines
common/cmd_pxecfg.c new file +4 -0
+
+	if (base_len + strlen(file) > MAX_TFTP_PATH_LEN) {
+		printf("path too long, skipping\n");
+		return -ENAMETOOLONG;

In such cases it would be helpful to know _which_ exact path was too long, so please include this information in the error messages. Please check and fix globally.

Ok.

Quoted 9 lines

...

common/cmd_pxecfg.c line 303

Quoted 5 lines
common/cmd_pxecfg.c new file +5 -0
+struct pxecfg_label *label_create(void)
+{
+	struct pxecfg_label *label;
+
+	label = malloc(sizeof *label);

You allocate space for a pointer only, but it appears you want a fuill struct here?

This is a full struct. 'sizeof label' is the pointer size.

Quoted 12 lines

common/cmd_pxecfg.c line 313

Quoted 9 lines
common/cmd_pxecfg.c new file +9 -0
+	if (!label)
+		return NULL;
+
+	label->name = NULL;
+	label->kernel = NULL;
+	label->append = NULL;
+	label->initrd = NULL;
+	label->localboot = 0;
+	label->attempted = 0;

Please use:

Quoted 1 line
	memset(label, 0, sizeof(label));

That relies on implementation specific behavior from C - that a NULL pointer is an all 0 bit pattern. I'm sure that behavior is common on all the platforms U-boot supports today, but is still sloppy IMO. I also think it obscures the intent to the reader. But, I will change this if it's your preference.

Quoted 8 lines

instead.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (label->append)
+		setenv("bootargs", label->append);

I dislike that code is messing with bootargs, completely overwriting
any user settings. Maybe you should just append instead, leaving the
user a chance to add his own needed settings?

I'm not sure I want to make that change. My concern here is preserving behavior that matches expectations created by pxelinux/syslinux behavior, where the arguments are all specified in the config scripts. The bootargs in U-boot's environment aren't as readily accessible as bootargs specified purely in the config scripts, which reside boot server side, and I'm not sure why someone would want to use those rather than using what's explicitly specified with the rest of the boot config.

Quoted 13 lines
Quoted 2 lines
common/cmd_pxecfg.c new file +1 -0
+		bootm_argv[2] = getenv("initrd_ram");

...

Quoted 1 line
common/cmd_pxecfg.c new file +1 -0
+	bootm_argv[1] = getenv("kernel_ram");

...

common/cmd_pxecfg.c line 431

Quoted 1 line
common/cmd_pxecfg.c new file +1 -0
+	bootm_argv[3] = getenv("fdtaddr");

It seems you are defining here a set of "standard" environment variables. Deferring the discussion about the actual names, I agree that such definitions make sense and should have been introduced and announced long time ago. When we do it now, we must at least provide full documentation for these.

Quoted 3 lines

And we must check for conflicts with existing boards.

I think this part should be split off into a separate commit.

I'm not sure how yet, but I will split the pxecfg (err, pxe) commit up and with the parts that use these environment variables.

Quoted 3 lines

common/cmd_pxecfg.c line 537

Quoted 3 lines
common/cmd_pxecfg.c new file +3 -0
+	/* eat non EOL whitespace */
+	while (*c == ' ' || *c == '\t')
+		c++;

This is isblank, but there is no isblank defined in U-boot. I can add add isblank instead of doing this.

Quoted 8 lines

common/cmd_pxecfg.c line 543

Quoted 6 lines
common/cmd_pxecfg.c new file +5 -0
+	/* eat comments */
+	if (*c == '#') {
+		while (*c && *c != '\n')
+			c++;
+	}

There is no way to escape a '#' character?

You can use a '#' after the first character in a string literal. syslinux files don't have a token (such as ") to indicate the start of a string literal, so if we allowed literals to begin with #, it would be ambiguous as to whether a comment or literal was starting. There are ways around this.. only allowing comments at the start of lines, adding escape characters, allowing/requiring quotes on literals. I don't really like any of those options.

Quoted 15 lines

...

common/cmd_pxecfg.c line 979

Quoted 12 lines
common/cmd_pxecfg.c new file +12 -0
+int do_pxecfg(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	if (argc < 2) {
+		printf("pxecfg requires at least one argument\n");
+		return EINVAL;
+	}
+
+	if (!strcmp(argv[1], "get"))
+		return get_pxecfg(argc, argv);
+
+	if (!strcmp(argv[1], "boot"))
+		return boot_pxecfg(argc, argv);

Please implement standard sub command handling here.

I will follow the pattern I see implemented for env commands.

Thank you for the continued review.

Jason

#15 lore raw

PATCH v3 6/7 Add pxecfg command

Dear "Jason Hobbs",

Quoted 18 lines · In message <20110726213914.GB22660@jhobbs-laptop> you wrote:
Quoted 17 lines

common/cmd_pxecfg.c line 39

Quoted 12 lines
common/cmd_pxecfg.c new file +11 -0
+static char *from_env(char *envvar)
+{
+	char *ret;
+
+	ret = getenv(envvar);
+
+	if (!ret)
+		printf("missing environment variable: %s\n", envvar);
+
+	return ret;
+}

I don't like this. It just blows up the code and shifts error handling from the place where it happens. In the result, you will have to check return codes on several function call levels. I recommend to drop this function.

Quoted 2 lines

I added this in response to your suggestion to make the print 'missing environment variable' code common. From the caller's perspective,

Arghhh... You got me there. This happens when somebody actually listens to my bavardage and actually puts it into code ;-)

Quoted 4 lines

from_env as with getenv, so I don't understand your concern about handling return codes in several function call levels. Do you have another suggestion that doesn't involve going back to scattering printf's throughout the code?

Not really. Please ignore my remark.

Quoted 4 lines

I'll change this to allocate in the caller, as you suggest. We didn't continue as if nothing happened, though. format_mac_pxecfg's caller can checks the value of *outbuf for NULL and doesn't use it if it's NULL. Anyhow, that will change as a result of the allocate in caller change.

Hm... that was not obvious to me when I read the code. Let;s see how the new version looks.

Quoted 7 lines
Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (last_slash == NULL)
+		return NULL;

This looks unnecessarily stringent to me. Why can we not accept a plain file name [we can always use "./" if we need a path for the directory] ?

Quoted 6 lines

Yes, that's he behavior, as you've suggested. I'll add comments to make this clearer. This function generates a prefix if it's required, and NULL if it isn't or if bootfile isn't defined. The NULL prefix results in the plain filename being used. It's awkward to use a NULL, I thought about using a zero length string, but that was awkward too. I'll see if I can improve this when I go after eliminating the dynamic allocation.

Why don't you simply use "." as directory name, then? This is something that everybody can understand when reading the code the first time.

Quoted 11 lines
Quoted 6 lines

common/cmd_pxecfg.c line 124

Quoted 4 lines
common/cmd_pxecfg.c new file +4 -0
+	if (path_len > MAX_TFTP_PATH_LEN) {
+		printf("Base path too long (%s%s)\n",
+					bootfile_path ? bootfile_path : "",
+					file_path);

Indentation is one level only. Please fix globally.

Moving these printf args substantially to the right follows kernel CodingStyle guidelines and is more readable than a single level of indentation. Is this a deviation from the kernel CodingStyle that should go into the U-boot coding style wiki?

I think you misread the Coding Style here. What you are referring to is probably this:

Statements longer than 80 columns will be broken into sensible chunks. Descendants are always substantially shorter than the parent and are placed substantially to the right. The same applies to function headers with
a long argument list. ^^^^^^^^^^^^^^^^

So this rule of "place substantially to the right" is given here for function >>headers<< only. I cannot find a place that makes such a comment for calling a function with a long argument list.

Personally, I don't think that such excessive indentation makes the code easier to read.

Quoted 7 lines
Quoted 4 lines

common/cmd_pxecfg.c line 165

Quoted 2 lines
common/cmd_pxecfg.c new file +2 -0
+	config_file_size = simple_strtoul(getenv("filesize"), NULL, 16);
+	*(char *)(file_addr + config_file_size) = '\0';

What exactly are you doing here?

Files retrieved by tftp aren't terminated with a null byte, so I'm grabbing the file size and doing so. I'll add a comment.

What do you mean by "files are not terminated with a nul byte"? Only C strings have such termination, but files are a blob of binary data which do not carry any kind of "end of file" marker. This is what the file size is good for.

Quoted 3 lines
Quoted 1 line

And what happens when getenv() should return NULL?

It's set by the do_tftpb routine, which succeeded, or we would have

It may be set there - or not. Every setenv() can fail, for example, when we are running out of memory.

Quoted 3 lines

bailed out after get_relfile. I can check it here to be more defensive, but if it's not set, we'll just have an empty file that the parser will skip over.

Wrong. You would run simple_strtoul(NULL, ...) which is causes undefined behaviour.

Quoted 10 lines
Quoted 8 lines

common/cmd_pxecfg.c line 303

Quoted 5 lines
common/cmd_pxecfg.c new file +5 -0
+struct pxecfg_label *label_create(void)
+{
+	struct pxecfg_label *label;
+
+	label = malloc(sizeof *label);

You allocate space for a pointer only, but it appears you want a fuill struct here?

This is a full struct. 'sizeof label' is the pointer size.

Yes, you are right. Anyway, please write

malloc(sizeof(struct pxecfg_label))

instead to avoid such confusion.

Quoted 12 lines
Quoted 12 lines

common/cmd_pxecfg.c line 313

Quoted 9 lines
common/cmd_pxecfg.c new file +9 -0
+	if (!label)
+		return NULL;
+
+	label->name = NULL;
+	label->kernel = NULL;
+	label->append = NULL;
+	label->initrd = NULL;
+	label->localboot = 0;
+	label->attempted = 0;

Please use:

Quoted 7 lines
Quoted 1 line
	memset(label, 0, sizeof(label));

That relies on implementation specific behavior from C - that a NULL pointer is an all 0 bit pattern. I'm sure that behavior is common on all the platforms U-boot supports today, but is still sloppy IMO. I also think it obscures the intent to the reader. But, I will change this if it's your preference.

Thisis a standard method to initialize structs, and guaranteed to work.

Quoted 7 lines
Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (label->append)
+		setenv("bootargs", label->append);

I dislike that code is messing with bootargs, completely overwriting
any user settings. Maybe you should just append instead, leaving the
user a chance to add his own needed settings?

Quoted 7 lines

I'm not sure I want to make that change. My concern here is preserving behavior that matches expectations created by pxelinux/syslinux behavior, where the arguments are all specified in the config scripts. The bootargs in U-boot's environment aren't as readily accessible as bootargs specified purely in the config scripts, which reside boot server side, and I'm not sure why someone would want to use those rather than using what's explicitly specified with the rest of the boot config.

Well, if you are really sure this is what users will expect then feel free to keep that.

Quoted 12 lines
Quoted 12 lines
Quoted 1 line
common/cmd_pxecfg.c new file +1 -0
+		bootm_argv[2] = getenv("initrd_ram");

...

Quoted 1 line
common/cmd_pxecfg.c new file +1 -0
+	bootm_argv[1] = getenv("kernel_ram");

...

common/cmd_pxecfg.c line 431

Quoted 1 line
common/cmd_pxecfg.c new file +1 -0
+	bootm_argv[3] = getenv("fdtaddr");

It seems you are defining here a set of "standard" environment variables. Deferring the discussion about the actual names, I agree that such definitions make sense and should have been introduced and announced long time ago. When we do it now, we must at least provide full documentation for these.

Quoted 6 lines
Quoted 3 lines

And we must check for conflicts with existing boards.

I think this part should be split off into a separate commit.

I'm not sure how yet, but I will split the pxecfg (err, pxe) commit up and with the parts that use these environment variables.

What we have been using for a long time and in many boards is this:

Variable name Contains
File name of ... on TFTP server:
u-boot U-Boot binary image
bootfile Linux kernel image
fdtfile DeviceTree Blob
ramdiskfile Ramdisk image

Load addresses in RAM of ...
u-boot_addr_r U-Boot binary image
kernel_addr_r Linux kernel image
fdt_addr_r DeviceTree Blob
ramdisk_addr_r Ramdisk image
Start addresses in NOR flash resp. offsets in NAND flash of ...
u-boot_addr U-Boot binary image
kernel_addr Linux kernel image
fdt_addr DeviceTree Blob
ramdisk_addr Ramdisk image

Maybe we should just document these, and try to standardize their use.

Quoted 6 lines
Quoted 3 lines

common/cmd_pxecfg.c line 537

Quoted 3 lines
common/cmd_pxecfg.c new file +3 -0
+	/* eat non EOL whitespace */
+	while (*c == ' ' || *c == '\t')
+		c++;

This is isblank, but there is no isblank defined in U-boot. I can add add isblank instead of doing this.

That would be nice - please introduce it as a separate patch, and use it in similar places like these:

board/hymod/env.c:      while ((c = *p) == ' ' || c == '\t')
board/hymod/env.c:      while (*nn == ' ' || *nn == '\t')
board/hymod/env.c:      while (nnl > 0 && ((c = nn[nnl - 1]) == ' ' || c == '\t'))
board/hymod/env.c:      while (nvl > 0 && ((c = p[nvl - 1]) == ' ' || c == '\t'))
common/command.c:       space = last_char == '\0' || last_char == ' ' || last_char == '\t';
common/command.c:       if (argc > 1 || (last_char == '\0' || last_char == ' ' || last_char == '\t')) {
common/command.c:               while ((*s == ' ') || (*s == '\t'))
common/command.c:               while (*s && (*s != ' ') && (*s != '\t'))
common/main.c:          while ((*line == ' ') || (*line == '\t')) {
common/main.c:          while (*line && (*line != ' ') && (*line != '\t')) {

drivers/bios_emulator/x86emu/debug.c: while (*s != ' ' && *s != '\t' && *s != '\n')
drivers/bios_emulator/x86emu/debug.c: while (*s == ' ' || *s == '\t')
drivers/bios_emulator/x86emu/debug.c: while (*s == ' ' || *s == '\t')
examples/standalone/smc911x_eeprom.c: if (line[0] && line[1] && line[1] != ' ' && line[1] != '\t')
examples/standalone/smc911x_eeprom.c: while (buf[0] == ' ' || buf[0] == '\t')
lib/hashtable.c: while ((*dp == ' ') || (*dp == '\t'))

Quoted 9 lines
Quoted 1 line

There is no way to escape a '#' character?

You can use a '#' after the first character in a string literal. syslinux files don't have a token (such as ") to indicate the start of a string literal, so if we allowed literals to begin with #, it would be ambiguous as to whether a comment or literal was starting. There are ways around this.. only allowing comments at the start of lines, adding escape characters, allowing/requiring quotes on literals. I don't really like any of those options.

OK.

Quoted 1 line

Thank you for the continued review.

Thanks for the work!

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
It is dangerous to be right on a subject  on  which  the  established
authorities are wrong.                                    -- Voltaire
#16 lore raw

PATCH v3 6/7 Add pxecfg command

Hi Wolfgang,

[...]

Quoted 15 lines
Quoted 11 lines
Quoted 6 lines

common/cmd_pxecfg.c line 124

Quoted 4 lines
common/cmd_pxecfg.c new file +4 -0
+	if (path_len > MAX_TFTP_PATH_LEN) {
+		printf("Base path too long (%s%s)\n",
+					bootfile_path ? bootfile_path : "",
+					file_path);

Indentation is one level only. Please fix globally.

Moving these printf args substantially to the right follows kernel CodingStyle guidelines and is more readable than a single level of indentation. Is this a deviation from the kernel CodingStyle that should go into the U-boot coding style wiki?

I think you misread the Coding Style here. What you are referring to is probably this:

Quoted 8 lines

Statements longer than 80 columns will be broken into sensible chunks. Descendants are always substantially shorter than the parent and are placed substantially to the right. The same applies to function headers with
a long argument list. ^^^^^^^^^^^^^^^^

So this rule of "place substantially to the right" is given here for function >>headers<< only. I cannot find a place that makes such a comment for calling a function with a long argument list.

Actually the quoted text clearly applies to "descendants" of "statements longer than 80 columns" _and_ of "function headers". So I believe your reading is not correct.

But this is only a formal remark - I agree that the proposed change is to the worse ;)

Cheers
Detlev

Signature · 5 lines
In the topologic hell the beer is packed in Klein's bottles.
--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
#17 lore raw

PATCH v3 7/7 arm: ca9x4_ct_vxp: enable pxecfg support

In reply to Jason Hobbs

---
changes in v2:
- use CONFIG_MENU to enable building the menu for pxecfg use

 include/configs/ca9x4_ct_vxp.h |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
include/configs/ca9x4_ct_vxp.h +5 -0
index 7f83249..f3d0e3f 100644
@@ -73,6 +73,8 @@
 /* Command line configuration */
 #define CONFIG_CMD_BDI
 #define CONFIG_CMD_DHCP
+#define CONFIG_CMD_PXECFG
+#define CONFIG_MENU
 #define CONFIG_CMD_ELF
 #define CONFIG_CMD_ENV
 #define CONFIG_CMD_FLASH
@@ -136,6 +138,9 @@
 		"kerneladdr=0x44100000\0" \
 		"initrdaddr=0x44800000\0" \
 		"maxinitrd=0x1800000\0" \
+		"pxecfg_ram=0x88000000\0" \
+		"initrd_ram=0x61000000\0" \
+		"kernel_ram=0x80008000\0" \
 		"console=ttyAMA0,38400n8\0" \
 		"dram=1024M\0" \
 		"root=/dev/sda1 rw\0" \
Signature · 1 line
1.7.0.4
#18 lore raw

v3 cover Add support for pxecfg commands

In reply to Jason Hobbs

Dear Wolfgang,

Quoted 40 lines · Jason Hobbs

The pxecfg commands provide a near subset of the functionality provided by the PXELINUX boot loader. This allows U-boot based systems to be controlled remotely using the same PXE based techniques that many non U-boot based servers use. To avoid identity confusion with PXELINUX, and because not all behavior is identical, we call this feature 'pxecfg'.

As an example, support for the pxecfg commands is enabled for the ca9x4_ct_vxp config.

Additional details are available in the README file added as part of this patch series.

v2 of this patch series separates the menu code from the pxecfg code, giving a reusable menu implementation. It also contains various smaller changes documented in the comment section of the patches.

v3 of this patch series adds a README for the menu, improves the menu interface, and includes other smaller changes documented in the comment section of the patches. The order of patches also changes, with all of the menu support being added first, followed by the pxecfg specific patches.

Jason Hobbs (7):
Add generic, reusable menu code
cosmetic, main: clean up declarations of abortboot common, menu: use abortboot for menu timeout cosmetic, main: correct indentation/spacing issues
common: add run_command2 for running simple or hush commands Add pxecfg command
arm: ca9x4_ct_vxp: enable pxecfg support

 common/Makefile                |    2 +
 common/cmd_pxecfg.c            |  991 ++++++++++++++++++++++++++++++++++++++++
 common/hush.c                  |    2 +-
 common/main.c                  |   62 ++--
 common/menu.c                  |  279 +++++++++++
 doc/README.menu                |  161 +++++++
 doc/README.pxecfg              |  239 ++++++++++
 include/common.h               |    7 +
 include/configs/ca9x4_ct_vxp.h |    5 +
Quoted 8 lines
 include/hush.h                 |    2 +-
 include/menu.h                 |   30 ++
 11 files changed, 1744 insertions(+), 36 deletions(-)
 create mode 100644 common/cmd_pxecfg.c
 create mode 100644 common/menu.c
 create mode 100644 doc/README.menu
 create mode 100644 doc/README.pxecfg
 create mode 100644 include/menu.h

The v3 version of this patch series has been out for about 10 days without any comments - can these patches please be pulled into mainline?

Thanks,
Jason