From patchwork Mon Dec 21 11:43:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 346407 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp4384690jai; Mon, 21 Dec 2020 03:44:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJzmqJ3bAuv4IzzOW8Kl03wKdgqQe5/ukgRrHAdK/yuT4y5HL5u+YA215HuyqqPjdqgTzRNf X-Received: by 2002:a17:906:b793:: with SMTP id dt19mr14928129ejb.120.1608551090652; Mon, 21 Dec 2020 03:44:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608551090; cv=none; d=google.com; s=arc-20160816; b=of6S59ohdUcZyBzImTdQyWqhLeTcS3Iv4jvNJ+6dgNuCXRe3rdnT6YkeJzsC2yx0eO Ur/tkBFziQMm9wqWZiWaprrbk0RGcG2N9MYuZV3TMeNFcX3xF+NYEaANhXXQkXy/BB4a G4UdjtrOPYdnqRCQQBjPJynKfr2y0qZx4we/sjt4NFBwHZPzsyijL0PBBpFITBtwBg4n 8neRxWzumFo7KGVzy7aGJs58UKRrZOJrL8XZ7C4CUK0i5ltV4yn+9yELU8pfRmOtUHxg ow3CyfEg4tjXSld66Hn1noODcBjJCFYmpbcTIAj5O/aTkvczeE5CKOXP0naydRFaLiGP +TCw== 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=wvCfsgR1rLmBsJ78facxQPPFwIALI1B9ZepyxGhtc+c=; b=pXeioKrGLDZIU1AWsn0gbJiexqKn4c3ZTY6ph0OcrAOzyTQq2BdUONdWaOLlEn0dnJ TIy94IuKL+aksVdnQ7bmjOWZFDYY9ousLyKDnxtmfwC+TS/r5Ot5VLKd6splQnbvSObC l9awNmTzaVyV48EEL4P+ZzsG3oj1h7SqIinZVWU0Ff3zi8jLmHCPVSjKJ98WM+06zhzD PEOoNyzbBgy5DnvEAFUmOD4kLMjsW2vb4R7pT4xQUuXwH0tmWqwzgpzPFuwmJd42Zu6k 4027uy1fu/2H5ybTkinB+bnGJOQZranEGobPfqadsG7t1NBovRGKaD0+IV/jnLYBUt8V Vv+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id bs24si10578094edb.519.2020.12.21.03.44.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Dec 2020 03:44:50 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 1AC4C82846; Mon, 21 Dec 2020 12:43:57 +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 CB4FD82829; Mon, 21 Dec 2020 12:43:51 +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 0744182804 for ; Mon, 21 Dec 2020 12:43:49 +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 5FF09101E; Mon, 21 Dec 2020 03:43:48 -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 BEB0E3F718; Mon, 21 Dec 2020 03:43:45 -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 v2 07/14] efi_loader: Add logic to parse EDKII specific fmp payload header Date: Mon, 21 Dec 2020 17:13:07 +0530 Message-Id: <20201221114314.25588-8-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201221114314.25588-1-sughosh.ganu@linaro.org> References: <20201221114314.25588-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 V1: * Detect the presence of the FMP Payload header at runtime instead of using a Kconfig option, as was suggested by Heinrich 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);