summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmpDebugPrint.c
blob: e97279376c10076b4945f805f28550060191b23c (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/** @file
  Publishes ESRT table from Firmware Management Protocol instances

  Copyright (c) 2016, Microsoft Corporation
  Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>

  All rights reserved.
  SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#include <Uefi.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Protocol/FirmwareManagement.h>
#include <Guid/SystemResourceTable.h>

/**
  Function to print a single ESRT Entry (ESRE) to the debug console.

  Print Format:
  | 00000000-0000-0000-0000-000000000000 | SSSSSSSSSSSS | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 | 0x00000000 |

  @param[in]  Entry  - Pointer to an ESRE entry
  @retval  EFI_SUCCESS
                        EFI_INVALID_PARAMETER
**/
EFI_STATUS
EFIAPI
PrintOutEsrtEntry (
  IN EFI_SYSTEM_RESOURCE_ENTRY  *Entry
  )
{
  if (Entry == NULL) {
    DEBUG ((DEBUG_INFO, "| ERROR:  Invalid resource entry pointer                           "));
    DEBUG ((DEBUG_INFO, "                                                    |\n"));
    return EFI_INVALID_PARAMETER;
  }

  //
  // GUID FW Class (36 chars plus table formatting)
  //
  DEBUG ((DEBUG_INFO, "| %g |", &Entry->FwClass));

  //
  // Entry Type (12 chars plus table formatting)
  //
  switch (Entry->FwType) {
  case (ESRT_FW_TYPE_SYSTEMFIRMWARE) :
    DEBUG ((DEBUG_INFO, " System FW    |"));
    break;
  case (ESRT_FW_TYPE_DEVICEFIRMWARE) :
    DEBUG ((DEBUG_INFO, " Device FW    |"));
    break;
  case (ESRT_FW_TYPE_UEFIDRIVER) :
    DEBUG ((DEBUG_INFO, " Uefi Driver  |"));
    break;
  case (ESRT_FW_TYPE_UNKNOWN) :
    DEBUG ((DEBUG_INFO, " Unknown Type |"));
    break;
  default:
    DEBUG ((DEBUG_INFO, " ? 0x%8X |", Entry->FwType));
    break;
  }

  //
  // FW Version (10 char UINT32 string plus table formatting)
  // Lowest Supported Version (10 char UINT32 string plus table formatting)
  // Capsule Flags (10 char UINT32 string plus table formatting)
  // Last Attempt Version (10 char UINT32 string plus table formatting)
  // Last Attempt Status (10 char UINT32 string plus table formatting)
  //
  DEBUG ((DEBUG_INFO,
    " 0x%8X | 0x%8X | 0x%8X | 0x%8X | 0x%8X |\n",
    Entry->FwVersion,
    Entry->LowestSupportedFwVersion,
    Entry->CapsuleFlags,
    Entry->LastAttemptVersion,
    Entry->LastAttemptStatus
    ));

  return EFI_SUCCESS;
}

/**
  Function to print the ESRT table to the debug console.

  @param[in]  Table  - Pointer to the ESRT table
**/
VOID
EFIAPI
PrintTable (
  IN EFI_SYSTEM_RESOURCE_TABLE  *Table
  )
{
  EFI_SYSTEM_RESOURCE_ENTRY  *Entry;
  UINTN                      Index;

  Entry = (EFI_SYSTEM_RESOURCE_ENTRY *)(((UINT8 *)Table) + sizeof (EFI_SYSTEM_RESOURCE_TABLE));

  //
  // Print ESRT table information
  //
  DEBUG ((DEBUG_INFO, "ESRT Table Information:\n"));
  if (Table == NULL) {
    DEBUG ((DEBUG_INFO, "ERROR:  Invalid table pointer\n"));
    return;
  }

  DEBUG ((DEBUG_INFO, "+--------------------------------------------------------+\n"));
  DEBUG ((DEBUG_INFO, "| Firmware Resource Count          : 0x%08x          |\n",  Table->FwResourceCount));
  DEBUG ((DEBUG_INFO, "| Firmware Resource Count Max      : 0x%08x          |\n",  Table->FwResourceCountMax));
  DEBUG ((DEBUG_INFO, "| Firmware Resource Entry Version  : 0x%016x  |\n",         Table->FwResourceVersion));
  DEBUG ((DEBUG_INFO, "+--------------------------------------------------------+\n"));

  //
  // Print table entry information
  //
  DEBUG ((DEBUG_INFO, "ESRT Table Entries:\n"));
  if (Table->FwResourceVersion != EFI_SYSTEM_RESOURCE_TABLE_FIRMWARE_RESOURCE_VERSION) {
    DEBUG ((DEBUG_INFO, "ERROR:  Unsupported Resource Entry Version\n"));
    return;
  }

  DEBUG ((DEBUG_INFO, "+--------------------------------------+--------------+------------"));
  DEBUG ((DEBUG_INFO, "+------------+------------+------------+------------+\n"));
  DEBUG ((DEBUG_INFO, "|                                      |              |            "));
  DEBUG ((DEBUG_INFO, "| Lowest     |            | Last       | Last       |\n"));
  DEBUG ((DEBUG_INFO, "|                                      | Firmware     |            "));
  DEBUG ((DEBUG_INFO, "| Supported  | Capsule    | Attempted  | Attempted  |\n"));
  DEBUG ((DEBUG_INFO, "| CLASS GUID                           | Type         | Version    "));
  DEBUG ((DEBUG_INFO, "| Version    | Flags      | Version    | Status     |\n"));
  DEBUG ((DEBUG_INFO, "+--------------------------------------+--------------+------------"));
  DEBUG ((DEBUG_INFO, "+------------+------------+------------+------------+\n"));

  for (Index = 0; Index < Table->FwResourceCount; Index++) {
    PrintOutEsrtEntry (&(Entry[Index]));
  }

  DEBUG ((DEBUG_INFO, "+--------------------------------------+--------------+------------"));
  DEBUG ((DEBUG_INFO, "+------------+------------+------------+------------+\n"));
}