準備源碼包(prepare source code pacakge) 3.0.35版本代碼(3.0.35 version code)u-boot源碼(u-boot source code) 文件名:u-boot-2009.08--svn*.tar.xz name of file:u-boot-2009.08--svn*.tar.xz kernel源碼(kernel source code) 文件名:linux-3.0.35--svn*.tar.xz name of file:linux-3.0.35--svn*.tar.xz 交叉編譯工具 (cross compifer tool) 文件名:gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12.tar.bz2 name of file:gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12.tar.bz2 配置編譯環(huán)境(configuration of compifer environment) 準備源碼(prepare source code)準備源碼包 (prepare source code package) 1)創(chuàng)建工作目錄 create working directory 創(chuàng)建 ~/my-imx6 作為工作目錄 create ~/my-imx6 as working directory $ mkdir ~/my-imx6 創(chuàng)建 ~/my-imx6/02_source/imx_3.0.35_4.1.0 作為源碼目錄 create ~/my-imx6/02_source/imx_3.0.35_4.1.0 as source code directory $ mkdir ~/my-imx6/02_source/imx_3.0.35_4.1.0 -p 創(chuàng)建 ~/my-imx6/03_tools 作為工具目錄 create ~/my-imx6/03_tools as tool directory $ mkdir ~/my-imx6/03_tools -p 2)復制源碼包到開發(fā)主機中 copy source code package to the development host 這一步驟自己采取相應的方式進行。 do it in this step in your own way。 提示:這里將網盤中“02_源碼”復制到Linux開發(fā)主機的“~/my-imx6/02_source/imx_3.0.35_4.1.0”,將網盤中“03_工具/toolchain”復制到Linux開發(fā)主機的“~/my-imx6/03_tools”。 tip:this step is to copy “02_source code”from network disk to “~/my-imx6/02_source/imx_3.0.35_4.1.0”in development host,and copy “03_tool/toolchain”to “~/my-imx6/03_tools”。in development host 解壓源碼包 (decompress source code package) 1)解壓u-boot源碼和內核源碼 decompress u-boot source code and kernel source code $ cd ~/my-imx6/02_source/imx_3.0.35_4.1.0 $ tar xf u-boot-2009.08--svn*.tar.xz $ tar xf linux-3.0.35--svn*.tar.xz 2)解壓交叉編譯工具 decompress cross compiler tool $ cd ~/my-imx6/03_tools/ $ tar jxf gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12.tar.bz2 開發(fā)環(huán)境配置(development environment configuration)安裝需要的包 (install package needed) 1)更新源列表 list of updated source $ sudo apt-get update 更新完成后如下圖所示: after update,it will look like below: 2)安裝aptitude包管理工具和ia32-libs install aptitude package management tool and ia32-libs 提示:如果編譯主機的Linux是32位的,可以跳過此步驟。 tips:if Linux of compiler host is 32bit,you can skip this step。
install aptitude package management tool $ sudo apt-get –y install aptitude
install ia32-libs with aptitude $ sudo aptitude –y install ia32-libs 提示:下圖為安裝過aptitude和ia32-libs后,再次執(zhí)行安裝命令的截圖。 tips:following is the screenshots with re-execution of installation command after installation of aptitude and ia32-libs is finished。 3)安裝mkimage工具 install mkimage tool $ sudo apt-get -y install uboot-mkimage 提示:下圖為安裝過mkimage工具后,再次執(zhí)行安裝命令的截圖。 tips:following is the screenshots with re-execution of installation command after installation of mkimage tool is finished。 4)安裝ncurses-dev install ncurses-dev 說明:make menuconfig對其具有依賴性質。 instruction:make menuconfig is dependent on it。 $ sudo aptitude -y install ncurses-dev 提示:下圖為安裝過ncurses-dev工具后,再次執(zhí)行安裝命令的截圖。 配置MY-IMX6編譯的環(huán)境變量 (configure environment variables of MY-IMX6 compilation)tips:following is the screenshots with re-execution of installation command after installation of ncurses-dev tool is finished。 1)將平臺信息寫入到一個新的配置文件 write platform information to a new configured file $ echo "export ARCH=arm" > ~/my-imx6/03_tools/myimx6_3035_build_env 2)將交叉編譯工具鏈路徑寫入到配置文件 write compiler tool chain path to configured file
enter cross compiler tool directory $ cd ~/my-imx6/03_tools/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/
write path to configured file $ sed -i "\$a IMX6_GCC462_PATH=$PWD" ~/my-imx6/03_tools/myimx6_3035_build_env
write cross compiler tool to configured file $ sed -i "\$a export CROSS_COMPILE=\$IMX6_GCC462_PATH/arm-none-linux-gnueabi-" ~/my-imx6/03_tools/myimx6_3035_build_env 3)查看配置文件 view configured file $ cat ~/my-imx6/03_tools/myimx6_3035_build_env 4)附圖 figures 注意:如果在某一步操作錯誤,則需要刪除 ~/my-imx6/03_tools/myimx6_3035_build_env 文件,并重新按照本小節(jié)操作。 note:if an error occurs in any step, need to delect ~/my-imx6/03_tools/myimx6_3035_build_env ,and operate again all steps of this segment。 編譯u-boot(compile u-boot) 進入u-boot源碼目錄(enter u-boot source code directory) $ cd ~/my-imx6/02_source/imx_3.0.35_4.1.0/u-boot-2009.08/ 使配置文件生效(validate configured file)
execute source command $ source ~/my-imx6/03_tools/myimx6_3035_build_env
view compiler configuration $ echo $ARCH $ echo $CROSS_COMPILE 提示:可看到ARCH和CROSS_COMPILE被設置 tips:you can see that ARCH和CROSS_COMPILE is configured
verify cross compiler tool configuration $${CROSS_COMPILE}gcc –v 提示:執(zhí)行命令后可以看到終端顯示出交叉編譯工具的版本信息。如下圖: tips:you can see version information of cross compiler tool shown on terminal after execution of command.as below: 清除u-boot配置(remove u-boot configuration) $ make distclean u-boot配置(u-boot configuration)
evaluation board and its corresponding u-boot compiler configuration:
MYIMX6EK200-6Qxx-1G configuration example: $ make myimx6ek200_6q_config 編譯(compilation)
execute compilation $ make 提示:這里為了提高編譯速度,在make后面加了“-j4”。這里編譯的Linux主機是雙核4線程的,所以“-j”后面用了4,也就是采用4線程編譯。“-j”后面的數(shù)字可以根據(jù)系統(tǒng)資源分配,但是不應該超過編譯主機最大支持的線程數(shù)。 Tips:To speed up the compilation,add "-j4" after make.The Linux host used to compile is dual-core ,4 threads .So "-j" is followed by 4, which takes 4 threads to compile. The number behind "-j" is allocated based on system resources,but It should not exceed the maximum threads the host support。
complete compilation 提示:u-boot編譯過程大概需要幾分鐘時間。 tips:u-boot compilation process will take a few minustes or so。 目標文件(target file) 編譯完成后通過ls命令即可看到編譯得到的目標文件u-boot.bin you can get the compiled file u-boot.bin with ls command after compilation $ ls 編譯內核(compile kernel) 進入內核源碼目錄(enter kernel source directory) $ cd ~/my-imx6/02_source/imx_3.0.35_4.1.0/linux-3.0.35/ 使配置文件生效(validate configured file)
execute source command $ source ~/my-imx6/03_tools/myimx6_3035_build_env
view compiler configuration $ echo $ARCH $ echo $CROSS_COMPILE 提示:可看到ARCH和CROSS_COMPILE被設置 tips:you can see that ARCH和CROSS_COMPILE is configured
verify cross compiler tool configuration $ ${CROSS_COMPILE}gcc –v 提示:執(zhí)行命令后可以看到終端顯示出交叉編譯工具的版本信息。如下圖: tips:you can see version information of cross compiler tool shown on terminal after execution of command.as below: 準備配置內核(prepare for kernel configuration)
remove kernel configuration $ make distclean
generated.config file 說明:MY-IMX6-EK200系列評估板及MY-IMX6-EK314系列評估板使用的配置文件是myimx6_defconfig instructions:configuration files used for MY-IMX6-EK200 seires of evaluation board and MY-IMX6-EK314 series of evaluation board is myimx6_defconfig $ make myimx6_defconfig 編譯內核(compile kernel)
compile uImage $ make uImage 說明:截圖中使用了4線程編譯。 instruction:4 threads compilation is used in the screenshots。
complete compilation
target file arch/arm/boot/uImage即為編譯得到的目標文件,使用ls命令可查看文件信息。 arch/arm/boot/uImage is the target file through compilation,you can view the file information with ls command。 $ ls arch/arm/boot/uImage –la 編譯模塊(compile module)
compile $ make 說明:截圖中使用了4線程編譯。 instruction:4 threads compilation is used in the screenshots。
complete compilation
target file 編譯完成后各模塊的.ko文件位于代碼所在的目錄,通過find命令可以找出編譯完成的模塊,參考命令如下: .ko file of each module is in the directory where code is located after compilation ,you can find the module compiled with find command after compilation,refering command as below: $ find -name *.ko Linux應用程序編譯(Linux application compilation) 編寫應用程序(write application) 1) 創(chuàng)建應用程序目錄 create application directory $ mkdir ~/my-imx6/02_source/application/ -p $ cd ~/my-imx6/02_source/application/ 2) 編寫應用程序(這里以hello.c為例) 創(chuàng)建 hello.c 文件寫入以下代碼并保存:
int main(int argc, char **argv) { printf("Hello, MYZR!\n"); return; } 3) 查看代碼 $ cat hello.c 使編譯配置文件生效(validate compiler configured file)
$ source ~/my-imx6/03_tools/myimx6_3035_build_env
$ echo $ARCH $ echo $CROSS_COMPILE 提示:可看到ARCH和CROSS_COMPILE被設置
$ ${CROSS_COMPILE}gcc –v 提示:執(zhí)行命令后可以看到終端顯示出交叉編譯工具的版本信息。如下圖: 編譯應用程序 (compile application) 2) 編譯 $ ${CROSS_COMPILE}gcc hello.c -o hello.out 注意:上面的命令有包含“$”號,即“${CROSS_COMPILE}gcc”,是引用我們source時產生的環(huán)境變量。 3) 查看目標文件類型 $ file hello.out 可以看到目標文件 hello.out 的屬性。 文件系統(tǒng)(file system) 文件系統(tǒng)說明(file system instruction) 文件系統(tǒng)包位于網盤對應的鏡像文件夾中。支持的文件系統(tǒng)類型及下載方式可參照《MY-IMX6 燒錄指導》。 解壓文件系統(tǒng)到編譯主機(decompress file system to compiler host) 1)創(chuàng)建文件系統(tǒng)的目錄并進入 $ mkdir ~/my-imx6/04_rootfs/ -p $ cd ~/my-imx6/04_rootfs/ 2)將文件系統(tǒng)復制到~/my-imx6/04_rootfs/目錄 這一步驟自己采取相應的方式進行 3)解壓文件系統(tǒng)到指定目錄 $ mkdir rootfs $ sudo tar jxf rootfs-linux.tar.bz2 -C rootfs 添加應用到文件系統(tǒng)(add application to file system) $ cp ~/my-imx6/02_source/application/hello.out rootfs/app_test/ 5)重新打包文件系統(tǒng) $ rm -rf rootfs-linux.tar.bz2 $ cd rootfs/ $ sudo tar cjf ../rootfs-linux.tar.bz2 * 添加模塊到文件系統(tǒng)(add module to file system) 準備需要模塊的.ko文件,其它請參照“添加應用到文件系統(tǒng)”。 |