Skip to contentSkip to conversation

bootstd: Add a boot menu

PATCH Superseded Simon Glass 2 participants 31 messages Nov 4, 2022 – Dec 20, 2022

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover bootstd: Add a boot menu

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.

Changes in v2:
- Drop the _add suffix on expo creation function
- Fix 'touse' typo
- Fix pylint warning in mkdir_cond()
- Put strings in a separate structure referenced by ID
- Rebase to master
- Rename vidconsole_get_font() to vidconsole_get_font_size()
- Update for new API

Simon Glass (25):
sandbox: Enable mmc command and legacy images
cli: Move readline character-processing to a state machine
bootmenu: Add a few comments
menu: Rename KEY_... to BKEY_...
menu: Update bootmenu_autoboot_loop() to return the code
menu: Update bootmenu_loop() to return the code
menu: Use a switch statement
menu: Make use of CLI character processing
image: Add a function to find a script in an image
image: Move common image code to image_board and command
video: Enable VIDEO_ANSI by default only with EFI
video: truetype: Rename the metrics function
video: Fix unchnaged typo
video: Add font functions to the vidconsole API
bootstd: Read the Operating System name for distro/scripts
bootstd: Allow reading a logo for the OS
menu: Factor out menu-keypress decoding
expo: Add basic implementation
expo: Add support for scenes
expo: Add support for scene menus
expo: Add basic tests
bootstd: Support creating a boot menu
bootstd: Add a test for the bootstd menu
bootstd: Support setting a theme for the menu
expo: Add documentation

 .../cmd_stm32prog/cmd_stm32prog.c             |   2 +-
 arch/sandbox/dts/test.dts                     |  11 +
 boot/Kconfig                                  |  12 +
 boot/Makefile                                 |   3 +
 boot/bootflow.c                               |   1 +
 boot/bootflow_internal.h                      |  47 ++
 boot/bootflow_menu.c                          | 284 +++++++++
 boot/bootmeth-uclass.c                        |  69 ++-
 boot/bootmeth_distro.c                        |  36 ++
 boot/bootmeth_script.c                        |  40 +-
 boot/bootstd-uclass.c                         |   2 +
 boot/expo.c                                   | 170 ++++++
 boot/image-board.c                            | 133 +++++
 boot/scene.c                                  | 414 ++++++++++++++
 boot/scene_internal.h                         | 123 ++++
 boot/scene_menu.c                             | 390 +++++++++++++
 cmd/bootflow.c                                |  44 +-
 cmd/bootmenu.c                                |  19 +-
 cmd/eficonfig.c                               |  38 +-
 cmd/font.c                                    |  11 +-
 cmd/source.c                                  | 140 +----
 common/Makefile                               |   6 +-
 common/cli_getch.c                            | 208 +++++++
 common/cli_readline.c                         | 150 +----
 common/command.c                              |  19 +
 common/menu.c                                 | 157 +++--
 configs/sandbox_defconfig                     |   2 +
 configs/sandbox_flattree_defconfig            |   2 +
 configs/snow_defconfig                        |   4 +
 configs/tools-only_defconfig                  |   2 +
 doc/develop/expo.rst                          | 188 ++++++
 doc/develop/index.rst                         |   1 +
 drivers/usb/gadget/f_sdp.c                    |   2 +-
 drivers/video/Kconfig                         |   7 +-
 drivers/video/console_truetype.c              |  37 +-
 drivers/video/vidconsole-uclass.c             |  33 ++
 include/bootflow.h                            |  40 ++
 include/bootmeth.h                            |  16 +
 include/bootstd.h                             |   4 +
 include/cli.h                                 |  74 +++
 include/command.h                             |  12 +
 include/expo.h                                | 521 +++++++++++++++++
 include/image.h                               |  17 +-
 include/menu.h                                |  77 ++-
 include/video.h                               |   2 +-
 include/video_console.h                       |  75 ++-
 test/boot/Makefile                            |   2 +
 test/boot/bootflow.c                          | 130 +++++
 test/boot/expo.c                              | 539 ++++++++++++++++++
 test/cmd/font.c                               |   6 +-
 test/py/tests/bootstd/armbian.bmp.xz          | Bin 0 -> 1384 bytes
 test/py/tests/bootstd/mmc4.img.xz             | Bin 0 -> 7072 bytes
 test/py/tests/test_android/test_avb.py        |   2 +
 test/py/tests/test_ut.py                      | 218 ++++++-
 54 files changed, 4075 insertions(+), 467 deletions(-)
 create mode 100644 boot/bootflow_internal.h
 create mode 100644 boot/bootflow_menu.c
 create mode 100644 boot/expo.c
 create mode 100644 boot/scene.c
 create mode 100644 boot/scene_internal.h
 create mode 100644 boot/scene_menu.c
 create mode 100644 common/cli_getch.c
 create mode 100644 doc/develop/expo.rst
 create mode 100644 include/expo.h
 create mode 100644 test/boot/expo.c
 create mode 100644 test/py/tests/bootstd/armbian.bmp.xz
 create mode 100644 test/py/tests/bootstd/mmc4.img.xz
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#1 lore raw

PATCH v2 1/25 sandbox: Enable mmc command and legacy images

The mmc command is useful for testing mmc disk images in sandbox, so enable it. We also need to enable legacy images so that we can run tests which use them.

Disable it for a few avb tests since MMC is not implemented there yet.

---

(no changes since v1)

 configs/sandbox_defconfig              | 2 ++
 configs/sandbox_flattree_defconfig     | 2 ++
 test/py/tests/test_android/test_avb.py | 2 ++
 3 files changed, 6 insertions(+)
configs/sandbox_defconfig +2 -0
index f12d0a4f516..2e12df1bcb0 100644
@@ -13,6 +13,7 @@ CONFIG_FIT=y
 CONFIG_FIT_RSASSA_PSS=y
 CONFIG_FIT_CIPHER=y
 CONFIG_FIT_VERBOSE=y
+CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_BOOTSTAGE=y
 CONFIG_BOOTSTAGE_REPORT=y
 CONFIG_BOOTSTAGE_FDT=y
@@ -72,6 +73,7 @@ CONFIG_CMD_IDE=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_LOADM=y
 CONFIG_CMD_LSBLK=y
+CONFIG_CMD_MMC=y
 CONFIG_CMD_MUX=y
 CONFIG_CMD_OSD=y
 CONFIG_CMD_PCI=y
configs/sandbox_flattree_defconfig +2 -0
index 01234dc183b..4055e3c9e9d 100644
@@ -11,6 +11,7 @@ CONFIG_DISTRO_DEFAULTS=y
 CONFIG_FIT=y
 CONFIG_FIT_SIGNATURE=y
 CONFIG_FIT_VERBOSE=y
+CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_BOOTSTAGE=y
 CONFIG_BOOTSTAGE_REPORT=y
 CONFIG_BOOTSTAGE_FDT=y
@@ -40,6 +41,7 @@ CONFIG_CMD_DEMO=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_I2C=y
+CONFIG_CMD_MMC=y
 CONFIG_CMD_OSD=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_REMOTEPROC=y
test/py/tests/test_android/test_avb.py +2 -0
index a3f883136b0..bc5c5b55821 100644
@@ -39,6 +39,7 @@ def test_avb_verify(u_boot_console):
 
 @pytest.mark.buildconfigspec('cmd_avb')
 @pytest.mark.buildconfigspec('cmd_mmc')
[email protected]('sandbox')
 def test_avb_mmc_uuid(u_boot_console):
     """Check if 'avb get_uuid' works, compare results with
     'part list mmc 1' output
@@ -97,6 +98,7 @@ def test_avb_is_unlocked(u_boot_console):
 
 @pytest.mark.buildconfigspec('cmd_avb')
 @pytest.mark.buildconfigspec('cmd_mmc')
[email protected]('sandbox')
 def test_avb_mmc_read(u_boot_console):
     """Test mmc read operation
     """
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#2 lore raw

PATCH v2 2/25 cli: Move readline character-processing to a state machine

In reply to Simon Glass

The current cread_line() function is very long. It handles the escape processing inline. The menu command does similar processing but at the character level, so there is some duplication.

Split the character processing into a new function cli_ch_process() which processes individual characters and returns the resulting input character, taking account of escape sequences. It requires the caller to set up and maintain its state.

Update cread_line() to use this new function.

The only intended functional change is that an invalid escape sequence does not add invalid/control characters into the input buffer, but instead discards these.

---

(no changes since v1)

 common/Makefile       |   6 +-
 common/cli_getch.c    | 204 ++++++++++++++++++++++++++++++++++++++++++
 common/cli_readline.c | 150 +++++--------------------------
 include/cli.h         |  72 +++++++++++++++
 4 files changed, 301 insertions(+), 131 deletions(-)
 create mode 100644 common/cli_getch.c
common/Makefile +3 -3
index 20addfb244c..67485e77a04 100644
@@ -38,7 +38,7 @@ obj-$(CONFIG_SPLASH_SOURCE) += splash_source.o
 obj-$(CONFIG_MENU) += menu.o
 obj-$(CONFIG_UPDATE_COMMON) += update.o
 obj-$(CONFIG_USB_KEYBOARD) += usb_kbd.o
-obj-$(CONFIG_CMDLINE) += cli_readline.o cli_simple.o
+obj-$(CONFIG_CMDLINE) += cli_getch.o cli_readline.o cli_simple.o
 
 endif # !CONFIG_SPL_BUILD
 
@@ -93,8 +93,8 @@ obj-y += eeprom/eeprom_field.o eeprom/eeprom_layout.o
 endif
 
 obj-y += cli.o
-obj-$(CONFIG_FSL_DDR_INTERACTIVE) += cli_simple.o cli_readline.o
-obj-$(CONFIG_STM32MP1_DDR_INTERACTIVE) += cli_simple.o cli_readline.o
+obj-$(CONFIG_FSL_DDR_INTERACTIVE) += cli_getch.o cli_simple.o cli_readline.o
+obj-$(CONFIG_STM32MP1_DDR_INTERACTIVE) += cli_getch.o cli_simple.o cli_readline.o
 obj-$(CONFIG_DFU_OVER_USB) += dfu.o
 obj-y += command.o
 obj-$(CONFIG_$(SPL_TPL_)LOG) += log.o
common/cli_getch.c new file +204 -0

204 lines not on this page · raw message

common/cli_readline.c +22 -128

193 lines not on this page · raw message

include/cli.h +72 -0

83 lines not on this page · raw message

Signature · 1 line
2.38.1.431.g37b22c650d-goog
#3 lore raw

PATCH v2 3/25 bootmenu: Add a few comments

In reply to Simon Glass

The behaviour of these two functions is completely undocumented. Add some notes so the poor, suffering dev can figure out what is going on.

---

(no changes since v1)

 include/menu.h | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
include/menu.h +42 -0
index 702aacb170c..0b4d9734149 100644
@@ -42,6 +42,7 @@ struct bootmenu_data {
 	struct bootmenu_entry *first;	/* first menu entry */
 };
 
+/** enum bootmenu_key - keys that can be returned by the bootmenu */
 enum bootmenu_key {
 	KEY_NONE = 0,
 	KEY_UP,
@@ -53,8 +54,49 @@ enum bootmenu_key {
 	KEY_SPACE,
 };
 
+/**
+ * bootmenu_autoboot_loop() - handle autobooting if no key is pressed
+ *
+ * This shows a prompt to allow the user to press a key to interrupt auto boot
+ * of the first menu option.
+ *
+ * It then waits for the required time (menu->delay in seconds) for a key to be
+ * pressed. If nothing is pressed in that time, @key returns KEY_SELECT
+ * indicating that the current option should be chosen.
+ *
+ * @menu: Menu being processed
+ * @key: Returns the code for the key the user pressed:
+ *	enter: KEY_SELECT
+ *	Ctrl-C: KEY_QUIT
+ *	anything else: KEY_NONE
+ * @esc: Set to 1 if the escape key is pressed, otherwise not updated
+ */
 void bootmenu_autoboot_loop(struct bootmenu_data *menu,
 			    enum bootmenu_key *key, int *esc);
+
+/**
+ * bootmenu_loop() - handle waiting for a keypress when autoboot is disabled
+ *
+ * This is used when the menu delay is negative, indicating that the delay has
+ * elapsed, or there was no delay to begin with.
+ *
+ * It reads a character and processes it, returning a menu-key code if a
+ * character is recognised
+ *
+ * @menu: Menu being processed
+ * @key: Returns the code for the key the user pressed:
+ *	enter: KEY_SELECT
+ *	Ctrl-C: KEY_QUIT
+ *	Up arrow: KEY_UP
+ *	Down arrow: KEY_DOWN
+ *	Escape (by itself): KEY_QUIT
+ *	Plus: KEY_PLUS
+ *	Minus: KEY_MINUS
+ *	Space: KEY_SPACE
+ * @esc: On input, a non-zero value indicates that an escape sequence has
+ *	resulted in that many characters so far. On exit this is updated to the
+ *	new number of characters
+ */
 void bootmenu_loop(struct bootmenu_data *menu,
 		   enum bootmenu_key *key, int *esc);
 
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#4 lore raw

PATCH v2 4/25 menu: Rename KEY_... to BKEY_...

In reply to Simon Glass

This enum values conflict with linux/input.h so rename them.

---

(no changes since v1)

 cmd/bootmenu.c  | 10 +++++-----
 cmd/eficonfig.c | 26 +++++++++++++-------------
 common/menu.c   | 34 +++++++++++++++++-----------------
 include/menu.h  | 32 ++++++++++++++++----------------
 4 files changed, 51 insertions(+), 51 deletions(-)
cmd/bootmenu.c +5 -5
index 3340be16325..c80004c54dc 100644
@@ -86,7 +86,7 @@ static char *bootmenu_choice_entry(void *data)
 {
 	struct bootmenu_data *menu = data;
 	struct bootmenu_entry *iter;
-	enum bootmenu_key key = KEY_NONE;
+	enum bootmenu_key key = BKEY_NONE;
 	int esc = 0;
 	int i;
 
@@ -100,22 +100,22 @@ static char *bootmenu_choice_entry(void *data)
 		}
 
 		switch (key) {
-		case KEY_UP:
+		case BKEY_UP:
 			if (menu->active > 0)
 				--menu->active;
 			/* no menu key selected, regenerate menu */
 			return NULL;
-		case KEY_DOWN:
+		case BKEY_DOWN:
 			if (menu->active < menu->count - 1)
 				++menu->active;
 			/* no menu key selected, regenerate menu */
 			return NULL;
-		case KEY_SELECT:
+		case BKEY_SELECT:
 			iter = menu->first;
 			for (i = 0; i < menu->active; ++i)
 				iter = iter->next;
 			return iter->key;
-		case KEY_QUIT:
+		case BKEY_QUIT:
 			/* Quit by choosing the last entry - U-Boot console */
 			iter = menu->first;
 			while (iter->next)
cmd/eficonfig.c +13 -13
index 2595dd95631..de7ce24f5ac 100644
@@ -193,31 +193,31 @@ static char *eficonfig_choice_entry(void *data)
 	int esc = 0;
 	struct list_head *pos, *n;
 	struct eficonfig_entry *entry;
-	enum bootmenu_key key = KEY_NONE;
+	enum bootmenu_key key = BKEY_NONE;
 	struct efimenu *efi_menu = data;
 
 	while (1) {
 		bootmenu_loop((struct bootmenu_data *)efi_menu, &key, &esc);
 
 		switch (key) {
-		case KEY_UP:
+		case BKEY_UP:
 			if (efi_menu->active > 0)
 				--efi_menu->active;
 			/* no menu key selected, regenerate menu */
 			return NULL;
-		case KEY_DOWN:
+		case BKEY_DOWN:
 			if (efi_menu->active < efi_menu->count - 1)
 				++efi_menu->active;
 			/* no menu key selected, regenerate menu */
 			return NULL;
-		case KEY_SELECT:
+		case BKEY_SELECT:
 			list_for_each_safe(pos, n, &efi_menu->list) {
 				entry = list_entry(pos, struct eficonfig_entry, list);
 				if (entry->num == efi_menu->active)
 					return entry->key;
 			}
 			break;
-		case KEY_QUIT:
+		case BKEY_QUIT:
 			/* Quit by choosing the last entry */
 			entry = list_last_entry(&efi_menu->list, struct eficonfig_entry, list);
 			return entry->key;
@@ -1864,14 +1864,14 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu)
 	int esc = 0;
 	struct list_head *pos, *n;
 	struct eficonfig_boot_order *tmp;
-	enum bootmenu_key key = KEY_NONE;
+	enum bootmenu_key key = BKEY_NONE;
 	struct eficonfig_boot_order *entry;
 
 	while (1) {
 		bootmenu_loop(NULL, &key, &esc);
 
 		switch (key) {
-		case KEY_PLUS:
+		case BKEY_PLUS:
 			if (efi_menu->active > 0) {
 				list_for_each_safe(pos, n, &efi_menu->list) {
 					entry = list_entry(pos, struct eficonfig_boot_order, list);
@@ -1885,11 +1885,11 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu)
 				list_add(&tmp->list, &entry->list);
 			}
 			fallthrough;
-		case KEY_UP:
+		case BKEY_UP:
 			if (efi_menu->active > 0)
 				--efi_menu->active;
 			return EFI_NOT_READY;
-		case KEY_MINUS:
+		case BKEY_MINUS:
 			if (efi_menu->active < efi_menu->count - 3) {
 				list_for_each_safe(pos, n, &efi_menu->list) {
 					entry = list_entry(pos, struct eficonfig_boot_order, list);
@@ -1905,11 +1905,11 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu)
 				++efi_menu->active;
 			}
 			return EFI_NOT_READY;
-		case KEY_DOWN:
+		case BKEY_DOWN:
 			if (efi_menu->active < efi_menu->count - 1)
 				++efi_menu->active;
 			return EFI_NOT_READY;
-		case KEY_SELECT:
+		case BKEY_SELECT:
 			/* "Save" */
 			if (efi_menu->active == efi_menu->count - 2)
 				return EFI_SUCCESS;
@@ -1919,7 +1919,7 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu)
 				return EFI_ABORTED;
 
 			break;
-		case KEY_SPACE:
+		case BKEY_SPACE:
 			if (efi_menu->active < efi_menu->count - 2) {
 				list_for_each_safe(pos, n, &efi_menu->list) {
 					entry = list_entry(pos, struct eficonfig_boot_order, list);
@@ -1930,7 +1930,7 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu)
 				}
 			}
 			break;
-		case KEY_QUIT:
+		case BKEY_QUIT:
 			return EFI_ABORTED;
 		default:
 			/* Pressed key is not valid, no need to regenerate the menu */
common/menu.c +17 -17
index 8fe00965c0c..a245c5a9c6c 100644
@@ -446,16 +446,16 @@ void bootmenu_autoboot_loop(struct bootmenu_data *menu,
 			switch (c) {
 			case '\e':
 				*esc = 1;
-				*key = KEY_NONE;
+				*key = BKEY_NONE;
 				break;
 			case '\r':
-				*key = KEY_SELECT;
+				*key = BKEY_SELECT;
 				break;
 			case 0x3: /* ^C */
-				*key = KEY_QUIT;
+				*key = BKEY_QUIT;
 				break;
 			default:
-				*key = KEY_NONE;
+				*key = BKEY_NONE;
 				break;
 			}
 
@@ -471,7 +471,7 @@ void bootmenu_autoboot_loop(struct bootmenu_data *menu,
 	printf(ANSI_CURSOR_POSITION ANSI_CLEAR_LINE, menu->count + 5, 1);
 
 	if (menu->delay == 0)
-		*key = KEY_SELECT;
+		*key = BKEY_SELECT;
 }
 
 void bootmenu_loop(struct bootmenu_data *menu,
@@ -503,17 +503,17 @@ void bootmenu_loop(struct bootmenu_data *menu,
 		/* First char of ANSI escape sequence '\e' */
 		if (c == '\e') {
 			*esc = 1;
-			*key = KEY_NONE;
+			*key = BKEY_NONE;
 		}
 		break;
 	case 1:
 		/* Second char of ANSI '[' */
 		if (c == '[') {
 			*esc = 2;
-			*key = KEY_NONE;
+			*key = BKEY_NONE;
 		} else {
 		/* Alone ESC key was pressed */
-			*key = KEY_QUIT;
+			*key = BKEY_QUIT;
 			*esc = (c == '\e') ? 1 : 0;
 		}
 		break;
@@ -522,7 +522,7 @@ void bootmenu_loop(struct bootmenu_data *menu,
 		/* Third char of ANSI (number '1') - optional */
 		if (*esc == 2 && c == '1') {
 			*esc = 3;
-			*key = KEY_NONE;
+			*key = BKEY_NONE;
 			break;
 		}
 
@@ -530,31 +530,31 @@ void bootmenu_loop(struct bootmenu_data *menu,
 
 		/* ANSI 'A' - key up was pressed */
 		if (c == 'A')
-			*key = KEY_UP;
+			*key = BKEY_UP;
 		/* ANSI 'B' - key down was pressed */
 		else if (c == 'B')
-			*key = KEY_DOWN;
+			*key = BKEY_DOWN;
 		/* other key was pressed */
 		else
-			*key = KEY_NONE;
+			*key = BKEY_NONE;
 
 		break;
 	}
 
 	/* enter key was pressed */
 	if (c == '\r')
-		*key = KEY_SELECT;
+		*key = BKEY_SELECT;
 
 	/* ^C was pressed */
 	if (c == 0x3)
-		*key = KEY_QUIT;
+		*key = BKEY_QUIT;
 
 	if (c == '+')
-		*key = KEY_PLUS;
+		*key = BKEY_PLUS;
 
 	if (c == '-')
-		*key = KEY_MINUS;
+		*key = BKEY_MINUS;
 
 	if (c == ' ')
-		*key = KEY_SPACE;
+		*key = BKEY_SPACE;
 }
include/menu.h +16 -16
index 0b4d9734149..29b457921e9 100644
@@ -44,14 +44,14 @@ struct bootmenu_data {
 
 /** enum bootmenu_key - keys that can be returned by the bootmenu */
 enum bootmenu_key {
-	KEY_NONE = 0,
-	KEY_UP,
-	KEY_DOWN,
-	KEY_SELECT,
-	KEY_QUIT,
-	KEY_PLUS,
-	KEY_MINUS,
-	KEY_SPACE,
+	BKEY_NONE = 0,
+	BKEY_UP,
+	BKEY_DOWN,
+	BKEY_SELECT,
+	BKEY_QUIT,
+	BKEY_PLUS,
+	BKEY_MINUS,
+	BKEY_SPACE,
 };
 
 /**
@@ -85,14 +85,14 @@ void bootmenu_autoboot_loop(struct bootmenu_data *menu,
  *
  * @menu: Menu being processed
  * @key: Returns the code for the key the user pressed:
- *	enter: KEY_SELECT
- *	Ctrl-C: KEY_QUIT
- *	Up arrow: KEY_UP
- *	Down arrow: KEY_DOWN
- *	Escape (by itself): KEY_QUIT
- *	Plus: KEY_PLUS
- *	Minus: KEY_MINUS
- *	Space: KEY_SPACE
+ *	enter: BKEY_SELECT
+ *	Ctrl-C: BKEY_QUIT
+ *	Up arrow: BKEY_UP
+ *	Down arrow: BKEY_DOWN
+ *	Escape (by itself): BKEY_QUIT
+ *	Plus: BKEY_PLUS
+ *	Minus: BKEY_MINUS
+ *	Space: BKEY_SPACE
  * @esc: On input, a non-zero value indicates that an escape sequence has
  *	resulted in that many characters so far. On exit this is updated to the
  *	new number of characters
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#5 lore raw

PATCH v2 5/25 menu: Update bootmenu_autoboot_loop() to return the code

In reply to Simon Glass

Use the return value to save having to pass around a pointer. This also resolves any ambiguity about what *key contains when the function is called.

---

(no changes since v1)

 cmd/bootmenu.c |  2 +-
 common/menu.c  | 16 +++++++++-------
 include/menu.h |  7 +++----
 3 files changed, 13 insertions(+), 12 deletions(-)
cmd/bootmenu.c +1 -1
index c80004c54dc..0e22f504fe4 100644
@@ -93,7 +93,7 @@ static char *bootmenu_choice_entry(void *data)
 	while (1) {
 		if (menu->delay >= 0) {
 			/* Autoboot was not stopped */
-			bootmenu_autoboot_loop(menu, &key, &esc);
+			key = bootmenu_autoboot_loop(menu, &esc);
 		} else {
 			/* Some key was pressed, so autoboot was stopped */
 			bootmenu_loop(menu, &key, &esc);
common/menu.c +9 -7
index a245c5a9c6c..bafc8470d7d 100644
@@ -425,9 +425,9 @@ int menu_destroy(struct menu *m)
 	return 1;
 }
 
-void bootmenu_autoboot_loop(struct bootmenu_data *menu,
-			    enum bootmenu_key *key, int *esc)
+enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc)
 {
+	enum bootmenu_key key = BKEY_NONE;
 	int i, c;
 
 	while (menu->delay > 0) {
@@ -446,16 +446,16 @@ void bootmenu_autoboot_loop(struct bootmenu_data *menu,
 			switch (c) {
 			case '\e':
 				*esc = 1;
-				*key = BKEY_NONE;
+				key = BKEY_NONE;
 				break;
 			case '\r':
-				*key = BKEY_SELECT;
+				key = BKEY_SELECT;
 				break;
 			case 0x3: /* ^C */
-				*key = BKEY_QUIT;
+				key = BKEY_QUIT;
 				break;
 			default:
-				*key = BKEY_NONE;
+				key = BKEY_NONE;
 				break;
 			}
 
@@ -471,7 +471,9 @@ void bootmenu_autoboot_loop(struct bootmenu_data *menu,
 	printf(ANSI_CURSOR_POSITION ANSI_CLEAR_LINE, menu->count + 5, 1);
 
 	if (menu->delay == 0)
-		*key = BKEY_SELECT;
+		key = BKEY_SELECT;
+
+	return key;
 }
 
 void bootmenu_loop(struct bootmenu_data *menu,
include/menu.h +3 -4
index 29b457921e9..9f30a3c1acd 100644
@@ -65,14 +65,13 @@ enum bootmenu_key {
  * indicating that the current option should be chosen.
  *
  * @menu: Menu being processed
- * @key: Returns the code for the key the user pressed:
+ * @esc: Set to 1 if the escape key is pressed, otherwise not updated
+ * Returns: code for the key the user pressed:
  *	enter: KEY_SELECT
  *	Ctrl-C: KEY_QUIT
  *	anything else: KEY_NONE
- * @esc: Set to 1 if the escape key is pressed, otherwise not updated
  */
-void bootmenu_autoboot_loop(struct bootmenu_data *menu,
-			    enum bootmenu_key *key, int *esc);
+enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc);
 
 /**
  * bootmenu_loop() - handle waiting for a keypress when autoboot is disabled
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#6 lore raw

PATCH v2 6/25 menu: Update bootmenu_loop() to return the code

In reply to Simon Glass

Use the return value to save having to pass around a pointer. This also resolves any ambiguity about what *key contains when the function is called.

---

(no changes since v1)

 cmd/bootmenu.c  |  2 +-
 cmd/eficonfig.c |  4 ++--
 common/menu.c   | 30 ++++++++++++++++--------------
 include/menu.h  | 11 +++++------
 4 files changed, 24 insertions(+), 23 deletions(-)
cmd/bootmenu.c +1 -1
index 0e22f504fe4..573afe16609 100644
@@ -96,7 +96,7 @@ static char *bootmenu_choice_entry(void *data)
 			key = bootmenu_autoboot_loop(menu, &esc);
 		} else {
 			/* Some key was pressed, so autoboot was stopped */
-			bootmenu_loop(menu, &key, &esc);
+			key = bootmenu_loop(menu, &esc);
 		}
 
 		switch (key) {
cmd/eficonfig.c +2 -2
index de7ce24f5ac..18f173e33ab 100644
@@ -197,7 +197,7 @@ static char *eficonfig_choice_entry(void *data)
 	struct efimenu *efi_menu = data;
 
 	while (1) {
-		bootmenu_loop((struct bootmenu_data *)efi_menu, &key, &esc);
+		key = bootmenu_loop((struct bootmenu_data *)efi_menu, &esc);
 
 		switch (key) {
 		case BKEY_UP:
@@ -1868,7 +1868,7 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu)
 	struct eficonfig_boot_order *entry;
 
 	while (1) {
-		bootmenu_loop(NULL, &key, &esc);
+		key = bootmenu_loop(NULL, &esc);
 
 		switch (key) {
 		case BKEY_PLUS:
common/menu.c +16 -14
index bafc8470d7d..6842f5409d6 100644
@@ -476,9 +476,9 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc)
 	return key;
 }
 
-void bootmenu_loop(struct bootmenu_data *menu,
-		   enum bootmenu_key *key, int *esc)
+enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, int *esc)
 {
+	enum bootmenu_key key = BKEY_NONE;
 	int c;
 
 	if (*esc == 1) {
@@ -505,17 +505,17 @@ void bootmenu_loop(struct bootmenu_data *menu,
 		/* First char of ANSI escape sequence '\e' */
 		if (c == '\e') {
 			*esc = 1;
-			*key = BKEY_NONE;
+			key = BKEY_NONE;
 		}
 		break;
 	case 1:
 		/* Second char of ANSI '[' */
 		if (c == '[') {
 			*esc = 2;
-			*key = BKEY_NONE;
+			key = BKEY_NONE;
 		} else {
 		/* Alone ESC key was pressed */
-			*key = BKEY_QUIT;
+			key = BKEY_QUIT;
 			*esc = (c == '\e') ? 1 : 0;
 		}
 		break;
@@ -524,7 +524,7 @@ void bootmenu_loop(struct bootmenu_data *menu,
 		/* Third char of ANSI (number '1') - optional */
 		if (*esc == 2 && c == '1') {
 			*esc = 3;
-			*key = BKEY_NONE;
+			key = BKEY_NONE;
 			break;
 		}
 
@@ -532,31 +532,33 @@ void bootmenu_loop(struct bootmenu_data *menu,
 
 		/* ANSI 'A' - key up was pressed */
 		if (c == 'A')
-			*key = BKEY_UP;
+			key = BKEY_UP;
 		/* ANSI 'B' - key down was pressed */
 		else if (c == 'B')
-			*key = BKEY_DOWN;
+			key = BKEY_DOWN;
 		/* other key was pressed */
 		else
-			*key = BKEY_NONE;
+			key = BKEY_NONE;
 
 		break;
 	}
 
 	/* enter key was pressed */
 	if (c == '\r')
-		*key = BKEY_SELECT;
+		key = BKEY_SELECT;
 
 	/* ^C was pressed */
 	if (c == 0x3)
-		*key = BKEY_QUIT;
+		key = BKEY_QUIT;
 
 	if (c == '+')
-		*key = BKEY_PLUS;
+		key = BKEY_PLUS;
 
 	if (c == '-')
-		*key = BKEY_MINUS;
+		key = BKEY_MINUS;
 
 	if (c == ' ')
-		*key = BKEY_SPACE;
+		key = BKEY_SPACE;
+
+	return key;
 }
include/menu.h +5 -6
index 9f30a3c1acd..8b9b36214f7 100644
@@ -83,7 +83,10 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc);
  * character is recognised
  *
  * @menu: Menu being processed
- * @key: Returns the code for the key the user pressed:
+ * @esc: On input, a non-zero value indicates that an escape sequence has
+ *	resulted in that many characters so far. On exit this is updated to the
+ *	new number of characters
+ * Returns: code for the key the user pressed:
  *	enter: BKEY_SELECT
  *	Ctrl-C: BKEY_QUIT
  *	Up arrow: BKEY_UP
@@ -92,11 +95,7 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc);
  *	Plus: BKEY_PLUS
  *	Minus: BKEY_MINUS
  *	Space: BKEY_SPACE
- * @esc: On input, a non-zero value indicates that an escape sequence has
- *	resulted in that many characters so far. On exit this is updated to the
- *	new number of characters
  */
-void bootmenu_loop(struct bootmenu_data *menu,
-		   enum bootmenu_key *key, int *esc);
+enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, int *esc);
 
 #endif /* __MENU_H__ */
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#7 lore raw

PATCH v2 7/25 menu: Use a switch statement

In reply to Simon Glass

Convert the long line of if() statements to a switch() since this makes better use of the C language.

---

(no changes since v1)

 common/menu.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)
common/menu.c +20 -11
index 6842f5409d6..7db98942a61 100644
@@ -543,22 +543,31 @@ enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, int *esc)
 		break;
 	}
 
-	/* enter key was pressed */
-	if (c == '\r')
+	switch (c) {
+	case '\r':
+		/* enter key was pressed */
 		key = BKEY_SELECT;
-
-	/* ^C was pressed */
-	if (c == 0x3)
+		break;
+	case CTL_CH('c'):
+		/* ^C was pressed */
 		key = BKEY_QUIT;
-
-	if (c == '+')
+		break;
+	case CTL_CH('p'):
+		key = BKEY_UP;
+		break;
+	case CTL_CH('n'):
+		key = BKEY_DOWN;
+		break;
+	case '+':
 		key = BKEY_PLUS;
-
-	if (c == '-')
+		break;
+	case '-':
 		key = BKEY_MINUS;
-
-	if (c == ' ')
+		break;
+	case ' ':
 		key = BKEY_SPACE;
+		break;
+	}
 
 	return key;
 }
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#8 lore raw

PATCH v2 8/25 menu: Make use of CLI character processing

In reply to Simon Glass

Avoid duplicating some of the escape-sequence processing here and use the CLI function instead.

---

Changes in v2:
- Rebase to master

 cmd/bootmenu.c     |  9 +++--
 cmd/eficonfig.c    | 12 ++++--
 common/cli_getch.c | 12 ++++--
 common/menu.c      | 92 +++++++++++++---------------------------------
 include/cli.h      |  4 +-
 include/menu.h     |  7 +++-
 6 files changed, 56 insertions(+), 80 deletions(-)
cmd/bootmenu.c +6 -3
index 573afe16609..52d8c2f266d 100644
@@ -4,6 +4,7 @@
  */
 
 #include <charset.h>
+#include <cli.h>
 #include <common.h>
 #include <command.h>
 #include <ansi.h>
@@ -84,19 +85,21 @@ static void bootmenu_print_entry(void *data)
 
 static char *bootmenu_choice_entry(void *data)
 {
+	struct cli_ch_state s_cch, *cch = &s_cch;
 	struct bootmenu_data *menu = data;
 	struct bootmenu_entry *iter;
 	enum bootmenu_key key = BKEY_NONE;
-	int esc = 0;
 	int i;
 
+	cli_ch_init(cch);
+
 	while (1) {
 		if (menu->delay >= 0) {
 			/* Autoboot was not stopped */
-			key = bootmenu_autoboot_loop(menu, &esc);
+			key = bootmenu_autoboot_loop(menu, cch);
 		} else {
 			/* Some key was pressed, so autoboot was stopped */
-			key = bootmenu_loop(menu, &esc);
+			key = bootmenu_loop(menu, cch);
 		}
 
 		switch (key) {
cmd/eficonfig.c +8 -4
index 18f173e33ab..5922891efc9 100644
@@ -6,6 +6,7 @@
  */
 
 #include <ansi.h>
+#include <cli.h>
 #include <common.h>
 #include <charset.h>
 #include <efi_loader.h>
@@ -190,14 +191,16 @@ static void eficonfig_display_statusline(struct menu *m)
  */
 static char *eficonfig_choice_entry(void *data)
 {
-	int esc = 0;
+	struct cli_ch_state s_cch, *cch = &s_cch;
 	struct list_head *pos, *n;
 	struct eficonfig_entry *entry;
 	enum bootmenu_key key = BKEY_NONE;
 	struct efimenu *efi_menu = data;
 
+	cli_ch_init(cch);
+
 	while (1) {
-		key = bootmenu_loop((struct bootmenu_data *)efi_menu, &esc);
+		key = bootmenu_loop((struct bootmenu_data *)efi_menu, cch);
 
 		switch (key) {
 		case BKEY_UP:
@@ -1861,14 +1864,15 @@ static void eficonfig_display_change_boot_order(struct efimenu *efi_menu)
  */
 static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu)
 {
-	int esc = 0;
+	struct cli_ch_state s_cch, *cch = &s_cch;
 	struct list_head *pos, *n;
 	struct eficonfig_boot_order *tmp;
 	enum bootmenu_key key = BKEY_NONE;
 	struct eficonfig_boot_order *entry;
 
+	cli_ch_init(cch);
 	while (1) {
-		key = bootmenu_loop(NULL, &esc);
+		key = bootmenu_loop(NULL, cch);
 
 		switch (key) {
 		case BKEY_PLUS:
common/cli_getch.c +8 -4
index 9eeea7fef29..87c23edcf4b 100644
@@ -140,10 +140,11 @@ int cli_ch_process(struct cli_ch_state *cch, int ichar)
 	 * sequence
 	 */
 	if (!ichar) {
-		if (cch->emit_upto) {
+		if (cch->emitting) {
 			if (cch->emit_upto < cch->esc_len)
 				return cch->esc_save[cch->emit_upto++];
 			cch->emit_upto = 0;
+			cch->emitting = false;
 		}
 		return 0;
 	} else if (ichar == -ETIMEDOUT) {
@@ -174,18 +175,21 @@ int cli_ch_process(struct cli_ch_state *cch, int ichar)
 		case ESC_SAVE:
 			/* save this character and return nothing */
 			cch->esc_save[cch->esc_len++] = ichar;
-			return 0;
+			ichar = 0;
+			break;
 		case ESC_REJECT:
 			/*
 			 * invalid escape sequence, start returning the
 			 * characters in it
 			 */
 			cch->esc_save[cch->esc_len++] = ichar;
-			return cch->esc_save[cch->emit_upto++];
+			ichar = cch->esc_save[cch->emit_upto++];
+			cch->emitting = true;
+			break;
 		case ESC_CONVERTED:
 			/* valid escape sequence, return the resulting char */
 			cch->esc_len = 0;
-			return ichar;
+			break;
 		}
 	}
 
common/menu.c +26 -66

152 lines not on this page · raw message

include/cli.h +3 -1
index 863519e4b13..c777c90313f 100644
@@ -14,12 +14,14 @@
  *
  * @esc_len: Number of escape characters read so far
  * @esc_save: Escape characters collected so far
- * @emit_upto: Next character to emit from esc_save (0 if not emitting)
+ * @emit_upto: Next index to emit from esc_save
+ * @emitting: true if emitting from esc_save
  */
 struct cli_ch_state {
 	int esc_len;
 	char esc_save[8];
 	int emit_upto;
+	bool emitting;
 };
 
 /**
include/menu.h +5 -2
index 8b9b36214f7..3996075a337 100644
@@ -6,6 +6,7 @@
 #ifndef __MENU_H__
 #define __MENU_H__
 
+struct cli_ch_state;
 struct menu;
 
 struct menu *menu_create(char *title, int timeout, int prompt,
@@ -71,7 +72,8 @@ enum bootmenu_key {
  *	Ctrl-C: KEY_QUIT
  *	anything else: KEY_NONE
  */
-enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc);
+enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu,
+					 struct cli_ch_state *cch);
 
 /**
  * bootmenu_loop() - handle waiting for a keypress when autoboot is disabled
@@ -96,6 +98,7 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc);
  *	Minus: BKEY_MINUS
  *	Space: BKEY_SPACE
  */
-enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, int *esc);
+enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
+				struct cli_ch_state *cch);
 
 #endif /* __MENU_H__ */
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#9 lore raw

PATCH v2 9/25 image: Add a function to find a script in an image

In reply to Simon Glass

Split this functionality out of the 'source' command so it can be used from another place. For now leave it where it is, but a future patch will move it out of cmd/

---

(no changes since v1)

 cmd/source.c    | 173 ++++++++++++++++++++++++++----------------------
 include/image.h |  13 ++++
 2 files changed, 107 insertions(+), 79 deletions(-)
cmd/source.c +94 -79
index 698d9f86d96..dfa995f1df6 100644
@@ -24,7 +24,6 @@
 #include <asm/byteorder.h>
 #include <asm/io.h>
 
-#if defined(CONFIG_FIT)
 /**
  * get_default_image() - Return default property from /images
  *
@@ -40,123 +39,139 @@ static const char *get_default_image(const void *fit)
 
 	return fdt_getprop(fit, images_noffset, FIT_DEFAULT_PROP, NULL);
 }
-#endif
 
-int image_source_script(ulong addr, const char *fit_uname)
+int image_locate_script(void *buf, int size, const char *fit_uname,
+			char **datap, uint *lenp)
 {
 	ulong		len;
-#if defined(CONFIG_LEGACY_IMAGE_FORMAT)
 	const struct legacy_img_hdr *hdr;
-#endif
 	u32		*data;
 	int		verify;
-	void *buf;
-#if defined(CONFIG_FIT)
 	const void*	fit_hdr;
 	int		noffset;
 	const void	*fit_data;
 	size_t		fit_len;
-#endif
 
 	verify = env_get_yesno("verify");
 
-	buf = map_sysmem(addr, 0);
 	switch (genimg_get_format(buf)) {
-#if defined(CONFIG_LEGACY_IMAGE_FORMAT)
 	case IMAGE_FORMAT_LEGACY:
-		hdr = buf;
+		if (IS_ENABLED(CONFIG_LEGACY_IMAGE_FORMAT)) {
+			hdr = buf;
 
-		if (!image_check_magic (hdr)) {
-			puts ("Bad magic number\n");
-			return 1;
-		}
+			if (!image_check_magic(hdr)) {
+				puts("Bad magic number\n");
+				return 1;
+			}
 
-		if (!image_check_hcrc (hdr)) {
-			puts ("Bad header crc\n");
-			return 1;
-		}
+			if (!image_check_hcrc(hdr)) {
+				puts("Bad header crc\n");
+				return 1;
+			}
+
+			if (verify) {
+				if (!image_check_dcrc(hdr)) {
+					puts("Bad data crc\n");
+					return 1;
+				}
+			}
 
-		if (verify) {
-			if (!image_check_dcrc (hdr)) {
-				puts ("Bad data crc\n");
+			if (!image_check_type(hdr, IH_TYPE_SCRIPT)) {
+				puts("Bad image type\n");
 				return 1;
 			}
-		}
 
-		if (!image_check_type (hdr, IH_TYPE_SCRIPT)) {
-			puts ("Bad image type\n");
-			return 1;
-		}
+			/* get length of script */
+			data = (u32 *)image_get_data(hdr);
 
-		/* get length of script */
-		data = (u32 *)image_get_data (hdr);
+			len = uimage_to_cpu(*data);
+			if (!len) {
+				puts("Empty Script\n");
+				return 1;
+			}
 
-		if ((len = uimage_to_cpu (*data)) == 0) {
-			puts ("Empty Script\n");
-			return 1;
+			/*
+			 * scripts are just multi-image files with one
+			 * component, so seek past the zero-terminated sequence
+			 * of image lengths to get to the actual image data
+			 */
+			while (*data++);
 		}
-
-		/*
-		 * scripts are just multi-image files with one component, seek
-		 * past the zero-terminated sequence of image lengths to get
-		 * to the actual image data
-		 */
-		while (*data++);
 		break;
-#endif
-#if defined(CONFIG_FIT)
 	case IMAGE_FORMAT_FIT:
-		fit_hdr = buf;
-		if (fit_check_format(fit_hdr, IMAGE_SIZE_INVAL)) {
-			puts ("Bad FIT image format\n");
-			return 1;
-		}
+		if (IS_ENABLED(CONFIG_FIT)) {
+			fit_hdr = buf;
+			if (fit_check_format(fit_hdr, IMAGE_SIZE_INVAL)) {
+				puts("Bad FIT image format\n");
+				return 1;
+			}
 
-		if (!fit_uname)
-			fit_uname = get_default_image(fit_hdr);
+			if (!fit_uname)
+				fit_uname = get_default_image(fit_hdr);
 
-		if (!fit_uname) {
-			puts("No FIT subimage unit name\n");
-			return 1;
-		}
+			if (!fit_uname) {
+				puts("No FIT subimage unit name\n");
+				return 1;
+			}
 
-		/* get script component image node offset */
-		noffset = fit_image_get_node (fit_hdr, fit_uname);
-		if (noffset < 0) {
-			printf ("Can't find '%s' FIT subimage\n", fit_uname);
-			return 1;
-		}
+			/* get script component image node offset */
+			noffset = fit_image_get_node(fit_hdr, fit_uname);
+			if (noffset < 0) {
+				printf("Can't find '%s' FIT subimage\n",
+				       fit_uname);
+				return 1;
+			}
 
-		if (!fit_image_check_type (fit_hdr, noffset, IH_TYPE_SCRIPT)) {
-			puts ("Not a image image\n");
-			return 1;
-		}
+			if (!fit_image_check_type(fit_hdr, noffset,
+						  IH_TYPE_SCRIPT)) {
+				puts("Not a image image\n");
+				return 1;
+			}
+
+			/* verify integrity */
+			if (verify) {
+				if (!fit_image_verify(fit_hdr, noffset)) {
+					puts("Bad Data Hash\n");
+					return 1;
+				}
+			}
 
-		/* verify integrity */
-		if (verify) {
-			if (!fit_image_verify(fit_hdr, noffset)) {
-				puts ("Bad Data Hash\n");
+			/* get script subimage data address and length */
+			if (fit_image_get_data(fit_hdr, noffset, &fit_data, &fit_len)) {
+				puts("Could not find script subimage data\n");
 				return 1;
 			}
-		}
 
-		/* get script subimage data address and length */
-		if (fit_image_get_data (fit_hdr, noffset, &fit_data, &fit_len)) {
-			puts ("Could not find script subimage data\n");
-			return 1;
+			data = (u32 *)fit_data;
+			len = (ulong)fit_len;
 		}
-
-		data = (u32 *)fit_data;
-		len = (ulong)fit_len;
 		break;
-#endif
 	default:
-		puts ("Wrong image format for \"source\" command\n");
-		return 1;
+		puts("Wrong image format for \"source\" command\n");
+		return -EPERM;
 	}
 
-	debug("** Script length: %ld\n", len);
-	return run_command_list((char *)data, len, 0);
+	*datap = (char *)data;
+	*lenp = len;
+
+	return 0;
+}
+
+int image_source_script(ulong addr, const char *fit_uname)
+{
+	char *data;
+	void *buf;
+	uint len;
+	int ret;
+
+	buf = map_sysmem(addr, 0);
+	ret = image_locate_script(buf, 0, fit_uname, &data, &len);
+	unmap_sysmem(buf);
+	if (ret)
+		return CMD_RET_FAILURE;
+
+	debug("** Script length: %d\n", len);
+	return run_command_list(data, len, 0);
 }
 
 /**************************************************/
include/image.h +13 -0
index 65d0d4f4387..375b9648e68 100644
@@ -720,6 +720,19 @@ int fit_image_load(struct bootm_headers *images, ulong addr,
  */
 int image_source_script(ulong addr, const char *fit_uname);
 
+/**
+ * image_locate_script() - Locate the raw script in an image
+ *
+ * @buf: Address of image
+ * @size: Size of image in bytes
+ * @fit_uname: Node name of FIT image to read
+ * @datap: Returns pointer to raw script on success
+ * @lenp: Returns size of raw script on success
+ * @return 0 if OK, non-zero on error
+ */
+int image_locate_script(void *buf, int size, const char *fit_uname,
+			char **datap, uint *lenp);
+
 /**
  * fit_get_node_from_config() - Look up an image a FIT by type
  *
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#10 lore raw

PATCH v2 10/25 image: Move common image code to image_board and command

In reply to Simon Glass

We should use the cmd/ directory for commands rather than for common code used elsewhere in U-Boot. Move the common 'source' code into image-board.c to achieve this.

The image_source_script() function needs to call run_command_list() so seems to belong better in the command library. Move and rename it.

---

(no changes since v1)

 .../cmd_stm32prog/cmd_stm32prog.c             |   2 +-
 boot/bootmeth_script.c                        |   2 +-
 boot/image-board.c                            | 133 +++++++++++++++
 cmd/source.c                                  | 155 +-----------------
 common/command.c                              |  19 +++
 drivers/usb/gadget/f_sdp.c                    |   2 +-
 include/command.h                             |  12 ++
 include/image.h                               |  12 --
 8 files changed, 168 insertions(+), 169 deletions(-)
arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c +1 -1
index 007f7131306..6fb3d868d77 100644
@@ -154,7 +154,7 @@ static int do_stm32prog(struct cmd_tbl *cmdtp, int flag, int argc,
 			do_bootz(cmdtp, 0, 4, bootm_argv);
 	}
 	if (data->script)
-		image_source_script(data->script, "script@stm32prog");
+		cmd_source_script(data->script, "script@stm32prog");
 
 	if (reset) {
 		puts("Reset...\n");
boot/bootmeth_script.c +1 -1
index d1c3f940037..16c5dadcca1 100644
@@ -101,7 +101,7 @@ static int script_boot(struct udevice *dev, struct bootflow *bflow)
 	log_debug("mmc_bootdev: %s\n", env_get("mmc_bootdev"));
 
 	addr = map_to_sysmem(bflow->buf);
-	ret = image_source_script(addr, NULL);
+	ret = cmd_source_script(addr, NULL);
 	if (ret)
 		return log_msg_ret("boot", ret);
 
boot/image-board.c +133 -0

136 lines not on this page · raw message

cmd/source.c +1 -154

170 lines not on this page · raw message

common/command.c +19 -0
index 41c91c6d8c8..1f52a15bc12 100644
@@ -13,7 +13,9 @@
 #include <command.h>
 #include <console.h>
 #include <env.h>
+#include <image.h>
 #include <log.h>
+#include <mapmem.h>
 #include <asm/global_data.h>
 #include <linux/ctype.h>
 
@@ -654,3 +656,20 @@ int cmd_process_error(struct cmd_tbl *cmdtp, int err)
 
 	return CMD_RET_SUCCESS;
 }
+
+int cmd_source_script(ulong addr, const char *fit_uname)
+{
+	char *data;
+	void *buf;
+	uint len;
+	int ret;
+
+	buf = map_sysmem(addr, 0);
+	ret = image_locate_script(buf, 0, fit_uname, &data, &len);
+	unmap_sysmem(buf);
+	if (ret)
+		return CMD_RET_FAILURE;
+
+	debug("** Script length: %d\n", len);
+	return run_command_list(data, len, 0);
+}
drivers/usb/gadget/f_sdp.c +1 -1
index af4b167e17a..282c15ce21f 100644
@@ -868,7 +868,7 @@ static int sdp_handle_in_ep(struct spl_image_info *spl_image,
 			jump_to_image_no_args(&spl_image);
 #else
 			/* In U-Boot, allow jumps to scripts */
-			image_source_script(sdp_func->jmp_address, "script@1");
+			cmd_source_script(sdp_func->jmp_address, "script@1");
 #endif
 		}
 
include/command.h +12 -0
index 966fd23c639..f32d41ccc34 100644
@@ -279,6 +279,18 @@ int run_commandf(const char *fmt, ...);
  * Return: 0 on success, or != 0 on error.
  */
 int run_command_list(const char *cmd, int len, int flag);
+
+/**
+ * cmd_source_script() - Execute a script
+ *
+ * Executes a U-Boot script at a particular address in memory. The script should
+ * have a header (FIT or legacy) with the script type (IH_TYPE_SCRIPT).
+ *
+ * @addr: Address of script
+ * @fit_uname: FIT subimage name
+ * Return: result code (enum command_ret_t)
+ */
+int cmd_source_script(ulong addr, const char *fit_uname);
 #endif	/* __ASSEMBLY__ */
 
 /*
include/image.h +0 -12
index 375b9648e68..306d2528d74 100644
@@ -708,18 +708,6 @@ int fit_image_load(struct bootm_headers *images, ulong addr,
 		   int arch, int image_ph_type, int bootstage_id,
 		   enum fit_load_op load_op, ulong *datap, ulong *lenp);
 
-/**
- * image_source_script() - Execute a script
- *
- * Executes a U-Boot script at a particular address in memory. The script should
- * have a header (FIT or legacy) with the script type (IH_TYPE_SCRIPT).
- *
- * @addr: Address of script
- * @fit_uname: FIT subimage name
- * Return: result code (enum command_ret_t)
- */
-int image_source_script(ulong addr, const char *fit_uname);
-
 /**
  * image_locate_script() - Locate the raw script in an image
  *
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#11 lore raw

PATCH v2 11/25 video: Enable VIDEO_ANSI by default only with EFI

In reply to Simon Glass

This is not generally needed unless EFI_LOADER is used. Adjust the default setting to reduce the size of the U-Boot build.

---

(no changes since v1)

 drivers/video/Kconfig | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/video/Kconfig +5 -2
index c841b99bb30..0c914dc1165 100644
@@ -112,10 +112,13 @@ config VIDEO_BPP32
 
 config VIDEO_ANSI
 	bool "Support ANSI escape sequences in video console"
-	default y
+	default y if EFI_LOADER
 	help
 	  Enable ANSI escape sequence decoding for a more fully functional
-	  console.
+	  console. Functionality includes changing the text colour and moving
+	  the cursor. These date from the 1970s and are still widely used today
+	  to control a text terminal. U-Boot implements these by decoding the
+	  sequences and performing the appropriate operation.
 
 config VIDEO_MIPI_DSI
 	bool "Support MIPI DSI interface"
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#12 lore raw

PATCH v2 12/25 video: truetype: Rename the metrics function

In reply to Simon Glass

This should really have a 'truetype' prefix. Fix it.

---

(no changes since v1)

 drivers/video/console_truetype.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/video/console_truetype.c +5 -5
index 6859c9fa116..4abc0bc2ff1 100644
@@ -595,7 +595,7 @@ void vidconsole_list_fonts(void)
 }
 
 /**
- * vidconsole_add_metrics() - Add a new font/size combination
+ * truetype_add_metrics() - Add a new font/size combination
  *
  * @dev:	Video console device to update
  * @font_name:	Name of font
@@ -604,8 +604,8 @@ void vidconsole_list_fonts(void)
  * @return 0 if OK, -EPERM if stbtt failed, -E2BIG if the the metrics table is
  *	full
  */
-static int vidconsole_add_metrics(struct udevice *dev, const char *font_name,
-				  uint font_size, const void *font_data)
+static int truetype_add_metrics(struct udevice *dev, const char *font_name,
+				uint font_size, const void *font_data)
 {
 	struct console_tt_priv *priv = dev_get_priv(dev);
 	struct console_tt_metrics *met;
@@ -693,7 +693,7 @@ int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
 				    !strcmp(name, tab->name)) {
 					int ret;
 
-					ret = vidconsole_add_metrics(dev,
+					ret = truetype_add_metrics(dev,
 						tab->name, size, tab->begin);
 					if (ret < 0)
 						return log_msg_ret("add", ret);
@@ -745,7 +745,7 @@ static int console_truetype_probe(struct udevice *dev)
 		return -EBFONT;
 	}
 
-	ret = vidconsole_add_metrics(dev, tab->name, font_size, tab->begin);
+	ret = truetype_add_metrics(dev, tab->name, font_size, tab->begin);
 	if (ret < 0)
 		return log_msg_ret("add", ret);
 	priv->cur_met = &priv->metrics[ret];
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#13 lore raw

PATCH v2 13/25 video: Fix unchnaged typo

In reply to Simon Glass

Fix this typo in the header file.

---

(no changes since v1)

 include/video.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/video.h +1 -1
index 43f2e2c02f0..3f67a93bc93 100644
@@ -248,7 +248,7 @@ void video_bmp_get_info(void *bmp_image, ulong *widthp, ulong *heightp,
  *		  that direction
  *		- if a coordinate is -ve then it will be offset to the
  *		  left/top of the centre by that many pixels
- *		- if a coordinate is positive it will be used unchnaged.
+ *		- if a coordinate is positive it will be used unchanged.
  * Return: 0 if OK, -ve on error
  */
 int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y,
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#14 lore raw

PATCH v2 14/25 video: Add font functions to the vidconsole API

In reply to Simon Glass

Support for fonts currently depends on the type of vidconsole in use. Add two new methods to enumerate fonts and to set the font.

Fix a few other method comments while we are here.

---

Changes in v2:
- Rename vidconsole_get_font() to vidconsole_get_font_size()

 cmd/font.c                        | 11 ++++-
 drivers/video/console_truetype.c  | 27 +++++++----
 drivers/video/vidconsole-uclass.c | 33 ++++++++++++++
 include/video_console.h           | 75 ++++++++++++++++++++++++++-----
 test/cmd/font.c                   |  6 +--
 5 files changed, 127 insertions(+), 25 deletions(-)
cmd/font.c +9 -2
index 3e522f3aaa1..7b4347f32b5 100644
@@ -15,7 +15,11 @@
 static int do_font_list(struct cmd_tbl *cmdtp, int flag, int argc,
 			char *const argv[])
 {
-	vidconsole_list_fonts();
+	struct udevice *dev;
+
+	if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
+		return CMD_RET_FAILURE;
+	vidconsole_list_fonts(dev);
 
 	return 0;
 }
@@ -47,6 +51,7 @@ static int do_font_select(struct cmd_tbl *cmdtp, int flag, int argc,
 static int do_font_size(struct cmd_tbl *cmdtp, int flag, int argc,
 			char *const argv[])
 {
+	const char *font_name;
 	struct udevice *dev;
 	uint size;
 	int ret;
@@ -56,9 +61,11 @@ static int do_font_size(struct cmd_tbl *cmdtp, int flag, int argc,
 
 	if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
 		return CMD_RET_FAILURE;
+	font_name = vidconsole_get_font_size(dev, &size);
 
 	size = dectoul(argv[1], NULL);
-	ret = vidconsole_select_font(dev, NULL, size);
+
+	ret = vidconsole_select_font(dev, font_name, size);
 	if (ret) {
 		printf("Failed (error %d)\n", ret);
 		return CMD_RET_FAILURE;
drivers/video/console_truetype.c +19 -8
index 4abc0bc2ff1..9cac9a6de4d 100644
@@ -584,14 +584,20 @@ static struct font_info *console_truetype_find_font(void)
 	return NULL;
 }
 
-void vidconsole_list_fonts(void)
+int console_truetype_get_font(struct udevice *dev, int seq,
+			      struct vidfont_info *info)
 {
 	struct font_info *tab;
+	int i;
 
-	for (tab = font_table; tab->begin; tab++) {
-		if (abs(tab->begin - tab->end) > 4)
-			printf("%s\n", tab->name);
+	for (i = 0, tab = font_table; tab->begin; tab++, i++) {
+		if (i == seq && font_valid(tab)) {
+			info->name = tab->name;
+			return 0;
+		}
 	}
+
+	return -ENOENT;
 }
 
 /**
@@ -674,7 +680,8 @@ static void select_metrics(struct udevice *dev, struct console_tt_metrics *met)
 	vc_priv->tab_width_frac = VID_TO_POS(met->font_size) * 8 / 2;
 }
 
-int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
+static int truetype_select_font(struct udevice *dev, const char *name,
+				uint size)
 {
 	struct console_tt_priv *priv = dev_get_priv(dev);
 	struct console_tt_metrics *met;
@@ -684,7 +691,7 @@ int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
 		if (!size)
 			size = CONFIG_CONSOLE_TRUETYPE_SIZE;
 		if (!name)
-			name = priv->cur_met->font_name;
+			name = font_table->name;
 
 		met = find_metrics(dev, name, size);
 		if (!met) {
@@ -694,7 +701,9 @@ int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
 					int ret;
 
 					ret = truetype_add_metrics(dev,
-						tab->name, size, tab->begin);
+								   tab->name,
+								   size,
+								   tab->begin);
 					if (ret < 0)
 						return log_msg_ret("add", ret);
 
@@ -715,7 +724,7 @@ int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
 	return 0;
 }
 
-const char *vidconsole_get_font(struct udevice *dev, uint *sizep)
+const char *vidconsole_get_font_size(struct udevice *dev, uint *sizep)
 {
 	struct console_tt_priv *priv = dev_get_priv(dev);
 	struct console_tt_metrics *met = priv->cur_met;
@@ -763,6 +772,8 @@ struct vidconsole_ops console_truetype_ops = {
 	.set_row	= console_truetype_set_row,
 	.backspace	= console_truetype_backspace,
 	.entry_start	= console_truetype_entry_start,
+	.get_font	= console_truetype_get_font,
+	.select_font	= truetype_select_font,
 };
 
 U_BOOT_DRIVER(vidconsole_truetype) = {
drivers/video/vidconsole-uclass.c +33 -0
index 6bdfb6e37dd..aadd54bfd4f 100644
@@ -557,6 +557,39 @@ static void vidconsole_puts(struct stdio_dev *sdev, const char *s)
 	}
 }
 
+void vidconsole_list_fonts(struct udevice *dev)
+{
+	struct vidfont_info info;
+	int ret, i;
+
+	for (i = 0, ret = 0; !ret; i++) {
+		ret = vidconsole_get_font(dev, i, &info);
+		if (!ret)
+			printf("%s\n", info.name);
+	}
+}
+
+int vidconsole_get_font(struct udevice *dev, int seq,
+			struct vidfont_info *info)
+{
+	struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+
+	if (!ops->get_font)
+		return -ENOSYS;
+
+	return ops->get_font(dev, seq, info);
+}
+
+int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
+{
+	struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+
+	if (!ops->select_font)
+		return -ENOSYS;
+
+	return ops->select_font(dev, name, size);
+}
+
 /* Set up the number of rows and colours (rotated drivers override this) */
 static int vidconsole_pre_probe(struct udevice *dev)
 {
include/video_console.h +63 -12

119 lines not on this page · raw message

test/cmd/font.c +3 -3
index 7a4156ade62..adb353965a7 100644
@@ -33,7 +33,7 @@ static int font_test_base(struct unit_test_state *uts)
 	ut_assertok(ut_check_console_end(uts));
 
 	ut_asserteq_str("nimbus_sans_l_regular",
-			vidconsole_get_font(dev, &size));
+			vidconsole_get_font_size(dev, &size));
 	ut_asserteq(18, size);
 
 	max_metrics = 1;
@@ -53,14 +53,14 @@ static int font_test_base(struct unit_test_state *uts)
 	ut_assertok(ut_check_console_end(uts));
 
 	ut_asserteq_str("cantoraone_regular",
-			vidconsole_get_font(dev, &size));
+			vidconsole_get_font_size(dev, &size));
 	ut_asserteq(40, size);
 
 	ut_assertok(run_command("font size 30", 0));
 	ut_assertok(ut_check_console_end(uts));
 
 	ut_asserteq_str("cantoraone_regular",
-			vidconsole_get_font(dev, &size));
+			vidconsole_get_font_size(dev, &size));
 	ut_asserteq(30, size);
 
 	return 0;
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#15 lore raw

PATCH v2 15/25 bootstd: Read the Operating System name for distro/scripts

In reply to Simon Glass

Add the concept of an OS name to the bootflow. This typically includes the OS name, version and kernel version.

Implement this for the distro and script bootmeths so that it works with Armbian and older version of Fedora.

---

(no changes since v1)

 boot/bootflow.c        |  1 +
 boot/bootmeth_distro.c | 36 ++++++++++++++++++++++++++++++++++++
 boot/bootmeth_script.c | 34 ++++++++++++++++++++++++++++++++++
 cmd/bootflow.c         |  1 +
 include/bootflow.h     |  3 +++
 test/boot/bootflow.c   |  1 +
 6 files changed, 76 insertions(+)
boot/bootflow.c +1 -0
index f9ad4099244..163cd4953dd 100644
@@ -354,6 +354,7 @@ void bootflow_free(struct bootflow *bflow)
 	free(bflow->subdir);
 	free(bflow->fname);
 	free(bflow->buf);
+	free(bflow->os_name);
 }
 
 void bootflow_remove(struct bootflow *bflow)
boot/bootmeth_distro.c +36 -0
index 5c6c687f0a6..6ef0fa1f2c9 100644
@@ -66,6 +66,38 @@ static int distro_check(struct udevice *dev, struct bootflow_iter *iter)
 	return 0;
 }
 
+/**
+ * distro_fill_info() - Decode the extlinux file to find out distro info
+ *
+ * @bflow: Bootflow to process
+ * @return 0 if OK, -ve on error
+ */
+static int distro_fill_info(struct bootflow *bflow)
+{
+	struct membuff mb;
+	char line[200];
+	char *data;
+	int len;
+
+	log_debug("parsing bflow file size %x\n", bflow->size);
+	membuff_init(&mb, bflow->buf, bflow->size);
+	membuff_putraw(&mb, bflow->size, true, &data);
+	while (len = membuff_readline(&mb, line, sizeof(line) - 1, ' '), len) {
+		char *tok, *p = line;
+
+		tok = strsep(&p, " ");
+		if (p) {
+			if (!strcmp("label", tok)) {
+				bflow->os_name = strdup(p);
+				if (!bflow->os_name)
+					return log_msg_ret("os", -ENOMEM);
+			}
+		}
+	}
+
+	return 0;
+}
+
 static int distro_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 {
 	struct blk_desc *desc;
@@ -99,6 +131,10 @@ static int distro_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 	if (ret)
 		return log_msg_ret("read", ret);
 
+	ret = distro_fill_info(bflow);
+	if (ret)
+		return log_msg_ret("inf", ret);
+
 	return 0;
 }
 
boot/bootmeth_script.c +34 -0
index 16c5dadcca1..6f2a09846db 100644
@@ -35,6 +35,36 @@ static int script_check(struct udevice *dev, struct bootflow_iter *iter)
 	return 0;
 }
 
+/**
+ * script_fill_info() - Decode the U-Boot script to find out distro info
+ *
+ * @bflow: Bootflow to process
+ * @return 0 if OK, -ve on error
+ */
+static int script_fill_info(struct bootflow *bflow)
+{
+	char *name = NULL;
+	char *data;
+	uint len;
+	int ret;
+
+	log_debug("parsing bflow file size %x\n", bflow->size);
+
+	ret = image_locate_script(bflow->buf, bflow->size, NULL, &data, &len);
+	if (!ret) {
+		if (strstr(data, "armbianEnv"))
+			name = "Armbian";
+	}
+
+	if (name) {
+		bflow->os_name = strdup(name);
+		if (!bflow->os_name)
+			return log_msg_ret("os", -ENOMEM);
+	}
+
+	return 0;
+}
+
 static int script_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 {
 	struct blk_desc *desc = NULL;
@@ -75,6 +105,10 @@ static int script_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 	if (ret)
 		return log_msg_ret("read", ret);
 
+	ret = script_fill_info(bflow);
+	if (ret)
+		return log_msg_ret("inf", ret);
+
 	return 0;
 }
 
cmd/bootflow.c +1 -0
index 313103d2775..6b8ac8c8504 100644
@@ -337,6 +337,7 @@ static int do_bootflow_info(struct cmd_tbl *cmdtp, int flag, int argc,
 	printf("Filename:  %s\n", bflow->fname);
 	printf("Buffer:    %lx\n", (ulong)map_to_sysmem(bflow->buf));
 	printf("Size:      %x (%d bytes)\n", bflow->size, bflow->size);
+	printf("OS:        %s\n", bflow->os_name ? bflow->os_name : "(none)");
 	printf("Error:     %d\n", bflow->err);
 	if (dump && bflow->buf) {
 		/* Set some sort of maximum on the size */
include/bootflow.h +3 -0
index 32dbbbbe261..776158c65df 100644
@@ -52,6 +52,8 @@ enum bootflow_state_t {
  * @buf: Bootflow file contents (allocated)
  * @size: Size of bootflow file in bytes
  * @err: Error number received (0 if OK)
+ * @os_name: Name of the OS / distro being booted, or NULL if not known
+ *	(allocated)
  */
 struct bootflow {
 	struct list_head bm_node;
@@ -68,6 +70,7 @@ struct bootflow {
 	char *buf;
 	int size;
 	int err;
+	char *os_name;
 };
 
 /**
test/boot/bootflow.c +1 -0
index e1e07082105..3296316cf0d 100644
@@ -188,6 +188,7 @@ 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("Error:     0");
 	ut_assert_console_end();
 
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#16 lore raw

PATCH v2 16/25 bootstd: Allow reading a logo for the OS

In reply to Simon Glass

Some operating systems provide a logo in bmp format. Read this in if present so it can be displayed in the menu.

---

(no changes since v1)

 boot/bootmeth-uclass.c | 69 ++++++++++++++++++++++++++++++++++++------
 boot/bootmeth_script.c |  4 +++
 cmd/bootflow.c         |  6 ++++
 include/bootflow.h     |  4 +++
 include/bootmeth.h     | 16 ++++++++++
 test/boot/bootflow.c   |  1 +
 6 files changed, 91 insertions(+), 9 deletions(-)
boot/bootmeth-uclass.c +60 -9
index 25552dd96f6..4c3529d1555 100644
@@ -290,25 +290,19 @@ int bootmeth_try_file(struct bootflow *bflow, struct blk_desc *desc,
 	return 0;
 }
 
-int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align)
+static int alloc_file(const char *fname, uint size, void **bufp)
 {
 	loff_t bytes_read;
 	ulong addr;
 	char *buf;
-	uint size;
 	int ret;
 
-	size = bflow->size;
-	log_debug("   - script file size %x\n", size);
-	if (size > size_limit)
-		return log_msg_ret("chk", -E2BIG);
-
-	buf = memalign(align, size + 1);
+	buf = malloc(size + 1);
 	if (!buf)
 		return log_msg_ret("buf", -ENOMEM);
 	addr = map_to_sysmem(buf);
 
-	ret = fs_read(bflow->fname, addr, 0, 0, &bytes_read);
+	ret = fs_read(fname, addr, 0, size, &bytes_read);
 	if (ret) {
 		free(buf);
 		return log_msg_ret("read", ret);
@@ -316,12 +310,69 @@ int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align)
 	if (size != bytes_read)
 		return log_msg_ret("bread", -EINVAL);
 	buf[size] = '\0';
+
+	*bufp = buf;
+
+	return 0;
+}
+
+int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align)
+{
+	void *buf;
+	uint size;
+	int ret;
+
+	size = bflow->size;
+	log_debug("   - script file size %x\n", size);
+	if (size > size_limit)
+		return log_msg_ret("chk", -E2BIG);
+
+	ret = alloc_file(bflow->fname, bflow->size, &buf);
+	if (ret)
+		return log_msg_ret("all", ret);
+
 	bflow->state = BOOTFLOWST_READY;
 	bflow->buf = buf;
 
 	return 0;
 }
 
+int bootmeth_alloc_other(struct bootflow *bflow, const char *fname,
+			 void **bufp, uint *sizep)
+{
+	struct blk_desc *desc = NULL;
+	char path[200];
+	loff_t size;
+	void *buf;
+	int ret;
+
+	snprintf(path, sizeof(path), "%s%s", bflow->subdir, fname);
+	log_debug("trying: %s\n", path);
+
+	if (bflow->blk)
+		desc = dev_get_uclass_plat(bflow->blk);
+
+	ret = setup_fs(bflow, desc);
+	if (ret)
+		return log_msg_ret("fs", ret);
+
+	ret = fs_size(path, &size);
+	log_debug("   %s - err=%d\n", path, ret);
+
+	ret = setup_fs(bflow, desc);
+	if (ret)
+		return log_msg_ret("fs", ret);
+
+	ret = alloc_file(path, size, &buf);
+	if (ret)
+		return log_msg_ret("all", ret);
+
+	*bufp = buf;
+	*sizep = size;
+
+	return 0;
+}
+
 int bootmeth_common_read_file(struct udevice *dev, struct bootflow *bflow,
 			      const char *file_path, ulong addr, ulong *sizep)
 {
boot/bootmeth_script.c +4 -0
index 6f2a09846db..a8f77e29f99 100644
@@ -109,6 +109,10 @@ static int script_read_bootflow(struct udevice *dev, struct bootflow *bflow)
 	if (ret)
 		return log_msg_ret("inf", ret);
 
+	ret = bootmeth_alloc_other(bflow, "boot.bmp", &bflow->logo,
+				   &bflow->logo_size);
+	/* ignore error */
+
 	return 0;
 }
 
cmd/bootflow.c +6 -0
index 6b8ac8c8504..495ef85f25b 100644
@@ -338,6 +338,12 @@ static int do_bootflow_info(struct cmd_tbl *cmdtp, int flag, int argc,
 	printf("Buffer:    %lx\n", (ulong)map_to_sysmem(bflow->buf));
 	printf("Size:      %x (%d bytes)\n", bflow->size, bflow->size);
 	printf("OS:        %s\n", bflow->os_name ? bflow->os_name : "(none)");
+	printf("Logo:      %s\n", bflow->logo ?
+	       simple_xtoa((ulong)map_to_sysmem(bflow->logo)) : "(none)");
+	if (bflow->logo) {
+		printf("Logo size: %x (%d bytes)\n", bflow->logo_size,
+		       bflow->logo_size);
+	}
 	printf("Error:     %d\n", bflow->err);
 	if (dump && bflow->buf) {
 		/* Set some sort of maximum on the size */
include/bootflow.h +4 -0
index 776158c65df..8a07ab30191 100644
@@ -49,6 +49,8 @@ enum bootflow_state_t {
  * @state: Current state (enum bootflow_state_t)
  * @subdir: Subdirectory to fetch files from (with trailing /), or NULL if none
  * @fname: Filename of bootflow file (allocated)
+ * @logo: Logo to display for this bootflow (BMP format)
+ * @logo_size: Size of the logo in bytes
  * @buf: Bootflow file contents (allocated)
  * @size: Size of bootflow file in bytes
  * @err: Error number received (0 if OK)
@@ -67,6 +69,8 @@ struct bootflow {
 	enum bootflow_state_t state;
 	char *subdir;
 	char *fname;
+	void *logo;
+	uint logo_size;
 	char *buf;
 	int size;
 	int err;
include/bootmeth.h +16 -0
index 50ded055f3f..669b14ce81e 100644
@@ -265,6 +265,22 @@ int bootmeth_try_file(struct bootflow *bflow, struct blk_desc *desc,
  */
 int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align);
 
+/**
+ * bootmeth_alloc_other() - Allocate and read a file for a bootflow
+ *
+ * This reads an arbitrary file in the same directory as the bootflow,
+ * allocating memory for it. The buffer is one byte larger than the file length,
+ * so that it can be nul-terminated.
+ *
+ * @bflow: Information about file to read
+ * @fname: Filename to read from (within bootflow->subdir)
+ * @bufp: Returns a pointer to the allocated buffer
+ * @sizep: Returns the size of the buffer
+ * Return: 0 if OK,  -ENOMEM if out of memory, other -ve on other error
+ */
+int bootmeth_alloc_other(struct bootflow *bflow, const char *fname,
+			 void **bufp, uint *sizep);
+
 /**
  * bootmeth_common_read_file() - Common handler for reading a file
  *
test/boot/bootflow.c +1 -0
index 3296316cf0d..00dfd990687 100644
@@ -189,6 +189,7 @@ static int bootflow_cmd_info(struct unit_test_state *uts)
 	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();
 
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#17 lore raw

PATCH v2 17/25 menu: Factor out menu-keypress decoding

In reply to Simon Glass

Move this code into a separate function so that it can be used in the new VBE menu.

---

(no changes since v1)

 common/menu.c  | 48 ++++++++++++++++++++++++++++++------------------
 include/menu.h | 10 ++++++++++
 2 files changed, 40 insertions(+), 18 deletions(-)
common/menu.c +30 -18
index 45f36ae3ede..cdcdbb2a185 100644
@@ -483,26 +483,11 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu,
 	return key;
 }
 
-enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
-				struct cli_ch_state *cch)
+enum bootmenu_key bootmenu_conv_key(int ichar)
 {
-	enum bootmenu_key key = BKEY_NONE;
-	int c;
-
-	c = cli_ch_process(cch, 0);
-	if (!c) {
-		while (!c && !tstc()) {
-			schedule();
-			mdelay(10);
-			c = cli_ch_process(cch, -ETIMEDOUT);
-		}
-		if (!c) {
-			c = getchar();
-			c = cli_ch_process(cch, c);
-		}
-	}
+	enum bootmenu_key key;
 
-	switch (c) {
+	switch (ichar) {
 	case '\n':
 		/* enter key was pressed */
 		key = BKEY_SELECT;
@@ -527,7 +512,34 @@ enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
 	case ' ':
 		key = BKEY_SPACE;
 		break;
+	default:
+		key = BKEY_NONE;
+		break;
+	}
+
+	return key;
+}
+
+enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
+				struct cli_ch_state *cch)
+{
+	enum bootmenu_key key;
+	int c;
+
+	c = cli_ch_process(cch, 0);
+	if (!c) {
+		while (!c && !tstc()) {
+			schedule();
+			mdelay(10);
+			c = cli_ch_process(cch, -ETIMEDOUT);
+		}
+		if (!c) {
+			c = getchar();
+			c = cli_ch_process(cch, c);
+		}
 	}
 
+	key = bootmenu_conv_key(c);
+
 	return key;
 }
include/menu.h +10 -0
index 3996075a337..1e88141d6bf 100644
@@ -53,6 +53,8 @@ enum bootmenu_key {
 	BKEY_PLUS,
 	BKEY_MINUS,
 	BKEY_SPACE,
+
+	BKEY_COUNT,
 };
 
 /**
@@ -101,4 +103,12 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu,
 enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
 				struct cli_ch_state *cch);
 
+/**
+ * bootmenu_conv_key() - Convert a U-Boot keypress into a menu key
+ *
+ * @ichar: Keypress to convert (ASCII, including control characters)
+ * Returns: Menu key that corresponds to @ichar, or BKEY_NONE if none
+ */
+enum bootmenu_key bootmenu_conv_key(int ichar);
+
 #endif /* __MENU_H__ */
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#18 lore raw

PATCH v2 18/25 expo: Add basic implementation

In reply to Simon Glass

An expo is a way of presenting and collecting information from the user. It consists of a collection of 'scenes' of which only one is presented at a time. An expo is typically used to show a boot menu and allow settings to be changed.

One created, the same expo can be automatically presented in graphical form using a vidconsole, or in text form on a serial console.

Add an initial implementation of the expo itself. Supports for scenes and objects is provided later.

---

Changes in v2:
- Drop the _add suffix on expo creation function
- Put strings in a separate structure referenced by ID

 boot/Kconfig                 |  12 +
 boot/expo.c                  | 170 ++++++++++++
 configs/tools-only_defconfig |   2 +
 include/expo.h               | 521 +++++++++++++++++++++++++++++++++++
 4 files changed, 705 insertions(+)
 create mode 100644 boot/expo.c
 create mode 100644 include/expo.h
boot/Kconfig +12 -0
index d5c582ebe8c..2d81aa46153 100644
@@ -556,6 +556,18 @@ config VPL_BOOTMETH_VBE_SIMPLE_FW
 
 endif # BOOTMETH_VBE
 
+config EXPO
+	bool "Support for expos - groups of scenes displaying a UI"
+	default y if BOOTMETH_VBE
+	help
+	  An expo is a way of presenting and collecting information from the
+	  user. It consists of a collection of 'scenes' of which only one is
+	  presented at a time. An expo is typically used to show a boot menu
+	  and allow settings to be changed.
+
+	  The expo can be presented in graphics form using a vidconsole, or in
+	  text form on a serial console.
+
 config BOOTMETH_SANDBOX
 	def_bool y
 	depends on SANDBOX
boot/expo.c new file +170 -0

170 lines not on this page · raw message

configs/tools-only_defconfig +2 -0
index 88a1271f7e3..6da9a0a2cd7 100644
@@ -7,6 +7,8 @@ CONFIG_ANDROID_BOOT_IMAGE=y
 CONFIG_FIT=y
 CONFIG_TIMESTAMP=y
 CONFIG_FIT_SIGNATURE=y
+# CONFIG_BOOTSTD_FULL is not set
+# CONFIG_BOOTMETH_VBE is not set
 CONFIG_USE_BOOTCOMMAND=y
 CONFIG_BOOTCOMMAND="run distro_bootcmd"
 # CONFIG_CMD_BOOTD is not set
include/expo.h new file +521 -0

521 lines not on this page · raw message

Signature · 1 line
2.38.1.431.g37b22c650d-goog
#19 lore raw

PATCH v2 19/25 expo: Add support for scenes

In reply to Simon Glass

A scene is a single screen within an expo. It is possible to move between scenes but only one can be displayed at once.

Add a basic implementation.

---

Changes in v2:
- Drop the _add suffix on expo creation function
- Put strings in a separate structure referenced by ID

 boot/scene.c          | 414 ++++++++++++++++++++++++++++++++++++++++++
 boot/scene_internal.h | 123 +++++++++++++
 2 files changed, 537 insertions(+)
 create mode 100644 boot/scene.c
 create mode 100644 boot/scene_internal.h
boot/scene.c new file +414 -0
new file mode 100644
index 00000000000..030f6aa2a0a
@@ -0,0 +1,414 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Implementation of a scene, a collection of text/image/menu items in an expo
+ *
+ * Copyright 2022 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <expo.h>
+#include <malloc.h>
+#include <mapmem.h>
+#include <video.h>
+#include <video_console.h>
+#include <linux/input.h>
+#include "scene_internal.h"
+
+uint resolve_id(struct expo *exp, uint id)
+{
+	if (!id)
+		id = exp->next_id++;
+	else if (id >= exp->next_id)
+		exp->next_id = id + 1;
+
+	return id;
+}
+
+int scene_new(struct expo *exp, const char *name, uint id, struct scene **scnp)
+{
+	struct scene *scn;
+
+	scn = calloc(1, sizeof(struct scene));
+	if (!scn)
+		return log_msg_ret("expo", -ENOMEM);
+	scn->name = strdup(name);
+	if (!scn->name) {
+		free(scn);
+		return log_msg_ret("name", -ENOMEM);
+	}
+
+	INIT_LIST_HEAD(&scn->obj_head);
+	scn->id = resolve_id(exp, id);
+	scn->expo = exp;
+	list_add_tail(&scn->sibling, &exp->scene_head);
+
+	*scnp = scn;
+
+	return scn->id;
+}
+
+void scene_obj_destroy(struct scene_obj *obj)
+{
+	if (obj->type == SCENEOBJT_MENU)
+		scene_menu_destroy((struct scene_obj_menu *)obj);
+	free(obj->name);
+	free(obj);
+}
+
+void scene_destroy(struct scene *scn)
+{
+	struct scene_obj *obj, *next;
+
+	list_for_each_entry_safe(obj, next, &scn->obj_head, sibling)
+		scene_obj_destroy(obj);
+
+	free(scn->name);
+	free(scn->title);
+	free(scn);
+}
+
+int scene_title_set(struct scene *scn, const char *title)
+{
+	free(scn->title);
+	scn->title = strdup(title);
+	if (!scn->title)
+		return log_msg_ret("tit", -ENOMEM);
+
+	return 0;
+}
+
+int scene_obj_count(struct scene *scn)
+{
+	struct scene_obj *obj;
+	int count = 0;
+
+	list_for_each_entry(obj, &scn->obj_head, sibling)
+		count++;
+
+	return count;
+}
+
+void *scene_obj_find(struct scene *scn, uint id, enum scene_obj_t type)
+{
+	struct scene_obj *obj;
+
+	list_for_each_entry(obj, &scn->obj_head, sibling) {
+		if (obj->id == id &&
+		    (type == SCENEOBJT_NONE || obj->type == type))
+			return obj;
+	}
+
+	return NULL;
+}
+
+int scene_obj_add(struct scene *scn, const char *name, uint id,
+		  enum scene_obj_t type, uint size, struct scene_obj **objp)
+{
+	struct scene_obj *obj;
+
+	obj = calloc(1, size);
+	if (!obj)
+		return log_msg_ret("obj", -ENOMEM);
+	obj->name = strdup(name);
+	if (!obj->name) {
+		free(obj);
+		return log_msg_ret("name", -ENOMEM);
+	}
+
+	obj->id = resolve_id(scn->expo, id);
+	obj->scene = scn;
+	obj->type = type;
+	list_add_tail(&obj->sibling, &scn->obj_head);
+	*objp = obj;
+
+	return obj->id;
+}
+
+int scene_img(struct scene *scn, const char *name, uint id, char *data,
+	      struct scene_obj_img **imgp)
+{
+	struct scene_obj_img *img;
+	int ret;
+
+	ret = scene_obj_add(scn, name, id, SCENEOBJT_IMAGE,
+			    sizeof(struct scene_obj_img),
+			    (struct scene_obj **)&img);
+	if (ret < 0)
+		return log_msg_ret("obj", -ENOMEM);
+
+	img->data = data;
+
+	if (imgp)
+		*imgp = img;
+
+	return img->obj.id;
+}
+
+int scene_txt(struct scene *scn, const char *name, uint id, uint str_id,
+	      struct scene_obj_txt **txtp)
+{
+	struct scene_obj_txt *txt;
+	int ret;
+
+	ret = scene_obj_add(scn, name, id, SCENEOBJT_TEXT,
+			    sizeof(struct scene_obj_txt),
+			    (struct scene_obj **)&txt);
+	if (ret < 0)
+		return log_msg_ret("obj", -ENOMEM);
+
+	txt->str_id = str_id;
+
+	if (txtp)
+		*txtp = txt;
+
+	return txt->obj.id;
+}
+
+int scene_txt_str(struct scene *scn, const char *name, uint id, uint str_id,
+		  const char *str, struct scene_obj_txt **txtp)
+{
+	struct scene_obj_txt *txt;
+	int ret;
+
+	ret = expo_str(scn->expo, name, str_id, str);
+	if (ret < 0)
+		return log_msg_ret("str", ret);
+	else if (ret != str_id)
+		return log_msg_ret("id", -EEXIST);
+
+	ret = scene_obj_add(scn, name, id, SCENEOBJT_TEXT,
+			    sizeof(struct scene_obj_txt),
+			    (struct scene_obj **)&txt);
+	if (ret < 0)
+		return log_msg_ret("obj", -ENOMEM);
+
+	txt->str_id = str_id;
+
+	if (txtp)
+		*txtp = txt;
+
+	return txt->obj.id;
+}
+
+int scene_txt_set_font(struct scene *scn, uint id, const char *font_name,
+		       uint font_size)
+{
+	struct scene_obj_txt *txt;
+
+	txt = scene_obj_find(scn, id, SCENEOBJT_TEXT);
+	if (!txt)
+		return log_msg_ret("find", -ENOENT);
+	txt->font_name = font_name;
+	txt->font_size = font_size;
+
+	return 0;
+}
+
+int scene_obj_set_pos(struct scene *scn, uint id, int x, int y)
+{
+	struct scene_obj *obj;
+
+	obj = scene_obj_find(scn, id, SCENEOBJT_NONE);
+	if (!obj)
+		return log_msg_ret("find", -ENOENT);
+	obj->x = x;
+	obj->y = y;
+	if (obj->type == SCENEOBJT_MENU)
+		scene_menu_arrange(scn, (struct scene_obj_menu *)obj);
+
+	return 0;
+}
+
+int scene_obj_set_hide(struct scene *scn, uint id, bool hide)
+{
+	struct scene_obj *obj;
+
+	obj = scene_obj_find(scn, id, SCENEOBJT_NONE);
+	if (!obj)
+		return log_msg_ret("find", -ENOENT);
+	obj->hide = hide;
+
+	return 0;
+}
+
+int scene_obj_get_hw(struct scene *scn, uint id, int *widthp)
+{
+	struct scene_obj *obj;
+
+	obj = scene_obj_find(scn, id, SCENEOBJT_NONE);
+	if (!obj)
+		return log_msg_ret("find", -ENOENT);
+
+	switch (obj->type) {
+	case SCENEOBJT_NONE:
+	case SCENEOBJT_MENU:
+		break;
+	case SCENEOBJT_IMAGE: {
+		struct scene_obj_img *img = (struct scene_obj_img *)obj;
+		ulong width, height;
+		uint bpix;
+
+		video_bmp_get_info(img->data, &width, &height, &bpix);
+		if (widthp)
+			*widthp = width;
+		return height;
+	}
+	case SCENEOBJT_TEXT: {
+		struct scene_obj_txt *txt = (struct scene_obj_txt *)obj;
+		struct expo *exp = scn->expo;
+
+		if (widthp)
+			*widthp = 16; /* fake value for now */
+		if (txt->font_size)
+			return txt->font_size;
+		if (exp->display)
+			return video_default_font_height(exp->display);
+
+		/* use a sensible default */
+		return 16;
+	}
+	}
+
+	return 0;
+}
+
+/**
+ * scene_obj_render() - Render an object
+ *
+ */
+static int scene_obj_render(struct scene_obj *obj, bool text_mode)
+{
+	struct scene *scn = obj->scene;
+	struct expo *exp = scn->expo;
+	struct udevice *cons, *dev = exp->display;
+	int x, y, ret;
+
+	cons = NULL;
+	if (!text_mode) {
+		ret = device_find_first_child_by_uclass(dev,
+							UCLASS_VIDEO_CONSOLE,
+							&cons);
+	}
+
+	x = obj->x;
+	y = obj->y;
+
+	switch (obj->type) {
+	case SCENEOBJT_NONE:
+		break;
+	case SCENEOBJT_IMAGE: {
+		struct scene_obj_img *img = (struct scene_obj_img *)obj;
+
+		if (!cons)
+			return -ENOTSUPP;
+		ret = video_bmp_display(dev, map_to_sysmem(img->data), x, y,
+					true);
+		if (ret < 0)
+			return log_msg_ret("img", ret);
+		break;
+	}
+	case SCENEOBJT_TEXT: {
+		struct scene_obj_txt *txt = (struct scene_obj_txt *)obj;
+		const char *str;
+
+		if (!cons)
+			return -ENOTSUPP;
+
+		if (txt->font_name || txt->font_size) {
+			ret = vidconsole_select_font(cons,
+						     txt->font_name,
+						     txt->font_size);
+		} else {
+			ret = vidconsole_select_font(cons, NULL, 0);
+		}
+		if (ret && ret != -ENOSYS)
+			return log_msg_ret("font", ret);
+		vidconsole_set_cursor_pos(cons, x, y);
+		str = expo_get_str(exp, txt->str_id);
+		if (str)
+			vidconsole_put_string(cons, str);
+		break;
+	}
+	case SCENEOBJT_MENU: {
+		struct scene_obj_menu *menu = (struct scene_obj_menu *)obj;
+		/*
+		 * With a vidconsole, the text and item pointer are rendered as
+		 * normal objects so we don't need to do anything here. The menu
+		 * simply controls where they are positioned.
+		 */
+		if (cons)
+			return -ENOTSUPP;
+
+		ret = scene_menu_display(menu);
+		if (ret < 0)
+			return log_msg_ret("img", ret);
+
+		break;
+	}
+	}
+
+	return 0;
+}
+
+int scene_arrange(struct scene *scn)
+{
+	struct scene_obj *obj;
+	int ret;
+
+	list_for_each_entry(obj, &scn->obj_head, sibling) {
+		if (obj->type == SCENEOBJT_MENU) {
+			struct scene_obj_menu *menu;
+
+			menu = (struct scene_obj_menu *)obj,
+			ret = scene_menu_arrange(scn, menu);
+			if (ret)
+				return log_msg_ret("arr", ret);
+		}
+	}
+
+	return 0;
+}
+
+int scene_render(struct scene *scn)
+{
+	struct expo *exp = scn->expo;
+	struct scene_obj *obj;
+	int ret;
+
+	list_for_each_entry(obj, &scn->obj_head, sibling) {
+		if (!obj->hide) {
+			ret = scene_obj_render(obj, exp->text_mode);
+			if (ret && ret != -ENOTSUPP)
+				return log_msg_ret("ren", ret);
+		}
+	}
+
+	return 0;
+}
+
+int scene_send_key(struct scene *scn, int key, struct expo_action *event)
+{
+	struct scene_obj *obj;
+	int ret;
+
+	list_for_each_entry(obj, &scn->obj_head, sibling) {
+		if (obj->type == SCENEOBJT_MENU) {
+			struct scene_obj_menu *menu;
+
+			menu = (struct scene_obj_menu *)obj,
+			ret = scene_menu_send_key(scn, menu, key, event);
+			if (ret)
+				return log_msg_ret("key", ret);
+
+			/* only allow one menu */
+			ret = scene_menu_arrange(scn, menu);
+			if (ret)
+				return log_msg_ret("arr", ret);
+			break;
+		}
+	}
+
+	return 0;
+}
boot/scene_internal.h new file +123 -0

123 lines not on this page · raw message

Signature · 1 line
2.38.1.431.g37b22c650d-goog
#20 lore raw

PATCH v2 20/25 expo: Add support for scene menus

In reply to Simon Glass

A menu is a key part of the expo design. It consists of a number of items which the user can select from.

Add the initial implementation of this.

---

Changes in v2:
- Drop the _add suffix on expo creation function
- Put strings in a separate structure referenced by ID

 boot/Makefile     |   2 +
 boot/scene_menu.c | 390 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 392 insertions(+)
 create mode 100644 boot/scene_menu.c
boot/Makefile +2 -0
index f0c31549213..0b30fcd64a9 100644
@@ -47,6 +47,8 @@ ifdef CONFIG_SPL_BUILD
 obj-$(CONFIG_SPL_LOAD_FIT) += common_fit.o
 endif
 
+obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE) += expo.o scene.o scene_menu.o
+
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE) += vbe.o vbe_request.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE) += vbe_simple.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_SIMPLE_FW) += vbe_simple_fw.o
boot/scene_menu.c new file +390 -0

390 lines not on this page · raw message

Signature · 1 line
2.38.1.431.g37b22c650d-goog
#21 lore raw

PATCH v2 21/25 expo: Add basic tests

In reply to Simon Glass

Add some tests for the expo, including setting up and rendering an expo.

---

Changes in v2:
- Drop the _add suffix on expo creation function
- Put strings in a separate structure referenced by ID

 test/boot/Makefile |   2 +
 test/boot/expo.c   | 539 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 541 insertions(+)
 create mode 100644 test/boot/expo.c
test/boot/Makefile +2 -0
index d724629d3b0..22ed61c8fa0 100644
@@ -5,6 +5,8 @@
 obj-$(CONFIG_BOOTSTD) += bootdev.o bootstd_common.o bootflow.o bootmeth.o
 obj-$(CONFIG_FIT) += image.o
 
+obj-$(CONFIG_EXPO) += expo.o
+
 ifdef CONFIG_OF_LIVE
 obj-$(CONFIG_BOOTMETH_VBE_SIMPLE) += vbe_simple.o
 endif
test/boot/expo.c new file +539 -0

539 lines not on this page · raw message

Signature · 1 line
2.38.1.431.g37b22c650d-goog
#22 lore raw

PATCH v2 22/25 bootstd: Support creating a boot menu

In reply to Simon Glass

Create an expo to handle the boot menu. For now this is quite simple, with just a header, some menu items and a pointer to show the current one.

---

Changes in v2:
- Rebase to master

 boot/Makefile            |   1 +
 boot/bootflow_internal.h |  47 ++++++++
 boot/bootflow_menu.c     | 241 +++++++++++++++++++++++++++++++++++++++
 cmd/bootflow.c           |  37 +++++-
 include/bootflow.h       |  23 ++++
 5 files changed, 347 insertions(+), 2 deletions(-)
 create mode 100644 boot/bootflow_internal.h
 create mode 100644 boot/bootflow_menu.c
boot/Makefile +1 -0
index 0b30fcd64a9..f990e66f522 100644
@@ -30,6 +30,7 @@ obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_SANDBOX) += bootmeth_sandbox.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_SCRIPT) += bootmeth_script.o
 ifdef CONFIG_$(SPL_TPL_)BOOTSTD_FULL
 obj-$(CONFIG_$(SPL_TPL_)CMD_BOOTEFI_BOOTMGR) += bootmeth_efi_mgr.o
+obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootflow_menu.o
 endif
 
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
boot/bootflow_internal.h new file +47 -0

47 lines not on this page · raw message

boot/bootflow_menu.c new file +241 -0

241 lines not on this page · raw message

cmd/bootflow.c +35 -2
index 495ef85f25b..2b6ed26fdcb 100644
@@ -389,6 +389,37 @@ static int do_bootflow_boot(struct cmd_tbl *cmdtp, int flag, int argc,
 
 	return 0;
 }
+
+static int do_bootflow_menu(struct cmd_tbl *cmdtp, int flag, int argc,
+			    char *const argv[])
+{
+	struct bootstd_priv *std;
+	struct bootflow *bflow;
+	bool text_mode = false;
+	int ret;
+
+	if (argc > 1 && *argv[1] == '-')
+		text_mode = strchr(argv[1], 't');
+
+	ret = bootstd_get_priv(&std);
+	if (ret)
+		return CMD_RET_FAILURE;
+
+	ret = bootflow_menu_run(std, text_mode, &bflow);
+	if (ret) {
+		if (ret == -EAGAIN)
+			printf("Nothing chosen\n");
+		else
+			printf("Menu failed (err=%d)\n", ret);
+
+		return CMD_RET_FAILURE;
+	}
+
+	printf("Selected: %s\n", bflow->os_name ? bflow->os_name : bflow->name);
+	std->cur_bootflow = bflow;
+
+	return 0;
+}
 #endif /* CONFIG_CMD_BOOTFLOW_FULL */
 
 #ifdef CONFIG_SYS_LONGHELP
@@ -398,7 +429,8 @@ static char bootflow_help_text[] =
 	"bootflow list [-e]             - list scanned bootflows (-e errors)\n"
 	"bootflow select [<num>|<name>] - select a bootflow\n"
 	"bootflow info [-d]             - show info on current bootflow (-d dump bootflow)\n"
-	"bootflow boot                  - boot current bootflow (or first available if none selected)";
+	"bootflow boot                  - boot current bootflow (or first available if none selected)\n"
+	"bootflow menu [-t]             - show a menu of available bootflows";
 #else
 	"scan - boot first available bootflow\n";
 #endif
@@ -410,6 +442,7 @@ U_BOOT_CMD_WITH_SUBCMDS(bootflow, "Boot flows", bootflow_help_text,
 	U_BOOT_SUBCMD_MKENT(list, 2, 1, do_bootflow_list),
 	U_BOOT_SUBCMD_MKENT(select, 2, 1, do_bootflow_select),
 	U_BOOT_SUBCMD_MKENT(info, 2, 1, do_bootflow_info),
-	U_BOOT_SUBCMD_MKENT(boot, 1, 1, do_bootflow_boot)
+	U_BOOT_SUBCMD_MKENT(boot, 1, 1, do_bootflow_boot),
+	U_BOOT_SUBCMD_MKENT(menu, 2, 1, do_bootflow_menu),
 #endif
 );
include/bootflow.h +23 -0
index 8a07ab30191..e7a09568f1b 100644
@@ -9,6 +9,9 @@
 
 #include <linux/list.h>
 
+struct bootstd_priv;
+struct expo;
+
 /**
  * enum bootflow_state_t - states that a particular bootflow can be in
  *
@@ -336,4 +339,24 @@ int bootflow_iter_uses_network(const struct bootflow_iter *iter);
  */
 int bootflow_iter_uses_system(const struct bootflow_iter *iter);
 
+/**
+ * bootflow_menu_new() - Create a new bootflow menu
+ *
+ * @expp: Returns the expo created
+ * Returns 0 on success, -ve on error
+ */
+int bootflow_menu_new(struct expo **expp);
+
+/**
+ * bootflow_menu_run() - Create and run a menu of available bootflows
+ *
+ * @std: Bootstd information
+ * @text_mode: Uses a text-based menu suitable for a serial port
+ * @bflowp: Returns chosen bootflow (set to NULL if nothing is chosen)
+ * @return 0 if an option was chosen, -EAGAIN if nothing was chosen, -ve on
+ * error
+ */
+int bootflow_menu_run(struct bootstd_priv *std, bool text_mode,
+		      struct bootflow **bflowp);
+
 #endif
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#23 lore raw

PATCH v2 23/25 bootstd: Add a test for the bootstd menu

In reply to Simon Glass

Add a test which checks that two operating systems can be displayed in a menu, allowing one to be selected.

Enable a few things on snow so that the unit tests build.

---

Changes in v2:
- Fix 'touse' typo
- Fix pylint warning in mkdir_cond()

 arch/sandbox/dts/test.dts            |  11 ++
 configs/snow_defconfig               |   4 +
 test/boot/bootflow.c                 |  51 +++++++
 test/py/tests/bootstd/armbian.bmp.xz | Bin 0 -> 1384 bytes
 test/py/tests/bootstd/mmc4.img.xz    | Bin 0 -> 7072 bytes
 test/py/tests/test_ut.py             | 218 ++++++++++++++++++++++++---
 6 files changed, 265 insertions(+), 19 deletions(-)
 create mode 100644 test/py/tests/bootstd/armbian.bmp.xz
 create mode 100644 test/py/tests/bootstd/mmc4.img.xz
arch/sandbox/dts/test.dts +11 -0
index dffe10adbf4..2e580f980fc 100644
@@ -94,6 +94,10 @@
 			compatible = "u-boot,distro-efi";
 		};
 
+		theme {
+			font-size = <30>;
+		};
+
 		/*
 		 * This is used for the VBE OS-request tests. A FAT filesystem
 		 * created in a partition with the VBE information appearing
@@ -1013,6 +1017,13 @@
 		non-removable;
 	};
 
+	/* This is used for bootstd bootmenu tests */
+	mmc4 {
+		status = "disabled";
+		compatible = "sandbox,mmc";
+		filename = "mmc4.img";
+	};
+
 	pch {
 		compatible = "sandbox,pch";
 	};
configs/snow_defconfig +4 -0
index 6921c5667da..faa3a944c02 100644
@@ -28,7 +28,11 @@ CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
 CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x2050000
 CONFIG_FIT=y
 CONFIG_FIT_BEST_MATCH=y
+CONFIG_BOOTSTD_FULL=y
 CONFIG_SILENT_CONSOLE=y
+CONFIG_BLOBLIST=y
+# CONFIG_SPL_BLOBLIST is not set
+CONFIG_BLOBLIST_ADDR=0x43d00000
 # CONFIG_SPL_FRAMEWORK is not set
 CONFIG_SPL_FOOTPRINT_LIMIT=y
 CONFIG_SPL_MAX_FOOTPRINT=0x3800
test/boot/bootflow.c +51 -0

69 lines not on this page · raw message

test/py/tests/bootstd/armbian.bmp.xz new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..ad137ea6e6df5c51d0a98a4be190c4cb4c48fc76
GIT binary patch
test/py/tests/bootstd/mmc4.img.xz new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..f4db011969fa8bea352ee2b8318dfdd72ccf72d8
GIT binary patch
test/py/tests/test_ut.py +199 -19

257 lines not on this page · raw message

Signature · 1 line
2.38.1.431.g37b22c650d-goog
#24 lore raw

PATCH v2 24/25 bootstd: Support setting a theme for the menu

In reply to Simon Glass

Allow a theme to be set. For now this is very simple, just a default font size to use for all elements.

---

(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(-)
boot/bootflow_menu.c +43 -0
index 1105783afeb..7f06dac0af7 100644
@@ -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)
boot/bootstd-uclass.c +2 -0
index 565c22a36e7..7887acdc11b 100644
@@ -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;
include/bootflow.h +10 -0
index e7a09568f1b..c201246c6de 100644
@@ -7,6 +7,7 @@
 #ifndef __bootflow_h
 #define __bootflow_h
 
+#include <dm/ofnode_decl.h>
 #include <linux/list.h>
 
 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
  *
include/bootstd.h +4 -0
index 01be249d16e..4fa0d531001 100644
@@ -9,6 +9,8 @@
 #ifndef __bootstd_h
 #define __bootstd_h
 
+#include <dm/ofnode_decl.h>
+
 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;
 };
 
 /**
test/boot/bootflow.c +80 -3

115 lines not on this page · raw message

Signature · 1 line
2.38.1.431.g37b22c650d-goog
#25 lore raw

PATCH v2 25/25 expo: Add documentation

In reply to Simon Glass

Add some documentation for the expo feature.

---

Changes in v2:
- Update for new API

 doc/develop/expo.rst  | 188 ++++++++++++++++++++++++++++++++++++++++++
 doc/develop/index.rst |   1 +
 2 files changed, 189 insertions(+)
 create mode 100644 doc/develop/expo.rst
doc/develop/expo.rst new file +188 -0
new file mode 100644
index 00000000000..32dd7f09030
@@ -0,0 +1,188 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Expo menu
+=========
+
+U-Boot provides a menu implementation for use with selecting bootflows and
+changing U-Boot settings. This is in early stages of development.
+
+Motivation
+----------
+
+U-Boot already has a text-based menu system accessed via the
+:doc:`../usage/cmd/bootmenu`. This works using environment variables, or via
+some EFI-specific hacks.
+
+The command makes use of a lower-level `menu` implementation, which is quite
+flexible and can be used to make menu hierarchies.
+
+However this system is not flexible enough for use with standard boot. It does
+not support a graphical user interface and cannot currently support anything
+more than a very simple list of items. While it does support multiple menus in
+hierarchies, these are implemented by the caller. See for example `eficonfig.c`.
+
+Another challenge with the current menu implementation is that it controls
+the event loop, such that bootmenu_loop() does not return until a key is
+pressed. This makes it difficult to implement dynamic displays or to do other
+things while the menu is running, such as searching for more bootflows.
+
+For these reasons an attempt has been made to develop a more flexible system
+which can handle menus as well as other elements. This is called 'expo', short
+for exposition, in an attempt to avoid common words like display, screen, menu
+and the like. The primary goal is to support Verified Boot for Embedded (VBE),
+although it is available to any boot method, using the 'bootflow menu' command.
+
+Efforts have been made to use common code with the existing menu, including
+key processing in particular.
+
+Previous work looked at integrating Nuklear into U-Boot. This works fine and
+could provide a way to provide a more flexible UI, perhaps with expo dealing
+with the interface to Nuklear. But this is quite a big step and it may be years
+before this becomes desirable, if at all. For now, U-Boot only needs a fairly
+simple set of menus and options, so rendering them directly is fairly
+straightforward.
+
+Concepts
+--------
+
+The creator of the expo is here called a `controller` and it controls most
+aspects of the expo. This is the code that you must write to use expo.
+
+An `expo` is a set of scenes which can be presented to the user one at a time,
+to show information and obtain input from the user.
+
+A `scene` is a collection of objects which are displayed together on the screen.
+Only one scene is visible at a time and scenes do not share objects.
+
+A `scene object` is something that appears in the scene, such as some text, an
+image or a menu. Objects can be positioned and hidden.
+
+A `menu object` contains a title, a set of `menu items` and a pointer to the
+current item. Menu items consist of a keypress (indicating what to press to
+select the item), label and description. All three are shown in a single line
+within the menu. Items can also have a preview image, which is shown when the
+item is highlighted.
+
+All components have a name. This is purely for debugging, so it is easy to see
+what object is referred to. Of course the ID numbers can help as well, but they
+are less easy to distinguish.
+
+While the expo implementation provides support for handling keypresses and
+rendering on the display or serial port, it does not actually deal with reading
+input from the user, nor what should be done when a particular menu item is
+selected. This is deliberate since having the event loop outside the expo is
+more flexible, particularly in a single-threaded environment like U-Boot.
+
+Everything within an expo has a unique ID number. This is done so that it is
+easy to refer to things after the expo has been created. The expectation is that
+the controller declares an enum containing all of the elements in the expo,
+passing the ID of each object as it is created. When a menu item is selected,
+its ID is returned. When a object's font or position needs to change, the ID is
+passed to expo functions to indicate which object it is. It is possible for expo
+to auto-allocate IDs, but this is not recommended. The use of IDs is a
+convenience, removing the need for the controller to store pointers to objects,
+or even the IDs of objects. Programmatic creation of many items in a loop can be
+handled by allocating space in the enum for a maximum number of items, then
+adding the loop count to the enum values to obtain unique IDs.
+
+All text strings are stored in a structure attached to the expo, referenced by
+a text ID. This makes it easier at some point to implement multiple languages or
+to support Unicode strings.
+
+Menu objects do not have their own text and image objects. Instead they simply
+refer to objects which have been created. So a menu item is just a collection
+of IDs of text and image objects. When adding a menu item you must create these
+objects first, then create the menu item, passing in the relevant IDs.
+
+Creating an expo
+----------------
+
+To create an expo, use `expo_new()` followed by `scene_new()` to create a scene.
+Then add objects to the scene, using functions like `scene_txt_str()` and
+`scene_menu()`. For every menu item, add text and image objects, then create
+the menu item with `scene_menuitem()`, referring to those objects.
+
+Layout
+------
+
+Individual objects can be positioned using `scene_obj_set_pos()`. Menu items
+cannot be positioned manually: this is done by `scene_arrange()` which is called
+automatically when something changes. The menu itself determines the position of
+its items.
+
+Rendering
+---------
+
+Rendering is performed by calling `expo_render()`. This uses either the
+vidconsole, if present, or the serial console in `text mode`. Expo handles
+presentation automatically in either case, without any change in how the expo is
+created.
+
+For the vidconsole, Truetype fonts can be used if enabled, to enhance the
+quality of the display. For text mode, each menu item is shown in a single line,
+allowing easy selection using arrow keys.
+
+Input
+-----
+
+The controller is responsible for collecting keyboard input. A good way to do
+this is to use `cli_ch_process()`, since it handles conversion of escape
+sequences into keys. However, expo has some special menu-key codes for
+navigating the interface. These are defined in `enum bootmenu_key` and include
+`BKEY_UP` for moving up and `BKEY_SELECT` for selecting an item. You can use
+`bootmenu_conv_key()` to convert an ASCII key into one of these.
+
+Once a keypress is decoded, call `expo_send_key()` to send it to the expo. This
+may cause an update to the expo state and may produce an action.
+
+Actions
+-------
+
+Call `expo_action_get()` in the event loop to check for any actions that the
+expo wants to report. These can include selecting a particular menu item, or
+quitting the menu. Processing of these is the responsibility of your controller.
+
+Event loop
+----------
+
+Expo is intended to be used in an event loop. For an example loop, see
+`bootflow_menu_run()`. It is possible to perform other work in your event loop,
+such as scanning devices for more bootflows.
+
+Themes
+------
+
+Expo does not itself support themes. The bootflow_menu implement supposed a
+basic theme, applying font sizes to the various text objects in the expo.
+
+API documentation
+-----------------
+
+.. kernel-doc:: include/expo.h
+
+Future ideas
+------------
+
+Some ideas for future work:
+
+- Default menu item and a timeout
+- Higher-level / automatic / more flexible layout of objects
+- Image formats other than BMP
+- Use of ANSI sequences to control a serial terminal
+- Colour selection
+- Better support for handling lots of settings, e.g. with multiple menus and
+  radio/option widgets
+- Mouse support
+- Integrate Nuklear, NxWidgets or some other library for a richer UI
+- Optimise rendering by only updating the display with changes since last render
+- Use expo to replace the existing menu implementation
+- Add a Kconfig option to drop the names to save code / data space
+- Add a Kconfig option to disable vidconsole support to save code / data space
+- Support both graphical and text menus at the same time on different devices
+- Implement proper measurement of object bounding boxes, to permit more exact
+  layout. This would tidy up the layout when Truetype is not used
+- Support unicode
+- Support curses for proper serial-terminal menus
+
+.. Simon Glass <[email protected]>
+.. 7-Oct-22
doc/develop/index.rst +1 -0
index 5934d9ffb11..629891b4d3b 100644
@@ -33,6 +33,7 @@ Implementation
    distro
    driver-model/index
    environment
+   expo
    event
    global_data
    logging
Signature · 1 line
2.38.1.431.g37b22c650d-goog
#26 lore raw
In reply to Simon Glass
Quoted 6 lines · Simon Glass

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.

Quoted 8 lines

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.

Please, add the link to your design document

https://docs.google.com/document/d/1VQeApnLlH6xKm_OI36AhWkJLUEd9OXEvIJXB8aM2de8/edit?resourcekey=0-DwgHpR2S8vJEJzvvwPb-AQ#heading=h.17wg41voij6q
is broken.

in future version of this series.

The series leaves us with duplicate code in

bootmenu_choice_entry() and eficonfig_choice_entry() as well as bootmenu_loop() and bootmenu_autoboot_loop().

The bootmenu command relies heavily on ANSI sequences but VIDEO_ANSI is disabled by default for CONFIG_EFI_LOADER=n which means that the bootmenu command will not work anymore.

Quoted 2 lines

All of this is implementing using a new 'expo' construct, a collection of

Expo is not an English word. Expo is typically used as name of trade fairs. Transaction probably is the right word to use here.

Files expo.c and scene.c are in boot/ which does not match a generic GUI feature. They should be placed in lib/.

Best regards

Heinrich

Quoted 122 lines

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.

Changes in v2:
- Drop the _add suffix on expo creation function
- Fix 'touse' typo
- Fix pylint warning in mkdir_cond()
- Put strings in a separate structure referenced by ID
- Rebase to master
- Rename vidconsole_get_font() to vidconsole_get_font_size()
- Update for new API

Simon Glass (25):
sandbox: Enable mmc command and legacy images
cli: Move readline character-processing to a state machine
bootmenu: Add a few comments
menu: Rename KEY_... to BKEY_...
menu: Update bootmenu_autoboot_loop() to return the code
menu: Update bootmenu_loop() to return the code
menu: Use a switch statement
menu: Make use of CLI character processing
image: Add a function to find a script in an image
image: Move common image code to image_board and command
video: Enable VIDEO_ANSI by default only with EFI
video: truetype: Rename the metrics function
video: Fix unchnaged typo
video: Add font functions to the vidconsole API
bootstd: Read the Operating System name for distro/scripts
bootstd: Allow reading a logo for the OS
menu: Factor out menu-keypress decoding
expo: Add basic implementation
expo: Add support for scenes
expo: Add support for scene menus
expo: Add basic tests
bootstd: Support creating a boot menu
bootstd: Add a test for the bootstd menu
bootstd: Support setting a theme for the menu
expo: Add documentation

  .../cmd_stm32prog/cmd_stm32prog.c             |   2 +-
  arch/sandbox/dts/test.dts                     |  11 +
  boot/Kconfig                                  |  12 +
  boot/Makefile                                 |   3 +
  boot/bootflow.c                               |   1 +
  boot/bootflow_internal.h                      |  47 ++
  boot/bootflow_menu.c                          | 284 +++++++++
  boot/bootmeth-uclass.c                        |  69 ++-
  boot/bootmeth_distro.c                        |  36 ++
  boot/bootmeth_script.c                        |  40 +-
  boot/bootstd-uclass.c                         |   2 +
  boot/expo.c                                   | 170 ++++++
  boot/image-board.c                            | 133 +++++
  boot/scene.c                                  | 414 ++++++++++++++
  boot/scene_internal.h                         | 123 ++++
  boot/scene_menu.c                             | 390 +++++++++++++
  cmd/bootflow.c                                |  44 +-
  cmd/bootmenu.c                                |  19 +-
  cmd/eficonfig.c                               |  38 +-
  cmd/font.c                                    |  11 +-
  cmd/source.c                                  | 140 +----
  common/Makefile                               |   6 +-
  common/cli_getch.c                            | 208 +++++++
  common/cli_readline.c                         | 150 +----
  common/command.c                              |  19 +
  common/menu.c                                 | 157 +++--
  configs/sandbox_defconfig                     |   2 +
  configs/sandbox_flattree_defconfig            |   2 +
  configs/snow_defconfig                        |   4 +
  configs/tools-only_defconfig                  |   2 +
  doc/develop/expo.rst                          | 188 ++++++
  doc/develop/index.rst                         |   1 +
  drivers/usb/gadget/f_sdp.c                    |   2 +-
  drivers/video/Kconfig                         |   7 +-
  drivers/video/console_truetype.c              |  37 +-
  drivers/video/vidconsole-uclass.c             |  33 ++
  include/bootflow.h                            |  40 ++
  include/bootmeth.h                            |  16 +
  include/bootstd.h                             |   4 +
  include/cli.h                                 |  74 +++
  include/command.h                             |  12 +
  include/expo.h                                | 521 +++++++++++++++++
  include/image.h                               |  17 +-
  include/menu.h                                |  77 ++-
  include/video.h                               |   2 +-
  include/video_console.h                       |  75 ++-
  test/boot/Makefile                            |   2 +
  test/boot/bootflow.c                          | 130 +++++
  test/boot/expo.c                              | 539 ++++++++++++++++++
  test/cmd/font.c                               |   6 +-
  test/py/tests/bootstd/armbian.bmp.xz          | Bin 0 -> 1384 bytes
  test/py/tests/bootstd/mmc4.img.xz             | Bin 0 -> 7072 bytes
  test/py/tests/test_android/test_avb.py        |   2 +
  test/py/tests/test_ut.py                      | 218 ++++++-
  54 files changed, 4075 insertions(+), 467 deletions(-)

create mode 100644 boot/bootflow_internal.h create mode 100644 boot/bootflow_menu.c
create mode 100644 boot/expo.c
create mode 100644 boot/scene.c
create mode 100644 boot/scene_internal.h create mode 100644 boot/scene_menu.c
create mode 100644 common/cli_getch.c
create mode 100644 doc/develop/expo.rst
create mode 100644 include/expo.h
create mode 100644 test/boot/expo.c
create mode 100644 test/py/tests/bootstd/armbian.bmp.xz create mode 100644 test/py/tests/bootstd/mmc4.img.xz

#27 lore raw

Hi Heinrich,

Quoted 14 lines · Heinrich Schuchardt
Quoted 12 lines · Simon Glass

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.

Quoted 7 lines
Quoted 2 lines

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.

Please, add the link to your design document

https://docs.google.com/document/d/1VQeApnLlH6xKm_OI36AhWkJLUEd9OXEvIJXB8aM2de8/edit?resourcekey=0-DwgHpR2S8vJEJzvvwPb-AQ#heading=h.17wg41voij6q
is broken.

What happens when you click that? It works for me.

Quoted 7 lines

in future version of this series.

The series leaves us with duplicate code in

bootmenu_choice_entry() and eficonfig_choice_entry() as well as bootmenu_loop() and bootmenu_autoboot_loop().

Yes OK, but that is the case today and my series actually removes some duplicated code, so perhaps that could be cleaned up later?

Quoted 4 lines

The bootmenu command relies heavily on ANSI sequences but VIDEO_ANSI is disabled by default for CONFIG_EFI_LOADER=n which means that the bootmenu command will not work anymore.

Does it not work, or does it just work but in a serial fashion? I don't see ANSI codes as being necessary to show a menu.

Quoted 6 lines
Quoted 3 lines

All of this is implementing using a new 'expo' construct, a collection of

Expo is not an English word. Expo is typically used as name of trade fairs. Transaction probably is the right word to use here.

That is debatable I think. Transaction is quite generic and appears in U-Boot >400 times. I think it will just be confusing, like the word 'metadata' used in the FWU stuff.

Expo is short for exposition. My use of it is somewhat archaic perhaps, but even for the meaning you mention, a public exposition is not a bad description of what is provided here.

I am not 100% convinced about 'expo' either. Do you have any other ideas?

Quoted 3 lines

Files expo.c and scene.c are in boot/ which does not match a generic GUI feature. They should be placed in lib/.

Yes I was wondering about that, but thought that boot/ made at least some sense since the menu will only ever be used for booting...?

I can move it, but I am a little nervous about that, since lib/ normally has utility libraries. Perhaps lib/expo would be better?

Regards,
Simon

Quoted 128 lines

Best regards

Heinrich

Quoted 122 lines

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.

Changes in v2:
- Drop the _add suffix on expo creation function
- Fix 'touse' typo
- Fix pylint warning in mkdir_cond()
- Put strings in a separate structure referenced by ID
- Rebase to master
- Rename vidconsole_get_font() to vidconsole_get_font_size()
- Update for new API

Simon Glass (25):
sandbox: Enable mmc command and legacy images
cli: Move readline character-processing to a state machine
bootmenu: Add a few comments
menu: Rename KEY_... to BKEY_...
menu: Update bootmenu_autoboot_loop() to return the code
menu: Update bootmenu_loop() to return the code
menu: Use a switch statement
menu: Make use of CLI character processing
image: Add a function to find a script in an image
image: Move common image code to image_board and command
video: Enable VIDEO_ANSI by default only with EFI
video: truetype: Rename the metrics function
video: Fix unchnaged typo
video: Add font functions to the vidconsole API
bootstd: Read the Operating System name for distro/scripts
bootstd: Allow reading a logo for the OS
menu: Factor out menu-keypress decoding
expo: Add basic implementation
expo: Add support for scenes
expo: Add support for scene menus
expo: Add basic tests
bootstd: Support creating a boot menu
bootstd: Add a test for the bootstd menu
bootstd: Support setting a theme for the menu
expo: Add documentation

  .../cmd_stm32prog/cmd_stm32prog.c             |   2 +-
  arch/sandbox/dts/test.dts                     |  11 +
  boot/Kconfig                                  |  12 +
  boot/Makefile                                 |   3 +
  boot/bootflow.c                               |   1 +
  boot/bootflow_internal.h                      |  47 ++
  boot/bootflow_menu.c                          | 284 +++++++++
  boot/bootmeth-uclass.c                        |  69 ++-
  boot/bootmeth_distro.c                        |  36 ++
  boot/bootmeth_script.c                        |  40 +-
  boot/bootstd-uclass.c                         |   2 +
  boot/expo.c                                   | 170 ++++++
  boot/image-board.c                            | 133 +++++
  boot/scene.c                                  | 414 ++++++++++++++
  boot/scene_internal.h                         | 123 ++++
  boot/scene_menu.c                             | 390 +++++++++++++
  cmd/bootflow.c                                |  44 +-
  cmd/bootmenu.c                                |  19 +-
  cmd/eficonfig.c                               |  38 +-
  cmd/font.c                                    |  11 +-
  cmd/source.c                                  | 140 +----
  common/Makefile                               |   6 +-
  common/cli_getch.c                            | 208 +++++++
  common/cli_readline.c                         | 150 +----
  common/command.c                              |  19 +
  common/menu.c                                 | 157 +++--
  configs/sandbox_defconfig                     |   2 +
  configs/sandbox_flattree_defconfig            |   2 +
  configs/snow_defconfig                        |   4 +
  configs/tools-only_defconfig                  |   2 +
  doc/develop/expo.rst                          | 188 ++++++
  doc/develop/index.rst                         |   1 +
  drivers/usb/gadget/f_sdp.c                    |   2 +-
  drivers/video/Kconfig                         |   7 +-
  drivers/video/console_truetype.c              |  37 +-
  drivers/video/vidconsole-uclass.c             |  33 ++
  include/bootflow.h                            |  40 ++
  include/bootmeth.h                            |  16 +
  include/bootstd.h                             |   4 +
  include/cli.h                                 |  74 +++
  include/command.h                             |  12 +
  include/expo.h                                | 521 +++++++++++++++++
  include/image.h                               |  17 +-
  include/menu.h                                |  77 ++-
  include/video.h                               |   2 +-
  include/video_console.h                       |  75 ++-
  test/boot/Makefile                            |   2 +
  test/boot/bootflow.c                          | 130 +++++
  test/boot/expo.c                              | 539 ++++++++++++++++++
  test/cmd/font.c                               |   6 +-
  test/py/tests/bootstd/armbian.bmp.xz          | Bin 0 -> 1384 bytes
  test/py/tests/bootstd/mmc4.img.xz             | Bin 0 -> 7072 bytes
  test/py/tests/test_android/test_avb.py        |   2 +
  test/py/tests/test_ut.py                      | 218 ++++++-
  54 files changed, 4075 insertions(+), 467 deletions(-)

create mode 100644 boot/bootflow_internal.h create mode 100644 boot/bootflow_menu.c
create mode 100644 boot/expo.c
create mode 100644 boot/scene.c
create mode 100644 boot/scene_internal.h create mode 100644 boot/scene_menu.c
create mode 100644 common/cli_getch.c
create mode 100644 doc/develop/expo.rst
create mode 100644 include/expo.h
create mode 100644 test/boot/expo.c
create mode 100644 test/py/tests/bootstd/armbian.bmp.xz create mode 100644 test/py/tests/bootstd/mmc4.img.xz

#28 lore raw

Hi Heinrich,

Quoted 65 lines · Simon Glass

Hi Heinrich,

Quoted 14 lines · Heinrich Schuchardt
Quoted 12 lines · Simon Glass

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.

Quoted 7 lines
Quoted 2 lines

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.

Please, add the link to your design document

https://docs.google.com/document/d/1VQeApnLlH6xKm_OI36AhWkJLUEd9OXEvIJXB8aM2de8/edit?resourcekey=0-DwgHpR2S8vJEJzvvwPb-AQ#heading=h.17wg41voij6q
is broken.

What happens when you click that? It works for me.

Quoted 7 lines

in future version of this series.

The series leaves us with duplicate code in

bootmenu_choice_entry() and eficonfig_choice_entry() as well as bootmenu_loop() and bootmenu_autoboot_loop().

Yes OK, but that is the case today and my series actually removes some duplicated code, so perhaps that could be cleaned up later?

Quoted 4 lines

The bootmenu command relies heavily on ANSI sequences but VIDEO_ANSI is disabled by default for CONFIG_EFI_LOADER=n which means that the bootmenu command will not work anymore.

Does it not work, or does it just work but in a serial fashion? I don't see ANSI codes as being necessary to show a menu.

Quoted 6 lines
Quoted 3 lines

All of this is implementing using a new 'expo' construct, a collection of

Expo is not an English word. Expo is typically used as name of trade fairs. Transaction probably is the right word to use here.

That is debatable I think. Transaction is quite generic and appears in U-Boot >400 times. I think it will just be confusing, like the word 'metadata' used in the FWU stuff.

Expo is short for exposition. My use of it is somewhat archaic perhaps, but even for the meaning you mention, a public exposition is not a bad description of what is provided here.

I am not 100% convinced about 'expo' either. Do you have any other ideas?

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

Files expo.c and scene.c are in boot/ which does not match a generic GUI feature. They should be placed in lib/.

Yes I was wondering about that, but thought that boot/ made at least some sense since the menu will only ever be used for booting...?

I can move it, but I am a little nervous about that, since lib/ normally has utility libraries. Perhaps lib/expo would be better?

Just to say that I replied to your comments on the doc also, so let me know what you think.

Regards,
Simon

#29 lore raw

Hi Heinrich (and anyone else),

Quoted 72 lines · Simon Glass

Hi Heinrich,

Quoted 68 lines · Simon Glass

Hi Heinrich,

Quoted 14 lines · Heinrich Schuchardt
Quoted 12 lines · Simon Glass

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.

Quoted 7 lines
Quoted 2 lines

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.

Please, add the link to your design document

https://docs.google.com/document/d/1VQeApnLlH6xKm_OI36AhWkJLUEd9OXEvIJXB8aM2de8/edit?resourcekey=0-DwgHpR2S8vJEJzvvwPb-AQ#heading=h.17wg41voij6q
is broken.

What happens when you click that? It works for me.

Quoted 7 lines

in future version of this series.

The series leaves us with duplicate code in

bootmenu_choice_entry() and eficonfig_choice_entry() as well as bootmenu_loop() and bootmenu_autoboot_loop().

Yes OK, but that is the case today and my series actually removes some duplicated code, so perhaps that could be cleaned up later?

Quoted 4 lines

The bootmenu command relies heavily on ANSI sequences but VIDEO_ANSI is disabled by default for CONFIG_EFI_LOADER=n which means that the bootmenu command will not work anymore.

Does it not work, or does it just work but in a serial fashion? I don't see ANSI codes as being necessary to show a menu.

Quoted 6 lines
Quoted 3 lines

All of this is implementing using a new 'expo' construct, a collection of

Expo is not an English word. Expo is typically used as name of trade fairs. Transaction probably is the right word to use here.

That is debatable I think. Transaction is quite generic and appears in U-Boot >400 times. I think it will just be confusing, like the word 'metadata' used in the FWU stuff.

Expo is short for exposition. My use of it is somewhat archaic perhaps, but even for the meaning you mention, a public exposition is not a bad description of what is provided here.

I am not 100% convinced about 'expo' either. Do you have any other ideas?

Quoted 3 lines

Files expo.c and scene.c are in boot/ which does not match a generic GUI feature. They should be placed in lib/.

Quoted 8 lines
Quoted 5 lines

Yes I was wondering about that, but thought that boot/ made at least some sense since the menu will only ever be used for booting...?

I can move it, but I am a little nervous about that, since lib/ normally has utility libraries. Perhaps lib/expo would be better?

Just to say that I replied to your comments on the doc also, so let me know what you think.

I'd like to get this applied now that -next is opening. Do you have any more comments?

Regards,
Simon

#30 lore raw

Hi Tom,

Quoted 79 lines · Simon Glass

Hi Heinrich (and anyone else),

Quoted 75 lines · Simon Glass

Hi Heinrich,

Quoted 71 lines · Simon Glass

Hi Heinrich,

Quoted 14 lines · Heinrich Schuchardt
Quoted 12 lines · Simon Glass

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.

Quoted 7 lines
Quoted 2 lines

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.

Please, add the link to your design document

https://docs.google.com/document/d/1VQeApnLlH6xKm_OI36AhWkJLUEd9OXEvIJXB8aM2de8/edit?resourcekey=0-DwgHpR2S8vJEJzvvwPb-AQ#heading=h.17wg41voij6q
is broken.

What happens when you click that? It works for me.

Quoted 7 lines

in future version of this series.

The series leaves us with duplicate code in

bootmenu_choice_entry() and eficonfig_choice_entry() as well as bootmenu_loop() and bootmenu_autoboot_loop().

Yes OK, but that is the case today and my series actually removes some duplicated code, so perhaps that could be cleaned up later?

Quoted 4 lines

The bootmenu command relies heavily on ANSI sequences but VIDEO_ANSI is disabled by default for CONFIG_EFI_LOADER=n which means that the bootmenu command will not work anymore.

Does it not work, or does it just work but in a serial fashion? I don't see ANSI codes as being necessary to show a menu.

Quoted 6 lines
Quoted 3 lines

All of this is implementing using a new 'expo' construct, a collection of

Expo is not an English word. Expo is typically used as name of trade fairs. Transaction probably is the right word to use here.

That is debatable I think. Transaction is quite generic and appears in U-Boot >400 times. I think it will just be confusing, like the word 'metadata' used in the FWU stuff.

Expo is short for exposition. My use of it is somewhat archaic perhaps, but even for the meaning you mention, a public exposition is not a bad description of what is provided here.

I am not 100% convinced about 'expo' either. Do you have any other ideas?

Quoted 3 lines

Files expo.c and scene.c are in boot/ which does not match a generic GUI feature. They should be placed in lib/.

Yes I was wondering about that, but thought that boot/ made at least some sense since the menu will only ever be used for booting...?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

I can move it, but I am a little nervous about that, since lib/ normally has utility libraries. Perhaps lib/expo would be better?

Just to say that I replied to your comments on the doc also, so let me know what you think.

I'd like to get this applied now that -next is opening. Do you have any more comments?

What are your thoughts on apply this now, -next?

I am starting to wonder if we should have a VBE tree, as we do for EFI?

Regards,
Simon