From patchwork Wed Dec 30 13:57:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 355261 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp11350964jai; Wed, 30 Dec 2020 05:59:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJw/V53BZwYPHGe96UnqteG8NDAbxgZ/KyY/RDOaw/9TdzRTLioi9bJrGw9roUx5+0UB/n5Y X-Received: by 2002:a17:907:36a:: with SMTP id rs10mr48713084ejb.411.1609336752600; Wed, 30 Dec 2020 05:59:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609336752; cv=none; d=google.com; s=arc-20160816; b=TDVgDXUystiSBKOSZbR7rhKngsqKZiZrKItJezVR6rMkk2MbRPmSR+9F00BNFBrSsq YIbyuTsd25m3DHIeZ3jlkSgklLlqw4aO931bFNDJutzBo+Wv2R/PggaB8xFqMNz+ACxX 9XLJh+0Ed7yo1eS4FdlPh+aqqVN22Gqv/+qKhwLVBE/awB1EPrNv+zdLSh4NdFk+naBr M8mHgUDo5cR8GG/wKXb3SglIK/taoLuQEepnjdQMLfD9D+5nPLu0Yd8RfH4/6eUHH1iF pl2TmcOEJJ0qQJrkP6ejWK0EakQk775JoLPDu5KSRUh2V1Bk9GFw925uJrSi5YJNfMMa ydeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from; bh=PEsBtrS1DG7QaZizVnjil+2DUU0uvfXMLbyVIx/jRXk=; b=b8zP/zuLHoT4skC152VMOSBD/6DydzYpuoRp67z9GLnQ5pylHrNXcP5hYWSZq9PrWk 7HiqWeBghH/tCHTP3SeSWf0wau7MOoSIqMJRUXU0gxPrMhrFCOsmjZjMAZLgOgTmEeLE b/7Q5WVe1YFZxMMCE/jaor51WXSJZdaRZUIKbNwFniOwbXgeyHWv6fadnMUJ8nPxupEc P9Y4Ep74ovns288iwQgpIY2F6LKFFYrZEUttHtpgMAKmeQqq0dE8dSyBQeIaWN194d34 Jf4intALIc535xVHYiUZVrxCu63JDm6RUO3SqncTgEX+s+zZmHj3YsZ4tbc8WY/l8J5w oQyg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id o20si9514742edi.262.2020.12.30.05.59.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 05:59:12 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3C0CE82636; Wed, 30 Dec 2020 14:58:22 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 6E49682623; Wed, 30 Dec 2020 14:58:00 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 7246682607 for ; Wed, 30 Dec 2020 14:57:56 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 25F2A1477; Wed, 30 Dec 2020 05:57:53 -0800 (PST) Received: from a076522.blr.arm.com (a076522.blr.arm.com [10.162.16.44]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 832773F6CF; Wed, 30 Dec 2020 05:57:50 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Takahiro Akashi , Heinrich Schuchardt , Alexander Graf , Lukasz Majewski , Tuomas Tynkkynen , Tom Rini , Ilias Apalodimas , Sughosh Ganu Subject: [PATCH v4 07/14] efi_loader: Add logic to parse EDKII specific fmp payload header Date: Wed, 30 Dec 2020 19:27:05 +0530 Message-Id: <20201230135712.5289-8-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201230135712.5289-1-sughosh.ganu@linaro.org> References: <20201230135712.5289-1-sughosh.ganu@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean When building the capsule using scripts in edk2, a fmp header is added on top of the binary payload. Add logic to detect presence of the header. When present, the pointer to the image needs to be adjusted as per the size of the header to point to the actual binary payload. Signed-off-by: Sughosh Ganu --- Changes since V3: None lib/efi_loader/efi_firmware.c | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) -- 2.17.1 diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index 72c560dbc2..5d2ecde2f1 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -11,8 +11,30 @@ #include #include #include +#include + #include +#define FMP_PAYLOAD_HDR_SIGNATURE SIGNATURE_32('M', 'S', 'S', '1') + +/** + * struct fmp_payload_header - EDK2 header for the FMP payload + * + * This structure describes the header which is preprended to the + * FMP payload by the edk2 capsule generation scripts. + * + * @signature: Header signature used to identify the header + * @header_size: Size of the structure + * @fw_version: Firmware versions used + * @lowest_supported_version: Lowest supported version + */ +struct fmp_payload_header { + u32 signature; + u32 header_size; + u32 fw_version; + u32 lowest_supported_version; +}; + /* Place holder; not supported */ static efi_status_t EFIAPI efi_firmware_get_image_unsupported( @@ -379,12 +401,31 @@ efi_status_t EFIAPI efi_firmware_raw_set_image( efi_status_t (*progress)(efi_uintn_t completion), u16 **abort_reason) { + u32 fmp_hdr_signature; + struct fmp_payload_header *header; + EFI_ENTRY("%p %d %p %ld %p %p %p\n", this, image_index, image, image_size, vendor_code, progress, abort_reason); if (!image) return EFI_EXIT(EFI_INVALID_PARAMETER); + fmp_hdr_signature = FMP_PAYLOAD_HDR_SIGNATURE; + header = (void *)image; + + if (!memcmp(&header->signature, &fmp_hdr_signature, + sizeof(fmp_hdr_signature))) { + /* + * When building the capsule with the scripts in + * edk2, a FMP header is inserted above the capsule + * payload. Compensate for this header to get the + * actual payload that is to be updated. + */ + image += header->header_size; + image_size -= header->header_size; + + } + if (dfu_write_by_alt(image_index - 1, (void *)image, image_size, NULL, NULL)) return EFI_EXIT(EFI_DEVICE_ERROR);