# 2. 간단한 Pkg 만들기

이번에는 앞서 만들었던 애플리케이션을 다른 패키지에 포함하여 빌드하자.

먼저 `OvmfPkg/OvmfPkgX64.dsc` 에서 `SimplestApp.inf`를 제외시킨다.

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

이후 임의의 패키지를 생성하기 위해 폴더 및 구성 파일을 생성한다.

```
$ mkdir UefiLessonsPkg
$ mv SimplestApp UefiLessonsPkg/SimplestApp
$ vi UefiLessonsPkg/UefiLessonsPkg.dsc
-----
[Defines]
  DSC_SPECIFICATION              = 0x0001001C
  PLATFORM_GUID                  = 3db7270f-ffac-4139-90a4-0ae68f3f8167
  PLATFORM_VERSION               = 0.01
  PLATFORM_NAME                  = UefiLessonsPkg
  SKUID_IDENTIFIER               = DEFAULT
  SUPPORTED_ARCHITECTURES        = X64
  BUILD_TARGETS                  = RELEASE

[Components]
  UefiLessonsPkg/SimplestApp/SimplestApp.inf
```

위 패키지 구성 파일의 세부 정보는 아래 UEFI 스펙 링크를 참조하자.\
<https://edk2-docs.gitbook.io/edk-ii-dsc-specification/>

파일 생성 이후 플랫폼 정보를 다음과 같이 변경하고 빌드를 진행하자.

```
$ . edksetup.sh
$ build --platform=UefiLessonsPkg/UefiLessonsPkg.dsc \
        --module=UefiLessonsPkg/SimplestApp/SimplestApp.inf \
        --arch=X64 \
        --buildtarget=RELEASE \
        --tagname=GCC5
```

그럼 다음과 같은 오류가 발생하는 것이 일반적이다.

```
error 4000: Instance of library class [UefiBootServicesTableLib] is not found
```

LibraryClass는 여러 인스턴스 및 라이브러리를 가질 수 있기 때문에 모두 지정해줄 필요가 있다.\
따라서 다음과 같은 명령어를 이용하여 포함되어야 할 구성 정보들을 포함해주어야 한다.

```
$ grep UefiApplicationEntryPoint -r ./ --include=*.inf | grep LIBRARY_CLASS
```

필요 라이브러리를 모두 포함한 `*.dsc` 파일 정보는 아래와 같다.

```
$ vi UefiLessonsPkg/UefiLessonsPkg.dsc\
-----
[Defines]
  PLATFORM_NAME                  = UefiLessonsPkg
  PLATFORM_GUID                  = 3db7270f-ffac-4139-90a4-0ae68f3f8167
  PLATFORM_VERSION               = 0.01
  DSC_SPECIFICATION              = 0x00010006
  OUTPUT_DIRECTORY               = Build/UefiLessonsPkg
  SUPPORTED_ARCHITECTURES        = X64
  BUILD_TARGETS                  = RELEASE
  SKUID_IDENTIFIER               = DEFAULT

[LibraryClasses]
  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
  DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
  BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
  RegisterFilterLib|MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.inf
  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
  DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf

[Components]
  UefiLessonsPkg/SimplestApp/SimplestApp.inf
```

이후 빌드 과정을 통하여 다른 패키지에 포함시킨 애플리케이션이 정상 동작하는지 확인한다.

```
$ cp Build/UefiLessonsPkg/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
```


---

# 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/2.simple-pkg.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.
