From 53fbaa4a4ae1dde1f83b2dda39ccf70a0b69373d Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 10 Jul 2022 15:40:22 +0200 Subject: dm: avoid NULL dereference in add_item() acpi_add_other_item() passes dev = NULL. Instead of dev->name write the string "other" to the debug log: ACPI: Writing ACPI tables at 1fd3000 0base: writing table '' * other: Added type 3, 0000000011fd4000, size 240 1facs: writing table 'FACS' * other: Added type 3, 0000000011fd4240, size 40 5csrt: writing table 'CSRT' * other: Added type 3, 0000000011fd4280, size 30 Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- drivers/core/acpi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c index 0df58dbc0d9..8457733edb5 100644 --- a/drivers/core/acpi.c +++ b/drivers/core/acpi.c @@ -159,8 +159,8 @@ static int add_item(struct acpi_ctx *ctx, struct udevice *dev, memcpy(item->buf, start, item->size); } item_count++; - log_debug("* %s: Added type %d, %p, size %x\n", dev->name, type, start, - item->size); + log_debug("* %s: Added type %d, %p, size %x\n", + dev ? dev->name : "other", type, start, item->size); return 0; } -- cgit v1.2.3 From 59ec024e563c9faab52f1c86736102562201c5fc Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 11 Jul 2022 08:21:30 +0200 Subject: test: fix log tests Consider CONFIG_LOG_MAX_LEVEL and gd->default_log_level in * do_log_test_helpers() * log_test_dropped() * log_test_level_deny() Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- test/log/log_test.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/log/log_test.c b/test/log/log_test.c index db7170f3042..c5abff80d11 100644 --- a/test/log/log_test.c +++ b/test/log/log_test.c @@ -277,7 +277,7 @@ int do_log_test_helpers(struct unit_test_state *uts) log_content("level %d\n", LOGL_DEBUG_CONTENT); log_io("level %d\n", LOGL_DEBUG_IO); - for (i = LOGL_EMERG; i <= _LOG_MAX_LEVEL; i++) + for (i = LOGL_EMERG; i <= gd->default_log_level; i++) ut_assert_nextline("%*s() level %d", CONFIG_LOGF_FUNC_PAD, __func__, i); ut_assert_console_end(); @@ -381,7 +381,8 @@ int log_test_level_deny(struct unit_test_state *uts) ut_assertok(console_record_reset_enable()); log_run(); check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE, - LOGL_WARNING + 1, _LOG_MAX_LEVEL); + LOGL_WARNING + 1, + min(gd->default_log_level, LOGL_INFO)); ut_assertok(log_remove_filter("console", filt1)); ut_assertok(log_remove_filter("console", filt2)); @@ -420,9 +421,11 @@ int log_test_dropped(struct unit_test_state *uts) gd->log_drop_count = 0; ut_assertok(console_record_reset_enable()); - log_run(); - ut_asserteq(gd->log_drop_count, 3 * (LOGL_COUNT - LOGL_FIRST - 1)); + log_run(); + ut_asserteq(2 * (LOGL_COUNT - LOGL_FIRST) + + _LOG_MAX_LEVEL - LOGL_FIRST + 1, + gd->log_drop_count); check_log_entries_flags_levels(EXPECT_DEBUG, LOGL_FIRST, CONFIG_LOG_DEFAULT_LEVEL); gd->flags |= GD_FLG_LOG_READY; -- cgit v1.2.3 From 7a6f5a4ea119441cb114b4239862f042501a6e5e Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 11 Jul 2022 08:21:31 +0200 Subject: dm: avoid NULL dereference in lists_bind_fdt() If parameter drv of lists_bind_fdt() is specified, we want to bind to this specific driver even if its field of_match is NULL. If entry->of_match is NULL, we should not dereference it in a debug statement. Fixes: d3e773613b6d ("dm: core: Use U-Boot logging instead of pr_debug()") Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- drivers/core/lists.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/core/lists.c b/drivers/core/lists.c index 22ccd9faaa9..93514a744d9 100644 --- a/drivers/core/lists.c +++ b/drivers/core/lists.c @@ -241,9 +241,10 @@ int lists_bind_fdt(struct udevice *parent, ofnode node, struct udevice **devp, } } - log_debug(" - found match at '%s': '%s' matches '%s'\n", - entry->name, entry->of_match->compatible, - id->compatible); + if (entry->of_match) + log_debug(" - found match at '%s': '%s' matches '%s'\n", + entry->name, entry->of_match->compatible, + id->compatible); ret = device_bind_with_driver_data(parent, entry, name, id->data, node, &dev); if (ret == -ENODEV) { -- cgit v1.2.3 From 9396116d2d1d6d87a8d96f2c4b50ae1019d6cdf0 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 11 Jul 2022 08:21:32 +0200 Subject: configs: sandbox_defconfig: CONFIG_LOG_MAX_LEVEL=9 Without setting CONFIG_LOG_MAX_LEVEL to a value above 6 we will not detect NULL dereferences and other errors in log_debug() calls. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- configs/sandbox_defconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 572cf8edd8b..d50ce91cd1e 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -31,6 +31,8 @@ CONFIG_CONSOLE_RECORD=y CONFIG_CONSOLE_RECORD_OUT_SIZE=0x6000 CONFIG_PRE_CONSOLE_BUFFER=y CONFIG_LOG=y +CONFIG_LOG_MAX_LEVEL=9 +CONFIG_LOG_DEFAULT_LEVEL=6 CONFIG_DISPLAY_BOARDINFO_LATE=y CONFIG_STACKPROTECTOR=y CONFIG_ANDROID_AB=y -- cgit v1.2.3 From de84a4f0eed297afa752ee46c072a99834dde806 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 11 Jul 2022 08:25:33 +0200 Subject: dm: fix logic of lists_bind_fdt() If parameter drv of lists_bind_fdt() is specified, we shall bind only to this very driver and to no other. If the driver drv has an of_match property, we shall only bind to the driver if it matches the compatible string of the device. Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- drivers/core/lists.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/core/lists.c b/drivers/core/lists.c index 93514a744d9..c49695b24f0 100644 --- a/drivers/core/lists.c +++ b/drivers/core/lists.c @@ -223,10 +223,14 @@ int lists_bind_fdt(struct udevice *parent, ofnode node, struct udevice **devp, compat); for (entry = driver; entry != driver + n_ents; entry++) { + if (drv) { + if (drv != entry) + continue; + if (!entry->of_match) + break; + } ret = driver_check_compatible(entry->of_match, &id, compat); - if ((drv) && (drv == entry)) - break; if (!ret) break; } -- cgit v1.2.3 From 54e89a8beb0edc6135586fed2a71139830d94974 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Tue, 12 Jul 2022 09:39:49 +0200 Subject: log: force DEBUG when LOG_DEBUG is activated When CONFIG_LOG is activated, if LOG_DEBUG is defined in a file and DEBUG is not defined the trace with debug() macro are not displayed, because the parameter cond : _DEBUG = 0 is checked in debug_cond(). With this patch the define DEBUG, used to force the trace generated by debug() macro, is linked with the define LOG_DEBUG, used to force the trace generated by other macros (log_debug, dev_dbg, pr_debug). We only need to define LOG_DEBUG in a file to activate all the traces generated by any U-Boot debug macro, as it is described in /doc/develop/logging.rst Signed-off-by: Patrick Delaunay --- doc/develop/logging.rst | 19 +++++++------------ include/log.h | 3 +++ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/doc/develop/logging.rst b/doc/develop/logging.rst index 51095b05ba9..704a6bf1d84 100644 --- a/doc/develop/logging.rst +++ b/doc/develop/logging.rst @@ -66,26 +66,21 @@ Sometimes it is useful to turn on logging just in one file. You can use this #define LOG_DEBUG to enable building in of all logging statements in a single file. Put it at -the top of the file, before any #includes. - -To actually get U-Boot to output this you need to also set the default logging -level - e.g. set CONFIG_LOG_DEFAULT_LEVEL to 7 (:c:data:`LOGL_DEBUG`) or more. -Otherwise debug output is suppressed and will not be generated. +the top of the file, before any #includes and any message in the file will be +written, regardless of the value of CONFIG_LOG_DEFAULT_LEVEL. Using DEBUG ----------- U-Boot has traditionally used a #define called DEBUG to enable debugging on a -file-by-file basis. The debug() macro compiles to a printf() statement if -DEBUG is enabled, and an empty statement if not. +file-by-file basis but LOG_DEBUG are intended to replace it with the logging +facilities; DEBUG is activated when LOG_DEBUG is activated. With logging enabled, debug() statements are interpreted as logging output -with a level of LOGL_DEBUG and a category of LOGC_NONE. +with a level of LOGL_DEBUG and a category of LOG_CATEGORY. -The logging facilities are intended to replace DEBUG, but if DEBUG is defined -at the top of a file, then it takes precedence. This means that debug() -statements will result in output to the console and this output will not be -logged. +With logging disabled, the debug() macro compiles to a printf() statement +if DEBUG is enabled and to an empty statement if not. Logging statements ------------------ diff --git a/include/log.h b/include/log.h index 8f35c10abb5..7abc70e4398 100644 --- a/include/log.h +++ b/include/log.h @@ -194,6 +194,9 @@ int _log_buffer(enum log_category_t cat, enum log_level_t level, #ifdef LOG_DEBUG #define _LOG_DEBUG LOGL_FORCE_DEBUG +#ifndef DEBUG +#define DEBUG +#endif #else #define _LOG_DEBUG 0 #endif -- cgit v1.2.3 From 109dbdf042e2a034edd8ed7b711143c522cb1465 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Tue, 12 Jul 2022 19:41:29 +0200 Subject: binman: Increase default fitImage data section resize step from 1k to 64k Currently the fitImage data area is resized in 1 kiB steps. This works when bundling smaller images below some 1 MiB, but when bundling large images into the fitImage, this make binman spend extreme amount of time and CPU just spinning in pylibfdt FdtSw.check_space() until the size grows enough for the large image to fit into the data area. Increase the default step to 64 kiB, which is a reasonable compromise -- the U-Boot blobs are somewhere in the 64kiB...1MiB range, DT blob are just short of 64 kiB, and so are the other blobs. This reduces binman runtime with 32 MiB blob from 2.3 minutes to 5 seconds. The following can be used to trigger the problem if rand.bin is some 32 MiB. " / { itb { fit { images { test { compression = "none"; description = "none"; type = "flat_dt"; blob { filename = "rand.bin"; type = "blob-ext"; }; }; }; }; }; configurations { binman_configuration: config { loadables = "test"; }; }; }; " Signed-off-by: Marek Vasut Cc: Alper Nebi Yasak Cc: Simon Glass Reviewed-by: Simon Glass --- tools/binman/etype/fit.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py index 12306623af6..ad43fce18ec 100644 --- a/tools/binman/etype/fit.py +++ b/tools/binman/etype/fit.py @@ -658,6 +658,7 @@ class Entry_fit(Entry_section): # Build a new tree with all nodes and properties starting from the # entry node fsw = libfdt.FdtSw() + fsw.INC_SIZE = 65536 fsw.finish_reservemap() to_remove = [] loadables = [] -- cgit v1.2.3 From 281996110c1f42b5476e43040798cb38169b6119 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 13 Jul 2022 06:06:58 -0600 Subject: addrmap: Support on sandbox Update this feature so that it works on sandbox, using a basic identity mapping. This allows us to run the 'ut addrmap' test. Also fix up the test to use the correct macros to access the linker list, so that the 'ut addrmap' command actually works. Signed-off-by: Simon Glass --- board/sandbox/sandbox.c | 9 +++++++++ configs/sandbox_defconfig | 1 + include/addr_map.h | 2 ++ lib/addr_map.c | 5 +++-- test/cmd/addrmap.c | 5 ++--- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/board/sandbox/sandbox.c b/board/sandbox/sandbox.c index e054f300c4a..ca9a2ca5b17 100644 --- a/board/sandbox/sandbox.c +++ b/board/sandbox/sandbox.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -155,3 +156,11 @@ int board_late_init(void) return 0; } #endif + +int init_addr_map(void) +{ + if (IS_ENABLED(CONFIG_ADDR_MAP)) + addrmap_set_entry(0, 0, CONFIG_SYS_SDRAM_SIZE, 0); + + return 0; +} diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index d50ce91cd1e..eba7bcbb483 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -315,6 +315,7 @@ CONFIG_WDT_GPIO=y CONFIG_WDT_SANDBOX=y CONFIG_FS_CBFS=y CONFIG_FS_CRAMFS=y +CONFIG_ADDR_MAP=y CONFIG_CMD_DHRYSTONE=y CONFIG_ECDSA=y CONFIG_ECDSA_VERIFY=y diff --git a/include/addr_map.h b/include/addr_map.h index 55d3a6a165a..db3712b5d30 100644 --- a/include/addr_map.h +++ b/include/addr_map.h @@ -14,7 +14,9 @@ struct addrmap { unsigned long vaddr; }; +#ifdef CONFIG_ADDR_MAP extern struct addrmap address_map[CONFIG_SYS_NUM_ADDR_MAP]; +#endif phys_addr_t addrmap_virt_to_phys(void *vaddr); void *addrmap_phys_to_virt(phys_addr_t paddr); diff --git a/lib/addr_map.c b/lib/addr_map.c index fb2ef400078..9b3e0a544e4 100644 --- a/lib/addr_map.c +++ b/lib/addr_map.c @@ -5,6 +5,7 @@ #include #include +#include struct addrmap address_map[CONFIG_SYS_NUM_ADDR_MAP]; @@ -18,7 +19,7 @@ phys_addr_t addrmap_virt_to_phys(void * vaddr) if (address_map[i].size == 0) continue; - addr = (u64)((u32)vaddr); + addr = map_to_sysmem(vaddr); base = (u64)(address_map[i].vaddr); upper = (u64)(address_map[i].size) + base - 1; @@ -48,7 +49,7 @@ void *addrmap_phys_to_virt(phys_addr_t paddr) offset = address_map[i].paddr - address_map[i].vaddr; - return (void *)(unsigned long)(paddr - offset); + return map_sysmem(paddr - offset, 0); } } diff --git a/test/cmd/addrmap.c b/test/cmd/addrmap.c index fb744485bbf..1eb5955db17 100644 --- a/test/cmd/addrmap.c +++ b/test/cmd/addrmap.c @@ -29,9 +29,8 @@ ADDRMAP_TEST(addrmap_test_basic, UT_TESTF_CONSOLE_REC); int do_ut_addrmap(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - struct unit_test *tests = ll_entry_start(struct unit_test, - addrmap_test); - const int n_ents = ll_entry_count(struct unit_test, addrmap_test); + struct unit_test *tests = UNIT_TEST_SUITE_START(addrmap_test); + const int n_ents = UNIT_TEST_SUITE_COUNT(addrmap_test); return cmd_ut_category("cmd_addrmap", "cmd_addrmap_", tests, n_ents, argc, argv); -- cgit v1.2.3 From 747244840b647991844556284aacdb3857440861 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 13 Jul 2022 06:06:59 -0600 Subject: fdt: Start a test for the fdt command Add a basic test of the 'fdt addr' command, to kick things off. This includes a new convenience function to run a command from a printf() string. Signed-off-by: Simon Glass --- common/cli.c | 15 ++++++ include/command.h | 10 ++++ include/test/suites.h | 1 + test/cmd/Makefile | 1 + test/cmd/fdt.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++ test/cmd_ut.c | 6 +++ 6 files changed, 175 insertions(+) create mode 100644 test/cmd/fdt.c diff --git a/common/cli.c b/common/cli.c index a7e3d84b68f..a47d6a3f2b4 100644 --- a/common/cli.c +++ b/common/cli.c @@ -126,6 +126,21 @@ int run_command_list(const char *cmd, int len, int flag) return rcode; } +int run_commandf(const char *fmt, ...) +{ + va_list args; + char cmd[128]; + int i, ret; + + va_start(args, fmt); + i = vsnprintf(cmd, sizeof(cmd), fmt, args); + va_end(args); + + ret = run_command(cmd, 0); + + return ret; +} + /****************************************************************************/ #if defined(CONFIG_CMD_RUN) diff --git a/include/command.h b/include/command.h index 0cf12fde396..44c91f655d4 100644 --- a/include/command.h +++ b/include/command.h @@ -257,6 +257,16 @@ int board_run_command(const char *cmdline); int run_command(const char *cmd, int flag); int run_command_repeatable(const char *cmd, int flag); +/** + * run_commandf() - Run a command created by a format string + * + * The command cannot be larger than 127 characters + * + * @fmt: printf() format string + * @...: Arguments to use (flag is always 0) + */ +int run_commandf(const char *fmt, ...); + /** * Run a list of commands separated by ; or even \0 * diff --git a/include/test/suites.h b/include/test/suites.h index ddb8827fdb1..44025ccecd6 100644 --- a/include/test/suites.h +++ b/include/test/suites.h @@ -38,6 +38,7 @@ int do_ut_compression(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_dm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_env(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); +int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_lib(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_loadm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ut_log(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]); diff --git a/test/cmd/Makefile b/test/cmd/Makefile index 4b2d7df0d2e..c331757425e 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_CONSOLE_RECORD) += test_echo.o endif obj-y += mem.o obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o +obj-$(CONFIG_CMD_FDT) += fdt.o obj-$(CONFIG_CMD_LOADM) += loadm.o obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o obj-$(CONFIG_CMD_PINMUX) += pinmux.o diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c new file mode 100644 index 00000000000..100a7ef5ebf --- /dev/null +++ b/test/cmd/fdt.c @@ -0,0 +1,142 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Tests for fdt command + * + * Copyright 2022 Google LLCmap_to_sysmem(fdt)); + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +/* Declare a new fdt test */ +#define FDT_TEST(_name, _flags) UNIT_TEST(_name, _flags, fdt_test) + +/** + * make_test_fdt() - Create an FDT with just a root node + * + * The size is set to the minimum needed + * + * @uts: Test state + * @fdt: Place to write FDT + * @size: Maximum size of space for fdt + */ +static int make_test_fdt(struct unit_test_state *uts, void *fdt, int size) +{ + ut_assertok(fdt_create(fdt, size)); + ut_assertok(fdt_finish_reservemap(fdt)); + ut_assert(fdt_begin_node(fdt, "") >= 0); + ut_assertok(fdt_end_node(fdt)); + ut_assertok(fdt_finish(fdt)); + + return 0; +} + +/* Test 'fdt addr' getting/setting address */ +static int fdt_test_addr(struct unit_test_state *uts) +{ + const void *fdt_blob, *new_fdt; + char fdt[256]; + ulong addr; + int ret; + + ut_assertok(console_record_reset_enable()); + ut_assertok(run_command("fdt addr -c", 0)); + ut_assert_nextline("Control fdt: %08lx", + (ulong)map_to_sysmem(gd->fdt_blob)); + ut_assertok(ut_check_console_end(uts)); + + /* The working fdt is not set, so this should fail */ + set_working_fdt_addr(0); + ut_asserteq(CMD_RET_FAILURE, run_command("fdt addr", 0)); + ut_assert_nextline("libfdt fdt_check_header(): FDT_ERR_BADMAGIC"); + ut_assertok(ut_check_console_end(uts)); + + /* Set up a working FDT and try again */ + ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt))); + addr = map_to_sysmem(fdt); + set_working_fdt_addr(addr); + ut_assertok(run_command("fdt addr", 0)); + ut_assert_nextline("Working fdt: %08lx", (ulong)map_to_sysmem(fdt)); + ut_assertok(ut_check_console_end(uts)); + + /* Set the working FDT */ + set_working_fdt_addr(0); + ut_assertok(run_commandf("fdt addr %08x", addr)); + ut_asserteq(addr, map_to_sysmem(working_fdt)); + ut_assertok(ut_check_console_end(uts)); + set_working_fdt_addr(0); + + /* Set the working FDT */ + fdt_blob = gd->fdt_blob; + gd->fdt_blob = NULL; + ret = run_commandf("fdt addr -c %08x", addr); + new_fdt = gd->fdt_blob; + gd->fdt_blob = fdt_blob; + ut_assertok(ret); + ut_asserteq(addr, map_to_sysmem(new_fdt)); + ut_assertok(ut_check_console_end(uts)); + + /* Test setting an invalid FDT */ + fdt[0] = 123; + ut_asserteq(1, run_commandf("fdt addr %08x", addr)); + ut_assert_nextline("libfdt fdt_check_header(): FDT_ERR_BADMAGIC"); + ut_assertok(ut_check_console_end(uts)); + + /* Test detecting an invalid FDT */ + fdt[0] = 123; + set_working_fdt_addr(addr); + ut_asserteq(1, run_commandf("fdt addr")); + ut_assert_nextline("libfdt fdt_check_header(): FDT_ERR_BADMAGIC"); + ut_assertok(ut_check_console_end(uts)); + + return 0; +} +FDT_TEST(fdt_test_addr, UT_TESTF_CONSOLE_REC); + +/* Test 'fdt addr' resizing an fdt */ +static int fdt_test_resize(struct unit_test_state *uts) +{ + char fdt[256]; + const int newsize = sizeof(fdt) / 2; + ulong addr; + + ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt))); + addr = map_to_sysmem(fdt); + set_working_fdt_addr(addr); + + /* Test setting and resizing the working FDT to a larger size */ + ut_assertok(console_record_reset_enable()); + ut_assertok(run_commandf("fdt addr %08x %x", addr, newsize)); + ut_assertok(ut_check_console_end(uts)); + + /* Try shrinking it */ + ut_assertok(run_commandf("fdt addr %08x %x", addr, sizeof(fdt) / 4)); + ut_assert_nextline("New length %d < existing length %d, ignoring", + (int)sizeof(fdt) / 4, newsize); + ut_assertok(ut_check_console_end(uts)); + + /* ...quietly */ + ut_assertok(run_commandf("fdt addr -q %08x %x", addr, sizeof(fdt) / 4)); + ut_assertok(ut_check_console_end(uts)); + + /* We cannot easily provoke errors in fdt_open_into(), so ignore that */ + + return 0; +} +FDT_TEST(fdt_test_resize, UT_TESTF_CONSOLE_REC); + +int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test); + const int n_ents = UNIT_TEST_SUITE_COUNT(fdt_test); + + return cmd_ut_category("fdt", "fdt_test_", tests, n_ents, argc, argv); +} diff --git a/test/cmd_ut.c b/test/cmd_ut.c index d70b72678ae..3789c6b784c 100644 --- a/test/cmd_ut.c +++ b/test/cmd_ut.c @@ -39,6 +39,9 @@ static struct cmd_tbl cmd_ut_sub[] = { #if defined(CONFIG_UT_ENV) U_BOOT_CMD_MKENT(env, CONFIG_SYS_MAXARGS, 1, do_ut_env, "", ""), #endif +#ifdef CONFIG_CMD_FDT + U_BOOT_CMD_MKENT(fdt, CONFIG_SYS_MAXARGS, 1, do_ut_fdt, "", ""), +#endif #ifdef CONFIG_UT_OPTEE U_BOOT_CMD_MKENT(optee, CONFIG_SYS_MAXARGS, 1, do_ut_optee, "", ""), #endif @@ -131,6 +134,9 @@ static char ut_help_text[] = #ifdef CONFIG_UT_ENV "ut env [test-name]\n" #endif +#ifdef CONFIG_CMD_FDT + "ut fdt [test-name] - test of the fdt command\n" +#endif #ifdef CONFIG_UT_LIB "ut lib [test-name] - test library functions\n" #endif -- cgit v1.2.3 From 006e56b1ae951c5247fb11081c1a9693e0b65f8a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 13 Jul 2022 06:07:00 -0600 Subject: doc: Make a start on docs for fdt command Add some information about the 'fdt addr' subcommand, to get things started. Signed-off-by: Simon Glass --- doc/usage/cmd/fdt.rst | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 2 files changed, 70 insertions(+) create mode 100644 doc/usage/cmd/fdt.rst diff --git a/doc/usage/cmd/fdt.rst b/doc/usage/cmd/fdt.rst new file mode 100644 index 00000000000..07fed732e45 --- /dev/null +++ b/doc/usage/cmd/fdt.rst @@ -0,0 +1,69 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +fdt command +=========== + +Synopis +------- + +:: + + fdt addr [-cq] [addr [len]] + +Description +----------- + +The fdt command provides access to flat device tree blobs in memory. It has +many subcommands, some of which are not documented here. + +Flags: + +-c + Select the control FDT (otherwise the working FDT is used). +-q + Don't display errors + +The control FDT is the one used by U-Boot itself to control various features, +including driver model. This should only be changed if you really know what you +are doing, since once U-Boot starts it maintains pointers into the FDT from the +various driver model data structures. + +The working FDT is the one passed to the Operating System when booting. This +can be freely modified, so far as U-Boot is concerned, since it does not affect +U-Boot's operation. + +fdt addr +~~~~~~~~ + +With no arguments, this shows the address of the current working or control +FDT. + +If the `addr` argument is provided, then this sets the address of the working or +control FDT to the provided address. + +If the `len` argument is provided, then the device tree is expanded to that +size. This can be used to make space for more nodes and properties. It is +assumed that there is enough space in memory for this expansion. + +Example +------- + +Get the control address and copy that FDT to free memory:: + + => fdt addr -c + Control fdt: 0aff9fd0 + => cp.b 0aff9fd0 10000 10000 + => md 10000 4 + 00010000: edfe0dd0 5b3d0000 78000000 7c270000 ......=[...x..'| + +The second word shows the size of the FDT. Now set the working FDT to that +address and expand it to 0xf000 in size:: + + => fdt addr 10000 f000 + => md 10000 4 + 00010000: edfe0dd0 00f00000 78000000 7c270000 ...........x..'| + +Return value +------------ + +The return value $? indicates whether the command succeeded. diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 8b98629d6bf..16a3db5c000 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -43,6 +43,7 @@ Shell commands cmd/false cmd/fatinfo cmd/fatload + cmd/fdt cmd/for cmd/load cmd/loadm -- cgit v1.2.3 From 76656bca9e4d7d7093333a1986c6ebb228571ed6 Mon Sep 17 00:00:00 2001 From: Oleksandr Suvorov Date: Wed, 13 Jul 2022 19:42:49 +0300 Subject: dm: fix mis-word in SPL_DM description Replace logically correct word in the description. Fixes: 91a91ff804d ("dm: Add Kconfig options for driver model SPL support") Signed-off-by: Oleksandr Suvorov Reviewed-by: Simon Glass --- drivers/core/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/core/Kconfig b/drivers/core/Kconfig index 8eb0070d222..007dc6a1de3 100644 --- a/drivers/core/Kconfig +++ b/drivers/core/Kconfig @@ -18,7 +18,7 @@ config SPL_DM consider using CONFIG_SPL_SYS_MALLOC_SIMPLE. In that case you must provide CONFIG_SPL_SYS_MALLOC_F_LEN to set the size. In most cases driver model will only allocate a few uclasses - and devices in SPL, so 1KB should be enable. See + and devices in SPL, so 1KB should be enough. See CONFIG_SPL_SYS_MALLOC_F_LEN for more details on how to enable it. config TPL_DM -- cgit v1.2.3 From dce4322c0e1940e11ef9ff086890b8c474707317 Mon Sep 17 00:00:00 2001 From: Douglas Anderson Date: Tue, 19 Jul 2022 14:56:27 -0700 Subject: patman: By default don't pass "--no-tree" to checkpatch for linux When you pass "--no-tree" to checkpatch it disables some extra checks that are important for Linux. Specifically I want checks like: warning: DT compatible string "boogie,woogie" appears un-documented check ./Documentation/devicetree/bindings/ Let's make the default for Linux to _not_ pass --no-tree. We'll have a config option and command line flag to override. Signed-off-by: Douglas Anderson Reviewed-by: Simon Glass --- tools/patman/checkpatch.py | 11 +++++++---- tools/patman/control.py | 7 ++++--- tools/patman/main.py | 6 ++++++ tools/patman/settings.py | 3 ++- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/tools/patman/checkpatch.py b/tools/patman/checkpatch.py index 70ba561c268..d1b902dd962 100644 --- a/tools/patman/checkpatch.py +++ b/tools/patman/checkpatch.py @@ -186,7 +186,7 @@ def check_patch_parse(checkpatch_output, verbose=False): return result -def check_patch(fname, verbose=False, show_types=False): +def check_patch(fname, verbose=False, show_types=False, use_tree=False): """Run checkpatch.pl on a file and parse the results. Args: @@ -194,6 +194,7 @@ def check_patch(fname, verbose=False, show_types=False): verbose: True to print out every line of the checkpatch output as it is parsed show_types: Tell checkpatch to show the type (number) of each message + use_tree (bool): If False we'll pass '--no-tree' to checkpatch. Returns: namedtuple containing: @@ -210,7 +211,9 @@ def check_patch(fname, verbose=False, show_types=False): stdout: Full output of checkpatch """ chk = find_check_patch() - args = [chk, '--no-tree'] + args = [chk] + if not use_tree: + args.append('--no-tree') if show_types: args.append('--show-types') output = command.output(*args, fname, raise_on_error=False) @@ -236,13 +239,13 @@ def get_warning_msg(col, msg_type, fname, line, msg): line_str = '' if line is None else '%d' % line return '%s:%s: %s: %s\n' % (fname, line_str, msg_type, msg) -def check_patches(verbose, args): +def check_patches(verbose, args, use_tree): '''Run the checkpatch.pl script on each patch''' error_count, warning_count, check_count = 0, 0, 0 col = terminal.Color() for fname in args: - result = check_patch(fname, verbose) + result = check_patch(fname, verbose, use_tree=use_tree) if not result.ok: error_count += result.errors warning_count += result.warnings diff --git a/tools/patman/control.py b/tools/patman/control.py index b40382388e0..bf426cf7bcf 100644 --- a/tools/patman/control.py +++ b/tools/patman/control.py @@ -64,7 +64,7 @@ def prepare_patches(col, branch, count, start, end, ignore_binary, signoff): patchstream.insert_cover_letter(cover_fname, series, to_do) return series, cover_fname, patch_files -def check_patches(series, patch_files, run_checkpatch, verbose): +def check_patches(series, patch_files, run_checkpatch, verbose, use_tree): """Run some checks on a set of patches This santiy-checks the patman tags like Series-version and runs the patches @@ -77,6 +77,7 @@ def check_patches(series, patch_files, run_checkpatch, verbose): run_checkpatch (bool): True to run checkpatch.pl verbose (bool): True to print out every line of the checkpatch output as it is parsed + use_tree (bool): If False we'll pass '--no-tree' to checkpatch. Returns: bool: True if the patches had no errors, False if they did @@ -86,7 +87,7 @@ def check_patches(series, patch_files, run_checkpatch, verbose): # Check the patches, and run them through 'git am' just to be sure if run_checkpatch: - ok = checkpatch.check_patches(verbose, patch_files) + ok = checkpatch.check_patches(verbose, patch_files, use_tree) else: ok = True return ok @@ -165,7 +166,7 @@ def send(args): col, args.branch, args.count, args.start, args.end, args.ignore_binary, args.add_signoff) ok = check_patches(series, patch_files, args.check_patch, - args.verbose) + args.verbose, args.check_patch_use_tree) ok = ok and gitutil.check_suppress_cc_config() diff --git a/tools/patman/main.py b/tools/patman/main.py index 66d4806c8d8..15e7af0e54e 100755 --- a/tools/patman/main.py +++ b/tools/patman/main.py @@ -81,6 +81,12 @@ send.add_argument('--no-binary', action='store_true', dest='ignore_binary', send.add_argument('--no-check', action='store_false', dest='check_patch', default=True, help="Don't check for patch compliance") +send.add_argument('--tree', dest='check_patch_use_tree', default=False, + action='store_true', + help=("Set `tree` to True. If `tree` is False then we'll " + "pass '--no-tree' to checkpatch (default: tree=%(default)s)")) +send.add_argument('--no-tree', dest='check_patch_use_tree', + action='store_false', help="Set `tree` to False") send.add_argument('--no-tags', action='store_false', dest='process_tags', default=True, help="Don't process subject tags as aliases") send.add_argument('--no-signoff', action='store_false', dest='add_signoff', diff --git a/tools/patman/settings.py b/tools/patman/settings.py index 4c847fe88fd..903d6fcb0b4 100644 --- a/tools/patman/settings.py +++ b/tools/patman/settings.py @@ -23,6 +23,7 @@ _default_settings = { "u-boot": {}, "linux": { "process_tags": "False", + "check_patch_use_tree": "True", }, "gcc": { "process_tags": "False", @@ -71,7 +72,7 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser): >>> config = _ProjectConfigParser("linux") >>> config.readfp(StringIO(sample_config)) >>> sorted((str(a), str(b)) for (a, b) in config.items("settings")) - [('am_hero', 'True'), ('process_tags', 'False')] + [('am_hero', 'True'), ('check_patch_use_tree', 'True'), ('process_tags', 'False')] # Check to make sure that settings works with unknown project. >>> config = _ProjectConfigParser("unknown") -- cgit v1.2.3