blob: 313dc0d0b1e17bf83437fd85da15a5b5478b9019 [file] [log] [blame]
Christopher Ferris2974eec2016-07-08 15:25:21 -07001Bionic Kernel Header Files
2==========================
3
Christopher Ferris08b60742014-06-05 11:17:06 -07004Bionic comes with a processed set of all of the uapi Linux kernel headers that
5can safely be included by userland applications and libraries.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08006
Christopher Ferris08b60742014-06-05 11:17:06 -07007These clean headers are automatically generated by several scripts located
8in the 'bionic/kernel/tools' directory. The tools process the original
9unmodified kernel headers in order to get rid of many annoying
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080010declarations and constructs that usually result in compilation failure.
11
Christopher Ferris08b60742014-06-05 11:17:06 -070012The 'clean headers' only contain type and macro definitions, with the
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080013exception of a couple static inline functions used for performance
Christopher Ferris08b60742014-06-05 11:17:06 -070014reason (e.g. optimized CPU-specific byte-swapping routines).
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080015
Christopher Ferris08b60742014-06-05 11:17:06 -070016They can be included from C++, or when compiling code in strict ANSI mode.
17They can be also included before or after any Bionic C library header.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080018
Christopher Ferris08b60742014-06-05 11:17:06 -070019Description of the directories involved in generating the parsed kernel headers:
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080020
Andrew Hsieh126601d2012-03-23 23:07:36 +080021 * 'external/kernel-headers/original/'
Christopher Ferris08b60742014-06-05 11:17:06 -070022 Contains the uapi kernel headers found in the android kernel. Note this
23 also includes the header files that are generated by building the kernel
24 sources.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080025
Christopher Ferris08b60742014-06-05 11:17:06 -070026 * 'bionic/libc/kernel/uapi'
27 Contains the cleaned kernel headers and mirrors the directory structure
28 in 'external/kernel-headers/original/uapi/'.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080029
Christopher Ferris08b60742014-06-05 11:17:06 -070030 * 'bionic/libc/kernel/tools'
31 Contains various Python and shell scripts used to get and re-generate
32 the headers.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080033
Christopher Ferris08b60742014-06-05 11:17:06 -070034The tools to get/parse the headers:
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080035
Christopher Ferris08b60742014-06-05 11:17:06 -070036 * tools/generate_uapi_headers.sh
37 Checks out the android kernel and generates all uapi header files.
38 copies all the changed files into external/kernel-headers.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080039
40 * tools/clean_header.py
Christopher Ferris08b60742014-06-05 11:17:06 -070041 Prints the clean version of a given kernel header. With the -u option,
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080042 this will also update the corresponding clean header file if its
Christopher Ferris08b60742014-06-05 11:17:06 -070043 content has changed. You can also process more than one file with -u.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080044
45 * tools/update_all.py
Christopher Ferris08b60742014-06-05 11:17:06 -070046 Automatically update all clean headers from the content of
47 'external/kernel-headers/original'.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080048
Christopher Ferris2974eec2016-07-08 15:25:21 -070049How To Update The Headers
50=========================
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080051
52IMPORTANT IMPORTANT:
53
Christopher Ferris2974eec2016-07-08 15:25:21 -070054WHEN UPDATING THE HEADERS, ALWAYS CHECK THAT THE NEW CLEAN HEADERS DO
55NOT BREAK THE KERNEL <-> USER ABI, FOR EXAMPLE BY CHANGING THE SIZE
56OF A GIVEN TYPE. THIS TASK CANNOT BE EASILY AUTOMATED AT THE MOMENT.
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080057
Christopher Ferris2974eec2016-07-08 15:25:21 -070058Download the Linux kernel source code:
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080059
Christopher Ferris2974eec2016-07-08 15:25:21 -070060 > mkdir kernel_src
61 > cd kernel_src
62 kernel_src> git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
63
64Then checkout the stable tag for the new kernel headers to import:
65
66 kernel_src> cd linux-stable
67 kernel_src/linux-stable> git checkout tags/vXXX
68
69Before running the command to import the headers, make sure that you have
70done a lunch TARGET. The script uses a variable set by the lunch command
71to determine which directory to use as the destination directory.
72
73After running lunch, run this command to import the headers into the android
74source tree:
75
76 bionic/libc/kernel/tools/generate_uapi_headers.sh --use-kernel-dir kernel_src
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080077
Christopher Ferris08b60742014-06-05 11:17:06 -070078Next, run this command to copy the parsed files to bionic/libc/kernel/uapi:
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080079
Christopher Ferrisea271fd2014-07-15 19:02:33 -070080 bionic/libc/kernel/tools/update_all.py
81
82Finally, run this command to regenerate the syscalls list:
83
84 bionic/libc/tools/gensyscalls.py
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080085
Christopher Ferris08b60742014-06-05 11:17:06 -070086After this, you will need to build/test the tree to make sure that these
87changes do not introduce any errors.