ANDROID: of: Support CONFIG_CMDLINE_EXTEND config option

The old logic assumes CMDLINE_FROM_BOOTLOADER vs. CMDLINE_FORCE and
ignores CMDLINE_EXTEND.  Here's the old logic:

- CONFIG_CMDLINE_FORCE=true
    CONFIG_CMDLINE
- dt bootargs=non-empty:
    dt bootargs
- dt bootargs=empty, @data is non-empty string
    @data is left unchanged
- dt bootargs=empty, @data is empty string
    CONFIG_CMDLINE (or "" if that's not defined)

The new logic is now documented in of_fdt.h and is copied here for
reference:

- CONFIG_CMDLINE_FORCE=true
    CONFIG_CMDLINE
- CONFIG_CMDLINE_EXTEND=true, @data is non-empty string
    @data + dt bootargs (even if dt bootargs are empty)
- CONFIG_CMDLINE_EXTEND=true, @data is empty string
    CONFIG_CMDLINE + dt bootargs (even if dt bootargs are empty)
- CMDLINE_FROM_BOOTLOADER=true, dt bootargs=non-empty:
    dt bootargs
- CMDLINE_FROM_BOOTLOADER=true, dt bootargs=empty, @data is non-empty string
    @data is left unchanged
- CMDLINE_FROM_BOOTLOADER=true, dt bootargs=empty, @data is empty string
    CONFIG_CMDLINE (or "" if that's not defined)

Signed-off-by: Doug Anderson <dianders@chromium.org>
CC: devicetree-discuss@lists.ozlabs.org
CC: Grant Likely <grant.likely@secretlab.ca>
CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
CC: Rob Herring <rob.herring@calxeda.com>
Bug: 120440972
Change-Id: I40ace250847f813358125dfcaa8998fd32cf7ea3
Signed-off-by: Colin Cross <ccross@android.com>
[AmitP: Folded following android-4.9 commit changes into this patch
        e820270abb ("ANDROID: of: fix CONFIG_CMDLINE_EXTEND")
        9a4a740554 ("ANDROID: of: Fix build warnings")]
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
This commit is contained in:
Doug Anderson
2012-02-02 22:58:28 -08:00
committed by Todd Kjos
parent 056f12819b
commit d9a2a3f2c2
2 changed files with 69 additions and 24 deletions

View File

@@ -1072,42 +1072,66 @@ int __init early_init_dt_scan_memory(unsigned long node, const char *uname,
return 0; return 0;
} }
/*
* Convert configs to something easy to use in C code
*/
#if defined(CONFIG_CMDLINE_FORCE)
static const int overwrite_incoming_cmdline = 1;
static const int read_dt_cmdline;
static const int concat_cmdline;
#elif defined(CONFIG_CMDLINE_EXTEND)
static const int overwrite_incoming_cmdline;
static const int read_dt_cmdline = 1;
static const int concat_cmdline = 1;
#else /* CMDLINE_FROM_BOOTLOADER */
static const int overwrite_incoming_cmdline;
static const int read_dt_cmdline = 1;
static const int concat_cmdline;
#endif
#ifdef CONFIG_CMDLINE
static const char *config_cmdline = CONFIG_CMDLINE;
#else
static const char *config_cmdline = "";
#endif
int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
int depth, void *data) int depth, void *data)
{ {
int l; int l = 0;
const char *p; const char *p = NULL;
char *cmdline = data;
pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname); pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
if (depth != 1 || !data || if (depth != 1 || !cmdline ||
(strcmp(uname, "chosen") != 0 && strcmp(uname, "chosen@0") != 0)) (strcmp(uname, "chosen") != 0 && strcmp(uname, "chosen@0") != 0))
return 0; return 0;
early_init_dt_check_for_initrd(node); early_init_dt_check_for_initrd(node);
/* Retrieve command line */ /* Put CONFIG_CMDLINE in if forced or if data had nothing in it to start */
p = of_get_flat_dt_prop(node, "bootargs", &l); if (overwrite_incoming_cmdline || !cmdline[0])
if (p != NULL && l > 0) strlcpy(cmdline, config_cmdline, COMMAND_LINE_SIZE);
strlcpy(data, p, min((int)l, COMMAND_LINE_SIZE));
/* /* Retrieve command line unless forcing */
* CONFIG_CMDLINE is meant to be a default in case nothing else if (read_dt_cmdline)
* managed to set the command line, unless CONFIG_CMDLINE_FORCE p = of_get_flat_dt_prop(node, "bootargs", &l);
* is set in which case we override whatever was found earlier.
*/ if (p != NULL && l > 0) {
#ifdef CONFIG_CMDLINE if (concat_cmdline) {
#if defined(CONFIG_CMDLINE_EXTEND) int cmdline_len;
strlcat(data, " ", COMMAND_LINE_SIZE); int copy_len;
strlcat(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE); strlcat(cmdline, " ", COMMAND_LINE_SIZE);
#elif defined(CONFIG_CMDLINE_FORCE) cmdline_len = strlen(cmdline);
strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE); copy_len = COMMAND_LINE_SIZE - cmdline_len - 1;
#else copy_len = min((int)l, copy_len);
/* No arguments from boot loader, use kernel's cmdl*/ strncpy(cmdline + cmdline_len, p, copy_len);
if (!((char *)data)[0]) cmdline[cmdline_len + copy_len] = '\0';
strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE); } else {
#endif strlcpy(cmdline, p, min((int)l, COMMAND_LINE_SIZE));
#endif /* CONFIG_CMDLINE */ }
}
pr_debug("Command line is: %s\n", (char*)data); pr_debug("Command line is: %s\n", (char*)data);

View File

@@ -69,6 +69,27 @@ extern unsigned long of_get_flat_dt_root(void);
extern int of_get_flat_dt_size(void); extern int of_get_flat_dt_size(void);
extern uint32_t of_get_flat_dt_phandle(unsigned long node); extern uint32_t of_get_flat_dt_phandle(unsigned long node);
/*
* early_init_dt_scan_chosen - scan the device tree for ramdisk and bootargs
*
* The boot arguments will be placed into the memory pointed to by @data.
* That memory should be COMMAND_LINE_SIZE big and initialized to be a valid
* (possibly empty) string. Logic for what will be in @data after this
* function finishes:
*
* - CONFIG_CMDLINE_FORCE=true
* CONFIG_CMDLINE
* - CONFIG_CMDLINE_EXTEND=true, @data is non-empty string
* @data + dt bootargs (even if dt bootargs are empty)
* - CONFIG_CMDLINE_EXTEND=true, @data is empty string
* CONFIG_CMDLINE + dt bootargs (even if dt bootargs are empty)
* - CMDLINE_FROM_BOOTLOADER=true, dt bootargs=non-empty:
* dt bootargs
* - CMDLINE_FROM_BOOTLOADER=true, dt bootargs=empty, @data is non-empty string
* @data is left unchanged
* - CMDLINE_FROM_BOOTLOADER=true, dt bootargs=empty, @data is empty string
* CONFIG_CMDLINE (or "" if that's not defined)
*/
extern int early_init_dt_scan_chosen(unsigned long node, const char *uname, extern int early_init_dt_scan_chosen(unsigned long node, const char *uname,
int depth, void *data); int depth, void *data);
extern int early_init_dt_scan_memory(unsigned long node, const char *uname, extern int early_init_dt_scan_memory(unsigned long node, const char *uname,