FD2000/4的UEFI编译和烧录文件打包过程记录
总的来说,参考官方的文档整个过程还是比较顺利的。
1、环境说明
虚拟机:ubuntu22.04
python3版本:3.10.12
版本:image_fix_ft2004c_v2.12和edk2-code-4.2.0。
注意:复制“image_fix_ft2004c”到ubuntu中,不能是共享目录方式。
2、交叉编译器
下载地址:https://releases.linaro.org/components/toolchain/binaries/7.4-
2019.02/aarch64-linux-gnu/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz
最后解压得到/home/f/Desktop/ft2004c/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin
#######sudo vim /etc/profile
#######文件中加入下面两行:
#######export PATH=$PATH:/home/f/Desktop/ft2004c/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin
#######export CROSS_COMPILE=aarch64-linux-gnu-
#######执行:source /etc/profile
#######
#######echo $PATH
#######echo $CROSS_COMPILE
#######
#######aarch64-linux-gnu-gcc -v
官方的的说法是加入到/etc/profile中,但是这样会导致虚拟机中其他项目编译时也会使用这个交叉编译器,所以我不写入文件,只是在终端中临时使用,具体操作见后续的编译过程。
3、其他库
sudo apt-get install libncurses5-dev
sudo apt-get install libncursesw5-dev
sudo apt-get install uuid-dev
sudo apt-get install acpica-tools
//sudo apt-get install python
//sudo apt-get install g++
4、git本地仓建立
sudo apt-get install git
cd edk2-code-4.2.0/edk2-for-support
git init
git config --global user.email "XXXX@qq.com"
git config --global user.name "XXXX"
git status
git add .
git commit -m "初始提交:项目初始化"
git log
5、UEFI编译
5.1、临时交叉编译链
cd edk2-code-4.2.0/edk2-for-support
export PATH=$PATH:/home/f/Desktop/ft2004c/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin
export CROSS_COMPILE=aarch64-linux-gnu-
aarch64-linux-gnu-gcc -v
5.2、编译前的一些修改工作
主要是GCC和python版本匹配导致的,如果按照官方的说的ubuntu18.04去做,可能没问题,但是我这里有ubuntu22.04。
修改项:
1)BaseTools/Source/C/BrotliCompress/GNUmakefile文末加“BUILD_CFLAGS += -Wno-vla-parameter“
2)BaseTools/Source/Python/AutoGen/UniClassObject.py的312行的Ucs2Info = codecs.lookup('ucs-2')为Ucs2Info = codecs.lookup('utf-16')
3)BaseTools/Source/Python/Common/Misc.py的1651行的if ByteArray.tostring() != b'PE\0\0':修改为if ByteArray.tobytes() != b'PE\0\0':
4)BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py的462行的SectionData.fromstring(Ui.encode("utf_16_le"))改为SectionData.frombytes(Ui.encode("utf_16_le"))
5)BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py的469行的SaveFileOnChange(Output, SectionData.tostring())改为SaveFileOnChange(Output, SectionData.tobytes())
5.3、编译过程
./build2004.sh clean //编译前的清除
./build2004.sh init //初始化,主要是生成基础工具,这个是在x86虚拟机上运行的,所以编译过程可能看到的是gcc,这是正常的。
./build2004.sh d //带打印的debug版本
编译结果日志如下:Fd File Name:PHYTIUM (/home/f/Desktop/ft2004c/edk2-code-4.2.0/edk2-for-support/Build/PhytiumPkg/Phytium2004Pkg/Phytium/DEBUG_GCC49/FV/PHYTIUM.fd)Generate Region at Offset 0x0Region Size = 0x20000Region Name = FVGenerating FV_SEC FV#####Generate Region at Offset 0x20000Region Size = 0x20000Region Name = DATAGenerate Region at Offset 0x40000Region Size = 0x10000Region Name = DATAGenerate Region at Offset 0x50000Region Size = 0x20000Region Name = NoneGenerate Region at Offset 0x70000Region Size = 0x1E0000Region Name = FVGenerating FVMAIN_COMPACT FVGenerating FVMAIN FV#######################################################################################################################################################################################################################################################Generate Region at Offset 0x250000Region Size = 0x1E0000Region Name = FVGUID cross reference file can be found at /home/f/Desktop/ft2004c/edk2-code-4.2.0/edk2-for-support/Build/PhytiumPkg/Phytium2004Pkg/Phytium/DEBUG_GCC49/FV/Guid.xrefFV Space InformationFV_SEC [83%Full] 131072 total, 109440 used, 21632 freeFVMAIN_COMPACT [97%Full] 1966080 total, 1914984 used, 51096 freeFVMAIN [99%Full] 15269888 total, 15208176 used, 61712 freeBuild report can be found at /home/f/Desktop/ft2004c/edk2-code-4.2.0/edk2-for-support/Build/build.log- Done -Build end time: 18:11:24, Nov.12 2025Build total time: 00:00:13aarch64-binfmt-P: Could not open '/lib/ld-linux-aarch64.so.1': No such file or directory0+1 records in0+1 records out1408 bytes (1.4 kB, 1.4 KiB) copied, 0.000197681 s, 7.1 MB/s0+1 records in0+1 records out657041 bytes (657 kB, 642 KiB) copied, 0.000975822 s, 673 MB/s0+1 records in0+1 records out932912 bytes (933 kB, 911 KiB) copied, 0.00134274 s, 695 MB/s3+1 records in3+1 records out468328 bytes (468 kB, 457 KiB) copied, 0.000704052 s, 665 MB/sdd: failed to open 'fipnew.bin': No such file or directorygenerate ft2004.fd OK.3745128 ft2004.fdrm: cannot remove 'fipnew.bin': No such file or directorybuild end../build2004.sh r //不带打印的relese版本
5.4、生成的文件
在根目录下生成了bios2004。
6、烧录文件生成
在image_fix_ft2004c目录中,创建 bios2004 的软连接为 bl33_new.bin,命令如下:
ln -s bios2004 bl33_new.bin
6.1、修改参数
1)./my_scripts/fix_parameter.sh //会弹出menuconfig界面,根据需要自行修改即可。
2)代码修改:my_scripts/get_parameter/do_config/include/config.h中把../../pack_config.h改为#include "../../pack_config.h"
6.2、打包
./my_scripts/image-fix.sh
执行成功后,根目录下的fip-all.bin文件即为可以烧录的固件,使用 spi flash 烧录器把该文件烧写到 bios flash 芯片即可。
打包过程的打印如下:
scripts/kconfig/conf --silentoldconfig KconfigCFG pack_config.hGEN include/autoconf.mkCHK include/config.hGEN include/autoconf.mk.depCFG pack_config.h
===================== done ========================make config file success
====================================================
initrd_start = 0x1900000
initrd_size = 0x0
initrd_size_bd = 0x0enabled update bl33.bin>>>>fip-all.bin pk <<<<
8.2M fip-all.bin/****** Pll info ----- Magic : 0x54460010 ----- Version : v0.1 ******/cpu frq : 2300 MHZ
lmu frq : 667 MHZ/*****************************************************************//****** Peu info ----- Magic : 0x54460011 ----- Version : v0.4 ******/independent_tree mode : 0x0
force equalization for W2: 0x0
PEU 0 : init--X8X8X1--RC--Gen3-Gen3-Gen3--p0-p1-p2
PEU 0 : equalization <0x7-0x7-0x7>
PEU 1 : init--X8X8X1--RC--Gen3-Gen3-Gen3--p0-p1-p2
PEU 1 : equalization <0x7-0x7-0x7>/*****************************************************************//****** Common info ----- Magic : 0x54460013 ----- Version : v0.2 ******/cluster 0 : core_0 core_1
cluster 1 : core_0 core_1
cpu OTP : enable/*****************************************************************//****** Mcu info ----- Magic : 0x54460014 ----- Version : v0.7 ******/CH enable : CH_0 & CH_1
ECC enable : enable
ECC writeback en : disable
DM enable : enable
DBI enable : disable
PDA invert : disable
1 CH driven 2 slot : disable
high performance mode : enable
2T preamble : disable
2T preamble plus : disable
skip scrub : disable
mult-rank high mode : disable
2rank rtt recfg en : disable
fix 2x refresh mode : disable
dq oe timing : 0x42
spd force : enableDDR4UDIMM/X16/No mirror/NO ECC/1 Rank/16 Row/10 Column/4 Bank Groups/4 BankstAAmin: 13750tRCDmin: 13750tRPmin: 13750tRASmin: 32000tRCmin: 45750tFAWmin: 21000tRRD_Smin: 3300tRRD_Lmin: 4900tCCD_Lmin: 5000tWRmin: 15000tWTR_Smin: 2500tWTR_Lmin: 7500
training : adaptive training to find the best param
train debug : normal
auto low power enable : disable
MEM encrypt : bypass
TZC : bypass/*****************************************************************//****** Board info ----- Magic : 0x54460015 ----- Version : v0.1 ******/read spd freq : disablewake up with se : disable
power ctr source : CPLD
qspi flash speed : 3 - 4.6MHZ /*****************************************************************//****** Pbf info ----- Magic : 0x54460000 ----- Version : v0.1 ******/cpu base frq : 48 MHZ
uart_level: rank 1
log_level : full
uart baud 115200
/*****************************************************************/