1 Star 3 Fork 2

xiayang / amlogic-s9xxx-armbian

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
recompile 25.01 KB
一键复制 编辑 原始数据 按行查看 历史
ophub 提交于 2022-06-06 17:57 . Unified grammar format
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
#!/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 Armbian for Amlogic TV Boxes
# https://github.com/ophub/amlogic-s9xxx-armbian
#
# Description: Run on x86_64 Ubuntu-20.04/22.04, Compile the kernel for Amlogic s9xxx tv box
# Copyright (C) 2021- https://github.com/unifreq
# Copyright (C) 2021- https://github.com/ophub/amlogic-s9xxx-armbian
#
# Command: sudo ./recompile -d
# 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 (GCC, Clang, Armbian)
# query_version : Query the latest kernel version
#
# get_kernel_source : Get the kernel source code
# env_check : Check the environment for compile kernel
# compile_kernel : Compile the kernel
# generate_uinitrd : Chroot into Armbian to generate initrd.img and uInitrd
# packit_kernel : Package the full set of kernel files
# 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)"
toolchain_path="/usr/local/toolchain"
#
# 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.100" "5.15.25")
auto_kernel="true"
custom_name="-ophub"
#
# Cross compile toolchain download mirror, run on ubuntu-20.04
dev_repo="https://github.com/ophub/kernel/releases/download/dev"
#
# Armbian download from: https://github.com/ophub/amlogic-s9xxx-armbian/releases
armbian_rootfs_file="armbian_22.05.0_aml_s922x_focal_5.15.35.tar.xz"
#
# GCC download from: https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/downloads
gcc_file="gcc-arm-11.2-2022.02-x86_64-aarch64-none-linux-gnu.tar.xz"
#
# Clang download from: https://github.com/llvm/llvm-project/releases
clang_file="clang+llvm-13.0.0-x86_64-linux-gnu-ubuntu-20.04.tar.xz"
#
# 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() {
cd ${make_path}
# If it is followed by [ : ], it means that the option requires a parameter value
get_all_ver="$(getopt "dk:a:n:r:" "${@}")"
while [[ -n "${1}" ]]; do
case "${1}" in
-d | --Default)
: ${build_kernel:="${build_kernel}"}
: ${auto_kernel:="${auto_kernel}"}
: ${custom_name:="${custom_name}"}
: ${repo_owner:="${repo_owner}"}
;;
-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}"
shift
else
error_msg "Invalid -n parameter [ ${2} ]!"
fi
;;
-r | --Repository)
if [[ -n "${2}" ]]; then
repo_owner="${2}"
shift
else
error_msg "Invalid -r 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} Check the cross-compilation environment ..."
if [[ "${host_release}" == "jammy" ]]; then
# Install dependencies for jammy
sudo apt-get -qq update
sudo apt-get -qq install -y $(cat compile-kernel/tools/script/ubuntu2204-build-armbian-depends)
else
# Install dependencies for focal
sudo apt-get -qq update
sudo apt-get -qq install -y $(cat compile-kernel/tools/script/ubuntu2004-build-armbian-depends)
[[ -d "${toolchain_path}" ]] || mkdir -p ${toolchain_path}
# Download gcc for Ubuntu focal
if [[ ! -d "${toolchain_path}/${gcc_file//.tar.xz/}/bin" ]]; then
echo -e "${INFO} Download gcc [ ${gcc_file} ] ..."
wget -c "${dev_repo}/${gcc_file}" -O "${toolchain_path}/${gcc_file}" >/dev/null 2>&1 && sync
tar -xJf ${toolchain_path}/${gcc_file} -C ${toolchain_path} && sync
rm -f ${toolchain_path}/${gcc_file} && sync
[[ -d "${toolchain_path}/${gcc_file//.tar.xz/}/bin" ]] || error_msg "The gcc is not set!"
fi
# Download clang for Ubuntu focal
if [[ ! -d "${toolchain_path}/${clang_file//.tar.xz/}/bin" ]]; then
echo -e "${INFO} Download clang [ ${clang_file} ] ..."
wget -c "${dev_repo}/${clang_file}" -O "${toolchain_path}/${clang_file}" >/dev/null 2>&1 && sync
tar -xJf ${toolchain_path}/${clang_file} -C ${toolchain_path} && sync
rm -f ${toolchain_path}/${clang_file} && sync
[[ -d "${toolchain_path}/${clang_file//.tar.xz/}/bin" ]] || error_msg "The clang is not set!"
fi
fi
# Download armbian
if [[ ! -f "${armbian_file}" ]]; then
echo -e "${INFO} Download armbian [ ${armbian_rootfs_file} ] ..."
rm -rf ${armbian_path} 2>/dev/null && mkdir -p ${armbian_path}
wget -c "${dev_repo}/${armbian_rootfs_file}" -O "${armbian_path}/${armbian_rootfs_file}" >/dev/null 2>&1 && sync
tar -xJf ${armbian_path}/${armbian_rootfs_file} -C ${armbian_path} && sync
mv -f ${armbian_path}/*.img ${armbian_file} && sync
rm -f ${armbian_path}/${armbian_rootfs_file} && sync
[[ -f "${armbian_file}" ]] || error_msg "There is no armbian file: [ ${armbian_file} ]"
fi
}
query_version() {
cd ${make_path}
# 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.100"
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="180"
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}
# kernel_folder > kernel_.tar.xz_file > download_from_kernel.org
echo -e "${STEPS} Start query and download the kernel."
[[ -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 && sync
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 && sync
[[ -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 --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 && sync
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
sync
}
env_check() {
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} ]. \n"
# Create a temp directory
rm -rf ${out_kernel}/{chroot/,boot/,dtb/,modules/,header/,${kernel_version}/} 2>/dev/null && sync
mkdir -p ${out_kernel}/{chroot/{root/boot/,},boot/,dtb/{allwinner/,amlogic/,rockchip/},modules/,header/,${kernel_version}/} && sync
}
compile_kernel() {
cd ${kernel_path}/${local_kernel_path}
echo -e "${STEPS} Set cross compilation parameters."
# Set cross compilation parameters
export ARCH="arm64"
export LOCALVERSION="${custom_name}"
if [[ "${host_release}" == "jammy" ]]; then
export CROSS_COMPILE="aarch64-linux-gnu-"
export CC="clang"
export LD="ld.lld"
else
export CROSS_COMPILE="${toolchain_path}/${gcc_file//.tar.xz/}/bin/aarch64-none-linux-gnu-"
export CC="${toolchain_path}/${clang_file//.tar.xz/}/bin/clang"
export LD="${toolchain_path}/${clang_file//.tar.xz/}/bin/ld.lld"
#
# Add $PATH variable
path_ubuntu="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
path_clang="${toolchain_path}/${clang_file//.tar.xz/}/bin:${path_ubuntu}"
# Set $PATH variable for ~/.bashrc
sed -i '/^PATH=/d' ~/.bashrc 2>/dev/null && sync
echo "PATH=${path_clang}" >>~/.bashrc && sync
source ~/.bashrc
# Set $PATH variable for /etc/profile
sed -i '/^PATH=/d' /etc/profile 2>/dev/null && sync
echo "PATH=${path_clang}" >>/etc/profile && sync
source /etc/profile
fi
# 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} LLVM=1 LLVM_IAS=1 LOCALVERSION=${LOCALVERSION} "
# Make clean/mrproper
make ${MAKE_SET_STRING} clean
# Make menuconfig
#make ${MAKE_SET_STRING} menuconfig
# Check .config file
if [[ ! -s ".config" ]]; then
# Copy config file
echo -e "${INFO} Copy config file to ${local_kernel_path}"
config_demo="$(ls ${config_path}/config-${kernel_verpatch}* 2>/dev/null | sort -rV | head -n 1)"
config_demo_file="${config_demo##*/}"
[[ -z "${config_demo_file}" ]] && error_msg "Missing [ config-${kernel_verpatch}* ] template!"
echo -e "${INFO} CONFIG_DEMO: [ ${config_path}/${config_demo_file} ]"
cp -f ${config_path}/${config_demo_file} .config && sync
else
echo -e "${INFO} Use the .config file in the current directory."
fi
#
sed -i "s|CONFIG_LOCALVERSION=.*|CONFIG_LOCALVERSION=\"\"|" .config
sync
# Enable/Disabled Linux Kernel Clang LTO
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 kernel
echo -e "${STEPS} Start compilation kernel [ ${local_kernel_path} ]..."
PROCESS="$(cat /proc/cpuinfo | grep "processor" | wc -l)"
[[ -z "${PROCESS}" ]] && PROCESS="1" && echo "PROCESS: 1"
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 ..."
make ${MAKE_SET_STRING} INSTALL_HDR_PATH=${out_kernel}/header 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} && sync
# 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} 2>/dev/null && sync
#
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}
sync
#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/* 2>/dev/null && sync
cp -rf ${out_kernel}/modules/lib/modules/${kernel_outname} ${tag_rootfs}/usr/lib/modules && sync
#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} && sync
echo "COMPRESS=gzip" >>${compress_initrd_file} && sync
[[ -f "/usr/bin/${qemu_binary_arm}" ]] && cp -f /usr/bin/${qemu_binary_arm} ${tag_rootfs}/usr/bin/ && sync
[[ -f "/usr/bin/${qemu_binary_arm64}" ]] && cp -f /usr/bin/${qemu_binary_arm64} ${tag_rootfs}/usr/bin/ && sync
#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 2>/dev/null && sync
chmod +x ${tag_rootfs}/root/ubuntu_chroot_armbian.sh 2>/dev/null
#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}"
[[ "${?}" -ne "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_kernel() {
# Pack the kernel 6 files
echo -e "${STEPS} Packing the 6 [ ${kernel_outname} ] kernel packages..."
cd ${out_kernel}/boot
chmod +x *
tar -czf boot-${kernel_outname}.tar.gz * && sync
mv -f *.tar.gz ${out_kernel}/${kernel_version} && sync
echo -e "${SUCCESS} The [ boot-${kernel_outname}.tar.gz ] file is packaged."
cd ${out_kernel}/dtb/allwinner
cp -f ${kernel_path}/${local_kernel_path}/arch/arm64/boot/dts/allwinner/*.dtb . && chmod +x * && sync
tar -czf dtb-allwinner-${kernel_outname}.tar.gz * && sync
mv -f *.tar.gz ${out_kernel}/${kernel_version} && sync
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 * && sync
tar -czf dtb-amlogic-${kernel_outname}.tar.gz * && sync
mv -f *.tar.gz ${out_kernel}/${kernel_version} && sync
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 * && sync
tar -czf dtb-rockchip-${kernel_outname}.tar.gz * && sync
mv -f *.tar.gz ${out_kernel}/${kernel_version} && sync
echo -e "${SUCCESS} The [ dtb-rockchip-${kernel_outname}.tar.gz ] file is packaged."
cd ${out_kernel}/modules/lib/modules
tar -czf modules-${kernel_outname}.tar.gz * && sync
mv -f *.tar.gz ${out_kernel}/${kernel_version} && sync
echo -e "${SUCCESS} The [ modules-${kernel_outname}.tar.gz ] file is packaged."
cd ${out_kernel}/header
tar -czf header-${kernel_outname}.tar.gz * && sync
mv -f *.tar.gz ${out_kernel}/${kernel_version} && sync
echo -e "${SUCCESS} The [ header-${kernel_outname}.tar.gz ] file is packaged."
cd ${out_kernel}/${kernel_version}
sha256sum * >sha256sums && sync
echo -e "${SUCCESS} The [ sha256sums ] file has been generated"
cd ${out_kernel}
tar -czf ${kernel_version}.tar.gz ${kernel_version} && sync
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}/} 2>/dev/null && sync
update-grub 2>/dev/null
echo -e "${SUCCESS} Space cleared successfully."
sync
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.100 ]
kernel_version="${k}"
# kernel_verpatch, such as [ 5.10 ]
kernel_verpatch="$(echo ${kernel_version} | awk -F '.' '{print $1"."$2}')"
# kernel_sub, such as [ 100 ]
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
env_check
compile_kernel
generate_uinitrd
packit_kernel
clean_tmp
let j++
done
}
# Check script permission, supports running on x86_64 Ubuntu: [ jammy / focal ]
[[ "$(id -u)" == "0" ]] || error_msg "Please run this script as root: [ sudo ./${0} ]"
[[ -n "${host_release}" && "jammy focal" == *"${host_release}"* ]] || error_msg "Supports running on Ubuntu: [ jammy / focal ]"
[[ "${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 "Welcome to compile kernel! \n"
echo -e "Server running on Ubuntu: [ Release: ${host_release} / Host: ${arch_info} ] \n"
echo -e "Server CPU configuration information: \n$(cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c) \n"
echo -e "Server memory usage: \n$(free -h) \n"
echo -e "Server space usage before starting to compile: \n$(df -hT ${make_path}) \n"
echo -e "Setting parameters: [ ${@} ] \n"
#
# Initialize variables, download the kernel source code and check the toolchain
init_var "${@}"
[[ "${auto_kernel}" == "true" ]] && query_version
echo -e "Kernel from: [ ${code_owner} ]"
echo -e "Kernel List: [ $(echo ${build_kernel[*]} | tr "\n" " ") ] \n"
toolchain_check
# Loop to compile the kernel
loop_recompile
#
# Show server end information
echo -e "${INFO} Server space usage after compilation: \n$(df -hT ${make_path}) \n"
# All process completed
wait
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xiayang0521/amlogic-s9xxx-armbian.git
git@gitee.com:xiayang0521/amlogic-s9xxx-armbian.git
xiayang0521
amlogic-s9xxx-armbian
amlogic-s9xxx-armbian
main

搜索帮助

344bd9b3 5694891 D2dac590 5694891