栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

DellaOS引导程序篇

DellaOS引导程序篇

DellaOS引导程序篇 1、环境配置

这里环境位centos7(带图形界面)

1.1、centos7没网
cd /etc/sysconfig/network-scripts/
vim ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_onLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=86312406-5cb4-4200-9903-2b7745ca4e97
DEVICE=ens33
onBOOT=yes
systemctl restart network
1.2、更新yum
sudo yum install wget -y
sudo wget -O /etc/yum.repos.d/CentOS-base.repo https://mirrors.tencent.com/repo/centos7_base.repo
sudo yum clean all
sudo yum makecache

安装依赖

sudo yum install gtk2 gtk2-devel libXt libXt-devel libXpm libXpm-devel SDL SDL-devel xorg-x11-server-devel nasm gcc-c++ glibc-headers libX11-devel libXrandr-devel lrzsz -y
1.3、zip
yum install -y unzip zip
1.4、安装git
yum -y install git
1.5、VPN(clash,需要在windows上安装过)
C:Usersxumeng03.config
上传到
/root/.config
订阅
wget https://mymonocloud.com/clash/457240/5K9yNAE6yMnc
mv 5K9yNAE6yMnc config.yaml
gunzip clash-linux-amd64-v1.8.0.gz

修改代理如下图

启动

./clash-linux-amd64-v1.8.0
1.6、edk2-UDK2018

安装依赖

yum install build-essential git uuid-dev iasl nasm libuuid-devel

拉取分支

#git clone https://github.com/tianocore/edk2.gitgit clone git://github.com/tianocore/edk2.git

切换分支

cd edk2/git checkout UDK2018

编译

make -C baseTools/baseTools/BuildEnv. ./edksetup.sh

修改配置文件

vim Conf/target.txt

target.txt

# ACTIVE_PLATFORM       = Nt32Pkg/Nt32Pkg.dsc
ACTIVE_PLATFORM = OvmfPkg/OvmfPkgX64.dsc

TARGET                = DEBUG

# TARGET_ARCH           = IA32
TARGET_ARCH = X64

TOOL_CHAIN_CONF       = Conf/tools_def.txt

# TOOL_CHAIN_TAG        = MYTOOLS
TOOL_CHAIN_TAG = GCC48

BUILD_RULE_CONF = Conf/build_rule.txt
git submodule update --init --recursivebuild
2、编译执行UEFI Shell 2.1、U盘分区处理



[root@localhost ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 31.0 GB, 31037849600 bytes, 60620800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x05353b8c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1  4294967295  2147483647+  ee  GPT
[root@localhost ~]# ls /dev/sdb*
/dev/sdb  /dev/sdb1  /dev/sdb2
2.2、拷贝UEFI应用程序
[root@localhost ~]# mount /dev/sdb1 /mnt/
[root@localhost ~]# mkdir -p /mnt/EFI/BOOT
[root@localhost ~]# cp /root/Desktop/dellaOS/edk2/Build/OvmfX64/DEBUG_GCC48/X64/Shell.efi /mnt/EFI/BOOT/BOOTx64.EFI
[root@localhost ~]# sync
[root@localhost ~]# umount /mnt/

2.3、新建虚拟机



2.4、配置UEFI固件
命令描述
cd显示或修改当前目录
cls清除终端输出信息或改变前景/背景颜色
cp复制一个或多个文件或目录到目标路径
date显示或设置当前系统日期
delrm命令的别名
devices显示UEFI驱动的设备管理列表
devtree显示UEFI驱动的设备管理树
dh显示UEFI环境的设备句柄
dirls命令的别名
dmem显示系统、IO寄存器、PCI/PCIe配置空间或设备内存空间信息
dmpstore管理所有UEFI环境变量
drivers显示UEFI环境里的UEFI驱动列表信息
echo显示脚本中的打印信息
edit文件的全屏编辑器
exit退出UEFI Shell或当前脚本
help显示UEFI Shell的内建命令列表
memdmem命令的别名
memmap显示UEFI环境维护的内存映射
mkdir创建一个或多个新的目录
mm显示或修改内存/MMIO/IO/PCI/PCIe地址空间
mode显示或修改终端设备的显示模式
mv移动一个或多个文件到目标路径
pci显示PCI设备列表或PCI/PCIe配置空间
reset重启系统
rm删除一个或多个文件或目录
setsize调整文件大小
time显示或设置当前系统时间
type发送文件的内容到标准输出设备
ver显示UEFI Shell和固件的版本信息
vol显示文件系统的容量信息

3、UEFI下的 ”Hello,world!“ 3.1、helloworld.c
#include 

EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE *SystemTable)
{
    SystemTable->ConOut->OutputString(SystemTable->ConOut,L"Hello Worldn");
    return EFI_SUCCESS;
}
  • 所有的UEFI程序都要包含头文件Uefi.h,Uefi.h定义了UEFI基本数据类型及核心数据结构
  • UEFI标准应用程序的入口函数为是UefiMain,入口函数名由工程文件UefiMain.inf指定,入口函数的函数名可以变化但函数签名(即返回值类型和参数列表类型)不能变化
  • 大部分UEFI程序的返回值都为EFI_STATUS,本质为无符号长整数
  • EFI_SUCCESS为预定义常量,值为0
  • ImageHandle和SystemTable为参数,ImageHandle表示模块自身加载到内存后生成的Image对象,SystemTable是程序与UEFI内核交互的桥梁,是UEFI内核中一个全局的结构体
  • 字符串“Hello World”前面的大写字母L 用于通知编译器字符串必须按照宽字符保存
  • 向标准输出设备打印字符串是通过SystemTable的ConOut提供的服务完成的。ConOut是EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL的一个实例。而EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL的主要功能是控制字符输出设备。向输出设备打印字符串是通过ConOut 提供的OutputString服务完成的。该服务(函数)的第一个参数是This指针,指向EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL实例(此处为ConOut)本身;第二个参数是Unicode字符串。关于Protocol和This指针将在第4章详细介绍。简而言之,这条打印语句的意义就是通过SystemTable →ConOut →OutputString服务将字符串L“HelloWorld”打印到SystemTable →ConOut所控制的字符输出设备

想要编译UEFI应用程序源代码,必须在源文件所在目录下创建一个后缀名为.inf的工程信息文件

3.2、helloworld.inf
[Defines]
  INF_VERSION                    = 0x00010005
  base_NAME                      = helloworld
  FILE_GUID                      = 6987936E-f301-4a63-9661-fc6030dcc899
  MODULE_TYPE                    = UEFI_APPLICATION
  VERSION_STRING                 = 1.0
  ENTRY_POINT                    = UefiMain

[Sources]
  helloworld.c

[Packages]
  MdePkg/MdePkg.dec

[LibraryClasses]
  UefiApplicationEntryPoint

[Protocols]

[Guids]
3.2.1、[Defines]块

语法格式

属性名 = 属性值

必选属性

变量名功能描述
INF_VERSIONINF标准的版本号,通常将INF_VERSION设置为0x00010005即可
base_NAMEUEFI程序的名字,不能包含空格
FILE_GUID所有EDK2的INF文件都必须包含GUID值(格式:8-4-4-4-12)
MODULE_TYPE程序类型(详情请查阅《UEFI原理与编程 戴正华(著)》)
VERSION_STRING模块的版本号字符串
ENTRY_POINT模块的入口函数
3.2.2、[Sources]块

语法格式

块内每一行表示一个文件,文件使用相对路径,根路径是工程文件所在的目录

示例1

[Sources]
  UefiMain.c

示例2

[Sources]
  UefiMain.c
[Sources .IA32]
	Cpu32.c
[Sources .x64]
	Cpu64.c
3.2.3、[Packages]块

语法格式

块内每一行列出一个文件,文件使用相对路径,若[Sources]块内列出了源文件,则在[Packages]块必须列出MdePkg/MdePkg.dec,并将其放在本块的首行

示例

[Packages]
  MdePkg/MdePkg.dec
3.2.4、[LibraryClasses]块

语法格式

块内每一行声明一个要链接的库
应用程序工程模块必须链接UefiApplicationEntryPoint库;驱动模块必须链接UefiDriverEntryPoint库

示例

[LibraryClasses]  UefiApplicationEntryPoint
3.2.5、[Protocols]块

语法格式

块内每一行声明模块中使用的一个Protocol,严格来说,列出的是Protocol对应的GUID,如果模块未使用任何Protocol,则此块为空
3.2.6、[Guids]块

语法格式

表示全局GUID名字
3.3、重新编译
make -C baseTools/baseTools/BuildEnv. ./edksetup.sh
3.4、项目文件放置

在EDK2目录的“AppPkgApplications”目录下创建名为“helloworld”的目录,并将工程1-1中的helloworld.inf和helloworld.c文件拷贝到helloworld目录里

3.5、AppPkg.dsc
[Defines]
  PLATFORM_NAME                  = AppPkg
  PLATFORM_GUID                  = 0458dade-8b6e-4e45-b773-1b27cbda3e06
  PLATFORM_VERSION               = 0.01
  DSC_SPECIFICATION              = 0x00010006
  OUTPUT_DIRECTORY               = Build/AppPkg
  SUPPORTED_ARCHITECTURES        = IA32|X64|ARM|AARCH64
  BUILD_TARGETS                  = DEBUG|RELEASE|NOOPT
  SKUID_IDENTIFIER               = DEFAULT

  # Debug output control
  DEFINE DEBUG_ENABLE_OUTPUT      = FALSE       # Set to TRUE to enable debug output
  DEFINE DEBUG_PRINT_ERROR_LEVEL  = 0x80000040  # Flags to control amount of debug output
  DEFINE DEBUG_PROPERTY_MASK      = 0

[PcdsFeatureFlag]

[PcdsFixedAtBuild]
  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|$(DEBUG_PROPERTY_MASK)
  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|$(DEBUG_PRINT_ERROR_LEVEL)

[PcdsFixedAtBuild.IPF]

[LibraryClasses]
  # Entry Point Libraries
  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
  ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf

  # Common Libraries
  baseLib|MdePkg/Library/baseLib/baseLib.inf
  baseMemoryLib|MdePkg/Library/baseMemoryLib/baseMemoryLib.inf
  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
  PrintLib|MdePkg/Library/basePrintLib/basePrintLib.inf
  PcdLib|MdePkg/Library/basePcdLibNull/basePcdLibNull.inf
  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf

  !if $(DEBUG_ENABLE_OUTPUT)
    DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
    DebugPrintErrorLevelLib|MdePkg/Library/baseDebugPrintErrorLevelLib/baseDebugPrintErrorLevelLib.inf
  !else   ## DEBUG_ENABLE_OUTPUT
    DebugLib|MdePkg/Library/baseDebugLibNull/baseDebugLibNull.inf
  !endif  ## DEBUG_ENABLE_OUTPUT

  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
  PeCoffGetEntryPointLib|MdePkg/Library/basePeCoffGetEntryPointLib/basePeCoffGetEntryPointLib.inf
  IoLib|MdePkg/Library/baseIoLibIntrinsic/baseIoLibIntrinsic.inf
  PciLib|MdePkg/Library/basePciLibCf8/basePciLibCf8.inf
  PciCf8Lib|MdePkg/Library/basePciCf8Lib/basePciCf8Lib.inf
  SynchronizationLib|MdePkg/Library/baseSynchronizationLib/baseSynchronizationLib.inf
  UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf
  UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf
  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
  FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
  SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
  ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
  CacheMaintenanceLib|MdePkg/Library/baseCacheMaintenanceLib/baseCacheMaintenanceLib.inf

[Components]

#### Sample Applications.
  AppPkg/Applications/helloworld/helloworld.inf
  AppPkg/Applications/Hello/Hello.inf        # No LibC includes or functions.
  AppPkg/Applications/Main/Main.inf          # Simple invocation. No other LibC functions.
  AppPkg/Applications/Enquire/Enquire.inf    #
  AppPkg/Applications/ArithChk/ArithChk.inf  #

  AppPkg/Applications/OrderedCollectionTest/OrderedCollectionTest.inf {
    
      OrderedCollectionLib|MdePkg/Library/baseOrderedCollectionRedBlackTreeLib/baseOrderedCollectionRedBlackTreeLib.inf
      DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
      DebugPrintErrorLevelLib|MdePkg/Library/baseDebugPrintErrorLevelLib/baseDebugPrintErrorLevelLib.inf
    
      gEfiMdePkgTokenSpaceGuid.PcdValidateOrderedCollection|TRUE
    
      gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2F
      gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80400040
  }

!include StdLib/StdLib.inc
!include AppPkg/Applications/Sockets/Sockets.inc
3.6、target.txt
# ACTIVE_PLATFORM       = Nt32Pkg/Nt32Pkg.dsc
# ACTIVE_PLATFORM = OvmfPkg/OvmfPkgX64.dsc
ACTIVE_PLATFORM       = AppPkg/AppPkg.dsc

TARGET                = DEBUG

# TARGET_ARCH           = IA32
TARGET_ARCH = X64

TOOL_CHAIN_CONF       = Conf/tools_def.txt

# TOOL_CHAIN_TAG        = MYTOOLS
TOOL_CHAIN_TAG = GCC48

BUILD_RULE_CONF = Conf/build_rule.txt
3.7、编译、拷贝程序
[root@localhost edk2]# build
[root@localhost ~]# mount /dev/sdb1 /mnt/
[root@localhost ~]# cp /root/Desktop/dellaOS/edk2/Build/AppPkg/DEBUG_GCC48/X64/helloworld.efi /mnt/
[root@localhost ~]# sync
[root@localhost ~]# umount /mnt/
3.8、运行效果

4、UEFI引导程序 4.1、核心任务
  • 将操作系统内核从存储介质加载到物理内存的指定地址
  • 获取硬件平台的物理地址空间信息
  • 配置图形设备的显示模式
  • 设置处理器的运行环境
4.2、图形设备显示协议(EFI_GRAPHICS_OUTPUT_PROTOCOL)
struct_EFI_GRAPHICS_OUTPUT_PROTOCOL{
    EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE QueryMode;	//查询显示模式
    EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode;		//设置显示模式
    EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT Blt;				//用于将图像传输到屏幕或从屏幕读取图像
    EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode;			//指向当前显示模式
}
结构体成员功能描述
QueryMode查询显示模式
SetMode设置显示模式
Blt用于将图像传输到屏幕或从屏幕读取图像
Mode指向当前显示模式
4.3、显示模式(EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE)
typedef struct {
    UINT32 MaxMode;										//显示设备支持的模式数量
    UINT32 Mode;										//当前显示模式
    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;			//当前显示模式下的模式信息
    UINTN SizeOfInfo;									//Info数据结构大小
    EFI_PHYSICAL_ADDRESS frameBufferbase;				//帧缓冲区物理地址大小
    UINTN frameBuffersize;								//帧缓冲区大小
}EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE;
结构体成员功能描述
UINT32 MaxMode图形设备支持的图形模式数量
UINT32 Mode图形设备当前使用的图形模式,有效数值为0~ MaxMode-1
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info图形模式信息结构(只读)
UINTN SizeOfInfo图形模式信息结构的长度
EFI_PHYSICAL_ADDRESS frameBufferbase图形设备线性帧缓冲区的起始地址
UINTN frameBufferSize图形设备线性帧缓冲区的长度
4.4、显示模式信息(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION)
typedef struct {
    UINT32 version;										//版本号
    UINT32 HorizontalResolution;						//垂直分辨率
    UINT32 verticalResolution;							//水平分辨率
    EFI_GRAPHICS_PIXEL_FORMAT PixelFormat;				//像素格式
    EFI_PIXEL_BITMASK PixelInformation					//仅在PixelFormat设置为PixelBitMask格式时有效
    UINT32 PixelsPerscanLine;							//每扫描行的像素数
}EFI_GRAPHICS_OUTPUT_MODE_INFORMATION;
结构体成员功能描述
UINT32 Version此结构的版本号
UINT32 HorizontalResolution屏幕像素X坐标轴的长度
UINT32 VerticalResolution屏幕像素Y坐标轴的长度
EFI_GRAPHICS_PIXEL_FORMAT PixelFormat像素的物理格式定义
EFI_PIXEL_BITMASK PixelInformation仅在PixelFormat设置为PixelBitMask格式时有效
UINT32 PixelsPerScanLine定义扫描线的像素数。
4.5、显示模式信息的像素(EFI_GRAPHICS_PIXEL_FORMAT)
typedef enum {
	PixelRedGreenBlueReserved8BitPerColor,				//RGB
    PixelBlueGreenRedReserved8BitPerColor,				//RGB
    PixelBitMask,										//像素掩码
    PixelBltonly,										//只能通过Blt函数访问缓冲区
    PixelFormatMax
}EFI_GRAPHICS_PIXEL_FORMAT;
枚举成员功能描述
PixelRedGreenBlueReserved8BitPerColor一个像素占32位,字节0表示红色,字节1表示绿色,字节2表示蓝色,字节3保留
PixelBlueGreenRedReserved8BitPerColor一个像素占32位,字节0表示蓝色,字节1表示绿色,字节2表示红色,字节3保留
PixelBitMask物理帧缓冲区的像素由EFI_PIXEL_BITMASK结构定义
PixelBltOnly此模式不支持物理帧缓冲区
4.6、EFI_PIXEL_BITMASK
typedef struct {
    UINT32 RedMask;
    UINT32 GreenMask;
    UINT32 BlueMask;
    UINT32 ReservedMask;
}EFI_PIXEL_BITMASK;
//位掩码中的红色、绿色和蓝色分量值代表颜色深度,每个颜色深度随着其颜色位掩码数值的增加而增加,复位颜色位掩码中的所有位表示最小颜色深度,置位颜色位掩码中的所有位表示最大颜色深度。
4.7、获取显示模式

video.c

#include 
#include 
#include 


EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE *SystemTable)
{
	EFI_GRAPHICS_OUTPUT_PROTOCOL* gGraphicsOutput = 0;
	EFI_GRAPHICS_OUTPUT_MODE_INFORMATION* Info = 0;
	UINTN InfoSize = 0;
	int i = 0;

	gBS->LocateProtocol(&gEfiGraphicsOutputProtocolGuid,NULL,(VOID **)&gGraphicsOutput);
	//EFI_GRAPHICS_OUTPUT_PROTOCOL->Mode为当前显示模式
	Print(L"Current Mode:%02d,Version:%x,Format:%d,Horizontal:%d,Vertical:%d,ScanLine:%d,frameBufferbase:%010lx,frameBufferSize:%010lxn",gGraphicsOutput->Mode->Mode,gGraphicsOutput->Mode->Info->Version,gGraphicsOutput->Mode->Info->PixelFormat,gGraphicsOutput->Mode->Info->HorizontalResolution,gGraphicsOutput->Mode->Info->VerticalResolution,gGraphicsOutput->Mode->Info->PixelsPerScanLine,gGraphicsOutput->Mode->frameBufferbase,gGraphicsOutput->Mode->frameBufferSize);

	for(i = 0;i < gGraphicsOutput->Mode->MaxMode;i++)
	{
		gGraphicsOutput->QueryMode(gGraphicsOutput,i,&InfoSize,&Info);
		Print(L"Mode:%02d,Version:%x,Format:%d,Horizontal:%d,Vertical:%d,ScanLine:%dn",i,Info->Version,Info->PixelFormat,Info->HorizontalResolution,Info->VerticalResolution,Info->PixelsPerScanLine);
		gBS->FreePool(Info);
	}

	gBS->CloseProtocol(gGraphicsOutput,&gEfiGraphicsOutputProtocolGuid,ImageHandle,NULL);

	return EFI_SUCCESS;
}

video.inf

[Defines]
  INF_VERSION                    = 0x00010005
  base_NAME                      = video
  FILE_GUID                      = 6987936E-f301-4a63-9661-fc6030dcc833
  MODULE_TYPE                    = UEFI_APPLICATION
  VERSION_STRING                 = 1.0
  ENTRY_POINT                    = UefiMain

[Sources]
  video.c

[Packages]
  MdePkg/MdePkg.dec

[LibraryClasses]
  UefiApplicationEntryPoint
  UefiLib

[Protocols]
  gEfiGraphicsOutputProtocolGuid

[Guids]
4.8、编译
baseTools/BuildEnv
. ./edksetup.sh
4.9、AppPkg.dsc
[Defines]
  PLATFORM_NAME                  = AppPkg
  PLATFORM_GUID                  = 0458dade-8b6e-4e45-b773-1b27cbda3e06
  PLATFORM_VERSION               = 0.01
  DSC_SPECIFICATION              = 0x00010006
  OUTPUT_DIRECTORY               = Build/AppPkg
  SUPPORTED_ARCHITECTURES        = IA32|X64|ARM|AARCH64
  BUILD_TARGETS                  = DEBUG|RELEASE|NOOPT
  SKUID_IDENTIFIER               = DEFAULT

  # Debug output control
  DEFINE DEBUG_ENABLE_OUTPUT      = FALSE       # Set to TRUE to enable debug output
  DEFINE DEBUG_PRINT_ERROR_LEVEL  = 0x80000040  # Flags to control amount of debug output
  DEFINE DEBUG_PROPERTY_MASK      = 0

[PcdsFeatureFlag]

[PcdsFixedAtBuild]
  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|$(DEBUG_PROPERTY_MASK)
  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|$(DEBUG_PRINT_ERROR_LEVEL)

[PcdsFixedAtBuild.IPF]

[LibraryClasses]
  # Entry Point Libraries
  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
  ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf

  # Common Libraries
  baseLib|MdePkg/Library/baseLib/baseLib.inf
  baseMemoryLib|MdePkg/Library/baseMemoryLib/baseMemoryLib.inf
  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
  PrintLib|MdePkg/Library/basePrintLib/basePrintLib.inf
  PcdLib|MdePkg/Library/basePcdLibNull/basePcdLibNull.inf
  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf

  !if $(DEBUG_ENABLE_OUTPUT)
    DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
    DebugPrintErrorLevelLib|MdePkg/Library/baseDebugPrintErrorLevelLib/baseDebugPrintErrorLevelLib.inf
  !else   ## DEBUG_ENABLE_OUTPUT
    DebugLib|MdePkg/Library/baseDebugLibNull/baseDebugLibNull.inf
  !endif  ## DEBUG_ENABLE_OUTPUT

  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
  PeCoffGetEntryPointLib|MdePkg/Library/basePeCoffGetEntryPointLib/basePeCoffGetEntryPointLib.inf
  IoLib|MdePkg/Library/baseIoLibIntrinsic/baseIoLibIntrinsic.inf
  PciLib|MdePkg/Library/basePciLibCf8/basePciLibCf8.inf
  PciCf8Lib|MdePkg/Library/basePciCf8Lib/basePciCf8Lib.inf
  SynchronizationLib|MdePkg/Library/baseSynchronizationLib/baseSynchronizationLib.inf
  UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf
  UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
  PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf
  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
  FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
  SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
  ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
  CacheMaintenanceLib|MdePkg/Library/baseCacheMaintenanceLib/baseCacheMaintenanceLib.inf

[Components]

#### Sample Applications.
  AppPkg/Applications/helloworld/helloworld.inf
  AppPkg/Applications/video/video.inf
  AppPkg/Applications/Hello/Hello.inf        # No LibC includes or functions.
  AppPkg/Applications/Main/Main.inf          # Simple invocation. No other LibC functions.
  AppPkg/Applications/Enquire/Enquire.inf    #
  AppPkg/Applications/ArithChk/ArithChk.inf  #

  AppPkg/Applications/OrderedCollectionTest/OrderedCollectionTest.inf {
    
      OrderedCollectionLib|MdePkg/Library/baseOrderedCollectionRedBlackTreeLib/baseOrderedCollectionRedBlackTreeLib.inf
      DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
      DebugPrintErrorLevelLib|MdePkg/Library/baseDebugPrintErrorLevelLib/baseDebugPrintErrorLevelLib.inf
    
      gEfiMdePkgTokenSpaceGuid.PcdValidateOrderedCollection|TRUE
    
      gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2F
      gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80400040
  }

!include StdLib/StdLib.inc
!include AppPkg/Applications/Sockets/Sockets.inc
4.10、target.txt
# ACTIVE_PLATFORM       = Nt32Pkg/Nt32Pkg.dsc
# ACTIVE_PLATFORM = OvmfPkg/OvmfPkgX64.dsc
ACTIVE_PLATFORM       = AppPkg/AppPkg.dsc

TARGET                = DEBUG

# TARGET_ARCH           = IA32
TARGET_ARCH = X64

TOOL_CHAIN_CONF       = Conf/tools_def.txt

# TOOL_CHAIN_TAG        = MYTOOLS
TOOL_CHAIN_TAG = GCC48

BUILD_RULE_CONF = Conf/build_rule.txt
4.11、编译、拷贝程序
[root@localhost edk2]# build
[root@localhost ~]# mount /dev/sdb1 /mnt/
[root@localhost ~]# cp /root/Desktop/dellaOS/edk2/Build/AppPkg/DEBUG_GCC48/X64/helloworld.efi /mnt/
[root@localhost ~]# sync
[root@localhost ~]# umount /mnt/
4.12、运行效果

4.13、设置显示模式
#include 
#include 
#include 


EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE *SystemTable)
{
	EFI_GRAPHICS_OUTPUT_PROTOCOL* gGraphicsOutput = 0;
	EFI_GRAPHICS_OUTPUT_MODE_INFORMATION* Info = 0;
	UINTN InfoSize = 0;
	int i = 0;

	gBS->LocateProtocol(&gEfiGraphicsOutputProtocolGuid,NULL,(VOID **)&gGraphicsOutput);
	Print(L"Current Mode:%02d,Version:%x,Format:%d,Horizontal:%d,Vertical:%d,ScanLine:%d,frameBufferbase:%010lx,frameBufferSize:%010lxn",gGraphicsOutput->Mode->Mode,gGraphicsOutput->Mode->Info->Version,gGraphicsOutput->Mode->Info->PixelFormat,gGraphicsOutput->Mode->Info->HorizontalResolution,gGraphicsOutput->Mode->Info->VerticalResolution,gGraphicsOutput->Mode->Info->PixelsPerScanLine,gGraphicsOutput->Mode->frameBufferbase,gGraphicsOutput->Mode->frameBufferSize);

	long H_V_Resolution = gGraphicsOutput->Mode->Info->HorizontalResolution * gGraphicsOutput->Mode->Info->VerticalResolution;
	int MaxResolutionMode = gGraphicsOutput->Mode->Mode;

	for(i = 0;i < gGraphicsOutput->Mode->MaxMode;i++)
	{
		gGraphicsOutput->QueryMode(gGraphicsOutput,i,&InfoSize,&Info);
		Print(L"Mode:%02d,Version:%x,Format:%d,Horizontal:%d,Vertical:%d,ScanLine:%dn",i,Info->Version,Info->PixelFormat,Info->HorizontalResolution,Info->VerticalResolution,Info->PixelsPerScanLine);

		if((Info->PixelFormat == 1) && (Info->HorizontalResolution * Info->VerticalResolution > H_V_Resolution))
		{
			H_V_Resolution = Info->HorizontalResolution * Info->VerticalResolution;
			MaxResolutionMode = i;
		}

		gBS->FreePool(Info);
	}

	gGraphicsOutput->SetMode(gGraphicsOutput,MaxResolutionMode);
	gBS->LocateProtocol(&gEfiGraphicsOutputProtocolGuid,NULL,(VOID **)&gGraphicsOutput);
	Print(L"Current Mode:%02d,Version:%x,Format:%d,Horizontal:%d,Vertical:%d,ScanLine:%d,frameBufferbase:%010lx,frameBufferSize:%010lxn",gGraphicsOutput->Mode->Mode,gGraphicsOutput->Mode->Info->Version,gGraphicsOutput->Mode->Info->PixelFormat,gGraphicsOutput->Mode->Info->HorizontalResolution,gGraphicsOutput->Mode->Info->VerticalResolution,gGraphicsOutput->Mode->Info->PixelsPerScanLine,gGraphicsOutput->Mode->frameBufferbase,gGraphicsOutput->Mode->frameBufferSize);

	gBS->CloseProtocol(gGraphicsOutput,&gEfiGraphicsOutputProtocolGuid,ImageHandle,NULL);

	return EFI_SUCCESS;
}

SetMode

EFI_STATUS SetMode
(
      IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
      IN UINT32 ModeNumber
);
4.14、运行效果

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/487381.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号