[OpenWrt-Devel] How to get OpenWRT to leave kernel .config the f alone?

Message ID f79a868b-c757-9e51-e28d-d4c84fdbf346@pobox.com
State New
Headers show
Series
  • [OpenWrt-Devel] How to get OpenWRT to leave kernel .config the f alone?
Related show

Commit Message

Daniel Santos March 9, 2018, 5:24 a.m.
Hello. I'm not very good with make and I need to make many changes to my
kernel .config for debugging. I wrote a patch to add an option to tell
OpenWRT to leave it alone, but I don't understand this build system very
well and it seems to always prevent the kernel .config from being
modified as well as leading to modules & kernel always being rebuilt.
Would somebody be kind enough to fix it for me? :)

I'm new to this project and I'm working with a device that has a crappy
u-boot build installed on it. I need to run a debug kernel, but any time
I attempt to tftp it to the device (directly to RAM) it fails to boot.
If I send the whole damn sysupgrade via lcui then it works. Thus, if I
upload a bad sysupgrade, I can potentially get locked out of the device
until I manually flash the SPI (and I don't know how to do that yet, I
guess some type of jtag?). So rather than just manually building my
kernel and building a sysupgrade by hand, I would rather the build do it
out of caution for messing it up.

Oh yeah, and I'm using CC at this commit:
0625aaa6f37dcf6a2ffb611245fa9b6477642b78 -- of which I have no choice
about. But if anybody can get that to work for the 17.x head, I can
backport it.

Thanks in advance!
Daniel

Comments

Alexandru Ardelean March 9, 2018, 7:46 a.m. | #1
On Fri, Mar 9, 2018 at 7:24 AM, Daniel Santos <daniel.santos@pobox.com> wrote:
> Hello. I'm not very good with make and I need to make many changes to my
> kernel .config for debugging. I wrote a patch to add an option to tell
> OpenWRT to leave it alone, but I don't understand this build system very
> well and it seems to always prevent the kernel .config from being
> modified as well as leading to modules & kernel always being rebuilt.
> Would somebody be kind enough to fix it for me? :)
>

The problem is not the OpenWrt build system here.
It's likely the kernel's Kconfig system and dependency chain.
Your patch is going about it from the wrong angle.

Most symbols in the .config [whether OpenWrt's .config or kernel's
.config] have a dependency chain.
Example: driver bcm2708-spi [don't remember the actual driver name
here] will not be built/installed if CONFIG_SPI is not enabled in
.config.

So, if the symbol for building bcm2708-spi [let's call it
CONFIG_BCM2708_SPI] disappears during build, it's a symptom that the
dependency chain is not correct.
In a way, you may want this behavior, versus leaving it there and not
building it anyway.

What you can do is [in the OpenWrt context]:
* make kernel_menuconfig
* hit the slash key " / "
* type/search for the symbol you want to enable
* once you find it, it will list all symbols it depends on ; and which
you also want enabled
* add those symbols to your kernel config, or enable them via this
menuconfig you are in

Note that this Kconfig build-system is present in many projects [
Linux kernel, OpenWrt, buildroot, etc ].
So, if you learn to use it, the skill will be useful later on.

Typically, what I've noticed, is that the Linux kernel [in newer
versions] will enforce dependencies in drivers/code that were
previously not there, and when you update your kernel, stuff
disappears/gets disabled.
So, if you using an older .config in a newer kernel, or some other
mix, this is possible.

> I'm new to this project and I'm working with a device that has a crappy
> u-boot build installed on it. I need to run a debug kernel, but any time
> I attempt to tftp it to the device (directly to RAM) it fails to boot.
> If I send the whole damn sysupgrade via lcui then it works. Thus, if I
> upload a bad sysupgrade, I can potentially get locked out of the device
> until I manually flash the SPI (and I don't know how to do that yet, I
> guess some type of jtag?). So rather than just manually building my
> kernel and building a sysupgrade by hand, I would rather the build do it
> out of caution for messing it up.
>
> Oh yeah, and I'm using CC at this commit:
> 0625aaa6f37dcf6a2ffb611245fa9b6477642b78 -- of which I have no choice
> about. But if anybody can get that to work for the 17.x head, I can
> backport it.
>
> Thanks in advance!
> Daniel
>

Alex

> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
>
Daniel Santos March 9, 2018, 4:07 p.m. | #2
On 03/09/2018 01:46 AM, Alexandru Ardelean wrote:
> On Fri, Mar 9, 2018 at 7:24 AM, Daniel Santos <daniel.santos@pobox.com> wrote:
>> Hello. I'm not very good with make and I need to make many changes to my
>> kernel .config for debugging. I wrote a patch to add an option to tell
>> OpenWRT to leave it alone, but I don't understand this build system very
>> well and it seems to always prevent the kernel .config from being
>> modified as well as leading to modules & kernel always being rebuilt.
>> Would somebody be kind enough to fix it for me? :)
>>
> The problem is not the OpenWrt build system here.
> It's likely the kernel's Kconfig system and dependency chain.
> Your patch is going about it from the wrong angle.
>
> Most symbols in the .config [whether OpenWrt's .config or kernel's
> .config] have a dependency chain.
> Example: driver bcm2708-spi [don't remember the actual driver name
> here] will not be built/installed if CONFIG_SPI is not enabled in
> .config.
>
> So, if the symbol for building bcm2708-spi [let's call it
> CONFIG_BCM2708_SPI] disappears during build, it's a symptom that the
> dependency chain is not correct.
> In a way, you may want this behavior, versus leaving it there and not
> building it anyway.
>
> What you can do is [in the OpenWrt context]:
> * make kernel_menuconfig
> * hit the slash key " / "
> * type/search for the symbol you want to enable
> * once you find it, it will list all symbols it depends on ; and which
> you also want enabled
> * add those symbols to your kernel config, or enable them via this
> menuconfig you are in
>
> Note that this Kconfig build-system is present in many projects [
> Linux kernel, OpenWrt, buildroot, etc ].
> So, if you learn to use it, the skill will be useful later on.
>
> Typically, what I've noticed, is that the Linux kernel [in newer
> versions] will enforce dependencies in drivers/code that were
> previously not there, and when you update your kernel, stuff
> disappears/gets disabled.
> So, if you using an older .config in a newer kernel, or some other
> mix, this is possible.


Thanks for the response.  This isn't the problem however.  I simply want
to be able to manage my own .config separate from OpenWRT.  I realize
this breaks the scheme, but I'm having a lot of problems getting the
kernel .config that I need using OpenWRT.  Currently, after having run
make kernel_menuconfig, oldconfig is now prompting me for a choice that
I have attempted to already make (and I'm not sure why).  This is
inhibiting a parallel build.  So as a work-around and also just another
option, I would like to manage the .config myself.

Thanks
Daniel

Patch

From 04d9b710782308106e6b37d40f3f08cba04e57fd Mon Sep 17 00:00:00 2001
From: Daniel Santos <daniel.santos@pobox.com>
Date: Thu, 8 Mar 2018 22:39:33 -0600
Subject: [PATCH] external kernel .config

---
 config/Config-devel.in     | 8 ++++++++
 include/kernel-build.mk    | 4 ++--
 include/kernel-defaults.mk | 8 ++++++++
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/config/Config-devel.in b/config/Config-devel.in
index d096c18a72..8603010485 100644
--- a/config/Config-devel.in
+++ b/config/Config-devel.in
@@ -65,6 +65,14 @@  menuconfig DEVEL
 		string "Use external kernel tree" if DEVEL
 		default ""
 
+	config EXTERNAL_KERNEL_CONFIG
+		bool "Use .config in external kernel tree (and do not modify it)." if DEVEL
+		depends on (EXTERNAL_KERNEL_TREE != "")
+		default N
+		help
+		  If enabled, OpenWRT will not generate or modify the .config
+		  file in the external kernel tree.
+
 	config KERNEL_GIT_CLONE_URI
 		string "Enter git repository to clone" if DEVEL
 		default ""
diff --git a/include/kernel-build.mk b/include/kernel-build.mk
index 9abfd542e8..7f19a7260e 100644
--- a/include/kernel-build.mk
+++ b/include/kernel-build.mk
@@ -126,9 +126,9 @@  define BuildKernel
 
   oldconfig menuconfig nconfig: $(STAMP_PREPARED) $(STAMP_CHECKED) FORCE
 	rm -f $(STAMP_CONFIGURED)
-	$(LINUX_RECONF_CMD) > $(LINUX_DIR)/.config
+	$(ifdef EXTERNAL_KERNEL_CONFIG,,$(LINUX_RECONF_CMD) > $(LINUX_DIR)/.config)
 	$(_SINGLE)$(MAKE) -C $(LINUX_DIR) $(KERNEL_MAKEOPTS) $$@
-	$(LINUX_RECONF_DIFF) $(LINUX_DIR)/.config > $(LINUX_RECONFIG_TARGET)
+	$(ifdef EXTERNAL_KERNEL_CONFIG,,$(LINUX_RECONF_DIFF) $(LINUX_DIR)/.config > $(LINUX_RECONFIG_TARGET))
 
   install: $(LINUX_DIR)/.image
 	+$(MAKE) -C image compile install TARGET_BUILD=
diff --git a/include/kernel-defaults.mk b/include/kernel-defaults.mk
index 24d26308b1..454c9da53d 100644
--- a/include/kernel-defaults.mk
+++ b/include/kernel-defaults.mk
@@ -100,6 +100,7 @@  define Kernel/SetNoInitramfs
 	echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config
 endef
 
+ifdef EXTERNAL_KERNEL_CONFIG
 define Kernel/Configure/Default
 	$(LINUX_CONF_CMD) > $(LINUX_DIR)/.config.target
 # copy CONFIG_KERNEL_* settings over to .config.target
@@ -114,6 +115,13 @@  define Kernel/Configure/Default
 	$(_SINGLE) [ -d $(LINUX_DIR)/user_headers ] || $(MAKE) $(KERNEL_MAKEOPTS) INSTALL_HDR_PATH=$(LINUX_DIR)/user_headers headers_install
 	$(SH_FUNC) grep '=[ym]' $(LINUX_DIR)/.config | LC_ALL=C sort | md5s > $(LINUX_DIR)/.vermagic
 endef
+else
+define Kernel/Configure/Default
+	rm -rf $(KERNEL_BUILD_DIR)/modules
+	$(_SINGLE) [ -d $(LINUX_DIR)/user_headers ] || $(MAKE) $(KERNEL_MAKEOPTS) INSTALL_HDR_PATH=$(LINUX_DIR)/user_headers headers_install
+	$(SH_FUNC) grep '=[ym]' $(LINUX_DIR)/.config | LC_ALL=C sort | md5s > $(LINUX_DIR)/.vermagic
+endef
+endif
 
 define Kernel/Configure/Initramfs
 	$(call Kernel/SetInitramfs)
-- 
2.15.0