From patchwork Thu Jun 14 16:55:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 929587 X-Patchwork-Delegate: sjg@chromium.org 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="GywnVWNy"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 4168wX40Xkz9ryk for ; Fri, 15 Jun 2018 02:59:08 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 354A6C21DEC; Thu, 14 Jun 2018 16:57:28 +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_MSPIKE_H2, 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 2E85BC21E0F; Thu, 14 Jun 2018 16:55:47 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 31901C21E2F; Thu, 14 Jun 2018 16:55:40 +0000 (UTC) Received: from mail-io0-f180.google.com (mail-io0-f180.google.com [209.85.223.180]) by lists.denx.de (Postfix) with ESMTPS id 5515AC21DF3 for ; Thu, 14 Jun 2018 16:55:36 +0000 (UTC) Received: by mail-io0-f180.google.com with SMTP id d22-v6so7800873iof.13 for ; Thu, 14 Jun 2018 09:55:36 -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=4GYumHRYOhzUkBvSOV51QHLPIMmBSzISiVwDSrxV9b0=; b=GywnVWNyy+UWcEjj9r5Ja949+8dNgZqNM9qAMvbMk4S0MGfDTgJN83H+oYHrR5k4Xk D8WP3xX8WyugU/RNiSwpQcYlYXV3QQ8uWGfFo7QwZcaWMZzThfvvz8lRahuKsVS6pliU IYvCCFice4sfyiNRSr03ZV1FCJnAEG075/hy7cnahg7PtZejsYlOz4lSPuSnNzjJs3mt FNvcLVjfCJZG2giwAVcLd0pnHLwzLnlOwsXa8Y6El8J340Ham5uiyTYOJnBV0Ug8GvFR Pd0+VhuO/JvaSfXj0sTTPRKhM8Y40AtW3KqbPgFTnV3+7CZNquAcodD8/863XB9eHu+e uncA== 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=4GYumHRYOhzUkBvSOV51QHLPIMmBSzISiVwDSrxV9b0=; b=dNS2g1yEKHpjlK8X0FE3iQaazqGZD2cZZS4nABjQ1vGPD870n1FIbyoC9JIGOCf9LY COsOHKZk9uSWh9j4WOWzt6imkk7Rw9BNW4/7XWoKGOHXoT2u2x4ZDHI38qbD9FiMyNZ0 h4OYMdcHANZu+9Yhd5NB6zlM2nW8zz9WU4vYxNpa1sfGyJW70eYHvVzUECdXd+v8zNfU R37dVIju6ngeiiL/tae1jIxTS0K2M+VEvdWxOvMli/FU3DvQUJUiDK80lor5x1F0J0Y7 5Gr4NaB+URbKnPmBhmleDyqPUWVJg4foztlG40ppQhUV0KNBoF98qgJR1XP7ArKZzRPU aYwQ== X-Gm-Message-State: APt69E1iD6O6r30ObG6ltf1yJ9Qy18IkGK8e90dCfl7HaLP+2t2nTvTQ cqFMTwNWqh9w/Xc6q4PofEazTw== X-Google-Smtp-Source: ADUXVKL7tR1Oa9+3ViDyXk/A3vITsMJXhl40AeOwIhPVgoTwFKYxp+6IF/U538kBgu9QBj4B9cLCtw== X-Received: by 2002:a6b:17c7:: with SMTP id 190-v6mr2839758iox.17.1528995334704; Thu, 14 Jun 2018 09:55:34 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id y64-v6sm3026282itb.33.2018.06.14.09.55.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Jun 2018 09:55:32 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 45114140C16; Thu, 14 Jun 2018 10:55:31 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Thu, 14 Jun 2018 10:55:22 -0600 Message-Id: <20180614165526.183597-8-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog In-Reply-To: <20180614165526.183597-1-sjg@chromium.org> References: <20180614165526.183597-1-sjg@chromium.org> Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v7 07/10] 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 v7: None Changes in v6: None Changes in v5: - Drop call to efi_init_obj_list() which is now done in do_bootefi() 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 | 87 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 24 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 707d159bac..a9ebde0c75 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -347,6 +347,60 @@ 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) +{ + 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, + (uintptr_t)test_func, + (uintptr_t)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(); + + /* 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; @@ -425,31 +479,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(); - /* 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, "\\selftest", + (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