From 4b5019e3e57222cfa12147b6fcbce321cd140aeb Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 28 Mar 2021 11:27:18 +1300 Subject: [PATCH 01/20] dtc: Update the build rule for pylibfdt Some versions of make complain about using a grouped target without a recipe: .../pylibfdt/Makefile:36: *** grouped targets must provide a recipe. Stop. Fix this by adding a dummy recipe. Signed-off-by: Simon Glass --- scripts/dtc/pylibfdt/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/dtc/pylibfdt/Makefile b/scripts/dtc/pylibfdt/Makefile index 4782dd45c6..493995e303 100644 --- a/scripts/dtc/pylibfdt/Makefile +++ b/scripts/dtc/pylibfdt/Makefile @@ -34,6 +34,7 @@ rebuild: $(src)/setup.py $(PYLIBFDT_srcs) fi $(obj)/_libfdt.so $(obj)/libfdt.py &: rebuild + @: always += _libfdt.so libfdt.py From 42bc156f803995ca749f88a435706e3c8fb5f557 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 22 Mar 2021 18:01:42 +1300 Subject: [PATCH 02/20] patman: Continue on if warnings are found outside a commit While we cannot know which commit the warning relates to, this should not be fatal. Print the warning and carry on. Signed-off-by: Simon Glass --- tools/patman/patchstream.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/patman/patchstream.py b/tools/patman/patchstream.py index cdcd50a849..a44cd861af 100644 --- a/tools/patman/patchstream.py +++ b/tools/patman/patchstream.py @@ -133,8 +133,8 @@ class PatchStream: ValueError: Warning is generated with no commit associated """ if not self.commit: - raise ValueError('Warning outside commit: %s' % warn) - if warn not in self.commit.warn: + print('Warning outside commit: %s' % warn) + elif warn not in self.commit.warn: self.commit.warn.append(warn) def _add_to_series(self, line, name, value): From 42a2668743b58820392a2cde3c722822daa50db6 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 25 Mar 2021 10:26:03 +1300 Subject: [PATCH 03/20] dm: core: Document the common error codes Driver model uses quite strong conventions on error codes, but these are currently not clearly documented. Add a description of the commonly used errors. Signed-off-by: Simon Glass Reviewed-by: Sean Anderson --- doc/develop/driver-model/design.rst | 133 ++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/doc/develop/driver-model/design.rst b/doc/develop/driver-model/design.rst index 4e5cecbab6..b0e6337030 100644 --- a/doc/develop/driver-model/design.rst +++ b/doc/develop/driver-model/design.rst @@ -900,6 +900,139 @@ Some special flags are used to determine whether to remove the device: The dm_remove_devices_flags() function can be used to remove devices based on their driver flags. + +Error codes +----------- + +Driver model tries to use errors codes in a consistent way, as follows: + +\-EAGAIN + Try later, e.g. dependencies not ready + +\-EINVAL + Invalid argument, such as `dev_read_...()` failed or any other + devicetree-related access. Also used when a driver method is passed an + argument it considers invalid or does not support. + +\-EIO + Failed to perform an I/O operation. This is used when a local device + (i.e. part of the SOC) does not work as expected. Use -EREMOTEIO for + failures to talk to a separate device, e.g. over an I2C or SPI + channel. + +\-ENODEV + Do not bind the device. This should not be used to indicate an + error probing the device or for any other purpose, lest driver model get + confused. Using `-ENODEV` inside a driver method makes no sense, since + clearly there is a device. + +\-ENOENT + Entry or object not found. This is used when a device, file or directory + cannot be found (e.g. when looked up by name), It can also indicate a + missing devicetree subnode. + +\-ENOMEM + Out of memory + +\-ENOSPC + Ran out of space (e.g. in a buffer or limited-size array) + +\-ENOSYS + Function not implemented. This is returned by uclasses where the driver does + not implement a particular method. It can also be returned by drivers when + a particular sub-method is not implemented. This is widely checked in the + wider code base, where a feature may or may not be compiled into U-Boot. It + indicates that the feature is not available, but this is often just normal + operation. Please do not use -ENOSUPP. If an incorrect or unknown argument + is provided to a method (e.g. an unknown clock ID), return -EINVAL. + +\-ENXIO + Couldn't find device/address. This is used when a device or address + could not be obtained or is not valid. It is often used to indicate a + different type of problem, if -ENOENT is already used for something else in + the driver. + +\-EPERM + This is -1 so some older code may use it as a generic error. This indicates + that an operation is not permitted, e.g. a security violation or policy + constraint. It is returned internally when binding devices before relocation, + if the device is not marked for pre-relocation use. + +\-EPFNOSUPPORT + Missing uclass. This is deliberately an uncommon error code so that it can + easily be distinguished. If you see this very early in U-Boot, it means that + a device exists with a particular uclass but the uclass does not (mostly + likely because it is not compiled in). Enable DEBUG in uclass.c or lists.c + to see which uclass ID or driver is causing the problem. + +\-EREMOTEIO + This indicates an error in talking to a peripheral over a comms link, such + as I2C or SPI. It might indicate that the device is not present or is not + responding as expected. + +\-ETIMEDOUT + Hardware access or some other operation has timed out. This is used where + there is an expected time of response and that was exceeded by enough of + a margin that there is probably something wrong. + + +Less common ones: + +\-ECOMM + Not widely used, but similar to -EREMOTEIO. Can be useful as a secondary + error to distinguish the problem from -EREMOTEIO. + +\-EKEYREJECTED + Attempt to remove a device which does not match the removal flags. See + device_remove(). + +\-EILSEQ + Devicetree read failure, specifically trying to read a string index which + does not exist, in a string-listg property + +\-ENOEXEC + Attempt to use a uclass method on a device not in that uclass. This is + seldom checked at present, since it is generally a programming error and a + waste of code space. A DEBUG-only check would be useful here. + +\-ENODATA + Devicetree read error, where a property exists but has no data associated + with it + +\-EOVERFLOW + Devicetree read error, where the property is longer than expected + +\-EPROBE_DEFER + Attempt to remove a non-vital device when the removal flags indicate that + only vital devices should be removed + +\-ERANGE + Returned by regmap functions when arguments are out of range. This can be + useful for disinguishing regmap errors from other errors obtained while + probing devices. + +Drivers should use the same conventions so that things function as expected. +In particular, if a driver fails to probe, or a uclass operation fails, the +error code is the primary way to indicate what actually happened. + +Printing error messages in drivers is discouraged due to code size bloat and +since it can result in messages appearing in normal operation. For example, if +a command tries two different devices and uses whichever one probes correctly, +we don't want an error message displayed, even if the command itself might show +a warning or informational message. Ideally, messages in drivers should only be +displayed when debugging, e.g. by using log_debug() although in extreme cases +log_warning() or log_error() may be used. + +Error messages can be logged using `log_msg_ret()`, so that enabling +`CONFIG_LOG` and `CONFIG_LOG_ERROR_RETURN` shows a trace of error codes returned +through the call stack. That can be a handy way of quickly figuring out where +an error occurred. Get into the habit of return errors with +`return log_msg_ret("here", ret)` instead of just `return ret`. The string +just needs to be long enough to find in a single function, since a log record +stores (and can print with `CONFIG_LOGF_FUNC`) the function where it was +generated. + + Data Structures --------------- From aa4ad8bbad9d18c2363565418fc0d6e3dec4e928 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 25 Mar 2021 10:26:04 +1300 Subject: [PATCH 04/20] dm: core: Use -ENOSPC in acpi_get_path() Update this function to use -ENOSPC which is more commly used when a buffer runs out of space. Signed-off-by: Simon Glass --- drivers/core/acpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c index 0901b9260a..2176d8b836 100644 --- a/drivers/core/acpi.c +++ b/drivers/core/acpi.c @@ -91,7 +91,7 @@ int acpi_get_path(const struct udevice *dev, char *out_path, int maxlen) path = dev_read_string(dev, "acpi,path"); if (path) { if (strlen(path) >= maxlen) - return -E2BIG; + return -ENOSPC; strcpy(out_path, path); return 0; } From 6379a94cace5b0dbb3b35f8b3890ff023a59158d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 25 Mar 2021 10:26:05 +1300 Subject: [PATCH 05/20] usb: Return -ENOSYS when system call is not available Update usb_gadget_release() to use -ENOSYS, which is the correct error code for U-Boot. Signed-off-by: Simon Glass --- drivers/usb/gadget/udc/udc-uclass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/gadget/udc/udc-uclass.c b/drivers/usb/gadget/udc/udc-uclass.c index 3053ccf7d9..dbc354e84f 100644 --- a/drivers/usb/gadget/udc/udc-uclass.c +++ b/drivers/usb/gadget/udc/udc-uclass.c @@ -45,7 +45,7 @@ int usb_gadget_release(int index) dev_array[index] = NULL; return ret; #else - return -ENOTSUPP; + return -ENOSYS; #endif } From 24e3d5d2a9ed4e4cad6aba4694596efaf82c610c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 25 Mar 2021 10:26:06 +1300 Subject: [PATCH 06/20] spi: Return -ENOSYS when system call is not available Update spi_controller_dma_map_mem_op_data() to use -ENOSYS, which is the correct error code for U-Boot. Signed-off-by: Simon Glass --- include/spi-mem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/spi-mem.h b/include/spi-mem.h index 8be3e2bf6b..e354c38897 100644 --- a/include/spi-mem.h +++ b/include/spi-mem.h @@ -222,7 +222,7 @@ spi_controller_dma_map_mem_op_data(struct spi_controller *ctlr, const struct spi_mem_op *op, struct sg_table *sg) { - return -ENOTSUPP; + return -ENOSYS; } static inline void From 2f541aa53c73b00dfb613e0560cc703547233561 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 25 Mar 2021 10:26:07 +1300 Subject: [PATCH 07/20] tlv_eeprom: Return -ENOSYS when system call is not available When CMD_TLV_EEPROM is not enabled, use -ENOSYS, which is the correct error code for U-Boot. Signed-off-by: Simon Glass --- include/tlv_eeprom.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/tlv_eeprom.h b/include/tlv_eeprom.h index 1de2fe2337..a2c333e744 100644 --- a/include/tlv_eeprom.h +++ b/include/tlv_eeprom.h @@ -114,19 +114,19 @@ int read_tlvinfo_tlv_eeprom(void *eeprom, struct tlvinfo_header **hdr, static inline int read_tlv_eeprom(void *eeprom, int offset, int len, int dev) { - return -ENOTSUPP; + return -ENOSYS; } static inline int write_tlv_eeprom(void *eeprom, int len) { - return -ENOTSUPP; + return -ENOSYS; } static inline int read_tlvinfo_tlv_eeprom(void *eeprom, struct tlvinfo_header **hdr, struct tlvinfo_tlv **first_entry, int dev) { - return -ENOTSUPP; + return -ENOSYS; } #endif /* CONFIG_IS_ENABLED(CMD_TLV_EEPROM) */ From 9042bf6fe415c319958637b5e8b44ea4cf6f3a76 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 25 Mar 2021 10:26:08 +1300 Subject: [PATCH 08/20] clk: Update drivers to use -EINVAL At present some drivers use -ENOSUPP to indicate that an unknown or unsupported clock is used. Most use -EINVAL, indicating an invalid value, so convert everything to that. Signed-off-by: Simon Glass Acked-by: Sean Anderson Reviewed-by: Stefan Roese --- drivers/clk/aspeed/clk_ast2600.c | 2 +- drivers/clk/clk-hsdk-cgu.c | 4 ++-- drivers/clk/imx/clk-imx8.c | 4 ++-- drivers/clk/imx/clk-imx8qm.c | 6 +++--- drivers/clk/imx/clk-imx8qxp.c | 6 +++--- drivers/clk/imx/clk-pllv3.c | 2 +- drivers/clk/kendryte/bypass.c | 2 +- drivers/clk/kendryte/clk.c | 2 +- drivers/clk/mvebu/armada-37xx-periph.c | 6 +++--- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/clk/aspeed/clk_ast2600.c b/drivers/clk/aspeed/clk_ast2600.c index acb7eca741..3a92739f5c 100644 --- a/drivers/clk/aspeed/clk_ast2600.c +++ b/drivers/clk/aspeed/clk_ast2600.c @@ -1140,7 +1140,7 @@ int soc_clk_dump(void) clk_free(&clk); - if (ret == -ENOTSUPP) { + if (ret == -EINVAL) { printf("clk ID %lu not supported yet\n", aspeed_clk_names[i].id); continue; diff --git a/drivers/clk/clk-hsdk-cgu.c b/drivers/clk/clk-hsdk-cgu.c index 449b430e23..26b0aa9a26 100644 --- a/drivers/clk/clk-hsdk-cgu.c +++ b/drivers/clk/clk-hsdk-cgu.c @@ -718,7 +718,7 @@ static ulong hsdk_cgu_set_rate(struct clk *sclk, ulong rate) if (clk->map[sclk->id].set_rate) return clk->map[sclk->id].set_rate(sclk, rate); - return -ENOTSUPP; + return -EINVAL; } static int hsdk_cgu_disable(struct clk *sclk) @@ -731,7 +731,7 @@ static int hsdk_cgu_disable(struct clk *sclk) if (clk->map[sclk->id].disable) return clk->map[sclk->id].disable(sclk); - return -ENOTSUPP; + return -EINVAL; } static const struct clk_ops hsdk_cgu_ops = { diff --git a/drivers/clk/imx/clk-imx8.c b/drivers/clk/imx/clk-imx8.c index 8484613eed..b3dc138c4b 100644 --- a/drivers/clk/imx/clk-imx8.c +++ b/drivers/clk/imx/clk-imx8.c @@ -29,7 +29,7 @@ __weak ulong imx8_clk_set_rate(struct clk *clk, unsigned long rate) __weak int __imx8_clk_enable(struct clk *clk, bool enable) { - return -ENOTSUPP; + return -EINVAL; } static int imx8_clk_disable(struct clk *clk) @@ -70,7 +70,7 @@ int soc_clk_dump(void) clk_free(&clk); - if (ret == -ENOTSUPP) { + if (ret == -EINVAL) { printf("clk ID %lu not supported yet\n", imx8_clk_names[i].id); continue; diff --git a/drivers/clk/imx/clk-imx8qm.c b/drivers/clk/imx/clk-imx8qm.c index 7e466d630a..7759dc63ee 100644 --- a/drivers/clk/imx/clk-imx8qm.c +++ b/drivers/clk/imx/clk-imx8qm.c @@ -133,7 +133,7 @@ ulong imx8_clk_get_rate(struct clk *clk) __func__, clk->id); return -EINVAL; } - return -ENOTSUPP; + return -EINVAL; }; ret = sc_pm_get_clock_rate(-1, resource, pm_clk, @@ -237,7 +237,7 @@ ulong imx8_clk_set_rate(struct clk *clk, unsigned long rate) __func__, clk->id); return -EINVAL; } - return -ENOTSUPP; + return -EINVAL; }; ret = sc_pm_set_clock_rate(-1, resource, pm_clk, &new_rate); @@ -337,7 +337,7 @@ int __imx8_clk_enable(struct clk *clk, bool enable) __func__, clk->id); return -EINVAL; } - return -ENOTSUPP; + return -EINVAL; } ret = sc_pm_clock_enable(-1, resource, pm_clk, enable, 0); diff --git a/drivers/clk/imx/clk-imx8qxp.c b/drivers/clk/imx/clk-imx8qxp.c index e6b2fb40da..ffa2fcee0b 100644 --- a/drivers/clk/imx/clk-imx8qxp.c +++ b/drivers/clk/imx/clk-imx8qxp.c @@ -126,7 +126,7 @@ ulong imx8_clk_get_rate(struct clk *clk) __func__, clk->id); return -EINVAL; } - return -ENOTSUPP; + return -EINVAL; }; ret = sc_pm_get_clock_rate(-1, resource, pm_clk, @@ -221,7 +221,7 @@ ulong imx8_clk_set_rate(struct clk *clk, unsigned long rate) __func__, clk->id); return -EINVAL; } - return -ENOTSUPP; + return -EINVAL; }; ret = sc_pm_set_clock_rate(-1, resource, pm_clk, &new_rate); @@ -311,7 +311,7 @@ int __imx8_clk_enable(struct clk *clk, bool enable) __func__, clk->id); return -EINVAL; } - return -ENOTSUPP; + return -EINVAL; } ret = sc_pm_clock_enable(-1, resource, pm_clk, enable, 0); diff --git a/drivers/clk/imx/clk-pllv3.c b/drivers/clk/imx/clk-pllv3.c index feacaee1c4..b5cbf80054 100644 --- a/drivers/clk/imx/clk-pllv3.c +++ b/drivers/clk/imx/clk-pllv3.c @@ -290,7 +290,7 @@ struct clk *imx_clk_pllv3(enum imx_pllv3_type type, const char *name, break; default: kfree(pll); - return ERR_PTR(-ENOTSUPP); + return ERR_PTR(-EINVAL); } pll->base = base; diff --git a/drivers/clk/kendryte/bypass.c b/drivers/clk/kendryte/bypass.c index 5f1986f2cb..bbdbd9a10d 100644 --- a/drivers/clk/kendryte/bypass.c +++ b/drivers/clk/kendryte/bypass.c @@ -157,7 +157,7 @@ static int k210_bypass_set_parent(struct clk *clk, struct clk *parent) if (ops->set_parent) return ops->set_parent(bypass->bypassee, parent); else - return -ENOTSUPP; + return -EINVAL; } /* diff --git a/drivers/clk/kendryte/clk.c b/drivers/clk/kendryte/clk.c index 4b959401a6..3b674a998e 100644 --- a/drivers/clk/kendryte/clk.c +++ b/drivers/clk/kendryte/clk.c @@ -495,7 +495,7 @@ static int k210_clk_probe(struct udevice *dev) * could fix this, but it's Probably Not Worth It (TM). */ if (probed) - return -ENOTSUPP; + return -EINVAL; base = dev_read_addr_ptr(dev_get_parent(dev)); if (!base) diff --git a/drivers/clk/mvebu/armada-37xx-periph.c b/drivers/clk/mvebu/armada-37xx-periph.c index 0132fcb7e6..b0f47c33b3 100644 --- a/drivers/clk/mvebu/armada-37xx-periph.c +++ b/drivers/clk/mvebu/armada-37xx-periph.c @@ -340,7 +340,7 @@ static int periph_clk_enable(struct clk *clk, int enable) return -EINVAL; if (!periph_clk->can_gate) - return -ENOTSUPP; + return -EINVAL; if (enable) clrbits_le32(priv->reg + CLK_DIS, periph_clk->disable_bit); @@ -408,7 +408,7 @@ static ulong armada_37xx_periph_clk_set_rate(struct clk *clk, ulong req_rate) return old_rate; if (!periph_clk->can_gate || !periph_clk->dividers) - return -ENOTSUPP; + return -EINVAL; parent_rate = get_parent_rate(priv, clk->id); if (parent_rate == -EINVAL) @@ -445,7 +445,7 @@ static int armada_37xx_periph_clk_set_parent(struct clk *clk, return -EINVAL; if (!periph_clk->can_mux || !periph_clk->can_gate) - return -ENOTSUPP; + return -EINVAL; ret = clk_get_by_index(clk->dev, 0, &check_parent); if (ret < 0) From 3bc11b983d01e8b761cfeafa60d520b5702f7d10 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 25 Mar 2021 10:26:09 +1300 Subject: [PATCH 09/20] clk: Return -ENOSYS when system call is not available Update clk_composite_set_parent() to use -ENOSYS, which is the correct error code for U-Boot. Also rearrange the code so that the error condition is clearly indicated and the function runs to the end in the normal case, since this is the common style in U-Boot. Signed-off-by: Simon Glass Reviewed-by: Sean Anderson --- drivers/clk/clk-composite.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c index 7e99c5b910..bb5351ebc0 100644 --- a/drivers/clk/clk-composite.c +++ b/drivers/clk/clk-composite.c @@ -37,10 +37,10 @@ static int clk_composite_set_parent(struct clk *clk, struct clk *parent) const struct clk_ops *mux_ops = composite->mux_ops; struct clk *mux = composite->mux; - if (mux && mux_ops) - return mux_ops->set_parent(mux, parent); - else - return -ENOTSUPP; + if (!mux || !mux_ops) + return -ENOSYS; + + return mux_ops->set_parent(mux, parent); } static unsigned long clk_composite_recalc_rate(struct clk *clk) From d6332d59d25c26b9f21e04792686c4989a9382a4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 25 Mar 2021 10:26:10 +1300 Subject: [PATCH 10/20] simple-pm-bus: Use -ENOSYS for checking missing system call We don't need to check -ENOTSUPP since this is not used for this purpose in U-Boot. Update the code accordingly. Signed-off-by: Simon Glass Reviewed-by: Sean Anderson --- drivers/core/simple-pm-bus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/core/simple-pm-bus.c b/drivers/core/simple-pm-bus.c index 7a18953cba..1bb0d86e28 100644 --- a/drivers/core/simple-pm-bus.c +++ b/drivers/core/simple-pm-bus.c @@ -21,7 +21,7 @@ static int simple_pm_bus_probe(struct udevice *dev) return ret; ret = clk_enable_bulk(bulk); - if (ret && ret != -ENOSYS && ret != -ENOTSUPP) { + if (ret && ret != -ENOSYS) { clk_release_bulk(bulk); return ret; } @@ -34,7 +34,7 @@ static int simple_pm_bus_remove(struct udevice *dev) struct clk_bulk *bulk = dev_get_priv(dev); ret = clk_release_bulk(bulk); - if (ret && ret != -ENOSYS && ret != -ENOTSUPP) + if (ret && ret != -ENOSYS) return ret; else return 0; From bddac45d0422acbba5bf01406d27eedb429a1f42 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 25 Mar 2021 10:26:11 +1300 Subject: [PATCH 11/20] pinctrl: Return -ENOSYS when system call is not available Update the code to use -ENOSYS, which is the correct error code for an unimplemented system call in U-Boot. Also we should not check for a missing operations array as this is not permitted. For now this can be covered by an assert(). Signed-off-by: Simon Glass --- drivers/pinctrl/pinctrl-uclass.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c index b0f30aa1f7..6e68e52c32 100644 --- a/drivers/pinctrl/pinctrl-uclass.c +++ b/drivers/pinctrl/pinctrl-uclass.c @@ -235,8 +235,9 @@ int pinctrl_gpio_request(struct udevice *dev, unsigned offset) return ret; ops = pinctrl_get_ops(pctldev); - if (!ops || !ops->gpio_request_enable) - return -ENOTSUPP; + assert(ops); + if (!ops->gpio_request_enable) + return -ENOSYS; return ops->gpio_request_enable(pctldev, pin_selector); } @@ -261,8 +262,9 @@ int pinctrl_gpio_free(struct udevice *dev, unsigned offset) return ret; ops = pinctrl_get_ops(pctldev); - if (!ops || !ops->gpio_disable_free) - return -ENOTSUPP; + assert(ops); + if (!ops->gpio_disable_free) + return -ENOSYS; return ops->gpio_disable_free(pctldev, pin_selector); } From 5f86454b3da54586513ab83941a021cb79c383c7 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 26 Mar 2021 14:39:39 +1300 Subject: [PATCH 12/20] buildman: Add an encoding to the out-env file The environment may contain some unicode characters. At least that is what seemed to happen on one commit: Building current source for 1 boards (0 threads, 64 jobs per thread) 0 0 0 /1 -1 (starting) Traceback (most recent call last): File ".../tools/buildman/buildman", line 64, in ret_code = control.DoBuildman(options, args) File "tools/buildman/control.py", line 372, in DoBuildman options.keep_outputs, options.verbose) File ".../tools/buildman/builder.py", line 1704, in BuildBoards results = self._single_builder.RunJob(job) File ".../tools/buildman/builderthread.py", line 526, in RunJob self._WriteResult(result, job.keep_outputs, job.work_in_output) File ".../tools//buildman/builderthread.py", line 349, in _WriteResult print('%s="%s"' % (var, env[var]), file=fd) UnicodeEncodeError: 'ascii' codec can't encode characters in position 311-312: ordinal not in range(128) The problem defies repetition with any change at all to buildman. But let's set an encoding in any case. Signed-off-by: Simon Glass --- tools/buildman/builderthread.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/buildman/builderthread.py b/tools/buildman/builderthread.py index 6c6dbd7872..06ed27203a 100644 --- a/tools/buildman/builderthread.py +++ b/tools/buildman/builderthread.py @@ -344,7 +344,8 @@ class BuilderThread(threading.Thread): # Write out the image and function size information and an objdump env = result.toolchain.MakeEnvironment(self.builder.full_path) - with open(os.path.join(build_dir, 'out-env'), 'w') as fd: + with open(os.path.join(build_dir, 'out-env'), 'w', + encoding='utf-8') as fd: for var in sorted(env.keys()): print('%s="%s"' % (var, env[var]), file=fd) lines = [] From 0c59acef34434e47e054957108eb4fa7cef93123 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 26 Mar 2021 16:17:25 +1300 Subject: [PATCH 13/20] dtoc: Show driver warnings once at the end At present warnings are shown as soon as they are discovered in the source scannner. But the function that detects them may be called multiple times. Collect all the warnings and show them at the end. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 6 ++++-- tools/dtoc/src_scan.py | 15 +++++++++------ tools/dtoc/test_dtoc.py | 2 +- tools/dtoc/test_src_scan.py | 38 ++++++++++++++++++------------------- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index c9c657cb9a..dd97a6be70 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -1194,8 +1194,7 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, phase, raise ValueError('Must specify either output or output_dirs, not both') if not scan: - scan = src_scan.Scanner(basedir, warning_disabled, drivers_additional, - phase) + scan = src_scan.Scanner(basedir, drivers_additional, phase) scan.scan_drivers() do_process = True else: @@ -1232,4 +1231,7 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, phase, plat.out_header(outfile) outfile.method(plat) plat.finish_output() + + if not warning_disabled: + scan.show_warnings() return plat diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py index 114212cfe2..2db96884c8 100644 --- a/tools/dtoc/src_scan.py +++ b/tools/dtoc/src_scan.py @@ -188,7 +188,6 @@ class Scanner: key: Driver alias declared with DM_DRIVER_ALIAS(driver_alias, driver_name) value: Driver name declared with U_BOOT_DRIVER(driver_name) - _warning_disabled: true to disable warnings about driver names not found _drivers_additional (list or str): List of additional drivers to use during scanning _of_match: Dict holding information about compatible strings @@ -206,7 +205,7 @@ class Scanner: _phase: The phase of U-Boot that we are generating data for, e.g. 'spl' or 'tpl'. None if not known """ - def __init__(self, basedir, warning_disabled, drivers_additional, phase=''): + def __init__(self, basedir, drivers_additional, phase=''): """Set up a new Scanner """ if not basedir: @@ -217,7 +216,7 @@ class Scanner: self._drivers = {} self._driver_aliases = {} self._drivers_additional = drivers_additional or [] - self._warning_disabled = warning_disabled + self._missing_drivers = set() self._of_match = {} self._compat_to_driver = {} self._uclass = {} @@ -268,9 +267,7 @@ class Scanner: aliases_c.remove(compat_c) return compat_c, aliases_c - if not self._warning_disabled: - print('WARNING: the driver %s was not found in the driver list' - % (compat_list_c[0])) + self._missing_drivers.add(compat_list_c[0]) return compat_list_c[0], compat_list_c[1:] @@ -578,6 +575,12 @@ class Scanner: self._drivers[driver.name] = driver self._of_match.update(of_match) + def show_warnings(self): + """Show any warnings that have been collected""" + for name in sorted(list(self._missing_drivers)): + print('WARNING: the driver %s was not found in the driver list' + % name) + def scan_driver(self, fname): """Scan a driver file to build a list of driver names and aliases diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index e951283457..458d68351e 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -104,7 +104,7 @@ def setup(): # Disable warnings so that calls to get_normalized_compat_name() will not # output things. - saved_scan = src_scan.Scanner(None, True, False) + saved_scan = src_scan.Scanner(None, False) saved_scan.scan_drivers() def copy_scan(): diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py index 0af86dcf0c..d6da03849f 100644 --- a/tools/dtoc/test_src_scan.py +++ b/tools/dtoc/test_src_scan.py @@ -48,7 +48,7 @@ class TestSrcScan(unittest.TestCase): def test_simple(self): """Simple test of scanning drivers""" - scan = src_scan.Scanner(None, True, None) + scan = src_scan.Scanner(None, None) scan.scan_drivers() self.assertIn('sandbox_gpio', scan._drivers) self.assertIn('sandbox_gpio_alias', scan._driver_aliases) @@ -59,8 +59,7 @@ class TestSrcScan(unittest.TestCase): def test_additional(self): """Test with additional drivers to scan""" scan = src_scan.Scanner( - None, True, - [None, '', 'tools/dtoc/test/dtoc_test_scan_drivers.cxx']) + None, [None, '', 'tools/dtoc/test/dtoc_test_scan_drivers.cxx']) scan.scan_drivers() self.assertIn('sandbox_gpio_alias2', scan._driver_aliases) self.assertEqual('sandbox_gpio', @@ -77,7 +76,7 @@ class TestSrcScan(unittest.TestCase): with open(driver_fn, 'wb+') as fout: fout.write(b'\x81') - scan = src_scan.Scanner(None, True, [driver_fn]) + scan = src_scan.Scanner(None, [driver_fn]) with test_util.capture_sys_output() as (stdout, _): scan.scan_drivers() self.assertRegex(stdout.getvalue(), @@ -126,7 +125,7 @@ class TestSrcScan(unittest.TestCase): # Mock out scan_driver and check that it is called with the # expected files with mock.patch.object(src_scan.Scanner, "scan_driver") as mocked: - scan = src_scan.Scanner(indir, True, None) + scan = src_scan.Scanner(indir, None) scan.scan_drivers() self.assertEqual(2, len(mocked.mock_calls)) self.assertEqual(mock.call(fname_list[0]), @@ -141,7 +140,7 @@ class TestSrcScan(unittest.TestCase): """Test scanning of a driver""" fname = os.path.join(OUR_PATH, '..', '..', 'drivers/i2c/tegra_i2c.c') buff = tools.ReadFile(fname, False) - scan = src_scan.Scanner(None, False, None) + scan = src_scan.Scanner(None, None) scan._parse_driver(fname, buff) self.assertIn('i2c_tegra', scan._drivers) drv = scan._drivers['i2c_tegra'] @@ -165,14 +164,15 @@ class TestSrcScan(unittest.TestCase): # get_normalized_compat_name() uses this to check for root node node.parent = FakeNode() - scan = src_scan.Scanner(None, False, None) + scan = src_scan.Scanner(None, None) with test_util.capture_sys_output() as (stdout, _): name, aliases = scan.get_normalized_compat_name(node) self.assertEqual('rockchip_rk3288_grf', name) self.assertEqual([], aliases) - self.assertEqual( - 'WARNING: the driver rockchip_rk3288_grf was not found in the driver list', - stdout.getvalue().strip()) + self.assertEqual(1, len(scan._missing_drivers)) + self.assertEqual({'rockchip_rk3288_grf'}, scan._missing_drivers) + #'WARNING: the driver rockchip_rk3288_grf was not found in the driver list', + #stdout.getvalue().strip()) i2c = 'I2C_UCLASS' compat = {'rockchip,rk3288-grf': 'ROCKCHIP_SYSCON_GRF', @@ -211,7 +211,7 @@ U_BOOT_DRIVER(i2c_tegra) = { .of_match = tegra_i2c_ids, }; ''' - scan = src_scan.Scanner(None, False, None) + scan = src_scan.Scanner(None, None) with self.assertRaises(ValueError) as exc: scan._parse_driver('file.c', buff) self.assertIn( @@ -232,7 +232,7 @@ U_BOOT_DRIVER(i2c_tegra) = { .of_match = of_match_ptr(tegra_i2c_ids), }; ''' - scan = src_scan.Scanner(None, False, None) + scan = src_scan.Scanner(None, None) scan._parse_driver('file.c', buff) self.assertIn('i2c_tegra', scan._drivers) drv = scan._drivers['i2c_tegra'] @@ -261,7 +261,7 @@ U_BOOT_DRIVER(testing) = { DM_HEADER() }; ''' - scan = src_scan.Scanner(None, False, None) + scan = src_scan.Scanner(None, None) scan._parse_driver('file.c', buff) self.assertIn('testing', scan._drivers) drv = scan._drivers['testing'] @@ -293,7 +293,7 @@ UCLASS_DRIVER(i2c) = { }; ''' - scan = src_scan.Scanner(None, False, None) + scan = src_scan.Scanner(None, None) scan._parse_uclass_driver('file.c', buff) self.assertIn('UCLASS_I2C', scan._uclass) drv = scan._uclass['UCLASS_I2C'] @@ -325,7 +325,7 @@ UCLASS_DRIVER(i2c) = { }; ''' - scan = src_scan.Scanner(None, False, None) + scan = src_scan.Scanner(None, None) with self.assertRaises(ValueError) as exc: scan._parse_uclass_driver('file.c', buff) self.assertIn("file.c: Cannot parse uclass ID in driver 'i2c'", @@ -340,7 +340,7 @@ struct some_struct1 { uint nmsgs; }; ''' - scan = src_scan.Scanner(None, False, None) + scan = src_scan.Scanner(None, None) scan._basedir = os.path.join(OUR_PATH, '..', '..') scan._parse_structs('arch/arm/include/asm/file.h', buff) self.assertIn('some_struct1', scan._structs) @@ -371,7 +371,7 @@ struct another_struct { output = tools.GetOutputFilename('output.h') tools.WriteFile(output, b'struct this is a test \x81 of bad unicode') - scan = src_scan.Scanner(None, False, None) + scan = src_scan.Scanner(None, None) with test_util.capture_sys_output() as (stdout, _): scan.scan_header(output) self.assertIn('due to unicode error', stdout.getvalue()) @@ -411,7 +411,7 @@ U_BOOT_DRIVER(%s) = { .of_match = test_ids, }; ''' % name - scan = src_scan.Scanner(None, False, None, phase) + scan = src_scan.Scanner(None, None, phase) scan._parse_driver('file1.c', driver1) self.assertIn(name, scan._drivers) drv1 = scan._drivers[name] @@ -476,7 +476,7 @@ U_BOOT_DRIVER(%s) = { def test_sequence(self): """Test assignment of sequence numnbers""" - scan = src_scan.Scanner(None, False, None, '') + scan = src_scan.Scanner(None, None, '') node = FakeNode() uc = src_scan.UclassDriver('UCLASS_I2C') node.uclass = uc From 3e200caff05bccc86392ba531770ebb0879ef93e Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 26 Mar 2021 16:17:26 +1300 Subject: [PATCH 14/20] dtoc: Adjust detection of 64-bit properties At present an empty size is considered to be a 64-bit value. This does not seem useful and wastes space. Limit the 64-bit detection to where one or both of the addr/size is two cells or more. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 6 +++--- tools/dtoc/test_dtoc.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index dd97a6be70..b989b4f4fc 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -467,6 +467,8 @@ class DtbPlatdata(): if reg.type != fdt.Type.INT: raise ValueError("Node '%s' reg property is not an int" % node.name) + if not isinstance(reg.value, list): + reg.value = [reg.value] if len(reg.value) % total: raise ValueError( "Node '%s' reg property has %d cells " @@ -474,13 +476,11 @@ class DtbPlatdata(): (node.name, len(reg.value), num_addr, num_size)) reg.num_addr = num_addr reg.num_size = num_size - if num_addr != 1 or num_size != 1: + if num_addr > 1 or num_size > 1: reg.type = fdt.Type.INT64 i = 0 new_value = [] val = reg.value - if not isinstance(val, list): - val = [val] while i < len(val): addr = fdt_util.fdt_cells_to_cpu(val[i:], reg.num_addr) i += num_addr diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 458d68351e..cff522567e 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -293,7 +293,7 @@ struct dtd_sandbox_i2c { }; struct dtd_sandbox_pmic { \tbool\t\tlow_power; -\tfdt64_t\t\treg[2]; +\tfdt32_t\t\treg[1]; }; struct dtd_sandbox_spl_test { \tconst char * acpi_name; @@ -341,7 +341,7 @@ U_BOOT_DRVINFO(i2c_at_0) = { */ static struct dtd_sandbox_pmic dtv_pmic_at_9 = { \t.low_power\t\t= true, -\t.reg\t\t\t= {0x9, 0x0}, +\t.reg\t\t\t= {0x9}, }; U_BOOT_DRVINFO(pmic_at_9) = { \t.name\t\t= "sandbox_pmic", @@ -721,7 +721,7 @@ struct dm_test_pdata __attribute__ ((section (".priv_data"))) \t.dtplat = { \t\t.ping_add\t\t= 0x5, \t\t.ping_expect\t\t= 0x5, -\t\t.reg\t\t\t= {0x5, 0x0}, +\t\t.reg\t\t\t= {0x5}, \t}, }; #include From da393412234a37af68188e7490eba136c832a275 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 26 Mar 2021 16:17:27 +1300 Subject: [PATCH 15/20] dtoc: Improve handling of reg properties This existing code assumes that a reg property is larger than one cell, but this is not always the case. Fix this assumption. Also if a node's parent is missing the #address-cells and #size-cells properties we use 2 as a default for each. But this should not happen in practice. More likely the properties were removed for SPL due to there being no 'u-boot,dm-pre-reloc' property, or similar. Add a warning for this as the failure can be very confusing. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 8 +++++-- tools/dtoc/test/dtoc_test_noprops.dts | 21 +++++++++++++++++ tools/dtoc/test/dtoc_test_single_reg.dts | 30 ++++++++++++++++++++++++ tools/dtoc/test_dtoc.py | 17 +++++++++++++- 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 tools/dtoc/test/dtoc_test_noprops.dts create mode 100644 tools/dtoc/test/dtoc_test_single_reg.dts diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index b989b4f4fc..1374f01c70 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -440,6 +440,9 @@ class DtbPlatdata(): Number of size cells for this node """ parent = node.parent + if parent and not parent.props: + raise ValueError("Parent node '%s' has no properties - do you need u-boot,dm-spl or similar?" % + parent.path) num_addr, num_size = 2, 2 if parent: addr_prop = parent.props.get('#address-cells') @@ -471,9 +474,10 @@ class DtbPlatdata(): reg.value = [reg.value] if len(reg.value) % total: raise ValueError( - "Node '%s' reg property has %d cells " + "Node '%s' (parent '%s') reg property has %d cells " 'which is not a multiple of na + ns = %d + %d)' % - (node.name, len(reg.value), num_addr, num_size)) + (node.name, node.parent.name, len(reg.value), num_addr, + num_size)) reg.num_addr = num_addr reg.num_size = num_size if num_addr > 1 or num_size > 1: diff --git a/tools/dtoc/test/dtoc_test_noprops.dts b/tools/dtoc/test/dtoc_test_noprops.dts new file mode 100644 index 0000000000..e6fdd11b83 --- /dev/null +++ b/tools/dtoc/test/dtoc_test_noprops.dts @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test device tree file for dtoc + * + * Copyright 2017 Google, Inc + */ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + i2c@0 { + pmic@9 { + compatible = "sandbox,pmic"; + u-boot,dm-pre-reloc; + reg = <9>; + low-power; + }; + }; +}; diff --git a/tools/dtoc/test/dtoc_test_single_reg.dts b/tools/dtoc/test/dtoc_test_single_reg.dts new file mode 100644 index 0000000000..804b67855b --- /dev/null +++ b/tools/dtoc/test/dtoc_test_single_reg.dts @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test device tree file for dtoc + * + * Copyright 2017 Google, Inc + */ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + i2c@0 { + compatible = "sandbox,i2c"; + u-boot,dm-pre-reloc; + #address-cells = <1>; + #size-cells = <0>; + pmic@9 { + compatible = "sandbox,pmic"; + u-boot,dm-pre-reloc; + reg = <9>; + low-power; + + gpio { + compatible = "sandbox,gpio"; + }; + }; + }; +}; diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index cff522567e..a05e3d9ed6 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -1462,7 +1462,7 @@ U_BOOT_DRVINFO(test3) = { with self.assertRaises(ValueError) as exc: self.run_test(['struct'], dtb_file, output) self.assertIn( - "Node 'spl-test' reg property has 3 cells which is not a multiple of na + ns = 1 + 1)", + "Node 'spl-test' (parent '/') reg property has 3 cells which is not a multiple of na + ns = 1 + 1)", str(exc.exception)) def test_add_prop(self): @@ -1824,3 +1824,18 @@ U_BOOT_DRVINFO(spl_test2) = { self.assertEqual( 'Warning: Cannot find header file for struct dm_test_uc_priv', stdout.getvalue().strip()) + + def test_missing_props(self): + """Test detection of a parent node with no properties""" + dtb_file = get_dtb_file('dtoc_test_noprops.dts', capture_stderr=True) + output = tools.GetOutputFilename('output') + with self.assertRaises(ValueError) as exc: + self.run_test(['struct'], dtb_file, output) + self.assertIn("Parent node '/i2c@0' has no properties - do you need", + str(exc.exception)) + + def test_single_reg(self): + """Test detection of a parent node with no properties""" + dtb_file = get_dtb_file('dtoc_test_single_reg.dts') + output = tools.GetOutputFilename('output') + self.run_test(['struct'], dtb_file, output) From 4ce5b8104a1f09c41c69d17f21d9aac567173312 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 26 Mar 2021 16:17:28 +1300 Subject: [PATCH 16/20] log: Fix up debug_cond() when LOG is enabled At present debug() statements can cause debuf output to appear when LOG is enabled but DEBUG is not. This is not intended and it seems that the condition is wrong. Fix it. Signed-off-by: Simon Glass --- include/log.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/include/log.h b/include/log.h index 6ef891d4d2..add3a1e4a0 100644 --- a/include/log.h +++ b/include/log.h @@ -222,11 +222,14 @@ static inline int _log_nop(enum log_category_t cat, enum log_level_t level, #define _SPL_BUILD 0 #endif -#if !_DEBUG && CONFIG_IS_ENABLED(LOG) +#if CONFIG_IS_ENABLED(LOG) -#define debug_cond(cond, fmt, args...) \ -({ \ - log(LOG_CATEGORY, LOGL_DEBUG, fmt, ##args); \ +#define debug_cond(cond, fmt, args...) \ +({ \ + if (cond) \ + log(LOG_CATEGORY, \ + (enum log_level_t)(LOGL_FORCE_DEBUG | _LOG_DEBUG), \ + fmt, ##args); \ }) #else /* _DEBUG */ From 7570d9bb47be24d9d73518742703f32126af8113 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 26 Mar 2021 16:17:29 +1300 Subject: [PATCH 17/20] moveconfig: Handle binary files cleanly Some files are not actually source code and thus can produce unicode errors. Report this and continue. Signed-off-by: Simon Glass --- tools/moveconfig.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/moveconfig.py b/tools/moveconfig.py index 9514d9a00c..1ac30c0028 100755 --- a/tools/moveconfig.py +++ b/tools/moveconfig.py @@ -12,6 +12,10 @@ config options from headers to Kconfig (defconfig). This tool intends to help this tremendous work. +Installing +---------- + +You may need to install 'python3-asteval' for the 'asteval' module. Usage ----- @@ -573,7 +577,11 @@ def cleanup_empty_blocks(header_path, options): """ pattern = re.compile(r'^\s*#\s*if.*$\n^\s*#\s*endif.*$\n*', flags=re.M) with open(header_path) as f: - data = f.read() + try: + data = f.read() + except UnicodeDecodeError as e: + print("Failed on file %s': %s" % (header_path, e)) + return new_data = pattern.sub('\n', data) @@ -596,7 +604,11 @@ def cleanup_one_header(header_path, patterns, options): options: option flags. """ with open(header_path) as f: - lines = f.readlines() + try: + lines = f.readlines() + except UnicodeDecodeError as e: + print("Failed on file %s': %s" % (header_path, e)) + return matched = [] for i, line in enumerate(lines): From 48f45455bf1955ca1b2ba89bda256af2803a7126 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 26 Mar 2021 16:17:30 +1300 Subject: [PATCH 18/20] Convert CONFIG_MISC_INIT_F to Kconfig This converts the following to Kconfig: CONFIG_MISC_INIT_F Signed-off-by: Simon Glass Reviewed-by: Stefan Roese --- common/Kconfig | 6 ++++++ configs/MPC8349ITXGP_defconfig | 1 + configs/MPC8349ITX_LOWBOOT_defconfig | 1 + configs/MPC8349ITX_defconfig | 1 + configs/kmcoge4_defconfig | 1 + configs/sandbox64_defconfig | 2 +- configs/sandbox_defconfig | 1 + configs/sandbox_flattree_defconfig | 2 +- configs/sandbox_spl_defconfig | 2 ++ configs/tools-only_defconfig | 1 + include/configs/MPC8349ITX.h | 2 -- include/configs/kmp204x.h | 2 -- include/configs/sandbox.h | 2 -- scripts/config_whitelist.txt | 1 - 14 files changed, 16 insertions(+), 9 deletions(-) diff --git a/common/Kconfig b/common/Kconfig index 482f123534..0e36dfd236 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -527,6 +527,12 @@ config LAST_STAGE_INIT U-Boot calls last_stage_init() before the command-line interpreter is started. +config MISC_INIT_F + bool "Execute pre-relocation misc init" + help + Enabling this option calls the 'misc_init_f' function in the init + sequence just before DRAM is inited. + config MISC_INIT_R bool "Execute Misc Init" default y if ARCH_KEYSTONE || ARCH_SUNXI || MPC85xx diff --git a/configs/MPC8349ITXGP_defconfig b/configs/MPC8349ITXGP_defconfig index 28e4ebf06f..92f2093bb6 100644 --- a/configs/MPC8349ITXGP_defconfig +++ b/configs/MPC8349ITXGP_defconfig @@ -154,6 +154,7 @@ CONFIG_SYS_EXTRA_OPTIONS="SYS_TEXT_BASE=0xFE000000" CONFIG_BOOTDELAY=6 CONFIG_USE_BOOTARGS=y CONFIG_BOOTARGS="root=/dev/nfs rw nfsroot=:/nfsroot/rootfs ip=::::mpc8349emitxgp:eth0:off console=ttyS0,115200" +CONFIG_MISC_INIT_F=y CONFIG_MISC_INIT_R=y CONFIG_HUSH_PARSER=y CONFIG_SYS_PROMPT="MPC8349E-mITX-GP> " diff --git a/configs/MPC8349ITX_LOWBOOT_defconfig b/configs/MPC8349ITX_LOWBOOT_defconfig index 46f7afc071..cf1e90d619 100644 --- a/configs/MPC8349ITX_LOWBOOT_defconfig +++ b/configs/MPC8349ITX_LOWBOOT_defconfig @@ -153,6 +153,7 @@ CONFIG_OF_STDOUT_VIA_ALIAS=y CONFIG_BOOTDELAY=6 CONFIG_USE_BOOTARGS=y CONFIG_BOOTARGS="root=/dev/nfs rw nfsroot=:/nfsroot/rootfs ip=::::mpc8349emitx:eth0:off console=ttyS0,115200" +CONFIG_MISC_INIT_F=y CONFIG_MISC_INIT_R=y CONFIG_HUSH_PARSER=y CONFIG_SYS_PROMPT="MPC8349E-mITX> " diff --git a/configs/MPC8349ITX_defconfig b/configs/MPC8349ITX_defconfig index 1f70b756b0..733e5d3599 100644 --- a/configs/MPC8349ITX_defconfig +++ b/configs/MPC8349ITX_defconfig @@ -152,6 +152,7 @@ CONFIG_OF_STDOUT_VIA_ALIAS=y CONFIG_BOOTDELAY=6 CONFIG_USE_BOOTARGS=y CONFIG_BOOTARGS="root=/dev/nfs rw nfsroot=:/nfsroot/rootfs ip=::::mpc8349emitx:eth0:off console=ttyS0,115200" +CONFIG_MISC_INIT_F=y CONFIG_MISC_INIT_R=y CONFIG_HUSH_PARSER=y CONFIG_SYS_PROMPT="MPC8349E-mITX> " diff --git a/configs/kmcoge4_defconfig b/configs/kmcoge4_defconfig index ddc8f8a7f9..462e567796 100644 --- a/configs/kmcoge4_defconfig +++ b/configs/kmcoge4_defconfig @@ -20,6 +20,7 @@ CONFIG_AUTOBOOT_STOP_STR=" " CONFIG_BOARD_EARLY_INIT_F=y CONFIG_BOARD_EARLY_INIT_R=y CONFIG_LAST_STAGE_INIT=y +CONFIG_MISC_INIT_F=y CONFIG_HUSH_PARSER=y CONFIG_CMD_ASKENV=y CONFIG_CMD_GREPENV=y diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index cfda83474b..4648808d51 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -20,8 +20,8 @@ CONFIG_BOOTSTAGE_STASH_SIZE=0x4096 CONFIG_CONSOLE_RECORD=y CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000 CONFIG_PRE_CONSOLE_BUFFER=y -CONFIG_LOG_SYSLOG=y CONFIG_DISPLAY_BOARDINFO_LATE=y +CONFIG_MISC_INIT_F=y CONFIG_CMD_CPU=y CONFIG_CMD_LICENSE=y CONFIG_CMD_BOOTZ=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 5bc90d09a8..5da8d1679e 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -24,6 +24,7 @@ CONFIG_PRE_CONSOLE_BUFFER=y CONFIG_LOG_SYSLOG=y CONFIG_LOG_ERROR_RETURN=y CONFIG_DISPLAY_BOARDINFO_LATE=y +CONFIG_MISC_INIT_F=y CONFIG_ANDROID_AB=y CONFIG_CMD_CPU=y CONFIG_CMD_LICENSE=y diff --git a/configs/sandbox_flattree_defconfig b/configs/sandbox_flattree_defconfig index 4401f33f0b..b68f938cb3 100644 --- a/configs/sandbox_flattree_defconfig +++ b/configs/sandbox_flattree_defconfig @@ -17,8 +17,8 @@ CONFIG_BOOTSTAGE_STASH=y CONFIG_BOOTSTAGE_STASH_SIZE=0x4096 CONFIG_CONSOLE_RECORD=y CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000 -CONFIG_LOG_SYSLOG=y CONFIG_DISPLAY_BOARDINFO_LATE=y +CONFIG_MISC_INIT_F=y CONFIG_CMD_CPU=y CONFIG_CMD_LICENSE=y CONFIG_CMD_BOOTZ=y diff --git a/configs/sandbox_spl_defconfig b/configs/sandbox_spl_defconfig index ac71cab5f1..0e40b17c62 100644 --- a/configs/sandbox_spl_defconfig +++ b/configs/sandbox_spl_defconfig @@ -11,6 +11,7 @@ CONFIG_SPL_SYS_MALLOC_F_LEN=0x8000 CONFIG_SPL=y CONFIG_BOOTSTAGE_STASH_ADDR=0x0 CONFIG_DEFAULT_DEVICE_TREE="sandbox" +CONFIG_TARGET_SANDBOX_SPL=y CONFIG_SANDBOX_SPL=y CONFIG_DEBUG_UART=y CONFIG_DISTRO_DEFAULTS=y @@ -27,6 +28,7 @@ CONFIG_BOOTSTAGE_STASH_SIZE=0x4096 CONFIG_CONSOLE_RECORD=y CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000 CONFIG_DISPLAY_BOARDINFO_LATE=y +CONFIG_MISC_INIT_F=y CONFIG_HANDOFF=y CONFIG_SPL_BOARD_INIT=y CONFIG_SPL_ENV_SUPPORT=y diff --git a/configs/tools-only_defconfig b/configs/tools-only_defconfig index a853abf2b8..e16f702f00 100644 --- a/configs/tools-only_defconfig +++ b/configs/tools-only_defconfig @@ -4,6 +4,7 @@ CONFIG_DEFAULT_DEVICE_TREE="sandbox" CONFIG_ANDROID_BOOT_IMAGE=y CONFIG_FIT=y CONFIG_FIT_SIGNATURE=y +CONFIG_MISC_INIT_F=y # CONFIG_CMD_BOOTD is not set # CONFIG_CMD_BOOTM is not set # CONFIG_CMD_ELF is not set diff --git a/include/configs/MPC8349ITX.h b/include/configs/MPC8349ITX.h index f50cdd717c..586c1e9ae8 100644 --- a/include/configs/MPC8349ITX.h +++ b/include/configs/MPC8349ITX.h @@ -39,8 +39,6 @@ #ifndef __CONFIG_H #define __CONFIG_H -#define CONFIG_MISC_INIT_F - /* * On-board devices */ diff --git a/include/configs/kmp204x.h b/include/configs/kmp204x.h index 90e3702bd8..af3b03be49 100644 --- a/include/configs/kmp204x.h +++ b/include/configs/kmp204x.h @@ -177,8 +177,6 @@ unsigned long get_board_sys_clk(unsigned long dummy); #define CONFIG_SYS_BR1_PRELIM CONFIG_SYS_QRIO_BR_PRELIM /* QRIO Base Address */ #define CONFIG_SYS_OR1_PRELIM CONFIG_SYS_QRIO_OR_PRELIM /* QRIO Options */ -#define CONFIG_MISC_INIT_F - #define CONFIG_HWCONFIG /* define to use L1 as initial stack */ diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h index e0708fe573..bbb7d12ad1 100644 --- a/include/configs/sandbox.h +++ b/include/configs/sandbox.h @@ -130,6 +130,4 @@ #define CONFIG_SYS_SATA_MAX_DEVICE 2 -#define CONFIG_MISC_INIT_F - #endif diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt index 85857a746c..b693925d20 100644 --- a/scripts/config_whitelist.txt +++ b/scripts/config_whitelist.txt @@ -1030,7 +1030,6 @@ CONFIG_MIPS_HUGE_TLB_SUPPORT CONFIG_MIPS_MT_FPAFF CONFIG_MIRQ_EN CONFIG_MISC_COMMON -CONFIG_MISC_INIT_F CONFIG_MIU_1BIT_INTERLEAVED CONFIG_MIU_2BIT_21_7_INTERLEAVED CONFIG_MIU_2BIT_INTERLEAVED From 4c30d18ed38c5ae84ed91da0f9d1ba4c9e83bffc Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 28 Mar 2021 11:05:00 +0200 Subject: [PATCH 19/20] sandbox: document parameters of os_realloc() Avoid 'make htmldocs' build warnings: ./include/os.h:139: warning: Function parameter or member 'ptr' not described in 'os_realloc' ./include/os.h:139: warning: Function parameter or member 'length' not described in 'os_realloc' Fixes: 14e46dfb176b ("sandbox: Add os_realloc()") Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- include/os.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/os.h b/include/os.h index 77d8bd89d0..bd1096eb8b 100644 --- a/include/os.h +++ b/include/os.h @@ -134,7 +134,9 @@ void os_free(void *ptr); * This follows the semantics of realloc(), so can perform an os_malloc() or * os_free() depending on @ptr and @length. * - * Return: Pointer to reallocated memory or NULL if @length is 0 + * @ptr: pointer to previously allocated memory of NULL + * @length: number of bytes to allocate + * Return: pointer to reallocated memory or NULL if @length is 0 */ void *os_realloc(void *ptr, size_t length); From d4a1592a9908f4278f306ff9f11e63c010e05704 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 25 Mar 2021 10:44:33 +1300 Subject: [PATCH 20/20] test: Allow tests to run on any board Due to a recent change, tests are limited to running on sandbox only. Correct this so that any architecture can run them. Signed-off-by: Simon Glass Reported-by: Sean Anderson Fixes: c79705ea938 ("test: Move dm_test_init() into test-main.c") Tested-by: Sean Anderson --- include/test/test.h | 9 +++++++++ test/test-main.c | 5 ++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/test/test.h b/include/test/test.h index 0b124edd60..bf7d785d8e 100644 --- a/include/test/test.h +++ b/include/test/test.h @@ -124,4 +124,13 @@ enum { */ struct udevice *testbus_get_clear_removed(void); +static inline void arch_reset_for_test(void) +{ +#ifdef CONFIG_SANDBOX +#include + + state_reset_for_test(state_get_current()); +#endif +} + #endif /* __TEST_TEST_H */ diff --git a/test/test-main.c b/test/test-main.c index 46a0c2ee2f..8c852d72f4 100644 --- a/test/test-main.c +++ b/test/test-main.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -46,9 +45,9 @@ static int dm_test_pre_run(struct unit_test_state *uts) uts->force_fail_alloc = false; uts->skip_post_probe = false; gd->dm_root = NULL; - if (!CONFIG_IS_ENABLED(OF_PLATDATA)) + if (IS_ENABLED(CONFIG_UT_DM) && !CONFIG_IS_ENABLED(OF_PLATDATA)) memset(dm_testdrv_op_count, '\0', sizeof(dm_testdrv_op_count)); - state_reset_for_test(state_get_current()); + arch_reset_for_test(); /* Determine whether to make the live tree available */ gd_set_of_root(of_live ? uts->of_root : NULL);