嵌入式Linux--MYS-6ULX-IOT--构建交叉编译环境

参考官方文档:《MYS-6ULX Linux 开发手册》

资料下载地址:http://down.myir-tech.com/MYS-6ULX/

一、部署开发环境

 开发前需要安装好Linux操作系统,推荐使用Ubuntu 16.04 64bit发行版,连接网线并配置好网络,后续操作需要连接互联网安装或下载相关软件包。

1、安装必备软件包

sudo apt-get install build-essential git-core libncurses5-dev \
flex bison texinfo zip unzip zlib1g-dev gettext u-boot-tools \
g++ xz-utils mtd-utils gawk diffstat gcc-multilib python git \
make gcc g++ diffstat bzip2 gawk chrpath wget cpio texinfo lzop

2、建立工作目录

 建立工作目录,方便设置统一的环境变量路径。拷贝产品光盘中的源码到工作目录下,同时设置DEV_ROOT变量,方便后续步骤的路径访问。

直接在linux上面的MYS6ULx-devel目录下面下载:wget -c http://down.myir-tech.com/MYS-6ULX/MYS-6ULX-20190312-M12.iso

mkdir -p ~/MYS6ULx-devel
export DEV_ROOT=~/MYS6ULx-devel
cp -r <DVDROM>/02-Images $DEV_ROOT
cp -r <DVDROM>/03-Tools $DEV_ROOT
cp -r <DVDROM>/04-Source $DEV_ROOT

3、配置编译工具

  • Linaro交叉编译器: gcc version 4.9.3 20141031 (prerelease) (Linaro GCC 2014.11)
  • Yocto交叉编译器: gcc version 5.3.0 (GCC)

 这里有两个编译器,一个是Linaro提供,另一个是由Yocto构建的,建议使用Yocto提供的,以便和文件系统统一。

1、Linaro编译器

cd $DEV_ROOT
tar -xvf 03-Tools/Toolchain/gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf.tar.xz
export PATH=$PATH:$DEV_ROOT/gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf/bin
export CROSS_COMPILE=arm-linux-gnueabihf-
export ARCH=arm

 执行完上述命令后输入"arm-linux-gnueabihf-gcc -v",若有输出版本信息,说明设置成功,以上设置只对当前终端有效。如需永久修改,请修改用户配置文件。

永久修改

修改环境变量:sudo vim /etc/profile
打开/etc/profile以后,在最后输入:

export PATH=$PATH:~/MYS6ULx-devel03-Tools/Toolchain/gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf/bin

然后重启虚拟机:reboot

$ arm-linux-gnueabihf-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/home/kevinchen/MYS6ULx/\
gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf/bin/../
libexec/gcc/arm-linux-gnueabihf/4.9.3/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: /home/buildslave/workspace/BinaryRelease/label/
x86_64/target/arm-linux-gnueabihf/snapshots/
gcc-linaro-4.9-2014.11/configure SHELL=/bin/bash --with-bugurl=
https://bugs.linaro.org
--with-mpc=/home/buildslave/workspace/BinaryRelease/label/x86_64
/target/arm-linux-gnueabihf/_build/builds/destdir/x86_64-unknown
-linux-gnu --with-mpfr=/home/buildslave/workspace/
BinaryRelease/label/x86_64/target/arm-linux-gnueabihf/_build/bui
lds/destdir/x86_64-unknown-linux-gnu
--with-gmp=/home/buildslave/workspace/BinaryRelease/label/x86_64
/target/arm-linux-gnueabihf/_build/builds/destdir/x86_64-unknown
-linux-gnu --with-gnu-as --with-gnu-ld --disable-libstdcxx-pch -
-disable-libmudflap --with-cloog=no --with-ppl=no --with-isl=no
--disable-nls --enable-multiarch --disable-multilib --enable-c99
--with-tune=cortex-a9 --with-arch=armv7-a --with-fpu=vfpv3-d16
--with-float=hard --with-mode=thumb --disable-shared --enable-
static --with-build-sysroot=/home/buildslave/workspace/BinaryRel
ease/label/x86_64/target/arm-linux-gnueabihf/_build/sysroots/arm
-linux-gnueabihf --enable-lto --enable-linker-build-id --enable-
long-long --enable-shared --with-sysroot=/home/buildslave/worksp
ace/BinaryRelease/label/x86_64arm-linux-gnueabihf/_build/builds/
destdir/x86_64-unknown-linux-gnu/libc --enable-languages=c,c++,
fortran,lto -enable-fix-cortex-a53-835769 --enable-checking=rele
ase --with-bugurl=https://bugs.linaro.org
--with-pkgversion='Linaro GCC 2014.11' --build=x86_64-unknown-li
nux-gnu --host=x86_64-unknown-linux-gnu --target=arm-linux-gnuea
bihf
--prefix=/home/buildslave/workspace/BinaryRelease/label/x86_64/t
arget/arm-linux-gnueabihf/_build/builds/destdir/x86_64-unknown-l
inux-gnu
Thread model: posix
gcc version 4.9.3 20141031 (prerelease) (Linaro GCC 2014.11)

2、Yocto编译工具链

 Yocto提供的工具链有两种,一种是底层开发的meta-toolchain,另一种是用于应用开发的工具链。
前者和Linaro类似,后者包含应用开发中的相关库,可以直接使用pkg-config工具来解决头文件或库文件的依赖关系。MYS-6ULX的资源包中有提供两种工具链。

工具链文件名描述
myir-imx-fb-glibc-x86_64-fsl-image-qt5-cortexa7hf-neon-toolchain-4.1.15-2.0.1.sh包含Qt5相关库的应用工具链
myir-imx-fb-glibc-x86_64-core-image-base-cortexa7hf-neon-toolchain-4.1.15-2.0.1.sh不包含Qt5的应用工具链
myir-imx-fb-glibc-x86_64-meta-toolchain-cortexa7hf-neon-toolchain-4.1.15-2.0.1.shmeta-toolchain

 Yocto编译器是以SDK工具包方式来提供,需要先安装SDK包后,才可以使用。安装方法如下:
以普通用户权限执行shell脚本,运行中会提示安装路径,默认在/opt目录下,同时会提示输入用户密码以便有写入目录的权限。安装完成后,可以使用"source"或"."命令加载工链接环境到当前终端。
例子: 把应用开发工具链安装在了/opt/myir-imx6ulx-fb/4.1.15-2.0.1目录下。

./myir-imx-fb-glibc-x86_64-fsl-image-qt5-cortexa7hf-neon-toolchain-4.1.15-2.0.1.sh
Freescale i.MX Release Distro SDK installer version 4.1.15-2.0.1
================================================================
Enter target directory for SDK (default: /opt/myir-imx-fb/4.1.15-2.0.1):
/opt/myir-imx6ulx-fb/4.1.15-2.0.1
Do You are about to install the SDK to "/opt/myir-imx6ulx-fb/4.1.15-2.0.1". Proceed[Y/n]? Y
[sudo] password for kevinchen:
Extracting SDK..................................................
................................................................
...............done
Setting it up...done
SDK has been successfully set up and is ready to be used.
Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
. /opt/myir-imx6ulx-fb/4.1.15-2.0.1/environment-setup-cortexa7hf-neon-poky-linux-gnueabi

 验证SDK工具链是否安装正确,先使用"source"命令加载Yocto的环境配置文件,然后查看编译器版本。

source /opt/myir-imx6ulx-fb/4.1.15-2.0.1/environment-setup-cortexa7hf-neon-poky-linux-gnueabi
arm-poky-linux-gnueabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-poky-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/opt/myir-imx6ulx-fb/4.1.15-2.0.1/sysroots/x
86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-p
oky-linux-gnueabi/5.3.0/lto-wrapper
Target: arm-poky-linux-gnueabi
Configured with: ../../../../../../work-shared/gcc-5.3.0-r0/gcc-
5.3.0/configure --build=x86_64-linux --host=x86_64-pokysdk-linux
--target=arm-poky-linux-gnueabi --prefix=/opt/myir-imx6ulx-fb/4.
1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr --exec_prefix=/opt/
myir-imx6ulx-fb/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr
--bindir=/opt/myir-imx6ulx-fb/4.1.15-2.0.1/sysroots/x86_64-pokys
dk-linux/usr/bin/arm-poky-linux-gnueabi
--sbindir=/opt/myir-imx6ulx-fb/4.1.15-2.0.1/sysroots/x86_64-poky
sdk-linux/usr/bin/arm-poky-linux-gnueabi --libexecdir=/opt/myir-
imx6ulx-fb/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexe
c/arm-poky-linux-gnueabi --datadir=/opt/myir-imx6ulx-fb/4.1.15-2
.0.1/sysroots/x86_64-pokysdk-linux/usr/share --sysconfdir=/opt/m
yir-imx6ulx-fb/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/etc
--sharedstatedir=/opt/myir-imx6ulx-fb/4.1.15-2.0.1/sysroots/x86_
64-pokysdk-linux/com
--localstatedir=/opt/myir-imx6ulx-fb/4.1.15-2.0.1/sysroots/x86_6
4-pokysdk-linux/var --libdir=/opt/myir-imx6ulx-fb/4.1.15-2.0.1/s
ysroots/x86_64-pokysdk-linux/usr/lib/
arm-poky-linux-gnueabi --includedir=/opt/myir-imx6ulx-fb/4.1.15-
2.0.1/sysroots/x86_64-pokysdk-linux/usr/include --oldincludedir=
/opt/myir-imx6ulx-fb/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/
usr/include --infodir=/opt/myir-imx6ulx-fb/4.1.15-2.0.1/
sysroots/x86_64-pokysdk-linux/usr/share/info
--mandir=/opt/myir-imx6ulx-fb/4.1.15-2.0.1/sysroots/x86_64-pokys
dk-linux/usr/share/man
--disable-silent-rules --disable-dependency-tracking
--with-libtool-sysroot=/home/kevinchen/mys-imx6ul/fsl-release-yo
cto/build/tmp/sysroots/x86_64-nativesdk-pokysdk-linux --with-gnu
-ld --enable-shared
--enable-languages=c,c++ --enable-threads=posix --enable-multili
b --enable-c99
--enable-long-long --enable-symvers=gnu --enable-libstdcxx-pch \
--program-prefix=arm-poky-linux-gnueabi- --without-local-prefix
--enable-lto --enable-libssp
--enable-libitm --disable-bootstrap --disable-libmudflap --with-
system-zlib
--with-linker-hash-style=gnu --enable-linker-build-id --with-ppl
=no --with-cloog=no
--enable-checking=release --enable-cheaders=c_global --without-i
sl
--with-gxx-include-dir=/not/exist/usr/include/c++/5.3.0
--with-build-time-tools=/home/kevinchen/mys-imx6ul/fsl-release-y
octo/build/tmp/sysroots/x86_64-linux/usr/arm-poky-linux-gnueabi/
bin --with-sysroot=/not/exist
--with-build-sysroot=/home/kevinchen/mys-imx6ul/fsl-release-yoct
o/build/tmp/sysroots/mys6ul14x14
--enable-poison-system-directories --with-mpfr=/home/kevinchen/m
ys-imx6ul/fsl-release-yocto/build/tmp/sysroots/x86_64-nativesdk-
pokysdk-linux --with-mpc=/home/kevinchen/mys-imx6ul/fsl-release-
yocto/build/tmp/sysroots/
x86_64-nativesdk-pokysdk-linux --enable-nls --with-arch=armv7-a
Thread model: posix
gcc version 5.3.0 (GCC)

 同样方法请自行安装底层开发的工具链meta-toolchain。安装两个工具链,请指定不同目录,请勿使用相同目录,出现文件相互覆盖情形。

二、构建系统

介绍MYS-6ULX开发板上, Linux操作系统相关部件的编译和使用。MYS-6ULX的Linux系统包含以下部件:

  • U-Boot: 引导程序,支持不同方式启动内核。
  • Linux Kernel: 适用于MYS-6ULX开发板的Linux 4.1.15内核,同时包含支持板载外设的驱动。
  • Yocto: 一个开源协作项目,提供丰富的模板、工具和方法来支持构建出面向嵌入式产品的自定义Linux系统。

编译u-boot和Linux内核代码前,请先安装meta-toolchain并加载环境变量到当前shell。

1.编译U-Boot

进入Bootloader目录,解压U-boot源码:

cd $DEV_ROOT/04-Source/
tar -xvf MYiR-iMX-uboot.tar.gz
cd MYiR-iMX-uboot

开始编译:

make distclean
make <config>
make

这里的是配置选项名称,不同的启动模式需使用不同的配置选项,MYS-6ULX开发板四种选项:

启动模式编译选项
MYS-6ULX-IND NAND Flashmys_imx6ul_14x14_nand_defconfig
MYS-6ULX-IND eMMC Flashmys_imx6ul_14x14_emmc_defconfig
MYS-6ULX-IoT NAND Flashmys_imx6ull_14x14_nand_defconfig
MYS-6ULX-IoT eMMC Flashmys_imx6ull_14x14_emmc_defconfig

u-boot启动时默认会先检测"boot.scr"文件,这个是u-boot上的脚本镜像文件,用于临时改变启动设
备或从Micro SD启动时,可以使用此文件。以下是"mys-imx6ul-boot-sdcard.txt"文件生成"boot.scr"文
件的例子,mkimage工具是在u-boot的tools目录下,u-boot编译完成后,mkimage也会被编译出来,
直接使用即可。

cat mys-imx6ul-boot-sdcard.txt
setenv mmcroot '/dev/mmcblk0p2 rootwait rw rootdelay=5 mem=256M'
setenv mmcargs 'setenv bootargs console=${console},${baudrate} \
root=${mmcroot} mtdparts=gpmi-nand:5m(boot),10m(kernel),1m(dtb),\
-(rootfs)'
run mmcargs
fatload mmc 0 0x83000000 zImage
fatload mmc 0 0x84000000 mys-imx6ul-14x14-evk-emmc.dtb
bootz 0x83000000 - 0x84000000
./tool/mkimage -A arm -T script -O linux -d \
mys-imx6ul-boot-sdcard.txt boot.scr

2.编译Linux Kernel

进入Kernel目录,解压内核源码:

cd $DEV_ROOT/Kernel
tar -xvf MYiR-iMX-Linux.tar.gz
cd MYiR-iMX-Linux

开始编译:

make distclean
make mys_imx6_defconfig
make zImage dtbs modules

编译完成后在"arch/arm/boot"目录会生成内核镜像文件zImage,在"arch/arm/boot/dts"目录会生成DTB文件。

DTB文件备注
mys-imx6ul-14x14-evk-emmc.dtbMYS-6ULX-IND eMMC
mys-imx6ul-14x14-evk-gpmi-weim.dtbMYS-6ULX-IND NAND
mys-imx6ul-14x14-evk-emmc-myb6ulx.dtbMYS-6ULX-IND eMMC 上安装MYB-6ULX扩展板
mys-imx6ul-14x14-evk-gpmi-weim-myb6ulx.dtbMYS-6ULX-IND NAND 上安装MYB-6ULX扩展板
mys-imx6ull-14x14-evk-emmc.dtbMYS-6ULX-IoT eMMC
mys-imx6ull-14x14-evk-gpmi-weim.dtbMYS-6ULX-IoT NAND
mys-imx6ull-14x14-evk-emmc-myb6ulx.dtbMYS-6ULX-IoT eMMC 上安装MYB-6ULX扩展板
mys-imx6ull-14x14-evk-gpmi-weim-myb6ulx.dtbMYS-6ULX-IoT NAND 上安装MYB-6ULX扩展板

MYS-6ULX板上的Micro SD卡槽是连接mmc0控制器,所有的dtb文件都是默认启用mmc0控制器。

添加有"myb6ulx"标识的dtb文件,是用于支持MYB-6ULX扩展板,已配置好MYB-6ULX上的
CAN,RS485,Ethernet,Camera和Audio功能,使用"myb6ulx"标识的dtb文件可以直接启动并使用
相关功能。使用前请先安装好MYB-6ULX扩展板至MYS-6ULX-IOT或MYS-6ULX-IND开发板上。

SD卡或eMMC方式启动时,U-Boot默认查找的文件是mys-imx6ul-14x14-evk-emmc.dtb或mys-
imx6ull-14x14-evk-emmc.dtb文件。因此,带有"myb6ulx"标识的文件,修改编译后需要重新命名为
对应文件名。由于NAND启动是从地址读数据,不受影响。

3.构建文件系统

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值