aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/gen_kheaders.sh
diff options
context:
space:
mode:
authorJoel Fernandes (Google) <joel@joelfernandes.org>2019-05-15 17:35:51 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-05-24 14:16:01 -0400
commitf7b101d33046a837c2aa4526cef28a3c785d7af2 (patch)
tree50756746345f4a6ba56994e823d5f60681eb662d /kernel/gen_kheaders.sh
parenta188339ca5a396acc588e5851ed7e19f66b0ebd9 (diff)
kheaders: Move from proc to sysfs
The kheaders archive consisting of the kernel headers used for compiling bpf programs is in /proc. However there is concern that moving it here will make it permanent. Let us move it to /sys/kernel as discussed [1]. [1] https://lore.kernel.org/patchwork/patch/1067310/#1265969 Suggested-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'kernel/gen_kheaders.sh')
-rwxr-xr-xkernel/gen_kheaders.sh89
1 files changed, 89 insertions, 0 deletions
diff --git a/kernel/gen_kheaders.sh b/kernel/gen_kheaders.sh
new file mode 100755
index 000000000000..581b83534587
--- /dev/null
+++ b/kernel/gen_kheaders.sh
@@ -0,0 +1,89 @@
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# This script generates an archive consisting of kernel headers
5# for CONFIG_IKHEADERS.
6set -e
7spath="$(dirname "$(readlink -f "$0")")"
8kroot="$spath/.."
9outdir="$(pwd)"
10tarfile=$1
11cpio_dir=$outdir/$tarfile.tmp
12
13# Script filename relative to the kernel source root
14# We add it to the archive because it is small and any changes
15# to this script will also cause a rebuild of the archive.
16sfile="$(realpath --relative-to $kroot "$(readlink -f "$0")")"
17
18src_file_list="
19include/
20arch/$SRCARCH/include/
21$sfile
22"
23
24obj_file_list="
25include/
26arch/$SRCARCH/include/
27"
28
29# Support incremental builds by skipping archive generation
30# if timestamps of files being archived are not changed.
31
32# This block is useful for debugging the incremental builds.
33# Uncomment it for debugging.
34# iter=1
35# if [ ! -f /tmp/iter ]; then echo 1 > /tmp/iter;
36# else; iter=$(($(cat /tmp/iter) + 1)); fi
37# find $src_file_list -type f | xargs ls -lR > /tmp/src-ls-$iter
38# find $obj_file_list -type f | xargs ls -lR > /tmp/obj-ls-$iter
39
40# include/generated/compile.h is ignored because it is touched even when none
41# of the source files changed. This causes pointless regeneration, so let us
42# ignore them for md5 calculation.
43pushd $kroot > /dev/null
44src_files_md5="$(find $src_file_list -type f |
45 grep -v "include/generated/compile.h" |
46 xargs ls -lR | md5sum | cut -d ' ' -f1)"
47popd > /dev/null
48obj_files_md5="$(find $obj_file_list -type f |
49 grep -v "include/generated/compile.h" |
50 xargs ls -lR | md5sum | cut -d ' ' -f1)"
51
52if [ -f $tarfile ]; then tarfile_md5="$(md5sum $tarfile | cut -d ' ' -f1)"; fi
53if [ -f kernel/kheaders.md5 ] &&
54 [ "$(cat kernel/kheaders.md5|head -1)" == "$src_files_md5" ] &&
55 [ "$(cat kernel/kheaders.md5|head -2|tail -1)" == "$obj_files_md5" ] &&
56 [ "$(cat kernel/kheaders.md5|tail -1)" == "$tarfile_md5" ]; then
57 exit
58fi
59
60if [ "${quiet}" != "silent_" ]; then
61 echo " GEN $tarfile"
62fi
63
64rm -rf $cpio_dir
65mkdir $cpio_dir
66
67pushd $kroot > /dev/null
68for f in $src_file_list;
69 do find "$f" ! -name "*.cmd" ! -name ".*";
70done | cpio --quiet -pd $cpio_dir
71popd > /dev/null
72
73# The second CPIO can complain if files already exist which can
74# happen with out of tree builds. Just silence CPIO for now.
75for f in $obj_file_list;
76 do find "$f" ! -name "*.cmd" ! -name ".*";
77done | cpio --quiet -pd $cpio_dir >/dev/null 2>&1
78
79# Remove comments except SDPX lines
80find $cpio_dir -type f -print0 |
81 xargs -0 -P8 -n1 perl -pi -e 'BEGIN {undef $/;}; s/\/\*((?!SPDX).)*?\*\///smg;'
82
83tar -Jcf $tarfile -C $cpio_dir/ . > /dev/null
84
85echo "$src_files_md5" > kernel/kheaders.md5
86echo "$obj_files_md5" >> kernel/kheaders.md5
87echo "$(md5sum $tarfile | cut -d ' ' -f1)" >> kernel/kheaders.md5
88
89rm -rf $cpio_dir