Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AE509C4332F for ; Mon, 17 Oct 2022 20:35:31 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3F3C984FA2; Mon, 17 Oct 2022 22:31:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="I/rSq51+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2B72284F5D; Mon, 17 Oct 2022 22:31:20 +0200 (CEST) Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 778AB84F9C for ; Mon, 17 Oct 2022 22:30:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2f.google.com with SMTP id q196so10099094iod.8 for ; Mon, 17 Oct 2022 13:30:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9tZ2kvuai5nOtUytW4hY0MCNIpt0s7ArRWEguEPIQsg=; b=I/rSq51+G6Tcec+x8jOPsgMOf0SrPm5F8m6es7ClxkFgedvpk35YFjokzpl7GRswJ2 Ze61rdK1JkfeAFGH2+FOpjfZ3E67bcL8w2qoyFenVGJrgQTfuvUERKsr5upq0R3Y0Q5U JejKLBpj81DrGafr5eraYVz/pvqH2iCD6b6DA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9tZ2kvuai5nOtUytW4hY0MCNIpt0s7ArRWEguEPIQsg=; b=wUoTII1Jgs8VKeqZsjJZveUZ786vV0IH0mlVsT6Dp7ILn0I0Ekd4X7jOCkouFyczZG D79fHEgriOqUXL3P65kEQ4rB0SW1mR30gwoRkyfOeKFmAkAknKBEHXx1ZCQ9YOe9Uy/g c7YpzAzWQfC5I9JNpOE95RD3mdkGPXzz23Faypwt5cZmxLlsZqsCN+23knIIsgFUczzQ 49FrNZ7Q9YW4ydTkgLXO78jBYApxFzvPwqrctiyqUhSQfU7bDvKuaaBTHBd6NzRGWAaa HoS8/dxxk3t9q0OBjGZ5tgiFVtWEsFiE+NVV0+nzDXXuJUuIrxn64IcbZJ0YLCFihjr+ Kopg== X-Gm-Message-State: ACrzQf1o9gWAKgIKNK7R/me+bhR6WWTlEXo5fERw3igI9s/BsNbdnJMI /Qh7n39oHZ9T917ZhcqEiM3vfmNltv/Xqw== X-Google-Smtp-Source: AMsMyM788vsB+L1phGlfF8uqIom9EBOYWlNes0w1mfz4vykm3ZW834qEiSNuuCk7I67Nay1G1BV6TQ== X-Received: by 2002:a05:6638:444:b0:363:94ed:7498 with SMTP id r4-20020a056638044400b0036394ed7498mr6353539jap.109.1666038638443; Mon, 17 Oct 2022 13:30:38 -0700 (PDT) Received: from kea.bld.corp.google.com ([2620:15c:183:200:91e:7804:2764:d161]) by smtp.gmail.com with ESMTPSA id j9-20020a926e09000000b002e939413e83sm258071ilc.48.2022.10.17.13.30.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 13:30:37 -0700 (PDT) From: Simon Glass To: u-boot@lists.denx.de Cc: Anatolij Gustschin , Tom Rini , Simon Glass , Artem Lapkin , Heinrich Schuchardt , Ramon Fried , Stefan Roese Subject: [PATCH 24/24] expo: Add documentation Date: Mon, 17 Oct 2022 14:30:00 -0600 Message-Id: <20221017203000.2207887-25-sjg@chromium.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221017203000.2207887-1-sjg@chromium.org> References: <20221017203000.2207887-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Add some documentation for the expo feature. Signed-off-by: Simon Glass --- doc/develop/expo.rst | 184 ++++++++++++++++++++++++++++++++++++++++++ doc/develop/index.rst | 1 + 2 files changed, 185 insertions(+) create mode 100644 doc/develop/expo.rst diff --git a/doc/develop/expo.rst b/doc/develop/expo.rst new file mode 100644 index 00000000000..5e502450053 --- /dev/null +++ b/doc/develop/expo.rst @@ -0,0 +1,184 @@ +.. 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. + +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_add()` and +`scene_menu_add()`. For every menu item, add text and image objects, then create +the menu item with `scene_menuitem_add()`, 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 resposibility 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 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 +.. 7-Oct-22 diff --git a/doc/develop/index.rst b/doc/develop/index.rst index ce6b38e5762..f43ded4a57f 100644 --- a/doc/develop/index.rst +++ b/doc/develop/index.rst @@ -32,6 +32,7 @@ Implementation distro driver-model/index environment + expo event global_data logging -- 2.38.0.413.g74048e4d9e-goog