From patchwork Wed Oct 17 07:32:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 149025 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp320631lji; Wed, 17 Oct 2018 00:33:23 -0700 (PDT) X-Google-Smtp-Source: ACcGV63RT6AGuhdmfgkxX5IWOCVQUvmmvuw0HGht9uSXUeBVtVAKCu1XmgMwG4q9IfOtxk6q0OmC X-Received: by 2002:a17:906:704f:: with SMTP id r15-v6mr26350796ejj.131.1539761603431; Wed, 17 Oct 2018 00:33:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539761603; cv=none; d=google.com; s=arc-20160816; b=XAWm9e85qZ6BRi3l4KRw5wKut4LQ/UCZAqfNX5j9n3iIpw5BciZakPx659XCxWlRC4 JQpOZcPnKi5DioChdKUX2ePNJO9I0sRhpxoHQuL6HoFiwKUmeFd8p0v3u2BsBIHZHAUI Ugf0t5OJlaPTzC6J4n3J2Vkf23yqOUzclsXwUgKsQHhDS1IbAn4V5uvz0kFK2T0lyXo9 hef888+aTCrLXptPR474uo8IqOPWiRIctBQtExiLBXSpViIwDt9w9qZZkFPkMymgzygu dAyVpxeZSASNT7nL/t9iXX0DdZKFzhVcdWhU0rOjZ7ZgsaLwy7Z/SR2RAh2qDGlg8GLd Lmaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature; bh=SUGtmM+GU54KZXF2BClAY3vtBqrCOKPwhABktzjljD4=; b=setwVWZ8nbOSv6SqRXT8e4OBuMTMI/TkP3+8wJk7oS6pCHI+AFcERPkBO+SedxmTXu WQgtIOSccoJSZQu4T1muVK2upc6S6tohV7AGiiWegVMlLl7SwgyvEYrOkQn0n69h+kBC EuVEjn35SKeu1TSfoTGK/RT7dWprL/0CCN0k9hykcH+kKQkUtIMJ8lF7hZiWfhXkz4QF hRFip69Rs+QiarT56NoWU49AYWIUXp2y0eH3LkBQlrlDRQHdiKq+3lOtFuOXYBu5vIfn hbH8tgOcUuULKEhu5BW14EQhT+66sfY+L35ycxyCAcksTtGsZaBBVpnUGPSJiJcON6hn +wrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=AtIhtZJk; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id s25-v6si1240621edb.140.2018.10.17.00.33.23; Wed, 17 Oct 2018 00:33:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=AtIhtZJk; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 146CFC21DED; Wed, 17 Oct 2018 07:31:39 +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 BA174C21DEC; Wed, 17 Oct 2018 07:31:04 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id ADC9EC21DC1; Wed, 17 Oct 2018 07:30:54 +0000 (UTC) Received: from mail-yw1-f68.google.com (mail-yw1-f68.google.com [209.85.161.68]) by lists.denx.de (Postfix) with ESMTPS id AA809C21DA1 for ; Wed, 17 Oct 2018 07:30:53 +0000 (UTC) Received: by mail-yw1-f68.google.com with SMTP id y76-v6so9965933ywd.2 for ; Wed, 17 Oct 2018 00:30:53 -0700 (PDT) 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=TaPaBTRsI5Dfd+5bd7Ffv6M2gRZhpKyQhJO3MdZsXhs=; b=AtIhtZJkEaEzxwRMS6bXsMzgQpTLBhwBPHkUzuS7mn9rqIRoCbtt9+KHvVNfzcaImi xlF98GiPcvyN8QP3izlAiHKOhQbSgpztpxuEQhkeGC+X7pf7FYlzYb76heiuC4cOx1Ia tqr2RmEqdw4hb3KdnUxs2l4eHdME8te691ySE= 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=TaPaBTRsI5Dfd+5bd7Ffv6M2gRZhpKyQhJO3MdZsXhs=; b=XE6NRnFNmkbFoDKxEDFyyvcU3DEvaTyRvSe6U4wcKuUEpDBk0LMX1yLZLdPPdQZfU0 Apmapx7wgQMl/upJeL66sT+gajZ2pwKf02VHh9yL92USZNdbaObxlO9HNz6bXe3pOn6I 1IqbNlBpnG9KiPbUQMmC+RrFvK8t7hcgNL32J6/AQ1pasdUsMIkObNsZ7jsLSysmuUEp P/pCE2RCmcSe7ukiJF64+b3G8bw88+OMlqL3NGRFqXpm3/D4M4K8gKWWmQm4eOdMyIQ0 O7CojFe39JoJr3Y114a5nIZcHLbYEA6MyVf/H7sjnktBe9/tjunlnfacPNuqZi/KDBip N6sw== X-Gm-Message-State: ABuFfoipBtwqIMHiCLnmuHgSX2OB6pNNHmCxF9oNl0tTtGcMmwLJrQCo 3JKCzu5+RuqE6bQJv1JCJQngwVPB4xQ= X-Received: by 2002:a81:560a:: with SMTP id k10-v6mr13010379ywb.80.1539761452569; Wed, 17 Oct 2018 00:30:52 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id y1-v6sm3968156ywf.34.2018.10.17.00.30.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Oct 2018 00:30:51 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de Date: Wed, 17 Oct 2018 16:32:06 +0900 Message-Id: <20181017073207.13150-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181017073207.13150-1-takahiro.akashi@linaro.org> References: <20181017073207.13150-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 5/6] 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 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index b3e2845120fe..5772f7422e5f 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -349,6 +349,31 @@ static efi_status_t efi_install_fdt(ulong fdt_addr) return ret; } +static 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 * @@ -516,7 +541,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(); @@ -532,21 +556,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; @@ -564,6 +573,9 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) struct efi_loaded_image_obj *image_handle; 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, @@ -593,7 +605,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]; @@ -602,6 +617,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);