飞腾UEFI开发环境搭建与编译实操

前段时间都在测试飞腾的UEFI固件,这里记录下UEFI固件的编译环境搭建和编译流程,汇总开发过程中遇到的各类报错,以及解决方法。

环境搭建:

  • 交叉工具链配置
    飞腾是arm64芯片,所以UEFI固件需提前部署aarch64 交叉编译工具链,本文使用 gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu 版本,统一存放至 /opt/toolchain 目录

需要根据文档要求,配置对应版本的工具链,不然可能会因为系统差异导致一些依赖库错误

1
tar -xf gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz 

编译流程

我拿到的SDK有两个,D3000和D20004C芯片,2004C代码较老,环境问题较多。大致步骤如下:

D3000

  • D3000 UEFI 固件编译:
    编译带日志固件
    ./build-d3000.sh d

  • D3000 BIOS打包:
    ./my_scripts/image-fix.sh

  • 修改参数配置:
    ./my_scripts/fix_parameter.sh
    详细参数配置规则可参考飞腾官方开发文档。

D20004C

1、前期准备

提前解压源码与打包工具:

  • EDK2 源码:edk2-code-4.2.0.rar
  • 固件打包工具:image_fix_ft2004c_v2.12.tar.gz

2、源码编译

1
2
3
4
5
6
7
8
9
# 初始化环境
./build2004c.sh init

# 编译
./build2004c.sh d

# 打包
./my_scripts/image-fix.sh bl33

源文件解读

飞腾的UEFI SDK整体基于开源EDK2框架开发,工程内包含多种后缀的源码与配置文件,这里重点解读开发调试中最常见的几类文件。

.asl
ASL(ACPI Source Language)ACPI 源语言文件,是 UEFI 中电源管理、硬件设备枚举的核心配置文件。

.inf 文件
工程模块描述文件,相当于模块编译配置清单,记录当前模块依赖的库文件、源码路径、编译架构、编译器规则。

.dsc 文件
平台工程描述文件,整个UEFI平台的顶层编译配置。定义全局编译架构、编译工具链、宏定义、包含的所有模块。

.dec 文件
库包声明文件,用于定义公共协议、全局 GUID、PPI、库接口等;

日常二次开发、移植适配时,大多只需要修改ASL设备描述、微调 dsc/inf 编译配置,即可完成硬件适配与功能裁剪。

编译问题记录

在编译过程中遇到的一些报错,如果遇到类似,可以参考下。

  • 执行文件权限报错
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
ERROR: testRandomDataCycles (TianoCompress.Tests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/lgw/Disk/FT_UEFI/edk2/BaseTools/Tests/TianoCompress.py", line 60, in testRandomDataCycles
self.compressionTestCycle(data)
File "/home/lgw/Disk/FT_UEFI/edk2/BaseTools/Tests/TianoCompress.py", line 34, in compressionTestCycle
result = self.RunTool(
File "/home/lgw/Disk/FT_UEFI/edk2/BaseTools/Tests/TestTools.py", line 121, in RunTool
Proc = subprocess.Popen(
File "/usr/lib/python3.10/subprocess.py", line 971, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.10/subprocess.py", line 1863, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: '/home/lgw/Disk/FT_UEFI/edk2/BaseTools/BinWrappers/PosixLike/TianoCompress'

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

解决方法:

1
2
chmod -R +x /home/lgw/Disk/FT_UEFI/edk2/BaseTools/BinWrappers/

  • python 执行出错
1
2
3
4
make[1]: Leaving directory '/home/lgw/Disk/FT_UEFI/edk2/BaseTools/Tests'
make: *** [GNUmakefile:19: Tests] Error 2
make: Leaving directory '/home/lgw/Disk/FT_UEFI/edk2/BaseTools'
../uefi-tools/edk2-build.sh: line 299: /home/lgw/Disk/FT_UEFI/uefi-tools/parse-platforms.py: Permission denied

解决方法:

1
2
chmod -R +x /home/lgw/Disk/FT_UEFI/uefi-tools/

  • 升级过程中,出现如下错误
1
2
3
4
5
../uefi-tools/edk2-build.sh: /home/lgw/Disk/FT_UEFI/uefi-tools/parse-platforms.py: /usr/bin/python: bad interpreter: No such file or directory
unknown arg peach
usage:


原因:python 在系统中没有找到,但是之前我安装过miniconda3
发现python3在miniconda3中

1
2
which python3
/home/lgw/miniconda3/bin/python3

解决方法:

1
2
sudo ln -s /home/lgw/miniconda3/bin/python3 /usr/bin/python

  • 能够编译了,后续缺少交叉编译链接
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

OK
make[1]: Leaving directory '/home/lgw/Disk/FT_UEFI/edk2/BaseTools/Tests'
make: Leaving directory '/home/lgw/Disk/FT_UEFI/edk2/BaseTools'
/home/lgw/Disk/FT_UEFI/edk2-platforms
path: /home/lgw/Disk/FT_UEFI/.git
Target: AARCH64
Build: X64
Building Peach Platform (AARCH64) - AARCH64
CROSS_COMPILE="aarch64-linux-gnu-"
peach_BUILDFLAGS=' '
PLATFORM_TOOLCHAIN is
Toolchain prefix: _AARCH64_PREFIX=aarch64-linux-gnu-
Build environment: Linux-6.8.0-90-generic-x86_64-with-glibc2.35
Build start time: 14:36:55, Jan.26 2026



build.py...
: error 1005: Not supported target [platform/phytium/peachpkg/peachpkg.dsc].
Please select one of: all genc genmake modules libraries fds clean cleanall cleanlib run

- Failed -
Build end time: 14:36:55, Jan.26 2026
Build total time: 00:00:00

解决方法:

1
2
sudo apt update && sudo apt install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu

  • 缺少iasl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/bin/sh: line 1: iasl: command not found
make: *** [GNUmakefile:306: /home/lgw/Disk/FT_UEFI/edk2-platforms/Build/PeachPkg/DEBUG_GCC5/AARCH64/Platform/Phytium/PeachPkg/AcpiTables/AcpiTables/OUTPUT/AcpiSsdtRootPci.aml] Error 127


build.py...
: error 7000: Failed to execute command
make tbuild [/home/lgw/Disk/FT_UEFI/edk2-platforms/Build/PeachPkg/DEBUG_GCC5/AARCH64/Platform/Phytium/PeachPkg/AcpiTables/AcpiTables]


build.py...
: error F002: Failed to build module
/home/lgw/Disk/FT_UEFI/edk2-platforms/Platform/Phytium/PeachPkg/AcpiTables/AcpiTables.inf [AARCH64, GCC5, DEBUG]

- Failed -

解决方法:

1
sudo apt install -y iasl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Please note: This script must be 'sourced' so the environment can be changed.
. edksetup.sh
source edksetup.sh
make: Entering directory '/home/lgw/Disk/FT_UEFI/edk2/BaseTools'
make -C Source/C
make[1]: Entering directory '/home/lgw/Disk/FT_UEFI/edk2/BaseTools/Source/C'
Attempting to detect HOST_ARCH from 'uname -m': x86_64
Detected HOST_ARCH of X64 using uname.
mkdir -p .
make -C Common
make[2]: Entering directory '/home/lgw/Disk/FT_UEFI/edk2/BaseTools/Source/C/Common'
make[2]: *** No rule to make target '/usr/include/x86_64-linux-gnu/bits/sys_errlist.h', needed by 'BasePeCoff.o'. Stop.
make[2]: Leaving directory '/home/lgw/Disk/FT_UEFI/edk2/BaseTools/Source/C/Common'
make[1]: *** [GNUmakefile:76: Common] Error 2
make[1]: Leaving directory '/home/lgw/Disk/FT_UEFI/edk2/BaseTools/Source/C'
make: *** [GNUmakefile:19: Source/C] Error 2
make: Leaving directory '/home/lgw/Disk/FT_UEFI/edk2/BaseTools'
Adding Build target: DEBUG
Loading previous configuration from /home/lgw/Disk/FT_UEFI/edk2/Conf/BuildEnv.sh
Using EDK2 in-source Basetools
WORKSPACE: /home/lgw/Disk/FT_UEFI/edk2-platforms
EDK_TOOLS_PATH: /home/lgw/Disk/FT_UEFI/edk2/BaseTools
CONF_PATH: /home/lgw/Disk/FT_UEFI/edk2/Conf
Copying $EDK_TOOLS_PATH/Conf/build_rule.template
to /home/lgw/Disk/FT_UEFI/edk2/Conf/build_rule.txt
Copying $EDK_TOOLS_PATH/Conf/tools_def.template
to /home/lgw/Disk/FT_UEFI/edk2/Conf/tools_def.txt
Copying $EDK_TOOLS_PATH/Conf/target.template
to /home/lgw/Disk/FT_UEFI/edk2/Conf/target.txt
make: Entering directory '/home/lgw/Disk/FT_UEFI/edk2/BaseTools'
make -C Source/C
make -C Source/Python
make[1]: Entering directory '/home/lgw/Disk/FT_UEFI/edk2/BaseTools/Source/C'
make[1]: Entering directory '/home/lgw/Disk/FT_UEFI/edk2/BaseTools/Source/Python'
make[1]: Nothing to be done for 'all'.
Attempting to detect HOST_ARCH from 'uname -m': x86_64make[1]: Leaving directory '/home/lgw/Disk/FT_UEFI/edk2/BaseTools/Source/Python'

Detected HOST_ARCH of X64 using uname.
mkdir -p .
make -C Common
make[2]: Entering directory '/home/lgw/Disk/FT_UEFI/edk2/BaseTools/Source/C/Common'
make[2]: *** No rule to make target '/usr/include/x86_64-linux-gnu/bits/sys_errlist.h', needed by 'BasePeCoff.o'. Stop.
make[2]: Leaving directory '/home/lgw/Disk/FT_UEFI/edk2/BaseTools/Source/C/Common'
make[1]: *** [GNUmakefile:76: Common] Error 2
make[1]: Leaving directory '/home/lgw/Disk/FT_UEFI/edk2/BaseTools/Source/C'
make: *** [GNUmakefile:19: Source/C] Error 2
make: Leaving directory '/home/lgw/Disk/FT_UEFI/edk2/BaseTools'
/home/lgw/Disk/FT_UEFI/edk2-platforms
!!! BaseTools failed to build !!!

解决方法:

1
2
sudo mkdir -p /usr/include/x86_64-linux-gnu/bits/ && sudo touch /usr/include/x86_64-linux-gnu/bits/sys_errlist.h