# 1. 간단한 EFI application 만들기

앞서 빌드된 환경에서 샘플 애플리케이션 제작을 위한 폴더를 생성한다.

```bash
$ mkdir SimplestApp
```

이후 생성할 애플리케이션의 코드를 아래와 같이 생성한다.

```c
$ vi SimplestApp/SimplestApp.c
-----
EFI_STATUS
EFIAPI
UefiMain (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  return EFI_SUCCESS;
}
```

생성한 애플리케이션의 설정을 지정하기 위해 `*.inf` 파일을 작성한다.\
<https://edk2-docs.gitbook.io/edk-ii-inf-specification/3_edk_ii_inf_file_format>

```
$ vi SimplestApp/SimplestApp.inf
-----
[Defines]
  INF_VERSION                    = 1.25
  BASE_NAME                      = SimplestApp
  FILE_GUID                      = 4a298956-fbe0-47fb-ae3a-2d5a0a959a26
  MODULE_TYPE                    = UEFI_APPLICATION
  VERSION_STRING                 = 1.0
  ENTRY_POINT                    = UefiMain

[Sources]
  SimplestApp.c

[Packages]
  MdePkg/MdePkg.dec

[LibraryClasses]
  UefiApplicationEntryPoint
```

작성한 섹션별 주요 정보는 다음과 같다.\
<https://edk2-docs.gitbook.io/edk-ii-inf-specification/3_edk_ii_inf_file_format/34_-defines-_section>

* Defines
  * `INF_VERSION`
  * `BASE_NAME`
  * `FILE_GUID`: 모듈을 식별하기 위해 고유한 GUID 값을 지정한다.\
    (`uuidgen` 명령어를 이용해 임의 생성이 가능하다)
  * `MODULE_TYPE`: EDK II에 정의되어진 모듈 type 중 애플리케이션로 지정한다.\
    [(https://edk2-docs.gitbook.io/edk-ii-inf-specification/appendix\_f\_module\_types)](https://edk2-docs.gitbook.io/edk-ii-inf-specification/appendix_f_module_types)
  * ENTRY\_POINT: 드라이버의 Entry point을 명시한다.
* Sources: 포함하는 소스 코드 정보를 명시한다.
* Packages: 포함하는 패키지 정보를 명시한다.
* LibraryClasses

작성한 애플리케이션을 빌드하기 위해서는 특정 패키지에 포함되어야 한다.

```
$ vi OvmfPkg/OvmfPkgX64.dsc
-----
 [Components]
+  SimplestApp/SimplestApp.inf
   OvmfPkg/ResetVector/ResetVector.inf
```

작성한 샘플 애플리케이션은 OvmfPkg에 포함되어 있으므로 아래와 같은 명령어를 통해 빌드한다.

```
$ build --platform=OvmfPkg/OvmfPkgX64.dsc --arch=X64 --buildtarget=RELEASE --tagname=GCC5
```

빌드 되어진 샘플 애플리케이션을 실행하기 위해서 해당 애플리케이션을 포함하여 QEMU를 실행한다.

```
$ mkdir ~/UEFI_disk
$ cp Build/OvmfX64/RELEASE_GCC5/X64/SimplestApp.efi ~/UEFI_disk
$ qemu-system-x86_64 -drive if=pflash,format=raw,file=Build/OvmfX64/RELEASE_GCC5/FV/OVMF.fd \
                     -drive format=raw,file=fat:rw:~/UEFI_disk \
                     -nographic \
                     -net none
```

QEMU 환경에서 생성한 애플리케이션을 실행한다.

```
Shell> fs0:
FS0:\> SimplestApp.efi
FS0:\>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bob-mcd-team.gitbook.io/uefi/uefi-development/uefi-start/1.efi-application.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
