From patchwork Fri Apr 1 19:17:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 555587 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1248:0:0:0:0 with SMTP id z8csp1820829mag; Fri, 1 Apr 2022 12:19:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx56mBdKgpq73fbQ2IkUnhcN0FBKqRo8+s2hfKHy6mZZaK8jyW+qCCNObU9rJOzLvGFHIa5 X-Received: by 2002:a17:907:1624:b0:6db:8caa:d71 with SMTP id hb36-20020a170907162400b006db8caa0d71mr1119143ejc.723.1648840756313; Fri, 01 Apr 2022 12:19:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648840756; cv=none; d=google.com; s=arc-20160816; b=nYpieGSRqsviyruBs8kVaM2PmcJI83hHqCCkmWCER89J8QI3A+mJ+Jvehbw3iQ+NJ4 SiY4i7D+kjr9mCCEG6SOYu5OB1ouRpqqUu1OtyUyv0J7cTHpCenWbA15XdP4NBH3StXi IRfOIiLBGekiNwyTDz+dYbt3tg9rnL4THpfQAMmBoWOdPAC26RAlhsdUBr7NOETLtp29 1VCxVjb/orAJA0xbiaXsXGgtj1tu63t7UAij/LbPLp5VYD+oPfOUK7GZmCRkDJV6/jd1 7AWByn9XoDzdQKavSLLdjw/9mhHBPUwiOk6VUUSWOayjxSDncnw9Juuz4ItY1Ve0N/7B iJvA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=8peH+w5ekWq/R42CskSt9UEahRQnwwFzpShwJLfTKfE=; b=UMaQ0DYqvpZryrd3Sz4nrWmRuHJ+RIcKh+M1jDf5MrOtkUTQdOHhsAWGAkUGzUks5j hD8EcwMbUt3dCLNsjNLXhOb0MSJsLnjfNKrsWU9O5ly8EeMnHeAP+wseeDt7y8IC3QoV RTuEx8jjE9zWzxCCATlTQkAi754YfVxmMqJu0hPPwQD/7VlW5V2TCxRz4QnyY/LcUw/F kfL0xl2GW/bazBWD5ivvXjf74PT0tY4tVLuXRI+tg0sTyEZ0qVDmjwnFwVNg33DL2fP6 kX4j6raFy5IEhaAW7PkLzf+H3PL7LmBupV5k2/P+RtW8qHeSobKxWMkV7Vs4RpCiZJy0 5+vg== 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 lc4-20020a170906dfe400b006e4aede00bdsi2092393ejc.667.2022.04.01.12.19.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Apr 2022 12:19:16 -0700 (PDT) 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 2C4DD8431B; Fri, 1 Apr 2022 21:18:47 +0200 (CEST) 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 139CA8433A; Fri, 1 Apr 2022 21:18:45 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no 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 AB8708431B for ; Fri, 1 Apr 2022 21:18:39 +0200 (CEST) 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 E221715DB; Fri, 1 Apr 2022 12:18:38 -0700 (PDT) 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 309523F73B; Fri, 1 Apr 2022 12:18:34 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , AKASHI Takahiro , Ying-Chun Liu , Tuomas Tynkkynen , Heiko Thiery , Frieder Schrempf , Michael Walle , Masami Hiramatsu , Jassi Brar , Michal Simek , Michal Simek , Sughosh Ganu Subject: [PATCH v5 4/8] efi: Define set_dfu_alt_info() for boards with UEFI capsule update enabled Date: Sat, 2 Apr 2022 00:47:55 +0530 Message-Id: <20220401191759.1670812-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220401191759.1670812-1-sughosh.ganu@linaro.org> References: <20220401191759.1670812-1-sughosh.ganu@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.5 at phobos.denx.de X-Virus-Status: Clean Currently, there are a bunch of boards which enable the UEFI capsule update feature. The actual update of the firmware images is done through the dfu framework which uses the dfu_alt_info environment variable for getting information on the update, like device, partition number/address etc. The dfu framework allows the variable to be set through the set_dfu_alt_info function defined by the platform, or if the function is not defined, it gets the variable from the environment. Using the value set in the environment is not very robust, since the variable can be modified from the u-boot command line and this can cause an incorrect update. To prevent this from happening, define the set_dfu_alt_info function when the capsule update feature is enabled. A weak function is defined which sets the dfu_alt_info environment variable by getting the string for the variable from the platform. Signed-off-by: Sughosh Ganu --- Changes since V4: * Define a weak function set_dfu_alt_info for setting the variable in a non board specific file as suggested by Ilias * Drop the definitions of set_dfu_alt_info that were being added in the board files lib/efi_loader/Kconfig | 2 ++ lib/efi_loader/efi_firmware.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index e5e35fe51f..09fb8cbe75 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -174,6 +174,7 @@ config EFI_CAPSULE_FIRMWARE_FIT depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT select UPDATE_FIT select DFU + select SET_DFU_ALT_INFO select EFI_CAPSULE_FIRMWARE help Select this option if you want to enable firmware management protocol @@ -185,6 +186,7 @@ config EFI_CAPSULE_FIRMWARE_RAW depends on SANDBOX || (!SANDBOX && !EFI_CAPSULE_FIRMWARE_FIT) select DFU_WRITE_ALT select DFU + select SET_DFU_ALT_INFO select EFI_CAPSULE_FIRMWARE help Select this option if you want to enable firmware management protocol diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index e9fc4b9c1e..cbfa57f64f 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -11,9 +11,11 @@ #include #include #include +#include #include #include +#include #define FMP_PAYLOAD_HDR_SIGNATURE SIGNATURE_32('M', 'S', 'S', '1') @@ -35,6 +37,27 @@ struct fmp_payload_header { u32 lowest_supported_version; }; +#define DFU_ALT_BUF_LEN SZ_1K + +__weak void set_dfu_alt_info(char *interface, char *devstr) +{ + int n; + const char *dfu_alt_info; + ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN); + + if (!CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT) && + env_get("dfu_alt_info")) + return; + + dfu_alt_info = update_info.dfu_string; + n = strlen(dfu_alt_info); + memset(buf, 0, n + 1); + + strncpy(buf, dfu_alt_info, n); + + env_set("dfu_alt_info", buf); +} + /* Place holder; not supported */ static efi_status_t EFIAPI efi_firmware_get_image_unsupported(