Linux kernel make 常用選項介紹


Linux kernel 編譯方法大全記錄

一、這是一個我自己寫的自動make腳本:

#!/bin/sh

export ARCH=arm
export 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 "
	fi
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 "
fi

二、當你指定ARCH=arm 之后,如下命令運行,則會出現arm相關kernel的help信息。

make ARCH=arm help
這里面完全介紹了有關arm kernel make的幫助信息。

三、挑幾個重點的講解一下。

編譯的時候,首先, 指定芯片的架構以及交叉編譯器前綴。
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabihf- 	

make clean
除了保存config文件以及構建外圍模塊必要的文件其他的全部清除。
make mrproper
清理全部生成的文件+config文件+不同的備份文件
make distclean
clean + mrproper , 徹底的清理


執行完上面的步驟之后。
選擇一個自己的產品參考的defconfig
文件在arch/arm/configs/ 里面,這里面全部都是你可以選擇的defconfig
例如:
make omap2plus_defconfig O=out
O 的指定是指output file 的意思,此時會在out文件夾下生成.config 文件。

當然,你應該還有一些想要添加的,我這里直接使用menuconfig進行配置
make menuconfig O=out

配置好了,你想要保存.config文件為自己的配置的一個備份。
make savedefconfig O=out
這時在out文件夾下就會有一個defconfig文件

當所有的都配置好了,現在,你想編譯自己的設備樹chenfl.dts
make -j2 chenfl.dtb O=out

你想編譯自己的鏡像zImage
make -j2 zImage O=out

你想編譯自己的模塊
make -j2 modules O=out

你想編譯所有的東西
make -j2 all O=out


好了,所有常用的make功能介紹完畢。
zImage 在out/arch/arm/boot/zImage
chenfl.dtb 在out/arch/arm/boot/dts/chenfl.dtb
defconfig 你可以復制到arm/arch/configs/ 里面,后綴必須是defconfig

不正望指出謝謝。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM