Skip to contentSkip to conversation

Add support for pxecfg commands

PATCH Superseded Jason Hobbs 3 participants 14 messages Jun 23, 2011 – Jun 24, 2011

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 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.

Jason Hobbs (6):
cosmetic, main: correct indentation/spacing issues
common: add run_command2 for running simple or hush commands
common: make abortboot available for menu use
Add generic, reusable menu code
Add pxecfg command
arm: ca9x4_ct_vxp: enable pxecfg support

 common/Makefile                |    2 +
 common/cmd_pxecfg.c            |  924 ++++++++++++++++++++++++++++++++++++++++
 common/hush.c                  |    2 +-
 common/main.c                  |   60 ++--
 common/menu.c                  |  338 +++++++++++++++
 doc/README.pxecfg              |  238 +++++++++++
 include/common.h               |    7 +
 include/configs/ca9x4_ct_vxp.h |    5 +
 include/hush.h                 |    2 +-
 include/menu.h                 |   40 ++
 10 files changed, 1584 insertions(+), 34 deletions(-)
 create mode 100644 common/cmd_pxecfg.c
 create mode 100644 common/menu.c
 create mode 100644 doc/README.pxecfg
 create mode 100644 include/menu.h
#1 lore raw

PATCH v2 1/6 cosmetic, main: correct indentation/spacing issues

---
changes in v2:
- new in v2

 common/main.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
common/main.c +6 -6
index dcbacc9..f05ee53 100644
@@ -406,15 +406,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
#2 lore raw

PATCH v2 2/6 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 1e4a6a5..e659630 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
#3 lore raw

PATCH v2 3/6 common: make abortboot available for menu use

In reply to Jason Hobbs

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

 common/main.c    |   12 ++++++++----
 include/common.h |    3 +++
 2 files changed, 11 insertions(+), 4 deletions(-)
common/main.c +8 -4
index 1f64523..a031a33 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,11 @@ extern void mdm_init(void); /* defined in board.c */
  */
 #if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0)
 # if defined(CONFIG_AUTOBOOT_KEYED)
+#ifdef CONFIG_MENU
+int abortboot(int bootdelay)
+#else
 static __inline__ int abortboot(int bootdelay)
+#endif
 {
 	int abort = 0;
 	uint64_t etime = endtick(bootdelay);
@@ -205,7 +205,11 @@ static __inline__ int abortboot(int bootdelay)
 static int menukey = 0;
 #endif
 
+#ifdef CONFIG_MENU
+int abortboot(int bootdelay)
+#else
 static __inline__ int abortboot(int bootdelay)
+#endif
 {
 	int abort = 0;
 
include/common.h +3 -0
index e659630..d8b8a79 100644
@@ -234,6 +234,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));
Signature · 1 line
1.7.0.4
#4 lore raw

PATCH v2 3/6 common: make abortboot available for menu use

common/main.c extern void mdm_init(void); /* defined in board.c */ · line 94

Quoted 5 lines · On Thursday, June 23, 2011 14:27:32 Jason Hobbs wrote:
common/main.c +4 -0
+#ifdef CONFIG_MENU
+int abortboot(int bootdelay)
+#else
 static __inline__ int abortboot(int bootdelay)
+#endif

more ifdef trickery here than necessary:

	#ifndef CONFIG_MENU
	static inline
	#endif
	int abortboot(int bootdelay)
	{

-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/20110623/6703be5e/attachment.pgp

#5 lore raw

PATCH v2 3/6 common: make abortboot available for menu use

Mike,

Quoted 6 lines · Mike Frysinger

more ifdef trickery here than necessary:

	#ifndef CONFIG_MENU
	static inline
	#endif
	int abortboot(int bootdelay)
	{

Thanks - I'll change this in the next version of the patch.

Jason

#6 lore raw

PATCH v2 3/6 common: make abortboot available for menu use

In reply to Jason Hobbs

Dear "Jason Hobbs",

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

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

 common/main.c    |   12 ++++++++----
 include/common.h |    3 +++
 2 files changed, 11 insertions(+), 4 deletions(-)

...

Quoted 1 line

+#ifdef CONFIG_MENU

This being a new CONFIG_ variable, it must be documented in the README. But as is this makes little sense, so I suggest you change the order of your patches and add the abortboot support to the menu system in a second step, after adding (and documenting) the menu stuff.

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
You have the capacity to learn from  mistakes.  You'll  learn  a  lot
today.
#7 lore raw

PATCH v2 3/6 common: make abortboot available for menu use

Dear Wolfgang,

Quoted 7 lines · Wolfgang Denk
Quoted 1 line

+#ifdef CONFIG_MENU

This being a new CONFIG_ variable, it must be documented in the README. But as is this makes little sense, so I suggest you change the order of your patches and add the abortboot support to the menu system in a second step, after adding (and documenting) the menu stuff.

I knew it wasn't right, but I didn't know what else to do. I'll follow your suggestion in the next version of this patch series.

Thanks,
Jason

#8 lore raw

PATCH v2 4/6 Add generic, reusable menu code

In reply to Jason Hobbs

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

 common/Makefile |    1 +
 common/menu.c   |  338 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/menu.h  |   40 +++++++
 3 files changed, 379 insertions(+), 0 deletions(-)
 create mode 100644 common/menu.c
 create mode 100644 include/menu.h
common/Makefile +1 -0
index f81cff9..9b413cd 100644
@@ -171,6 +171,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 +338 -0

338 lines not on this page · raw message

include/menu.h new file +40 -0
new file mode 100644
index 0000000..5ffb3b8
@@ -0,0 +1,40 @@
+/*
+ * 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_item;
+
+void *menu_items_data_iter(struct menu *m,
+		void *(*callback)(void *, void *),
+		void *extra);
+
+int menu_should_prompt(struct menu *m);
+int menu_default_set(struct menu *m, char *key);
+void *menu_default_choice(struct menu *m);
+void *menu_user_choice(struct menu *m);
+int menu_item_add(struct menu *m, char *item_key, void *item_data);
+struct menu *menu_create(void (*item_data_print)(void *),
+			void (*item_data_destroy)(void *));
+int menu_title_set(struct menu *m, char *title);
+void menu_destroy(struct menu *m);
+void menu_prompt_set(struct menu *m, int prompt);
+void menu_timeout_set(struct menu *m, int timeout);
+
+#endif /* __MENU_H__ */
Signature · 1 line
1.7.0.4
#9 lore raw

PATCH v2 4/6 Add generic, reusable menu code

Dear "Jason Hobbs",

Quoted 8 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

Quoted 6 lines
 common/Makefile |    1 +
 common/menu.c   |  338 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/menu.h  |   40 +++++++
 3 files changed, 379 insertions(+), 0 deletions(-)
 create mode 100644 common/menu.c
 create mode 100644 include/menu.h

Is this all new code, or was it copied from some other project? If so, reference would be needed.

Then, we need documentation how this is going to be used. Please add a README with documentation of the interfaces and usage examples.

Also, I would like to know why you didn't adapt for example the menu code from barebox - which specific advantages do you see in the code you have chosen?

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
I think it's a new feature. Don't tell anyone it was an accident. :-)
  -- Larry Wall on s/foo/bar/eieio in <[email protected]>
#10 lore raw

PATCH v2 4/6 Add generic, reusable menu code

Quoted 3 lines · Wolfgang Denk

Dear "Jason Hobbs",
Is this all new code, or was it copied from some other project? If so, reference would be needed.

All new code.

Quoted 2 lines

Then, we need documentation how this is going to be used. Please add a README with documentation of the interfaces and usage examples.

Ok - I'll add this.

Quoted 3 lines

Also, I would like to know why you didn't adapt for example the menu code from barebox - which specific advantages do you see in the code you have chosen?

I looked over barebox's menu code after you pointed it out, and it does have more functionality and a fancier interface than this implementation. Unfortunately, it appears that there aren't any menus defined to use it in the barebox codebase to provide a real example for it.

The primary advantage of the implementation I've provided over the barebox implementation is simplicity.

#11 lore raw

PATCH v2 4/6 Add generic, reusable menu code

Dear "Jason Hobbs",

Quoted 16 lines · In message <20110624202511.GA18667@jhobbs-laptop> you wrote:
Quoted 3 lines · Wolfgang Denk

Dear "Jason Hobbs",
Is this all new code, or was it copied from some other project? If so, reference would be needed.

All new code.

Quoted 2 lines

Then, we need documentation how this is going to be used. Please add a README with documentation of the interfaces and usage examples.

Ok - I'll add this.

Quoted 3 lines

Also, I would like to know why you didn't adapt for example the menu code from barebox - which specific advantages do you see in the code you have chosen?

Quoted 8 lines

I looked over barebox's menu code after you pointed it out, and it does have more functionality and a fancier interface than this implementation. Unfortunately, it appears that there aren't any menus defined to use it in the barebox codebase to provide a real example for it.

The primary advantage of the implementation I've provided over the barebox implementation is simplicity.

...

Thanks for the detailed explanation.

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
You can't evaluate a man by logic alone.
	-- McCoy, "I, Mudd", stardate 4513.3
#12 lore raw

PATCH v2 5/6 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

 common/Makefile     |    1 +
 common/cmd_pxecfg.c |  924 +++++++++++++++++++++++++++++++++++++++++++++++++++
 doc/README.pxecfg   |  238 +++++++++++++
 include/common.h    |    3 +
 4 files changed, 1166 insertions(+), 0 deletions(-)
 create mode 100644 common/cmd_pxecfg.c
 create mode 100644 doc/README.pxecfg
common/Makefile +1 -0
index 9b413cd..8885c6d 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 +924 -0

924 lines not on this page · raw message

doc/README.pxecfg new file +238 -0

238 lines not on this page · raw message

include/common.h +3 -0
index d8b8a79..a28abe1 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 v2 6/6 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