6 Star 6 Fork 4

xiaobao/amlogic-s9xxx-armbian

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
recompile 28.00 KB
一键复制 编辑 原始数据 按行查看 历史
ophub 提交于 2023-02-05 11:56 . Add build total display
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
#!/bin/bash
#==============================================================================================
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.
#
# This file is a part of the Rebuild Armbian
# https://github.com/ophub/amlogic-s9xxx-armbian
#
# Description: Run on x86_64 Ubuntu-22.04(jammy), Compile the kernel.
# Copyright (C) 2021- https://github.com/unifreq
# Copyright (C) 2021- https://github.com/ophub/amlogic-s9xxx-armbian
#
# Command: sudo ./recompile
# Command optional parameters please refer to the source code repository
#
#======================================= Functions list =======================================
#
# error_msg : Output error message
#
# init_var : Initialize all variables
# toolchain_check : Check and install the cross-compilation toolchain
# query_version : Query the latest kernel version
#
# get_kernel_source : Get the kernel source code
# headers_install : Deploy the kernel headers file
# compile_env : Set up the compile kernel environment
# compile_dtbs : Compile the dtbs
# compile_kernel : Compile the kernel
# generate_uinitrd : Chroot into Armbian to generate initrd.img and uInitrd
# packit_dtbs : Packit dtbs files
# packit_kernel : Packit boot, modules and header files
# compile_selection : Choose to compile dtbs or all kernels
# clean_tmp : Clear temporary files
#
# loop_recompile : Loop to compile kernel
#
#=============================== Set make environment variables ===============================
#
# Related file storage path
make_path="${PWD}"
compile_path="${make_path}/compile-kernel"
kernel_path="${compile_path}/kernel"
config_path="${compile_path}/tools/config"
script_path="${compile_path}/tools/script"
armbian_path="${compile_path}/tools/armbian"
armbian_file="${armbian_path}/armbian.img"
out_kernel="${compile_path}/output"
chroot_path="${out_kernel}/chroot"
chroot_file="${chroot_path}/chroot_armbian.img"
arch_info="$(arch)"
host_release="$(cat /etc/os-release | grep '^VERSION_CODENAME=.*' | cut -d'=' -f2)"
# Set the default value of the [ -r ] parameter
# When set to [ -r kernel.org ], Kernel download from kernel.org
kernel_org_repo="https://cdn.kernel.org/pub/linux/kernel/v5.x/"
# Set the default for downloading kernel sources from github.com
repo_owner="unifreq"
repo_branch="main"
build_kernel=("5.10.125" "5.15.50")
auto_kernel="true"
custom_name="-ophub"
# Set the kernel compile object, options: [ dtbs / all ]
package_list="all"
# Cross compile toolchain download mirror
dev_repo="https://github.com/ophub/kernel/releases/download/dev"
# Arm GNU Toolchain source: https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads
gun_file="arm-gnu-toolchain-12.2.rel1-x86_64-aarch64-none-linux-gnu.tar.xz"
# Armenian file source: https://github.com/ophub/amlogic-s9xxx-armbian/releases
armbian_rootfs_file="armbian.tar.xz"
# Set the toolchain path
toolchain_path="/usr/local/toolchain"
# Set the default cross-compilation toolchain: [ gcc / clang ]
toolchain_name="clang"
# QEMU BINARY
qemu_binary_arm="qemu-arm-static"
qemu_binary_arm64="qemu-aarch64-static"
# Set font color
STEPS="[\033[95m STEPS \033[0m]"
INFO="[\033[94m INFO \033[0m]"
SUCCESS="[\033[92m SUCCESS \033[0m]"
WARNING="[\033[93m WARNING \033[0m]"
ERROR="[\033[91m ERROR \033[0m]"
#
#==============================================================================================
error_msg() {
echo -e "${ERROR} ${1}"
exit 1
}
init_var() {
echo -e "${STEPS} Start Initializing Variables..."
# If it is followed by [ : ], it means that the option requires a parameter value
get_all_ver="$(getopt "k:a:n:p:r:t:" "${@}")"
while [[ -n "${1}" ]]; do
case "${1}" in
-k | --Kernel)
if [[ -n "${2}" ]]; then
oldIFS=$IFS
IFS=_
build_kernel=(${2})
IFS=$oldIFS
shift
else
error_msg "Invalid -k parameter [ ${2} ]!"
fi
;;
-a | --AutoKernel)
if [[ -n "${2}" ]]; then
auto_kernel="${2}"
shift
else
error_msg "Invalid -a parameter [ ${2} ]!"
fi
;;
-n | --customName)
if [[ -n "${2}" ]]; then
custom_name="${2// /}"
[[ ${custom_name:0:1} != "-" ]] && custom_name="-${custom_name}"
shift
else
error_msg "Invalid -n parameter [ ${2} ]!"
fi
;;
-p | --PackageList)
if [[ -n "${2}" ]]; then
package_list="${2}"
shift
else
error_msg "Invalid -p parameter [ ${2} ]!"
fi
;;
-r | --Repository)
if [[ -n "${2}" ]]; then
repo_owner="${2}"
shift
else
error_msg "Invalid -r parameter [ ${2} ]!"
fi
;;
-t | --Toolchain)
if [[ -n "${2}" ]]; then
toolchain_name="${2}"
shift
else
error_msg "Invalid -t parameter [ ${2} ]!"
fi
;;
*)
error_msg "Invalid option [ ${1} ]!"
;;
esac
shift
done
# Receive the value entered by the [ -r ] parameter
input_r_value="${repo_owner//https\:\/\/github\.com\//}"
code_owner="$(echo "${input_r_value}" | awk -F '@' '{print $1}' | awk -F '/' '{print $1}')"
code_repo="$(echo "${input_r_value}" | awk -F '@' '{print $1}' | awk -F '/' '{print $2}')"
code_branch="$(echo "${input_r_value}" | awk -F '@' '{print $2}')"
#
[[ -n "${code_owner}" ]] || error_msg "The [ -r ] parameter is invalid."
[[ -n "${code_branch}" ]] || code_branch="${repo_branch}"
}
toolchain_check() {
cd ${make_path}
echo -e "${STEPS} Start checking the toolchain for compiling the kernel..."
# Install dependencies for jammy
apt-get -qq update
apt-get -qq install -y $(cat compile-kernel/tools/script/ubuntu2204-build-armbian-depends)
# Download armbian
if [[ ! -f "${armbian_file}" ]]; then
echo -e "${INFO} Start downloading Armbian rootfs file [ ${armbian_rootfs_file} ]..."
rm -rf ${armbian_path} && mkdir -p ${armbian_path}
wget -q "${dev_repo}/${armbian_rootfs_file}" -O "${armbian_path}/${armbian_rootfs_file}"
[[ "${?}" -eq "0" ]] || error_msg "Armbian file download failed"
tar -xJf ${armbian_path}/${armbian_rootfs_file} -C ${armbian_path}
# Change other names to armbian.img
[[ -f "${armbian_file}" ]] || mv -f ${armbian_path}/*.img ${armbian_file}
# Delete download file
rm -f ${armbian_path}/${armbian_rootfs_file}
[[ -f "${armbian_file}" ]] || error_msg "There is no Armbian rootfs file: [ ${armbian_file} ]"
fi
# Download the cross-compilation toolchain: [ clang / gcc ]
[[ -d "/etc/apt/sources.list.d" ]] || mkdir -p /etc/apt/sources.list.d
if [[ "${toolchain_name}" == "clang" ]]; then
# Set llvm version
llvm_version="14"
echo -e "${INFO} Start installing the [ llvm: ${llvm_version} ] toolchain..."
# Add apt source for llvm
llvm_toolchain_list="/etc/apt/sources.list.d/llvm-toolchain.list"
echo "deb http://apt.llvm.org/${host_release}/ llvm-toolchain-${host_release}-${llvm_version} main" >${llvm_toolchain_list}
echo "deb-src http://apt.llvm.org/${host_release}/ llvm-toolchain-${host_release}-${llvm_version} main" >>${llvm_toolchain_list}
[[ -s "${llvm_toolchain_list}" ]] || error_msg "failed to add apt source: [ ${llvm_toolchain_list} ]"
# Add gpg key for llvm
llvm_toolchain_asc="/etc/apt/trusted.gpg.d/llvm-toolchain.asc"
curl -sL "https://apt.llvm.org/llvm-snapshot.gpg.key" -o "${llvm_toolchain_asc}"
[[ -s "${llvm_toolchain_asc}" ]] || error_msg "failed to add gpg key: [ ${llvm_toolchain_asc} ]"
# Set up the installation package, refer to the source: https://apt.llvm.org/
llvm_pkg="\
clang-${llvm_version} lldb-${llvm_version} lld-${llvm_version} clangd-${llvm_version} clang-tidy-${llvm_version} \
clang-format-${llvm_version} clang-tools-${llvm_version} llvm-${llvm_version}-dev lld-${llvm_version} lldb-${llvm_version} \
llvm-${llvm_version}-tools libomp-${llvm_version}-dev libc++-${llvm_version}-dev libc++abi-${llvm_version}-dev \
libclang-common-${llvm_version}-dev libclang-${llvm_version}-dev libclang-dev libunwind-${llvm_version}-dev \
"
# Install llvm
apt-get -qq install -y ${llvm_pkg}
# Set cross compilation parameters
export CROSS_COMPILE="aarch64-linux-gnu-"
export CC="clang"
export LD="ld.lld"
export MFLAGS=" LLVM=1 LLVM_IAS=1 "
else
# Download Arm GNU Toolchain
[[ -d "${toolchain_path}" ]] || mkdir -p ${toolchain_path}
if [[ ! -d "${toolchain_path}/${gun_file//.tar.xz/}/bin" ]]; then
echo -e "${INFO} Start downloading the ARM GNU toolchain [ ${gun_file} ]..."
wget -q "${dev_repo}/${gun_file}" -O "${toolchain_path}/${gun_file}"
[[ "${?}" -eq "0" ]] || error_msg "GNU toolchain file download failed"
tar -xJf ${toolchain_path}/${gun_file} -C ${toolchain_path}
rm -f ${toolchain_path}/${gun_file}
[[ -d "${toolchain_path}/${gun_file//.tar.xz/}/bin" ]] || error_msg "The gcc is not set!"
fi
# Add ${PATH} variable
path_ubuntu="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
path_gcc="${toolchain_path}/${gun_file//.tar.xz/}/bin:${path_ubuntu}"
export PATH="${path_gcc}"
# Set cross compilation parameters
export CROSS_COMPILE="${toolchain_path}/${gun_file//.tar.xz/}/bin/aarch64-none-linux-gnu-"
export CC="${CROSS_COMPILE}gcc"
export LD="${CROSS_COMPILE}ld.bfd"
export MFLAGS=""
fi
}
query_version() {
cd ${make_path}
echo -e "${STEPS} Start querying the latest kernel version..."
# Set empty array
tmp_arr_kernels=()
# Query the latest kernel in a loop
i=1
for KERNEL_VAR in ${build_kernel[*]}; do
echo -e "${INFO} (${i}) Auto query the latest kernel version of the same series for [ ${KERNEL_VAR} ]"
# Identify the kernel mainline
MAIN_LINE="$(echo ${KERNEL_VAR} | awk -F '.' '{print $1"."$2}')"
if [[ "${code_owner}" == "kernel.org" ]]; then
# latest_version="5.10.125"
latest_version="$(curl -s ${kernel_org_repo} | grep -oE linux-${MAIN_LINE}.[0-9]+.tar.xz | sort -rV | head -n 1 | grep -oE '[1-9].[0-9]{1,3}.[0-9]+')"
if [[ "${?}" -eq "0" && -n "${latest_version}" ]]; then
tmp_arr_kernels[${i}]="${latest_version}"
else
error_msg "Failed to query the kernel version in [ ${kernel_org_repo} ]"
fi
echo -e "${INFO} (${i}) [ ${tmp_arr_kernels[$i]} ] is kernel.org latest kernel. \n"
else
if [[ -z "${code_repo}" ]]; then linux_repo="linux-${MAIN_LINE}.y"; else linux_repo="${code_repo}"; fi
github_kernel_repo="${code_owner}/${linux_repo}/${code_branch}"
github_kernel_ver="https://raw.githubusercontent.com/${github_kernel_repo}/Makefile"
# latest_version="125"
latest_version="$(curl -s ${github_kernel_ver} | grep -oE "SUBLEVEL =.*" | head -n 1 | grep -oE '[0-9]{1,3}')"
if [[ "${?}" -eq "0" && -n "${latest_version}" ]]; then
tmp_arr_kernels[${i}]="${MAIN_LINE}.${latest_version}"
else
error_msg "Failed to query the kernel version in [ github.com/${github_kernel_repo} ]"
fi
echo -e "${INFO} (${i}) [ ${tmp_arr_kernels[$i]} ] is github.com/${github_kernel_repo} latest kernel. \n"
fi
let i++
done
# Reset the kernel array to the latest kernel version
unset build_kernel
build_kernel="${tmp_arr_kernels[*]}"
}
get_kernel_source() {
cd ${make_path}
echo -e "${STEPS} Start downloading the kernel source code..."
# kernel_folder > kernel_.tar.xz_file > download_from_kernel.org
[[ -d "${kernel_path}" ]] || mkdir -p ${kernel_path}
if [[ ! -d "${kernel_path}/${local_kernel_path}" ]]; then
if [[ "${code_owner}" == "kernel.org" ]]; then
if [[ -f "${kernel_path}/${local_kernel_path}.tar.xz" ]]; then
echo -e "${INFO} Unzip local files [ ${local_kernel_path}.tar.xz ]"
cd ${kernel_path}
tar -xJf ${local_kernel_path}.tar.xz
[[ "${?}" -eq "0" ]] || error_msg "[ ${local_kernel_path}.tar.xz ] file decompression failed."
else
echo -e "${INFO} [ ${kernel_version} ] Kernel loading from [ ${server_kernel_repo}${local_kernel_path}.tar.xz ]"
wget -q -P ${kernel_path} ${server_kernel_repo}${local_kernel_path}.tar.xz
if [[ "${?}" -eq "0" && -s "${kernel_path}/${local_kernel_path}.tar.xz" ]]; then
echo -e "${SUCCESS} The kernel file is downloaded successfully."
cd ${kernel_path}
tar -xJf ${local_kernel_path}.tar.xz
[[ -d "${local_kernel_path}" ]] || error_msg "[ ${local_kernel_path}.tar.xz ] file decompression failed."
else
error_msg "Kernel file download failed!"
fi
fi
else
echo -e "${INFO} Start cloning from [ https://github.com/${server_kernel_repo} -b ${code_branch} ]"
git clone -q --single-branch --depth 1 https://github.com/${server_kernel_repo} -b ${code_branch} ${kernel_path}/${local_kernel_path}
[[ "${?}" -eq "0" ]] || error_msg "[ https://github.com/${server_kernel_repo} ] Clone failed."
fi
elif [ "${code_owner}" != "kernel.org" ]; then
# Get a local kernel version
local_makefile="${kernel_path}/${local_kernel_path}/Makefile"
local_makefile_version="$(cat ${local_makefile} | grep -oE "VERSION =.*" | head -n 1 | grep -oE '[0-9]{1,3}')"
local_makefile_patchlevel="$(cat ${local_makefile} | grep -oE "PATCHLEVEL =.*" | head -n 1 | grep -oE '[0-9]{1,3}')"
local_makefile_sublevel="$(cat ${local_makefile} | grep -oE "SUBLEVEL =.*" | head -n 1 | grep -oE '[0-9]{1,3}')"
# Local version and server version comparison
if [[ "${auto_kernel}" == "true" && "${kernel_sub}" -gt "${local_makefile_sublevel}" ]]; then
# Pull the latest source code of the server
cd ${kernel_path}/${local_kernel_path}
git checkout ${code_branch} && git reset --hard origin/${code_branch} && git pull
unset kernel_version
kernel_version="${local_makefile_version}.${local_makefile_patchlevel}.${kernel_sub}"
echo -e "${INFO} Synchronize the upstream source code, compile the kernel version [ ${kernel_version} ]."
else
# Reset to local kernel version number
unset kernel_version
kernel_version="${local_makefile_version}.${local_makefile_patchlevel}.${local_makefile_sublevel}"
echo -e "${INFO} Use local source code, compile the kernel version [ ${kernel_version} ]."
fi
fi
}
headers_install() {
cd ${kernel_path}/${local_kernel_path}
# Set headers files list
head_list="$(mktemp)"
(
find . arch/${ARCH} -maxdepth 1 -name Makefile\*
find include scripts -type f -o -type l
find arch/${ARCH} -name Kbuild.platforms -o -name Platform
find $(find arch/${ARCH} -name include -o -name scripts -type d) -type f
) >${head_list}
# Set object files list
obj_list="$(mktemp)"
{
[[ -n "$(grep "^CONFIG_OBJTOOL=y" include/config/auto.conf 2>/dev/null)" ]] && echo "tools/objtool/objtool"
find arch/${ARCH}/include Module.symvers include scripts -type f
[[ -n "$(grep "^CONFIG_GCC_PLUGINS=y" include/config/auto.conf 2>/dev/null)" ]] && find scripts/gcc-plugins -name \*.so
} >${obj_list}
# Install related files to the specified directory
tar --exclude '*.orig' -c -f - -C ${kernel_path}/${local_kernel_path} -T ${head_list} | tar -xf - -C ${out_kernel}/header
tar --exclude '*.orig' -c -f - -T ${obj_list} | tar -xf - -C ${out_kernel}/header
# copy .config manually to be where it's expected to be
cp -f .config ${out_kernel}/header/.config
# Delete temporary files
rm -f ${head_list} ${obj_list}
}
compile_env() {
cd ${make_path}
echo -e "${STEPS} Start checking local compilation environments..."
# Get kernel output name
kernel_outname="${kernel_version}${custom_name}"
echo -e "${INFO} Compile kernel output name: [ ${kernel_outname} ]"
# Create a temp directory
echo -e "${INFO} Create a temp directory: [ ${out_kernel} ]"
rm -rf ${out_kernel}/{chroot/,boot/,dtb/,modules/,header/,${kernel_version}/}
mkdir -p ${out_kernel}/{chroot/{root/boot/,},boot/,dtb/{allwinner/,amlogic/,rockchip/},modules/,header/,${kernel_version}/}
cd ${kernel_path}/${local_kernel_path}
echo -e "${STEPS} Set cross compilation parameters..."
# Set cross compilation parameters
export ARCH="arm64"
export LOCALVERSION="${custom_name}"
# Show variable
echo -e "${INFO} ARCH: [ ${ARCH} ]"
echo -e "${INFO} LOCALVERSION: [ ${LOCALVERSION} ]"
echo -e "${INFO} CROSS_COMPILE: [ ${CROSS_COMPILE} ]"
echo -e "${INFO} CC: [ ${CC} ]"
echo -e "${INFO} LD: [ ${LD} ]"
# Set generic make string
MAKE_SET_STRING=" ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} CC=${CC} LD=${LD} ${MFLAGS} LOCALVERSION=${LOCALVERSION} "
# Make clean/mrproper
make ${MAKE_SET_STRING} mrproper
# Check .config file
if [[ ! -s ".config" ]]; then
[[ -s "${config_path}/config-${kernel_verpatch}" ]] || error_msg "Missing [ config-${kernel_verpatch} ] template!"
echo -e "${INFO} Copy [ ${config_path}/config-${kernel_verpatch} ] to [ .config ]"
cp -f ${config_path}/config-${kernel_verpatch} .config
else
echo -e "${INFO} Use the .config file in the current directory."
fi
# Clear kernel signature
sed -i "s|CONFIG_LOCALVERSION=.*|CONFIG_LOCALVERSION=\"\"|" .config
# Enable/Disabled Linux Kernel Clang LTO
[[ "${toolchain_name}" == "clang" ]] && {
kernel_x="$(echo "${kernel_version}" | cut -d '.' -f1)"
kernel_y="$(echo "${kernel_version}" | cut -d '.' -f2)"
if [[ "${kernel_x}" -ge "6" ]] || [[ "${kernel_x}" -eq "5" && "${kernel_y}" -ge "12" ]]; then
scripts/config -e LTO_CLANG_THIN
else
scripts/config -d LTO_CLANG_THIN
fi
}
# Make menuconfig
#make ${MAKE_SET_STRING} menuconfig
# Set max process
PROCESS="$(cat /proc/cpuinfo | grep "processor" | wc -l)"
[[ -z "${PROCESS}" ]] && PROCESS="1" && echo "PROCESS: 1"
}
compile_dtbs() {
cd ${kernel_path}/${local_kernel_path}
# Make dtbs
echo -e "${STEPS} Start compilation dtbs [ ${local_kernel_path} ]..."
make ${MAKE_SET_STRING} dtbs -j${PROCESS}
[[ "${?}" -eq "0" ]] && echo -e "${SUCCESS} The dtbs is compiled successfully."
}
compile_kernel() {
cd ${kernel_path}/${local_kernel_path}
# Make kernel
echo -e "${STEPS} Start compilation kernel [ ${local_kernel_path} ]..."
make ${MAKE_SET_STRING} Image modules dtbs -j${PROCESS}
[[ "${?}" -eq "0" ]] && echo -e "${SUCCESS} The kernel is compiled successfully."
# Install modules
echo -e "${STEPS} Install modules..."
make ${MAKE_SET_STRING} INSTALL_MOD_PATH=${out_kernel}/modules modules_install
[[ "${?}" -eq "0" ]] && echo -e "${SUCCESS} The modules is installed successfully."
# Install headers
echo -e "${STEPS} Install headers..."
headers_install
[[ "${?}" -eq "0" ]] && echo -e "${SUCCESS} The headers is installed successfully."
}
generate_uinitrd() {
cd ${make_path}
echo -e "${STEPS} Create chroot..."
cp -f ${armbian_file} ${chroot_file}
# Mount the armbian system
tag_rootfs="${chroot_path}/root"
loop_armbian="$(losetup -P -f --show "${chroot_file}")"
[[ -n "${loop_armbian}" ]] || error_msg "losetup ${chroot_file} failed."
if ! mount ${loop_armbian}p2 ${tag_rootfs}; then
error_msg "mount ${loop_armbian}p2 failed!"
fi
if ! mount ${loop_armbian}p1 ${tag_rootfs}/boot; then
error_msg "mount ${loop_armbian}p1 failed!"
fi
# Copy /boot related files into armbian system
rm -f ${tag_rootfs}/boot/{config-*,initrd.img-*,System.map-*,uInitrd-*,vmlinuz-*,uInitrd,zImage}
#
cp -f ${kernel_path}/${local_kernel_path}/System.map ${tag_rootfs}/boot/System.map-${kernel_outname}
cp -f ${kernel_path}/${local_kernel_path}/.config ${tag_rootfs}/boot/config-${kernel_outname}
cp -f ${kernel_path}/${local_kernel_path}/arch/arm64/boot/Image ${tag_rootfs}/boot/vmlinuz-${kernel_outname}
cp -f ${kernel_path}/${local_kernel_path}/arch/arm64/boot/Image ${tag_rootfs}/boot/zImage
#echo -e "${INFO} Kernel copy results in the [ ${tag_rootfs}/boot ] directory: \n$(ls -l ${tag_rootfs}/boot) \n"
rm -rf ${tag_rootfs}/usr/lib/modules/*
cp -rf ${out_kernel}/modules/lib/modules/${kernel_outname} ${tag_rootfs}/usr/lib/modules
#echo -e "${INFO} Kernel copy results in the [ ${tag_rootfs}/usr/lib/modules ] directory: \n$(ls -l ${tag_rootfs}/usr/lib/modules) \n"
# COMPRESS: [ gzip | bzip2 | lz4 | lzma | lzop | xz | zstd ]
compress_initrd_file="${tag_rootfs}/etc/initramfs-tools/initramfs.conf"
sed -i "/^COMPRESS=/d" ${compress_initrd_file}
echo "COMPRESS=gzip" >>${compress_initrd_file}
[[ -f "/usr/bin/${qemu_binary_arm}" ]] && cp -f /usr/bin/${qemu_binary_arm} ${tag_rootfs}/usr/bin/
[[ -f "/usr/bin/${qemu_binary_arm64}" ]] && cp -f /usr/bin/${qemu_binary_arm64} ${tag_rootfs}/usr/bin/
#echo -e "${INFO} The [ ${qemu_binary_arm64} ] file copy results: \n$(ls -l ${tag_rootfs}/usr/bin/${qemu_binary_arm64}) \n"
cp -f ${script_path}/ubuntu_chroot_armbian.sh ${tag_rootfs}/root
chmod +x ${tag_rootfs}/root/ubuntu_chroot_armbian.sh && sync
#echo -e "${INFO} Kernel copy results in the [ ${tag_rootfs}/root ] directory: \n$(ls -l ${tag_rootfs}/root) \n"
# Enter the armbian system to generate /boot/uInitrd-${kernel_outname} file
echo -e "${INFO} Enter the chroot armbian system..."
chroot ${tag_rootfs} /bin/bash -c "/root/ubuntu_chroot_armbian.sh ${kernel_outname}"
[[ "${?}" -eq "0" && -f "${tag_rootfs}/boot/uInitrd-${kernel_outname}" ]] || error_msg "Create chroot uInitrd-${kernel_outname} file failed."
cd ${make_path}
# Copy the generated uInitrd file to the current system
echo -e "${INFO} Copy the generated files from [ ${tag_rootfs}/boot ]"
cp -f ${tag_rootfs}/boot/*${kernel_outname} ${out_kernel}/boot && sync
# Unmount the armbian system
umount ${tag_rootfs}/boot 2>/dev/null
umount ${tag_rootfs} 2>/dev/null
losetup -D 2>/dev/null
}
packit_dtbs() {
# Pack 3 dtbs files
echo -e "${STEPS} Packing the [ ${kernel_outname} ] dtbs packages..."
cd ${out_kernel}/dtb/allwinner
cp -f ${kernel_path}/${local_kernel_path}/arch/arm64/boot/dts/allwinner/*.dtb . && chmod +x *
tar -czf dtb-allwinner-${kernel_outname}.tar.gz *
mv -f *.tar.gz ${out_kernel}/${kernel_version}
echo -e "${SUCCESS} The [ dtb-allwinner-${kernel_outname}.tar.gz ] file is packaged."
cd ${out_kernel}/dtb/amlogic
cp -f ${kernel_path}/${local_kernel_path}/arch/arm64/boot/dts/amlogic/*.dtb . && chmod +x *
tar -czf dtb-amlogic-${kernel_outname}.tar.gz *
mv -f *.tar.gz ${out_kernel}/${kernel_version}
echo -e "${SUCCESS} The [ dtb-amlogic-${kernel_outname}.tar.gz ] file is packaged."
cd ${out_kernel}/dtb/rockchip
cp -f ${kernel_path}/${local_kernel_path}/arch/arm64/boot/dts/rockchip/*.dtb . && chmod +x *
tar -czf dtb-rockchip-${kernel_outname}.tar.gz *
mv -f *.tar.gz ${out_kernel}/${kernel_version}
echo -e "${SUCCESS} The [ dtb-rockchip-${kernel_outname}.tar.gz ] file is packaged."
}
packit_kernel() {
# Pack 3 kernel files
echo -e "${STEPS} Packing the [ ${kernel_outname} ] boot, modules and header packages..."
cd ${out_kernel}/boot
chmod +x *
tar -czf boot-${kernel_outname}.tar.gz *
mv -f *.tar.gz ${out_kernel}/${kernel_version}
echo -e "${SUCCESS} The [ boot-${kernel_outname}.tar.gz ] file is packaged."
cd ${out_kernel}/modules/lib/modules
tar -czf modules-${kernel_outname}.tar.gz *
mv -f *.tar.gz ${out_kernel}/${kernel_version}
echo -e "${SUCCESS} The [ modules-${kernel_outname}.tar.gz ] file is packaged."
cd ${out_kernel}/header
tar -czf header-${kernel_outname}.tar.gz *
mv -f *.tar.gz ${out_kernel}/${kernel_version}
echo -e "${SUCCESS} The [ header-${kernel_outname}.tar.gz ] file is packaged."
}
compile_selection() {
# Compile by selection
if [[ "${package_list}" == "dtbs" ]]; then
compile_dtbs
packit_dtbs
else
compile_kernel
generate_uinitrd
packit_dtbs
packit_kernel
fi
# Add sha256sum integrity verification file
cd ${out_kernel}/${kernel_version}
sha256sum * >sha256sums
echo -e "${SUCCESS} The [ sha256sums ] file has been generated"
cd ${out_kernel}
tar -czf ${kernel_version}.tar.gz ${kernel_version}
sync && sleep 3
echo -e "${INFO} Kernel series files are stored in [ ${out_kernel} ]."
}
clean_tmp() {
cd ${make_path}
echo -e "${STEPS} Clear the space and update-grub..."
rm -rf ${out_kernel}/{chroot/,boot/,dtb/,modules/,header/,${kernel_version}/}
update-grub 2>/dev/null
echo -e "${SUCCESS} All processes have been completed."
}
loop_recompile() {
cd ${make_path}
j="1"
for k in ${build_kernel[*]}; do
# kernel_version, such as [ 5.10.125 ]
kernel_version="${k}"
# kernel_verpatch, such as [ 5.10 ]
kernel_verpatch="$(echo ${kernel_version} | awk -F '.' '{print $1"."$2}')"
# kernel_sub, such as [ 125 ]
kernel_sub="$(echo ${kernel_version} | awk -F '.' '{print $3}')"
# The loop variable assignment
if [[ "${code_owner}" == "kernel.org" ]]; then
server_kernel_repo="${kernel_org_repo}"
local_kernel_path="linux-${kernel_version}"
elif [[ -z "${code_repo}" ]]; then
server_kernel_repo="${code_owner}/linux-${kernel_verpatch}.y"
local_kernel_path="linux-${kernel_verpatch}.y"
else
server_kernel_repo="${code_owner}/${code_repo}"
local_kernel_path="${code_repo}-${code_branch}"
fi
# Execute the following functions in sequence
get_kernel_source
compile_env
compile_selection
clean_tmp
let j++
done
}
# Check script permission, supports running on x86_64 Ubuntu: [ jammy ]
[[ "$(id -u)" == "0" ]] || error_msg "Please run this script as root: [ sudo ./${0} ]"
[[ "${arch_info}" == "x86_64" ]] || error_msg "Running this tool on non-x86_64 Ubuntu build hosts is not supported."
# Show welcome and server start information
echo -e "${STEPS} Welcome to compile kernel! \n"
echo -e "${INFO} Server running on Ubuntu: [ Release: ${host_release} / Host: ${arch_info} ] \n"
echo -e "${INFO} Server CPU configuration information: \n$(cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c) \n"
echo -e "${INFO} Server memory usage: \n$(free -h) \n"
echo -e "${INFO} Server space usage before starting to compile: \n$(df -hT ${make_path}) \n"
echo -e "${INFO} Setting parameters: [ ${@} ] \n"
#
# Initialize variables, download the kernel source code and check the toolchain
init_var "${@}"
[[ "${auto_kernel}" == "true" ]] && query_version
echo -e "${INFO} Kernel compilation toolchain: [ ${toolchain_name} ]"
echo -e "${INFO} Kernel from: [ ${code_owner} ]"
echo -e "${INFO} Kernel List: [ $(echo ${build_kernel[*]} | xargs) ] \n"
toolchain_check
# Loop to compile the kernel
loop_recompile
#
# Show server end information
echo -e "${STEPS} Server space usage after compilation: \n$(df -hT ${make_path}) \n"
echo -e "${SUCCESS} All process completed successfully."
# All process completed
wait
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/recologypower/amlogic-s9xxx-armbian.git
git@gitee.com:recologypower/amlogic-s9xxx-armbian.git
recologypower
amlogic-s9xxx-armbian
amlogic-s9xxx-armbian
main

搜索帮助