From patchwork Sat Jun 8 22:42:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Schwierzeck X-Patchwork-Id: 249984 X-Patchwork-Delegate: daniel.schwierzeck@googlemail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id C993B2C008A for ; Sun, 9 Jun 2013 08:48:32 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5CB384A08B; Sun, 9 Jun 2013 00:48:27 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0y+l87LhrB4Z; Sun, 9 Jun 2013 00:48:27 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4A8A24A047; Sun, 9 Jun 2013 00:48:21 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9CBEC4A047 for ; Sun, 9 Jun 2013 00:48:18 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id agVjxnl0Riex for ; Sun, 9 Jun 2013 00:48:12 +0200 (CEST) X-Greylist: delayed 307 seconds by postgrey-1.27 at theia; Sun, 09 Jun 2013 00:48:06 CEST X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-ea0-f176.google.com (mail-ea0-f176.google.com [209.85.215.176]) by theia.denx.de (Postfix) with ESMTPS id 2AA5B4A02D for ; Sun, 9 Jun 2013 00:48:06 +0200 (CEST) Received: by mail-ea0-f176.google.com with SMTP id z15so1492709ead.21 for ; Sat, 08 Jun 2013 15:48:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=IfIS2Yx/PDDGGb7z+p2khuwkjGENCClrTHT3N0Tf9n0=; b=CNyqlH/ZE3tNWlbBgWzhVHiUPsDqKrayMy/8LUQA6IzET3zE1kSw7BzaXWQyUsKqeV MRi1g4VVIbRsEHRB8A8qkwwIGPH+1Tg8xPrdRwx8VlKlAcq2mEtkx5A9pJ80+hsUJ86e HZpLCWmt/FdiNM6buiAqTQ/+zc1EkBP/QVzDPUxn9x8dsXsoubbATCfOBCjP+jHIrAHY fENWV/aQH0O5SVjk0wta5YwRV8OU9fHUmGbYpv6YzbXMgOjRwRG8OcgXApXq0j43iDO8 n9/S51HIfzU53qXmWKglAVCzrwBQKd96FJV2xJh3r79AYqjmS1HAUJsmjUeOq+Ov24HB EvzA== X-Received: by 10.14.182.5 with SMTP id n5mr4356837eem.151.1370731379200; Sat, 08 Jun 2013 15:42:59 -0700 (PDT) Received: from workstation.zombienet.local (p5DDCAFD5.dip0.t-ipconnect.de. [93.220.175.213]) by mx.google.com with ESMTPSA id u7sm10052133eef.14.2013.06.08.15.42.58 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 08 Jun 2013 15:42:58 -0700 (PDT) From: Daniel Schwierzeck To: u-boot@lists.denx.de Date: Sun, 9 Jun 2013 00:42:43 +0200 Message-Id: <1370731370-32767-5-git-send-email-daniel.schwierzeck@gmail.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1370731370-32767-1-git-send-email-daniel.schwierzeck@gmail.com> References: <1370731370-32767-1-git-send-email-daniel.schwierzeck@gmail.com> Subject: [U-Boot] [PATCH 04/11] MIPS: bootm: refactor initialisation of kernel cmdline X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Move initialisation of Linux command line to separate functions. Also add support for bootm subcommand 'cmdline'. Signed-off-by: Daniel Schwierzeck --- 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;