1# Bionic Kernel Header Files 2 3Bionic comes with a processed set of all of the uapi Linux kernel headers that 4can safely be included by userland applications and libraries. 5 6These clean headers are automatically generated by several scripts located 7in the `tools/` directory. The tools process the original 8unmodified kernel headers in order to get rid of many annoying 9declarations and constructs that usually result in compilation failure. 10 11The 'clean headers' only contain type and macro definitions, with the 12exception of a couple static inline functions used for performance 13reason (e.g. optimized CPU-specific byte-swapping routines). 14 15They can be included from C++, or when compiling code in strict ANSI mode. 16They can be also included before or after any Bionic C library header. 17 18Description of the directories involved in generating the parsed kernel headers: 19 20 * `external/kernel-headers/original/` 21 Contains the uapi kernel headers found in the android kernel. Note this 22 also includes the header files that are generated by building the kernel 23 sources. 24 25 * `bionic/libc/kernel/uapi/` 26 Contains the cleaned kernel headers and mirrors the directory structure 27 in `external/kernel-headers/original/uapi/`. 28 29 * `bionic/libc/kernel/tools/` 30 Contains various Python and shell scripts used to get and re-generate 31 the headers. 32 33The tools to get/parse the headers: 34 35 * `tools/generate_uapi_headers.sh` 36 Checks out the android kernel and generates all uapi header files. 37 copies all the changed files into external/kernel-headers. 38 39 * `tools/clean_header.py` 40 Prints the clean version of a given kernel header. With the -u option, 41 this will also update the corresponding clean header file if its 42 content has changed. You can also process more than one file with -u. 43 44 * `tools/update_all.py` 45 Automatically update all clean headers from the content of 46 `external/kernel-headers/original/`. 47 48## How To Update The Headers 49 50IMPORTANT IMPORTANT: 51 52WHEN UPDATING THE HEADERS, ALWAYS CHECK THAT THE NEW CLEAN HEADERS DO 53NOT BREAK THE KERNEL <-> USER ABI, FOR EXAMPLE BY CHANGING THE SIZE 54OF A GIVEN TYPE. THIS TASK CANNOT BE EASILY AUTOMATED AT THE MOMENT. 55 56Download the Android mainline kernel source code: 57``` 58 > mkdir kernel_src 59 > cd kernel_src 60 kernel_src> git clone https://android.googlesource.com/kernel/common/ -b android-mainline 61``` 62 63For now, there are no tags, take the top of tree version. To find the 64version of the linux stable kernel headers the mainline source code is 65tracking, read the uapi/linux/version.h that is generated. 66``` 67 kernel_src> cd linux-stable 68 kernel_src/linux-stable> git checkout tags/vXXX 69``` 70 71Before running the command to import the headers, make sure that you have 72done a lunch TARGET. The script uses a variable set by the lunch command 73to determine which directory to use as the destination directory. 74 75After running lunch, run this command to import the headers into the android 76source tree if there is a kernel source tree already checked out: 77``` 78 bionic/libc/kernel/tools/generate_uapi_headers.sh --use-kernel-dir kernel_src 79``` 80 81Run this command to automatically download the latest version of the headers 82and import them if there is no checked out kernel source tree: 83``` 84 bionic/libc/kernel/tools/generate_uapi_headers.sh --download-kernel 85``` 86 87Next, run this command to copy the parsed files to bionic/libc/kernel/uapi: 88``` 89 bionic/libc/kernel/tools/update_all.py 90``` 91 92After this, you will need to build/test the tree to make sure that these 93changes do not introduce any errors. 94