日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

NXP iMX8 SCFW和Boot Container Image编译

發布時間:2023/12/10 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 NXP iMX8 SCFW和Boot Container Image编译 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

By Toradex秦海

1).?簡介

NXP iMX8系列ARM處理器是NXP目前性能最強勁確也是架構最復雜的ARM處理器,和之前的ARMv7系列處理器比如iMX6系列不同,在iMX8系列芯片中NXP加入了SCU模塊來管理芯片的啟動和關鍵外設初始化(如PMIC、時鐘等),iMX8QM處理器的簡單框圖如下:

SCU(System Control Unit)的框圖放大如下,其中包含一個基于Cortex-M4內核的SCU CM4 Complex模塊,其運行的固件就是SCFW,還有一基于Cortex-M0內核的SECO模塊,運行SECO固件,負責安全認證相關的工作。

本文就簡單介紹下iMX8處理器的啟動流程,然后結合來自于Toradex Apalis?iMX8?的ARM嵌入式平臺,演示一下包含了SCFW以及SECO固件等的boot container image的編譯流程。

2).?準備

a).?Apalis iMX8QM?4GB?WB IT?ARM核心版配合Ioxra?載板,連接調試串口UART1(載板X22)到開發主機方便調試。

3).?NXP iMX8?啟動流程

a).?NXP iMX8啟動流程圖如下所示,首先SCU boot rom代碼加載啟動,然后通過芯片的SCU boot mode相關管腳配置,來選擇進入那種啟動模式,一般要么是正常啟動,要么是進入恢復模式,然后通過SDP模式啟動。正常啟動流程到最后,加載運行Boot container image來繼續下一階段啟動。

b).?Boot container image?包含如下內容

./ SCFW -?運行與SCU M4核心的firmware,用于啟動管理和外設初始化等任務,可以進行定制修改。

./ SECO FW - SECO firmware,NXP只提供binary文件,負責啟動過程中的一些security認證。

./ Optional Coretex-M4 firmware,?由上面章節一的iMX8芯片框圖可以看到iMX8支持2x Cortex-M4?核心,那么運行與這些M4核心的固件可以一起集成到boot container image里面去,如果不需要或者可以后續通過U-boot加載,因此可選添加。

./ Optional Cortex-A image,運行于Cortex-A核心啟動相關的image,主要包含ATF(ARM Trusted Firmware)和U-boot image。

c).?Boot container image?加載流程如下圖,最后當U-boot運行后,就由U-boot控制進行正常的Linux Kernel和Rootfs加載流程了。

4).?Boot Container Image編譯組裝

a).?本文以下編譯流程都是基于當前Toradex?最新Linux BSP V5.3版本操作,其他版本基本流程都是一致的,版本差異可以參考這里說明修改適配

b).?首先獲取?SECO firmware

----------------------------------

$ cd ~/workdir

$ wget -c https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/imx-seco-3.8.1.bin

$ chmod u+x imx-seco-3.8.1.bin

$ ./imx-seco-3.8.1.bin

$ ls imx-seco-3.8.1/firmware/seco/

commit-id.txt??mx8dxla1-ahab-container.img ?mx8qxb0-ahab-container.img ?SECO_FW_release_note.pdf

mx8dxla0-ahab-container.img ?mx8qmb0-ahab-container.img ??mx8qxc0-ahab-container.img

----------------------------------

可以看到SECO firmware binary已經在?imx-seco-3.8.1/firmware/seco/?目錄下,針對不同的iMX8芯片選擇不同的文件,本文測試使用的iMX8QM處理器對應的是?mx8qmb0-ahab-container.img?這個文件。

c).?然后編譯?SCFW

./從NXP官網下載?SCFW porting kit(需要有效的NXP賬號登錄),當前適用版本為?SCFW Porting Kit 1.7.3

./?解壓到?build-scfw?目錄

----------------------------------

###?create build-scfw folder for building

$ cd ~/workdir

$?mkdir build-scfw

$?cd build-scfw

###?extract package

$?tar xf imx-scfw-porting-kit-1.7.3.tar.gz

$ cd packages/

$ chmod +x imx-scfw-porting-kit-1.7.3.bin

$ ./imx-scfw-porting-kit-1.7.3.bin

###?deploy source code, corresponding to iMX8QM

$ cd imx-scfw-porting-kit-1.7.3/src/

$ tar xf scfw_export_mx8qm_b0.tar.gz

$ ls scfw_export_mx8qm_b0

bin ?build_mx8qm_b0 ?COPYING ?Makefile ?makefiles ?MANIFEST ?platform ?SCR-imx-scfw-porting-kit.txt

----------------------------------

./?查看當前SCFW版本號/Commit

----------------------------------

$ cd ~/workdir/build-scfw/packages/imx-scfw-porting-kit-1.7.3/

$ $ cat VERSION

NXP i.MX System Controller Firmware

--------------------------------------------

Git repo: ?????ssh://bitbucket.sw.nxp.com/imxpriv/imx-sc-firmware.git

Branch name: ??imx_scfw_2020q4

Build version: 5222

Commit ID: ????bc122ee1

Build date: ???May 27 2021

Build time: ???16:27:17

----------------------------------

./?將Toradex Apalis iMX8QM針對其核心板的相關修改部署到上述下載NXP imx8qm SCFW?源代碼中

----------------------------------

$ cd build-scfw/packages/imx-scfw-porting-kit-1.7.3/src

$ git clone?https://github.com/toradex/i.MX-System-Controller-Firmware.git

$ cp -r i.MX-System-Controller-Firmware/src/scfw_export_mx8qm_b0/*?/scfw_export_mx8qm_b0/

----------------------------------

./?可選?-?根據需要修改SCFW源代碼

----------------------------------

###?參考文檔位于?../imx-scfw-porting-kit-1.7.3/doc/,有HDML和PDF兩種格式文檔

$ ls?pdf/

sc_fw_api_dxl_a0.pdf ?sc_fw_api.pdf ?sc_fw_api_qm_b0.pdf ?sc_fw_api_qx_b0.pdf ???sc_fw_rn.pdf

###?針對Toradex Apalis iMX8,核心修改文件位于

### build-scfw/packages/imx-scfw-porting-kit-1.7.3/src/scfw_export_mx8qm_b0/platform/board/mx8qm_apalis

$ ls

board.bom ?board.c ?board.h ?dcd ?Makefile

### dcd?目錄主要存放ram timing配置文件,主要修改部分在?board.c?這個文件,這個文件的內容和修改請參考上述sc_fw_port.pdf文檔說明,包含了從底層CPU/RAM/時鐘/PMIC初始化到外部資源分配的各方面

###?比如常用的SOC資源在SCU、Cortex-A、Cortex-M核心直接的分配,可以參考文檔的第六章節,通過?board.c?文件的board_system_config()?函數來進行配置,當然也有其他run-time的API函數可用

void board_system_config(sc_bool_t early, sc_rm_pt_t pt_boot)

{

????sc_err_t err = SC_ERR_NONE;

????/* This function configures the system. It usually partitions

???????resources according to the system design. It must be modified by

???????customers. Partitions should then be specified using the mkimage

???????-p option. */

????/* Note the configuration here is for NXP test purposes */

????......

????/* Name default partitions */

????PARTITION_NAME(SC_PT, "SCU");

????PARTITION_NAME(SECO_PT, "SECO");

????PARTITION_NAME(pt_boot, "BOOT");

????/* Configure initial resource allocation (note additional allocation

???????and assignments can be made by the SCFW clients at run-time */

????......

/* Create M4 0 partition */

????????if (rm_is_resource_avail(SC_R_M4_0_PID0) != SC_FALSE)

????????{

????????????sc_rm_mr_t mr;

????????????/* List of resources */

????????????static const sc_rsrc_t rsrc_list[7U] =

????????????{

????????????????SC_R_SYSTEM,

????????????????SC_R_IRQSTR_M4_0,

????????????????SC_R_MU_5B,

????????????????SC_R_MU_7A,

????????????????SC_R_MU_8B,

????????????????SC_R_GPT_4,

????????????????SC_R_SECO_MU_4

????????????};

......

----------------------------------

./?修改好源代碼后,配置toolchain準備進行編譯

----------------------------------

###?使用GCC ARM?針對?Coretex-M核心的GNU-RM?最新版本即可,下載地址如下,當前針對Linux X86_64平臺的最新版本為gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2

https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads

$ cd ~/workdir

$?mkdir toolchain

$ cd toolchain

###?解壓下載的toolchain壓縮包

$ tar xvf gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2

$ ls gcc-arm-none-eabi-10-2020-q4-major

arm-none-eabi ?bin ?lib ?share

### export?編譯環境變量

$ export ARCH=arm

$ export CROSS_COMPILE=~/workdir/toolchain/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-

$ export PATH=$PATH:~/workdir/toolchain/gcc-arm-none-eabi-10-2020-q4-major/bin

###?測試toolchain

$ arm-none-eabi-gcc --version

arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10-2020-q4-major) 10.2.1 20201103 (release)

Copyright (C) 2020 Free Software Foundation, Inc.

This is free software; see the source for copying conditions. ?There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

./?SCFW編譯

----------------------------------

$ cd?~/workdir/build-scfw/packages/imx-scfw-porting-kit-1.7.3/src/scfw_export_mx8qm_b0

$ make clean;make SOC=MX8QM B=apalis D=0 DL=0 R=b0 U=0 V=0 qm

Generating platform/board/mx8qm_apalis/dcd/imx8_ramid1_dcd_1.6GHz.h

......

Linking build_mx8qm_b0/scfw_tcm.elf ....

Objcopy build_mx8qm_b0/scfw_tcm.bin ....

done.

###?關于編譯的相關選項含義,可以通過help查看,比如D配置debug選項,U配置SCU調試UART

$ make help

Usage: make TARGET OPTIONS

Targets:

help ??????????: display help text

clean ?????????: remove all build files

??dxl ????????????: build for i.MX8DXL die, output in build_mx8dxl

??qm ????????????: build for i.MX8QM die, output in build_mx8qm

??......

Options:

V=0 ???????????: quite output (default)

V=1 ???????????: verbose output

D=0 ???????????: configure for no debug

D=1 ???????????: configure for debug (default)

DL=<level> ????: configure debug level (0-5)

B=<board> ?????: configure board (default=val)

U=<uart> ??????: configure debug UART (default=0)

DDR_CON=<file> : specify DDR config file

R=<srev> ??????: silicon revision (default=A0)

M=0 ???????????: no debug monitor (default)

M=1 ???????????: include debug monitor

LTO=0 ?????????: build without link-time optimization (default)

LTO=1 ?????????: build with link-time optimization

T=<test> ??????: run tests rather than boot next core

----------------------------------

./?編譯好生成的SCFW固件位于如下位置,后面打包Boot Container Image會需要

----------------------------------

$ ls build_mx8qm_b0/scfw_tcm.bin

----------------------------------

當然,如果你無需修改Toradex SCFW的默認配置,也可以從下面github上面直接下載Toradex編譯好的SCFW binary固件文件mx8qm-apalis-scfw-tcm.bin后重命名為scfw_tcm.bin

----------------------------------

$ wget https://github.com/toradex/i.MX-System-Controller-Firmware/blob/master/src/scfw_export_mx8qm_b0/build_mx8qm_b0/mx8qm-apalis-scfw-tcm.bin

$ mv?mx8qm-apalis-scfw-tcm.bin?scfw_tcm.bin

----------------------------------

d).?編譯ATF

./?獲取ATF源代碼

-------------------------------

$ cd ~/workdir

$?git clone git://git.toradex.com/imx-atf.git -b?toradex_imx_5.4.70_2.3.0

-------------------------------

./?參考這里說明配置編譯toolchain,因為ATF運行與Cortex-A核心,因此和上面SCFW不同,需要使用GCC ARM針對Coretx-A核心的GNU-A toolchain,為了和Ycoto編譯版本Dunfell對應,這里使用了9.2 aarch64 64bit版本。另外,請注意因為使用編譯器和上述SCFW編譯不同,因此要開一個新的Terminal窗口進行配合和后續編譯。

-------------------------------

$ cd ~/workdir/toolchain/

###?解壓下載的toolchain壓縮包

$ tar xvf gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz

$ ls gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu

9.2-2019.12-x86_64-aarch64-none-linux-gnu-manifest.txt ?bin ?????lib ???libexec

aarch64-none-linux-gnu ?????????????????????????????????include ?lib64 ?share

### export?編譯環境變量

$ export ARCH=arm

$ export CROSS_COMPILE=aarch64-none-linux-gnu-

$ export PATH=$PATH:~/workdir/toolchain/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu/bin

###?測試toolchain

$ aarch64-none-linux-gnu-gcc --version

aarch64-none-linux-gnu-gcc (GNU Toolchain for the A-profile Architecture 9.2-2019.12 (arm-9.10)) 9.2.1 20191025

Copyright ? 2019 Free Software Foundation, Inc.

......

-------------------------------

./?編譯ATF

-------------------------------

$ cd ~/workdir/imx-atf

$ make PLAT=imx8qm bl31

??CC ?????plat/imx/imx8qm/imx8qm_bl31_setup.c

......

??LD ?????build/imx8qm/release/bl31/bl31.elf

??BIN ????build/imx8qm/release/bl31.bin

Built build/imx8qm/release/bl31.bin successfully

??OD ?????build/imx8qm/release/bl31/bl31.dump

###?編譯出?bl31.bin?再后續組裝Boot Container Image中會需要

$ ls build/imx8qm/release/bl31.bin

build/imx8qm/release/bl31.bin

-------------------------------

e).?U-boot編譯

./?參考這里說明進行U-boot源代碼下載以及編譯,這個就是比較常規的bootloader修改編譯過程了,針對iMX8/iMX8X平臺,如果只是需要修改U-boot(SCFW不做修改)的話也需要參考本文流程重新組裝Boot Container Image文件后再進行部署。

./?下載對應BSP版本U-boot源代碼

-------------------------------

$ cd ~/workdir

$?git clone -b toradex_imx_v2020.04_5.4.70_2.3.0 git://git.toradex.cn/u-boot-toradex.git

-------------------------------

./?編譯toolchain及上一章節編譯ATF同樣toolchain配置,這里不再贅述。

./?編譯,生成u-boot.bin用于后續Boot Container Image組裝

-------------------------------

$ cd ~/workdir/u-boot-toradex

$ make apalis-imx8_defconfig

$?make -j$(nproc) 2>&1 | tee build.log

$ ls u-boot.bin

u-boot.bin

-------------------------------

f).?Boot Container Image組裝

./?首先下載?imx-mkimage?工具

-------------------------------

$ cd ~/workdir/

$ git clone -b imx_5.4.70_2.3.0 https://source.codeaurora.org/external/imx/imx-mkimage/

-------------------------------

./?將上述章節準備好的SECO、SCFW、ATF、U-boot binary文件復制到imx-mkimage對應目錄

-------------------------------

$ cd ~/workdir/imx-mkimage/

$ cp ~/workdir/imx-seco-3.8.1/firmware/seco/mx8qmb0-ahab-container.img?iMX8QM

$ cp?~/workdir/build-scfw/../build_mx8qm_b0/scfw_tcm.bin iMX8QM

$ cp ~/workdir/imx-atf/build/imx8qm/release/bl31.bin iMX8QM

$ cp ~/workdir/u-boot-toradex/u-boot.bin iMX8QM

-------------------------------

./?組裝Boot Container Image,最終生成?flash.bin?文件

-------------------------------

$ make SOC=iMX8QM flash_b0

$ ls iMX8QM/flash.bin

iMX8QM/flash.bin

-------------------------------

5).?部署測試

a).?從這里下載Toradex Ycoto Linux BSP Multimedia Image Quarterly 5.2.0+build.7版本,默認image通過Toradex Easy Installer安裝后啟動通過調試串口可以看到目前的SCFW Commit ID

-------------------------------

U-Boot 2020.04-5.2.0-devel+git.76fd4496a40b (Apr 07 2021 - 07:35:42 +0000)

CPU: ??NXP i.MX8QM RevB A53 at 1200 MHz

DRAM: ?4 GiB

MMC: ??FSL_SDHC: 0, FSL_SDHC: 1, FSL_SDHC: 2

Loading Environment from MMC... OK

In: ???serial

Out: ??serial

Err: ??serial

Model: Toradex Apalis iMX8 QuadMax 4GB Wi-Fi / BT IT V1.1B, Serial# 06738378

?BuildInfo:

??- SCFW?0d54291f, SECO-FW d63fdb21, IMX-MKIMAGE 8947fea3, ATF 7f1187b

??- U-Boot 2020.04-5.2.0-devel+git.76fd4496a40b

-------------------------------

b).?用上述章節4生成的?flash.bin文件替換掉剛才下載的BSP 5.2.0 image壓縮包里面的imx-boot文件

-------------------------------

$ cd ~/workdir/

$ tar xvf Apalis-iMX8_Reference-Multimedia-Image-Tezi_5.2.0+build.7.tar

$ cd Apalis-iMX8_Reference-Multimedia-Image-Tezi_5.2.0+build.7/

$ rm imx-boot

$ cp?imx-mkimage/iMX8QM/flash.bin?imx-boot

-------------------------------

c).?將上述修改后的image重新通過Toradex Easy Installer更新到Apalis iMX8模塊后,啟動查看SCFW Commit ID是否和之前SCFW編譯章節查看到的Commit一致,如一致說明編譯部署成功。

-------------------------------

U-Boot 2020.04-06904-g7f3416a28c (Jul 05 2021 - 15:43:42 +0800)

CPU: ??NXP i.MX8QM RevB A53 at 1200 MHz

DRAM: ?4 GiB

MMC: ??FSL_SDHC: 0, FSL_SDHC: 1, FSL_SDHC: 2

Loading Environment from MMC... OK

In: ???serial

Out: ??serial

Err: ??serial

Model: Toradex Apalis iMX8 QuadMax 4GB Wi-Fi / BT IT V1.1B, Serial# 06738378

?BuildInfo:

??- SCFW?bc122ee1, SECO-FW d63fdb21, IMX-MKIMAGE 8947fea3, ATF

??- U-Boot 2020.04-06904-g7f3416a28c

-------------------------------

6).?總結

本文基于NXP iMX8嵌入式平臺簡單介紹了NXP iMX8/iMX8X新一代iMX處理器的啟動流程,以及SCFW、ATF、U-boot的編譯和Boot Container Image的組裝供參考,而NXP另外一個iMX8M Mini/Plus系列是不包含SCU的,但是還是需要一個包含DDR timing、ATF、SPL、U-boot等的Boot Container Image,詳細編譯可以參考這里說明。

參考文獻

https://www.nxp.com.cn/docs/en/application-note/AN13275.pdf

https://developer.toradex.com/knowledge-base/build-custom-imx-88x-system-controller-firmware-scfw

https://developer.toradex.cn/knowledge-base/build-u-boot-and-linux-kernel-from-source-code

總結

以上是生活随笔為你收集整理的NXP iMX8 SCFW和Boot Container Image编译的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。