Bug 4389 - kernel: Remove "make scripts" requirement for module building from SDK/on target
Summary: kernel: Remove "make scripts" requirement for module building from SDK/on target
Status: IN PROGRESS DESIGN COMPLETE
Alias: None
Product: ADT
Classification: Yocto Project Subprojects
Component: adt (show other bugs)
Version: 1.5
Hardware: x86 Multiple
: Medium enhancement
Target Milestone: 6.99
Assignee: Bruce Ashfield
QA Contact:
URL:
Whiteboard:
: 5402 6630 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-04-22 18:17 UTC by Bruce Ashfield
Modified: 2026-06-25 15:36 UTC (History)
15 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: Don't know


Attachments
sample/simple module (1.35 KB, application/x-compressed-tar)
2013-05-07 15:27 UTC, Bruce Ashfield
no flags Details
patches being tested. (4.99 KB, patch)
2018-02-16 18:24 UTC, Juro Bystricky
no flags Details | Diff
WIP kernel-devsrc patch (9.48 KB, patch)
2018-02-21 15:47 UTC, Bruce Ashfield
no flags Details | Diff
WIP second iteration, combined patches, powerpc does not build. (7.30 KB, patch)
2018-02-23 00:30 UTC, Juro Bystricky
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Bruce Ashfield 2013-04-22 18:17:33 UTC
We can build kernel modules using the ADT, with the exception of some missing
elements such as the kernel scripts, and the kernel .config triggering a 'make oldconfig'.

As part of the SDK install, can the scripts be restored ? i.e. an automatic 'make scripts', to
drop the requirement of the manual step ? Or perhaps the scripts can be packaged separately
and hence avoid the target QA issues if they are packaged with kernel-dev.

For the .config (this may already be done), have the export of the proper environment variables
(ARCH) to prevent oldconfig from triggering.

The same technique/approach should work for target or host use of the SDK.
Comment 1 Laurentiu Palcu 2013-05-07 11:51:43 UTC
I need more info on this. I don't understand which scripts are you referring to here... I can find the scripts directory in /usr/src/kernel/scripts in the target rootfs. I used adt-installer with the default config file.
Comment 2 Bruce Ashfield 2013-05-07 15:26:56 UTC
The scripts directory is not complete out of the box. If you try building a module
against it, you should get failures. If you don't, then that's even better and the bug
is easy to close.

If you extract the sample-module that I attached and try something like the following:

# make sure the kernel source is in the SDK (via something like the below):

TOOLCHAIN_TARGET_TASK_append = " python-dev kernel-dev"

# build and export the ADT/SDK
# install the SDK

# source the SDK

  % cd /path/to/sdk/
  % source env.sh

  # change to the kernel source:
  % cd /path/to/sdk/<BSP>/sysroots/<BSP>/usr/src/kernel/
  
  # build the sample module
  % make CROSS_COMPILE=<prefix>-linux-gnu- ARCH=x86
                   M=/path/to/sample-module modules

Does it work ? I need an intermediate step of:
  % cd /path/to/sdk/<BSP>/sysroots/<BSP>/usr/src/kernel/
  % make ARCH=x86 scripts

for the build to work for me. Maybe I'm just doing something wrong, or am missing
a setup step!
Comment 3 Bruce Ashfield 2013-05-07 15:27:37 UTC
Created attachment 1208 [details]
sample/simple module
Comment 4 Bruce Ashfield 2013-06-17 20:11:46 UTC
Setting this back to New, since the information was updated.
Comment 5 Laurentiu Palcu 2013-07-05 10:07:22 UTC
I duplicated the problem. Looking for a solution...
Comment 6 Bruce Ashfield 2013-07-06 01:30:04 UTC
Yang Shi at Windriver (I added him to the cc of the bug) did a bit of
legwork at the options for this as well. I don't have the latest, but
he should be around next week to update the case with some options.
Comment 7 Laurentiu Palcu 2013-07-08 08:58:04 UTC
I believe the correct way to do it is to have a nativesdk kernel-scripts package. We could do a 'make scripts' at SDK install time, which would be easy, but that would imply the user has the native toolchain installed because we only provide a cross-toolchain with the SDK.
Comment 8 Yang Shi 2013-07-09 00:55:58 UTC
It could work. I talked with Bruce about two other approaches.

1. It's similar to your approach, but just reuse kernel-dev package

2. Create a task or function to install the scripts binaries, then add the task or function into populate_sdk.
Comment 9 Michel Thebeau 2013-08-20 12:56:03 UTC
Good Morning,

I've been asked to find out if this being worked on and to pick it up if not.  Please let me know, thanks.

M

PS: had to set "Documentation change" in order to add myself to CC.
Comment 10 Paul Eggleton 2014-01-17 15:44:43 UTC
*** Bug 5402 has been marked as a duplicate of this bug. ***
Comment 11 Michel Thebeau 2014-04-01 19:24:41 UTC
I never really wrapped my head our this one. I talked to Bruce since he did some work on it.  He replied: "our workaround is specific to Wind River and it would need more effort to be generalized."
Comment 12 Saul Wold 2016-08-24 15:47:38 UTC
I meant to mark this as M+ yesterday, so the High is invalid
Comment 13 Bruce Ashfield 2018-02-15 23:59:50 UTC
Funny this just updated. I wanted to add a comment to this.

I spent several hours today trying to implement this, and it currently isn't possible to do this due to technical issues.

I'm working on this in my new kernel-devsrc implementation, since it is a much cleaner representation of the kernel build, and have found the following:

 - we cannot copy the scripts from the kernel build, since they will fail QA due
   to rpath issues. We also cannot easily change the kernel build to avoid the
   rpath issues, since the tools/flags/etc are filtered by the kernel.

 - the tools as built for the actual kernel compile, are using the host compiler
   so have the wrong interpreter, or are even the wrong architecture completely for
   use on the target.

So barring the ability to copy the tools from the kernel artifacts, I was attempting to implement a build of the script as part of the kernel-devsrc packaging. That failed due to the following:

 - If we pass the target LDFLAGS, CFLAGS, etc, we can build the scripts such that
   they pass QA (rpaths are good), but they won't actually run on the target, since
   you get the host's ld.so, and that is not the right intepreter on the target, so
   you can't actually run the scripts on the target.

 - If we override HOST_CC to actually be CC (aka the target compiler) and also pass
   the target CFLAGS, LDFLAGS, etc, we can't build the tools, since 'fixdep' is 
   always built *and* run as part of the scripts building. When you build it with
   the target compiler + flags, it can't run on the host, so your scripts build
   fails.

So outside of using qemu to somehow build the scripts in the kernel-devsrc build, I'm not seeing a way to make this work. I looked into using qemu_run, but couldn't figure out an effective way to do it.

If someone knows how to do this, or has another idea. Let me know.
Comment 14 Juro Bystricky 2018-02-16 00:04:48 UTC
I'm actually testing this now. The way to do this was to build the non-native binaries with oemake HOSTCC=${CC} etc, . The cross-compiled build is rather easy, but in order to run these non-native binaries I had to create feww wrappers and run the binaries via qemu-xxx (user mode qemu). Seems to work fine, I will definitely test it thoroughly.
Comment 15 Bruce Ashfield 2018-02-16 00:16:26 UTC
(In reply to comment #14)
> I'm actually testing this now. The way to do this was to build the
> non-native binaries with oemake HOSTCC=${CC} etc, . The cross-compiled build
> is rather easy, but in order to run these non-native binaries I had to
> create feww wrappers and run the binaries via qemu-xxx (user mode qemu).
> Seems to work fine, I will definitely test it thoroughly.

Right. I was to the point of doing the qemu wrapper myself, since the HOSTCC=CC
is what I currently have implemented .. but got bogged down in the details.

This should really be done as part of the new implementation I've done for kernel-devsrc, how did you want to combine the two changes ?

Once you have something working, can you send it to me, or attach it here, so I can merge it into the new build steps and test ?
Comment 16 Juro Bystricky 2018-02-16 00:17:13 UTC
And obviously I had to patch some Makefiles to call the wrappers instead of the actual (original) non-native binaries. 
One important observation: if you install qemu native on your host via:

# apt install qemu-user

Then it simply adding
oe_runmake ARCH=${ARCH} HOSTCC="${CC} -static" HOSTLD="${LD}" HOSTAR="${AR}" scripts

into do_install is pretty much all you need to do, as the cross-compiled binaries are "automagically" handled by the host.

I ran into this when I noticed that otherwise identical setups on two different machines would not build identically: one would not build at all (the one missing the qemus), the other one had no problems. But whatever the host did with installed qemus I managed to reproduce with our oe qemu-native.
Comment 17 Juro Bystricky 2018-02-16 00:19:27 UTC
And obviously I had to patch some Makefiles to call the wrappers instead of the actual (original) non-native binaries. 
One important observation: if you install qemu native on your host via:

# apt install qemu-user

Then it simply adding
oe_runmake ARCH=${ARCH} HOSTCC="${CC} -static" HOSTLD="${LD}" HOSTAR="${AR}" scripts

into do_install is pretty much all you need to do, as the cross-compiled binaries are "automagically" handled by the host.

I ran into this when I noticed that otherwise identical setups on two different machines would not build identically: one would not build at all (the one missing the qemus), the other one had no problems. But whatever the host did with installed qemus I managed to reproduce with our oe qemu-native. 
(In reply to comment #15)
> (In reply to comment #14)
> > I'm actually testing this now. The way to do this was to build the
> > non-native binaries with oemake HOSTCC=${CC} etc, . The cross-compiled build
> > is rather easy, but in order to run these non-native binaries I had to
> > create feww wrappers and run the binaries via qemu-xxx (user mode qemu).
> > Seems to work fine, I will definitely test it thoroughly.
> 
> Right. I was to the point of doing the qemu wrapper myself, since the
> HOSTCC=CC
> is what I currently have implemented .. but got bogged down in the details.
> 
> This should really be done as part of the new implementation I've done for
> kernel-devsrc, how did you want to combine the two changes ?
> 
> Once you have something working, can you send it to me, or attach it here,
> so I can merge it into the new build steps and test ?

I'll wait for your changes to be merged first.
Comment 18 Bruce Ashfield 2018-02-16 00:20:52 UTC
Ah, but that's the problem. Unless you get those patches upstream, the approach
is dead in the water.

Even though I'd like to, this isn't something that can only work with a patched
kernel. So at a minimum, there needs to be a test and a graceful fallback when
trying to do these cross-compiled, target-native scripts.

It gets complex, and just making people run "make scripts" starts to look like the right answer again.
Comment 19 Juro Bystricky 2018-02-16 00:24:15 UTC
I'll send you my patch tomorrow, needs a cleanup, more of a POC at this point.(In reply to comment #18)
> Ah, but that's the problem. Unless you get those patches upstream, the
> approach
> is dead in the water.
> 
> Even though I'd like to, this isn't something that can only work with a
> patched
> kernel. So at a minimum, there needs to be a test and a graceful fallback
> when
> trying to do these cross-compiled, target-native scripts.
> 
> It gets complex, and just making people run "make scripts" starts to look
> like the right answer again.

No, there is no problem. I undo the patching (restore the unmodified Makefiles) after the the "make scripts". The wrappers are not distributed either.
Comment 20 Bruce Ashfield 2018-02-16 00:26:12 UTC
(In reply to comment #19)
> I'll send you my patch tomorrow, needs a cleanup, more of a POC at this
> point.(In reply to comment #18)
> > Ah, but that's the problem. Unless you get those patches upstream, the
> > approach
> > is dead in the water.
> > 
> > Even though I'd like to, this isn't something that can only work with a
> > patched
> > kernel. So at a minimum, there needs to be a test and a graceful fallback
> > when
> > trying to do these cross-compiled, target-native scripts.
> > 
> > It gets complex, and just making people run "make scripts" starts to look
> > like the right answer again.
> 
> No, there is no problem. I undo the patching (restore the unmodified
> Makefiles) after the the "make scripts". The wrappers are not distributed
> either.

That's definitely a problem, if you are somehow apply a patch during the
build to the kernel.

That's not something I ever want done to any of the kernel build workflows
that I have, and there's no guaranteed that the patching will work across
kernel versions.

How exactly are you doing this patching ?
Comment 21 Juro Bystricky 2018-02-16 18:23:23 UTC
(In reply to comment #20)
> (In reply to comment #19)
> > I'll send you my patch tomorrow, needs a cleanup, more of a POC at this
> > point.(In reply to comment #18)
> > > Ah, but that's the problem. Unless you get those patches upstream, the
> > > approach
> > > is dead in the water.
> > > 
> > > Even though I'd like to, this isn't something that can only work with a
> > > patched
> > > kernel. So at a minimum, there needs to be a test and a graceful fallback
> > > when
> > > trying to do these cross-compiled, target-native scripts.
> > > 
> > > It gets complex, and just making people run "make scripts" starts to look
> > > like the right answer again.
> > 
> > No, there is no problem. I undo the patching (restore the unmodified
> > Makefiles) after the the "make scripts". The wrappers are not distributed
> > either.
> 
> That's definitely a problem, if you are somehow apply a patch during the
> build to the kernel.
> 
> That's not something I ever want done to any of the kernel build workflows
> that I have, and there's no guaranteed that the patching will work across
> kernel versions.
> 
> How exactly are you doing this patching ?

I attached the two patches I am currently testing. The idea is to populate the kernel-devsrc with additional files that are supposed to be the same as if the user ran "make script" in native build environment. (so the user does not have to do that). Some of the files are binaries (cross-compiled) and some of the files are the artifacts created by these binaries.  Beside these additional files, the rest of the package (sources etc) remain exactly as before. No existing files should be modified.
Comment 22 Juro Bystricky 2018-02-16 18:24:37 UTC
Created attachment 4213 [details]
patches being tested.
Comment 23 Bruce Ashfield 2018-02-18 16:54:56 UTC
(In reply to comment #22)
> Created attachment 4213 [details]
> patches being tested.

The approach is on-track, and is what I was considering as well. So we are aligned with that. I'm just glad I didn't go any further with my work before realizing we were looking at the same thing.

I'm going to submit my kernel-devsrc changes early next week (Monday is a holiday here), and after that, you can easily slide these changes on top of my patch into the new package build process.

Did you want a copy of the WIP patch for the new dev-src for testing ?
Comment 24 Juro Bystricky 2018-02-19 17:29:00 UTC
(In reply to comment #23)
> (In reply to comment #22)
> > Created attachment 4213 [details]
> > patches being tested.
> 
> The approach is on-track, and is what I was considering as well. So we are
> aligned with that. I'm just glad I didn't go any further with my work before
> realizing we were looking at the same thing.
> 
> I'm going to submit my kernel-devsrc changes early next week (Monday is a
> holiday here), and after that, you can easily slide these changes on top of
> my patch into the new package build process.
> 
> Did you want a copy of the WIP patch for the new dev-src for testing ?

Good to know we are on the same page here. And yes, getting an advanced copy of your patch is a good idea, as it will enable me to test both patches together on a variety of MACHINEs. (Monday is a holiday here as well).
Comment 25 Bruce Ashfield 2018-02-21 15:47:34 UTC
Created attachment 4217 [details]
WIP kernel-devsrc patch
Comment 26 Bruce Ashfield 2018-02-21 15:47:42 UTC
Sorry for the slow update, I was derailed with another issue yesterday.

Attached is my WIP patch for the new kernel-devsrc.

I'm still working on it today, but would be interested to know that your patches work on top of the new structure.
Comment 27 Juro Bystricky 2018-02-21 17:08:32 UTC
(In reply to comment #26)
> Sorry for the slow update, I was derailed with another issue yesterday.
> 
> Attached is my WIP patch for the new kernel-devsrc.
> 
> I'm still working on it today, but would be interested to know that your
> patches work on top of the new structure.

Thanks. I know you have been very busy lately and I am actually surprised you found some extra time to work on this one. I'll keep you posted.
Comment 28 Juro Bystricky 2018-02-23 00:30:12 UTC
Created attachment 4218 [details]
WIP second iteration, combined patches, powerpc does not build.
Comment 29 Juro Bystricky 2018-02-23 00:31:26 UTC
Just to keep you posted, I attached a new patch, (combining your work with mine).
I tested it with

$ core-image-sato-sdk -ctestimage

With the following MACHINEs:

#builds + tests OK (combined patch) MACHINE = "qemuarm64"
#builds + tests OK (combined patch) MACHINE = "qemuarm"
#builds + tests OK (combined patch) MACHINE = "qemux86-64"
#builds + tests OK (combined patch) MACHINE = "qemux86"
#builds + tests OK (combined patch) MACHINE = "qemumips64"

Some problems I have to resolve yet:

MACHINE = "qemumips"
-------------------
do_rootfs:
# error building image MACHINE = "qemumips"
#Error: 
# Problem 1: conflicting requests
#  - nothing provides gdbserver needed by packagegroup-core-eclipse-debug-1.0-r0.noarch
# Problem 2: conflicting requests
#  - nothing provides gdbserver needed by packagegroup-core-tools-debug-1.0-r3.noarch

Package builds fine, though. So chances are good this will work OK. 

MACHINE="qemuppc"
---------------
Cannot build the package at all,
qemu-ppc throws an illegal instruction:

powerpc-poky-linux-gcc  -m32 -mhard-float -mcpu=7400 -mno-spe --sysroot=/data/master/poky/build-sato-testimage/tmp/work/qemuppc-poky-linux/kernel-devsrc/1.0-r0/recipe-sysroot -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wp,-MD,scripts/basic/.fixdep.d -Iscripts/basic -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89 -o scripts/basic/fixdep scripts/basic/fixdep.c
| qemu: uncaught target signal 4 (Illegal instruction) - core dumped
| Illegal instruction (core dumped)
Comment 30 Bruce Ashfield 2018-02-23 04:01:10 UTC
(In reply to comment #29)
> Just to keep you posted, I attached a new patch, (combining your work with
> mine).
> I tested it with
> 
> $ core-image-sato-sdk -ctestimage
> 
> With the following MACHINEs:
> 
> #builds + tests OK (combined patch) MACHINE = "qemuarm64"
> #builds + tests OK (combined patch) MACHINE = "qemuarm"
> #builds + tests OK (combined patch) MACHINE = "qemux86-64"
> #builds + tests OK (combined patch) MACHINE = "qemux86"
> #builds + tests OK (combined patch) MACHINE = "qemumips64"
> 
> Some problems I have to resolve yet:
> 
> MACHINE = "qemumips"
> -------------------
> do_rootfs:
> # error building image MACHINE = "qemumips"
> #Error: 
> # Problem 1: conflicting requests
> #  - nothing provides gdbserver needed by
> packagegroup-core-eclipse-debug-1.0-r0.noarch
> # Problem 2: conflicting requests
> #  - nothing provides gdbserver needed by
> packagegroup-core-tools-debug-1.0-r3.noarch
> 
> Package builds fine, though. So chances are good this will work OK. 

That's definitely good news.

I'll finish my testing and submit the patch to the mailing list on Friday.

On my side, this isn't the first time I've heard of qemuppc getting sigill and crashing.

I personally wouldn't want to hold up the work you are doing on ppc, so is it possible to do an arch test, and require the on-target "make scripts" for PPC ?

Bruce

> 
> MACHINE="qemuppc"
> ---------------
> Cannot build the package at all,
> qemu-ppc throws an illegal instruction:
> 
> powerpc-poky-linux-gcc  -m32 -mhard-float -mcpu=7400 -mno-spe
> --sysroot=/data/master/poky/build-sato-testimage/tmp/work/qemuppc-poky-linux/
> kernel-devsrc/1.0-r0/recipe-sysroot -Wl,-O1 -Wl,--hash-style=gnu
> -Wl,--as-needed -Wp,-MD,scripts/basic/.fixdep.d -Iscripts/basic -Wall
> -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89
> -o scripts/basic/fixdep scripts/basic/fixdep.c
> | qemu: uncaught target signal 4 (Illegal instruction) - core dumped
> | Illegal instruction (core dumped)
Comment 31 Juro Bystricky 2018-02-23 16:45:57 UTC
(In reply to comment #30)
> (In reply to comment #29)
> > Just to keep you posted, I attached a new patch, (combining your work with
> > mine).
> > I tested it with
> > 
> > $ core-image-sato-sdk -ctestimage
> > 

> On my side, this isn't the first time I've heard of qemuppc getting sigill
> and crashing.
> 
> I personally wouldn't want to hold up the work you are doing on ppc, so is
> it possible to do an arch test, and require the on-target "make scripts" for
> PPC ?
> 

I actually managed to build the package for powerpc as well meanwhile.
I had to create the images with static linking though (passing -static to CC). So the binaries a bit bigger as a consequence. I'll try to investigate a bit deeper later on.
Comment 32 Richard Purdie 2018-10-11 15:04:47 UTC
*** Bug 6630 has been marked as a duplicate of this bug. ***
Comment 33 Bruce Ashfield 2021-06-24 16:05:44 UTC
This is still valid, and should stay around to document that we are aware of how this works (and for someone else to pick up the work in progress parts .. if that ever happens). It just isn't high priority.
Comment 34 Randy MacLeod 2023-10-24 14:24:48 UTC
Bulk move from 4.99 or 0.00 to 5.99
Comment 35 Tim Orling 2026-06-25 15:36:38 UTC
There was some recent discussion on IRC related to this topic and some discussion during bug triage meeting.