## @file\r
# generate capsule\r
#\r
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
#\r
# This program and the accompanying materials\r
# are licensed and made available under the terms and conditions of the BSD License\r
from Common.Misc import PackRegistryFormatGuid\r
import uuid\r
from struct import pack\r
+from GenFds import FindExtendTool\r
+from Common import EdkLogger\r
+from Common.BuildToolError import *\r
\r
\r
T_CHAR_LF = '\n'\r
+WIN_CERT_REVISION = 0x0200\r
+WIN_CERT_TYPE_EFI_GUID = 0x0EF1\r
+EFI_CERT_TYPE_PKCS7_GUID = uuid.UUID('{4aafd29d-68df-49ee-8aa9-347d375665a7}')\r
+EFI_CERT_TYPE_RSA2048_SHA256_GUID = uuid.UUID('{a7717414-c616-4977-9420-844712a735bf}')\r
\r
## create inf file describes what goes into capsule and call GenFv to generate capsule\r
#\r
FwMgrHdr.write(pack('=HH', len(self.CapsuleDataList), len(self.FmpPayloadList)))\r
FwMgrHdrSize = 4+2+2+8*(len(self.CapsuleDataList)+len(self.FmpPayloadList))\r
\r
+ #\r
+ # typedef struct _WIN_CERTIFICATE {\r
+ # UINT32 dwLength;\r
+ # UINT16 wRevision;\r
+ # UINT16 wCertificateType;\r
+ # //UINT8 bCertificate[ANYSIZE_ARRAY];\r
+ # } WIN_CERTIFICATE;\r
+ #\r
+ # typedef struct _WIN_CERTIFICATE_UEFI_GUID {\r
+ # WIN_CERTIFICATE Hdr;\r
+ # EFI_GUID CertType;\r
+ # //UINT8 CertData[ANYSIZE_ARRAY];\r
+ # } WIN_CERTIFICATE_UEFI_GUID;\r
+ #\r
+ # typedef struct {\r
+ # UINT64 MonotonicCount;\r
+ # WIN_CERTIFICATE_UEFI_GUID AuthInfo;\r
+ # } EFI_FIRMWARE_IMAGE_AUTHENTICATION;\r
+ #\r
+ # typedef struct _EFI_CERT_BLOCK_RSA_2048_SHA256 {\r
+ # EFI_GUID HashType;\r
+ # UINT8 PublicKey[256];\r
+ # UINT8 Signature[256];\r
+ # } EFI_CERT_BLOCK_RSA_2048_SHA256;\r
+ #\r
+\r
PreSize = FwMgrHdrSize\r
Content = StringIO.StringIO()\r
for driver in self.CapsuleDataList:\r
Content.write(File.read())\r
File.close()\r
for fmp in self.FmpPayloadList:\r
- payload = fmp.GenCapsuleSubItem()\r
+ if fmp.Existed:\r
+ FwMgrHdr.write(pack('=Q', PreSize))\r
+ PreSize += len(fmp.Buffer)\r
+ Content.write(fmp.Buffer)\r
+ continue\r
+ if fmp.ImageFile:\r
+ for Obj in fmp.ImageFile:\r
+ fmp.ImageFile = Obj.GenCapsuleSubItem()\r
+ if fmp.VendorCodeFile:\r
+ for Obj in fmp.VendorCodeFile:\r
+ fmp.VendorCodeFile = Obj.GenCapsuleSubItem()\r
+ if fmp.Certificate_Guid:\r
+ ExternalTool, ExternalOption = FindExtendTool([], GenFdsGlobalVariable.ArchList, fmp.Certificate_Guid)\r
+ CmdOption = ''\r
+ CapInputFile = fmp.ImageFile\r
+ if not os.path.isabs(fmp.ImageFile):\r
+ CapInputFile = os.path.join(GenFdsGlobalVariable.WorkSpaceDir, fmp.ImageFile)\r
+ CapOutputTmp = os.path.join(GenFdsGlobalVariable.FvDir, self.UiCapsuleName) + '.tmp'\r
+ if ExternalTool == None:\r
+ EdkLogger.error("GenFds", GENFDS_ERROR, "No tool found with GUID %s" % fmp.Certificate_Guid)\r
+ else:\r
+ CmdOption += ExternalTool\r
+ if ExternalOption:\r
+ CmdOption = CmdOption + ' ' + ExternalOption\r
+ CmdOption += ' -e ' + ' --monotonic-count ' + str(fmp.MonotonicCount) + ' -o ' + CapOutputTmp + ' ' + CapInputFile\r
+ CmdList = CmdOption.split()\r
+ GenFdsGlobalVariable.CallExternalTool(CmdList, "Failed to generate FMP auth capsule")\r
+ if uuid.UUID(fmp.Certificate_Guid) == EFI_CERT_TYPE_PKCS7_GUID:\r
+ dwLength = 4 + 2 + 2 + 16 + os.path.getsize(CapOutputTmp) - os.path.getsize(CapInputFile)\r
+ else:\r
+ dwLength = 4 + 2 + 2 + 16 + 16 + 256 + 256\r
+ fmp.ImageFile = CapOutputTmp\r
+ AuthData = [fmp.MonotonicCount, dwLength, WIN_CERT_REVISION, WIN_CERT_TYPE_EFI_GUID, fmp.Certificate_Guid]\r
+ fmp.Buffer = fmp.GenCapsuleSubItem(AuthData)\r
+ else:\r
+ fmp.Buffer = fmp.GenCapsuleSubItem()\r
FwMgrHdr.write(pack('=Q', PreSize))\r
- PreSize += len(payload)\r
- Content.write(payload)\r
+ PreSize += len(fmp.Buffer)\r
+ Content.write(fmp.Buffer)\r
BodySize = len(FwMgrHdr.getvalue()) + len(Content.getvalue())\r
Header.write(pack('=I', HdrSize + BodySize))\r
#\r