platform_bionic/libc/kernel
Christopher Ferris 430527b4cd Update the generate script.
The arm kvm.h file has been deprecated, so nobody should be including it.
Therefore, remove the hack to copy the file out of the tools directory.

Also, update to remove the arm kvm.h file.

Test: Ran generate and update script and verified only the arm kvm.h
Test: was deleted.
Test: Builds and boots on a walleye.
Change-Id: I95dcc8877bdb2da2858b0b9d0aa95d1d2072cf9a
2020-06-04 12:32:09 -07:00
..
android Update to android-mainline kernel headers v5.4. 2019-12-12 14:59:25 -08:00
tools Update the generate script. 2020-06-04 12:32:09 -07:00
uapi Update the generate script. 2020-06-04 12:32:09 -07:00
.clang-format Fully disable clang format where needed. 2020-01-30 08:10:17 -08:00
README.md Update documentation around kernel header imports. 2019-12-13 17:20:20 -08:00

Bionic Kernel Header Files

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 in the tools/ directory. The tools process the original unmodified kernel headers in order to get rid of many annoying declarations and constructs that usually result in compilation failure.

The 'clean headers' only contain type and macro definitions, with the exception of a couple static inline functions used for performance reason (e.g. optimized CPU-specific byte-swapping routines).

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.

Description of the directories involved in generating the parsed kernel headers:

  • external/kernel-headers/original/ Contains the uapi kernel headers found in the android kernel. Note this also includes the header files that are generated by building the kernel sources.

  • bionic/libc/kernel/uapi/ Contains the cleaned kernel headers and mirrors the directory structure in external/kernel-headers/original/uapi/.

  • bionic/libc/kernel/tools/ Contains various Python and shell scripts used to get and re-generate the headers.

The tools to get/parse the headers:

  • tools/generate_uapi_headers.sh Checks out the android kernel and generates all uapi header files. copies all the changed files into external/kernel-headers.

  • tools/clean_header.py Prints the clean version of a given kernel header. With the -u option, this will also update the corresponding clean header file if its content has changed. You can also process more than one file with -u.

  • tools/update_all.py Automatically update all clean headers from the content of external/kernel-headers/original/.

How To Update The Headers

IMPORTANT IMPORTANT:

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.

Download the Android mainline kernel source code:

  > mkdir kernel_src
  > cd kernel_src
  kernel_src> git clone https://android.googlesource.com/kernel/common/ -b android-mainline

For now, there are no tags, take the top of tree version. To find the version of the linux stable kernel headers the mainline source code is tracking, read the uapi/linux/version.h that is generated.

  kernel_src> cd linux-stable
  kernel_src/linux-stable> git checkout tags/vXXX

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.

After running lunch, run this command to import the headers into the android source tree if there is a kernel source tree already checked out:

  bionic/libc/kernel/tools/generate_uapi_headers.sh --use-kernel-dir kernel_src

Run this command to automatically download the latest version of the headers and import them if there is no checked out kernel source tree:

  bionic/libc/kernel/tools/generate_uapi_headers.sh --download-kernel

Next, run this command to copy the parsed files to bionic/libc/kernel/uapi:

  bionic/libc/kernel/tools/update_all.py

After this, you will need to build/test the tree to make sure that these changes do not introduce any errors.