From: Jerry Van Baren <gvb.uboot@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC][PATCH v4] bootm: Add sub commands
Date: Wed, 08 Oct 2008 21:48:06 -0400 [thread overview]
Message-ID: <48ED62D6.9040100@gmail.com> (raw)
In-Reply-To: <1222182462-27755-1-git-send-email-galak@kernel.crashing.org>
Kumar Gala wrote:
> * Use new find_cmd_tbl() to process sub-commands
>
> If this looks good I'll go ahead and clean it up for the other arches and OSes.
Hi Kumar,
Thanks to your sequence hint, interrupt command hint, and one additional
piece, I have this working now.
The missing piece is reserving memory for the stack before copying the
ramdisk to high mem. It looks like this was lost when you consolidated
the machine-specific lib_*/bootm.c do_bootm_linux() functions into one.
Without the reservation code, the copy overwrites the stack.
Seriously bad karma.
See below for a proof-of-concept hack.
> ---
> common/cmd_bootm.c | 142 ++++++++++++++++++++++++++++-
> include/image.h | 20 ++++-
> lib_ppc/bootm.c | 262 ++++++++++++++++++++++++++++++++++------------------
> 3 files changed, 330 insertions(+), 94 deletions(-)
>
> diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
> index 19257bb..e6dcb7a 100644
> --- a/common/cmd_bootm.c
> +++ b/common/cmd_bootm.c
> @@ -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,113 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
> return 0;
> }
>
> +/* we over load the cmd field with our state machine info instead of a
> + * function pointer */
Nitpick: comment format and s/over load/overload/
/*
* We overload the cmd field with our state machine info instead of a
* function pointer
*/
[snip]
> +int do_bootm_subcommand (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
> +{
[snip]
> + 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];
We need to reserve the memory used by the stack here or earlier.
Unfortunately, all three target CPU architectures do this differently.
Below is my proof-of-concept hack. I did not attempt to generalize it
(yet).
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index e6dcb7a..067fbcd 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -60,6 +60,10 @@
DECLARE_GLOBAL_DATA_PTR;
+/**** START HACK ****/
+extern ulong get_effective_memsize(void);
+/**** END HACK ****/
+
extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned
long *lenp);
#ifndef CFG_BOOTM_LEN
#define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
@@ -443,8 +447,18 @@ int do_bootm_subcommand (cmd_tbl_t *cmdtp, int
flag, int argc, char *argv[])
case BOOTM_STATE_RAMDISK:
{
ulong rd_len = images.rd_end - images.rd_start;
+ ulong sp;
char str[17];
+/**** START HACK ****/
+ asm( "mr %0,1": "=r"(sp) : )
+ debug ("## Current stack ends at 0x%08lx\n", sp);
+
+ /* adjust sp by 1K to be safe */
+ sp -= 1024;
+ lmb_reserve(&images.lmb, sp, (CFG_SDRAM_BASE +
get_effective_memsize() - sp));
+/**** END HACK ****/
+
ret = boot_ramdisk_high(&images.lmb, images.rd_start,
rd_len, &images.initrd_start, &images.initrd_end);
if (ret)
> + 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
[snip]
> @@ -386,6 +494,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 +907,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"
s/its/it's/ (contraction "it is", not possessive like "his")
> + "\tstart [addr [arg ...]]\n"
The following is more descriptive?
start <os_addr> [(-|<ramdisk_addr>) [<fdt_addr>]]
> + "\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"
[snip]
Thanks,
gvb
next prev parent reply other threads:[~2008-10-09 1:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-23 15:07 [U-Boot] [RFC][PATCH v4] bootm: Add sub commands Kumar Gala
2008-09-29 13:39 ` Kumar Gala
2008-09-29 13:49 ` Jerry Van Baren
2008-10-08 6:04 ` Kumar Gala
2008-10-08 13:17 ` Jerry Van Baren
2008-10-08 13:45 ` Kumar Gala
2008-10-08 14:15 ` Jerry Van Baren
2008-10-08 13:51 ` [U-Boot] [RFC][PATCH v4] bootm: Add sub commands (sequence of commands to replicate bootm) Kumar Gala
2008-10-09 1:48 ` Jerry Van Baren [this message]
2008-10-13 18:27 ` [U-Boot] [RFC][PATCH v4] bootm: Add sub commands Kumar Gala
2008-10-13 19:14 ` Kumar Gala
2008-10-14 1:38 ` Jerry Van Baren
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48ED62D6.9040100@gmail.com \
--to=gvb.uboot@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox