Skip to content

Commit

Permalink
generic: move bootargs patch to generic
Browse files Browse the repository at this point in the history
3 different target (ipq806x, mpc85xx and mediatek) require the very same
patch. Replace these patch with more upstream friendly patch and move to
generic.

Also drop the redundant config as we can directly check for the presence
of the chosen property and the size increase is marginal.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
  • Loading branch information
Ansuel committed May 10, 2024
1 parent 9001014 commit 66c43e2
Show file tree
Hide file tree
Showing 12 changed files with 400 additions and 207 deletions.
21 changes: 0 additions & 21 deletions target/linux/generic/hack-6.1/920-device_tree_cmdline.patch

This file was deleted.

21 changes: 0 additions & 21 deletions target/linux/generic/hack-6.6/920-device_tree_cmdline.patch

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
From a71b56fdb26ba0e942dda0b780e0c584ccb921d9 Mon Sep 17 00:00:00 2001
From: Christian Marangi <ansuelsmth@gmail.com>
Date: Fri, 10 May 2024 17:49:42 +0200
Subject: [PATCH 1/3] docs: dt: Document new bootargs chosen property

The bootargs property might be overridden by bootloaders on kernel load,
in such scenario, bootargs-override might be used instead. With
bootargs-override set, any value set in bootargs will be ignored.

The bootargs-append can be used to append additional kernel arguments
to the bootargs property. This can be useful in the context of a
bootargs overridden by the bootloader that contains correct that but
the kernel require additional one to be correctly setup.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
Documentation/devicetree/usage-model.rst | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/Documentation/devicetree/usage-model.rst b/Documentation/devicetree/usage-model.rst
index 0717426856b2..885be3e582fc 100644
--- a/Documentation/devicetree/usage-model.rst
+++ b/Documentation/devicetree/usage-model.rst
@@ -217,6 +217,15 @@ On ARM, the function setup_machine_fdt() is responsible for early
scanning of the device tree after selecting the correct machine_desc
that supports the board.

+The bootargs property might be overridden by bootloaders on kernel load,
+in such scenario, bootargs-override might be used instead. With
+bootargs-override set, any value set in bootargs will be ignored.
+
+The bootargs-append can be used to append additional kernel arguments
+to the bootargs property. This can be useful in the context of a
+bootargs overridden by the bootloader that contains correct that but
+the kernel require additional one to be correctly setup.
+
2.4 Device population
---------------------
After the board has been identified, and after the early configuration data
--
2.43.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
From e91bf6918d5a0ae1ed6401454fbe162592601e20 Mon Sep 17 00:00:00 2001
From: Christian Marangi <ansuelsmth@gmail.com>
Date: Fri, 10 May 2024 17:29:47 +0200
Subject: [PATCH 2/3] of: add support for bootargs-override chosen property

On some devices bootloader may hardcoded and overwrite the
bootargs DT property passed in "/chosen" when the kernel is
loaded resulting in the value dropped.

While CMDLINE_FORCE can be used, this is not a good option for
kernels that are shared across devices.

This setting enables using "/chosen/bootargs-override" as the
cmdline if it exists in the device tree.

This broken behaviour was found in various devices from ipq806x Soc,
to Mediatek and even PowerPC.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
arch/arm/Kconfig | 13 +++++++++++++
arch/arm64/Kconfig | 13 +++++++++++++
arch/powerpc/Kconfig | 13 +++++++++++++
drivers/of/fdt.c | 12 ++++++++++--
4 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index b14aed3a17ab..7f1a73be88b2 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1519,6 +1519,19 @@ config CMDLINE_FORCE
command-line options your boot loader passes to the kernel.
endchoice

+config CMDLINE_OVERRIDE
+ bool "Use alternative cmdline from device tree"
+ depends on CMDLINE == ""
+ help
+ On some devices bootloader may hardcoded and overwrite the
+ bootargs DT property passed in "/chosen" when the kernel is
+ loaded resulting in the value dropped.
+ While CMDLINE_FORCE can be used, this is not a good option for
+ kernels that are shared across devices.
+
+ This setting enables using "/chosen/bootargs-override" as the
+ cmdline if it exists in the device tree.
+
config XIP_KERNEL
bool "Kernel Execute-In-Place from ROM"
depends on !ARM_LPAE && !ARCH_MULTIPLATFORM
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 7b11c98b3e84..3f134e74c0fa 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -2280,6 +2280,19 @@ config CMDLINE_FORCE

endchoice

+config CMDLINE_OVERRIDE
+ bool "Use alternative cmdline from device tree"
+ depends on CMDLINE == ""
+ help
+ On some devices bootloader may hardcoded and overwrite the
+ bootargs DT property passed in "/chosen" when the kernel is
+ loaded resulting in the value dropped.
+ While CMDLINE_FORCE can be used, this is not a good option for
+ kernels that are shared across devices.
+
+ This setting enables using "/chosen/bootargs-override" as the
+ cmdline if it exists in the device tree.
+
config EFI_STUB
bool

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 1c4be3373686..d87ddcd3368d 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -985,6 +985,19 @@ config CMDLINE_FORCE

endchoice

+config CMDLINE_OVERRIDE
+ bool "Use alternative cmdline from device tree"
+ depends on CMDLINE == ""
+ help
+ On some devices bootloader may hardcoded and overwrite the
+ bootargs DT property passed in "/chosen" when the kernel is
+ loaded resulting in the value dropped.
+ While CMDLINE_FORCE can be used, this is not a good option for
+ kernels that are shared across devices.
+
+ This setting enables using "/chosen/bootargs-override" as the
+ cmdline if it exists in the device tree.
+
config EXTRA_TARGETS
string "Additional default image types"
help
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index a8a04f27915b..253315421591 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -1068,8 +1068,16 @@ int __init early_init_dt_scan_chosen(char *cmdline)
fdt_totalsize(initial_boot_params));
}

- /* Retrieve command line */
- p = of_get_flat_dt_prop(node, "bootargs", &l);
+ /*
+ * Retrieve command line
+ * bootargs might be hardcoded and overwrite by bootloader on
+ * kernel load.
+ * Check if alternative bootargs-override is present instead
+ * first.
+ */
+ p = of_get_flat_dt_prop(node, "bootargs-override", &l);
+ if (p == NULL || l == 0)
+ p = of_get_flat_dt_prop(node, "bootargs", &l);
if (p != NULL && l > 0)
strscpy(cmdline, p, min(l, COMMAND_LINE_SIZE));

--
2.43.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From 03ca6536acc421464e5ad69bac7226e24bd81e68 Mon Sep 17 00:00:00 2001
From: Christian Marangi <ansuelsmth@gmail.com>
Date: Fri, 10 May 2024 17:43:41 +0200
Subject: [PATCH 3/3] of: add support for bootargs-append chosen property

Add support for bootargs-append chosen property.

The bootargs-append can be used to append additional kernel arguments
to the bootargs property. This can be useful in the context of a
bootargs overridden by the bootloader that contains correct that but
the kernel require additional one to be correctly setup.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
drivers/of/fdt.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 253315421591..5d88f3fc2f35 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -1080,6 +1080,9 @@ int __init early_init_dt_scan_chosen(char *cmdline)
p = of_get_flat_dt_prop(node, "bootargs", &l);
if (p != NULL && l > 0)
strscpy(cmdline, p, min(l, COMMAND_LINE_SIZE));
+ p = of_get_flat_dt_prop(node, "bootargs-append", &l);
+ if (p != NULL && l > 0)
+ strlcat(cmdline, p, min(strlen(cmdline) + l, COMMAND_LINE_SIZE));

handle_cmdline:
/*
--
2.43.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
From a71b56fdb26ba0e942dda0b780e0c584ccb921d9 Mon Sep 17 00:00:00 2001
From: Christian Marangi <ansuelsmth@gmail.com>
Date: Fri, 10 May 2024 17:49:42 +0200
Subject: [PATCH 1/3] docs: dt: Document new bootargs chosen property

The bootargs property might be overridden by bootloaders on kernel load,
in such scenario, bootargs-override might be used instead. With
bootargs-override set, any value set in bootargs will be ignored.

The bootargs-append can be used to append additional kernel arguments
to the bootargs property. This can be useful in the context of a
bootargs overridden by the bootloader that contains correct that but
the kernel require additional one to be correctly setup.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
Documentation/devicetree/usage-model.rst | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/Documentation/devicetree/usage-model.rst b/Documentation/devicetree/usage-model.rst
index 0717426856b2..885be3e582fc 100644
--- a/Documentation/devicetree/usage-model.rst
+++ b/Documentation/devicetree/usage-model.rst
@@ -217,6 +217,15 @@ On ARM, the function setup_machine_fdt() is responsible for early
scanning of the device tree after selecting the correct machine_desc
that supports the board.

+The bootargs property might be overridden by bootloaders on kernel load,
+in such scenario, bootargs-override might be used instead. With
+bootargs-override set, any value set in bootargs will be ignored.
+
+The bootargs-append can be used to append additional kernel arguments
+to the bootargs property. This can be useful in the context of a
+bootargs overridden by the bootloader that contains correct that but
+the kernel require additional one to be correctly setup.
+
2.4 Device population
---------------------
After the board has been identified, and after the early configuration data
--
2.43.0

0 comments on commit 66c43e2

Please sign in to comment.