使用defconfig生成的配置都比较全,编译出来的内核都比较大,有没有一个最小配置呢,可以通过tinyconfig生成一个最小配置。
打开V=1选项,编译tinyconfig。日志如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | ARCH="arm64" CROSS_COMPILE=/home/yuanjp/toolchain/crosstool-mt7981/bin/aarch64-linux-gnu- make -C /home/yuanjp/Xrouter/staging/source/linux-6.6.31 O=/home/yuanjp/Xrouter/staging/mt7981/linux-6.6.31 tinyconfig make[1]: Entering directory '/home/yuanjp/Xrouter/staging/source/linux-6.6.31' make -C /home/yuanjp/Xrouter/staging/mt7981/linux-6.6.31 \ -f /home/yuanjp/Xrouter/staging/source/linux-6.6.31/Makefile tinyconfig make[2]: Entering directory '/home/yuanjp/Xrouter/staging/mt7981/linux-6.6.31' make --no-print-directory -C /home/yuanjp/Xrouter/staging/mt7981/linux-6.6.31 \ -f /home/yuanjp/Xrouter/staging/source/linux-6.6.31/Makefile tinyconfig ln -fsn /home/yuanjp/Xrouter/staging/source/linux-6.6.31 source # GEN Makefile { echo "# Automatically generated by /home/yuanjp/Xrouter/staging/source/linux-6.6.31/Makefile: don't edit"; echo "include /home/yuanjp/Xrouter/staging/source/linux-6.6.31/Makefile"; } > Makefile test -e .gitignore || \ { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore make -f /home/yuanjp/Xrouter/staging/source/linux-6.6.31/scripts/Makefile.build obj=scripts/basic make -f /home/yuanjp/Xrouter/staging/source/linux-6.6.31/scripts/Makefile.build obj=scripts/kconfig tinyconfig KCONFIG_ALLCONFIG=kernel/configs/tiny-base.config make -f /home/yuanjp/Xrouter/staging/source/linux-6.6.31/Makefile allnoconfig ln -fsn /home/yuanjp/Xrouter/staging/source/linux-6.6.31 source # GEN Makefile { echo "# Automatically generated by /home/yuanjp/Xrouter/staging/source/linux-6.6.31/Makefile: don't edit"; echo "include /home/yuanjp/Xrouter/staging/source/linux-6.6.31/Makefile"; } > Makefile test -e .gitignore || \ { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore make -f /home/yuanjp/Xrouter/staging/source/linux-6.6.31/scripts/Makefile.build obj=scripts/basic make -f /home/yuanjp/Xrouter/staging/source/linux-6.6.31/scripts/Makefile.build obj=scripts/kconfig allnoconfig scripts/kconfig/conf --allnoconfig Kconfig # # configuration written to .config # make -f /home/yuanjp/Xrouter/staging/source/linux-6.6.31/Makefile tiny.config ln -fsn /home/yuanjp/Xrouter/staging/source/linux-6.6.31 source # GEN Makefile { echo "# Automatically generated by /home/yuanjp/Xrouter/staging/source/linux-6.6.31/Makefile: don't edit"; echo "include /home/yuanjp/Xrouter/staging/source/linux-6.6.31/Makefile"; } > Makefile test -e .gitignore || \ { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore make -f /home/yuanjp/Xrouter/staging/source/linux-6.6.31/scripts/Makefile.build obj=scripts/basic make -f /home/yuanjp/Xrouter/staging/source/linux-6.6.31/scripts/Makefile.build obj=scripts/kconfig tiny.config sh /home/yuanjp/Xrouter/staging/source/linux-6.6.31/scripts/kconfig/merge_config.sh -m .config /home/yuanjp/Xrouter/staging/source/linux-6.6.31/kernel/configs/tiny.config Using .config as base Merging /home/yuanjp/Xrouter/staging/source/linux-6.6.31/kernel/configs/tiny.config Value of CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE is redefined by fragment /home/yuanjp/Xrouter/staging/source/linux-6.6.31/kernel/configs/tiny.config: Previous value: CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y New value: # CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE is not set Value of CONFIG_CC_OPTIMIZE_FOR_SIZE is redefined by fragment /home/yuanjp/Xrouter/staging/source/linux-6.6.31/kernel/configs/tiny.config: Previous value: # CONFIG_CC_OPTIMIZE_FOR_SIZE is not set New value: CONFIG_CC_OPTIMIZE_FOR_SIZE=y Value of CONFIG_SLUB_TINY is redefined by fragment /home/yuanjp/Xrouter/staging/source/linux-6.6.31/kernel/configs/tiny.config: Previous value: # CONFIG_SLUB_TINY is not set New value: CONFIG_SLUB_TINY=y # # merged configuration written to .config (needs make) # make -f /home/yuanjp/Xrouter/staging/source/linux-6.6.31/Makefile olddefconfig ln -fsn /home/yuanjp/Xrouter/staging/source/linux-6.6.31 source # GEN Makefile { echo "# Automatically generated by /home/yuanjp/Xrouter/staging/source/linux-6.6.31/Makefile: don't edit"; echo "include /home/yuanjp/Xrouter/staging/source/linux-6.6.31/Makefile"; } > Makefile test -e .gitignore || \ { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore make -f /home/yuanjp/Xrouter/staging/source/linux-6.6.31/scripts/Makefile.build obj=scripts/basic make -f /home/yuanjp/Xrouter/staging/source/linux-6.6.31/scripts/Makefile.build obj=scripts/kconfig olddefconfig scripts/kconfig/conf --olddefconfig Kconfig # # configuration written to .config # make[2]: Leaving directory '/home/yuanjp/Xrouter/staging/mt7981/linux-6.6.31' make[1]: Leaving directory '/home/yuanjp/Xrouter/staging/source/linux-6.6.31' |
它执行的是allnoconfig+tiny.config。
tiny.config调用scripts/kconfig/merge_config.sh合并allnoconfig生成的.config和kernel/configs/tiny.config
编译:
$ TIME=%e time make kernel/compile -j12
kernel/prepare
kernel/compile
23.02
12线程编译,只花了23s。
查看编译结果,可以看到vmlinux才2M,Image才1.8M,压缩后的Image才721K。
$ ls -l arch/arm64/boot/ vmlinux*
-rwxr-xr-x. 1 yuanjp yuanjp 2271712 May 26 09:13 vmlinux
-rw-r--r--. 1 yuanjp yuanjp 30590 May 26 09:13 vmlinux.a
-rw-r--r--. 1 yuanjp yuanjp 3426824 May 26 09:13 vmlinux.o
-rw-r--r--. 1 yuanjp yuanjp 0 May 26 09:13 vmlinux.symvers
arch/arm64/boot/:
total 2208
-rwxr-xr-x. 1 yuanjp yuanjp 1802248 May 26 09:13 Image
-rw-r--r--. 1 yuanjp yuanjp 721985 May 26 09:13 Image.gz