summaryrefslogtreecommitdiff
path: root/test/boot/bootflow.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2023-01-17 08:55:40 -0500
committerTom Rini <trini@konsulko.com>2023-01-17 08:55:40 -0500
commit5b958dea5c678dbdb2aeb6ac3c0c8cc8dfea065c (patch)
tree172424111d1a39640cf5245eefd080fae3b5fb27 /test/boot/bootflow.c
parent6d03688e75041a7bae4d33815de28da781c37dd6 (diff)
parentb5c8fea7b830c0304051237ad1501431a958b0e6 (diff)
Merge branch '2022-01-16-bootstd-updates'
To quote the author: So far standard boot lacks a boot menu, although it is possible to create a rudimentary one using the existing 'bootmenu' command. Even then, this text-based menu offer only basic functionality and does not take full advantage of the displays which are common on many devices. This series provides a 'bootflow menu' command which allows the user to select from the available bootflows. An attempt is made to show the name of the available operating systems, by reading more information into the bootflow. A logo can be read also, where supported, so that this can be presented to the user when an option is highlighted. Full use is made of TrueType fonts, if enabled. For cases where only a serial console is available, it falls back to a simple text-based menu. All of this is implementing using a new 'expo' construct, a collection of scenes (like menu screens) which can be navigated by the user to view information and select options. This is fairly general and should be able to cope with a wider array of use cases, with less hacking of the menu code, such as is currently needed for CMD_BOOTEFI_BOOTMGR. Of course it would be possible to enhance the existing menu rather than creating a new setup. Instead it seems better to make the existing menu use expo, if code space permits. It avoids the event-loop problem and should be more extensible, given its loosely coupled components and use of IDs instead of pointers. Further motivation is provided in the documentation. For now the CLI keypress-decoding code is split out to be used by the new menu. The key codes defined by menu.h are reused also. This is of course just a starting point. Some ideas for future work are included in the documentation.
Diffstat (limited to 'test/boot/bootflow.c')
-rw-r--r--test/boot/bootflow.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index e1e07082105..5b76cd3ab14 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -11,14 +11,23 @@
#include <bootflow.h>
#include <bootmeth.h>
#include <bootstd.h>
+#include <cli.h>
#include <dm.h>
+#include <expo.h>
#ifdef CONFIG_SANDBOX
#include <asm/test.h>
#endif
+#include <dm/device-internal.h>
#include <dm/lists.h>
#include <test/suites.h>
#include <test/ut.h>
#include "bootstd_common.h"
+#include "../../boot/bootflow_internal.h"
+#include "../../boot/scene_internal.h"
+
+DECLARE_GLOBAL_DATA_PTR;
+
+extern U_BOOT_DRIVER(bootmeth_script);
static int inject_response(struct unit_test_state *uts)
{
@@ -188,6 +197,8 @@ static int bootflow_cmd_info(struct unit_test_state *uts)
ut_assert_nextline("Filename: /extlinux/extlinux.conf");
ut_assert_nextlinen("Buffer: ");
ut_assert_nextline("Size: 253 (595 bytes)");
+ ut_assert_nextline("OS: Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)");
+ ut_assert_nextline("Logo: (none)");
ut_assert_nextline("Error: 0");
ut_assert_console_end();
@@ -460,3 +471,122 @@ static int bootflow_cmd_boot(struct unit_test_state *uts)
return 0;
}
BOOTSTD_TEST(bootflow_cmd_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
+
+/**
+ * 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;
+ ofnode node;
+
+ /* Enable the mmc4 node since we need a second bootflow */
+ node = ofnode_path("/mmc4");
+ ut_assertok(lists_bind_fdt(gd->dm_root, node, &dev, NULL, false));
+
+ /* Enable the script bootmeth too */
+ ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
+ ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_script),
+ "bootmeth_script", 0, ofnode_null(), &dev));
+
+ /* Change the order to include mmc4 */
+ std = dev_get_priv(bootstd);
+ old_order = std->bootdev_order;
+ std->bootdev_order = order;
+
+ console_record_reset_enable();
+ ut_assertok(run_command("bootflow scan", 0));
+ ut_assert_console_end();
+
+ /* 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';
+ prev[2] = '\0';
+ ut_asserteq(2, console_in_puts(prev));
+
+ ut_assertok(run_command("bootflow menu", 0));
+ ut_assert_nextline("Selected: Armbian");
+ ut_assert_console_end();
+
+ 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);