OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
ocvalidate.c
Go to the documentation of this file.
1
16#include "ocvalidate.h"
17#include "OcValidateLib.h"
18
19#include <Library/OcMainLib.h>
20
21#include <UserFile.h>
22
23UINT32
25 IN OC_GLOBAL_CONFIG *Config
26 )
27{
28 UINT32 ErrorCount;
29 UINT32 CurrErrorCount;
30 UINTN Index;
31 STATIC CONFIG_CHECK ConfigCheckers[] = {
32 &CheckACPI,
36 &CheckMisc,
40 };
41
42 ErrorCount = 0;
43 CurrErrorCount = 0;
44
45 //
46 // Pass config structure to all checkers.
47 //
48 for (Index = 0; Index < ARRAY_SIZE (ConfigCheckers); ++Index) {
49 CurrErrorCount = ConfigCheckers[Index](Config);
50
51 if (CurrErrorCount != 0) {
52 //
53 // Print an extra newline on error.
54 //
55 DEBUG ((DEBUG_WARN, "\n"));
56 ErrorCount += CurrErrorCount;
57 }
58 }
59
60 return ErrorCount;
61}
62
63int
65 int argc,
66 char *argv[]
67 )
68{
69 UINT8 *ConfigFileBuffer;
70 UINT32 ConfigFileSize;
71 CONST CHAR8 *ConfigFileName;
72 INT64 ExecTimeStart;
73 OC_GLOBAL_CONFIG Config;
74 EFI_STATUS Status;
75 UINT32 ErrorCount;
76
77 ErrorCount = 0;
78
79 //
80 // Enable PCD debug logging.
81 //
82 PcdGet8 (PcdDebugPropertyMask) |= DEBUG_PROPERTY_DEBUG_CODE_ENABLED;
83 PcdGet32 (PcdFixedDebugPrintErrorLevel) |= DEBUG_INFO;
84 PcdGet32 (PcdDebugPrintErrorLevel) |= DEBUG_INFO;
85
86 DEBUG ((DEBUG_ERROR, "\nNOTE: This version of ocvalidate is only compatible with OpenCore version %a!\n\n", OPEN_CORE_VERSION));
87
88 //
89 // Print usage.
90 //
91 if (argc != 2) {
92 DEBUG ((DEBUG_ERROR, "Usage: %a <path/to/config.plist>\n\n", argv[0]));
93 return -1;
94 }
95
96 //
97 // Read config file (Only one single config is supported).
98 //
99 ConfigFileName = argv[1];
100 ConfigFileBuffer = UserReadFile (ConfigFileName, &ConfigFileSize);
101 if (ConfigFileBuffer == NULL) {
102 DEBUG ((DEBUG_ERROR, "Failed to read %a\n", ConfigFileName));
103 return -1;
104 }
105
106 //
107 // Record the current time when action starts.
108 //
109 ExecTimeStart = GetCurrentTimestamp ();
110
111 //
112 // Initialise config structure to be checked, and exit on error.
113 //
114 Status = OcConfigurationInit (&Config, ConfigFileBuffer, ConfigFileSize, &ErrorCount);
115 if (EFI_ERROR (Status)) {
116 DEBUG ((DEBUG_ERROR, "Invalid config\n"));
117 return -1;
118 }
119
120 if (ErrorCount > 0) {
121 DEBUG ((DEBUG_ERROR, "Serialisation returns %u %a!\n", ErrorCount, ErrorCount > 1 ? "errors" : "error"));
122 }
123
124 //
125 // Print a newline that splits errors between OcConfigurationInit and config checkers.
126 //
127 DEBUG ((DEBUG_ERROR, "\n"));
128 ErrorCount += CheckConfig (&Config);
129
130 OcConfigurationFree (&Config);
131 FreePool (ConfigFileBuffer);
132
133 if (ErrorCount == 0) {
134 DEBUG ((
135 DEBUG_ERROR,
136 "Completed validating %a in %llu ms. No issues found.\n",
137 ConfigFileName,
138 GetCurrentTimestamp () - ExecTimeStart
139 ));
140 } else {
141 DEBUG ((
142 DEBUG_ERROR,
143 "Completed validating %a in %llu ms. Found %u %a requiring attention.\n",
144 ConfigFileName,
145 GetCurrentTimestamp () - ExecTimeStart,
146 ErrorCount,
147 ErrorCount > 1 ? "issues" : "issue"
148 ));
149
150 return EXIT_FAILURE;
151 }
152
153 return 0;
154}
155
156int
158 const uint8_t *Data,
159 size_t Size
160 )
161{
162 VOID *NewData;
163 OC_GLOBAL_CONFIG Config;
164
165 NewData = AllocatePool (Size);
166 if (NewData != NULL) {
167 CopyMem (NewData, Data, Size);
168 OcConfigurationInit (&Config, NewData, Size, NULL);
169 OcConfigurationFree (&Config);
170 FreePool (NewData);
171 }
172
173 return 0;
174}
#define ARRAY_SIZE(Array)
Definition AppleMacEfi.h:34
DMG_SIZE_DEVICE_PATH Size
VOID OcConfigurationFree(IN OUT OC_GLOBAL_CONFIG *Config)
EFI_STATUS OcConfigurationInit(OUT OC_GLOBAL_CONFIG *Config, IN VOID *Buffer, IN UINT32 Size, IN OUT UINT32 *ErrorCount OPTIONAL)
#define OPEN_CORE_VERSION
Definition OcMainLib.h:33
INT64 GetCurrentTimestamp(VOID)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
UINT8 * UserReadFile(IN CONST CHAR8 *FileName, OUT UINT32 *Size)
Definition UserFile.c:62
UINT8 uint8_t
int ENTRY_POINT(void)
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
Definition ocvalidate.c:157
UINT32 CheckConfig(IN OC_GLOBAL_CONFIG *Config)
Definition ocvalidate.c:24
UINT32 CheckMisc(IN OC_GLOBAL_CONFIG *Config)
UINT32(* CONFIG_CHECK)(IN OC_GLOBAL_CONFIG *Config)
Definition ocvalidate.h:27
UINT32 CheckNvram(IN OC_GLOBAL_CONFIG *Config)
UINT32 CheckDeviceProperties(IN OC_GLOBAL_CONFIG *Config)
UINT32 CheckACPI(IN OC_GLOBAL_CONFIG *Config)
UINT32 CheckPlatformInfo(IN OC_GLOBAL_CONFIG *Config)
UINT32 CheckKernel(IN OC_GLOBAL_CONFIG *Config)
UINT32 CheckBooter(IN OC_GLOBAL_CONFIG *Config)
UINT32 CheckUefi(IN OC_GLOBAL_CONFIG *Config)