diff options
author | Tom Rini <trini@konsulko.com> | 2023-01-17 08:55:40 -0500 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2023-01-17 08:55:40 -0500 |
commit | 5b958dea5c678dbdb2aeb6ac3c0c8cc8dfea065c (patch) | |
tree | 172424111d1a39640cf5245eefd080fae3b5fb27 /include | |
parent | 6d03688e75041a7bae4d33815de28da781c37dd6 (diff) | |
parent | b5c8fea7b830c0304051237ad1501431a958b0e6 (diff) |
Merge branch '2022-01-16-bootstd-updates'
To quote the author:
So far standard boot lacks a boot menu, although it is possible to create
a rudimentary one using the existing 'bootmenu' command.
Even then, this text-based menu offer only basic functionality and does
not take full advantage of the displays which are common on many devices.
This series provides a 'bootflow menu' command which allows the user to
select from the available bootflows. An attempt is made to show the name
of the available operating systems, by reading more information into the
bootflow. A logo can be read also, where supported, so that this can be
presented to the user when an option is highlighted.
Full use is made of TrueType fonts, if enabled. For cases where only a
serial console is available, it falls back to a simple text-based menu.
All of this is implementing using a new 'expo' construct, a collection of
scenes (like menu screens) which can be navigated by the user to view
information and select options. This is fairly general and should be able
to cope with a wider array of use cases, with less hacking of the menu
code, such as is currently needed for CMD_BOOTEFI_BOOTMGR.
Of course it would be possible to enhance the existing menu rather than
creating a new setup. Instead it seems better to make the existing menu
use expo, if code space permits. It avoids the event-loop problem and
should be more extensible, given its loosely coupled components and use of
IDs instead of pointers. Further motivation is provided in the
documentation.
For now the CLI keypress-decoding code is split out to be used by the new
menu. The key codes defined by menu.h are reused also.
This is of course just a starting point. Some ideas for future work are
included in the documentation.
Diffstat (limited to 'include')
-rw-r--r-- | include/bootflow.h | 40 | ||||
-rw-r--r-- | include/bootmeth.h | 16 | ||||
-rw-r--r-- | include/bootstd.h | 4 | ||||
-rw-r--r-- | include/cli.h | 74 | ||||
-rw-r--r-- | include/command.h | 12 | ||||
-rw-r--r-- | include/expo.h | 522 | ||||
-rw-r--r-- | include/image.h | 30 | ||||
-rw-r--r-- | include/menu.h | 77 | ||||
-rw-r--r-- | include/video.h | 2 | ||||
-rw-r--r-- | include/video_console.h | 75 |
10 files changed, 809 insertions, 43 deletions
diff --git a/include/bootflow.h b/include/bootflow.h index 32dbbbbe261..c201246c6de 100644 --- a/include/bootflow.h +++ b/include/bootflow.h @@ -7,8 +7,12 @@ #ifndef __bootflow_h #define __bootflow_h +#include <dm/ofnode_decl.h> #include <linux/list.h> +struct bootstd_priv; +struct expo; + /** * enum bootflow_state_t - states that a particular bootflow can be in * @@ -49,9 +53,13 @@ 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) + * @os_name: Name of the OS / distro being booted, or NULL if not known + * (allocated) */ struct bootflow { struct list_head bm_node; @@ -65,9 +73,12 @@ struct bootflow { enum bootflow_state_t state; char *subdir; char *fname; + void *logo; + uint logo_size; char *buf; int size; int err; + char *os_name; }; /** @@ -329,4 +340,33 @@ 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_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 + * + * @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 diff --git a/include/bootmeth.h b/include/bootmeth.h index 50ded055f3f..669b14ce81e 100644 --- a/include/bootmeth.h +++ b/include/bootmeth.h @@ -266,6 +266,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 * * Reads a named file from the same location as the bootflow file. diff --git a/include/bootstd.h b/include/bootstd.h index 01be249d16e..4fa0d531001 100644 --- a/include/bootstd.h +++ b/include/bootstd.h @@ -9,6 +9,8 @@ #ifndef __bootstd_h #define __bootstd_h +#include <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; }; /** diff --git a/include/cli.h b/include/cli.h index ba5b8ebd36e..c777c90313f 100644 --- a/include/cli.h +++ b/include/cli.h @@ -7,6 +7,23 @@ #ifndef __CLI_H #define __CLI_H +#include <stdbool.h> + +/** + * struct cli_ch_state - state information for reading cmdline characters + * + * @esc_len: Number of escape characters read so far + * @esc_save: Escape characters collected so far + * @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; +}; + /** * Go into the command loop * @@ -154,5 +171,62 @@ void cli_loop(void); void cli_init(void); #define endtick(seconds) (get_ticks() + (uint64_t)(seconds) * get_tbclk()) +#define CTL_CH(c) ((c) - 'a' + 1) + +/** + * cli_ch_init() - Set up the initial state to process input characters + * + * @cch: State to set up + */ +void cli_ch_init(struct cli_ch_state *cch); + +/** + * cli_ch_process() - Process an input character + * + * When @ichar is 0, this function returns any characters from an invalid escape + * sequence which are still pending in the buffer + * + * Otherwise it processes the input character. If it is an escape character, + * then an escape sequence is started and the function returns 0. If we are in + * the middle of an escape sequence, the character is processed and may result + * in returning 0 (if more characters are needed) or a valid character (if + * @ichar finishes the sequence). + * + * If @ichar is a valid character and there is no escape sequence in progress, + * then it is returned as is. + * + * If the Enter key is pressed, '\n' is returned. + * + * Usage should be like this:: + * + * struct cli_ch_state cch; + * + * cli_ch_init(cch); + * do + * { + * int ichar, ch; + * + * ichar = cli_ch_process(cch, 0); + * if (!ichar) { + * ch = getchar(); + * ichar = cli_ch_process(cch, ch); + * } + * (handle the ichar character) + * } while (!done) + * + * If tstc() is used to look for keypresses, this function can be called with + * @ichar set to -ETIMEDOUT if there is no character after 5-10ms. This allows + * the ambgiuity between the Escape key and the arrow keys (which generate an + * escape character followed by other characters) to be resolved. + * + * @cch: Current state + * @ichar: Input character to process, or 0 if none, or -ETIMEDOUT if no + * character has been received within a small number of milliseconds (this + * cancels any existing escape sequence and allows pressing the Escape key to + * work) + * Returns: Resulting input character after processing, 0 if none, '\e' if + * an existing escape sequence was cancelled + */ +int cli_ch_process(struct cli_ch_state *cch, int ichar); #endif diff --git a/include/command.h b/include/command.h index 966fd23c639..3c6132e0c54 100644 --- a/include/command.h +++ b/include/command.h @@ -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, const char *confname); #endif /* __ASSEMBLY__ */ /* diff --git a/include/expo.h b/include/expo.h new file mode 100644 index 00000000000..d242f48e30c --- /dev/null +++ b/include/expo.h @@ -0,0 +1,522 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2022 Google LLC + * Written by Simon Glass <sjg@chromium.org> + */ + +#ifndef __SCENE_H +#define __SCENE_H + +#include <linux/list.h> + +struct udevice; + +/** + * enum expoact_type - types of actions reported by the expo + * + * @EXPOACT_NONE: no action + * @EXPOACT_POINT: menu item was highlighted (@id indicates which) + * @EXPOACT_SELECT: menu item was selected (@id indicates which) + * @EXPOACT_QUIT: request to exit the menu + */ +enum expoact_type { + EXPOACT_NONE, + EXPOACT_POINT, + EXPOACT_SELECT, + EXPOACT_QUIT, +}; + +/** + * struct expo_action - an action report by the expo + * + * @type: Action type (EXPOACT_NONE if there is no action) + * @select: Used for EXPOACT_POINT and EXPOACT_SELECT + * @id: ID number of the object affected. + */ +struct expo_action { + enum expoact_type type; + union { + struct { + int id; + } select; + }; +}; + +/** + * struct expo - information about an expo + * + * A group of scenes which can be presented to the user, typically to obtain + * input or to make a selection. + * + * @name: Name of the expo (allocated) + * @display: Display to use (`UCLASS_VIDEO`), or NULL to use text mode + * @scene_id: Current scene ID (0 if none) + * @next_id: Next ID number to use, for automatic allocation + * @action: Action selected by user. At present only one is supported, with the + * type set to EXPOACT_NONE if there is no action + * @text_mode: true to use text mode for the menu (no vidconsole) + * @priv: Private data for the controller + * @scene_head: List of scenes + * @str_head: list of strings + */ +struct expo { + char *name; + struct udevice *display; + uint scene_id; + uint next_id; + struct expo_action action; + bool text_mode; + void *priv; + struct list_head scene_head; + struct list_head str_head; +}; + +/** + * struct expo_string - a string that can be used in an expo + * + * @id: ID number of the string + * @str: String + * @sibling: Node to link this object to its siblings + */ +struct expo_string { + uint id; + const char *str; + struct list_head sibling; +}; + +/** + * struct scene - information about a scene in an expo + * + * A collection of text/image/menu items in an expo + * + * @expo: Expo this scene is part of + * @name: Name of the scene (allocated) + * @id: ID number of the scene + * @title: Title of the scene (allocated) + * @sibling: Node to link this scene to its siblings + * @obj_head: List of objects in the scene + */ +struct scene { + struct expo *expo; + char *name; + uint id; + char *title; + struct list_head sibling; + struct list_head obj_head; +}; + +/** + * enum scene_obj_t - type of a scene object + * + * @SCENEOBJT_NONE: Used to indicate that the type does not matter + * @SCENEOBJT_IMAGE: Image data to render + * @SCENEOBJT_TEXT: Text line to render + * @SCENEOBJT_MENU: Menu containing items the user can select + */ +enum scene_obj_t { + SCENEOBJT_NONE = 0, + SCENEOBJT_IMAGE, + SCENEOBJT_TEXT, + SCENEOBJT_MENU, +}; + +/** + * struct scene_obj - information about an object in a scene + * + * @scene: Scene that this object relates to + * @name: Name of the object (allocated) + * @id: ID number of the object + * @type: Type of this object + * @x: x position, in pixels from left side + * @y: y position, in pixels from top + * @hide: true if the object should be hidden + * @sibling: Node to link this object to its siblings + */ +struct scene_obj { + struct scene *scene; + char *name; + uint id; + enum scene_obj_t type; + int x; + int y; + bool hide; + struct list_head sibling; +}; + +/** + * struct scene_obj_img - information about an image object in a scene + * + * This is a rectangular image which is blitted onto the display + * + * @obj: Basic object information + * @data: Image data in BMP format + */ +struct scene_obj_img { + struct scene_obj obj; + char *data; +}; + +/** + * struct scene_obj_txt - information about a text object in a scene + * + * This is a single-line text object + * + * @obj: Basic object information + * @str_id: ID of the text string to display + * @font_name: Name of font (allocated by caller) + * @font_size: Nominal size of font in pixels + */ +struct scene_obj_txt { + struct scene_obj obj; + uint str_id; + const char *font_name; + uint font_size; +}; + +/** + * struct scene_obj_menu - information about a menu object in a scene + * + * A menu has a number of items which can be selected by the user + * + * It also has: + * + * - a text/image object (@pointer_id) which points to the current item + * (@cur_item_id) + * + * - a preview object which shows an image related to the current item + * + * @obj: Basic object information + * @title_id: ID of the title text, or 0 if none + * @cur_item_id: ID of the current menu item, or 0 if none + * @pointer_id: ID of the object pointing to the current selection + * @item_head: List of items in the menu + */ +struct scene_obj_menu { + struct scene_obj obj; + uint title_id; + uint cur_item_id; + uint pointer_id; + struct list_head item_head; +}; + +/** + * enum scene_menuitem_flags_t - flags for menu items + * + * @SCENEMIF_GAP_BEFORE: Add a gap before this item + */ +enum scene_menuitem_flags_t { + SCENEMIF_GAP_BEFORE = 1 << 0, +}; + +/** + * struct scene_menitem - a menu item in a menu + * + * A menu item has: + * + * - text object holding the name (short) and description (can be longer) + * - a text object holding the keypress + * + * @name: Name of the item (this is allocated by this call) + * @id: ID number of the object + * @key_id: ID of text object to use as the keypress to show + * @label_id: ID of text object to use as the label text + * @desc_id: ID of text object to use as the description text + * @preview_id: ID of the preview object, or 0 if none + * @flags: Flags for this item + * @sibling: Node to link this item to its siblings + */ +struct scene_menitem { + char *name; + uint id; + uint key_id; + uint label_id; + uint desc_id; + uint preview_id; + uint flags; + struct list_head sibling; +}; + +/** + * expo_new() - create a new expo + * + * Allocates a new expo + * + * @name: Name of expo (this is allocated by this call) + * @priv: Private data for the controller + * @expp: Returns a pointer to the new expo on success + * Returns: 0 if OK, -ENOMEM if out of memory + */ +int expo_new(const char *name, void *priv, struct expo **expp); + +/** + * expo_destroy() - Destroy an expo and free all its memory + * + * @exp: Expo to destroy + */ +void expo_destroy(struct expo *exp); + +/** + * expo_str() - add a new string to an expo + * + * @exp: Expo to update + * @name: Name to use (this is allocated by this call) + * @id: ID to use for the new object (0 to allocate one) + * @str: Pointer to text to display (allocated by caller) + * Returns: ID number for the object (typically @id), or -ve on error + */ +int expo_str(struct expo *exp, const char *name, uint id, const char *str); + +/** + * expo_get_str() - Get a string by ID + * + * @exp: Expo to use + * @id: String ID to look up + * @returns string, or NULL if not found + */ +const char *expo_get_str(struct expo *exp, uint id); + +/** + * expo_set_display() - set the display to use for a expo + * + * @exp: Expo to update + * @dev: Display to use (`UCLASS_VIDEO`), NULL to use text mode + * Returns: 0 (always) + */ +int expo_set_display(struct expo *exp, struct udevice *dev); + +/** + * expo_set_scene_id() - Set the current scene ID + * + * @exp: Expo to update + * @scene_id: New scene ID to use (0 to select no scene) + * Returns: 0 if OK, -ENOENT if there is no scene with that ID + */ +int expo_set_scene_id(struct expo *exp, uint scene_id); + +/** + * expo_render() - render the expo on the display / console + * + * @exp: Expo to render + * + * Returns: 0 if OK, -ECHILD if there is no current scene, -ENOENT if the + * current scene is not found, other error if something else goes wrong + */ +int expo_render(struct expo *exp); + +/** + * exp_set_text_mode() - Controls whether the expo renders in text mode + * + * @exp: Expo to update + * @text_mode: true to use text mode, false to use the console + */ +void exp_set_text_mode(struct expo *exp, bool text_mode); + +/** + * scene_new() - create a new scene in a expo + * + * The scene is given the ID @id which must be unique across all scenes, objects + * and items. The expo's @next_id is updated to at least @id + 1 + * + * @exp: Expo to update + * @name: Name to use (this is allocated by this call) + * @id: ID to use for the new scene (0 to allocate one) + * @scnp: Returns a pointer to the new scene on success + * Returns: ID number for the scene (typically @id), or -ve on error + */ +int scene_new(struct expo *exp, const char *name, uint id, struct scene **scnp); + +/** + * expo_lookup_scene_id() - Look up a scene by ID + * + * @exp: Expo to check + * @scene_id: Scene ID to look up + * @returns pointer to scene if found, else NULL + */ +struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id); + +/** + * scene_title_set() - set the scene title + * + * @scn: Scene to update + * @title: Title to set, NULL if none (this is allocated by this call) + * Returns: 0 if OK, -ENOMEM if out of memory + */ +int scene_title_set(struct scene *scn, const char *title); + +/** + * scene_obj_count() - Count the number of objects in a scene + * + * @scn: Scene to check + * Returns: number of objects in the scene, 0 if none + */ +int scene_obj_count(struct scene *scn); + +/** + * scene_img() - add a new image to a scene + * + * @scn: Scene to update + * @name: Name to use (this is allocated by this call) + * @id: ID to use for the new object (0 to allocate one) + * @data: Pointer to image data + * @imgp: If non-NULL, returns the new object + * Returns: ID number for the object (typically @id), or -ve on error + */ +int scene_img(struct scene *scn, const char *name, uint id, char *data, + struct scene_obj_img **imgp); + +/** + * scene_txt() - add a new text object to a scene + * + * @scn: Scene to update + * @name: Name to use (this is allocated by this call) + * @id: ID to use for the new object (0 to allocate one) + * @str_id: ID of the string to use + * @txtp: If non-NULL, returns the new object + * Returns: ID number for the object (typically @id), or -ve on error + */ +int scene_txt(struct scene *scn, const char *name, uint id, uint str_id, + struct scene_obj_txt **txtp); + +/** + * scene_txt_str() - add a new string to expr and text object to a scene + * + * @scn: Scene to update + * @name: Name to use (this is allocated by this call) + * @id: ID to use for the new object (0 to allocate one) + * @str_id: ID of the string to use + * @str: Pointer to text to display (allocated by caller) + * @txtp: If non-NULL, returns the new object + * Returns: ID number for the object (typically @id), or -ve on error + */ +int scene_txt_str(struct scene *scn, const char *name, uint id, uint str_id, + const char *str, struct scene_obj_txt **txtp); + +/** + * scene_menu() - create a menu + * + * @scn: Scene to update + * @name: Name to use (this is allocated by this call) + * @id: ID to use for the new object (0 to allocate one) + * @menup: If non-NULL, returns the new object + * Returns: ID number for the object (typically @id), or -ve on error + */ +int scene_menu(struct scene *scn, const char *name, uint id, + struct scene_obj_menu **menup); + +/** + * scene_txt_set_font() - Set the font for an object + * + * @scn: Scene to update + * @id: ID of object to update + * @font_name: Font name to use (allocated by caller) + * @font_size: Font size to use (nominal height in pixels) + */ +int scene_txt_set_font(struct scene *scn, uint id, const char *font_name, + uint font_size); + +/** + * scene_obj_set_pos() - Set the postion of an object + * + * @scn: Scene to update + * @id: ID of object to update + * @x: x position, in pixels from left side + * @y: y position, in pixels from top + * Returns: 0 if OK, -ENOENT if @id is invalid + */ +int scene_obj_set_pos(struct scene *scn, uint id, int x, int y); + +/** + * scene_obj_set_hide() - Set whether an object is hidden + * + * The update happens when the expo is next rendered. + * + * @scn: Scene to update + * @id: ID of object to update + * @hide: true to hide the object, false to show it + * Returns: 0 if OK, -ENOENT if @id is invalid + */ +int scene_obj_set_hide(struct scene *scn, uint id, bool hide); + +/** + * scene_menu_set_title() - Set the title of a menu + * + * @scn: Scene to update + * @id: ID of menu object to update + * @title_id: ID of text object to use as the title + * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @title_id is invalid + */ +int scene_menu_set_title(struct scene *scn, uint id, uint title_id); + +/** + * scene_menu_set_pointer() - Set the item pointer for a menu + * + * This is a visual indicator of the current item, typically a ">" character + * which sits next to the current item and moves when the user presses the + * up/down arrow keys + * + * @scn: Scene to update + * @id: ID of menu object to update + * @cur_item_id: ID of text or image object to use as a pointer to the current + * item + * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @cur_item_id is invalid + */ +int scene_menu_set_pointer(struct scene *scn, uint id, uint cur_item_id); + +/** + * scene_obj_get_hw() - Get width and height of an object in a scene + * + * @scn: Scene to check + * @id: ID of menu object to check + * @widthp: If non-NULL, returns width of object in pixels + * Returns: Height of object in pixels + */ +int scene_obj_get_hw(struct scene *scn, uint id, int *widthp); + +/** + * scene_menuitem() - Add an item to a menu + * + * @scn: Scene to update + * @menu_id: ID of menu object to update + * @name: Name to use (this is allocated by this call) + * @id: ID to use for the new object (0 to allocate one) + * @key_id: ID of text object to use as the keypress to show + * @label_id: ID of text object to use as the label text + * @desc_id: ID of text object to use as the description text + * @preview_id: ID of object to use as the preview (text or image) + * @flags: Flags for this item (enum scene_menuitem_flags_t) + * @itemp: If non-NULL, returns the new object + * Returns: ID number for the item (typically @id), or -ve on error + */ +int scene_menuitem(struct scene *scn, uint menu_id, const char *name, uint id, + uint key_id, uint label_id, uint desc_id, uint preview_id, + uint flags, struct scene_menitem **itemp); + +/** + * scene_arrange() - Arrange the scene to deal with object sizes + * + * Updates any menus in the scene so that their objects are in the right place. + * + * @scn: Scene to arrange + * Returns: 0 if OK, -ve on error + */ +int scene_arrange(struct scene *scn); + +/** + * expo_send_key() - set a keypress to the expo + * + * @exp: Expo to receive the key + * @key: Key to send (ASCII or enum bootmenu_key) + * Returns: 0 if OK, -ECHILD if there is no current scene + */ +int expo_send_key(struct expo *exp, int key); + +/** + * expo_action_get() - read user input from the expo + * + * @exp: Expo to check + * @act: Returns action + * Returns: 0 if OK, -EAGAIN if there was no action to return + */ +int expo_action_get(struct expo *exp, struct expo_action *act); + +#endif /*__SCENE_H */ diff --git a/include/image.h b/include/image.h index bed75ce1b38..7717a4c13d3 100644 --- a/include/image.h +++ b/include/image.h @@ -710,24 +710,18 @@ int fit_image_load(struct bootm_headers *images, ulong addr, enum fit_load_op load_op, ulong *datap, ulong *lenp); /** - * image_source_script() - Execute a script - * @addr: Address of script - * @fit_uname: FIT subimage name - * @confname: FIT config name. The subimage is chosen based on FIT_SCRIPT_PROP. - * - * 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). - * - * If @fit_uname is the empty string, then the default image is used. If - * @confname is the empty string, the default config is used. If @confname and - * @fit_uname are both non-%NULL, then @confname is ignored. If @confname and - * @fit_uname are both %NULL, then first the default config is tried, and then - * the default image. - * - * Return: result code (enum command_ret_t) - */ -int image_source_script(ulong addr, const char *fit_uname, - const char *confname); + * 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 + * @confname: Node name of FIT config 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, + const char *confname, char **datap, uint *lenp); /** * fit_get_node_from_config() - Look up an image a FIT by type diff --git a/include/menu.h b/include/menu.h index 702aacb170c..1e88141d6bf 100644 --- a/include/menu.h +++ b/include/menu.h @@ -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, @@ -42,20 +43,72 @@ 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, - 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, + + BKEY_COUNT, }; -void bootmenu_autoboot_loop(struct bootmenu_data *menu, - enum bootmenu_key *key, int *esc); -void bootmenu_loop(struct bootmenu_data *menu, - enum bootmenu_key *key, int *esc); +/** + * 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 + * @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 + */ +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 + * + * 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 + * @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 + * Down arrow: BKEY_DOWN + * Escape (by itself): BKEY_QUIT + * Plus: BKEY_PLUS + * Minus: BKEY_MINUS + * Space: BKEY_SPACE + */ +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__ */ diff --git a/include/video.h b/include/video.h index 43f2e2c02f0..3f67a93bc93 100644 --- a/include/video.h +++ b/include/video.h @@ -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, diff --git a/include/video_console.h b/include/video_console.h index d755eb73cf2..9d2c0f210e4 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -63,6 +63,15 @@ struct vidconsole_priv { }; /** + * struct vidfont_info - information about a font + * + * @name: Font name, e.g. nimbus_sans_l_regular + */ +struct vidfont_info { + const char *name; +}; + +/** * struct vidconsole_ops - Video console operations * * These operations work on either an absolute console position (measured @@ -111,6 +120,9 @@ struct vidconsole_ops { /** * entry_start() - Indicate that text entry is starting afresh * + * @dev: Device to adjust + * Returns: 0 on success, -ve on error + * * Consoles which use proportional fonts need to track the position of * each character output so that backspace will return to the correct * place. This method signals to the console driver that a new entry @@ -123,6 +135,9 @@ struct vidconsole_ops { /** * backspace() - Handle erasing the last character * + * @dev: Device to adjust + * Returns: 0 on success, -ve on error + * * With proportional fonts the vidconsole uclass cannot itself erase * the previous character. This optional method will be called when * a backspace is needed. The driver should erase the previous @@ -133,12 +148,54 @@ struct vidconsole_ops { * characters. */ int (*backspace)(struct udevice *dev); + + /** + * get_font() - Obtain information about a font (optional) + * + * @dev: Device to check + * @seq: Font number to query (0=first, 1=second, etc.) + * @info: Returns font information on success + * Returns: 0 on success, -ENOENT if no such font + */ + int (*get_font)(struct udevice *dev, int seq, + struct vidfont_info *info); + + /** + * select_font() - Select a particular font by name / size + * + * @dev: Device to adjust + * @name: Font name to use (NULL to use default) + * @size: Font size to use (0 to use default) + * Returns: 0 on success, -ENOENT if no such font + */ + int (*select_font)(struct udevice *dev, const char *name, uint size); }; /* Get a pointer to the driver operations for a video console device */ #define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops) /** + * vidconsole_get_font() - Obtain information about a font + * + * @dev: Device to check + * @seq: Font number to query (0=first, 1=second, etc.) + * @info: Returns font information on success + * Returns: 0 on success, -ENOENT if no such font, -ENOSYS if there is no such + * method + */ +int vidconsole_get_font(struct udevice *dev, int seq, + struct vidfont_info *info); + +/** + * vidconsole_select_font() - Select a particular font by name / size + * + * @dev: Device to adjust + * @name: Font name to use (NULL to use default) + * @size: Font size to use (0 to use default) + */ +int vidconsole_select_font(struct udevice *dev, const char *name, uint size); + +/** * vidconsole_putc_xy() - write a single character to a position * * @dev: Device to write to @@ -234,27 +291,21 @@ void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y); /** * vidconsole_list_fonts() - List the available fonts * - * This shows a list on the console - */ -void vidconsole_list_fonts(void); - -/** - * vidconsole_select_font() - Select a font to use + * @dev: vidconsole device to check * - * @dev: vidconsole device - * @name: Font name - * @size: Size of the font (norminal pixel height) or 0 for default + * This shows a list of fonts known by this vidconsole. The list is displayed on + * the console (not necessarily @dev but probably) */ -int vidconsole_select_font(struct udevice *dev, const char *name, uint size); +void vidconsole_list_fonts(struct udevice *dev); /** - * vidconsole_get_font() - get the current font name and size + * vidconsole_get_font_size() - get the current font name and size * * @dev: vidconsole device * @sizep: Place to put the font size (nominal height in pixels) * Returns: Current font name */ -const char *vidconsole_get_font(struct udevice *dev, uint *sizep); +const char *vidconsole_get_font_size(struct udevice *dev, uint *sizep); #ifdef CONFIG_VIDEO_COPY /** |