WhyCan Forum(哇酷论坛)

人过留名,雁过留声,感谢各位朋友不离不弃地支持。 QQ: 516333132, 微信: whycan_cn (哇酷网/挖坑网/填坑网) admin@whycan.cn

您尚未登录。

#1 2020-01-10 15:16:59

Jmhh247
会员
注册时间: 2018-12-21
累计积分: 193

[正点原子i.MX6UL开发板] 编译uboot、linux、buildroot-rootfs

关键字: 正点原子,i.MX6UL,linux, buildroot


- 主机环境:ubuntu16.04-64bit
- 硬件版本:正点原子i.MX6UL emmc



官方似乎没有提供 github ,所以相关代码、工具需要去论坛下载:

- 正点原子官方资料页:- [ 【Linux视频文档发布】正点原子150讲视频+1500页Linux教程发布,配套Alpha Linux开发板,请赶紧下载学习  ](http://www.openedv.com/thread-300792-1-1.html)



#### 友情提示:
百度云下载慢怎么办,不怕:配合本站免费提供的账号,可以享受尊贵的会员服务,详情点这里-- https://whycan.cn/t_3291.html

---



### 一、用buildroot制作根文件系统

- 出厂根文件系统用的是yocto,制作太难了。
- 用buildroot相对简单,相关支持可能不如yocto。
- 先制作根文件系统的目的是生成工具链。


使用buildroot2017,这里下载:buildroot-2017_08_1_tar.gz



##### s1. 解压

```
tar xvf buildroot-2017.08.1.tar.gz 

```

##### s2. 配置

```
cd buildroot-2017.08.1/

make menuconfig
```

控制篇幅只列出部分,这里有个参考配置(不是压缩文件,需要改名为.config):yz_imx6u_buildroot2017-v1_config.rar

```
    Target Architecture (ARM (little endian))  --->              
  │ │        Target Binary Format (ELF)  --->                             │ │  
  │ │        Target Architecture Variant (cortex-A7)  --->                │ │  
  │ │        Target ABI (EABIhf)  --->                                    │ │  
  │ │        Floating point strategy (NEON/VFPv4)  --->                   │ │  
  │ │        ARM instruction set (ARM)  --->                              │ │  
```
```
           Toolchain type (Buildroot toolchain)  --->                                │ │  
  │ │            *** Toolchain Buildroot Options ***                                       │ │  
  │ │        (buildroot) custom toolchain vendor name (NEW)                                │ │  
  │ │            C library (glibc)  --->                                                   │ │  
  │ │            *** Kernel Header Options ***                                             │ │  
  │ │            Kernel Headers (Linux 4.1.x kernel headers)  --->                         │ │  
  │ │            *** Binutils Options ***                                                  │ │  
  │ │            Binutils Version (binutils 2.28.1)  --->                                  │ │  
  │ │        ()  Additional binutils options (NEW)                                         │ │  
  │ │            *** GCC Options ***                                                       │ │  
  │ │            GCC compiler Version (gcc 6.x)  --->                                      │ │  
  │ │        ()  Additional gcc options (NEW)                                              │ │  
  │ │        [*] Enable C++ support                                                        │ │  
  │ │        [ ] Enable Fortran support (NEW)                                              │ │  
  │ │        [ ] Enable compiler link-time-optimization support (NEW)                      │ │  
  │ │        [ ] Enable compiler OpenMP support (NEW)                                      │ │  
  │ │        [ ] Enable graphite support (NEW)                                             │ │  
  │ │            *** Host GDB Options ***                                                  │ │  
  │ │        [*] Build cross gdb for the host                                              │ │  
  │ │        [ ]   TUI support (NEW)                                                       │ │  
  │ │        [ ]   Python support (NEW)                                                    │ │  
  │ │        [ ]   Simulator support (NEW)                                                 │ │  
  │ │              GDB debugger Version (gdb 7.11.x)  --->                                 │ │  
  │ │            *** Toolchain Generic Options ***                                         │ │  
  │ │        [ ] Copy gconv libraries (NEW)                                                │ │  
  │ │        [*] Enable MMU support (NEW)                                                  │ │  
  │ │        ()  Target Optimizations (NEW)                                                │ │  
  │ │        ()  Target linker options (NEW)                                               │ │  
  │ │        [ ] Register toolchain within Eclipse Buildroot plug-in (NEW)   
```

##### s3. 编译

```
time make
```

- 编译的根文件系统在这里:buildroot-2017.08.1/output/images/rootfs.tar


- 工具链位置在这里:buildroot-2017.08.1/output/host/bin/arm-buildroot-linux-gnueabihf-


##### s4. 工具链设置脚本

- 方便后面编译uboot、linux,写一个脚本。
- 脚本是临时有效的,每次编译时先执行此脚本。


build-set-yz-imx6ul-env.sh 实现:

```
#! /bin/sh

echo "set env"
export PATH=$PATH:/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/host/bin
export ARCH=arm
export CROSS_COMPILE=arm-buildroot-linux-gnueabihf-

echo "done"
```

---
### 二、编译u-boot

u-boot源码在:阿尔法Linux开发板光盘资料(A盘)\1、例程源码\11、开发板教程对应的uboot和linux源码里面

##### s1. 复制 uboot-imx-rel_imx_4.1.15_2.1.0_ga_alientek.tar.bz2 到 ubuntu16

```
# 新建目录,复制到这里
mkdir uboot
```

##### s2. 解压

```
cd uboot
tar xjvf uboot-imx-2016.03-2.1.0-gd9420c3-v1.1.tar.bz2
```

##### s3. 编译

```
# 1.脚本配置工具链
source build-set-yz-imx6ul-env.sh

# 2.配置uboot
make distclean
make mx6ull_14x14_ddr512_emmc_defconfig

# 3.编译
make all -j6

# 4.改名
mv u-boot.imx u-boot-imx6ull-14x14-ddr512-emmc.imx

```

最终得到 u-boot-imx6ull-14x14-ddr512-emmc.imx.



---
### 三、编译linux
linux源码在:阿尔法Linux开发板光盘资料(A盘)\1、例程源码\11、开发板教程对应的uboot和linux源码里面

##### s1. 复制 linux-imx-4.1.15-2.1.0-gbedf008-v1.1.tar.bz2 到 ubuntu16

```
# 新建目录,复制到这里
mkdir linux
```

##### s2. 解压

```
cd linux
tar xjvf linux-imx-4.1.15-2.1.0-gbedf008-v1.1.tar.bz2
```

##### s3. 编译

- 编译前先安装 lzop

```
sudo apt-get install lzop
```

- 编译linux

```
# 1.脚本配置工具链
source build-set-yz-imx6ul-env.sh

# 2.配置内核
make distclean
make imx_v7_defconfig

# 3.编译
time make -j6
make -j6 imx6ull-14x14-emmc-7-1024x600-c.dtb

# 4.安装模块
rm -rf m_out
mkdir m_out

make -j6 modules_install INSTALL_MOD_PATH="./m_out"
```
- 打包模块

mfgtool需要用到。
```
cd m_out/lib/modules/
sudo tar cjvf ../modules.tar.bz2 .
```

##### 生成相关文件位置:

- 内  核:arch/arm/boot/zImage
- 模  块:m_out/lib/modules.tar.bz2
- 设备树:arch/arm/boot/dts/imx6ull-14x14-emmc-7-1024x600-c.dtb

---
### 四、打包rootfs

##### s1.汇总前面得到相关文件到一个目录内,如下:

```
.
├── imx6ull-14x14-emmc-7-1024x600-c.dtb
├── modules.tar.bz2
├── pack_yz_imx6ul_rootfs-v1.sh
├── rootfs.tar
├── u-boot-imx6ull-14x14-ddr512-emmc.imx
└── zImage

0 directories, 6 files

```

其中,pack_yz_imx6ul_rootfs-v1.sh是个脚本,目的是处理成mfgtool需要的格式,很简单,内容如下:

```
#! /bin/sh

echo "s1: start pack..."
rm -rf imx6ul_rootfs
mkdir -p imx6ul_rootfs/rootfs

rm -f rootfs.tar.bz2


echo "s2: tar xf rootfs.tar..."
tar xf rootfs.tar -C imx6ul_rootfs/rootfs/
mkdir imx6ul_rootfs/rootfs/lib/modules
sync

echo "s3: tar xjf rootfs.tar.bz2..."
cd imx6ul_rootfs/rootfs
tar cjf ../rootfs.tar.bz2 .
sync

cd ..
cd ..

echo "s4: cp rootfs.tar.bz2..."

cp imx6ul_rootfs/rootfs.tar.bz2 ./
sync

rm -rf imx6ul_rootfs

echo "pack done."

```

##### s2. 执行脚本

```
vmtest@linux-test:~/work/yuanzi/code-build/bin-bak$ sudo ./pack_yz_imx6ul_rootfs-v1.sh 
s1: start pack...
s2: tar xf rootfs.tar...
s3: tar xjf rootfs.tar.bz2...
s4: cp rootfs.tar.bz2...
pack done.
vmtest@linux-test:~/work/yuanzi/code-build/bin-bak$ 

```

执行脚本后得到 rootfs.tar.bz2。

```
.
├── imx6ull-14x14-emmc-7-1024x600-c.dtb
├── modules.tar.bz2
├── pack_yz_imx6ul_rootfs-v1.sh
├── rootfs.tar
├── rootfs.tar.bz2
├── u-boot-imx6ull-14x14-ddr512-emmc.imx
└── zImage

0 directories, 7 files

```

到这里,所需要的文件都准备好了,可以召唤神龙了 可以烧录到emmc了。


---
### 五、烧录固件到emmc

- 在win10下操作。
- mfgtoo位置:阿尔法Linux开发板光盘资料(A盘)\5、开发工具\4、正点原子修改过的MFG_TOOL烧写工具


##### s1.替换相关文件

```
#1
modules.tar.bz2 复制到 mfgtool\Profiles\Linux\OS Firmware\files\modules

#2
rootfs.tar.bz2 复制到 mfgtool\Profiles\Linux\OS Firmware\files\filesystem

#3 
uboot、zImage、dtb 复制 mfgtool\Profiles\Linux\OS Firmware\files\boot
```

##### s2.烧录固件
烧录过程和正常烧录一样,控制篇幅不再列出,可参考官方文档或者这个帖子-[ [正点原子i.MX6UL开发板] 开箱与固件烧录](https://whycan.cn/t_3521.html).


---

### 六、编译qt例程
qt自带例程的编译可以参考晕哥这个视频:- [buildroot成功后如何编译Qt应用程序]( https://www.bilibili.com/video/av16396112/)

看log或许更直观:

```
vmtest@linux-test:~/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/build/qt5base-5.9.1/examples/widgets/widgets/analogclock$ pwd
/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/build/qt5base-5.9.1/examples/widgets/widgets/analogclock
vmtest@linux-test:~/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/build/qt5base-5.9.1/examples/widgets/widgets/analogclock$ ls
analogclock.cpp  analogclock.h  analogclock.pro  main.cpp
vmtest@linux-test:~/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/build/qt5base-5.9.1/examples/widgets/widgets/analogclock$ /home/vmtest/work/yuanzi/
code-build/rootfs/buildroot-2017.08.1/output/host/bin/qmake analogclock.pro 
vmtest@linux-test:~/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/build/qt5base-5.9.1/examples/widgets/widgets/analogclock$ time make
/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/host/bin/arm-buildroot-linux-gnueabihf-g++ -c -pipe -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os --sysroot=/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/host/arm-buildroot-linux-gnueabihf/sysroot -O2 -O3 -fno-exceptions -Wall -W -D_REENTRANT -fPIC -DQT_NO_EXCEPTIONS -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I../../../../include -I../../../../include/QtWidgets -I../../../../include/QtGui -I../../../../include/QtCore -I.moc -I../../../../mkspecs/devices/linux-buildroot-g++ -o .obj/analogclock.o analogclock.cpp
/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/host/bin/arm-buildroot-linux-gnueabihf-g++ -c -pipe -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os --sysroot=/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/host/arm-buildroot-linux-gnueabihf/sysroot -O2 -O3 -fno-exceptions -Wall -W -D_REENTRANT -fPIC -DQT_NO_EXCEPTIONS -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I../../../../include -I../../../../include/QtWidgets -I../../../../include/QtGui -I../../../../include/QtCore -I.moc -I../../../../mkspecs/devices/linux-buildroot-g++ -o .obj/main.o main.cpp
/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/host/bin/arm-buildroot-linux-gnueabihf-g++ -pipe -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os --sysroot=/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/host/arm-buildroot-linux-gnueabihf/sysroot -O2 -O3 -fno-exceptions -Wall -W -dM -E -o .moc/moc_predefs.h /home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/host/mkspecs/features/data/dummy.cpp
/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/build/qt5base-5.9.1/bin/moc -DQT_NO_EXCEPTIONS -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB --include .moc/moc_predefs.h -I/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/build/qt5base-5.9.1/mkspecs/devices/linux-buildroot-g++ -I/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/build/qt5base-5.9.1/examples/widgets/widgets/analogclock -I/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/build/qt5base-5.9.1/include -I/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/build/qt5base-5.9.1/include/QtWidgets -I/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/build/qt5base-5.9.1/include/QtGui -I/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/build/qt5base-5.9.1/include/QtCore -I/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/host/arm-buildroot-linux-gnueabihf/include/c++/6.4.0 -I/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/host/arm-buildroot-linux-gnueabihf/include/c++/6.4.0/arm-buildroot-linux-gnueabihf -I/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/host/arm-buildroot-linux-gnueabihf/include/c++/6.4.0/backward -I/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/host/lib/gcc/arm-buildroot-linux-gnueabihf/6.4.0/include -I/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/host/lib/gcc/arm-buildroot-linux-gnueabihf/6.4.0/include-fixed -I/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/host/arm-buildroot-linux-gnueabihf/include -I/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/host/arm-buildroot-linux-gnueabihf/sysroot/usr/include analogclock.h -o .moc/moc_analogclock.cpp
/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/host/bin/arm-buildroot-linux-gnueabihf-g++ -c -pipe -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os --sysroot=/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/host/arm-buildroot-linux-gnueabihf/sysroot -O2 -O3 -fno-exceptions -Wall -W -D_REENTRANT -fPIC -DQT_NO_EXCEPTIONS -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I. -I../../../../include -I../../../../include/QtWidgets -I../../../../include/QtGui -I../../../../include/QtCore -I.moc -I../../../../mkspecs/devices/linux-buildroot-g++ -o .obj/moc_analogclock.o .moc/moc_analogclock.cpp
/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/host/bin/arm-buildroot-linux-gnueabihf-g++ --sysroot=/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/host/arm-buildroot-linux-gnueabihf/sysroot -Wl,-O1 -Wl,--enable-new-dtags -o analogclock .obj/analogclock.o .obj/main.o .obj/moc_analogclock.o   -L/home/vmtest/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/build/qt5base-5.9.1/lib -lQt5Widgets -lQt5Gui -lQt5Core -lrt -ldl -latomic -lpthread 

real	0m5.039s
user	0m2.604s
sys	0m0.948s
vmtest@linux-test:~/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/build/qt5base-5.9.1/examples/widgets/widgets/analogclock$ ls
analogclock      analogclock.h    main.cpp
analogclock.cpp  analogclock.pro  Makefile

vmtest@linux-test:~/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/build/qt5base-5.9.1/examples/widgets/widgets/analogclock$ file analogclock
analogclock: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-, for GNU/Linux 4.1.0, not stripped
vmtest@linux-test:~/work/yuanzi/code-build/rootfs/buildroot-2017.08.1/output/build/qt5base-5.9.1/examples/widgets/widgets/analogclock$ 
```

  ana.png

离线

#2 2020-01-10 15:54:52

晕哥
Administrator
注册时间: 2017-09-06
累计积分: 8,870

Re: [正点原子i.MX6UL开发板] 编译uboot、linux、buildroot-rootfs

楼主叙述条理清晰,有理有据,看完我差点忘记三连了。

离线

#3 2020-01-10 17:41:56

k455619
会员
注册时间: 2018-07-29
累计积分: 68

Re: [正点原子i.MX6UL开发板] 编译uboot、linux、buildroot-rootfs

三连三连

离线

#4 2020-01-14 11:04:01

Jmhh247
会员
注册时间: 2018-12-21
累计积分: 193

Re: [正点原子i.MX6UL开发板] 编译uboot、linux、buildroot-rootfs

- 打开声卡操作

音量
# tinymix set 12 110

右声道
# tinymix set 43 1

左声道
# tinymix set 50 1

离线

#5 2020-01-14 22:58:38

sea18c
会员
注册时间: 2019-08-05
累计积分: 34

Re: [正点原子i.MX6UL开发板] 编译uboot、linux、buildroot-rootfs

实用,支持多开课

离线

页脚