Skip to content

Commit

Permalink
ANDROID: of: Support CONFIG_CMDLINE_EXTEND config option
Browse files Browse the repository at this point in the history
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 <[email protected]>
CC: [email protected]
CC: Grant Likely <[email protected]>
CC: Benjamin Herrenschmidt <[email protected]>
CC: Rob Herring <[email protected]>
Change-Id: I40ace250847f813358125dfcaa8998fd32cf7ea3
Signed-off-by: Colin Cross <[email protected]>
  • Loading branch information
dianders authored and Dmitry Shmidt committed Jan 27, 2017
1 parent ba01a66 commit 4db7f78
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 22 deletions.
62 changes: 40 additions & 22 deletions drivers/of/fdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,29 @@ int __init early_init_dt_scan_memory(unsigned long node, const char *uname,
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 depth, void *data)
{
Expand All @@ -1068,28 +1091,23 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,

early_init_dt_check_for_initrd(node);

/* Retrieve command line */
p = of_get_flat_dt_prop(node, "bootargs", &l);
if (p != NULL && l > 0)
strlcpy(data, p, min((int)l, COMMAND_LINE_SIZE));

/*
* CONFIG_CMDLINE is meant to be a default in case nothing else
* managed to set the command line, unless CONFIG_CMDLINE_FORCE
* is set in which case we override whatever was found earlier.
*/
#ifdef CONFIG_CMDLINE
#if defined(CONFIG_CMDLINE_EXTEND)
strlcat(data, " ", COMMAND_LINE_SIZE);
strlcat(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
#elif defined(CONFIG_CMDLINE_FORCE)
strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
#else
/* No arguments from boot loader, use kernel's cmdl*/
if (!((char *)data)[0])
strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
#endif
#endif /* CONFIG_CMDLINE */
/* Put CONFIG_CMDLINE in if forced or if data had nothing in it to start */
if (overwrite_incoming_cmdline || !((char *)data)[0])
strlcpy(data, config_cmdline, COMMAND_LINE_SIZE);

/* Retrieve command line unless forcing */
if (read_dt_cmdline) {
p = of_get_flat_dt_prop(node, "bootargs", &l);
if (p != NULL && l > 0) {
if (concat_cmdline) {
strlcat(data, " ", COMMAND_LINE_SIZE);
strlcat(data, p, min_t(int, (int)l,
COMMAND_LINE_SIZE));
} else
strlcpy(data, p, min_t(int, (int)l,
COMMAND_LINE_SIZE));
}
}

pr_debug("Command line is: %s\n", (char*)data);

Expand Down
21 changes: 21 additions & 0 deletions include/linux/of_fdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,27 @@ extern int of_flat_dt_match(unsigned long node, const char *const *matches);
extern unsigned long of_get_flat_dt_root(void);
extern int of_get_flat_dt_size(void);

/*
* 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,
int depth, void *data);
extern int early_init_dt_scan_memory(unsigned long node, const char *uname,
Expand Down

0 comments on commit 4db7f78

Please sign in to comment.