@@ -14,6 +14,9 @@ generate_headers()
14
14
zcat /proc/config.gz > .config
15
15
make ARCH=x86 oldconfig > /dev/null
16
16
make ARCH=x86 prepare > /dev/null
17
+
18
+ # Clean up abundant non-header files to speed-up copying
19
+ find ${BUILD_DIR} -regex ' .*\.c\|.*\.txt\|.*Makefile\|.*Build\|.*Kconfig' -type f -delete
17
20
}
18
21
19
22
fetch_cos_linux_sources ()
@@ -23,6 +26,16 @@ fetch_cos_linux_sources()
23
26
curl -s " https://storage.googleapis.com/cos-tools/${BUILD_ID} /kernel-src.tar.gz" | tar -xzf - -C ${BUILD_DIR}
24
27
}
25
28
29
+ fetch_generic_linux_sources ()
30
+ {
31
+ kernel_version=$( uname -r | tr -d ' +' )
32
+ major_version=$( echo ${kernel_version} | cut -d . -f 1)
33
+ echo " Fetching upstream kernel sources for ${kernel_version} ."
34
+ mkdir -p ${BUILD_DIR}
35
+ curl -sL https://www.kernel.org/pub/linux/kernel/v${major_version} .x/linux-$kernel_version .tar.gz | tar --strip-components=1 -xzf - -C ${BUILD_DIR}
36
+
37
+ }
38
+
26
39
install_cos_linux_headers ()
27
40
{
28
41
if grep -q CHROMEOS_RELEASE_VERSION ${LSB_FILE} ; then
@@ -31,15 +44,29 @@ install_cos_linux_headers()
31
44
SOURCES_DIR=" ${TARGET_DIR} /linux-lakitu-${BUILD_ID} "
32
45
33
46
if [ ! -e " ${SOURCES_DIR} /.installed" ]; then
34
- echo " Installing kernel headers for for COS build ${BUILD_ID} "
35
- fetch_cos_linux_sources
36
- generate_headers
37
- mv ${BUILD_DIR} ${TARGET_DIR}
47
+ echo " Installing kernel headers for COS build ${BUILD_ID} "
48
+ time fetch_cos_linux_sources
49
+ time generate_headers
50
+ time mv ${BUILD_DIR} ${TARGET_DIR}
38
51
touch " ${SOURCES_DIR} /.installed"
39
52
fi
40
53
fi
41
54
}
42
55
56
+ install_generic_linux_headers ()
57
+ {
58
+ BUILD_DIR=" /linux-generic-$( uname -r) "
59
+ SOURCES_DIR=" ${TARGET_DIR} /linux-generic-$( uname -r) "
60
+
61
+ if [ ! -e " ${SOURCES_DIR} /.installed" ]; then
62
+ echo " Installing kernel headers for generic kernel"
63
+ time fetch_generic_linux_sources
64
+ time generate_headers
65
+ time mv ${BUILD_DIR} ${TARGET_DIR}
66
+ touch " ${SOURCES_DIR} /.installed"
67
+ fi
68
+ }
69
+
43
70
install_headers ()
44
71
{
45
72
distro=$( grep ^NAME ${OS_RELEASE_FILE} | cut -d = -f 2)
@@ -50,7 +77,10 @@ install_headers()
50
77
HEADERS_TARGET=${SOURCES_DIR}
51
78
;;
52
79
* )
53
- echo " WARNING: ${distro} is not a supported distro, cannot install headers, ensure they are installed to /lib/modules"
80
+ echo " WARNING: Cannot find distro-specific headers for ${distro} . Fetching generic headers."
81
+ install_generic_linux_headers
82
+ HEADERS_TARGET=${SOURCES_DIR}
83
+ ;;
54
84
esac
55
85
}
56
86
0 commit comments