From patchwork Fri Oct 13 17:33:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 825637 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yDFGZ2dp6z9s7C for ; Sat, 14 Oct 2017 04:35:02 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id D3A44C22022; Fri, 13 Oct 2017 17:34:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 4563EC22027; Fri, 13 Oct 2017 17:33:41 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 11611C21CEC; Fri, 13 Oct 2017 17:33:38 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by lists.denx.de (Postfix) with ESMTPS id 93AF3C21CEC for ; Fri, 13 Oct 2017 17:33:38 +0000 (UTC) Received: from workstation4.fritz.box ([94.114.42.150]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0LobGI-1daqpG0kWY-00gYVs; Fri, 13 Oct 2017 19:33:36 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Fri, 13 Oct 2017 19:33:06 +0200 Message-Id: <20171013173314.22304-2-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171013173314.22304-1-xypron.glpk@gmx.de> References: <20171013173314.22304-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K0:0Wb5zxXzIhUvxQWsPnlAumzKMa6SZsNHu38EkHPK8/pub1f5LR4 WczXGaK/DpU78CcqMKrR73jFkd8lEaz7OKzNymZMMkD+vQ6RHGOnIdyOoQAUwjGgs4Alme6 XDoR5dfioY69GvXbZHYQ31D/doCU6aeuelU8U7NsMntqfF7AWUV9JWHzMTEh3yz4RnETZZL KS3AelMYwKA5D62FQQXjA== X-UI-Out-Filterresults: notjunk:1; V01:K0:eCrBxM31AgQ=:KayFC49a9b69aFM70SUwOy td4bM3nmbkWHP5bCV3tFNxJ7owqSV+JzzfAvs2anaoJYA4uLPQLv1tko/XyHIi/TK9ynaWVAi 6MRqAVa01cQA7BWqhiH6rzKGBDw8+AZcfBOTj0aFhZHg1EeXp6cbNhvVemf2tFEjjahQjg7Gd b58gX+W47Z/HV1BEriUkFkY9gAMk539Cg4zMTNzfWIaleNWfKRceylSNgV7zAgc5GbQTzBHX5 UGK83Tf6qA+grdtDJeeVufQ0mky+9zNgukxqsZgr61zo7PMidvJVEUR+o2ZhuLwixC2jvkK8y lGRoLCZMZ8Mk8Mb6zXnNjVAog/uh/3HWGjOjAq/PsOM+ltocFfedo6d9f/3ER41OuZSn6SLW6 yPXkXQxpTakBfek4jfS41ceHHwbtvEyZ1O8KVnzNXdrzNvRK/5wr6aMMqF8ngT2pSCSSggGff sKSLJ/pblFWhWUPQofz6x6fFjs4U0puZpNQ0lrOzhtmyxoZTo4Xg3b/o2OgLhsyP1m5WtwQkQ R9icUAozJqPn9v9+b9WTuuIBDxbgs41zwnKDFWx4HUOcx3NvsXpyk2BBLxG0NiVr2CeudJ/gq kxa2qYukENkYIwGqNzDpfm7FNoNeWBDsG1fjre17wHCu3hIAZwCTUTXsdL8uPxe1E3ohpUefc 5D6AXSAf1NWJL/D2AmSWH25tKBDK0jc5RoQO5k/Vd9oO+1vArPRJNBlomZ/VV6jwC5xzM6nHH SG2EIli/RggHkTNtSLbOBXCAVTciaPdMJi+2u7CpcTXuOvXr5/og9YfaT3Kh4D3b3SLL/AH5s 8ULV2/HZCJuc1zG8M7twp2bZ3UuyQ== Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [U-Boot] [PATCH v2 1/9] efi_loader: move efi_search_obj up in code X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" To avoid a forward declaration move efi_search_obj before all protocol services functions. Signed-off-by: Heinrich Schuchardt --- v2 no change --- lib/efi_loader/efi_boottime.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index f627340de4..30577f717e 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -690,6 +690,27 @@ static efi_status_t EFIAPI efi_check_event(struct efi_event *event) return EFI_EXIT(EFI_INVALID_PARAMETER); } +/* + * Find the internal EFI object for a handle. + * + * @handle handle to find + * @return EFI object + */ +static struct efi_object *efi_search_obj(void *handle) +{ + struct list_head *lhandle; + + list_for_each(lhandle, &efi_obj_list) { + struct efi_object *efiobj; + + efiobj = list_entry(lhandle, struct efi_object, link); + if (efiobj->handle == handle) + return efiobj; + } + + return NULL; +} + /* * Install protocol interface. * @@ -1355,26 +1376,6 @@ static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle, panic("EFI application exited"); } -/* - * Find the internal EFI object for a handle. - * - * @handle handle to find - * @return EFI object - */ -static struct efi_object *efi_search_obj(void *handle) -{ - struct list_head *lhandle; - - list_for_each(lhandle, &efi_obj_list) { - struct efi_object *efiobj; - efiobj = list_entry(lhandle, struct efi_object, link); - if (efiobj->handle == handle) - return efiobj; - } - - return NULL; -} - /* * Unload an EFI image. * From patchwork Fri Oct 13 17:33:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 825632 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yDFF73msbz9sRV for ; Sat, 14 Oct 2017 04:33:47 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 371A2C2206A; Fri, 13 Oct 2017 17:33:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 4E0EEC21F7F; Fri, 13 Oct 2017 17:33:40 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id F391BC2201C; Fri, 13 Oct 2017 17:33:38 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lists.denx.de (Postfix) with ESMTPS id 98591C21FC5 for ; Fri, 13 Oct 2017 17:33:38 +0000 (UTC) Received: from workstation4.fritz.box ([94.114.42.150]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0MYcJi-1dhUfa1yy2-00VONU; Fri, 13 Oct 2017 19:33:36 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Fri, 13 Oct 2017 19:33:07 +0200 Message-Id: <20171013173314.22304-3-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171013173314.22304-1-xypron.glpk@gmx.de> References: <20171013173314.22304-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K0:+KUdSHfrNweSTUjclMjJyeXM8eLCJWWN3mS5oE9+332UHDNnBPL nCSBRBfEcpPOfL2kZTM9PWfnTLPTb5n4Cynoq56i97pCNj9riinqRHh7X3DQVa2Y79NXPro 9UZjWSHz20v5jxAG1y8IavCWn/RgVPuMkI1S5T8fnL9F8rSXhzOEeFCXDlh4swGurLD/5kq TUAlX0xEq3rmM4UzBLJjw== X-UI-Out-Filterresults: notjunk:1; V01:K0:SzoazygIYyk=:Rb5bPuuLpdCsudH1T81djT 9QUdL6T7Ni8+VpcBB3FWGDWTqOFrKotjTtMXphAYsrU8guJjhgtMJMfMha6vTyFMIKp5KtL90 dM7SumOLXPwmqFCq+Gops2KamWgp7/mVtPz5IXuqxguQAROH+Txg04NNo4W4glVY81j2oxha/ qOicm2bpUb8Tgt7I0fxSjgs14zeskUGvdWz8MLF3THad/8joOjcQDLbkc/z3RDjHaTjWEplZY OWzGdu6g4t8H3gkk5RnohlBg/2o45k6hFa4HtTxjD/uwR5MnMEgv7Dfjtb19hzXkpBrcS9v5P mNisJqB8fJ5tlO1GGpf+mElEcO+6/woUF2Yz5YExuUTcK4haCxQQbvDMsyYL6Z1obhBmiEX+8 DzncoMIBXmJ7jxtwPWFQyluKwilZjamItQ7ngKph3cxZ/eIRIJQRaGinflb46LZuRPaSQV0Io 1lriOY5b49Ger4eXXxnnjeXWPadS4alOpC/DIVXmrJe7IoGsPFWoVcjqAlQkdzqwT51doLdfB 4z1HHIEmepEJ+GAw9pKW28lesUagl8rqhBmpzH0SSGkAgFltPFfRGFOFYkmIUr132im84FbOh JXHvO1Y1ZvgrP5G/YeDPimoaSx5P5PqjxAPRS3QcIthNFAUFW24O3RqXGV8MNf4qn1JWOsxU8 t/lFW00iprdCHQmpQIk5m1yqjIxsgzb+TYXqvxjh5BxsKMPh4Cuj9zMSnOyxde89bXO/YreOI mPQ15DoEXLRgiQrgNy5NlTrHJsprum1xeTl7/l64pxUi4Uoyo+tm2efscpiJlHmxzKrnZ+ABf Gh5X9AOlQ/UauXCG8xU4oK68H5elQ== Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [U-Boot] [PATCH v2 2/9] efi_loader: implement SetWatchdogTimer X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The watchdog is initialized with a 5 minute timeout period. It can be reset by SetWatchdogTimer. It is stopped by ExitBoottimeServices. Signed-off-by: Heinrich Schuchardt --- v2 code comments updated --- cmd/bootefi.c | 1 + include/efi_loader.h | 4 ++ lib/efi_loader/Makefile | 2 +- lib/efi_loader/efi_boottime.c | 17 ++------- lib/efi_loader/efi_watchdog.c | 86 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 15 deletions(-) create mode 100644 lib/efi_loader/efi_watchdog.c diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 478bc116e2..18176a1266 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -43,6 +43,7 @@ static void efi_init_obj_list(void) #ifdef CONFIG_GENERATE_SMBIOS_TABLE efi_smbios_register(); #endif + efi_watchdog_register(); /* Initialize EFI runtime services */ efi_reset_system_init(); diff --git a/include/efi_loader.h b/include/efi_loader.h index 1b92edbd77..af64b11cee 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -163,6 +163,8 @@ int efi_disk_register(void); int efi_gop_register(void); /* Called by bootefi to make the network interface available */ int efi_net_register(void); +/* Called by bootefi to make the watchdog available */ +int efi_watchdog_register(void); /* Called by bootefi to make SMBIOS tables available */ void efi_smbios_register(void); @@ -171,6 +173,8 @@ efi_fs_from_path(struct efi_device_path *fp); /* Called by networking code to memorize the dhcp ack package */ void efi_net_set_dhcp_ack(void *pkt, int len); +/* Called by efi_set_watchdog_timer to reset the timer */ +efi_status_t efi_set_watchdog(unsigned long timeout); /* Called from places to check whether a timer expired */ void efi_timer_check(void); diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index ddb978f650..83d879b686 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -17,7 +17,7 @@ endif obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o obj-y += efi_image_loader.o efi_boottime.o efi_runtime.o efi_console.o obj-y += efi_memory.o efi_device_path_to_text.o efi_device_path.o -obj-y += efi_file.o efi_variable.o efi_bootmgr.o +obj-y += efi_file.o efi_variable.o efi_bootmgr.o efi_watchdog.o obj-$(CONFIG_LCD) += efi_gop.o obj-$(CONFIG_DM_VIDEO) += efi_gop.o obj-$(CONFIG_PARTITIONS) += efi_disk.o diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 30577f717e..fd8d15655b 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -155,18 +155,6 @@ void efi_signal_event(struct efi_event *event) event->is_queued = false; } -/* - * Write a debug message for an EPI API service that is not implemented yet. - * - * @funcname function that is not yet implemented - * @return EFI_UNSUPPORTED - */ -static efi_status_t efi_unsupported(const char *funcname) -{ - debug("EFI: App called into unimplemented function %s\n", funcname); - return EFI_EXIT(EFI_UNSUPPORTED); -} - /* * Raise the task priority level. * @@ -1454,6 +1442,7 @@ static efi_status_t EFIAPI efi_exit_boot_services(void *image_handle, bootm_disable_interrupts(); /* Give the payload some time to boot */ + efi_set_watchdog(0); WATCHDOG_RESET(); return EFI_EXIT(EFI_SUCCESS); @@ -1497,7 +1486,7 @@ static efi_status_t EFIAPI efi_stall(unsigned long microseconds) /* * Reset the watchdog timer. * - * This function implements the WatchdogTimer service. + * This function implements the SetWatchdogTimer service. * See the Unified Extensible Firmware Interface (UEFI) specification * for details. * @@ -1514,7 +1503,7 @@ static efi_status_t EFIAPI efi_set_watchdog_timer(unsigned long timeout, { EFI_ENTRY("%ld, 0x%"PRIx64", %ld, %p", timeout, watchdog_code, data_size, watchdog_data); - return efi_unsupported(__func__); + return EFI_EXIT(efi_set_watchdog(timeout)); } /* diff --git a/lib/efi_loader/efi_watchdog.c b/lib/efi_loader/efi_watchdog.c new file mode 100644 index 0000000000..eb437faf4b --- /dev/null +++ b/lib/efi_loader/efi_watchdog.c @@ -0,0 +1,86 @@ +/* + * EFI watchdog + * + * Copyright (c) 2017 Heinrich Schuchardt + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include + +static struct efi_event *watchdog_timer_event; + +/* + * Reset the system when the watchdog event is notified. + * + * @event: the watchdog event + * @context: not used + */ +static void EFIAPI efi_watchdog_timer_notify(struct efi_event *event, + void *context) +{ + EFI_ENTRY("%p, %p", event, context); + + printf("\nEFI: Watchdog timeout\n"); + EFI_CALL_VOID(efi_runtime_services.reset_system(EFI_RESET_COLD, + EFI_SUCCESS, 0, NULL)); + + EFI_EXIT(EFI_UNSUPPORTED); +} + +/* + * Reset the watchdog timer. + * + * This function is used by the SetWatchdogTimer service. + * + * @timeout: seconds before reset by watchdog + * @return: status code + */ +efi_status_t efi_set_watchdog(unsigned long timeout) +{ + efi_status_t r; + + if (timeout) + /* Reset watchdog */ + r = efi_set_timer(watchdog_timer_event, EFI_TIMER_RELATIVE, + 10000000 * timeout); + else + /* Deactivate watchdog */ + r = efi_set_timer(watchdog_timer_event, EFI_TIMER_STOP, 0); + return r; +} + +/* + * Initialize the EFI watchdog. + * + * This function is called by efi_init_obj_list() + */ +int efi_watchdog_register(void) +{ + efi_status_t r; + + /* + * Create a timer event. + */ + r = efi_create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK, + efi_watchdog_timer_notify, NULL, + &watchdog_timer_event); + if (r != EFI_SUCCESS) { + 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 0; +} From patchwork Fri Oct 13 17:33:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 825651 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yDFKf14gWz9s7C for ; Sat, 14 Oct 2017 04:37:41 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id A72FFC2205F; Fri, 13 Oct 2017 17:34:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id E8DBCC2204C; Fri, 13 Oct 2017 17:33:42 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 38786C21F7F; Fri, 13 Oct 2017 17:33:39 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lists.denx.de (Postfix) with ESMTPS id 96356C21F7F for ; Fri, 13 Oct 2017 17:33:38 +0000 (UTC) Received: from workstation4.fritz.box ([94.114.42.150]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0Meduu-1dry0G3DPk-00OCJe; Fri, 13 Oct 2017 19:33:36 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Fri, 13 Oct 2017 19:33:08 +0200 Message-Id: <20171013173314.22304-4-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171013173314.22304-1-xypron.glpk@gmx.de> References: <20171013173314.22304-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K0:ASIRZZf2JcbXzFuIBU8WkvHGgnnNioGViB9kMIrYJ0CdnxR95P2 sSQfA4GpG6XofyC+ZSDaMMiYMWTez2TLGZw4g7+9RZ282YLFscH3N+nonQd38SgRjWvy8jx xXDe9UYXCmGH1FHsLbe97ylF7ZAQOy1lsGA+EbnkZg3N2Vx7uWrN49339dEW0oaa+MSleca cXl50VobwEq0T8duMjTMw== X-UI-Out-Filterresults: notjunk:1; V01:K0:Sjaay0IXOGM=:hZtwJB87AGOUJlZwaZPMRM KfVsRtPaCBtkPN9Gc93oSAMgrBouvGWmJ/SOmtrcqjgFOw0q0lJUb8GHFZdt8DBdKkDUkFWV4 76FREGTIEc2FSu2ale6q7KmM/pq9EiYtTZphm00A2+/jqgP7kJCOcBgAsAgro/AWPTkommpaJ VgJ734Ue8Dok5oJndk5hR/WqFqghgzlEVy0lehYE8arAxwNTyymohYMnK9zBrPjl4ML8WwSIA W1sULzpscUYheVj3Gn9IkFFdWllazpoaTJ3/Tw0Jm4Knp19v5dL+98RFY7q1BmyqB/saXfkIW YVT2vZi6y95hQlwAiue3I/VwNmT52NmScXQsAGlrT3nJZgITwMlTcBs1VFDgN1zS5WCc9f6Z6 ubdXUpBQjK36VR41Zn2CvzowM1DYtgd0CtbbZ4mWkAqtr+9gaDfTvfyrSo6upiBKQcpNUL/Xa FBbafzDC7vshnLGVKCyKuWBiI3M2gWQ4W4Et/2GDO0/VWGW3WbpULidQC+BMv+w8KSI6WyTHp 76Fjuq3j9/WBlSQI/ev9DZ/W2ysJvq3I4CHKP6sjhrYo8IeHbb2KkHmI8z0z13Jd8f4iemvMt bU+eeKhmjFUDkx02M2tPldeEeRp2etcfyEXF5g/YbxBGAdE4UlvCXVT7YXck/fVGDqKFKpuAC 7SdG87bjyoxK6NyMf48tbhetgrs6mSiQv6DMSZmW/ECkq0Q9q4cPr6rvnFCOWrF13Jf3zkTOn hpc0uKoP7zulpWH4HXFXVOVSfHtpC5OLw2IW+PRmspSwMzuG0iq6iZ82mTKUB8KovICVfbkrX xyk64LxIrjMIFZorJQ2vhRhL7whag== Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [U-Boot] [PATCH v2 3/9] efi_selftest: provide test for watchdog timer X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The test verifies that resetting the watchdog timer ensures that it is not called during the timeout period. Testing that the watchdog timer actually executes a reset would require a test outside the efi_selftest framework. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- v2 no change --- lib/efi_selftest/Makefile | 5 +- lib/efi_selftest/efi_selftest_watchdog.c | 185 +++++++++++++++++++++++++++++++ 2 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 lib/efi_selftest/efi_selftest_watchdog.c diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile index e446046e02..3e5c9a6d16 100644 --- a/lib/efi_selftest/Makefile +++ b/lib/efi_selftest/Makefile @@ -21,6 +21,8 @@ CFLAGS_efi_selftest_tpl.o := $(CFLAGS_EFI) CFLAGS_REMOVE_efi_selftest_tpl.o := $(CFLAGS_NON_EFI) CFLAGS_efi_selftest_util.o := $(CFLAGS_EFI) CFLAGS_REMOVE_efi_selftest_util.o := $(CFLAGS_NON_EFI) +CFLAGS_efi_selftest_watchdog.o := $(CFLAGS_EFI) +CFLAGS_REMOVE_efi_selftest_watchdog.o := $(CFLAGS_NON_EFI) obj-$(CONFIG_CMD_BOOTEFI_SELFTEST) += \ efi_selftest.o \ @@ -29,4 +31,5 @@ efi_selftest_events.o \ efi_selftest_exitbootservices.o \ efi_selftest_snp.o \ efi_selftest_tpl.o \ -efi_selftest_util.o +efi_selftest_util.o \ +efi_selftest_watchdog.o diff --git a/lib/efi_selftest/efi_selftest_watchdog.c b/lib/efi_selftest/efi_selftest_watchdog.c new file mode 100644 index 0000000000..f8c5404000 --- /dev/null +++ b/lib/efi_selftest/efi_selftest_watchdog.c @@ -0,0 +1,185 @@ +/* + * efi_selftest_watchdog + * + * Copyright (c) 2017 Heinrich Schuchardt + * + * SPDX-License-Identifier: GPL-2.0+ + * + * This unit test checks that the watchdog timer will not cause + * a system restart during the timeout period after a timer reset. + * + * Testing that the watchdog timer actually will reset the system + * after a timeout is not possible within the used framework. + */ + +#include + +/* + * This is the communication structure for the notification function. + */ +struct notify_context { + /* Status code returned when resetting watchdog */ + efi_status_t status; + /* Number of invocations of the notification function */ + unsigned int timer_ticks; +}; + +static struct efi_event *event_notify; +static struct efi_event *event_wait; +static struct efi_boot_services *boottime; +static struct notify_context notification_context; + +/* + * Notification function, increments the notfication count if parameter + * context is provided. + * + * @event notified event + * @context pointer to the timeout + */ +static void EFIAPI notify(struct efi_event *event, void *context) +{ + struct notify_context *notify_context = context; + efi_status_t ret = EFI_SUCCESS; + + if (!notify_context) + return; + + /* Reset watchdog timer to one second */ + ret = boottime->set_watchdog_timer(1, 0, 0, NULL); + if (ret != EFI_SUCCESS) + notify_context->status = ret; + /* Count number of calls */ + notify_context->timer_ticks++; +} + +/* + * Setup unit test. + * + * Create two timer events. + * One with EVT_NOTIFY_SIGNAL, the other with EVT_NOTIFY_WAIT. + * + * @handle: handle of the loaded image + * @systable: system table + * @return: EFI_ST_SUCCESS for success + */ +static int setup(const efi_handle_t handle, + const struct efi_system_table *systable) +{ + efi_status_t ret; + + boottime = systable->boottime; + + notification_context.status = EFI_SUCCESS; + notification_context.timer_ticks = 0; + ret = boottime->create_event(EVT_TIMER | EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, notify, + (void *)¬ification_context, + &event_notify); + if (ret != EFI_SUCCESS) { + efi_st_error("could not create event\n"); + return EFI_ST_FAILURE; + } + ret = boottime->create_event(EVT_TIMER | EVT_NOTIFY_WAIT, + TPL_CALLBACK, notify, NULL, &event_wait); + if (ret != EFI_SUCCESS) { + efi_st_error("could not create event\n"); + return EFI_ST_FAILURE; + } + return EFI_ST_SUCCESS; +} + +/* + * Tear down unit test. + * + * Close the events created in setup. + * + * @return: EFI_ST_SUCCESS for success + */ +static int teardown(void) +{ + efi_status_t ret; + + /* Set the watchdog timer to the five minute default value */ + ret = boottime->set_watchdog_timer(300, 0, 0, NULL); + if (ret != EFI_SUCCESS) { + efi_st_error("Setting watchdog timer failed\n"); + return EFI_ST_FAILURE; + } + if (event_notify) { + ret = boottime->close_event(event_notify); + event_notify = NULL; + if (ret != EFI_SUCCESS) { + efi_st_error("Could not close event\n"); + return EFI_ST_FAILURE; + } + } + if (event_wait) { + ret = boottime->close_event(event_wait); + event_wait = NULL; + if (ret != EFI_SUCCESS) { + efi_st_error("Could not close event\n"); + return EFI_ST_FAILURE; + } + } + return EFI_ST_SUCCESS; +} + +/* + * Execute unit test. + * + * Run a 600 ms periodic timer that resets the watchdog to one second + * on every timer tick. + * + * Run a 1350 ms single shot timer and check that the 600ms timer has + * been called 2 times. + * + * @return: EFI_ST_SUCCESS for success + */ +static int execute(void) +{ + size_t index; + efi_status_t ret; + + /* Set the watchdog timeout to one second */ + ret = boottime->set_watchdog_timer(1, 0, 0, NULL); + if (ret != EFI_SUCCESS) { + efi_st_error("Setting watchdog timer failed\n"); + return EFI_ST_FAILURE; + } + /* Set 600 ms timer */ + ret = boottime->set_timer(event_notify, EFI_TIMER_PERIODIC, 6000000); + if (ret != EFI_SUCCESS) { + efi_st_error("Could not set timer\n"); + return EFI_ST_FAILURE; + } + /* Set 1350 ms timer */ + ret = boottime->set_timer(event_wait, EFI_TIMER_RELATIVE, 13500000); + if (ret != EFI_SUCCESS) { + efi_st_error("Could not set timer\n"); + return EFI_ST_FAILURE; + } + + ret = boottime->wait_for_event(1, &event_wait, &index); + if (ret != EFI_SUCCESS) { + efi_st_error("Could not wait for event\n"); + return EFI_ST_FAILURE; + } + if (notification_context.status != EFI_SUCCESS) { + efi_st_error("Setting watchdog timer failed\n"); + return EFI_ST_FAILURE; + } + if (notification_context.timer_ticks != 2) { + efi_st_error("The timer was called %u times, expected 2.\n", + notification_context.timer_ticks); + return EFI_ST_FAILURE; + } + return EFI_ST_SUCCESS; +} + +EFI_UNIT_TEST(watchdog) = { + .name = "watchdog timer", + .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, + .setup = setup, + .execute = execute, + .teardown = teardown, +}; From patchwork Fri Oct 13 17:33:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 825652 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yDFLH58N7z9s7C for ; Sat, 14 Oct 2017 04:38:15 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 2856CC2206D; Fri, 13 Oct 2017 17:35:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 98560C22065; Fri, 13 Oct 2017 17:33:46 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 07579C21F7F; Fri, 13 Oct 2017 17:33:39 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lists.denx.de (Postfix) with ESMTPS id CD6B5C22016 for ; Fri, 13 Oct 2017 17:33:38 +0000 (UTC) Received: from workstation4.fritz.box ([94.114.42.150]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0LlGoc-1dVNiR0Isg-00b5Om; Fri, 13 Oct 2017 19:33:37 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Fri, 13 Oct 2017 19:33:09 +0200 Message-Id: <20171013173314.22304-5-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171013173314.22304-1-xypron.glpk@gmx.de> References: <20171013173314.22304-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K0:JU6jg12IByc8CWzK5F+jdYpaAHJHofTD5xBcbrTG3TMYyAanvNg uL6A6E3kK5keYgNo1laptqEpax0UZd3TeCDp4smI6wVDTBsqWXMP7skcQZUUaPAwDMrxmtq 7s4fw49AwMP6WJDdC3HafyIxLCHvWWFSlOml726U1nP9vINre0aRo51z+wfaD67PAoyDb8S hjQtKYn7h55pe/Vs4NBPw== X-UI-Out-Filterresults: notjunk:1; V01:K0:qrv/jrRbRyw=:0jvTgHpePYMfvQH7Ljj9Rg 5E76tRAbaru+8neH42JamZeY+HIiDf+EbIs+wisafz8eNjJPkfR//rnffmqZ5gG+jCdUKp7kO ky/gOVwNctGEz9b2PAXzGZ7KBcJ+NmtZ6OicWzzBLxMW3guoYAlKQjVsqTzN2Mjz3qz9qHak+ GgPNyATJ7BR3sOCROAP2BqB3ZFFxPHPg3fnV78gIo6R+GuTgDPf03K+uN3spFTWui9ZNhGlos FXlSQ+fAMCO0a6rXiu5v6E3j4vG6p9X6XLHYPPTDHBM9mwHdCHD/k4L2n4IVbwLJJtqGx7gN9 jUlF2XDgv/t44ElxgiYHAYGYfDxL71jo671SRZV0MY1CvRbAyqtaBhJPbS+8LzIb3ZxD3TEVV TbBFvzOkn3SEg+1Tu4Z0k1tDGKllzJyTHZEnHkTuchoyH3nB64lLzHJo3g5gFREs9kGNJgXfp 1UlPIRbqrensMi+Y1PIa6FmgshpkzRNyaxhTmJ1VGMfFzft1Z71fksGkI+egc8DJafkVzCx4g hMItQYps4Sxqo2UVjHeCgkyRFUgcpAoHLvPxnjpIwRWL0+eOiDaLRNJTbvjcx9c5RvxEyZRKT N8J4kom84RuEdxv1eMY8c//CNJL4EXPTQyCIKnYFni69CyqRfYdS14h8Gv3yVuAiuRTXAtORb aQo1QzrfuYT7+t9lzA0WLXmm1earU/JeZOYRaqbOxf4rXnlADjYQT8UHD568U4FcASVBNf1KF RjiipJ6WPsKfwfw/DsI7ymjhA0BcCKk93QiTDg4k8uYwPuY7GBo5PzA74mAzGvXTeI3vXmjhl IKzquD8dF2KiqAotJldgdyr9Zv7nQ== Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [U-Boot] [PATCH v2 4/9] efi_loader: new function utf8_to_utf16 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Provide a conversion function from utf8 to utf16. Add missing #include in include/charset.h. Remove superfluous #include in lib/charset.c. Signed-off-by: Heinrich Schuchardt --- v2 new patch --- include/charset.h | 15 +++++++++++++++ lib/charset.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/include/charset.h b/include/charset.h index 37a3278499..2662c2f7c9 100644 --- a/include/charset.h +++ b/include/charset.h @@ -9,6 +9,8 @@ #ifndef __CHARSET_H_ #define __CHARSET_H_ +#include + #define MAX_UTF8_PER_UTF16 3 /** @@ -62,4 +64,17 @@ uint16_t *utf16_strdup(const uint16_t *s); */ uint8_t *utf16_to_utf8(uint8_t *dest, const uint16_t *src, size_t size); +/** + * utf8_to_utf16() - Convert an utf8 string to utf16 + * + * Converts up to 'size' characters of the utf16 string 'src' to utf8 + * written to the 'dest' buffer. Stops at 0x00. + * + * @dest the destination buffer to write the utf8 characters + * @src the source utf16 string + * @size maximum number of utf16 characters to convert + * @return the pointer to the first unwritten byte in 'dest' + */ +uint16_t *utf8_to_utf16(uint16_t *dest, const uint8_t *src, size_t size); + #endif /* __CHARSET_H_ */ diff --git a/lib/charset.c b/lib/charset.c index ff76e88c77..8cd17ea1cb 100644 --- a/lib/charset.c +++ b/lib/charset.c @@ -6,7 +6,6 @@ * SPDX-License-Identifier: GPL-2.0+ */ -#include #include #include @@ -99,3 +98,59 @@ uint8_t *utf16_to_utf8(uint8_t *dest, const uint16_t *src, size_t size) return dest; } + +uint16_t *utf8_to_utf16(uint16_t *dest, const uint8_t *src, size_t size) +{ + while (size--) { + int extension_bytes; + uint32_t code; + + extension_bytes = 0; + if (*src <= 0x7f) { + code = *src++; + /* Exit on zero byte */ + if (!code) + size = 0; + } else if (*src <= 0xbf) { + /* Illegal code */ + code = '?'; + } else if (*src <= 0xdf) { + code = *src++ & 0x1f; + extension_bytes = 1; + } else if (*src <= 0xef) { + code = *src++ & 0x0f; + extension_bytes = 2; + } else if (*src <= 0xf7) { + code = *src++ & 0x07; + extension_bytes = 3; + } else { + /* Illegal code */ + code = '?'; + } + + for (; extension_bytes && size; --size, --extension_bytes) { + if ((*src & 0xc0) == 0x80) { + code <<= 6; + code |= *src++ & 0x3f; + } else { + /* Illegal code */ + code = '?'; + ++src; + --size; + break; + } + } + + if (code < 0x10000) { + *dest++ = code; + } else { + /* + * Simplified expression for + * (((code - 0x10000) >> 10) & 0x3ff) | 0xd800 + */ + *dest++ = (code >> 10) + 0xd7c0; + *dest++ = (code & 0x3ff) | 0xdc00; + } + } + return dest; +} From patchwork Fri Oct 13 17:33:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 825642 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yDFHx1LQxz9sRW for ; Sat, 14 Oct 2017 04:36:12 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 8C3F7C22012; Fri, 13 Oct 2017 17:34:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 297FEC2203E; Fri, 13 Oct 2017 17:33:42 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 21AE1C21FC5; Fri, 13 Oct 2017 17:33:39 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by lists.denx.de (Postfix) with ESMTPS id 9A0F9C21FF6 for ; Fri, 13 Oct 2017 17:33:38 +0000 (UTC) Received: from workstation4.fritz.box ([94.114.42.150]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0LhkiL-1dPY921XXt-00mvEJ; Fri, 13 Oct 2017 19:33:37 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Fri, 13 Oct 2017 19:33:10 +0200 Message-Id: <20171013173314.22304-6-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171013173314.22304-1-xypron.glpk@gmx.de> References: <20171013173314.22304-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K0:M8qvqpS2qh+AXXvHjjowQZAftMAieDIuXEm8FrMRtaLWNJ8ypoS C/qTpV5TgG099QPqzKfOLL+axhVOuZ5wsMstev1P8bcMOAzX4uEBVG9Gn5YXPE4ui5GlQF6 efHmH72qALxakdnHnGM8M0EUaxNmvyMH2a94CIoMZV7H6y6ooe5MYAQ8cmQWy7gWrPdTuMv HrAqvci7cMLH5ybutHdfQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:Pg/Xh3yg+yA=:juwoNecX4/wLnqwuu3B2Yq Z3YqzkcHnqmKgKWF1yh4p205fQUAFq4LmGA5vxUAdfUc29jS5B3HEVG9QpZCg1QTHV1KahN1R tvECQ8je92OVC9xUyBluoahjcRaz+gS9RAcwRiiRBz363dSFpD3a4TFvC/xx/748rxo38azla DQAxEASDhbCalNNIi/CKySJhHTzLbqHTZvJOZFAZcayGDbwARaYZ481n9B+6+B0t/qKq03aOR vTCZxZQ4wL8I5GaCyB5UNaeE2hiO8qUgTDkuCpc0YzlKt42kHSW7OOWmB3ax6hCWbgj1OpwqV 33TFsNKJJNO400nvP0Yef+abWR19YFWufarAhDjbvA9F6/94e5TroljFV1Hos2lV3gJxbYdUu itGLcPPLHlbywDXX5EQH8+a3m/NTgG4/+gblRtWBc317YQFLumvXZEfQZHzrwVVIy7k/SIBD1 LLuHeH43QOr+1xkx8RDk0yeEAHOWaVp5kqop38mboGFCvYLXhxqK2uIKvtAkdxYbUAXqilEwF JGiz27fj36AgaDauYicsHYFW868yumw6wMZSmtivRxQbz39t+Suv8cewpodM1nXbKYLkC+aMz QYD36ZC7WEH4mqcNgu2ZzicDGx9ZlsmKxK5aL4OlYbImrL2YpOxbEBvdQqZMkGoXXEMx0T/6o 4oztkCMCs+N5XDtlnlghcPTPBB4IIb400mO92yB4+dSEx5XPxjAc5ZI4KGrYJBbRNQ1mewGyU sGLQ6IMK6FAcNdlYAGs9qFGmR/mcpY2yEYZWnSzqczCTyQ4uI9IEFjS0cV0Aq+xDo/ajD2PS5 MeQLNxtt3fB5aNzKu5I+cmNpTtFdg== Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [U-Boot] [PATCH v2 5/9] efi_loader: guard against double inclusion of efi_loader.h X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Use a define to detect double inclusion of efi_loader.h. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- v2 new patch --- include/efi_loader.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index af64b11cee..e506eeec61 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -6,6 +6,9 @@ * SPDX-License-Identifier: GPL-2.0+ */ +#ifndef _EFI_LOADER_H +#define _EFI_LOADER_H 1 + #include #include #include @@ -345,4 +348,6 @@ static inline void efi_set_bootdev(const char *dev, const char *devnr, const char *path) { } static inline void efi_net_set_dhcp_ack(void *pkt, int len) { } -#endif +#endif /* CONFIG_EFI_LOADER && !CONFIG_SPL_BUILD */ + +#endif /* _EFI_LOADER_H */ From patchwork Fri Oct 13 17:33:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 825648 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yDFKR4Cdbz9s7C for ; Sat, 14 Oct 2017 04:37:31 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 1E8A1C22020; Fri, 13 Oct 2017 17:35:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id C3DACC22042; Fri, 13 Oct 2017 17:33:43 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 51120C21FF6; Fri, 13 Oct 2017 17:33:39 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lists.denx.de (Postfix) with ESMTPS id D96BDC2201B for ; Fri, 13 Oct 2017 17:33:38 +0000 (UTC) Received: from workstation4.fritz.box ([94.114.42.150]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0LviG8-1dAtwb2loq-017THi; Fri, 13 Oct 2017 19:33:37 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Fri, 13 Oct 2017 19:33:11 +0200 Message-Id: <20171013173314.22304-7-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171013173314.22304-1-xypron.glpk@gmx.de> References: <20171013173314.22304-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K0:IkW+zwnYSWvo52aVETNPpBVghc6ZlMf/Aeop+HgNfKAHvwMhiKC uYv22apKcOUn3vzef6ujQ1ZuF1IA8XTT2imqlpxEEOGPMc9wA0Lna5akv2FQa+GrfbiVJPp hD2jHLwLx2/ceYSoO1hqC3Pctigw2Zmd7aYPShRDfjvt3+eeTeBVxTZMWf6jgfMQxy1lHbV /eAL5dmH+MlOl3ubMF01A== X-UI-Out-Filterresults: notjunk:1; V01:K0:5V7pe0Qme48=:VDApbRB0L0n3f+WDANPF6q L2H+ZKTuQ2tcmf3Ah8pjs0kfQk/yxiAfKFyTNOJUMbCsp7HeaGGD8UBnPnPFqRXJqUl5nyUo/ REZLft2d48cZ+TjNpIkFUI9/DVpngqCeW9RljCC+0YzxqobS15ZiN2TVffUwvA2ZAdPJ1RDnU u3ONdkUJ+UVYKU8mKeLSfjuegfsbAJIAHxAzLYcK2C7AhJKNlwC8KXYYpieRHeFdtmjHiNJ0m v5zrrqrNN6kqfqqDyraYniacqZGK0OWn9/vXsvApNX/L2OgYZwwUWnCa75qKI4TQ4K2fxu2rB AG84IKw7wppXqzshyiGDnDtNQyxX+jwIPT1GfDG4v3zEKRR6io6q5NAM9BUwoul98C/QV28ih vQelpHBTtIF3ysfBoEJaugB18iClODEjDPYz3EIFCy6Gj1+jITPaRrDY0GGSIZPgom0BkLGwH q279Z/Nm8C+dMtMqoAUTiVOoNqVGL7ojzuugy2q1Vgnow6VrJ4JHMXTu4vbC5Nb6cW52/RPH4 MiEeXoL01+jx/N/GUoLUX1M5ufC23Vrib2GfoIVFEK9RG77j1MicBnP7m3ZL+AfT95RaoqnWI hoiQhpNi2zA13e3JACLN+ZnmSdpsJCloKgvNPPbS5Fylv/2um70qzZcX7LM333kOBA9aaJFyf s3hdVavagJNoNmk8dBRJUJnLSgfcOz4aBjAFnjZ6J1aOIJiBzCg/dUtPhNku3mfL0DpAO/M6D 1SQ13OQ4pgS6eZjcUIP+DzWkuJaWBowB0QwR8AsjDDis/Hny0tw5UxTBLyIGDZItwjrsUAlVv BHOmNMhooSWyzmThfiEldRz2a2HWQ== Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [U-Boot] [PATCH v2 6/9] efi_selftest: allow to select a single test for exexution X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Environment variable efi_selftest is passed as load options to the selftest application. It is used to select a single test to be executed. Special value 'list' displays a list of all available tests. Tests get an on_request property. If this property is set the tests are only executed if explicitly requested. The invocation of efi_selftest is changed to reflect that bootefi selftest with efi_selftest = 'list' will call the Exit bootservice. Environment variable bootargs is used as load options for all other bootefi payloads. Signed-off-by: Heinrich Schuchardt --- v2 use an environment variable to choose a test --- cmd/bootefi.c | 46 ++++++++++++++++- include/efi_selftest.h | 18 +++++++ lib/efi_selftest/efi_selftest.c | 90 +++++++++++++++++++++++++++++++-- lib/efi_selftest/efi_selftest_console.c | 10 ++++ lib/efi_selftest/efi_selftest_util.c | 11 +++- 5 files changed, 168 insertions(+), 7 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 18176a1266..2d70137482 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -6,10 +6,12 @@ * SPDX-License-Identifier: GPL-2.0+ */ +#include #include #include #include #include +#include #include #include #include @@ -50,6 +52,32 @@ static void efi_init_obj_list(void) efi_get_time_init(); } +/* + * Set the load options of an image from an environment variable. + * + * @loaded_image_info: the image + * @env_var: name of the environment variable + */ +static void set_load_options(struct efi_loaded_image *loaded_image_info, + const char *env_var) +{ + size_t size; + const char *env = env_get(env_var); + + loaded_image_info->load_options = NULL; + loaded_image_info->load_options_size = 0; + if (!env) + return; + size = strlen(env) + 1; + loaded_image_info->load_options = calloc(size, sizeof(u16)); + if (!loaded_image_info->load_options) { + printf("ERROR: Out of memory\n"); + return; + } + utf8_to_utf16(loaded_image_info->load_options, (u8 *)env, size); + loaded_image_info->load_options_size = size * 2; +} + static void *copy_fdt(void *fdt) { u64 fdt_size = fdt_totalsize(fdt); @@ -190,6 +218,8 @@ static unsigned long do_bootefi_exec(void *efi, void *fdt, efi_install_configuration_table(&fdt_guid, NULL); } + /* Transfer environment variable bootargs as load options */ + set_load_options(&loaded_image_info, "bootargs"); /* Load the EFI payload */ entry = efi_load_pe(efi, &loaded_image_info); if (!entry) { @@ -237,6 +267,7 @@ static unsigned long do_bootefi_exec(void *efi, void *fdt, exit: /* image has returned, loaded-image obj goes *poof*: */ + free(loaded_image_info.load_options); list_del(&loaded_image_info_obj.link); return ret; @@ -301,17 +332,26 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) efi_setup_loaded_image(&loaded_image_info, &loaded_image_info_obj, - bootefi_device_path, bootefi_image_path); + NULL, NULL); /* * gd lives in a fixed register which may get clobbered while we * execute the payload. So save it here and restore it on every * callback entry */ efi_save_gd(); + loaded_image_info.image_code_type = EFI_LOADER_CODE; + loaded_image_info.image_data_type = EFI_LOADER_DATA; /* Initialize and populate EFI object list */ if (!efi_obj_list_initalized) efi_init_obj_list(); - return efi_selftest(&loaded_image_info, &systab); + /* Transfer environment variable efi_selftest as load options */ + set_load_options(&loaded_image_info, "efi_selftest"); + /* Execute the test */ + r = efi_selftest(&loaded_image_info, &systab); + efi_restore_gd(); + free(loaded_image_info.load_options); + list_del(&loaded_image_info_obj.link); + return r; } else #endif if (!strcmp(argv[1], "bootmgr")) { @@ -357,6 +397,8 @@ static char bootefi_help_text[] = #ifdef CONFIG_CMD_BOOTEFI_SELFTEST "bootefi selftest\n" " - boot an EFI selftest application stored within U-Boot\n" + " Use environment variable efi_selftest to select a single test.\n" + " Use 'setenv efi_selftest list' to enumerate all tests.\n" #endif "bootmgr [fdt addr]\n" " - load and boot EFI payload based on BootOrder/BootXXXX variables.\n" diff --git a/include/efi_selftest.h b/include/efi_selftest.h index 7ec42a0406..978ca2a7ea 100644 --- a/include/efi_selftest.h +++ b/include/efi_selftest.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #define EFI_ST_SUCCESS 0 @@ -71,6 +72,15 @@ void efi_st_printf(const char *fmt, ...) */ int efi_st_memcmp(const void *buf1, const void *buf2, size_t length); +/* + * Compare an u16 string to a char string. + * + * @buf1: u16 string + * @buf2: char string + * @return: 0 if both buffers contain the same bytes + */ +int efi_st_strcmp_16_8(const u16 *buf1, const char *buf2); + /* * Reads an Unicode character from the input device. * @@ -88,6 +98,7 @@ u16 efi_st_get_key(void); * @setup: set up the unit test * @teardown: tear down the unit test * @execute: execute the unit test + * @on_request: test is only executed on request */ struct efi_unit_test { const char *name; @@ -96,10 +107,17 @@ struct efi_unit_test { const struct efi_system_table *systable); int (*execute)(void); int (*teardown)(void); + bool on_request; }; /* Declare a new EFI unit test */ #define EFI_UNIT_TEST(__name) \ ll_entry_declare(struct efi_unit_test, __name, efi_unit_test) +#define EFI_SELFTEST_TABLE_GUID \ + EFI_GUID(0xbc3ebe57, 0x09e5, 0xa59d, 0xdb, 0x87, \ + 0xf5, 0x79, 0x61, 0x62, 0x06, 0xde) + +extern const efi_guid_t efi_selftest_table_guid; + #endif /* _EFI_SELFTEST_H */ diff --git a/lib/efi_selftest/efi_selftest.c b/lib/efi_selftest/efi_selftest.c index 45d8d3d384..110284f9c7 100644 --- a/lib/efi_selftest/efi_selftest.c +++ b/lib/efi_selftest/efi_selftest.c @@ -15,6 +15,8 @@ static const struct efi_runtime_services *runtime; static efi_handle_t handle; static u16 reset_message[] = L"Selftest completed"; +const efi_guid_t efi_selftest_table_guid = EFI_SELFTEST_TABLE_GUID; + /* * Exit the boot services. * @@ -25,8 +27,8 @@ static u16 reset_message[] = L"Selftest completed"; */ void efi_st_exit_boot_services(void) { - unsigned long map_size = 0; - unsigned long map_key; + unsigned long map_size = 0; + unsigned long map_key; unsigned long desc_size; u32 desc_version; efi_status_t ret; @@ -133,6 +135,41 @@ static int teardown(struct efi_unit_test *test, unsigned int *failures) return ret; } +/* + * Check that a test exists. + * + * @testname: name of the test + * @return: test + */ +static struct efi_unit_test *find_test(const u16 *testname) +{ + struct efi_unit_test *test; + + for (test = ll_entry_start(struct efi_unit_test, efi_unit_test); + test < ll_entry_end(struct efi_unit_test, efi_unit_test); ++test) { + if (!efi_st_strcmp_16_8(testname, test->name)) + return test; + } + efi_st_printf("\nTest '%ps' not found\n", testname); + return NULL; +} + +/* + * List all available tests. + */ +static void list_all_tests(void) +{ + struct efi_unit_test *test; + + /* List all tests */ + efi_st_printf("\nAvailable tests:\n"); + for (test = ll_entry_start(struct efi_unit_test, efi_unit_test); + test < ll_entry_end(struct efi_unit_test, efi_unit_test); ++test) { + efi_st_printf("'%s'%s\n", test->name, + test->on_request ? " - on request" : ""); + } +} + /* * Execute selftest of the EFI API * @@ -155,6 +192,9 @@ efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle, { struct efi_unit_test *test; unsigned int failures = 0; + const u16 *testname = NULL; + struct efi_loaded_image *loaded_image; + efi_status_t ret; systable = systab; boottime = systable->boottime; @@ -163,14 +203,47 @@ efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle, con_out = systable->con_out; con_in = systable->con_in; + ret = boottime->handle_protocol(image_handle, &efi_guid_loaded_image, + (void **)&loaded_image); + if (ret != EFI_SUCCESS) { + efi_st_error("Cannot open loaded image protocol"); + return ret; + } + + if (loaded_image->load_options) + testname = (u16 *)loaded_image->load_options; + + if (testname) { + if (!efi_st_strcmp_16_8(testname, "list") || + !find_test(testname)) { + list_all_tests(); + /* + * TODO: + * Once the Exit boottime service is correctly + * implemented we should call + * boottime->exit(image_handle, EFI_SUCCESS, 0, NULL); + * here, cf. + * https://lists.denx.de/pipermail/u-boot/2017-October/308720.html + */ + return EFI_SUCCESS; + } + } + efi_st_printf("\nTesting EFI API implementation\n"); - efi_st_printf("\nNumber of tests to execute: %u\n", - ll_entry_count(struct efi_unit_test, efi_unit_test)); + if (testname) + efi_st_printf("\nSelected test: '%ps'\n", testname); + else + efi_st_printf("\nNumber of tests to execute: %u\n", + ll_entry_count(struct efi_unit_test, + efi_unit_test)); /* Execute boottime tests */ for (test = ll_entry_start(struct efi_unit_test, efi_unit_test); test < ll_entry_end(struct efi_unit_test, efi_unit_test); ++test) { + if (testname ? + efi_st_strcmp_16_8(testname, test->name) : test->on_request) + continue; if (test->phase == EFI_EXECUTE_BEFORE_BOOTTIME_EXIT) { setup(test, &failures); execute(test, &failures); @@ -181,6 +254,9 @@ efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle, /* Execute mixed tests */ for (test = ll_entry_start(struct efi_unit_test, efi_unit_test); test < ll_entry_end(struct efi_unit_test, efi_unit_test); ++test) { + if (testname ? + efi_st_strcmp_16_8(testname, test->name) : test->on_request) + continue; if (test->phase == EFI_SETUP_BEFORE_BOOTTIME_EXIT) setup(test, &failures); } @@ -189,6 +265,9 @@ efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle, for (test = ll_entry_start(struct efi_unit_test, efi_unit_test); test < ll_entry_end(struct efi_unit_test, efi_unit_test); ++test) { + if (testname ? + efi_st_strcmp_16_8(testname, test->name) : test->on_request) + continue; if (test->phase == EFI_SETUP_BEFORE_BOOTTIME_EXIT) { execute(test, &failures); teardown(test, &failures); @@ -198,6 +277,9 @@ efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle, /* Execute runtime tests */ for (test = ll_entry_start(struct efi_unit_test, efi_unit_test); test < ll_entry_end(struct efi_unit_test, efi_unit_test); ++test) { + if (testname ? + efi_st_strcmp_16_8(testname, test->name) : test->on_request) + continue; if (test->phase == EFI_SETUP_AFTER_BOOTTIME_EXIT) { setup(test, &failures); execute(test, &failures); diff --git a/lib/efi_selftest/efi_selftest_console.c b/lib/efi_selftest/efi_selftest_console.c index 840e2290c6..6a7fd20da5 100644 --- a/lib/efi_selftest/efi_selftest_console.c +++ b/lib/efi_selftest/efi_selftest_console.c @@ -142,6 +142,7 @@ void efi_st_printf(const char *fmt, ...) const char *c; u16 *pos = buf; const char *s; + const u16 *u; va_start(args, fmt); @@ -179,9 +180,18 @@ void efi_st_printf(const char *fmt, ...) case 'p': ++c; switch (*c) { + /* MAC address */ case 'm': mac(va_arg(args, void*), &pos); break; + + /* u16 string */ + case 's': + u = va_arg(args, u16*); + /* Ensure string fits into buffer */ + for (; *u && pos < buf + 120; ++u) + *pos++ = *u; + break; default: --c; pointer(va_arg(args, void*), &pos); diff --git a/lib/efi_selftest/efi_selftest_util.c b/lib/efi_selftest/efi_selftest_util.c index 5cffe383d8..1b17bf4d4b 100644 --- a/lib/efi_selftest/efi_selftest_util.c +++ b/lib/efi_selftest/efi_selftest_util.c @@ -21,5 +21,14 @@ int efi_st_memcmp(const void *buf1, const void *buf2, size_t length) ++pos1; ++pos2; } - return EFI_ST_SUCCESS; + return 0; +} + +int efi_st_strcmp_16_8(const u16 *buf1, const char *buf2) +{ + for (; *buf1 || *buf2; ++buf1, ++buf2) { + if (*buf1 != *buf2) + return *buf1 - *buf2; + } + return 0; } From patchwork Fri Oct 13 17:33:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 825643 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yDFJl6FVHz9s7C for ; Sat, 14 Oct 2017 04:36:55 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 74A6BC22062; Fri, 13 Oct 2017 17:36:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 7BC3DC2206F; Fri, 13 Oct 2017 17:33:47 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 1CCF5C21FF6; Fri, 13 Oct 2017 17:33:39 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lists.denx.de (Postfix) with ESMTPS id 4F514C21CEC for ; Fri, 13 Oct 2017 17:33:39 +0000 (UTC) Received: from workstation4.fritz.box ([94.114.42.150]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0MTMzb-1deUXG43d9-00SOEf; Fri, 13 Oct 2017 19:33:38 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Fri, 13 Oct 2017 19:33:12 +0200 Message-Id: <20171013173314.22304-8-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171013173314.22304-1-xypron.glpk@gmx.de> References: <20171013173314.22304-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K0:K7NgcVy5ibLiWNbsehuFa6hbUSGlCWQFBJwCRXIvCMQvoIYGmPm z94Yn+FFKcNpieDG+qbMaa8tOh14RHYey6ZYb/z1/URprsCDcI9qutR7DKJSep/Oz9Q477j Sr+KUtb+nErQlpvpjzi/6TrKOyTFzE4q5v+ID6lCU7LxU0M23m05cNgOYGmHPjv6Ug0+JHJ RxWDV85D15kGYL0VmP9jQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:C5H1lbD5sJc=:QrqUsPRmLzShJnOd6JrYs5 wJvCnPV51uVuoLUan2w6xYN99vxoLFRjWYetIHOJuATP4l0FaZIliBut8qwlTP6OVwlbm6rHj +f1rUhU9eKAez7BbLN05yHHTuMS8eBTPeyk4FII/AFST/qkPwROF0B0GxbMQcSOeiXp2Qsq28 8Z0Ra+7s6ZbXVAutOhLC/jAUztzQRaPf+vp4RJlaC25/oPMeU3IjcMT/xe4e0nwtxHvEjz3Fp n6AXqdOcgPDFaoTijIJ8Iav7/ono6hvO3D69TB3Y5TaNHdie+ATDJMQvM65Z1RrnsyG6Qu4fI HjqNPnPMDFVDm+ZQIpt6F4kCGhwDyuZx72JHOm+lPcEaTIJi8PkjOGJeeaXR7I3ZHzgMdKt2+ OjNt75gYnmUva4Xn2gsk/QQRLOrt0antUBcx7KjzDETpNaThTHHtH+E+yoy1eo1RHIJTLZB5w s9scjPhSGG6Y1zsH+vd1H4SIBdEVp7NxGbk4YR8yYyzK4gVLV7yniTYeIIVB/nxGlWYWSCX97 gP1EG3FMySLX9+Uzm3U+4PP9tdRDExkUUJ1Vm9nTwyM6aXRAc+KipLPdwu67tzz8L2CFPQEQP Xtfdef+HRjFzJe/GTH4K84NfzZqOEzyASGVuvR+DsKhWwFHVw8byYBk1QXyEkaGLmgv7OFb6d PpgD9gO8GnwA7aA3//k9txIYi7aipP5GDkLXBVOM25Esvdz02m0FlRPBMIe0k5VAqN8Ec5k6u PtYQxPovmaXMg4Xb0qVY6bDUWowJFNWlWi4O/eSmbupZLxn9vKQg2vHLD9CTxr4PIslGuQDKf V2FHdHO25A3QtsCnXREqWY2w/vNjw== Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [U-Boot] [PATCH v2 7/9] efi_selftest: test reboot by watchdog X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" A test is added that verifies that the watchdog timer actually causes a reboot upon timeout. The test in only executed on request using bootefi selftest 'watchdog reboot' Signed-off-by: Heinrich Schuchardt --- v2 no change --- lib/efi_selftest/efi_selftest_watchdog.c | 65 +++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/lib/efi_selftest/efi_selftest_watchdog.c b/lib/efi_selftest/efi_selftest_watchdog.c index f8c5404000..a2c11ab1b9 100644 --- a/lib/efi_selftest/efi_selftest_watchdog.c +++ b/lib/efi_selftest/efi_selftest_watchdog.c @@ -5,11 +5,15 @@ * * SPDX-License-Identifier: GPL-2.0+ * - * This unit test checks that the watchdog timer will not cause - * a system restart during the timeout period after a timer reset. + * The 'watchdog timer' unit test checks that the watchdog timer + * will not cause a system restart during the timeout period after + * a timer reset. * - * Testing that the watchdog timer actually will reset the system - * after a timeout is not possible within the used framework. + * The 'watchdog reboot' unit test checks that the watchdog timer + * actually reboots the system after a timeout. The test is only + * executed on explicit request. Use the following command: + * + * bootefi selftest 'watchdog reboot' */ #include @@ -28,6 +32,7 @@ static struct efi_event *event_notify; static struct efi_event *event_wait; static struct efi_boot_services *boottime; static struct notify_context notification_context; +static bool watchdog_reset; /* * Notification function, increments the notfication count if parameter @@ -88,6 +93,34 @@ static int setup(const efi_handle_t handle, return EFI_ST_SUCCESS; } +/* + * Execute the test resetting the watchdog in a timely manner. No reboot occurs. + * + * @handle: handle of the loaded image + * @systable: system table + * @return: EFI_ST_SUCCESS for success + */ +static int setup_timer(const efi_handle_t handle, + const struct efi_system_table *systable) +{ + watchdog_reset = true; + return setup(handle, systable); +} + +/* + * Execute the test without resetting the watchdog. A system reboot occurs. + * + * @handle: handle of the loaded image + * @systable: system table + * @return: EFI_ST_SUCCESS for success + */ +static int setup_reboot(const efi_handle_t handle, + const struct efi_system_table *systable) +{ + watchdog_reset = false; + return setup(handle, systable); +} + /* * Tear down unit test. * @@ -146,11 +179,14 @@ static int execute(void) efi_st_error("Setting watchdog timer failed\n"); return EFI_ST_FAILURE; } + if (watchdog_reset) { /* Set 600 ms timer */ - ret = boottime->set_timer(event_notify, EFI_TIMER_PERIODIC, 6000000); - if (ret != EFI_SUCCESS) { - efi_st_error("Could not set timer\n"); - return EFI_ST_FAILURE; + ret = boottime->set_timer(event_notify, EFI_TIMER_PERIODIC, + 6000000); + if (ret != EFI_SUCCESS) { + efi_st_error("Could not set timer\n"); + return EFI_ST_FAILURE; + } } /* Set 1350 ms timer */ ret = boottime->set_timer(event_wait, EFI_TIMER_RELATIVE, 13500000); @@ -176,10 +212,19 @@ static int execute(void) return EFI_ST_SUCCESS; } -EFI_UNIT_TEST(watchdog) = { +EFI_UNIT_TEST(watchdog1) = { .name = "watchdog timer", .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, - .setup = setup, + .setup = setup_timer, + .execute = execute, + .teardown = teardown, +}; + +EFI_UNIT_TEST(watchdog2) = { + .name = "watchdog reboot", + .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT, + .setup = setup_reboot, .execute = execute, .teardown = teardown, + .on_request = true, }; From patchwork Fri Oct 13 17:33:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 825654 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yDFMd41N1z9sRW for ; Sat, 14 Oct 2017 04:39:25 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 33FEFC2205B; Fri, 13 Oct 2017 17:35:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id B42BEC21FC5; Fri, 13 Oct 2017 17:33:44 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CE83CC21FF6; Fri, 13 Oct 2017 17:33:39 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lists.denx.de (Postfix) with ESMTPS id 788B3C21F7F for ; Fri, 13 Oct 2017 17:33:39 +0000 (UTC) Received: from workstation4.fritz.box ([94.114.42.150]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0Mcxtm-1dlwf2180g-00IAy8; Fri, 13 Oct 2017 19:33:38 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Fri, 13 Oct 2017 19:33:13 +0200 Message-Id: <20171013173314.22304-9-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171013173314.22304-1-xypron.glpk@gmx.de> References: <20171013173314.22304-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K0:cJTZXNTf4dH8mahu0oilQ9hRJX45S21t7JsgFVF1LJjU85ZXWch Q94Ed7+QcHh9hSDQ8RmfaE3ztN07fApSnmgpIrcT0Ke1eJMAJzTN0NleWMiajwmtksdL0hV 3oLCywgPzGeM2QBJtIRtTZplvhE09oPJrkOMHFNjUp8PwHolJ81AXxstwyoUly55lFYoeFY NKiIA82tipK5/j06XP0/Q== X-UI-Out-Filterresults: notjunk:1; V01:K0:fnmlsxMnZdQ=:ef00TsvvMmT/K94l/B2+2F 5F2wbAA1GZ/SdOSFW1W6M5WgyqRQXk6m3t+SFPAJ7PiA/mYcIRAZBSxltOjWHcBKIw/DANtn5 2WHCK2vNAorLT6+fYAGTqF0wmomqDFlFT+Pzzgzrr1GnxSv5ho5/HlfZ3epfVSHOb7Pme7jNF 8TbMkARZuSKNOMjdkpImhHFURIfIbxYpYbld3bHiA7R8xkSScqlZpnVQwij04bq2DqspuaYwZ tE6Fck3aHdkaxvOWPnEecYUSOjL1+ATQDqU5kGNlrryX8Fyo3iImN33MV7FXqexAYV9/wBwy0 B0h0xHO4EjSJRs3yic7dfXytuPQtVOjeFIi6DbVciuvFpnmd0741jXoKG/1VJ9jHbshd9laCv IzJC+9o3oEqFLHu6HPH1OG1dUHW/VeESYSeGjwUtOlnFom65fh6gAPY3dH58Z6RCtg8izLNdh aYfb31yPAqwnD2fZ7d1sYaO8ny4PhbJI56AfZCgVz2OHwEhO8vrp3YYL0gXt7VwHIZilZYSlr gQ53S3m4bLdmQ2fX9bnUhhkpIKau5ZFBxLwqRusb30L90ricHKTgp03Yb8Qqog8k0BofUizGe gpsOHolLjdJ+kTtUJMUv1iOk42kvKknAjvQVSbPzVTYo6XQUFnlwV+M+M1/NG/bPmzSVdr40k KEEKweL7mP2dP38CxU5FmPQ8utcKYH51Hb7jJ0rmrcGQz7ggpeyAKA2gf6p8/AKkqFU9iv/i3 cMDkWm7xPrMrlq0aWrUf37894+v5nicuAUw96OkHFRvNjT8F9dPk9O66ngY+jzuJEZD61tfyO Ge/72ex7VX2VAJu5VkjtzqtVxbxLw== Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [U-Boot] [PATCH v2 8/9] test/py: test reboot by EFI watchdog X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Clear environment variable efi_selftest before executing the default tests. Provide a test verifying that the EFI watchdog reboots the system upon timeout. The test depends on CONFIG_CMD_EFI_SELFTEST=y. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- v2 choose test via environment variable --- test/py/tests/test_efi_selftest.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/py/tests/test_efi_selftest.py b/test/py/tests/test_efi_selftest.py index 76e282a6c7..66b799bed6 100644 --- a/test/py/tests/test_efi_selftest.py +++ b/test/py/tests/test_efi_selftest.py @@ -1,4 +1,3 @@ -# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. # Copyright (c) 2017, Heinrich Schuchardt # # SPDX-License-Identifier: GPL-2.0 @@ -14,6 +13,7 @@ def test_efi_selftest(u_boot_console): Run bootefi selftest """ + u_boot_console.run_command(cmd='setenv efi_selftest') u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False) m = u_boot_console.p.expect(['Summary: 0 failures', 'Press any key']) if m != 0: @@ -23,3 +23,15 @@ def test_efi_selftest(u_boot_console): if m != 0: raise Exception('Reset failed during the EFI selftest') u_boot_console.restart_uboot(); + +@pytest.mark.buildconfigspec('cmd_bootefi_selftest') +def test_efi_selftest_watchdog_reboot(u_boot_console): + u_boot_console.run_command(cmd='setenv efi_selftest list') + output = u_boot_console.run_command('bootefi selftest') + assert '\'watchdog reboot\'' in output + u_boot_console.run_command(cmd='setenv efi_selftest watchdog reboot') + u_boot_console.run_command(cmd='bootefi selftest', wait_for_prompt=False) + m = u_boot_console.p.expect(['resetting', 'U-Boot']) + if m != 0: + raise Exception('Reset failed in \'watchdog reboot\' test') + u_boot_console.restart_uboot(); From patchwork Fri Oct 13 17:33:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 825653 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yDFMX1Dmsz9sPr for ; Sat, 14 Oct 2017 04:39:19 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 5D345C22061; Fri, 13 Oct 2017 17:36:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 5953DC22069; Fri, 13 Oct 2017 17:33:48 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 324F2C21FC5; Fri, 13 Oct 2017 17:33:40 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lists.denx.de (Postfix) with ESMTPS id AADF8C21FC5 for ; Fri, 13 Oct 2017 17:33:39 +0000 (UTC) Received: from workstation4.fritz.box ([94.114.42.150]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0MC7em-1duE8Q2PNw-008vZi; Fri, 13 Oct 2017 19:33:38 +0200 From: Heinrich Schuchardt To: Alexander Graf Date: Fri, 13 Oct 2017 19:33:14 +0200 Message-Id: <20171013173314.22304-10-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171013173314.22304-1-xypron.glpk@gmx.de> References: <20171013173314.22304-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K0:LXevtlOx9mw1LeIiiTDntQqe4UUWI5aqVjnHmGKYPU+zkP1LiV4 1VQDX0OaGhe+r9rsb6/9H2Dq+YGa43fa4/L4sQr3cxrp9llMAzsmEZuSRnwTGxZjsbzGXsb EGjZDhH14SfonT7o1NK7zd4wWjrkr6Qo8oJkx/Ma+N3y0a2wAbXiXph/8RH3GBaytB4Acs4 vWxKTzhyp8oWzENWtmSaw== X-UI-Out-Filterresults: notjunk:1; V01:K0:wtx5+8ANC7I=:ldXkuPiJCSbvf/N5Ub8mxu Jnyf8zu6vpqfVs4noUazwC86fbHHmX4gMGIwyopziasH5Mspd3Cm2oGtzDIT69eKZNr2ym0HO V8jnv7/YspbXn5jVTxcDI/hX3a4DmVY89HgglV/wpExBGjdGcKq6aJ8/yWtPq68tHgxFJhBZU /BT2+B8G7GBn3H0GUiQAiOt5QroOF7O6wcYbKinpXoJDbVd29YTRnnC2FJfrBiu+z9ZKLTaFe E0Zd5FoiPqJ2vhmLe5xI+/49lZEoaZMwuwtWyF58PKJgb/RD/qiNlUMbTbmwxf8kjuZgrUMAf 7HP2tSBNhFNhdRSBzAXu8XxrNzMqWdlp++oeXKs84Uv1SqcnjbM050n2I7q9LfIV6lrZlMIHD 4iX2ugwlXRUZRhWlwDroU25EHc2gbZEwbtilH01d84lqP+yH231CzwGzIHwyBtfU41pDG4lnK mHagro4XOBuwBeKj9cXvqDMjuG3DyZBp6J69/1FrFh7A6nAYlqm5PAJa1PKGrL3qSQjSK9bDH RPEV7cmsQoI5VpuFS2ONM5yZw7h6NMUAsIrgbH7TkQZAy7zhrc2ri5P4IIV82Idf1L10ePgv1 VqBctnM2dTquM/J8KXKpyK0pDTj4LsbF/eeUJJmnWnwUwvr1DE1qo0GHwOssEz/Gp9gRiAGOo bgi3sBIBj1fJ6KG1np+0plJrFPTJG7IaaFXWrYUny/UTe0OvqpjWMDuB0VqrH5363bOqCwo6H Cq/9y2OejTXKqPFjqZeEqXz6H+IVUI9lNMgRJ/333tokxkXpnEdyLodhqie/RXSxbTEt1s5Fm jwQWoL5WM98urkxr1/iVXTjt+tz+A== Cc: u-boot@lists.denx.de, Heinrich Schuchardt Subject: [U-Boot] [PATCH v2 9/9] test/py: fix typo in test_efi_loader.py X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Make a comment line easier to read. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- v2 no change --- test/py/tests/test_efi_loader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/py/tests/test_efi_loader.py b/test/py/tests/test_efi_loader.py index 5d7f5dbfb2..4d391e13ef 100644 --- a/test/py/tests/test_efi_loader.py +++ b/test/py/tests/test_efi_loader.py @@ -12,7 +12,7 @@ import u_boot_utils """ Note: This test relies on boardenv_* containing configuration values to define -which the network environment available for testing. Without this, the parts +which network environment is available for testing. Without this, the parts that rely on network will be automatically skipped. For example: