当前位置:网站首页>UEFI learning 01-arm aarch64 compilation, armplatformpripeicore (SEC)
UEFI learning 01-arm aarch64 compilation, armplatformpripeicore (SEC)
2022-04-23 13:15:00 【MyeDy】
List of articles
1. AARCH64 Build the compilation environment
git clone https://github.com/tianocore/edk2-platforms.git
git clone https://github.com/acpica/acpica.git
git clone https://github.com/tianocore/edk2.git
cd edk2
git submodule update --init
cd ..
sudo apt-get install gcc-aarch64-linux-gnu
sudo apt-get install qemu-system-aarch64
export WORKSPACE=$PWD
export PACKAGES_PATH=$WORKSPACE/edk2:$WORKSPACE/edk2-platforms
export IASL_PREFIX=$WORKSPACE/acpica/generate/unix/bin/
export GCC5_AARCH64_PREFIX=/usr/bin/aarch64-linux-gnu-
source edk2/edksetup.sh
build -a AARCH64 -t GCC5 -p edk2/ArmVirtPkg/ArmVirtQemu.dsc -b DEBUG
After compiling, it will generate UEFI file :Build/ArmVirtQemu-AARCH64/DEBUG_GCC5/FV/QEMU_EFI.fd
Run the command as follows
qemu-system-aarch64 -M virt -cpu cortex-a57 -bios Build/ArmVirtQemu-AARCH64/DEBUG_GCC5/FV/QEMU_EFI.fd -net none -serial stdio
2. ArmPlatformPriPeiCore
Most tutorials use OVMF To make the sample ,OVMF The first to run UEFI The module is SEC. but AARCH64 Medium SEC This is it ArmPlatformPriPeiCore. So in edk2 Of AARCH64 Example ,ArmPlatformPriPeiCore Is the first module to run .
2.1 QEMU_EFI.fd What is included
We use it UEFITool NE open QEMU_EFI.fd, You can see the following figure

- ArmPlatformPrePeiCore, Act as the SEC core Module . from 0x1000 Deposit
- PeiCore,PEI Core Code for
- 7 individual PEIM
PEIM function PlatformPei initialization SOC Platform related code MemoryInit Initialize memory CpuPei initialization ARM cortex a57 cluster PcdPeim Provide dynamic Pcd PeiVariablePei Not used DxeIplPei Provide load DXE The function of - And finally a Volumn image, This is a compressed volume , It contains PEI Later stage image, Such as DXE, BSD wait . Need to be in PEI Unzip and run .
2.2 QEMU virt aarch64 relevant
- ROM The space of is 0x00000000 - 0x3FFFFFFF
- RAM The space is 0x40000000 - 0x7FFFFFFF
- CPU The first instruction is in 0 Address operation , That is to say ROM On
- QEMU_EFI.fd The documents are stored in ROM On , From 0 Address start
2.3 From the first instruction to ArmPlatformPrePeiCore entrance
from 2.2 We know CPU The first instruction is from 0 Address execution , that QEMU_EFI.fd The first one in word Stored something ? View with binary editor QEMU_EFI.fd You can see in the 0 The address stores a word:0x14000400.

This is a jump command , according to armv8a Look at your manual , This command is b pc+0x1000.CPU When it started ,PC The register is 0, So this command will jump directly to 0x1000 Address .

Then look at the same 0x1000 Address data . Another jump command 0x14000d16. The result is b pc+0x3458, At present pc yes 0x1000, So he jumped to 0x4458.

that 0x4458 What is stored ?
First, through disassembly ArmPlatformPrePeiCore.debug, You can get 0x3458 yes ArmPlatformPrePeiCore Of _ModuleEntryPoint

And then we look at QEMU_EFI.fd Of 0x4458 Data stored at the address of , It's corresponding to _ModuleEntryPoint The first instruction of . We know ArmPlatformPrePeiCore It's from 0x1000 Deposited , So in fact 0x4458 Namely ArmPlatformPrePeiCore Of _ModuleEntryPoint. and ArmPlatformPrePeiCore The compiled code is location independent code , So pass 0 Address and 0x1000 Two jumps of address , Finally jump to ArmPlatformPrePeiCore Of _ModuleEntryPoint in .

2.4 ArmPlatformPrePeiCore Did something
ArmPlatformPrePeiCore It's simple , Primary initialization CPU, Set the stack pointer , initialization PEI Parameters required for the phase SecCoreData Finally jump to PEI core In the middle .
The function call stack is as follows :
_ModuleEntryPoint
_SetupPrimaryCoreStack
_PrepareArguments
CEntryPoint
PrimaryMain
(PeiCoreEntryPoint)(&SecCoreData, PpiList);
_ModuleEntryPoint
edk2/ArmPlatformPkg/PrePeiCore/AArch64/PrePeiCoreEntryPoint.S
This first calls ArmPlatformPeiBootAction, This function is an empty implementation , It doesn't really work . Then call SetupExceptionLevel1 Set up EL1 Environment , And then jump to MainEntryPoint.
ASM_FUNC(_ModuleEntryPoint)
// Do early platform specific actions
bl ASM_PFX(ArmPlatformPeiBootAction)
EL1_OR_EL2(x0)
1:bl ASM_PFX(SetupExceptionLevel1)
b ASM_PFX(MainEntryPoint)
MainEntryPoint Read in CPU ID Configure the stack pointer , If it is primary core Is set primary Stack , If it is secondary core Is set secondary Stack . We'll just talk about primary core. Stack pointer from FIX PCD In order to get
ASM_PFX(MainEntryPoint):
MOV64 (x1, FixedPcdGet64(PcdCPUCoresStackBase) + FixedPcdGet32(PcdCPUCorePrimaryStackSize))
// x0 is equal to 1 if I am the primary core
cmp x0, #1
b.eq _SetupPrimaryCoreStack
_SetupPrimaryCoreStackz Stack registers are mainly configured in SP, And then jump to _PrepareArguments
_SetupPrimaryCoreStack:
mov sp, x1
...
b _PrepareArguments
_PrepareArguments from PCD I'll get PEI CORE Of entry, Then pass it to CEntryPoint, The back is C Code.
_PrepareArguments:
// The PEI Core Entry Point has been computed by GenFV and stored in the second entry of the Reset Vector
MOV64 (x2, FixedPcdGet64(PcdFvBaseAddress))
ldr x1, [x2, #8]
// Move sec startup address into a data register
// Ensure we're jumping to FV version of the code (not boot remapped alias)
ldr x3, =ASM_PFX(CEntryPoint)
CEntryPoint
edk2/ArmPlatformPkg/PrePeiCore/PrePeiCore.c
CEntryPoint It mainly initializes some ARM CPU Something about , close cache, open VFP, Set up VBAR And so on. , And then jump to PrimaryMain In the .
CEntryPoint (
IN UINTN MpId,
IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
)
{
// Close all Dcache
ArmDisableDataCache ();
// Invalid all ICache
ArmInvalidateInstructionCache ();
// Can make ICACHE
ArmEnableInstructionCache ();
// Brush off the stack Dcache
InvalidateDataCacheRange (
(VOID *)(UINTN)PcdGet64 (PcdCPUCoresStackBase),
PcdGet32 (PcdCPUCorePrimaryStackSize)
);
// Set up VBAR To PeiVectorTable --> PEI Exception vector table
ArmWriteVBar ((UINTN)PeiVectorTable);
// Enable floating point units
ArmEnableVFP ();
PrimaryMain (PeiCoreEntryPoint);
}
PrimaryMain
edk2/ArmPlatformPkg/PrePeiCore/MainMPCore.c
PrimaryMain It mainly established SEC Phase to phase PEI Of PPI list, And then configure it SecCoreData Structure , Jump to PeiCore In the middle .
VOID
EFIAPI
PrimaryMain (
IN EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
)
{
...
// establish SEC Stage PPI
CreatePpiList (&PpiListSize, &PpiList);
// Can make GIC
ArmGicEnableDistributor (PcdGet64 (PcdGicDistributorBase));
...
// from PCD In order to get TempStack Of base,TempStack Temporary memory before permanent memory initialization
TemporaryRamBase = (UINTN)PcdGet64 (PcdCPUCoresStackBase) + PpiListSize;
// from PCD In order to get TempStack Size
TemporaryRamSize = (UINTN)PcdGet32 (PcdCPUCorePrimaryStackSize) - PpiListSize;
SecCoreData.DataSize = sizeof (EFI_SEC_PEI_HAND_OFF);
// from PCD In order to get PEI Of FV Address and length and store in SecCoreData in
SecCoreData.BootFirmwareVolumeBase = (VOID *)(UINTN)PcdGet64 (PcdFvBaseAddress);
SecCoreData.BootFirmwareVolumeSize = PcdGet32 (PcdFvSize);
SecCoreData.TemporaryRamBase = (VOID *)TemporaryRamBase; // We run on the primary core (and so we use the first stack)
SecCoreData.TemporaryRamSize = TemporaryRamSize;
SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase;
SecCoreData.PeiTemporaryRamSize = ALIGN_VALUE (SecCoreData.TemporaryRamSize / 2, CPU_STACK_ALIGNMENT);
SecCoreData.StackBase = (VOID *)((UINTN)SecCoreData.TemporaryRamBase + SecCoreData.PeiTemporaryRamSize);
SecCoreData.StackSize = (TemporaryRamBase + TemporaryRamSize) - (UINTN)SecCoreData.StackBase;
// Jump to PEI core entry point
PeiCoreEntryPoint (&SecCoreData, PpiList);
}
We are PeiCore The entrance of the has been added with printing , hold SecCoreData dump Come out as follows
DataSize:48
BootFirmwareVolumeBase:00000001000
BootFirmwareVolumeSize:000001FF000
TemporaryRamBase:0004007C030
TemporaryRamSize:00000003FD0
PeiTemporaryRamBase:0004007C030
PeiTemporaryRamSize:00000001FF0
StackBase:0004007E020
StackSize:00000001FE0
thus ,SEC It's over , The back is PEI The execution of the phase
版权声明
本文为[MyeDy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230612364784.html
边栏推荐
- Uninstall MySQL database
- [Technical Specification]: how to write technical documents?
- 你和42W奖金池,就差一次“长沙银行杯”腾讯云启创新大赛!
- pyqt5 将opencv图片存入内置SQLlite数据库,并查询
- Design of body fat detection system based on 51 single chip microcomputer (51 + OLED + hx711 + US100)
- How to convert opencv pictures to bytes
- Use Proteus to simulate STM32 ultrasonic srf04 ranging! Code+Proteus
- MySQL basic statement query
- 这几种 VSCode 扩展是我最喜欢的
- Nodejs + websocket cycle small case
猜你喜欢

Kernel error: no rule to make target 'Debian / canonical certs pem‘, needed by ‘certs/x509_ certificate_ list‘

MySQL 8.0.11 download, install and connect tutorials using visualization tools

解决Oracle中文乱码的问题

three.js文字模糊问题

AUTOSAR from introduction to mastery 100 lectures (86) - 2F of UDS service foundation

nodejs + mysql 实现简单注册功能(小demo)

Important knowledge of network layer (interview, reexamination, term end)

vscode小技巧

数据仓库—什么是OLAP

The difference between string and character array in C language
随机推荐
Mui wechat payment pit
AUTOSAR from introduction to mastery 100 lectures (81) - FIM of AUTOSAR Foundation
Filter and listener of three web components
【动态规划】221. 最大正方形
[Technical Specification]: how to write technical documents?
CSDN College Club "famous teacher college trip" -- Hunan Normal University Station
Design of STM32 multi-channel temperature measurement wireless transmission alarm system (industrial timing temperature measurement / engine room temperature timing detection, etc.)
MySQL -- 16. Data structure of index
MySQL 8.0.11下载、安装和使用可视化工具连接教程
5 tricky activity life cycle interview questions. After learning, go and hang the interviewer!
Solve the problem that Oracle needs to set IP every time in the virtual machine
AUTOSAR from introduction to mastery lecture 100 (84) - Summary of UDS time parameters
AUTOSAR from introduction to mastery 100 lectures (87) - key weapon of advanced EEA - AUTOSAR and DDS
Office 2021 installation package download and activation tutorial
The first lesson is canvas, showing a small case
2021年6月程序员工资统计,平均15052元,你拖后腿了吗?
Learning notes of AMBA protocol
普通大学生如何拿到大厂offer?敖丙教你一招致胜!
Esp32 vhci architecture sets scan mode for traditional Bluetooth, so that the device can be searched
将opencv 图片转换为字节的方式