From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web09.37546.1639553126669298952 for ; Tue, 14 Dec 2021 23:25:27 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jJA/YJLU; spf=pass (domain: kernel.org, ip: 145.40.68.75, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9C002B81B3D for ; Wed, 15 Dec 2021 07:25:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D794C34608 for ; Wed, 15 Dec 2021 07:25:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1639553123; bh=fjGo83r3zIIeJ5ROmCWvY0p+qTy3rKs1IYx0zY2/XAY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=jJA/YJLU+MMit9dTee+6mzxaFVzDhUxJ+6XUSpbhcCCBuQPu5xHhbVvU6SIOX7U6K UGtb864PwHu0VDx55CgI9ZBm3vfUSzhn89c9B5mILwXMjmLnJ/YQqpuoAgII0gu2L2 e8rNRV2SulPwejYjAvJyJ0Mcesczy+Imw+xSsgzIu2c9VNTxe227jUm+HKJ4ERn/uL +AsDkprGH4ZJxVcMjnrD5TrFxF3x6nU9DUceTmiI8IGusxyiemJ1AMDqHP8uuM+dAd XShnxDt8W2SwSifMIKGJVf497lk3Q34c+T2q0Vf0KbhPljRIMeWwFqwFkIGxfbfdXv QvPl1JabuhhSA== Received: by mail-wr1-f47.google.com with SMTP id i22so6699816wrb.13 for ; Tue, 14 Dec 2021 23:25:23 -0800 (PST) X-Gm-Message-State: AOAM532MY9uLfcO505k3+6HDiAhIq0FXWJF9tyWAVJQmVnldpA1OJ2jG 0WQ8qipF+YW1mUsx/dCThGh7ZAxcLgCUA/QaVcI= X-Google-Smtp-Source: ABdhPJxQCqmnsxW3Dco6PmKOV4UrEEviiMzWa8RKOhKPAC3TIWnl9BtlTnZucGjCXheGAcXFo/DSH4BpDFE+F3ocbSw= X-Received: by 2002:adf:d18f:: with SMTP id v15mr3095353wrc.447.1639553121660; Tue, 14 Dec 2021 23:25:21 -0800 (PST) MIME-Version: 1.0 References: <20211209065133.7748-1-wei6.xu@intel.com> <020301d7f176$ffc51520$ff4f3f60$@byosoft.com.cn> In-Reply-To: <020301d7f176$ffc51520$ff4f3f60$@byosoft.com.cn> From: "Ard Biesheuvel" Date: Wed, 15 Dec 2021 08:25:10 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [edk2-devel][Patch] StandaloneMmPkg/FvLib: Support large file with EFI_FFS_FILE_HEADER2. To: edk2-devel-groups-io , "Liming Gao (Byosoft address)" Cc: Wei6 Xu , Ard Biesheuvel , Sami Mujawar , Jiewen Yao , Supreeth Venkatesh Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, 15 Dec 2021 at 06:46, gaoliming wrote: > > Reviewed-by: Liming Gao > Merged as #2307 Thanks, > > -----=E9=82=AE=E4=BB=B6=E5=8E=9F=E4=BB=B6----- > > =E5=8F=91=E4=BB=B6=E4=BA=BA: devel@edk2.groups.io =E4=BB=A3=E8=A1=A8 Xu, Wei6 > > =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2021=E5=B9=B412=E6=9C=889=E6=97= =A5 14:52 > > =E6=94=B6=E4=BB=B6=E4=BA=BA: devel@edk2.groups.io > > =E6=8A=84=E9=80=81: Ard Biesheuvel ; Sami Mu= jawar > > ; Jiewen Yao ; Supreeth > > Venkatesh ; Liming Gao > > > > =E4=B8=BB=E9=A2=98: [edk2-devel][Patch] StandaloneMmPkg/FvLib: Support = large file with > > EFI_FFS_FILE_HEADER2. > > > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3769 > > > > Current FvLib will hit parse issue when encountering LARGE file, then > > ignore latter ffs/section, thus causing required drivers not being > > dispatched. Therefore, need to add support for EFI_FFS_FILE_HEADER2 > > and EFI_COMMON_SECTION_HEADER2 in FvLib to fix this issue. > > > > Cc: Ard Biesheuvel > > Cc: Sami Mujawar > > Cc: Jiewen Yao > > Cc: Supreeth Venkatesh > > Cc: Liming Gao > > Signed-off-by: Wei6 Xu > > --- > > StandaloneMmPkg/Library/FvLib/FvLib.c | 65 > > ++++++++++++++++++++++++----------- > > 1 file changed, 45 insertions(+), 20 deletions(-) > > > > diff --git a/StandaloneMmPkg/Library/FvLib/FvLib.c > > b/StandaloneMmPkg/Library/FvLib/FvLib.c > > index aa36a35eff..89504b9ee9 100644 > > --- a/StandaloneMmPkg/Library/FvLib/FvLib.c > > +++ b/StandaloneMmPkg/Library/FvLib/FvLib.c > > @@ -1,8 +1,8 @@ > > /** @file > > > > -Copyright (c) 2015, Intel Corporation. All rights reserved.
> > +Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.
> > Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.
> > > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > **/ > > @@ -61,22 +61,24 @@ CalculateHeaderChecksum ( > > ) > > { > > UINT8 *ptr; > > UINTN Index; > > UINT8 Sum; > > + UINTN Size; > > > > - Sum =3D 0; > > - ptr =3D (UINT8 *)FileHeader; > > + Sum =3D 0; > > + ptr =3D (UINT8 *)FileHeader; > > + Size =3D IS_FFS_FILE2 (FileHeader) ? sizeof (EFI_FFS_FILE_HEADER2) : > sizeof > > (EFI_FFS_FILE_HEADER); > > > > - for (Index =3D 0; Index < sizeof (EFI_FFS_FILE_HEADER) - 3; Index += =3D 4) { > > + for (Index =3D 0; Index < Size - 3; Index +=3D 4) { > > Sum =3D (UINT8)(Sum + ptr[Index]); > > Sum =3D (UINT8)(Sum + ptr[Index + 1]); > > Sum =3D (UINT8)(Sum + ptr[Index + 2]); > > Sum =3D (UINT8)(Sum + ptr[Index + 3]); > > } > > > > - for ( ; Index < sizeof (EFI_FFS_FILE_HEADER); Index++) { > > + for ( ; Index < Size; Index++) { > > Sum =3D (UINT8)(Sum + ptr[Index]); > > } > > > > // > > // State field (since this indicates the different state of file). > > @@ -155,11 +157,12 @@ FfsFindNextFile ( > > } else { > > // > > // Length is 24 bits wide so mask upper 8 bits > > // FileLength is adjusted to FileOccupiedSize as it is 8 byte > aligned. > > // > > - FileLength =3D FFS_FILE_SIZE (*FileHeader); > > + FileLength =3D IS_FFS_FILE2 (*FileHeader) ? > > + FFS_FILE2_SIZE (*FileHeader) : FFS_FILE_SIZE > > (*FileHeader); > > FileOccupiedSize =3D GET_OCCUPIED_SIZE (FileLength, 8); > > FfsFileHeader =3D (EFI_FFS_FILE_HEADER *)((UINT8 *)*FileHeader = + > > FileOccupiedSize); > > } > > > > FileOffset =3D (UINT32)((UINT8 *)FfsFileHeader - (UINT8 *)FwVolHeade= r); > > @@ -170,18 +173,25 @@ FfsFindNextFile ( > > // > > FileState =3D GetFileState (ErasePolarity, FfsFileHeader); > > > > switch (FileState) { > > case EFI_FILE_HEADER_INVALID: > > - FileOffset +=3D sizeof (EFI_FFS_FILE_HEADER); > > - FfsFileHeader =3D (EFI_FFS_FILE_HEADER *)((UINT8 *)FfsFileHead= er > > + sizeof (EFI_FFS_FILE_HEADER)); > > + if (IS_FFS_FILE2 (FfsFileHeader)) { > > + FileOffset +=3D sizeof (EFI_FFS_FILE_HEADER2); > > + FfsFileHeader =3D (EFI_FFS_FILE_HEADER *)((UINT8 > > *)FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER2)); > > + } else { > > + FileOffset +=3D sizeof (EFI_FFS_FILE_HEADER); > > + FfsFileHeader =3D (EFI_FFS_FILE_HEADER *)((UINT8 > > *)FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER)); > > + } > > + > > break; > > > > case EFI_FILE_DATA_VALID: > > case EFI_FILE_MARKED_FOR_UPDATE: > > if (CalculateHeaderChecksum (FfsFileHeader) =3D=3D 0) { > > - FileLength =3D FFS_FILE_SIZE (FfsFileHeader); > > + FileLength =3D IS_FFS_FILE2 (FfsFileHeader) ? > > + FFS_FILE2_SIZE (FfsFileHeader) : FFS_FILE_SIZE > > (FfsFileHeader); > > FileOccupiedSize =3D GET_OCCUPIED_SIZE (FileLength, 8); > > > > if ((SearchType =3D=3D FfsFileHeader->Type) || (SearchType = =3D=3D > > EFI_FV_FILETYPE_ALL)) { > > *FileHeader =3D FfsFileHeader; > > > > @@ -195,11 +205,12 @@ FfsFindNextFile ( > > } > > > > break; > > > > case EFI_FILE_DELETED: > > - FileLength =3D FFS_FILE_SIZE (FfsFileHeader); > > + FileLength =3D IS_FFS_FILE2 (FfsFileHeader) ? > > + FFS_FILE2_SIZE (FfsFileHeader) : FFS_FILE_SIZE > > (FfsFileHeader); > > FileOccupiedSize =3D GET_OCCUPIED_SIZE (FileLength, 8); > > FileOffset +=3D FileOccupiedSize; > > FfsFileHeader =3D (EFI_FFS_FILE_HEADER *)((UINT8 > > *)FfsFileHeader + FileOccupiedSize); > > break; > > > > @@ -251,11 +262,11 @@ FindFfsSectionInSections ( > > > > CurrentAddress =3D EndOfSection; > > > > Section =3D (EFI_COMMON_SECTION_HEADER > > *)(UINTN)CurrentAddress; > > > > - Size =3D SECTION_SIZE (Section); > > + Size =3D IS_SECTION2 (Section) ? SECTION2_SIZE (Section) : > > SECTION_SIZE (Section); > > if (Size < sizeof (*Section)) { > > return EFI_VOLUME_CORRUPTED; > > } > > > > EndOfSection =3D CurrentAddress + Size; > > @@ -304,13 +315,17 @@ FfsFindSection ( > > // > > // Size is 24 bits wide so mask upper 8 bits. > > // Does not include FfsFileHeader header size > > // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned. > > // > > - Section =3D (EFI_COMMON_SECTION_HEADER *)(FfsFileHeader + 1); > > - FileSize =3D FFS_FILE_SIZE (FfsFileHeader); > > - FileSize -=3D sizeof (EFI_FFS_FILE_HEADER); > > + if (IS_FFS_FILE2 (FfsFileHeader)) { > > + Section =3D (EFI_COMMON_SECTION_HEADER > > *)((EFI_FFS_FILE_HEADER2 *)FfsFileHeader + 1); > > + FileSize =3D FFS_FILE2_SIZE (FfsFileHeader) - sizeof > > (EFI_FFS_FILE_HEADER2); > > + } else { > > + Section =3D (EFI_COMMON_SECTION_HEADER *)(FfsFileHeader + 1); > > + FileSize =3D FFS_FILE_SIZE (FfsFileHeader) - sizeof > > (EFI_FFS_FILE_HEADER); > > + } > > > > Status =3D FindFfsSectionInSections ( > > Section, > > FileSize, > > SectionType, > > @@ -349,29 +364,39 @@ FfsFindSectionData ( > > // > > // Size is 24 bits wide so mask upper 8 bits. > > // Does not include FfsFileHeader header size > > // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned. > > // > > - Section =3D (EFI_COMMON_SECTION_HEADER *)(FfsFileHeader + 1); > > - FileSize =3D FFS_FILE_SIZE (FfsFileHeader); > > - FileSize -=3D sizeof (EFI_FFS_FILE_HEADER); > > + if (IS_FFS_FILE2 (FfsFileHeader)) { > > + Section =3D (EFI_COMMON_SECTION_HEADER > > *)((EFI_FFS_FILE_HEADER2 *)FfsFileHeader + 1); > > + FileSize =3D FFS_FILE2_SIZE (FfsFileHeader) - sizeof > > (EFI_FFS_FILE_HEADER2); > > + } else { > > + Section =3D (EFI_COMMON_SECTION_HEADER *)(FfsFileHeader + 1); > > + FileSize =3D FFS_FILE_SIZE (FfsFileHeader) - sizeof > > (EFI_FFS_FILE_HEADER); > > + } > > > > *SectionData =3D NULL; > > ParsedLength =3D 0; > > while (ParsedLength < FileSize) { > > if (Section->Type =3D=3D SectionType) { > > - *SectionData =3D (VOID *)(Section + 1); > > - *SectionDataSize =3D SECTION_SIZE (Section); > > + if (IS_SECTION2 (Section)) { > > + *SectionData =3D (VOID > > *)((EFI_COMMON_SECTION_HEADER2 *)Section + 1); > > + *SectionDataSize =3D SECTION2_SIZE (Section); > > + } else { > > + *SectionData =3D (VOID *)(Section + 1); > > + *SectionDataSize =3D SECTION_SIZE (Section); > > + } > > + > > return EFI_SUCCESS; > > } > > > > // > > // Size is 24 bits wide so mask upper 8 bits. > > // SectionLength is adjusted it is 4 byte aligned. > > // Go to the next section > > // > > - SectionLength =3D SECTION_SIZE (Section); > > + SectionLength =3D IS_SECTION2 (Section) ? SECTION2_SIZE (Section) = : > > SECTION_SIZE (Section); > > SectionLength =3D GET_OCCUPIED_SIZE (SectionLength, 4); > > > > ParsedLength +=3D SectionLength; > > Section =3D (EFI_COMMON_SECTION_HEADER *)((UINT8 > > *)Section + SectionLength); > > } > > -- > > 2.16.2.windows.1 > > > > > > > > > > > > > > > >=20 > >