linux: Introduce DTB's bootargs fixup feature
PATCH 1/1 linux: Introduce DTB's bootargs fixup feature
The goal of this patch is to make Kernel command line modifications in DTB without having to add patches on top of the Kernel tree.
This is done from Buildroot's config, user can:
- Overwrite the full bootargs property's value
- Append a string to the bootargs property's value
For example, the first option is usefull when the user want to change the root parameter, while the second option can be used to add debug parameters.
--- linux/Config.in | 21 +++++++++++++++++++++ linux/linux.mk | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 54 insertions(+), 5 deletions(-)
linux/Config.in +21 -0
@@ -381,6 +381,27 @@ config BR2_LINUX_KERNEL_CUSTOM_DTS_PATH provide a list of dts paths to copy and build, separated by spaces. +config BR2_LINUX_KERNEL_DTB_BOOTARGS_FIXUP + bool "Modify bootargs in DT blob" + select BR2_PACKAGE_HOST_DTC + help + Use fdtput tool from libfdt to fixup the Kernel + command line defined in the DT blob. + It avoids patching the DTS file. + +config BR2_LINUX_KERNEL_DTB_BOOTARGS_OVERWRITE_STRING + string "Overwrite bootargs string in DT blob" + depends on BR2_LINUX_KERNEL_DTB_BOOTARGS_FIXUP + help + String which overwrites the bootargs defined + in the DT blob. + +config BR2_LINUX_KERNEL_DTB_BOOTARGS_APPEND_STRING + string "Append bootargs string in DT blob" + depends on BR2_LINUX_KERNEL_DTB_BOOTARGS_FIXUP + help + String to append to the bootargs defined in + the DT blob. endif config BR2_LINUX_KERNEL_INSTALL_TARGET
linux/linux.mk +33 -5
@@ -87,6 +87,13 @@ LINUX_MAKE_ENV = \ $(TARGET_MAKE_ENV) \ BR_BINARIES_DIR=$(BINARIES_DIR) +ifeq ($(BR2_LINUX_KERNEL_DTB_BOOTARGS_FIXUP),y) +LINUX_DEPENDENCIES += host-dtc +# Reserve some padding for fixup +LINUX_MAKE_ENV += \ + DTC_FLAGS="-p 1024" +endif + # Get the real Linux version, which tells us where kernel modules are # going to be installed in the target filesystem. LINUX_VERSION_PROBED = `$(MAKE) $(LINUX_MAKE_FLAGS) -C $(LINUX_DIR) --no-print-directory -s kernelrelease 2>/dev/null`
@@ -102,6 +109,9 @@ KERNEL_DTS_NAME = $(basename $(filter %.dts,$(notdir $(call qstrip,$(BR2_LINUX_K endif KERNEL_DTBS = $(addsuffix .dtb,$(KERNEL_DTS_NAME)) +# dtbs moved from arch/<ARCH>/boot to arch/<ARCH>/boot/dts since 3.8-rc1 +KERNEL_DTBS_PATH = $(addprefix $(KERNEL_ARCH_PATH)/boot/$(if $(wildcard \ + $(addprefix $(KERNEL_ARCH_PATH)/boot/dts/,$(KERNEL_DTBS))),dts/),$(KERNEL_DTBS)) ifeq ($(BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM),y) LINUX_IMAGE_NAME = $(call qstrip,$(BR2_LINUX_KERNEL_IMAGE_NAME))
@@ -267,13 +277,30 @@ ifeq ($(BR2_LINUX_KERNEL_DTB_IS_SELF_BUILT),) define LINUX_BUILD_DTB $(LINUX_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) $(KERNEL_DTBS) endef +ifeq ($(BR2_LINUX_KERNEL_DTB_BOOTARGS_FIXUP),y) +define LINUX_FIXUP_DTB + $(LINUX_DTB_OVERWRITE_BOOTARGS) + $(LINUX_DTB_APPEND_BOOTARGS) +endef +ifneq ($(BR2_LINUX_KERNEL_DTB_BOOTARGS_OVERWRITE_STRING),"") +define LINUX_DTB_OVERWRITE_BOOTARGS + # Overwriting DTB's bootargs + $(HOST_DIR)/usr/bin/fdtput -ts $(KERNEL_DTBS_PATH) "/chosen" "bootargs" \ + $(call qstrip,$(BR2_LINUX_KERNEL_DTB_BOOTARGS_OVERWRITE_STRING)) +endef +endif # BR2_LINUX_KERNEL_DTB_BOOTARGS_OVERWRITE_STRING +ifneq ($(BR2_LINUX_KERNEL_DTB_BOOTARGS_APPEND_STRING),"") +define LINUX_DTB_APPEND_BOOTARGS + # Appending DTB's bootargs + $(HOST_DIR)/usr/bin/fdtput -ts $(KERNEL_DTBS_PATH) "/chosen" "bootargs" \ + "`$(HOST_DIR)/usr/bin/fdtget -ts $(KERNEL_DTBS_PATH) \ + "/chosen" "bootargs"` $(call qstrip,$(BR2_LINUX_KERNEL_DTB_BOOTARGS_APPEND_STRING))" +endef +endif # BR2_LINUX_KERNEL_DTB_BOOTARGS_APPEND_STRING +endif # BR2_LINUX_KERNEL_DTB_BOOTARGS_FIXUP ifeq ($(BR2_LINUX_KERNEL_APPENDED_DTB),) define LINUX_INSTALL_DTB - # dtbs moved from arch/<ARCH>/boot to arch/<ARCH>/boot/dts since 3.8-rc1 - cp $(addprefix \ - $(KERNEL_ARCH_PATH)/boot/$(if $(wildcard \ - $(addprefix $(KERNEL_ARCH_PATH)/boot/dts/,$(KERNEL_DTBS))),dts/),$(KERNEL_DTBS)) \ - $(1) + cp $(KERNEL_DTBS_PATH) $(1) endef endif # BR2_LINUX_KERNEL_APPENDED_DTB endif # BR2_LINUX_KERNEL_DTB_IS_SELF_BUILT
@@ -319,6 +346,7 @@ define LINUX_BUILD_CMDS $(LINUX_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) modules ; \ fi $(LINUX_BUILD_DTB) + $(LINUX_FIXUP_DTB) $(LINUX_APPEND_DTB) endef
Signature · 1 line
1.9.1
PATCH 1/1 linux: Introduce DTB's bootargs fixup feature
Hello,
Quoted 8 lines · Maxime Coquelin
The goal of this patch is to make Kernel command line modifications in DTB without having to add patches on top of the Kernel tree.
This is done from Buildroot's config, user can:
- Overwrite the full bootargs property's value
- Append a string to the bootargs property's value
Quoted 5 lines
For example, the first option is usefull when the user want to change the root parameter, while the second option can be used to add debug parameters.
Signed-off-by Maxime Coquelin <[email protected]>
Thanks for this patch! I see how it can be useful for the STM32 defconfigs.
However, I am not entirely sure this is something we want to take in Buildroot. Indeed, your patch only allows to customize
the /chosen/bootargs property, and not any other property of the Device Tree. If we want to do that via Config.in options, it suddenly becomes a lot more complicated.
So I believe a more Buildroot-ish way of doing this is to simply do it in a post-image script. The only thing needed to do that is to add some padding when creating the DTB, which we could either do unconditionally, or add an option to indicate how much padding is needed. But then, calling fdtput would be done in a post-image script.
It is IMO even more important to do it this way since as of today, only one platform/board needs to adjust its bootargs this way. All other platforms have an ATAGs or DT compatible bootloader, where the bootargs customization is done via the bootloader, not via patching the DTB.
Of course, let's see what others think.
Thanks!
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
PATCH 1/1 linux: Introduce DTB's bootargs fixup feature
2016-03-21 13:12 GMT+01:00 Thomas Petazzoni
<[email protected]>:
Quoted 17 lines
Hello,
Quoted 8 lines · Maxime Coquelin
The goal of this patch is to make Kernel command line modifications in DTB without having to add patches on top of the Kernel tree.
This is done from Buildroot's config, user can:
- Overwrite the full bootargs property's value
- Append a string to the bootargs property's valueQuoted 5 lines
For example, the first option is usefull when the user want to change the root parameter, while the second option can be used to add debug parameters.
Signed-off-by Maxime Coquelin <[email protected]>
Quoted 8 lines
Thanks for this patch! I see how it can be useful for the STM32 defconfigs.
However, I am not entirely sure this is something we want to take in Buildroot. Indeed, your patch only allows to customize
the /chosen/bootargs property, and not any other property of the Device Tree. If we want to do that via Config.in options, it suddenly becomes a lot more complicated.
Indeed, it will be difficult to extend it further than bootargs. It works well for bootargs for two reasons:
1- It is a generic property
2- It is a string
There could be other uses for DTB patching, such as MAC address assignment. But I agree than doing this in Config.in makes no sense.
Quoted 11 lines
So I believe a more Buildroot-ish way of doing this is to simply do it in a post-image script. The only thing needed to do that is to add some padding when creating the DTB, which we could either do unconditionally, or add an option to indicate how much padding is needed. But then, calling fdtput would be done in a post-image script.
It is IMO even more important to do it this way since as of today, only one platform/board needs to adjust its bootargs this way. All other platforms have an ATAGs or DT compatible bootloader, where the bootargs customization is done via the bootloader, not via patching the DTB.
Ok, For sure it can be done, but I wanted to propose a generic way of doing this.
Indeed, this is something other platforms could potentially use, even if not the case today.
Quoted 1 line
Of course, let's see what others think.
Agree.
If it is decided to do this as post-image script, I will be happy to implement it.
Regards,
Maxime
PATCH 1/1 linux: Introduce DTB's bootargs fixup feature
Hello,
Quoted 5 lines · Maxime Coquelin
Quoted 5 lines
However, I am not entirely sure this is something we want to take in Buildroot. Indeed, your patch only allows to customize
the /chosen/bootargs property, and not any other property of the Device Tree. If we want to do that via Config.in options, it suddenly becomes a lot more complicated.
Quoted 7 lines
Indeed, it will be difficult to extend it further than bootargs. It works well for bootargs for two reasons:
1- It is a generic property
2- It is a stringThere could be other uses for DTB patching, such as MAC address assignment. But I agree than doing this in Config.in makes no sense.
Right.
Quoted 10 lines
Quoted 4 lines
It is IMO even more important to do it this way since as of today, only one platform/board needs to adjust its bootargs this way. All other platforms have an ATAGs or DT compatible bootloader, where the bootargs customization is done via the bootloader, not via patching the DTB.
Ok, For sure it can be done, but I wanted to propose a generic way of doing this.
Indeed, this is something other platforms could potentially use, even if not the case today.
Quoted 5 lines
Quoted 1 line
Of course, let's see what others think.
Agree.
If it is decided to do this as post-image script, I will be happy to implement it.
Nobody spoke up, so let's say we'll do it in a post-image script for now. host-dtc is already visible in menuconfig, so it can be enabled in a defconfig, and therefore it's just a matter of enabling it and write the appropriate post-image script.
Do you want to write a patch on top of my series adding Cortex-M support?
Best regards,
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
PATCH 1/1 linux: Introduce DTB's bootargs fixup feature
Hi Thomas,
2016-03-30 0:11 GMT+02:00 Thomas Petazzoni
<[email protected]>:
Quoted 35 lines
Hello,
Quoted 5 lines · Maxime Coquelin
Quoted 5 lines
However, I am not entirely sure this is something we want to take in Buildroot. Indeed, your patch only allows to customize
the /chosen/bootargs property, and not any other property of the Device Tree. If we want to do that via Config.in options, it suddenly becomes a lot more complicated.Quoted 7 lines
Indeed, it will be difficult to extend it further than bootargs. It works well for bootargs for two reasons:
1- It is a generic property
2- It is a stringThere could be other uses for DTB patching, such as MAC address assignment. But I agree than doing this in Config.in makes no sense.
Right.
Quoted 10 lines
Quoted 4 lines
It is IMO even more important to do it this way since as of today, only one platform/board needs to adjust its bootargs this way. All other platforms have an ATAGs or DT compatible bootloader, where the bootargs customization is done via the bootloader, not via patching the DTB.
Ok, For sure it can be done, but I wanted to propose a generic way of doing this.
Indeed, this is something other platforms could potentially use, even if not the case today.Quoted 5 lines
Quoted 1 line
Of course, let's see what others think.
Agree.
If it is decided to do this as post-image script, I will be happy to implement it.
Quoted 7 lines
Nobody spoke up, so let's say we'll do it in a post-image script for now. host-dtc is already visible in menuconfig, so it can be enabled in a defconfig, and therefore it's just a matter of enabling it and write the appropriate post-image script.
Do you want to write a patch on top of my series adding Cortex-M support?
Yes.
Will you apply your Cortex-M series soon on master branch? I will propose a patch as soon as your series is available.
Regards,
Maxime
PATCH 1/1 linux: Introduce DTB's bootargs fixup feature
Hello,
Quoted 4 lines · Maxime Coquelin
Quoted 2 lines
Do you want to write a patch on top of my series adding Cortex-M support?
Yes.
Thanks!
Quoted 2 lines
Will you apply your Cortex-M series soon on master branch? I will propose a patch as soon as your series is available.
I applied a few more patches yesterday. But some other patches had comments, which I need to address and resend a new version.
Thanks!
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com