Linux kernel 编译方法大全记录
一、这是一个我自己写的自动make脚本:
#!/bin/shexport ARCH=armexport CROSS_COMPILE=arm-linux-gnueabihf- export CHEN_DTB="chenfl.dtb" if [ 1 -eq $# ]; then if [ $1 = "dtb" ]; then make -j2 $CHEN_DTB O=out cp ~/am335x/kernel4.4.12/out/arch/arm/boot/dts/am335x-chenfl.dtb $CHEN_PATH -rf # cp ~/am335x/kernel4.4.12/out/arch/arm/boot/dts/am335x-sbc7109.dtb $CHEN_PATH -rf sync echo "Copy dts over ...\n" elif [ $1 = "defconfig" ]; then make -j2 aplex_sbc7109_defconfig O=out echo "Use aplex_sbc7109_defconfig over ...\n" elif [ $1 = "menuconfig" ]; then make -j2 $1 O=out elif [ $1 = "zImage" ]; then make -j2 $1 O=out cp ~/am335x/kernel4.4.12/out/arch/arm/boot/zImage $CHEN_PATH -rf sync echo "Copy kernel zImage to myself file over ... \n" elif [ $1 = "all" ]; then make -j2 $1 O=out cp ~/am335x/kernel4.4.12/out/arch/arm/boot/zImage $CHEN_PATH -rf cp ~/am335x/kernel4.4.12/out/arch/arm/boot/dts/am335x-sbc7109.dtb $CHEN_PATH -rf sync echo "Copy kernel image and dts over ... \n" elif [ $1 = "savedefconfig" ]; then make $1 O=out echo "Save .config to defconfig over ... \n" elif [ $1 = "clean" ]; then make $1 O=out echo "Clean out over ...\n" elif [ $1 = "distclean" ]; then make $1 O=out echo "Distclean over ...\n" elif [ $1 = "help" ]; then make $1 else echo " " echo "You can following command to do the thing you want to do..." echo "./remake dtb -- Only cross-complie your device tree table" echo "./remake defconfig -- Only configure your defconfig" echo "./remake menuconfig -- Only configure your configuration" echo "./remake zImage -- Only cross-complie your Linux kernel zImage " echo "./remake all -- Cross-complie kernel and dts" echo "./remake savedefconfig -- Save your .config as defconfig " echo "./remake clean -- Clean your output file" echo "./remake distclean -- Deep clean your output file" echo "./remake help -- Check help infomation " fielse echo " " echo "You can following command to do the thing you want to do..." echo "./remake dtb -- Only cross-complie your device tree table" echo "./remake defconfig -- Only configure your defconfig" echo "./remake menuconfig -- Only configure your configuration" echo "./remake zImage -- Only cross-complie your Linux kernel zImage " echo "./remake all -- Cross-complie kernel and dts" echo "./remake savedefconfig -- Save your .config as defconfig " echo "./remake clean -- Clean your output file" echo "./remake distclean -- Deep clean your output file" echo "./remake help -- Check help infomation "fi
二、当你指定ARCH=arm 之后,如下命令运行,则会出现arm相关kernel的help信息。
make ARCH=arm help这里面完全介绍了有关arm kernel make的帮助信息。
三、挑几个重点的讲解一下。
编译的时候,首先, 指定芯片的架构以及交叉编译器前缀。export ARCH=armexport CROSS_COMPILE=arm-linux-gnueabihf- make clean除了保存config文件以及构建外围模块必要的文件其他的全部清除。make mrproper清理全部生成的文件+config文件+不同的备份文件make distcleanclean + mrproper , 彻底的清理执行完上面的步骤之后。选择一个自己的产品参考的defconfig文件在arch/arm/configs/ 里面,这里面全部都是你可以选择的defconfig例如:make omap2plus_defconfig O=outO 的指定是指output file 的意思,此时会在out文件夹下生成.config 文件。当然,你应该还有一些想要添加的,我这里直接使用menuconfig进行配置make menuconfig O=out配置好了,你想要保存.config文件为自己的配置的一个备份。make savedefconfig O=out这时在out文件夹下就会有一个defconfig文件当所有的都配置好了,现在,你想编译自己的设备树chenfl.dtsmake -j2 chenfl.dtb O=out你想编译自己的镜像zImagemake -j2 zImage O=out你想编译自己的模块make -j2 modules O=out你想编译所有的东西make -j2 all O=out好了,所有常用的make功能介绍完毕。zImage 在out/arch/arm/boot/zImagechenfl.dtb 在out/arch/arm/boot/dts/chenfl.dtbdefconfig 你可以复制到arm/arch/configs/ 里面,后缀必须是defconfig
不正望指出谢谢。