From patchwork Tue Dec 10 15:47:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frieder Schrempf X-Patchwork-Id: 1207142 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=2a01:238:438b:c500:173d:9f52:ddab:ee01; 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 [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 47XPbJ33MCz9sPh for ; Wed, 11 Dec 2019 02:47:56 +1100 (AEDT) Received: from phobos.denx.de (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 122D280919; Tue, 10 Dec 2019 16:47:47 +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 1D863815F1; Tue, 10 Dec 2019 16:47:45 +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.0 required=5.0 tests=SPF_HELO_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from skedge04.snt-world.com (skedge04.snt-world.com [91.208.41.69]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5BC7E808E0 for ; Tue, 10 Dec 2019 16:47:42 +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 sntmail10s.snt-is.com (unknown [10.203.32.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by skedge04.snt-world.com (Postfix) with ESMTPS id B298571638E; Tue, 10 Dec 2019 16:47:40 +0100 (CET) Received: from sntmail12r.snt-is.com (10.203.32.182) by sntmail10s.snt-is.com (10.203.32.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 10 Dec 2019 16:47:40 +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.1713.004; Tue, 10 Dec 2019 16:47:40 +0100 From: Schrempf Frieder To: Abhishek Shah , Schrempf Frieder , Joe Hershberger , "Leon Yu" , =?iso-8859-1?q?Marek_Beh=FAn?= , Patrice Chotard , Simon Glass , Vladimir Olovyannikov Subject: [PATCH 1/2] menu: Make some parts of the menu available to other components Thread-Topic: [PATCH 1/2] menu: Make some parts of the menu available to other components Thread-Index: AQHVr3EnnmQP5fWbC0aPEUI2e2z1hQ== Date: Tue, 10 Dec 2019 15:47:40 +0000 Message-ID: <20191210154558.9307-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: B298571638E.ADF1A 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, 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: Ben Wolsieffer , "u-boot@lists.denx.de" Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean From: Frieder Schrempf In order to iterate over the menu entries and match for a specific name in the pxe boot, we need to properly export the needed structs and functions. Signed-off-by: Frieder Schrempf --- common/menu.c | 31 +------------------------------ include/menu.h | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/common/menu.c b/common/menu.c index 7b66d199a9..82b03f17f7 100644 --- a/common/menu.c +++ b/common/menu.c @@ -12,36 +12,7 @@ #include "menu.h" -/* - * Internally, each item in a menu is represented by a struct menu_item. - * - * These items will be alloc'd and initialized by menu_item_add and destroyed - * by menu_item_destroy, and the consumer of the interface never sees that - * this struct is used at all. - */ -struct menu_item { - char *key; - void *data; - struct list_head list; -}; -/* - * The menu is composed of a list of items along with settings and callbacks - * provided by the user. An incomplete definition of this struct is available - * in menu.h, but the full definition is here to prevent consumers from - * relying on its contents. - */ -struct menu { - struct menu_item *default_item; - int timeout; - char *title; - int prompt; - void (*item_data_print)(void *); - char *(*item_choice)(void *); - void *item_choice_data; - struct list_head items; - int item_cnt; -}; /* * An iterator function for menu items. callback will be called for each item @@ -51,7 +22,7 @@ struct menu { * used for search type operations. It is also safe for callback to remove the * item from the list of items. */ -static inline void *menu_items_iter(struct menu *m, +inline void *menu_items_iter(struct menu *m, void *(*callback)(struct menu *, struct menu_item *, void *), void *extra) { diff --git a/include/menu.h b/include/menu.h index 2d227c20bd..b3f8db87e4 100644 --- a/include/menu.h +++ b/include/menu.h @@ -6,8 +6,40 @@ #ifndef __MENU_H__ #define __MENU_H__ -struct menu; +/* + * Internally, each item in a menu is represented by a struct menu_item. + * + * These items will be alloc'd and initialized by menu_item_add and destroyed + * by menu_item_destroy, and the consumer of the interface never sees that + * this struct is used at all. + */ +struct menu_item { + char *key; + void *data; + struct list_head list; +}; + +/* + * The menu is composed of a list of items along with settings and callbacks + * provided by the user. An incomplete definition of this struct is available + * in menu.h, but the full definition is here to prevent consumers from + * relying on its contents. + */ +struct menu { + struct menu_item *default_item; + int timeout; + char *title; + int prompt; + void (*item_data_print)(void *); + char *(*item_choice)(void *); + void *item_choice_data; + struct list_head items; + int item_cnt; +}; +void *menu_items_iter(struct menu *m, + void *(*callback)(struct menu *, struct menu_item *, void *), + void *extra); struct menu *menu_create(char *title, int timeout, int prompt, void (*item_data_print)(void *), char *(*item_choice)(void *), From patchwork Tue Dec 10 15:47:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frieder Schrempf X-Patchwork-Id: 1207143 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) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47XPbN4VrWz9sPh for ; Wed, 11 Dec 2019 02:48:00 +1100 (AEDT) Received: from phobos.denx.de (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 00CFD81657; Tue, 10 Dec 2019 16:47:53 +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 2033181656; Tue, 10 Dec 2019 16:47:52 +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.0 required=5.0 tests=SPF_HELO_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from skedge04.snt-world.com (skedge04.snt-world.com [91.208.41.69]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4EFEE81637 for ; Tue, 10 Dec 2019 16:47:49 +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 sntmail11s.snt-is.com (unknown [10.203.32.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by skedge04.snt-world.com (Postfix) with ESMTPS id 53E077163A7; Tue, 10 Dec 2019 16:47:48 +0100 (CET) Received: from sntmail12r.snt-is.com (10.203.32.182) by sntmail11s.snt-is.com (10.203.32.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 10 Dec 2019 16:47:47 +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.1713.004; Tue, 10 Dec 2019 16:47:47 +0100 From: Schrempf Frieder To: Abhishek Shah , Ben Wolsieffer , Schrempf Frieder , Joe Hershberger , Leon Yu , "Patrice Chotard" , Simon Glass , "Vladimir Olovyannikov" Subject: [PATCH 2/2] pxe: Get default selection from board type if label matches Thread-Topic: [PATCH 2/2] pxe: Get default selection from board type if label matches Thread-Index: AQHVr3ErzkHi8bW+6UOpwnNqWQ0X1Q== Date: Tue, 10 Dec 2019 15:47:47 +0000 Message-ID: <20191210154558.9307-2-frieder.schrempf@kontron.de> References: <20191210154558.9307-1-frieder.schrempf@kontron.de> In-Reply-To: <20191210154558.9307-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: 53E077163A7.AF7EF 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, 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.101.4 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 --- cmd/pxe_utils.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/cmd/pxe_utils.c b/cmd/pxe_utils.c index a636346bb5..510957e68f 100644 --- a/cmd/pxe_utils.c +++ b/cmd/pxe_utils.c @@ -1219,6 +1219,61 @@ struct pxe_menu *parse_pxefile(cmd_tbl_t *cmdtp, unsigned long menucfg) return cfg; } +#ifdef CONFIG_OF_CONTROL +/* + * Check if an item's name matches a provided string, pointed to by extra. + * + * This is called via menu_items_iter, so it returns a pointer to the item if + * the name matches, and returns NULL otherwise. + */ +static inline void *pxe_item_name_match(struct menu *m, struct menu_item *item, + void *extra) +{ + char *name = extra; + struct pxe_label *label; + + if (!name || !item->key) + return NULL; + + label = (struct pxe_label *)item->data; + + if (strcmp(label->name, name) == 0) + return item; + + return NULL; +} + +/* + * Find the first item with a name matching the given name, if any exists. + */ +inline struct menu_item *menu_item_by_pxe_name(struct menu *m, char *name) +{ + return menu_items_iter(m, pxe_item_name_match, name); +} + +int pxe_runtime_select_menu_default(struct menu *m) +{ + DECLARE_GLOBAL_DATA_PTR; + struct menu_item *item = NULL; + const char *model; + + model = fdt_getprop(gd->fdt_blob, 0, "model", NULL); + + if (!model) + return 0; + + item = menu_item_by_pxe_name(m, model); + + if (item) { + printf("Menu entry %s fits detected board. " \ + "Use as default selection...\n", item->key); + m->default_item = item; + } + + return 0; +} +#endif + /* * Converts a pxe_menu struct into a menu struct for use with U-Boot's generic * menu code. @@ -1257,6 +1312,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); @@ -1268,6 +1325,11 @@ static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg) printf("Missing default: %s\n", cfg->default_label); } +#ifdef CONFIG_OF_CONTROL + } else if (pxe_runtime_select_menu_default(m)) { + menu_destroy(m); + return NULL; +#endif } return m;