Skip to contentSkip to conversation

Building external modules against objdirs

DISCUSSION Andi Kleen 3 participants 11 messages Jul 30, 2006 – Aug 1, 2006 Kbuild

lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

Hi,

It looks like building external modules against separate objdirs doesn't work anymore in 2.6.18.

tmod is a simple module I use for some testing.

obj-* are objdirs tree built against separate source with make O=$(pwd) -C ../linux-...

Quoted 1 line

cat Makefile

obj-m := tmod.o

KERNELDIR := /lib/modules/uname -r/build

all:

        $(MAKE) -C ${KERNELDIR} M=`pwd`

With 2.6.17 it works great:

Quoted 1 line

make KERNELDIR=/home/lsrc/obj-2.6.17

make -C /home/lsrc/obj-2.6.17 M=pwd
make[1]: Entering directory `/home/lsrc/obj-2.6.17' make -C /home/lsrc/linux-2.6.17 O=/home/lsrc/obj-2.6.17
Building modules, stage 2.
MODPOST
CC /home/andi/tsrc/tmod/tmod.mod.o
LD [M] /home/andi/tsrc/tmod/tmod.ko
make[1]: Leaving directory `/home/lsrc/obj-2.6.17'

But with 2.6.18-rc3 it doesn't work anymore. I saw this for at least a few weeks already with 2.6.17-git*, but only realized now it wasn't some stupid mistake on my side.

Quoted 1 line

make -C /home/lsrc/quilt/obj M=pwd

make[1]: Entering directory `/home/lsrc/quilt/obj'
make -C /basil/home/lsrc/quilt/linux O=/basil/home/lsrc/quilt/obj
/home/lsrc/quilt/linux/Makefile:456: *** kernel configuration not valid - run 'make prepare' in /home/lsrc/quilt/linux to update it. Stop. make[2]: *** [_all] Error 2
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/lsrc/quilt/obj'
make: *** [all] Error 2

Is there a workaround? It would be good to fix it for 2.6.18 because it will likely cause trouble for a lot of external projects.

-Andi

#1 lore raw
Quoted 5 lines · Andi Kleen

Hi,

It looks like building external modules against separate objdirs doesn't work anymore in 2.6.18.

I just tried it out with -linus (from a few hours ago). $> cd ~/kernel/linux-2.6
$> mkdir ../o
$> make O=../o defconfig
$> make O=../o
...
$> cd ~/kernel/external
$> cat Makefile
obj-m := sam.o
sam-y := sam1.o
EXTRA_CFLAGS := -I$(src)/include

$> make M=pwd O=~/kernel/o -C ~/kernel/linux-2.6
make: Entering directory `/home/sam/kernel/linux-2.6'

  LD      /home/sam/kernel/external/built-in.o
  CC [M]  /home/sam/kernel/external/sam1.o
  LD [M]  /home/sam/kernel/external/sam.o

Building modules, stage 2.
MODPOST
CC /home/sam/kernel/external/sam.mod.o
LD [M] /home/sam/kernel/external/sam.ko
make: Leaving directory `/home/sam/kernel/linux-2.6'

So it seems to work out fine here.

Can you check that you really did a 'make prepare' in the relevant output directory. Previously only the make *config step was needed.

Sam

author
#2 lore raw
Quoted 3 lines

Can you check that you really did a 'make prepare' in the relevant output directory. Previously only the make *config step was needed.

The output directory is a full build (configuration + make without any targets). Is that not enough anymore?

Anyways after a make prepare it seems to work - thanks - but I think that should be really done as part of the standard build like it was in 2.6.17.

-Andi

#3 lore raw
Quoted 9 lines · Andi Kleen
Quoted 3 lines

Can you check that you really did a 'make prepare' in the relevant output directory. Previously only the make *config step was needed.

The output directory is a full build (configuration + make without any targets). Is that not enough anymore?

Anyways after a make prepare it seems to work - thanks - but I think that should be really done as part of the standard build like it was in 2.6.17.

'make prepare' is and has always been part of the standard build. So I really do not see what is going on.

Can you please check that followign files exists in your output directory:
.config
include/config/auto.conf.cmd
include/config/auto.conf

the latter should be the latest of the three.

Also try applying following patch to reveal why we trigger this rule:

Makefile +1 -0
index 1dd58d3..4c30ed5 100644
@@ -453,6 +453,7 @@ include/config/auto.conf: $(KCONFIG_CONF
 ifeq ($(KBUILD_EXTMOD),)
 	$(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
 else
+	@echo triggered by - $? -
 	$(error kernel configuration not valid - run 'make prepare' in $(srctree) to update it)
 endif
 
#9 lore raw
In reply to Andi Kleen
Quoted 9 lines · Andi Kleen
Quoted 3 lines

Can you check that you really did a 'make prepare' in the relevant output directory. Previously only the make *config step was needed.

The output directory is a full build (configuration + make without any targets). Is that not enough anymore?

Anyways after a make prepare it seems to work - thanks - but I think that should be really done as part of the standard build like it was in 2.6.17.

It could also be a mis-merge of some suse patches. Is this with a vanilla kernel or a suse patched one?

If the latter can I then have a full copy to look at.

Sam

author
#4 lore raw
In reply to Sam Ravnborg
Quoted 5 lines · Sam Ravnborg
Quoted 4 lines · Andi Kleen
Quoted 3 lines

Can you check that you really did a 'make prepare' in the relevant output directory. Previously only the make *config step was needed.

Quoted 7 lines
Quoted 5 lines

The output directory is a full build (configuration + make without any targets). Is that not enough anymore?

Anyways after a make prepare it seems to work - thanks - but I think that should be really done as part of the standard build like it was in 2.6.17.

'make prepare' is and has always been part of the standard build. So I really do not see what is going on.

To reproduce (on x86-64 at least)

mkdir obj
cd obj
make -C ../linux-2.6.18-... O=$(pwd) defconfig
make

Quoted 7 lines

Can you please check that followign files exists in your output directory:
.config
include/config/auto.conf.cmd
include/config/auto.conf

the latter should be the latest of the three.

-rw-r--r--  1 andi users 28481 2006-07-29 19:01 .config
-rw-r--r--  1 andi users  7739 2006-07-29 19:07 include/config/auto.conf
-rw-r--r--  1 andi users  6867 2006-07-29 19:07 include/config/auto.conf.cmd

Makefile include/config/auto.conf: $(KCONFIG_CONF · line 458

Quoted 13 lines

Also try applying following patch to reveal why we trigger this rule:

Makefile +1 -0
index 1dd58d3..4c30ed5 100644
@@ -453,6 +453,7 @@ include/config/auto.conf: $(KCONFIG_CONF
 ifeq ($(KBUILD_EXTMOD),)
 	$(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
 else
+	@echo triggered by - $? -
 	$(error kernel configuration not valid - run 'make prepare' in $(srctree) to update it)
 endif

The echo didn't output for some reason, but adding it to the error gives

/home/lsrc/quilt/linux/Makefile:456: *** triggered by /home/lsrc/quilt/linux/drivers/net/wireless/Kconfig /home/lsrc/quilt/linux/drivers/message/fusion/Kconfig /home/lsrc/quilt/linux/net/ieee80211/Kconfig /home/lsrc/quilt/linux/net/netfilter/Kconfig kernel configuration not valid - run 'make prepare' in /home/lsrc/quilt/linux to update it. Stop.

-Andi

author
#10 lore raw
In reply to Sam Ravnborg
Quoted 5 lines · Sam Ravnborg
Quoted 4 lines · Andi Kleen
Quoted 3 lines

Can you check that you really did a 'make prepare' in the relevant output directory. Previously only the make *config step was needed.

Quoted 7 lines
Quoted 5 lines

The output directory is a full build (configuration + make without any targets). Is that not enough anymore?

Anyways after a make prepare it seems to work - thanks - but I think that should be really done as part of the standard build like it was in 2.6.17.

It could also be a mis-merge of some suse patches. Is this with a vanilla kernel or a suse patched one?

vanilla kernel + my x86-64 patchkit, but it doesn't really change anything significant in Makefiles

-Andi

#5 lore raw
In reply to Andi Kleen
Quoted 4 lines · Andi Kleen

The echo didn't output for some reason, but adding it to the error gives

/home/lsrc/quilt/linux/Makefile:456: *** triggered by /home/lsrc/quilt/linux/drivers/net/wireless/Kconfig /home/lsrc/quilt/linux/drivers/message/fusion/Kconfig /home/lsrc/quilt/linux/net/ieee80211/Kconfig /home/lsrc/quilt/linux/net/netfilter/Kconfig kernel configuration not valid - run 'make prepare' in /home/lsrc/quilt/linux to update it. Stop.

What happens is that a few Kconfig files in your quilt tree are updated after last time you reran 'make'.
And then kbuild say that config is invalid since it has not been updated since last edit of Kconfig files.

Hmm...

Sam

author
#6 lore raw
Quoted 9 lines · Sam Ravnborg
Quoted 4 lines · Andi Kleen

The echo didn't output for some reason, but adding it to the error gives

/home/lsrc/quilt/linux/Makefile:456: *** triggered by /home/lsrc/quilt/linux/drivers/net/wireless/Kconfig /home/lsrc/quilt/linux/drivers/message/fusion/Kconfig /home/lsrc/quilt/linux/net/ieee80211/Kconfig /home/lsrc/quilt/linux/net/netfilter/Kconfig kernel configuration not valid - run 'make prepare' in /home/lsrc/quilt/linux to update it. Stop.

What happens is that a few Kconfig files in your quilt tree are updated after last time you reran 'make'.

Yes that happens when I push/pop patches in quilt.

-Andi

#7 lore raw
In reply to Sam Ravnborg

Hi,

Quoted 5 lines · Sam Ravnborg
Quoted 3 lines · Andi Kleen

The echo didn't output for some reason, but adding it to the error gives

Quoted 8 lines
Quoted 1 line

/home/lsrc/quilt/linux/Makefile:456: *** triggered by /home/lsrc/quilt/linux/drivers/net/wireless/Kconfig /home/lsrc/quilt/linux/drivers/message/fusion/Kconfig /home/lsrc/quilt/linux/net/ieee80211/Kconfig /home/lsrc/quilt/linux/net/netfilter/Kconfig kernel configuration not valid - run 'make prepare' in /home/lsrc/quilt/linux to update it. Stop.

What happens is that a few Kconfig files in your quilt tree are updated after last time you reran 'make'.
And then kbuild say that config is invalid since it has not been updated since last edit of Kconfig files.

Hmm...

What we could do is to call silentoldconfig and set KCONFIG_NOSILENTUPDATE, if the .config is uptodate it will only update autoconf and abort otherwise.

bye, Roman

#8 lore raw
Quoted 16 lines · Roman Zippel

Hi,

Quoted 12 lines · Sam Ravnborg
Quoted 4 lines · Andi Kleen

The echo didn't output for some reason, but adding it to the error gives

/home/lsrc/quilt/linux/Makefile:456: *** triggered by /home/lsrc/quilt/linux/drivers/net/wireless/Kconfig /home/lsrc/quilt/linux/drivers/message/fusion/Kconfig /home/lsrc/quilt/linux/net/ieee80211/Kconfig /home/lsrc/quilt/linux/net/netfilter/Kconfig kernel configuration not valid - run 'make prepare' in /home/lsrc/quilt/linux to update it. Stop.

What happens is that a few Kconfig files in your quilt tree are updated after last time you reran 'make'.
And then kbuild say that config is invalid since it has not been updated since last edit of Kconfig files.

Quoted 5 lines
Quoted 1 line

Hmm...

What we could do is to call silentoldconfig and set KCONFIG_NOSILENTUPDATE, if the .config is uptodate it will only update autoconf and abort otherwise.

External modules shall to a great extent just rely on the avialble kernel, and any attempt to do automatic updates are not OK. The kernel source could be RO and no rights to write in the directories either.
So it is preferable to bail out in case we cannot build the external module but to avoid the consistency checks all over. Following patch does this for the configuration part.

Sam

Makefile +18 -6
index 110db85..291bb5e 100644
@@ -436,12 +436,13 @@ core-y		:= usr/
 endif # KBUILD_EXTMOD
 
 ifeq ($(dot-config),1)
-# In this section, we need .config
+# Read in config
+-include include/config/auto.conf
 
+ifeq ($(KBUILD_EXTMOD),)
 # Read in dependencies to all Kconfig* files, make sure to run
 # oldconfig if changes are detected.
 -include include/config/auto.conf.cmd
--include include/config/auto.conf
 
 # To avoid any implicit rule to kick in, define an empty command
 $(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;
@@ -451,16 +452,27 @@ # with it and forgot to run make oldconf
 # if auto.conf.cmd is missing then we are probably in a cleaned tree so
 # we execute the config step to be sure to catch updated Kconfig files
 include/config/auto.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
-ifeq ($(KBUILD_EXTMOD),)
 	$(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
 else
-	$(error kernel configuration not valid - run 'make prepare' in $(srctree) to update it)
-endif
+# external modules needs include/linux/autoconf.h and include/config/auto.conf
+# but do not care if they are up-to-date. Use auto.conf to trigger the test
+PHONY += include/config/auto.conf
+
+include/config/auto.conf:
+	$(Q)test -e include/linux/autoconf.h -a -e $@ || (		\
+	echo;								\
+	echo "  ERROR: Kernel configuration is invalid.";		\
+	echo "         include/linux/autoconf.h or $@ is missing.";	\
+	echo "         Run 'make oldconfig && make prepare' on kernel src to fix it.";	\
+	echo;								\
+	/bin/false)
+
+endif # KBUILD_EXTMOD
 
 else
 # Dummy target needed, because used as prerequisite
 include/config/auto.conf: ;
-endif
+endif # $(dot-config)
 
 # The all: target is the default when no target is given on the
 # command line.