diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2012-04-29 20:13:53 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-05-14 09:16:31 +0200 |
commit | ee4cab9e587442f95e4fb3442355ca1eb56d9495 (patch) | |
tree | 5ef83d351e929e8970171dda175b7c1ae9bb49e6 /common/bootargs.c | |
parent | b8c94a15611ce7e191d022a3cd9f3ba23930a9c8 (diff) | |
download | barebox-ee4cab9e587442f95e4fb3442355ca1eb56d9495.tar.gz barebox-ee4cab9e587442f95e4fb3442355ca1eb56d9495.tar.xz |
booting: more flexible Linux bootargs generation
We currently use the environment variable 'bootargs' to get the
Linux bootargs. This patch allows for a more flexible bootargs
generation using global variables. With it the Linux bootargs
are concatenated from multiple variables. This allows to replace
parts of the bootargs string without having to reconstruct it
completely.
With this bootargs can be constructed like:
global linux.bootargs.base="console=ttyS0,115200"
global linux.bootargs.ip="ip=dhcp"
global linux.mtdparts="physmap-flash.0:512K(nor0.barebox),-(root)"
This will then automatically be combined into a kernel bootargs
string during boot.
If the 'linux.bootargs.' variables are all empty the old standard
'bootargs' way will be used.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/bootargs.c')
-rw-r--r-- | common/bootargs.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/common/bootargs.c b/common/bootargs.c new file mode 100644 index 0000000000..b17e6d15ae --- /dev/null +++ b/common/bootargs.c @@ -0,0 +1,79 @@ +/* + * bootargs.c - concatenate Linux bootargs + * + * Copyright (c) 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix + * + * 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 version 2 + * as published by the Free Software Foundation. + * + * 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 <boot.h> +#include <malloc.h> +#include <globalvar.h> +#include <environment.h> + +static char *linux_bootargs; +static int linux_bootargs_overwritten; + +/* + * This returns the Linux bootargs + * + * There are two ways to handle bootargs. The old legacy way is to use the + * 'bootargs' environment variable. The new and more flexible way is to use + * global variables beginning with "global.linux.bootargs." and + * "global.linux.mtdparts.". These variables will be concatenated together to + * the resulting bootargs. If there are no "global.linux.bootargs." variables + * we fall back to "bootargs" + */ +const char *linux_bootargs_get(void) +{ + char *bootargs, *mtdparts; + + if (linux_bootargs_overwritten) + return linux_bootargs; + + free(linux_bootargs); + + bootargs = globalvar_get_match("linux.bootargs.", " "); + if (!strlen(bootargs)) + return getenv("bootargs"); + + mtdparts = globalvar_get_match("linux.mtdparts.", ";"); + + if (strlen(mtdparts)) { + linux_bootargs = asprintf("%s mtdparts=%s", bootargs, mtdparts); + free(bootargs); + free(mtdparts); + } else { + free(mtdparts); + linux_bootargs = bootargs; + } + + return linux_bootargs; +} + +int linux_bootargs_overwrite(const char *bootargs) +{ + if (bootargs) { + free(linux_bootargs); + linux_bootargs = xstrdup(bootargs); + linux_bootargs_overwritten = 1; + } else { + linux_bootargs_overwritten = 0; + } + + return 0; +} |