3 # update_kernel.sh: (c) 2017 Jonas Gorski <jonas.gorski@gmail.com>
4 # Licensed under the terms of the GNU GPL License version 2
15 while [ $# -gt 0 ]; do
35 if [ -z "$KERNEL" ]; then
37 elif [ -z "$PATCHVER" ]; then
52 if [ -z "$KERNEL" ]; then
53 echo "usage: $0 [<options>...] <patchver> [<version>]"
54 echo "example: $0 3.18 3.18.30"
55 echo "If <version> is not given, it will try to find out the latest from kernel.org"
58 echo "-b|--build <args> also do a test build with <args> as extra arguments (e.g. -j 3)"
59 echo "-q|--quiet less output"
60 echo "-t|--test don't do anything, just print what it would do"
61 echo "-u|--update update include/kernel-version.mk after a successful run"
62 echo "-v|--verbose more output (pass V=ws to all commands)"
66 if [ -z "$PATCHVER" ]; then
67 if [ -n "$(which curl)" ]; then
71 if [ -n "$(which wget)" ]; then
72 DL_CMD
="wget -O - -q "
75 if [ -z "$DL_CMD" ]; then
76 echo "Failed to find a suitable download program. Please install either curl or wget." >&2
80 # https://www.kernel.org/feeds/kdist.xml
81 # $(curl -s https://www.kernel.org/feeds/kdist.xml | sed -ne 's|^.*"html_url": "\(.*/commit/.*\)",|\1.patch|p')
82 # curl -s "https://www.kernel.org/feeds/kdist.xml"
83 CURR_VERS
=$
($DL_CMD "https://www.kernel.org/feeds/kdist.xml" |
sed -ne 's|^.*title>\([1-9][^\w]*\): .*|\1|p')
85 for ver
in $CURR_VERS; do
92 if [ -n "$PATCHVER" ]; then
97 if [ -z "$PATCHVER" ]; then
98 echo "Failed to find the latest release on kernel.org, please specify the release manually" >&2
103 echo "Refreshing Kernel $KERNEL to release $PATCHVER ..."
105 targets
=$
(ls -b target
/linux
)
107 if [ "$TEST" -eq 1 ]; then
111 for target
in $targets; do
112 if [ "$target" = "generic" -o -f "$target" ]; then
116 grep -q "broken" target
/linux
/$target/Makefile
&& { \
117 echo "Skipping $target (broken)"
121 if [ -e tmp
/${target}_
${PATCHVER}_done
]; then
125 grep -q "${PATCHVER}" target
/linux
/$target/Makefile || \
126 [ -f target
/linux
/$target/config-
${KERNEL} ] || \
127 [ -d target
/linux
/$target/patches-
${KERNEL} ] && {
128 echo "refreshing $target ..."
129 $CMD echo "CONFIG_TARGET_$target=y" > .config ||
exit 1
130 $CMD echo "CONFIG_ALL_KMODS=y" >> .config ||
exit 1
131 $CMD make defconfig KERNEL_PATCHVER
=${KERNEL} ||
exit 1
132 if [ ! -f tmp
/${target}_
${PATCHVER}_refreshed
]; then
133 $CMD make target
/linux
/refresh V
=$VERBOSE KERNEL_PATCHVER
=${KERNEL} LINUX_VERSION
=${PATCHVER} LINUX_KERNEL_HASH
=skip ||
exit 1
134 $CMD make target
/linux
/prepare V
=$VERBOSE KERNEL_PATCHVER
=${KERNEL} LINUX_VERSION
=${PATCHVER} ||
exit 1
135 $CMD touch tmp
/${target}_
${PATCHVER}_refreshed
137 if [ "$BUILD" = "1" ]; then
138 echo "building $target ... "
139 $CMD make V
=$VERBOSE KERNEL_PATCHVER
=${KERNEL} LINUX_VERSION
=${PATCHVER} $BUILD_ARGS ||
exit 1
141 $CMD make target
/linux
/clean
142 $CMD touch tmp
/${target}_
${PATCHVER}_done
144 echo "skipping $target (no support for $KERNEL)"
148 if [ "$UPDATE" -eq 1 ]; then
149 NEWVER
=${PATCHVER#$KERNEL}
150 if [ "$TEST" -eq 1 ]; then
151 echo .
/staging_dir
/host
/bin
/mkhash sha256 dl
/linux-
$PATCHVER.
tar.xz
154 if [ -f dl
/linux-
$PATCHVER.
tar.xz
]; then
155 CHECKSUM
=$
(.
/staging_dir
/host
/bin
/mkhash sha256 dl
/linux-
$PATCHVER.
tar.xz
)
158 $CMD .
/staging_dir
/host
/bin
/sed -i include
/kernel-version.mk \
159 -e "s|LINUX_VERSION-${KERNEL} =.*|LINUX_VERSION-${KERNEL} = ${NEWVER}|" \
160 -e "s|LINUX_KERNEL_HASH-${KERNEL}.*|LINUX_KERNEL_HASH-${PATCHVER} = ${CHECKSUM}|"