From nobody Mon Apr 29 12:51:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+91584+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+91584+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1658326094; cv=none; d=zohomail.com; s=zohoarc; b=cLnhX3y5PNq0b+yAQrm6hctbafp6jmKY22DCPmdELwfw66UfTk++mpAzOn7UzaNfaCEMbNzK9/ojbCaKLuMq/47NzT48lL2JUSB4soMmlqqwhtWwNz+xuu4zmYq3e7d+yYzFQN1cTnDvnJ1YF9BnDXwHlS9zZ0CxeMxfxXV5nDs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658326094; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=Sq6mH05agM8f/TpNCV9dbeGGUaqXTF+l5135atGi8fg=; b=bwisVeVdgv2BBqrJVGMlwOjSETJQiqAtoVrQiyaYPpCiJifDacp3IBb3yoEjUdMKB7p+OPLzg7Supzk6UTF2+OxsFl5IK7Whr6+055x/xxHLONuM0NrgoEtXt86G4XrQncm+GIVolDXzao2oVoNNzvr6Du7v0fOgsKBCi+Wvahc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+91584+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1658326094296692.201011004312; Wed, 20 Jul 2022 07:08:14 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id XE7QYY1788612xdWtSyuGkbK; Wed, 20 Jul 2022 07:08:13 -0700 X-Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by mx.groups.io with SMTP id smtpd.web09.54188.1658326093089172385 for ; Wed, 20 Jul 2022 07:08:13 -0700 X-Received: by mail-lj1-f172.google.com with SMTP id m9so18603302ljp.9 for ; Wed, 20 Jul 2022 07:08:12 -0700 (PDT) X-Gm-Message-State: oU0ZY4xi81RUcbuFih0FuE3Gx1787277AA= X-Google-Smtp-Source: AGRyM1uUfCFau6LBHypUMlVBOX1oBr5PLB5ELBhEhiEWOXpBmrFFmEbDqZgulhTm2fm8/7Ea/VZayQ== X-Received: by 2002:a2e:8710:0:b0:25d:abcb:a636 with SMTP id m16-20020a2e8710000000b0025dabcba636mr1187599lji.324.1658326090975; Wed, 20 Jul 2022 07:08:10 -0700 (PDT) X-Received: from PC10319.67 ([82.97.198.254]) by smtp.googlemail.com with ESMTPSA id g1-20020a2ea4a1000000b0025d75995a07sm3229805ljm.24.2022.07.20.07.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 07:08:10 -0700 (PDT) From: "Konstantin Aladyshev" To: devel@edk2.groups.io Cc: bob.c.feng@intel.com, gaoliming@byosoft.com.cn, yuwei.chen@intel.com, Konstantin Aladyshev Subject: [edk2-devel] [PATCH] BaseTools/GenSec: Support EFI_SECTION_FREEFORM_SUBTYPE_GUID sections Date: Wed, 20 Jul 2022 17:08:12 +0300 Message-Id: <20220720140812.23803-1-aladyshev22@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,aladyshev22@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1658326093; bh=OAlTQFZsST8ZxFs45vLHRno0GWEQPbI0QspA3gGeBC4=; h=Cc:Date:From:Reply-To:Subject:To; b=nEZe92GEsFvxw3p3fqpowrVyxjZM0gPr1VVG4schBeNzCtFTXJVm5n2nMCeqEFE5+fR 5bl5nnEM6Ufw9bSwRB54GgfpWFG0rUKvvDXsRfLTWVKmAcPsvyHs7h9NEeTdOCkDCK4Xa 9ongpBDXA1jfgmXpwdDWLoDhILOX6lAb7S8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1658326096391100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Konstantin Aladyshev Reviewed-by: Bob Feng --- BaseTools/Source/C/GenSec/GenSec.c | 171 ++++++++++++++++++++++++++++- 1 file changed, 169 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/C/GenSec/GenSec.c b/BaseTools/Source/C/GenSec= /GenSec.c index 35a1ac64ea..d86cc197cc 100644 --- a/BaseTools/Source/C/GenSec/GenSec.c +++ b/BaseTools/Source/C/GenSec/GenSec.c @@ -988,6 +988,155 @@ Returns: return EFI_SUCCESS; } =20 +EFI_STATUS +GenSectionSubtypeGuidSection ( + CHAR8 **InputFileName, + UINT32 *InputFileAlign, + UINT32 InputFileNum, + EFI_GUID *SubTypeGuid, + UINT8 **OutFileBuffer + ) +/*++ + +Routine Description: + + Generate a section of type EFI_SECTION_FREEFORM_SUBTYPE_GUID + The function won't validate the input file contents. + The utility will add section header to the file. + +Arguments: + + InputFileName - Name of the input file. + + InputFileAlign - Alignment required by the input file data. + + InputFileNum - Number of input files. Should be 1 for this section. + + SubTypeGuid - Specify vendor guid value. + + OutFileBuffer - Buffer pointer to Output file contents + +Returns: + + EFI_SUCCESS on successful return + EFI_INVALID_PARAMETER if InputFileNum is less than 1 + EFI_ABORTED if unable to open input file. + EFI_OUT_OF_RESOURCES No resource to complete the operation. + +--*/ +{ + UINT32 TotalLength; + UINT32 InputLength; + UINT32 Offset; + UINT8 *FileBuffer; + EFI_STATUS Status; + EFI_FREEFORM_SUBTYPE_GUID_SECTION *SubtypeGuidSect; + EFI_FREEFORM_SUBTYPE_GUID_SECTION2 *SubtypeGuidSect2; + + + InputLength =3D 0; + Offset =3D 0; + FileBuffer =3D NULL; + TotalLength =3D 0; + + if (InputFileNum > 1) { + Error (NULL, 0, 2000, "Invalid parameter", "more than one input file s= pecified"); + return STATUS_ERROR; + } else if (InputFileNum < 1) { + Error (NULL, 0, 2000, "Invalid parameter", "no input file specified"); + return STATUS_ERROR; + } + + // + // read all input file contents into a buffer + // first get the size of all file contents + // + Status =3D GetSectionContents ( + InputFileName, + InputFileAlign, + InputFileNum, + FileBuffer, + &InputLength + ); + + if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { + Offset =3D sizeof (EFI_FREEFORM_SUBTYPE_GUID_SECTION); + if (InputLength + Offset >=3D MAX_SECTION_SIZE) { + Offset =3D sizeof (EFI_FREEFORM_SUBTYPE_GUID_SECTION2); + } + TotalLength =3D InputLength + Offset; + + FileBuffer =3D (UINT8 *) malloc (InputLength + Offset); + if (FileBuffer =3D=3D NULL) { + Error (NULL, 0, 4001, "Resource", "memory cannot be allocated"); + return EFI_OUT_OF_RESOURCES; + } + // + // read all input file contents into a buffer + // + Status =3D GetSectionContents ( + InputFileName, + InputFileAlign, + InputFileNum, + FileBuffer + Offset, + &InputLength + ); + } + + if (EFI_ERROR (Status)) { + if (FileBuffer !=3D NULL) { + free (FileBuffer); + } + Error (NULL, 0, 0001, "Error opening file for reading", InputFileName[= 0]); + return Status; + } + + if (InputLength =3D=3D 0) { + if (FileBuffer !=3D NULL) { + free (FileBuffer); + } + Error (NULL, 0, 2000, "Invalid parameter", "the size of input file %s = can't be zero", InputFileName); + return EFI_NOT_FOUND; + } + + // + // InputLength !=3D 0, but FileBuffer =3D=3D NULL means out of resources. + // + if (FileBuffer =3D=3D NULL) { + Error (NULL, 0, 4001, "Resource", "memory cannot be allocated"); + return EFI_OUT_OF_RESOURCES; + } + + // + // Now data is in FileBuffer + Offset + // + if (TotalLength >=3D MAX_SECTION_SIZE) { + SubtypeGuidSect2 =3D (EFI_FREEFORM_SUBTYPE_GUID_SECTION2 *) FileBuffer; + SubtypeGuidSect2->CommonHeader.Type =3D EFI_SECTION_GUID_DEFINED; + SubtypeGuidSect2->CommonHeader.Size[0] =3D (UINT8) 0xff; + SubtypeGuidSect2->CommonHeader.Size[1] =3D (UINT8) 0xff; + SubtypeGuidSect2->CommonHeader.Size[2] =3D (UINT8) 0xff; + SubtypeGuidSect2->CommonHeader.ExtendedSize =3D InputLength + sizeof (= EFI_FREEFORM_SUBTYPE_GUID_SECTION2); + memcpy (&(SubtypeGuidSect2->SubTypeGuid), SubTypeGuid, sizeof (EFI_GUI= D)); + } else { + SubtypeGuidSect =3D (EFI_FREEFORM_SUBTYPE_GUID_SECTION *) FileBuffer; + SubtypeGuidSect->CommonHeader.Type =3D EFI_SECTION_FREEFORM_SUBTYP= E_GUID; + SubtypeGuidSect->CommonHeader.Size[0] =3D (UINT8) (TotalLength & 0xff= ); + SubtypeGuidSect->CommonHeader.Size[1] =3D (UINT8) ((TotalLength & 0xf= f00) >> 8); + SubtypeGuidSect->CommonHeader.Size[2] =3D (UINT8) ((TotalLength & 0xf= f0000) >> 16); + memcpy (&(SubtypeGuidSect->SubTypeGuid), SubTypeGuid, sizeof (EFI_GUID= )); + } + + VerboseMsg ("the size of the created section file is %u bytes", (unsigne= d) TotalLength); + + // + // Set OutFileBuffer + // + *OutFileBuffer =3D FileBuffer; + + return EFI_SUCCESS; +} + EFI_STATUS FfsRebaseImageRead ( IN VOID *FileHandle, @@ -1591,14 +1740,22 @@ Returns: } =20 // - // GuidValue is only required by Guided section. + // GuidValue is only required by Guided section and SubtypeGuid section. // - if ((SectType !=3D EFI_SECTION_GUID_DEFINED) && + if ((SectType !=3D EFI_SECTION_GUID_DEFINED) && (SectType !=3D EFI_SECTI= ON_FREEFORM_SUBTYPE_GUID) && (SectionName !=3D NULL) && (CompareGuid (&VendorGuid, &mZeroGuid) !=3D 0)) { fprintf (stdout, "Warning: the input guid value is not required for th= is section type %s\n", SectionName); } =20 + // + // Check whether there is GUID for the SubtypeGuid section + // + if ((SectType =3D=3D EFI_SECTION_FREEFORM_SUBTYPE_GUID) && (CompareGuid = (&VendorGuid, &mZeroGuid) =3D=3D 0)) { + Error (NULL, 0, 1001, "Missing options", "GUID"); + goto Finish; + } + // // Check whether there is input file // @@ -1667,6 +1824,16 @@ Returns: ); break; =20 + case EFI_SECTION_FREEFORM_SUBTYPE_GUID: + Status =3D GenSectionSubtypeGuidSection ( + InputFileName, + InputFileAlign, + InputFileNum, + &VendorGuid, + &OutFileBuffer + ); + break; + case EFI_SECTION_VERSION: Index =3D sizeof (EFI_COMMON_SECTION_HEADER); // --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#91584): https://edk2.groups.io/g/devel/message/91584 Mute This Topic: https://groups.io/mt/92505133/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-