UEFI Build file

本文详细介绍了UEFI(统一可扩展固件接口)的构建文件流程,涵盖了从源码准备到编译、链接的步骤,揭示了UEFI程序在固件层的构建原理,适合对固件开发感兴趣的读者深入理解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Mouble 一个模块,有.inf的文件编译
Package 有0个或许多个Mouble组成,有.dsc和.dec文件
Platform 一个特殊的Package文件一定包含一个.dec文件


EDK II 发展史:
    1、创造了Package用于整合Mouble,作为基础的Mouble的合集,也定义了DEC文件和GUID、Protocols
    2、由于产生了Package,必须创建INF文件用于规范Mouble的属性和结构。
    3、创建DSC文件用于编译
    4、调整Mouble,用于适应于开发出来的体系

Build
    Parsing_Tool:
        INF\DEC\DSC\Target.txt\Tool_def.txt\FDF
    -------->Makefile\Auto.c\Auto.h
    -------->Build(source filde)
    -------->.EFI



EDK II Package
1、包含了许多Mouble和一个DEC
2、提供: MdePkg, MdeModulePkg, etc.基础的包
3、基础包含Include, Library, Application and Drivers.


Sample example:
    Package.dec
    Package.dsc
    Library:
        NameOnelib
        NameTwolib
    Include:
        Protocols
        Library
        Ppi
        Guid 
        IndustryStanard
    Application
    NameOneDxe
    NameOnePei

描述文件:DEC
    定义了属性,库引用,协议,版本号等
Demo;
[Defines] 
    DEC_SPECIFICATION = 0x00010005 
    PACKAGE_NAME = PackageName
    PACKAGE_GUID = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 
    PACKAGE_VERSION = 0.1 
[Includes] 
    Include #Package Include directory 
[LibraryClasses] 
    ## Library class name is same to library header file name 
    OneClassLib|Include/Library/OneClassLib.h 
[Guids] 
    #GuidCName = {xxxxxxxx,xxxx,xxxx,{xx,xx,xx,xx,xx,xx,xx,xx}}, 
[Ppis] 
    #PpiGuidCName = {xxxxxxxx,xxxx,xxxx,{xx,xx,xx,xx,xx,xx,xx,xx}}, 
[Protocols] 
    #ProtocolGuidCName = {xxxxxxxx,xxxx,xxxx,{xx,xx,xx,xx,xx,xx,xx,xx}}, 
[PcdsFeatureFlag] 
    #FeatureFlag PCD is BOOLEAN type, the value is TRUR or FALSE. 
    #PcdTokenSpaceCGuidName.PcdName|TRUE|BOOLEAN|TokenNumber 
    #PcdTokenSpaceCGuidName.PcdName|FALSE|BOOLEAN|TokenNumber 
[PcdsFixedAtBuild] 
    #PcdTokenSpaceCGuidName.PcdName|DefaultValue|DataType|TokenNumber 
[PcdsPatchableInModule] 
    #PcdTokenSpaceCGuidName.PcdName|DefaultValue|DataType|TokenNumber 
[PcdsDynamic] 
    #PcdTokenSpaceCGuidName.PcdName|DefaultValue|DataType|TokenNumber 
[PcdsDynamicEx] 
    #PcdTokenSpaceCGuidName.PcdName|DefaultValue|DataType|TokenNumber

DSC文件主要是用于编译,但也描述了定义,库等内容

Demo:
[Defines] 
    PLATFORM_NAME = PacakgeName 
    PLATFORM_GUID = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 
    PLATFORM_VERSION = 0.1 
    DSC_SPECIFICATION = 0x00010005 
    OUTPUT_DIRECTORY = Build/PackageName 
    SUPPORTED_ARCHITECTURES = IA32|IPF|X64|EBC 
    BUILD_TARGETS = DEBUG|RELEASE 
    SKUID_IDENTIFIER = DEFAULT 
[SkuIds] 
    0|DEFAULT #The entry: 0|DEFAULT is reserved and required. 
[LibraryClasses] 
    ## More library instances need to be added if more library classes are 
used 
    ## by the components in the following [Components] section. 
    ## library class name | library instance INF file path from package 
    DebugLib | MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf 
    BaseLib | MdePkg/Library/BaseLib/BaseLib.inf 
    BaseMemoryLib | MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf 
    …… 
    ##PCDs sections are not specified. 
    ##All PCDs value are from their Default value in DEC. 
##[PcdsFeatureFlag] 
##[PcdsFixedAtBuild] 
[Components] 
    ## All libraries, drivers and applications are added here to be compiled 
    ## Module INF file path are specified from package directory. 
    PackageNamePkg/Library/NameOneLib/NameOneLib.inf 
    PackageNamePkg/NameOneDxe/NameOneDxe.inf 
    PackageNamePkg/NameTwoPei/NameTwoPei.inf 

创建Package;
    1、当需要添加自己创建的Package时,首先需要创建一个符合规范的命名
    2、创建DEC和DSC文件
    3、创建目录用于包含所需要的源文件(Include\Library\Dxe\Pei)
Use Package:
    1、当一个Mouble在创建后,编写时,需要引用Package中一些库,函数时就需要将这个Package添加进来
    2、每个DSC文件中都包含了该Package所提供的模块,可以通过寻找这些DEC文件获取需要的Mouble.
更新 Package:
    当源文件改变时,需要更改Package.
更新 Package下的Include
    DEC文件中更新关于Include\LibraryClasses\Protocols\Guids模块的变更选项
    Demo:
[Includes] 
     Include # Package Include path 
     LocalInclude # Add new include path 

[Guids] 
    #gGuidCName = {00000000,0000,0000,{00,00,00,00,00,00,00,00}} 
    #updated to 
    gNewGuidCName = {00000000,0000,0000,{00,00,00,00,00,00,00,01}} 
[LibraryClasses] 
    #OneClassLib|Include/Library/OneClassLib.inf updated to 
    BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf 
[PcdsFixedAtBuild] 
    #Add new FixedAtBuild PCD 
    #PcdTokenSpaceCGuidName.PcdName|DefaultValue|DataType|TokenNumber 
    gEfiMdeModulePkgTokenSpaceGuid.PcdHelloWorldTimes|1|UINT32|0x40000005
重点:
    当Mouble的INF文件改变和其他一些改变,需要到DSC文件中去修改
Demo:
[Components] 
    #Module INF file path are specified from package directory. 
    #PackageNamePkg/NameTwoPei/NameTwoDxe.inf #updated to 
    MdeModulePkg/Application/HelloWorld/HelloWorld.inf 


EDK II Mouble

Mouble:简单来说就是一个具有某种功能的模块,包含了库,协议,源代码等。

TYPE:
    SEC      建立前期的准备,没有标准定义这个模块,但是又有相同规则,都是给PEI准备内存和栈
    PEI_CORE  被用于PI的专属操作
    PEIM      被用于PI的专属操作
    DXE_CORE   被用于PI的专属操作
    DXE_DRIVER  被用于PI的专属操作,都是在操作系统启动前,在RT之后结束
    DXE_RUNTIME_DRIVER 在启动操作系统整个过程中,建立虚拟内存映射应用于操作系统
    DXE_SAL_DRIVER 在物理内存映射之前的物理模式
    DXE_SMM_DRIVER 在操作系统下一直执行,关于CPU物理内存方面
    UEFI_DRIVER     在Boot环境下的UEFI
    UEFI_APPLICATION 在Boot环境下的UEFI的应用

创建一个Mouble
    1、选择或创建一个Mouble位置的Package
    2、创建一个目录和INF文件
    3、在INF文件中加入Package的依赖
    4、在INF中加入PPI,Protocol,Guid,Library
    5、加入Depex
    6、创建源代码,并把源代码路径加入到INF中

Mouble位置:
    一般是在Package中,所以首先要确定下Package
选择Package:
    1、相同应用范围
    2、相似的操作流程
    3、同一个类下
    4、同一平台
创建目录:
    Library Mouble
    PPI,Protocol,Guid,LibraryClasses
    Application
    Driver Mouble
    命名规则:
    xxxxPei------PEIM, PEI_CORE
    xxxxDxe------DXE_DRIVER, UEFI_DRIVER 
    xxxRuntimeDxe----DXE_RUNTIME_DRIVER 
    xxxDxeSal-------DXE_SAL_DRIVER
    xxxxLib---------Library Instance 
INF的文件

    需要包含属性,命名等基本信息
    关于Package的路径和依赖
    源文件或二进制文件的
    协议和版本(Protocol\Guid)
    库(LibraryClasses)
    其他,属性,编译,Dxe

(Application)Demo:
[Defines] 
  INF_VERSION = 0x00010005 
  BASE_NAME = HelloWorld 
  FILE_GUID = XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX 
  MODULE_TYPE = UEFI_APPLICATION 
  VERSION_STRING = 1.0 
  UEFI_SPECIFICATION_VERSION = 0x0002001E 
  ENTRY_POINT = UefiMain 
# 
# The following information is for reference only and not required by the 
#build tools. 
# 
# VALID_ARCHITECTURES = IA32 X64 IPF EBC 
# 
## 
[Sources.common] 
 HelloWorld.c 
## 
[Packages] 
  MdePkg/MdePkg.dec 
## 
[LibraryClasses] 
  UefiBootServicesTableLib 
  UefiApplicationEntryPoint 
  UefiLib 
  DebugLib 

(LibraryClasses)Demo:
[Defines] 
 INF_VERSION = 0x00010005 
 BASE_NAME = PeiServicesTablePointerLib 
 FILE_GUID = XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX 
 MODULE_TYPE = PEIM 
 VERSION_STRING = 1.0 
 LIBRARY_CLASS = PeiServicesTablePointerLib|PEIM 
PEI_CORE SEC 
 CONSTRUCTOR = PeiServicesTablePointerLibConstructor 
# 
# VALID_ARCHITECTURES = IA32 X64 IPF EBC (E
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值