fdt_support.c: Allow late kernel cmdline modification
PATCH 1/1 fdt_support.c: Allow late kernel cmdline modification
By declaring board-specific board_fdt_chosen_bootargs() the kernel command line arguments can be adjusted before injecting to flat dt chosen node.
--- common/fdt_support.c | 12 +++++++++++- include/fdt_support.h | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-)
common/fdt_support.c +11 -1
@@ -269,6 +269,15 @@ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end)return 0 ; } +/** +* board_fdt_chosen_bootargs - boards may override this function to use +* alternative kernel command line arguments +*/ +__weak char *board_fdt_chosen_bootargs (void ) +{ +return env_get ("bootargs" ); +} +int fdt_chosen (void *fdt) {int nodeoffset;
@@ -286,7 +295,8 @@ int fdt_chosen(void *fdt)if (nodeoffset <0 )return nodeoffset; - str =env_get ("bootargs" ); + str =board_fdt_chosen_bootargs (); +if (str) { err =fdt_setprop (fdt, nodeoffset,"bootargs" , str,strlen (str) +1 );
include/fdt_support.h +10 -0
@@ -185,6 +185,16 @@ int fdt_find_or_add_subnode(void *fdt, int parentoffset, const char *name);*/ int ft_board_setup (void *blob,struct bd_info *bd); +/** +* board_fdt_chosen_bootargs() - Arbitrarily amend fdt kernel command line +* +* 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 +*/ +char *board_fdt_chosen_bootargs (void ); +/* * The keystone2 SOC requires all 32 bit aliased addresses to be converted * to their 36 physical format. This has to happen after all fdt nodes
Signature · 1 line
2.20.1
PATCH 1/1 fdt_support.c: Allow late kernel cmdline modification
Quoted 31 lines · Niko Mauno
By declaring board-specific
board_fdt_chosen_bootargs()the kernel command line arguments can be adjusted before injecting to flat dt chosen node.Signed-off-by Niko Mauno <[email protected]>--- common/fdt_support.c | 12 +++++++++++- include/fdt_support.h | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-)common/fdt_support.c +9
-0@@ -269,6 +269,15 @@ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end)return 0 ; } +/** +* board_fdt_chosen_bootargs - boards may override this function to use +* alternative kernel command line arguments +*/ +__weak char *board_fdt_chosen_bootargs (void ) +{ +return env_get ("bootargs" ); +} +int fdt_chosen (void *fdt) {int nodeoffset;
common/fdt_support.c int fdt_chosen(void *fdt) · line 302
Quoted 9 lines
common/fdt_support.c +2
-1@@ -286,7 +295,8 @@ int fdt_chosen(void *fdt)if (nodeoffset <0 )return nodeoffset; - str =env_get ("bootargs" ); + str =board_fdt_chosen_bootargs (); +if (str) { err =fdt_setprop (fdt, nodeoffset,"bootargs" , str,strlen (str) +1 );
What's this look like in practice? I'm very wary about changing "set bootargs to what you pass to the kernel" logic that's been there for forever and a constant of every platform. Thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210222/2d2084e9/attachment.sig>
PATCH 1/1 fdt_support.c: Allow late kernel cmdline modification
Quoted 36 lines · Tom Rini
Quoted 34 lines · Niko Mauno
By declaring board-specific
board_fdt_chosen_bootargs()the kernel command line arguments can be adjusted before injecting to flat dt chosen node.Signed-off-by Niko Mauno <[email protected]>--- common/fdt_support.c | 12 +++++++++++- include/fdt_support.h | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-)common/fdt_support.c +9
-0@@ -269,6 +269,15 @@ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end)return 0 ; } +/** +* board_fdt_chosen_bootargs - boards may override this function to use +* alternative kernel command line arguments +*/ +__weak char *board_fdt_chosen_bootargs (void ) +{ +return env_get ("bootargs" ); +} +int fdt_chosen (void *fdt) {int nodeoffset;@@ -286,7 +295,8 @@ int fdt_chosen(void *fdt)if (nodeoffset <0 )return nodeoffset;
Quoted 11 lines
common/fdt_support.c int fdt_chosen(void *fdt) · line 302
Quoted 6 lines
common/fdt_support.c +2
-1- str =env_get ("bootargs" ); + str =board_fdt_chosen_bootargs (); +if (str) { err =fdt_setprop (fdt, nodeoffset,"bootargs" , str,strlen (str) +1 );What's this look like in practice? I'm very wary about changing "set bootargs to what you pass to the kernel" logic that's been there for forever and a constant of every platform. Thanks!
Hi Tom,
Effectively this change as such should introduce no changes to
prevalent "bootargs" logic when an overriding board_fdt_chosen_bootargs() is not defined. Our motivation for proposing this change is that it provides us with a means to introduce an entry point where we can append rootfs specific dm-verity kernel command line metrics (such as described in
https://www.kernel.org/doc/html/latest/admin-guide/device-mapper/verity.html)
by reading a property from within a kernel tier FIT image header, in order to facilitate secure boot process all the way to root filesystem.
-Niko
PATCH 1/1 fdt_support.c: Allow late kernel cmdline modification
Quoted 48 lines · Niko Mauno
Quoted 36 lines · Tom Rini
Quoted 34 lines · Niko Mauno
By declaring board-specific
board_fdt_chosen_bootargs()the kernel command line arguments can be adjusted before injecting to flat dt chosen node.Signed-off-by Niko Mauno <[email protected]>--- common/fdt_support.c | 12 +++++++++++- include/fdt_support.h | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-)common/fdt_support.c +10
-1@@ -269,6 +269,15 @@ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end)return 0 ; } +/** +* board_fdt_chosen_bootargs - boards may override this function to use +* alternative kernel command line arguments +*/ +__weak char *board_fdt_chosen_bootargs (void ) +{ +return env_get ("bootargs" ); +} +int fdt_chosen (void *fdt) {int nodeoffset;@@ -286,7 +295,8 @@ int fdt_chosen(void *fdt)if (nodeoffset <0 )return nodeoffset; - str =env_get ("bootargs" ); + str =board_fdt_chosen_bootargs ();Quoted 9 lines
common/fdt_support.c int fdt_chosen(void *fdt) · line 302
Quoted 4 lines
common/fdt_support.c +1
-0+if (str) { err =fdt_setprop (fdt, nodeoffset,"bootargs" , str,strlen (str) +1 );What's this look like in practice? I'm very wary about changing "set bootargs to what you pass to the kernel" logic that's been there for forever and a constant of every platform. Thanks!
Hi Tom,
Quoted 8 lines
Effectively this change as such should introduce no changes to prevalent
"bootargs" logic when an overridingboard_fdt_chosen_bootargs()is not defined. Our motivation for proposing this change is that it provides us with a means to introduce an entry point where we can append rootfs specific dm-verity kernel command line metrics (such as described in
https://www.kernel.org/doc/html/latest/admin-guide/device-mapper/verity.html)
by reading a property from within a kernel tier FIT image header, in order to facilitate secure boot process all the way to root filesystem.
Right. But what does that logic look like, and why must it be done in C? People have used dm-verity with U-Boot for ages, for example.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210224/63563ee3/attachment.sig>
PATCH 1/1 fdt_support.c: Allow late kernel cmdline modification
Quoted 58 lines · Tom Rini
Quoted 48 lines · Niko Mauno
Quoted 36 lines · Tom Rini
Quoted 34 lines · Niko Mauno
By declaring board-specific
board_fdt_chosen_bootargs()the kernel command line arguments can be adjusted before injecting to flat dt chosen node.Signed-off-by Niko Mauno <[email protected]>--- common/fdt_support.c | 12 +++++++++++- include/fdt_support.h | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-)common/fdt_support.c +10
-1@@ -269,6 +269,15 @@ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end)return 0 ; } +/** +* board_fdt_chosen_bootargs - boards may override this function to use +* alternative kernel command line arguments +*/ +__weak char *board_fdt_chosen_bootargs (void ) +{ +return env_get ("bootargs" ); +} +int fdt_chosen (void *fdt) {int nodeoffset;@@ -286,7 +295,8 @@ int fdt_chosen(void *fdt)if (nodeoffset <0 )return nodeoffset; - str =env_get ("bootargs" ); + str =board_fdt_chosen_bootargs ();Quoted 9 lines
common/fdt_support.c int fdt_chosen(void *fdt) · line 302
Quoted 4 lines
common/fdt_support.c +1
-0+if (str) { err =fdt_setprop (fdt, nodeoffset,"bootargs" , str,strlen (str) +1 );What's this look like in practice? I'm very wary about changing "set bootargs to what you pass to the kernel" logic that's been there for forever and a constant of every platform. Thanks!
Hi Tom,
Quoted 8 lines
Effectively this change as such should introduce no changes to prevalent
"bootargs" logic when an overridingboard_fdt_chosen_bootargs()is not defined. Our motivation for proposing this change is that it provides us with a means to introduce an entry point where we can append rootfs specific dm-verity kernel command line metrics (such as described in
https://www.kernel.org/doc/html/latest/admin-guide/device-mapper/verity.html)
by reading a property from within a kernel tier FIT image header, in order to facilitate secure boot process all the way to root filesystem.
Quoted 3 lines
Right. But what does that logic look like, and why must it be done in C? People have used dm-verity with U-Boot for ages, for example.
Our build time implementation injects rootfs specific dm-verity metrics in FIT conf node property, effectively coupling the particular (kernel tier) FIT image and particular rootfs image containing trailing verity hash tree.
Below is a sample of such conf node - please note also that the two '${rootdev}' placeholder strings in the injected property are replaced with device node path to 'active' rootfs (in a dual bank scheme where the 'active' rootfs bank is resolved runtime).
configurations {
default = "conf-c";
conf-c {
description = "Linux kernel and FDT blob";
kernel = "kernel";
fdt = "fdt-c";
vaisala,dm-verity-args = "dm-mod.create="dm-verity, ec077aa7-78e5-43b7-9605-0d7f72fc65b9, , ro, 0 136220 verity 1 ${rootdev} ${rootdev} 1024 4096 68110 17028 sha256 2dcd25db0f5b94603843316e5a16ca7717585802bf9a3fbced1443d7f83ec5f6 fec6bf67513d044bc704c63e37508b223d75867842ac828ba0147c6080578698 1
restart_on_corruption" root=/dev/dm-0 ro";
signature {
...
};
};In the boot flow the FIT needs to be signature verified and is processed only after boot command has been issued. Resorting to u-boot scripting means it would require parsing FIT twice and do all verifications twice. Using C avoids this redundancy.
The command line approach is supported since Linux kernel version 5.1 onwards (CONFIG_DM_INIT), and it avoids us the need to bundle a "trampoline" initramfs with Linux kernel for issuing veritysetup and mount commands. The bundling approach struck as more time consuming and also more cumbersome on Yocto to build for various different image types in same build, and introduces additional booting overhead on target.
Related to existing dm-verity support in U-Boot, I observed there is Android Verified Boot 2.0 code which seemed to resort to appending the kernel command line, which lead us to propose this change which would allow us to perform the picking of the property from the FIT image, processing it and appending it to our default "bootargs" in a board specific function.
-Niko
PATCH 1/1 fdt_support.c: Allow late kernel cmdline modification
Quoted 109 lines · Niko Mauno
Quoted 61 lines · Tom Rini
Quoted 60 lines · Niko Mauno
Quoted 39 lines · Tom Rini
Quoted 37 lines · Niko Mauno
By declaring board-specific
board_fdt_chosen_bootargs()the kernel command line arguments can be adjusted before injecting to flat dt chosen node.Signed-off-by Niko Mauno <[email protected]>---
??common/fdt_support.c? | 12 +++++++++++- ??include/fdt_support.h| 10 ++++++++++
?? 2 files changed, 21 insertions(+), 1 deletion(-)common/fdt_support.c +2
-0@@ -269,6 +269,15 @@ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end) ?????? return 0; ?? } +/** +* board_fdt_chosen_bootargs - boards may override this function to use
+ *???????????????????????????? alternative kernel command line arguments
+ */common/fdt_support.c +5
-0+__weak char *board_fdt_chosen_bootargs (void ) +{ +??? return env_get("bootargs"); +} +?? int
fdt_chosen(void *fdt)
?? {
?????? int?? nodeoffset;common/fdt_support.c +1
-1@@ -286,7 +295,8 @@ int fdt_chosen(void *fdt) ?????? if (nodeoffset < 0) ?????????? return nodeoffset; -??? str = env_get("bootargs"); +??? str = board_fdt_chosen_bootargs();Quoted 9 lines
common/fdt_support.c int fdt_chosen(void *fdt) · line 301
Quoted 4 lines
common/fdt_support.c +1
-0+ ?????? if (str) { ?????????? err = fdt_setprop(fdt, nodeoffset, "bootargs", str, ???????????????????? strlen(str) + 1);What's this look like in practice?? I'm very wary about changing "set bootargs to what you pass to the kernel" logic that's been there for forever and a constant of every platform.? Thanks!
Hi Tom,
??? Effectively this change as such should introduce no changes to prevalent
"bootargs" logic when an overridingboard_fdt_chosen_bootargs()is not defined. Our motivation for proposing this change is that it provides us with a means to introduce an entry point where we can append rootfs specific
dm-verity kernel command line metrics (such as described in
https://www.kernel.org/doc/html/latest/admin-guide/device-mapper/verity.html)Quoted 7 lines
Quoted 3 lines
by reading a property from within a kernel tier FIT image header, in order
to facilitate secure boot process all the way to root filesystem.Right.? But what does that logic look like, and why must it be done in C?? People have used dm-verity with U-Boot for ages, for example.
Our build time implementation injects rootfs specific dm-verity metrics in FIT conf node property, effectively coupling the particular (kernel tier) FIT image and particular rootfs image containing trailing verity hash tree.
Below is a sample of such conf node - please note also that the two '${rootdev}' placeholder strings in the injected property are replaced with device node path to 'active' rootfs (in a dual bank scheme where the 'active' rootfs bank is resolved runtime).
??? configurations {
??????? default = "conf-c";
??????? conf-c {
??????????? description = "Linux kernel and FDT blob"; ??????????? kernel = "kernel";
??????????? fdt = "fdt-c";
??????????? vaisala,dm-verity-args = "dm-mod.create="dm-verity,
ec077aa7-78e5-43b7-9605-0d7f72fc65b9, , ro,? 0 136220 verity 1 ${rootdev} ${rootdev} 1024 4096 68110 17028 sha2562dcd25db0f5b94603843316e5a16ca7717585802bf9a3fbced1443d7f83ec5f6fec6bf67513d044bc704c63e37508b223d75867842ac828ba0147c60805786981restart_on_corruption" root=/dev/dm-0 ro";
??????????? signature {
??????????????? ...
??????????? };
??????? };In the boot flow the FIT needs to be signature verified and is processed only after boot command has been issued. Resorting to u-boot scripting means it would require parsing FIT twice and do all verifications twice. Using C avoids this redundancy.
The command line approach is supported since Linux kernel version 5.1 onwards (
CONFIG_DM_INIT), and it avoids us the need to bundle a "trampoline" initramfs with Linux kernel for issuing veritysetup and mount commands. The bundling approach struck as more time consuming and also more cumbersome on Yocto to build for various different image types in same build, and introduces additional booting overhead on target.
Quoted 8 lines
Related to existing dm-verity support in U-Boot, I observed there is Android Verified Boot 2.0 code which seemed to resort to appending the kernel command line, which lead us to propose this change which would allow us to perform the picking of the property from the FIT image, processing it and appending it to our default "bootargs" in a board specific function.
-Niko
Since discussion seems discontinued, adding Mr. Simon Glass to recipients as custodian of common/fdt_support.c as reported by scripts/get_maintainer.pl
PATCH 1/1 fdt_support.c: Allow late kernel cmdline modification
Hi Niko,
Quoted 118 lines · Niko Mauno
Quoted 116 lines · Niko Mauno
Quoted 61 lines · Tom Rini
Quoted 60 lines · Niko Mauno
Quoted 39 lines · Tom Rini
Quoted 37 lines · Niko Mauno
By declaring board-specific
board_fdt_chosen_bootargs()the kernel command line arguments can be adjusted before injecting to flat dt chosen node.Signed-off-by Niko Mauno <[email protected]>--- common/fdt_support.c | 12 +++++++++++- include/fdt_support.h | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-)common/fdt_support.c +2
-0@@ -269,6 +269,15 @@ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end)return 0 ; } +/** +* board_fdt_chosen_bootargs - boards may override this function to use
+ * alternative kernel command line
arguments
+ */common/fdt_support.c +6
-1+__weak char *board_fdt_chosen_bootargs (void ) +{ +return env_get ("bootargs" ); +} +int fdt_chosen (void *fdt) {int nodeoffset;@@ -286,7 +295,8 @@ int fdt_chosen(void *fdt)if (nodeoffset <0 )return nodeoffset; - str =env_get ("bootargs" ); + str =board_fdt_chosen_bootargs ();Quoted 9 lines
common/fdt_support.c int fdt_chosen(void *fdt) · line 302
Quoted 4 lines
common/fdt_support.c +1
-0+if (str) { err =fdt_setprop (fdt, nodeoffset,"bootargs" , str,strlen (str) +1 );What's this look like in practice? I'm very wary about changing "set bootargs to what you pass to the kernel" logic that's been there for forever and a constant of every platform. Thanks!
Hi Tom,
Effectively this change as such should introduce no changes to
prevalent
"bootargs" logic when an overridingboard_fdt_chosen_bootargs()is not defined. Our motivation for proposing this change is that it provides us with a means to introduce an entry point where we can append rootfs specific
dm-verity kernel command line metrics (such as described in
https://www.kernel.org/doc/html/latest/admin-guide/device-mapper/verity.html)Quoted 7 lines
Quoted 3 lines
by reading a property from within a kernel tier FIT image header, in order
to facilitate secure boot process all the way to root filesystem.Right. But what does that logic look like, and why must it be done in C? People have used dm-verity with U-Boot for ages, for example.
Our build time implementation injects rootfs specific dm-verity metrics in FIT conf node property, effectively coupling the particular (kernel tier) FIT image and particular rootfs image containing trailing verity hash tree.
Below is a sample of such conf node - please note also that the two '${rootdev}' placeholder strings in the injected property are replaced with device node path to 'active' rootfs (in a dual bank scheme where the 'active' rootfs bank is resolved runtime).
configurations { default = "conf-c"; conf-c { description = "Linux kernel and FDT blob"; kernel = "kernel"; fdt = "fdt-c"; vaisala,dm-verity-args = "dm-mod.create="dm-verity,ec077aa7-78e5-43b7-9605-0d7f72fc65b9, , ro, 0 136220 verity 1 ${rootdev} ${rootdev} 1024 4096 68110 17028 sha256
2dcd25db0f5b94603843316e5a16ca7717585802bf9a3fbced1443d7f83ec5f6fec6bf67513d044bc704c63e37508b223d75867842ac828ba0147c60805786981restart_on_corruption" root=/dev/dm-0 ro"; signature { ... }; };In the boot flow the FIT needs to be signature verified and is processed only after boot command has been issued. Resorting to u-boot scripting means it would require parsing FIT twice and do all verifications twice. Using C avoids this redundancy.
The command line approach is supported since Linux kernel version 5.1 onwards (
CONFIG_DM_INIT), and it avoids us the need to bundle a "trampoline" initramfs with Linux kernel for issuing veritysetup and mount commands. The bundling approach struck as more time consuming and also more cumbersome on Yocto to build for various different image types in same build, and introduces additional booting overhead on target.Related to existing dm-verity support in U-Boot, I observed there is Android Verified Boot 2.0 code which seemed to resort to appending the kernel command line, which lead us to propose this change which would allow us to perform the picking of the property from the FIT image, processing it and appending it to our default "bootargs" in a board specific function.
Quoted 5 lines
Quoted 1 line
-Niko
Since discussion seems discontinued, adding Mr. Simon Glass to recipients as custodian of
common/fdt_support.cas reported byscripts/get_maintainer.pl
This is used on coral which enables CONFIG_BOOTARGS_SUBST so you might find that does what you want. Once you have the args in an env var then bootm should do it for you.
Regards,
Simon
PATCH 1/1 fdt_support.c: Allow late kernel cmdline modification
In reply to Niko MaunoQuoted 5 lines · Niko Mauno
By declaring board-specific
board_fdt_chosen_bootargs()the kernel command line arguments can be adjusted before injecting to flat dt chosen node.Signed-off-by Niko Mauno <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210506/c4d4386b/attachment.sig>