From 4001e5ab9b9bd4735798477531c68cdf26951d7c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 1 Oct 2023 19:15:12 -0600 Subject: test: Add a new suite for commands Add a new suite for 'cmd' tests, used for testing commands. These are kept in the test/cmd directory. For now it is empty, but it will be used for coreboot-command tests. Signed-off-by: Simon Glass --- include/test/cmd.h | 15 +++++++++++++++ include/test/suites.h | 1 + 2 files changed, 16 insertions(+) create mode 100644 include/test/cmd.h (limited to 'include') diff --git a/include/test/cmd.h b/include/test/cmd.h new file mode 100644 index 00000000000..c200570e423 --- /dev/null +++ b/include/test/cmd.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright 2023 Google LLC + * Written by Simon Glass + */ + +#ifndef __TEST_CMD_H__ +#define __TEST_CMD_H__ + +#include + +/* Declare a new command test */ +#define CMD_TEST(_name, _flags) UNIT_TEST(_name, _flags, cmd_test) + +#endif /* __TEST_CMD_H__ */ diff --git a/include/test/suites.h b/include/test/suites.h index ad4fc926f48..49224d8ea2e 100644 --- a/include/test/suites.h +++ b/include/test/suites.h @@ -34,6 +34,7 @@ int do_ut_bootstd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_bloblist(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); +int do_ut_cmd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_common(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_compression(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); -- cgit v1.3.1 From 30a75e77946b8b2f4ed26e207bba3e4828629fee Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 1 Oct 2023 19:15:13 -0600 Subject: test: Add helper to skip to partial console line Sometimes we need to skip to a line but it includes addresses or other information which can vary depending on the runtime conditions. Add a new ut_assert_skip_to_linen() which is similar to the existing ut_assert_skip_to_line() function but only checks that the console line matches up to the length of the provided string. Signed-off-by: Simon Glass --- include/test/ut.h | 30 ++++++++++++++++++++++++++++++ test/ut.c | 27 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) (limited to 'include') diff --git a/include/test/ut.h b/include/test/ut.h index ea6ee95d734..d3172af8083 100644 --- a/include/test/ut.h +++ b/include/test/ut.h @@ -97,6 +97,23 @@ int ut_check_skipline(struct unit_test_state *uts); */ int ut_check_skip_to_line(struct unit_test_state *uts, const char *fmt, ...); +/** + * ut_check_skip_to_linen() - skip output until a partial line is found + * + * This creates a string and then checks it against the following lines of + * console output obtained with console_record_readline() until it is found. + * Only the characters up to the length of the string are checked, so the line + * may extend further + * + * After the function returns, uts->expect_str holds the expected string and + * uts->actual_str holds the actual string read from the console. + * + * @uts: Test state + * @fmt: printf() format string to look for, followed by args + * Return: 0 if OK, -ENOENT if not found, other value on error + */ +int ut_check_skip_to_linen(struct unit_test_state *uts, const char *fmt, ...); + /** * ut_check_console_end() - Check there is no more console output * @@ -359,6 +376,19 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes); __ret; \ }) +/* Assert that a following console output line matches */ +#define ut_assert_skip_to_linen(fmt, args...) ({ \ + int __ret = 0; \ + \ + if (ut_check_skip_to_linen(uts, fmt, ##args)) { \ + ut_failf(uts, __FILE__, __LINE__, __func__, \ + "console", "\nExpected '%s',\n got to '%s'", \ + uts->expect_str, uts->actual_str); \ + return CMD_RET_FAILURE; \ + } \ + __ret; \ +}) + /* Assert that there is no more console output */ #define ut_assert_console_end() ({ \ int __ret = 0; \ diff --git a/test/ut.c b/test/ut.c index 28da417686e..628e9dc9805 100644 --- a/test/ut.c +++ b/test/ut.c @@ -121,6 +121,33 @@ int ut_check_skipline(struct unit_test_state *uts) return 0; } +int ut_check_skip_to_linen(struct unit_test_state *uts, const char *fmt, ...) +{ + va_list args; + int len; + int ret; + + va_start(args, fmt); + len = vsnprintf(uts->expect_str, sizeof(uts->expect_str), fmt, args); + va_end(args); + if (len >= sizeof(uts->expect_str)) { + ut_fail(uts, __FILE__, __LINE__, __func__, + "unit_test_state->expect_str too small"); + return -EOVERFLOW; + } + while (1) { + if (!console_record_avail()) + return -ENOENT; + ret = readline_check(uts); + if (ret < 0) + return ret; + + if (!strncmp(uts->expect_str, uts->actual_str, + strlen(uts->expect_str))) + return 0; + } +} + int ut_check_skip_to_line(struct unit_test_state *uts, const char *fmt, ...) { va_list args; -- cgit v1.3.1 From cde03fa23e2fa47707ef81b9a91b1f4b631adbb7 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 1 Oct 2023 19:15:23 -0600 Subject: video: Add a function to clear the display Move the code from the 'cls' command into the console file, so it can be called from elsewhere. Signed-off-by: Simon Glass --- cmd/cls.c | 25 +++---------------------- common/console.c | 31 +++++++++++++++++++++++++++++++ include/console.h | 10 ++++++++++ 3 files changed, 44 insertions(+), 22 deletions(-) (limited to 'include') diff --git a/cmd/cls.c b/cmd/cls.c index 1125a3f81bb..80d0558d467 100644 --- a/cmd/cls.c +++ b/cmd/cls.c @@ -7,33 +7,14 @@ */ #include #include +#include #include -#include - -#define CSI "\x1b[" static int do_video_clear(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - __maybe_unused struct udevice *dev; - - /* - * Send clear screen and home - * - * FIXME(Heinrich Schuchardt ): This should go - * through an API and only be written to serial terminals, not video - * displays - */ - printf(CSI "2J" CSI "1;1H"); - if (IS_ENABLED(CONFIG_VIDEO_ANSI)) - return 0; - - if (IS_ENABLED(CONFIG_VIDEO)) { - if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev)) - return CMD_RET_FAILURE; - if (vidconsole_clear_and_reset(dev)) - return CMD_RET_FAILURE; - } + if (console_clear()) + return CMD_RET_FAILURE; return CMD_RET_SUCCESS; } diff --git a/common/console.c b/common/console.c index 98c3ee6ca6b..1ffda49c87e 100644 --- a/common/console.c +++ b/common/console.c @@ -19,12 +19,15 @@ #include #include #include +#include #include #include #include DECLARE_GLOBAL_DATA_PTR; +#define CSI "\x1b[" + static int on_console(const char *name, const char *value, enum env_op op, int flags) { @@ -1010,6 +1013,34 @@ int console_init_f(void) return 0; } +int console_clear(void) +{ + /* + * Send clear screen and home + * + * FIXME(Heinrich Schuchardt ): This should go + * through an API and only be written to serial terminals, not video + * displays + */ + printf(CSI "2J" CSI "1;1H"); + if (IS_ENABLED(CONFIG_VIDEO_ANSI)) + return 0; + + if (IS_ENABLED(CONFIG_VIDEO)) { + struct udevice *dev; + int ret; + + ret = uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev); + if (ret) + return ret; + ret = vidconsole_clear_and_reset(dev); + if (ret) + return ret; + } + + return 0; +} + static void stdio_print_current_devices(void) { char *stdinname, *stdoutname, *stderrname; diff --git a/include/console.h b/include/console.h index ceb733b5cb6..e29817e57b0 100644 --- a/include/console.h +++ b/include/console.h @@ -156,6 +156,16 @@ int console_announce_r(void); */ void console_puts_select_stderr(bool serial_only, const char *s); +/** + * console_clear() - Clear the console + * + * Uses an ANSI sequence to clear the display, failing back to clearing the + * video display directly if !CONFIG_VIDEO_ANSI + * + * Return: 0 if OK, -ve on error + */ +int console_clear(void); + /* * CONSOLE multiplexing. */ -- cgit v1.3.1 From c659ac7cca151be29712f37fc77dd18fb4ab96c5 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 9 Nov 2023 09:23:02 -0800 Subject: acpi: move acpi_get_rsdp_addr() to acpi/acpi_table.h Function acpi_get_rsdp_addr() is needed on all architectures which write ACPI tables. Move the definition from the x86 include to an architecture independent one. Signed-off-by: Heinrich Schuchardt Reviewed-by: Tom Rini Reviewed-by: Simon Glass --- arch/x86/include/asm/acpi_table.h | 9 --------- drivers/misc/qfw.c | 1 + include/acpi/acpi_table.h | 9 +++++++++ 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/arch/x86/include/asm/acpi_table.h b/arch/x86/include/asm/acpi_table.h index 226753b65d6..57e41654ce3 100644 --- a/arch/x86/include/asm/acpi_table.h +++ b/arch/x86/include/asm/acpi_table.h @@ -64,15 +64,6 @@ int acpi_write_dbg2_pci_uart(struct acpi_ctx *ctx, struct udevice *dev, */ int acpi_create_gnvs(struct acpi_global_nvs *gnvs); -/** - * acpi_get_rsdp_addr() - get ACPI RSDP table address - * - * This routine returns the ACPI RSDP table address in the system memory. - * - * @return: ACPI RSDP table address - */ -ulong acpi_get_rsdp_addr(void); - /** * arch_read_sci_irq_select() - Read the system-control interrupt number * diff --git a/drivers/misc/qfw.c b/drivers/misc/qfw.c index 7c01bf23d53..e3b6b4cd741 100644 --- a/drivers/misc/qfw.c +++ b/drivers/misc/qfw.c @@ -7,6 +7,7 @@ #define LOG_CATEGORY UCLASS_QFW #include +#include #include #include #include diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h index 1f85de091d3..a3b67259e64 100644 --- a/include/acpi/acpi_table.h +++ b/include/acpi/acpi_table.h @@ -920,6 +920,15 @@ void acpi_fill_header(struct acpi_table_header *header, char *signature); */ int acpi_fill_csrt(struct acpi_ctx *ctx); +/** + * acpi_get_rsdp_addr() - get ACPI RSDP table address + * + * This routine returns the ACPI RSDP table address in the system memory. + * + * @return: ACPI RSDP table address + */ +ulong acpi_get_rsdp_addr(void); + /** * write_acpi_tables() - Write out the ACPI tables * -- cgit v1.3.1 From 1de1a0348755ad5e57790a39059eceeb8e8aba42 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2023 08:27:44 -0700 Subject: boot: Drop size parameter from image_setup_libfdt() The of_size parameter is not used, so remove it. Signed-off-by: Simon Glass Reviewed-by: Tom Rini --- arch/mips/lib/bootm.c | 4 ++-- boot/image-board.c | 2 +- boot/image-fdt.c | 3 ++- cmd/bootefi.c | 2 +- include/image.h | 3 +-- lib/efi_loader/efi_dt_fixup.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index d6d2f7d9d03..f1cff691f4f 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -246,8 +246,8 @@ static int boot_setup_fdt(struct bootm_headers *images) { images->initrd_start = virt_to_phys((void *)images->initrd_start); images->initrd_end = virt_to_phys((void *)images->initrd_end); - return image_setup_libfdt(images, images->ft_addr, images->ft_len, - &images->lmb); + + return image_setup_libfdt(images, images->ft_addr, &images->lmb); } static void boot_prep_linux(struct bootm_headers *images) diff --git a/boot/image-board.c b/boot/image-board.c index bb0ca9d7f22..75f6906cd56 100644 --- a/boot/image-board.c +++ b/boot/image-board.c @@ -908,7 +908,7 @@ int image_setup_linux(struct bootm_headers *images) } if (CONFIG_IS_ENABLED(OF_LIBFDT) && of_size) { - ret = image_setup_libfdt(images, *of_flat_tree, of_size, lmb); + ret = image_setup_libfdt(images, *of_flat_tree, lmb); if (ret) return ret; } diff --git a/boot/image-fdt.c b/boot/image-fdt.c index 08fca08b710..07e50322325 100644 --- a/boot/image-fdt.c +++ b/boot/image-fdt.c @@ -575,12 +575,13 @@ __weak int arch_fixup_fdt(void *blob) } int image_setup_libfdt(struct bootm_headers *images, void *blob, - int of_size, struct lmb *lmb) + struct lmb *lmb) { ulong *initrd_start = &images->initrd_start; ulong *initrd_end = &images->initrd_end; int ret = -EPERM; int fdt_ret; + int of_size; if (fdt_root(blob) < 0) { printf("ERROR: root node setup failed\n"); diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 4d74969ad62..2ed29ad6bb8 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -309,7 +309,7 @@ efi_status_t efi_install_fdt(void *fdt) return EFI_OUT_OF_RESOURCES; } - if (image_setup_libfdt(&img, fdt, 0, NULL)) { + if (image_setup_libfdt(&img, fdt, NULL)) { log_err("ERROR: failed to process device tree\n"); return EFI_LOAD_ERROR; } diff --git a/include/image.h b/include/image.h index b89912a50f9..9f43518cef8 100644 --- a/include/image.h +++ b/include/image.h @@ -1028,12 +1028,11 @@ int image_decomp(int comp, ulong load, ulong image_start, int type, * * @images: Images information * @blob: FDT to update - * @of_size: Size of the FDT * @lmb: Points to logical memory block structure * Return: 0 if ok, <0 on failure */ int image_setup_libfdt(struct bootm_headers *images, void *blob, - int of_size, struct lmb *lmb); + struct lmb *lmb); /** * Set up the FDT to use for booting a kernel diff --git a/lib/efi_loader/efi_dt_fixup.c b/lib/efi_loader/efi_dt_fixup.c index 838023c78ff..a0c889cf986 100644 --- a/lib/efi_loader/efi_dt_fixup.c +++ b/lib/efi_loader/efi_dt_fixup.c @@ -173,7 +173,7 @@ efi_dt_fixup(struct efi_dt_fixup_protocol *this, void *dtb, } fdt_set_totalsize(dtb, *buffer_size); - if (image_setup_libfdt(&img, dtb, 0, NULL)) { + if (image_setup_libfdt(&img, dtb, NULL)) { log_err("failed to process device tree\n"); ret = EFI_INVALID_PARAMETER; goto out; -- cgit v1.3.1 From 451c1ab6b07b677ef10d36af5c63a7d764ea8ba2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2023 08:27:46 -0700 Subject: fdt: Improve the comment for fdt_shrink_to_minimum() Add a bit more detail about what this function does. Signed-off-by: Simon Glass --- boot/fdt_support.c | 1 - include/fdt_support.h | 12 +++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/boot/fdt_support.c b/boot/fdt_support.c index b15d07765fe..090d82ee80a 100644 --- a/boot/fdt_support.c +++ b/boot/fdt_support.c @@ -667,7 +667,6 @@ int fdt_record_loadable(void *blob, u32 index, const char *name, return node; } -/* Resize the fdt to its actual size + a bit of padding */ int fdt_shrink_to_minimum(void *blob, uint extrasize) { int i; diff --git a/include/fdt_support.h b/include/fdt_support.h index feda0d99740..0601f5f7dc8 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -232,13 +232,23 @@ int ft_system_setup(void *blob, struct bd_info *bd); void set_working_fdt_addr(ulong addr); /** - * shrink down the given blob to minimum size + some extrasize if required + * fdt_shrink_to_minimum() - shrink FDT while allowing for some margin + * + * Shrink down the given blob to 'minimum' size + some extrasize. + * + * The new size is enough to hold the existing contents plus @extrasize bytes, + * plus 5 memory reservations. Also, the end of the FDT is aligned to a 4KB + * boundary, so it might end up up to 4KB larger than needed. + * + * If there is an existing memory reservation for @blob in the FDT, it is + * updated for the new size. * * @param blob FDT blob to update * @param extrasize additional bytes needed * Return: 0 if ok, or -FDT_ERR_... on error */ int fdt_shrink_to_minimum(void *blob, uint extrasize); + int fdt_increase_size(void *fdt, int add_len); int fdt_delete_disabled_nodes(void *blob); -- cgit v1.3.1 From f2cbe6e43e18e9b65190c53cb4b92dd6699cb38b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 12 Nov 2023 08:27:48 -0700 Subject: boot: Move adding initrd earlier in image_setup_libfdt() This may as well happen before the general event is emitted, so move it. This will allow us to use the livetree for the event part, but the flattree for the earlier part. Signed-off-by: Simon Glass --- boot/image-fdt.c | 5 ++++- include/fdt_support.h | 12 +++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/boot/image-fdt.c b/boot/image-fdt.c index 6cdac6a556d..173ddb6e074 100644 --- a/boot/image-fdt.c +++ b/boot/image-fdt.c @@ -635,6 +635,10 @@ int image_setup_libfdt(struct bootm_headers *images, void *blob, goto err; } } + + if (fdt_initrd(blob, *initrd_start, *initrd_end)) + goto err; + if (!of_live_active() && CONFIG_IS_ENABLED(EVENT)) { struct event_ft_fixup fixup; @@ -664,7 +668,6 @@ int image_setup_libfdt(struct bootm_headers *images, void *blob, if (lmb) lmb_reserve(lmb, (ulong)blob, of_size); - fdt_initrd(blob, *initrd_start, *initrd_end); if (!ft_verify_fdt(blob)) goto err; diff --git a/include/fdt_support.h b/include/fdt_support.h index 0601f5f7dc8..25600d62f29 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -55,7 +55,17 @@ int fdt_chosen(void *fdt); /** * Add initrd information to the FDT before booting the OS. * - * @param fdt FDT address in memory + * Adds linux,initrd-start and linux,initrd-end properties to the /chosen node, + * creating it if necessary. + * + * A memory reservation for the ramdisk is added to the FDT, or an existing one + * (with matching @initrd_start) updated. + * + * If @initrd_start == @initrd_end this function does nothing and returns 0. + * + * @fdt: Pointer to FDT in memory + * @initrd_start: Start of ramdisk + * @initrd_end: End of ramdisk * Return: 0 if ok, or -FDT_ERR_... on error */ int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end); -- cgit v1.3.1 From bda020e762c4c391e4bf13fd73c093e757f92b3e Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 21 Nov 2023 15:41:27 +0100 Subject: acpi: fix struct acpi_xsdt The size of the ACPI table header is not a multiple of 8. We have to mark struct acpi_xsdt as packed to correctly access field Entry. Add a unit test for the offsets of field Entry in the RSDT and XSDT tables. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- include/acpi/acpi_table.h | 2 +- test/dm/acpi.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h index a3b67259e64..20ac3b51ba7 100644 --- a/include/acpi/acpi_table.h +++ b/include/acpi/acpi_table.h @@ -80,7 +80,7 @@ struct acpi_rsdt { }; /* XSDT (Extended System Description Table) */ -struct acpi_xsdt { +struct __packed acpi_xsdt { struct acpi_table_header header; u64 entry[MAX_ACPI_TABLES]; }; diff --git a/test/dm/acpi.c b/test/dm/acpi.c index 5236b3994e2..7e661ee1166 100644 --- a/test/dm/acpi.c +++ b/test/dm/acpi.c @@ -747,3 +747,13 @@ static int dm_test_acpi_find_table(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_acpi_find_table, 0); + +/* Test offsets in RSDT, XSDT */ +static int dm_test_acpi_offsets(struct unit_test_state *uts) +{ + ut_asserteq(36, offsetof(struct acpi_rsdt, entry)); + ut_asserteq(36, offsetof(struct acpi_xsdt, entry)); + + return 0; +} +DM_TEST(dm_test_acpi_offsets, 0); -- cgit v1.3.1