diff mbox

[U-Boot,v2,6/8] sandbox: Allow processing instead of or before main loop

Message ID 1326242752-9981-6-git-send-email-sjg@chromium.org
State Superseded, archived
Delegated to: Mike Frysinger
Headers show

Commit Message

Simon Glass Jan. 11, 2012, 12:45 a.m. UTC
In order to pass command line arguments to sandbox we need to be able
to act on them. So take control back at the end of board_init_r() from
where we can call the main loop or do something else.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
Changes in v2:
- Call cpu_main_loop() from board_init_r()

 arch/sandbox/cpu/start.c                  |    8 ++++++++
 arch/sandbox/include/asm/u-boot-sandbox.h |    3 +++
 arch/sandbox/lib/board.c                  |    7 ++++---
 3 files changed, 15 insertions(+), 3 deletions(-)

Comments

Mike Frysinger Jan. 20, 2012, 7 p.m. UTC | #1
On Tuesday 10 January 2012 19:45:50 Simon Glass wrote:
> In order to pass command line arguments to sandbox we need to be able
> to act on them. So take control back at the end of board_init_r() from
> where we can call the main loop or do something else.

does this need to be done this early ?  parsing args can easily be done inside 
main() (as i showed in my patch that added command line support).

in terms of processing the state, i think we can just make this into an init 
func that runs before we let board_init_r tail into main_loop
-mike
Simon Glass Jan. 23, 2012, 6:25 a.m. UTC | #2
Hi Mike,

On Fri, Jan 20, 2012 at 11:00 AM, Mike Frysinger <vapier@gentoo.org> wrote:
> On Tuesday 10 January 2012 19:45:50 Simon Glass wrote:
>> In order to pass command line arguments to sandbox we need to be able
>> to act on them. So take control back at the end of board_init_r() from
>> where we can call the main loop or do something else.
>
> does this need to be done this early ?  parsing args can easily be done inside
> main() (as i showed in my patch that added command line support).

My thought here is that I would like the command line to influence
U-Boot right from the start, before board init. If we don't know our
parameters until then, then we might do something we shouldn't. For
one thing, if the arguments are --help then we are wasting our time.

One little niggle is that it isn't really possible at present to call
printf() too early. I have left it along for now, and just come back
later and print usage, but it *might* be necessary at some point to
implement os_printf() or similar to allow messages from Sandbox.

>
> in terms of processing the state, i think we can just make this into an init
> func that runs before we let board_init_r tail into main_loop

Well the requirement may be that we don't even want to run main_loop -
see the next patch.

> -mike

Regards,
Simon
diff mbox

Patch

diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c
index b3442e8..d7402be 100644
--- a/arch/sandbox/cpu/start.c
+++ b/arch/sandbox/cpu/start.c
@@ -22,6 +22,14 @@ 
 #include <common.h>
 #include <asm/arch/state.h>
 
+#include <os.h>
+
+void start_main_loop(void)
+{
+	for (;;)
+		main_loop();
+}
+
 int main(int argc, char *argv[])
 {
 	struct sandbox_state *state = NULL;
diff --git a/arch/sandbox/include/asm/u-boot-sandbox.h b/arch/sandbox/include/asm/u-boot-sandbox.h
index 236b4ee..3743289 100644
--- a/arch/sandbox/include/asm/u-boot-sandbox.h
+++ b/arch/sandbox/include/asm/u-boot-sandbox.h
@@ -35,4 +35,7 @@ 
 int board_init(void);
 int dram_init(void);
 
+/* start.c */
+void start_main_loop(void);
+
 #endif	/* _U_BOOT_SANDBOX_H_ */
diff --git a/arch/sandbox/lib/board.c b/arch/sandbox/lib/board.c
index c5a1177..31e09d1 100644
--- a/arch/sandbox/lib/board.c
+++ b/arch/sandbox/lib/board.c
@@ -270,11 +270,12 @@  void board_init_r(gd_t *id, ulong dest_addr)
 #endif
 
 	/*
-	 * For now, run the main loop. Later we might let this be done
-	 * in the main program.
+	 * This function can't return (to match other archs) so call back
+	 * into start.c so that sandbox can do something other than the main
+	 * loop if it likes
 	 */
 	while (1)
-		main_loop();
+		start_main_loop();
 
 	/* NOTREACHED - no way out of command loop except booting */
 }