From patchwork Tue Feb 22 00:58:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 544882 Delivered-To: patch@linaro.org Received: by 2002:ac0:e142:0:0:0:0:0 with SMTP id r2csp3656232imn; Mon, 21 Feb 2022 16:57:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJxpoBwjKZ/APu5FY9Pqwmmwo9nBM7sq7SrrzZqpuqpFpbqdOGhI1TkMbBhQKwXFmpd/nhCs X-Received: by 2002:a05:6402:3583:b0:410:a99b:59ee with SMTP id y3-20020a056402358300b00410a99b59eemr24286322edc.454.1645491450732; Mon, 21 Feb 2022 16:57:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645491450; cv=none; d=google.com; s=arc-20160816; b=d+N4ujiUSyteRo504sLbCM97xyoXSThWDLZIkbn+binbFldYKLkDaq/TPAYJ9dNRgU msDELV8WjPWXNbnaJGkw1HCHHU3zFWeIiIYPwv7efpm7GU6tGmWXM7AHXxBiYu1QcWDs Mt0DK3bjwVQkFJK0flUGYs1thYK/9TrTDo+nPa9WacbvJ9SgxZClmFhlxZY7R4K/HpYv yI3FGjWemj4q2YJcvgi4FilmIeaVqVpVKZSOy4J36ZapFZ3pVs/jN+thMJcdaQA3+mVv Yx/GwvOwnGeE3ag3Mwly7xGEdESSa/fJ5U+z1tRUU9jJfKJ+psVDL43cKRvOikFNH+u8 Q5Zw== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=m4sCkn9xCwjjmIjL+mY/dcTTzt2W+N9O12S/SgTXa/A=; b=M6fWnw7Ze9VSWdGrzQSjjMfgjsDtN41Rj1WsoUd5zvoHst9OdXSAIRWPUU87CrlYrp HpZeBSixe9G2/CDhSTPSyaSfU1zXAKAB0GJQqu25uuZqIKukp7dj4YMnPvp/NvyZCxS5 mlt7gxQgNFSEEY7ZlixoP9Jeroaljx9TShLV1S+GOFJO26Lg6K99LYxduNcX9A++1qKl tYQrfKwpRfWf2H1rQnByRhXh4eyRHUIehfXn2o+XUdzme6PGlESIhdrfiy4lIPvJNh7Y 2ZC4OSqo4e0tNXJVdidXHoVh3Z+6yiUC/M1tWQDyix5RX7jhUc4pzDGA2juvg7i1u3yX 7ouA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uNNd+5Uo; 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=pass (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 gb3si11158630ejc.441.2022.02.21.16.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 16:57:30 -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; dkim=pass header.i=@linaro.org header.s=google header.b=uNNd+5Uo; 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=pass (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 855FD839EB; Tue, 22 Feb 2022 01:57:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="uNNd+5Uo"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 41733837C7; Tue, 22 Feb 2022 01:57:24 +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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BF2F8837C7 for ; Tue, 22 Feb 2022 01:57:20 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x62f.google.com with SMTP id q11so4403684pln.11 for ; Mon, 21 Feb 2022 16:57:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=m4sCkn9xCwjjmIjL+mY/dcTTzt2W+N9O12S/SgTXa/A=; b=uNNd+5Uo7LZSW0tyM1C1UvgpV6IdGS/Ma29kHphhAMFqeaZEdjKJZZIj7orCaYKdVH 8QXlTF97wwu30ZWhid2TdrxHRBCt5j+kkZTu8lGj31oJLWKnYSXE0d/VrzJFvGyAj3Hj 6rn37JtOzYrylubRvF2IYzzXxeWPUXj4AR9orbeO1uRuy58AXoBMoAY7zH2IK8IIkcPq YRijM3o7kWGGHiXjiPdlFrTbwAp9XFi3+qMYYwZkjtB4AkYxxJrJu9kXUk67Hn1AuPei ZvWIYOGsXM72uQHO9xSXHcYA6YWjgIiT7qOZwK68cdxc62y17Za9WIlRpvOgdsQhJqBS F9Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=m4sCkn9xCwjjmIjL+mY/dcTTzt2W+N9O12S/SgTXa/A=; b=3VqTGVnWmDtm1B3PdzYRlyYfc2Lwn6JmislltGsTgg50Xvm4UWfuC2YLQbW62j9X/r Y2L0KTn/79TnczQAbpqP8AVLVV5ZBcYN70Qi4hTexxbH4yYPJgbyE3/gJCjXZSpiPUNL LX5mVtksqY1iR/M3u6prkAe+rRXQqRHvSgsd3l6+3UmFH9SXUIpdRpnm8k5EIQPXPd3o 0L89JbgJcpvckUqxt5jVx27Xj1bBheCiAlZDROSHgnjILTCfd7pfkuplRJ3OtPa39JJ6 wKRhJVyxGyC/vULpaEwq2LiluEbFNH+H0zvQmPauRkK9TsXe7leQVagdz9EEPf/EBGEJ IIHw== X-Gm-Message-State: AOAM531+VzQojCtbB3qklJ72gjZO/7gDsHnK/FIu8NDrjGA2jOHkVgJX nU6OwsbFVQVONkQukCHVRa3nwkEbyi3z2Q== X-Received: by 2002:a17:902:b485:b0:14d:77eb:1675 with SMTP id y5-20020a170902b48500b0014d77eb1675mr20827910plr.147.1645491438942; Mon, 21 Feb 2022 16:57:18 -0800 (PST) Received: from localhost.localdomain ([2400:2411:502:a100:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id k8sm19444278pgc.89.2022.02.21.16.57.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 16:57:18 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH] efi_loader: update the timing of enabling and disabling EFI watchdog Date: Tue, 22 Feb 2022 09:58:30 +0900 Message-Id: <20220222005830.5996-1-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 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 UEFI specification requires that 5 minutes watchdog timer is armed before the firmware's boot manager invokes an EFI boot option. This watchdog timer is updated as follows, according to the UEFI specification. 1) The EFI Image may reset or disable the watchdog timer as needed. 2) If control is returned to the firmware's boot manager, the watchdog timer must be disabled. 3) On successful completion of EFI_BOOT_SERVICES.ExitBootServices() the watchdog timer is disabled. 1) is up to the EFI image, and 3) is already implemented in U-Boot. This patch implements 2), the watchdog is disabled when control is returned to U-Boot. In addition, current implementation arms the EFI watchdog at only the first "bootefi" invocation. The EFI watchdog must be armed in every EFI boot option invocation. Signed-off-by: Masahisa Kojima Reviewed-by: Heinrich Schuchardt --- cmd/bootefi.c | 17 +++++++++++++++++ lib/efi_loader/efi_watchdog.c | 13 +------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 94d18ca73f..46eebd5ee2 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -353,6 +353,19 @@ static efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options) /* On ARM switch from EL3 or secure mode to EL2 or non-secure mode */ switch_to_non_secure_mode(); + /* + * The UEFI standard requires that the watchdog timer is set to five + * minutes when invoking an EFI boot option. + * + * Unified Extensible Firmware Interface (UEFI), version 2.7 Errata A + * 7.5. Miscellaneous Boot Services - EFI_BOOT_SERVICES.SetWatchdogTimer + */ + ret = efi_set_watchdog(300); + if (ret != EFI_SUCCESS) { + log_err("ERROR: Failed to set watchdog timer\n"); + goto out; + } + /* Call our payload! */ ret = EFI_CALL(efi_start_image(handle, &exit_data_size, &exit_data)); if (ret != EFI_SUCCESS) { @@ -366,11 +379,15 @@ static efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options) efi_restore_gd(); +out: free(load_options); if (IS_ENABLED(CONFIG_EFI_LOAD_FILE2_INITRD)) efi_initrd_deregister(); + /* Control is returned to U-Boot, disable EFI watchdog */ + efi_set_watchdog(0); + return ret; } diff --git a/lib/efi_loader/efi_watchdog.c b/lib/efi_loader/efi_watchdog.c index 87ca6c5b0b..d741076dcd 100644 --- a/lib/efi_loader/efi_watchdog.c +++ b/lib/efi_loader/efi_watchdog.c @@ -75,17 +75,6 @@ efi_status_t efi_watchdog_register(void) printf("ERROR: Failed to register watchdog event\n"); return r; } - /* - * The UEFI standard requires that the watchdog timer is set to five - * minutes when invoking an EFI boot option. - * - * Unified Extensible Firmware Interface (UEFI), version 2.7 Errata A - * 7.5. Miscellaneous Boot Services - EFI_BOOT_SERVICES.SetWatchdogTimer - */ - r = efi_set_watchdog(300); - if (r != EFI_SUCCESS) { - printf("ERROR: Failed to set watchdog timer\n"); - return r; - } + return EFI_SUCCESS; }