UEFI基础——测试用例Hello Word

Hello 测试用例

硬件环境:龙芯ls3a6000平台
软件环境:龙芯uefi固件

GUID获取网址:https://guidgen.com

一、创建工程

  • mkdir TextPkg/
  • 三个文件 Hello.c 、 Hello.inf 、HelloPkg.dsc

1.1 Hello.c

/** @file
  The application to print hello word.

Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/
#include #include //#include EFI_STATUS EFIAPI MyHello( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { Print(L"Hello World!\n"); // gST->ConOut->OutputString(SystemTable->ConOut, L"Hello World!\n"); // SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Hello World!\n"); return EFI_SUCCESS; }

1.2 Hello.inf

## @file
#  The application to print hello word.
#
#  The application pops up a menu showing all the boot options referenced by
#  BootOrder NV variable and user can choose to boot from one of them.
#  
#  Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>
#  This program and the accompanying materials
#  are licensed and made available under the terms and conditions of the BSD License
#  which accompanies this distribution.  The full text of the license may be found at
#  http://opensource.org/licenses/bsd-license.php
#  
#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#  
##

[Defines]
  INF_VERSION                    = 0x00010005
  BASE_NAME                      = Hello
  FILE_GUID                      = ae9fad76-2e2a-457f-bf1f-90c9c5afe889
  MODULE_TYPE                    = UEFI_APPLICATION
  VERSION_STRING                 = 1.0 
  ENTRY_POINT                    = MyHello

#
# The following information is for reference only and not required by the build tools.
#
#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC
#

[Sources]
  Hello.c

[Packages]
  MdePkg/MdePkg.dec
  MdeModulePkg/MdeModulePkg.dec

[LibraryClasses]
  UefiLib
  UefiApplicationEntryPoint

1.3 HelloPkg.dsc

## @file
#  The application to print hello word.
#
#  The application pops up a menu showing all the boot options referenced by
#  BootOrder NV variable and user can choose to boot from one of them.
#  
#  Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>
#  This program and the accompanying materials
#  are licensed and made available under the terms and conditions of the BSD License
#  which accompanies this distribution.  The full text of the license may be found at
#  http://opensource.org/licenses/bsd-license.php
#  
#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#  
##

[Defines]
  PLATFORM_NAME					 = HelloPkg
  PLATFORM_GUID                  = 41ee9fe9-c2aa-4f67-a6e5-5bae7560438d
  PLATFORM_VERSION               = 0.1
  DSC_SPECIFICATION              = 0x00010005
  SUPPORTED_ARCHITECTURES        = LOONGARCH64
  BUILD_TARGETS                  = DEBUG|RELEASE
  SKUID_IDENTIFIER               = DEFAULT
  PLATFORM_DIRECTORY             = LsRefCodePkg/SampleCode/Desktop/
  CONFIG_FILE                    = $(PLATFORM_DIRECTORY)/Script/Desktop.cfg

!include $(CONFIG_FILE)
!if ($(CPU_TYPE) == 3A5000 || $(CPU_TYPE) == 3B5000)
!include $(PLATFORM_DIRECTORY)/Script/Loongson3a.fdf.inc
  PLATFORM_NAME                  = Ls3a50007a
  CPU_TYPE                       = 3A5000
  CORES_PRE_NODE                 = 4
  TOT_NODE_NUM                   = 1
  APPEND_FLAG                    = -DLOONGSON_3A5000
!elseif ($(CPU_TYPE) == 3A6000)
!include $(PLATFORM_DIRECTORY)/Script/Loongson3a.fdf.inc
  PLATFORM_NAME                  = Ls3a60007a
  CPU_TYPE                       = 3A6000
  CORES_PRE_NODE                 = 8
  TOT_NODE_NUM                   = 1
  APPEND_FLAG                    = -DLOONGSON_3A5000 -DFLAT_MODE
!elseif ($(CPU_TYPE) == 2K2000)
!include $(PLATFORM_DIRECTORY)/Script/Loongson2k.fdf.inc
  PLATFORM_NAME                  = Ls2k2000
  CPU_TYPE                       = 2K2000
  CORES_PRE_NODE                 = 2
  TOT_NODE_NUM                   = 1
  APPEND_FLAG                    = -DLOONGSON_2K2000 -DLS2K2000_GMEM_SIZE="256"
!endif
  OUTPUT_DIRECTORY               = Build/$(PLATFORM_NAME)
  NODE_OFFSET                    = 44

  DEFINE COMMON_BUILD_OPTIONS_FLAGS = -DLS$(CPU_TYPE) -DCLK_BASE=$(BASE_CLK) -DHIGH_MEM_BASE_ADDRESS=$(HIGH_MEM_BASE_ADDRESS) -DHT0_FREQ=$(HT0_FREQ) -DDDR_FREQ=$(MEM_FREQ) -DLS$(SOUTH_BRIDGE) -DCLK_DDR=$(DDR_CLK) -DCLK_REF=$(REF_CLK) -DMPS_ADDR=$(MPS_ADDR) -DMPS_STEP=$(MPS_STEP) -DVOL_LEVEL_HI=$(VOL_LEVEL_HI) -DVOL_LEVEL_MI=$(VOL_LEVEL_MI) -DVOL_LEVEL_LO=$(VOL_LEVEL_LO) -DCACHED_MEMORY_ADDR=$(CACHED_MEMORY_ADDR) -DUNCACHED_MEMORY_ADDR=$(UNCACHED_MEMORY_ADDR) -DTOT_NODE_NUM=$(TOT_NODE_NUM) -DCORES_PER_NODE=$(CORES_PRE_NODE) -DPCIE_CONF_BASE=$(PCIE_CONF_BASE) $(APPEND_FLAG) -DVGA_HOTP_LEVEL=$(VGA_HOTP_LEVEL) -DNODE_OFFSET=$(NODE_OFFSET) -DLS7A_LINK_ID_BUF="0"
  COMMON_BUILD_OPTIONS_FLAGS        = -DTOT_7A_NUM="1" -DBEEP_NEW="1" $(COMMON_BUILD_OPTIONS_FLAGS)

  !if $(BONITO_100M) == TRUE
    COMMON_BUILD_OPTIONS_FLAGS   = -DBONITO_100M $(COMMON_BUILD_OPTIONS_FLAGS)
  !else
    COMMON_BUILD_OPTIONS_FLAGS   = -DBONITO_25M $(COMMON_BUILD_OPTIONS_FLAGS)
  !endif

  !if $(CPU_FREQ)
    COMMON_BUILD_OPTIONS_FLAGS   = -DCPU_FREQ=$(CPU_FREQ) $(COMMON_BUILD_OPTIONS_FLAGS)
  !endif

  !if $(SPI_DUAL_LINE) == TRUE
    COMMON_BUILD_OPTIONS_FLAGS   = -DSPI_DUAL_LINE $(COMMON_BUILD_OPTIONS_FLAGS)
  !endif

  !if $(COMP_TYPE) == DEBUG
    COMMON_BUILD_OPTIONS_FLAGS   = -DASM_DEBUG $(COMMON_BUILD_OPTIONS_FLAGS)
  !endif

  !if $(PG_MODE) == TRUE
    COMMON_BUILD_OPTIONS_FLAGS   = -DPG_MODE $(COMMON_BUILD_OPTIONS_FLAGS)
  !endif

  !if $(GMEM_ENABLE) == TRUE
    COMMON_BUILD_OPTIONS_FLAGS   = -DGMEM_ENABLE='1' $(COMMON_BUILD_OPTIONS_FLAGS)
  !else
    COMMON_BUILD_OPTIONS_FLAGS   = -DGMEM_ENABLE='0' $(COMMON_BUILD_OPTIONS_FLAGS)
  !endif

  !if $(LS7A_PHYS48_TO_HT40) == TRUE
    COMMON_BUILD_OPTIONS_FLAGS   = -DLS7A_PHYS48_TO_HT40 $(COMMON_BUILD_OPTIONS_FLAGS)
  !endif

  !if $(CODEC_VERBTABLE_SUPPORT) == TRUE
    COMMON_BUILD_OPTIONS_FLAGS   = -DFIX_VERB_TABLE $(COMMON_BUILD_OPTIONS_FLAGS)
  !endif

  !if $(EFFICIENT_CORE_DYNAMIC_CONTROL) == TRUE
    COMMON_BUILD_OPTIONS_FLAGS   = -DEFFICIENT_CORE_DYNAMIC_CONTROL $(COMMON_BUILD_OPTIONS_FLAGS)
  !endif

############################################################################
#
# Defines for default states.  These can be changed on the command line.
# -D FLAG=VALUE
############################################################################

[BuildOptions]
  GCC:RELEASE_*_*_CC_FLAGS       = -DMDEPKG_NDEBUG -DSPEEDUP

  GCC:*_*_*_CC_FLAGS             = $(COMMON_BUILD_OPTIONS_FLAGS)

  *_*_LOONGARCH64_PP_FLAGS       = $(COMMON_BUILD_OPTIONS_FLAGS)

  *_*_*_ASLPP_FLAGS              = $(COMMON_BUILD_OPTIONS_FLAGS)

  *_*_*_VFRPP_FLAGS              = $(COMMON_BUILD_OPTIONS_FLAGS)


[LibraryClasses]
  UefiLib                          | MdePkg/Library/UefiLib/UefiLib.inf
  UefiApplicationEntryPoint        | MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
  UefiBootServicesTableLib         | MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
  DebugLib                         | MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
  BaseLib                          | MdePkg/Library/BaseLib/BaseLib.inf
  PcdLib                           | MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
  BaseMemoryLib                    | MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
  SerialPortLib                    | LsRefCodePkg/Library/SerialPortLib/SerialPortLib.inf
  PrintLib                         | MdePkg/Library/BasePrintLib/BasePrintLib.inf
  DebugPrintErrorLevelLib          | MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
  IoLib                            | MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
  RegisterFilterLib                | LsRefCodePkg/Core/Library/RegisterFilterLib/RegisterFilterLib.inf
  MemoryAllocationLib              | MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
  DevicePathLib                    | MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLibDevicePathProtocol.inf
 UefiRuntimeServicesTableLib      | MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf

[Components]
  TextPkg/Hello.inf

二、编译工程

2.1 配置环境变量

  • export WORKSPACE=$PWD
  • export EDK_TOOLS_PATH=$PWD/BaseTools/
  • source edksetup.sh

2.2 执行编译

build -a LOONGARCH64 -t GCC83 -p TextPkg/HelloPkg.dsc -j log.txt

  • a 指定架构
  • t 指定工具链版本
  • p 指定工程路径
  • j 编译输出存放位置

2.3 编译截图

UEFI基础——测试用例Hello Word_第1张图片

2.4 编译结果

UEFI基础——测试用例Hello Word_第2张图片

2.5 运行结果

UEFI基础——测试用例Hello Word_第3张图片

你可能感兴趣的:(UEFI学习,uefi,uefi入门,uefi基础)