UEFI---(NT32)的第一個代碼

暑期實習,找到一份作固件的實習。跟我一直所追求的仍是有一些差距。不過正是之前的積累,可以對我學習新的知識有很大幫助。php

第一個代碼依然仍是擁抱世界 hello world 啦shell

 

咱們須要修改三個文件app

text1.cide

text1.inf函數

Nt32Pkg.dsc工具

/** @file
  This is a simple shell application

  Copyright (c) 2008 - 2010, 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.

**/

#include <Uefi.h>
#include <Library/UefiApplicationEntryPoint.h>
#include <Library/UefiLib.h>

/**
  as the real entry point for the application.

  @param[in] ImageHandle    The firmware allocated handle for the EFI image.
  @param[in] SystemTable    A pointer to the EFI System Table.

  @retval EFI_SUCCESS       The entry point is executed successfully.
  @retval other             Some error occurs when executing this entry point.

**/
EFI_STATUS
EFIAPI
main (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  Print(L"hello world\r\n");
  return EFI_SUCCESS;
}
text1.c
## @file
#  Sample UEFI Application Reference EDKII Module
#
#  This is a simple shell application
#
#  Copyright (c) 2009 - 2010, 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                      = text1
  FILE_GUID                      = 1D73FF57-579C-40F2-BA4F-851DFE50B614
  MODULE_TYPE                    = UEFI_APPLICATION
  VERSION_STRING                 = 1.0
  ENTRY_POINT                    = main

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

[Sources]
  text1.c

[Packages]
  MdePkg/MdePkg.dec

[LibraryClasses]
  UefiApplicationEntryPoint
  UefiLib
text1.inf

 

其實就編寫的基本流程來講,分爲一下幾個步驟學習

  1.  複製要編寫的程序模板,其中至少包括  *.c  *.inf 文件
  2. *.C 文件中,咱們要作兩件事情
    1.   修改想要的入口函數名
    2.        在主函數中實現想要的功能
  3.  *.inf 文件中,咱們作如下事情
    1.   在defines中,
      1.        修改BASE_NAME --> 生成的模塊名字
      2.        修改GUID標識(使用VS自帶工具)
      3.        修改ENTRY_POINT  --> 入口函數名 (與 *.c 文件對應)
    2.      在sources中, 聲明所包含的子文件。在本次實驗中只包含 text1.c 一個文件
  4.   在NT32Pkg目錄下找到Nt32Pkg.dsc ,將咱們須要新編譯的*.inf文件添加在 Components 之中完成聲明。

 

在編譯過程當中,出現了一點小問題。就是在根目錄下采用 build -p Nt32Pkg\Nt32Pkg.dsc  編譯後並不能編譯出新的可執行的 *.elf 文件ui

只能採用build -p Nt32Pkg\Nt32Pkg.dsc -a IA32 -m ShellPkg\Application\text1\text1.inf  進入文件目錄後編譯才能夠。this

 

 

另一個問題就是若是在*.c文件中輸出字符串後面不加\r\n。 會致使字符輸出不全,個人只顯示   orld    四個字符。詢問前輩得知是因爲被覆蓋,具體不詳spa

相關文章
相關標籤/搜索