OpenCorePlatform.c 21.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/** @file
  OpenCore driver.

Copyright (c) 2019, vit9696. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution.  The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#include <OpenCore.h>

17 18
#include <Protocol/DataHub.h>

19 20
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
21
#include <Library/MacInfoLib.h>
22 23 24 25 26 27 28 29 30
#include <Library/MemoryAllocationLib.h>
#include <Library/PrintLib.h>
#include <Library/OcCpuLib.h>
#include <Library/OcDataHubLib.h>
#include <Library/OcSmbiosLib.h>
#include <Library/OcStringLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>

31
#include <IndustryStandard/AppleSmBios.h>
32
#include <IndustryStandard/AppleFeatures.h>
33

34 35
#include <Guid/AppleVariable.h>

36 37 38 39
STATIC
VOID
OcPlatformUpdateDataHub (
  IN OC_GLOBAL_CONFIG    *Config,
40 41
  IN OC_CPU_INFO         *CpuInfo,
  IN MAC_INFO_DATA       *MacInfo
42 43
  )
{
44 45 46 47
  EFI_STATUS            Status;
  OC_DATA_HUB_DATA      Data;
  EFI_GUID              Uuid;
  UINT64                StartupPowerEvents;
48
  UINT64                InitialTSC;
49 50 51 52 53 54 55
  EFI_DATA_HUB_PROTOCOL *DataHub;

  DataHub = OcDataHubInstallProtocol (FALSE);
  if (DataHub == NULL) {
    DEBUG ((DEBUG_WARN, "OC: Failed to install Data Hub\n"));
    return;
  }
56 57 58

  ZeroMem (&Data, sizeof (Data));

59 60 61 62 63 64 65
  if (MacInfo == NULL) {
    //
    // Manual mode, read data from DataHub.
    //
    if (OC_BLOB_GET (&Config->PlatformInfo.DataHub.PlatformName)[0] != '\0') {
      Data.PlatformName = OC_BLOB_GET (&Config->PlatformInfo.DataHub.PlatformName);
    }
66

67 68 69
    if (OC_BLOB_GET (&Config->PlatformInfo.DataHub.SystemProductName)[0] != '\0') {
      Data.SystemProductName = OC_BLOB_GET (&Config->PlatformInfo.DataHub.SystemProductName);
    }
70

71 72 73
    if (OC_BLOB_GET (&Config->PlatformInfo.DataHub.SystemSerialNumber)[0] != '\0') {
      Data.SystemSerialNumber = OC_BLOB_GET (&Config->PlatformInfo.DataHub.SystemSerialNumber);
    }
74

75 76 77 78
    if (Config->PlatformInfo.DataHub.SystemUuid.Size == GUID_STRING_LENGTH + 1
      && !EFI_ERROR (AsciiStrToGuid (OC_BLOB_GET (&Config->PlatformInfo.DataHub.SystemUuid), &Uuid))) {
      Data.SystemUUID         = &Uuid;
    }
79

80 81 82
    if (OC_BLOB_GET (&Config->PlatformInfo.DataHub.BoardProduct)[0] != '\0') {
      Data.BoardProduct = OC_BLOB_GET (&Config->PlatformInfo.DataHub.BoardProduct);
    }
83

84 85 86
    Data.BoardRevision      = &Config->PlatformInfo.DataHub.BoardRevision[0];
    Data.StartupPowerEvents = &Config->PlatformInfo.DataHub.StartupPowerEvents;
    Data.InitialTSC         = &Config->PlatformInfo.DataHub.InitialTSC;
87

88 89 90
    if (Config->PlatformInfo.DataHub.FSBFrequency != 0) {
      Data.FSBFrequency     = &Config->PlatformInfo.DataHub.FSBFrequency;
    }
91

92 93 94
    if (Config->PlatformInfo.DataHub.ARTFrequency != 0) {
      Data.ARTFrequency     = &Config->PlatformInfo.DataHub.ARTFrequency;
    }
95

96 97
    if (Config->PlatformInfo.DataHub.DevicePathsSupported != 0) {
      Data.DevicePathsSupported = &Config->PlatformInfo.DataHub.DevicePathsSupported;
98
    }
99

100 101 102 103 104 105 106 107
    if (Config->PlatformInfo.DataHub.SmcRevision[0] != 0
      || Config->PlatformInfo.DataHub.SmcRevision[1] != 0
      || Config->PlatformInfo.DataHub.SmcRevision[2] != 0
      || Config->PlatformInfo.DataHub.SmcRevision[3] != 0
      || Config->PlatformInfo.DataHub.SmcRevision[4] != 0
      || Config->PlatformInfo.DataHub.SmcRevision[5] != 0) {
      Data.SmcRevision      = &Config->PlatformInfo.DataHub.SmcRevision[0];
    }
108

109 110 111 112 113 114 115 116 117 118
    if (Config->PlatformInfo.DataHub.SmcBranch[0] != 0
      || Config->PlatformInfo.DataHub.SmcBranch[1] != 0
      || Config->PlatformInfo.DataHub.SmcBranch[2] != 0
      || Config->PlatformInfo.DataHub.SmcBranch[3] != 0
      || Config->PlatformInfo.DataHub.SmcBranch[4] != 0
      || Config->PlatformInfo.DataHub.SmcBranch[5] != 0
      || Config->PlatformInfo.DataHub.SmcBranch[6] != 0
      || Config->PlatformInfo.DataHub.SmcBranch[7] != 0) {
      Data.SmcBranch        = &Config->PlatformInfo.DataHub.SmcBranch[0];
    }
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 145 146
    if (Config->PlatformInfo.DataHub.SmcPlatform[0] != 0
      || Config->PlatformInfo.DataHub.SmcPlatform[1] != 0
      || Config->PlatformInfo.DataHub.SmcPlatform[2] != 0
      || Config->PlatformInfo.DataHub.SmcPlatform[3] != 0
      || Config->PlatformInfo.DataHub.SmcPlatform[4] != 0
      || Config->PlatformInfo.DataHub.SmcPlatform[5] != 0
      || Config->PlatformInfo.DataHub.SmcPlatform[6] != 0
      || Config->PlatformInfo.DataHub.SmcPlatform[7] != 0) {
      Data.SmcPlatform      = &Config->PlatformInfo.DataHub.SmcPlatform[0];
    }
  } else {
    //
    // Automatic mode read data from Generic & MacInfo.
    //
    Data.PlatformName = MacInfo->DataHub.PlatformName;
    Data.SystemProductName = MacInfo->DataHub.SystemProductName;
  
    if (OC_BLOB_GET (&Config->PlatformInfo.Generic.SystemSerialNumber)[0] != '\0') {
      Data.SystemSerialNumber = OC_BLOB_GET (&Config->PlatformInfo.Generic.SystemSerialNumber);
    }

    if (Config->PlatformInfo.Generic.SystemUuid.Size == GUID_STRING_LENGTH + 1
      && !EFI_ERROR (AsciiStrToGuid (OC_BLOB_GET (&Config->PlatformInfo.Generic.SystemUuid), &Uuid))) {
      Data.SystemUUID         = &Uuid;
    }

    Data.BoardProduct  = MacInfo->DataHub.BoardProduct;
147
    Data.BoardRevision = &MacInfo->DataHub.BoardRevision[0];
148 149
    StartupPowerEvents = 0;
    Data.StartupPowerEvents = &StartupPowerEvents;
150 151
    InitialTSC = 0;
    Data.InitialTSC = &InitialTSC;
152 153 154 155 156
    Data.DevicePathsSupported = &MacInfo->DataHub.DevicePathsSupported[0];

    Data.SmcRevision      = &MacInfo->DataHub.SmcRevision[0];
    Data.SmcBranch        = &MacInfo->DataHub.SmcBranch[0];
    Data.SmcPlatform      = &MacInfo->DataHub.SmcPlatform[0];
157 158
  }

159
  Status = UpdateDataHub (DataHub , &Data, CpuInfo);
160 161 162 163 164 165 166 167
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_WARN, "OC: Failed to update Data Hub - %r\n", Status));
  }
}

STATIC
VOID
OcPlatformUpdateSmbios (
168 169 170 171 172
  IN     OC_GLOBAL_CONFIG       *Config,
  IN     OC_CPU_INFO            *CpuInfo,
  IN     MAC_INFO_DATA          *MacInfo,
  IN OUT OC_SMBIOS_TABLE        *SmbiosTable,
  IN     OC_SMBIOS_UPDATE_MODE  UpdateMode
173 174 175 176 177
  )
{
  EFI_STATUS       Status;
  OC_SMBIOS_DATA   Data;
  EFI_GUID         Uuid;
178
  UINT8            SmcVersion[APPLE_SMBIOS_SMC_VERSION_SIZE];
179 180 181

  ZeroMem (&Data, sizeof (Data));

182 183 184 185 186 187 188
  if (MacInfo == NULL) {
    //
    // Manual mode, read data from SMBIOS.
    //
    if (OC_BLOB_GET (&Config->PlatformInfo.Smbios.BIOSVendor)[0] != '\0') {
      Data.BIOSVendor = OC_BLOB_GET (&Config->PlatformInfo.Smbios.BIOSVendor);
    }
189

190 191 192
    if (OC_BLOB_GET (&Config->PlatformInfo.Smbios.BIOSVersion)[0] != '\0') {
      Data.BIOSVersion = OC_BLOB_GET (&Config->PlatformInfo.Smbios.BIOSVersion);
    }
193

194 195 196
    if (OC_BLOB_GET (&Config->PlatformInfo.Smbios.BIOSReleaseDate)[0] != '\0') {
      Data.BIOSReleaseDate = OC_BLOB_GET (&Config->PlatformInfo.Smbios.BIOSReleaseDate);
    }
197

198 199 200
    if (OC_BLOB_GET (&Config->PlatformInfo.Smbios.SystemManufacturer)[0] != '\0') {
      Data.SystemManufacturer = OC_BLOB_GET (&Config->PlatformInfo.Smbios.SystemManufacturer);
    }
201

202 203 204
    if (OC_BLOB_GET (&Config->PlatformInfo.Smbios.SystemProductName)[0] != '\0') {
      Data.SystemProductName = OC_BLOB_GET (&Config->PlatformInfo.Smbios.SystemProductName);
    }
205

206 207 208
    if (OC_BLOB_GET (&Config->PlatformInfo.Smbios.SystemVersion)[0] != '\0') {
      Data.SystemVersion = OC_BLOB_GET (&Config->PlatformInfo.Smbios.SystemVersion);
    }
209

210 211 212
    if (OC_BLOB_GET (&Config->PlatformInfo.Smbios.SystemSerialNumber)[0] != '\0') {
      Data.SystemSerialNumber = OC_BLOB_GET (&Config->PlatformInfo.Smbios.SystemSerialNumber);
    }
213

214 215 216 217
    if (Config->PlatformInfo.DataHub.SystemUuid.Size == GUID_STRING_LENGTH + 1
      && !EFI_ERROR (AsciiStrToGuid (OC_BLOB_GET (&Config->PlatformInfo.DataHub.SystemUuid), &Uuid))) {
      Data.SystemUUID         = &Uuid;
    }
218

219 220 221
    if (Config->PlatformInfo.Smbios.BoardType != 0) {
      Data.BoardType = &Config->PlatformInfo.Smbios.BoardType;
    }
222

223 224 225
    if (Config->PlatformInfo.Smbios.ChassisType != 0) {
      Data.ChassisType = &Config->PlatformInfo.Smbios.ChassisType;
    }
226

227 228 229
    if (OC_BLOB_GET (&Config->PlatformInfo.Smbios.SystemSKUNumber)[0] != '\0') {
      Data.SystemSKUNumber = OC_BLOB_GET (&Config->PlatformInfo.Smbios.SystemSKUNumber);
    }
230

231 232 233
    if (OC_BLOB_GET (&Config->PlatformInfo.Smbios.SystemFamily)[0] != '\0') {
      Data.SystemFamily = OC_BLOB_GET (&Config->PlatformInfo.Smbios.SystemFamily);
    }
234

235 236 237
    if (OC_BLOB_GET (&Config->PlatformInfo.Smbios.BoardManufacturer)[0] != '\0') {
      Data.BoardManufacturer = OC_BLOB_GET (&Config->PlatformInfo.Smbios.BoardManufacturer);
    }
238

239 240 241
    if (OC_BLOB_GET (&Config->PlatformInfo.Smbios.BoardProduct)[0] != '\0') {
      Data.BoardProduct = OC_BLOB_GET (&Config->PlatformInfo.Smbios.BoardProduct);
    }
242

243 244 245
    if (OC_BLOB_GET (&Config->PlatformInfo.Smbios.BoardVersion)[0] != '\0') {
      Data.BoardVersion = OC_BLOB_GET (&Config->PlatformInfo.Smbios.BoardVersion);
    }
246

247 248 249
    if (OC_BLOB_GET (&Config->PlatformInfo.Smbios.BoardSerialNumber)[0] != '\0') {
      Data.BoardSerialNumber = OC_BLOB_GET (&Config->PlatformInfo.Smbios.BoardSerialNumber);
    }
250

251 252 253
    if (OC_BLOB_GET (&Config->PlatformInfo.Smbios.BoardAssetTag)[0] != '\0') {
      Data.BoardAssetTag = OC_BLOB_GET (&Config->PlatformInfo.Smbios.BoardAssetTag);
    }
254

255 256 257
    if (OC_BLOB_GET (&Config->PlatformInfo.Smbios.BoardLocationInChassis)[0] != '\0') {
      Data.BoardLocationInChassis = OC_BLOB_GET (&Config->PlatformInfo.Smbios.BoardLocationInChassis);
    }
258

259 260 261
    if (OC_BLOB_GET (&Config->PlatformInfo.Smbios.ChassisManufacturer)[0] != '\0') {
      Data.ChassisManufacturer = OC_BLOB_GET (&Config->PlatformInfo.Smbios.ChassisManufacturer);
    }
262

263 264 265
    if (OC_BLOB_GET (&Config->PlatformInfo.Smbios.ChassisVersion)[0] != '\0') {
      Data.ChassisVersion = OC_BLOB_GET (&Config->PlatformInfo.Smbios.ChassisVersion);
    }
266

267 268 269
    if (OC_BLOB_GET (&Config->PlatformInfo.Smbios.ChassisSerialNumber)[0] != '\0') {
      Data.ChassisSerialNumber = OC_BLOB_GET (&Config->PlatformInfo.Smbios.ChassisSerialNumber);
    }
270

271 272 273
    if (OC_BLOB_GET (&Config->PlatformInfo.Smbios.ChassisAssetTag)[0] != '\0') {
      Data.ChassisAssetTag = OC_BLOB_GET (&Config->PlatformInfo.Smbios.ChassisAssetTag);
    }
274

275 276 277
    if (Config->PlatformInfo.Smbios.MemoryFormFactor != 0) {
      Data.MemoryFormFactor = &Config->PlatformInfo.Smbios.MemoryFormFactor;
    }
278

279 280
    Data.FirmwareFeatures     = Config->PlatformInfo.Smbios.FirmwareFeatures;
    Data.FirmwareFeaturesMask = Config->PlatformInfo.Smbios.FirmwareFeaturesMask;
281

282 283 284
    if (Config->PlatformInfo.Smbios.ProcessorType != 0) {
      Data.ProcessorType = &Config->PlatformInfo.Smbios.ProcessorType;
    }
285

V
vit9696 已提交
286 287
    if (Config->PlatformInfo.Smbios.PlatformFeature != 0xFFFFFFFFU) {
      Data.PlatformFeature    = &Config->PlatformInfo.Smbios.PlatformFeature;
288 289 290 291 292
    }

    if (Config->PlatformInfo.Smbios.SmcVersion[0] != '\0') {
      Data.SmcVersion = &Config->PlatformInfo.Smbios.SmcVersion[0];
    }
293 294 295 296
  } else {
    //
    // Automatic mode read data from Generic & MacInfo.
    //
297 298 299 300 301 302 303
    if (Config->PlatformInfo.Generic.SpoofVendor) {
      Data.BIOSVendor          = OC_SMBIOS_VENDOR_NAME;
      Data.SystemManufacturer  = OC_SMBIOS_VENDOR_NAME;
      Data.ChassisManufacturer = OC_SMBIOS_VENDOR_NAME;
      Data.BoardManufacturer   = OC_SMBIOS_VENDOR_NAME;
    }

304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
    Data.BIOSVersion = MacInfo->Smbios.BIOSVersion;
    Data.BIOSReleaseDate = MacInfo->Smbios.BIOSReleaseDate;
    Data.SystemProductName = MacInfo->Smbios.SystemProductName;
    Data.SystemVersion = MacInfo->Smbios.SystemVersion;

    if (OC_BLOB_GET (&Config->PlatformInfo.Generic.SystemSerialNumber)[0] != '\0') {
      Data.SystemSerialNumber = OC_BLOB_GET (&Config->PlatformInfo.Generic.SystemSerialNumber);
    }

    if (Config->PlatformInfo.Generic.SystemUuid.Size == GUID_STRING_LENGTH + 1
      && !EFI_ERROR (AsciiStrToGuid (OC_BLOB_GET (&Config->PlatformInfo.Generic.SystemUuid), &Uuid))) {
      Data.SystemUUID = &Uuid;
    }

    Data.BoardType              = MacInfo->Smbios.BoardType;
    Data.ChassisType            = MacInfo->Smbios.ChassisType;
    Data.SystemSKUNumber        = MacInfo->Smbios.SystemSKUNumber;
    Data.SystemFamily           = MacInfo->Smbios.SystemFamily;
    Data.BoardProduct           = MacInfo->Smbios.BoardProduct;
    Data.BoardVersion           = MacInfo->Smbios.BoardVersion;
324 325 326 327 328

    if (OC_BLOB_GET (&Config->PlatformInfo.Generic.Mlb)[0] != '\0') {
      Data.BoardSerialNumber = OC_BLOB_GET (&Config->PlatformInfo.Generic.Mlb);
    }

329 330 331 332 333 334 335 336 337 338 339 340
    Data.BoardAssetTag          = MacInfo->Smbios.BoardAssetTag;
    Data.BoardLocationInChassis = MacInfo->Smbios.BoardLocationInChassis;
    Data.ChassisVersion         = MacInfo->Smbios.ChassisVersion;

    if (OC_BLOB_GET (&Config->PlatformInfo.Generic.SystemSerialNumber)[0] != '\0') {
      Data.ChassisSerialNumber = OC_BLOB_GET (&Config->PlatformInfo.Generic.SystemSerialNumber);
    }

    Data.ChassisAssetTag      = MacInfo->Smbios.ChassisAssetTag;
    Data.MemoryFormFactor     = MacInfo->Smbios.MemoryFormFactor;
    Data.FirmwareFeatures     = MacInfo->Smbios.FirmwareFeatures;
    Data.FirmwareFeaturesMask = MacInfo->Smbios.FirmwareFeaturesMask;
341 342 343 344 345 346 347 348 349

    //
    // Adopt to arbitrary hardware specifics. This bit allows the use
    // of legacy Windows installation in boot selector preference pane.
    // We need it because Windows systems with EFI partition not being 1st
    // are recognised as legacy. See:
    // https://github.com/acidanthera/bugtracker/issues/327
    // https://sourceforge.net/p/cloverefiboot/tickets/435
    //
350 351 352
    if (Config->PlatformInfo.Generic.AdviseWindows) {
      Data.FirmwareFeatures     |= FW_FEATURE_SUPPORTS_CSM_LEGACY_MODE | FW_FEATURE_SUPPORTS_UEFI_WINDOWS_BOOT;
      Data.FirmwareFeaturesMask |= FW_FEATURE_SUPPORTS_CSM_LEGACY_MODE | FW_FEATURE_SUPPORTS_UEFI_WINDOWS_BOOT;
353
    }
354

355
    Data.ProcessorType        = NULL;
356
    Data.PlatformFeature      = MacInfo->Smbios.PlatformFeature;
357

358
    if (MacInfo->DataHub.SmcRevision != NULL) {
359
      OcSmbiosGetSmcVersion (MacInfo->DataHub.SmcRevision, SmcVersion);
360 361
      Data.SmcVersion           = SmcVersion;
    }
362
  }
363

364
  Status = OcSmbiosCreate (SmbiosTable, &Data, UpdateMode, CpuInfo);
365 366 367
  if (EFI_ERROR (Status)) {
    DEBUG ((DEBUG_WARN, "OC: Failed to update SMBIOS - %r\n", Status));
  }
368 369
}

370 371 372
STATIC
VOID
OcPlatformUpdateNvram (
373 374
  IN OC_GLOBAL_CONFIG    *Config,
  IN MAC_INFO_DATA       *MacInfo
375 376 377
  )
{
  EFI_STATUS   Status;
378
  CONST CHAR8  *Bid;
V
vit9696 已提交
379
  UINTN        BidSize;
380
  CONST CHAR8  *Mlb;
V
vit9696 已提交
381
  UINTN        MlbSize;
382
  CONST  UINT8 *Rom;
V
vit9696 已提交
383
  UINTN        RomSize;
384 385 386 387 388
  UINT64       ExFeatures;
  UINT64       ExFeaturesMask;
  UINT32       Features;
  UINT32       FeaturesMask;

389 390
  if (MacInfo == NULL) {
    Bid            = OC_BLOB_GET (&Config->PlatformInfo.Nvram.Bid);
V
vit9696 已提交
391
    BidSize        = Config->PlatformInfo.Nvram.Bid.Size - 1;
392
    Mlb            = OC_BLOB_GET (&Config->PlatformInfo.Nvram.Mlb);
V
vit9696 已提交
393
    MlbSize        = Config->PlatformInfo.Nvram.Mlb.Size - 1;
394
    Rom            = &Config->PlatformInfo.Nvram.Rom[0];
V
vit9696 已提交
395
    RomSize        = sizeof (Config->PlatformInfo.Nvram.Rom);
396 397 398 399
    ExFeatures     = Config->PlatformInfo.Nvram.FirmwareFeatures;
    ExFeaturesMask = Config->PlatformInfo.Nvram.FirmwareFeaturesMask;
  } else {
    Bid            = MacInfo->Smbios.BoardProduct;
V
vit9696 已提交
400
    BidSize        = AsciiStrLen (Bid);
401
    Mlb            = OC_BLOB_GET (&Config->PlatformInfo.Generic.Mlb);
V
vit9696 已提交
402
    MlbSize        = Config->PlatformInfo.Generic.Mlb.Size - 1;
403
    Rom            = &Config->PlatformInfo.Generic.Rom[0];
V
vit9696 已提交
404
    RomSize        = sizeof (Config->PlatformInfo.Generic.Rom);
405 406 407 408
    ExFeatures     = MacInfo->Smbios.FirmwareFeatures;
    ExFeaturesMask = MacInfo->Smbios.FirmwareFeaturesMask;
  }

409 410
  Features       = (UINT32) ExFeatures;
  FeaturesMask   = (UINT32) ExFeaturesMask;
411 412 413 414 415 416

  if (Bid[0] != '\0') {
    Status = gRT->SetVariable (
      L"HW_BID",
      &gAppleVendorVariableGuid,
      EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
V
vit9696 已提交
417
      BidSize,
418
      (CHAR8 *) Bid
419 420 421 422 423 424 425 426 427 428 429 430 431 432
      );
    DEBUG ((
      EFI_ERROR (Status) ? DEBUG_WARN : DEBUG_INFO,
      "OC: Setting HW_BID %a - %r\n",
      Bid,
      Status
      ));
  }

  if (Rom[0] != 0 || Rom[1] != 0 || Rom[2] != 0 || Rom[3] != 0 || Rom[4] != 0 || Rom[5] != 0) {
    Status = gRT->SetVariable (
      L"HW_ROM",
      &gAppleVendorVariableGuid,
      EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
V
vit9696 已提交
433
      RomSize,
434
      (UINT8 *) Rom
435 436 437
      );
    DEBUG ((
      EFI_ERROR (Status) ? DEBUG_WARN : DEBUG_INFO,
438 439
      "OC: Setting HW_ROM %02x:%02x:%02x:%02x:%02x:%02x - %r\n",
      Rom[0], Rom[1], Rom[2], Rom[3], Rom[4], Rom[5],
440 441 442 443 444 445 446
      Status
      ));

    Status = gRT->SetVariable (
      L"ROM",
      &gAppleVendorVariableGuid,
      EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
V
vit9696 已提交
447
      RomSize,
448
      (UINT8 *) Rom
449 450 451
      );
    DEBUG ((
      EFI_ERROR (Status) ? DEBUG_WARN : DEBUG_INFO,
452 453
      "OC: Setting ROM %02x:%02x:%02x:%02x:%02x:%02x - %r\n",
      Rom[0], Rom[1], Rom[2], Rom[3], Rom[4], Rom[5],
454 455 456 457 458 459 460 461 462
      Status
      ));
  }

  if (Mlb[0] != '\0') {
    Status = gRT->SetVariable (
      L"HW_MLB",
      &gAppleVendorVariableGuid,
      EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
V
vit9696 已提交
463
      MlbSize,
464
      (CHAR8 *) Mlb
465 466 467 468
      );
    DEBUG ((
      EFI_ERROR (Status) ? DEBUG_WARN : DEBUG_INFO,
      "OC: Setting HW_MLB %a - %r\n",
469
      Mlb,
470 471 472 473 474 475 476
      Status
      ));

    Status = gRT->SetVariable (
      L"MLB",
      &gAppleVendorVariableGuid,
      EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
V
vit9696 已提交
477
      MlbSize,
478
      (CHAR8 *) Mlb
479 480 481 482
      );
    DEBUG ((
      EFI_ERROR (Status) ? DEBUG_WARN : DEBUG_INFO,
      "OC: Setting MLB %a - %r\n",
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
      Mlb,
      Status
      ));
  }

  if (ExFeatures != 0 || ExFeaturesMask != 0) {
    Status = gRT->SetVariable (
      L"FirmwareFeatures",
      &gAppleVendorVariableGuid,
      EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
      sizeof (Features),
      &Features
      );
    DEBUG ((
      EFI_ERROR (Status) ? DEBUG_WARN : DEBUG_INFO,
      "OC: Setting FirmwareFeatures %08x - %r\n",
      Features,
      Status
      ));

    Status = gRT->SetVariable (
      L"ExtendedFirmwareFeatures",
      &gAppleVendorVariableGuid,
      EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
      sizeof (ExFeatures),
      &ExFeatures
      );
    DEBUG ((
      EFI_ERROR (Status) ? DEBUG_WARN : DEBUG_INFO,
      "OC: Setting ExtendedFirmwareFeatures %016Lx - %r\n",
      ExFeatures,
      Status
      ));

    Status = gRT->SetVariable (
      L"FirmwareFeaturesMask",
      &gAppleVendorVariableGuid,
      EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
      sizeof (FeaturesMask),
      &FeaturesMask
      );
    DEBUG ((
      EFI_ERROR (Status) ? DEBUG_WARN : DEBUG_INFO,
      "OC: Setting FirmwareFeaturesMask %08x - %r\n",
      FeaturesMask,
      Status
      ));

    Status = gRT->SetVariable (
      L"ExtendedFirmwareFeaturesMask",
      &gAppleVendorVariableGuid,
      EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
      sizeof (ExFeaturesMask),
      &ExFeaturesMask
      );
    DEBUG ((
      EFI_ERROR (Status) ? DEBUG_WARN : DEBUG_INFO,
      "OC: Setting ExtendedFirmwareFeaturesMask %016Lx - %r\n",
      ExFeaturesMask,
542 543 544 545 546
      Status
      ));
  }
}

547 548 549 550 551 552
VOID
OcLoadPlatformSupport (
  IN OC_GLOBAL_CONFIG    *Config,
  IN OC_CPU_INFO         *CpuInfo
  )
{
553 554
  CONST CHAR8            *SmbiosUpdateStr;
  OC_SMBIOS_UPDATE_MODE  SmbiosUpdateMode;
555 556
  MAC_INFO_DATA          InfoData;
  MAC_INFO_DATA          *UsedMacInfo;
557 558 559
  EFI_STATUS             Status;
  OC_SMBIOS_TABLE        SmbiosTable;
  BOOLEAN                ExposeOem;
560

561
  if (Config->PlatformInfo.Automatic) {
562 563 564 565
    GetMacInfo (OC_BLOB_GET (&Config->PlatformInfo.Generic.SystemProductName), &InfoData);
    UsedMacInfo = &InfoData;
  } else {
    UsedMacInfo = NULL;
566 567 568
  }

  if (Config->PlatformInfo.UpdateDataHub) {
569
    OcPlatformUpdateDataHub (Config, CpuInfo, UsedMacInfo);
570
  }
571

572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
  ExposeOem = (Config->Misc.Security.ExposeSensitiveData & OCS_EXPOSE_OEM_INFO) != 0;

  if (ExposeOem || Config->PlatformInfo.UpdateSmbios) {
    Status = OcSmbiosTablePrepare (&SmbiosTable);
    if (!EFI_ERROR (Status)) {
      if (ExposeOem) {
        OcSmbiosExposeOemInfo (&SmbiosTable);
      }

      if (Config->PlatformInfo.UpdateSmbios) {
        SmbiosUpdateStr  = OC_BLOB_GET (&Config->PlatformInfo.UpdateSmbiosMode);

        if (AsciiStrCmp (SmbiosUpdateStr, "TryOverwrite") == 0) {
          SmbiosUpdateMode = OcSmbiosUpdateTryOverwrite;
        } else if (AsciiStrCmp (SmbiosUpdateStr, "Create") == 0) {
          SmbiosUpdateMode = OcSmbiosUpdateCreate;
        } else if (AsciiStrCmp (SmbiosUpdateStr, "Overwrite") == 0) {
          SmbiosUpdateMode = OcSmbiosUpdateOverwrite;
        } else if (AsciiStrCmp (SmbiosUpdateStr, "Custom") == 0) {
          SmbiosUpdateMode = OcSmbiosUpdateCustom;
        } else {
          DEBUG ((DEBUG_WARN, "OC: Invalid SMBIOS update mode %a\n", SmbiosUpdateStr));
          SmbiosUpdateMode = OcSmbiosUpdateCreate;
        }

        OcPlatformUpdateSmbios (Config, CpuInfo, UsedMacInfo, &SmbiosTable, SmbiosUpdateMode);
      }

      OcSmbiosTableFree (&SmbiosTable);
601
    } else {
602
      DEBUG ((DEBUG_WARN, "OC: Unable to obtain SMBIOS - %r\n", Status));
603 604
    }
  }
605 606

  if (Config->PlatformInfo.UpdateNvram) {
607
    OcPlatformUpdateNvram (Config, UsedMacInfo);
608
  }
609
}