From patchwork Mon Nov 5 09:06:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 992955 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=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="N6K3XLDt"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 42pRnW2s9Qz9sB5 for ; Mon, 5 Nov 2018 20:14:07 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 18065C2221A; Mon, 5 Nov 2018 09:07: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=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 99EB8C221FB; Mon, 5 Nov 2018 09:06:54 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0D178C22229; Mon, 5 Nov 2018 09:05:17 +0000 (UTC) Received: from mail-yb1-f196.google.com (mail-yb1-f196.google.com [209.85.219.196]) by lists.denx.de (Postfix) with ESMTPS id AF6AAC22205 for ; Mon, 5 Nov 2018 09:05:13 +0000 (UTC) Received: by mail-yb1-f196.google.com with SMTP id h187-v6so1142502ybg.10 for ; Mon, 05 Nov 2018 01:05:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lel+yNRURJUJ/dF4EwEoLObz3vXjOlgvG3SBirZfMzg=; b=N6K3XLDtFgSKnYQ79MlOP7VkhPKH4AbqhiVteX7bgDP/lAL6gq4+ecMmheqo9mleHH RzHe5XNuct2yNrAnjxNb0MxDX1TrfJRaC7hxSJwm9XC37wkqY/k0VB3XvLRcsFbAM2eI 78Yj2bRFBAoCE7TNMrB5yxIPNrWJNU/UZm/Xs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lel+yNRURJUJ/dF4EwEoLObz3vXjOlgvG3SBirZfMzg=; b=eCRJ5lJNqhTL4ezVvrc5xZkW4yPIYEalHOZ7qjqgf3ZJDgWC5U/95sw3gPvaGPNMeE oCDpQwss1lpTosCLUfxoaIZTA6O7mJ1a3aRa1PaxkLIlM+CGb2zAsGIf80MX4BeXChSd AL4Gywo6pb2/DxeSUIGJMp4MY46wsRriUl2xRu0FjrnehSagfoPqrtLPcw8Y1Y0A0D+V Vwhx/A3JeR7CbtUFaSYoQm+UCLqiJHtWQLsxLaYJaUE7WeOwMKn0qiYfoooV2pX7nJ7+ kDEQbB3zSfte5IFAHPl7mmZLR4CIv0+XIncTcifREfXwNktA4szrZObNe/MlcH75JCaS zxiw== X-Gm-Message-State: AGRZ1gIi3qedghDNHq2AhM5Tvo6/7kuR6+/nGRZz8FTEWb2oIAQ4CjaX 5jRRp4uxcRvonPO5yP+YOReBcA== X-Google-Smtp-Source: AJdET5d3DClxqe5kntEbOb0fzd7e+iKl7pVfMCJVKlqf+lvcvreB5yR0gRYCRdPzYm1lvV5MR0NGLQ== X-Received: by 2002:a25:3fc5:: with SMTP id m188-v6mr21199524yba.359.1541408712520; Mon, 05 Nov 2018 01:05:12 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id m16-v6sm20515574ywh.18.2018.11.05.01.05.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 01:05:12 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de Date: Mon, 5 Nov 2018 18:06:49 +0900 Message-Id: <20181105090653.7409-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181105090653.7409-1-takahiro.akashi@linaro.org> References: <20181105090653.7409-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: xypron.glpk@gmx.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 10/14] cmd: bootefi: carve out fdt parameter handling 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The current way how command parameters, particularly "fdt addr," are handled makes it a bit complicated to add a subcommand-specific parameter. So just refactor the code and extract efi_handle_fdt(). This commit is a preparatory change for enhancing bootmgr sub-command. Signed-off-by: AKASHI Takahiro --- cmd/bootefi.c | 51 +++++++++++++++++++++++++++++++++----------------- cmd/efishell.h | 1 + 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 5d61819f1f5c..3aedf5a09f93 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -356,6 +356,31 @@ static efi_status_t efi_install_fdt(ulong fdt_addr) return ret; } +int efi_handle_fdt(char *fdt_opt) +{ + unsigned long fdt_addr; + efi_status_t r; + + if (fdt_opt) { + fdt_addr = simple_strtoul(fdt_opt, NULL, 16); + if (!fdt_addr && *fdt_opt != '0') + return CMD_RET_USAGE; + + /* Install device tree */ + r = efi_install_fdt(fdt_addr); + if (r != EFI_SUCCESS) { + printf("ERROR: failed to install device tree\n"); + return CMD_RET_FAILURE; + } + } else { + /* Remove device tree. EFI_NOT_FOUND can be ignored here */ + efi_install_configuration_table(&efi_guid_fdt, NULL); + printf("WARNING: booting without device tree\n"); + } + + return CMD_RET_SUCCESS; +} + /** * do_bootefi_exec() - execute EFI binary * @@ -511,7 +536,6 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) unsigned long addr; char *saddr; efi_status_t r; - unsigned long fdt_addr; /* Allow unaligned memory access */ allow_unaligned(); @@ -527,21 +551,6 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (argc < 2) return CMD_RET_USAGE; - if (argc > 2) { - fdt_addr = simple_strtoul(argv[2], NULL, 16); - if (!fdt_addr && *argv[2] != '0') - return CMD_RET_USAGE; - /* Install device tree */ - r = efi_install_fdt(fdt_addr); - if (r != EFI_SUCCESS) { - printf("ERROR: failed to install device tree\n"); - return CMD_RET_FAILURE; - } - } else { - /* Remove device tree. EFI_NOT_FOUND can be ignored here */ - efi_install_configuration_table(&efi_guid_fdt, NULL); - printf("WARNING: booting without device tree\n"); - } #ifdef CONFIG_CMD_BOOTEFI_HELLO if (!strcmp(argv[1], "hello")) { ulong size = __efi_helloworld_end - __efi_helloworld_begin; @@ -559,6 +568,9 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) struct efi_loaded_image_obj *image_obj; struct efi_loaded_image *loaded_image_info; + if (efi_handle_fdt(argc > 2 ? argv[2] : NULL)) + return CMD_RET_FAILURE; + /* Construct a dummy device path. */ bootefi_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, (uintptr_t)&efi_selftest, @@ -583,7 +595,10 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } else #endif if (!strcmp(argv[1], "bootmgr")) { - return do_bootefi_bootmgr_exec(); + if (efi_handle_fdt(argc > 2 ? argv[2] : NULL)) + return CMD_RET_FAILURE; + + return do_bootefi_bootmgr_exec(boot_id); } else { saddr = argv[1]; @@ -592,6 +607,8 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (!addr && *saddr != '0') return CMD_RET_USAGE; + if (efi_handle_fdt(argc > 2 ? argv[2] : NULL)) + return CMD_RET_FAILURE; } printf("## Starting EFI application at %08lx ...\n", addr); diff --git a/cmd/efishell.h b/cmd/efishell.h index 6f70b402b26b..1e5764a8a38d 100644 --- a/cmd/efishell.h +++ b/cmd/efishell.h @@ -3,3 +3,4 @@ #include efi_status_t efi_init_obj_list(void); +int efi_handle_fdt(char *fdt_opt);