public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2] BaseTools: Add support for version 3 of FMP Image Header structure
@ 2021-04-22  7:50 Sughosh Ganu
  2021-05-12  0:27 ` [edk2-devel] " Bob Feng
  0 siblings, 1 reply; 3+ messages in thread
From: Sughosh Ganu @ 2021-04-22  7:50 UTC (permalink / raw)
  To: devel; +Cc: Michael Kinney, Bob Feng, Liming Gao, Yuwei Chen, Sughosh Ganu

Add support for the ImageCapsuleSupport field, introduced in version 3
of the EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER structure. This
structure member is used to indicate if the corresponding payload has
support for authentication and dependency.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---

Changes since v1:
- Reword the patch header to get rid of the PatchCheck warning
- Make passing of ImageCapsuleSupport parameter to the AddPayload
  function as an optional parameter to maintain backward compatibility
- Declare the values of CAPSULE_SUPPORT_DEPENDENCY and
  CAPSULE_SUPPORT_AUTHENTICATION in the FmpCapsuleHeaderClass and use
  those in the GenerateCapsule script

 .../Source/Python/Capsule/GenerateCapsule.py  |  5 +++-
 .../Common/Uefi/Capsule/FmpCapsuleHeader.py   | 28 +++++++++++++------
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/BaseTools/Source/Python/Capsule/GenerateCapsule.py b/BaseTools/Source/Python/Capsule/GenerateCapsule.py
index a8de988253..b8039db878 100644
--- a/BaseTools/Source/Python/Capsule/GenerateCapsule.py
+++ b/BaseTools/Source/Python/Capsule/GenerateCapsule.py
@@ -561,6 +561,7 @@ if __name__ == '__main__':
                 print ('GenerateCapsule: error:' + str(Msg))
                 sys.exit (1)
         for SinglePayloadDescriptor in PayloadDescriptorList:
+            ImageCapsuleSupport = 0x0000000000000000
             Result = SinglePayloadDescriptor.Payload
             try:
                 FmpPayloadHeader.FwVersion              = SinglePayloadDescriptor.FwVersion
@@ -575,6 +576,7 @@ if __name__ == '__main__':
             if SinglePayloadDescriptor.UseDependency:
                 CapsuleDependency.Payload = Result
                 CapsuleDependency.DepexExp = SinglePayloadDescriptor.DepexExp
+                ImageCapsuleSupport        |= FmpCapsuleHeader.CAPSULE_SUPPORT_DEPENDENCY
                 Result = CapsuleDependency.Encode ()
                 if args.Verbose:
                     CapsuleDependency.DumpInfo ()
@@ -607,13 +609,14 @@ if __name__ == '__main__':
                     FmpAuthHeader.MonotonicCount = SinglePayloadDescriptor.MonotonicCount
                     FmpAuthHeader.CertData       = CertData
                     FmpAuthHeader.Payload        = Result
+                    ImageCapsuleSupport          |= FmpCapsuleHeader.CAPSULE_SUPPORT_AUTHENTICATION
                     Result = FmpAuthHeader.Encode ()
                     if args.Verbose:
                         FmpAuthHeader.DumpInfo ()
                 except:
                     print ('GenerateCapsule: error: can not encode FMP Auth Header')
                     sys.exit (1)
-            FmpCapsuleHeader.AddPayload (SinglePayloadDescriptor.Guid, Result, HardwareInstance = SinglePayloadDescriptor.HardwareInstance, UpdateImageIndex = SinglePayloadDescriptor.UpdateImageIndex)
+            FmpCapsuleHeader.AddPayload (SinglePayloadDescriptor.Guid, Result, HardwareInstance = SinglePayloadDescriptor.HardwareInstance, UpdateImageIndex = SinglePayloadDescriptor.UpdateImageIndex, CapsuleSupport = ImageCapsuleSupport)
         try:
             for EmbeddedDriver in EmbeddedDriverDescriptorList:
                 FmpCapsuleHeader.AddEmbeddedDriver(EmbeddedDriver)
diff --git a/BaseTools/Source/Python/Common/Uefi/Capsule/FmpCapsuleHeader.py b/BaseTools/Source/Python/Common/Uefi/Capsule/FmpCapsuleHeader.py
index 91d24919c4..8abb449c6f 100644
--- a/BaseTools/Source/Python/Common/Uefi/Capsule/FmpCapsuleHeader.py
+++ b/BaseTools/Source/Python/Common/Uefi/Capsule/FmpCapsuleHeader.py
@@ -47,14 +47,19 @@ class FmpCapsuleImageHeaderClass (object):
     #   /// therefore can be modified without changing the Auth data.
     #   ///
     #   UINT64   UpdateHardwareInstance;
+    #
+    #   ///
+    #   /// Bits which indicate authentication and depex information for the image that follows this structure
+    #   ///
+    #   UINT64   ImageCapsuleSupport
     # } EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER;
     #
-    #  #define EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION 0x00000002
+    #  #define EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION 0x00000003
 
-    _StructFormat = '<I16sB3BIIQ'
+    _StructFormat = '<I16sB3BIIQQ'
     _StructSize   = struct.calcsize (_StructFormat)
 
-    EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION = 0x00000002
+    EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION = 0x00000003
 
     def __init__ (self):
         self._Valid                 = False
@@ -64,6 +69,7 @@ class FmpCapsuleImageHeaderClass (object):
         self.UpdateImageSize        = 0
         self.UpdateVendorCodeSize   = 0
         self.UpdateHardwareInstance = 0x0000000000000000
+        self.ImageCapsuleSupport    = 0x0000000000000000
         self.Payload                = b''
         self.VendorCodeBytes        = b''
 
@@ -78,7 +84,8 @@ class FmpCapsuleImageHeaderClass (object):
                                          0,0,0,
                                          self.UpdateImageSize,
                                          self.UpdateVendorCodeSize,
-                                         self.UpdateHardwareInstance
+                                         self.UpdateHardwareInstance,
+                                         self.ImageCapsuleSupport
                                          )
         self._Valid = True
         return FmpCapsuleImageHeader + self.Payload + self.VendorCodeBytes
@@ -86,7 +93,7 @@ class FmpCapsuleImageHeaderClass (object):
     def Decode (self, Buffer):
         if len (Buffer) < self._StructSize:
             raise ValueError
-        (Version, UpdateImageTypeId, UpdateImageIndex, r0, r1, r2, UpdateImageSize, UpdateVendorCodeSize, UpdateHardwareInstance) = \
+        (Version, UpdateImageTypeId, UpdateImageIndex, r0, r1, r2, UpdateImageSize, UpdateVendorCodeSize, UpdateHardwareInstance, ImageCapsuleSupport) = \
             struct.unpack (
                      self._StructFormat,
                      Buffer[0:self._StructSize]
@@ -105,6 +112,7 @@ class FmpCapsuleImageHeaderClass (object):
         self.UpdateImageSize        = UpdateImageSize
         self.UpdateVendorCodeSize   = UpdateVendorCodeSize
         self.UpdateHardwareInstance = UpdateHardwareInstance
+        self.ImageCapsuleSupport    = ImageCapsuleSupport
         self.Payload                = Buffer[self._StructSize:self._StructSize + UpdateImageSize]
         self.VendorCodeBytes        = Buffer[self._StructSize + UpdateImageSize:]
         self._Valid                 = True
@@ -119,6 +127,7 @@ class FmpCapsuleImageHeaderClass (object):
         print ('EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER.UpdateImageSize        = {UpdateImageSize:08X}'.format (UpdateImageSize = self.UpdateImageSize))
         print ('EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER.UpdateVendorCodeSize   = {UpdateVendorCodeSize:08X}'.format (UpdateVendorCodeSize = self.UpdateVendorCodeSize))
         print ('EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER.UpdateHardwareInstance = {UpdateHardwareInstance:016X}'.format (UpdateHardwareInstance = self.UpdateHardwareInstance))
+        print ('EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER.ImageCapsuleSupport    = {ImageCapsuleSupport:016X}'.format (ImageCapsuleSupport = self.ImageCapsuleSupport))
         print ('sizeof (Payload)                                                    = {Size:08X}'.format (Size = len (self.Payload)))
         print ('sizeof (VendorCodeBytes)                                            = {Size:08X}'.format (Size = len (self.VendorCodeBytes)))
 
@@ -153,6 +162,8 @@ class FmpCapsuleHeaderClass (object):
     _ItemOffsetSize   = struct.calcsize (_ItemOffsetFormat)
 
     EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER_INIT_VERSION = 0x00000001
+    CAPSULE_SUPPORT_AUTHENTICATION = 0x0000000000000001
+    CAPSULE_SUPPORT_DEPENDENCY     = 0x0000000000000002
 
     def __init__ (self):
         self._Valid                     = False
@@ -172,8 +183,8 @@ class FmpCapsuleHeaderClass (object):
             raise ValueError
         return self._EmbeddedDriverList[Index]
 
-    def AddPayload (self, UpdateImageTypeId, Payload = b'', VendorCodeBytes = b'', HardwareInstance = 0, UpdateImageIndex = 1):
-        self._PayloadList.append ((UpdateImageTypeId, Payload, VendorCodeBytes, HardwareInstance, UpdateImageIndex))
+    def AddPayload (self, UpdateImageTypeId, Payload = b'', VendorCodeBytes = b'', HardwareInstance = 0, UpdateImageIndex = 1, CapsuleSupport = 0):
+        self._PayloadList.append ((UpdateImageTypeId, Payload, VendorCodeBytes, HardwareInstance, UpdateImageIndex, CapsuleSupport))
 
     def GetFmpCapsuleImageHeader (self, Index):
         if Index >= len (self._FmpCapsuleImageHeaderList):
@@ -198,13 +209,14 @@ class FmpCapsuleHeaderClass (object):
             self._ItemOffsetList.append (Offset)
             Offset = Offset + len (EmbeddedDriver)
         Index = 1
-        for (UpdateImageTypeId, Payload, VendorCodeBytes, HardwareInstance, UpdateImageIndex) in self._PayloadList:
+        for (UpdateImageTypeId, Payload, VendorCodeBytes, HardwareInstance, UpdateImageIndex, CapsuleSupport) in self._PayloadList:
             FmpCapsuleImageHeader = FmpCapsuleImageHeaderClass ()
             FmpCapsuleImageHeader.UpdateImageTypeId      = UpdateImageTypeId
             FmpCapsuleImageHeader.UpdateImageIndex       = UpdateImageIndex
             FmpCapsuleImageHeader.Payload                = Payload
             FmpCapsuleImageHeader.VendorCodeBytes        = VendorCodeBytes
             FmpCapsuleImageHeader.UpdateHardwareInstance = HardwareInstance
+            FmpCapsuleImageHeader.ImageCapsuleSupport    = CapsuleSupport
             FmpCapsuleImage = FmpCapsuleImageHeader.Encode ()
             FmpCapsuleData = FmpCapsuleData + FmpCapsuleImage
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2] BaseTools: Add support for version 3 of FMP Image Header structure
@ 2021-04-23 11:28 Sughosh Ganu
  0 siblings, 0 replies; 3+ messages in thread
From: Sughosh Ganu @ 2021-04-23 11:28 UTC (permalink / raw)
  To: devel; +Cc: Michal Simek, Sughosh Ganu

Add support for the ImageCapsuleSupport field, introduced in version 3
of the EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER structure. This
structure member is used to indicate if the corresponding payload has
support for authentication and dependency.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---

Changes since v1:
- Reword the patch header to get rid of the PatchCheck warning
- Make passing of ImageCapsuleSupport parameter to the AddPayload
  function as an optional parameter to maintain backward compatibility
- Declare the values of CAPSULE_SUPPORT_DEPENDENCY and
  CAPSULE_SUPPORT_AUTHENTICATION in the FmpCapsuleHeaderClass and use
  those in the GenerateCapsule script

 .../Source/Python/Capsule/GenerateCapsule.py  |  5 +++-
 .../Common/Uefi/Capsule/FmpCapsuleHeader.py   | 28 +++++++++++++------
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/BaseTools/Source/Python/Capsule/GenerateCapsule.py b/BaseTools/Source/Python/Capsule/GenerateCapsule.py
index a8de988253..b8039db878 100644
--- a/BaseTools/Source/Python/Capsule/GenerateCapsule.py
+++ b/BaseTools/Source/Python/Capsule/GenerateCapsule.py
@@ -561,6 +561,7 @@ if __name__ == '__main__':
                 print ('GenerateCapsule: error:' + str(Msg))
                 sys.exit (1)
         for SinglePayloadDescriptor in PayloadDescriptorList:
+            ImageCapsuleSupport = 0x0000000000000000
             Result = SinglePayloadDescriptor.Payload
             try:
                 FmpPayloadHeader.FwVersion              = SinglePayloadDescriptor.FwVersion
@@ -575,6 +576,7 @@ if __name__ == '__main__':
             if SinglePayloadDescriptor.UseDependency:
                 CapsuleDependency.Payload = Result
                 CapsuleDependency.DepexExp = SinglePayloadDescriptor.DepexExp
+                ImageCapsuleSupport        |= FmpCapsuleHeader.CAPSULE_SUPPORT_DEPENDENCY
                 Result = CapsuleDependency.Encode ()
                 if args.Verbose:
                     CapsuleDependency.DumpInfo ()
@@ -607,13 +609,14 @@ if __name__ == '__main__':
                     FmpAuthHeader.MonotonicCount = SinglePayloadDescriptor.MonotonicCount
                     FmpAuthHeader.CertData       = CertData
                     FmpAuthHeader.Payload        = Result
+                    ImageCapsuleSupport          |= FmpCapsuleHeader.CAPSULE_SUPPORT_AUTHENTICATION
                     Result = FmpAuthHeader.Encode ()
                     if args.Verbose:
                         FmpAuthHeader.DumpInfo ()
                 except:
                     print ('GenerateCapsule: error: can not encode FMP Auth Header')
                     sys.exit (1)
-            FmpCapsuleHeader.AddPayload (SinglePayloadDescriptor.Guid, Result, HardwareInstance = SinglePayloadDescriptor.HardwareInstance, UpdateImageIndex = SinglePayloadDescriptor.UpdateImageIndex)
+            FmpCapsuleHeader.AddPayload (SinglePayloadDescriptor.Guid, Result, HardwareInstance = SinglePayloadDescriptor.HardwareInstance, UpdateImageIndex = SinglePayloadDescriptor.UpdateImageIndex, CapsuleSupport = ImageCapsuleSupport)
         try:
             for EmbeddedDriver in EmbeddedDriverDescriptorList:
                 FmpCapsuleHeader.AddEmbeddedDriver(EmbeddedDriver)
diff --git a/BaseTools/Source/Python/Common/Uefi/Capsule/FmpCapsuleHeader.py b/BaseTools/Source/Python/Common/Uefi/Capsule/FmpCapsuleHeader.py
index 91d24919c4..8abb449c6f 100644
--- a/BaseTools/Source/Python/Common/Uefi/Capsule/FmpCapsuleHeader.py
+++ b/BaseTools/Source/Python/Common/Uefi/Capsule/FmpCapsuleHeader.py
@@ -47,14 +47,19 @@ class FmpCapsuleImageHeaderClass (object):
     #   /// therefore can be modified without changing the Auth data.
     #   ///
     #   UINT64   UpdateHardwareInstance;
+    #
+    #   ///
+    #   /// Bits which indicate authentication and depex information for the image that follows this structure
+    #   ///
+    #   UINT64   ImageCapsuleSupport
     # } EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER;
     #
-    #  #define EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION 0x00000002
+    #  #define EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION 0x00000003
 
-    _StructFormat = '<I16sB3BIIQ'
+    _StructFormat = '<I16sB3BIIQQ'
     _StructSize   = struct.calcsize (_StructFormat)
 
-    EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION = 0x00000002
+    EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION = 0x00000003
 
     def __init__ (self):
         self._Valid                 = False
@@ -64,6 +69,7 @@ class FmpCapsuleImageHeaderClass (object):
         self.UpdateImageSize        = 0
         self.UpdateVendorCodeSize   = 0
         self.UpdateHardwareInstance = 0x0000000000000000
+        self.ImageCapsuleSupport    = 0x0000000000000000
         self.Payload                = b''
         self.VendorCodeBytes        = b''
 
@@ -78,7 +84,8 @@ class FmpCapsuleImageHeaderClass (object):
                                          0,0,0,
                                          self.UpdateImageSize,
                                          self.UpdateVendorCodeSize,
-                                         self.UpdateHardwareInstance
+                                         self.UpdateHardwareInstance,
+                                         self.ImageCapsuleSupport
                                          )
         self._Valid = True
         return FmpCapsuleImageHeader + self.Payload + self.VendorCodeBytes
@@ -86,7 +93,7 @@ class FmpCapsuleImageHeaderClass (object):
     def Decode (self, Buffer):
         if len (Buffer) < self._StructSize:
             raise ValueError
-        (Version, UpdateImageTypeId, UpdateImageIndex, r0, r1, r2, UpdateImageSize, UpdateVendorCodeSize, UpdateHardwareInstance) = \
+        (Version, UpdateImageTypeId, UpdateImageIndex, r0, r1, r2, UpdateImageSize, UpdateVendorCodeSize, UpdateHardwareInstance, ImageCapsuleSupport) = \
             struct.unpack (
                      self._StructFormat,
                      Buffer[0:self._StructSize]
@@ -105,6 +112,7 @@ class FmpCapsuleImageHeaderClass (object):
         self.UpdateImageSize        = UpdateImageSize
         self.UpdateVendorCodeSize   = UpdateVendorCodeSize
         self.UpdateHardwareInstance = UpdateHardwareInstance
+        self.ImageCapsuleSupport    = ImageCapsuleSupport
         self.Payload                = Buffer[self._StructSize:self._StructSize + UpdateImageSize]
         self.VendorCodeBytes        = Buffer[self._StructSize + UpdateImageSize:]
         self._Valid                 = True
@@ -119,6 +127,7 @@ class FmpCapsuleImageHeaderClass (object):
         print ('EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER.UpdateImageSize        = {UpdateImageSize:08X}'.format (UpdateImageSize = self.UpdateImageSize))
         print ('EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER.UpdateVendorCodeSize   = {UpdateVendorCodeSize:08X}'.format (UpdateVendorCodeSize = self.UpdateVendorCodeSize))
         print ('EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER.UpdateHardwareInstance = {UpdateHardwareInstance:016X}'.format (UpdateHardwareInstance = self.UpdateHardwareInstance))
+        print ('EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER.ImageCapsuleSupport    = {ImageCapsuleSupport:016X}'.format (ImageCapsuleSupport = self.ImageCapsuleSupport))
         print ('sizeof (Payload)                                                    = {Size:08X}'.format (Size = len (self.Payload)))
         print ('sizeof (VendorCodeBytes)                                            = {Size:08X}'.format (Size = len (self.VendorCodeBytes)))
 
@@ -153,6 +162,8 @@ class FmpCapsuleHeaderClass (object):
     _ItemOffsetSize   = struct.calcsize (_ItemOffsetFormat)
 
     EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER_INIT_VERSION = 0x00000001
+    CAPSULE_SUPPORT_AUTHENTICATION = 0x0000000000000001
+    CAPSULE_SUPPORT_DEPENDENCY     = 0x0000000000000002
 
     def __init__ (self):
         self._Valid                     = False
@@ -172,8 +183,8 @@ class FmpCapsuleHeaderClass (object):
             raise ValueError
         return self._EmbeddedDriverList[Index]
 
-    def AddPayload (self, UpdateImageTypeId, Payload = b'', VendorCodeBytes = b'', HardwareInstance = 0, UpdateImageIndex = 1):
-        self._PayloadList.append ((UpdateImageTypeId, Payload, VendorCodeBytes, HardwareInstance, UpdateImageIndex))
+    def AddPayload (self, UpdateImageTypeId, Payload = b'', VendorCodeBytes = b'', HardwareInstance = 0, UpdateImageIndex = 1, CapsuleSupport = 0):
+        self._PayloadList.append ((UpdateImageTypeId, Payload, VendorCodeBytes, HardwareInstance, UpdateImageIndex, CapsuleSupport))
 
     def GetFmpCapsuleImageHeader (self, Index):
         if Index >= len (self._FmpCapsuleImageHeaderList):
@@ -198,13 +209,14 @@ class FmpCapsuleHeaderClass (object):
             self._ItemOffsetList.append (Offset)
             Offset = Offset + len (EmbeddedDriver)
         Index = 1
-        for (UpdateImageTypeId, Payload, VendorCodeBytes, HardwareInstance, UpdateImageIndex) in self._PayloadList:
+        for (UpdateImageTypeId, Payload, VendorCodeBytes, HardwareInstance, UpdateImageIndex, CapsuleSupport) in self._PayloadList:
             FmpCapsuleImageHeader = FmpCapsuleImageHeaderClass ()
             FmpCapsuleImageHeader.UpdateImageTypeId      = UpdateImageTypeId
             FmpCapsuleImageHeader.UpdateImageIndex       = UpdateImageIndex
             FmpCapsuleImageHeader.Payload                = Payload
             FmpCapsuleImageHeader.VendorCodeBytes        = VendorCodeBytes
             FmpCapsuleImageHeader.UpdateHardwareInstance = HardwareInstance
+            FmpCapsuleImageHeader.ImageCapsuleSupport    = CapsuleSupport
             FmpCapsuleImage = FmpCapsuleImageHeader.Encode ()
             FmpCapsuleData = FmpCapsuleData + FmpCapsuleImage
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [edk2-devel] [PATCH v2] BaseTools: Add support for version 3 of FMP Image Header structure
  2021-04-22  7:50 [PATCH v2] BaseTools: Add support for version 3 of FMP Image Header structure Sughosh Ganu
@ 2021-05-12  0:27 ` Bob Feng
  0 siblings, 0 replies; 3+ messages in thread
From: Bob Feng @ 2021-05-12  0:27 UTC (permalink / raw)
  To: devel@edk2.groups.io, sughosh.ganu@linaro.org
  Cc: Kinney, Michael D, Liming Gao, Chen, Christine

This patch is good to me.
Reviewed-by: Bob Feng <bob.c.feng@intel.com>


Thanks,
Bob

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Sughosh Ganu
Sent: Thursday, April 22, 2021 3:51 PM
To: devel@edk2.groups.io
Cc: Kinney, Michael D <michael.d.kinney@intel.com>; Feng, Bob C <bob.c.feng@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>; Chen, Christine <yuwei.chen@intel.com>; Sughosh Ganu <sughosh.ganu@linaro.org>
Subject: [edk2-devel] [PATCH v2] BaseTools: Add support for version 3 of FMP Image Header structure

Add support for the ImageCapsuleSupport field, introduced in version 3 of the EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER structure. This structure member is used to indicate if the corresponding payload has support for authentication and dependency.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---

Changes since v1:
- Reword the patch header to get rid of the PatchCheck warning
- Make passing of ImageCapsuleSupport parameter to the AddPayload
  function as an optional parameter to maintain backward compatibility
- Declare the values of CAPSULE_SUPPORT_DEPENDENCY and
  CAPSULE_SUPPORT_AUTHENTICATION in the FmpCapsuleHeaderClass and use
  those in the GenerateCapsule script

 .../Source/Python/Capsule/GenerateCapsule.py  |  5 +++-
 .../Common/Uefi/Capsule/FmpCapsuleHeader.py   | 28 +++++++++++++------
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/BaseTools/Source/Python/Capsule/GenerateCapsule.py b/BaseTools/Source/Python/Capsule/GenerateCapsule.py
index a8de988253..b8039db878 100644
--- a/BaseTools/Source/Python/Capsule/GenerateCapsule.py
+++ b/BaseTools/Source/Python/Capsule/GenerateCapsule.py
@@ -561,6 +561,7 @@ if __name__ == '__main__':
                 print ('GenerateCapsule: error:' + str(Msg))
                 sys.exit (1)
         for SinglePayloadDescriptor in PayloadDescriptorList:
+            ImageCapsuleSupport = 0x0000000000000000
             Result = SinglePayloadDescriptor.Payload
             try:
                 FmpPayloadHeader.FwVersion              = SinglePayloadDescriptor.FwVersion
@@ -575,6 +576,7 @@ if __name__ == '__main__':
             if SinglePayloadDescriptor.UseDependency:
                 CapsuleDependency.Payload = Result
                 CapsuleDependency.DepexExp = SinglePayloadDescriptor.DepexExp
+                ImageCapsuleSupport        |= FmpCapsuleHeader.CAPSULE_SUPPORT_DEPENDENCY
                 Result = CapsuleDependency.Encode ()
                 if args.Verbose:
                     CapsuleDependency.DumpInfo () @@ -607,13 +609,14 @@ if __name__ == '__main__':
                     FmpAuthHeader.MonotonicCount = SinglePayloadDescriptor.MonotonicCount
                     FmpAuthHeader.CertData       = CertData
                     FmpAuthHeader.Payload        = Result
+                    ImageCapsuleSupport          |= FmpCapsuleHeader.CAPSULE_SUPPORT_AUTHENTICATION
                     Result = FmpAuthHeader.Encode ()
                     if args.Verbose:
                         FmpAuthHeader.DumpInfo ()
                 except:
                     print ('GenerateCapsule: error: can not encode FMP Auth Header')
                     sys.exit (1)
-            FmpCapsuleHeader.AddPayload (SinglePayloadDescriptor.Guid, Result, HardwareInstance = SinglePayloadDescriptor.HardwareInstance, UpdateImageIndex = SinglePayloadDescriptor.UpdateImageIndex)
+            FmpCapsuleHeader.AddPayload (SinglePayloadDescriptor.Guid, 
+ Result, HardwareInstance = SinglePayloadDescriptor.HardwareInstance, 
+ UpdateImageIndex = SinglePayloadDescriptor.UpdateImageIndex, 
+ CapsuleSupport = ImageCapsuleSupport)
         try:
             for EmbeddedDriver in EmbeddedDriverDescriptorList:
                 FmpCapsuleHeader.AddEmbeddedDriver(EmbeddedDriver)
diff --git a/BaseTools/Source/Python/Common/Uefi/Capsule/FmpCapsuleHeader.py b/BaseTools/Source/Python/Common/Uefi/Capsule/FmpCapsuleHeader.py
index 91d24919c4..8abb449c6f 100644
--- a/BaseTools/Source/Python/Common/Uefi/Capsule/FmpCapsuleHeader.py
+++ b/BaseTools/Source/Python/Common/Uefi/Capsule/FmpCapsuleHeader.py
@@ -47,14 +47,19 @@ class FmpCapsuleImageHeaderClass (object):
     #   /// therefore can be modified without changing the Auth data.
     #   ///
     #   UINT64   UpdateHardwareInstance;
+    #
+    #   ///
+    #   /// Bits which indicate authentication and depex information for the image that follows this structure
+    #   ///
+    #   UINT64   ImageCapsuleSupport
     # } EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER;
     #
-    #  #define EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION 0x00000002
+    #  #define 
+ EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION 0x00000003
 
-    _StructFormat = '<I16sB3BIIQ'
+    _StructFormat = '<I16sB3BIIQQ'
     _StructSize   = struct.calcsize (_StructFormat)
 
-    EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION = 0x00000002
+    EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION = 
+ 0x00000003
 
     def __init__ (self):
         self._Valid                 = False
@@ -64,6 +69,7 @@ class FmpCapsuleImageHeaderClass (object):
         self.UpdateImageSize        = 0
         self.UpdateVendorCodeSize   = 0
         self.UpdateHardwareInstance = 0x0000000000000000
+        self.ImageCapsuleSupport    = 0x0000000000000000
         self.Payload                = b''
         self.VendorCodeBytes        = b''
 
@@ -78,7 +84,8 @@ class FmpCapsuleImageHeaderClass (object):
                                          0,0,0,
                                          self.UpdateImageSize,
                                          self.UpdateVendorCodeSize,
-                                         self.UpdateHardwareInstance
+                                         self.UpdateHardwareInstance,
+                                         self.ImageCapsuleSupport
                                          )
         self._Valid = True
         return FmpCapsuleImageHeader + self.Payload + self.VendorCodeBytes @@ -86,7 +93,7 @@ class FmpCapsuleImageHeaderClass (object):
     def Decode (self, Buffer):
         if len (Buffer) < self._StructSize:
             raise ValueError
-        (Version, UpdateImageTypeId, UpdateImageIndex, r0, r1, r2, UpdateImageSize, UpdateVendorCodeSize, UpdateHardwareInstance) = \
+        (Version, UpdateImageTypeId, UpdateImageIndex, r0, r1, r2, 
+ UpdateImageSize, UpdateVendorCodeSize, UpdateHardwareInstance, 
+ ImageCapsuleSupport) = \
             struct.unpack (
                      self._StructFormat,
                      Buffer[0:self._StructSize] @@ -105,6 +112,7 @@ class FmpCapsuleImageHeaderClass (object):
         self.UpdateImageSize        = UpdateImageSize
         self.UpdateVendorCodeSize   = UpdateVendorCodeSize
         self.UpdateHardwareInstance = UpdateHardwareInstance
+        self.ImageCapsuleSupport    = ImageCapsuleSupport
         self.Payload                = Buffer[self._StructSize:self._StructSize + UpdateImageSize]
         self.VendorCodeBytes        = Buffer[self._StructSize + UpdateImageSize:]
         self._Valid                 = True
@@ -119,6 +127,7 @@ class FmpCapsuleImageHeaderClass (object):
         print ('EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER.UpdateImageSize        = {UpdateImageSize:08X}'.format (UpdateImageSize = self.UpdateImageSize))
         print ('EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER.UpdateVendorCodeSize   = {UpdateVendorCodeSize:08X}'.format (UpdateVendorCodeSize = self.UpdateVendorCodeSize))
         print ('EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER.UpdateHardwareInstance = {UpdateHardwareInstance:016X}'.format (UpdateHardwareInstance = self.UpdateHardwareInstance))
+        print ('EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER.ImageCapsuleSupport    = {ImageCapsuleSupport:016X}'.format (ImageCapsuleSupport = self.ImageCapsuleSupport))
         print ('sizeof (Payload)                                                    = {Size:08X}'.format (Size = len (self.Payload)))
         print ('sizeof (VendorCodeBytes)                                            = {Size:08X}'.format (Size = len (self.VendorCodeBytes)))
 
@@ -153,6 +162,8 @@ class FmpCapsuleHeaderClass (object):
     _ItemOffsetSize   = struct.calcsize (_ItemOffsetFormat)
 
     EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER_INIT_VERSION = 0x00000001
+    CAPSULE_SUPPORT_AUTHENTICATION = 0x0000000000000001
+    CAPSULE_SUPPORT_DEPENDENCY     = 0x0000000000000002
 
     def __init__ (self):
         self._Valid                     = False
@@ -172,8 +183,8 @@ class FmpCapsuleHeaderClass (object):
             raise ValueError
         return self._EmbeddedDriverList[Index]
 
-    def AddPayload (self, UpdateImageTypeId, Payload = b'', VendorCodeBytes = b'', HardwareInstance = 0, UpdateImageIndex = 1):
-        self._PayloadList.append ((UpdateImageTypeId, Payload, VendorCodeBytes, HardwareInstance, UpdateImageIndex))
+    def AddPayload (self, UpdateImageTypeId, Payload = b'', VendorCodeBytes = b'', HardwareInstance = 0, UpdateImageIndex = 1, CapsuleSupport = 0):
+        self._PayloadList.append ((UpdateImageTypeId, Payload, 
+ VendorCodeBytes, HardwareInstance, UpdateImageIndex, CapsuleSupport))
 
     def GetFmpCapsuleImageHeader (self, Index):
         if Index >= len (self._FmpCapsuleImageHeaderList):
@@ -198,13 +209,14 @@ class FmpCapsuleHeaderClass (object):
             self._ItemOffsetList.append (Offset)
             Offset = Offset + len (EmbeddedDriver)
         Index = 1
-        for (UpdateImageTypeId, Payload, VendorCodeBytes, HardwareInstance, UpdateImageIndex) in self._PayloadList:
+        for (UpdateImageTypeId, Payload, VendorCodeBytes, HardwareInstance, UpdateImageIndex, CapsuleSupport) in self._PayloadList:
             FmpCapsuleImageHeader = FmpCapsuleImageHeaderClass ()
             FmpCapsuleImageHeader.UpdateImageTypeId      = UpdateImageTypeId
             FmpCapsuleImageHeader.UpdateImageIndex       = UpdateImageIndex
             FmpCapsuleImageHeader.Payload                = Payload
             FmpCapsuleImageHeader.VendorCodeBytes        = VendorCodeBytes
             FmpCapsuleImageHeader.UpdateHardwareInstance = HardwareInstance
+            FmpCapsuleImageHeader.ImageCapsuleSupport    = CapsuleSupport
             FmpCapsuleImage = FmpCapsuleImageHeader.Encode ()
             FmpCapsuleData = FmpCapsuleData + FmpCapsuleImage
 
--
2.17.1







^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-12  0:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-22  7:50 [PATCH v2] BaseTools: Add support for version 3 of FMP Image Header structure Sughosh Ganu
2021-05-12  0:27 ` [edk2-devel] " Bob Feng
  -- strict thread matches above, loose matches on Subject: below --
2021-04-23 11:28 Sughosh Ganu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox