[ 物联网篇 ] 01 - NXP i.MX 8M Mini 环境的搭建

[ 物联网篇 ] 01 - NXP i.MX 8M Mini 环境的搭建_第1张图片

记录下如何搭建NXP i.MX 8M 的开发环境。

1. 看文档 / 找资料

不管任何时候,接触任何新的平台或学习新的知识,首先就是看官网提供的文档,或搜索下是否有相关的资料。

  • 找到开发板的文档入口 : Evaluation Kit for the i.MX 8M Mini Applications Processor 详细介绍了开发板的资源以及相关资料下载路径。

  • 详细介绍了各个文档的作用

[ 物联网篇 ] 01 - NXP i.MX 8M Mini 环境的搭建_第2张图片

2. 源码下载
  • 阅读下载的文章中i.MX_Yocto_Project_User’s_Guide.pdf详细介绍了下载源码的步骤。
// 下载repo 工具 
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo

// 下载源码 
mkdir imx-yocto-bsp
cd imx-yocto-bsp
repo init -u https://source.codeaurora.org/external/imx/imx-manifest -b imx-linux-rocko -m imx-4.9.88-2.0.0_ga.xml
repo sync
  • 源码下载过程遇到的错误1 : repo init 提示 fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
➜  imx-yocto-bsp ./repo init -u https://source.codeaurora.org/external/imx/imx-manifest -b imx-linux-rocko -m imx-4.9.88-2.0.0_ga.xml
fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
fatal: error [Errno 101] Network is unreachable
fatal: cloning the git-repo repository failed, will remove '.repo/repo' 

// 解决方案: 

先单独克隆repo,然后将git-repo里面的repo文件复制到bin目录,在同步源码的工作目录新建.repo文件夹,把git-repo重命名为repo复制到.repo目录下:

git clone https://gerrit-googlesource.lug.ustc.edu.cn/git-repo

参考解决:Cannot get http://gerrit.googlesource.com/git-repo/clone.bundle

  • 源码下载过程遇到的错误2 : ImportError: cannot import name 'spawn’
// 运行错误
➜  imx-yocto-bsp bitbake fsl-image-validation-imx
Traceback (most recent call last):
  File "/home/mike/Work/nxp-imx8/imx-yocto-bsp/sources/poky/bitbake/bin/bitbake", line 31, in 
    import bb
  File "/home/mike/Work/nxp-imx8/imx-yocto-bsp/sources/poky/bitbake/lib/bb/__init__.py", line 79, in 
    from bb import fetch2 as fetch
  File "/home/mike/Work/nxp-imx8/imx-yocto-bsp/sources/poky/bitbake/lib/bb/fetch2/__init__.py", line 1843, in 
    from . import clearcase
  File "/home/mike/Work/nxp-imx8/imx-yocto-bsp/sources/poky/bitbake/lib/bb/fetch2/clearcase.py", line 72, in 
    from   distutils import spawn
ImportError: cannot import name 'spawn'

// 解决方案
安装sudo apt-get install python3-distutils 之后解决
  • 源码下载过程遇到的错误3 : ERROR: Unable to start bitbake server
ERROR: Unable to start bitbake server
ERROR: Last 10 lines of server log for this session (/home/mike/Work/nxp-imx8/imx-yocto-bsp/bitbake-cookerdaemon.log):
    self.cooker = bb.cooker.BBCooker(self.configuration, self.featureset)
  File "/home/mike/Work/nxp-imx8/imx-yocto-bsp/sources/poky/bitbake/lib/bb/cooker.py", line 197, in __init__
    self.initConfigurationData()
  File "/home/mike/Work/nxp-imx8/imx-yocto-bsp/sources/poky/bitbake/lib/bb/cooker.py", line 356, in initConfigurationData
    self.databuilder.parseBaseConfiguration()
  File "/home/mike/Work/nxp-imx8/imx-yocto-bsp/sources/poky/bitbake/lib/bb/cookerdata.py", line 316, in parseBaseConfiguration
    raise bb.BBHandledException
bb.BBHandledException
ERROR: The following required tools (as specified by HOSTTOOLS) appear to be unavailable in PATH, please install them in order to proceed:
  chrpath
  
//解决方案 
sudo apt-get install chrpath
sudo apt-get install texinfo 

参考Unable to connect to bitbake server

  • 下载最新代码
//查看最新的提交
 https://source.codeaurora.org/external/imx/imx-manifest/?h=imx-linux-rocko
// 下载最新代码
 To use this manifest repo, the 'repo' tool must be isntalled first.
--------------------------------------------------------
$: mkdir ~/bin
$: curl http://commondatastorage.googleapis.com/git-repo-downloads/repo  > ~/bin/repo
$: chmod a+x ~/bin/repo
$: PATH=${PATH}:~/bin

To excute 
$: mkdir 
$: cd 
$: repo init -u https://source.codeaurora.org/external/imx/fsl-arm-yocto-bsp -b  [ -m ]

// 下载imx-linux-sumo分支代码
repo init -u https://source.codeaurora.org/external/imx/imx-manifest -b imx-linux-sumo -m imx-virt-4.14.98-4.11-0.10_ga.xml

[ 物联网篇 ] 01 - NXP i.MX 8M Mini 环境的搭建_第3张图片


2.1 编译
  • 源码的编译主要使用fsl-setup-release.sh脚本完成
  • DISTRO=fsl-imx-x11 source fsl-setup-release.sh -b build , 详细用法如下
DISTRO= MACHINE= source fsl-setup-release.sh -b 
// DISTRO
DISTRO=  is the distro, which configures the build environment and it is stored in meta-fsl-
bsp-release/imx/meta-sdk/conf/distro .

对应源码中的 sources/meta-fsl-bsp-release/imx/meta-sdk/conf/distro/fsl-imx-x11.conf,可以看到 

DISTRO = "fsl-imx-x11"

// MACHINE
MACHINE=  is the machine name which points to the configuration file in conf/machine in
meta-freescale and meta-fsl-bsp-release.

// 编译输出的目录 
-b  specifies the name of the build directory created by the fsl-setup-release.sh script.

通过分析 fsl-setup-release.sh 脚本了解的一些信息

// MACHINE默认参数为imx6qpsabresd
if [ -z "$MACHINE" ]; then
    echo setting to default machine
    MACHINE='imx6qpsabresd'
fi
  • build 目录中执行 bitbake -k core-image-minimal , -k 代表 : 发生错误后尽可能继续执行。 编译过程持续 2~3 h
2.2 分析output
  • 参考Yocto Project Reference Manual -> 5.2. The Build Directory - build/ 了解编译成功后各个目录含义

    • build/downloads/ : 下载的源代码,可以通过修改 build/conf/local.conf中的DL_DIR ?= "${TOPDIR}/downloads"改变路径
    • build/sstate-cache/ : 含共享状态缓存,可以通过修改 build/conf/local.conf中的SSTATE_DIR ?= "${TOPDIR}/sstate-cache"改变路径
    • build/tmp/ : 构建系统的输出目录。 可以通过修改 build/conf/local.conf中的TMPDIR = “${TOPDIR}/tmp”"改变路径
目录 含义
build/tmp/buildstats/ 存储构建统计信息
build/tmp/deploy/ 最终输出的固件
build/tmp/sstate-control/ 共享状态清单文件
build/tmp/sysroots/ 为每台机器创建一个全局共享sysroot以及一个本机sysroot
build/tmp/work/ 由BitBake构建的包的特定于体系结构的工作子目录
build/tmp/work-shared/ 保存与其他配方共享工作目录的recipes
3. 固件烧录
  • NXP 固件烧录借助于uuu (Universal Update Utility) mfgtools,全平台覆盖
    [ 物联网篇 ] 01 - NXP i.MX 8M Mini 环境的搭建_第4张图片

  • Uboot 中通过fastboot 进入烧录模式

//fastboot devices
u-boot=> fastboot  devices
switch to partitions #0, OK
mmc1(part 0) is current device
Starting download of 16776232 bytes
..........................................................................
.....................................................

  • PC端通过UUU 进行烧录
sudo ./uuu -b emmc_all imx-boot-imx8mmevk-sd.bin-flash_evk sdcard.img

你可能感兴趣的:([,项目经验,])