bootm: Add sub commands
RFC PATCH v2 1/1 bootm: Add sub commands
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
If this looks good I'll go ahead and clean it up for the other arches and OSes.
- k
Posting this again for discussion. The two features I'm interested in enabling are:
* Having the ability to modify the device tree before its passed to the kernel but after 'fdt boardsetup'
* Ability to do all setup but not actually jumping to the kernel. (This is useful as a way to setup the memory image [kernel, ramdisk, fdt, etc] for a different cpu than the boot one)
Having bootm sub-commands allows both of these as we can break up the sequeunce of steps that are part of the bootm process.
--- common/cmd_bootm.c | 150 +++++++++++++++++++++++++++++- include/image.h | 20 ++++- lib_ppc/bootm.c | 262 ++++++++++++++++++++++++++++++++++------------------ 3 files changed, 338 insertions(+), 94 deletions(-)
common/cmd_bootm.c +149 -1
@@ -34,6 +34,7 @@#include <bzlib.h> #include <environment.h> #include <lmb.h> +#include <linux/ctype.h> #include <asm/byteorder.h> #if defined(CONFIG_CMD_USB )
@@ -273,7 +274,7 @@ static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } images.os.start = (ulong )os_hdr; - images.valid =1 ; + images.state =BOOTM_STATE_START ;return 0 ; }
@@ -376,6 +377,121 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)return 0 ; } +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 ; + } + +if (images.state >= state) { +printf ("Trying to execute a command out of order\n" ); +printf ("Usage:\n%s\n" , cmdtp->usage); +return 1 ; + } + + images.state |= state; + +switch (state) { +ulong load_end; +case BOOTM_STATE_START : +/* should never occur */ +break ; +case BOOTM_STATE_LOADOS : + ret =bootm_load_os (images.os, &load_end,0 ); +if (ret) +return ret; + +lmb_reserve (&images.lmb, images.os.load, + (load_end - images.os.load)); +break ; +#if defined(CONFIG_PPC ) || defined(CONFIG_M68K ) || defined(CONFIG_SPARC ) +case BOOTM_STATE_RAMDISK : + { +ulong rd_len = images.rd_end - images.rd_start; +char str[17 ]; + + ret =boot_ramdisk_high (&images.lmb, images.rd_start, + rd_len, &images.initrd_start, &images.initrd_end); +if (ret) +return ret; + +sprintf (str,"%lx" , images.initrd_start); +setenv ("initrd_start" , str); +sprintf (str,"%lx" , images.initrd_end); +setenv ("initrd_end" , str); + } +break ; +#endif +#ifdef CONFIG_OF_LIBFDT +case BOOTM_STATE_FDT : + { +ulong bootmap_base =getenv_bootm_low (); + ret =boot_relocate_fdt (&images.lmb, bootmap_base, + &images.ft_addr, &images.ft_len); +break ; + } +#endif +case BOOTM_STATE_OS_CMDLINE : +do_bootm_linux (BOOTM_STATE_OS_CMDLINE , argc, argv, &images); +break ; +case BOOTM_STATE_OS_BD_T : +do_bootm_linux (BOOTM_STATE_OS_BD_T , argc, argv, &images); +break ; +case BOOTM_STATE_OS_PREP : +do_bootm_linux (BOOTM_STATE_OS_PREP , argc, argv, &images); +break ; +case BOOTM_STATE_OS_GO : +disable_interrupts (); +do_bootm_linux (BOOTM_STATE_OS_GO , argc, argv, &images); +break ; + } + +return ret; +} +/*******************************************************************/ /* bootm - boot application image from image in memory */ /*******************************************************************/
@@ -386,6 +502,23 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])ulong load_end =0 ;int ret; +/* determine if we have a sub command */ +if (argc >1 ) { +char *endp; + +simple_strtoul (argv[1 ], &endp,16 ); +/* endp pointing to NULL means that argv[1] was just a +* valid number, pass it along to the normal bootm processing +* +* If endp is ':' or '#' assume a FIT identifier so pass +* along for normal processing. +* +* Right now we assume the first arg should never be '-' +*/ +if ((*endp !=0 ) && (*endp !=':' ) && (*endp !='#' )) +return do_bootm_subcommand (cmdtp, flag, argc, argv); + } +if (bootm_start (cmdtp, flag, argc, argv))return 1 ;
@@ -782,6 +915,21 @@ U_BOOT_CMD("\tUse iminfo command to get the list of existing component\n" "\timages and configurations.\n"#endif +"\nSub-commands to do part of the bootm sequence. The sub-commands " +"must be\n" +"issued in the order below (its ok to not issue all sub-commands):\n" +"\tstart [addr [arg ...]]\n" + "\tloados - load OS image\n" +#if defined(CONFIG_PPC ) || defined(CONFIG_M68K ) || defined(CONFIG_SPARC ) + "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n" +#endif +#if defined(CONFIG_OF_LIBFDT ) +"\tfdt - relocate flat device tree\n" +#endif +"\tbdt - OS specific bd_t processing\n" +"\tcmdline - OS specific command line processing/setup\n" +"\tprepos - OS specific prep before relocation or go\n" +"\tgo - start OS\n" );/*******************************************************************/
include/image.h +19 -1
@@ -228,6 +228,7 @@ typedef struct bootm_headers {#endif #endif +#ifndef USE_HOSTCC image_info_t os;/* os image info */ ulong ep;/* entry point of OS */
@@ -238,8 +239,25 @@ typedef struct bootm_headers {#endif ulong ft_len;/* length of flat device tree */ +ulong initrd_start; +ulong initrd_end; +ulong cmdline_start; +ulong cmdline_end; +bd_t *kbd; +#endif +int verify;/* getenv("verify")[0] != 'n' */ -int valid;/* set to 1 if we've set values in the header */ + +#define BOOTM_STATE_START (0x00000001) +#define BOOTM_STATE_LOADOS (0x00000002) +#define BOOTM_STATE_RAMDISK (0x00000004) +#define BOOTM_STATE_FDT (0x00000008) +#define BOOTM_STATE_OS_CMDLINE (0x00000010) +#define BOOTM_STATE_OS_BD_T (0x00000020) +#define BOOTM_STATE_OS_PREP (0x00000040) +#define BOOTM_STATE_OS_GO (0x00000080) +int state; +#ifndef USE_HOSTCC struct lmb lmb;/* for memory mgmt */ #endif
lib_ppc/bootm.c +170 -92
333 lines not on this page · raw message
Signature · 1 line
1.5.5.1
RFC PATCH v2 1/1 bootm: Add sub commands
Dear Kumar Gala,
Quoted 4 lines · In message <[email protected]> you…
This version:
* cleans ups issues pointed out by Jerry
* adds a state machine to the command processing
* addsbd_tand 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.
Quoted 38 lines
common/cmd_bootm.c +38
-0+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 ;
common/cmd_bootm.c static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress) · line 427
Quoted 10 lines
common/cmd_bootm.c +10
-0+ } +/* 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
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 "In matters of principle, stand like a rock; in matters of taste, swim with the current." - Thomas Jefferson
RFC PATCH v2 1/1 bootm: Add sub commands
Quoted 12 lines · Wolfgang Denk
Dear Kumar Gala,
Quoted 4 lines · In message <[email protected]> you…
This version:
* cleans ups issues pointed out by Jerry
* adds a state machine to the command processing
* addsbd_tand cmdline process on linux for ppcThanks a lot.
I'm still missing the possibility to use longer sub-command names, and code to parse these in a sane way.
[snip]
Quoted 3 lines
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.
But They All Do It That Way (typed with a whine).
Quoted 6 lines
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..]
BINGO, now I understand your objection. :-)
Quoted 3 lines
Best regards,
Wolfgang Denk
Best regards,
gvb