> For the complete documentation index, see [llms.txt](https://bob-mcd-team.gitbook.io/uefi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bob-mcd-team.gitbook.io/uefi/uefi-development/hii/56.file_guid-base_name.md).

# 56. 코드에서 FILE\_GUID 및 BASE\_NAME을 가져오기

이전에 `PlatformDxe` 모듈의 HII 리소스를 살펴봤다.\
<https://github.com/tianocore/edk2/blob/master/OvmfPkg/PlatformDxe>\
이 리소스는 패키지 DEC 파일이나 `*.c` 파일에 참조되지 않은 GUID 번호로 등록되어 있다는 것을 알 수 있다.

```
PackageList[9]: GUID=D9DCC5DF-4007-435E-9098-8970935504B2; size=0x855
        Package[0]: type=FORMS; size=0x1F6
        Package[1]: type=STRINGS; size=0x62B
        Package[2]: type=DEVICE_PATH; size=0x1C
        Package[3]: type=END; size=0x4
```

GUID 값은 모듈 INF 파일의 `FILE_GUID` 값과 동일하다.\
<https://github.com/tianocore/edk2/blob/master/OvmfPkg/PlatformDxe/Platform.inf>

```
[Defines]
  ...
  BASE_NAME                      = PlatformDxe
  FILE_GUID                      = D9DCC5DF-4007-435E-9098-8970935504B2
  ...
  
```

GUID를 C 코드에 가져오는 방법은 EDK2의 빌드 시스템을 사용해 간단하게 할 가져올 수 있다. INF 파일의 `FILE_GUID` 키의 GUID는 자동으로 몇 가지 다른 값과 함께 Autoconf 헤더로 이동한다.\
<https://github.com/tianocore/edk2/blob/master/BaseTools/Source/Python/AutoGen/GenC.py>

```python
def CreateHeaderCode(Info, AutoGenC, AutoGenH):
    ...
    #
    # Publish the CallerId Guid
    #
    AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(Info.Guid))
    AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID gEdkiiDscPlatformGuid = %s;\n' % GuidStringToGuidStructureString(Info.PlatformInfo.Guid))
    AutoGenC.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *gEfiCallerBaseName = "%s";\n' % Info.Name)
```

이런 값은 `Build/OvmfX64/RELEASE_GCC5/X64/OvmfPkg/PlatformDxe/Platform/DEBUG/AutoGen.h`에서 확인할 수 있다.

```c
extern GUID  gEfiCallerIdGuid;
extern GUID  gEdkiiDscPlatformGuid;
extern CHAR8 *gEfiCallerBaseName;

#define EFI_CALLER_ID_GUID \
  {0xD9DCC5DF, 0x4007, 0x435E, {0x90, 0x98, 0x89, 0x70, 0x93, 0x55, 0x04, 0xB2}}
#define EDKII_DSC_PLATFORM_GUID \
  {0x5a9e7754, 0xd81b, 0x49ea, {0x85, 0xad, 0x69, 0xea, 0xa7, 0xb1, 0x53, 0x9b}}
```

그리고 `Build/OvmfX64/RELEASE_GCC5/X64/OvmfPkg/PlatformDxe/Platform/DEBUG/AutoGen.c`에서도 확인할 수 있다.

이 세 가지 변수는 우리가 생성한 모듈을 포함해 모든 모듈에 대한 Autoconf 파일에 존재한다.

* `gEfiCallerIdGuid` - 모듈 INF 파일의 `FILE_GUID` 키 값
* `gEdkiiDscPlatformGuid` - 모듈 패키지 DSC 파일의 `PLATFORM_GUID` 키 값
* `gEfiCallerBaseName` - ASCII 문자열로 인코딩된 모듈 INF 파일의 `BASE_NAME` 키 값

아래 링크에서 `gEfiCallerIdGuid`가 사용되는 코드를 확인할 수 있다.\
<https://github.com/tianocore/edk2/blob/master/OvmfPkg/PlatformDxe/Platform.c>

```
EFI_STATUS
EFIAPI
PlatformInit (
  IN  EFI_HANDLE        ImageHandle,
  IN  EFI_SYSTEM_TABLE  *SystemTable
  )
  ...
  mInstalledPackages = HiiAddPackages (
                         &gEfiCallerIdGuid,  // PackageListGuid
                         ImageHandle,        // associated DeviceHandle
                         PlatformDxeStrings, // 1st package
                         PlatformFormsBin,   // 2nd package
                         NULL                // terminator
                         );
  ...
```

EDK2 코드베이스에서 `gEdkiiDscPlatformGuid`가 사용되지 않는 것처럼 보이지만 원하는 경우 다른 GUID와 같은 방식으로 사용할 수 있다.

`gEfiCallerBaseName`의 경우 디버깅 출력에 자주 사용된다.

```
DEBUG ((DEBUG_ERROR, "%a: %a: MyFunction(): %r\n",  gEfiCallerBaseName, __FUNCTION__, Status));
```

`gEfiCallerBaseName` 문자열은 ASCII(`=CHAR8*`)로 인코딩되므로 출력하려면 `%a` 형식을 사용해야 한다.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://bob-mcd-team.gitbook.io/uefi/uefi-development/hii/56.file_guid-base_name.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
