Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DF221C4708D for ; Fri, 6 Jan 2023 14:58:15 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 53AF18563A; Fri, 6 Jan 2023 15:54:40 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="clGGqtqs"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7BE2D85638; Fri, 6 Jan 2023 15:54:17 +0100 (CET) Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A86AB85634 for ; Fri, 6 Jan 2023 15:53:09 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2e.google.com with SMTP id h6so771702iof.9 for ; Fri, 06 Jan 2023 06:53:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t/Eg+4G70tZro6uZRx8afR31+P3HYtzNNQkdSvXJvQE=; b=clGGqtqsZOB2qWVETBEct8d255TuqRlmOpsJ4MJ0GnxX6dhTLyELrdzSaW7vWRyWVn fJIma/vNu8yj9lfdBjEiDQiNVkH1sCEwitxj2FEwPamVtGGnQxj1Q/8TP01vs3RzNWLP ljlh3lLHVkvyiM5qmrUfDc8h7XD36bUgM7d7U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t/Eg+4G70tZro6uZRx8afR31+P3HYtzNNQkdSvXJvQE=; b=7m5YyaBPdxA+LO99vlbljSikzk+sFFK+GyYtf5Hmq5PAN7PFeoPsxTUWt4JqYChKzW KC+48NJsFehTgxDMYKWsMXR/wKpaXE5UChXXVdxbmPYAZGrkBIJQY1VOkPXczJCAAwb4 qjAnL+05pUTncy852CYDU4KKr5kT/FITIbDhJSbW11syNOWV6K58Z+47qNfaqTvtzLjd yiRLSB5/alH2N7zHy/xs629g23nEs30HxnXpVaeGszPYdZjjucbm6TutAqFjYVs295Rg 5KZhhUt6h5mwM0Ye0aql8UnyvoPMkofqc5YE0+gUu84OlULxB1D9/GSbJbnR0JKAGYlN GNPw== X-Gm-Message-State: AFqh2kqpGjzl8DgcN/ABZi1NwoGAtRUo5aZJ3m53NZiTkw5bBGDhHWGW +b019Y9CS1puB3W9U3pP7vvcXyAZqPmmo8SDzxw= X-Google-Smtp-Source: AMrXdXtJ+gakJop5VN6o7KT6tDhAqhS9Qf7ShuN30UZ01U1xEJr/lHdSc4oup2bdXP0bt1d4K9jEzw== X-Received: by 2002:a5d:8982:0:b0:6e4:1e29:bd42 with SMTP id m2-20020a5d8982000000b006e41e29bd42mr36095671iol.5.1673016789038; Fri, 06 Jan 2023 06:53:09 -0800 (PST) Received: from sjg1.lan (c-71-56-217-229.hsd1.co.comcast.net. [71.56.217.229]) by smtp.gmail.com with ESMTPSA id w20-20020a05663800d400b00375783003fcsm360273jao.136.2023.01.06.06.53.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 06:53:08 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Anatolij Gustschin , Tom Rini , Heinrich Schuchardt , Simon Glass Subject: [PATCH v3 24/25] bootstd: Support setting a theme for the menu Date: Fri, 6 Jan 2023 08:52:42 -0600 Message-Id: <20230106145243.411626-25-sjg@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230106145243.411626-1-sjg@chromium.org> References: <20230106145243.411626-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Allow a theme to be set. For now this is very simple, just a default font size to use for all elements. Signed-off-by: Simon Glass --- (no changes since v1) boot/bootflow_menu.c | 43 ++++++++++++++++++++++ boot/bootstd-uclass.c | 2 ++ include/bootflow.h | 10 ++++++ include/bootstd.h | 4 +++ test/boot/bootflow.c | 83 +++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 139 insertions(+), 3 deletions(-) diff --git a/boot/bootflow_menu.c b/boot/bootflow_menu.c index 1105783afeb..7f06dac0af7 100644 --- a/boot/bootflow_menu.c +++ b/boot/bootflow_menu.c @@ -129,6 +129,43 @@ int bootflow_menu_new(struct expo **expp) return 0; } +int bootflow_menu_apply_theme(struct expo *exp, ofnode node) +{ + struct menu_priv *priv = exp->priv; + struct scene *scn; + u32 font_size; + int ret; + + log_debug("Applying theme %s\n", ofnode_get_name(node)); + scn = expo_lookup_scene_id(exp, MAIN); + if (!scn) + return log_msg_ret("scn", -ENOENT); + + /* Avoid error-checking optional items */ + if (!ofnode_read_u32(node, "font-size", &font_size)) { + int i; + + log_debug("font size %d\n", font_size); + scene_txt_set_font(scn, OBJ_PROMPT, NULL, font_size); + scene_txt_set_font(scn, OBJ_POINTER, NULL, font_size); + for (i = 0; i < priv->num_bootflows; i++) { + ret = scene_txt_set_font(scn, ITEM_DESC + i, NULL, + font_size); + if (ret) + return log_msg_ret("des", ret); + scene_txt_set_font(scn, ITEM_KEY + i, NULL, font_size); + scene_txt_set_font(scn, ITEM_LABEL + i, NULL, + font_size); + } + } + + ret = scene_arrange(scn); + if (ret) + return log_msg_ret("arr", ret); + + return 0; +} + int bootflow_menu_run(struct bootstd_priv *std, bool text_mode, struct bootflow **bflowp) { @@ -149,6 +186,12 @@ int bootflow_menu_run(struct bootstd_priv *std, bool text_mode, if (ret) return log_msg_ret("exp", ret); + if (ofnode_valid(std->theme)) { + ret = bootflow_menu_apply_theme(exp, std->theme); + if (ret) + return log_msg_ret("thm", ret); + } + /* For now we only support a video console */ ret = uclass_first_device_err(UCLASS_VIDEO, &dev); if (ret) diff --git a/boot/bootstd-uclass.c b/boot/bootstd-uclass.c index 565c22a36e7..7887acdc11b 100644 --- a/boot/bootstd-uclass.c +++ b/boot/bootstd-uclass.c @@ -33,6 +33,8 @@ static int bootstd_of_to_plat(struct udevice *dev) &priv->prefixes); dev_read_string_list(dev, "bootdev-order", &priv->bootdev_order); + + priv->theme = ofnode_find_subnode(dev_ofnode(dev), "theme"); } return 0; diff --git a/include/bootflow.h b/include/bootflow.h index e7a09568f1b..c201246c6de 100644 --- a/include/bootflow.h +++ b/include/bootflow.h @@ -7,6 +7,7 @@ #ifndef __bootflow_h #define __bootflow_h +#include #include struct bootstd_priv; @@ -347,6 +348,15 @@ int bootflow_iter_uses_system(const struct bootflow_iter *iter); */ int bootflow_menu_new(struct expo **expp); +/** + * bootflow_menu_apply_theme() - Apply a theme to a bootmenu + * + * @exp: Expo to update + * @node: Node containing the theme information + * Returns 0 on success, -ve on error + */ +int bootflow_menu_apply_theme(struct expo *exp, ofnode node); + /** * bootflow_menu_run() - Create and run a menu of available bootflows * diff --git a/include/bootstd.h b/include/bootstd.h index 01be249d16e..4fa0d531001 100644 --- a/include/bootstd.h +++ b/include/bootstd.h @@ -9,6 +9,8 @@ #ifndef __bootstd_h #define __bootstd_h +#include + struct udevice; /** @@ -27,6 +29,7 @@ struct udevice; * @bootmeth_count: Number of bootmeth devices in @bootmeth_order * @bootmeth_order: List of bootmeth devices to use, in order, NULL-terminated * @vbe_bootmeth: Currently selected VBE bootmeth, NULL if none + * @theme: Node containing the theme information */ struct bootstd_priv { const char **prefixes; @@ -37,6 +40,7 @@ struct bootstd_priv { int bootmeth_count; struct udevice **bootmeth_order; struct udevice *vbe_bootmeth; + ofnode theme; }; /** diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index abafa44b2ed..5b76cd3ab14 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -13,6 +13,7 @@ #include #include #include +#include #ifdef CONFIG_SANDBOX #include #endif @@ -21,6 +22,8 @@ #include #include #include "bootstd_common.h" +#include "../../boot/bootflow_internal.h" +#include "../../boot/scene_internal.h" DECLARE_GLOBAL_DATA_PTR; @@ -469,14 +472,18 @@ static int bootflow_cmd_boot(struct unit_test_state *uts) } BOOTSTD_TEST(bootflow_cmd_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT); -/* Check 'bootflow menu' to select a bootflow */ -static int bootflow_cmd_menu(struct unit_test_state *uts) +/** + * prep_mmc4_bootdev() - Set up the mmc4 bootdev so we can access a fake Armbian + * + * @uts: Unit test state + * Returns 0 on success, -ve on failure + */ +static int prep_mmc4_bootdev(struct unit_test_state *uts) { static const char *order[] = {"mmc2", "mmc1", "mmc4", NULL}; struct udevice *dev, *bootstd; struct bootstd_priv *std; const char **old_order; - char prev[3]; ofnode node; /* Enable the mmc4 node since we need a second bootflow */ @@ -500,6 +507,16 @@ static int bootflow_cmd_menu(struct unit_test_state *uts) /* Restore the order used by the device tree */ std->bootdev_order = old_order; + return 0; +} + +/* Check 'bootflow menu' to select a bootflow */ +static int bootflow_cmd_menu(struct unit_test_state *uts) +{ + char prev[3]; + + ut_assertok(prep_mmc4_bootdev(uts)); + /* Add keypresses to move to and select the second one in the list */ prev[0] = CTL_CH('n'); prev[1] = '\r'; @@ -513,3 +530,63 @@ static int bootflow_cmd_menu(struct unit_test_state *uts) return 0; } BOOTSTD_TEST(bootflow_cmd_menu, UT_TESTF_DM | UT_TESTF_SCAN_FDT); + +/** + * check_font() - Check that the font size for an item matches expectations + * + * @uts: Unit test state + * @scn: Scene containing the text object + * @id: ID of the text object + * Returns 0 on success, -ve on failure + */ +static int check_font(struct unit_test_state *uts, struct scene *scn, uint id, + int font_size) +{ + struct scene_obj_txt *txt; + + txt = scene_obj_find(scn, id, SCENEOBJT_TEXT); + ut_assertnonnull(txt); + + ut_asserteq(font_size, txt->font_size); + + return 0; +} + +/* Check themes work with a bootflow menu */ +static int bootflow_menu_theme(struct unit_test_state *uts) +{ + const int font_size = 30; + struct scene *scn; + struct expo *exp; + ofnode node; + int i; + + ut_assertok(prep_mmc4_bootdev(uts)); + + ut_assertok(bootflow_menu_new(&exp)); + node = ofnode_path("/bootstd/theme"); + ut_assert(ofnode_valid(node)); + ut_assertok(bootflow_menu_apply_theme(exp, node)); + + scn = expo_lookup_scene_id(exp, MAIN); + ut_assertnonnull(scn); + + /* + * Check that the txt objects have the correct font size from the + * device tree node: bootstd/theme + * + * Check both menu items, since there are two bootflows + */ + ut_assertok(check_font(uts, scn, OBJ_PROMPT, font_size)); + ut_assertok(check_font(uts, scn, OBJ_POINTER, font_size)); + for (i = 0; i < 2; i++) { + ut_assertok(check_font(uts, scn, ITEM_DESC + i, font_size)); + ut_assertok(check_font(uts, scn, ITEM_KEY + i, font_size)); + ut_assertok(check_font(uts, scn, ITEM_LABEL + i, font_size)); + } + + expo_destroy(exp); + + return 0; +} +BOOTSTD_TEST(bootflow_menu_theme, UT_TESTF_DM | UT_TESTF_SCAN_FDT); -- 2.39.0.314.g84b9a713c41-goog