aboutsummaryrefslogtreecommitdiff
path: root/common
AgeCommit message (Collapse)Author
2024-02-29Merge patch series "Handoff bloblist from previous boot stage"Tom Rini
Raymond Mao <raymond.mao@linaro.org> says: This patch set adds/adapts a few bloblist APIs and implements Arm arch custom function to retrieve the bloblist (aka. Transfer List) from previous loader via boot arguments when BLOBLIST option is enabled and all boot arguments are compliant to the register conventions defined in the Firmware Handoff spec v0.9. If an arch wishes to have different behaviors for loading bloblist from the previous boot stage, it is required to implement the custom function xferlist_from_boot_arg().
2024-02-29bloblist: Load the bloblist from the previous loaderRaymond Mao
During bloblist initialization, load the bloblist via boot arguments from the previous loader. If a valid bloblist exists in boot arguments, relocate it into the fixed bloblist memory region. If not, fallback to support BLOBLIST_ADDR or BLOBLIST_ALLOC. Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
2024-02-29bloblist: refactor of bloblist_reloc()Raymond Mao
The current bloblist pointer and size can be retrieved from global data, so we don't need to pass them from the function arguments. This change also help to remove all external access of gd->bloblist outside of bloblist module. Signed-off-by: Raymond Mao <raymond.mao@linaro.org> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-02-29bloblist: check bloblist with specified buffer sizeRaymond Mao
Instead of expecting the bloblist total size to be the same as the pre-allocated buffer size, practically we are more interested in whether the pre-allocated buffer size is bigger than the bloblist total size. Signed-off-by: Raymond Mao <raymond.mao@linaro.org> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-02-29bloblist: add API to check the register conventionsRaymond Mao
Add bloblist_check_reg_conv() to check whether the bloblist is compliant to the register conventions defined in Firmware Handoff specification. This API can be used for all Arm platforms. Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
2024-02-19common: usb-hub: Reset USB 3.0 hubs onlyShantur Rathore
Additional testing of the changes introduced in commit 33e06dcbe57a "common: usb-hub: Reset hub port before scanning") revealed that some USB 2.0 and 3.0 flash drives didn't work in U-Boot on some Allwinner SoCs that support USB 2.0 interfaces only. More precisely, some of the tested USB 2.0 and 3.0 flash drives failed to be detected and work on an OrangePi Zero 3, based on the Allwinner H616 SoC that supports USB 2.0 only, while the same USB flash drives worked just fine on a Pine64 H64, based on the Allwinner H6 SoC that supports both USB 2.0 and USB 3.0 interfaces. The USB ID of the above-mentioned USB 3.0 flash drive that failed to work is 1f75:0917 (Innostor Technology Corporation IS917 Mass storage), it is 32 GB in size and sold under the PNY brand. The mentioned USB 2.0 drive is some inexpensive no-name drive with an invalid USB ID. Resetting USB 3.0 hubs only, which this patch introduces to the USB hub resets, has been tested to work as expected, resolving the identified issues on the Allwinner H616, while not introducing any new issues on other tested Allwinner SoCs. Thus, let's fix it that way. According to the USB 3.0 specification, resetting a USB 3.0 port is required when an attached USB device transitions between different states, such as when it resumes from suspend. Though, the Linux kernel performs additional USB 3.0 port resets upon initial USB device attachment, as visible in commit 07194ab7be63 ("USB: Reset USB 3.0 devices on (re)discovery") in the kernel source, to ensure proper state of the USB 3.0 hub port and proper USB mode negotiation during the initial USB device attachment and enumeration. These additional types of USB port resets don't exist for USB 2.0 hubs, according the USB 2.0 specification. The resets seem to be added to the USB 3.0 specification as part of the port and device mode negotiation. The Linux kernel resets USB 3.0 (i.e. SuperSpeed) hubs only, as visible in commit 10d674a82e55 ("USB: When hot reset for USB3 fails, try warm reset.") in the kernel source. The check for SuperSpeed hubs is performed in a way that also applies to newer SuperSpeed Plus (USB 3.1 or 3.2) hubs as well, which hopefully makes it future proof. Fixes: 33e06dcbe57a ("common: usb-hub: Reset hub port before scanning") Link: https://lore.kernel.org/u-boot/20240207102327.35125-1-i@shantur.com/T/#u Link: https://lore.kernel.org/u-boot/20240201164604.13315fa6@donnerap.manchester.arm.com/T/#u Signed-off-by: Shantur Rathore <i@shantur.com> Helped-by: Dragan Simic <dsimic@manjaro.org> Tested-by: Andre Przywara <andre.przywara@arm.com> Reviewed-by: Dragan Simic <dsimic@manjaro.org> Reviewed-by: Marek Vasut <marex@denx.de>
2024-02-15common: avb_verify: add str_avb_io_error/str_avb_slot_errorIgor Opaniuk
Introduce str_avb_io_error() and str_avb_slot_error() functions, that provide a pointer to AVB runtime error message. Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> Signed-off-by: Igor Opaniuk <igor.opaniuk@gmail.com> Link: https://lore.kernel.org/r/20240209192045.3961832-6-igor.opaniuk@foundries.io Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2024-02-15common: avb_verify: rework error/debug printsIgor Opaniuk
Make error prints more verbose with additional context. Also s/print/debug/g for prints, which might be relevant only for debugging purposes. Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> Signed-off-by: Igor Opaniuk <igor.opaniuk@gmail.com> Link: https://lore.kernel.org/r/20240209192045.3961832-4-igor.opaniuk@foundries.io Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2024-02-15avb: move SPDX license identifiers to the first lineIgor Opaniuk
Move SPDX license identifiers to the first line, so it conforms to license placement rule [1]: Placement: The SPDX license identifier in kernel files shall be added at the first possible line in a file which can contain a comment. For the majority of files this is the first line, except for scripts which require the '#!PATH_TO_INTERPRETER' in the first line. For those scripts the SPDX identifier goes into the second line. [1] https://www.kernel.org/doc/Documentation/process/license-rules.rst Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> Signed-off-by: Igor Opaniuk <igor.opaniuk@gmail.com> Link: https://lore.kernel.org/r/20240209192045.3961832-3-igor.opaniuk@foundries.io Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2024-02-15common: avb_verify: don't call mmc_switch_part for SDIgor Opaniuk
mmc_switch_part() is used for switching between hw partitions on eMMC (boot0, boot1, user, rpmb). There is no need to do that for SD card. This fixes the avb command usage on SD cards. Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> Signed-off-by: Igor Opaniuk <igor.opaniuk@gmail.com> Reviewed-by: Dragan Simic <dsimic@manjaro.org> Link: https://lore.kernel.org/r/20240209192045.3961832-2-igor.opaniuk@foundries.io Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2024-02-13boot: add support for button commandsCaleb Connolly
With the relatively new button API in U-Boot, it's now much easier to model the common usecase of mapping arbitrary actions to different buttons during boot - for example entering fastboot mode, setting some additional kernel cmdline arguments, or booting with a custom recovery ramdisk, to name a few. Historically, this functionality has been implemented in board code, making it fixed for a given U-Boot binary and requiring the code be duplicated and modified for every board. Implement a generic abstraction to run an arbitrary command during boot when a specific button is pressed. The button -> command mapping is configured via environment variables with the following format: button_cmd_N_name=<button label> button_cmd_N=<command to run> Where N is the mapping number starting from 0. For example: button_cmd_0_name=vol_down button_cmd_0=fastboot usb 0 This will cause the device to enter fastboot mode if volume down is held during boot. After we enter the cli loop the button commands are no longer valid, this allows the buttons to additionally be used for navigating a boot menu. Tested-by: Svyatoslav Ryhel <clamor95@gmail.com> # Tegra30 Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
2024-02-07Merge branch '2024-02-06-assorted-fixes'Tom Rini
A number of assorted fixes
2024-02-06common: event: check event_type_name() argumentHeinrich Schuchardt
In event_type_name() we should avoid possible buffer overruns by checking the type argument. Addresses-Coverity-ID: 478862 Out-of-bounds access Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2024-02-04spl: Make SPL_STACK available for ROCKCHIP_RK3036 without spl frameworkKever Yang
rk3036 soc has limit internal sram, and not able to support spl framework. Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
2024-01-31spl: riscv: falcon: move fdt blob to specified addressRandolph
In Falcon Boot mode, the fdt blob should be move to the RAM from kernel BSS section. To avoid being cleared by BSS initialisation. SPL_PAYLOAD_ARGS_ADDR is the address where SPL copies. Signed-off-by: Randolph <randolph@andestech.com> Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
2024-01-29common: splash_source: Don't compile ubifs splash cmd for SPL buildDevarsh Thakkar
Don't compile ubifs splash mount command for SPL build as this command is not supported (and also not enabled) during SPL stage. This fixes below compilation error, when CONFIG_CMD_UBIFS is enabled in defconfig along with splash screen enabled at SPL stage: "aarch64-none-linux-gnu-ld.bfd: common/cli.o: in function `run_command': u-boot-next/u-boot/common/cli.c:51: undefined reference to `parse_string_outer' u-boot-next/u-boot/common/cli.c:51:(.text.run_command+0x10): relocation truncated to fit: R_AARCH64_JUMP26 against undefined symbol `parse_string_outer' make[2]: *** [u-boot-next/u-boot/scripts/Makefile.spl:527: spl/u-boot-spl] Error 1 make[1]: *** [u-boot-next/u-boot/Makefile:2053: spl/u-boot-spl] Error 2 make[1]: Leaving directory 'u-boot-next/u-boot/out/a53' make: *** [Makefile:177: sub-make] Error 2" Fixes: eb9217dc03 ("common: Enable splash functions at SPL") Signed-off-by: Devarsh Thakkar <devarsht@ti.com> Reviewed-by: Nikhil M Jain <n-jain1@ti.com>
2024-01-29Merge patch series "Move framebuffer reservation for SPL to RAM end"Tom Rini
Devarsh Thakkar <devarsht@ti.com> says: Move video memory reservation for SPL at end of RAM so that it does not interefere with reservations for next stage so that the next stage need not have holes in between for passed regions and instead it can maintain continuity in reservations. Also catch the bloblist before starting reservations to avoid the same problem. While at it, also fill missing fields in video handoff struct before passing it to next stage. This is as per discussions at : For moving SPL framebuffer reservation at end of RAM: https://lore.kernel.org/all/CAPnjgZ3xSoe_G3yrqwuAvoiVjUfZ+YQgkOR0ZTVXGT9VK8TwJg@mail.gmail.com/ For filling missing video handoff fields : https://lore.kernel.org/all/CAPnjgZ1Hs0rNf0JDirp6YPsOQ5=QqQSP9g9qRwLoOASUV8a4cw@mail.gmail.com/
2024-01-29video: Skip framebuffer reservation if already reservedDevarsh Thakkar
Skip framebufer reservation if it was already reserved from previous stage and whose information was passed using a bloblist. Return error in case framebuffer information received from bloblist is invalid i.e NULL or empty. While at it, improve the debug message to make it more clear that address in discussion is of framebuffer and not bloblist and also match it with printing scheme followed in video_reserve function. Signed-off-by: Devarsh Thakkar <devarsht@ti.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2024-01-29common/board_f: Catch bloblist before starting reservationsDevarsh Thakkar
Start reservations needed for init sequence only after catching bloblists from previous stage. This is to avoid catching bloblists in the middle causing gaps while u-boot is reserving. Adjust the relocaddr as per video hand-off information received from previous stage so that further reservations start only after regions reserved for previous stages Skip reservation for video memory if it was already filled by a bloblist. Signed-off-by: Devarsh Thakkar <devarsht@ti.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2024-01-29spl: Enforce framebuffer reservation from end of RAMDevarsh Thakkar
Add an API which enforces framebuffer reservation from end of RAM. This is done so that next stage can directly skip this region before carrying out further reservations. Signed-off-by: Devarsh Thakkar <devarsht@ti.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2024-01-29sunxi: Consider SPL size limitations for FIT loadingSamuel Holland
Now that 32-bit SoCs can load U-Boot proper (and possibly other firmware) from a FIT, people can use that by enabling CONFIG_SPL_LOAD_FIT. However SPL_FIT_IMAGE_TINY is required to stay within the 24 or 32 KiB SPL size limit on early SoCs; for consistency, enable it everywhere. Signed-off-by: Samuel Holland <samuel@sholland.org> [Andre: drop unconditional FIT image enablement for all SoCs] Reviewed-by: Andre Przywara <andre.przywara@arm.com>
2024-01-29sunxi: spl: Disable padding from SPL_PAD_TOSamuel Holland
Starting with H6, Allwinner removed the artificial 32 KiB SPL size limit from the boot ROM. Now SPL size is only limited by the available SRAM. This limit ranges from 152 KiB on H6 to a whopping 2052 KiB on R329. To take advantage of this additional space, we must increase SPL_MAX_SIZE. Since we do not want to unnecessarily pad SPL out to these giant sizes, we must set SPL_PAD_TO to zero. This causes no problems because binman already takes care of appending the SPL payload at the right offset. Signed-off-by: Samuel Holland <samuel@sholland.org> Reviewed-by: Andre Przywara <andre.przywara@arm.com>
2024-01-24common: console: Fix print complete stdio device listPatrice Chotard
In case CONSOLE_MUX and SYS_CONSOLE_IS_IN_ENV are on and stdin or stdout or stderr are missing in environment, as fallback, get these either from stdio_devices[std] or stdio_devices[std]->name. Fixes: 6b343ab38d ("console: Print out complete stdio device list") Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
2024-01-22common: usb-hub: Reset hub port before scanningShantur Rathore
Currently when a hub is turned on, all the ports are powered on. This works well for hubs which have individual power control. For the hubs without individual power control this has no effect. Mostly in these scenarios the hub port is powered before the USB controller is enabled, this can lead to some devices in unexpected state. With this patch, we explicitly reset the port while powering up hub This resets the port for hubs without port power control and has no effect on hubs with port power control as the port is still off. Before this patch AMicro AM8180 based NVME to USB adapter won't be detected as a USB3.0 Mass Storage device but with this it works as expected. Tested working after this patch: 1. AMicro AM8180 based NVME to USB Adapter 2. Kingston DataTraveler 3.0 3. GenesysLogic USB3.0 Hub The drives were tested while connected directly and via the hub. Signed-off-by: Shantur Rathore <i@shantur.com> Reviewed-by: Marek Vasut <marex@denx.de>
2024-01-18getchar(): Correct usageTom Rini
The function getchar() returns an 'int' and not a 'char'. Coverity notes that "Assigning the return value of getchar to char ... truncates its value." and so for the most part we can resolve this easily by using 'int' as intended, and often used throughout the codebase. A few places are not so simple and would require further re-architecting of the code in order to change this, so we leave them be. Signed-off-by: Tom Rini <trini@konsulko.com>
2024-01-16cmd/command.c: relax length check in cmd_get_data_size()Rasmus Villemoes
Just check that the length is at least 2. This allows passing strings like ".b", which can be convenient when constructing tests (i.e. parametrizing the suffix used). Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
2024-01-16cmd/command.c: constify "arg" argument of cmd_get_data_size()Rasmus Villemoes
This function obviously does not and must not modify "arg". Change the prototype to allow passing an argument of type "const char*" without requiring a cast. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
2024-01-09lib: membuff: fix readline not returning line in case of overflowIon Agorria
If line overflows readline it will not be returned, fix this behavior, make it optional and documented properly. Signed-off-by: Ion Agorria <ion@agorria.com> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com> Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> Reviewed-by: Simon Glass <sjg@chromium.org> Link: https://lore.kernel.org/r/20240105072212.6615-6-clamor95@gmail.com Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2024-01-09common: console: record console from the beginningIon Agorria
Set flag to enable console record on console_record_init and not only on console_record_reset_enable. This fixes missing start of U-Boot log for fastboot oem console command. Signed-off-by: Ion Agorria <ion@agorria.com> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com> Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> Link: https://lore.kernel.org/r/20240105072212.6615-5-clamor95@gmail.com Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2024-01-09common: console: introduce console_record_isempty helperIon Agorria
Add console_record_isempty to check if console record buffer contains any data. Signed-off-by: Ion Agorria <ion@agorria.com> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com> Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> Link: https://lore.kernel.org/r/20240105072212.6615-4-clamor95@gmail.com Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
2024-01-08spl: binman: Disable u_boot_any symbols for i.MX93 boardsMathieu Othacehe
This is extending commit 6516c9b349b3 ("spl: binman: Disable u_boot_any symbols for i.MX8M boards") to i.MX93 boards. Signed-off-by: Mathieu Othacehe <m.othacehe@gmail.com>
2023-12-31bloblist: Add alignment to bloblist_new()Simon Glass
Allow the alignment to be specified when creating a bloblist. Signed-off-by: Simon Glass <sjg@chromium.org> Co-developed-by: Raymond Mao <raymond.mao@linaro.org> Signed-off-by: Raymond Mao <raymond.mao@linaro.org> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2023-12-31bloblist: Adjust the bloblist headerSimon Glass
The v0.9 spec provides for a 24-byte header. Update the implementation to match this. Rename the fields of the bloblist header to align to the spec. Adds an alignment field into the bloblist header. Update the related bloblist APIs and UT testcases. Signed-off-by: Simon Glass <sjg@chromium.org> Co-developed-by: Raymond Mao <raymond.mao@linaro.org> Signed-off-by: Raymond Mao <raymond.mao@linaro.org> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2023-12-31bloblist: Reduce blob-header sizeSimon Glass
The v0.9 spec provides for an 8-byte header for each blob, with fewer fields. The blob data start address should be aligned to the alignment specified by the bloblist header. Update the implementation to match this. Signed-off-by: Simon Glass <sjg@chromium.org> Co-developed-by: Raymond Mao <raymond.mao@linaro.org> Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
2023-12-31bloblist: Handle alignment with a void entrySimon Glass
Rather than setting the alignment using the header size, add an entirely new entry to cover the gap left by the alignment. Signed-off-by: Simon Glass <sjg@chromium.org> Co-developed-by: Raymond Mao <raymond.mao@linaro.org> Signed-off-by: Raymond Mao <raymond.mao@linaro.org> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2023-12-31bloblist: Checksum the entire bloblistSimon Glass
Use a sinple 8-bit checksum for bloblist, as specified by the spec version 0.9. Spec v0.9 specifies that the entire bloblist area is checksummed, including unused portions. Update the code to follow this. Signed-off-by: Simon Glass <sjg@chromium.org> Co-developed-by: Raymond Mao <raymond.mao@linaro.org> Signed-off-by: Raymond Mao <raymond.mao@linaro.org> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2023-12-31bloblist: Drop spare value from bloblist recordSimon Glass
Drop spare value from bloblist record header. For now it is still present in the header, with an underscore, so that tests continue to pass. Signed-off-by: Simon Glass <sjg@chromium.org> Co-developed-by: Raymond Mao <raymond.mao@linaro.org> Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
2023-12-31bloblist: Access record hdr_size and tag via a functionSimon Glass
Convert accesses to tag and hdr_size via function for grouping tag and hdr_size together later. Signed-off-by: Simon Glass <sjg@chromium.org> Co-developed-by: Raymond Mao <raymond.mao@linaro.org> Signed-off-by: Raymond Mao <raymond.mao@linaro.org> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2023-12-31bloblist: Adjust API to align in powers of 2Simon Glass
The updated bloblist structure stores the alignment as a power-of-two value in its structures. Adjust the API to use this, to avoid needing to calling ilog2(). Update the bloblist alignment from 16 bytes to 8 bytes. Drop a stale comment while we are here. Signed-off-by: Simon Glass <sjg@chromium.org> Co-developed-by: Raymond Mao <raymond.mao@linaro.org> Signed-off-by: Raymond Mao <raymond.mao@linaro.org> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2023-12-31bloblist: Update the tag numberingSimon Glass
Align bloblist tags with the FW handoff spec v0.9. The most common ones are from 0. TF related ones are from 0x100. All non-standard ones from 0xfff000. Added new defined tags: BLOBLISTT_OPTEE_PAGABLE_PART for TF. BLOBLISTT_TPM_EVLOG and BLOBLISTT_TPM_CRB_BASE for TPM. Signed-off-by: Simon Glass <sjg@chromium.org> Co-developed-by: Raymond Mao <raymond.mao@linaro.org> Signed-off-by: Raymond Mao <raymond.mao@linaro.org> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2023-12-28Merge patch series "Modernize U-Boot shell"Tom Rini
Francis Laniel <francis.laniel@amarulasolutions.com> says: During 2021 summer, Sean Anderson wrote a contribution to add a new shell, based on LIL, to U-Boot [1, 2]. While one of the goals of this contribution was to address the fact actual U-Boot shell, which is based on Busybox hush, is old there was a discussion about adding a new shell versus updating the actual one [3, 4]. So, in this series, with Harald Seiler, we updated the actual U-Boot shell to reflect what is currently in Busybox source code. Basically, this contribution is about taking a snapshot of Busybox shell/hush.c file (as it exists in commit 37460f5da) and adapt it to suit U-Boot needs. This contribution was written to be as backward-compatible as possible to avoid breaking the existing. So, the modern hush flavor offers the same as the actual, that is to say: 1. Variable expansion. 2. Instruction lists (;, && and ||). 3. If, then and else. 4. Loops (for, while and until). No new features offered by Busybox hush were implemented (e.g. functions). It is possible to change the parser at runtime using the "cli" command: => cli print old => cli set modern => cli print modern => cli set old The default parser is the old one. Note that to use both parser, you would need to set both CONFIG_HUSH_MODERN_PARSER and CONFIG_HUSH_OLD_PARSER. In terms of testing, new unit tests were added to ut to ensure the new behavior is the same as the old one and it does not add regression. Nonetheless, if old behavior was buggy and fixed upstream, the fix is then added to U-Boot [5]. In sandbox, all of these tests pass smoothly: => printenv board board=sandbox => ut hush Running 20 hush tests ... Failures: 0 => cli set modern => ut hush Running 20 hush tests ... Failures: 0 Thanks to the effort of Harald Seiler, I was successful booting a board: => printenv fdtfile fdtfile=amlogic/meson-gxl-s905x-libretech-cc.dtb => cli get old => boot ... root@lepotato:~# root@lepotato:~# reboot ... => cli set modern => cli get modern => printenv fdtfile fdtfile=amlogic/meson-gxl-s905x-libretech-cc.dtb => boot ... root@lepotato:~# This contribution indeed adds a lot of code and there were concern about its size [6, 7]. With regard to the amount of code added, the cli_hush_upstream.c is 13030 lines long but it seems a smaller subset is really used: gcc -D__U_BOOT__ -E common/cli_hush_upstream.c | wc -l 2870 Despite this, it is better to still have the whole upstream code for the sake of easing maintenance. With regard to memory size, I conducted some experiments for version 8 of this series and for a subset of arm64 boards and found the worst case to be 4K [8]. Tom Rini conducted more research on this and also found the increase to be acceptable [9]. If you want to review it - your review will really be appreciated - here are some information regarding the commits: * commits marked as "test:" deal with unit tests. * commit "cli: Add Busybox upstream hush.c file." copies Busybox shell/hush.c into U-Boot tree, this explain why this commit contains around 12000 additions. * commit "cli: Port Busybox 2021 hush to U-Boot." modifies previously added file to permit us to use this as new shell. The really good idea of #include'ing Busybox code into a wrapper file to define some particular functions while minimizing modifications to upstream code comes from Harald Seiler. * commit "cmd: Add new parser command" adds a new command which permits selecting parser at runtime. I am not really satisfied with the fact it calls cli_init() and cli_loop() each time the parser is set, so your reviews would be welcomed. * Other commits focus on enabling features we need (e.g. if).
2023-12-28cli: modern_hush: Add upstream commits up to 2nd October 2023.Francis Laniel
This commit adds the following hush busybox upstream commits: 791b222dd55d ("sleep: fix "sleep -- ARGS"") 5353df91cba7 ("Update applet size estimates") e41e481fd571 ("hush: fix a compile failure") 07a95cfcabb0 ("ash: disable check for "good" function name, bash does not check this") e5692e2342c6 ("hush: quote values in "readonly" output") 96769486e20f ("shell: move varcmp() to shell_common.h and use it in hush") bab8828b0dad ("hush: fix expansion of space in "a=${a:+$a }c" construct") b5be8da350b5 ("hush: make "false" built-in") 6824298ab4d3 ("hush: fix ELIF cmd1;cmd2 THEN ... not executing cmd2, closes 15571") 3a7f00eadcf4 ("hush: add comment about abort on syntax error %{^}") acae889dd972 ("ash,hush: tab completion of functions and aliases") 90b607d79a13 ("hush: quote variable values printed by "set" (match ash behavior)") 6748e6494c22 ("hush (NOMMU): fix LINENO in execed children") fd5fb2d2b596 ("hush: speed up "big heredoc" code") 1409432d072e ("hush: add TODO comment") 93ae7464e6e4 ("hush: restore SIGHUP handling, this time explain why we do what we do") 1fdb33bd07e5 ("hush: restore tty pgrp on SIGHUP") 6101b6d3eaa0 ("hush: remove special handling of SIGHUP") 93e0898c663a ("shell: fix SIGWINCH and SIGCHLD (in hush) interrupting line input, closes 15256") 969e00816835 ("hush: code shrink") 27be0e8cfeb6 ("shell: fix compile failures in some configs") 7d1c7d833785 ("ash,hush: use HOME for tab completion and prompts") 21afddefd258 ("hush: fix "error: invalid preprocessing directive ##"") e53c7dbafc78 ("hush: fix set -n to act immediately, not just after run_list()") 574b9c446da1 ("hush: fix var_LINENO3.tests failure") 49bcf9f40cff ("hush: speed up ${x//\*/|} too") 53b2fdcdba4c ("*: add NOINLINEs where code noticeably shrinks") 7c3e96d4b3d4 ("shell: use more compact SHELL_ASH / HUSH config defines. no code changes") 62f1eed1e191 ("hush: in a comment, document what -i might be doing") aaf3d5ba74c5 ("shell: tweak --help") db5546ca1018 ("libbb: code shrink: introduce and use [_]exit_SUCCESS()") 931c55f9e2b4 ("libbb: invert the meaning of SETUP_ENV_NO_CHDIR -> SETUP_ENV_CHDIR") 12566e7f9b5e ("ash,hush: fix handling of SIGINT while waiting for interactive input") 987be932ed3c ("*: slap on a few ALIGN_PTR where appropriate") Signed-off-by: Francis Laniel <francis.laniel@amarulasolutions.com>
2023-12-28cli: hush_modern: Enable loopsFrancis Laniel
Enables the use of for, while and until loops for command line as well as with run_command(). Signed-off-by: Francis Laniel <francis.laniel@amarulasolutions.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2023-12-28cli: hush_modern: Enable if keywordFrancis Laniel
Adds support for "if then else" construct both for command line interface and through run_command(). Signed-off-by: Francis Laniel <francis.laniel@amarulasolutions.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2023-12-28cli: hush_modern: Enable using < and > as string compare operatorsFrancis Laniel
In Busybox hush, '<' and '>' are used as redirection operators. For example, cat foo > bar will write content of file foo inside file bar. In U-Boot, we do not have file system, so we can hardly redirect command output inside a file. But, in actual U-Boot hush, these operators ('<' and '>') are used as string compare operators. For example, test aaa < bbb returns 0 as aaa is before bbb in the dictionary. Busybox hush also permits this, but operators need to be escaped ('\<' and '\>'). Indeed, if escaping is needed it permits the developer to think about its code, as in a lot of case, we want to compare integers (using '-lt' or '-gt') rather than strings. As testing in U-Boot is handled by the test command, we will stick with the original behaviour and not adapt to Busybox one. Nonetheless, if one day we decide to implement test with '[[ ]]', we will then stick to upstream Busybox behavior. Signed-off-by: Francis Laniel <francis.laniel@amarulasolutions.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2023-12-28cli: add modern hush as parser for run_command*()Francis Laniel
Enables using, in code, modern hush as parser for run_command function family. It also enables the command run to be used by CLI user of modern hush. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Francis Laniel <francis.laniel@amarulasolutions.com>
2023-12-28cli: hush_modern: Add functions to be called from run_command()Francis Laniel
run_command() is called internally by the command run and it can also be called directly from U-Boot code, e.g. to do unit tests. This commit adds this path to go to modern hush. Signed-off-by: Francis Laniel <francis.laniel@amarulasolutions.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2023-12-28cli: hush_modern: Enable variables expansion for modern hushFrancis Laniel
Enables variables expansion for modern hush, both for local and environment variables. So the following commands: foo=bar echo $foo setenv bar foo echo $bar leads to "bar" and "foo" being printed on console output. Signed-off-by: Francis Laniel <francis.laniel@amarulasolutions.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2023-12-28cli: Enables using modern hush parser as command line parserFrancis Laniel
If one defines HUSH_MODERN_PARSER, it is then possible to use modern parser with: => cli get old => cli set modern => cli get modern Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Francis Laniel <francis.laniel@amarulasolutions.com>
2023-12-28cmd: Add new cli commandFrancis Laniel
This command can be used to print the current parser with 'cli get'. It can also be used to set the current parser with 'cli set'. For the moment, only one value is valid for set: old. Signed-off-by: Francis Laniel <francis.laniel@amarulasolutions.com>