Patchwork [U-Boot] common/cmd_bootm.c: prevent running of subcommands before 'bootm start'

login
register
mail settings
Submitter Gabor Juhos
Date Jan. 7, 2013, 9:04 a.m.
Message ID <1357549465-7758-1-git-send-email-juhosg@openwrt.org>
Download mbox | patch
Permalink /patch/209880/
State Accepted
Delegated to: Tom Rini
Headers show

Comments

Gabor Juhos - Jan. 7, 2013, 9:04 a.m.
The execution order of the bootm subcommands is fixed.
Although here is a sanity check in the state machine
which should prevent running the subcommands in wrong
order but it does not catch all possible errors.

It is possible to run any subcommand without running
'bootm start' first which leads to unexpected behaviour.
For example, running 'bootm loados' without 'bootm start'
causes a hang:

    U-Boot> bootm loados
       XIP Invalid Image ... OK
    OK

Add a sanity check to 'do_bootm_subcommand' in order
to ensure that no subcommands can be executed before
'bootm start'.

After the patch running of any subcommand without running
'bootm start' will cause an error like this:

    U-Boot> bootm loados
    Trying to execute a command out of order
    bootm - boot application image from memory

    Usage:
    bootm [addr [arg ...]]
        - boot application image stored in memory
    ...

Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
---
 common/cmd_bootm.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Tom Rini - Feb. 4, 2013, 4:37 p.m.
On Sun, Jan 06, 2013 at 11:04:25PM -0000, Gabor Juhos wrote:

> The execution order of the bootm subcommands is fixed.
> Although here is a sanity check in the state machine
> which should prevent running the subcommands in wrong
> order but it does not catch all possible errors.
> 
> It is possible to run any subcommand without running
> 'bootm start' first which leads to unexpected behaviour.
> For example, running 'bootm loados' without 'bootm start'
> causes a hang:
> 
>     U-Boot> bootm loados
>        XIP Invalid Image ... OK
>     OK
> 
> Add a sanity check to 'do_bootm_subcommand' in order
> to ensure that no subcommands can be executed before
> 'bootm start'.
> 
> After the patch running of any subcommand without running
> 'bootm start' will cause an error like this:
> 
>     U-Boot> bootm loados
>     Trying to execute a command out of order
>     bootm - boot application image from memory
> 
>     Usage:
>     bootm [addr [arg ...]]
>         - boot application image stored in memory
>     ...
> 
> Signed-off-by: Gabor Juhos <juhosg@openwrt.org>

Applied to u-boot/master, thanks!

Patch

diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index 2eb0c29..addde86 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -498,7 +498,8 @@  static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
 		return CMD_RET_USAGE;
 	}
 
-	if (images.state >= state) {
+	if (images.state < BOOTM_STATE_START ||
+	    images.state >= state) {
 		printf("Trying to execute a command out of order\n");
 		return CMD_RET_USAGE;
 	}