Skip to contentSkip to conversation

command.c: Break commands out to appropriate cmd_*.c files

PATCH New Peter Tyser 2 participants 6 messages Oct 16, 2009 – Nov 22, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 command.c: Break commands out to appropriate cmd_*.c files

command.c should contain common code related to commands, not miscellaneous command implementations.

---
 common/Makefile      |    5 +
 common/cmd_echo.c    |   58 +++++++++++++
 common/cmd_exit.c    |   42 +++++++++
 common/cmd_help.c    |   57 ++++++++++++
 common/cmd_test.c    |  151 ++++++++++++++++++++++++++++++++
 common/cmd_version.c |   40 +++++++++
 common/command.c     |  233 --------------------------------------------------
 7 files changed, 353 insertions(+), 233 deletions(-)
 create mode 100644 common/cmd_echo.c
 create mode 100644 common/cmd_exit.c
 create mode 100644 common/cmd_help.c
 create mode 100644 common/cmd_test.c
 create mode 100644 common/cmd_version.c
common/Makefile +5 -0
index 3781738..35af8ae 100644
@@ -45,7 +45,9 @@ COBJS-y += xyzModem.o
 # core command
 COBJS-y += cmd_boot.o
 COBJS-y += cmd_bootm.o
+COBJS-y += cmd_help.o
 COBJS-y += cmd_nvedit.o
+COBJS-y += cmd_version.o
 
 # environment
 COBJS-y += env_common.o
@@ -84,9 +86,11 @@ COBJS-$(CONFIG_CMD_DIAG) += cmd_diag.o
 endif
 COBJS-$(CONFIG_CMD_DISPLAY) += cmd_display.o
 COBJS-$(CONFIG_CMD_DTT) += cmd_dtt.o
+COBJS-$(CONFIG_CMD_ECHO) += cmd_echo.o
 COBJS-$(CONFIG_ENV_IS_IN_EEPROM) += cmd_eeprom.o
 COBJS-$(CONFIG_CMD_EEPROM) += cmd_eeprom.o
 COBJS-$(CONFIG_CMD_ELF) += cmd_elf.o
+COBJS-$(CONFIG_SYS_HUSH_PARSER) += cmd_exit.o
 COBJS-$(CONFIG_CMD_EXT2) += cmd_ext2.o
 COBJS-$(CONFIG_CMD_FAT) += cmd_fat.o
 COBJS-$(CONFIG_CMD_FDC)$(CONFIG_CMD_FDOS) += cmd_fdc.o
@@ -135,6 +139,7 @@ COBJS-$(CONFIG_CMD_SPI) += cmd_spi.o
 COBJS-$(CONFIG_CMD_SPIBOOTLDR) += cmd_spibootldr.o
 COBJS-$(CONFIG_CMD_STRINGS) += cmd_strings.o
 COBJS-$(CONFIG_CMD_TERMINAL) += cmd_terminal.o
+COBJS-$(CONFIG_SYS_HUSH_PARSER) += cmd_test.o
 COBJS-$(CONFIG_CMD_TSI148) += cmd_tsi148.o
 COBJS-$(CONFIG_CMD_UBI) += cmd_ubi.o
 COBJS-$(CONFIG_CMD_UBIFS) += cmd_ubifs.o
common/cmd_echo.c new file +58 -0

58 lines not on this page · raw message

common/cmd_exit.c new file +42 -0

42 lines not on this page · raw message

common/cmd_help.c new file +57 -0

57 lines not on this page · raw message

common/cmd_test.c new file +151 -0

151 lines not on this page · raw message

common/cmd_version.c new file +40 -0
new file mode 100644
index 0000000..7f165c7
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2000-2009
+ * Wolfgang Denk, DENX Software Engineering, wd at denx.de.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 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 that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <command.h>
+
+extern char version_string[];
+
+int do_version(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+	printf("\n%s\n", version_string);
+
+	return 0;
+}
+
+U_BOOT_CMD(
+	version,	1,		1,	do_version,
+	"print monitor version",
+	""
+);
common/command.c +0 -233

245 lines not on this page · raw message

Signature · 1 line
1.6.2.1
#1 lore raw

PATCH 2/3 cmd_help: General cleanup

Shorten the overly-verbose help message of 'help' and clean up some redundant ifdefery while we're at it.

---
 common/cmd_help.c |   21 +++++++--------------
 1 files changed, 7 insertions(+), 14 deletions(-)
common/cmd_help.c +7 -14
index f01d14e..e860dfb 100644
@@ -33,25 +33,18 @@ int do_help(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 
 U_BOOT_CMD(
 	help,	CONFIG_SYS_MAXARGS,	1,	do_help,
-	"print online help",
-	"[command ...]\n"
-	"    - show help information (for 'command')\n"
-	"'help' prints online help for the monitor commands.\n\n"
-	"Without arguments, it prints a short usage message for all commands.\n\n"
-	"To get detailed help information for specific commands you can type\n"
-	"'help' with one or more command names as arguments."
+	"print command description/usage",
+	"\n"
+	"	- print brief description of all commands\n"
+	"help command ...\n"
+	"	- print detailed usage of 'command'"
 );
 
 /* This does not use the U_BOOT_CMD macro as ? can't be used in symbol names */
-#ifdef  CONFIG_SYS_LONGHELP
 cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = {
 	"?",	CONFIG_SYS_MAXARGS,	1,	do_help,
 	"alias for 'help'",
+#ifdef  CONFIG_SYS_LONGHELP
 	""
-};
-#else
-cmd_tbl_t __u_boot_cmd_question_mark Struct_Section = {
-	"?",	CONFIG_SYS_MAXARGS,	1,	do_help,
-	"alias for 'help'"
-};
 #endif /* CONFIG_SYS_LONGHELP */
+};
Signature · 1 line
1.6.2.1
#2 lore raw

PATCH 2/3 cmd_help: General cleanup

Dear Peter Tyser,

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

Shorten the overly-verbose help message of 'help' and clean up some redundant ifdefery while we're at it.

---
 common/cmd_help.c |   21 +++++++--------------
 1 files changed, 7 insertions(+), 14 deletions(-)

Applied, to "next" branch, 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
You humans have that emotional need  to  express  gratitude.  "You're
welcome," I believe, is the correct response.
	-- Spock, "Bread and Circuses", stardate 4041.2
#3 lore raw

PATCH 3/3 Add 'true' and 'false' commands

In reply to Peter Tyser

These commands are only enabled when the hush shell is enabled and can be useful in scripts such as:

while true do

    echo "Booting OS...";
    run $bootcmd;
    echo "Booting OS failed";
    sleep 10;

done

---
This could be added as a hush builtin command if people don't want to pollute the top-level help listing. Its debatable if 'false' should be added also, but I threw it in to be consistent.

 common/cmd_test.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
common/cmd_test.c +22 -0
index 3cdd07b..d886f89 100644
@@ -149,3 +149,25 @@ U_BOOT_CMD(
 	"minimal test like /bin/sh",
 	"[args..]"
 );
+
+int do_false(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+	return 1;
+}
+
+U_BOOT_CMD(
+	false,	CONFIG_SYS_MAXARGS,	1,	do_false,
+	"do nothing, unsuccessfully",
+	NULL
+);
+
+int do_true(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+	return 0;
+}
+
+U_BOOT_CMD(
+	true,	CONFIG_SYS_MAXARGS,	1,	do_true,
+	"do nothing, successfully",
+	NULL
+);
Signature · 1 line
1.6.2.1
#4 lore raw

PATCH 3/3 Add 'true' and 'false' commands

Dear Peter Tyser,

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

These commands are only enabled when the hush shell is enabled and can be useful in scripts such as:

while true do

    echo "Booting OS...";
    run $bootcmd;
    echo "Booting OS failed";
    sleep 10;

done

Quoted 8 lines

---
This could be added as a hush builtin command if people don't want to pollute the top-level help listing. Its debatable if 'false' should be added also, but I threw it in to be consistent.

 common/cmd_test.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

Applied, to "next" branch, 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
FORTRAN? The syntactically incorrect statement "DO 10 I = 1.10"  will
parse  and  generate  code  creating  a  variable, DO10I, as follows:
"DO10I = 1.10" If that doesn't terrify you, it should.
#5 lore raw

PATCH 1/3 command.c: Break commands out to appropriate cmd_*.c files

In reply to Peter Tyser

Dear Peter Tyser,

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

command.c should contain common code related to commands, not miscellaneous command implementations.

Quoted 14 lines
---
 common/Makefile      |    5 +
 common/cmd_echo.c    |   58 +++++++++++++
 common/cmd_exit.c    |   42 +++++++++
 common/cmd_help.c    |   57 ++++++++++++
 common/cmd_test.c    |  151 ++++++++++++++++++++++++++++++++
 common/cmd_version.c |   40 +++++++++
 common/command.c     |  233 --------------------------------------------------
 7 files changed, 353 insertions(+), 233 deletions(-)
 create mode 100644 common/cmd_echo.c
 create mode 100644 common/cmd_exit.c
 create mode 100644 common/cmd_help.c
 create mode 100644 common/cmd_test.c
 create mode 100644 common/cmd_version.c

Applied, to "next" branch, thanks.

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
As in certain cults it is possible to kill a process if you know  its
true name.                      -- Ken Thompson and Dennis M. Ritchie