Skip to content

Commit

Permalink
Optimizing Kernel Compiled Code
Browse files Browse the repository at this point in the history
  • Loading branch information
ophub committed Jan 25, 2022
1 parent eabe120 commit 1ccd883
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
6 changes: 3 additions & 3 deletions compile-kernel/README.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

- ### 本地编译

1. 安装必要的软件包(脚本仅在 Ubuntu_20.04-x86_64 下做过测试)
1. 安装必要的软件包(脚本仅在 Ubuntu-20.04-x86_64 下做过测试)

```yaml
sudo apt-get update -y
Expand All @@ -50,9 +50,9 @@ sudo apt-get install -y $(curl -fsSL git.io/ubuntu-2004-server)

2. 如果本地的内核目录如 `compile-kernel/kernel/linux-5.4.170` 中没有 [.config](tools/config) 文件,将自动从 unifreq 分享的模板中复制相同内核系列的配置文件。

3. 内核编译完成后,将会按照 `unifreq` 分享的内核文件的组织方式自动打包成 6 个内核文件,并存放在 `compile-kernel/output` 目录下。这些内核文件会自动从当前内核编译的系统中自动清除。如果你想在当前 Armbian 系统安装,可进入对应的内核目录如 `compile-kernel/output/5.4.170` 下,执行 `armbian-update` 命令进行内核安装。内核中的 `headers` 文件默认安装在 `/use/local/include` 目录下。
3. 内核编译完成后,将会按照 `unifreq` 分享的内核文件的组织方式自动打包成 6 个内核文件,并存放在 `compile-kernel/output` 目录下。这些内核文件会自动从当前内核编译的系统中自动清除。可以将这 6 个内核文件上传到 `Armbian` 系统任意目录,如 `/opt/5.4.170` 目录下,并在此内核目录内执行 `armbian-update` 命令进行内核安装。内核中的 `headers` 文件默认安装在 `/use/local/include` 目录下。

4. 如果当前 `Armbian` 系统中已经安装了相同名称的内核如 `5.4.170-meson64-dev` ,将会自动停止编译,因为打包时会删除本地相同名称的内核文件,这么做会造成系统瘫痪。
4. 如果当前系统中已经安装了相同名称的内核如 `5.4.170-meson64-dev` ,将会自动停止编译,因为打包时会删除本地相同名称的内核文件,这么做会造成系统瘫痪。

5. 在内核测试时,请在 `USB/TF` 设备上进行测试,请不要贸然写入 `EMMC` 分区,避免成砖;在没有熟练地掌握救砖方法之前,请不要进行自定义内核测试;请不要在正式生产环境中测试自定义内核。

6 changes: 3 additions & 3 deletions compile-kernel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Compile a custom kernel as needed. This kernel can be used in [Armbian](https://

- ### Local compilation

1. Install the necessary packages (The script has only been tested on Ubuntu_20.04-x86_64)
1. Install the necessary packages (The script has only been tested on Ubuntu-20.04-x86_64)

```yaml
sudo apt-get update -y
Expand All @@ -50,9 +50,9 @@ sudo apt-get install -y $(curl -fsSL git.io/ubuntu-2004-server)

2. If there is no [.config](tools/config) file in the local kernel directory such as `compile-kernel/kernel/linux-5.4.170`, the file will be automatically copied from template.

3. After the kernel is compiled, it will be automatically packaged into 6 kernel files according to the organization of the kernel files shared by `unifreq` and stored in the `compile-kernel/output` directory. These kernel files will be automatically cleared from the system compiled with the current kernel. If you want to install on the current Armbian system, you can enter the corresponding kernel directory such as `compile-kernel/output/5.4.170` and execute the `armbian-update` command to install the kernel. The `headers` files in the kernel is installed in the `/use/local/include` directory.
3. After the kernel is compiled, it will be automatically packaged into 6 kernel files according to the organization of the kernel files shared by `unifreq` and stored in the `compile-kernel/output` directory. These kernel files will be automatically cleared from the system compiled with the current kernel. You can upload these 6 kernel files to any directory of `Armbian` system, such as `/opt/5.4.170` directory, and execute the `armbian-update` command in this kernel directory to install the kernel. The `headers` files in the kernel is installed in the `/use/local/include` directory.

4. If a kernel with the same name such as `5.4.170-meson64-dev` is already installed in the current `Armbian` system, the compilation will automatically stop, because the local kernel file with the same name will be deleted during packaging, which will cause the system to crash.
4. If a kernel with the same name such as `5.4.170-meson64-dev` is already installed in the current system, the compilation will automatically stop, because the local kernel file with the same name will be deleted during packaging, which will cause the system to crash.

5. During the kernel test, please test on the `USB/TF` device, and don't write to the `EMMC` partition rashly to avoid bricking; Please do not perform a custom kernel test before you have mastered the method of system recovery proficiently; Please do not test the custom kernel in a formal production environment.

32 changes: 14 additions & 18 deletions recompile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
#============================================================================================
#
# Description: Run on ubuntu-20.04, compile linux kernel for armbian
# Description: Run on Ubuntu-20.04-x86_64, compile linux kernel for armbian
# Copyright (C) 2020-2021 https://github.com/unifreq
# Copyright (C) 2020-2021 https://github.com/ophub/amlogic-s9xxx-armbian
#
Expand Down Expand Up @@ -64,10 +64,10 @@ armbian_file="${armbian_dir}/armbian.img"
chroot_dir="${out_kernel}/chroot"
chroot_file="${chroot_dir}/armbian.img"
# gcc
gcc_repo="https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel"
#gcc_repo="https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel"
gcc_file="gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.xz"
# clang
clang_repo="https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0"
#clang_repo="https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0"
clang_file="clang+llvm-13.0.0-x86_64-linux-gnu-ubuntu-20.04.tar.xz"

# QEMU BINARY
Expand Down Expand Up @@ -101,27 +101,30 @@ toolchain_check() {

# Download gcc
if [ ! -d "${toolchain_dir}/${gcc_file//.tar.xz/}/bin" ]; then
echo -e "${INFO} Download [ ${gcc_file} ] ..."
echo -e "${INFO} Download gcc [ ${gcc_file} ] ..."
wget -c "${dev_repo}/${gcc_file}" -O "${toolchain_dir}/${gcc_file}" >/dev/null 2>&1 && sync
tar -xJf ${toolchain_dir}/${gcc_file} -C ${toolchain_dir} && sync
rm -f ${toolchain_dir}/${gcc_file} && sync
[ -d "${toolchain_dir}/${gcc_file//.tar.xz/}/bin" ] || error_msg "The gcc is not set!"
fi

# Download clang
if [ ! -d "${toolchain_dir}/${clang_file//.tar.xz/}/bin" ]; then
echo -e "${INFO} Download [ ${clang_file} ] ..."
echo -e "${INFO} Download clang [ ${clang_file} ] ..."
wget -c "${dev_repo}/${clang_file}" -O "${toolchain_dir}/${clang_file}" >/dev/null 2>&1 && sync
tar -xJf ${toolchain_dir}/${clang_file} -C ${toolchain_dir} && sync
rm -f ${toolchain_dir}/${clang_file} && sync
[ -d "${toolchain_dir}/${clang_file//.tar.xz/}/bin" ] || error_msg "The clang is not set!"
fi

# Download armbian
if [ ! -f "${armbian_file}" ]; then
echo -e "${INFO} Download armbian from [ github.com/${armbian_repo}/releases ]..."
echo -e "${INFO} Download armbian [ ${armbian_rootfs_file} ]..."
rm -rf ${armbian_dir} 2>/dev/null && mkdir -p ${armbian_dir}
wget -c "${dev_repo}/${armbian_rootfs_file}" -O "${armbian_dir}/${armbian_rootfs_file}" >/dev/null 2>&1 && sync
tar -xJf ${armbian_dir}/${armbian_rootfs_file} -C ${armbian_dir} && sync
mv -f ${armbian_dir}/*.img ${armbian_file} && rm -f ${armbian_dir}/*.tar.xz && sync
mv -f ${armbian_dir}/*.img ${armbian_file} && sync
rm -f ${armbian_dir}/${armbian_rootfs_file} && sync
[ -f "${armbian_file}" ] || error_msg "There is no armbian file: [ ${armbian_file} ]"
fi
}
Expand Down Expand Up @@ -250,8 +253,8 @@ make_kernel() {
config_demo=$(ls ${config_dir}/config-${kernel_verpatch}* 2>/dev/null | 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_demo_file}"
cp -vf ${config_dir}/${config_demo_file} .config && sync
echo -e "${INFO} CONFIG_DEMO: [ ${config_dir}/${config_demo_file} ]"
cp -f ${config_dir}/${config_demo_file} .config && sync
else
echo -e "${STEPS} Use the .config file in the current directory."
fi
Expand Down Expand Up @@ -299,14 +302,9 @@ make_kernel() {
header_path="${out_kernel}/header"
make ${MAKE_SET_STRING} headers_install INSTALL_HDR_PATH=${header_path}
[ $? -eq 0 ] && echo -e "${SUCCESS} The headers is installed successfully."

# Install new image
#echo -e "${STEPS} Install new image ..."
#make ${MAKE_SET_STRING} install
#[ $? -eq 0 ] && echo -e "${SUCCESS} The new image is installed successfully."
}

update_initramfs() {
generate_uinitrd() {
cd ${make_path}
cp -f ${armbian_file} ${chroot_file} && sync

Expand Down Expand Up @@ -410,7 +408,6 @@ packit_kernel() {

clean_tmp() {
cd ${make_path}
# Update grub
echo -e "${STEPS} Clear the space and update-grub."

rm -rf ${out_kernel}/{chroot/,boot/,dtb/,modules/,header/,${kernel_version}/} 2>/dev/null && sync
Expand Down Expand Up @@ -516,14 +513,13 @@ for x in ${build_kernel[*]}; do
download_kernel
compile_env_check
make_kernel
update_initramfs
generate_uinitrd
packit_kernel
clean_tmp

let k++
done

#rm -rf ${armbian_dir} 2>/dev/null
sync
echo -e "${INFO} Server space usage after compilation: \n$(df -hT ${PWD}) \n"
exit 0

0 comments on commit 1ccd883

Please sign in to comment.