Bug 5305 - Make sanitized kernel headers available
Summary: Make sanitized kernel headers available
Status: IN PROGRESS REVIEW
Alias: None
Product: OE-Core
Classification: Build System, Metadata & Runtime
Component: kernel (show other bugs)
Version: unspecified
Hardware: All Multiple
: Medium enhancement
Target Milestone: 6.99
Assignee: Bruce Ashfield
QA Contact:
URL:
Whiteboard:
: 4119 7866 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-10-03 08:40 UTC by Peter Kjellerstedt
Modified: 2026-02-26 16:00 UTC (History)
11 users (show)

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


Attachments
bbclass to make sanitized kernel headers available for a recipe (258 bytes, application/octet-stream)
2013-10-03 08:40 UTC, Peter Kjellerstedt
no flags Details
dual mode headers patch (4.83 KB, application/octet-stream)
2020-03-05 20:01 UTC, Bruce Ashfield
no flags Details
updated bbclass for new overrides (5.05 KB, application/octet-stream)
2021-08-25 16:46 UTC, Bruce Ashfield
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Kjellerstedt 2013-10-03 08:40:21 UTC
Created attachment 1542 [details]
bbclass to make sanitized kernel headers available for a recipe

In a recent commit (http://cgit.openembedded.org/openembedded-core/commit/?id=c27ac156bcaf3193d52f456480947b0cfaef3c72), Richard added a big warning about not forking the linux-libc-headers recipe to get at specific kernel headers for user space. As a consequence I thought I should remove our fork of linux-libc-headers and instead use the suggested method of including the needed files from ${STAGING_KERNEL_DIR} in the recipes that need them.

However, I soon realized that what I need are the sanitized headers that are generated by running "make headers_install" in the kernel sources. So what I then did was to create a simple bbclass that generates them for me and makes them available for my recipe (see attachment). After that I could simply do 'inherit kernel-headers' and 'CFLAGS += "-I${KINCLUDES}/includes"' in my recipe to get at the sanitized kernel headers.

But, it seems somewhat wasteful for each recipe that need those headers to do that. It would be better if the sanitized headers were provided once for all to use (similar to ${STAGING_KERNEL_DIR} for the kernel sources).

When I asked about this on the OE mailing list, Bruce Ashfield replied:

I've proposed similar solutions in the past, including installing the headers into the sysroot along side of the libc-headers in "usr-alt/", or "kernel-headers/", rather than within the kernel staging dir, since the staging dir is often tar'd up and added to things like the kernel-dev package or SDKs .. and if not properly installed, you can clash with the libc usr/include/linux headers.

But yes, either way, I'm all for doing this once, making them available in a oe-core "standard" location, as long as it isn't picked up by default include paths.

If you want to open up something in the bugzilla, we can take care of this early in the yocto 1.6 cycle, since at this point in 1.5, we don't want to jiggle much of anything :)
Comment 1 Bruce Ashfield 2013-10-03 12:46:49 UTC
I'll grab this one. Thanks for the report.
Comment 2 Bruce Ashfield 2014-03-31 16:34:18 UTC
Moving this to 1.7, since it better matches the developer experience theme. In flight patches will be
rebased and submitted then.
Comment 3 Bruce Ashfield 2014-03-31 18:04:04 UTC
*** Bug 4119 has been marked as a duplicate of this bug. ***
Comment 4 Leon Woestenberg 2015-06-23 12:20:35 UTC
*** Bug 7866 has been marked as a duplicate of this bug. ***
Comment 5 Bruce Ashfield 2020-03-04 18:53:37 UTC
working on cleaning this up, to have two modes .. one that does something like the attached bbclass, and another that packages the alternate headers (so it can be reused).
Comment 6 Bruce Ashfield 2020-03-05 20:01:13 UTC
Created attachment 4647 [details]
dual mode headers patch
Comment 7 Peter Kjellerstedt 2020-03-07 13:01:20 UTC
(In reply to comment #6)
> Created attachment 4647 [details]
> dual mode headers patch

Two comments about the patch:

* You should use "${KERNEL_PACKAGE_NAME}-headers-alt" instead of "kernel-headers-alt" as package name.
* Some lines in the shell functions use a mix of spaces and tabs for indentation rather than all tabs.
Comment 8 Bruce Ashfield 2020-03-07 16:41:45 UTC
(In reply to comment #7)
> (In reply to comment #6)
> > Created attachment 4647 [details]
> > dual mode headers patch
> 
> Two comments about the patch:
> 
> * You should use "${KERNEL_PACKAGE_NAME}-headers-alt" instead of
> "kernel-headers-alt" as package name.

Actually, I named it this way on purpose. It isn't actually supposed to be used, it is a placeholder against QA errors. But yes, there's no harm in following whatever naming is in a given kernel recipe.

> * Some lines in the shell functions use a mix of spaces and tabs for
> indentation rather than all tabs.

Noted. This isn't the final version, just a placeholder.

This isn't being sent out until post release and will have more revision before then. People were asking about this, so I wanted to put the WIP someplace they could find.
Comment 9 Bruce Ashfield 2020-03-07 16:55:13 UTC
(In reply to comment #8)
> (In reply to comment #7)
> > (In reply to comment #6)
> > > Created attachment 4647 [details]
> > > dual mode headers patch
> > 
> > Two comments about the patch:
> > 
> > * You should use "${KERNEL_PACKAGE_NAME}-headers-alt" instead of
> > "kernel-headers-alt" as package name.
> 
> Actually, I named it this way on purpose. It isn't actually supposed to be
> used, it is a placeholder against QA errors. But yes, there's no harm in
> following whatever naming is in a given kernel recipe.
> 
> > * Some lines in the shell functions use a mix of spaces and tabs for
> > indentation rather than all tabs.
> 
> Noted. This isn't the final version, just a placeholder.
> 
> This isn't being sent out until post release and will have more revision
> before then. People were asking about this, so I wanted to put the WIP
> someplace they could find.

I've run tabify on the functions, they are all consistent now!
Comment 10 Karthik Poduval 2021-02-24 01:21:46 UTC
I tried the mode 1 approach with the patch (0001-kernel-provide-alternate-headers-for-package-specifi.patch) applied to my bsp layer (I am using yocto version 3.1 and yoe distro). The target application was able to find the exported kernel headers. However I see one side effect that kernel menuconfig command can't run anymore.

bitbake virtual/kernel -c menuconfig
***
*** The source tree is not clean, please run 'make mrproper'
*** in /home/workspace/yoe-dmabuf/build/tmp/work-shared/qemuarm64/kernel-source
***
make[1]: *** [outputmakefile] Error 1
make: *** [sub-make] Error 2
Command failed.
Press any key to continue...

Is this because make headers_install was run from KERNEL_STAGING_DIRECTORY ?
It works after doing a cleanall on virtual/kernel first.
Comment 11 Karthik Poduval 2021-02-24 02:03:17 UTC
A small change to the patch helps mitigate the side effect.
do_compile_prepend() {
        if [ "${KERNEL_SOURCE_IS_LOCAL}" = "False" ]; then
            # install from the staging kernel directory
            oe_runmake -C ${STAGING_KERNEL_DIR} headers_install INSTALL_HDR_PATH=${WORKDIR}/${KERNEL_ALT_HEADER_DIR}
            oe_runmake -C ${STAGING_KERNEL_DIR} mrproper
        fi
}
Comment 12 Karthik Poduval 2021-02-24 06:44:10 UTC
mode 2 worked fine.
Comment 13 Bruce Ashfield 2021-08-25 16:46:54 UTC
Created attachment 4825 [details]
updated bbclass for new overrides

this is the same bbclass that I've attached before, with the last comment change integrated and update to the new override syntax.
Comment 14 Randy MacLeod 2024-10-17 19:04:14 UTC
Bulk move of medium importance bugs from 5.1 to 5.2 on behalf of Bruce.