Skip to content

Commit

Permalink
common: fdt: hand over original fdt bootargs into board chosen handler
Browse files Browse the repository at this point in the history
Sometimes, it is necessary to provide an additional bootargs string to
the kernel command line.

We have a real scenario where one U-Boot blob needs to boot several
kernel images: the vendor-patched kernel image and the latest upstream
kernel image. The Amlogic (Meson architecture) tty driver has different
tty suffixes in these kernels: the vendor uses 'ttySx', while the
upstream implementation uses 'ttyAMLx'. The initial console setup is
provided to the kernel using the kernel command line (bootargs). For the
vendor kernel, we should use 'console=ttyS0,115200', while for the
upstream kernel, it must be 'console=ttyAML0,115200'. This means we have
to use different command line strings depending on the kernel version.

To resolve this issue, we cannot use the CMDLINE_EXTEND kernel
configuration because it is considered legacy and is not supported for
the arm64 architecture. CMDLINE_EXTEND is outdated primarily because we
can provide additional command line strings through the
'chosen/bootargs' FDT node. However, U-Boot uses this node to inject the
U-Boot bootargs environment variable content, which results in U-Boot
silently overriding all data in the 'chosen/bootargs' node. While we do
have the board_fdt_chosen_bootargs() board hook to address such issues,
this function lacks any FDT context, such as the original value of the
'chosen/bootargs' node.

This patch introduces a read-only (RO) fdt_property argument to
board_fdt_chosen_bootargs() to share the original 'chosen/bootargs' data
with the board code. Consequently, the board developer can decide how to
handle this information for their board setup: whether to drop it or
merge it with the bootargs environment.

Signed-off-by: Dmitry Rokosov <[email protected]>
Reviewed-by: Quentin Schulz <[email protected]>
  • Loading branch information
rockosov authored and trini committed Jan 14, 2025
1 parent c39257c commit 1cfdac9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions boot/fdt_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ int fdt_kaslrseed(void *fdt, bool overwrite)
* board_fdt_chosen_bootargs - boards may override this function to use
* alternative kernel command line arguments
*/
__weak const char *board_fdt_chosen_bootargs(void)
__weak const char *board_fdt_chosen_bootargs(const struct fdt_property *fdt_ba)
{
return env_get("bootargs");
}
Expand Down Expand Up @@ -364,7 +364,8 @@ int fdt_chosen(void *fdt)
}
}

str = board_fdt_chosen_bootargs();
str = board_fdt_chosen_bootargs(fdt_get_property(fdt, nodeoffset,
"bootargs", NULL));

if (str) {
err = fdt_setprop(fdt, nodeoffset, "bootargs", str,
Expand Down
4 changes: 3 additions & 1 deletion include/fdt_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,14 @@ int board_rng_seed(struct abuf *buf);
/**
* board_fdt_chosen_bootargs() - arbitrarily amend fdt kernel command line
*
* @fdt_ba: FDT chosen/bootargs from the kernel image if available
*
* This is used for late modification of kernel command line arguments just
* before they are added into the /chosen node in flat device tree.
*
* Return: pointer to kernel command line arguments in memory
*/
const char *board_fdt_chosen_bootargs(void);
const char *board_fdt_chosen_bootargs(const struct fdt_property *fdt_ba);

/*
* The keystone2 SOC requires all 32 bit aliased addresses to be converted
Expand Down

0 comments on commit 1cfdac9

Please sign in to comment.