1
0
mirror of https://github.com/rancher/os-kernel.git synced 2025-04-28 10:33:19 +00:00
os-kernel/scripts/build-common
2019-06-10 08:22:34 +02:00

138 lines
3.5 KiB
Bash
Executable File

#!/bin/bash
set -e
if [[ "$KERNEL_TAG" == "" ]]; then
echo "ERROR: Please set the KERNEL_TAG (the mainline KERNEL version is also the git tag) you're building"
echo " e.g., KERNEL_TAG=4.9.10 make release"
exit 1
fi
: ${ARTIFACTS:=$(pwd)/assets}
: ${BUILD:=/usr/src}
: ${CONFIG:=$(pwd)/config}
: ${DIST:=$(pwd)/dist}
: ${PATCHES:=$(pwd)/patches}
mkdir -p ${DIST}/kernel
list_build_files() {
find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl
find $(find ./arch/${SRCARCH} -name include -o -name scripts -type d) ./include ./scripts -type f
find ./arch/${SRCARCH} -name module.lds -o -name Kbuild.platforms -o -name Platform
find . -name Module.symvers -type f
find . -name objtool -type f
}
create_firmware_tar() {
local list=$1
local temp=firmware-temp
rm -rf $temp
mkdir -p $temp
tar xf linux*.tar -C $temp
if [ ! -e linux-firmware ]; then
git clone git://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git
pushd linux-firmware
git checkout -b ${FIRMWARE_TAG} ${FIRMWARE_TAG}
popd
fi
(
cd linux-firmware
git rev-parse HEAD > .git-commit
)
echo .git-commit > files
for i in $(<$list); do
if [ ! -e $temp/lib/firmware/$i ]; then
if [ -e linux-firmware/$i ]; then
echo Found $i
echo $i >> files
else
echo WARNING: Firmware listed in $list Not found $i
fi
fi
done
tar cf firmware.tar --transform 's,^,lib/firmware/,' -C linux-firmware $(<files)
for i in $(<files); do
if [ -e linux-firmware/$i ]; then
rm linux-firmware/$i
fi
done
tar cf firmware-extra.tar --transform 's,^./,lib/firmware/,' -C linux-firmware --exclude .git .
}
move_files() {
local module_list=$1
local target=$2
local target_file=${DIST}/kernel/modules-${target}.list
for i in $(<$module_list); do
if [ ! -e $i ]; then
echo "WARNING move_files into $target, $i does not exist"
continue
fi
for j in $i ${DEPS[$i]}; do
if [ -e $j ]; then
dest=$(readlink -f $j | sed 's!/build/!/'$target'/!')
mkdir -p $(dirname $dest)
mv -f $j $dest
echo $j >> ${target_file}
fi
done
done
sort ${target_file} -o ${target_file}
}
declare -A DEPS
build_deps() {
while read LINE; do
DEPS[${LINE%%:*}]="${LINE##*:}"
done < <(cat modules.dep)
}
split_tar() {
local archive=$1
local module_list=$2
local module_extra_list=$3
rm -rf tar
mkdir -p tar/{build,main,extra}
echo Extracting $archive
tar xf $archive -C tar/build
/sbin/depmod -b tar/build $(basename tar/build/lib/modules/*)
cd tar/build/lib/modules/*/kernel/..
build_deps
echo Separating modules
move_files $module_list main
move_files $module_extra_list extra
if [ $(find kernel -type f | wc -l) -gt 0 ]; then
echo Invalid files in $(pwd)
find kernel -type f
echo
echo ERROR: Extra files in $(pwd)
echo ERROR: You may need to either remove some modules from your kernel .config, or
echo ERROR: add these files to $module_list or $module_extra_list
exit 1
fi
rm -rf kernel
mv $(pwd | sed 's!/build/!/main/!')/kernel .
echo Creating base.tar
tar cf ../../../../../base.tar -C ../../.. .
echo Creating extra.tar
tar cf ../../../../../extra.tar -C ../../../../extra .
}