[U-Boot] [PATCH 0/11] MIPS: bootm updates

- refactoring and optimization of bootm command - add support for logical memory blocks (LMB) - make external init ramdisks working again with recent kernels - add support for bootm subcommand 'cmdline' - prepare bootm for upcoming device tree support - add bootm support for newly added MIPS Malta Qemu - drop obsolete bootm support of MIPS Qemu
Daniel Schwierzeck (11): MIPS: bootm: fix checkpatch.pl warnings MIPS: bootm: optimise kernel entry call MIPS: bootm: add support for LMB MIPS: bootm: refactor initialisation of kernel cmdline MIPS: bootm: refactor initialisation of kernel environment MIPS: bootm: make initialisation of Linux environment optional MIPS: bootm: add support for generic relocation of init ramdisks MIPS: bootm: automatically initialise kernel cmdline variable 'mem' MIPS: bootm: automatically initialise kernel cmdline variables 'rd_start' and 'rd_size' MIPS: bootm: add YAMON style Linux preparation/jump code for Qemu Malta MIPS: bootm: drop obsolete Qemu specific bootm implementation
README | 6 + arch/mips/include/asm/config.h | 3 + arch/mips/lib/Makefile | 4 - arch/mips/lib/bootm.c | 274 +++++++++++++++++++++++++++------------- arch/mips/lib/bootm_qemu_mips.c | 78 ------------ 5 files changed, 198 insertions(+), 167 deletions(-) delete mode 100644 arch/mips/lib/bootm_qemu_mips.c

Signed-off-by: Daniel Schwierzeck daniel.schwierzeck@gmail.com --- arch/mips/lib/bootm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index a36154a..6b38955 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -57,7 +57,7 @@ static void boot_prep_linux(bootm_headers_t *images) #else sprintf(env_buf, "%lu", (ulong)(gd->ram_size >> 20)); debug("## Giving linux memsize in MB, %lu\n", - (ulong)(gd->ram_size >> 20)); + (ulong)(gd->ram_size >> 20)); #endif /* CONFIG_MEMSIZE_IN_BYTES */
linux_env_set("memsize", env_buf); @@ -130,9 +130,9 @@ static void linux_params_init(ulong start, char *line) char *next, *quote, *argp;
linux_argc = 1; - linux_argv = (char **) start; + linux_argv = (char **)start; linux_argv[0] = 0; - argp = (char *) (linux_argv + LINUX_MAX_ARGS); + argp = (char *)(linux_argv + LINUX_MAX_ARGS);
next = line;
@@ -167,9 +167,9 @@ static void linux_params_init(ulong start, char *line) line = next; }
- linux_env = (char **) (((ulong) argp + 15) & ~15); + linux_env = (char **)(((ulong) argp + 15) & ~15); linux_env[0] = 0; - linux_env_p = (char *) (linux_env + LINUX_MAX_ENVS); + linux_env_p = (char *)(linux_env + LINUX_MAX_ENVS); linux_env_idx = 0; }

Signed-off-by: Daniel Schwierzeck daniel.schwierzeck@gmail.com
--- Changes in v2: - fix multi-line comment
arch/mips/lib/bootm.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index a36154a..148c18b 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -57,7 +57,7 @@ static void boot_prep_linux(bootm_headers_t *images) #else sprintf(env_buf, "%lu", (ulong)(gd->ram_size >> 20)); debug("## Giving linux memsize in MB, %lu\n", - (ulong)(gd->ram_size >> 20)); + (ulong)(gd->ram_size >> 20)); #endif /* CONFIG_MEMSIZE_IN_BYTES */
linux_env_set("memsize", env_buf); @@ -130,9 +130,9 @@ static void linux_params_init(ulong start, char *line) char *next, *quote, *argp;
linux_argc = 1; - linux_argv = (char **) start; + linux_argv = (char **)start; linux_argv[0] = 0; - argp = (char *) (linux_argv + LINUX_MAX_ARGS); + argp = (char *)(linux_argv + LINUX_MAX_ARGS);
next = line;
@@ -141,7 +141,8 @@ static void linux_params_init(ulong start, char *line) next = strchr(line, ' ');
while (next && quote && quote < next) { - /* we found a left quote before the next blank + /* + * we found a left quote before the next blank * now we have to find the matching right quote */ next = strchr(quote + 1, '"'); @@ -167,9 +168,9 @@ static void linux_params_init(ulong start, char *line) line = next; }
- linux_env = (char **) (((ulong) argp + 15) & ~15); + linux_env = (char **)(((ulong) argp + 15) & ~15); linux_env[0] = 0; - linux_env_p = (char *) (linux_env + LINUX_MAX_ENVS); + linux_env_p = (char *)(linux_env + LINUX_MAX_ENVS); linux_env_idx = 0; }

Fix signature of kernel entry function. Mark the kernel entry with __noreturn for better code optimisation.
Signed-off-by: Daniel Schwierzeck daniel.schwierzeck@gmail.com --- arch/mips/lib/bootm.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index 6b38955..5540477 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -85,20 +85,17 @@ static void boot_prep_linux(bootm_headers_t *images)
static void boot_jump_linux(bootm_headers_t *images) { - void (*theKernel) (int, char **, char **, int *); + typedef void __noreturn (*kernel_entry_t)(int, ulong, ulong, ulong); + kernel_entry_t kernel = (kernel_entry_t) images->ep;
- /* find kernel entry point */ - theKernel = (void (*)(int, char **, char **, int *))images->ep; - - debug("## Transferring control to Linux (at address %08lx) ...\n", - (ulong) theKernel); + debug("## Transferring control to Linux (at address %p) ...\n", kernel);
bootstage_mark(BOOTSTAGE_ID_RUN_OS);
/* we assume that the kernel is in place */ printf("\nStarting kernel ...\n\n");
- theKernel(linux_argc, linux_argv, linux_env, 0); + kernel(linux_argc, (ulong)linux_argv, (ulong)linux_env, 0); }
int do_bootm_linux(int flag, int argc, char * const argv[],

This is required for init ramdisk relocation and device tree support.
Signed-off-by: Gabor Juhos juhosg@openwrt.org Signed-off-by: Daniel Schwierzeck daniel.schwierzeck@gmail.com --- arch/mips/include/asm/config.h | 2 ++ arch/mips/lib/bootm.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+)
diff --git a/arch/mips/include/asm/config.h b/arch/mips/include/asm/config.h index 049c44e..36438be 100644 --- a/arch/mips/include/asm/config.h +++ b/arch/mips/include/asm/config.h @@ -21,4 +21,6 @@ #ifndef _ASM_CONFIG_H_ #define _ASM_CONFIG_H_
+#define CONFIG_LMB + #endif diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index 5540477..1b0b06a 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -43,6 +43,27 @@ static int linux_env_idx; static void linux_params_init(ulong start, char *commandline); static void linux_env_set(char *env_name, char *env_val);
+static ulong arch_get_sp(void) +{ + ulong ret; + + __asm__ __volatile__("move %0, $sp" : "=r"(ret) : ); + + return ret; +} + +void arch_lmb_reserve(struct lmb *lmb) +{ + ulong sp; + + sp = arch_get_sp(); + debug("## Current stack ends at 0x%08lx\n", sp); + + /* adjust sp by 4K to be safe */ + sp -= 4096; + lmb_reserve(lmb, sp, CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp); +} + static void boot_prep_linux(bootm_headers_t *images) { char *commandline = getenv("bootargs");

Move initialisation of Linux command line to separate functions. Also add support for bootm subcommand 'cmdline'.
Signed-off-by: Daniel Schwierzeck daniel.schwierzeck@gmail.com --- arch/mips/lib/bootm.c | 130 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 84 insertions(+), 46 deletions(-)
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index 1b0b06a..6045905 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -35,12 +35,13 @@ DECLARE_GLOBAL_DATA_PTR;
static int linux_argc; static char **linux_argv; +static char *linux_argp;
static char **linux_env; static char *linux_env_p; static int linux_env_idx;
-static void linux_params_init(ulong start, char *commandline); +static void linux_params_init(void); static void linux_env_set(char *env_name, char *env_val);
static ulong arch_get_sp(void) @@ -64,13 +65,84 @@ void arch_lmb_reserve(struct lmb *lmb) lmb_reserve(lmb, sp, CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp); }
+static void linux_cmdline_init(void) +{ + linux_argc = 1; + linux_argv = (char **)UNCACHED_SDRAM(gd->bd->bi_boot_params); + linux_argv[0] = 0; + linux_argp = (char *)(linux_argv + LINUX_MAX_ARGS); +} + +static void linux_cmdline_set(const char *value, size_t len) +{ + linux_argv[linux_argc] = linux_argp; + memcpy(linux_argp, value, len); + linux_argp[len] = 0; + + linux_argp += len + 1; + linux_argc++; +} + +static void linux_cmdline_dump(void) +{ +#ifdef DEBUG + int i; + + printf("## cmdline argv at 0x%p, argp at 0x%p\n", + linux_argv, linux_argp); + + for (i = 1; i < linux_argc; i++) + printf(" arg %03d: %s\n", i, linux_argv[i]); +#endif +} + +static void boot_cmdline_linux(bootm_headers_t *images) +{ + const char *bootargs, *next, *quote; + + linux_cmdline_init(); + + bootargs = getenv("bootargs"); + if (!bootargs) + return; + + next = bootargs; + + while (bootargs && *bootargs && linux_argc < LINUX_MAX_ARGS) { + quote = strchr(bootargs, '"'); + next = strchr(bootargs, ' '); + + while (next && quote && quote < next) { + /* we found a left quote before the next blank + * now we have to find the matching right quote + */ + next = strchr(quote + 1, '"'); + if (next) { + quote = strchr(next + 1, '"'); + next = strchr(next + 1, ' '); + } + } + + if (!next) + next = bootargs + strlen(bootargs); + + linux_cmdline_set(bootargs, next - bootargs); + + if (*next) + next++; + + bootargs = next; + } + + linux_cmdline_dump(); +} + static void boot_prep_linux(bootm_headers_t *images) { - char *commandline = getenv("bootargs"); char env_buf[12]; char *cp;
- linux_params_init(UNCACHED_SDRAM(gd->bd->bi_boot_params), commandline); + linux_params_init();
#ifdef CONFIG_MEMSIZE_IN_BYTES sprintf(env_buf, "%lu", (ulong)gd->ram_size); @@ -123,9 +195,14 @@ int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t *images) { /* No need for those on MIPS */ - if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) + if (flag & BOOTM_STATE_OS_BD_T) return -1;
+ if (flag & BOOTM_STATE_OS_CMDLINE) { + boot_cmdline_linux(images); + return 0; + } + if (flag & BOOTM_STATE_OS_PREP) { boot_prep_linux(images); return 0; @@ -136,6 +213,7 @@ int do_bootm_linux(int flag, int argc, char * const argv[], return 0; }
+ boot_cmdline_linux(images); boot_prep_linux(images); boot_jump_linux(images);
@@ -143,49 +221,9 @@ int do_bootm_linux(int flag, int argc, char * const argv[], return 1; }
-static void linux_params_init(ulong start, char *line) +static void linux_params_init(void) { - char *next, *quote, *argp; - - linux_argc = 1; - linux_argv = (char **)start; - linux_argv[0] = 0; - argp = (char *)(linux_argv + LINUX_MAX_ARGS); - - next = line; - - while (line && *line && linux_argc < LINUX_MAX_ARGS) { - quote = strchr(line, '"'); - next = strchr(line, ' '); - - while (next && quote && quote < next) { - /* we found a left quote before the next blank - * now we have to find the matching right quote - */ - next = strchr(quote + 1, '"'); - if (next) { - quote = strchr(next + 1, '"'); - next = strchr(next + 1, ' '); - } - } - - if (!next) - next = line + strlen(line); - - linux_argv[linux_argc] = argp; - memcpy(argp, line, next - line); - argp[next - line] = 0; - - argp += next - line + 1; - linux_argc++; - - if (*next) - next++; - - line = next; - } - - linux_env = (char **)(((ulong) argp + 15) & ~15); + linux_env = (char **)(((ulong) linux_argp + 15) & ~15); linux_env[0] = 0; linux_env_p = (char *)(linux_env + LINUX_MAX_ENVS); linux_env_idx = 0;

Dear Daniel Schwierzeck,
In message 1370731370-32767-5-git-send-email-daniel.schwierzeck@gmail.com you wrote:
Move initialisation of Linux command line to separate functions. Also add support for bootm subcommand 'cmdline'.
+static void linux_cmdline_dump(void) +{ +#ifdef DEBUG
- int i;
- printf("## cmdline argv at 0x%p, argp at 0x%p\n",
linux_argv, linux_argp);
- for (i = 1; i < linux_argc; i++)
printf(" arg %03d: %s\n", i, linux_argv[i]);
+#endif +}
Please remove the #ifdef here, and change printf() into debug() instead.
while (next && quote && quote < next) {
/* we found a left quote before the next blank
* now we have to find the matching right quote
*/
Incorrect multiline comment style.
Best regards,
Wolfgang Denk

2013/6/9 Wolfgang Denk wd@denx.de:
Dear Daniel Schwierzeck,
In message 1370731370-32767-5-git-send-email-daniel.schwierzeck@gmail.com you wrote:
Move initialisation of Linux command line to separate functions. Also add support for bootm subcommand 'cmdline'.
+static void linux_cmdline_dump(void) +{ +#ifdef DEBUG
int i;
printf("## cmdline argv at 0x%p, argp at 0x%p\n",
linux_argv, linux_argp);
for (i = 1; i < linux_argc; i++)
printf(" arg %03d: %s\n", i, linux_argv[i]);
+#endif +}
Please remove the #ifdef here, and change printf() into debug() instead.
I will change it
while (next && quote && quote < next) {
/* we found a left quote before the next blank
* now we have to find the matching right quote
*/
Incorrect multiline comment style.
a left-over from the original code. I will fix it in patch 01/11.
Thanks, Daniel

Move initialisation of Linux command line to separate functions. Also add support for bootm subcommand 'cmdline'.
Signed-off-by: Daniel Schwierzeck daniel.schwierzeck@gmail.com
--- Changes in v2: - use debug() macro
arch/mips/lib/bootm.c | 130 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 83 insertions(+), 47 deletions(-)
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index 61e7816..3d0786d 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -35,12 +35,13 @@ DECLARE_GLOBAL_DATA_PTR;
static int linux_argc; static char **linux_argv; +static char *linux_argp;
static char **linux_env; static char *linux_env_p; static int linux_env_idx;
-static void linux_params_init(ulong start, char *commandline); +static void linux_params_init(void); static void linux_env_set(char *env_name, char *env_val);
static ulong arch_get_sp(void) @@ -64,13 +65,83 @@ void arch_lmb_reserve(struct lmb *lmb) lmb_reserve(lmb, sp, CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp); }
+static void linux_cmdline_init(void) +{ + linux_argc = 1; + linux_argv = (char **)UNCACHED_SDRAM(gd->bd->bi_boot_params); + linux_argv[0] = 0; + linux_argp = (char *)(linux_argv + LINUX_MAX_ARGS); +} + +static void linux_cmdline_set(const char *value, size_t len) +{ + linux_argv[linux_argc] = linux_argp; + memcpy(linux_argp, value, len); + linux_argp[len] = 0; + + linux_argp += len + 1; + linux_argc++; +} + +static void linux_cmdline_dump(void) +{ + int i; + + debug("## cmdline argv at 0x%p, argp at 0x%p\n", + linux_argv, linux_argp); + + for (i = 1; i < linux_argc; i++) + debug(" arg %03d: %s\n", i, linux_argv[i]); +} + +static void boot_cmdline_linux(bootm_headers_t *images) +{ + const char *bootargs, *next, *quote; + + linux_cmdline_init(); + + bootargs = getenv("bootargs"); + if (!bootargs) + return; + + next = bootargs; + + while (bootargs && *bootargs && linux_argc < LINUX_MAX_ARGS) { + quote = strchr(bootargs, '"'); + next = strchr(bootargs, ' '); + + while (next && quote && quote < next) { + /* + * we found a left quote before the next blank + * now we have to find the matching right quote + */ + next = strchr(quote + 1, '"'); + if (next) { + quote = strchr(next + 1, '"'); + next = strchr(next + 1, ' '); + } + } + + if (!next) + next = bootargs + strlen(bootargs); + + linux_cmdline_set(bootargs, next - bootargs); + + if (*next) + next++; + + bootargs = next; + } + + linux_cmdline_dump(); +} + static void boot_prep_linux(bootm_headers_t *images) { - char *commandline = getenv("bootargs"); char env_buf[12]; char *cp;
- linux_params_init(UNCACHED_SDRAM(gd->bd->bi_boot_params), commandline); + linux_params_init();
#ifdef CONFIG_MEMSIZE_IN_BYTES sprintf(env_buf, "%lu", (ulong)gd->ram_size); @@ -123,9 +194,14 @@ int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t *images) { /* No need for those on MIPS */ - if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) + if (flag & BOOTM_STATE_OS_BD_T) return -1;
+ if (flag & BOOTM_STATE_OS_CMDLINE) { + boot_cmdline_linux(images); + return 0; + } + if (flag & BOOTM_STATE_OS_PREP) { boot_prep_linux(images); return 0; @@ -136,6 +212,7 @@ int do_bootm_linux(int flag, int argc, char * const argv[], return 0; }
+ boot_cmdline_linux(images); boot_prep_linux(images); boot_jump_linux(images);
@@ -143,50 +220,9 @@ int do_bootm_linux(int flag, int argc, char * const argv[], return 1; }
-static void linux_params_init(ulong start, char *line) +static void linux_params_init(void) { - char *next, *quote, *argp; - - linux_argc = 1; - linux_argv = (char **)start; - linux_argv[0] = 0; - argp = (char *)(linux_argv + LINUX_MAX_ARGS); - - next = line; - - while (line && *line && linux_argc < LINUX_MAX_ARGS) { - quote = strchr(line, '"'); - next = strchr(line, ' '); - - while (next && quote && quote < next) { - /* - * we found a left quote before the next blank - * now we have to find the matching right quote - */ - next = strchr(quote + 1, '"'); - if (next) { - quote = strchr(next + 1, '"'); - next = strchr(next + 1, ' '); - } - } - - if (!next) - next = line + strlen(line); - - linux_argv[linux_argc] = argp; - memcpy(argp, line, next - line); - argp[next - line] = 0; - - argp += next - line + 1; - linux_argc++; - - if (*next) - next++; - - line = next; - } - - linux_env = (char **)(((ulong) argp + 15) & ~15); + linux_env = (char **)(((ulong) linux_argp + 15) & ~15); linux_env[0] = 0; linux_env_p = (char *)(linux_env + LINUX_MAX_ENVS); linux_env_idx = 0;

Move initialisation of Linux environment to separate functions.
Signed-off-by: Daniel Schwierzeck daniel.schwierzeck@gmail.com --- arch/mips/lib/bootm.c | 69 ++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 34 deletions(-)
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index 6045905..304ee53 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -41,9 +41,6 @@ static char **linux_env; static char *linux_env_p; static int linux_env_idx;
-static void linux_params_init(void); -static void linux_env_set(char *env_name, char *env_val); - static ulong arch_get_sp(void) { ulong ret; @@ -137,12 +134,36 @@ static void boot_cmdline_linux(bootm_headers_t *images) linux_cmdline_dump(); }
-static void boot_prep_linux(bootm_headers_t *images) +static void linux_env_init(void) { - char env_buf[12]; - char *cp; + linux_env = (char **)(((ulong) linux_argp + 15) & ~15); + linux_env[0] = 0; + linux_env_p = (char *)(linux_env + LINUX_MAX_ENVS); + linux_env_idx = 0; +}
- linux_params_init(); +static void linux_env_set(const char *env_name, const char *env_val) +{ + if (linux_env_idx < LINUX_MAX_ENVS - 1) { + linux_env[linux_env_idx] = linux_env_p; + + strcpy(linux_env_p, env_name); + linux_env_p += strlen(env_name); + + *linux_env_p++ = '='; + + strcpy(linux_env_p, env_val); + linux_env_p += strlen(env_val); + + linux_env_p++; + linux_env[++linux_env_idx] = 0; + } +} + +static void boot_prep_linux_legacy(bootm_headers_t *images) +{ + char env_buf[12]; + const char *cp;
#ifdef CONFIG_MEMSIZE_IN_BYTES sprintf(env_buf, "%lu", (ulong)gd->ram_size); @@ -153,6 +174,8 @@ static void boot_prep_linux(bootm_headers_t *images) (ulong)(gd->ram_size >> 20)); #endif /* CONFIG_MEMSIZE_IN_BYTES */
+ linux_env_init(); + linux_env_set("memsize", env_buf);
sprintf(env_buf, "0x%08X", (uint) UNCACHED_SDRAM(images->rd_start)); @@ -176,6 +199,11 @@ static void boot_prep_linux(bootm_headers_t *images) linux_env_set("eth1addr", cp); }
+static void boot_prep_linux(bootm_headers_t *images) +{ + boot_prep_linux_legacy(images); +} + static void boot_jump_linux(bootm_headers_t *images) { typedef void __noreturn (*kernel_entry_t)(int, ulong, ulong, ulong); @@ -220,30 +248,3 @@ int do_bootm_linux(int flag, int argc, char * const argv[], /* does not return */ return 1; } - -static void linux_params_init(void) -{ - linux_env = (char **)(((ulong) linux_argp + 15) & ~15); - linux_env[0] = 0; - linux_env_p = (char *)(linux_env + LINUX_MAX_ENVS); - linux_env_idx = 0; -} - -static void linux_env_set(char *env_name, char *env_val) -{ - if (linux_env_idx < LINUX_MAX_ENVS - 1) { - linux_env[linux_env_idx] = linux_env_p; - - strcpy(linux_env_p, env_name); - linux_env_p += strlen(env_name); - - strcpy(linux_env_p, "="); - linux_env_p += 1; - - strcpy(linux_env_p, env_val); - linux_env_p += strlen(env_val); - - linux_env_p++; - linux_env[++linux_env_idx] = 0; - } -}

Recent linux kernels do not use that special environment variables anymore. Add an option to disable compilation of that code but keep it for compatibilty with older kernels.
Signed-off-by: Daniel Schwierzeck daniel.schwierzeck@gmail.com --- README | 6 ++++++ arch/mips/lib/bootm.c | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/README b/README index 33bda8c..1623616 100644 --- a/README +++ b/README @@ -522,6 +522,12 @@ The following options need to be configured: expect it to be in bytes, others in MB. Define CONFIG_MEMSIZE_IN_BYTES to make it in bytes.
+ CONFIG_DISABLE_ENV_INIT [relevant for MIPS only] + + Disable initialization of traditional environment variables + passed to Linux. Modern kernels only use variables from command + line. + CONFIG_OF_LIBFDT
New kernel versions are expecting firmware settings to be diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index 304ee53..e13e0d5 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -33,6 +33,12 @@ DECLARE_GLOBAL_DATA_PTR; #define LINUX_MAX_ENVS 256 #define LINUX_MAX_ARGS 256
+#if defined(CONFIG_DISABLE_ENV_INIT) +#define need_linux_env 0 +#else +#define need_linux_env 1 +#endif + static int linux_argc; static char **linux_argv; static char *linux_argp; @@ -201,7 +207,8 @@ static void boot_prep_linux_legacy(bootm_headers_t *images)
static void boot_prep_linux(bootm_headers_t *images) { - boot_prep_linux_legacy(images); + if (need_linux_env) + boot_prep_linux_legacy(images); }
static void boot_jump_linux(bootm_headers_t *images)

All linux kernels after v2.6 require a page-aligned location of an external init ramdisk. Enable CONFIG_SYS_BOOT_RAMDISK_HIGH to support this with the generic U-Boot relocation code.
Signed-off-by: Daniel Schwierzeck daniel.schwierzeck@gmail.com --- arch/mips/include/asm/config.h | 1 + arch/mips/lib/bootm.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/arch/mips/include/asm/config.h b/arch/mips/include/asm/config.h index 36438be..6ddc349 100644 --- a/arch/mips/include/asm/config.h +++ b/arch/mips/include/asm/config.h @@ -22,5 +22,6 @@ #define _ASM_CONFIG_H_
#define CONFIG_LMB +#define CONFIG_SYS_BOOT_RAMDISK_HIGH
#endif diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index e13e0d5..741e088 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -170,6 +170,7 @@ static void boot_prep_linux_legacy(bootm_headers_t *images) { char env_buf[12]; const char *cp; + ulong rd_start, rd_size;
#ifdef CONFIG_MEMSIZE_IN_BYTES sprintf(env_buf, "%lu", (ulong)gd->ram_size); @@ -180,14 +181,17 @@ static void boot_prep_linux_legacy(bootm_headers_t *images) (ulong)(gd->ram_size >> 20)); #endif /* CONFIG_MEMSIZE_IN_BYTES */
+ rd_start = UNCACHED_SDRAM(images->initrd_start); + rd_size = images->initrd_end - images->initrd_start; + linux_env_init();
linux_env_set("memsize", env_buf);
- sprintf(env_buf, "0x%08X", (uint) UNCACHED_SDRAM(images->rd_start)); + sprintf(env_buf, "0x%08lX", rd_start); linux_env_set("initrd_start", env_buf);
- sprintf(env_buf, "0x%X", (uint) (images->rd_end - images->rd_start)); + sprintf(env_buf, "0x%lX", rd_size); linux_env_set("initrd_size", env_buf);
sprintf(env_buf, "0x%08X", (uint) (gd->bd->bi_flashstart));

This replaces the passing of memory size via the traditional Linux environment. This is required for recent Linux kernels.
Signed-off-by: Daniel Schwierzeck daniel.schwierzeck@gmail.com --- arch/mips/lib/bootm.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index 741e088..796d405 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -102,9 +102,15 @@ static void linux_cmdline_dump(void) static void boot_cmdline_linux(bootm_headers_t *images) { const char *bootargs, *next, *quote; + char buf[12]; + unsigned int mem = gd->ram_size >> 20;
linux_cmdline_init();
+ /* append mem */ + sprintf(buf, "mem=%uM", mem); + linux_cmdline_set(buf, strlen(buf)); + bootargs = getenv("bootargs"); if (!bootargs) return;

This replaces the passing of the location and size of an external init ramdisk via the traditional Linux environment. This is required to supporta again external init ramdisks with recent Linux kernels.
Signed-off-by: Daniel Schwierzeck daniel.schwierzeck@gmail.com --- arch/mips/lib/bootm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index 796d405..68b57d7 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -104,6 +104,7 @@ static void boot_cmdline_linux(bootm_headers_t *images) const char *bootargs, *next, *quote; char buf[12]; unsigned int mem = gd->ram_size >> 20; + ulong rd_start, rd_size;
linux_cmdline_init();
@@ -111,6 +112,17 @@ static void boot_cmdline_linux(bootm_headers_t *images) sprintf(buf, "mem=%uM", mem); linux_cmdline_set(buf, strlen(buf));
+ /* append rd_start and rd_size */ + rd_start = images->initrd_start; + rd_size = images->initrd_end - images->initrd_start; + + if (rd_size) { + sprintf(buf, "rd_start=0x%08lX", rd_start); + linux_cmdline_set(buf, strlen(buf)); + sprintf(buf, "rd_size=0x%lX", rd_size); + linux_cmdline_set(buf, strlen(buf)); + } + bootargs = getenv("bootargs"); if (!bootargs) return;

Signed-off-by: Gabor Juhos juhosg@openwrt.org Signed-off-by: Daniel Schwierzeck daniel.schwierzeck@gmail.com --- arch/mips/lib/bootm.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index 68b57d7..1dc4e73 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -39,6 +39,12 @@ DECLARE_GLOBAL_DATA_PTR; #define need_linux_env 1 #endif
+#if defined(CONFIG_QEMU_MALTA) +#define board_is_qemu_malta 1 +#else +#define board_is_qemu_malta 0 +#endif + static int linux_argc; static char **linux_argv; static char *linux_argp; @@ -174,7 +180,12 @@ static void linux_env_set(const char *env_name, const char *env_val) strcpy(linux_env_p, env_name); linux_env_p += strlen(env_name);
- *linux_env_p++ = '='; + if (board_is_qemu_malta) { + linux_env_p++; + linux_env[++linux_env_idx] = linux_env_p; + } else { + *linux_env_p++ = '='; + }
strcpy(linux_env_p, env_val); linux_env_p += strlen(env_val); @@ -225,6 +236,9 @@ static void boot_prep_linux_legacy(bootm_headers_t *images) cp = getenv("eth1addr"); if (cp) linux_env_set("eth1addr", cp); + + if (board_is_qemu_malta) + linux_env_set("modetty0", "38400n8r"); }
static void boot_prep_linux(bootm_headers_t *images) @@ -237,15 +251,19 @@ static void boot_jump_linux(bootm_headers_t *images) { typedef void __noreturn (*kernel_entry_t)(int, ulong, ulong, ulong); kernel_entry_t kernel = (kernel_entry_t) images->ep; + ulong linux_extra = 0;
debug("## Transferring control to Linux (at address %p) ...\n", kernel);
bootstage_mark(BOOTSTAGE_ID_RUN_OS);
+ if (board_is_qemu_malta) + linux_extra = gd->ram_size; + /* we assume that the kernel is in place */ printf("\nStarting kernel ...\n\n");
- kernel(linux_argc, (ulong)linux_argv, (ulong)linux_env, 0); + kernel(linux_argc, (ulong)linux_argv, (ulong)linux_env, linux_extra); }
int do_bootm_linux(int flag, int argc, char * const argv[],

The Qemu specific bootm implementation was intended for a special Qemu target in Linux kernel. But this target has been dropped in v2.6.25-rc1 by commit 302922e5f6901eb6f29c58539631f71b3d9746b8
Author: Ralf Baechle ralf@linux-mips.org Date: Tue Jan 29 10:15:02 2008 +0000
[MIPS] Qemu: Remove platform.
The Qemu platform was originally implemented to have an easily supportable platform until Qemu reaches a state where it emulates a real world system. Since the latest release Qemu is capable of emulating the MIPSsim and Malta platforms, so this goal has been reached. The Qemu plaform is also rather underfeatured so less useful than a Malta emulation.
Thus the special bootm implementation is obsolete by now and can be dropped. The Qemu support in U-Boot is going to be replaced by MIPS Malta board support.
Signed-off-by: Gabor Juhos juhosg@openwrt.org Signed-off-by: Daniel Schwierzeck daniel.schwierzeck@gmail.com
--- arch/mips/lib/Makefile | 4 --- arch/mips/lib/bootm_qemu_mips.c | 78 ----------------------------------------- 2 files changed, 82 deletions(-) delete mode 100644 arch/mips/lib/bootm_qemu_mips.c
diff --git a/arch/mips/lib/Makefile b/arch/mips/lib/Makefile index 967e98a..a68a564 100644 --- a/arch/mips/lib/Makefile +++ b/arch/mips/lib/Makefile @@ -35,11 +35,7 @@ LGOBJS := $(addprefix $(obj),$(GLSOBJS)) SOBJS-y +=
COBJS-y += board.o -ifeq ($(CONFIG_QEMU_MIPS),y) -COBJS-y += bootm_qemu_mips.o -else COBJS-y += bootm.o -endif
SRCS := $(SOBJS-y:.o=.S) $(COBJS-y:.o=.c) OBJS := $(addprefix $(obj),$(SOBJS-y) $(COBJS-y)) diff --git a/arch/mips/lib/bootm_qemu_mips.c b/arch/mips/lib/bootm_qemu_mips.c deleted file mode 100644 index 0815c9c..0000000 --- a/arch/mips/lib/bootm_qemu_mips.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * (C) Copyright 2008 - * Jean-Christophe PLAGNIOL-VILLARD jcplagniol@jcrosoft.com - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include <common.h> -#include <command.h> -#include <image.h> -#include <asm/byteorder.h> -#include <asm/addrspace.h> - -DECLARE_GLOBAL_DATA_PTR; - -int do_bootm_linux(int flag, int argc, char * const argv[], - bootm_headers_t *images) -{ - void (*theKernel) (int, char **, char **, int *); - char *bootargs = getenv("bootargs"); - char *start; - uint len; - - /* find kernel entry point */ - theKernel = (void (*)(int, char **, char **, int *))images->ep; - - bootstage_mark(BOOTSTAGE_ID_RUN_OS); - - debug("## Transferring control to Linux (at address %08lx) ...\n", - (ulong) theKernel); - - gd->bd->bi_boot_params = gd->bd->bi_memstart + (16 << 20) - 256; - debug("%-12s= 0x%08lX\n", "boot_params", (ulong)gd->bd->bi_boot_params); - - /* set Magic */ - *(int32_t *)(gd->bd->bi_boot_params - 4) = 0x12345678; - /* set ram_size */ - *(int32_t *)(gd->bd->bi_boot_params - 8) = gd->ram_size; - - start = (char *)gd->bd->bi_boot_params; - - len = strlen(bootargs); - - strncpy(start, bootargs, len + 1); - - start += len; - - len = images->rd_end - images->rd_start; - if (len > 0) { - start += sprintf(start, " rd_start=0x%08X rd_size=0x%0X", - (uint) UNCACHED_SDRAM(images->rd_start), - (uint) len); - } - - /* we assume that the kernel is in place */ - printf("\nStarting kernel ...\n\n"); - - theKernel(0, NULL, NULL, 0); - - /* does not return */ - return 1; -}

Hi Daniel,
- refactoring and optimization of bootm command
- add support for logical memory blocks (LMB)
- make external init ramdisks working again with recent kernels
- add support for bootm subcommand 'cmdline'
- prepare bootm for upcoming device tree support
- add bootm support for newly added MIPS Malta Qemu
- drop obsolete bootm support of MIPS Qemu
Daniel Schwierzeck (11): MIPS: bootm: fix checkpatch.pl warnings MIPS: bootm: optimise kernel entry call MIPS: bootm: add support for LMB MIPS: bootm: refactor initialisation of kernel cmdline MIPS: bootm: refactor initialisation of kernel environment MIPS: bootm: make initialisation of Linux environment optional MIPS: bootm: add support for generic relocation of init ramdisks MIPS: bootm: automatically initialise kernel cmdline variable 'mem' MIPS: bootm: automatically initialise kernel cmdline variables 'rd_start' and 'rd_size' MIPS: bootm: add YAMON style Linux preparation/jump code for Qemu Malta MIPS: bootm: drop obsolete Qemu specific bootm implementation
The series looks good.
Acked-by: Gabor Juhos juhosg@openwrt.org
-Gabor

Hello Daniel,
sorry for being late with my questions.
Daniel Schwierzeck wrote onĀ 2013-06-09:
MIPS: bootm: refactor initialisation of kernel cmdline MIPS: bootm: refactor initialisation of kernel environment MIPS: bootm: make initialisation of Linux environment optional MIPS: bootm: add support for generic relocation of init ramdisks MIPS: bootm: automatically initialise kernel cmdline variable 'mem' MIPS: bootm: automatically initialise kernel cmdline variables 'rd_start' and 'rd_size'
These patches changing the style, how parameters are given to the kernel (using cmdline instead of environment).
Can you explain a little, why this is necessary? Please give some references to the corresponding kernel changes or discussions, if possible.
And how about backward compatibility? Will it still be possible to boot older kernels?
When you automatically add the variable 'mem', will it still be possible to override the memory size by manually adding it to the bootargs?
Best Regards, Thomas

Hi Thomas,
Am 21.06.2013 21:59 schrieb "Langer Thomas (LQDE RD ST PON SW)" < thomas.langer@lantiq.com>:
Hello Daniel,
sorry for being late with my questions.
Daniel Schwierzeck wrote on 2013-06-09:
MIPS: bootm: refactor initialisation of kernel cmdline MIPS: bootm: refactor initialisation of kernel environment MIPS: bootm: make initialisation of Linux environment optional MIPS: bootm: add support for generic relocation of init ramdisks MIPS: bootm: automatically initialise kernel cmdline variable 'mem' MIPS: bootm: automatically initialise kernel cmdline variables
'rd_start' and 'rd_size'
These patches changing the style, how parameters are given to the kernel (using cmdline instead of environment)
The environment is still available
Can you explain a little, why this is necessary? Please give some references to the corresponding kernel changes or
discussions, if possible.
the current U-Boot kernel interface emulates the YAMON interface. But almost all boards supported by the kernel are bootloader agnostic or don't use U-Boot.
And how about backward compatibility? Will it still be possible to boot
older kernels?
When you automatically add the variable 'mem', will it still be possible to override the memory size by manually adding it to the bootargs?
Best Regards, Thomas

2013/6/25 Daniel Schwierzeck daniel.schwierzeck@gmail.com:
Hi Thomas,
oops, I hit the send key too early
Am 21.06.2013 21:59 schrieb "Langer Thomas (LQDE RD ST PON SW)" thomas.langer@lantiq.com:
Hello Daniel,
sorry for being late with my questions.
Daniel Schwierzeck wrote on 2013-06-09:
MIPS: bootm: refactor initialisation of kernel cmdline MIPS: bootm: refactor initialisation of kernel environment MIPS: bootm: make initialisation of Linux environment optional MIPS: bootm: add support for generic relocation of init ramdisks MIPS: bootm: automatically initialise kernel cmdline variable 'mem' MIPS: bootm: automatically initialise kernel cmdline variables 'rd_start' and 'rd_size'
These patches changing the style, how parameters are given to the kernel (using cmdline instead of environment)
The environment is still available
Can you explain a little, why this is necessary? Please give some references to the corresponding kernel changes or discussions, if possible.
the current U-Boot kernel interface emulates the YAMON interface. But almost all boards supported by the kernel are bootloader agnostic or don't use U-Boot.
The generic kernel interface for mem and initramfs is either commandline or device tree. IMHO it makes no sense to add bootloader specific code like environment parsing to the kernel. So I want to support the generic interfaces in U-Boot. The old environment code is still available.
And how about backward compatibility? Will it still be possible to boot older kernels?
I had no problems in my tests. Also a Lantiq BSP kernel boots fine.
When you automatically add the variable 'mem', will it still be possible to override the memory size by manually adding it to the bootargs?
I think you are referring to Lantiq's way of passing memory sizes for voice firmware to the kernel. Indeed this won't work anymore. I can add an additional if condition around the automatic code. Anyway I think it is better to always pass the full memory size to the kernel and reserve firmware memory by allocating contiguous DMA memory. Then there is no need for propietary or bootloader-specific boot interfaces.
-- Best regards, Daniel
participants (4)
-
Daniel Schwierzeck
-
Gabor Juhos
-
Langer Thomas (LQDE RD ST PON SW)
-
Wolfgang Denk