From: Wolfgang Denk Date: Tue, 23 Sep 2008 13:34:44 +0200 Subject: [U-Boot] [RFC][PATCH v2] bootm: Add sub commands In-Reply-To: <1222151236-13920-1-git-send-email-galak@kernel.crashing.org> References: <1222151236-13920-1-git-send-email-galak@kernel.crashing.org> Message-ID: <20080923113444.EA82E24844@gemini.denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Dear Kumar Gala, In message <1222151236-13920-1-git-send-email-galak@kernel.crashing.org> you wrote: > This version: > * cleans ups issues pointed out by Jerry > * adds a state machine to the command processing > * adds bd_t and cmdline process on linux for ppc Thanks a lot. I'm still missing the possibility to use longer sub-command names, and code to parse these in a sane way. > +int do_bootm_subcommand (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) > +{ > + int ret = 0; > + int state; > + > + /* start */ > + if (argv[1][0] == 's') { > + argc--; > + argv++; > + return bootm_start(cmdtp, flag, argc, argv); > + } > + /* loados */ > + else if (argv[1][0] == 'l') { > + state = BOOTM_STATE_LOADOS; > + } > + /* ramdisk relocate */ > +#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC) > + else if (argv[1][0] == 'r') { > + state = BOOTM_STATE_RAMDISK; > + } > +#endif > +#ifdef CONFIG_OF_LIBFDT > + /* fdt relocate */ > + else if (argv[1][0] == 'f') { > + state = BOOTM_STATE_FDT; > + } > +#endif > + /* bd_t setup */ > + else if (argv[1][0] == 'b') { > + state = BOOTM_STATE_OS_BD_T; > + } > + /* cmdline setup */ > + else if (argv[1][0] == 'c') { > + state = BOOTM_STATE_OS_CMDLINE; > + } > + /* prep os */ > + else if (argv[1][0] == 'p') { > + state = BOOTM_STATE_OS_PREP; > + } > + /* go */ > + else if (argv[1][0] == 'g') { > + state = BOOTM_STATE_OS_GO; > + } > + /* Unrecognized command */ > + else { > + printf ("Usage:\n%s\n", cmdtp->usage); > + return 1; > + } I really wonder why you didn't use a switch statement here? Anyway, as mentioned before, I do not like to be restrricted to one letter subcommand names - we would rather sooner than later come up with names that nobody can remember. Maybe we can extend find_cmd() (in "common/command.c") to take an alternative command table (for the sub-commands) and reuse the existing code? [And then probably do this also for some other commands that take subcommands..] Best regards, Wolfgang Denk -- 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 "In matters of principle, stand like a rock; in matters of taste, swim with the current." - Thomas Jefferson