From 5c3ea29e437a0b35aea82c668252d761adff2d7f Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 27 Jan 2023 00:38:50 +0100 Subject: [PATCH 01/29] cmd: fix mtest on 64 bit systems * Use 16 digits on 64 bit systems. * Use 64 bit patterns on 64 bit systems. * Expect the sign bit in bit 63 on 64 bit systems. * Adjust the formatting of a constant. * Always print result on new line Signed-off-by: Heinrich Schuchardt Reviewed-by: Stefan Roese --- cmd/mem.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/cmd/mem.c b/cmd/mem.c index 1e39348195a..66c2d36a148 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -818,8 +818,8 @@ static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr, * * Returns: 0 if the test succeeds, 1 if the test fails. */ - pattern = (vu_long) 0xaaaaaaaa; - anti_pattern = (vu_long) 0x55555555; + pattern = (vu_long)0xaaaaaaaaaaaaaaaa; + anti_pattern = (vu_long)0x5555555555555555; debug("%s:%d: length = 0x%.8lx\n", __func__, __LINE__, num_words); /* @@ -970,7 +970,7 @@ static ulong test_bitflip_comparison(volatile unsigned long *bufa, max = sizeof(unsigned long) * 8; for (k = 0; k < max; k++) { - q = 0x00000001L << k; + q = 1UL << k; for (j = 0; j < 8; j++) { schedule(); q = ~q; @@ -1009,6 +1009,7 @@ static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr, ulong errs = 0; ulong incr, length; ulong val, readback; + const int plen = 2 * sizeof(ulong); /* Alternate the pattern */ incr = 1; @@ -1020,17 +1021,17 @@ static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr, * the "negative" patterns and increment the "positive" * patterns to preserve this feature. */ - if (pattern & 0x80000000) + if (pattern > (ulong)LONG_MAX) pattern = -pattern; /* complement & increment */ else pattern = ~pattern; } length = (end_addr - start_addr) / sizeof(ulong); end = buf + length; - printf("\rPattern %08lX Writing..." + printf("\rPattern %0*lX Writing..." "%12s" "\b\b\b\b\b\b\b\b\b\b", - pattern, ""); + plen, pattern, ""); for (addr = buf, val = pattern; addr < end; addr++) { schedule(); @@ -1046,10 +1047,9 @@ static ulong mem_test_quick(vu_long *buf, ulong start_addr, ulong end_addr, if (readback != val) { ulong offset = addr - buf; - printf("\nMem error @ 0x%08X: " - "found %08lX, expected %08lX\n", - (uint)(uintptr_t)(start_addr + offset*sizeof(vu_long)), - readback, val); + printf("\nMem error @ 0x%0*lX: found %0*lX, expected %0*lX\n", + plen, start_addr + offset * sizeof(vu_long), + plen, readback, plen, val); errs++; if (ctrlc()) return -1; @@ -1135,11 +1135,7 @@ static int do_mem_mtest(struct cmd_tbl *cmdtp, int flag, int argc, unmap_sysmem((void *)buf); - if (errs == -1UL) { - /* Memory test was aborted - write a newline to finish off */ - putc('\n'); - } - printf("Tested %d iteration(s) with %lu errors.\n", iteration, count); + printf("\nTested %d iteration(s) with %lu errors.\n", iteration, count); return errs != 0; } From 0f3cd9e6df957caa1d677d949aa360c9e898236c Mon Sep 17 00:00:00 2001 From: Frieder Schrempf Date: Thu, 19 Jan 2023 12:20:34 +0100 Subject: [PATCH 02/29] doc: sl-mx8mm: Mention OSM 1.1 support The latest revision of the SoM is compliant to OSM 1.1. Signed-off-by: Frieder Schrempf --- doc/board/kontron/sl-mx8mm.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/board/kontron/sl-mx8mm.rst b/doc/board/kontron/sl-mx8mm.rst index f022e0979b1..57143b973a9 100644 --- a/doc/board/kontron/sl-mx8mm.rst +++ b/doc/board/kontron/sl-mx8mm.rst @@ -9,7 +9,7 @@ with an i.MX8M-Mini SoC, 1/2/4 GB LPDDR4 RAM, SPI NOR, eMMC and PMIC. The matching evaluation boards (Board-Line, BL) have two Ethernet ports, USB 2.0, HDMI/LVDS, SD card, CAN, RS485, RS232 and much more. -The OSM-S i.MX8MM is compliant to the Open Standard Module (OSM) 1.0 +The OSM-S i.MX8MM is compliant to the Open Standard Module (OSM) 1.1 specification, size S (https://sget.org/standards/osm). Quick Start From 4a30efa264d82e1c3c33e96a5440acd6bb604058 Mon Sep 17 00:00:00 2001 From: Frieder Schrempf Date: Thu, 19 Jan 2023 12:20:35 +0100 Subject: [PATCH 03/29] doc: sl-mx8mm: Add note about using cross toolchain This clarifies the usage of a cross toolchain to build U-Boot and TF-A. Signed-off-by: Frieder Schrempf --- doc/board/kontron/sl-mx8mm.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/board/kontron/sl-mx8mm.rst b/doc/board/kontron/sl-mx8mm.rst index 57143b973a9..ff6f01d3b7d 100644 --- a/doc/board/kontron/sl-mx8mm.rst +++ b/doc/board/kontron/sl-mx8mm.rst @@ -20,6 +20,12 @@ Quick Start - Build U-Boot - Boot +.. note:: + + To build on a x86-64 host machine, you need a GNU cross toolchain for the + target architecture (aarch64). Check your distros package manager or + download and install the necessary tools (``aarch64-linux-gnu-*``) manually. + Get and Build the Trusted Firmware-A (TF-A) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From a93985ddfcc3bab7cd066a9452453384e3398ae3 Mon Sep 17 00:00:00 2001 From: Frieder Schrempf Date: Thu, 19 Jan 2023 12:20:36 +0100 Subject: [PATCH 04/29] doc: sl-mx8mm: Update the NXP TF-A source reference Use the latest version of the NXP TF-A code and add a note about quirks with GCC 12. Signed-off-by: Frieder Schrempf Convert Note: to ..note:: Signed-off-by: Heinrich Schuchardt --- doc/board/kontron/sl-mx8mm.rst | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/doc/board/kontron/sl-mx8mm.rst b/doc/board/kontron/sl-mx8mm.rst index ff6f01d3b7d..aa3ca0885eb 100644 --- a/doc/board/kontron/sl-mx8mm.rst +++ b/doc/board/kontron/sl-mx8mm.rst @@ -29,22 +29,29 @@ Quick Start Get and Build the Trusted Firmware-A (TF-A) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Note: builddir is U-Boot build directory (source directory for in-tree builds) - There are two sources for the TF-A. Mainline and NXP. Get the one you prefer (support and features might differ). +.. note:: + + If you are using GCC 12 and you get compiler/linker errors, try to add the + following arguments to your make command as workaround: + ``CFLAGS="-Wno-array-bounds" LDFLAGS="--no-warn-rwx-segments"`` + **NXP's imx-atf** -1. Get TF-A from: https://source.codeaurora.org/external/imx/imx-atf, branch: imx_5.4.70_2.3.0 -2. Apply the patch to select the correct UART for the console, otherwise the TF-A will lock up during boot. -3. Build +1. Get TF-A from: https://github.com/nxp-imx/imx-atf, branch: lf_v2.6 +2. Build .. code-block:: bash - $ make PLAT=imx8mm bl31 + $ make PLAT=imx8mm CROSS_COMPILE=aarch64-linux-gnu- IMX_BOOT_UART_BASE="0x30880000" bl31 $ cp build/imx8mm/release/bl31.bin $(builddir) +.. note:: + + *builddir* is U-Boot's build directory (source directory for in-tree builds) + **Mainline TF-A** 1. Get TF-A from: https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/, tag: v2.4 From 5800fb8c7ad895fd1220288e4f0772d280d3f4d1 Mon Sep 17 00:00:00 2001 From: Frieder Schrempf Date: Thu, 19 Jan 2023 12:20:37 +0100 Subject: [PATCH 05/29] doc: sl-mx8mm: Update references to latest DDR firmware 8.18 Use the latest firmware available from NXP. Signed-off-by: Frieder Schrempf --- doc/board/kontron/sl-mx8mm.rst | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/doc/board/kontron/sl-mx8mm.rst b/doc/board/kontron/sl-mx8mm.rst index aa3ca0885eb..b3e21d8538b 100644 --- a/doc/board/kontron/sl-mx8mm.rst +++ b/doc/board/kontron/sl-mx8mm.rst @@ -67,10 +67,13 @@ Get the DDR firmware .. code-block:: bash - $ wget https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/firmware-imx-8.9.bin - $ chmod +x firmware-imx-8.9.bin - $ ./firmware-imx-8.9.bin - $ cp firmware-imx-8.9/firmware/ddr/synopsys/lpddr4*.bin $(builddir) + $ wget https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/firmware-imx-8.18.bin + $ chmod +x firmware-imx-8.18.bin + $ ./firmware-imx-8.18.bin + $ cp firmware-imx-8.18/firmware/ddr/synopsys/lpddr4_pmu_train_1d_imem.bin $(builddir) + $ cp firmware-imx-8.18/firmware/ddr/synopsys/lpddr4_pmu_train_1d_dmem.bin $(builddir) + $ cp firmware-imx-8.18/firmware/ddr/synopsys/lpddr4_pmu_train_2d_imem.bin $(builddir) + $ cp firmware-imx-8.18/firmware/ddr/synopsys/lpddr4_pmu_train_2d_dmem.bin $(builddir) Build U-Boot ^^^^^^^^^^^^ From 888ff2eae7417c6fbc1521332836cbebb66d2af1 Mon Sep 17 00:00:00 2001 From: Frieder Schrempf Date: Thu, 19 Jan 2023 12:20:38 +0100 Subject: [PATCH 06/29] doc: sl-mx8mm: Add guide for copying the bootloader to SPI NOR This adds a guide for copying the raw bootloader image on the SD card to the SPI NOR using U-Boot itself. Signed-off-by: Frieder Schrempf --- doc/board/kontron/sl-mx8mm.rst | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/doc/board/kontron/sl-mx8mm.rst b/doc/board/kontron/sl-mx8mm.rst index b3e21d8538b..8b29cbba67b 100644 --- a/doc/board/kontron/sl-mx8mm.rst +++ b/doc/board/kontron/sl-mx8mm.rst @@ -92,7 +92,39 @@ Burn the flash.bin to SD card at an offset of 33 KiB: Boot ^^^^ -Put the SD card in the slot on the board and apply power. +Put the SD card in the slot on the board and apply power. Check the serial +console for output. + +Flash the Bootloader to SPI NOR +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +1. Determine and note the exact size of the ``flash.bin`` image in bytes (e.g. + by running ``ls -l flash.bin``) + +2. On the U-Boot CLI copy the bootloader from SD card to RAM: + + .. code-block:: + + mmc dev 1 + mmc read $loadaddr 0x42 0x1000 + +3. Erase the SPI NOR flash: + + .. code-block:: + + sf probe + sf erase 0x0 0x200000 + +4. Copy the bootloader from RAM to SPI NOR. For the last parameter of the + command, use the size determined in step 1 in **hexadecimal notation**: + + .. code-block:: + + sf write $loadaddr 0x400 0x13B6F0 + +.. note:: + + To be able to boot from SPI NOR the OTP fuses need to be set accordingly. Further Information ------------------- From 1402f1dcee07bd87953f247cd61d1ebc00ae2d1f Mon Sep 17 00:00:00 2001 From: Frieder Schrempf Date: Thu, 19 Jan 2023 12:20:39 +0100 Subject: [PATCH 07/29] doc: sl-mx8mm: Add CROSS_COMPILE to U-Boot make call and improve comment Add the CROSS_COMPILE flag as we assume we build in a cross environment. Also improve the comment about copying the binary to SD card. Signed-off-by: Frieder Schrempf --- doc/board/kontron/sl-mx8mm.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/board/kontron/sl-mx8mm.rst b/doc/board/kontron/sl-mx8mm.rst index 8b29cbba67b..702db60fe38 100644 --- a/doc/board/kontron/sl-mx8mm.rst +++ b/doc/board/kontron/sl-mx8mm.rst @@ -81,9 +81,9 @@ Build U-Boot .. code-block:: bash $ make kontron-sl-mx8mm_defconfig - $ make + $ make CROSS_COMPILE=aarch64-linux-gnu- -Burn the flash.bin to SD card at an offset of 33 KiB: +Copy the flash.bin to SD card at an offset of 33 KiB: .. code-block:: bash From d67811aa9a7d85793e73bead898f30139265c3c2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 20 Jan 2023 14:46:05 -0700 Subject: [PATCH 08/29] event: Document dynamic event handlers Add mention of this feature in the event documentation. Signed-off-by: Simon Glass --- doc/develop/event.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/doc/develop/event.rst b/doc/develop/event.rst index 6951ec97e77..4ff59348371 100644 --- a/doc/develop/event.rst +++ b/doc/develop/event.rst @@ -64,3 +64,26 @@ in an image, use $(CROSS_COMPILE)nm:: nm u-boot |grep evspy |grep list 00000000002d6300 D _u_boot_list_2_evspy_info_2_EVT_MISC_INIT_F + +Logging is also available. Events use category `LOGC_EVENT`, so you can enable +logging on that, or add `#define LOG_DEBUG` to the top of `common/event.c` to +see events being sent. + + +Dynamic events +-------------- + +Static events provide a way of dealing with events known at build time. In some +cases we want to attach an event handler at runtime. For example, we may wish +to be notified when a particular device is probed or removed. + +This can be handled by enabling `CONFIG_EVENT_DYNAMIC`. It is then possible to +call `event_register()` to register a new handler for a particular event. + +Dynamic event handlers are called after all the static event spy handlers have +been processed. Of course, since dynamic event handlers are created at runtime +it is not possible to use the `event_dump.py` to see them. + +At present there is no way to list dynamic event handlers from the command line, +nor to deregister a dynamic event handler. These features can be added when +needed. From d485d1237b1d503753f039893179753817708553 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 21 Jan 2023 10:25:04 +0100 Subject: [PATCH 09/29] doc: example heading should be h2 The 'Example' heading should be on a lower level than 'bdinfo command'. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- doc/usage/cmd/bdinfo.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/usage/cmd/bdinfo.rst b/doc/usage/cmd/bdinfo.rst index 6b3cde2ccb5..b287d0ff736 100644 --- a/doc/usage/cmd/bdinfo.rst +++ b/doc/usage/cmd/bdinfo.rst @@ -17,7 +17,7 @@ Description The *bdinfo* command prints information about the board. Example -======= +------- :: From d530add2eff7a1ee2bf3dd596f3ca10341bb470e Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 21 Jan 2023 16:24:03 +0100 Subject: [PATCH 10/29] doc: sleep man-page Provide a man-page for the sleep command. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- doc/usage/cmd/sleep.rst | 45 +++++++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 2 files changed, 46 insertions(+) create mode 100644 doc/usage/cmd/sleep.rst diff --git a/doc/usage/cmd/sleep.rst b/doc/usage/cmd/sleep.rst new file mode 100644 index 00000000000..d19e5b3af87 --- /dev/null +++ b/doc/usage/cmd/sleep.rst @@ -0,0 +1,45 @@ +.. SPDX-License-Identifier: GPL-2.0+ +.. Copyright 2023, Heinrich Schuchardt + +sleep command +============= + +Synopsis +-------- + +:: + + sleep + +Description +----------- + +The *sleep* command waits for *delay* seconds. It can be interrupted by +CTRL+C. + +delay + delay in seconds. The value is decimal and can be fractional. + +Example +------- + +The current data and time is display before and after sleeping for 3.2 +seconds: + +:: + + => date; sleep 3.2; date + Date: 2023-01-21 (Saturday) Time: 16:02:41 + Date: 2023-01-21 (Saturday) Time: 16:02:44 + => + +Configuration +------------- + +The command is only available if CONFIG_CMD_SLEEP=y. + +Return value +------------ + +The return value $? is 0 (true) if the command completes. +The return value is 1 (false) if the command is interrupted by CTRL+C. diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 7d4a1cbc10d..72c15ca17ad 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -76,6 +76,7 @@ Shell commands cmd/scp03 cmd/setexpr cmd/size + cmd/sleep cmd/sound cmd/source cmd/temperature From ebeb8d950559fbbc3660bd767d28e979ee6dc04b Mon Sep 17 00:00:00 2001 From: Ovidiu Panait Date: Sun, 22 Jan 2023 19:57:13 +0200 Subject: [PATCH 11/29] spl: doc: use correct name in jump_to_image_optee() description The actual function being documented is jump_to_image_optee(), not jump_to_image_linux(). Signed-off-by: Ovidiu Panait Reviewed-by: Heinrich Schuchardt --- include/spl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/spl.h b/include/spl.h index fb8c279d726..827bd25c883 100644 --- a/include/spl.h +++ b/include/spl.h @@ -535,7 +535,7 @@ const char *spl_board_loader_name(u32 boot_device); void __noreturn jump_to_image_linux(struct spl_image_info *spl_image); /** - * jump_to_image_linux() - Jump to OP-TEE OS from SPL + * jump_to_image_optee() - Jump to OP-TEE OS from SPL * * This jumps into OP-TEE OS using the information in @spl_image. * From f4ece689dbc4dc8f07122e1420969b9db1d219d5 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 21 Jan 2023 17:18:14 +0100 Subject: [PATCH 12/29] doc: update font man-page * add return values * move configuration to separate section to match other man-pages * fix typo Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- doc/usage/cmd/font.rst | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/doc/usage/cmd/font.rst b/doc/usage/cmd/font.rst index 6fb08232703..8ba149d7599 100644 --- a/doc/usage/cmd/font.rst +++ b/doc/usage/cmd/font.rst @@ -12,33 +12,27 @@ Synopis font select [] font size - Description ----------- The *font* command allows selection of the font to use on the video console. -This is available when the Truetype console is in use. This is the case when -`CONFIG_CONSOLE_TRUETYPE` is enabled. - +This is available when the TrueType console is in use. font list ~~~~~~~~~ This lists the available fonts, using the name of the font file in the build. - font select ~~~~~~~~~~~ This selects a new font and optionally changes the size. - font size ~~~~~~~~~ This changes the font size only. - Examples -------- @@ -50,3 +44,14 @@ Examples => font size 40 => font select cantoraone_regular 20 => + +Configuration +------------- + +The command is only available if CONFIG_CONSOLE_TRUETYPE=y. + +Return value +------------ + +The return value $? is 0 (true) if the command completes. +The return value is 1 (false) if the command fails. From a13b92ae6f1065b189a67ec354908fb21088b8ac Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 22 Jan 2023 11:27:10 +0100 Subject: [PATCH 13/29] doc: rework doc/mkeficapsule.1 * Indicate the location of the directory for EFI capsules. * Improve the readability. Signed-off-by: Heinrich Schuchardt --- doc/mkeficapsule.1 | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/doc/mkeficapsule.1 b/doc/mkeficapsule.1 index 6fb2dd0810d..1ca245a10f8 100644 --- a/doc/mkeficapsule.1 +++ b/doc/mkeficapsule.1 @@ -11,22 +11,23 @@ mkeficapsule \- Generate EFI capsule file for U-Boot .RI [ options ] " " [ image-blob ] " " capsule-file .SH "DESCRIPTION" +The .B mkeficapsule -command is used to create an EFI capsule file for use with the U-Boot -EFI capsule update. -A capsule file may contain various type of firmware blobs which -are to be applied to the system and must be placed in the specific -directory on the UEFI system partition. -An update will be automatically executed at next reboot. +command is used to create an EFI capsule file to be used by U-Boot for firmware +updates. +A capsule file may contain various types of firmware blobs which are to be +applied to the system. +If a capsule file is placed in the /EFI/CapusuleUpdate directory of the EFI +system partition, U-Boot will try to execute the update at the next reboot. Optionally, a capsule file can be signed with a given private key. In this case, the update will be authenticated by verifying the signature before applying. -Additionally, an empty capsule file can be generated for acceptance or -rejection of firmware images by a governing component like an Operating -System. The empty capsules do not require an image-blob input file. - +Additionally, an empty capsule file can be generated to indicate the acceptance +or rejection of firmware images by a governing component like an operating +system. +Empty capsules do not require an image-blob input file. .B mkeficapsule takes any type of image files when generating non empty capsules, including: From e1f0fd525fb1b635e64661de1321bf968ad80e91 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Tue, 24 Jan 2023 10:16:02 +0100 Subject: [PATCH 14/29] doc: add rst references to distro documentation in stm32mp1 board Use internal rst reference with :doc: to have a link to distro.rst page in the generated U-Boot documentation. Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- doc/board/st/stm32mp1.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/board/st/stm32mp1.rst b/doc/board/st/stm32mp1.rst index 3f70634d283..c0b1daa0418 100644 --- a/doc/board/st/stm32mp1.rst +++ b/doc/board/st/stm32mp1.rst @@ -478,7 +478,8 @@ or: +-------+--------+---------+------------------------+------------------------+ And the 4th partition (Rootfs) is marked bootable with a file extlinux.conf -following the Generic Distribution feature (doc/develop/distro.rst for use). +following the Generic Distribution feature (see :doc:`../../develop/distro` for +use). The size of fip or ssbl partition must be enough for the associated binary file, 4MB and 2MB are default values. From 7d489128dc3721a168fd356e7accc62453e0d3e6 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 26 Jan 2023 19:40:35 +0100 Subject: [PATCH 15/29] doc: man-page for mtest Provide a man-page for the mtest command. Signed-off-by: Heinrich Schuchardt --- doc/usage/cmd/mtest.rst | 66 +++++++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 2 files changed, 67 insertions(+) create mode 100644 doc/usage/cmd/mtest.rst diff --git a/doc/usage/cmd/mtest.rst b/doc/usage/cmd/mtest.rst new file mode 100644 index 00000000000..81d1f8fd1bd --- /dev/null +++ b/doc/usage/cmd/mtest.rst @@ -0,0 +1,66 @@ +.. SPDX-License-Identifier: GPL-2.0+ +.. Copyright 2022, Heinrich Schuchardt + +mtest command +============= + +Synopsis +-------- + +:: + + mtest [start [end [pattern [iterations]]]] + +Description +----------- + +The *mtest* command tests the random access memory. It writes long values, reads +them back and checks for differences. The test can be interrupted with CTRL+C. + +The default test uses *pattern* as first value to be written and varies it +between memory addresses. + +An alternative test can be selected with CONFIG_SYS_ALT_MEMTEST=y. It uses +multiple hard coded bit patterns. + +With CONFIGSYS_ALT_MEMTEST_BITFLIP=y a further test is executed. It writes long +values offset by half the size of long and checks if writing to the one address +causes bit flips at the other address. + +start + start address of the memory range tested, defaults to + CONFIG_SYS_MEMTEST_START + +end + end address of the memory range tested, defaults to + CONFIG_SYS_MEMTEST_END. If CONFIGSYS_ALT_MEMTEST_BITFLIP=y, a value will + be written to this address. Otherwise it is excluded from the range. + +pattern + pattern to be written to memory. This is a 64bit value on 64bit systems + and a 32bit value on 32bit systems. It defaults to 0. The value is + ignored if CONFIG_SYS_ALT_MEMTEST=y. + +iterations + number of test repetitions. If the value is not provided the test will + not terminate automatically. Enter CTRL+C instead. + +Examples +-------- + +:: + + => mtest 1000 2000 0x55aa55aa55aa55aa 10 + Testing 00001000 ... 00002000: + Pattern AA55AA55AA55AA55 Writing... Reading... + Tested 16 iteration(s) with 0 errors. + +Configuration +------------- + +The mtest command is enabled by CONFIG_CMD_MEMTEST=y. + +Return value +------------ + +The return value $? is 0 (true) if the command succeeds, 1 (false) otherwise. diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 72c15ca17ad..2c95471f45c 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -63,6 +63,7 @@ Shell commands cmd/mbr cmd/md cmd/mmc + cmd/mtest cmd/part cmd/pause cmd/pinmux From cf69dc7458ec77983d230e53373438e532cad297 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 25 Jan 2023 19:14:56 +0100 Subject: [PATCH 16/29] README: correct path to sandbox.rst sandbox.rst was moved. Fixes: 2851cc94f301 ("dm: Add documentation for host command and implementation") Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 40619ee40c5..24e91b9a1f3 100644 --- a/README +++ b/README @@ -189,7 +189,7 @@ board. This allows feature development which is not board- or architecture- specific to be undertaken on a native platform. The sandbox is also used to run some of U-Boot's tests. -See doc/arch/sandbox.rst for more details. +See doc/arch/sandbox/sandbox.rst for more details. Board Initialisation Flow: From 1405bfdfd05b93e17c36193b69bc727c8af7a5b0 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 25 Jan 2023 19:14:57 +0100 Subject: [PATCH 17/29] README: rework contribution advices Remove description of coding standards and patch submission process. Link to the relevant HTML documentation instead. Signed-off-by: Heinrich Schuchardt Reviewed-by: Tom Rini Reviewed-by: Simon Glass --- README | 110 ++++----------------------------------------------------- 1 file changed, 6 insertions(+), 104 deletions(-) diff --git a/README b/README index 24e91b9a1f3..f5db75d913d 100644 --- a/README +++ b/README @@ -2862,108 +2862,10 @@ void no_more_time (int sig) } -Coding Standards: ------------------ +Contributing +============ -All contributions to U-Boot should conform to the Linux kernel -coding style; see the kernel coding style guide at -https://www.kernel.org/doc/html/latest/process/coding-style.html, and the -script "scripts/Lindent" in your Linux kernel source directory. - -Source files originating from a different project (for example the -MTD subsystem) are generally exempt from these guidelines and are not -reformatted to ease subsequent migration to newer versions of those -sources. - -Please note that U-Boot is implemented in C (and to some small parts in -Assembler); no C++ is used, so please do not use C++ style comments (//) -in your code. - -Please also stick to the following formatting rules: -- remove any trailing white space -- use TAB characters for indentation and vertical alignment, not spaces -- make sure NOT to use DOS '\r\n' line feeds -- do not add more than 2 consecutive empty lines to source files -- do not add trailing empty lines to source files - -Submissions which do not conform to the standards may be returned -with a request to reformat the changes. - - -Submitting Patches: -------------------- - -Since the number of patches for U-Boot is growing, we need to -establish some rules. Submissions which do not conform to these rules -may be rejected, even when they contain important and valuable stuff. - -Please see https://www.denx.de/wiki/U-Boot/Patches for details. - -Patches shall be sent to the u-boot mailing list ; -see https://lists.denx.de/listinfo/u-boot - -When you send a patch, please include the following information with -it: - -* For bug fixes: a description of the bug and how your patch fixes - this bug. Please try to include a way of demonstrating that the - patch actually fixes something. - -* For new features: a description of the feature and your - implementation. - -* For major contributions, add a MAINTAINERS file with your - information and associated file and directory references. - -* When you add support for a new board, don't forget to add a - maintainer e-mail address to the boards.cfg file, too. - -* If your patch adds new configuration options, don't forget to - document these in the README file. - -* The patch itself. If you are using git (which is *strongly* - recommended) you can easily generate the patch using the - "git format-patch". If you then use "git send-email" to send it to - the U-Boot mailing list, you will avoid most of the common problems - with some other mail clients. - - If you cannot use git, use "diff -purN OLD NEW". If your version of - diff does not support these options, then get the latest version of - GNU diff. - - The current directory when running this command shall be the parent - directory of the U-Boot source tree (i. e. please make sure that - your patch includes sufficient directory information for the - affected files). - - We prefer patches as plain text. MIME attachments are discouraged, - and compressed attachments must not be used. - -* If one logical set of modifications affects or creates several - files, all these changes shall be submitted in a SINGLE patch file. - -* Changesets that contain different, unrelated modifications shall be - submitted as SEPARATE patches, one patch per changeset. - - -Notes: - -* Before sending the patch, run the buildman script on your patched - source tree and make sure that no errors or warnings are reported - for any of the boards. - -* Keep your modifications to the necessary minimum: A patch - containing several unrelated changes or arbitrary reformats will be - returned with a request to re-formatting / split it. - -* If you modify existing code, make sure that your new code does not - add to the memory footprint of the code ;-) Small is beautiful! - When adding new features, these should compile conditionally only - (using #ifdef), and the resulting code with the new feature - disabled must not need more memory than the old code without your - modification. - -* Remember that there is a size limit of 100 kB per message on the - u-boot mailing list. Bigger patches will be moderated. If they are - reasonable and not too big, they will be acknowledged. But patches - bigger than the size limit should be avoided. +The U-Boot projects depends on contributions from the user community. +If you want to participate, please, have a look at the 'General' +section of https://u-boot.readthedocs.io/en/latest/develop/index.html +where we describe coding standards and the patch submission process. From 57ccfa7b0c8a7cc50a7e43a0ecedc49f5fbba087 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 25 Jan 2023 19:14:58 +0100 Subject: [PATCH 18/29] README: remove NetBSD section The information in this section is outdated. Signed-off-by: Heinrich Schuchardt Reviewed-by: Tom Rini Reviewed-by: Simon Glass --- README | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/README b/README index f5db75d913d..b4bfe39f81a 100644 --- a/README +++ b/README @@ -2526,35 +2526,6 @@ configuration to your "File transfer protocols" section: Y kermit /usr/bin/kermit -i -l %l -r N D Y N N -NetBSD Notes: -============= - -Starting at version 0.9.2, U-Boot supports NetBSD both as host -(build U-Boot) and target system (boots NetBSD/mpc8xx). - -Building requires a cross environment; it is known to work on -NetBSD/i386 with the cross-powerpc-netbsd-1.3 package (you will also -need gmake since the Makefiles are not compatible with BSD make). -Note that the cross-powerpc package does not install include files; -attempting to build U-Boot will fail because is -missing. This file has to be installed and patched manually: - - # cd /usr/pkg/cross/powerpc-netbsd/include - # mkdir powerpc - # ln -s powerpc machine - # cp /usr/src/sys/arch/powerpc/include/ansi.h powerpc/ansi.h - # ${EDIT} powerpc/ansi.h ## must remove __va_list, _BSD_VA_LIST - -Native builds *don't* work due to incompatibilities between native -and U-Boot include files. - -Booting assumes that (the first part of) the image booted is a -stage-2 loader which in turn loads and then invokes the kernel -proper. Loader sources will eventually appear in the NetBSD source -tree (probably in sys/arc/mpc8xx/stand/u-boot_stage2/); in the -meantime, see ftp://ftp.denx.de/pub/u-boot/ppcboot_stage2.tar.gz - - Implementation Internals: ========================= From 0c4759fbfd5be481d14ebb8b7c2d085ec649d04d Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 25 Jan 2023 19:14:59 +0100 Subject: [PATCH 19/29] README: replace references to CHANGELOG Board configurations are in configs/ and not in the Makefile. git log is the adequate way to identify who contributed to our source. scripts/get_maintainer.pl is the correct way to identify maintainers. Signed-off-by: Heinrich Schuchardt Reviewed-by: Tom Rini Reviewed-by: Simon Glass --- README | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/README b/README index b4bfe39f81a..a969fc7a979 100644 --- a/README +++ b/README @@ -28,20 +28,16 @@ load and run it dynamically. Status: ======= -In general, all boards for which a configuration option exists in the -Makefile have been tested to some extent and can be considered +In general, all boards for which a default configuration file exists in the +configs/ directory have been tested to some extent and can be considered "working". In fact, many of them are used in production systems. -In case of problems see the CHANGELOG file to find out who contributed -the specific port. In addition, there are various MAINTAINERS files -scattered throughout the U-Boot source identifying the people or -companies responsible for various boards and subsystems. +In case of problems you can use -Note: As of August, 2010, there is no longer a CHANGELOG file in the -actual U-Boot source tree; however, it can be created dynamically -from the Git log using: + scripts/get_maintainer.pl - make CHANGELOG +to identify the people or companies responsible for various boards and +subsystems. Or have a look at the git log. Where to get help: From 2042365acf0e4620b97a9e519430376d15e95d27 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 25 Jan 2023 19:15:00 +0100 Subject: [PATCH 20/29] doc: move 'Reproducible builds' Move the README section to the HTML documentation. Signed-off-by: Heinrich Schuchardt Reviewed-by: Tom Rini Reviewed-by: Simon Glass --- README | 11 ----------- doc/build/index.rst | 1 + doc/build/reproducible.rst | 25 +++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 doc/build/reproducible.rst diff --git a/README b/README index a969fc7a979..48db5355567 100644 --- a/README +++ b/README @@ -1713,17 +1713,6 @@ This firmware often needs to be loaded during U-Boot booting. - CONFIG_SYS_MC_RSV_MEM_ALIGN Define alignment of reserved memory MC requires -Reproducible builds -------------------- - -In order to achieve reproducible builds, timestamps used in the U-Boot build -process have to be set to a fixed value. - -This is done using the SOURCE_DATE_EPOCH environment variable. -SOURCE_DATE_EPOCH is to be set on the build host's shell, not as a configuration -option for U-Boot or an environment variable in U-Boot. - -SOURCE_DATE_EPOCH should be set to a number of seconds since the epoch, in UTC. Building the Software: ====================== diff --git a/doc/build/index.rst b/doc/build/index.rst index dc9cde40014..64e66491bd7 100644 --- a/doc/build/index.rst +++ b/doc/build/index.rst @@ -9,6 +9,7 @@ Build U-Boot source gcc clang + reproducible docker tools buildman diff --git a/doc/build/reproducible.rst b/doc/build/reproducible.rst new file mode 100644 index 00000000000..5423080633e --- /dev/null +++ b/doc/build/reproducible.rst @@ -0,0 +1,25 @@ +Reproducible builds +=================== + +In order to achieve reproducible builds, timestamps used in the U-Boot build +process have to be set to a fixed value. + +This is done using the SOURCE_DATE_EPOCH environment variable which specifies +the number of seconds since 1970-01-01T00:00:00Z. + +Example +------- + +To build the sandbox with 2023-01-01T00:00:00Z as timestamp we can use: + +.. code-block:: bash + + make sandbox_defconfig + SOURCE_DATE_EPOCH=1672531200 make + +This date is shown when we launch U-Boot: + +.. code-block:: console + + ./u-boot -T + U-Boot 2023.01 (Jan 01 2023 - 00:00:00 +0000) From 18a7f2299d835c8534eb6fb4f7e7c9f98cd63b3c Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 25 Jan 2023 19:15:01 +0100 Subject: [PATCH 21/29] README: remove section 'Versioning' The information is already maintained in doc/develop/release_cycle.rst. Signed-off-by: Heinrich Schuchardt Reviewed-by: Tom Rini Reviewed-by: Simon Glass --- README | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/README b/README index 48db5355567..5437a1bdc20 100644 --- a/README +++ b/README @@ -105,22 +105,6 @@ the string "u_boot" or on "U_BOOT". Example: IH_OS_U_BOOT u_boot_hush_start -Versioning: -=========== - -Starting with the release in October 2008, the names of the releases -were changed from numerical release numbers without deeper meaning -into a time stamp based numbering. Regular releases are identified by -names consisting of the calendar year and month of the release date. -Additional fields (if present) indicate release candidates or bug fix -releases in "stable" maintenance trees. - -Examples: - U-Boot v2009.11 - Release November 2009 - U-Boot v2009.11.1 - Release 1 in version November 2009 stable tree - U-Boot v2010.09-rc1 - Release candidate 1 for September 2010 release - - Directory Hierarchy: ==================== From c85ee98efa8b18f151c57908884a29136812af2c Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 25 Jan 2023 19:15:02 +0100 Subject: [PATCH 22/29] doc: move directory hierarchy to HTML Move section 'Directory hierarchy' from file README to the HTML documentation. Signed-off-by: Heinrich Schuchardt Reviewed-by: Tom Rini Reviewed-by: Simon Glass --- README | 38 ------------------- doc/develop/directories.rst | 76 +++++++++++++++++++++++++++++++++++++ doc/develop/index.rst | 1 + 3 files changed, 77 insertions(+), 38 deletions(-) create mode 100644 doc/develop/directories.rst diff --git a/README b/README index 5437a1bdc20..8b395356dcf 100644 --- a/README +++ b/README @@ -105,44 +105,6 @@ the string "u_boot" or on "U_BOOT". Example: IH_OS_U_BOOT u_boot_hush_start -Directory Hierarchy: -==================== - -/arch Architecture-specific files - /arc Files generic to ARC architecture - /arm Files generic to ARM architecture - /m68k Files generic to m68k architecture - /microblaze Files generic to microblaze architecture - /mips Files generic to MIPS architecture - /nios2 Files generic to Altera NIOS2 architecture - /powerpc Files generic to PowerPC architecture - /riscv Files generic to RISC-V architecture - /sandbox Files generic to HW-independent "sandbox" - /sh Files generic to SH architecture - /x86 Files generic to x86 architecture - /xtensa Files generic to Xtensa architecture -/api Machine/arch-independent API for external apps -/board Board-dependent files -/boot Support for images and booting -/cmd U-Boot commands functions -/common Misc architecture-independent functions -/configs Board default configuration files -/disk Code for disk drive partition handling -/doc Documentation (a mix of ReST and READMEs) -/drivers Device drivers -/dts Makefile for building internal U-Boot fdt. -/env Environment support -/examples Example code for standalone applications, etc. -/fs Filesystem code (cramfs, ext2, jffs2, etc.) -/include Header Files -/lib Library routines generic to all architectures -/Licenses Various license files -/net Networking code -/post Power On Self Test -/scripts Various build scripts and Makefiles -/test Various unit test files -/tools Tools to build and sign FIT images, etc. - Software Configuration: ======================= diff --git a/doc/develop/directories.rst b/doc/develop/directories.rst new file mode 100644 index 00000000000..112b5655f6e --- /dev/null +++ b/doc/develop/directories.rst @@ -0,0 +1,76 @@ +Directory hierarchy +=================== + +.. list-table:: + :header-rows: 1 + + * - Directory path + - Usage + * - /arch + - Architecture-specific files + * - /arch/arc + - Files relating to ARC architecture + * - /arch/arm + - Files relating to ARM architecture + * - /arch/m68k + - Files relating to m68k architecture + * - /arch/microblaze + - Files relating to microblaze architecture + * - /arch/mips + - Files relating to MIPS architecture + * - /arch/nios2 + - Files relating to Altera NIOS2 architecture + * - /arch/powerpc + - Files relating to PowerPC architecture + * - /arch/riscv + - Files relating to RISC-V architecture + * - /arch/sandbox + - Files relating to HW-independent "sandbox" + * - /arch/sh + - Files relating to SH architecture + * - /arch/x86 + - Files relating to x86 architecture + * - /arch/xtensa + - Files relating to Xtensa architecture + * - /api + - Machine/arch-independent API for external apps + * - /board + - Board-dependent files + * - /boot + - Support for images and booting + * - /cmd + - U-Boot commands functions + * - /common + - Misc architecture-independent functions + * - /configs + - Board default configuration files + * - /disk + - Code for disk drive partition handling + * - /doc + - Documentation (a mix of ReST and READMEs) + * - /drivers + - Device drivers + * - /dts + - Makefile for building internal U-Boot fdt. + * - /env + - Environment support + * - /examples + - Example code for standalone applications, etc. + * - /fs + - Filesystem code (cramfs, ext2, jffs2, etc.) + * - /include + - Header Files + * - /lib + - Library routines relating to all architectures + * - /Licenses + - Various license files + * - /net + - Networking code + * - /post + - Power On Self Test + * - /scripts + - Various build scripts and Makefiles + * - /test + - Various unit test files + * - /tools + - Tools to build and sign FIT images, etc. diff --git a/doc/develop/index.rst b/doc/develop/index.rst index 79d7736b134..a52ad630d0d 100644 --- a/doc/develop/index.rst +++ b/doc/develop/index.rst @@ -24,6 +24,7 @@ Implementation .. toctree:: :maxdepth: 1 + directories bloblist bootstd ci_testing From 2af09d5ac4ccb1427d0777aabcce0f488cce652e Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Wed, 25 Jan 2023 20:00:23 +0100 Subject: [PATCH 23/29] README: remove 'U-Boot Porting Guide' section This section does not match the standards of our documentation. Signed-off-by: Heinrich Schuchardt Reviewed-by: Tom Rini --- README | 74 ---------------------------------------------------------- 1 file changed, 74 deletions(-) diff --git a/README b/README index 8b395356dcf..edce7890c0f 100644 --- a/README +++ b/README @@ -2690,80 +2690,6 @@ running from ROM, and because the code will have to be relocated to a new address in RAM. -U-Boot Porting Guide: ----------------------- - -[Based on messages by Jerry Van Baren in the U-Boot-Users mailing -list, October 2002] - - -int main(int argc, char *argv[]) -{ - sighandler_t no_more_time; - - signal(SIGALRM, no_more_time); - alarm(PROJECT_DEADLINE - toSec (3 * WEEK)); - - if (available_money > available_manpower) { - Pay consultant to port U-Boot; - return 0; - } - - Download latest U-Boot source; - - Subscribe to u-boot mailing list; - - if (clueless) - email("Hi, I am new to U-Boot, how do I get started?"); - - while (learning) { - Read the README file in the top level directory; - Read https://www.denx.de/wiki/bin/view/DULG/Manual; - Read applicable doc/README.*; - Read the source, Luke; - /* find . -name "*.[chS]" | xargs grep -i */ - } - - if (available_money > toLocalCurrency ($2500)) - Buy a BDI3000; - else - Add a lot of aggravation and time; - - if (a similar board exists) { /* hopefully... */ - cp -a board/ board/ - cp include/configs/.h include/configs/.h - } else { - Create your own board support subdirectory; - Create your own board include/configs/.h file; - } - Edit new board/ files - Edit new include/configs/.h - - while (!accepted) { - while (!running) { - do { - Add / modify source code; - } until (compiles); - Debug; - if (clueless) - email("Hi, I am having problems..."); - } - Send patch file to the U-Boot email list; - if (reasonable critiques) - Incorporate improvements from email list code review; - else - Defend code as written; - } - - return 0; -} - -void no_more_time (int sig) -{ - hire_a_guru(); -} - - Contributing ============ From cb50dda10f59fd1b790788ec9ed4096247f65fd3 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 24 Jan 2023 00:25:23 +0100 Subject: [PATCH 24/29] efi_loader: fix comment in ESRT code There is no variable num_pages in function efi_esrt_allocate_install(). Signed-off-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- lib/efi_loader/efi_esrt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_esrt.c b/lib/efi_loader/efi_esrt.c index dcc08a6d3a2..7f46d651e6f 100644 --- a/lib/efi_loader/efi_esrt.c +++ b/lib/efi_loader/efi_esrt.c @@ -115,7 +115,7 @@ efi_status_t efi_esrt_allocate_install(u32 num_entries) u32 size = efi_esrt_entries_to_size(num_entries); efi_guid_t esrt_guid = efi_esrt_guid; - /* Reserve num_pages for ESRT */ + /* Reserve memory for ESRT */ ret = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, size, (void **)&new_esrt); From cd160b27bdaa81c83dabd6a82f666a388796382f Mon Sep 17 00:00:00 2001 From: Masahisa Kojima Date: Tue, 24 Jan 2023 15:56:13 +0900 Subject: [PATCH 25/29] eficonfig: refactor eficonfig_process_common function Current change boot order implementation does not call eficonfig_process_common() and call own menu functions for display_statusline, item_data_print and item_choice. Change boot order functionality should call eficonfig_process_common() to improve maintenanceability. This commit is a preparation to remove the change boot order specific implementation. The menu functions (display_statusline, item_data_print and item_choice) are added as argument of eficonfig_process_common(). The menu description string displayed at the bottom of the menu is also added as argument. Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- cmd/eficonfig.c | 71 +++++++++++++++++++++++++++++++++---------- cmd/eficonfig_sbkey.c | 18 +++++++++-- include/efi_config.h | 13 +++++++- 3 files changed, 82 insertions(+), 20 deletions(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index d830e4af53b..24d6bdb6bfd 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -22,6 +22,8 @@ #include static struct efi_simple_text_input_protocol *cin; +const char *eficonfig_menu_desc = + " Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit"; #define EFICONFIG_DESCRIPTION_MAX 32 #define EFICONFIG_OPTIONAL_DATA_MAX 64 @@ -134,10 +136,10 @@ void eficonfig_print_msg(char *msg) * * @data: pointer to the data associated with each menu entry */ -static void eficonfig_print_entry(void *data) +void eficonfig_print_entry(void *data) { struct eficonfig_entry *entry = data; - int reverse = (entry->efi_menu->active == entry->num); + bool reverse = (entry->efi_menu->active == entry->num); /* TODO: support scroll or page for many entries */ @@ -161,7 +163,7 @@ static void eficonfig_print_entry(void *data) * * @m: pointer to the menu structure */ -static void eficonfig_display_statusline(struct menu *m) +void eficonfig_display_statusline(struct menu *m) { struct eficonfig_entry *entry; @@ -171,10 +173,11 @@ static void eficonfig_display_statusline(struct menu *m) printf(ANSI_CURSOR_POSITION "\n%s\n" ANSI_CURSOR_POSITION ANSI_CLEAR_LINE ANSI_CURSOR_POSITION - " Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit" + "%s" ANSI_CLEAR_LINE_TO_END ANSI_CURSOR_POSITION ANSI_CLEAR_LINE, 1, 1, entry->efi_menu->menu_header, entry->efi_menu->count + 5, 1, - entry->efi_menu->count + 6, 1, entry->efi_menu->count + 7, 1); + entry->efi_menu->count + 6, 1, entry->efi_menu->menu_desc, + entry->efi_menu->count + 7, 1); } /** @@ -183,7 +186,7 @@ static void eficonfig_display_statusline(struct menu *m) * @data: pointer to the efimenu structure * Return: key string to identify the selected entry */ -static char *eficonfig_choice_entry(void *data) +char *eficonfig_choice_entry(void *data) { struct cli_ch_state s_cch, *cch = &s_cch; struct list_head *pos, *n; @@ -361,9 +364,17 @@ out: * * @efi_menu: pointer to the efimenu structure * @menu_header: pointer to the menu header string + * @menu_desc: pointer to the menu description + * @display_statusline: function pointer to draw statusline + * @item_data_print: function pointer to draw the menu item + * @item_choice: function pointer to handle the key press * Return: status code */ -efi_status_t eficonfig_process_common(struct efimenu *efi_menu, char *menu_header) +efi_status_t eficonfig_process_common(struct efimenu *efi_menu, + char *menu_header, const char *menu_desc, + void (*display_statusline)(struct menu *), + void (*item_data_print)(void *), + char *(*item_choice)(void *)) { struct menu *menu; void *choice = NULL; @@ -382,10 +393,11 @@ efi_status_t eficonfig_process_common(struct efimenu *efi_menu, char *menu_heade if (!efi_menu->menu_header) return EFI_OUT_OF_RESOURCES; } + if (menu_desc) + efi_menu->menu_desc = menu_desc; - menu = menu_create(NULL, 0, 1, eficonfig_display_statusline, - eficonfig_print_entry, eficonfig_choice_entry, - efi_menu); + menu = menu_create(NULL, 0, 1, display_statusline, item_data_print, + item_choice, efi_menu); if (!menu) return EFI_INVALID_PARAMETER; @@ -644,7 +656,12 @@ static efi_status_t eficonfig_select_volume(struct eficonfig_select_file_info *f if (ret != EFI_SUCCESS) goto out; - ret = eficonfig_process_common(efi_menu, " ** Select Volume **"); + ret = eficonfig_process_common(efi_menu, " ** Select Volume **", + eficonfig_menu_desc, + eficonfig_display_statusline, + eficonfig_print_entry, + eficonfig_choice_entry); + out: efi_free_pool(volume_handles); list_for_each_safe(pos, n, &efi_menu->list) { @@ -819,7 +836,11 @@ static efi_status_t eficonfig_show_file_selection(struct eficonfig_select_file_i if (ret != EFI_SUCCESS) goto err; - ret = eficonfig_process_common(efi_menu, " ** Select File **"); + ret = eficonfig_process_common(efi_menu, " ** Select File **", + eficonfig_menu_desc, + eficonfig_display_statusline, + eficonfig_print_entry, + eficonfig_choice_entry); err: EFI_CALL(f->close(f)); eficonfig_destroy(efi_menu); @@ -980,7 +1001,11 @@ efi_status_t eficonfig_process_show_file_option(void *data) if (!efi_menu) return EFI_OUT_OF_RESOURCES; - ret = eficonfig_process_common(efi_menu, " ** Update File **"); + ret = eficonfig_process_common(efi_menu, " ** Update File **", + eficonfig_menu_desc, + eficonfig_display_statusline, + eficonfig_print_entry, + eficonfig_choice_entry); if (ret != EFI_SUCCESS) /* User selects "Clear" or "Quit" */ ret = EFI_NOT_READY; @@ -1326,7 +1351,12 @@ static efi_status_t eficonfig_show_boot_option(struct eficonfig_boot_option *bo, if (ret != EFI_SUCCESS) goto out; - ret = eficonfig_process_common(efi_menu, header_str); + ret = eficonfig_process_common(efi_menu, header_str, + eficonfig_menu_desc, + eficonfig_display_statusline, + eficonfig_print_entry, + eficonfig_choice_entry); + out: eficonfig_destroy(efi_menu); @@ -1745,7 +1775,11 @@ static efi_status_t eficonfig_show_boot_selection(unsigned int *selected) if (ret != EFI_SUCCESS) goto out; - ret = eficonfig_process_common(efi_menu, " ** Select Boot Option **"); + ret = eficonfig_process_common(efi_menu, " ** Select Boot Option **", + eficonfig_menu_desc, + eficonfig_display_statusline, + eficonfig_print_entry, + eficonfig_choice_entry); out: list_for_each_safe(pos, n, &efi_menu->list) { entry = list_entry(pos, struct eficonfig_entry, list); @@ -2567,7 +2601,12 @@ static int do_eficonfig(struct cmd_tbl *cmdtp, int flag, int argc, char *const a if (!efi_menu) return CMD_RET_FAILURE; - ret = eficonfig_process_common(efi_menu, " ** UEFI Maintenance Menu **"); + ret = eficonfig_process_common(efi_menu, + " ** UEFI Maintenance Menu **", + eficonfig_menu_desc, + eficonfig_display_statusline, + eficonfig_print_entry, + eficonfig_choice_entry); eficonfig_destroy(efi_menu); if (ret == EFI_ABORTED) diff --git a/cmd/eficonfig_sbkey.c b/cmd/eficonfig_sbkey.c index ed39aab0817..caca27495e0 100644 --- a/cmd/eficonfig_sbkey.c +++ b/cmd/eficonfig_sbkey.c @@ -410,7 +410,10 @@ static efi_status_t enumerate_and_show_signature_database(void *varname) goto out; snprintf(buf, sizeof(buf), " ** Show Signature Database (%ls) **", (u16 *)varname); - ret = eficonfig_process_common(efi_menu, buf); + ret = eficonfig_process_common(efi_menu, buf, eficonfig_menu_desc, + eficonfig_display_statusline, + eficonfig_print_entry, + eficonfig_choice_entry); out: list_for_each_safe(pos, n, &efi_menu->list) { entry = list_entry(pos, struct eficonfig_entry, list); @@ -472,7 +475,11 @@ static efi_status_t eficonfig_process_set_secure_boot_key(void *data) efi_menu = eficonfig_create_fixed_menu(key_config_menu_items, ARRAY_SIZE(key_config_menu_items)); - ret = eficonfig_process_common(efi_menu, header_str); + ret = eficonfig_process_common(efi_menu, header_str, + eficonfig_menu_desc, + eficonfig_display_statusline, + eficonfig_print_entry, + eficonfig_choice_entry); eficonfig_destroy(efi_menu); if (ret == EFI_ABORTED) @@ -518,7 +525,12 @@ efi_status_t eficonfig_process_secure_boot_config(void *data) break; } - ret = eficonfig_process_common(efi_menu, header_str); + ret = eficonfig_process_common(efi_menu, header_str, + eficonfig_menu_desc, + eficonfig_display_statusline, + eficonfig_print_entry, + eficonfig_choice_entry); + eficonfig_destroy(efi_menu); if (ret == EFI_ABORTED) diff --git a/include/efi_config.h b/include/efi_config.h index fd699263436..cec5715f844 100644 --- a/include/efi_config.h +++ b/include/efi_config.h @@ -9,12 +9,14 @@ #define _EFI_CONFIG_H #include +#include #define EFICONFIG_ENTRY_NUM_MAX 99 #define EFICONFIG_VOLUME_PATH_MAX 512 #define EFICONFIG_FILE_PATH_MAX 512 #define EFICONFIG_FILE_PATH_BUF_SIZE (EFICONFIG_FILE_PATH_MAX * sizeof(u16)) +extern const char *eficonfig_menu_desc; typedef efi_status_t (*eficonfig_entry_func)(void *data); /** @@ -45,6 +47,7 @@ struct eficonfig_entry { * @active: active menu entry index * @count: total count of menu entry * @menu_header: menu header string + * @menu_desc: menu description string * @list: menu entry list structure */ struct efimenu { @@ -52,6 +55,7 @@ struct efimenu { int active; int count; char *menu_header; + const char *menu_desc; struct list_head list; }; @@ -86,9 +90,16 @@ struct eficonfig_select_file_info { }; void eficonfig_print_msg(char *msg); +void eficonfig_print_entry(void *data); +void eficonfig_display_statusline(struct menu *m); +char *eficonfig_choice_entry(void *data); void eficonfig_destroy(struct efimenu *efi_menu); efi_status_t eficonfig_process_quit(void *data); -efi_status_t eficonfig_process_common(struct efimenu *efi_menu, char *menu_header); +efi_status_t eficonfig_process_common(struct efimenu *efi_menu, + char *menu_header, const char *menu_desc, + void (*display_statusline)(struct menu *), + void (*item_data_print)(void *), + char *(*item_choice)(void *)); efi_status_t eficonfig_process_select_file(void *data); efi_status_t eficonfig_get_unused_bootoption(u16 *buf, efi_uintn_t buf_size, u32 *index); From 0d59085235589f47323d84b7e412d1b6acb10286 Mon Sep 17 00:00:00 2001 From: Masahisa Kojima Date: Tue, 24 Jan 2023 15:56:14 +0900 Subject: [PATCH 26/29] eficonfig: refactor change boot order implementation This commit removes the change boot order specific menu implementation. The change boot order implementation calls eficonfig_process_common() same as other menus. The change boot order menu requires own item_data_print and item_choice implementation, but display_statusline function can be a same function as other menus. Signed-off-by: Masahisa Kojima Acked-by: Ilias Apalodimas Reviewed-by: Ilias Apalodimas --- cmd/eficonfig.c | 248 +++++++++++++++++++++++++++++------------------- 1 file changed, 152 insertions(+), 96 deletions(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 24d6bdb6bfd..01bd1b05bc2 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -25,6 +25,11 @@ static struct efi_simple_text_input_protocol *cin; const char *eficonfig_menu_desc = " Press UP/DOWN to move, ENTER to select, ESC/CTRL+C to quit"; +static const char *eficonfig_change_boot_order_desc = + " Press UP/DOWN to move, +/- to change orde\n" + " Press SPACE to activate or deactivate the entry\n" + " Select [Save] to complete, ESC/CTRL+C to quit"; + #define EFICONFIG_DESCRIPTION_MAX 32 #define EFICONFIG_OPTIONAL_DATA_MAX 64 @@ -106,6 +111,17 @@ struct eficonfig_boot_order_data { bool active; }; +/** + * struct eficonfig_save_boot_order_data - structure to be used to change boot order + * + * @efi_menu: pointer to efimenu structure + * @selected: flag to indicate user selects "Save" entry + */ +struct eficonfig_save_boot_order_data { + struct efimenu *efi_menu; + bool selected; +}; + /** * eficonfig_print_msg() - print message * @@ -174,10 +190,9 @@ void eficonfig_display_statusline(struct menu *m) "\n%s\n" ANSI_CURSOR_POSITION ANSI_CLEAR_LINE ANSI_CURSOR_POSITION "%s" - ANSI_CLEAR_LINE_TO_END ANSI_CURSOR_POSITION ANSI_CLEAR_LINE, + ANSI_CLEAR_LINE_TO_END, 1, 1, entry->efi_menu->menu_header, entry->efi_menu->count + 5, 1, - entry->efi_menu->count + 6, 1, entry->efi_menu->menu_desc, - entry->efi_menu->count + 7, 1); + entry->efi_menu->count + 6, 1, entry->efi_menu->menu_desc); } /** @@ -1844,63 +1859,44 @@ out: } /** - * eficonfig_display_change_boot_order() - display the BootOrder list + * eficonfig_print_change_boot_order_entry() - print the boot option entry * - * @efi_menu: pointer to the efimenu structure - * Return: status code + * @data: pointer to the data associated with each menu entry */ -static void eficonfig_display_change_boot_order(struct efimenu *efi_menu) +static void eficonfig_print_change_boot_order_entry(void *data) { - bool reverse; - struct list_head *pos, *n; - struct eficonfig_entry *entry; + struct eficonfig_entry *entry = data; + bool reverse = (entry->efi_menu->active == entry->num); - printf(ANSI_CLEAR_CONSOLE ANSI_CURSOR_POSITION - "\n ** Change Boot Order **\n" - ANSI_CURSOR_POSITION - " Press UP/DOWN to move, +/- to change order" - ANSI_CURSOR_POSITION - " Press SPACE to activate or deactivate the entry" - ANSI_CURSOR_POSITION - " Select [Save] to complete, ESC/CTRL+C to quit" - ANSI_CURSOR_POSITION ANSI_CLEAR_LINE, - 1, 1, efi_menu->count + 5, 1, efi_menu->count + 6, 1, - efi_menu->count + 7, 1, efi_menu->count + 8, 1); + printf(ANSI_CURSOR_POSITION, entry->num + 4, 7); - /* draw boot option list */ - list_for_each_safe(pos, n, &efi_menu->list) { - entry = list_entry(pos, struct eficonfig_entry, list); - reverse = (entry->num == efi_menu->active); + if (reverse) + puts(ANSI_COLOR_REVERSE); - printf(ANSI_CURSOR_POSITION, entry->num + 4, 7); - - if (reverse) - puts(ANSI_COLOR_REVERSE); - - if (entry->num < efi_menu->count - 2) { - if (((struct eficonfig_boot_order_data *)entry->data)->active) - printf("[*] "); - else - printf("[ ] "); - } - - printf("%s", entry->title); - - if (reverse) - puts(ANSI_COLOR_RESET); + if (entry->num < entry->efi_menu->count - 2) { + if (((struct eficonfig_boot_order_data *)entry->data)->active) + printf("[*] "); + else + printf("[ ] "); } + + printf("%s", entry->title); + + if (reverse) + puts(ANSI_COLOR_RESET); } /** - * eficonfig_choice_change_boot_order() - handle the BootOrder update + * eficonfig_choice_change_boot_order() - user key input handler * - * @efi_menu: pointer to the efimenu structure - * Return: status code + * @data: pointer to the menu entry + * Return: key string to identify the selected entry */ -static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) +char *eficonfig_choice_change_boot_order(void *data) { struct cli_ch_state s_cch, *cch = &s_cch; struct list_head *pos, *n; + struct efimenu *efi_menu = data; enum bootmenu_key key = BKEY_NONE; struct eficonfig_entry *entry, *tmp; @@ -1926,7 +1922,7 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) case BKEY_UP: if (efi_menu->active > 0) --efi_menu->active; - return EFI_NOT_READY; + return NULL; case BKEY_MINUS: if (efi_menu->active < efi_menu->count - 3) { list_for_each_safe(pos, n, &efi_menu->list) { @@ -1942,20 +1938,29 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) ++efi_menu->active; } - return EFI_NOT_READY; + return NULL; case BKEY_DOWN: if (efi_menu->active < efi_menu->count - 1) ++efi_menu->active; - return EFI_NOT_READY; + return NULL; case BKEY_SELECT: /* "Save" */ - if (efi_menu->active == efi_menu->count - 2) - return EFI_SUCCESS; - + if (efi_menu->active == efi_menu->count - 2) { + list_for_each_prev_safe(pos, n, &efi_menu->list) { + entry = list_entry(pos, struct eficonfig_entry, list); + if (entry->num == efi_menu->active) + break; + } + return entry->key; + } /* "Quit" */ - if (efi_menu->active == efi_menu->count - 1) - return EFI_ABORTED; - + if (efi_menu->active == efi_menu->count - 1) { + entry = list_last_entry(&efi_menu->list, + struct eficonfig_entry, + list); + return entry->key; + } + /* Pressed key is not valid, wait next key press */ break; case BKEY_SPACE: if (efi_menu->active < efi_menu->count - 2) { @@ -1965,20 +1970,84 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) struct eficonfig_boot_order_data *data = entry->data; data->active = !data->active; - return EFI_NOT_READY; + return NULL; } } } + /* Pressed key is not valid, wait next key press */ break; case BKEY_QUIT: - return EFI_ABORTED; + entry = list_last_entry(&efi_menu->list, + struct eficonfig_entry, list); + return entry->key; default: - /* Pressed key is not valid, no need to regenerate the menu */ + /* Pressed key is not valid, wait next key press */ break; } } } +/** + * eficonfig_process_save_boot_order() - callback function for "Save" entry + * + * @data: pointer to the data + * Return: status code + */ +static efi_status_t eficonfig_process_save_boot_order(void *data) +{ + u32 count = 0; + efi_status_t ret; + efi_uintn_t size; + struct list_head *pos, *n; + u16 *new_bootorder; + struct efimenu *efi_menu; + struct eficonfig_entry *entry; + struct eficonfig_save_boot_order_data *save_data = data; + + efi_menu = save_data->efi_menu; + + /* + * The change boot order menu always has "Save" and "Quit" entries. + * !(efi_menu->count - 2) means there is no user defined boot option. + */ + if (!(efi_menu->count - 2)) + return EFI_SUCCESS; + + new_bootorder = calloc(1, (efi_menu->count - 2) * sizeof(u16)); + if (!new_bootorder) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + + /* create new BootOrder */ + count = 0; + list_for_each_safe(pos, n, &efi_menu->list) { + struct eficonfig_boot_order_data *data; + + entry = list_entry(pos, struct eficonfig_entry, list); + /* exit the loop when iteration reaches "Save" */ + if (!strncmp(entry->title, "Save", strlen("Save"))) + break; + + data = entry->data; + if (data->active) + new_bootorder[count++] = data->boot_index; + } + + size = count * sizeof(u16); + ret = efi_set_variable_int(u"BootOrder", &efi_global_variable_guid, + EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, + size, new_bootorder, false); + + save_data->selected = true; +out: + free(new_bootorder); + + return ret; +} + /** * eficonfig_add_change_boot_order_entry() - add boot order entry * @@ -2054,6 +2123,7 @@ static efi_status_t eficonfig_create_change_boot_order_entry(struct efimenu *efi efi_status_t ret; u16 *var_name16 = NULL; efi_uintn_t size, buf_size; + struct eficonfig_save_boot_order_data *save_data; /* list the load option in the order of BootOrder variable */ for (i = 0; i < num; i++) { @@ -2104,7 +2174,17 @@ static efi_status_t eficonfig_create_change_boot_order_entry(struct efimenu *efi goto out; } - ret = eficonfig_append_menu_entry(efi_menu, title, NULL, NULL); + save_data = malloc(sizeof(struct eficonfig_save_boot_order_data)); + if (!save_data) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + save_data->efi_menu = efi_menu; + save_data->selected = false; + + ret = eficonfig_append_menu_entry(efi_menu, title, + eficonfig_process_save_boot_order, + save_data); if (ret != EFI_SUCCESS) goto out; @@ -2127,7 +2207,6 @@ out: */ static efi_status_t eficonfig_process_change_boot_order(void *data) { - u32 count; u16 *bootorder; efi_status_t ret; efi_uintn_t num, size; @@ -2148,47 +2227,24 @@ static efi_status_t eficonfig_process_change_boot_order(void *data) goto out; while (1) { - eficonfig_display_change_boot_order(efi_menu); - - ret = eficonfig_choice_change_boot_order(efi_menu); - if (ret == EFI_SUCCESS) { - u16 *new_bootorder; - - new_bootorder = calloc(1, (efi_menu->count - 2) * sizeof(u16)); - if (!new_bootorder) { - ret = EFI_OUT_OF_RESOURCES; - goto out; - } - - /* create new BootOrder */ - count = 0; - list_for_each_safe(pos, n, &efi_menu->list) { - struct eficonfig_boot_order_data *data; - + ret = eficonfig_process_common(efi_menu, + " ** Change Boot Order **", + eficonfig_change_boot_order_desc, + eficonfig_display_statusline, + eficonfig_print_change_boot_order_entry, + eficonfig_choice_change_boot_order); + /* exit from the menu if user selects the "Save" entry. */ + if (ret == EFI_SUCCESS && efi_menu->active == (efi_menu->count - 2)) { + list_for_each_prev_safe(pos, n, &efi_menu->list) { entry = list_entry(pos, struct eficonfig_entry, list); - /* exit the loop when iteration reaches "Save" */ - if (!strncmp(entry->title, "Save", strlen("Save"))) + if (entry->num == efi_menu->active) break; - - data = entry->data; - if (data->active) - new_bootorder[count++] = data->boot_index; } - - size = count * sizeof(u16); - ret = efi_set_variable_int(u"BootOrder", &efi_global_variable_guid, - EFI_VARIABLE_NON_VOLATILE | - EFI_VARIABLE_BOOTSERVICE_ACCESS | - EFI_VARIABLE_RUNTIME_ACCESS, - size, new_bootorder, false); - - free(new_bootorder); - goto out; - } else if (ret == EFI_NOT_READY) { - continue; - } else { - goto out; + if (((struct eficonfig_save_boot_order_data *)entry->data)->selected) + break; } + if (ret != EFI_SUCCESS) + break; } out: free(bootorder); From 8dbd0a0f8e4c59c4fa705585ee2d552acdc5bdb2 Mon Sep 17 00:00:00 2001 From: Masahisa Kojima Date: Tue, 24 Jan 2023 15:56:15 +0900 Subject: [PATCH 27/29] eficonfig: add vertical scroll support The current eficonfig menu does not support vertical scroll, so it can not display the menu entries greater than the console row size. This commit add the vertial scroll support. The console size is retrieved by SIMPLE_TEXT_OUTPUT_PROTOCOL.QueryMode() service, then calculates the row size for menu entry by subtracting menu header and description row size from the console row size. "start" and "end" are added in the efimenu structure. "start" keeps the menu entry index at the top, "end" keeps the bottom menu entry index. item_data_print() menu function only draws the menu entry between "start" and "end". This commit also fixes the issue that "Save" and "Quit" entries can be moved by BKEY_PLUS in change boot order menu. Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- cmd/eficonfig.c | 92 ++++++++++++++++++++++++++++++++++++-------- include/efi_config.h | 4 ++ include/efi_loader.h | 1 + 3 files changed, 80 insertions(+), 17 deletions(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 01bd1b05bc2..47c04cf5363 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -30,8 +30,13 @@ static const char *eficonfig_change_boot_order_desc = " Press SPACE to activate or deactivate the entry\n" " Select [Save] to complete, ESC/CTRL+C to quit"; +static struct efi_simple_text_output_protocol *cout; +static int avail_row; + #define EFICONFIG_DESCRIPTION_MAX 32 #define EFICONFIG_OPTIONAL_DATA_MAX 64 +#define EFICONFIG_MENU_HEADER_ROW_NUM 3 +#define EFICONFIG_MENU_DESC_ROW_NUM 5 /** * struct eficonfig_filepath_info - structure to be used to store file path @@ -122,6 +127,30 @@ struct eficonfig_save_boot_order_data { bool selected; }; +/** + * struct eficonfig_menu_adjust - update start and end entry index + * + * @efi_menu: pointer to efimenu structure + * @add: flag to add or substract the index + */ +static void eficonfig_menu_adjust(struct efimenu *efi_menu, bool add) +{ + if (add) + ++efi_menu->active; + else + --efi_menu->active; + + if (add && efi_menu->end < efi_menu->active) { + efi_menu->start++; + efi_menu->end++; + } else if (!add && efi_menu->start > efi_menu->active) { + efi_menu->start--; + efi_menu->end--; + } +} +#define eficonfig_menu_up(_a) eficonfig_menu_adjust(_a, false) +#define eficonfig_menu_down(_a) eficonfig_menu_adjust(_a, true) + /** * eficonfig_print_msg() - print message * @@ -157,18 +186,16 @@ void eficonfig_print_entry(void *data) struct eficonfig_entry *entry = data; bool reverse = (entry->efi_menu->active == entry->num); - /* TODO: support scroll or page for many entries */ + if (entry->efi_menu->start > entry->num || entry->efi_menu->end < entry->num) + return; - /* - * Move cursor to line where the entry will be drawn (entry->num) - * First 3 lines(menu header) + 1 empty line - */ - printf(ANSI_CURSOR_POSITION, entry->num + 4, 7); + printf(ANSI_CURSOR_POSITION, (entry->num - entry->efi_menu->start) + + EFICONFIG_MENU_HEADER_ROW_NUM + 1, 7); if (reverse) puts(ANSI_COLOR_REVERSE); - printf("%s", entry->title); + printf(ANSI_CLEAR_LINE "%s", entry->title); if (reverse) puts(ANSI_COLOR_RESET); @@ -191,8 +218,8 @@ void eficonfig_display_statusline(struct menu *m) ANSI_CURSOR_POSITION ANSI_CLEAR_LINE ANSI_CURSOR_POSITION "%s" ANSI_CLEAR_LINE_TO_END, - 1, 1, entry->efi_menu->menu_header, entry->efi_menu->count + 5, 1, - entry->efi_menu->count + 6, 1, entry->efi_menu->menu_desc); + 1, 1, entry->efi_menu->menu_header, avail_row + 4, 1, + avail_row + 5, 1, entry->efi_menu->menu_desc); } /** @@ -217,12 +244,14 @@ char *eficonfig_choice_entry(void *data) switch (key) { case BKEY_UP: if (efi_menu->active > 0) - --efi_menu->active; + eficonfig_menu_up(efi_menu); + /* no menu key selected, regenerate menu */ return NULL; case BKEY_DOWN: if (efi_menu->active < efi_menu->count - 1) - ++efi_menu->active; + eficonfig_menu_down(efi_menu); + /* no menu key selected, regenerate menu */ return NULL; case BKEY_SELECT: @@ -402,6 +431,8 @@ efi_status_t eficonfig_process_common(struct efimenu *efi_menu, efi_menu->delay = -1; efi_menu->active = 0; + efi_menu->start = 0; + efi_menu->end = avail_row - 1; if (menu_header) { efi_menu->menu_header = strdup(menu_header); @@ -1868,7 +1899,11 @@ static void eficonfig_print_change_boot_order_entry(void *data) struct eficonfig_entry *entry = data; bool reverse = (entry->efi_menu->active == entry->num); - printf(ANSI_CURSOR_POSITION, entry->num + 4, 7); + if (entry->efi_menu->start > entry->num || entry->efi_menu->end < entry->num) + return; + + printf(ANSI_CURSOR_POSITION ANSI_CLEAR_LINE, + (entry->num - entry->efi_menu->start) + EFICONFIG_MENU_HEADER_ROW_NUM + 1, 7); if (reverse) puts(ANSI_COLOR_REVERSE); @@ -1906,7 +1941,8 @@ char *eficonfig_choice_change_boot_order(void *data) switch (key) { case BKEY_PLUS: - if (efi_menu->active > 0) { + if (efi_menu->active > 0 && + efi_menu->active < efi_menu->count - 2) { list_for_each_safe(pos, n, &efi_menu->list) { entry = list_entry(pos, struct eficonfig_entry, list); if (entry->num == efi_menu->active) @@ -1917,11 +1953,14 @@ char *eficonfig_choice_change_boot_order(void *data) tmp->num++; list_del(&tmp->list); list_add(&tmp->list, &entry->list); + + eficonfig_menu_up(efi_menu); } - fallthrough; + return NULL; case BKEY_UP: if (efi_menu->active > 0) - --efi_menu->active; + eficonfig_menu_up(efi_menu); + return NULL; case BKEY_MINUS: if (efi_menu->active < efi_menu->count - 3) { @@ -1936,12 +1975,13 @@ char *eficonfig_choice_change_boot_order(void *data) list_del(&entry->list); list_add(&entry->list, &tmp->list); - ++efi_menu->active; + eficonfig_menu_down(efi_menu); } return NULL; case BKEY_DOWN: if (efi_menu->active < efi_menu->count - 1) - ++efi_menu->active; + eficonfig_menu_down(efi_menu); + return NULL; case BKEY_SELECT: /* "Save" */ @@ -2590,6 +2630,7 @@ static efi_status_t eficonfig_init(void) efi_status_t ret = EFI_SUCCESS; static bool init; struct efi_handler *handler; + unsigned long columns, rows; if (!init) { ret = efi_search_protocol(efi_root, &efi_guid_text_input_protocol, &handler); @@ -2600,6 +2641,23 @@ static efi_status_t eficonfig_init(void) EFI_OPEN_PROTOCOL_GET_PROTOCOL); if (ret != EFI_SUCCESS) return ret; + ret = efi_search_protocol(efi_root, &efi_guid_text_output_protocol, &handler); + if (ret != EFI_SUCCESS) + return ret; + + ret = efi_protocol_open(handler, (void **)&cout, efi_root, NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (ret != EFI_SUCCESS) + return ret; + + cout->query_mode(cout, cout->mode->mode, &columns, &rows); + avail_row = rows - (EFICONFIG_MENU_HEADER_ROW_NUM + + EFICONFIG_MENU_DESC_ROW_NUM); + if (avail_row <= 0) { + eficonfig_print_msg("Console size is too small!"); + return EFI_INVALID_PARAMETER; + } + /* TODO: Should we check the minimum column size? */ } init = true; diff --git a/include/efi_config.h b/include/efi_config.h index cec5715f844..6a104e4b1db 100644 --- a/include/efi_config.h +++ b/include/efi_config.h @@ -49,6 +49,8 @@ struct eficonfig_entry { * @menu_header: menu header string * @menu_desc: menu description string * @list: menu entry list structure + * @start: top menu index to draw + * @end: bottom menu index to draw */ struct efimenu { int delay; @@ -57,6 +59,8 @@ struct efimenu { char *menu_header; const char *menu_desc; struct list_head list; + int start; + int end; }; /** diff --git a/include/efi_loader.h b/include/efi_loader.h index f9e427f0905..4560b0d04cb 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -328,6 +328,7 @@ extern const efi_guid_t efi_esrt_guid; extern const efi_guid_t smbios_guid; /*GUID of console */ extern const efi_guid_t efi_guid_text_input_protocol; +extern const efi_guid_t efi_guid_text_output_protocol; extern char __efi_runtime_start[], __efi_runtime_stop[]; extern char __efi_runtime_rel_start[], __efi_runtime_rel_stop[]; From 23aa0502a4b9a60156809cd27baf7e9016d1be56 Mon Sep 17 00:00:00 2001 From: Masahisa Kojima Date: Tue, 24 Jan 2023 15:56:16 +0900 Subject: [PATCH 28/29] eficonfig: increase the number of menu entries Current eficonfig has the maximum number of menu entries and it is 99. If there are more EFI load options and files in the system, eficonfig can not handle it. This commit increases this maximum number of menu entries to INT_MAX. Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- include/efi_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/efi_config.h b/include/efi_config.h index 6a104e4b1db..e5edbb5e090 100644 --- a/include/efi_config.h +++ b/include/efi_config.h @@ -11,7 +11,7 @@ #include #include -#define EFICONFIG_ENTRY_NUM_MAX 99 +#define EFICONFIG_ENTRY_NUM_MAX INT_MAX #define EFICONFIG_VOLUME_PATH_MAX 512 #define EFICONFIG_FILE_PATH_MAX 512 #define EFICONFIG_FILE_PATH_BUF_SIZE (EFICONFIG_FILE_PATH_MAX * sizeof(u16)) From 15436faa46a9958b019aea22d24bc52eb1da15ff Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 24 Jan 2023 20:36:45 +0100 Subject: [PATCH 29/29] efi_loader: don't use HandleProtocol HandleProtocol() is deprecrated. According to the UEFI specification it should be implemented as a call to OpenProtocolInterface() with a hard coded agent handle. This implies that we would have to call CloseProtocolInterfaces() after usage with the same handle. Getting rid of an EFI_CALL() is also appreciated. Signed-off-by: Heinrich Schuchardt Acked-by: Ilias Apalodimas --- lib/efi_loader/efi_boottime.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index e65ca6a4cbe..ba28989f36a 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -1949,6 +1949,7 @@ efi_status_t efi_load_image_from_path(bool boot_policy, efi_uintn_t buffer_size; uint64_t addr, pages; const efi_guid_t *guid; + struct efi_handler *handler; /* In case of failure nothing is returned */ *buffer = NULL; @@ -1970,11 +1971,11 @@ efi_status_t efi_load_image_from_path(bool boot_policy, } if (ret != EFI_SUCCESS) return EFI_NOT_FOUND; - ret = EFI_CALL(efi_handle_protocol(device, guid, - (void **)&load_file_protocol)); + ret = efi_search_protocol(device, guid, &handler); if (ret != EFI_SUCCESS) return EFI_NOT_FOUND; buffer_size = 0; + load_file_protocol = handler->protocol_interface; ret = EFI_CALL(load_file_protocol->load_file( load_file_protocol, rem, boot_policy, &buffer_size, NULL));