【ecfw】ecfw构建基础
概述
Intel有一个开源项目(后面简称ecfw)是用于其参考板上的EC固件的,地址是github.com/intel/ecfw-zephyr。
通过该项目可以学习EC的开发,也可以编译出实际的EC固件用于Intel参考板。
本文介绍使用该项目完成Intel参考板EC的基础构建流程。
由于Intel的EC依赖于Zephyr,所以需要对Zephyr的使用有一个基本的了解,可以参考【Zephyr】Window下的Zephyr编译和使用_zephyr windows-CSDN博客,其中包含了代码下载,工具下载和部署等内容。
相关的测试代码已经上传ecfw: EC固件开发。
代码下载和部署
ecfw可以直接在GitHub - intel/ecfw-zephyr下载,如果无法下载也可以使用ecfw-zephyr: https://github.com/intel/ecfw-zephyr.git。此外还需要下载Zephyr源码,可以使用zephyr: https://github.com/zephyrproject-rtos/zephyr。
目前ecfw的稳定版本是open_ecfw_3.01.02.02,它匹配的Zephyr版本是v3.4.0,所以下载完成之后需要checkout。
代码的下载已经在ecfw: EC固件开发的脚本中包含,所以直接执行其中的venv.bat
脚本即可,该脚本还会完成基础的环境部署,此外还有额外的部署也可以通过README文件查看具体步骤。
另外需要特别注意,ecfw和Zephyr并没有完全适配,ecfw中包含补丁,需要将该补丁打到Zephyr源码中,但是目前发现对应v3.4.0的补丁并不能完美适配该版本下的Zephyr源码,导致补丁失败,所以后续构建的时候还是会报一些错,并且最终编译出来的二进制也不是完美适配参考板的。
查看板极支持
ecfw具体支持哪些Intel的参考板,可以通过输入如下的命令来确认。
(.venv) E:\zephyrproject>west boards --board-root ecfw-zephyr\out_of_tree_boards
mec1501_adl
mec1501_adl_p
mec1501_mtl_p
mec172x_mtl_s
mec172xlj_mtl_template
在ecfw-zephyr\out_of_tree_boards
目录下放置了所有支持的单板配置。它们分别使用一个个的yaml文件来声明,比如上面显示的mec1501_adl
有对应的文件ecfw-zephyr\out_of_tree_boards\boards\arm\mec1501_adl\mec1501_adl.yaml
,其内容如下:
identifier: mec1501_adl
name: MEC1501 ADL
type: mcu
arch: arm
toolchain:- zephyr
ram: 32
flash: 224
supported:- adc- counter- espi- gpio- i2c- pinctrl- pwm- watchdog- ps2- peci- kscan- sensor
显示的名字是通过identifier
键定义的。
本文以该单板为例进行构建。顺便说一下,mec1501_adl这个参考板使用的EC芯片是MEC152x,它是基于ARM Cortex-M4开发的。
构建
使用ecfw: EC固件开发下的venv.bat
打开构建环境,然后执行build.bat
就可以开始构建,实际执行的命令是:
west build -p auto -b mec1501_adl %CUR_DIR%\ecfw-zephyr\
-b
指定了单板,而之后跟的就是ecfw项目源码目录,它实际上是一个Zephyr应用。
编译过程中会报一些错(因为打补丁失败的缘故),这里需要修改一部分内容:
ecfw-zephyr\boards\mec1501_adl.conf
:
# CONFIG_SOC_MEC1501_EXT_32K=y // 注释掉
# CONFIG_SOC_MEC1501_EXT_32K_CRYSTAL=y // 注释掉
# CONFIG_SOC_MEC1501_EXT_32K_PARALLEL_CRYSTAL=y // 注释掉
CONFIG_SOC_MEC1501_VCI_PINS_AS_GPIOS=y
CONFIG_ESPI_FLASH_CHANNEL=n // 新增
zephyr\drivers\espi\espi_saf_mchp_xec.c
:
DEVICE_DT_INST_DEFINE(0, &espi_saf_xec_init, NULL,&espi_saf_xec_data, &espi_saf_xec_config, POST_KERNEL,CONFIG_ESPI_SAF_INIT_PRIORITY, &espi_saf_xec_driver_api); // 将CONFIG_ESPI_SAF_INIT_PRIORITY改成数字4
zephyr\drivers\spi\CMakeLists.txt
:
# zephyr_library_sources_ifdef(CONFIG_SPI_XEC_QMSPI spi_xec_qmspi.c) // 注释掉
zephyr_library_sources_ifdef(CONFIG_SPI_GECKO spi_gecko.c)
zephyr_library_sources_ifdef(CONFIG_SPI_XLNX_AXI_QUADSPI spi_xlnx_axi_quadspi.c)
zephyr_library_sources_ifdef(CONFIG_ESP32_SPIM spi_esp32_spim.c)
zephyr_library_sources_ifdef(CONFIG_SPI_TEST spi_test.c)
zephyr_library_sources_ifdef(CONFIG_SPI_PSOC6 spi_psoc6.c)
zephyr_library_sources_ifdef(CONFIG_SPI_NPCX_FIU spi_npcx_fiu.c)
zephyr_library_sources_ifdef(CONFIG_SPI_BITBANG spi_bitbang.c)
# zephyr_library_sources_ifdef(CONFIG_SPI_XEC_QMSPI_LDMA spi_xec_qmspi_ldma.c) // 注释掉
注意这里的修改还是比较粗糙的,实际可以根据补丁文件以及构建过程中的报错进行更精细的修改。
修改之后就可以正确构建。
(.venv) E:\ecfw>build.bat
-- west build: generating a build system
CMake Warning at E:/ecfw/zephyr/cmake/app/boilerplate.cmake:20 (message):Loading of Zephyr boilerplate.cmake directly is deprecated, please use'find_package(Zephyr)'
Call Stack (most recent call first):CMakeLists.txt:5 (include)Loading Zephyr default modules (Zephyr base).
-- Application: E:/ecfw/ecfw-zephyr
-- CMake version: 4.1.0-rc3
-- Found Python3: E:/ecfw/.venv/Scripts/python.exe (found suitable exact version "3.10.11") found components: Interpreter
-- Cache files will be written to: E:/ecfw/zephyr/.cache
-- Zephyr version: 3.4.0 (E:/ecfw/zephyr)
-- Found west (found suitable version "1.5.0", minimum required is "0.14.0")
-- Board: mec1501_adl
-- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK
-- Found host-tools: zephyr 0.16.8 (E:/zephyr-sdk-0.16.8)
-- Found toolchain: zephyr 0.16.8 (E:/zephyr-sdk-0.16.8)
-- Found Dtc: E:/ecfw/zephyrtools/dtc.exe (found suitable version "1.6.1", minimum required is "1.4.6")
-- Found BOARD.dts: E:/ecfw/ecfw-zephyr/out_of_tree_boards/boards/arm/mec1501_adl/mec1501_adl.dts
-- Generated zephyr.dts: E:/ecfw/zephyr/build/zephyr/zephyr.dts
-- Generated devicetree_generated.h: E:/ecfw/zephyr/build/zephyr/include/generated/devicetree_generated.h
-- Including generated dts.cmake file: E:/ecfw/zephyr/build/zephyr/dts.cmakewarning: SAF_SPI_CAPACITY (defined at E:/ecfw/ecfw-zephyr\app/saf/Kconfig:16) was assigned the value
'32' but got the value ''. Check these unsatisfied dependencies: ESPI_SAF (=n). See
http://docs.zephyrproject.org/latest/kconfig.html#CONFIG_SAF_SPI_CAPACITY and/or look up
SAF_SPI_CAPACITY in the menuconfig/guiconfig interface. The Application Development Primer, Setting
Configuration Values, and Kconfig - Tips and Best Practices sections of the manual might be helpful
too.warning: ESPI_SAF (defined at drivers/espi/Kconfig.xec:157, drivers/espi/Kconfig:179) was assigned
the value 'y' but got the value 'n'. Check these unsatisfied dependencies: ((ESPI_FLASH_CHANNEL &&
ESPI_XEC_V2 && ESPI) || (ESPI_FLASH_CHANNEL && ESPI)) (=n). See
http://docs.zephyrproject.org/latest/kconfig.html#CONFIG_ESPI_SAF and/or look up ESPI_SAF in the
menuconfig/guiconfig interface. The Application Development Primer, Setting Configuration Values,
and Kconfig - Tips and Best Practices sections of the manual might be helpful too.Parsing E:/ecfw/ecfw-zephyr/Kconfig
Loaded configuration 'E:/ecfw/ecfw-zephyr/out_of_tree_boards/boards/arm/mec1501_adl/mec1501_adl_defconfig'
Merged configuration 'E:/ecfw/ecfw-zephyr/prj.conf'
Merged configuration 'E:/ecfw/ecfw-zephyr/boards/mec1501_adl.conf'
Configuration saved to 'E:/ecfw/zephyr/build/zephyr/.config'
Kconfig header saved to 'E:/ecfw/zephyr/build/zephyr/include/generated/autoconf.h'
-- Found GnuLd: e:/zephyr-sdk-0.16.8/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe (found version "2.38")
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- The ASM compiler identification is GNU
-- Found assembler: E:/zephyr-sdk-0.16.8/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
CMake Warning at out_of_tree_boards/boards/arm/mec1501_adl/CMakeLists.txt:26 (message):Microchip SPI Image Generation tool (everglades_spi_gen_RomE.exe) is notavailable. SPI Image will not be generated.CMake Warning at E:/ecfw/zephyr/CMakeLists.txt:870 (message):No SOURCES given to Zephyr library: drivers__spiExcluding target from build.-- Configuring done (9.7s)
-- Generating done (0.2s)
-- Build files have been written to: E:/ecfw/zephyr/build
-- west build: building application
[1/210] Generating include/generated/version.h
-- Zephyr version: 3.4.0 (E:/ecfw/zephyr), build: zephyr-v3.4.0-12-g72899b67dbe4
[200/210] Linking C executable zephyr\zephyr_pre0.elf; Logical command for additional byproducts on target: zephyr_pre0[204/210] Linking C executable zephyr\zephyr_pre1.elf; Logical command for additional byproducts on target: zephyr_pre1[210/210] Linking C executable zephyr\zephyr.elf; Generating files from zephyr.elf for board: mec1501_adl
Memory region Used Size Region Size %age UsedFLASH: 79076 B 224 KB 34.47%RAM: 17968 B 32 KB 54.83%IDT_LIST: 0 GB 2 KB 0.00%