From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EvO7gBNT; spf=pass (domain: gmail.com, ip: 209.85.208.172, mailfrom: aladyshev22@gmail.com) Received: by mail-lj1-f172.google.com with SMTP id m9so18603302ljp.9 for ; Wed, 20 Jul 2022 07:08:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=TRq4Mb94ELj8y93ZKfr5+M8DbsWHa+tBE1evS9ZvCXw=; b=EvO7gBNT7d/AN0waQttShxjqIu1meB0Q7mNa3HWfMHwinc1/rikKzhLQAbFrMw3u/D Dh2bJgxrIvt5QWC1/NJg6PSW/ee0WntvhyW3KhyY6vsObQw34A74Ct2VG9BQ3oRVX3kY nq6S673YG0tnoa3Ot4vCX0j1WtrDwqr1zHtvZOBcfVwzL21vX8/ROt0BK2tCFyi4emM9 Q+GzL1rC03ikF8D0gPiMhzS0WmphDXCSfqBTdrHJSD3SXlRTXXW+GHn8GZ8DN2cq52xt Cdsd0jBg92wf4zMIbZz5tdmJExA1+j0owgwWooraylq60Ymnl18pxSWw1Pvc29ztz1MW q6ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=TRq4Mb94ELj8y93ZKfr5+M8DbsWHa+tBE1evS9ZvCXw=; b=1SCdGjguydWx9LdVMGFTaXW+5EoVDYMfmvy3G/VksbMoSmgwHoHqS6Wc8glljUSTcj rurV1GeqRwP03V2b9PqGpCnYEbN2bh0POl5qdor3MOA1IDxysU1x4v2LVZ/PAFl2Ut21 zA6NEIfIdpzkhDLONuH11vCp6QN+4NsJJatLkVkwof9D44UpT9Z4yzdDenIaklxLFQH0 mmLQZOtIkCD5Ik1RePEigW3eN4ZWcYiHyfiNGNkGAgsSzei4/Rfoa+T3lHjsdqm1onv+ yrQN4v2IeFBr2eZdHJ0zMc04RoyaDli/jDef3n/cBAg/djaTcpBjKuk705V2PVihbs5M XAQg== X-Gm-Message-State: AJIora8WmjjgRy8G6/SvVBzCjpYULBsgzVuE3nzKYs2F/xdaydDIhUDZ h2DxetXzaOkTjf66ROj/WFNiSnqemgI= 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) Return-Path: 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: [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> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Signed-off-by: Konstantin Aladyshev --- 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;=0D }=0D =0D +EFI_STATUS=0D +GenSectionSubtypeGuidSection (=0D + CHAR8 **InputFileName,=0D + UINT32 *InputFileAlign,=0D + UINT32 InputFileNum,=0D + EFI_GUID *SubTypeGuid,=0D + UINT8 **OutFileBuffer=0D + )=0D +/*++=0D +=0D +Routine Description:=0D +=0D + Generate a section of type EFI_SECTION_FREEFORM_SUBTYPE_GUID=0D + The function won't validate the input file contents.=0D + The utility will add section header to the file.=0D +=0D +Arguments:=0D +=0D + InputFileName - Name of the input file.=0D +=0D + InputFileAlign - Alignment required by the input file data.=0D +=0D + InputFileNum - Number of input files. Should be 1 for this section.=0D +=0D + SubTypeGuid - Specify vendor guid value.=0D +=0D + OutFileBuffer - Buffer pointer to Output file contents=0D +=0D +Returns:=0D +=0D + EFI_SUCCESS on successful return=0D + EFI_INVALID_PARAMETER if InputFileNum is less than 1=0D + EFI_ABORTED if unable to open input file.=0D + EFI_OUT_OF_RESOURCES No resource to complete the operation.=0D +=0D +--*/=0D +{=0D + UINT32 TotalLength;=0D + UINT32 InputLength;=0D + UINT32 Offset;=0D + UINT8 *FileBuffer;=0D + EFI_STATUS Status;=0D + EFI_FREEFORM_SUBTYPE_GUID_SECTION *SubtypeGuidSect;=0D + EFI_FREEFORM_SUBTYPE_GUID_SECTION2 *SubtypeGuidSect2;=0D +=0D +=0D + InputLength =3D 0;=0D + Offset =3D 0;=0D + FileBuffer =3D NULL;=0D + TotalLength =3D 0;=0D +=0D + if (InputFileNum > 1) {=0D + Error (NULL, 0, 2000, "Invalid parameter", "more than one input file s= pecified");=0D + return STATUS_ERROR;=0D + } else if (InputFileNum < 1) {=0D + Error (NULL, 0, 2000, "Invalid parameter", "no input file specified");= =0D + return STATUS_ERROR;=0D + }=0D +=0D + //=0D + // read all input file contents into a buffer=0D + // first get the size of all file contents=0D + //=0D + Status =3D GetSectionContents (=0D + InputFileName,=0D + InputFileAlign,=0D + InputFileNum,=0D + FileBuffer,=0D + &InputLength=0D + );=0D +=0D + if (Status =3D=3D EFI_BUFFER_TOO_SMALL) {=0D + Offset =3D sizeof (EFI_FREEFORM_SUBTYPE_GUID_SECTION);=0D + if (InputLength + Offset >=3D MAX_SECTION_SIZE) {=0D + Offset =3D sizeof (EFI_FREEFORM_SUBTYPE_GUID_SECTION2);=0D + }=0D + TotalLength =3D InputLength + Offset;=0D +=0D + FileBuffer =3D (UINT8 *) malloc (InputLength + Offset);=0D + if (FileBuffer =3D=3D NULL) {=0D + Error (NULL, 0, 4001, "Resource", "memory cannot be allocated");=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D + //=0D + // read all input file contents into a buffer=0D + //=0D + Status =3D GetSectionContents (=0D + InputFileName,=0D + InputFileAlign,=0D + InputFileNum,=0D + FileBuffer + Offset,=0D + &InputLength=0D + );=0D + }=0D +=0D + if (EFI_ERROR (Status)) {=0D + if (FileBuffer !=3D NULL) {=0D + free (FileBuffer);=0D + }=0D + Error (NULL, 0, 0001, "Error opening file for reading", InputFileName[= 0]);=0D + return Status;=0D + }=0D +=0D + if (InputLength =3D=3D 0) {=0D + if (FileBuffer !=3D NULL) {=0D + free (FileBuffer);=0D + }=0D + Error (NULL, 0, 2000, "Invalid parameter", "the size of input file %s = can't be zero", InputFileName);=0D + return EFI_NOT_FOUND;=0D + }=0D +=0D + //=0D + // InputLength !=3D 0, but FileBuffer =3D=3D NULL means out of resources= .=0D + //=0D + if (FileBuffer =3D=3D NULL) {=0D + Error (NULL, 0, 4001, "Resource", "memory cannot be allocated");=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D +=0D + //=0D + // Now data is in FileBuffer + Offset=0D + //=0D + if (TotalLength >=3D MAX_SECTION_SIZE) {=0D + SubtypeGuidSect2 =3D (EFI_FREEFORM_SUBTYPE_GUID_SECTION2 *) FileBuffer= ;=0D + SubtypeGuidSect2->CommonHeader.Type =3D EFI_SECTION_GUID_DEFINED;= =0D + SubtypeGuidSect2->CommonHeader.Size[0] =3D (UINT8) 0xff;=0D + SubtypeGuidSect2->CommonHeader.Size[1] =3D (UINT8) 0xff;=0D + SubtypeGuidSect2->CommonHeader.Size[2] =3D (UINT8) 0xff;=0D + SubtypeGuidSect2->CommonHeader.ExtendedSize =3D InputLength + sizeof (= EFI_FREEFORM_SUBTYPE_GUID_SECTION2);=0D + memcpy (&(SubtypeGuidSect2->SubTypeGuid), SubTypeGuid, sizeof (EFI_GUI= D));=0D + } else {=0D + SubtypeGuidSect =3D (EFI_FREEFORM_SUBTYPE_GUID_SECTION *) FileBuffer;= =0D + SubtypeGuidSect->CommonHeader.Type =3D EFI_SECTION_FREEFORM_SUBTYP= E_GUID;=0D + SubtypeGuidSect->CommonHeader.Size[0] =3D (UINT8) (TotalLength & 0xff= );=0D + SubtypeGuidSect->CommonHeader.Size[1] =3D (UINT8) ((TotalLength & 0xf= f00) >> 8);=0D + SubtypeGuidSect->CommonHeader.Size[2] =3D (UINT8) ((TotalLength & 0xf= f0000) >> 16);=0D + memcpy (&(SubtypeGuidSect->SubTypeGuid), SubTypeGuid, sizeof (EFI_GUID= ));=0D + }=0D +=0D + VerboseMsg ("the size of the created section file is %u bytes", (unsigne= d) TotalLength);=0D +=0D + //=0D + // Set OutFileBuffer=0D + //=0D + *OutFileBuffer =3D FileBuffer;=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D EFI_STATUS=0D FfsRebaseImageRead (=0D IN VOID *FileHandle,=0D @@ -1591,14 +1740,22 @@ Returns: }=0D =0D //=0D - // GuidValue is only required by Guided section.=0D + // GuidValue is only required by Guided section and SubtypeGuid section.= =0D //=0D - if ((SectType !=3D EFI_SECTION_GUID_DEFINED) &&=0D + if ((SectType !=3D EFI_SECTION_GUID_DEFINED) && (SectType !=3D EFI_SECTI= ON_FREEFORM_SUBTYPE_GUID) &&=0D (SectionName !=3D NULL) &&=0D (CompareGuid (&VendorGuid, &mZeroGuid) !=3D 0)) {=0D fprintf (stdout, "Warning: the input guid value is not required for th= is section type %s\n", SectionName);=0D }=0D =0D + //=0D + // Check whether there is GUID for the SubtypeGuid section=0D + //=0D + if ((SectType =3D=3D EFI_SECTION_FREEFORM_SUBTYPE_GUID) && (CompareGuid = (&VendorGuid, &mZeroGuid) =3D=3D 0)) {=0D + Error (NULL, 0, 1001, "Missing options", "GUID");=0D + goto Finish;=0D + }=0D +=0D //=0D // Check whether there is input file=0D //=0D @@ -1667,6 +1824,16 @@ Returns: );=0D break;=0D =0D + case EFI_SECTION_FREEFORM_SUBTYPE_GUID:=0D + Status =3D GenSectionSubtypeGuidSection (=0D + InputFileName,=0D + InputFileAlign,=0D + InputFileNum,=0D + &VendorGuid,=0D + &OutFileBuffer=0D + );=0D + break;=0D +=0D case EFI_SECTION_VERSION:=0D Index =3D sizeof (EFI_COMMON_SECTION_HEADER);=0D //=0D --=20 2.25.1