From patchwork Wed Feb 12 10:37:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frieder Schrempf X-Patchwork-Id: 1236759 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=kontron.de Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48HbgR3pHRz9sPJ for ; Wed, 12 Feb 2020 21:37:23 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 29DFB8185A; Wed, 12 Feb 2020 11:37:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=kontron.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id F162181850; Wed, 12 Feb 2020 11:37:14 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_00,SORTED_RECIPS, SPF_HELO_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from skedge03.snt-world.com (skedge03.snt-world.com [91.208.41.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 945F38179D for ; Wed, 12 Feb 2020 11:37:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=kontron.de Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=frieder.schrempf@kontron.de Received: from sntmail12r.snt-is.com (unknown [10.203.32.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by skedge03.snt-world.com (Postfix) with ESMTPS id E11D067A5A7; Wed, 12 Feb 2020 11:37:11 +0100 (CET) Received: from sntmail12r.snt-is.com (10.203.32.182) by sntmail12r.snt-is.com (10.203.32.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1913.5; Wed, 12 Feb 2020 11:37:11 +0100 Received: from sntmail12r.snt-is.com ([fe80::e551:8750:7bba:3305]) by sntmail12r.snt-is.com ([fe80::e551:8750:7bba:3305%3]) with mapi id 15.01.1913.005; Wed, 12 Feb 2020 11:37:11 +0100 From: Schrempf Frieder To: Abhishek Shah , Ben Wolsieffer , Schrempf Frieder , Joe Hershberger , Leon Yu , =?iso-8859-1?q?Marek_Beh=FAn?= , Patrice Chotard , Patrick Delaunay , "Simon Glass" Subject: [PATCH v4 2/2] pxe: Get default selection from board type if label matches Thread-Topic: [PATCH v4 2/2] pxe: Get default selection from board type if label matches Thread-Index: AQHV4ZBh1qFtG226fE2LxCmkXdCUsg== Date: Wed, 12 Feb 2020 10:37:11 +0000 Message-ID: <20200212103629.12746-2-frieder.schrempf@kontron.de> References: <20200212103629.12746-1-frieder.schrempf@kontron.de> In-Reply-To: <20200212103629.12746-1-frieder.schrempf@kontron.de> Accept-Language: de-DE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.17.1 x-originating-ip: [172.25.9.193] x-c2processedorg: 51b406b7-48a2-4d03-b652-521f56ac89f3 MIME-Version: 1.0 X-SnT-MailScanner-Information: Please contact the ISP for more information X-SnT-MailScanner-ID: E11D067A5A7.AFA8B X-SnT-MailScanner: Not scanned: please contact your Internet E-Mail Service Provider for details X-SnT-MailScanner-SpamCheck: X-SnT-MailScanner-From: frieder.schrempf@kontron.de X-SnT-MailScanner-To: abhishek.shah@broadcom.com, benwolsieffer@gmail.com, joe.hershberger@ni.com, leoyu@nvidia.com, marek.behun@nic.cz, patrice.chotard@st.com, patrick.delaunay@st.com, sjg@chromium.org, u-boot@lists.denx.de, vladimir.olovyannikov@broadcom.com X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "u-boot@lists.denx.de" Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.1 at phobos.denx.de X-Virus-Status: Clean From: Frieder Schrempf In order to auto-select an option from the pxe boot menu, that matches the detected board, we check the board model string in the devicetree and set the default menu selection, if it matches the label of the menu entry and there is no default selection already set. This is useful in combination with SPL that loads a FIT image with U-Boot and multiple DTBs. SPL can detect the board and choose the matching configuration in the FIT by using board_fit_config_name_match(). Signed-off-by: Frieder Schrempf Reviewed-by: Simon Glass --- Changes in v4: * Remove #ifdef that would cause build failures in case of OF_CONTROL being disabled. Changes in v3: * Get rid of #ifdef by using IS_ENABLED() in else branch. Changes in v2: * Don't use internal structs of menu, but instead call --- cmd/pxe_utils.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/cmd/pxe_utils.c b/cmd/pxe_utils.c index 53af04d7dc..9a6c67c93a 100644 --- a/cmd/pxe_utils.c +++ b/cmd/pxe_utils.c @@ -1220,6 +1220,44 @@ struct pxe_menu *parse_pxefile(cmd_tbl_t *cmdtp, unsigned long menucfg) return cfg; } +int pxe_match_menu_label_with_str(void *data, void *str) +{ + struct pxe_label *label; + + if (!data || !str) + return 0; + + label = (struct pxe_label *)data; + + if (strcmp(label->name, str) == 0) + return 1; + + return 0; +} + +int pxe_runtime_select_menu_default(struct menu *m) +{ + DECLARE_GLOBAL_DATA_PTR; + const char *model; + char *key; + int ret; + + model = fdt_getprop(gd->fdt_blob, 0, "model", NULL); + + if (!model) + return 0; + + ret = menu_set_default_by_item_data_match(m, + pxe_match_menu_label_with_str, (void *)model, &key); + if (ret) + return ret; + + printf("Menu entry %s fits detected board. " \ + "Use as default selection...\n", key); + + return 0; +} + /* * Converts a pxe_menu struct into a menu struct for use with U-Boot's generic * menu code. @@ -1258,6 +1296,8 @@ static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg) /* * After we've created items for each label in the menu, set the * menu's default label if one was specified. + * If OF_CONTROL is enabled and we don't have a default specified, + * we try to use an entry that matches the board/model name as default. */ if (default_num) { err = menu_default_set(m, default_num); @@ -1269,6 +1309,10 @@ static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg) printf("Missing default: %s\n", cfg->default_label); } + } else if (IS_ENABLED(CONFIG_OF_CONTROL) && + pxe_runtime_select_menu_default(m)) { + menu_destroy(m); + return NULL; } return m;