diff options
Diffstat (limited to 'Lessons/Lesson_38/UefiLessonsPkg')
6 files changed, 296 insertions, 0 deletions
| diff --git a/Lessons/Lesson_38/UefiLessonsPkg/SimpleClassProtocol/SimpleClassProtocol.c b/Lessons/Lesson_38/UefiLessonsPkg/SimpleClassProtocol/SimpleClassProtocol.c new file mode 100644 index 0000000..8bd7f87 --- /dev/null +++ b/Lessons/Lesson_38/UefiLessonsPkg/SimpleClassProtocol/SimpleClassProtocol.c @@ -0,0 +1,84 @@ +#include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiLib.h> + +#include <Protocol/SimpleClass.h> + + +EFI_HANDLE  mSimpleClassHandle = NULL; + +UINTN mNumber = 0; + +EFI_STATUS +EFIAPI +SimpleClassProtocolSetNumber ( +  UINTN Number +  ) +{ +  mNumber = Number; + +  return EFI_SUCCESS; +} + + +EFI_STATUS +EFIAPI +SimpleClassProtocolGetNumber ( +  UINTN* Number +  ) +{ +  if (Number == NULL) { +    return EFI_INVALID_PARAMETER; +  } + +  *Number = mNumber; + +  return EFI_SUCCESS; +} + + +SIMPLE_CLASS_PROTOCOL  mSimpleClass = { +  SimpleClassProtocolGetNumber, +  SimpleClassProtocolSetNumber +}; + + +EFI_STATUS +EFIAPI +SimpleClassProtocolDriverUnload ( +  IN EFI_HANDLE        ImageHandle +  ) +{ +  Print(L"Bye-bye from SimpleClassProtocol driver, handle=%p\n", mSimpleClassHandle); + +  EFI_STATUS Status = gBS->UninstallMultipleProtocolInterfaces( +                             mSimpleClassHandle, +                             &gSimpleClassProtocolGuid, +                             &mSimpleClass, +                             NULL +                             ); + +  return Status; +} + +EFI_STATUS +EFIAPI +SimpleClassProtocolDriverEntryPoint ( +  IN EFI_HANDLE        ImageHandle, +  IN EFI_SYSTEM_TABLE  *SystemTable +  ) +{ +  Print(L"Hello from SimpleClassProtocol driver"); + +  EFI_STATUS Status = gBS->InstallMultipleProtocolInterfaces( +                             &mSimpleClassHandle, +                             &gSimpleClassProtocolGuid, +                             &mSimpleClass, +                             NULL +                             ); +  if (!EFI_ERROR(Status)) +    Print(L", handle=%p\n", mSimpleClassHandle); +  else +    Print(L"\n", mSimpleClassHandle); + +  return Status; +} diff --git a/Lessons/Lesson_38/UefiLessonsPkg/SimpleClassProtocol/SimpleClassProtocol.inf b/Lessons/Lesson_38/UefiLessonsPkg/SimpleClassProtocol/SimpleClassProtocol.inf new file mode 100644 index 0000000..63b4e9f --- /dev/null +++ b/Lessons/Lesson_38/UefiLessonsPkg/SimpleClassProtocol/SimpleClassProtocol.inf @@ -0,0 +1,23 @@ +[Defines] +  INF_VERSION                    = 1.25 +  BASE_NAME                      = SimpleClassProtocol +  FILE_GUID                      = 51d6a90a-c021-4472-b2c1-5fdd1b7f2196 +  MODULE_TYPE                    = UEFI_DRIVER +  VERSION_STRING                 = 1.0 +  ENTRY_POINT                    = SimpleClassProtocolDriverEntryPoint +#  UNLOAD_IMAGE                   = SimpleClassProtocolDriverUnload + +[Sources] +  SimpleClassProtocol.c + +[Packages] +  MdePkg/MdePkg.dec +  UefiLessonsPkg/UefiLessonsPkg.dec + +[Protocols] +  gSimpleClassProtocolGuid + +[LibraryClasses] +  UefiDriverEntryPoint +  UefiLib + diff --git a/Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.c b/Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.c new file mode 100644 index 0000000..bd3ac1d --- /dev/null +++ b/Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.c @@ -0,0 +1,67 @@ +#include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiLib.h> + +#include <Protocol/SimpleClass.h> + +EFI_STATUS +EFIAPI +UefiMain ( +  IN EFI_HANDLE        ImageHandle, +  IN EFI_SYSTEM_TABLE  *SystemTable +  ) +{ +  UINTN                  HandleCount; +  EFI_HANDLE*            HandleBuffer; +  UINTN Index; +  SIMPLE_CLASS_PROTOCOL* SimpleClass; + +  EFI_STATUS Status = gBS->LocateHandleBuffer ( +                  ByProtocol, +                  &gSimpleClassProtocolGuid, +                  NULL, +                  &HandleCount, +                  &HandleBuffer +                  ); +  if (EFI_ERROR (Status)) { +    Print(L"Error! Can't find any handle with gSimpleClassProtocolGuid: %r\n", Status); +    return Status; +  } + +  for (Index = 0; Index < HandleCount; Index++) { +    Print(L"Handle = %p\n", HandleBuffer[Index]); +    Status = gBS->OpenProtocol( +      HandleBuffer[Index], +      &gSimpleClassProtocolGuid, +      (VOID **)&SimpleClass, +      ImageHandle, +      NULL, +      EFI_OPEN_PROTOCOL_GET_PROTOCOL +    ); + +    if (!EFI_ERROR(Status)) { +      UINTN Number; + +      Status = SimpleClass->GetNumber(&Number); +      if (!EFI_ERROR(Status)) { +        Print(L"Number before=%d\n", Number); +      } else { +        Print(L"Error! Can't get number: %r\n", Status); +      } + +      Status = SimpleClass->SetNumber(Number+5); +      if (EFI_ERROR(Status)) +        Print(L"Error! Can't set number: %r\n", Status); + +      Status = SimpleClass->GetNumber(&Number); +      if (!EFI_ERROR(Status)) { +        Print(L"Number after=%d\n", Number); +      } else { +        Print(L"Error! Can't get number: %r\n", Status); +      } +    } else { +      Print(L"Error! Can't open SimpleClass protocol: %r\n", Status); +    } +  } + +  return Status; +} diff --git a/Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.inf b/Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.inf new file mode 100644 index 0000000..cb57e68 --- /dev/null +++ b/Lessons/Lesson_38/UefiLessonsPkg/SimpleClassUser/SimpleClassUser.inf @@ -0,0 +1,22 @@ +[Defines] +  INF_VERSION                    = 1.25 +  BASE_NAME                      = SimpleClassUser +  FILE_GUID                      = 466eed70-8def-44ea-9fb4-9012b266ec8c +  MODULE_TYPE                    = UEFI_APPLICATION +  VERSION_STRING                 = 1.0 +  ENTRY_POINT                    = UefiMain + +[Sources] +  SimpleClassUser.c + +[Packages] +  MdePkg/MdePkg.dec +  UefiLessonsPkg/UefiLessonsPkg.dec + +[Protocols] +  gSimpleClassProtocolGuid + +[LibraryClasses] +  UefiApplicationEntryPoint +  UefiLib + diff --git a/Lessons/Lesson_38/UefiLessonsPkg/UefiLessonsPkg.dec b/Lessons/Lesson_38/UefiLessonsPkg/UefiLessonsPkg.dec new file mode 100644 index 0000000..8d14eec --- /dev/null +++ b/Lessons/Lesson_38/UefiLessonsPkg/UefiLessonsPkg.dec @@ -0,0 +1,35 @@ +[Defines]
 +  DEC_SPECIFICATION              = 0x00010005
 +  PACKAGE_NAME                   = UefiLessonsPkg
 +  PACKAGE_GUID                   = 7e7edbba-ca2c-4177-a3f0-d3371358773a
 +  PACKAGE_VERSION                = 1.01
 +
 +[Includes]
 +  Include
 +
 +[Guids]
 +  # FILE_GUID as defined in UefiLessonsPkg/HelloWorld/HelloWorld.inf
 +  gHelloWorldFileGuid            = {0x2e55fa38, 0xf148, 0x42d3, {0xaf, 0x90, 0x1b, 0xe2, 0x47, 0x32, 0x3e, 0x30}}
 +  gUefiLessonsPkgTokenSpaceGuid = {0x150cab53, 0xad47, 0x4385, {0xb5, 0xdd, 0xbc, 0xfc, 0x76, 0xba, 0xca, 0xf0}}
 +
 +[Protocols]
 +  gSimpleClassProtocolGuid = { 0xb5510eea, 0x6f11, 0x4e4b, { 0xad, 0x0f, 0x35, 0xce, 0x17, 0xbd, 0x7a, 0x67 }}
 +
 +[PcdsFixedAtBuild]
 +  gUefiLessonsPkgTokenSpaceGuid.PcdMyVar32|42|UINT32|0x00000001
 +  gUefiLessonsPkgTokenSpaceGuid.PcdMyVar32_1|42|UINT32|0x00000002
 +  gUefiLessonsPkgTokenSpaceGuid.PcdMyVar32_2|42|UINT32|0x00000003
 +  gUefiLessonsPkgTokenSpaceGuid.PcdMyVarBool|FALSE|BOOLEAN|0x00000004
 +
 +[PcdsPatchableInModule]
 +  gUefiLessonsPkgTokenSpaceGuid.PcdMyPatchableVar32|0x31313131|UINT32|0x10000001
 +
 +[PcdsFeatureFlag]
 +  gUefiLessonsPkgTokenSpaceGuid.PcdMyFeatureFlagVar|FALSE|BOOLEAN|0x20000001
 +
 +[PcdsDynamic]
 +  gUefiLessonsPkgTokenSpaceGuid.PcdMyDynamicVar32|0x38323232|UINT32|0x30000001
 +  gUefiLessonsPkgTokenSpaceGuid.PcdMyDynamicVar32_1|42|UINT32|0x30000002
 +
 +[PcdsDynamicEx]
 +  gUefiLessonsPkgTokenSpaceGuid.PcdMyDynamicExVar32|0x38333333|UINT32|0x40000001
 diff --git a/Lessons/Lesson_38/UefiLessonsPkg/UefiLessonsPkg.dsc b/Lessons/Lesson_38/UefiLessonsPkg/UefiLessonsPkg.dsc new file mode 100644 index 0000000..905d31f --- /dev/null +++ b/Lessons/Lesson_38/UefiLessonsPkg/UefiLessonsPkg.dsc @@ -0,0 +1,65 @@ +[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 + + +[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 +  PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.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 +  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf +  MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf +  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf +  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf +  ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf +  ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf +  FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf   +  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf +  SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf +  UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf +  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf +  #SimpleLibrary|UefiLessonsPkg/Library/SimpleLibrary/SimpleLibrary.inf +  #SimpleLibrary|UefiLessonsPkg/Library/SimpleLibraryWithConstructor/SimpleLibraryWithConstructor.inf +  SimpleLibrary|UefiLessonsPkg/Library/SimpleLibraryWithConstructorAndDestructor/SimpleLibraryWithConstructorAndDestructor.inf + +[Components] +  UefiLessonsPkg/SimplestApp/SimplestApp.inf +  UefiLessonsPkg/HelloWorld/HelloWorld.inf +  UefiLessonsPkg/ImageHandle/ImageHandle.inf +  UefiLessonsPkg/ImageInfo/ImageInfo.inf +  UefiLessonsPkg/MemoryInfo/MemoryInfo.inf +  UefiLessonsPkg/SimpleShellApp/SimpleShellApp.inf +  UefiLessonsPkg/ListVariables/ListVariables.inf +  UefiLessonsPkg/ShowBootVariables/ShowBootVariables.inf +  UefiLessonsPkg/InteractiveApp/InteractiveApp.inf +  #UefiLessonsPkg/GOPInfo/GOPInfo.inf +  #UefiLessonsPkg/HiiMenu/HiiMenu.inf +  #UefiLessonsPkg/TestGlyphs/TestGlyphs.inf +  #UefiLessonsPkg/ShowHii/ShowHii.inf +  UefiLessonsPkg/PCDLesson/PCDLesson.inf +  UefiLessonsPkg/ShowTables/ShowTables.inf +  UefiLessonsPkg/AcpiInfo/AcpiInfo.inf +  UefiLessonsPkg/SaveBGRT/SaveBGRT.inf +  UefiLessonsPkg/ListPCI/ListPCI.inf +  UefiLessonsPkg/PCIRomInfo/PCIRomInfo.inf +  UefiLessonsPkg/Library/SimpleLibrary/SimpleLibrary.inf +  UefiLessonsPkg/Library/SimpleLibraryWithConstructor/SimpleLibraryWithConstructor.inf +  UefiLessonsPkg/SimpleLibraryUser/SimpleLibraryUser.inf +  UefiLessonsPkg/SimpleClassProtocol/SimpleClassProtocol.inf +  UefiLessonsPkg/SimpleClassUser/SimpleClassUser.inf + +[PcdsFixedAtBuild] +  gUefiLessonsPkgTokenSpaceGuid.PcdMyVar32_2|44 + | 
