From patchwork Wed Jun 13 02:37:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 928624 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="d0Z1q54a"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 4159xK5xGcz9s1B for ; Wed, 13 Jun 2018 12:41:25 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 4DD58C21CB1; Wed, 13 Jun 2018 02:38:50 +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_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 21A77C21D72; Wed, 13 Jun 2018 02:38:02 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9C9DFC21DEC; Wed, 13 Jun 2018 02:37:50 +0000 (UTC) Received: from mail-it0-f51.google.com (mail-it0-f51.google.com [209.85.214.51]) by lists.denx.de (Postfix) with ESMTPS id 98B61C21D83 for ; Wed, 13 Jun 2018 02:37:46 +0000 (UTC) Received: by mail-it0-f51.google.com with SMTP id v83-v6so1951959itc.3 for ; Tue, 12 Jun 2018 19:37:46 -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=ezMgtiKts2JExp+cMdT75+FoAvPM1fXZ9Ygg6cb/Kmc=; b=d0Z1q54a+VpXcsziJK0KQDm0GhGXjsm6VsVNcb5Q6mljS0N8PAi8V3Ft9m/6+n+z9X o0lOeEztfnOuTvh9i5Kgm4YXmpgYyQ0/b/7TYPTD1GtjUlyIzVWphAPlYSL+FEch/Kht 8bXytIccbButjuER8i3aOziqfM0JHuwtnG11t/kBXOUKkmIxv7FxBPaHUxkHSnormOCw jc6Sa/bhopuDL54yCiHNwRxu6O+N2qkTgWapQ/VX6olP8lF0BYnKQUc1MhCOIwEVlDlT KPICPYkV216//BEHGJbVu5CvDeFAp4vDWAMFeKjVhxQVAPoTHs3L0rtrgRIAgE0t9uDE cOvg== 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=ezMgtiKts2JExp+cMdT75+FoAvPM1fXZ9Ygg6cb/Kmc=; b=Hq3uMaeQYiiYlwLJDad3bKBUwlXENaMgXExHGjL92HF6auSwxhjR4r93RiLxUk4HHe rzMUVuME+nhlZsKMr+ZSwSS1iIRRTJ93F8aF7ii3rtYguulk+bvx4nTMzaKO8ey+bQRo 40aDicORRP9387taBgVINL6a0XBMdzkdnD3O8XWAt6ppEf/T8BOJ80bU9qDTxhVAs7PT sIjM9qv0hzVeJ4UvwMN09Ep81T4SRcmXO6Z0SfXH1ZKVoAi4l/Oq1HA5yqiROhlYuqPm JCvbzqBn2MtBgtQ3AE9GxhFctdLPg2XZ6NxXvr+pCo9yN8rHsAZMcglbBJ2ekBdGhbbW O7Mg== X-Gm-Message-State: APt69E0S9JQ/uf57NWinzkVm28FJCUw7hOBvjMwv6D/t23bLa2aEMyH2 LBWhvnLof+wOpIc4CrLp8iF1ig== X-Google-Smtp-Source: ADUXVKJITb4Bx5m3/QDlqG4tjZwonJA+OkhvVP24Yk25x4BynrL1y7vS6mEWGzrwFl9FT0iTxhceIw== X-Received: by 2002:a24:4516:: with SMTP id y22-v6mr2945782ita.109.1528857464875; Tue, 12 Jun 2018 19:37:44 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id x16-v6sm928413ith.6.2018.06.12.19.37.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jun 2018 19:37:43 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 00E2514153C; Tue, 12 Jun 2018 20:37:42 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 12 Jun 2018 20:37:24 -0600 Message-Id: <20180613023728.202173-10-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog In-Reply-To: <20180613023728.202173-1-sjg@chromium.org> References: <20180613023728.202173-1-sjg@chromium.org> Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v6 09/13] 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 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