2019-04-11 22:38:25 +02:00
|
|
|
# Bionic Kernel Header Files
|
2016-07-09 00:25:21 +02:00
|
|
|
|
2014-06-05 20:17:06 +02:00
|
|
|
Bionic comes with a processed set of all of the uapi Linux kernel headers that
|
|
|
|
can safely be included by userland applications and libraries.
|
|
|
|
|
|
|
|
These clean headers are automatically generated by several scripts located
|
2019-04-11 22:38:25 +02:00
|
|
|
in the `tools/` directory. The tools process the original
|
2014-06-05 20:17:06 +02:00
|
|
|
unmodified kernel headers in order to get rid of many annoying
|
2009-03-04 04:28:35 +01:00
|
|
|
declarations and constructs that usually result in compilation failure.
|
|
|
|
|
2014-06-05 20:17:06 +02:00
|
|
|
The 'clean headers' only contain type and macro definitions, with the
|
2009-03-04 04:28:35 +01:00
|
|
|
exception of a couple static inline functions used for performance
|
2014-06-05 20:17:06 +02:00
|
|
|
reason (e.g. optimized CPU-specific byte-swapping routines).
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2014-06-05 20:17:06 +02:00
|
|
|
They can be included from C++, or when compiling code in strict ANSI mode.
|
|
|
|
They can be also included before or after any Bionic C library header.
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2014-06-05 20:17:06 +02:00
|
|
|
Description of the directories involved in generating the parsed kernel headers:
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2021-03-18 08:38:34 +01:00
|
|
|
* `external/kernel-headers/original/uapi/`
|
|
|
|
Contains the uapi kernel headers found in the Android kernel. Note this
|
2014-06-05 20:17:06 +02:00
|
|
|
also includes the header files that are generated by building the kernel
|
|
|
|
sources.
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2021-03-18 08:38:34 +01:00
|
|
|
* `external/kernel-headers/original/scsi/`
|
|
|
|
Contains copies of the kernel scsi header files. These where never
|
|
|
|
made into uapi files, but some user space code expects that these
|
|
|
|
headers are available.
|
|
|
|
|
|
|
|
* `external/kernel-headers/modified/scsi/`
|
|
|
|
Contains hand-modified versions of a few files from `original/scsi/`
|
|
|
|
that removes the kernel specific code from these files so they can
|
|
|
|
be used as uapi headers. The tools to process the kernel headers will
|
|
|
|
warn if any scsi header files have changed and require new versions
|
|
|
|
to be hand-modified.
|
|
|
|
|
2019-04-11 22:38:25 +02:00
|
|
|
* `bionic/libc/kernel/uapi/`
|
2014-06-05 20:17:06 +02:00
|
|
|
Contains the cleaned kernel headers and mirrors the directory structure
|
2019-04-11 22:38:25 +02:00
|
|
|
in `external/kernel-headers/original/uapi/`.
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2019-04-11 22:38:25 +02:00
|
|
|
* `bionic/libc/kernel/tools/`
|
2014-06-05 20:17:06 +02:00
|
|
|
Contains various Python and shell scripts used to get and re-generate
|
|
|
|
the headers.
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2014-06-05 20:17:06 +02:00
|
|
|
The tools to get/parse the headers:
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2019-04-11 22:38:25 +02:00
|
|
|
* `tools/generate_uapi_headers.sh`
|
2021-03-18 08:38:34 +01:00
|
|
|
Checks out the Android kernel and generates all uapi header files.
|
2014-06-05 20:17:06 +02:00
|
|
|
copies all the changed files into external/kernel-headers.
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2019-04-11 22:38:25 +02:00
|
|
|
* `tools/clean_header.py`
|
2014-06-05 20:17:06 +02:00
|
|
|
Prints the clean version of a given kernel header. With the -u option,
|
2009-03-04 04:28:35 +01:00
|
|
|
this will also update the corresponding clean header file if its
|
2014-06-05 20:17:06 +02:00
|
|
|
content has changed. You can also process more than one file with -u.
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2019-04-11 22:38:25 +02:00
|
|
|
* `tools/update_all.py`
|
2014-06-05 20:17:06 +02:00
|
|
|
Automatically update all clean headers from the content of
|
2019-04-11 22:38:25 +02:00
|
|
|
`external/kernel-headers/original/`.
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2019-04-11 22:38:25 +02:00
|
|
|
## How To Update The Headers
|
2009-03-04 04:28:35 +01:00
|
|
|
|
|
|
|
IMPORTANT IMPORTANT:
|
|
|
|
|
2016-07-09 00:25:21 +02:00
|
|
|
WHEN UPDATING THE HEADERS, ALWAYS CHECK THAT THE NEW CLEAN HEADERS DO
|
|
|
|
NOT BREAK THE KERNEL <-> USER ABI, FOR EXAMPLE BY CHANGING THE SIZE
|
|
|
|
OF A GIVEN TYPE. THIS TASK CANNOT BE EASILY AUTOMATED AT THE MOMENT.
|
|
|
|
|
2019-12-14 02:17:10 +01:00
|
|
|
Download the Android mainline kernel source code:
|
2019-04-11 22:38:25 +02:00
|
|
|
```
|
2016-07-09 00:25:21 +02:00
|
|
|
> mkdir kernel_src
|
|
|
|
> cd kernel_src
|
2019-12-14 02:17:10 +01:00
|
|
|
kernel_src> git clone https://android.googlesource.com/kernel/common/ -b android-mainline
|
2019-04-11 22:38:25 +02:00
|
|
|
```
|
2016-07-09 00:25:21 +02:00
|
|
|
|
2021-03-18 08:38:34 +01:00
|
|
|
The Android mainline kernel source has tags that indicate the kernel
|
|
|
|
version to which they correspond. The format of a tag is
|
|
|
|
android-mainline-XXX, where XXX is the kernel version. For example,
|
|
|
|
android-mainline-5.10 corresponds to linux stable kernel 5.10. To check out
|
|
|
|
a particular tag:
|
2019-04-11 22:38:25 +02:00
|
|
|
```
|
2021-03-18 08:38:34 +01:00
|
|
|
kernel_src> cd common
|
|
|
|
kernel_src/common> git checkout tags/android-mainline-XXX
|
2019-04-11 22:38:25 +02:00
|
|
|
```
|
2016-07-09 00:25:21 +02:00
|
|
|
|
2021-03-18 08:38:34 +01:00
|
|
|
It is expected that a kernel update should only be performed on a valid tag.
|
|
|
|
For testing purposes, it is possible that you can use the top of tree
|
|
|
|
version, but never use that as the basis for importing new kernel headers.
|
|
|
|
|
2016-07-09 00:25:21 +02:00
|
|
|
Before running the command to import the headers, make sure that you have
|
|
|
|
done a lunch TARGET. The script uses a variable set by the lunch command
|
|
|
|
to determine which directory to use as the destination directory.
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2021-03-18 08:38:34 +01:00
|
|
|
After running lunch, run this command to import the headers into the Android
|
2019-12-14 02:17:10 +01:00
|
|
|
source tree if there is a kernel source tree already checked out:
|
2019-04-11 22:38:25 +02:00
|
|
|
```
|
2016-07-09 00:25:21 +02:00
|
|
|
bionic/libc/kernel/tools/generate_uapi_headers.sh --use-kernel-dir kernel_src
|
2019-04-11 22:38:25 +02:00
|
|
|
```
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2019-12-14 02:17:10 +01:00
|
|
|
Run this command to automatically download the latest version of the headers
|
|
|
|
and import them if there is no checked out kernel source tree:
|
|
|
|
```
|
2022-10-01 17:27:10 +02:00
|
|
|
# For testing only, not for use in production!
|
2019-12-14 02:17:10 +01:00
|
|
|
bionic/libc/kernel/tools/generate_uapi_headers.sh --download-kernel
|
|
|
|
```
|
|
|
|
|
2014-06-05 20:17:06 +02:00
|
|
|
Next, run this command to copy the parsed files to bionic/libc/kernel/uapi:
|
2019-04-11 22:38:25 +02:00
|
|
|
```
|
2014-07-16 04:02:33 +02:00
|
|
|
bionic/libc/kernel/tools/update_all.py
|
2019-04-11 22:38:25 +02:00
|
|
|
```
|
2014-07-16 04:02:33 +02:00
|
|
|
|
2014-06-05 20:17:06 +02:00
|
|
|
After this, you will need to build/test the tree to make sure that these
|
|
|
|
changes do not introduce any errors.
|