From patchwork Thu Jun 14 16:55: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: 929586 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="kKQSBiGu"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 4168wG2ZSKz9ryk for ; Fri, 15 Jun 2018 02:58:54 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 03620C21DEC; Thu, 14 Jun 2018 16:58:20 +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=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 2509EC21E56; Thu, 14 Jun 2018 16:56:03 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D9A35C21E56; Thu, 14 Jun 2018 16:55:45 +0000 (UTC) Received: from mail-io0-f173.google.com (mail-io0-f173.google.com [209.85.223.173]) by lists.denx.de (Postfix) with ESMTPS id 434FAC21E30 for ; Thu, 14 Jun 2018 16:55:39 +0000 (UTC) Received: by mail-io0-f173.google.com with SMTP id l25-v6so7789324ioh.12 for ; Thu, 14 Jun 2018 09:55:39 -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=Lk8BFQ2QulNjoAKisSdGh9K93F5yvdmKx60vJmzCF7g=; b=kKQSBiGuB5CnoF0fx1BKpL55M4mfyoqy/LjRX9oADh1XuVs4rxKPTAo+kRRL0+WW26 nUVI+dq99Vfup9foCNf9p71weLKb907VmvhfwFzF8FRLrmnr7+UCdPZ0t9FUZdl8UO63 8OINyOTz9MqHKSe5ufa8KZ2zFCxxMVPRbcPbEOni0xnqRr49M1zsHsxuk/zciF1BPKdI iMiW4BCnyL3yj7CUagsbTvI/d2cMFZfmQjlwObyWCyVV3zGo/vK0Y6UvaJG7ETirQ7ge yyFIfaPil5CrzLf16XOrAuWAE9J/WHRvVlZvY6Usj5suBIR5VmbSKZrKC5V1+8Z5bbnk 5dQw== 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=Lk8BFQ2QulNjoAKisSdGh9K93F5yvdmKx60vJmzCF7g=; b=nSo6aVGVEbCCcWICsrTUlYRl+zJwbHuhWN9BxjrdyqHL5Rpj+vLIxIIs62AFzBycKD uL/GL6SKMftAnC9ff/VAg4DS+DfH4omtUhLP2FSSaHa+BitAKAAkQXeIJ97o2DnBx767 nujAbuaL8xjWeTNF5zyuSFLmb3gx6CFJeibEk2Fa+oeeGXfukDg7n0Mvw/Rod+ZtM3lJ SCHw2O31EGaH+Y168yjtbxp/Z6RHD90pO11wPkx/XALYdWsQLwXVN5j0RJbwoACq1fue NhsGSNIO0Sv/c7C9l+Yutau70ajITLawk5mOEMlXjiGMYr6SbMZ77O9YM1MsB0N2mufb Xfjw== X-Gm-Message-State: APt69E1Qo6nf+2J9D1EBRHX9pYpMk7nMUomwHanc6urp1vmc0eVAiAF3 xdZzIIDz+A2vcZEDSQ5Qh2Cs2A== X-Google-Smtp-Source: ADUXVKLdh8L06G+e2mKtW4XWNEZ4A6yFVvO4VPpWH1oyxuoEBGdPIlerco7n99f3jk6zNJA6RaF4UQ== X-Received: by 2002:a6b:ea01:: with SMTP id m1-v6mr2955221ioc.210.1528995337664; Thu, 14 Jun 2018 09:55:37 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id k16-v6sm2041900iog.45.2018.06.14.09.55.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Jun 2018 09:55:35 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 547ED140484; Thu, 14 Jun 2018 10:55:32 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Thu, 14 Jun 2018 10:55:24 -0600 Message-Id: <20180614165526.183597-10-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 09/10] efi: Create a function to set up for running EFI 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" Add a new bootefi_run_prepare() function which holds common code used to set up U-Boot to run EFI code. Make use of this from the existing bootefi_test_prepare() function, as well as do_bootefi_exec(). Also shorten a few variable names. 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() - Introduce load_options_path to specifyc U-Boot env var for load_options_path Changes in v4: - Rebase to master Changes in v3: - Add patch to create a function to set up for running EFI code Changes in v2: None cmd/bootefi.c | 79 ++++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 36 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index ac80074bc4..b9eb04531b 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -253,6 +253,26 @@ static efi_status_t efi_install_fdt(void *fdt) return ret; } +static efi_status_t bootefi_run_prepare(struct efi_loaded_image *image, + struct efi_object *obj, + const char *load_options_path, + struct efi_device_path *device_path, + struct efi_device_path *image_path) +{ + efi_setup_loaded_image(image, obj, device_path, 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 as load options */ + set_load_options(image, load_options_path); + + return 0; +} + /* * Load an EFI payload into a newly allocated piece of memory, register all * EFI objects it would want to access and jump to it. @@ -261,8 +281,8 @@ static efi_status_t do_bootefi_exec(void *efi, struct efi_device_path *device_path, struct efi_device_path *image_path) { - struct efi_loaded_image loaded_image_info = {}; - struct efi_object loaded_image_info_obj = {}; + struct efi_loaded_image image; + struct efi_object obj; struct efi_device_path *memdp = NULL; efi_status_t ret; @@ -283,19 +303,13 @@ static efi_status_t do_bootefi_exec(void *efi, assert(device_path && image_path); } - efi_setup_loaded_image(&loaded_image_info, &loaded_image_info_obj, - device_path, image_path); + ret = bootefi_run_prepare(&image, &obj, "bootargs", device_path, + image_path); + if (ret) + return ret; - /* - * 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 bootargs as load options */ - set_load_options(&loaded_image_info, "bootargs"); /* Load the EFI payload */ - entry = efi_load_pe(efi, &loaded_image_info); + entry = efi_load_pe(efi, &image); if (!entry) { ret = EFI_LOAD_ERROR; goto exit; @@ -303,10 +317,10 @@ static efi_status_t do_bootefi_exec(void *efi, if (memdp) { struct efi_device_path_memory *mdp = (void *)memdp; - mdp->memory_type = loaded_image_info.image_code_type; - mdp->start_address = (uintptr_t)loaded_image_info.image_base; + mdp->memory_type = image.image_code_type; + mdp->start_address = (uintptr_t)image.image_base; mdp->end_address = mdp->start_address + - loaded_image_info.image_size; + image.image_size; } /* we don't support much: */ @@ -316,8 +330,8 @@ static efi_status_t do_bootefi_exec(void *efi, /* Call our payload! */ debug("%s:%d Jumping to 0x%lx\n", __func__, __LINE__, (long)entry); - if (setjmp(&loaded_image_info.exit_jmp)) { - ret = loaded_image_info.exit_status; + if (setjmp(&image.exit_jmp)) { + ret = image.exit_status; goto exit; } @@ -329,7 +343,7 @@ static efi_status_t do_bootefi_exec(void *efi, /* Move into EL2 and keep running there */ armv8_switch_to_el2((ulong)entry, - (ulong)&loaded_image_info_obj.handle, + (ulong)&obj.handle, (ulong)&systab, 0, (ulong)efi_run_in_el2, ES_TO_AARCH64); @@ -338,11 +352,11 @@ static efi_status_t do_bootefi_exec(void *efi, } #endif - ret = efi_do_enter(loaded_image_info_obj.handle, &systab, entry); + ret = efi_do_enter(obj.handle, &systab, entry); exit: /* image has returned, loaded-image obj goes *poof*: */ - list_del(&loaded_image_info_obj.link); + list_del(&obj.link); return ret; } @@ -358,11 +372,13 @@ exit: * @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 + * @load_options_path: U-Boot environment variable to use as load options * @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) + const char *path, ulong test_func, + const char *load_options_path) { memset(image, '\0', sizeof(*image)); memset(obj, '\0', sizeof(*obj)); @@ -371,18 +387,8 @@ static efi_status_t bootefi_test_prepare(struct efi_loaded_image *image, (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; + return bootefi_run_prepare(image, obj, load_options_path, + bootefi_device_path, bootefi_image_path); } /** @@ -481,7 +487,7 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) int ret; if (bootefi_test_prepare(&image, &obj, "\\test", - (ulong)&efi_test)) + (ulong)&efi_test, "efi_test")) return CMD_RET_FAILURE; ret = efi_test(&image, &systab); @@ -497,7 +503,8 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) #ifdef CONFIG_CMD_BOOTEFI_SELFTEST if (!strcmp(argv[1], "selftest")) { if (bootefi_test_prepare(&image, &obj, "\\selftest", - (uintptr_t)&efi_selftest)) + (uintptr_t)&efi_selftest, + "efi_selftest")) return CMD_RET_FAILURE; /* Execute the test */