@@ -134,46 +134,35 @@ EOF
134134 rm -rf $INITRAMFS_BUILD
135135}
136136
137-
138- function get_linux_git {
139- # git clone -s -b v$KV ../../linux
140- # --depth 1
141- cd linux
142- LATEST_TAG=$( git tag -l " v$KV .*" --sort=v:refname | tail -1)
143- git clean -fdx
144- git checkout $LATEST_TAG
137+ function clone_amazon_linux_repo {
138+ [ -d linux ] || git clone https://github.com/amazonlinux/linux linux
145139}
146140
147-
148- # Download the latest kernel source for the given kernel version
149- function get_linux_tarball {
141+ # prints the git tag corresponding to the newest and best matching the provided kernel version $1
142+ # this means that if a microvm kernel exists, the tag returned will be of the form
143+ #
144+ # microvm-kernel-$1.<patch number>.amzn2[023]
145+ #
146+ # otherwise choose the newest tag matching
147+ #
148+ # kernel-$1.<patch number>.amzn2[023]
149+ function get_tag {
150150 local KERNEL_VERSION=$1
151- echo " Downloading the latest patch version for v$KERNEL_VERSION ..."
152- local major_version=" ${KERNEL_VERSION%% .* } "
153- local url_base=" https://cdn.kernel.org/pub/linux/kernel"
154- local LATEST_VERSION=$(
155- curl -fsSL $url_base /v$major_version .x/ \
156- | grep -o " linux-$KERNEL_VERSION \.[0-9]*\.tar.xz" \
157- | sort -rV \
158- | head -n 1 || true)
159- # Fetch tarball and sha256 checksum.
160- curl -fsSLO " $url_base /v$major_version .x/sha256sums.asc"
161- curl -fsSLO " $url_base /v$major_version .x/$LATEST_VERSION "
162- # Verify checksum.
163- grep " ${LATEST_VERSION} " sha256sums.asc | sha256sum -c -
164- echo " Extracting the kernel source..."
165- tar -xaf $LATEST_VERSION
166- local DIR=$( basename $LATEST_VERSION .tar.xz)
167- ln -svfT $DIR linux
151+
152+ # list all tags from newest to oldest
153+ (git --no-pager tag -l --sort=-creatordate | grep " microvm-kernel-$1 \..*\.amzn2" \
154+ || git --no-pager tag -l --sort=-creatordate | grep " kernel-$1 \..*\.amzn2" ) | head -n1
168155}
169156
170- function build_linux {
157+ function build_al_kernel {
171158 local KERNEL_CFG=$1
172159 # Extract the kernel version from the config file provided as parameter.
173- local KERNEL_VERSION=$( grep -Po " ^# Linux\/\w+ \ K(\d+\.\d+)" " $KERNEL_CFG " )
160+ local KERNEL_VERSION=$( echo $KERNEL_CFG | grep -Po " microvm-kernel-ci- $ARCH -\ K(\d+\.\d+)" )
174161
175- get_linux_tarball $KERNEL_VERSION
176162 pushd linux
163+ make distclean
164+
165+ git checkout $( get_tag $KERNEL_VERSION )
177166
178167 arch=$( uname -m)
179168 if [ " $arch " = " x86_64" ]; then
@@ -187,8 +176,8 @@ function build_linux {
187176
188177 # Patch 6.1 kernels on ARM with 6.10 patches for supporting VMGenID
189178 # via DeviceTree bindings.
190- # TODO: drop this (and remove the patches from the repo) when we switch
191- # to building kernels from AL tree .
179+ # TODO: drop this (and remove the patches from the repo) when AL backports the
180+ # patches to 6.1 .
192181 if [[ $KERNEL_VERSION == " 6.1" ]]; then
193182 for i in ../patches/vmgenid_dt/* ; do
194183 patch -p1 < $i
@@ -204,9 +193,13 @@ function build_linux {
204193 make -j $( nproc) $target
205194 LATEST_VERSION=$( cat include/config/kernel.release)
206195 flavour=$( basename $KERNEL_CFG .config | grep -Po " \d+\.\d+\K(-.*)" || true)
207- OUTPUT_FILE=$OUTPUT_DIR /vmlinux-$LATEST_VERSION$flavour
196+ # Strip off everything after the last number - sometimes AL kernels have some stuff there.
197+ # e.g. vmlinux-4.14.348-openela -> vmlinux-4.14.348
198+ normalized_version=$( echo " $LATEST_VERSION " | sed -E " s/(.*[[:digit:]]).*/\1/g" )
199+ OUTPUT_FILE=$OUTPUT_DIR /vmlinux-$normalized_version$flavour
208200 cp -v $binary_path $OUTPUT_FILE
209201 cp -v .config $OUTPUT_FILE .config
202+
210203 popd & > /dev/null
211204}
212205
226219build_rootfs ubuntu-22.04 jammy
227220build_initramfs
228221
229- build_linux $PWD /guest_configs/microvm-kernel-ci-$ARCH -4.14.config
230- build_linux $PWD /guest_configs/microvm-kernel-ci-$ARCH -5.10.config
222+ clone_amazon_linux_repo
223+
224+ build_al_kernel $PWD /guest_configs/microvm-kernel-ci-$ARCH -4.14.config
225+ build_al_kernel $PWD /guest_configs/microvm-kernel-ci-$ARCH -5.10.config
231226if [ $ARCH == " x86_64" ]; then
232- build_linux $PWD /guest_configs/microvm-kernel-ci-$ARCH -5.10-no-acpi.config
227+ build_al_kernel $PWD /guest_configs/microvm-kernel-ci-$ARCH -5.10-no-acpi.config
233228fi
234- build_linux $PWD /guest_configs/microvm-kernel-ci-$ARCH -6.1.config
229+ build_al_kernel $PWD /guest_configs/microvm-kernel-ci-$ARCH -6.1.config
235230
236231tree -h $OUTPUT_DIR
0 commit comments