/src/barebox/common/bootargs.c
Line | Count | Source |
1 | | // SPDX-License-Identifier: GPL-2.0-only |
2 | | /* |
3 | | * bootargs.c - concatenate Linux bootargs |
4 | | * |
5 | | * Copyright (c) 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix |
6 | | */ |
7 | | #include <common.h> |
8 | | #include <boot.h> |
9 | | #include <malloc.h> |
10 | | #include <magicvar.h> |
11 | | #include <globalvar.h> |
12 | | #include <environment.h> |
13 | | |
14 | | static char *linux_bootargs; |
15 | | |
16 | | /* |
17 | | * This returns the Linux bootargs |
18 | | * |
19 | | * The bootargs are concatenated from the global variables beginning with |
20 | | * "global.linux.bootargs.", "global.linux.mtdparts." and |
21 | | * "global.linux.blkdevparts.". The legacy 'bootargs' environment variable |
22 | | * is only used by the CONFIG_FLEXIBLE_BOOTARGS=n stub in <bootargs.h>. |
23 | | */ |
24 | | const char *linux_bootargs_get(void) |
25 | 0 | { |
26 | 0 | char *bootargs, *parts; |
27 | |
|
28 | 0 | free(linux_bootargs); |
29 | 0 | linux_bootargs = globalvar_get_match("linux.bootargs.", " "); |
30 | |
|
31 | 0 | parts = globalvar_get_match("linux.mtdparts.", ";"); |
32 | 0 | if (strlen(parts)) { |
33 | 0 | bootargs = basprintf("%s%smtdparts=%s", linux_bootargs, |
34 | 0 | *linux_bootargs ? " " : "", parts); |
35 | 0 | free(linux_bootargs); |
36 | 0 | linux_bootargs = bootargs; |
37 | 0 | } |
38 | |
|
39 | 0 | free(parts); |
40 | |
|
41 | 0 | parts = globalvar_get_match("linux.blkdevparts.", ";"); |
42 | 0 | if (strlen(parts)) { |
43 | 0 | bootargs = basprintf("%s%sblkdevparts=%s", linux_bootargs, |
44 | 0 | *linux_bootargs ? " " : "", parts); |
45 | 0 | free(linux_bootargs); |
46 | 0 | linux_bootargs = bootargs; |
47 | 0 | } |
48 | |
|
49 | 0 | free(parts); |
50 | |
|
51 | 0 | if (!*linux_bootargs) { |
52 | 0 | free(linux_bootargs); |
53 | 0 | linux_bootargs = NULL; |
54 | 0 | } |
55 | |
|
56 | 0 | return linux_bootargs; |
57 | 0 | } |
58 | | |
59 | | char *linux_bootargs_append_rootwait(char *rootarg_old) |
60 | 0 | { |
61 | 0 | char *rootarg = xasprintf("%s rootwait=%d", |
62 | 0 | rootarg_old, linux_rootwait_secs); |
63 | 0 | free(rootarg_old); |
64 | 0 | return rootarg; |
65 | 0 | } |
66 | | |
67 | | |
68 | | BAREBOX_MAGICVAR(global.linux.bootargs.*, "Linux bootargs variables"); |
69 | | BAREBOX_MAGICVAR(global.linux.mtdparts.*, "Linux mtdparts variables"); |
70 | | BAREBOX_MAGICVAR(global.linux.blkdevparts.*, "Linux blkdevparts variables"); |
71 | | #ifdef CONFIG_ROOTWAIT_BOOTARG |
72 | | BAREBOX_MAGICVAR(global.linux.rootwait, "Argument (in seconds) for Linux rootwait= option if it's fixed up. A negative value waits indefinitely"); |
73 | | #endif |