From patchwork Wed May 16 15:42:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 914705 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="eJOCj0Rd"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40mJhR54fSz9s33 for ; Thu, 17 May 2018 01:46:47 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 603FAC21FC0; Wed, 16 May 2018 15:45:27 +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=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID 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 97BCDC21F8E; Wed, 16 May 2018 15:43:35 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CD94BC21FDA; Wed, 16 May 2018 15:43:10 +0000 (UTC) Received: from mail-it0-f44.google.com (mail-it0-f44.google.com [209.85.214.44]) by lists.denx.de (Postfix) with ESMTPS id A6884C21FAD for ; Wed, 16 May 2018 15:43:04 +0000 (UTC) Received: by mail-it0-f44.google.com with SMTP id 70-v6so3119096ity.2 for ; Wed, 16 May 2018 08:43:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=DBi/N6eMcMBxUdwqB//G7w4Xg4krb8guFT1IYmonWno=; b=eJOCj0RdV+62Cz8cqvzWVI0ifFkZGW7aUswRHQ1P9wjxof1U5NrjLLNnn/lTSaHj/i bEjFgrEYdgfzzDSnkNOMfqepsna79mTVWV1+eMkPhQ3lu+AfhS0EENvN1VkRCfmA+zSH iqiW7Re/kdHTAr7IanaDMqM1b8aLKmeAZTlzV36rRbMrkqzKrZt4zy3/bcP8fbiq8eKA ZI4hsQFxIwMNLGq0OSLhBsF1502ziynxkkQUQC+ilnJMzLuIhqaiUK8WQ9wPJYjTgDl9 2gXERdsUV8advEFcle4NvK4RXn4wKudktHbjB0RIgRMh9rc/uE5KwNgqPjM76OHqmdTb Dcnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=DBi/N6eMcMBxUdwqB//G7w4Xg4krb8guFT1IYmonWno=; b=czQuLhr7zy1JSdcCU4b4j6iM8dJtstZRxrrLUjgcJFqtIuo6ZcLeT/XmpPBmh+j0ki PrLaHEp1p8R64uZeqaS4fyx35k5efczQDfStYZccDDczsLGHx90Sqd0tRK0Us8ufaEL4 STiMKsvzgHbKrGswvP9KH0/A24qL1042gaZ6oSS63h7DE9of9UO/H4G7mnqBMsmAWZjs KsfjODODDwgSa8YS5V/u7HztVO0GkuPBCESQtd66MVc0idi9djyEx169ombL6BeuJ0Cz nu3oCZF6801jNbOKoE+4j+pftbzVdPM+JzniHTjKxhJAv8+yF6gla72rqnjz5eD8ZQwY dAtw== X-Gm-Message-State: ALKqPwcHCsTUFWHpQAPy6m+tYUw/lvCRhRwdkWJHZzwv8GxoENuDUF4e Sf4cly5ed71ozWBQDE2lRT6kVA== X-Google-Smtp-Source: AB8JxZpU2bbIagyF2pHh+ohdUOJzT/tygCtLP6T+c1XgE/fkhS2vccdzW2mbx4/oENDHB7sx6IsDcQ== X-Received: by 2002:a24:42c6:: with SMTP id i189-v6mr1490893itb.73.1526485383159; Wed, 16 May 2018 08:43:03 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id k14-v6sm1608597iok.10.2018.05.16.08.43.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 May 2018 08:43:02 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 433B4140474; Wed, 16 May 2018 09:43:02 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Wed, 16 May 2018 09:42:30 -0600 Message-Id: <20180516154233.21457-14-sjg@chromium.org> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog In-Reply-To: <20180516154233.21457-1-sjg@chromium.org> References: <20180516154233.21457-1-sjg@chromium.org> Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v4 13/16] efi: Split out test init/uninit into functions 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" We plan to run more than one EFI test. In order to avoid duplicating code, create functions which handle preparing for running the test and cleaning up afterwards. Also shorten the awfully long variable names here. Signed-off-by: Simon Glass --- Changes in v4: None Changes in v3: - Add new patch to split out test init/uninit into functions Changes in v2: None cmd/bootefi.c | 93 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 26 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 11b84c55289..9bcdf8bdc48 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -335,6 +335,64 @@ exit: return ret; } +#ifdef CONFIG_CMD_BOOTEFI_SELFTEST +/** + * bootefi_test_prepare() - prepare to run an EFI test + * + * This sets things up so we can call EFI functions. This involves preparing + * the 'gd' pointer and setting up the load ed image data structures. + * + * @image: Pointer to a struct which will hold the loaded image info + * @obj: Pointer to a struct which will hold the loaded image object + * @path: File path to the test being run (often just the test name with a + * backslash before it + * @test_func: Address of the test function that is being run + * @return 0 if OK, -ve on error + */ +static efi_status_t bootefi_test_prepare(struct efi_loaded_image *image, + struct efi_object *obj, + const char *path, ulong test_func) +{ + efi_status_t ret; + + memset(image, '\0', sizeof(*image)); + memset(obj, '\0', sizeof(*obj)); + /* Construct a dummy device path */ + bootefi_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, + test_func, test_func); + bootefi_image_path = efi_dp_from_file(NULL, 0, path); + efi_setup_loaded_image(image, obj, bootefi_device_path, + bootefi_image_path); + /* + * 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(); + /* Initialize and populate our EFI object list */ + ret = efi_init_obj_list(); + if (ret) + return ret; + /* Transfer environment variable efi_selftest as load options */ + set_load_options(image, "efi_selftest"); + + return 0; +} + +/** + * bootefi_test_finish() - finish up after running an EFI test + * + * @image: Pointer to a struct which holds the loaded image info + * @obj: Pointer to a struct which holds the loaded image object + */ +static void bootefi_test_finish(struct efi_loaded_image *image, + struct efi_object *obj) +{ + efi_restore_gd(); + free(image->load_options); + list_del(&obj->link); +} +#endif /* CONFIG_CMD_BOOTEFI_SELFTEST */ + static int do_bootefi_bootmgr_exec(void) { struct efi_device_path *device_path, *file_path; @@ -410,33 +468,16 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) #endif #ifdef CONFIG_CMD_BOOTEFI_SELFTEST if (!strcmp(argv[1], "selftest")) { - struct efi_loaded_image loaded_image_info = {}; - struct efi_object loaded_image_info_obj = {}; - - /* Construct a dummy device path. */ - bootefi_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, - (uintptr_t)&efi_selftest, - (uintptr_t)&efi_selftest); - bootefi_image_path = efi_dp_from_file(NULL, 0, "\\selftest"); - - efi_setup_loaded_image(&loaded_image_info, - &loaded_image_info_obj, - bootefi_device_path, bootefi_image_path); - /* - * 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(); - /* Initialize and populate EFI object list */ - efi_init_obj_list(); - /* Transfer environment variable efi_selftest as load options */ - set_load_options(&loaded_image_info, "efi_selftest"); + struct efi_loaded_image image; + struct efi_object obj; + + if (bootefi_test_prepare(&image, &obj, "\\test", + (uintptr_t)&efi_selftest)) + return CMD_RET_FAILURE; + /* Execute the test */ - r = efi_selftest(loaded_image_info_obj.handle, &systab); - efi_restore_gd(); - free(loaded_image_info.load_options); - list_del(&loaded_image_info_obj.link); + r = efi_selftest(obj.handle, &systab); + bootefi_test_finish(&image, &obj); return r != EFI_SUCCESS; } else #endif