From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::243; helo=mail-wr0-x243.google.com; envelope-from=sigmaepsilon92@gmail.com; receiver=edk2-devel@lists.01.org Received: from mail-wr0-x243.google.com (mail-wr0-x243.google.com [IPv6:2a00:1450:400c:c0c::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4EED420945B6A for ; Mon, 11 Dec 2017 22:47:44 -0800 (PST) Received: by mail-wr0-x243.google.com with SMTP id q9so19938192wre.7 for ; Mon, 11 Dec 2017 22:52:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=DOpaNJ5U1K62T24xTfxct4IEnuL8GUrcOWG3VunBFS0=; b=mBBAVzW9uWDUZBWCKV+fN+Baec0Vn2OgrEkHu3Gaxx6OYeONxVDn7vDP1YCjKr9y9E DM+jX7z36n+kQ7krHNgDBsasEq6JVWsuKFcaKMocTVyVGyMvCEpwabIha/lRnR9MTUth 3csu0kIg10B0YFzewk0JgPkPjQnQ7SfaKW6swNZ1ZeHL6dbjqK+Iz1EWWYvveUXfphB7 XZGaun/Ar3SP8VxjsLJcamgRm6XV1KfdRqJ03jE2HDkcssl07H+Qw+urbNaKpz6BpEtV f1rj3F33Oy4XbmEnEEQR2tZZMNkJuOpSyAhA9cs9tIzRGnQ2IQ/+lC85FUSpfVIp6T5F mA5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=DOpaNJ5U1K62T24xTfxct4IEnuL8GUrcOWG3VunBFS0=; b=RJDxXo/Oo1czCumr0YeFCHHpslkiLTjcjdvgGlPW4N/7Jg/tDG0q9pVKlP7qGgqScw iJW7dFsNGk15LXBN9+iydvinWu34lT8S1j4z9uCX0sm0aPKd78Omyf/v7Xuc8W0upeZ9 Y1nvEGayxWkccTk0jTz80LDe7Sztwt3BoQFG5M+1/fl/3nG+4ThVAe0S8yW8118T6dIw 6hv18sQTj+fXEXJRjTBfFv661wqqHduIecrf3BGdMoWKgx/N7XOdjOZJWcN3EZT8/5U0 U7xtryZJNISTN9lod7sNFudtU6wvRHBusFBZDn/HqjSGo7FlE7OQf415hrKhq+NUTEky 6zgw== X-Gm-Message-State: AKGB3mJyHo0U9xNTSoGT/SCe4sILyX9n8P/Q/MNeVzM5e0mKuYOTFrf7 Z4jR8dmTY2Maub4LFUsZqljpYX6L X-Google-Smtp-Source: ACJfBotUVm5y6RDIqXPshEKoIbC+l9lvFSoln6f3Sl5EqeVQI5EJqUTZIrULcBoUT2GMPT3GmpJY8Q== X-Received: by 10.223.136.164 with SMTP id f33mr2628412wrf.162.1513061540825; Mon, 11 Dec 2017 22:52:20 -0800 (PST) Received: from localhost.localdomain ([2a02:908:5a9:8400:5ec8:3210:9b68:c91c]) by smtp.gmail.com with ESMTPSA id x142sm11550016wme.34.2017.12.11.22.52.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Dec 2017 22:52:20 -0800 (PST) From: M1cha To: edk2-devel@lists.01.org Cc: Ard Biesheuvel , Leif Lindholm Date: Tue, 12 Dec 2017 07:52:19 +0100 Message-Id: <20171212065219.11843-1-sigmaepsilon92@gmail.com> X-Mailer: git-send-email 2.15.1 Subject: [PATCH] EmbeddedPkg/PrePiLib: add support for v2 sections X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Dec 2017 06:47:44 -0000 From: Michael Zimmermann Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Michael Zimmermann --- EmbeddedPkg/Library/PrePiLib/FwVol.c | 61 ++++++++++++++++---- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/EmbeddedPkg/Library/PrePiLib/FwVol.c b/EmbeddedPkg/Library/PrePiLib/FwVol.c index 530fc15dca1c..d513de351ff5 100644 --- a/EmbeddedPkg/Library/PrePiLib/FwVol.c +++ b/EmbeddedPkg/Library/PrePiLib/FwVol.c @@ -296,35 +296,61 @@ FfsProcessSection ( UINT32 SectionLength; UINT32 ParsedLength; EFI_COMPRESSION_SECTION *CompressionSection; + EFI_COMPRESSION_SECTION2 *CompressionSection2; UINT32 DstBufferSize; VOID *ScratchBuffer; UINT32 ScratchBufferSize; VOID *DstBuffer; UINT16 SectionAttribute; UINT32 AuthenticationStatus; + CHAR8 *CompressedData; + UINTN CompressedDataLength; *OutputBuffer = NULL; ParsedLength = 0; Status = EFI_NOT_FOUND; while (ParsedLength < SectionSize) { + if (IS_SECTION2 (Section)) { + ASSERT (SECTION2_SIZE (Section) > 0x00FFFFFF); + } + if (Section->Type == SectionType) { - *OutputBuffer = (VOID *)(Section + 1); + if (IS_SECTION2 (Section)) { + *OutputBuffer = (VOID *)((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER2)); + } else { + *OutputBuffer = (VOID *)((UINT8 *) Section + sizeof (EFI_COMMON_SECTION_HEADER)); + } return EFI_SUCCESS; } else if ((Section->Type == EFI_SECTION_COMPRESSION) || (Section->Type == EFI_SECTION_GUID_DEFINED)) { if (Section->Type == EFI_SECTION_COMPRESSION) { - CompressionSection = (EFI_COMPRESSION_SECTION *) Section; - SectionLength = *(UINT32 *)Section->Size & 0x00FFFFFF; + if (IS_SECTION2 (Section)) { + CompressionSection2 = (EFI_COMPRESSION_SECTION2 *) Section; + SectionLength = SECTION2_SIZE (Section); - if (CompressionSection->CompressionType != EFI_STANDARD_COMPRESSION) { - return EFI_UNSUPPORTED; + if (CompressionSection2->CompressionType != EFI_STANDARD_COMPRESSION) { + return EFI_UNSUPPORTED; + } + + CompressedData = (CHAR8 *) ((EFI_COMPRESSION_SECTION2 *) Section + 1); + CompressedDataLength = (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION2); + } else { + CompressionSection = (EFI_COMPRESSION_SECTION *) Section; + SectionLength = SECTION_SIZE (Section); + + if (CompressionSection->CompressionType != EFI_STANDARD_COMPRESSION) { + return EFI_UNSUPPORTED; + } + + CompressedData = (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1); + CompressedDataLength = (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION); } Status = UefiDecompressGetInfo ( - (UINT8 *) ((EFI_COMPRESSION_SECTION *) Section + 1), - (UINT32) SectionLength - sizeof (EFI_COMPRESSION_SECTION), + CompressedData, + CompressedDataLength, &DstBufferSize, &ScratchBufferSize ); @@ -362,13 +388,23 @@ FfsProcessSection ( // DstBuffer still is one section. Adjust DstBuffer offset, skip EFI section header // to make section data at page alignment. // - DstBuffer = (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER); + if (IS_SECTION2 (Section)) + DstBuffer = (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER2); + else + DstBuffer = (UINT8 *)DstBuffer + EFI_PAGE_SIZE - sizeof (EFI_COMMON_SECTION_HEADER); // // Call decompress function // if (Section->Type == EFI_SECTION_COMPRESSION) { + if (IS_SECTION2 (Section)) { + CompressedData = (CHAR8 *) ((EFI_COMPRESSION_SECTION2 *) Section + 1); + } + else { + CompressedData = (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1); + } + Status = UefiDecompress ( - (CHAR8 *) ((EFI_COMPRESSION_SECTION *) Section + 1), + CompressedData, DstBuffer, ScratchBuffer ); @@ -397,12 +433,15 @@ FfsProcessSection ( } } + if (IS_SECTION2 (Section)) { + SectionLength = SECTION2_SIZE (Section); + } else { + SectionLength = SECTION_SIZE (Section); + } // - // Size is 24 bits wide so mask upper 8 bits. // SectionLength is adjusted it is 4 byte aligned. // Go to the next section // - SectionLength = *(UINT32 *)Section->Size & 0x00FFFFFF; SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4); ASSERT (SectionLength != 0); ParsedLength += SectionLength; -- 2.15.1