aboutsummaryrefslogtreecommitdiffstats
path: root/UefiLessonsPkg/DisplayHIIByGuid/DisplayHIIByGuid.c
blob: 2bd715ff5ed29b89e210c0a560b65cf1ee6a5285 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Copyright (c) 2021, Konstantin Aladyshev <aladyshev22@gmail.com>
 *
 * SPDX-License-Identifier: MIT
 */

#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>

#include <Library/MemoryAllocationLib.h>
#include <Library/HiiLib.h>
#include <Protocol/FormBrowser2.h>

INTN
EFIAPI
ShellAppMain (
  IN UINTN Argc,
  IN CHAR16 **Argv
  )
{
  if ((Argc < 2) || (Argc > 3)) {
    Print(L"Usage:\n");
    Print(L"  DisplayHIIByGuid <Package list GUID> [<Formset classguid>]\n");
    return EFI_INVALID_PARAMETER;
  }

  EFI_GUID PackageListGuid;
  EFI_STATUS Status = StrToGuid(Argv[1], &PackageListGuid);
  if (Status != RETURN_SUCCESS) {
    Print(L"Error! Can't convert <Package list GUID> argument to GUID\n");
    return EFI_INVALID_PARAMETER;
  }

  EFI_GUID FormsetClassGuid = EFI_HII_PLATFORM_SETUP_FORMSET_GUID;
  if (Argc == 3) {
    Status = StrToGuid(Argv[2], &FormsetClassGuid);
    if (Status != RETURN_SUCCESS) {
      Print(L"Error! Can't convert <Formset classguid> argument to GUID\n");
      return EFI_INVALID_PARAMETER;
    }
  }

  EFI_HII_HANDLE* HiiHandles = HiiGetHiiHandles(&PackageListGuid);

  EFI_HII_HANDLE* HiiHandle = HiiHandles;
  UINTN HandleCount=0;
  while (*HiiHandle != NULL) {
    HiiHandle++;
    HandleCount++;
  }

  EFI_FORM_BROWSER2_PROTOCOL* FormBrowser2;
  Status = gBS->LocateProtocol(&gEfiFormBrowser2ProtocolGuid, NULL, (VOID**)&FormBrowser2);
  if (EFI_ERROR(Status)) {
    Print(L"Error! Can't locate gEfiFormBrowser2Protocol\n");
    FreePool(HiiHandles);
    return Status;
  }

  Status = FormBrowser2->SendForm (
                           FormBrowser2,
                           HiiHandles,
                           HandleCount,
                           &FormsetClassGuid,
                           0,
                           NULL,
                           NULL
                           );  

  if (EFI_ERROR(Status)) {
    Print(L"Error! SendForm returned %r\n", Status);
  }

  FreePool(HiiHandles);

  return EFI_SUCCESS;
}