From sha at pengutronix.de  Mon Apr  3 00:03:29 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Mon, 3 Apr 2023 09:03:29 +0200
Subject: [PATCH v2 1/4] firmware: Add request/release_firmware() calls
In-Reply-To: <20230330124643.3562397-1-p.zabel@pengutronix.de>
References: <20230330124643.3562397-1-p.zabel@pengutronix.de>
Message-ID: <20230403070329.GM19113@pengutronix.de>

On Thu, Mar 30, 2023 at 02:46:40PM +0200, Philipp Zabel wrote:
> Add request_firmware() and release_firmware() calls that allow drivers
> to load a firmware file. Also move the struct firmware definition from
> remoteproc.h into firmware.h.
> 
> Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
> Reviewed-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
> v2:
> - let request_firmware() stub return -EINVAL instead of -EOPNOTSUPP
> - drop spurious #include <unistd.h>
> ---
>  common/firmware.c          | 32 ++++++++++++++++++++++++++++++++
>  include/firmware.h         | 16 ++++++++++++++++
>  include/linux/remoteproc.h |  5 -----
>  3 files changed, 48 insertions(+), 5 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/common/firmware.c b/common/firmware.c
> index e4ad6ac867b0..6dc621d3081d 100644
> --- a/common/firmware.c
> +++ b/common/firmware.c
> @@ -304,6 +304,38 @@ out:
>  	return ret;
>  }
>  
> +/*
> + * request_firmware - load a firmware to a device
> + */
> +int request_firmware(const struct firmware **out, const char *fw_name, struct device *dev)
> +{
> +	char fw_path[PATH_MAX + 1];
> +	struct firmware *fw;
> +	int ret;
> +
> +	fw = kzalloc(sizeof(struct firmware), GFP_KERNEL);
> +	if (!fw)
> +		return -ENOMEM;
> +
> +	snprintf(fw_path, sizeof(fw_path), "%s/%s", firmware_path, fw_name);
> +
> +	ret = read_file_2(fw_path, &fw->size, (void *)&fw->data, FILESIZE_MAX);
> +	if (ret) {
> +		kfree(fw);
> +		return ret;
> +	}
> +
> +	*out = fw;
> +
> +	return 0;
> +}
> +
> +void release_firmware(const struct firmware *fw)
> +{
> +	kfree_const(fw->data);
> +	kfree_const(fw);
> +}
> +
>  static int firmware_init(void)
>  {
>  	firmware_path = strdup("/env/firmware");
> diff --git a/include/firmware.h b/include/firmware.h
> index 05433f2f7858..93c800e11bfd 100644
> --- a/include/firmware.h
> +++ b/include/firmware.h
> @@ -13,6 +13,11 @@
>  #include <debug_ll.h>
>  #include <linux/kernel.h>
>  
> +struct firmware {
> +	size_t size;
> +	const u8 *data;
> +};
> +
>  struct firmware_handler {
>  	char *id; /* unique identifier for this firmware device */
>  	char *model; /* description for this device */
> @@ -37,6 +42,8 @@ struct firmware_mgr *firmwaremgr_find_by_node(struct device_node *np);
>  int firmwaremgr_load_file(struct firmware_mgr *, const char *path);
>  char *firmware_get_searchpath(void);
>  void firmware_set_searchpath(const char *path);
> +int request_firmware(const struct firmware **fw, const char *fw_name, struct device *dev);
> +void release_firmware(const struct firmware *fw);
>  #else
>  static inline struct firmware_mgr *firmwaremgr_find_by_node(struct device_node *np)
>  {
> @@ -57,6 +64,15 @@ static inline void firmware_set_searchpath(const char *path)
>  {
>  }
>  
> +static inline int request_firmware(const struct firmware **fw, const char *fw_name,
> +				   struct device *dev)
> +{
> +	return -EINVAL;
> +}
> +
> +static inline void release_firmware(const struct firmware *fw)
> +{
> +}
>  #endif
>  
>  void firmwaremgr_list_handlers(void);
> diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
> index 170fff7987fb..33fe2f81b748 100644
> --- a/include/linux/remoteproc.h
> +++ b/include/linux/remoteproc.h
> @@ -18,11 +18,6 @@ struct resource_table {
>  	u32 offset[0];
>  } __packed;
>  
> -struct firmware {
> -	size_t size;
> -	const u8 *data;
> -};
> -
>  struct rproc;
>  
>  struct rproc_ops {
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Mon Apr  3 00:04:13 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Mon, 3 Apr 2023 09:04:13 +0200
Subject: [PATCH] common: state: make barebox-state enabling in Kconfig
 easier
In-Reply-To: <20230331143130.1903540-1-a.fatoum@pengutronix.de>
References: <20230331143130.1903540-1-a.fatoum@pengutronix.de>
Message-ID: <20230403070413.GN19113@pengutronix.de>

On Fri, Mar 31, 2023 at 04:31:30PM +0200, Ahmad Fatoum wrote:
> CONFIG_STATE only enables the framework, but practically all users
> interact with the framework via the device tree binding, which has a
> separate symbol. Make barebox state enabling easier by automatically
> enabling STATE_DRV and CMD_STATE if possible when STATE itself is
> enabled. They can still be disabled for configurations that don't
> need them.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  common/Kconfig | 2 ++
>  1 file changed, 2 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/common/Kconfig b/common/Kconfig
> index 57fe5f7886de..d951947463a2 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -1016,6 +1016,8 @@ config STATE
>  	select ENVIRONMENT_VARIABLES
>  	select OFTREE
>  	select PARAMETER
> +	imply STATE_DRV
> +	imply CMD_STATE
>  	help
>  	  barebox state is a generic framework for atomic power fail-safe
>  	  variable storage and retrieval. It can be used to safely maintain
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Mon Apr  3 00:04:40 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Mon, 3 Apr 2023 09:04:40 +0200
Subject: [PATCH master] pinctrl: stm32: Remove check for pins-are-numbered
In-Reply-To: <20230331103123.1525200-1-a.fatoum@pengutronix.de>
References: <20230331103123.1525200-1-a.fatoum@pengutronix.de>
Message-ID: <20230403070440.GO19113@pengutronix.de>

On Fri, Mar 31, 2023 at 12:31:23PM +0200, Ahmad Fatoum wrote:
> Upstream has dropped this property from the device trees that we import,
> so drop our check for it to fix boot up on STM32MP1.
> 
> Link: https://lore.kernel.org/all/20221129023401.278780-3-bero at baylibre.com/
> Fixes: 03b1dd74aa6e ("dts: update to v6.3-rc1")
> Reported-by: David Jander <david at protonic.nl>
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  drivers/pinctrl/pinctrl-stm32.c | 5 -----
>  1 file changed, 5 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/pinctrl/pinctrl-stm32.c b/drivers/pinctrl/pinctrl-stm32.c
> index 15d845e0ad34..1eed5473f6e0 100644
> --- a/drivers/pinctrl/pinctrl-stm32.c
> +++ b/drivers/pinctrl/pinctrl-stm32.c
> @@ -348,11 +348,6 @@ static int stm32_pinctrl_probe(struct device *dev)
>  	struct device_node *np = dev->of_node, *child;
>  	int ret;
>  
> -	if (!of_find_property(np, "pins-are-numbered", NULL)) {
> -		dev_err(dev, "only pins-are-numbered format supported\n");
> -		return -EINVAL;
> -	}
> -
>  	for_each_available_child_of_node(np, child)
>  		if (of_property_read_bool(child, "gpio-controller"))
>  			nbanks++;
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Mon Apr  3 00:05:27 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Mon, 3 Apr 2023 09:05:27 +0200
Subject: [PATCH] of: implement of_property_present helper
In-Reply-To: <20230331090453.1424337-1-a.fatoum@pengutronix.de>
References: <20230331090453.1424337-1-a.fatoum@pengutronix.de>
Message-ID: <20230403070527.GP19113@pengutronix.de>

On Fri, Mar 31, 2023 at 11:04:53AM +0200, Ahmad Fatoum wrote:
> We have various code using of_find_property(np, propname, NULL) to
> detect whether propname exists and some more that uses
> of_property_read_bool on non-boolean properties.
> 
> There's work underway in Linux to switch a lot of these instances to
> of_property_present[1]. Let's prepare for porting Linux code that
> uses the property by adding it.
> 
> [1]: https://lore.kernel.org/linux-devicetree/?q=of_property_present
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  include/of.h | 20 ++++++++++++++++++--
>  1 file changed, 18 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/include/of.h b/include/of.h
> index 3fb6ecec8dfe..22358f5579ec 100644
> --- a/include/of.h
> +++ b/include/of.h
> @@ -1038,8 +1038,10 @@ static inline int of_property_read_string_index(const struct device_node *np,
>   * @np:		device node from which the property value is to be read.
>   * @propname:	name of the property to be searched.
>   *
> - * Search for a property in a device node.
> - * Returns true if the property exist false otherwise.
> + * Search for a boolean property in a device node. Usage on non-boolean
> + * property types is deprecated.
> +
> + * Return: true if the property exist false otherwise.
>   */
>  static inline bool of_property_read_bool(const struct device_node *np,
>  					 const char *propname)
> @@ -1049,6 +1051,20 @@ static inline bool of_property_read_bool(const struct device_node *np,
>  	return prop ? true : false;
>  }
>  
> +/**
> + * of_property_present - Test if a property is present in a node
> + * @np:		device node to search for the property.
> + * @propname:	name of the property to be searched.
> + *
> + * Test for a property present in a device node.
> + *
> + * Return: true if the property exists false otherwise.
> + */
> +static inline bool of_property_present(const struct device_node *np, const char *propname)
> +{
> +	return of_property_read_bool(np, propname);
> +}
> +
>  static inline int of_property_read_u8(const struct device_node *np,
>  				       const char *propname,
>  				       u8 *out_value)
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Mon Apr  3 00:11:05 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Mon, 3 Apr 2023 09:11:05 +0200
Subject: [PATCH next v2] arm: rockchip: add support for CM3 on IO board
In-Reply-To: <20230330161101.58529-1-r.czerwinski@pengutronix.de>
References: <20230330161101.58529-1-r.czerwinski@pengutronix.de>
Message-ID: <20230403071105.GQ19113@pengutronix.de>

On Thu, Mar 30, 2023 at 06:11:01PM +0200, Rouven Czerwinski wrote:
> From: Rouven Czerwinski <rouven at czerwinskis.de>
> 
> Working:
> - RKBIN DDR training (rk3566_ddr_1056MHz_v1.13.bin)
> - RKBIN TF-A (v1.34) from RKBIN
> - Environment storage
> - DHCP, ping and link detection
> 
> Signed-off-by: Rouven Czerwinski <rouven at czerwinskis.de>
> ---
> v2:
> - rebase on next and adjust to RK356x changes
> - update rockchip boards documentation
> 
> +	memory at a00000 {
> +		device_type = "memory";
> +		reg = <0x0 0x00a00000 0x0 0x7f600000>;
> +	};

Now that we have a driver reading back the memory settings from the
controller this shouldn't be needed anymore. I dropped the memory node
while applying, please check if it works.

Sascha


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Mon Apr  3 00:12:01 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Mon, 3 Apr 2023 09:12:01 +0200
Subject: [PATCH 2/4] spi: stm32: support per-transfer bits per word
 switching
In-Reply-To: <20230330145309.GA7856@pengutronix.de>
References: <20230330103359.2751080-1-p.zabel@pengutronix.de>
 <20230330103359.2751080-2-p.zabel@pengutronix.de>
 <20230330145309.GA7856@pengutronix.de>
Message-ID: <20230403071201.GR19113@pengutronix.de>

On Thu, Mar 30, 2023 at 04:53:09PM +0200, Philipp Zabel wrote:
> On Thu, Mar 30, 2023 at 12:33:57PM +0200, Philipp Zabel wrote:
> > Allow dynamically switching data size between transfers.
> > 
> > Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
> > ---
> >  drivers/spi/stm32_spi.c | 50 ++++++++++++++++++++++++++++++++---------
> >  1 file changed, 39 insertions(+), 11 deletions(-)
> > 
> > diff --git a/drivers/spi/stm32_spi.c b/drivers/spi/stm32_spi.c
> > index 0d7407c279a2..1ac86fbe11e6 100644
> > --- a/drivers/spi/stm32_spi.c
> > +++ b/drivers/spi/stm32_spi.c
> [...]
> > @@ -543,6 +570,7 @@ static int stm32_spi_probe(struct device *dev)
> >  	master->transfer = stm32_spi_transfer;
> >  	master->mem_ops = &stm32_spi_mem_ops;
> >  
> > +	master->bits_per_word_mask = stm32_spi_get_bpw_mask(priv);
> 
> This has to be moved down a few lines, after the clock is enabled and
> the device is reset. I'll fix this in v2.

Please do so. Otherwise the series looks good to me.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Mon Apr  3 00:32:02 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Mon, 3 Apr 2023 09:32:02 +0200
Subject: [PATCH v2 0/6] ARM: Rockchip: Read amount of memory from DDR
 controller
In-Reply-To: <2b65b588-aa9c-b6c7-a020-807ccea5dc58@wolfvision.net>
References: <20230328074037.1202993-1-s.hauer@pengutronix.de>
 <2b65b588-aa9c-b6c7-a020-807ccea5dc58@wolfvision.net>
Message-ID: <20230403073202.GS19113@pengutronix.de>

On Fri, Mar 31, 2023 at 05:42:54PM +0200, Michael Riesch wrote:
> Hi Sascha,
> 
> On 3/28/23 09:40, Sascha Hauer wrote:
> > This series adds support for reading the amount of memory from
> > the DDR controller. This helps on boards which come with
> > different amounts of memory like the Radxa Rock3a.
> > 
> > This series also fixes issues with an upstream TF-A firmware. With this
> > the IRAM where the bootsource is stored is no longer accessible in
> > normal mode. We have to read its contents before starting the TF-A.
> > For this it became necessary to add a common barebox entry function
> > for rk3568, to get a common place to read the IRAM contents.
> 
> Nice, thanks for your efforts! Now it should be possible to remove the
> memory nodes from arch/arm/dts/rk356*, right?
> 
> I tried this on a ROCK3A with 8 GB and the memory calculation returned
> the correct result. There are now two ram devices
> 
>    `-- mem0
>       `-- 0x00000000-0x10fffffff (   4.3 GiB): /dev/ram1
>    `-- mem1
>       `-- 0x00000000-0xef5fffff (   3.7 GiB): /dev/ram0
>    `-- mem2
>       `-- 0x00000000-0xffffffffffffffff (   0 Bytes): /dev/mem

At first sight I was a bit puzzled that both memory regions start a 0x0.
That's correct for the devinfo output of course. The output of 'iomem'
would show the situation better here.

> 
> that start at SZ_4G and 0xa00000, respectively.
> 
> However, after loading the kernel the system hangs:
> 
> Loaded kernel to 0x100000000, devicetree at 0x101970000
> 
> Is this a bug in barebox or is something special required to boot the
> kernel from SZ_4G?

I would have guessed that barebox puts the kernel below the malloc area
just as usual. Ok, apparently it doesn't. I haven't found anything in
Documentation/arm64/booting.rst that forbids placing the kernel above
the 32bit boundary. You could verify that the memory nodes barebox
writes meet your expectations by adding some -v to the boot command.
Also earlycon might help to get some output from the kernel.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From michael.riesch at wolfvision.net  Mon Apr  3 03:04:08 2023
From: michael.riesch at wolfvision.net (Michael Riesch)
Date: Mon, 3 Apr 2023 12:04:08 +0200
Subject: [PATCH v2 0/6] ARM: Rockchip: Read amount of memory from DDR
 controller
In-Reply-To: <20230403073202.GS19113@pengutronix.de>
References: <20230328074037.1202993-1-s.hauer@pengutronix.de>
 <2b65b588-aa9c-b6c7-a020-807ccea5dc58@wolfvision.net>
 <20230403073202.GS19113@pengutronix.de>
Message-ID: <ffd88538-ddb2-3b0b-0ca7-3d6bc2533caf@wolfvision.net>

Hi Sascha,

On 4/3/23 09:32, Sascha Hauer wrote:
> On Fri, Mar 31, 2023 at 05:42:54PM +0200, Michael Riesch wrote:
>> Hi Sascha,
>>
>> On 3/28/23 09:40, Sascha Hauer wrote:
>>> This series adds support for reading the amount of memory from
>>> the DDR controller. This helps on boards which come with
>>> different amounts of memory like the Radxa Rock3a.
>>>
>>> This series also fixes issues with an upstream TF-A firmware. With this
>>> the IRAM where the bootsource is stored is no longer accessible in
>>> normal mode. We have to read its contents before starting the TF-A.
>>> For this it became necessary to add a common barebox entry function
>>> for rk3568, to get a common place to read the IRAM contents.
>>
>> Nice, thanks for your efforts! Now it should be possible to remove the
>> memory nodes from arch/arm/dts/rk356*, right?
>>
>> I tried this on a ROCK3A with 8 GB and the memory calculation returned
>> the correct result. There are now two ram devices
>>
>>    `-- mem0
>>       `-- 0x00000000-0x10fffffff (   4.3 GiB): /dev/ram1
>>    `-- mem1
>>       `-- 0x00000000-0xef5fffff (   3.7 GiB): /dev/ram0
>>    `-- mem2
>>       `-- 0x00000000-0xffffffffffffffff (   0 Bytes): /dev/mem
> 
> At first sight I was a bit puzzled that both memory regions start a 0x0.
> That's correct for the devinfo output of course. The output of 'iomem'
> would show the situation better here.

barebox at Radxa ROCK3 Model A:/ iomem
0x0000000000000000 - 0xffffffffffffffff (size 0x0000000000000000) iomem
  0x0000000000a00000 - 0x00000000efffffff (size 0x00000000ef600000) ram0
    0x00000000afcf0e00 - 0x00000000efcf0dff (size 0x0000000040000000)
malloc space
    0x00000000efcf0e00 - 0x00000000efcfffd1 (size 0x000000000000f1d2)
board data
    0x00000000efd00000 - 0x00000000efd99a4f (size 0x0000000000099a50)
barebox
    0x00000000efd99a50 - 0x00000000efde59ff (size 0x000000000004bfb0)
barebox data
    0x00000000efde5a00 - 0x00000000efde8d57 (size 0x0000000000003358) bss
    0x00000000effe8000 - 0x00000000effeffff (size 0x0000000000008000) stack
  0x00000000fd000000 - 0x00000000fd3fffff (size 0x0000000000400000) xHCI0
  0x00000000fdd40000 - 0x00000000fdd40fff (size 0x0000000000001000)
fdd40000.i2c at fdd40000.of
  0x00000000fdd60000 - 0x00000000fdd600ff (size 0x0000000000000100)
pinctrl.of
  0x00000000fe000000 - 0x00000000fe003fff (size 0x0000000000004000)
fe000000.mmc at fe000000.of
  0x00000000fe010000 - 0x00000000fe01ffff (size 0x0000000000010000)
fe010000.ethernet at fe010000.of
  0x00000000fe2b0000 - 0x00000000fe2b3fff (size 0x0000000000004000)
fe2b0000.mmc at fe2b0000.of
  0x00000000fe310000 - 0x00000000fe31ffff (size 0x0000000000010000)
fe310000.mmc at fe310000.of
  0x00000000fe5e0000 - 0x00000000fe5e0fff (size 0x0000000000001000)
fe5e0000.i2c at fe5e0000.of
  0x00000000fe650000 - 0x00000000fe6500ff (size 0x0000000000000100)
fe650000.serial at fe650000.of
  0x00000000fe660000 - 0x00000000fe6600ff (size 0x0000000000000100)
fe660000.serial at fe660000.of
  0x00000000fe720000 - 0x00000000fe7200ff (size 0x0000000000000100)
fe720000.saradc at fe720000.of
  0x00000000fe740000 - 0x00000000fe7400ff (size 0x0000000000000100)
pinctrl.of
  0x00000000fe750000 - 0x00000000fe7500ff (size 0x0000000000000100)
pinctrl.of
  0x00000000fe760000 - 0x00000000fe7600ff (size 0x0000000000000100)
pinctrl.of
  0x00000000fe770000 - 0x00000000fe7700ff (size 0x0000000000000100)
pinctrl.of
  0x00000000fe820000 - 0x00000000fe8200ff (size 0x0000000000000100)
fe820000.phy at fe820000.of
  0x00000000fe830000 - 0x00000000fe8300ff (size 0x0000000000000100)
fe830000.phy at fe830000.of
  0x00000000fe840000 - 0x00000000fe8400ff (size 0x0000000000000100)
fe840000.phy at fe840000.of
  0x00000000fe8a0000 - 0x00000000fe8affff (size 0x0000000000010000)
fe8a0000.usb2phy at fe8a0000.of
  0x00000000fe8b0000 - 0x00000000fe8bffff (size 0x0000000000010000)
fe8b0000.usb2phy at fe8b0000.of
  0x0000000100000000 - 0x000000020fffffff (size 0x0000000110000000) ram1
barebox at Radxa ROCK3 Model A:/

>> that start at SZ_4G and 0xa00000, respectively.
>>
>> However, after loading the kernel the system hangs:
>>
>> Loaded kernel to 0x100000000, devicetree at 0x101970000
>>
>> Is this a bug in barebox or is something special required to boot the
>> kernel from SZ_4G?
> 
> I would have guessed that barebox puts the kernel below the malloc area
> just as usual. Ok, apparently it doesn't. I haven't found anything in
> Documentation/arm64/booting.rst that forbids placing the kernel above
> the 32bit boundary. You could verify that the memory nodes barebox
> writes meet your expectations by adding some -v to the boot command.
> Also earlycon might help to get some output from the kernel.

After having a quick look at booti.c I think that
memory_bank_first_find_space is invoked to determine the start address.
Apparently, this returns the start and end of ram1. I tried to override
the start and end variables with the boundaries of ram0, which caused
the kernel to boot from 0xa00000 but didn't bring any further success.

With the earlycon parameter set, the boot log now shows:

Loaded kernel to 0x00a00000, devicetree at 0x02370000
[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x412fd050]
[    0.000000] Linux version 6.3.0-rc2-20230316-1+ (ptxdist at ptxdist)
(aarch64-v8a-linux-gnu-gcc (OSELAS.0
[    0.000000] Machine model: Radxa ROCK3 Model A
[    0.000000] earlycon: uart0 at MMIO32 0x00000000fe660000 (options
'1500000n8')
[    0.000000] printk: bootconsole [uart0] enabled
[    0.000000] SError Interrupt on CPU0, code 0x00000000be000011 -- SError
[    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted
6.3.0-rc2-20230316-1+ #17
[    0.000000] Hardware name: Radxa ROCK3 Model A (DT)
[    0.000000] pstate: 200000c9 (nzCv daIF -PAN -UAO -TCO -DIT -SSBS
BTYPE=--)
[    0.000000] pc : __memset+0x16c/0x188
[    0.000000] lr : early_pgtable_alloc+0xb0/0x130
[    0.000000] sp : ffffffc009753b10
[    0.000000] x29: ffffffc009753b10 x28: 0000000000000000 x27:
0000000000a10000
[    0.000000] x26: ffffffc008c9ffff x25: ffffffc008010000 x24:
0000000000000000
[    0.000000] x23: ffffffc008010000 x22: fffffffdfda36000 x21:
ffffffc0097dd000
[    0.000000] x20: 000000020ffff000 x19: caaead2f6f13289c x18:
0000000000000000
[    0.000000] x17: 386e303030303035 x16: 312720736e6f6974 x15:
0000000000000000
[    0.000000] x14: 0000000000000000 x13: 0000000000000000 x12:
000000000002667a
[    0.000000] x11: 656c6f736e6f6374 x10: ffffffc007600000 x9 :
0000000000000000
[    0.000000] x8 : fffffffdfda39780 x7 : 0000000000000000 x6 :
000000000000003f
[    0.000000] x5 : 0000000000000040 x4 : 0000000000000000 x3 :
0000000000000004
[    0.000000] x2 : 0000000000000840 x1 : 0000000000000000 x0 :
fffffffdfda39000
[    0.000000] Kernel panic - not syncing: Asynchronous SError Interrupt
[    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted
6.3.0-rc2-20230316-1+ #17
[    0.000000] Hardware name: Radxa ROCK3 Model A (DT)
[    0.000000] Call trace:
[    0.000000]  dump_backtrace+0xb4/0x138
[    0.000000]  show_stack+0x30/0x48
[    0.000000]  dump_stack_lvl+0x60/0xb0
[    0.000000]  dump_stack+0x18/0x28
[    0.000000]  panic+0x394/0x3a8
[    0.000000]  nmi_panic+0xbc/0xc8
[    0.000000]  arm64_serror_panic+0x6c/0x88
[    0.000000]  do_serror+0x44/0x88
[    0.000000]  el1h_64_error_handler+0x38/0x50
[    0.000000]  el1h_64_error+0x64/0x68
[    0.000000]  __memset+0x16c/0x188
[    0.000000]  create_kpti_ng_temp_pgd+0x110/0x640
[    0.000000]  map_kernel_segment+0xd0/0x1b0
[    0.000000]  paging_init+0x1c8/0xdb0
[    0.000000]  setup_arch+0x3c8/0xa40
[    0.000000]  start_kernel+0xe0/0xcf8
[    0.000000]  __primary_switched+0xb4/0xc8

and boot -vvvv prints the memory nodes:

        memory at 100000000 {
                device_type = "memory";
                reg = <0x1 0x0 0x1 0x10000000>;
        };
        memory at a00000 {
                device_type = "memory";
                reg = <0x0 0xa00000 0x0 0xef600000>;
        };

FWIW: I commented out the arm_add_mem_device call for ram1. With that
change, only the memory at a00000 is appended and the kernel boots normally
on the ROCK3A 8GB.

Thanks and best regards,
Michael


From p.zabel at pengutronix.de  Mon Apr  3 04:53:38 2023
From: p.zabel at pengutronix.de (Philipp Zabel)
Date: Mon,  3 Apr 2023 13:53:38 +0200
Subject: [PATCH v2 2/4] spi: stm32: support per-transfer bits per word switching
In-Reply-To: <20230403115340.3416720-1-p.zabel@pengutronix.de>
References: <20230403115340.3416720-1-p.zabel@pengutronix.de>
Message-ID: <20230403115340.3416720-2-p.zabel@pengutronix.de>

Allow dynamically switching data size between transfers.

Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
---
v2: query max bits-per-word after clk_enable() and device_reset()
---
 drivers/spi/stm32_spi.c | 50 ++++++++++++++++++++++++++++++++---------
 1 file changed, 39 insertions(+), 11 deletions(-)

diff --git a/drivers/spi/stm32_spi.c b/drivers/spi/stm32_spi.c
index 0d7407c279a2..bdaeb6b5d0e5 100644
--- a/drivers/spi/stm32_spi.c
+++ b/drivers/spi/stm32_spi.c
@@ -111,6 +111,24 @@ static inline struct stm32_spi_priv *to_stm32_spi_priv(struct spi_master *master
 	return container_of(master, struct stm32_spi_priv, master);
 }
 
+static int stm32_spi_get_bpw_mask(struct stm32_spi_priv *priv)
+{
+	u32 cfg1, max_bpw;
+
+	/*
+	 * The most significant bit at DSIZE bit field is reserved when the
+	 * maximum data size of periperal instances is limited to 16-bit
+	 */
+	setbits_le32(priv->base + STM32_SPI_CFG1, SPI_CFG1_DSIZE);
+
+	cfg1 = readl(priv->base + STM32_SPI_CFG1);
+	max_bpw = FIELD_GET(SPI_CFG1_DSIZE, cfg1) + 1;
+
+	dev_dbg(priv->master.dev, "%d-bit maximum data frame\n", max_bpw);
+
+	return SPI_BPW_RANGE_MASK(4, max_bpw);
+}
+
 static void stm32_spi_write_txfifo(struct stm32_spi_priv *priv)
 {
 	while ((priv->tx_len > 0) &&
@@ -261,19 +279,15 @@ static void stm32_spi_set_mode(struct stm32_spi_priv *priv, unsigned mode)
 
 static void stm32_spi_set_fthlv(struct stm32_spi_priv *priv, u32 xfer_len)
 {
-	u32 fthlv, half_fifo;
+	u32 fthlv, packet, bpw;
 
 	/* data packet should not exceed 1/2 of fifo space */
-	half_fifo = (priv->fifo_size / 2);
-
-	/* data_packet should not exceed transfer length */
-	fthlv = (half_fifo > xfer_len) ? xfer_len : half_fifo;
+	packet = clamp(xfer_len, 1U, priv->fifo_size / 2);
 
 	/* align packet size with data registers access */
-	fthlv -= (fthlv % 4);
+	bpw = DIV_ROUND_UP(priv->cur_bpw, 8);
+	fthlv = DIV_ROUND_UP(packet, bpw);
 
-	if (!fthlv)
-		fthlv = 1;
 	clrsetbits_le32(priv->base + STM32_SPI_CFG1, SPI_CFG1_FTHLV,
 			(fthlv - 1) << SPI_CFG1_FTHLV_SHIFT);
 }
@@ -344,9 +358,17 @@ static int stm32_spi_transfer_one(struct stm32_spi_priv *priv,
 	u32 ifcr = 0;
 	u32 mode;
 	int xfer_status = 0;
+	int nb_words;
 
-	if (t->len <= SPI_CR2_TSIZE)
-		writel(t->len, priv->base + STM32_SPI_CR2);
+	if (t->bits_per_word <= 8)
+		nb_words = t->len;
+	else if (t->bits_per_word <= 16)
+		nb_words = DIV_ROUND_UP(t->len * 8, 16);
+	else
+		nb_words = DIV_ROUND_UP(t->len * 8, 32);
+
+	if (nb_words <= SPI_CR2_TSIZE)
+		writel(nb_words, priv->base + STM32_SPI_CR2);
 	else
 		return -EMSGSIZE;
 
@@ -361,9 +383,11 @@ static int stm32_spi_transfer_one(struct stm32_spi_priv *priv,
 	else if (!priv->rx_buf)
 		mode = SPI_SIMPLEX_TX;
 
-	if (priv->cur_xferlen != t->len || priv->cur_mode != mode) {
+	if (priv->cur_xferlen != t->len || priv->cur_mode != mode ||
+	    priv->cur_bpw != t->bits_per_word) {
 		priv->cur_mode = mode;
 		priv->cur_xferlen = t->len;
+		priv->cur_bpw = t->bits_per_word;
 
 		/* Disable the SPI hardware to unlock CFG1/CFG2 registers */
 		stm32_spi_disable(priv);
@@ -373,6 +397,9 @@ static int stm32_spi_transfer_one(struct stm32_spi_priv *priv,
 
 		stm32_spi_set_fthlv(priv, t->len);
 
+		clrsetbits_le32(priv->base + STM32_SPI_CFG1, SPI_CFG1_DSIZE,
+				priv->cur_bpw - 1);
+
 		/* Enable the SPI hardware */
 		stm32_spi_enable(priv);
 	}
@@ -560,6 +587,7 @@ static int stm32_spi_probe(struct device *dev)
 	if (ret)
 		return ret;
 
+	master->bits_per_word_mask = stm32_spi_get_bpw_mask(priv);
 	priv->fifo_size = stm32_spi_get_fifo_size(priv);
 
 	priv->cur_mode = SPI_FULL_DUPLEX;
-- 
2.39.2



From p.zabel at pengutronix.de  Mon Apr  3 04:53:40 2023
From: p.zabel at pengutronix.de (Philipp Zabel)
Date: Mon,  3 Apr 2023 13:53:40 +0200
Subject: [PATCH v2 4/4] spi: update spi_board_info FIXME comment
In-Reply-To: <20230403115340.3416720-1-p.zabel@pengutronix.de>
References: <20230403115340.3416720-1-p.zabel@pengutronix.de>
Message-ID: <20230403115340.3416720-4-p.zabel@pengutronix.de>

The spi-stm32 driver now supports the spi_transfer.bits_per_word
override.

Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
---
 include/spi/spi.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/spi/spi.h b/include/spi/spi.h
index 809ebd8df1a8..d479e4f34f0c 100644
--- a/include/spi/spi.h
+++ b/include/spi/spi.h
@@ -44,7 +44,7 @@ struct spi_board_info {
  *	This may be changed by the device's driver, or left at the
  *	default (0) indicating protocol words are eight bit bytes.
  *	The spi_transfer.bits_per_word can override this for each transfer
- *	(FIXME: not currently implemented).
+ *	(FIXME: not currently implemented by most drivers).
  * @irq: Negative, or the number passed to request_irq() to receive
  *	interrupts from this device.
  * @controller_state: Controller's runtime state
-- 
2.39.2



From p.zabel at pengutronix.de  Mon Apr  3 04:53:39 2023
From: p.zabel at pengutronix.de (Philipp Zabel)
Date: Mon,  3 Apr 2023 13:53:39 +0200
Subject: [PATCH v2 3/4] video: mipi_dbi: disable byte swapping if 16-bit SPI transfers are supported
In-Reply-To: <20230403115340.3416720-1-p.zabel@pengutronix.de>
References: <20230403115340.3416720-1-p.zabel@pengutronix.de>
Message-ID: <20230403115340.3416720-3-p.zabel@pengutronix.de>

If the SPI controller supports switching to 16-bit transfers, there
is no need to swap bytes on little-endian architectures. This also
allows to transfer directly from the 16-bit framebuffer.

Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
---
 drivers/video/mipi_dbi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/video/mipi_dbi.c b/drivers/video/mipi_dbi.c
index 61b0fbcc49c6..aab6b1243954 100644
--- a/drivers/video/mipi_dbi.c
+++ b/drivers/video/mipi_dbi.c
@@ -632,8 +632,7 @@ int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *dbi,
 
 	dbi->command = mipi_dbi_typec3_command;
 	dbi->dc = dc;
-	// TODO: can we just force 16 bit?
-	if (mipi_dbi_machine_little_endian() && spi->bits_per_word != 16)
+	if (mipi_dbi_machine_little_endian() && !spi_is_bpw_supported(spi, 16))
 		dbi->swap_bytes = true;
 
 	dev_dbg(dev, "SPI speed: %uMHz\n", spi->max_speed_hz / 1000000);
-- 
2.39.2



From p.zabel at pengutronix.de  Mon Apr  3 04:53:37 2023
From: p.zabel at pengutronix.de (Philipp Zabel)
Date: Mon,  3 Apr 2023 13:53:37 +0200
Subject: [PATCH v2 1/4] spi: add per-driver bits-per-word mask
Message-ID: <20230403115340.3416720-1-p.zabel@pengutronix.de>

Allow SPI hosts to signal per-transfer bits-per-word switching
support and drivers to query it with spi_is_bpw_supported().

Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
---
 include/spi/spi.h | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/include/spi/spi.h b/include/spi/spi.h
index fa9329b08c80..809ebd8df1a8 100644
--- a/include/spi/spi.h
+++ b/include/spi/spi.h
@@ -131,6 +131,11 @@ struct spi_message;
  *	SPI slaves, and are numbered from zero to num_chipselects.
  *	each slave has a chipselect signal, but it's common that not
  *	every chipselect is connected to a slave.
+ * @bits_per_word_mask: A mask indicating which values of bits_per_word are
+ *	supported by the driver. Bit n indicates that a bits_per_word n+1 is
+ *	supported. If set, the SPI core will reject any transfer with an
+ *	unsupported bits_per_word. If not set, this value is simply ignored,
+ *	and it's up to the individual driver to perform any validation.
  * @max_speed_hz: Highest supported transfer speed
  * @setup: updates the device mode and clocking records used by a
  *	device's SPI controller; protocol code may call this.  This
@@ -165,6 +170,12 @@ struct spi_controller {
 
 	/* Optimized handlers for SPI memory-like operations */
 	const struct spi_controller_mem_ops *mem_ops;
+
+	/* Bitmask of supported bits_per_word for transfers */
+	u32			bits_per_word_mask;
+#define SPI_BPW_MASK(bits) BIT((bits) - 1)
+#define SPI_BPW_RANGE_MASK(min, max) GENMASK((max) - 1, (min) - 1)
+
 	/*
 	 * on some hardware transfer size may be constrained
 	 * the limit may depend on device transfer settings
@@ -435,6 +446,26 @@ spi_transfer_del(struct spi_transfer *t)
 	list_del(&t->transfer_list);
 }
 
+/**
+ * spi_is_bpw_supported - Check if bits per word is supported
+ * @spi: SPI device
+ * @bpw: Bits per word
+ *
+ * This function checks to see if the SPI controller supports @bpw.
+ *
+ * Returns:
+ * True if @bpw is supported, false otherwise.
+ */
+static inline bool spi_is_bpw_supported(struct spi_device *spi, u32 bpw)
+{
+	u32 bpw_mask = spi->master->bits_per_word_mask;
+
+	if (bpw == 8 || (bpw <= 32 && bpw_mask & SPI_BPW_MASK(bpw)))
+		return true;
+
+	return false;
+}
+
 /* All these synchronous SPI transfer routines are utilities layered
  * over the core async transfer primitive.  Here, "synchronous" means
  * they will sleep uninterruptibly until the async transfer completes.
-- 
2.39.2



From p.zabel at pengutronix.de  Mon Apr  3 05:18:42 2023
From: p.zabel at pengutronix.de (Philipp Zabel)
Date: Mon,  3 Apr 2023 14:18:42 +0200
Subject: [PATCH 1/3] video: fb: add optional damage tracking
Message-ID: <20230403121844.3447836-1-p.zabel@pengutronix.de>

Add an optional fb_damage operation that drivers may use to accumulate
damage on the framebuffer until fb_flush is called. The accumulated
damage can be used to support partial updates for displays with an
integrated framebuffer.

Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
---
 drivers/video/fb.c | 6 ++++++
 include/fb.h       | 9 +++++++++
 2 files changed, 15 insertions(+)

diff --git a/drivers/video/fb.c b/drivers/video/fb.c
index 44754065e7d9..6f412d62c434 100644
--- a/drivers/video/fb.c
+++ b/drivers/video/fb.c
@@ -43,6 +43,12 @@ static int fb_close(struct cdev *cdev)
 	return 0;
 }
 
+void fb_damage(struct fb_info *info, struct fb_rect *rect)
+{
+	if (info->fbops->fb_damage)
+		info->fbops->fb_damage(info, rect);
+}
+
 static int fb_op_flush(struct cdev *cdev)
 {
 	struct fb_info *info = cdev->priv;
diff --git a/include/fb.h b/include/fb.h
index 15bb74b99576..4e3eb611db48 100644
--- a/include/fb.h
+++ b/include/fb.h
@@ -80,6 +80,13 @@ struct fb_bitfield {
 
 struct fb_info;
 
+struct fb_rect {
+	u32 x1;
+	u32 y1;
+	u32 x2;
+	u32 y2;
+};
+
 struct fb_ops {
 	/* set color register */
 	int (*fb_setcolreg)(unsigned regno, unsigned red, unsigned green,
@@ -87,6 +94,7 @@ struct fb_ops {
 	void (*fb_enable)(struct fb_info *info);
 	void (*fb_disable)(struct fb_info *info);
 	int (*fb_activate_var)(struct fb_info *info);
+	void (*fb_damage)(struct fb_info *info, struct fb_rect *rect);
 	void (*fb_flush)(struct fb_info *info);
 };
 
@@ -156,6 +164,7 @@ int register_framebuffer(struct fb_info *info);
 
 int fb_enable(struct fb_info *info);
 int fb_disable(struct fb_info *info);
+void fb_damage(struct fb_info *info, struct fb_rect *rect);
 void fb_flush(struct fb_info *info);
 
 #define FBIOGET_SCREENINFO	_IOR('F', 1, loff_t)
-- 
2.39.2



From p.zabel at pengutronix.de  Mon Apr  3 05:18:43 2023
From: p.zabel at pengutronix.de (Philipp Zabel)
Date: Mon,  3 Apr 2023 14:18:43 +0200
Subject: [PATCH 2/3] video: fbconsole: add optional damage tracking
In-Reply-To: <20230403121844.3447836-1-p.zabel@pengutronix.de>
References: <20230403121844.3447836-1-p.zabel@pengutronix.de>
Message-ID: <20230403121844.3447836-2-p.zabel@pengutronix.de>

Annotate framebuffer updates with damage rectangles so drivers may
implement partial updates for displays with an integrated framebuffer.

Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
---
 drivers/video/fbconsole.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 070378aa2352..25d7ea685ff6 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -18,6 +18,7 @@ enum state_t {
 struct fbc_priv {
 	struct console_device cdev;
 	struct fb_info *fb;
+	struct fb_rect rect;
 
 	struct screen *sc;
 
@@ -60,9 +61,11 @@ static int fbc_tstc(struct console_device *cdev)
 static void cls(struct fbc_priv *priv)
 {
 	void *buf = gui_screen_render_buffer(priv->sc);
+	struct fb_info *fb = priv->fb;
 
 	memset(buf, 0, priv->fb->line_length * priv->fb->yres);
 	gu_screen_blit(priv->sc);
+	fb_damage(fb, &priv->rect);
 }
 
 struct rgb {
@@ -139,13 +142,20 @@ static void drawchar(struct fbc_priv *priv, int x, int y, int c)
 static void video_invertchar(struct fbc_priv *priv, int x, int y)
 {
 	void *buf;
+	struct fb_rect rect;
+
+	rect.x1 = x * priv->font->width;
+	rect.y1 = y * priv->font->height;
+	rect.x2 = rect.x1 + priv->font->width;
+	rect.y2 = rect.y1 + priv->font->height;
 
 	buf = gui_screen_render_buffer(priv->sc);
 
-	gu_invert_area(priv->fb, buf, x * priv->font->width, y * priv->font->height,
+	gu_invert_area(priv->fb, buf, rect.x1, rect.y1,
 			priv->font->width, priv->font->height);
-	gu_screen_blit_area(priv->sc, x * priv->font->width, y * priv->font->height,
+	gu_screen_blit_area(priv->sc, rect.x1, rect.y1,
 			priv->font->width, priv->font->height);
+	fb_damage(priv->fb, &rect);
 }
 
 static void show_cursor(struct fbc_priv *priv, int x, int y)
@@ -156,6 +166,9 @@ static void show_cursor(struct fbc_priv *priv, int x, int y)
 
 static void printchar(struct fbc_priv *priv, int c)
 {
+	struct fb_info *fb = priv->fb;
+	struct fb_rect rect;
+
 	video_invertchar(priv, priv->x, priv->y);
 
 	switch (c) {
@@ -185,9 +198,14 @@ static void printchar(struct fbc_priv *priv, int c)
 	default:
 		drawchar(priv, priv->x, priv->y, c);
 
-		gu_screen_blit_area(priv->sc, priv->x * priv->font->width,
-				priv->y * priv->font->height,
+		rect.x1 = priv->x * priv->font->width;
+		rect.y1 = priv->y * priv->font->height;
+		rect.x2 =  rect.x1 + priv->font->width;
+		rect.y2 =  rect.y1 + priv->font->height;
+
+		gu_screen_blit_area(priv->sc, rect.x1, rect.y1,
 				priv->font->width, priv->font->height);
+		fb_damage(fb, &rect);
 
 		priv->x++;
 		if (priv->x > priv->cols) {
@@ -207,6 +225,7 @@ static void printchar(struct fbc_priv *priv, int c)
 		memset(buf + line_height * priv->rows, 0, line_height);
 
 		gu_screen_blit(priv->sc);
+		fb_damage(fb, &priv->rect);
 		priv->y = priv->rows;
 	}
 
@@ -508,6 +527,11 @@ int register_fbconsole(struct fb_info *fb)
 			set_font, NULL,
 			&priv->par_font_val, priv);
 
+	priv->rect.x1 = 0;
+	priv->rect.y1 = 0;
+	priv->rect.x2 = fb->xres;
+	priv->rect.y2 = fb->yres;
+
 	pr_info("registered as %s%d\n", cdev->class_dev.name, cdev->class_dev.id);
 
 	return 0;
-- 
2.39.2



From p.zabel at pengutronix.de  Mon Apr  3 05:18:44 2023
From: p.zabel at pengutronix.de (Philipp Zabel)
Date: Mon,  3 Apr 2023 14:18:44 +0200
Subject: [PATCH 3/3] video: mipi_dbi: add damage tracking and partial updates
In-Reply-To: <20230403121844.3447836-1-p.zabel@pengutronix.de>
References: <20230403121844.3447836-1-p.zabel@pengutronix.de>
Message-ID: <20230403121844.3447836-3-p.zabel@pengutronix.de>

Track framebuffer damage with a simple rectangle that can be used to
issue partial updates during fb_flush. This speeds up fbconsole.

Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
---
 drivers/video/mipi_dbi.c       | 83 ++++++++++++++++++++++++++++------
 drivers/video/panel-mipi-dbi.c |  1 +
 include/video/mipi_dbi.h       |  6 +++
 3 files changed, 75 insertions(+), 15 deletions(-)

diff --git a/drivers/video/mipi_dbi.c b/drivers/video/mipi_dbi.c
index 61b0fbcc49c6..3107725b224b 100644
--- a/drivers/video/mipi_dbi.c
+++ b/drivers/video/mipi_dbi.c
@@ -199,19 +199,33 @@ int mipi_dbi_command_stackbuf(struct mipi_dbi *dbi, u8 cmd, const u8 *data,
 EXPORT_SYMBOL(mipi_dbi_command_stackbuf);
 
 /**
- * mipi_dbi_buf_copy_swap - Copy a framebuffer swapping MSB/LSB of 16-bit values
+ * mipi_dbi_buf_copy - Copy a framebuffer, transforming it if necessary
  * @dst: The destination buffer
  * @info: The source framebuffer info
+ * @clip: Clipping rectangle of the area to be copied
+ * @swap: When true, swap MSB/LSB of 16-bit values
  */
-static void mipi_dbi_buf_copy_swap(u16 *dst, struct fb_info *info)
+static void mipi_dbi_buf_copy(u16 *dst, struct fb_info *info,
+			      struct fb_rect *clip, bool swap)
 {
 	u16 *src = (u16 *)info->screen_base;
-	size_t len = info->xres * info->yres;
-	int i;
+	unsigned int height = clip->y2 - clip->y1;
+	unsigned int width = clip->x2 - clip->x1;
+	int x, y;
 
-	for (i = 0; i < len; i++) {
-		*dst++ = *src << 8 | *src >> 8;
-		src++;
+	src += clip->y1 * info->xres + clip->x1;
+	if (swap) {
+		for (y = 0; y < height; y++) {
+			for (x = 0; x < width; x++)
+				*dst++ = src[x] << 8 | src[x] >> 8;
+			src += info->xres;
+		}
+	} else {
+		for (y = 0; y < height; y++) {
+			memcpy(dst, src, 2 * width);
+			dst += width;
+			src += info->xres;
+		}
 	}
 }
 
@@ -232,28 +246,38 @@ static void mipi_dbi_set_window_address(struct mipi_dbi_dev *dbidev,
 			 ys & 0xff, (ye >> 8) & 0xff, ye & 0xff);
 }
 
-static void mipi_dbi_fb_dirty(struct mipi_dbi_dev *dbidev, struct fb_info *info)
+static void mipi_dbi_fb_dirty(struct mipi_dbi_dev *dbidev, struct fb_info *info,
+			      struct fb_rect *rect)
 {
+	unsigned int height = rect->y2 - rect->y1;
+	unsigned int width = rect->x2 - rect->x1;
 	struct mipi_dbi *dbi = &dbidev->dbi;
-	unsigned int height = info->yres;
-	unsigned int width = info->xres;
 	bool swap = dbi->swap_bytes;
 	int ret;
+	bool full;
 	void *tr;
 
-	if (swap) {
+	full = width == info->xres && height == info->yres;
+
+	if (!full || swap) {
 		tr = dbidev->tx_buf;
-		mipi_dbi_buf_copy_swap(tr, info);
+		mipi_dbi_buf_copy(tr, info, rect, swap);
 	} else {
 		tr = info->screen_base;
 	}
 
-	mipi_dbi_set_window_address(dbidev, 0, width - 1, 0, height - 1);
+	mipi_dbi_set_window_address(dbidev, rect->x1, rect->x2 - 1, rect->y1,
+				    rect->y2 - 1);
 
 	ret = mipi_dbi_command_buf(dbi, MIPI_DCS_WRITE_MEMORY_START, tr,
 				   width * height * 2);
 	if (ret)
 		pr_err_once("Failed to update display %d\n", ret);
+
+	dbidev->damage.x1 = 0;
+	dbidev->damage.y1 = 0;
+	dbidev->damage.x2 = 0;
+	dbidev->damage.y2 = 0;
 }
 
 /**
@@ -267,7 +291,14 @@ static void mipi_dbi_fb_dirty(struct mipi_dbi_dev *dbidev, struct fb_info *info)
 void mipi_dbi_enable_flush(struct mipi_dbi_dev *dbidev,
 			   struct fb_info *info)
 {
-	mipi_dbi_fb_dirty(dbidev, info);
+	struct fb_rect rect = {
+		.x1 = 0,
+		.y1 = 0,
+		.x2 = info->xres,
+		.y2 = info->yres
+	};
+
+	mipi_dbi_fb_dirty(dbidev, info, &rect);
 
 	if (dbidev->backlight)
 		backlight_set_brightness_default(dbidev->backlight);
@@ -309,11 +340,33 @@ void mipi_dbi_fb_disable(struct fb_info *info)
 }
 EXPORT_SYMBOL(mipi_dbi_fb_disable);
 
+void mipi_dbi_fb_damage(struct fb_info *info, struct fb_rect *rect)
+{
+	struct mipi_dbi_dev *dbidev = container_of(info, struct mipi_dbi_dev, info);
+
+	if (dbidev->damage.x2 && dbidev->damage.y2) {
+		dbidev->damage.x1 = min(dbidev->damage.x1, rect->x1);
+		dbidev->damage.y1 = min(dbidev->damage.y1, rect->y1);
+		dbidev->damage.x2 = max(dbidev->damage.x2, rect->x2);
+		dbidev->damage.y2 = max(dbidev->damage.y2, rect->y2);
+	} else {
+		dbidev->damage = *rect;
+	}
+}
+EXPORT_SYMBOL(mipi_dbi_fb_damage);
+
 void mipi_dbi_fb_flush(struct fb_info *info)
 {
 	struct mipi_dbi_dev *dbidev = container_of(info, struct mipi_dbi_dev, info);
 
-	mipi_dbi_fb_dirty(dbidev, info);
+	if (!dbidev->damage.x2 || !dbidev->damage.y2) {
+		dbidev->damage.x1 = 0;
+		dbidev->damage.y1 = 0;
+		dbidev->damage.x2 = info->xres;
+		dbidev->damage.y2 = info->yres;
+	}
+
+	mipi_dbi_fb_dirty(dbidev, info, &dbidev->damage);
 }
 EXPORT_SYMBOL(mipi_dbi_fb_flush);
 
diff --git a/drivers/video/panel-mipi-dbi.c b/drivers/video/panel-mipi-dbi.c
index ac6f585be32c..7fada69d6f26 100644
--- a/drivers/video/panel-mipi-dbi.c
+++ b/drivers/video/panel-mipi-dbi.c
@@ -218,6 +218,7 @@ static void panel_mipi_dbi_enable(struct fb_info *info)
 static struct fb_ops panel_mipi_dbi_ops = {
 	.fb_enable = panel_mipi_dbi_enable,
 	.fb_disable = mipi_dbi_fb_disable,
+	.fb_damage = mipi_dbi_fb_damage,
 	.fb_flush = mipi_dbi_fb_flush,
 };
 
diff --git a/include/video/mipi_dbi.h b/include/video/mipi_dbi.h
index 917f7ddd597f..7bacd4a88bc7 100644
--- a/include/video/mipi_dbi.h
+++ b/include/video/mipi_dbi.h
@@ -109,6 +109,11 @@ struct mipi_dbi_dev {
 	 * @driver_private: Driver private data.
 	 */
 	void *driver_private;
+
+	/**
+	 * @damage: Damage rectangle.
+	 */
+	struct fb_rect damage;
 };
 
 static inline const char *mipi_dbi_name(struct mipi_dbi *dbi)
@@ -120,6 +125,7 @@ int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *dbi,
 		      int dc);
 int mipi_dbi_dev_init(struct mipi_dbi_dev *dbidev,
 		      struct fb_ops *ops, struct fb_videomode *mode);
+void mipi_dbi_fb_damage(struct fb_info *info, struct fb_rect *rect);
 void mipi_dbi_fb_flush(struct fb_info *info);
 void mipi_dbi_enable_flush(struct mipi_dbi_dev *dbidev,
 			   struct fb_info *info);
-- 
2.39.2



From m.felsch at pengutronix.de  Mon Apr  3 05:25:09 2023
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Mon,  3 Apr 2023 14:25:09 +0200
Subject: [PATCH] ARM: boards: protonic-imx6: fix bbu_handler device paths
Message-ID: <20230403122509.258800-1-m.felsch@pengutronix.de>

The update handler path must be a full-path starting at '/'. Fix this by
adding the '/dev/' path prefix.

Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
---
 arch/arm/boards/protonic-imx6/board.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
index d2fb25d3cc..0d57f409d2 100644
--- a/arch/arm/boards/protonic-imx6/board.c
+++ b/arch/arm/boards/protonic-imx6/board.c
@@ -530,7 +530,7 @@ static int prt_imx6_bbu(struct prt_imx6_priv *priv)
 		emmc_flags = BBU_HANDLER_FLAG_DEFAULT;
 	}
 
-	devicefile = basprintf("mmc%d", dcfg->emmc_usdhc);
+	devicefile = basprintf("/dev/mmc%d", dcfg->emmc_usdhc);
 	if (!devicefile) {
 		ret = -ENOMEM;
 		goto exit_bbu;
@@ -540,7 +540,7 @@ static int prt_imx6_bbu(struct prt_imx6_priv *priv)
 	if (ret)
 		goto exit_bbu;
 
-	devicefile = basprintf("mmc%d", dcfg->sd_usdhc);
+	devicefile = basprintf("/dev/mmc%d", dcfg->sd_usdhc);
 	if (!devicefile) {
 		ret = -ENOMEM;
 		goto exit_bbu;
-- 
2.39.2



From s.hauer at pengutronix.de  Mon Apr  3 12:43:39 2023
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 3 Apr 2023 21:43:39 +0200
Subject: [PATCH v2 2/6] ARM: Rockchip: implement memory read out from
 controller
In-Reply-To: <20230328074037.1202993-3-s.hauer@pengutronix.de>
References: <20230328074037.1202993-1-s.hauer@pengutronix.de>
 <20230328074037.1202993-3-s.hauer@pengutronix.de>
Message-ID: <20230403194339.GH15436@pengutronix.de>

On Tue, Mar 28, 2023 at 09:40:33AM +0200, Sascha Hauer wrote:
> From: Ahmad Fatoum <ahmad at a3f.at>
> 
> Add a driver to read out the amount of memory from the DDR controller.
> The decoding of the registers has been taken from U-Boot. Currently
> supported are the RK3399 and the RK3568, but decoding should work on
> other Rockchip SoCs as well.
> 

This patch needs an update. The RAM is divided into two parts, one below
the SoC internal register space and one starting at 4GiB up to the end.
The previous version assumed that the RAM address decoding skips
the internal register space, but it seems the internal register space
shadows the RAM behind it, so a board with 8GiB of memory has the
last address on 0x200000000-1 instead of 0x210000000-1 like the previous
version assumed.

----------------------------------8<----------------------------

>From bc9baa7ac71c4a8e75d000317d85d6bf6a85a8e4 Mon Sep 17 00:00:00 2001
From: Ahmad Fatoum <ahmad at a3f.at>
Date: Thu, 5 Jan 2023 08:34:40 +0100
Subject: [PATCH] ARM: Rockchip: implement memory read out from controller

Add a driver to read out the amount of memory from the DDR controller.
The decoding of the registers has been taken from U-Boot. Currently
supported are the RK3399 and the RK3568, but decoding should work on
other Rockchip SoCs as well.

Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-rockchip/Makefile     |   1 +
 arch/arm/mach-rockchip/dmc.c        | 219 ++++++++++++++++++++++++++++
 include/linux/sizes.h               |   3 +
 include/mach/rockchip/dmc.h         |  86 +++++++++++
 include/mach/rockchip/rk3399-regs.h |   1 +
 include/mach/rockchip/rk3568-regs.h |   1 +
 6 files changed, 311 insertions(+)
 create mode 100644 arch/arm/mach-rockchip/dmc.c
 create mode 100644 include/mach/rockchip/dmc.h

diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile
index 2529af7c7e..f6c575854e 100644
--- a/arch/arm/mach-rockchip/Makefile
+++ b/arch/arm/mach-rockchip/Makefile
@@ -6,4 +6,5 @@ obj-$(CONFIG_ARCH_RK3188) += rk3188.o
 obj-$(CONFIG_ARCH_RK3288) += rk3288.o
 obj-pbl-$(CONFIG_ARCH_RK3568) += rk3568.o
 obj-$(CONFIG_ARCH_ROCKCHIP_V8) += bootm.o
+obj-pbl-$(CONFIG_ARCH_ROCKCHIP_V8) += dmc.o
 obj-$(CONFIG_BAREBOX_UPDATE) += bbu.o
diff --git a/arch/arm/mach-rockchip/dmc.c b/arch/arm/mach-rockchip/dmc.c
new file mode 100644
index 0000000000..dd60db5830
--- /dev/null
+++ b/arch/arm/mach-rockchip/dmc.c
@@ -0,0 +1,219 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+#define pr_fmt(fmt) "rockchip-dmc: " fmt
+
+#include <common.h>
+#include <init.h>
+#include <asm/barebox-arm.h>
+#include <asm/memory.h>
+#include <pbl.h>
+#include <io.h>
+#include <regmap.h>
+#include <mfd/syscon.h>
+#include <mach/rockchip/dmc.h>
+#include <mach/rockchip/rk3399-regs.h>
+#include <mach/rockchip/rk3568-regs.h>
+
+#define RK3399_PMUGRF_OS_REG2		0x308
+#define RK3399_PMUGRF_OS_REG3		0x30C
+
+#define RK3568_PMUGRF_OS_REG2           0x208
+#define RK3568_PMUGRF_OS_REG3           0x20c
+
+#define RK3399_INT_REG_START		0xf0000000
+#define RK3568_INT_REG_START		RK3399_INT_REG_START
+
+struct rockchip_dmc_drvdata {
+	unsigned int os_reg2;
+	unsigned int os_reg3;
+	resource_size_t internal_registers_start;
+};
+
+static resource_size_t rockchip_sdram_size(u32 sys_reg2, u32 sys_reg3)
+{
+	u32 rank, cs0_col, bk, cs0_row, cs1_row, bw, row_3_4;
+	resource_size_t chipsize_mb, size_mb = 0;
+	u32 ch;
+	u32 cs1_col;
+	u32 bg = 0;
+	u32 dbw, dram_type;
+	u32 ch_num = 1 + FIELD_GET(SYS_REG_NUM_CH, sys_reg2);
+	u32 version = FIELD_GET(SYS_REG_VERSION, sys_reg3);
+
+	pr_debug("%s(reg2=%x, reg3=%x)\n", __func__, sys_reg2, sys_reg3);
+
+	dram_type = FIELD_GET(SYS_REG_DDRTYPE, sys_reg2);
+
+	if (version >= 3)
+		dram_type |= FIELD_GET(SYS_REG_EXTEND_DDRTYPE, sys_reg3) << 3;
+
+	for (ch = 0; ch < ch_num; ch++) {
+		rank = 1 + (sys_reg2 >> SYS_REG_RANK_SHIFT(ch) & SYS_REG_RANK_MASK);
+		cs0_col = 9 + (sys_reg2 >> SYS_REG_COL_SHIFT(ch) & SYS_REG_COL_MASK);
+		cs1_col = cs0_col;
+
+		bk = 3 - ((sys_reg2 >> SYS_REG_BK_SHIFT(ch)) & SYS_REG_BK_MASK);
+
+		cs0_row = sys_reg2 >> SYS_REG_CS0_ROW_SHIFT(ch) & SYS_REG_CS0_ROW_MASK;
+		cs1_row = sys_reg2 >> SYS_REG_CS1_ROW_SHIFT(ch) & SYS_REG_CS1_ROW_MASK;
+
+		if (version >= 2) {
+			cs1_col = 9 + (sys_reg3 >> SYS_REG_CS1_COL_SHIFT(ch) &
+				  SYS_REG_CS1_COL_MASK);
+
+			cs0_row |= (sys_reg3 >> SYS_REG_EXTEND_CS0_ROW_SHIFT(ch) &
+					SYS_REG_EXTEND_CS0_ROW_MASK) << 2;
+
+			if (cs0_row == 7)
+				cs0_row = 12;
+			else
+				cs0_row += 13;
+
+			cs1_row |= (sys_reg3 >> SYS_REG_EXTEND_CS1_ROW_SHIFT(ch) &
+					SYS_REG_EXTEND_CS1_ROW_MASK) << 2;
+
+			if (cs1_row == 7)
+				cs1_row = 12;
+			else
+				cs1_row += 13;
+		} else {
+			cs0_row += 13;
+			cs1_row += 13;
+		}
+
+		bw = (2 >> ((sys_reg2 >> SYS_REG_BW_SHIFT(ch)) & SYS_REG_BW_MASK));
+		row_3_4 = sys_reg2 >> SYS_REG_ROW_3_4_SHIFT(ch) & SYS_REG_ROW_3_4_MASK;
+
+		if (dram_type == DDR4) {
+			dbw = (sys_reg2 >> SYS_REG_DBW_SHIFT(ch)) & SYS_REG_DBW_MASK;
+			bg = (dbw == 2) ? 2 : 1;
+		}
+
+		chipsize_mb = (1 << (cs0_row + cs0_col + bk + bg + bw - 20));
+
+		if (rank > 1)
+			chipsize_mb += chipsize_mb >> ((cs0_row - cs1_row) +
+				       (cs0_col - cs1_col));
+		if (row_3_4)
+			chipsize_mb = chipsize_mb * 3 / 4;
+
+		size_mb += chipsize_mb;
+
+		if (rank > 1)
+			pr_debug("rank %d cs0_col %d cs1_col %d bk %d cs0_row %d "
+				 "cs1_row %d bw %d row_3_4 %d\n",
+				 rank, cs0_col, cs1_col, bk, cs0_row,
+				 cs1_row, bw, row_3_4);
+		else
+			pr_debug("rank %d cs0_col %d bk %d cs0_row %d "
+				 "bw %d row_3_4 %d\n",
+				 rank, cs0_col, bk, cs0_row,
+				 bw, row_3_4);
+	}
+
+	return (resource_size_t)size_mb << 20;
+}
+
+resource_size_t rk3399_ram0_size(void)
+{
+	void __iomem *pmugrf = IOMEM(RK3399_PMUGRF_BASE);
+	u32 sys_reg2, sys_reg3;
+	resource_size_t size;
+
+	sys_reg2 = readl(pmugrf + RK3399_PMUGRF_OS_REG2);
+	sys_reg3 = readl(pmugrf + RK3399_PMUGRF_OS_REG3);
+
+	size = rockchip_sdram_size(sys_reg2, sys_reg3);
+	size = min_t(resource_size_t, RK3399_INT_REG_START, size);
+
+	pr_debug("%s() = %llu\n", __func__, (u64)size);
+
+	return size;
+}
+
+resource_size_t rk3568_ram0_size(void)
+{
+	void __iomem *pmugrf = IOMEM(RK3568_PMUGRF_BASE);
+	u32 sys_reg2, sys_reg3;
+	resource_size_t size;
+
+	sys_reg2 = readl(pmugrf + RK3568_PMUGRF_OS_REG2);
+	sys_reg3 = readl(pmugrf + RK3568_PMUGRF_OS_REG3);
+
+	size = rockchip_sdram_size(sys_reg2, sys_reg3);
+	size = min_t(resource_size_t, RK3568_INT_REG_START, size);
+
+	pr_debug("%s() = %llu\n", __func__, (u64)size);
+
+	return size;
+}
+
+static int rockchip_dmc_probe(struct device *dev)
+{
+	const struct rockchip_dmc_drvdata *drvdata;
+	resource_size_t membase, memsize;
+	struct regmap *regmap;
+	u32 sys_reg2, sys_reg3;
+
+	regmap = syscon_regmap_lookup_by_phandle(dev->of_node, "rockchip,pmu");
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	drvdata = device_get_match_data(dev);
+	if (!drvdata)
+		return -ENOENT;
+
+	regmap_read(regmap, drvdata->os_reg2, &sys_reg2);
+	regmap_read(regmap, drvdata->os_reg3, &sys_reg3);
+
+	memsize = rockchip_sdram_size(sys_reg2, sys_reg3);
+
+	dev_info(dev, "Detected memory size: %pa\n", &memsize);
+
+	/* lowest 10M are shaved off for secure world firmware */
+	membase = 0xa00000;
+
+	/* ram0, from 0xa00000 up to SoC internal register space start */
+	arm_add_mem_device("ram0", membase,
+		min_t(resource_size_t, drvdata->internal_registers_start, memsize) - membase);
+
+	/* ram1, remaining RAM beyond 32bit space */
+	if (memsize > SZ_4G)
+		arm_add_mem_device("ram1", SZ_4G, memsize - SZ_4G);
+
+	return 0;
+}
+
+static const struct rockchip_dmc_drvdata rk3399_drvdata = {
+	.os_reg2 = RK3399_PMUGRF_OS_REG2,
+	.os_reg3 = RK3399_PMUGRF_OS_REG3,
+	.internal_registers_start = RK3399_INT_REG_START,
+};
+
+static const struct rockchip_dmc_drvdata rk3568_drvdata = {
+	.os_reg2 = RK3568_PMUGRF_OS_REG2,
+	.os_reg3 = RK3568_PMUGRF_OS_REG3,
+	.internal_registers_start = RK3568_INT_REG_START,
+};
+
+static struct of_device_id rockchip_dmc_dt_ids[] = {
+	{
+		.compatible = "rockchip,rk3399-dmc",
+		.data = &rk3399_drvdata,
+	},
+	{
+		.compatible = "rockchip,rk3568-dmc",
+		.data = &rk3568_drvdata,
+	},
+	{ /* sentinel */ }
+};
+
+static struct driver rockchip_dmc_driver = {
+	.name   = "rockchip-dmc",
+	.probe  = rockchip_dmc_probe,
+	.of_compatible = rockchip_dmc_dt_ids,
+};
+mem_platform_driver(rockchip_dmc_driver);
diff --git a/include/linux/sizes.h b/include/linux/sizes.h
index fbde0bc7e8..1d222daeab 100644
--- a/include/linux/sizes.h
+++ b/include/linux/sizes.h
@@ -47,5 +47,8 @@
 #define SZ_2G				0x80000000
 
 #define SZ_4G				_AC(0x100000000, ULL)
+#define SZ_8G				_AC(0x200000000, ULL)
+#define SZ_16G				_AC(0x400000000, ULL)
+#define SZ_32G				_AC(0x800000000, ULL)
 
 #endif /* __LINUX_SIZES_H__ */
diff --git a/include/mach/rockchip/dmc.h b/include/mach/rockchip/dmc.h
new file mode 100644
index 0000000000..ff197d50a0
--- /dev/null
+++ b/include/mach/rockchip/dmc.h
@@ -0,0 +1,86 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
+ */
+
+#ifndef _MACH_ROCKCHIP_DMC_H
+#define _MACH_ROCKCHIP_DMC_H
+
+#include <linux/compiler.h>
+#include <linux/types.h>
+#include <linux/bitfield.h>
+
+enum {
+	DDR4 = 0,
+	DDR3 = 0x3,
+	LPDDR2 = 0x5,
+	LPDDR3 = 0x6,
+	LPDDR4 = 0x7,
+	UNUSED = 0xFF
+};
+
+/*
+ * sys_reg2 bitfield struct
+ * [31]		row_3_4_ch1
+ * [30]		row_3_4_ch0
+ * [29:28]	chinfo
+ * [27]		rank_ch1
+ * [26:25]	col_ch1
+ * [24]		bk_ch1
+ * [23:22]	low bits of cs0_row_ch1
+ * [21:20]	low bits of cs1_row_ch1
+ * [19:18]	bw_ch1
+ * [17:16]	dbw_ch1;
+ * [15:13]	ddrtype
+ * [12]		channelnum
+ * [11]		rank_ch0
+ * [10:9]	col_ch0,
+ * [8]		bk_ch0
+ * [7:6]	low bits of cs0_row_ch0
+ * [5:4]	low bits of cs1_row_ch0
+ * [3:2]	bw_ch0
+ * [1:0]	dbw_ch0
+ */
+
+#define SYS_REG_DDRTYPE			GENMASK(15, 13)
+#define SYS_REG_NUM_CH			BIT(12)
+#define SYS_REG_ROW_3_4_SHIFT(ch)	(30 + (ch))
+#define SYS_REG_ROW_3_4_MASK		1
+#define SYS_REG_CHINFO_SHIFT(ch)	(28 + (ch))
+#define SYS_REG_RANK_SHIFT(ch)		(11 + (ch) * 16)
+#define SYS_REG_RANK_MASK		1
+#define SYS_REG_COL_SHIFT(ch)		(9 + (ch) * 16)
+#define SYS_REG_COL_MASK		3
+#define SYS_REG_BK_SHIFT(ch)		(8 + (ch) * 16)
+#define SYS_REG_BK_MASK			1
+#define SYS_REG_CS0_ROW_SHIFT(ch)	(6 + (ch) * 16)
+#define SYS_REG_CS0_ROW_MASK		3
+#define SYS_REG_CS1_ROW_SHIFT(ch)	(4 + (ch) * 16)
+#define SYS_REG_CS1_ROW_MASK		3
+#define SYS_REG_BW_SHIFT(ch)		(2 + (ch) * 16)
+#define SYS_REG_BW_MASK			3
+#define SYS_REG_DBW_SHIFT(ch)		((ch) * 16)
+#define SYS_REG_DBW_MASK		3
+
+/*
+ * sys_reg3 bitfield struct
+ * [7]		high bit of cs0_row_ch1
+ * [6]		high bit of cs1_row_ch1
+ * [5]		high bit of cs0_row_ch0
+ * [4]		high bit of cs1_row_ch0
+ * [3:2]	cs1_col_ch1
+ * [1:0]	cs1_col_ch0
+ */
+#define SYS_REG_VERSION				GENMASK(31, 28)
+#define SYS_REG_EXTEND_DDRTYPE			GENMASK(13, 12)
+#define SYS_REG_EXTEND_CS0_ROW_SHIFT(ch)	(5 + (ch) * 2)
+#define SYS_REG_EXTEND_CS0_ROW_MASK		1
+#define SYS_REG_EXTEND_CS1_ROW_SHIFT(ch)	(4 + (ch) * 2)
+#define SYS_REG_EXTEND_CS1_ROW_MASK		1
+#define SYS_REG_CS1_COL_SHIFT(ch)		(0 + (ch) * 2)
+#define SYS_REG_CS1_COL_MASK			3
+
+resource_size_t rk3399_ram0_size(void);
+resource_size_t rk3568_ram0_size(void);
+
+#endif
diff --git a/include/mach/rockchip/rk3399-regs.h b/include/mach/rockchip/rk3399-regs.h
index 57033b6510..6db082da9b 100644
--- a/include/mach/rockchip/rk3399-regs.h
+++ b/include/mach/rockchip/rk3399-regs.h
@@ -10,6 +10,7 @@
 #define RK3399_UART3_BASE	0xff1b0000
 #define RK3399_UART4_BASE	0xff370000
 
+#define RK3399_PMUGRF_BASE	0xff320000
 #define RK3399_IRAM_BASE	0xff8c0000
 #define RK3399_STIMER_BASE	0xff8680a0
 
diff --git a/include/mach/rockchip/rk3568-regs.h b/include/mach/rockchip/rk3568-regs.h
index edd5ee268d..55d28790dd 100644
--- a/include/mach/rockchip/rk3568-regs.h
+++ b/include/mach/rockchip/rk3568-regs.h
@@ -16,5 +16,6 @@
 #define RK3568_UART9_BASE	0xfe6d0000
 
 #define RK3568_IRAM_BASE	0xfdcc0000
+#define RK3568_PMUGRF_BASE	0xfdc20000
 
 #endif /* __MACH_RK3568_REGS_H */
-- 
2.39.2

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From michael.riesch at wolfvision.net  Mon Apr  3 23:25:47 2023
From: michael.riesch at wolfvision.net (Michael Riesch)
Date: Tue, 4 Apr 2023 08:25:47 +0200
Subject: [PATCH v2 2/6] ARM: Rockchip: implement memory read out from
 controller
In-Reply-To: <20230403194339.GH15436@pengutronix.de>
References: <20230328074037.1202993-1-s.hauer@pengutronix.de>
 <20230328074037.1202993-3-s.hauer@pengutronix.de>
 <20230403194339.GH15436@pengutronix.de>
Message-ID: <94991d12-6b3d-ef27-82eb-cf6ac0d22109@wolfvision.net>

Hi Sascha,

On 4/3/23 21:43, Sascha Hauer wrote:
> On Tue, Mar 28, 2023 at 09:40:33AM +0200, Sascha Hauer wrote:
>> From: Ahmad Fatoum <ahmad at a3f.at>
>>
>> Add a driver to read out the amount of memory from the DDR controller.
>> The decoding of the registers has been taken from U-Boot. Currently
>> supported are the RK3399 and the RK3568, but decoding should work on
>> other Rockchip SoCs as well.
>>
> 
> This patch needs an update. The RAM is divided into two parts, one below
> the SoC internal register space and one starting at 4GiB up to the end.
> The previous version assumed that the RAM address decoding skips
> the internal register space, but it seems the internal register space
> shadows the RAM behind it, so a board with 8GiB of memory has the
> last address on 0x200000000-1 instead of 0x210000000-1 like the previous
> version assumed.
> 
> ----------------------------------8<----------------------------

With this version of the patch Linux boots normally on my ROCK3A 8GB.
Thanks a lot!

Best regards,
Michael

> 
> From bc9baa7ac71c4a8e75d000317d85d6bf6a85a8e4 Mon Sep 17 00:00:00 2001
> From: Ahmad Fatoum <ahmad at a3f.at>
> Date: Thu, 5 Jan 2023 08:34:40 +0100
> Subject: [PATCH] ARM: Rockchip: implement memory read out from controller
> 
> Add a driver to read out the amount of memory from the DDR controller.
> The decoding of the registers has been taken from U-Boot. Currently
> supported are the RK3399 and the RK3568, but decoding should work on
> other Rockchip SoCs as well.
> 
> Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  arch/arm/mach-rockchip/Makefile     |   1 +
>  arch/arm/mach-rockchip/dmc.c        | 219 ++++++++++++++++++++++++++++
>  include/linux/sizes.h               |   3 +
>  include/mach/rockchip/dmc.h         |  86 +++++++++++
>  include/mach/rockchip/rk3399-regs.h |   1 +
>  include/mach/rockchip/rk3568-regs.h |   1 +
>  6 files changed, 311 insertions(+)
>  create mode 100644 arch/arm/mach-rockchip/dmc.c
>  create mode 100644 include/mach/rockchip/dmc.h
> 
> diff --git a/arch/arm/mach-rockchip/Makefile b/arch/arm/mach-rockchip/Makefile
> index 2529af7c7e..f6c575854e 100644
> --- a/arch/arm/mach-rockchip/Makefile
> +++ b/arch/arm/mach-rockchip/Makefile
> @@ -6,4 +6,5 @@ obj-$(CONFIG_ARCH_RK3188) += rk3188.o
>  obj-$(CONFIG_ARCH_RK3288) += rk3288.o
>  obj-pbl-$(CONFIG_ARCH_RK3568) += rk3568.o
>  obj-$(CONFIG_ARCH_ROCKCHIP_V8) += bootm.o
> +obj-pbl-$(CONFIG_ARCH_ROCKCHIP_V8) += dmc.o
>  obj-$(CONFIG_BAREBOX_UPDATE) += bbu.o
> diff --git a/arch/arm/mach-rockchip/dmc.c b/arch/arm/mach-rockchip/dmc.c
> new file mode 100644
> index 0000000000..dd60db5830
> --- /dev/null
> +++ b/arch/arm/mach-rockchip/dmc.c
> @@ -0,0 +1,219 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
> + */
> +
> +#define pr_fmt(fmt) "rockchip-dmc: " fmt
> +
> +#include <common.h>
> +#include <init.h>
> +#include <asm/barebox-arm.h>
> +#include <asm/memory.h>
> +#include <pbl.h>
> +#include <io.h>
> +#include <regmap.h>
> +#include <mfd/syscon.h>
> +#include <mach/rockchip/dmc.h>
> +#include <mach/rockchip/rk3399-regs.h>
> +#include <mach/rockchip/rk3568-regs.h>
> +
> +#define RK3399_PMUGRF_OS_REG2		0x308
> +#define RK3399_PMUGRF_OS_REG3		0x30C
> +
> +#define RK3568_PMUGRF_OS_REG2           0x208
> +#define RK3568_PMUGRF_OS_REG3           0x20c
> +
> +#define RK3399_INT_REG_START		0xf0000000
> +#define RK3568_INT_REG_START		RK3399_INT_REG_START
> +
> +struct rockchip_dmc_drvdata {
> +	unsigned int os_reg2;
> +	unsigned int os_reg3;
> +	resource_size_t internal_registers_start;
> +};
> +
> +static resource_size_t rockchip_sdram_size(u32 sys_reg2, u32 sys_reg3)
> +{
> +	u32 rank, cs0_col, bk, cs0_row, cs1_row, bw, row_3_4;
> +	resource_size_t chipsize_mb, size_mb = 0;
> +	u32 ch;
> +	u32 cs1_col;
> +	u32 bg = 0;
> +	u32 dbw, dram_type;
> +	u32 ch_num = 1 + FIELD_GET(SYS_REG_NUM_CH, sys_reg2);
> +	u32 version = FIELD_GET(SYS_REG_VERSION, sys_reg3);
> +
> +	pr_debug("%s(reg2=%x, reg3=%x)\n", __func__, sys_reg2, sys_reg3);
> +
> +	dram_type = FIELD_GET(SYS_REG_DDRTYPE, sys_reg2);
> +
> +	if (version >= 3)
> +		dram_type |= FIELD_GET(SYS_REG_EXTEND_DDRTYPE, sys_reg3) << 3;
> +
> +	for (ch = 0; ch < ch_num; ch++) {
> +		rank = 1 + (sys_reg2 >> SYS_REG_RANK_SHIFT(ch) & SYS_REG_RANK_MASK);
> +		cs0_col = 9 + (sys_reg2 >> SYS_REG_COL_SHIFT(ch) & SYS_REG_COL_MASK);
> +		cs1_col = cs0_col;
> +
> +		bk = 3 - ((sys_reg2 >> SYS_REG_BK_SHIFT(ch)) & SYS_REG_BK_MASK);
> +
> +		cs0_row = sys_reg2 >> SYS_REG_CS0_ROW_SHIFT(ch) & SYS_REG_CS0_ROW_MASK;
> +		cs1_row = sys_reg2 >> SYS_REG_CS1_ROW_SHIFT(ch) & SYS_REG_CS1_ROW_MASK;
> +
> +		if (version >= 2) {
> +			cs1_col = 9 + (sys_reg3 >> SYS_REG_CS1_COL_SHIFT(ch) &
> +				  SYS_REG_CS1_COL_MASK);
> +
> +			cs0_row |= (sys_reg3 >> SYS_REG_EXTEND_CS0_ROW_SHIFT(ch) &
> +					SYS_REG_EXTEND_CS0_ROW_MASK) << 2;
> +
> +			if (cs0_row == 7)
> +				cs0_row = 12;
> +			else
> +				cs0_row += 13;
> +
> +			cs1_row |= (sys_reg3 >> SYS_REG_EXTEND_CS1_ROW_SHIFT(ch) &
> +					SYS_REG_EXTEND_CS1_ROW_MASK) << 2;
> +
> +			if (cs1_row == 7)
> +				cs1_row = 12;
> +			else
> +				cs1_row += 13;
> +		} else {
> +			cs0_row += 13;
> +			cs1_row += 13;
> +		}
> +
> +		bw = (2 >> ((sys_reg2 >> SYS_REG_BW_SHIFT(ch)) & SYS_REG_BW_MASK));
> +		row_3_4 = sys_reg2 >> SYS_REG_ROW_3_4_SHIFT(ch) & SYS_REG_ROW_3_4_MASK;
> +
> +		if (dram_type == DDR4) {
> +			dbw = (sys_reg2 >> SYS_REG_DBW_SHIFT(ch)) & SYS_REG_DBW_MASK;
> +			bg = (dbw == 2) ? 2 : 1;
> +		}
> +
> +		chipsize_mb = (1 << (cs0_row + cs0_col + bk + bg + bw - 20));
> +
> +		if (rank > 1)
> +			chipsize_mb += chipsize_mb >> ((cs0_row - cs1_row) +
> +				       (cs0_col - cs1_col));
> +		if (row_3_4)
> +			chipsize_mb = chipsize_mb * 3 / 4;
> +
> +		size_mb += chipsize_mb;
> +
> +		if (rank > 1)
> +			pr_debug("rank %d cs0_col %d cs1_col %d bk %d cs0_row %d "
> +				 "cs1_row %d bw %d row_3_4 %d\n",
> +				 rank, cs0_col, cs1_col, bk, cs0_row,
> +				 cs1_row, bw, row_3_4);
> +		else
> +			pr_debug("rank %d cs0_col %d bk %d cs0_row %d "
> +				 "bw %d row_3_4 %d\n",
> +				 rank, cs0_col, bk, cs0_row,
> +				 bw, row_3_4);
> +	}
> +
> +	return (resource_size_t)size_mb << 20;
> +}
> +
> +resource_size_t rk3399_ram0_size(void)
> +{
> +	void __iomem *pmugrf = IOMEM(RK3399_PMUGRF_BASE);
> +	u32 sys_reg2, sys_reg3;
> +	resource_size_t size;
> +
> +	sys_reg2 = readl(pmugrf + RK3399_PMUGRF_OS_REG2);
> +	sys_reg3 = readl(pmugrf + RK3399_PMUGRF_OS_REG3);
> +
> +	size = rockchip_sdram_size(sys_reg2, sys_reg3);
> +	size = min_t(resource_size_t, RK3399_INT_REG_START, size);
> +
> +	pr_debug("%s() = %llu\n", __func__, (u64)size);
> +
> +	return size;
> +}
> +
> +resource_size_t rk3568_ram0_size(void)
> +{
> +	void __iomem *pmugrf = IOMEM(RK3568_PMUGRF_BASE);
> +	u32 sys_reg2, sys_reg3;
> +	resource_size_t size;
> +
> +	sys_reg2 = readl(pmugrf + RK3568_PMUGRF_OS_REG2);
> +	sys_reg3 = readl(pmugrf + RK3568_PMUGRF_OS_REG3);
> +
> +	size = rockchip_sdram_size(sys_reg2, sys_reg3);
> +	size = min_t(resource_size_t, RK3568_INT_REG_START, size);
> +
> +	pr_debug("%s() = %llu\n", __func__, (u64)size);
> +
> +	return size;
> +}
> +
> +static int rockchip_dmc_probe(struct device *dev)
> +{
> +	const struct rockchip_dmc_drvdata *drvdata;
> +	resource_size_t membase, memsize;
> +	struct regmap *regmap;
> +	u32 sys_reg2, sys_reg3;
> +
> +	regmap = syscon_regmap_lookup_by_phandle(dev->of_node, "rockchip,pmu");
> +	if (IS_ERR(regmap))
> +		return PTR_ERR(regmap);
> +
> +	drvdata = device_get_match_data(dev);
> +	if (!drvdata)
> +		return -ENOENT;
> +
> +	regmap_read(regmap, drvdata->os_reg2, &sys_reg2);
> +	regmap_read(regmap, drvdata->os_reg3, &sys_reg3);
> +
> +	memsize = rockchip_sdram_size(sys_reg2, sys_reg3);
> +
> +	dev_info(dev, "Detected memory size: %pa\n", &memsize);
> +
> +	/* lowest 10M are shaved off for secure world firmware */
> +	membase = 0xa00000;
> +
> +	/* ram0, from 0xa00000 up to SoC internal register space start */
> +	arm_add_mem_device("ram0", membase,
> +		min_t(resource_size_t, drvdata->internal_registers_start, memsize) - membase);
> +
> +	/* ram1, remaining RAM beyond 32bit space */
> +	if (memsize > SZ_4G)
> +		arm_add_mem_device("ram1", SZ_4G, memsize - SZ_4G);
> +
> +	return 0;
> +}
> +
> +static const struct rockchip_dmc_drvdata rk3399_drvdata = {
> +	.os_reg2 = RK3399_PMUGRF_OS_REG2,
> +	.os_reg3 = RK3399_PMUGRF_OS_REG3,
> +	.internal_registers_start = RK3399_INT_REG_START,
> +};
> +
> +static const struct rockchip_dmc_drvdata rk3568_drvdata = {
> +	.os_reg2 = RK3568_PMUGRF_OS_REG2,
> +	.os_reg3 = RK3568_PMUGRF_OS_REG3,
> +	.internal_registers_start = RK3568_INT_REG_START,
> +};
> +
> +static struct of_device_id rockchip_dmc_dt_ids[] = {
> +	{
> +		.compatible = "rockchip,rk3399-dmc",
> +		.data = &rk3399_drvdata,
> +	},
> +	{
> +		.compatible = "rockchip,rk3568-dmc",
> +		.data = &rk3568_drvdata,
> +	},
> +	{ /* sentinel */ }
> +};
> +
> +static struct driver rockchip_dmc_driver = {
> +	.name   = "rockchip-dmc",
> +	.probe  = rockchip_dmc_probe,
> +	.of_compatible = rockchip_dmc_dt_ids,
> +};
> +mem_platform_driver(rockchip_dmc_driver);
> diff --git a/include/linux/sizes.h b/include/linux/sizes.h
> index fbde0bc7e8..1d222daeab 100644
> --- a/include/linux/sizes.h
> +++ b/include/linux/sizes.h
> @@ -47,5 +47,8 @@
>  #define SZ_2G				0x80000000
>  
>  #define SZ_4G				_AC(0x100000000, ULL)
> +#define SZ_8G				_AC(0x200000000, ULL)
> +#define SZ_16G				_AC(0x400000000, ULL)
> +#define SZ_32G				_AC(0x800000000, ULL)
>  
>  #endif /* __LINUX_SIZES_H__ */
> diff --git a/include/mach/rockchip/dmc.h b/include/mach/rockchip/dmc.h
> new file mode 100644
> index 0000000000..ff197d50a0
> --- /dev/null
> +++ b/include/mach/rockchip/dmc.h
> @@ -0,0 +1,86 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +/*
> + * Copyright (C) 2017 Rockchip Electronics Co., Ltd.
> + */
> +
> +#ifndef _MACH_ROCKCHIP_DMC_H
> +#define _MACH_ROCKCHIP_DMC_H
> +
> +#include <linux/compiler.h>
> +#include <linux/types.h>
> +#include <linux/bitfield.h>
> +
> +enum {
> +	DDR4 = 0,
> +	DDR3 = 0x3,
> +	LPDDR2 = 0x5,
> +	LPDDR3 = 0x6,
> +	LPDDR4 = 0x7,
> +	UNUSED = 0xFF
> +};
> +
> +/*
> + * sys_reg2 bitfield struct
> + * [31]		row_3_4_ch1
> + * [30]		row_3_4_ch0
> + * [29:28]	chinfo
> + * [27]		rank_ch1
> + * [26:25]	col_ch1
> + * [24]		bk_ch1
> + * [23:22]	low bits of cs0_row_ch1
> + * [21:20]	low bits of cs1_row_ch1
> + * [19:18]	bw_ch1
> + * [17:16]	dbw_ch1;
> + * [15:13]	ddrtype
> + * [12]		channelnum
> + * [11]		rank_ch0
> + * [10:9]	col_ch0,
> + * [8]		bk_ch0
> + * [7:6]	low bits of cs0_row_ch0
> + * [5:4]	low bits of cs1_row_ch0
> + * [3:2]	bw_ch0
> + * [1:0]	dbw_ch0
> + */
> +
> +#define SYS_REG_DDRTYPE			GENMASK(15, 13)
> +#define SYS_REG_NUM_CH			BIT(12)
> +#define SYS_REG_ROW_3_4_SHIFT(ch)	(30 + (ch))
> +#define SYS_REG_ROW_3_4_MASK		1
> +#define SYS_REG_CHINFO_SHIFT(ch)	(28 + (ch))
> +#define SYS_REG_RANK_SHIFT(ch)		(11 + (ch) * 16)
> +#define SYS_REG_RANK_MASK		1
> +#define SYS_REG_COL_SHIFT(ch)		(9 + (ch) * 16)
> +#define SYS_REG_COL_MASK		3
> +#define SYS_REG_BK_SHIFT(ch)		(8 + (ch) * 16)
> +#define SYS_REG_BK_MASK			1
> +#define SYS_REG_CS0_ROW_SHIFT(ch)	(6 + (ch) * 16)
> +#define SYS_REG_CS0_ROW_MASK		3
> +#define SYS_REG_CS1_ROW_SHIFT(ch)	(4 + (ch) * 16)
> +#define SYS_REG_CS1_ROW_MASK		3
> +#define SYS_REG_BW_SHIFT(ch)		(2 + (ch) * 16)
> +#define SYS_REG_BW_MASK			3
> +#define SYS_REG_DBW_SHIFT(ch)		((ch) * 16)
> +#define SYS_REG_DBW_MASK		3
> +
> +/*
> + * sys_reg3 bitfield struct
> + * [7]		high bit of cs0_row_ch1
> + * [6]		high bit of cs1_row_ch1
> + * [5]		high bit of cs0_row_ch0
> + * [4]		high bit of cs1_row_ch0
> + * [3:2]	cs1_col_ch1
> + * [1:0]	cs1_col_ch0
> + */
> +#define SYS_REG_VERSION				GENMASK(31, 28)
> +#define SYS_REG_EXTEND_DDRTYPE			GENMASK(13, 12)
> +#define SYS_REG_EXTEND_CS0_ROW_SHIFT(ch)	(5 + (ch) * 2)
> +#define SYS_REG_EXTEND_CS0_ROW_MASK		1
> +#define SYS_REG_EXTEND_CS1_ROW_SHIFT(ch)	(4 + (ch) * 2)
> +#define SYS_REG_EXTEND_CS1_ROW_MASK		1
> +#define SYS_REG_CS1_COL_SHIFT(ch)		(0 + (ch) * 2)
> +#define SYS_REG_CS1_COL_MASK			3
> +
> +resource_size_t rk3399_ram0_size(void);
> +resource_size_t rk3568_ram0_size(void);
> +
> +#endif
> diff --git a/include/mach/rockchip/rk3399-regs.h b/include/mach/rockchip/rk3399-regs.h
> index 57033b6510..6db082da9b 100644
> --- a/include/mach/rockchip/rk3399-regs.h
> +++ b/include/mach/rockchip/rk3399-regs.h
> @@ -10,6 +10,7 @@
>  #define RK3399_UART3_BASE	0xff1b0000
>  #define RK3399_UART4_BASE	0xff370000
>  
> +#define RK3399_PMUGRF_BASE	0xff320000
>  #define RK3399_IRAM_BASE	0xff8c0000
>  #define RK3399_STIMER_BASE	0xff8680a0
>  
> diff --git a/include/mach/rockchip/rk3568-regs.h b/include/mach/rockchip/rk3568-regs.h
> index edd5ee268d..55d28790dd 100644
> --- a/include/mach/rockchip/rk3568-regs.h
> +++ b/include/mach/rockchip/rk3568-regs.h
> @@ -16,5 +16,6 @@
>  #define RK3568_UART9_BASE	0xfe6d0000
>  
>  #define RK3568_IRAM_BASE	0xfdcc0000
> +#define RK3568_PMUGRF_BASE	0xfdc20000
>  
>  #endif /* __MACH_RK3568_REGS_H */


From sha at pengutronix.de  Tue Apr  4 00:04:18 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Tue, 4 Apr 2023 09:04:18 +0200
Subject: [PATCH v2 02/23] bbu: make it possible to check multiple
 of-compatibles
In-Reply-To: <20230228-v2023-02-0-topic-flexspi-v2-2-3d33126d2434@pengutronix.de>
References: <20230228-v2023-02-0-topic-flexspi-v2-0-3d33126d2434@pengutronix.de>
 <20230228-v2023-02-0-topic-flexspi-v2-2-3d33126d2434@pengutronix.de>
Message-ID: <20230404070417.GI15436@pengutronix.de>

On Mon, Mar 13, 2023 at 02:41:41PM +0100, Marco Felsch wrote:
> It is possible that one barebox can rule multiple platforms e.g.
> multiple platform revision each has a dedicated device tree and of
> compatible. While it is possible to add multiple of-compatibles via
> IMD_USED_OF() (see: zii-imx8mq-dev) we didn't allowed it to flash it
> without 'force'. Fix this by check all possible IMD_TYPE_OF_COMPATIBLE
> image metadata types.
> 
> Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
> ---
>  common/bbu.c | 42 +++++++++++++++++++++++++++---------------
>  1 file changed, 27 insertions(+), 15 deletions(-)
> 
> diff --git a/common/bbu.c b/common/bbu.c
> index 3ec17216cb..a9b3fef7a0 100644
> --- a/common/bbu.c
> +++ b/common/bbu.c
> @@ -154,36 +154,44 @@ struct bbu_handler *bbu_find_handler_by_device(const char *devicepath)
>  	return NULL;
>  }
>  
> -static int bbu_check_of_compat(struct bbu_data *data)
> +static int bbu_check_of_compat(struct bbu_data *data, unsigned short of_compat_nr)
>  {
> +	const struct imd_header *imd = data->imd_data;
> +	const struct imd_header *of_compat;
>  	struct device_node *root_node;
>  	const char *machine, *str;
>  	int ret;
> -	const struct imd_header *of_compat;
>  
>  	if (!IS_ENABLED(CONFIG_OFDEVICE) || !IS_ENABLED(CONFIG_IMD))
>  		return 0;

This patch breaks barebox update when the update image doesn't contain
any IMD_TYPE_OF_COMPATIBLE entries. To fix this we need this here:

	if (!of_compat_nr)
		return 0;

I fixed this up.

Sascha


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Tue Apr  4 00:04:54 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Tue, 4 Apr 2023 09:04:54 +0200
Subject: [PATCH v2 1/4] spi: add per-driver bits-per-word mask
In-Reply-To: <20230403115340.3416720-1-p.zabel@pengutronix.de>
References: <20230403115340.3416720-1-p.zabel@pengutronix.de>
Message-ID: <20230404070454.GU19113@pengutronix.de>

On Mon, Apr 03, 2023 at 01:53:37PM +0200, Philipp Zabel wrote:
> Allow SPI hosts to signal per-transfer bits-per-word switching
> support and drivers to query it with spi_is_bpw_supported().
> 
> Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
> ---
>  include/spi/spi.h | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/include/spi/spi.h b/include/spi/spi.h
> index fa9329b08c80..809ebd8df1a8 100644
> --- a/include/spi/spi.h
> +++ b/include/spi/spi.h
> @@ -131,6 +131,11 @@ struct spi_message;
>   *	SPI slaves, and are numbered from zero to num_chipselects.
>   *	each slave has a chipselect signal, but it's common that not
>   *	every chipselect is connected to a slave.
> + * @bits_per_word_mask: A mask indicating which values of bits_per_word are
> + *	supported by the driver. Bit n indicates that a bits_per_word n+1 is
> + *	supported. If set, the SPI core will reject any transfer with an
> + *	unsupported bits_per_word. If not set, this value is simply ignored,
> + *	and it's up to the individual driver to perform any validation.
>   * @max_speed_hz: Highest supported transfer speed
>   * @setup: updates the device mode and clocking records used by a
>   *	device's SPI controller; protocol code may call this.  This
> @@ -165,6 +170,12 @@ struct spi_controller {
>  
>  	/* Optimized handlers for SPI memory-like operations */
>  	const struct spi_controller_mem_ops *mem_ops;
> +
> +	/* Bitmask of supported bits_per_word for transfers */
> +	u32			bits_per_word_mask;
> +#define SPI_BPW_MASK(bits) BIT((bits) - 1)
> +#define SPI_BPW_RANGE_MASK(min, max) GENMASK((max) - 1, (min) - 1)
> +
>  	/*
>  	 * on some hardware transfer size may be constrained
>  	 * the limit may depend on device transfer settings
> @@ -435,6 +446,26 @@ spi_transfer_del(struct spi_transfer *t)
>  	list_del(&t->transfer_list);
>  }
>  
> +/**
> + * spi_is_bpw_supported - Check if bits per word is supported
> + * @spi: SPI device
> + * @bpw: Bits per word
> + *
> + * This function checks to see if the SPI controller supports @bpw.
> + *
> + * Returns:
> + * True if @bpw is supported, false otherwise.
> + */
> +static inline bool spi_is_bpw_supported(struct spi_device *spi, u32 bpw)
> +{
> +	u32 bpw_mask = spi->master->bits_per_word_mask;
> +
> +	if (bpw == 8 || (bpw <= 32 && bpw_mask & SPI_BPW_MASK(bpw)))
> +		return true;
> +
> +	return false;
> +}
> +
>  /* All these synchronous SPI transfer routines are utilities layered
>   * over the core async transfer primitive.  Here, "synchronous" means
>   * they will sleep uninterruptibly until the async transfer completes.
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Tue Apr  4 00:05:32 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Tue, 4 Apr 2023 09:05:32 +0200
Subject: [PATCH] ARM: boards: protonic-imx6: fix bbu_handler device paths
In-Reply-To: <20230403122509.258800-1-m.felsch@pengutronix.de>
References: <20230403122509.258800-1-m.felsch@pengutronix.de>
Message-ID: <20230404070532.GV19113@pengutronix.de>

On Mon, Apr 03, 2023 at 02:25:09PM +0200, Marco Felsch wrote:
> The update handler path must be a full-path starting at '/'. Fix this by
> adding the '/dev/' path prefix.
> 
> Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
> ---
>  arch/arm/boards/protonic-imx6/board.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/arch/arm/boards/protonic-imx6/board.c b/arch/arm/boards/protonic-imx6/board.c
> index d2fb25d3cc..0d57f409d2 100644
> --- a/arch/arm/boards/protonic-imx6/board.c
> +++ b/arch/arm/boards/protonic-imx6/board.c
> @@ -530,7 +530,7 @@ static int prt_imx6_bbu(struct prt_imx6_priv *priv)
>  		emmc_flags = BBU_HANDLER_FLAG_DEFAULT;
>  	}
>  
> -	devicefile = basprintf("mmc%d", dcfg->emmc_usdhc);
> +	devicefile = basprintf("/dev/mmc%d", dcfg->emmc_usdhc);
>  	if (!devicefile) {
>  		ret = -ENOMEM;
>  		goto exit_bbu;
> @@ -540,7 +540,7 @@ static int prt_imx6_bbu(struct prt_imx6_priv *priv)
>  	if (ret)
>  		goto exit_bbu;
>  
> -	devicefile = basprintf("mmc%d", dcfg->sd_usdhc);
> +	devicefile = basprintf("/dev/mmc%d", dcfg->sd_usdhc);
>  	if (!devicefile) {
>  		ret = -ENOMEM;
>  		goto exit_bbu;
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From m.felsch at pengutronix.de  Tue Apr  4 01:01:42 2023
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Tue, 4 Apr 2023 10:01:42 +0200
Subject: [PATCH v2 02/23] bbu: make it possible to check multiple
 of-compatibles
In-Reply-To: <20230404070417.GI15436@pengutronix.de>
References: <20230228-v2023-02-0-topic-flexspi-v2-0-3d33126d2434@pengutronix.de>
 <20230228-v2023-02-0-topic-flexspi-v2-2-3d33126d2434@pengutronix.de>
 <20230404070417.GI15436@pengutronix.de>
Message-ID: <20230404080142.itltxhz6vtagoipo@pengutronix.de>

On 23-04-04, Sascha Hauer wrote:
> On Mon, Mar 13, 2023 at 02:41:41PM +0100, Marco Felsch wrote:
> > It is possible that one barebox can rule multiple platforms e.g.
> > multiple platform revision each has a dedicated device tree and of
> > compatible. While it is possible to add multiple of-compatibles via
> > IMD_USED_OF() (see: zii-imx8mq-dev) we didn't allowed it to flash it
> > without 'force'. Fix this by check all possible IMD_TYPE_OF_COMPATIBLE
> > image metadata types.
> > 
> > Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
> > ---
> >  common/bbu.c | 42 +++++++++++++++++++++++++++---------------
> >  1 file changed, 27 insertions(+), 15 deletions(-)
> > 
> > diff --git a/common/bbu.c b/common/bbu.c
> > index 3ec17216cb..a9b3fef7a0 100644
> > --- a/common/bbu.c
> > +++ b/common/bbu.c
> > @@ -154,36 +154,44 @@ struct bbu_handler *bbu_find_handler_by_device(const char *devicepath)
> >  	return NULL;
> >  }
> >  
> > -static int bbu_check_of_compat(struct bbu_data *data)
> > +static int bbu_check_of_compat(struct bbu_data *data, unsigned short of_compat_nr)
> >  {
> > +	const struct imd_header *imd = data->imd_data;
> > +	const struct imd_header *of_compat;
> >  	struct device_node *root_node;
> >  	const char *machine, *str;
> >  	int ret;
> > -	const struct imd_header *of_compat;
> >  
> >  	if (!IS_ENABLED(CONFIG_OFDEVICE) || !IS_ENABLED(CONFIG_IMD))
> >  		return 0;
> 
> This patch breaks barebox update when the update image doesn't contain
> any IMD_TYPE_OF_COMPATIBLE entries. To fix this we need this here:
> 
> 	if (!of_compat_nr)
> 		return 0;
> 
> I fixed this up.

Argh.. thanks :) To make even more robust and forcable by board we could
replace it with a dedicated CONFIG_IMD_OF_COMPATIBLE. This way boards
can select it to enforce the check or we skip the check. Since just
checking:

  if (!of_comat_nr)
     return 0;

could also hide board code issues.

Regards,
  Marco


> 
> Sascha
> 
> 
> -- 
> Pengutronix e.K.                           |                             |
> Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> 


From sha at pengutronix.de  Tue Apr  4 01:49:00 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Tue, 4 Apr 2023 10:49:00 +0200
Subject: [PATCH v2 02/23] bbu: make it possible to check multiple
 of-compatibles
In-Reply-To: <20230404080142.itltxhz6vtagoipo@pengutronix.de>
References: <20230228-v2023-02-0-topic-flexspi-v2-0-3d33126d2434@pengutronix.de>
 <20230228-v2023-02-0-topic-flexspi-v2-2-3d33126d2434@pengutronix.de>
 <20230404070417.GI15436@pengutronix.de>
 <20230404080142.itltxhz6vtagoipo@pengutronix.de>
Message-ID: <20230404084900.GX19113@pengutronix.de>

On Tue, Apr 04, 2023 at 10:01:42AM +0200, Marco Felsch wrote:
> On 23-04-04, Sascha Hauer wrote:
> > On Mon, Mar 13, 2023 at 02:41:41PM +0100, Marco Felsch wrote:
> > > It is possible that one barebox can rule multiple platforms e.g.
> > > multiple platform revision each has a dedicated device tree and of
> > > compatible. While it is possible to add multiple of-compatibles via
> > > IMD_USED_OF() (see: zii-imx8mq-dev) we didn't allowed it to flash it
> > > without 'force'. Fix this by check all possible IMD_TYPE_OF_COMPATIBLE
> > > image metadata types.
> > > 
> > > Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
> > > ---
> > >  common/bbu.c | 42 +++++++++++++++++++++++++++---------------
> > >  1 file changed, 27 insertions(+), 15 deletions(-)
> > > 
> > > diff --git a/common/bbu.c b/common/bbu.c
> > > index 3ec17216cb..a9b3fef7a0 100644
> > > --- a/common/bbu.c
> > > +++ b/common/bbu.c
> > > @@ -154,36 +154,44 @@ struct bbu_handler *bbu_find_handler_by_device(const char *devicepath)
> > >  	return NULL;
> > >  }
> > >  
> > > -static int bbu_check_of_compat(struct bbu_data *data)
> > > +static int bbu_check_of_compat(struct bbu_data *data, unsigned short of_compat_nr)
> > >  {
> > > +	const struct imd_header *imd = data->imd_data;
> > > +	const struct imd_header *of_compat;
> > >  	struct device_node *root_node;
> > >  	const char *machine, *str;
> > >  	int ret;
> > > -	const struct imd_header *of_compat;
> > >  
> > >  	if (!IS_ENABLED(CONFIG_OFDEVICE) || !IS_ENABLED(CONFIG_IMD))
> > >  		return 0;
> > 
> > This patch breaks barebox update when the update image doesn't contain
> > any IMD_TYPE_OF_COMPATIBLE entries. To fix this we need this here:
> > 
> > 	if (!of_compat_nr)
> > 		return 0;
> > 
> > I fixed this up.
> 
> Argh.. thanks :) To make even more robust and forcable by board we could
> replace it with a dedicated CONFIG_IMD_OF_COMPATIBLE.

Making this a compile time option is not a good idea. Should be runtime.

> This way boards
> can select it to enforce the check or we skip the check. Since just
> checking:
> 
>   if (!of_comat_nr)
>      return 0;
> 
> could also hide board code issues.

Indeed, yes. Ahmad has a patch in the queue which automatically adds the
IMD_TYPE_OF_COMPATIBLE entries for each board based on the device tree
that is used in the image. I suggest we wait for this patch, and with it
we can re-evaluate this.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From a.fatoum at pengutronix.de  Tue Apr  4 02:05:42 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue,  4 Apr 2023 11:05:42 +0200
Subject: [PATCH] hush: pacify clang -Wparentheses-equality warning
Message-ID: <20230404090542.1820785-1-a.fatoum@pengutronix.de>

Code is fine, but clang's -Wparentheses-equality warns when using double
parentheses in conditionals that don't do assignment. This aligns with
our code style as well, so change it to silence the warning.

No functional change.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/hush.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/hush.c b/common/hush.c
index 5138a1a45ae9..608c0e4937c1 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -1837,7 +1837,7 @@ static char **make_list_in(char **inp, char *name)
 		p3 = insert_var_value(inp[i]);
 		p1 = p3;
 		while (*p1) {
-			if ((*p1 == ' ')) {
+			if (*p1 == ' ') {
 				p1++;
 				continue;
 			}
-- 
2.39.2



From m.felsch at pengutronix.de  Tue Apr  4 02:05:57 2023
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Tue, 4 Apr 2023 11:05:57 +0200
Subject: [PATCH v2 02/23] bbu: make it possible to check multiple
 of-compatibles
In-Reply-To: <20230404084900.GX19113@pengutronix.de>
References: <20230228-v2023-02-0-topic-flexspi-v2-0-3d33126d2434@pengutronix.de>
 <20230228-v2023-02-0-topic-flexspi-v2-2-3d33126d2434@pengutronix.de>
 <20230404070417.GI15436@pengutronix.de>
 <20230404080142.itltxhz6vtagoipo@pengutronix.de>
 <20230404084900.GX19113@pengutronix.de>
Message-ID: <20230404090557.3nqhbgpwlhi3w3fy@pengutronix.de>

On 23-04-04, Sascha Hauer wrote:
> On Tue, Apr 04, 2023 at 10:01:42AM +0200, Marco Felsch wrote:
> > On 23-04-04, Sascha Hauer wrote:
> > > On Mon, Mar 13, 2023 at 02:41:41PM +0100, Marco Felsch wrote:
> > > > It is possible that one barebox can rule multiple platforms e.g.
> > > > multiple platform revision each has a dedicated device tree and of
> > > > compatible. While it is possible to add multiple of-compatibles via
> > > > IMD_USED_OF() (see: zii-imx8mq-dev) we didn't allowed it to flash it
> > > > without 'force'. Fix this by check all possible IMD_TYPE_OF_COMPATIBLE
> > > > image metadata types.
> > > > 
> > > > Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
> > > > ---
> > > >  common/bbu.c | 42 +++++++++++++++++++++++++++---------------
> > > >  1 file changed, 27 insertions(+), 15 deletions(-)
> > > > 
> > > > diff --git a/common/bbu.c b/common/bbu.c
> > > > index 3ec17216cb..a9b3fef7a0 100644
> > > > --- a/common/bbu.c
> > > > +++ b/common/bbu.c
> > > > @@ -154,36 +154,44 @@ struct bbu_handler *bbu_find_handler_by_device(const char *devicepath)
> > > >  	return NULL;
> > > >  }
> > > >  
> > > > -static int bbu_check_of_compat(struct bbu_data *data)
> > > > +static int bbu_check_of_compat(struct bbu_data *data, unsigned short of_compat_nr)
> > > >  {
> > > > +	const struct imd_header *imd = data->imd_data;
> > > > +	const struct imd_header *of_compat;
> > > >  	struct device_node *root_node;
> > > >  	const char *machine, *str;
> > > >  	int ret;
> > > > -	const struct imd_header *of_compat;
> > > >  
> > > >  	if (!IS_ENABLED(CONFIG_OFDEVICE) || !IS_ENABLED(CONFIG_IMD))
> > > >  		return 0;
> > > 
> > > This patch breaks barebox update when the update image doesn't contain
> > > any IMD_TYPE_OF_COMPATIBLE entries. To fix this we need this here:
> > > 
> > > 	if (!of_compat_nr)
> > > 		return 0;
> > > 
> > > I fixed this up.
> > 
> > Argh.. thanks :) To make even more robust and forcable by board we could
> > replace it with a dedicated CONFIG_IMD_OF_COMPATIBLE.
> 
> Making this a compile time option is not a good idea. Should be runtime.

Yes, you're right. I thought the same after send this mail :/

> 
> > This way boards
> > can select it to enforce the check or we skip the check. Since just
> > checking:
> > 
> >   if (!of_comat_nr)
> >      return 0;
> > 
> > could also hide board code issues.
> 
> Indeed, yes. Ahmad has a patch in the queue which automatically adds the
> IMD_TYPE_OF_COMPATIBLE entries for each board based on the device tree
> that is used in the image. I suggest we wait for this patch, and with it
> we can re-evaluate this.

Sure

Regards,
  Marco

> 
> Sascha
> 
> -- 
> Pengutronix e.K.                           |                             |
> Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> 


From a.fatoum at pengutronix.de  Tue Apr  4 03:17:05 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue,  4 Apr 2023 12:17:05 +0200
Subject: [PATCH v2 1/2] scripts: gen-dtb-s: reference OF IMD entries automatically
Message-ID: <20230404101706.2237453-1-a.fatoum@pengutronix.de>

We currently require IMD_OF_USED to get the DT compatible into the
barebox image data meta section. As the PBL is already referencing the
DT to pass it along to barebox proper, let's add a reference from the DT
to the image data section to make IMD_OF_USED unnecessary.

Suggested-by: Antony Pavlov <antonynpavlov at gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
--
v1 -> v2:
  - use dword, to fix build for 64-bit (Sascha)
  - place IMD reference before STRUCT_ALIGNMENT
---
 scripts/gen-dtb-s | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
index c5c46a4d8675..6309a814a483 100755
--- a/scripts/gen-dtb-s
+++ b/scripts/gen-dtb-s
@@ -49,6 +49,9 @@ echo "__dtb_${name}_start:"
 echo ".incbin \"$dtb\""
 echo "__dtb_${name}_end:"
 echo ".global __dtb_${name}_end"
+if [ "$imd" = "y" ]; then
+	echo ".dword __barebox_imd_OF_${name}"
+fi
 echo ".balign STRUCT_ALIGNMENT"
 
 compressed=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" $dtb.z)
@@ -65,5 +68,8 @@ printf ".int 0x%08x\n"  $uncompressed
 echo ".incbin \"$dtb.z\""
 echo "__dtb_z_${name}_end:"
 echo ".global __dtb_z_${name}_end"
+if [ "$imd" = "y" ]; then
+	echo ".dword __barebox_imd_OF_${name}"
+fi
 echo ".balign STRUCT_ALIGNMENT"
 echo "#endif"
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr  4 03:17:06 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue,  4 Apr 2023 12:17:06 +0200
Subject: [PATCH v2 2/2] treewide: remove no-longer needed IMD_USED_OF
In-Reply-To: <20230404101706.2237453-1-a.fatoum@pengutronix.de>
References: <20230404101706.2237453-1-a.fatoum@pengutronix.de>
Message-ID: <20230404101706.2237453-2-a.fatoum@pengutronix.de>

Now that a __dtb* reference automatically pulls in the IMD tag if
support is compiled in, we can drop all IMD_USED_OF and turn the macro
into a no-op until we remove it completely.

Theoretically, an out-of-tree board could reference a DT via IMD_USED_OF
and not actually reference it via __dtb_*_start. So instead of makign
IMD_USED_OF a no-top, let's print a warning for a few releases until
we remove it completely.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - drop <image-metadata.h> header where applicable (Marco)
  - add depreciation warning for macro
---
 arch/arm/boards/innocomm-imx8mm-wb15/lowlevel.c  |  3 ---
 arch/arm/boards/ls1046ardb/lowlevel.c            |  2 --
 arch/arm/boards/nxp-imx8mm-evk/lowlevel.c        |  3 ---
 arch/arm/boards/nxp-imx8mp-evk/lowlevel.c        |  3 ---
 arch/arm/boards/nxp-imx8mq-evk/lowlevel.c        |  3 ---
 arch/arm/boards/phytec-som-imx6/lowlevel.c       |  1 -
 arch/arm/boards/protonic-imx8m/lowlevel-prt8mm.c |  3 ---
 arch/arm/boards/tqmls1046a/lowlevel.c            |  3 ---
 arch/arm/boards/zii-imx8mq-dev/lowlevel.c        |  4 ----
 include/image-metadata.h                         | 10 ++++++----
 10 files changed, 6 insertions(+), 29 deletions(-)

diff --git a/arch/arm/boards/innocomm-imx8mm-wb15/lowlevel.c b/arch/arm/boards/innocomm-imx8mm-wb15/lowlevel.c
index f7753bd32671..30cb7d9cae1a 100644
--- a/arch/arm/boards/innocomm-imx8mm-wb15/lowlevel.c
+++ b/arch/arm/boards/innocomm-imx8mm-wb15/lowlevel.c
@@ -13,7 +13,6 @@
 #include <mfd/bd71837.h>
 #include <mach/xload.h>
 #include <soc/imx8m/ddr.h>
-#include <image-metadata.h>
 
 #include "lowlevel.h"
 
@@ -74,8 +73,6 @@ void innocomm_wb15_power_init_board(void)
 
 ENTRY_FUNCTION(start_innocomm_wb15_evk, r0, r1, r2)
 {
-	IMD_USED_OF(imx8mm_innocomm_wb15_evk);
-
 	imx8mm_cpu_lowlevel_init();
 
 	relocate_to_current_adr();
diff --git a/arch/arm/boards/ls1046ardb/lowlevel.c b/arch/arm/boards/ls1046ardb/lowlevel.c
index 055e5f4c9995..b5265cd986b2 100644
--- a/arch/arm/boards/ls1046ardb/lowlevel.c
+++ b/arch/arm/boards/ls1046ardb/lowlevel.c
@@ -202,8 +202,6 @@ static noinline __noreturn void ls1046ardb_r_entry(unsigned long memsize)
 	debug_ll_init();
 	ls1046a_init_lowlevel();
 
-	IMD_USED_OF(fsl_ls1046a_rdb);
-
 	i2c = ls1046_i2c_init(IOMEM(LSCH2_I2C1_BASE_ADDR));
 	ret = spd_read_eeprom(i2c, 0x51, &spd_eeprom);
 	if (ret) {
diff --git a/arch/arm/boards/nxp-imx8mm-evk/lowlevel.c b/arch/arm/boards/nxp-imx8mm-evk/lowlevel.c
index 6132df53ec75..5dbb4962cf57 100644
--- a/arch/arm/boards/nxp-imx8mm-evk/lowlevel.c
+++ b/arch/arm/boards/nxp-imx8mm-evk/lowlevel.c
@@ -18,7 +18,6 @@
 #include <mfd/bd71837.h>
 #include <mach/xload.h>
 #include <soc/imx8m/ddr.h>
-#include <image-metadata.h>
 
 extern char __dtb_z_imx8mm_evk_start[];
 
@@ -119,7 +118,5 @@ ENTRY_FUNCTION(start_nxp_imx8mm_evk, r0, r1, r2)
 	relocate_to_current_adr();
 	setup_c();
 
-	IMD_USED_OF(imx8mm_evk);
-
 	nxp_imx8mm_evk_start();
 }
diff --git a/arch/arm/boards/nxp-imx8mp-evk/lowlevel.c b/arch/arm/boards/nxp-imx8mp-evk/lowlevel.c
index 3cb24df1ca3f..a62e2ba27efd 100644
--- a/arch/arm/boards/nxp-imx8mp-evk/lowlevel.c
+++ b/arch/arm/boards/nxp-imx8mp-evk/lowlevel.c
@@ -4,7 +4,6 @@
 #include <common.h>
 #include <debug_ll.h>
 #include <firmware.h>
-#include <image-metadata.h>
 #include <asm/mmu.h>
 #include <asm/cache.h>
 #include <asm/sections.h>
@@ -134,7 +133,5 @@ ENTRY_FUNCTION(start_nxp_imx8mp_evk, r0, r1, r2)
 	relocate_to_current_adr();
 	setup_c();
 
-	IMD_USED_OF(imx8mp_evk);
-
 	nxp_imx8mp_evk_start();
 }
diff --git a/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c b/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
index 0c9f6345ff30..8d57fecff36e 100644
--- a/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
+++ b/arch/arm/boards/nxp-imx8mq-evk/lowlevel.c
@@ -2,7 +2,6 @@
 
 #include <common.h>
 #include <firmware.h>
-#include <image-metadata.h>
 #include <linux/sizes.h>
 #include <mach/generic.h>
 #include <asm/barebox-arm-head.h>
@@ -107,7 +106,5 @@ ENTRY_FUNCTION(start_nxp_imx8mq_evk, r0, r1, r2)
 	relocate_to_current_adr();
 	setup_c();
 
-	IMD_USED_OF(imx8mq_evk);
-
 	nxp_imx8mq_evk_start();
 }
diff --git a/arch/arm/boards/phytec-som-imx6/lowlevel.c b/arch/arm/boards/phytec-som-imx6/lowlevel.c
index 62a1c8de7309..31c1e056aa1f 100644
--- a/arch/arm/boards/phytec-som-imx6/lowlevel.c
+++ b/arch/arm/boards/phytec-som-imx6/lowlevel.c
@@ -75,7 +75,6 @@ static void __noreturn start_imx6_phytec_common(uint32_t size,
 		extern char __dtb_##fdt_name##_start[];			\
 									\
 		IMD_USED(physom_mx6_memsize_##memory_size);		\
-		IMD_USED_OF(fdt_name);					\
 									\
 		start_imx6_phytec_common(memory_size, do_early_uart_config, \
 					 __dtb_##fdt_name##_start);	\
diff --git a/arch/arm/boards/protonic-imx8m/lowlevel-prt8mm.c b/arch/arm/boards/protonic-imx8m/lowlevel-prt8mm.c
index bfae39ea522e..80a1e44b3263 100644
--- a/arch/arm/boards/protonic-imx8m/lowlevel-prt8mm.c
+++ b/arch/arm/boards/protonic-imx8m/lowlevel-prt8mm.c
@@ -2,7 +2,6 @@
 
 #include <asm/barebox-arm.h>
 #include <common.h>
-#include <image-metadata.h>
 #include <debug_ll.h>
 #include <firmware.h>
 #include <mach/atf.h>
@@ -87,7 +86,5 @@ ENTRY_FUNCTION(start_prt_prt8mm, r0, r1, r2)
 	relocate_to_current_adr();
 	setup_c();
 
-	IMD_USED_OF(imx8mm_prt8mm);
-
 	prt_prt8mm_start();
 }
diff --git a/arch/arm/boards/tqmls1046a/lowlevel.c b/arch/arm/boards/tqmls1046a/lowlevel.c
index 99dcf1eff7ab..072be0599342 100644
--- a/arch/arm/boards/tqmls1046a/lowlevel.c
+++ b/arch/arm/boards/tqmls1046a/lowlevel.c
@@ -1,7 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 #include <common.h>
 #include <debug_ll.h>
-#include <image-metadata.h>
 #include <platform_data/mmc-esdhc-imx.h>
 #include <soc/fsl/fsl_ddr_sdram.h>
 #include <soc/fsl/immap_lsch2.h>
@@ -109,8 +108,6 @@ static noinline __noreturn void tqmls1046a_r_entry(void)
 	udelay(500);
 	putc_ll('>');
 
-	IMD_USED_OF(fsl_tqmls1046a_mbls10xxa);
-
 	fsl_ddr_set_memctl_regs(&ddrc[0], 0);
 
 	ls1046a_errata_post_ddr();
diff --git a/arch/arm/boards/zii-imx8mq-dev/lowlevel.c b/arch/arm/boards/zii-imx8mq-dev/lowlevel.c
index cf53fb2defd6..311e61fb1da4 100644
--- a/arch/arm/boards/zii-imx8mq-dev/lowlevel.c
+++ b/arch/arm/boards/zii-imx8mq-dev/lowlevel.c
@@ -6,7 +6,6 @@
 
 #include <common.h>
 #include <firmware.h>
-#include <image-metadata.h>
 #include <linux/sizes.h>
 #include <mach/generic.h>
 #include <asm/barebox-arm-head.h>
@@ -201,8 +200,5 @@ ENTRY_FUNCTION(start_zii_imx8mq_dev, r0, r1, r2)
 	relocate_to_current_adr();
 	setup_c();
 
-	IMD_USED_OF(imx8mq_zii_ultra_rmb3);
-	IMD_USED_OF(imx8mq_zii_ultra_zest);
-
 	zii_imx8mq_dev_start();
 }
diff --git a/include/image-metadata.h b/include/image-metadata.h
index bf4e08d98a47..615632f9ce81 100644
--- a/include/image-metadata.h
+++ b/include/image-metadata.h
@@ -156,10 +156,12 @@ static inline void imd_used(const void *unused)
 
 #define IMD_USED(_name) \
 	imd_used(&__barebox_imd_##_name)
-#define IMD_USED_OF(_name) ({ \
-	extern char __barebox_imd_OF_ ## _name[]; \
-	imd_used(&__barebox_imd_OF_ ## _name); \
-	})
+
+__attribute__((deprecated("IMD entries are now always referenced if DT itself is")))
+static inline void IMD_USED_OF(void)
+{}
+
+#define IMD_USED_OF(_name) IMD_USED_OF()
 
 #endif /* __BAREBOX__ */
 
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr  4 03:19:14 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue,  4 Apr 2023 12:19:14 +0200
Subject: [PATCH] clock: implement CLOCKSOURCE_MASK in terms of GENMASK_ULL
Message-ID: <20230404101914.2244083-1-a.fatoum@pengutronix.de>

Clang doesn't like our implementation of CLOCKSOURCE_MASK:

  common/clock.c:33:10: warning: shift count >= width of type [-Wshift-count-overflow]
	.mask = CLOCKSOURCE_MASK(64),
                ^~~~~~~~~~~~~~~~~~~~
  include/clock.h:8:63: note: expanded from macro 'CLOCKSOURCE_MASK'
	 #define CLOCKSOURCE_MASK(bits) (uint64_t)((bits) < 64 ? ((1ULL<<(bits))-1) : -1)

So the bits < 64 check we have is apparently not enough to suppress the
warning when built with clang.

Let's do what the kernel does and use GENMASK_ULL instead to get rid of
the last remaining warning when building ARCH=sandbox targettools_defconfig
with clang version 16.0.1.

Not functional change intended.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 include/clock.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/clock.h b/include/clock.h
index 8e07c35d374e..03a38911a7a7 100644
--- a/include/clock.h
+++ b/include/clock.h
@@ -4,8 +4,9 @@
 
 #include <types.h>
 #include <linux/time.h>
+#include <linux/bitops.h>
 
-#define CLOCKSOURCE_MASK(bits) (uint64_t)((bits) < 64 ? ((1ULL<<(bits))-1) : -1)
+#define CLOCKSOURCE_MASK(bits) GENMASK_ULL((bits) - 1, 0)
 
 struct clocksource {
 	uint32_t	shift;
-- 
2.39.2



From s.hauer at pengutronix.de  Tue Apr  4 03:46:03 2023
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue,  4 Apr 2023 12:46:03 +0200
Subject: [PATCH] ARM: i.MX: iim: Fix imx_iim_reg_write() return type
Message-ID: <20230404104603.134177-1-s.hauer@pengutronix.de>

struct regmap_bus::reg_write should return int, not ssize_t.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-imx/iim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/iim.c b/arch/arm/mach-imx/iim.c
index d403fa9f86..092cf5bcd3 100644
--- a/arch/arm/mach-imx/iim.c
+++ b/arch/arm/mach-imx/iim.c
@@ -291,7 +291,7 @@ err_out:
 	return ret;
 }
 
-static ssize_t imx_iim_reg_write(void *ctx, unsigned int reg, unsigned int val)
+static int imx_iim_reg_write(void *ctx, unsigned int reg, unsigned int val)
 {
 	struct iim_bank *bank = ctx;
 
-- 
2.39.2



From sha at pengutronix.de  Tue Apr  4 03:46:38 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Tue, 4 Apr 2023 12:46:38 +0200
Subject: [PATCH] hush: pacify clang -Wparentheses-equality warning
In-Reply-To: <20230404090542.1820785-1-a.fatoum@pengutronix.de>
References: <20230404090542.1820785-1-a.fatoum@pengutronix.de>
Message-ID: <20230404104638.GY19113@pengutronix.de>

On Tue, Apr 04, 2023 at 11:05:42AM +0200, Ahmad Fatoum wrote:
> Code is fine, but clang's -Wparentheses-equality warns when using double
> parentheses in conditionals that don't do assignment. This aligns with
> our code style as well, so change it to silence the warning.
> 
> No functional change.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  common/hush.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks

Sascha

> 
> diff --git a/common/hush.c b/common/hush.c
> index 5138a1a45ae9..608c0e4937c1 100644
> --- a/common/hush.c
> +++ b/common/hush.c
> @@ -1837,7 +1837,7 @@ static char **make_list_in(char **inp, char *name)
>  		p3 = insert_var_value(inp[i]);
>  		p1 = p3;
>  		while (*p1) {
> -			if ((*p1 == ' ')) {
> +			if (*p1 == ' ') {
>  				p1++;
>  				continue;
>  			}
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From a.fatoum at pengutronix.de  Tue Apr  4 05:24:59 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 4 Apr 2023 14:24:59 +0200
Subject: [PATCH 1/3] video: fb: add optional damage tracking
In-Reply-To: <20230403121844.3447836-1-p.zabel@pengutronix.de>
References: <20230403121844.3447836-1-p.zabel@pengutronix.de>
Message-ID: <7a08e414-95d1-0d81-64b4-9772ceb6f680@pengutronix.de>

On 03.04.23 14:18, Philipp Zabel wrote:
> Add an optional fb_damage operation that drivers may use to accumulate
> damage on the framebuffer until fb_flush is called. The accumulated
> damage can be used to support partial updates for displays with an
> integrated framebuffer.
> 
> Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
> ---
>  drivers/video/fb.c | 6 ++++++
>  include/fb.h       | 9 +++++++++
>  2 files changed, 15 insertions(+)
> 
> diff --git a/drivers/video/fb.c b/drivers/video/fb.c
> index 44754065e7d9..6f412d62c434 100644
> --- a/drivers/video/fb.c
> +++ b/drivers/video/fb.c
> @@ -43,6 +43,12 @@ static int fb_close(struct cdev *cdev)
>  	return 0;
>  }
>  
> +void fb_damage(struct fb_info *info, struct fb_rect *rect)
> +{
> +	if (info->fbops->fb_damage)
> +		info->fbops->fb_damage(info, rect);
> +}
> +
>  static int fb_op_flush(struct cdev *cdev)
>  {
>  	struct fb_info *info = cdev->priv;
> diff --git a/include/fb.h b/include/fb.h
> index 15bb74b99576..4e3eb611db48 100644
> --- a/include/fb.h
> +++ b/include/fb.h
> @@ -80,6 +80,13 @@ struct fb_bitfield {
>  
>  struct fb_info;
>  
> +struct fb_rect {
> +	u32 x1;
> +	u32 y1;
> +	u32 x2;
> +	u32 y2;
> +};
> +
>  struct fb_ops {
>  	/* set color register */
>  	int (*fb_setcolreg)(unsigned regno, unsigned red, unsigned green,
> @@ -87,6 +94,7 @@ struct fb_ops {
>  	void (*fb_enable)(struct fb_info *info);
>  	void (*fb_disable)(struct fb_info *info);
>  	int (*fb_activate_var)(struct fb_info *info);
> +	void (*fb_damage)(struct fb_info *info, struct fb_rect *rect);

const struct fb_rect * ?

>  	void (*fb_flush)(struct fb_info *info);
>  };
>  
> @@ -156,6 +164,7 @@ int register_framebuffer(struct fb_info *info);
>  
>  int fb_enable(struct fb_info *info);
>  int fb_disable(struct fb_info *info);
> +void fb_damage(struct fb_info *info, struct fb_rect *rect);
>  void fb_flush(struct fb_info *info);
>  
>  #define FBIOGET_SCREENINFO	_IOR('F', 1, loff_t)

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



From r.czerwinski at pengutronix.de  Tue Apr  4 05:28:40 2023
From: r.czerwinski at pengutronix.de (Rouven Czerwinski)
Date: Tue, 04 Apr 2023 14:28:40 +0200
Subject: [PATCH next v2] arm: rockchip: add support for CM3 on IO board
In-Reply-To: <20230403071105.GQ19113@pengutronix.de>
References: <20230330161101.58529-1-r.czerwinski@pengutronix.de>
	 <20230403071105.GQ19113@pengutronix.de>
Message-ID: <156da0c77eb2c3e02501777a577934759bfafb16.camel@pengutronix.de>

Hi Sascha,

On Mon, 2023-04-03 at 09:11 +0200, Sascha Hauer wrote:
> On Thu, Mar 30, 2023 at 06:11:01PM +0200, Rouven Czerwinski wrote:
> > From: Rouven Czerwinski <rouven at czerwinskis.de>
> > 
> > Working:
> > - RKBIN DDR training (rk3566_ddr_1056MHz_v1.13.bin)
> > - RKBIN TF-A (v1.34) from RKBIN
> > - Environment storage
> > - DHCP, ping and link detection
> > 
> > Signed-off-by: Rouven Czerwinski <rouven at czerwinskis.de>
> > ---
> > v2:
> > - rebase on next and adjust to RK356x changes
> > - update rockchip boards documentation
> > 
> > +???????memory at a00000 {
> > +???????????????device_type = "memory";
> > +???????????????reg = <0x0 0x00a00000 0x0 0x7f600000>;
> > +???????};
> 
> Now that we have a driver reading back the memory settings from the
> controller this shouldn't be needed anymore. I dropped the memory node
> while applying, please check if it works.

It does, thanks!

Best regards,
Rouven Czerwinski


From s.hauer at pengutronix.de  Tue Apr  4 23:48:45 2023
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 5 Apr 2023 08:48:45 +0200
Subject: [PATCH v2 4/6] ARM: Rockchip: rk3568: use rk3568_barebox_entry()
In-Reply-To: <20230328074037.1202993-5-s.hauer@pengutronix.de>
References: <20230328074037.1202993-1-s.hauer@pengutronix.de>
 <20230328074037.1202993-5-s.hauer@pengutronix.de>
Message-ID: <20230405064845.GJ15436@pengutronix.de>

On Tue, Mar 28, 2023 at 09:40:35AM +0200, Sascha Hauer wrote:
> There is a rk3568 specific entry function for barebox now, switch
> the existing boards over to use it.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  arch/arm/boards/pine64-quartz64/lowlevel.c    | 30 +++--------------
>  arch/arm/boards/radxa-rock3/lowlevel.c        | 31 +++---------------
>  .../rockchip-rk3568-bpi-r2pro/lowlevel.c      | 31 +++---------------
>  .../arm/boards/rockchip-rk3568-evb/lowlevel.c | 32 +++----------------
>  4 files changed, 17 insertions(+), 107 deletions(-)
> 
> diff --git a/arch/arm/boards/pine64-quartz64/lowlevel.c b/arch/arm/boards/pine64-quartz64/lowlevel.c
> index 1e63c0e698..975f8aa51c 100644
> --- a/arch/arm/boards/pine64-quartz64/lowlevel.c
> +++ b/arch/arm/boards/pine64-quartz64/lowlevel.c
> @@ -1,41 +1,19 @@
>  // SPDX-License-Identifier: GPL-2.0-only
> +
>  #include <common.h>
> -#include <linux/sizes.h>
> -#include <asm/barebox-arm-head.h>
>  #include <asm/barebox-arm.h>
>  #include <mach/rockchip/hardware.h>
>  #include <mach/rockchip/atf.h>
>  #include <debug_ll.h>
> -#include <mach/rockchip/rockchip.h>
>  
>  extern char __dtb_rk3566_quartz64_a_start[];
>  
> -static noinline void start_quartz64(void)
> -{
> -	void *fdt = __dtb_rk3566_quartz64_a_start;
> -
> -	if (current_el() == 3) {
> -		rk3568_lowlevel_init();
> -		rk3568_atf_load_bl31(fdt);
> -		/* not reached */
> -	}
> -
> -	barebox_arm_entry(RK3568_DRAM_BOTTOM, 0x80000000 - RK3568_DRAM_BOTTOM,
> -			  fdt);
> -}
> -
>  ENTRY_FUNCTION(start_quartz64a, r0, r1, r2)
>  {
> -	/*
> -	 * Image execution starts at 0x0, but this is used for ATF and
> -	 * OP-TEE later, so move away from here.
> -	 */
> -	if (current_el() == 3)
> -		relocate_to_adr_full(RK3568_BAREBOX_LOAD_ADDRESS);
> -	else
> -		relocate_to_current_adr();
> +	putc_ll('>');
>  
> +	relocate_to_adr_full(RK3568_BAREBOX_LOAD_ADDRESS);

This doesn't work when barebox is started from another barebox, because
it places the new barebox at an address near
RK3568_BAREBOX_LOAD_ADDRESS. Calling relocate_to_adr_full() will
partly overwrite the image. I'll revert this change to what has been
done before:

	if (current_el() == 3)
		relocate_to_adr_full(RK3568_BAREBOX_LOAD_ADDRESS);
	else
		relocate_to_current_adr();

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From m.felsch at pengutronix.de  Wed Apr  5 02:50:36 2023
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Wed,  5 Apr 2023 11:50:36 +0200
Subject: [PATCH] fastboot: avoid console_countdown_abort for getvar request
Message-ID: <20230405095036.2864517-1-m.felsch@pengutronix.de>

Don't abort the console countdown in case of 'fastboot getvar' requests.
Most the time the host just want to query information but don't want to
abort the boot. Therefore skip the abort in case of getvar requests and
abort it in all other cases.

Suggested-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
---
 common/fastboot.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/common/fastboot.c b/common/fastboot.c
index ae7f132444..6c58195395 100644
--- a/common/fastboot.c
+++ b/common/fastboot.c
@@ -772,6 +772,11 @@ static void cb_erase(struct fastboot *fb, const char *cmd)
 		fastboot_tx_print(fb, FASTBOOT_MSG_OKAY, "");
 }
 
+static bool fastboot_cmd_abort_allowed(const char *cmdbuf)
+{
+	return strcmp_l1("getvar:", cmdbuf) == 0 ? false : true;
+}
+
 struct cmd_dispatch_info {
 	char *cmd;
 	void (*cb)(struct fastboot *fb, const char *opt);
@@ -783,7 +788,8 @@ static void fb_run_command(struct fastboot *fb, const char *cmdbuf,
 	const struct cmd_dispatch_info *cmd;
 	int i;
 
-	console_countdown_abort();
+	if (fastboot_cmd_abort_allowed(cmdbuf))
+		console_countdown_abort();
 
 	for (i = 0; i < num_commands; i++) {
 		cmd = &cmds[i];
-- 
2.39.2



From sha at pengutronix.de  Wed Apr  5 04:13:56 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Wed, 5 Apr 2023 13:13:56 +0200
Subject: [PATCH 2/3] video: fbconsole: add optional damage tracking
In-Reply-To: <20230403121844.3447836-2-p.zabel@pengutronix.de>
References: <20230403121844.3447836-1-p.zabel@pengutronix.de>
 <20230403121844.3447836-2-p.zabel@pengutronix.de>
Message-ID: <20230405111356.GZ19113@pengutronix.de>

On Mon, Apr 03, 2023 at 02:18:43PM +0200, Philipp Zabel wrote:
> Annotate framebuffer updates with damage rectangles so drivers may
> implement partial updates for displays with an integrated framebuffer.
> 
> Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
> ---
>  drivers/video/fbconsole.c | 32 ++++++++++++++++++++++++++++----
>  1 file changed, 28 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
> index 070378aa2352..25d7ea685ff6 100644
> --- a/drivers/video/fbconsole.c
> +++ b/drivers/video/fbconsole.c
> @@ -18,6 +18,7 @@ enum state_t {
>  struct fbc_priv {
>  	struct console_device cdev;
>  	struct fb_info *fb;
> +	struct fb_rect rect;
>  
>  	struct screen *sc;
>  
> @@ -60,9 +61,11 @@ static int fbc_tstc(struct console_device *cdev)
>  static void cls(struct fbc_priv *priv)
>  {
>  	void *buf = gui_screen_render_buffer(priv->sc);
> +	struct fb_info *fb = priv->fb;
>  
>  	memset(buf, 0, priv->fb->line_length * priv->fb->yres);
>  	gu_screen_blit(priv->sc);
> +	fb_damage(fb, &priv->rect);
>  }
>  
>  struct rgb {
> @@ -139,13 +142,20 @@ static void drawchar(struct fbc_priv *priv, int x, int y, int c)
>  static void video_invertchar(struct fbc_priv *priv, int x, int y)
>  {
>  	void *buf;
> +	struct fb_rect rect;
> +
> +	rect.x1 = x * priv->font->width;
> +	rect.y1 = y * priv->font->height;
> +	rect.x2 = rect.x1 + priv->font->width;
> +	rect.y2 = rect.y1 + priv->font->height;
>  
>  	buf = gui_screen_render_buffer(priv->sc);
>  
> -	gu_invert_area(priv->fb, buf, x * priv->font->width, y * priv->font->height,
> +	gu_invert_area(priv->fb, buf, rect.x1, rect.y1,
>  			priv->font->width, priv->font->height);
> -	gu_screen_blit_area(priv->sc, x * priv->font->width, y * priv->font->height,
> +	gu_screen_blit_area(priv->sc, rect.x1, rect.y1,
>  			priv->font->width, priv->font->height);
> +	fb_damage(priv->fb, &rect);

Does it make sense to call fb_damage() from gu_screen_blit_area() and
gu_screen_blit() instead?

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From p.zabel at pengutronix.de  Wed Apr  5 05:26:45 2023
From: p.zabel at pengutronix.de (Philipp Zabel)
Date: Wed, 05 Apr 2023 14:26:45 +0200
Subject: [PATCH 1/3] video: fb: add optional damage tracking
In-Reply-To: <7a08e414-95d1-0d81-64b4-9772ceb6f680@pengutronix.de>
References: <20230403121844.3447836-1-p.zabel@pengutronix.de>
	 <7a08e414-95d1-0d81-64b4-9772ceb6f680@pengutronix.de>
Message-ID: <013b899a6c8647489b3aa7c2b344c2d08cd6d36d.camel@pengutronix.de>

On Di, 2023-04-04 at 14:24 +0200, Ahmad Fatoum wrote:
> On 03.04.23 14:18, Philipp Zabel wrote:
> > Add an optional fb_damage operation that drivers may use to accumulate
> > damage on the framebuffer until fb_flush is called. The accumulated
> > damage can be used to support partial updates for displays with an
> > integrated framebuffer.
> > 
> > Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
> > ---
> > ?drivers/video/fb.c | 6 ++++++
> > ?include/fb.h       | 9 +++++++++
> > ?2 files changed, 15 insertions(+)
> > 
> > diff --git a/drivers/video/fb.c b/drivers/video/fb.c
> > index 44754065e7d9..6f412d62c434 100644
> > --- a/drivers/video/fb.c
> > +++ b/drivers/video/fb.c
> > @@ -43,6 +43,12 @@ static int fb_close(struct cdev *cdev)
> > ?	return 0;
> > ?}
> > ?
> > 
> > +void fb_damage(struct fb_info *info, struct fb_rect *rect)
> > +{
> > +	if (info->fbops->fb_damage)
> > +		info->fbops->fb_damage(info, rect);
> > +}
> > +
> > ?static int fb_op_flush(struct cdev *cdev)
> > ?{
> > ?	struct fb_info *info = cdev->priv;
> > diff --git a/include/fb.h b/include/fb.h
> > index 15bb74b99576..4e3eb611db48 100644
> > --- a/include/fb.h
> > +++ b/include/fb.h
> > @@ -80,6 +80,13 @@ struct fb_bitfield {
> > ?
> > 
> > ?struct fb_info;
> > ?
> > 
> > +struct fb_rect {
> > +	u32 x1;
> > +	u32 y1;
> > +	u32 x2;
> > +	u32 y2;
> > +};
> > +
> > ?struct fb_ops {
> > ?	/* set color register */
> > ?	int (*fb_setcolreg)(unsigned regno, unsigned red, unsigned green,
> > @@ -87,6 +94,7 @@ struct fb_ops {
> > ?	void (*fb_enable)(struct fb_info *info);
> > ?	void (*fb_disable)(struct fb_info *info);
> > ?	int (*fb_activate_var)(struct fb_info *info);
> > +	void (*fb_damage)(struct fb_info *info, struct fb_rect *rect);
> 
> const struct fb_rect * ?

Yes, changed to const in v2.

regards
Philipp


From p.zabel at pengutronix.de  Wed Apr  5 05:27:16 2023
From: p.zabel at pengutronix.de (Philipp Zabel)
Date: Wed, 05 Apr 2023 14:27:16 +0200
Subject: [PATCH 2/3] video: fbconsole: add optional damage tracking
In-Reply-To: <20230405111356.GZ19113@pengutronix.de>
References: <20230403121844.3447836-1-p.zabel@pengutronix.de>
	 <20230403121844.3447836-2-p.zabel@pengutronix.de>
	 <20230405111356.GZ19113@pengutronix.de>
Message-ID: <c014e29c02e3ef16fbdfb79ae3fb27b047eb21a6.camel@pengutronix.de>

On Mi, 2023-04-05 at 13:13 +0200, Sascha Hauer wrote:
> On Mon, Apr 03, 2023 at 02:18:43PM +0200, Philipp Zabel wrote:
[...]
> > +	gu_screen_blit_area(priv->sc, rect.x1, rect.y1,
> > ?			priv->font->width, priv->font->height);
> > +	fb_damage(priv->fb, &rect);
> 
> Does it make sense to call fb_damage() from gu_screen_blit_area() and
> gu_screen_blit() instead?

Makes sense to me, changed in v2.

regards
Philipp


From p.zabel at pengutronix.de  Wed Apr  5 05:27:32 2023
From: p.zabel at pengutronix.de (Philipp Zabel)
Date: Wed,  5 Apr 2023 14:27:32 +0200
Subject: [PATCH v2 1/3] video: fb: add optional damage tracking
Message-ID: <20230405122734.2348025-1-p.zabel@pengutronix.de>

Add an optional fb_damage operation that drivers may use to accumulate
damage on the framebuffer until fb_flush is called. The accumulated
damage can be used to support partial updates for displays with an
integrated framebuffer.

Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
---
v2: make rect parameter to fb_damage const
---
 drivers/video/fb.c | 6 ++++++
 include/fb.h       | 9 +++++++++
 2 files changed, 15 insertions(+)

diff --git a/drivers/video/fb.c b/drivers/video/fb.c
index 44754065e7d9..6f412d62c434 100644
--- a/drivers/video/fb.c
+++ b/drivers/video/fb.c
@@ -43,6 +43,12 @@ static int fb_close(struct cdev *cdev)
 	return 0;
 }
 
+void fb_damage(struct fb_info *info, struct fb_rect *rect)
+{
+	if (info->fbops->fb_damage)
+		info->fbops->fb_damage(info, rect);
+}
+
 static int fb_op_flush(struct cdev *cdev)
 {
 	struct fb_info *info = cdev->priv;
diff --git a/include/fb.h b/include/fb.h
index 15bb74b99576..88e6c0e45835 100644
--- a/include/fb.h
+++ b/include/fb.h
@@ -80,6 +80,13 @@ struct fb_bitfield {
 
 struct fb_info;
 
+struct fb_rect {
+	u32 x1;
+	u32 y1;
+	u32 x2;
+	u32 y2;
+};
+
 struct fb_ops {
 	/* set color register */
 	int (*fb_setcolreg)(unsigned regno, unsigned red, unsigned green,
@@ -87,6 +94,7 @@ struct fb_ops {
 	void (*fb_enable)(struct fb_info *info);
 	void (*fb_disable)(struct fb_info *info);
 	int (*fb_activate_var)(struct fb_info *info);
+	void (*fb_damage)(struct fb_info *info, const struct fb_rect *rect);
 	void (*fb_flush)(struct fb_info *info);
 };
 
@@ -156,6 +164,7 @@ int register_framebuffer(struct fb_info *info);
 
 int fb_enable(struct fb_info *info);
 int fb_disable(struct fb_info *info);
+void fb_damage(struct fb_info *info, struct fb_rect *rect);
 void fb_flush(struct fb_info *info);
 
 #define FBIOGET_SCREENINFO	_IOR('F', 1, loff_t)
-- 
2.39.2



From p.zabel at pengutronix.de  Wed Apr  5 05:27:33 2023
From: p.zabel at pengutronix.de (Philipp Zabel)
Date: Wed,  5 Apr 2023 14:27:33 +0200
Subject: [PATCH v2 2/3] graphic_utils: add optional damage tracking
In-Reply-To: <20230405122734.2348025-1-p.zabel@pengutronix.de>
References: <20230405122734.2348025-1-p.zabel@pengutronix.de>
Message-ID: <20230405122734.2348025-2-p.zabel@pengutronix.de>

Annotate framebuffer updates with damage rectangles so drivers may
implement partial updates for displays with an integrated framebuffer.
This can speed up fbconsole.

Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
---
v2: call fb_damage() in graphic_utils instead of fbconsole
---
 lib/gui/graphic_utils.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/lib/gui/graphic_utils.c b/lib/gui/graphic_utils.c
index 92f249e722bc..d91a7f355051 100644
--- a/lib/gui/graphic_utils.c
+++ b/lib/gui/graphic_utils.c
@@ -313,6 +313,12 @@ void gu_screen_blit_area(struct screen *sc, int startx, int starty, int width,
 {
 	struct fb_info *info = sc->info;
 	int bpp = info->bits_per_pixel >> 3;
+	struct fb_rect rect = {
+		.x1 = startx,
+		.y1 = starty,
+		.x2 = startx + width,
+		.y2 = starty + height,
+	};
 
 	if (info->screen_base_shadow) {
 		int y;
@@ -325,14 +331,24 @@ void gu_screen_blit_area(struct screen *sc, int startx, int starty, int width,
 			fboff += sc->info->line_length;
 		}
 	}
+
+	fb_damage(info, &rect);
 }
 
 void gu_screen_blit(struct screen *sc)
 {
 	struct fb_info *info = sc->info;
+	struct fb_rect rect = {
+		.x1 = 0,
+		.y1 = 0,
+		.x2 = info->xres,
+		.y2 = info->yres,
+	};
 
 	if (info->screen_base_shadow)
 		memcpy(info->screen_base, info->screen_base_shadow, sc->fbsize);
+
+	fb_damage(info, &rect);
 }
 
 void gu_fill_rectangle(struct screen *sc,
-- 
2.39.2



From p.zabel at pengutronix.de  Wed Apr  5 05:27:34 2023
From: p.zabel at pengutronix.de (Philipp Zabel)
Date: Wed,  5 Apr 2023 14:27:34 +0200
Subject: [PATCH v2 3/3] video: mipi_dbi: add damage tracking and partial updates
In-Reply-To: <20230405122734.2348025-1-p.zabel@pengutronix.de>
References: <20230405122734.2348025-1-p.zabel@pengutronix.de>
Message-ID: <20230405122734.2348025-3-p.zabel@pengutronix.de>

Track framebuffer damage with a simple rectangle that can be used to
issue partial updates during fb_flush. This speeds up fbconsole.

Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
---
v2: make rect parameter to fb_damage const
---
 drivers/video/mipi_dbi.c       | 83 ++++++++++++++++++++++++++++------
 drivers/video/panel-mipi-dbi.c |  1 +
 include/video/mipi_dbi.h       |  6 +++
 3 files changed, 75 insertions(+), 15 deletions(-)

diff --git a/drivers/video/mipi_dbi.c b/drivers/video/mipi_dbi.c
index aab6b1243954..a2333150b9d8 100644
--- a/drivers/video/mipi_dbi.c
+++ b/drivers/video/mipi_dbi.c
@@ -199,19 +199,33 @@ int mipi_dbi_command_stackbuf(struct mipi_dbi *dbi, u8 cmd, const u8 *data,
 EXPORT_SYMBOL(mipi_dbi_command_stackbuf);
 
 /**
- * mipi_dbi_buf_copy_swap - Copy a framebuffer swapping MSB/LSB of 16-bit values
+ * mipi_dbi_buf_copy - Copy a framebuffer, transforming it if necessary
  * @dst: The destination buffer
  * @info: The source framebuffer info
+ * @clip: Clipping rectangle of the area to be copied
+ * @swap: When true, swap MSB/LSB of 16-bit values
  */
-static void mipi_dbi_buf_copy_swap(u16 *dst, struct fb_info *info)
+static void mipi_dbi_buf_copy(u16 *dst, struct fb_info *info,
+			      struct fb_rect *clip, bool swap)
 {
 	u16 *src = (u16 *)info->screen_base;
-	size_t len = info->xres * info->yres;
-	int i;
+	unsigned int height = clip->y2 - clip->y1;
+	unsigned int width = clip->x2 - clip->x1;
+	int x, y;
 
-	for (i = 0; i < len; i++) {
-		*dst++ = *src << 8 | *src >> 8;
-		src++;
+	src += clip->y1 * info->xres + clip->x1;
+	if (swap) {
+		for (y = 0; y < height; y++) {
+			for (x = 0; x < width; x++)
+				*dst++ = src[x] << 8 | src[x] >> 8;
+			src += info->xres;
+		}
+	} else {
+		for (y = 0; y < height; y++) {
+			memcpy(dst, src, 2 * width);
+			dst += width;
+			src += info->xres;
+		}
 	}
 }
 
@@ -232,28 +246,38 @@ static void mipi_dbi_set_window_address(struct mipi_dbi_dev *dbidev,
 			 ys & 0xff, (ye >> 8) & 0xff, ye & 0xff);
 }
 
-static void mipi_dbi_fb_dirty(struct mipi_dbi_dev *dbidev, struct fb_info *info)
+static void mipi_dbi_fb_dirty(struct mipi_dbi_dev *dbidev, struct fb_info *info,
+			      struct fb_rect *rect)
 {
+	unsigned int height = rect->y2 - rect->y1;
+	unsigned int width = rect->x2 - rect->x1;
 	struct mipi_dbi *dbi = &dbidev->dbi;
-	unsigned int height = info->yres;
-	unsigned int width = info->xres;
 	bool swap = dbi->swap_bytes;
 	int ret;
+	bool full;
 	void *tr;
 
-	if (swap) {
+	full = width == info->xres && height == info->yres;
+
+	if (!full || swap) {
 		tr = dbidev->tx_buf;
-		mipi_dbi_buf_copy_swap(tr, info);
+		mipi_dbi_buf_copy(tr, info, rect, swap);
 	} else {
 		tr = info->screen_base;
 	}
 
-	mipi_dbi_set_window_address(dbidev, 0, width - 1, 0, height - 1);
+	mipi_dbi_set_window_address(dbidev, rect->x1, rect->x2 - 1, rect->y1,
+				    rect->y2 - 1);
 
 	ret = mipi_dbi_command_buf(dbi, MIPI_DCS_WRITE_MEMORY_START, tr,
 				   width * height * 2);
 	if (ret)
 		pr_err_once("Failed to update display %d\n", ret);
+
+	dbidev->damage.x1 = 0;
+	dbidev->damage.y1 = 0;
+	dbidev->damage.x2 = 0;
+	dbidev->damage.y2 = 0;
 }
 
 /**
@@ -267,7 +291,14 @@ static void mipi_dbi_fb_dirty(struct mipi_dbi_dev *dbidev, struct fb_info *info)
 void mipi_dbi_enable_flush(struct mipi_dbi_dev *dbidev,
 			   struct fb_info *info)
 {
-	mipi_dbi_fb_dirty(dbidev, info);
+	struct fb_rect rect = {
+		.x1 = 0,
+		.y1 = 0,
+		.x2 = info->xres,
+		.y2 = info->yres
+	};
+
+	mipi_dbi_fb_dirty(dbidev, info, &rect);
 
 	if (dbidev->backlight)
 		backlight_set_brightness_default(dbidev->backlight);
@@ -309,11 +340,33 @@ void mipi_dbi_fb_disable(struct fb_info *info)
 }
 EXPORT_SYMBOL(mipi_dbi_fb_disable);
 
+void mipi_dbi_fb_damage(struct fb_info *info, const struct fb_rect *rect)
+{
+	struct mipi_dbi_dev *dbidev = container_of(info, struct mipi_dbi_dev, info);
+
+	if (dbidev->damage.x2 && dbidev->damage.y2) {
+		dbidev->damage.x1 = min(dbidev->damage.x1, rect->x1);
+		dbidev->damage.y1 = min(dbidev->damage.y1, rect->y1);
+		dbidev->damage.x2 = max(dbidev->damage.x2, rect->x2);
+		dbidev->damage.y2 = max(dbidev->damage.y2, rect->y2);
+	} else {
+		dbidev->damage = *rect;
+	}
+}
+EXPORT_SYMBOL(mipi_dbi_fb_damage);
+
 void mipi_dbi_fb_flush(struct fb_info *info)
 {
 	struct mipi_dbi_dev *dbidev = container_of(info, struct mipi_dbi_dev, info);
 
-	mipi_dbi_fb_dirty(dbidev, info);
+	if (!dbidev->damage.x2 || !dbidev->damage.y2) {
+		dbidev->damage.x1 = 0;
+		dbidev->damage.y1 = 0;
+		dbidev->damage.x2 = info->xres;
+		dbidev->damage.y2 = info->yres;
+	}
+
+	mipi_dbi_fb_dirty(dbidev, info, &dbidev->damage);
 }
 EXPORT_SYMBOL(mipi_dbi_fb_flush);
 
diff --git a/drivers/video/panel-mipi-dbi.c b/drivers/video/panel-mipi-dbi.c
index ac6f585be32c..7fada69d6f26 100644
--- a/drivers/video/panel-mipi-dbi.c
+++ b/drivers/video/panel-mipi-dbi.c
@@ -218,6 +218,7 @@ static void panel_mipi_dbi_enable(struct fb_info *info)
 static struct fb_ops panel_mipi_dbi_ops = {
 	.fb_enable = panel_mipi_dbi_enable,
 	.fb_disable = mipi_dbi_fb_disable,
+	.fb_damage = mipi_dbi_fb_damage,
 	.fb_flush = mipi_dbi_fb_flush,
 };
 
diff --git a/include/video/mipi_dbi.h b/include/video/mipi_dbi.h
index 917f7ddd597f..a15264c83392 100644
--- a/include/video/mipi_dbi.h
+++ b/include/video/mipi_dbi.h
@@ -109,6 +109,11 @@ struct mipi_dbi_dev {
 	 * @driver_private: Driver private data.
 	 */
 	void *driver_private;
+
+	/**
+	 * @damage: Damage rectangle.
+	 */
+	struct fb_rect damage;
 };
 
 static inline const char *mipi_dbi_name(struct mipi_dbi *dbi)
@@ -120,6 +125,7 @@ int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *dbi,
 		      int dc);
 int mipi_dbi_dev_init(struct mipi_dbi_dev *dbidev,
 		      struct fb_ops *ops, struct fb_videomode *mode);
+void mipi_dbi_fb_damage(struct fb_info *info, const struct fb_rect *rect);
 void mipi_dbi_fb_flush(struct fb_info *info);
 void mipi_dbi_enable_flush(struct mipi_dbi_dev *dbidev,
 			   struct fb_info *info);
-- 
2.39.2



From p.zabel at pengutronix.de  Wed Apr  5 06:06:45 2023
From: p.zabel at pengutronix.de (Philipp Zabel)
Date: Wed,  5 Apr 2023 15:06:45 +0200
Subject: [PATCH] video: fbconsole: implement non-fullscreen fbconsole
Message-ID: <20230405130645.2407719-1-p.zabel@pengutronix.de>

Let fbconsole cover only part of the screen.
Configurable via margin.{left,top,right,bottom} device parameters.

Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
---
 drivers/video/fbconsole.c | 115 +++++++++++++++++++++++++++++++++-----
 1 file changed, 101 insertions(+), 14 deletions(-)

diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 070378aa2352..6c85e8e06a8c 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -18,6 +18,12 @@ enum state_t {
 struct fbc_priv {
 	struct console_device cdev;
 	struct fb_info *fb;
+	struct {
+		u32 top;
+		u32 left;
+		u32 bottom;
+		u32 right;
+	} margin;
 
 	struct screen *sc;
 
@@ -60,9 +66,26 @@ static int fbc_tstc(struct console_device *cdev)
 static void cls(struct fbc_priv *priv)
 {
 	void *buf = gui_screen_render_buffer(priv->sc);
+	struct fb_info *fb = priv->fb;
+	int width = fb->xres - priv->margin.left - priv->margin.right;
+	int height = fb->yres - priv->margin.top - priv->margin.bottom;
+	void *adr;
+
+	adr = buf + priv->fb->line_length * priv->margin.top;
+
+	if (!priv->margin.left && !priv->margin.right) {
+		memset(adr, 0, priv->fb->line_length * height);
+	} else {
+		int bpp = priv->fb->bits_per_pixel >> 3;
+		int y;
 
-	memset(buf, 0, priv->fb->line_length * priv->fb->yres);
-	gu_screen_blit(priv->sc);
+		for (y = 0; y < height; y++) {
+			memset(adr + priv->margin.left * bpp, 0, width * bpp);
+			adr += priv->fb->line_length;
+		}
+	}
+	gu_screen_blit_area(priv->sc, priv->margin.left, priv->margin.top,
+			    width, height);
 }
 
 struct rgb {
@@ -122,7 +145,8 @@ static void drawchar(struct fbc_priv *priv, int x, int y, int c)
 		uint8_t t = inbuf[i];
 		int j;
 
-		adr = buf + line_length * (y * priv->font->height + i) + x * priv->font->width * bpp;
+		adr = buf + line_length * (priv->margin.top + y * priv->font->height + i) +
+		      (priv->margin.left + x * priv->font->width) * bpp;
 
 		for (j = 0; j < priv->font->width; j++) {
 			if (t & 0x80)
@@ -142,9 +166,11 @@ static void video_invertchar(struct fbc_priv *priv, int x, int y)
 
 	buf = gui_screen_render_buffer(priv->sc);
 
-	gu_invert_area(priv->fb, buf, x * priv->font->width, y * priv->font->height,
+	gu_invert_area(priv->fb, buf, priv->margin.left + x * priv->font->width,
+			priv->margin.top + y * priv->font->height,
 			priv->font->width, priv->font->height);
-	gu_screen_blit_area(priv->sc, x * priv->font->width, y * priv->font->height,
+	gu_screen_blit_area(priv->sc, priv->margin.left + x * priv->font->width,
+			priv->margin.top + y * priv->font->height,
 			priv->font->width, priv->font->height);
 }
 
@@ -185,8 +211,9 @@ static void printchar(struct fbc_priv *priv, int c)
 	default:
 		drawchar(priv, priv->x, priv->y, c);
 
-		gu_screen_blit_area(priv->sc, priv->x * priv->font->width,
-				priv->y * priv->font->height,
+		gu_screen_blit_area(priv->sc,
+				priv->margin.left + priv->x * priv->font->width,
+				priv->margin.top + priv->y * priv->font->height,
 				priv->font->width, priv->font->height);
 
 		priv->x++;
@@ -198,15 +225,36 @@ static void printchar(struct fbc_priv *priv, int c)
 
 	if (priv->y > priv->rows) {
 		void *buf;
+		void *adr;
 		u32 line_length = priv->fb->line_length;
 		int line_height = line_length * priv->font->height;
+		int width = priv->fb->xres - priv->margin.left - priv->margin.right;
+		int height = (priv->rows + 1) * priv->font->height;
 
 		buf = gui_screen_render_buffer(priv->sc);
+		adr = buf + priv->margin.top * line_length;
+
+		if (!priv->margin.left && !priv->margin.right) {
+			memcpy(adr, adr + line_height, line_height * priv->rows);
+			memset(adr + line_height * priv->rows, 0, line_height);
+		} else {
+			int bpp = priv->fb->bits_per_pixel >> 3;
+			int y;
+
+			adr += priv->margin.left * bpp;
+
+			for (y = 0; y < height - priv->font->height; y++) {
+				memcpy(adr, adr + line_height, width * bpp);
+				adr += line_length;
+			}
+			for (y = height - priv->font->height; y < height; y++) {
+				memset(adr, 0, width * bpp);
+				adr += line_length;
+			}
+		}
 
-		memcpy(buf, buf + line_height, line_height * priv->rows);
-		memset(buf + line_height * priv->rows, 0, line_height);
-
-		gu_screen_blit(priv->sc);
+		gu_screen_blit_area(priv->sc, priv->margin.left, priv->margin.top,
+				width, height);
 		priv->y = priv->rows;
 	}
 
@@ -401,8 +449,9 @@ static void fbc_putc(struct console_device *cdev, char c)
 
 static int setup_font(struct fbc_priv *priv)
 {
-	struct fb_info *fb = priv->fb;
 	const struct font_desc *font;
+	unsigned int height = priv->fb->yres - priv->margin.top - priv->margin.bottom;
+	unsigned int width = priv->fb->xres - priv->margin.left - priv->margin.right;
 
 	font = find_font_enum(priv->par_font_val);
 	if (!font) {
@@ -411,8 +460,8 @@ static int setup_font(struct fbc_priv *priv)
 
 	priv->font = font;
 
-	priv->rows = fb->yres / priv->font->height - 1;
-	priv->cols = fb->xres / priv->font->width - 1;
+	priv->rows = height / priv->font->height - 1;
+	priv->cols = width / priv->font->width - 1;
 
 	return 0;
 }
@@ -472,6 +521,35 @@ static int set_font(struct param_d *p, void *vpriv)
 	return 0;
 }
 
+static int set_margin(struct param_d *p, void *vpriv)
+{
+	struct fbc_priv *priv = vpriv;
+	struct console_device *cdev = &priv->cdev;
+	int ret;
+
+	if (!priv->font) {
+		ret = setup_font(priv);
+		if (ret)
+			return ret;
+	}
+
+	priv->margin.left = min(priv->margin.left,
+			priv->fb->xres - priv->margin.right - priv->font->width);
+	priv->margin.top = min(priv->margin.top,
+			priv->fb->yres - priv->margin.bottom - priv->font->height);
+	priv->margin.right = min(priv->margin.right,
+			priv->fb->xres - priv->margin.left - priv->font->width);
+	priv->margin.bottom = min(priv->margin.bottom,
+			priv->fb->yres - priv->margin.top - priv->font->height);
+
+	if (cdev->f_active & (CONSOLE_STDOUT | CONSOLE_STDERR)) {
+		cls(priv);
+		setup_font(priv);
+	}
+
+	return 0;
+}
+
 int register_fbconsole(struct fb_info *fb)
 {
 	struct fbc_priv *priv;
@@ -508,6 +586,15 @@ int register_fbconsole(struct fb_info *fb)
 			set_font, NULL,
 			&priv->par_font_val, priv);
 
+	dev_add_param_uint32(&cdev->class_dev, "margin.top", set_margin,
+			NULL, &priv->margin.top, "%u", priv);
+	dev_add_param_uint32(&cdev->class_dev, "margin.left", set_margin,
+			NULL, &priv->margin.left, "%u", priv);
+	dev_add_param_uint32(&cdev->class_dev, "margin.bottom", set_margin,
+			NULL, &priv->margin.bottom, "%u", priv);
+	dev_add_param_uint32(&cdev->class_dev, "margin.right", set_margin,
+			NULL, &priv->margin.right, "%u", priv);
+
 	pr_info("registered as %s%d\n", cdev->class_dev.name, cdev->class_dev.id);
 
 	return 0;
-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr  7 02:59:10 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri,  7 Apr 2023 11:59:10 +0200
Subject: [PATCH] fixup! spi: add per-driver bits-per-word mask
Message-ID: <20230407095910.3778931-1-a.fatoum@pengutronix.de>

From: Ahmad Fatoum <ahmad at a3f.at>

Fixed up commit introduces instances of the BIT() and GENMASK() macros
into the file. Add the appropriate header to go along with it.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 include/spi/spi.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/spi/spi.h b/include/spi/spi.h
index d479e4f34f0c..f806c7a30b36 100644
--- a/include/spi/spi.h
+++ b/include/spi/spi.h
@@ -6,6 +6,7 @@
 #include <linux/err.h>
 #include <linux/kernel.h>
 #include <linux/string.h>
+#include <linux/bitops.h>
 
 struct spi_controller_mem_ops;
 
-- 
2.39.2



From sam at ravnborg.org  Fri Apr  7 11:43:56 2023
From: sam at ravnborg.org (Sam Ravnborg)
Date: Fri, 7 Apr 2023 20:43:56 +0200
Subject: [PATCH v1 1/2] ARM: sama5d4_wifx: fix build with moved mach files
Message-ID: <20230407184356.GA1648837@ravnborg.org>


Signed-off-by: Sam Ravnborg <sam at ravnborg.org>
---
 arch/arm/boards/sama5d4_wifx/lowlevel.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boards/sama5d4_wifx/lowlevel.c b/arch/arm/boards/sama5d4_wifx/lowlevel.c
index 0c3529e659..c47b14c55b 100644
--- a/arch/arm/boards/sama5d4_wifx/lowlevel.c
+++ b/arch/arm/boards/sama5d4_wifx/lowlevel.c
@@ -2,8 +2,8 @@
 // SPDX-FileCopyrightText: 2022 Ahmad Fatoum, Pengutronix
 
 #include <debug_ll.h>
-#include <mach/barebox-arm.h>
-#include <mach/ddramc.h>
+#include <mach/at91/barebox-arm.h>
+#include <mach/at91/ddramc.h>
 
 SAMA5D4_ENTRY_FUNCTION(start_sama5d4_wifx_l1, r4)
 {
-- 
2.34.1



From sam at ravnborg.org  Fri Apr  7 11:45:00 2023
From: sam at ravnborg.org (Sam Ravnborg)
Date: Fri, 7 Apr 2023 20:45:00 +0200
Subject: [PATCH v1 2/2] ARM: add sama5d4_wifx to at91_multi_defconfig
Message-ID: <20230407184500.GB1648837@ravnborg.org>

With this change we have more chances to catch build issues during
refactoring.
The board is added to get build coverage, it is not verified if it
actually boots with this config.

Signed-off-by: Sam Ravnborg <sam at ravnborg.org>
---
 arch/arm/configs/at91_multi_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/at91_multi_defconfig b/arch/arm/configs/at91_multi_defconfig
index 6cbe013162..151f9a7069 100644
--- a/arch/arm/configs/at91_multi_defconfig
+++ b/arch/arm/configs/at91_multi_defconfig
@@ -7,6 +7,7 @@ CONFIG_MACH_MICROCHIP_KSZ9477_EVB=y
 CONFIG_MACH_SAMA5D3_XPLAINED=y
 CONFIG_MACH_SAMA5D27_SOM1=y
 CONFIG_MACH_SAMA5D27_GIANTBOARD=y
+CONFIG_MACH_SAMA5D4_WIFX=y
 CONFIG_AEABI=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_ARM_UNWIND=y
-- 
2.34.1



From ahmad at a3f.at  Sat Apr  8 01:06:16 2023
From: ahmad at a3f.at (Ahmad Fatoum)
Date: Sat,  8 Apr 2023 10:06:16 +0200
Subject: [PATCH master] treewide: add missing device tree artifact cleanup where needed
Message-ID: <20230408080616.938638-1-ahmad@a3f.at>

The DTs in arch/$ARCH/dts are all cleaned up when invoking the make
target, but we have a few DTs outside these directories.

Clean those up as well and add a clean line for the overlay too.

Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
---
 arch/riscv/boards/riscvemu/Makefile | 3 +++
 common/boards/qemu-virt/Makefile    | 3 +++
 test/self/Makefile                  | 3 +++
 3 files changed, 9 insertions(+)

diff --git a/arch/riscv/boards/riscvemu/Makefile b/arch/riscv/boards/riscvemu/Makefile
index 56949c2357c8..ec7e89479e77 100644
--- a/arch/riscv/boards/riscvemu/Makefile
+++ b/arch/riscv/boards/riscvemu/Makefile
@@ -3,3 +3,6 @@
 obj-y += board.o
 obj-y += overlay-of-sram.dtb.o
 bbenv-$(CONFIG_CMD_TUTORIAL) += defaultenv-riscvemu
+
+clean-files := *.dtb *.dtb.S .*.dtc .*.pre .*.dts *.dtb.z
+clean-files += *.dtbo *.dtbo.S .*.dtso
diff --git a/common/boards/qemu-virt/Makefile b/common/boards/qemu-virt/Makefile
index 88184e9a7969..8cacfafee734 100644
--- a/common/boards/qemu-virt/Makefile
+++ b/common/boards/qemu-virt/Makefile
@@ -5,3 +5,6 @@ obj-y += overlay-of-flash.dtb.o
 ifeq ($(CONFIG_RISCV),y)
 DTC_CPP_FLAGS_overlay-of-flash.dtb := -DRISCV_VIRT=1
 endif
+
+clean-files := *.dtb *.dtb.S .*.dtc .*.pre .*.dts *.dtb.z
+clean-files += *.dtbo *.dtbo.S .*.dtso
diff --git a/test/self/Makefile b/test/self/Makefile
index 4d2c0374c9c3..d55d9133be23 100644
--- a/test/self/Makefile
+++ b/test/self/Makefile
@@ -8,3 +8,6 @@ obj-$(CONFIG_SELFTEST_OF_MANIPULATION) += of_manipulation.o of_manipulation.dtb.
 obj-$(CONFIG_SELFTEST_ENVIRONMENT_VARIABLES) += envvar.o
 obj-$(CONFIG_SELFTEST_FS_RAMFS) += ramfs.o
 obj-$(CONFIG_SELFTEST_JSON) += json.o
+
+clean-files := *.dtb *.dtb.S .*.dtc .*.pre .*.dts *.dtb.z
+clean-files += *.dtbo *.dtbo.S .*.dtso
-- 
2.38.4



From Renaud.Barbier at ametek.com  Mon Apr 10 07:58:08 2023
From: Renaud.Barbier at ametek.com (Renaud Barbier)
Date: Mon, 10 Apr 2023 14:58:08 +0000
Subject: [PATCH] ARM: LS1021A: slow boot
Message-ID: <BL0PR07MB5665E8DA118845ED96A8289DEC959@BL0PR07MB5665.namprd07.prod.outlook.com>

It was noticed that the LS1021A-IOT was slow to boot and perform
computing intensive operations. Enable SMP so the cortex-a7 cache
works as expected.

Signed-off-by: Renaud Barbier mailto:renaud.barbier at ametek.com
---
 arch/arm/boards/ls1021aiot/lowlevel.c       | 1 -
 arch/arm/mach-layerscape/lowlevel-ls102xa.c | 4 ++++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boards/ls1021aiot/lowlevel.c b/arch/arm/boards/ls1021aiot/lowlevel.c
index 4dec451558..b7106887f2 100644
--- a/arch/arm/boards/ls1021aiot/lowlevel.c
+++ b/arch/arm/boards/ls1021aiot/lowlevel.c
@@ -86,7 +86,6 @@ static noinline __noreturn void ls1021aiot_r_entry(void)
                  __dtb_fsl_ls1021a_iot_start);
    }

-   arm_cpu_lowlevel_init();
    ls102xa_init_lowlevel();
    ls102xa_debug_ll_init();

diff --git a/arch/arm/mach-layerscape/lowlevel-ls102xa.c b/arch/arm/mach-layerscape/lowlevel-ls102xa.c
index 7f4fcdf55c..259d8866d5 100644
--- a/arch/arm/mach-layerscape/lowlevel-ls102xa.c
+++ b/arch/arm/mach-layerscape/lowlevel-ls102xa.c
@@ -6,6 +6,7 @@
 #include <common.h>
 #include <io.h>
 #include <clock.h>
+#include <asm/barebox-arm-head.h>
 #include <asm/syscounter.h>
 #include <asm/system.h>
 #include <mach/layerscape/errata.h>
@@ -311,6 +312,9 @@ void ls102xa_init_lowlevel(void)
    uint32_t state, major, ctrl, freq;
    uint64_t val;

+   cortex_a7_lowlevel_init();
+   arm_cpu_lowlevel_init();
+
    init_csu();

    writel(SYS_COUNTER_CTRL_ENABLE, LSCH2_SYS_COUNTER_ADDR);
--
2.34.1


From a.fatoum at pengutronix.de  Tue Apr 11 00:14:27 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 09:14:27 +0200
Subject: [PATCH master 05/14] gpiolib: fix gpio label generation with gpiod_get
In-Reply-To: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
References: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
Message-ID: <20230411071436.1630752-6-a.fatoum@pengutronix.de>

Current mistaken use of con_id instead of _con_id, can lead to labels
being called regulator.of-<NULL>. Fix this, so the label becomes
regulator.of instead.

Fixes: 9fb2fa240d58 ("gpiolib: implement dev_gpiod_get_index")
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/gpio/gpiolib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 736279875856..6ec63b1119b5 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -583,7 +583,7 @@ int dev_gpiod_get_index(struct device *dev,
 	buf = NULL;
 
 	if (!label) {
-		if (con_id)
+		if (_con_id)
 			label = buf = basprintf("%s-%s", dev_name(dev), _con_id);
 		else
 			label = dev_name(dev);
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 11 00:14:29 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 09:14:29 +0200
Subject: [PATCH master 07/14] RISC-V: restrict GCC optimization some more
In-Reply-To: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
References: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
Message-ID: <20230411071436.1630752-8-a.fatoum@pengutronix.de>

Some of these we are already setting for ARM and all of them are already
in use by the Linux RISC-V arch Makefile.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/riscv/Makefile | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index 1371f17e7c90..71ca82fe8dc0 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -22,6 +22,9 @@ toolchain-need-zicsr-zifencei := $(call cc-option-yn, -march=$(riscv-march-y)_zi
 riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei
 
 KBUILD_CPPFLAGS += -march=$(riscv-march-y)
+KBUILD_CFLAGS += -mno-save-restore
+KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
+KBUILD_CFLAGS += $(call cc-option,-mstrict-align)
 KBUILD_CPPFLAGS += -Wstrict-prototypes -mcmodel=medany -fpic
 riscv-ldflags-y += -pie -static
 
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 11 00:14:28 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 09:14:28 +0200
Subject: [PATCH master 06/14] test: emulate.pl: fix firmware use with non-tuxmake out-of-tree build
In-Reply-To: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
References: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
Message-ID: <20230411071436.1630752-7-a.fatoum@pengutronix.de>

The YAMLs may contain URLs for firmware that needs to be fetched before
starting Qemu. This firmware needs to be installed where Qemu will find
it, which is _not_ the source directory for out-of-tree builds. This
adjust the path.

Fixes: 7271ce78d0fc ("test: add emulate.pl, a runner for barebox on emulated targets")
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 test/emulate.pl | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/test/emulate.pl b/test/emulate.pl
index b5e2188b86dd..a4ca6b7aee6e 100755
--- a/test/emulate.pl
+++ b/test/emulate.pl
@@ -18,6 +18,17 @@ my @QEMU_INTERACTIVE_OPTS = qw(-serial mon:stdio -trace file=/dev/null);
 
 my %targets;
 
+my $LG_BUILDDIR;
+
+if (exists $ENV{KBUILD_OUTPUT}) {
+    $LG_BUILDDIR = $ENV{KBUILD_OUTPUT};
+} elsif (-d 'build') {
+    $LG_BUILDDIR = 'build';
+} else {
+    $LG_BUILDDIR = getcwd();
+}
+
+
 for my $arch (glob dirname(__FILE__) . "/*/") {
     for my $cfg (glob "$arch/*.yaml") {
 	my $linkdest = readlink $cfg // '';
@@ -152,7 +163,7 @@ sub process {
 		    or die "Failed to download resource `$v': $?\n";
 	    }
 
-	    symlink_force("$dir/$k", "$k") unless $tuxmake;
+	    symlink_force("$dir/$k", "$LG_BUILDDIR/$k") unless $tuxmake;
 	}
 
 	if ($shell) {
@@ -388,20 +399,11 @@ sub rel2abs {
 
 sub abs_configpath {
     my ($path, $args) = @_;
-    my $LG_BUILDDIR;
 
     return unless defined $path;
     $path = $args->{target}{images}{$path};
     return unless defined $path;
 
-    if (exists $ENV{KBUILD_OUTPUT}) {
-	$LG_BUILDDIR = $ENV{KBUILD_OUTPUT};
-    } elsif (-d 'build') {
-	$LG_BUILDDIR = 'build';
-    } else {
-	$LG_BUILDDIR = getcwd();
-    }
-
     $path =~ s/\$LG_BUILDDIR\b/$LG_BUILDDIR/g;
 
     return rel2abs($path, $args->{builddir})
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 11 00:14:22 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 09:14:22 +0200
Subject: [PATCH master 00/14] treewide: fixes for master
Message-ID: <20230411071436.1630752-1-a.fatoum@pengutronix.de>

I am packaging barebox for NixOS, which is a tad different (and newer)
than Debian, which I was previously using. This had me run into a couple
of issues, which this PR addresses. All of them apply onto master.
The fixes for next will be posted separately.

Ahmad Fatoum (14):
  test: riscv: fix YAMLs after defconfig rename
  RISC-V: board-dt-2nd: fix hang in startup
  RISC-V: sifive: disable non-functional SPI nodes
  video: qemu-ramfb: reduce -ENODEV lo level to debug
  gpiolib: fix gpio label generation with gpiod_get
  test: emulate.pl: fix firmware use with non-tuxmake out-of-tree build
  RISC-V: restrict GCC optimization some more
  RISC-V: configs: rv64i_defconfig: disable SBI serial
  net: dsa: realtek: include needed headers directly
  net: linux/mdio.h: add missing init.h header
  Kbuild: export CROSS_PKG_CONFIG
  treewide: fix includes missed by multiarch support
  mci: dw_mmc: make reset optional
  kbuild: remove useless use of /usr/bin/env

 Documentation/boards/imx.rst                  |  4 ++--
 Makefile                                      |  2 +-
 arch/riscv/Makefile                           |  3 +++
 arch/riscv/boot/board-dt-2nd.c                |  6 +++++
 arch/riscv/configs/rv64i_defconfig            |  1 -
 arch/riscv/dts/hifive-unleashed-a00.dts       |  4 ++++
 arch/riscv/dts/hifive-unmatched-a00.dts       |  5 +++++
 drivers/aiodev/am335x_adc.c                   |  2 +-
 drivers/aiodev/imx_thermal.c                  |  2 +-
 drivers/gpio/gpiolib.c                        |  2 +-
 drivers/hab/hab.c                             |  2 +-
 drivers/mci/dw_mmc.c                          |  2 +-
 drivers/net/realtek-dsa/realtek-mdio.c        |  1 +
 drivers/net/realtek-dsa/realtek-smi.c         |  1 +
 drivers/net/realtek-dsa/rtl8365mb.c           |  2 ++
 drivers/net/realtek-dsa/rtl8366rb.c           |  2 ++
 drivers/net/realtek-dsa/tag_rtl4_a.c          |  1 +
 drivers/net/realtek-dsa/tag_rtl8_4.c          |  1 +
 drivers/nvmem/ocotp.c                         |  4 ++--
 drivers/pci/pci-imx6.c                        |  6 ++---
 drivers/pinctrl/imx-iomux-v2.c                |  2 +-
 drivers/spi/atmel-quadspi.c                   |  6 ++---
 drivers/video/imx-ipu-fb.c                    |  4 ++--
 drivers/video/ramfb.c                         |  2 +-
 include/linux/mdio.h                          |  1 +
 scripts/Makefile.lib                          |  2 +-
 scripts/regsubst.pl                           |  8 +++----
 scripts/socfpga_xml_to_config.sh              |  4 ++--
 test/emulate.pl                               | 22 ++++++++++---------
 ....yaml => qemu-virt64 at rv64i_defconfig.yaml} |  0
 test/riscv/rv64i_defconfig.yaml               |  1 +
 ...onfig.yaml => sifive at rv64i_defconfig.yaml} |  0
 ...nfig.yaml => tinyemu at rv64i_defconfig.yaml} |  0
 test/riscv/virt64_defconfig.yaml              |  1 -
 34 files changed, 67 insertions(+), 39 deletions(-)
 rename test/riscv/{qemu at virt64_defconfig.yaml => qemu-virt64 at rv64i_defconfig.yaml} (100%)
 create mode 120000 test/riscv/rv64i_defconfig.yaml
 rename test/riscv/{sifive_defconfig.yaml => sifive at rv64i_defconfig.yaml} (100%)
 rename test/riscv/{tinyemu at virt64_defconfig.yaml => tinyemu at rv64i_defconfig.yaml} (100%)
 delete mode 120000 test/riscv/virt64_defconfig.yaml

-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 11 00:14:31 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 09:14:31 +0200
Subject: [PATCH master 09/14] net: dsa: realtek: include needed headers directly
In-Reply-To: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
References: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
Message-ID: <20230411071436.1630752-10-a.fatoum@pengutronix.de>

Building the driver for RISC-V instead of ARM, shows that the
headers of some symbols depended on were included indirectly
before. Fix this to enable RISC-V build.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/net/realtek-dsa/realtek-mdio.c | 1 +
 drivers/net/realtek-dsa/realtek-smi.c  | 1 +
 drivers/net/realtek-dsa/rtl8365mb.c    | 2 ++
 drivers/net/realtek-dsa/rtl8366rb.c    | 2 ++
 drivers/net/realtek-dsa/tag_rtl4_a.c   | 1 +
 drivers/net/realtek-dsa/tag_rtl8_4.c   | 1 +
 6 files changed, 8 insertions(+)

diff --git a/drivers/net/realtek-dsa/realtek-mdio.c b/drivers/net/realtek-dsa/realtek-mdio.c
index 8b32c3cf539e..579eefebe233 100644
--- a/drivers/net/realtek-dsa/realtek-mdio.c
+++ b/drivers/net/realtek-dsa/realtek-mdio.c
@@ -23,6 +23,7 @@
 #include <regmap.h>
 #include <clock.h>
 #include <gpiod.h>
+#include <linux/printk.h>
 #include <linux/mdio.h>
 
 #include "realtek.h"
diff --git a/drivers/net/realtek-dsa/realtek-smi.c b/drivers/net/realtek-dsa/realtek-smi.c
index 83d197dcdfcd..a12cb7ffd4be 100644
--- a/drivers/net/realtek-dsa/realtek-smi.c
+++ b/drivers/net/realtek-dsa/realtek-smi.c
@@ -31,6 +31,7 @@
 #include <of.h>
 #include <of_device.h>
 #include <linux/mdio.h>
+#include <linux/printk.h>
 #include <clock.h>
 #include <gpiod.h>
 #include <driver.h>
diff --git a/drivers/net/realtek-dsa/rtl8365mb.c b/drivers/net/realtek-dsa/rtl8365mb.c
index 1f11ed4ed4bc..d8e8ac714deb 100644
--- a/drivers/net/realtek-dsa/rtl8365mb.c
+++ b/drivers/net/realtek-dsa/rtl8365mb.c
@@ -94,6 +94,8 @@
 #include <linux/bitops.h>
 #include <linux/mutex.h>
 #include <linux/spinlock.h>
+#include <linux/printk.h>
+#include <linux/export.h>
 #include <regmap.h>
 #include <net.h>
 #include <linux/if_bridge.h>
diff --git a/drivers/net/realtek-dsa/rtl8366rb.c b/drivers/net/realtek-dsa/rtl8366rb.c
index 67dcb7fb704f..5449b9481cf7 100644
--- a/drivers/net/realtek-dsa/rtl8366rb.c
+++ b/drivers/net/realtek-dsa/rtl8366rb.c
@@ -15,6 +15,8 @@
 #include <linux/bitops.h>
 #include <net.h>
 #include <linux/if_bridge.h>
+#include <linux/printk.h>
+#include <linux/export.h>
 #include <regmap.h>
 
 #include "realtek.h"
diff --git a/drivers/net/realtek-dsa/tag_rtl4_a.c b/drivers/net/realtek-dsa/tag_rtl4_a.c
index dabd4ccba2d9..30c6a712d9bf 100644
--- a/drivers/net/realtek-dsa/tag_rtl4_a.c
+++ b/drivers/net/realtek-dsa/tag_rtl4_a.c
@@ -16,6 +16,7 @@
  */
 
 #include <net.h>
+#include <linux/printk.h>
 
 #include "realtek.h"
 #include "dsa_priv.h"
diff --git a/drivers/net/realtek-dsa/tag_rtl8_4.c b/drivers/net/realtek-dsa/tag_rtl8_4.c
index a6762fc4e90d..80e977a65d4d 100644
--- a/drivers/net/realtek-dsa/tag_rtl8_4.c
+++ b/drivers/net/realtek-dsa/tag_rtl8_4.c
@@ -74,6 +74,7 @@
  */
 
 #include <linux/bitfield.h>
+#include <linux/printk.h>
 #include <net.h>
 
 #include "realtek.h"
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 11 00:14:36 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 09:14:36 +0200
Subject: [PATCH master 14/14] kbuild: remove useless use of /usr/bin/env
In-Reply-To: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
References: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
Message-ID: <20230411071436.1630752-15-a.fatoum@pengutronix.de>

For some reason, NixOS failed to build device trees, because of the use
of `/usr/bin/env echo -e` here. Given that calling /usr/bin/env is
unneeded anyway for echo, let's just drop it and make the NixOS build
problem go away as well.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 scripts/Makefile.lib | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 4deaa5dfa73c..8f6dcd7430a1 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -372,7 +372,7 @@ $(obj)/%.dtb.z: $(obj)/%.dtb FORCE
 dts-frags = $(subst $(quote),,$(CONFIG_EXTERNAL_DTS_FRAGMENTS))
 quiet_cmd_dtc = DTC     $@
 # For compatibility between make 4.2 and 4.3
-cmd_dtc = /usr/bin/env echo -e '$(pound)define $(subst -,_,$(*F))_dts 1\n'$(foreach f,$< $(2),'$(pound)include "$(f)"\n') | \
+cmd_dtc = echo -e '$(pound)define $(subst -,_,$(*F))_dts 1\n'$(foreach f,$< $(2),'$(pound)include "$(f)"\n') | \
 	$(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) - ; \
 	$(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 \
 		-i $(srctree)/arch/$(SRCARCH)/dts $(DTC_FLAGS) \
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 11 00:14:23 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 09:14:23 +0200
Subject: [PATCH master 01/14] test: riscv: fix YAMLs after defconfig rename
In-Reply-To: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
References: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
Message-ID: <20230411071436.1630752-2-a.fatoum@pengutronix.de>

With the recent consolidation of 64-bit RISC-V defconfigs into
a single rv64i_defconfig, the YAMLs for QEMUs become outdated.
Sync them with the new naming.

Fixes: 42089e3f532b ("RISC-V: squash 64bit defconfigs into rv64i_defconfig")
Reported-by: Antony Pavlov <antonynpavlov at gmail.com>
Link: https://lore.barebox.org/barebox/20221022105554.c9bbe152814a3c7a682df735 at gmail.com/
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 ...mu at virt64_defconfig.yaml => qemu-virt64 at rv64i_defconfig.yaml} | 0
 test/riscv/rv64i_defconfig.yaml                                  | 1 +
 .../riscv/{sifive_defconfig.yaml => sifive at rv64i_defconfig.yaml} | 0
 ...inyemu at virt64_defconfig.yaml => tinyemu at rv64i_defconfig.yaml} | 0
 test/riscv/virt64_defconfig.yaml                                 | 1 -
 5 files changed, 1 insertion(+), 1 deletion(-)
 rename test/riscv/{qemu at virt64_defconfig.yaml => qemu-virt64 at rv64i_defconfig.yaml} (100%)
 create mode 120000 test/riscv/rv64i_defconfig.yaml
 rename test/riscv/{sifive_defconfig.yaml => sifive at rv64i_defconfig.yaml} (100%)
 rename test/riscv/{tinyemu at virt64_defconfig.yaml => tinyemu at rv64i_defconfig.yaml} (100%)
 delete mode 120000 test/riscv/virt64_defconfig.yaml

diff --git a/test/riscv/qemu at virt64_defconfig.yaml b/test/riscv/qemu-virt64 at rv64i_defconfig.yaml
similarity index 100%
rename from test/riscv/qemu at virt64_defconfig.yaml
rename to test/riscv/qemu-virt64 at rv64i_defconfig.yaml
diff --git a/test/riscv/rv64i_defconfig.yaml b/test/riscv/rv64i_defconfig.yaml
new file mode 120000
index 000000000000..46080baed60d
--- /dev/null
+++ b/test/riscv/rv64i_defconfig.yaml
@@ -0,0 +1 @@
+qemu-virt64 at rv64i_defconfig.yaml
\ No newline at end of file
diff --git a/test/riscv/sifive_defconfig.yaml b/test/riscv/sifive at rv64i_defconfig.yaml
similarity index 100%
rename from test/riscv/sifive_defconfig.yaml
rename to test/riscv/sifive at rv64i_defconfig.yaml
diff --git a/test/riscv/tinyemu at virt64_defconfig.yaml b/test/riscv/tinyemu at rv64i_defconfig.yaml
similarity index 100%
rename from test/riscv/tinyemu at virt64_defconfig.yaml
rename to test/riscv/tinyemu at rv64i_defconfig.yaml
diff --git a/test/riscv/virt64_defconfig.yaml b/test/riscv/virt64_defconfig.yaml
deleted file mode 120000
index ab419d5e7fb4..000000000000
--- a/test/riscv/virt64_defconfig.yaml
+++ /dev/null
@@ -1 +0,0 @@
-qemu at virt64_defconfig.yaml
\ No newline at end of file
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 11 00:14:26 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 09:14:26 +0200
Subject: [PATCH master 04/14] video: qemu-ramfb: reduce -ENODEV lo level to debug
In-Reply-To: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
References: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
Message-ID: <20230411071436.1630752-5-a.fatoum@pengutronix.de>

It's perfectly normal for fw_cfg to be available, but ramfb not being
configured. Driver core handles -ENODEV silently to accommodate this
case. The initcall calling ramfb_probe does too, but ramfb_probe itself
prints an error. Replace that with a debug print.

Fixes: 1db52e5a1039 ("video: add support for QEMU ramfb")
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/video/ramfb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/ramfb.c b/drivers/video/ramfb.c
index 26e01196fc02..3442e81b9e51 100644
--- a/drivers/video/ramfb.c
+++ b/drivers/video/ramfb.c
@@ -131,7 +131,7 @@ static int ramfb_probe(struct device *parent_dev, int fd)
 
 	ret = fw_cfg_find_file(parent_dev, fd, "etc/ramfb");
 	if (ret < 0) {
-		dev_err(parent_dev, "ramfb: fw_cfg (etc/ramfb) file not found\n");
+		dev_dbg(parent_dev, "ramfb: fw_cfg (etc/ramfb) file not found\n");
 		return -ENODEV;
 	}
 
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 11 00:14:33 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 09:14:33 +0200
Subject: [PATCH master 11/14] Kbuild: export CROSS_PKG_CONFIG
In-Reply-To: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
References: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
Message-ID: <20230411071436.1630752-12-a.fatoum@pengutronix.de>

CROSS_PKG_CONFIG is referenced in both Kconfig and Makefiles. To be
visibile everywhere, its default needs to be exported, but it wasn't.

This wasn't noticed, because usual usage was:

  CROSS_PKG_CONFIG=some-pkg-config make scripts

where the shell took care to export the variable. On NixOS, cross
pkg-config is actually called ${CROSS_COMPILE}pkg-config and it didn't
work out of the box. Fix this.

Fixes: 1c1198a3f252 ("scripts: allow building USB loader tools for target as well")
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 6f2f4ce74800..3debf5b42799 100644
--- a/Makefile
+++ b/Makefile
@@ -364,7 +364,7 @@ KCONFIG_CONFIG	?= .config
 
 CROSS_PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
 
-export KCONFIG_CONFIG
+export KCONFIG_CONFIG CROSS_PKG_CONFIG
 
 # SHELL used by kbuild
 CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 11 00:14:34 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 09:14:34 +0200
Subject: [PATCH master 12/14] treewide: fix includes missed by multiarch support
In-Reply-To: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
References: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
Message-ID: <20230411071436.1630752-13-a.fatoum@pengutronix.de>

Found by manual inspection of the results of:

  rg '#include\s*<mach/[^/]+>' | rg -v 'arch/(powerpc|sandbox|mips|x86|kvx)'

Fixes: 68b778c24314 ("ARM: Drop mach dir include path")
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 Documentation/boards/imx.rst     | 4 ++--
 drivers/aiodev/am335x_adc.c      | 2 +-
 drivers/aiodev/imx_thermal.c     | 2 +-
 drivers/hab/hab.c                | 2 +-
 drivers/nvmem/ocotp.c            | 4 ++--
 drivers/pci/pci-imx6.c           | 6 +++---
 drivers/pinctrl/imx-iomux-v2.c   | 2 +-
 drivers/spi/atmel-quadspi.c      | 6 +++---
 drivers/video/imx-ipu-fb.c       | 4 ++--
 scripts/regsubst.pl              | 8 ++++----
 scripts/socfpga_xml_to_config.sh | 4 ++--
 11 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/Documentation/boards/imx.rst b/Documentation/boards/imx.rst
index 6fbf1554d10e..5cc4676a9613 100644
--- a/Documentation/boards/imx.rst
+++ b/Documentation/boards/imx.rst
@@ -168,13 +168,13 @@ keys/certificates are expected in these config variables (assuming HABv4):
   CONFIG_HABV4_IMG_CRT_PEM
 
 A CSF template is located in
-``arch/arm/mach-imx/include/mach/habv4-imx6-gencsf.h`` which is preprocessed
+``include/mach/imx/habv4-imx6-gencsf.h`` which is preprocessed
 by barebox.
 It must be included in the board's flash header:
 
 .. code-block:: none
 
-  #include <mach/habv4-imx6-gencsf.h>
+  #include <mach/imx/habv4-imx6-gencsf.h>
 
 Analogous to HABv4 options and a template exist for HABv3.
 
diff --git a/drivers/aiodev/am335x_adc.c b/drivers/aiodev/am335x_adc.c
index ceb7531dc0d6..491866ca36e6 100644
--- a/drivers/aiodev/am335x_adc.c
+++ b/drivers/aiodev/am335x_adc.c
@@ -19,7 +19,7 @@
 #include <io.h>
 #include <linux/log2.h>
 #include <aiodev.h>
-#include <mach/am33xx-clock.h>
+#include <mach/omap/am33xx-clock.h>
 #include "ti_am335x_tscadc.h"
 
 struct am335x_adc_data {
diff --git a/drivers/aiodev/imx_thermal.c b/drivers/aiodev/imx_thermal.c
index 4d24f6cae32f..0b1670708fc9 100644
--- a/drivers/aiodev/imx_thermal.c
+++ b/drivers/aiodev/imx_thermal.c
@@ -22,7 +22,7 @@
 #include <linux/math64.h>
 #include <linux/log2.h>
 #include <linux/clk.h>
-#include <mach/imx6-anadig.h>
+#include <mach/imx/imx6-anadig.h>
 #include <io.h>
 #include <aiodev.h>
 #include <mfd/syscon.h>
diff --git a/drivers/hab/hab.c b/drivers/hab/hab.c
index 65384a6c10db..5bb97c4b689b 100644
--- a/drivers/hab/hab.c
+++ b/drivers/hab/hab.c
@@ -5,7 +5,7 @@
 #include <fcntl.h>
 #include <environment.h>
 #include <libfile.h>
-#include <mach/generic.h>
+#include <mach/imx/generic.h>
 #include <hab.h>
 #include <regmap.h>
 #include <fs.h>
diff --git a/drivers/nvmem/ocotp.c b/drivers/nvmem/ocotp.c
index ff1e815c6b98..f3bd377f844d 100644
--- a/drivers/nvmem/ocotp.c
+++ b/drivers/nvmem/ocotp.c
@@ -30,8 +30,8 @@
 #include <mach/imx/ocotp.h>
 #include <mach/imx/ocotp-fusemap.h>
 #else
-#include <mach/ocotp.h>
-#include <mach/ocotp-fusemap.h>
+#include <mach/mxs/ocotp.h>
+#include <mach/mxs/ocotp-fusemap.h>
 #endif
 #include <soc/imx8m/featctrl.h>
 #include <linux/nvmem-provider.h>
diff --git a/drivers/pci/pci-imx6.c b/drivers/pci/pci-imx6.c
index 6212a00913a5..40bcf3d89033 100644
--- a/drivers/pci/pci-imx6.c
+++ b/drivers/pci/pci-imx6.c
@@ -30,9 +30,9 @@
 #include <mfd/imx6q-iomuxc-gpr.h>
 #include <mfd/imx7-iomuxc-gpr.h>
 
-#include <mach/imx6-regs.h>
-#include <mach/imx7-regs.h>
-#include <mach/imx8mq-regs.h>
+#include <mach/imx/imx6-regs.h>
+#include <mach/imx/imx7-regs.h>
+#include <mach/imx/imx8mq-regs.h>
 
 #include "pcie-designware.h"
 
diff --git a/drivers/pinctrl/imx-iomux-v2.c b/drivers/pinctrl/imx-iomux-v2.c
index 806c3f882c07..cc5b8f11bcfe 100644
--- a/drivers/pinctrl/imx-iomux-v2.c
+++ b/drivers/pinctrl/imx-iomux-v2.c
@@ -7,7 +7,7 @@
 #include <io.h>
 #include <init.h>
 #include <linux/err.h>
-#include <mach/iomux-mx31.h>
+#include <mach/imx/iomux-mx31.h>
 
 /*
  * IOMUX register (base) addresses
diff --git a/drivers/spi/atmel-quadspi.c b/drivers/spi/atmel-quadspi.c
index e579fcaed6ee..923a170844f6 100644
--- a/drivers/spi/atmel-quadspi.c
+++ b/drivers/spi/atmel-quadspi.c
@@ -21,9 +21,9 @@
 #include <of_gpio.h>
 #include <io.h>
 #include <spi/spi.h>
-#include <mach/iomux.h>
-#include <mach/board.h>
-#include <mach/cpu.h>
+#include <mach/at91/iomux.h>
+#include <mach/at91/board.h>
+#include <mach/at91/cpu.h>
 #include <linux/clk.h>
 #include <linux/err.h>
 
diff --git a/drivers/video/imx-ipu-fb.c b/drivers/video/imx-ipu-fb.c
index 77c0ba2c9ca8..e2ff01929be2 100644
--- a/drivers/video/imx-ipu-fb.c
+++ b/drivers/video/imx-ipu-fb.c
@@ -8,14 +8,14 @@
 #include <dma.h>
 #include <init.h>
 #include <io.h>
-#include <mach/imx35-regs.h>
+#include <mach/imx/imx35-regs.h>
 #include <fb.h>
 #include <platform_data/imxfb.h>
 #include <malloc.h>
 #include <errno.h>
 #include <linux/math64.h>
 #include <mmu.h>
-#include <mach/imx-ipu-fb.h>
+#include <mach/imx/imx-ipu-fb.h>
 #include <linux/clk.h>
 #include <linux/err.h>
 
diff --git a/scripts/regsubst.pl b/scripts/regsubst.pl
index 026c4eed2f12..1aaab4f6a20e 100755
--- a/scripts/regsubst.pl
+++ b/scripts/regsubst.pl
@@ -47,8 +47,8 @@ First you have to add the right #include directives to your file:
  loadaddr 0x20000000
  ivtofs 0x400
  
- #include <mach/imx6-ddr-regs.h>
- #include <mach/imx6dl-ddr-regs.h>
+ #include <mach/imx/imx6-ddr-regs.h>
+ #include <mach/imx/imx6dl-ddr-regs.h>
  
  wm 32 0x020e0774 0x000C0000
  wm 32 0x020e0754 0x00000000
@@ -61,8 +61,8 @@ Then you can process the file with B<regsubst.pl>:
  loadaddr 0x20000000
  ivtofs 0x400
  
- #include <mach/imx6-ddr-regs.h>
- #include <mach/imx6dl-ddr-regs.h>
+ #include <mach/imx/imx6-ddr-regs.h>
+ #include <mach/imx/imx6dl-ddr-regs.h>
  
  wm 32 MX6_IOM_GRP_DDR_TYPE 0x000C0000
  wm 32 MX6_IOM_GRP_DDRPKE 0x00000000
diff --git a/scripts/socfpga_xml_to_config.sh b/scripts/socfpga_xml_to_config.sh
index 1e6056cfb461..2ec2788865b0 100755
--- a/scripts/socfpga_xml_to_config.sh
+++ b/scripts/socfpga_xml_to_config.sh
@@ -41,7 +41,7 @@ pll_config() {
         sed -e "s/^/\t./g" |
         sort`
 
-    echo "#include <mach/arria10-clock-manager.h>" > $tgt
+    echo "#include <mach/socfpga/arria10-clock-manager.h>" > $tgt
     echo >> $tgt
     echo "static struct arria10_mainpll_cfg mainpll_cfg = {" >> $tgt
     echo "$MAINPLL" >> $tgt
@@ -107,7 +107,7 @@ pinmux_config() {
             sed -e "s/\.sel' value='/] = /g" | \
             sed -e "s/' \/>/,/g"`
 
-    echo "#include <mach/arria10-pinmux.h>" > $tgt
+    echo "#include <mach/socfpga/arria10-pinmux.h>" > $tgt
     echo >> $tgt
     echo "static uint32_t pinmux[] = {" >> $tgt
     echo "$SHARED" >> $tgt
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 11 00:14:35 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 09:14:35 +0200
Subject: [PATCH master 13/14] mci: dw_mmc: make reset optional
In-Reply-To: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
References: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
Message-ID: <20230411071436.1630752-14-a.fatoum@pengutronix.de>

The reset is optional, so no point in warning about it unless there
was an actual error getting the reset.

reset_control_get_optional() reports the case of no reset being
specified by returning NULL, so use that instead.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/mci/dw_mmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mci/dw_mmc.c b/drivers/mci/dw_mmc.c
index 8f3317deb51a..73a8ebbc152e 100644
--- a/drivers/mci/dw_mmc.c
+++ b/drivers/mci/dw_mmc.c
@@ -570,7 +570,7 @@ static int dw_mmc_probe(struct device *dev)
 	clk_enable(host->clk_biu);
 	clk_enable(host->clk_ciu);
 
-	rst = reset_control_get(dev, "reset");
+	rst = reset_control_get_optional(dev, "reset");
 	if (IS_ERR(rst)) {
 		dev_warn(dev, "error claiming reset: %pe\n", rst);
 	} else if (rst) {
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 11 00:14:30 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 09:14:30 +0200
Subject: [PATCH master 08/14] RISC-V: configs: rv64i_defconfig: disable SBI serial
In-Reply-To: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
References: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
Message-ID: <20230411071436.1630752-9-a.fatoum@pengutronix.de>

On Virt64, enabling SBI serial leads to doubled output, because both
OpenSBI and barebox use the same serial for output and all consoles
are enabled by default.

Given that SBI PUTCHAR is no longer part of newer SBI specs, we can
just disable the sbi console driver in the defconfig to work around
this.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/riscv/configs/rv64i_defconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/riscv/configs/rv64i_defconfig b/arch/riscv/configs/rv64i_defconfig
index 2c5bfd2df131..53c367c5e415 100644
--- a/arch/riscv/configs/rv64i_defconfig
+++ b/arch/riscv/configs/rv64i_defconfig
@@ -97,7 +97,6 @@ CONFIG_NET_FASTBOOT=y
 CONFIG_OF_BAREBOX_DRIVERS=y
 CONFIG_OF_BAREBOX_ENV_IN_FS=y
 CONFIG_DRIVER_SERIAL_NS16550=y
-CONFIG_SERIAL_SBI=y
 CONFIG_VIRTIO_CONSOLE=y
 CONFIG_SERIAL_SIFIVE=y
 CONFIG_DRIVER_NET_MACB=y
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 11 00:14:24 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 09:14:24 +0200
Subject: [PATCH master 02/14] RISC-V: board-dt-2nd: fix hang in startup
In-Reply-To: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
References: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
Message-ID: <20230411071436.1630752-3-a.fatoum@pengutronix.de>

relocate_to_current_adr() will do a sync_caches_for_execution() after
concluding. The method used for icache synchronization depends on the
CPU being used. Allwinner D1 support added the assumption that any
code running in S-Mode will have populated sscratch with the flags
before calling riscv_vendor_id(). This is not the case for
barebox-dt-2nd, which does relocation before riscv_set_flags().

Quick fix this by calling riscv_set_flags manually.

Cc: Marco Felsch <m.felsch at pengutronix.de>
Fixes: c986c565b023 ("RISC-V: use m/sscratch registers for barebox_riscv_pbl_flags")
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/riscv/boot/board-dt-2nd.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/riscv/boot/board-dt-2nd.c b/arch/riscv/boot/board-dt-2nd.c
index 8b78e1b11d31..f1479d834615 100644
--- a/arch/riscv/boot/board-dt-2nd.c
+++ b/arch/riscv/boot/board-dt-2nd.c
@@ -50,6 +50,12 @@ static void noinline __noreturn start_dt_2nd_nonnaked(unsigned long hartid,
 	if (!fdt)
 		hang();
 
+	/*
+	 * We need to call this here, as a multiplatform build
+	 * depends on querying mode for riscv_vendor_id()
+	 */
+	riscv_set_flags(RISCV_S_MODE);
+
 	relocate_to_current_adr();
 	setup_c();
 
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 11 00:14:32 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 09:14:32 +0200
Subject: [PATCH master 10/14] net: linux/mdio.h: add missing init.h header
In-Reply-To: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
References: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
Message-ID: <20230411071436.1630752-11-a.fatoum@pengutronix.de>

The header defines device_mdio_driver, which requires the macros in
init.h to be usable. Therefore include the appropriate header.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 include/linux/mdio.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/mdio.h b/include/linux/mdio.h
index a4aee49d8db3..c441a074ec7f 100644
--- a/include/linux/mdio.h
+++ b/include/linux/mdio.h
@@ -13,6 +13,7 @@
 
 #include <linux/types.h>
 #include <linux/mii.h>
+#include <init.h>
 
 /* MDIO Manageable Devices (MMDs). */
 #define MDIO_MMD_PMAPMD		1	/* Physical Medium Attachment/
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 11 00:14:25 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 09:14:25 +0200
Subject: [PATCH master 03/14] RISC-V: sifive: disable non-functional SPI nodes
In-Reply-To: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
References: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
Message-ID: <20230411071436.1630752-4-a.fatoum@pengutronix.de>

For some reasons,newer QEMU versions (tested v5.2.0) trigger a load
fault at the first readl of the driver. For now disable the nodes,
until this issue is looked into.

Reported-by: Antony Pavlov <antonynpavlov at gmail.com>
Link: https://lore.barebox.org/barebox/20220830140533.deb229d3e3f32c827e6ff521 at gmail.com/
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/riscv/dts/hifive-unleashed-a00.dts | 4 ++++
 arch/riscv/dts/hifive-unmatched-a00.dts | 5 +++++
 2 files changed, 9 insertions(+)

diff --git a/arch/riscv/dts/hifive-unleashed-a00.dts b/arch/riscv/dts/hifive-unleashed-a00.dts
index 65694bfd246a..3b82c16ff0f7 100644
--- a/arch/riscv/dts/hifive-unleashed-a00.dts
+++ b/arch/riscv/dts/hifive-unleashed-a00.dts
@@ -1,3 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0 OR X11 */
 
 #include <riscv/sifive/hifive-unleashed-a00.dts>
+
+/* probing on QEMU v5.2.0 triggers load access fault @0x10040014 */
+&qspi0 { status = "disabled"; };
+&qspi2 { status = "disabled"; };
diff --git a/arch/riscv/dts/hifive-unmatched-a00.dts b/arch/riscv/dts/hifive-unmatched-a00.dts
index b8793e910555..24a4c798a941 100644
--- a/arch/riscv/dts/hifive-unmatched-a00.dts
+++ b/arch/riscv/dts/hifive-unmatched-a00.dts
@@ -1,3 +1,8 @@
 /* SPDX-License-Identifier: GPL-2.0 OR X11 */
 
 #include <riscv/sifive/hifive-unmatched-a00.dts>
+
+/* probing on QEMU v5.2.0 triggers load access fault @0x10040014 */
+&qspi0 { status = "disabled"; };
+&qspi1 { status = "disabled"; };
+&spi0  { status = "disabled"; };
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 11 02:38:41 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 11:38:41 +0200
Subject: [PATCH 0/3] scripts: imx: make imx-usb-loader compilable for MinGW
Message-ID: <20230411093844.1297004-1-a.fatoum@pengutronix.de>

While the system flashing Linux is often running Linux itself, it may
be Windows instead. To support this, let's support building
imx-usb-loader for Windows.

Only compiled-tested on Debian 11 with:

   x86_64-w64-mingw32-gcc (GCC) 10-win32 20210110 (gcc-mingw-w64-x86-64-posix)
   libusb-1.0.26-binaries.7z  (from Github releases page)

  CC=${CC:-x86_64-w64-mingw32-gcc}
  LIBUSB=${LIBUSB:-../libusb-binaries}
  
  CPPFLAGS="-isystem $LIBUSB -I scripts/include/ -I include/mach/"
  LDFLAGS="-L $LIBUSB -lusb-1.0"
  
  $CC -c -o imx.o scripts/imx/imx.c $CPPFLAGS
  $CC -c -o imx-usb-loader.o scripts/imx/imx-usb-loader.c $CPPFLAGS
  
  $CC -o imx-usb-loader.exe imx.o imx-usb-loader.o $LDFLAGS


Ahmad Fatoum (3):
  imx-usb-loader: don't depend on arpa/inet.h for endianness conversion
  scripts: compiler.h: add Windows support
  scripts: common: drop unused mman.h include

 scripts/common.c             |  1 -
 scripts/compiler.h           | 33 ++++++++++++++++++++++++
 scripts/imx/imx-usb-loader.c | 49 ++++++++++++++++++------------------
 3 files changed, 57 insertions(+), 26 deletions(-)

-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 11 02:38:43 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 11:38:43 +0200
Subject: [PATCH 2/3] scripts: compiler.h: add Windows support
In-Reply-To: <20230411093844.1297004-1-a.fatoum@pengutronix.de>
References: <20230411093844.1297004-1-a.fatoum@pengutronix.de>
Message-ID: <20230411093844.1297004-3-a.fatoum@pengutronix.de>

We lack endianness conversion functions for Windows. Import them from
the public-domain portable_endian.h[1]. We skip the 64-bit XBox support
though as it's unlikely we'll need to run imx-usb-loader on that
particular game console.

While at it, only define min when it's undefined. This works around one
of the winapi headers indirectly included defining it.

[1]: https://gist.github.com/panzi/6856583

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 scripts/compiler.h | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/scripts/compiler.h b/scripts/compiler.h
index c932f715c551..925cad21b6cf 100644
--- a/scripts/compiler.h
+++ b/scripts/compiler.h
@@ -61,6 +61,37 @@ typedef unsigned int  uint;
 #elif defined(__OpenBSD__) || defined(__FreeBSD__) || \
       defined(__NetBSD__) || defined(__DragonFly__)
 # include <sys/endian.h>
+#elif defined _WIN32
+# if defined(_MSC_VER)
+#  include <stdlib.h>
+#  define htobe16(x) _byteswap_ushort(x)
+#  define htole16(x) (x)
+#  define be16toh(x) _byteswap_ushort(x)
+#  define le16toh(x) (x)
+#  define htobe32(x) _byteswap_ulong(x)
+#  define htole32(x) (x)
+#  define be32toh(x) _byteswap_ulong(x)
+#  define le32toh(x) (x)
+#  define htobe64(x) _byteswap_uint64(x)
+#  define htole64(x) (x)
+#  define be64toh(x) _byteswap_uint64(x)
+#  define le64toh(x) (x)
+# elif defined(__GNUC__) || defined(__clang__)
+#  define htobe16(x) __builtin_bswap16(x)
+#  define htole16(x) (x)
+#  define be16toh(x) __builtin_bswap16(x)
+#  define le16toh(x) (x)
+#  define htobe32(x) __builtin_bswap32(x)
+#  define htole32(x) (x)
+#  define be32toh(x) __builtin_bswap32(x)
+#  define le32toh(x) (x)
+#  define htobe64(x) __builtin_bswap64(x)
+#  define htole64(x) (x)
+#  define be64toh(x) __builtin_bswap64(x)
+#  define le64toh(x) (x)
+#else
+#  error platform not supported
+#endif
 #else /* assume Linux */
 # include <sys/types.h>
 # include <endian.h>
@@ -128,11 +159,13 @@ typedef uint32_t __u32;
 # define be64_to_cpu(x)		(x)
 #endif
 
+#ifndef min
 #define min(x, y) ({                            \
 	typeof(x) _min1 = (x);                  \
 	typeof(y) _min2 = (y);                  \
 	(void) (&_min1 == &_min2);              \
 	_min1 < _min2 ? _min1 : _min2; })
+#endif
 
 static inline void *xmalloc(size_t size)
 {
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 11 02:38:42 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 11:38:42 +0200
Subject: [PATCH 1/3] imx-usb-loader: don't depend on arpa/inet.h for endianness conversion
In-Reply-To: <20230411093844.1297004-1-a.fatoum@pengutronix.de>
References: <20230411093844.1297004-1-a.fatoum@pengutronix.de>
Message-ID: <20230411093844.1297004-2-a.fatoum@pengutronix.de>

We already have <scripts/compiler.h>, which offers endianness conversion
for non-Linux platforms like MacOS. Let's use that to reduce our
dependency on external implementation-defined headers.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 scripts/imx/imx-usb-loader.c | 49 ++++++++++++++++++------------------
 1 file changed, 24 insertions(+), 25 deletions(-)

diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index 4bcb4cbab6fe..41d57906c752 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -31,7 +31,6 @@
 #include <stdlib.h>
 #include <libusb.h>
 #include <getopt.h>
-#include <arpa/inet.h>
 #include <linux/kernel.h>
 
 #include "../common.h"
@@ -594,8 +593,8 @@ static int read_memory(unsigned addr, void *dest, unsigned cnt)
 	int err;
 	int rem;
 	unsigned char tmp[64];
-	read_reg_command.addr = htonl(addr);
-	read_reg_command.cnt = htonl(cnt);
+	read_reg_command.addr = htobe32(addr);
+	read_reg_command.cnt = htobe32(cnt);
 
 	for (;;) {
 		err = transfer(1, &read_reg_command, 16, &last_trans);
@@ -651,8 +650,8 @@ static int write_memory(unsigned addr, unsigned val, int width)
 		.rsvd = 0,
 	};
 
-	write_reg_command.addr = htonl(addr);
-	write_reg_command.cnt = htonl(4);
+	write_reg_command.addr = htobe32(addr);
+	write_reg_command.cnt = htobe32(4);
 
 	if (verbose > 1)
 		printf("write memory reg: 0x%08x val: 0x%08x width: %d\n", addr, val, width);
@@ -671,7 +670,7 @@ static int write_memory(unsigned addr, unsigned val, int width)
 			return -1;
 	}
 
-	write_reg_command.data = htonl(val);
+	write_reg_command.data = htobe32(val);
 
 	for (;;) {
 		err = transfer(1, &write_reg_command, 16, &last_trans);
@@ -771,8 +770,8 @@ static int load_file(void *buf, unsigned len, unsigned dladdr,
 
 	len = ALIGN(len, 4);
 
-	dl_command.addr = htonl(dladdr);
-	dl_command.cnt = htonl(len);
+	dl_command.addr = htobe32(dladdr);
+	dl_command.cnt = htobe32(len);
 	dl_command.rsvd = type;
 
 	for (;;) {
@@ -833,7 +832,7 @@ static int sdp_jump_address(unsigned addr)
 	int last_trans, err;
 	int retry = 0;
 
-	jump_command.addr = htonl(addr);
+	jump_command.addr = htobe32(addr);
 
 	for (;;) {
 		err = transfer(1, &jump_command, 16, &last_trans);
@@ -862,10 +861,10 @@ static int do_dcd_v2_cmd_write(const unsigned char *dcd)
 	int set_bits = 0, clear_bits = 0;
 	int idx, bytes;
 	struct imx_dcd_v2_write *recs = (struct imx_dcd_v2_write *) dcd;
-	int num_rec = (ntohs(recs->length) - 4) /
+	int num_rec = (be16toh(recs->length) - 4) /
 		      sizeof(struct imx_dcd_v2_write_rec);
 	printf("DCD write: sub dcd length: 0x%04x, flags: 0x%02x\n",
-		ntohs(recs->length), recs->param);
+		be16toh(recs->length), recs->param);
 
 	if (recs->param & PARAMETER_FLAG_MASK) {
 		if (recs->param & PARAMETER_FLAG_SET)
@@ -886,8 +885,8 @@ static int do_dcd_v2_cmd_write(const unsigned char *dcd)
 
 	for (idx = 0; idx < num_rec; idx++) {
 		const struct imx_dcd_v2_write_rec *record = &recs->data[idx];
-		int ret = modify_memory(ntohl(record->addr),
-				 ntohl(record->val), bytes,
+		int ret = modify_memory(be32toh(record->addr),
+				 be32toh(record->val), bytes,
 				 set_bits, clear_bits);
 		if (ret < 0)
 			return ret;
@@ -902,13 +901,13 @@ static int do_dcd_v2_cmd_check(const unsigned char *dcd)
 	int bytes;
 	enum imx_dcd_v2_check_cond cond;
 	struct imx_dcd_v2_check *check = (struct imx_dcd_v2_check *) dcd;
-	switch (ntohs(check->length)) {
+	switch (be16toh(check->length)) {
 	case 12:
 		/* poll indefinitely */
 		poll_count = 0xffffffff;
 		break;
 	case 16:
-		poll_count = ntohl(check->count);
+		poll_count = be32toh(check->count);
 		if (poll_count == 0)
 			/* this command behaves as for NOP */
 			return 0;
@@ -941,10 +940,10 @@ static int do_dcd_v2_cmd_check(const unsigned char *dcd)
 		return -1;
 	}
 
-	mask = ntohl(check->mask);
+	mask = be32toh(check->mask);
 
 	fprintf(stderr, "DCD check condition %i on address 0x%x\n",
-		cond, ntohl(check->addr));
+		cond, be32toh(check->addr));
 	/* Reduce the poll count to some arbitrary practical limit.
 	   Polling via SRP commands will be much slower compared to
 	   polling when DCD is interpreted by the SOC microcode.
@@ -954,7 +953,7 @@ static int do_dcd_v2_cmd_check(const unsigned char *dcd)
 
 	while (poll_count > 0) {
 		uint32_t data = 0;
-		int ret = read_memory(ntohl(check->addr), &data, bytes);
+		int ret = read_memory(be32toh(check->addr), &data, bytes);
 		if (ret < 0)
 			return ret;
 
@@ -983,7 +982,7 @@ static int do_dcd_v2_cmd_check(const unsigned char *dcd)
 
 	fprintf(stderr, "Error: timeout waiting for DCD check condition %i "
 		"on address 0x%08x to match 0x%08x\n", cond,
-		ntohl(check->addr), ntohl(check->mask));
+		be32toh(check->addr), be32toh(check->mask));
 	return -1;
 }
 
@@ -1015,7 +1014,7 @@ static int process_dcd_table_ivt(const struct imx_flash_header_v2 *hdr,
 		fprintf(stderr, "Error: Unknown DCD header tag\n");
 		return -1;
 	}
-	m_length = ntohs(dcd_hdr->length);
+	m_length = be16toh(dcd_hdr->length);
 	dcd_end = dcd + m_length;
 	if (dcd_end > file_end) {
 		fprintf(stderr, "Error: DCD length %08x exceeds EOF\n",
@@ -1028,7 +1027,7 @@ static int process_dcd_table_ivt(const struct imx_flash_header_v2 *hdr,
 	while (dcd < dcd_end) {
 		int ret = 0;
 		struct imx_ivt_header *cmd_hdr = (struct imx_ivt_header *) dcd;
-		unsigned s_length = ntohs(cmd_hdr->length);
+		unsigned s_length = be16toh(cmd_hdr->length);
 		if (dcd +  s_length > file_end) {
 			fprintf(stderr, "Error: DCD length %08x exceeds EOF\n",
 				s_length);
@@ -1473,14 +1472,14 @@ static int mxs_load_buf(uint8_t *data, int size)
 	static struct mxs_command dl_command;
 	int last_trans, err;
 
-	dl_command.sign = htonl(0x424c5443); /* Signature: BLTC */
-	dl_command.tag = htonl(0x1);
-	dl_command.size = htonl(size);
+	dl_command.sign = htobe32(0x424c5443); /* Signature: BLTC */
+	dl_command.tag = htobe32(0x1);
+	dl_command.size = htobe32(size);
 	dl_command.flags = 0;
 	dl_command.rsvd[0] = 0;
 	dl_command.rsvd[1] = 0;
 	dl_command.cmd = MXS_CMD_FW_DOWNLOAD;
-	dl_command.dw_size = htonl(size);
+	dl_command.dw_size = htobe32(size);
 
 	err = transfer(1, &dl_command, 20, &last_trans);
 	if (err) {
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 11 02:38:44 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 11:38:44 +0200
Subject: [PATCH 3/3] scripts: common: drop unused mman.h include
In-Reply-To: <20230411093844.1297004-1-a.fatoum@pengutronix.de>
References: <20230411093844.1297004-1-a.fatoum@pengutronix.de>
Message-ID: <20230411093844.1297004-4-a.fatoum@pengutronix.de>

<sys/mman.h> is for mmap use of which there is none in scripts/common.c.
Drop it. This has the additional benefit that the file is now compilable
with x86_64-w64-mingw32-gcc.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 scripts/common.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/scripts/common.c b/scripts/common.c
index e2c53c5aef71..88173bc9772a 100644
--- a/scripts/common.c
+++ b/scripts/common.c
@@ -9,7 +9,6 @@
 #include <string.h>
 #include <errno.h>
 #include <stdarg.h>
-#include <sys/mman.h>
 
 #include "common.h"
 
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 11 03:00:18 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 12:00:18 +0200
Subject: [PATCH v3 0/3] boards: qemu-virt: support passing in FIT public
 key
In-Reply-To: <20230313144220.1689252-1-a.fatoum@pengutronix.de>
References: <20230313144220.1689252-1-a.fatoum@pengutronix.de>
Message-ID: <a4ce283b-8b12-3a42-71cf-ad2acc99db15@pengutronix.de>

Hello Sascha,

please drop 

  a9d3244883d7 ("boards: qemu-virt: apply overlay at postcore_initcall level")
  e664ca8f7c35 ("boards: qemu-virt: compile overlay as such")
  224b5ef1da4c ("boards: qemu-virt: support passing in FIT public key")

again. I had been testing with ARM qemu_virt64_defconfig, but now that
I tested on RISC-V, I notice that non-qemu-virt platforms also execute
the initcall when they shouldn't and that DTC_CPP_FLAGS wasn't defined
for overlays leading to broken state there.

I'll send a revised version, but please drop the current one for now.

Thanks,
Ahmad

On 13.03.23 15:42, Ahmad Fatoum wrote:
> FIT public key is usually passed in via board DT. Usual way to use
> barebox with QEMU Virt however is to use DT supplied by Qemu and apply
> overlay to it. mkimage doesn't generate overlay DTB though. To make
> barbebox Qemu Virt behave like other boards, let's define a dummy DT
> that includes CONFIG_BOOTM_FITIMAGE_PUBKEY, which is merged with the
> barebox live device tree.
> 
> This replaces v2 of the series available in next and fixes the
> regressions I introduced for deep-probe systems that ensure probe in
> other devices.
> 
> I dropped Jan's Tested-by, because the differences warrant it, but
> I tested locally that a RSA key was registered as before.
> 
> v2 was here:
> https://lore.barebox.org/barebox/20230210165353.3601175-1-a.fatoum at pengutronix.de/
> 
> v2 -> v3:
>   - drop "support of_ensure_probed for top-level machine device"
>   - switch from board driver back to initcall
> 
> v1 -> v2:
>   - support of_ensure_probed for top-level machine device
>   - ensure qemu board driver is probed at postcore
> 
> Ahmad Fatoum (3):
>   boards: qemu-virt: apply overlay at postcore_initcall level
>   boards: qemu-virt: compile overlay as such
>   boards: qemu-virt: support passing in FIT public key
> 
>  common/boards/qemu-virt/Makefile              |  2 +-
>  common/boards/qemu-virt/board.c               | 52 +++++++++++--------
>  common/boards/qemu-virt/fitimage-pubkey.dts   |  7 +++
>  .../{overlay-of-flash.dts => flash.dtso}      |  0
>  4 files changed, 38 insertions(+), 23 deletions(-)
>  create mode 100644 common/boards/qemu-virt/fitimage-pubkey.dts
>  rename common/boards/qemu-virt/{overlay-of-flash.dts => flash.dtso} (100%)
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



From sha at pengutronix.de  Tue Apr 11 04:44:25 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Apr 2023 13:44:25 +0200
Subject: [PATCH master 00/14] treewide: fixes for master
In-Reply-To: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
References: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
Message-ID: <20230411114425.GC19113@pengutronix.de>

On Tue, Apr 11, 2023 at 09:14:22AM +0200, Ahmad Fatoum wrote:
> I am packaging barebox for NixOS, which is a tad different (and newer)
> than Debian, which I was previously using. This had me run into a couple
> of issues, which this PR addresses. All of them apply onto master.
> The fixes for next will be posted separately.
> 
> Ahmad Fatoum (14):
>   test: riscv: fix YAMLs after defconfig rename
>   RISC-V: board-dt-2nd: fix hang in startup
>   RISC-V: sifive: disable non-functional SPI nodes
>   video: qemu-ramfb: reduce -ENODEV lo level to debug
>   gpiolib: fix gpio label generation with gpiod_get
>   test: emulate.pl: fix firmware use with non-tuxmake out-of-tree build
>   RISC-V: restrict GCC optimization some more
>   RISC-V: configs: rv64i_defconfig: disable SBI serial
>   net: dsa: realtek: include needed headers directly
>   net: linux/mdio.h: add missing init.h header
>   Kbuild: export CROSS_PKG_CONFIG
>   treewide: fix includes missed by multiarch support
>   mci: dw_mmc: make reset optional

Applied 1-13, thanks

Sascha

>   kbuild: remove useless use of /usr/bin/env
> 
>  Documentation/boards/imx.rst                  |  4 ++--
>  Makefile                                      |  2 +-
>  arch/riscv/Makefile                           |  3 +++
>  arch/riscv/boot/board-dt-2nd.c                |  6 +++++
>  arch/riscv/configs/rv64i_defconfig            |  1 -
>  arch/riscv/dts/hifive-unleashed-a00.dts       |  4 ++++
>  arch/riscv/dts/hifive-unmatched-a00.dts       |  5 +++++
>  drivers/aiodev/am335x_adc.c                   |  2 +-
>  drivers/aiodev/imx_thermal.c                  |  2 +-
>  drivers/gpio/gpiolib.c                        |  2 +-
>  drivers/hab/hab.c                             |  2 +-
>  drivers/mci/dw_mmc.c                          |  2 +-
>  drivers/net/realtek-dsa/realtek-mdio.c        |  1 +
>  drivers/net/realtek-dsa/realtek-smi.c         |  1 +
>  drivers/net/realtek-dsa/rtl8365mb.c           |  2 ++
>  drivers/net/realtek-dsa/rtl8366rb.c           |  2 ++
>  drivers/net/realtek-dsa/tag_rtl4_a.c          |  1 +
>  drivers/net/realtek-dsa/tag_rtl8_4.c          |  1 +
>  drivers/nvmem/ocotp.c                         |  4 ++--
>  drivers/pci/pci-imx6.c                        |  6 ++---
>  drivers/pinctrl/imx-iomux-v2.c                |  2 +-
>  drivers/spi/atmel-quadspi.c                   |  6 ++---
>  drivers/video/imx-ipu-fb.c                    |  4 ++--
>  drivers/video/ramfb.c                         |  2 +-
>  include/linux/mdio.h                          |  1 +
>  scripts/Makefile.lib                          |  2 +-
>  scripts/regsubst.pl                           |  8 +++----
>  scripts/socfpga_xml_to_config.sh              |  4 ++--
>  test/emulate.pl                               | 22 ++++++++++---------
>  ....yaml => qemu-virt64 at rv64i_defconfig.yaml} |  0
>  test/riscv/rv64i_defconfig.yaml               |  1 +
>  ...onfig.yaml => sifive at rv64i_defconfig.yaml} |  0
>  ...nfig.yaml => tinyemu at rv64i_defconfig.yaml} |  0
>  test/riscv/virt64_defconfig.yaml              |  1 -
>  34 files changed, 67 insertions(+), 39 deletions(-)
>  rename test/riscv/{qemu at virt64_defconfig.yaml => qemu-virt64 at rv64i_defconfig.yaml} (100%)
>  create mode 120000 test/riscv/rv64i_defconfig.yaml
>  rename test/riscv/{sifive_defconfig.yaml => sifive at rv64i_defconfig.yaml} (100%)
>  rename test/riscv/{tinyemu at virt64_defconfig.yaml => tinyemu at rv64i_defconfig.yaml} (100%)
>  delete mode 120000 test/riscv/virt64_defconfig.yaml
> 
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Tue Apr 11 04:57:03 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Apr 2023 13:57:03 +0200
Subject: [PATCH master 14/14] kbuild: remove useless use of /usr/bin/env
In-Reply-To: <20230411071436.1630752-15-a.fatoum@pengutronix.de>
References: <20230411071436.1630752-1-a.fatoum@pengutronix.de>
 <20230411071436.1630752-15-a.fatoum@pengutronix.de>
Message-ID: <20230411115703.GD19113@pengutronix.de>

On Tue, Apr 11, 2023 at 09:14:36AM +0200, Ahmad Fatoum wrote:
> For some reason, NixOS failed to build device trees, because of the use
> of `/usr/bin/env echo -e` here. Given that calling /usr/bin/env is
> unneeded anyway for echo, let's just drop it and make the NixOS build
> problem go away as well.

/usr/bin/env was used on purpose here, likely because for example the
dash echo builtin does not support the -e option.

See
https://lore.barebox.org/barebox/20220120091433.GJ7102 at pengutronix.de/

Michael suggested to use printf back then.

Sascha

> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  scripts/Makefile.lib | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index 4deaa5dfa73c..8f6dcd7430a1 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -372,7 +372,7 @@ $(obj)/%.dtb.z: $(obj)/%.dtb FORCE
>  dts-frags = $(subst $(quote),,$(CONFIG_EXTERNAL_DTS_FRAGMENTS))
>  quiet_cmd_dtc = DTC     $@
>  # For compatibility between make 4.2 and 4.3
> -cmd_dtc = /usr/bin/env echo -e '$(pound)define $(subst -,_,$(*F))_dts 1\n'$(foreach f,$< $(2),'$(pound)include "$(f)"\n') | \
> +cmd_dtc = echo -e '$(pound)define $(subst -,_,$(*F))_dts 1\n'$(foreach f,$< $(2),'$(pound)include "$(f)"\n') | \
>  	$(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) - ; \
>  	$(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 \
>  		-i $(srctree)/arch/$(SRCARCH)/dts $(DTC_FLAGS) \
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Tue Apr 11 04:58:24 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Apr 2023 13:58:24 +0200
Subject: [PATCH] fixup! spi: add per-driver bits-per-word mask
In-Reply-To: <20230407095910.3778931-1-a.fatoum@pengutronix.de>
References: <20230407095910.3778931-1-a.fatoum@pengutronix.de>
Message-ID: <20230411115824.GE19113@pengutronix.de>

On Fri, Apr 07, 2023 at 11:59:10AM +0200, Ahmad Fatoum wrote:
> From: Ahmad Fatoum <ahmad at a3f.at>
> 
> Fixed up commit introduces instances of the BIT() and GENMASK() macros
> into the file. Add the appropriate header to go along with it.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  include/spi/spi.h | 1 +
>  1 file changed, 1 insertion(+)

Applied, thanks

Sascha

> 
> diff --git a/include/spi/spi.h b/include/spi/spi.h
> index d479e4f34f0c..f806c7a30b36 100644
> --- a/include/spi/spi.h
> +++ b/include/spi/spi.h
> @@ -6,6 +6,7 @@
>  #include <linux/err.h>
>  #include <linux/kernel.h>
>  #include <linux/string.h>
> +#include <linux/bitops.h>
>  
>  struct spi_controller_mem_ops;
>  
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Tue Apr 11 05:00:25 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Apr 2023 14:00:25 +0200
Subject: [PATCH v1 1/2] ARM: sama5d4_wifx: fix build with moved mach files
In-Reply-To: <20230407184356.GA1648837@ravnborg.org>
References: <20230407184356.GA1648837@ravnborg.org>
Message-ID: <20230411120025.GF19113@pengutronix.de>

On Fri, Apr 07, 2023 at 08:43:56PM +0200, Sam Ravnborg wrote:
> 
> Signed-off-by: Sam Ravnborg <sam at ravnborg.org>
> ---
>  arch/arm/boards/sama5d4_wifx/lowlevel.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/arch/arm/boards/sama5d4_wifx/lowlevel.c b/arch/arm/boards/sama5d4_wifx/lowlevel.c
> index 0c3529e659..c47b14c55b 100644
> --- a/arch/arm/boards/sama5d4_wifx/lowlevel.c
> +++ b/arch/arm/boards/sama5d4_wifx/lowlevel.c
> @@ -2,8 +2,8 @@
>  // SPDX-FileCopyrightText: 2022 Ahmad Fatoum, Pengutronix
>  
>  #include <debug_ll.h>
> -#include <mach/barebox-arm.h>
> -#include <mach/ddramc.h>
> +#include <mach/at91/barebox-arm.h>
> +#include <mach/at91/ddramc.h>
>  
>  SAMA5D4_ENTRY_FUNCTION(start_sama5d4_wifx_l1, r4)
>  {
> -- 
> 2.34.1
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Tue Apr 11 05:00:51 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Apr 2023 14:00:51 +0200
Subject: [PATCH v1 2/2] ARM: add sama5d4_wifx to at91_multi_defconfig
In-Reply-To: <20230407184500.GB1648837@ravnborg.org>
References: <20230407184500.GB1648837@ravnborg.org>
Message-ID: <20230411120051.GG19113@pengutronix.de>

On Fri, Apr 07, 2023 at 08:45:00PM +0200, Sam Ravnborg wrote:
> With this change we have more chances to catch build issues during
> refactoring.
> The board is added to get build coverage, it is not verified if it
> actually boots with this config.
> 
> Signed-off-by: Sam Ravnborg <sam at ravnborg.org>
> ---
>  arch/arm/configs/at91_multi_defconfig | 1 +
>  1 file changed, 1 insertion(+)

Applied, thanks

Sascha

> 
> diff --git a/arch/arm/configs/at91_multi_defconfig b/arch/arm/configs/at91_multi_defconfig
> index 6cbe013162..151f9a7069 100644
> --- a/arch/arm/configs/at91_multi_defconfig
> +++ b/arch/arm/configs/at91_multi_defconfig
> @@ -7,6 +7,7 @@ CONFIG_MACH_MICROCHIP_KSZ9477_EVB=y
>  CONFIG_MACH_SAMA5D3_XPLAINED=y
>  CONFIG_MACH_SAMA5D27_SOM1=y
>  CONFIG_MACH_SAMA5D27_GIANTBOARD=y
> +CONFIG_MACH_SAMA5D4_WIFX=y
>  CONFIG_AEABI=y
>  CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
>  CONFIG_ARM_UNWIND=y
> -- 
> 2.34.1
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Tue Apr 11 05:01:44 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Apr 2023 14:01:44 +0200
Subject: [PATCH master] treewide: add missing device tree artifact
 cleanup where needed
In-Reply-To: <20230408080616.938638-1-ahmad@a3f.at>
References: <20230408080616.938638-1-ahmad@a3f.at>
Message-ID: <20230411120144.GH19113@pengutronix.de>

On Sat, Apr 08, 2023 at 10:06:16AM +0200, Ahmad Fatoum wrote:
> The DTs in arch/$ARCH/dts are all cleaned up when invoking the make
> target, but we have a few DTs outside these directories.
> 
> Clean those up as well and add a clean line for the overlay too.
> 
> Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
> ---
>  arch/riscv/boards/riscvemu/Makefile | 3 +++
>  common/boards/qemu-virt/Makefile    | 3 +++
>  test/self/Makefile                  | 3 +++
>  3 files changed, 9 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/arch/riscv/boards/riscvemu/Makefile b/arch/riscv/boards/riscvemu/Makefile
> index 56949c2357c8..ec7e89479e77 100644
> --- a/arch/riscv/boards/riscvemu/Makefile
> +++ b/arch/riscv/boards/riscvemu/Makefile
> @@ -3,3 +3,6 @@
>  obj-y += board.o
>  obj-y += overlay-of-sram.dtb.o
>  bbenv-$(CONFIG_CMD_TUTORIAL) += defaultenv-riscvemu
> +
> +clean-files := *.dtb *.dtb.S .*.dtc .*.pre .*.dts *.dtb.z
> +clean-files += *.dtbo *.dtbo.S .*.dtso
> diff --git a/common/boards/qemu-virt/Makefile b/common/boards/qemu-virt/Makefile
> index 88184e9a7969..8cacfafee734 100644
> --- a/common/boards/qemu-virt/Makefile
> +++ b/common/boards/qemu-virt/Makefile
> @@ -5,3 +5,6 @@ obj-y += overlay-of-flash.dtb.o
>  ifeq ($(CONFIG_RISCV),y)
>  DTC_CPP_FLAGS_overlay-of-flash.dtb := -DRISCV_VIRT=1
>  endif
> +
> +clean-files := *.dtb *.dtb.S .*.dtc .*.pre .*.dts *.dtb.z
> +clean-files += *.dtbo *.dtbo.S .*.dtso
> diff --git a/test/self/Makefile b/test/self/Makefile
> index 4d2c0374c9c3..d55d9133be23 100644
> --- a/test/self/Makefile
> +++ b/test/self/Makefile
> @@ -8,3 +8,6 @@ obj-$(CONFIG_SELFTEST_OF_MANIPULATION) += of_manipulation.o of_manipulation.dtb.
>  obj-$(CONFIG_SELFTEST_ENVIRONMENT_VARIABLES) += envvar.o
>  obj-$(CONFIG_SELFTEST_FS_RAMFS) += ramfs.o
>  obj-$(CONFIG_SELFTEST_JSON) += json.o
> +
> +clean-files := *.dtb *.dtb.S .*.dtc .*.pre .*.dts *.dtb.z
> +clean-files += *.dtbo *.dtbo.S .*.dtso
> -- 
> 2.38.4
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Tue Apr 11 05:02:55 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Apr 2023 14:02:55 +0200
Subject: [PATCH v2 1/3] video: fb: add optional damage tracking
In-Reply-To: <20230405122734.2348025-1-p.zabel@pengutronix.de>
References: <20230405122734.2348025-1-p.zabel@pengutronix.de>
Message-ID: <20230411120255.GI19113@pengutronix.de>

On Wed, Apr 05, 2023 at 02:27:32PM +0200, Philipp Zabel wrote:
> Add an optional fb_damage operation that drivers may use to accumulate
> damage on the framebuffer until fb_flush is called. The accumulated
> damage can be used to support partial updates for displays with an
> integrated framebuffer.
> 
> Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
> ---
> v2: make rect parameter to fb_damage const
> ---
>  drivers/video/fb.c | 6 ++++++
>  include/fb.h       | 9 +++++++++
>  2 files changed, 15 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/drivers/video/fb.c b/drivers/video/fb.c
> index 44754065e7d9..6f412d62c434 100644
> --- a/drivers/video/fb.c
> +++ b/drivers/video/fb.c
> @@ -43,6 +43,12 @@ static int fb_close(struct cdev *cdev)
>  	return 0;
>  }
>  
> +void fb_damage(struct fb_info *info, struct fb_rect *rect)
> +{
> +	if (info->fbops->fb_damage)
> +		info->fbops->fb_damage(info, rect);
> +}
> +
>  static int fb_op_flush(struct cdev *cdev)
>  {
>  	struct fb_info *info = cdev->priv;
> diff --git a/include/fb.h b/include/fb.h
> index 15bb74b99576..88e6c0e45835 100644
> --- a/include/fb.h
> +++ b/include/fb.h
> @@ -80,6 +80,13 @@ struct fb_bitfield {
>  
>  struct fb_info;
>  
> +struct fb_rect {
> +	u32 x1;
> +	u32 y1;
> +	u32 x2;
> +	u32 y2;
> +};
> +
>  struct fb_ops {
>  	/* set color register */
>  	int (*fb_setcolreg)(unsigned regno, unsigned red, unsigned green,
> @@ -87,6 +94,7 @@ struct fb_ops {
>  	void (*fb_enable)(struct fb_info *info);
>  	void (*fb_disable)(struct fb_info *info);
>  	int (*fb_activate_var)(struct fb_info *info);
> +	void (*fb_damage)(struct fb_info *info, const struct fb_rect *rect);
>  	void (*fb_flush)(struct fb_info *info);
>  };
>  
> @@ -156,6 +164,7 @@ int register_framebuffer(struct fb_info *info);
>  
>  int fb_enable(struct fb_info *info);
>  int fb_disable(struct fb_info *info);
> +void fb_damage(struct fb_info *info, struct fb_rect *rect);
>  void fb_flush(struct fb_info *info);
>  
>  #define FBIOGET_SCREENINFO	_IOR('F', 1, loff_t)
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Tue Apr 11 05:30:18 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Apr 2023 14:30:18 +0200
Subject: [PATCH 0/3] scripts: imx: make imx-usb-loader compilable for
 MinGW
In-Reply-To: <20230411093844.1297004-1-a.fatoum@pengutronix.de>
References: <20230411093844.1297004-1-a.fatoum@pengutronix.de>
Message-ID: <20230411123018.GJ19113@pengutronix.de>

On Tue, Apr 11, 2023 at 11:38:41AM +0200, Ahmad Fatoum wrote:
> While the system flashing Linux is often running Linux itself, it may
> be Windows instead. To support this, let's support building
> imx-usb-loader for Windows.
> 
> Only compiled-tested on Debian 11 with:
> 
>    x86_64-w64-mingw32-gcc (GCC) 10-win32 20210110 (gcc-mingw-w64-x86-64-posix)
>    libusb-1.0.26-binaries.7z  (from Github releases page)
> 
>   CC=${CC:-x86_64-w64-mingw32-gcc}
>   LIBUSB=${LIBUSB:-../libusb-binaries}
>   
>   CPPFLAGS="-isystem $LIBUSB -I scripts/include/ -I include/mach/"
>   LDFLAGS="-L $LIBUSB -lusb-1.0"
>   
>   $CC -c -o imx.o scripts/imx/imx.c $CPPFLAGS
>   $CC -c -o imx-usb-loader.o scripts/imx/imx-usb-loader.c $CPPFLAGS
>   
>   $CC -o imx-usb-loader.exe imx.o imx-usb-loader.o $LDFLAGS
> 
> 
> Ahmad Fatoum (3):
>   imx-usb-loader: don't depend on arpa/inet.h for endianness conversion
>   scripts: compiler.h: add Windows support
>   scripts: common: drop unused mman.h include

Applied, thanks

Sascha

> 
>  scripts/common.c             |  1 -
>  scripts/compiler.h           | 33 ++++++++++++++++++++++++
>  scripts/imx/imx-usb-loader.c | 49 ++++++++++++++++++------------------
>  3 files changed, 57 insertions(+), 26 deletions(-)
> 
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Tue Apr 11 05:34:06 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Apr 2023 14:34:06 +0200
Subject: [PATCH] ARM: LS1021A: slow boot
In-Reply-To: <BL0PR07MB5665E8DA118845ED96A8289DEC959@BL0PR07MB5665.namprd07.prod.outlook.com>
References: <BL0PR07MB5665E8DA118845ED96A8289DEC959@BL0PR07MB5665.namprd07.prod.outlook.com>
Message-ID: <20230411123406.GK19113@pengutronix.de>

On Mon, Apr 10, 2023 at 02:58:08PM +0000, Renaud Barbier wrote:
> It was noticed that the LS1021A-IOT was slow to boot and perform
> computing intensive operations. Enable SMP so the cortex-a7 cache
> works as expected.
> 
> Signed-off-by: Renaud Barbier mailto:renaud.barbier at ametek.com
> ---
>  arch/arm/boards/ls1021aiot/lowlevel.c       | 1 -
>  arch/arm/mach-layerscape/lowlevel-ls102xa.c | 4 ++++
>  2 files changed, 4 insertions(+), 1 deletion(-)

Applied, thanks

Sascha

> 
> diff --git a/arch/arm/boards/ls1021aiot/lowlevel.c b/arch/arm/boards/ls1021aiot/lowlevel.c
> index 4dec451558..b7106887f2 100644
> --- a/arch/arm/boards/ls1021aiot/lowlevel.c
> +++ b/arch/arm/boards/ls1021aiot/lowlevel.c
> @@ -86,7 +86,6 @@ static noinline __noreturn void ls1021aiot_r_entry(void)
>                   __dtb_fsl_ls1021a_iot_start);
>     }
> 
> -   arm_cpu_lowlevel_init();
>     ls102xa_init_lowlevel();
>     ls102xa_debug_ll_init();
> 
> diff --git a/arch/arm/mach-layerscape/lowlevel-ls102xa.c b/arch/arm/mach-layerscape/lowlevel-ls102xa.c
> index 7f4fcdf55c..259d8866d5 100644
> --- a/arch/arm/mach-layerscape/lowlevel-ls102xa.c
> +++ b/arch/arm/mach-layerscape/lowlevel-ls102xa.c
> @@ -6,6 +6,7 @@
>  #include <common.h>
>  #include <io.h>
>  #include <clock.h>
> +#include <asm/barebox-arm-head.h>
>  #include <asm/syscounter.h>
>  #include <asm/system.h>
>  #include <mach/layerscape/errata.h>
> @@ -311,6 +312,9 @@ void ls102xa_init_lowlevel(void)
>     uint32_t state, major, ctrl, freq;
>     uint64_t val;
> 
> +   cortex_a7_lowlevel_init();
> +   arm_cpu_lowlevel_init();
> +
>     init_csu();
> 
>     writel(SYS_COUNTER_CTRL_ENABLE, LSCH2_SYS_COUNTER_ADDR);
> --
> 2.34.1
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Tue Apr 11 05:35:36 2023
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Apr 2023 14:35:36 +0200
Subject: [PATCH v3 0/3] boards: qemu-virt: support passing in FIT public
 key
In-Reply-To: <a4ce283b-8b12-3a42-71cf-ad2acc99db15@pengutronix.de>
References: <20230313144220.1689252-1-a.fatoum@pengutronix.de>
 <a4ce283b-8b12-3a42-71cf-ad2acc99db15@pengutronix.de>
Message-ID: <20230411123536.GL19113@pengutronix.de>

On Tue, Apr 11, 2023 at 12:00:18PM +0200, Ahmad Fatoum wrote:
> Hello Sascha,
> 
> please drop 
> 
>   a9d3244883d7 ("boards: qemu-virt: apply overlay at postcore_initcall level")
>   e664ca8f7c35 ("boards: qemu-virt: compile overlay as such")
>   224b5ef1da4c ("boards: qemu-virt: support passing in FIT public key")
> 
> again. I had been testing with ARM qemu_virt64_defconfig, but now that
> I tested on RISC-V, I notice that non-qemu-virt platforms also execute
> the initcall when they shouldn't and that DTC_CPP_FLAGS wasn't defined
> for overlays leading to broken state there.
> 
> I'll send a revised version, but please drop the current one for now.

Ok, did that.

Sascha

> 
> Thanks,
> Ahmad
> 
> On 13.03.23 15:42, Ahmad Fatoum wrote:
> > FIT public key is usually passed in via board DT. Usual way to use
> > barebox with QEMU Virt however is to use DT supplied by Qemu and apply
> > overlay to it. mkimage doesn't generate overlay DTB though. To make
> > barbebox Qemu Virt behave like other boards, let's define a dummy DT
> > that includes CONFIG_BOOTM_FITIMAGE_PUBKEY, which is merged with the
> > barebox live device tree.
> > 
> > This replaces v2 of the series available in next and fixes the
> > regressions I introduced for deep-probe systems that ensure probe in
> > other devices.
> > 
> > I dropped Jan's Tested-by, because the differences warrant it, but
> > I tested locally that a RSA key was registered as before.
> > 
> > v2 was here:
> > https://lore.barebox.org/barebox/20230210165353.3601175-1-a.fatoum at pengutronix.de/
> > 
> > v2 -> v3:
> >   - drop "support of_ensure_probed for top-level machine device"
> >   - switch from board driver back to initcall
> > 
> > v1 -> v2:
> >   - support of_ensure_probed for top-level machine device
> >   - ensure qemu board driver is probed at postcore
> > 
> > Ahmad Fatoum (3):
> >   boards: qemu-virt: apply overlay at postcore_initcall level
> >   boards: qemu-virt: compile overlay as such
> >   boards: qemu-virt: support passing in FIT public key
> > 
> >  common/boards/qemu-virt/Makefile              |  2 +-
> >  common/boards/qemu-virt/board.c               | 52 +++++++++++--------
> >  common/boards/qemu-virt/fitimage-pubkey.dts   |  7 +++
> >  .../{overlay-of-flash.dts => flash.dtso}      |  0
> >  4 files changed, 38 insertions(+), 23 deletions(-)
> >  create mode 100644 common/boards/qemu-virt/fitimage-pubkey.dts
> >  rename common/boards/qemu-virt/{overlay-of-flash.dts => flash.dtso} (100%)
> > 
> 
> -- 
> Pengutronix e.K.                           |                             |
> Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From a.fatoum at pengutronix.de  Tue Apr 11 05:42:50 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 11 Apr 2023 14:42:50 +0200
Subject: [PATCH] Documentation: barebox environment: recommend a partition
 type GUID for GPT partitions
In-Reply-To: <20230327131218.247157-1-m.felsch@pengutronix.de>
References: <20230327131218.247157-1-m.felsch@pengutronix.de>
Message-ID: <3e9a6489-127b-e30c-9dc7-cd3666dc63b5@pengutronix.de>

On 27.03.23 15:12, Marco Felsch wrote:
> The partition type GUID was generated randomly. Having a defined GUID
> should reduce the risk of collisions in the future.
> 
> The GUID and a phandle reference to the storage medium could be used as
> replacement for device-path if the medium supports GPT.
> 
> Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>

Reviewed-by: Ahmad Fatoum <a.fatoum at pengutronix.de>

> ---
>  .../devicetree/bindings/barebox/barebox,environment.rst        | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/barebox/barebox,environment.rst b/Documentation/devicetree/bindings/barebox/barebox,environment.rst
> index 8a57bf1add..40239f424a 100644
> --- a/Documentation/devicetree/bindings/barebox/barebox,environment.rst
> +++ b/Documentation/devicetree/bindings/barebox/barebox,environment.rst
> @@ -23,6 +23,9 @@ the path to the environment. Supported values for <type>:
>    be the label for MTD partitions, the number for DOS
>    partitions (beginning with 0) or the name for GPT partitions.
>  
> +If the *environmnet* is located in a GPT partition, use
> +``6C3737F2-07F8-45D1-AD45-15D260AAB24D`` as partition type GUID.
> +
>  The file-path is the name of a file located in a FAT filesystem on the
>  device named in device-path.  This filesystem will be mounted and the
>  environment loaded from the file's location in the directory tree.

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



From sha at pengutronix.de  Tue Apr 11 06:10:24 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Apr 2023 15:10:24 +0200
Subject: [PATCH v2 1/2] scripts: gen-dtb-s: reference OF IMD entries
 automatically
In-Reply-To: <20230404101706.2237453-1-a.fatoum@pengutronix.de>
References: <20230404101706.2237453-1-a.fatoum@pengutronix.de>
Message-ID: <20230411131024.GN19113@pengutronix.de>

On Tue, Apr 04, 2023 at 12:17:05PM +0200, Ahmad Fatoum wrote:
> We currently require IMD_OF_USED to get the DT compatible into the
> barebox image data meta section. As the PBL is already referencing the
> DT to pass it along to barebox proper, let's add a reference from the DT
> to the image data section to make IMD_OF_USED unnecessary.
> 
> Suggested-by: Antony Pavlov <antonynpavlov at gmail.com>
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> --
> v1 -> v2:
>   - use dword, to fix build for 64-bit (Sascha)
>   - place IMD reference before STRUCT_ALIGNMENT
> ---
>  scripts/gen-dtb-s | 6 ++++++
>  1 file changed, 6 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
> index c5c46a4d8675..6309a814a483 100755
> --- a/scripts/gen-dtb-s
> +++ b/scripts/gen-dtb-s
> @@ -49,6 +49,9 @@ echo "__dtb_${name}_start:"
>  echo ".incbin \"$dtb\""
>  echo "__dtb_${name}_end:"
>  echo ".global __dtb_${name}_end"
> +if [ "$imd" = "y" ]; then
> +	echo ".dword __barebox_imd_OF_${name}"
> +fi
>  echo ".balign STRUCT_ALIGNMENT"
>  
>  compressed=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" $dtb.z)
> @@ -65,5 +68,8 @@ printf ".int 0x%08x\n"  $uncompressed
>  echo ".incbin \"$dtb.z\""
>  echo "__dtb_z_${name}_end:"
>  echo ".global __dtb_z_${name}_end"
> +if [ "$imd" = "y" ]; then
> +	echo ".dword __barebox_imd_OF_${name}"
> +fi
>  echo ".balign STRUCT_ALIGNMENT"
>  echo "#endif"
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Tue Apr 11 06:13:31 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Apr 2023 15:13:31 +0200
Subject: [PATCH] clock: implement CLOCKSOURCE_MASK in terms of GENMASK_ULL
In-Reply-To: <20230404101914.2244083-1-a.fatoum@pengutronix.de>
References: <20230404101914.2244083-1-a.fatoum@pengutronix.de>
Message-ID: <20230411131331.GO19113@pengutronix.de>

On Tue, Apr 04, 2023 at 12:19:14PM +0200, Ahmad Fatoum wrote:
> Clang doesn't like our implementation of CLOCKSOURCE_MASK:
> 
>   common/clock.c:33:10: warning: shift count >= width of type [-Wshift-count-overflow]
> 	.mask = CLOCKSOURCE_MASK(64),
>                 ^~~~~~~~~~~~~~~~~~~~
>   include/clock.h:8:63: note: expanded from macro 'CLOCKSOURCE_MASK'
> 	 #define CLOCKSOURCE_MASK(bits) (uint64_t)((bits) < 64 ? ((1ULL<<(bits))-1) : -1)
> 
> So the bits < 64 check we have is apparently not enough to suppress the
> warning when built with clang.
> 
> Let's do what the kernel does and use GENMASK_ULL instead to get rid of
> the last remaining warning when building ARCH=sandbox targettools_defconfig
> with clang version 16.0.1.
> 
> Not functional change intended.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  include/clock.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Applied, thanks

Sascha

> 
> diff --git a/include/clock.h b/include/clock.h
> index 8e07c35d374e..03a38911a7a7 100644
> --- a/include/clock.h
> +++ b/include/clock.h
> @@ -4,8 +4,9 @@
>  
>  #include <types.h>
>  #include <linux/time.h>
> +#include <linux/bitops.h>
>  
> -#define CLOCKSOURCE_MASK(bits) (uint64_t)((bits) < 64 ? ((1ULL<<(bits))-1) : -1)
> +#define CLOCKSOURCE_MASK(bits) GENMASK_ULL((bits) - 1, 0)
>  
>  struct clocksource {
>  	uint32_t	shift;
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Tue Apr 11 06:14:04 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Apr 2023 15:14:04 +0200
Subject: [PATCH] video: fbconsole: implement non-fullscreen fbconsole
In-Reply-To: <20230405130645.2407719-1-p.zabel@pengutronix.de>
References: <20230405130645.2407719-1-p.zabel@pengutronix.de>
Message-ID: <20230411131404.GP19113@pengutronix.de>

On Wed, Apr 05, 2023 at 03:06:45PM +0200, Philipp Zabel wrote:
> Let fbconsole cover only part of the screen.
> Configurable via margin.{left,top,right,bottom} device parameters.
> 
> Signed-off-by: Philipp Zabel <p.zabel at pengutronix.de>
> ---
>  drivers/video/fbconsole.c | 115 +++++++++++++++++++++++++++++++++-----
>  1 file changed, 101 insertions(+), 14 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
> index 070378aa2352..6c85e8e06a8c 100644
> --- a/drivers/video/fbconsole.c
> +++ b/drivers/video/fbconsole.c
> @@ -18,6 +18,12 @@ enum state_t {
>  struct fbc_priv {
>  	struct console_device cdev;
>  	struct fb_info *fb;
> +	struct {
> +		u32 top;
> +		u32 left;
> +		u32 bottom;
> +		u32 right;
> +	} margin;
>  
>  	struct screen *sc;
>  
> @@ -60,9 +66,26 @@ static int fbc_tstc(struct console_device *cdev)
>  static void cls(struct fbc_priv *priv)
>  {
>  	void *buf = gui_screen_render_buffer(priv->sc);
> +	struct fb_info *fb = priv->fb;
> +	int width = fb->xres - priv->margin.left - priv->margin.right;
> +	int height = fb->yres - priv->margin.top - priv->margin.bottom;
> +	void *adr;
> +
> +	adr = buf + priv->fb->line_length * priv->margin.top;
> +
> +	if (!priv->margin.left && !priv->margin.right) {
> +		memset(adr, 0, priv->fb->line_length * height);
> +	} else {
> +		int bpp = priv->fb->bits_per_pixel >> 3;
> +		int y;
>  
> -	memset(buf, 0, priv->fb->line_length * priv->fb->yres);
> -	gu_screen_blit(priv->sc);
> +		for (y = 0; y < height; y++) {
> +			memset(adr + priv->margin.left * bpp, 0, width * bpp);
> +			adr += priv->fb->line_length;
> +		}
> +	}
> +	gu_screen_blit_area(priv->sc, priv->margin.left, priv->margin.top,
> +			    width, height);
>  }
>  
>  struct rgb {
> @@ -122,7 +145,8 @@ static void drawchar(struct fbc_priv *priv, int x, int y, int c)
>  		uint8_t t = inbuf[i];
>  		int j;
>  
> -		adr = buf + line_length * (y * priv->font->height + i) + x * priv->font->width * bpp;
> +		adr = buf + line_length * (priv->margin.top + y * priv->font->height + i) +
> +		      (priv->margin.left + x * priv->font->width) * bpp;
>  
>  		for (j = 0; j < priv->font->width; j++) {
>  			if (t & 0x80)
> @@ -142,9 +166,11 @@ static void video_invertchar(struct fbc_priv *priv, int x, int y)
>  
>  	buf = gui_screen_render_buffer(priv->sc);
>  
> -	gu_invert_area(priv->fb, buf, x * priv->font->width, y * priv->font->height,
> +	gu_invert_area(priv->fb, buf, priv->margin.left + x * priv->font->width,
> +			priv->margin.top + y * priv->font->height,
>  			priv->font->width, priv->font->height);
> -	gu_screen_blit_area(priv->sc, x * priv->font->width, y * priv->font->height,
> +	gu_screen_blit_area(priv->sc, priv->margin.left + x * priv->font->width,
> +			priv->margin.top + y * priv->font->height,
>  			priv->font->width, priv->font->height);
>  }
>  
> @@ -185,8 +211,9 @@ static void printchar(struct fbc_priv *priv, int c)
>  	default:
>  		drawchar(priv, priv->x, priv->y, c);
>  
> -		gu_screen_blit_area(priv->sc, priv->x * priv->font->width,
> -				priv->y * priv->font->height,
> +		gu_screen_blit_area(priv->sc,
> +				priv->margin.left + priv->x * priv->font->width,
> +				priv->margin.top + priv->y * priv->font->height,
>  				priv->font->width, priv->font->height);
>  
>  		priv->x++;
> @@ -198,15 +225,36 @@ static void printchar(struct fbc_priv *priv, int c)
>  
>  	if (priv->y > priv->rows) {
>  		void *buf;
> +		void *adr;
>  		u32 line_length = priv->fb->line_length;
>  		int line_height = line_length * priv->font->height;
> +		int width = priv->fb->xres - priv->margin.left - priv->margin.right;
> +		int height = (priv->rows + 1) * priv->font->height;
>  
>  		buf = gui_screen_render_buffer(priv->sc);
> +		adr = buf + priv->margin.top * line_length;
> +
> +		if (!priv->margin.left && !priv->margin.right) {
> +			memcpy(adr, adr + line_height, line_height * priv->rows);
> +			memset(adr + line_height * priv->rows, 0, line_height);
> +		} else {
> +			int bpp = priv->fb->bits_per_pixel >> 3;
> +			int y;
> +
> +			adr += priv->margin.left * bpp;
> +
> +			for (y = 0; y < height - priv->font->height; y++) {
> +				memcpy(adr, adr + line_height, width * bpp);
> +				adr += line_length;
> +			}
> +			for (y = height - priv->font->height; y < height; y++) {
> +				memset(adr, 0, width * bpp);
> +				adr += line_length;
> +			}
> +		}
>  
> -		memcpy(buf, buf + line_height, line_height * priv->rows);
> -		memset(buf + line_height * priv->rows, 0, line_height);
> -
> -		gu_screen_blit(priv->sc);
> +		gu_screen_blit_area(priv->sc, priv->margin.left, priv->margin.top,
> +				width, height);
>  		priv->y = priv->rows;
>  	}
>  
> @@ -401,8 +449,9 @@ static void fbc_putc(struct console_device *cdev, char c)
>  
>  static int setup_font(struct fbc_priv *priv)
>  {
> -	struct fb_info *fb = priv->fb;
>  	const struct font_desc *font;
> +	unsigned int height = priv->fb->yres - priv->margin.top - priv->margin.bottom;
> +	unsigned int width = priv->fb->xres - priv->margin.left - priv->margin.right;
>  
>  	font = find_font_enum(priv->par_font_val);
>  	if (!font) {
> @@ -411,8 +460,8 @@ static int setup_font(struct fbc_priv *priv)
>  
>  	priv->font = font;
>  
> -	priv->rows = fb->yres / priv->font->height - 1;
> -	priv->cols = fb->xres / priv->font->width - 1;
> +	priv->rows = height / priv->font->height - 1;
> +	priv->cols = width / priv->font->width - 1;
>  
>  	return 0;
>  }
> @@ -472,6 +521,35 @@ static int set_font(struct param_d *p, void *vpriv)
>  	return 0;
>  }
>  
> +static int set_margin(struct param_d *p, void *vpriv)
> +{
> +	struct fbc_priv *priv = vpriv;
> +	struct console_device *cdev = &priv->cdev;
> +	int ret;
> +
> +	if (!priv->font) {
> +		ret = setup_font(priv);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	priv->margin.left = min(priv->margin.left,
> +			priv->fb->xres - priv->margin.right - priv->font->width);
> +	priv->margin.top = min(priv->margin.top,
> +			priv->fb->yres - priv->margin.bottom - priv->font->height);
> +	priv->margin.right = min(priv->margin.right,
> +			priv->fb->xres - priv->margin.left - priv->font->width);
> +	priv->margin.bottom = min(priv->margin.bottom,
> +			priv->fb->yres - priv->margin.top - priv->font->height);
> +
> +	if (cdev->f_active & (CONSOLE_STDOUT | CONSOLE_STDERR)) {
> +		cls(priv);
> +		setup_font(priv);
> +	}
> +
> +	return 0;
> +}
> +
>  int register_fbconsole(struct fb_info *fb)
>  {
>  	struct fbc_priv *priv;
> @@ -508,6 +586,15 @@ int register_fbconsole(struct fb_info *fb)
>  			set_font, NULL,
>  			&priv->par_font_val, priv);
>  
> +	dev_add_param_uint32(&cdev->class_dev, "margin.top", set_margin,
> +			NULL, &priv->margin.top, "%u", priv);
> +	dev_add_param_uint32(&cdev->class_dev, "margin.left", set_margin,
> +			NULL, &priv->margin.left, "%u", priv);
> +	dev_add_param_uint32(&cdev->class_dev, "margin.bottom", set_margin,
> +			NULL, &priv->margin.bottom, "%u", priv);
> +	dev_add_param_uint32(&cdev->class_dev, "margin.right", set_margin,
> +			NULL, &priv->margin.right, "%u", priv);
> +
>  	pr_info("registered as %s%d\n", cdev->class_dev.name, cdev->class_dev.id);
>  
>  	return 0;
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Tue Apr 11 06:14:39 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Apr 2023 15:14:39 +0200
Subject: [PATCH] Documentation: barebox environment: recommend a
 partition type GUID for GPT partitions
In-Reply-To: <20230327131218.247157-1-m.felsch@pengutronix.de>
References: <20230327131218.247157-1-m.felsch@pengutronix.de>
Message-ID: <20230411131439.GQ19113@pengutronix.de>

On Mon, Mar 27, 2023 at 03:12:18PM +0200, Marco Felsch wrote:
> The partition type GUID was generated randomly. Having a defined GUID
> should reduce the risk of collisions in the future.
> 
> The GUID and a phandle reference to the storage medium could be used as
> replacement for device-path if the medium supports GPT.
> 
> Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
> ---
>  .../devicetree/bindings/barebox/barebox,environment.rst        | 3 +++
>  1 file changed, 3 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/Documentation/devicetree/bindings/barebox/barebox,environment.rst b/Documentation/devicetree/bindings/barebox/barebox,environment.rst
> index 8a57bf1add..40239f424a 100644
> --- a/Documentation/devicetree/bindings/barebox/barebox,environment.rst
> +++ b/Documentation/devicetree/bindings/barebox/barebox,environment.rst
> @@ -23,6 +23,9 @@ the path to the environment. Supported values for <type>:
>    be the label for MTD partitions, the number for DOS
>    partitions (beginning with 0) or the name for GPT partitions.
>  
> +If the *environmnet* is located in a GPT partition, use
> +``6C3737F2-07F8-45D1-AD45-15D260AAB24D`` as partition type GUID.
> +
>  The file-path is the name of a file located in a FAT filesystem on the
>  device named in device-path.  This filesystem will be mounted and the
>  environment loaded from the file's location in the directory tree.
> -- 
> 2.30.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From a.fatoum at pengutronix.de  Wed Apr 12 02:01:05 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 12 Apr 2023 11:01:05 +0200
Subject: [PATCH] commands: menu: enable help text parsing for sphinx docs
Message-ID: <20230412090105.4160849-1-a.fatoum@pengutronix.de>

Use of the macros is required, so Documentation/gen_commands.py may
format it into ReST for the documentation.

Reported-by: Leonard G?hrs <l.goehrs at pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 commands/menu.c | 107 ++++++++++++++++++++++++------------------------
 1 file changed, 54 insertions(+), 53 deletions(-)

diff --git a/commands/menu.c b/commands/menu.c
index 7a01aff28066..e0fe09b5088b 100644
--- a/commands/menu.c
+++ b/commands/menu.c
@@ -406,64 +406,65 @@ end:
 	return 1;
 }
 
-static const __maybe_unused char cmd_menu_help[] =
-"Manage Menu:\n"
-"  -m  menu\n"
-"  -l  list\n"
-"  -s  show\n"
+BAREBOX_CMD_HELP_START(menu)
+BAREBOX_CMD_HELP_TEXT("Manage Menu:")
+BAREBOX_CMD_HELP_OPT ("-m", "menu")
+BAREBOX_CMD_HELP_OPT ("-l", "list")
+BAREBOX_CMD_HELP_OPT ("-s", "show")
+BAREBOX_CMD_HELP_TEXT("")
 #if defined(CONFIG_CMD_MENU_MANAGEMENT)
-"Advanced menu management:\n"
-"  -e  menu entry\n"
-"  -a  add\n"
-"  -r  remove\n"
-"  -S  select\n"
+BAREBOX_CMD_HELP_TEXT("Advanced menu management:")
+BAREBOX_CMD_HELP_OPT ("-e", "menu entry")
+BAREBOX_CMD_HELP_OPT ("-a", "add")
+BAREBOX_CMD_HELP_OPT ("-r", "remove")
+BAREBOX_CMD_HELP_OPT ("-S", "select")
+BAREBOX_CMD_HELP_TEXT("")
 #endif
-"\n"
-"Show menu:\n"
-"  (-A auto select delay)\n"
-"  (-d auto select description)\n"
-"  menu -s -m MENU [-A delay] [-d auto_display]\n"
-"\n"
-"List menu:\n"
-"  menu -l\n"
-"\n"
+BAREBOX_CMD_HELP_TEXT("Show menu:")
+BAREBOX_CMD_HELP_OPT ("-A", "auto select delay")
+BAREBOX_CMD_HELP_OPT ("-d", "auto select description")
+BAREBOX_CMD_HELP_TEXT("\tmenu -s -m MENU [-A delay] [-d auto_display]")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("List menu:")
+BAREBOX_CMD_HELP_TEXT("\tmenu -l\n")
+BAREBOX_CMD_HELP_TEXT("")
 #if defined(CONFIG_CMD_MENU_MANAGEMENT)
-"Add a menu:\n"
-"  menu -a -m NAME -d DESC\n"
-"\n"
-"Remove a menu:\n"
-"  menu -r -m NAME\n"
-"\n"
-"Add an entry:\n"
-"  (-R for do no exit the menu after executing the command)\n"
-"  (-b for box style 1 for selected)\n"
-"  (and optional -c for the command to run when we change the state)\n"
-"  menu -e -a -m MENU -c COMMAND [-R] [-b 0|1] -d DESC\n"
-
-"Add a submenu entry:\n"
-"  (-R is not needed)\n"
-"  (-b for box style 1 for selected)\n"
-"  (and -c is not needed)\n"
-"  menu -e -a -m MENU -u submenu -d [-b 0|1] DESC\n"
-"\n"
-"Remove an entry:\n"
-"  menu -e -r -m NAME -n ENTRY\n"
-"\n"
-"Select an entry:\n"
-"  menu -m <menu> -S -n ENTRY\n"
-"\n"
-"List menu:\n"
-"  menu -e -l [menu]\n"
-"\n"
-"Menu examples:\n"
-"  menu -a -m boot -d \"Boot Menu\"\n"
-"  menu -e -a -m boot -c boot -d \"Boot\"\n"
-"  menu -e -a -m boot -c reset -d \"Reset\"\n"
+BAREBOX_CMD_HELP_TEXT("Add a menu:")
+BAREBOX_CMD_HELP_TEXT("\tmenu -a -m NAME -d DESC")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Remove a menu:")
+BAREBOX_CMD_HELP_TEXT("\tmenu -r -m NAME")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Add an entry:")
+BAREBOX_CMD_HELP_TEXT("\t(-R for do no exit the menu after executing the command)")
+BAREBOX_CMD_HELP_TEXT("\t(-b for box style 1 for selected)")
+BAREBOX_CMD_HELP_TEXT("\t(and optional -c for the command to run when we change the state)")
+BAREBOX_CMD_HELP_TEXT("\tmenu -e -a -m MENU -c COMMAND [-R] [-b 0|1] -d DESC")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Add a submenu entry:")
+BAREBOX_CMD_HELP_TEXT("\t(-R is not needed)")
+BAREBOX_CMD_HELP_TEXT("\t(-b for box style 1 for selected)")
+BAREBOX_CMD_HELP_TEXT("\t(and -c is not needed)")
+BAREBOX_CMD_HELP_TEXT("\tmenu -e -a -m MENU -u submenu -d [-b 0|1] DESC")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Remove an entry:")
+BAREBOX_CMD_HELP_TEXT("\tmenu -e -r -m NAME -n ENTRY")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Select an entry:")
+BAREBOX_CMD_HELP_TEXT("\tmenu -m <menu> -S -n ENTRY")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("List menu:")
+BAREBOX_CMD_HELP_TEXT("\tmenu -e -l [menu]")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Menu examples:")
+BAREBOX_CMD_HELP_TEXT("\tmenu -a -m boot -d \"Boot Menu\"")
+BAREBOX_CMD_HELP_TEXT("\tmenu -e -a -m boot -c boot -d \"Boot\"")
+BAREBOX_CMD_HELP_TEXT("\tmenu -e -a -m boot -c reset -d \"Reset\"")
 #else
-"Menu example:\n"
+BAREBOX_CMD_HELP_TEXT("Menu example:")
 #endif
-"  menu -s -m boot\n"
-;
+BAREBOX_CMD_HELP_TEXT("\tmenu -s -m boot")
+BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(menu)
 	.cmd		= do_menu,
-- 
2.39.2



From sha at pengutronix.de  Wed Apr 12 03:58:10 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Apr 2023 12:58:10 +0200
Subject: [PATCH v2 1/2] scripts: gen-dtb-s: reference OF IMD entries
 automatically
In-Reply-To: <20230404101706.2237453-1-a.fatoum@pengutronix.de>
References: <20230404101706.2237453-1-a.fatoum@pengutronix.de>
Message-ID: <20230412105810.GK15436@pengutronix.de>

On Tue, Apr 04, 2023 at 12:17:05PM +0200, Ahmad Fatoum wrote:
> We currently require IMD_OF_USED to get the DT compatible into the
> barebox image data meta section. As the PBL is already referencing the
> DT to pass it along to barebox proper, let's add a reference from the DT
> to the image data section to make IMD_OF_USED unnecessary.
> 
> Suggested-by: Antony Pavlov <antonynpavlov at gmail.com>
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> --
> v1 -> v2:
>   - use dword, to fix build for 64-bit (Sascha)

Indeed it fixes it for 64-bit, but now breaks it for 32-bit. Do we have
to #ifdef this or is there something clever we can do about this?

Sascha

>   - place IMD reference before STRUCT_ALIGNMENT
> ---
>  scripts/gen-dtb-s | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
> index c5c46a4d8675..6309a814a483 100755
> --- a/scripts/gen-dtb-s
> +++ b/scripts/gen-dtb-s
> @@ -49,6 +49,9 @@ echo "__dtb_${name}_start:"
>  echo ".incbin \"$dtb\""
>  echo "__dtb_${name}_end:"
>  echo ".global __dtb_${name}_end"
> +if [ "$imd" = "y" ]; then
> +	echo ".dword __barebox_imd_OF_${name}"
> +fi
>  echo ".balign STRUCT_ALIGNMENT"
>  
>  compressed=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" $dtb.z)
> @@ -65,5 +68,8 @@ printf ".int 0x%08x\n"  $uncompressed
>  echo ".incbin \"$dtb.z\""
>  echo "__dtb_z_${name}_end:"
>  echo ".global __dtb_z_${name}_end"
> +if [ "$imd" = "y" ]; then
> +	echo ".dword __barebox_imd_OF_${name}"
> +fi
>  echo ".balign STRUCT_ALIGNMENT"
>  echo "#endif"
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From a.fatoum at pengutronix.de  Wed Apr 12 04:22:32 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 12 Apr 2023 13:22:32 +0200
Subject: [PATCH] fixup! scripts: gen-dtb-s: reference OF IMD entries automatically
In-Reply-To: <20230412105810.GK15436@pengutronix.de>
References: <20230412105810.GK15436@pengutronix.de>
Message-ID: <20230412112232.422198-1-a.fatoum@pengutronix.de>

Apparently, .dword is not supported for 32-bit ARM builds.

Let's define ASM_PTR that expands to either .dword or .word and use
that instead.

The definition is taken from RISCV_PTR in arch/riscv/include/asm/asm.h.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
Sascha, how about this?
---
 include/asm-generic/pointer.h | 30 ++++++++++++++++++++++++++++++
 scripts/gen-dtb-s             |  5 +++--
 2 files changed, 33 insertions(+), 2 deletions(-)
 create mode 100644 include/asm-generic/pointer.h

diff --git a/include/asm-generic/pointer.h b/include/asm-generic/pointer.h
new file mode 100644
index 000000000000..a0ea084b983c
--- /dev/null
+++ b/include/asm-generic/pointer.h
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __ASM_GENERIC_PTR_H___
+#define __ASM_GENERIC_PTR_H___
+
+#if __SIZEOF_POINTER__ == 8
+#ifdef __ASSEMBLY__
+#define ASM_PTR		.dword
+#define ASM_SZPTR	8
+#define ASM_LGPTR	3
+#else
+#define ASM_PTR		".dword"
+#define ASM_SZPTR	"8"
+#define ASM_LGPTR	"3"
+#endif
+#elif __SIZEOF_POINTER__ == 4
+#ifdef __ASSEMBLY__
+#define ASM_PTR		.word
+#define ASM_SZPTR	4
+#define ASM_LGPTR	2
+#else
+#define ASM_PTR		".word"
+#define ASM_SZPTR	"4"
+#define ASM_LGPTR	"2"
+#endif
+#else
+#error "Unexpected __SIZEOF_POINTER__"
+#endif
+
+#endif /* __ASM_GENERIC_PTR_H___ */
diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
index 6309a814a483..6a624e0bd5d0 100755
--- a/scripts/gen-dtb-s
+++ b/scripts/gen-dtb-s
@@ -5,6 +5,7 @@ dtb=$2
 imd=$3
 
 echo "#include <asm/barebox.lds.h>"
+echo "#include <asm-generic/pointer.h>"
 
 le32() {
 	printf ".byte 0x%02x, 0x%02x, 0x%02x, 0x%02x\n" \
@@ -50,7 +51,7 @@ echo ".incbin \"$dtb\""
 echo "__dtb_${name}_end:"
 echo ".global __dtb_${name}_end"
 if [ "$imd" = "y" ]; then
-	echo ".dword __barebox_imd_OF_${name}"
+	echo "ASM_PTR __barebox_imd_OF_${name}"
 fi
 echo ".balign STRUCT_ALIGNMENT"
 
@@ -69,7 +70,7 @@ echo ".incbin \"$dtb.z\""
 echo "__dtb_z_${name}_end:"
 echo ".global __dtb_z_${name}_end"
 if [ "$imd" = "y" ]; then
-	echo ".dword __barebox_imd_OF_${name}"
+	echo "ASM_PTR __barebox_imd_OF_${name}"
 fi
 echo ".balign STRUCT_ALIGNMENT"
 echo "#endif"
-- 
2.39.2



From u.kleine-koenig at pengutronix.de  Wed Apr 12 04:29:45 2023
From: u.kleine-koenig at pengutronix.de (Uwe =?utf-8?Q?Kleine-K=C3=B6nig?=)
Date: Wed, 12 Apr 2023 13:29:45 +0200
Subject: [PATCH] hush: Fix a memory leak in run_command()
In-Reply-To: <20220714164118.56761-1-u.kleine-koenig@pengutronix.de>
References: <20220714164118.56761-1-u.kleine-koenig@pengutronix.de>
Message-ID: <20230412112945.2fvnj7d7wnf7ybzv@pengutronix.de>

Hello,

On Thu, Jul 14, 2022 at 06:41:18PM +0200, Uwe Kleine-K?nig wrote:
> parse_string_outer() calls initialize_context(), too. As the latter
> allocates memory make sure to only call it once.
> 
> This fixes
> 
> 	automount -d /mnt/foo true
> 	ls -l /mnt/foo
> 
> dying with a failure to allocate memory. Now it results in an endless loop,
> which admittedly is only a little bit better :-)
> 
> Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig at pengutronix.de>
> ---
>  common/hush.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/common/hush.c b/common/hush.c
> index 6a089fabf11d..117b273ea4e2 100644
> --- a/common/hush.c
> +++ b/common/hush.c
> @@ -1887,8 +1887,6 @@ int run_command(const char *cmd)
>  	struct p_context ctx = {};
>  	int ret;
>  
> -	initialize_context(&ctx);
> -
>  	ret = parse_string_outer(&ctx, cmd, FLAG_PARSE_SEMICOLON);
>  	release_context(&ctx);

Just a heads-up, looking at 6bd5212b3d431d4fdc2a0022a06c68939b145c52: I
tried to evaluate the alternative approach, i.e.  relying in
parse_string_outer that ctx is initialized. Then a call to
initialize_context() is required in run_shell().

However dropping the initialize_context() from parse_stream_outer()
breaks things. So adding release_context(ctx); before it would be an
option.

Also shell_expand() should get a call of release_context(&ctx);

So the prototype patch with some printfs looks as follows:

diff --git a/common/hush.c b/common/hush.c
index 5138a1a45ae9..1c654b126305 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -1177,6 +1177,7 @@ static void initialize_context(struct p_context *ctx)
 	ctx->pipe = NULL;
 	ctx->child = NULL;
 	ctx->list_head = new_pipe();
+	printf("%s:%d: ctx=%p, list_head=%p\n", __func__, __LINE__, ctx, ctx->list_head);
 	ctx->pipe = ctx->list_head;
 	ctx->w = RES_NONE;
 	ctx->stack = NULL;
@@ -1188,6 +1189,7 @@ static void initialize_context(struct p_context *ctx)
 
 static void release_context(struct p_context *ctx)
 {
+	printf("%s:%d: ctx=%p, list_head=%p\n", __func__, __LINE__, ctx, ctx->list_head);
 #ifdef CONFIG_CMD_GETOPT
 	struct option *opt, *tmp;
 
@@ -1701,6 +1703,8 @@ char *shell_expand(char *str)
 	free_pipe_list(ctx.list_head, 0);
 	b_free(&o);
 
+	release_context(&ctx);
+
 	return res;
 }
 
@@ -1714,6 +1718,13 @@ static int parse_stream_outer(struct p_context *ctx, struct in_str *inp, int fla
 
 	do {
 		ctx->type = flag;
+
+		/*
+		 * parse_stream_outer() is always called with an initialized
+		 * *ctx.  Before reinitializing it, release the old state to not
+		 * leak memory.
+		 */
+		release_context(ctx);
 		initialize_context(ctx);
 		update_ifs_map();
 
@@ -1954,6 +1965,7 @@ int run_shell(void)
 	do {
 		ctrlc_handled();
 		setup_file_in_str(&input);
+		initialize_context(&ctx);
 		rcode = parse_stream_outer(&ctx, &input, FLAG_PARSE_SEMICOLON);
 		if (rcode < -1) {
 			exit = 1;


Then I get in the sandbox:

	barebox at Sandbox:/ for i in 1; do echo $i; done
	initialize_context:1180: ctx=00007ffcde6bfb90, list_head=00007ff63c7dfc90
	initialize_context:1180: ctx=00007ffcde6bf920, list_head=00007ff63c7e13b0
	release_context:1192: ctx=00007ffcde6bf920, list_head=00007ff63c7e13b0
	initialize_context:1180: ctx=00007ffcde6bf920, list_head=00007ff63c7e1470
	1
	release_context:1192: ctx=00007ffcde6bf920, list_head=00007ff63c7e1470
	release_context:1192: ctx=00007ffcde6bfb90, list_head=00007ff63c7e0660
	initialize_context:1180: ctx=00007ffcde6bfb90, list_head=00007ff63c7e0660
	barebox at Sandbox:/ for i in 1; do echo $i; done
	initialize_context:1180: ctx=00007ffcde6bfb90, list_head=00007ff63c7dfc90
	initialize_context:1180: ctx=00007ffcde6bf920, list_head=00007ff63c7dfc30
	release_context:1192: ctx=00007ffcde6bf920, list_head=00007ff63c7dfc30
	initialize_context:1180: ctx=00007ffcde6bf920, list_head=00007ff63c7dfc60
	1
	release_context:1192: ctx=00007ffcde6bf920, list_head=00007ff63c7dfc60
	release_context:1192: ctx=00007ffcde6bfb90, list_head=00007ff63c7e0660
	initialize_context:1180: ctx=00007ffcde6bfb90, list_head=00007ff63c7e0660

So there is still some inbalance, each command triggers 4x
initialize_context but only 3x release_context.

The further details are unclear to me, e.g. how and when a ctx changes
the list_head and how list_head is freed (that doesn't happen in
release_context()).

So while I think parts of the above patch are correct, I don't
understand the whole picture. The time that I planned to take looking
into this is over now. So here come just a few notes for someone (maybe
a future me) to pick it up later.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20230412/aec9b493/attachment.sig>

From sha at pengutronix.de  Wed Apr 12 07:12:57 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Apr 2023 16:12:57 +0200
Subject: [PATCH] fixup! scripts: gen-dtb-s: reference OF IMD entries
 automatically
In-Reply-To: <20230412112232.422198-1-a.fatoum@pengutronix.de>
References: <20230412105810.GK15436@pengutronix.de>
 <20230412112232.422198-1-a.fatoum@pengutronix.de>
Message-ID: <20230412141257.GU19113@pengutronix.de>

On Wed, Apr 12, 2023 at 01:22:32PM +0200, Ahmad Fatoum wrote:
> Apparently, .dword is not supported for 32-bit ARM builds.
> 
> Let's define ASM_PTR that expands to either .dword or .word and use
> that instead.
> 
> The definition is taken from RISCV_PTR in arch/riscv/include/asm/asm.h.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
> Sascha, how about this?

Ok, let's give it a try.

Sascha

> ---
>  include/asm-generic/pointer.h | 30 ++++++++++++++++++++++++++++++
>  scripts/gen-dtb-s             |  5 +++--
>  2 files changed, 33 insertions(+), 2 deletions(-)
>  create mode 100644 include/asm-generic/pointer.h
> 
> diff --git a/include/asm-generic/pointer.h b/include/asm-generic/pointer.h
> new file mode 100644
> index 000000000000..a0ea084b983c
> --- /dev/null
> +++ b/include/asm-generic/pointer.h
> @@ -0,0 +1,30 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +
> +#ifndef __ASM_GENERIC_PTR_H___
> +#define __ASM_GENERIC_PTR_H___
> +
> +#if __SIZEOF_POINTER__ == 8
> +#ifdef __ASSEMBLY__
> +#define ASM_PTR		.dword
> +#define ASM_SZPTR	8
> +#define ASM_LGPTR	3
> +#else
> +#define ASM_PTR		".dword"
> +#define ASM_SZPTR	"8"
> +#define ASM_LGPTR	"3"
> +#endif
> +#elif __SIZEOF_POINTER__ == 4
> +#ifdef __ASSEMBLY__
> +#define ASM_PTR		.word
> +#define ASM_SZPTR	4
> +#define ASM_LGPTR	2
> +#else
> +#define ASM_PTR		".word"
> +#define ASM_SZPTR	"4"
> +#define ASM_LGPTR	"2"
> +#endif
> +#else
> +#error "Unexpected __SIZEOF_POINTER__"
> +#endif
> +
> +#endif /* __ASM_GENERIC_PTR_H___ */
> diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
> index 6309a814a483..6a624e0bd5d0 100755
> --- a/scripts/gen-dtb-s
> +++ b/scripts/gen-dtb-s
> @@ -5,6 +5,7 @@ dtb=$2
>  imd=$3
>  
>  echo "#include <asm/barebox.lds.h>"
> +echo "#include <asm-generic/pointer.h>"
>  
>  le32() {
>  	printf ".byte 0x%02x, 0x%02x, 0x%02x, 0x%02x\n" \
> @@ -50,7 +51,7 @@ echo ".incbin \"$dtb\""
>  echo "__dtb_${name}_end:"
>  echo ".global __dtb_${name}_end"
>  if [ "$imd" = "y" ]; then
> -	echo ".dword __barebox_imd_OF_${name}"
> +	echo "ASM_PTR __barebox_imd_OF_${name}"
>  fi
>  echo ".balign STRUCT_ALIGNMENT"
>  
> @@ -69,7 +70,7 @@ echo ".incbin \"$dtb.z\""
>  echo "__dtb_z_${name}_end:"
>  echo ".global __dtb_z_${name}_end"
>  if [ "$imd" = "y" ]; then
> -	echo ".dword __barebox_imd_OF_${name}"
> +	echo "ASM_PTR __barebox_imd_OF_${name}"
>  fi
>  echo ".balign STRUCT_ALIGNMENT"
>  echo "#endif"
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Thu Apr 13 00:26:19 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Thu, 13 Apr 2023 09:26:19 +0200
Subject: [PATCH] fixup! scripts: gen-dtb-s: reference OF IMD entries
 automatically
In-Reply-To: <20230412112232.422198-1-a.fatoum@pengutronix.de>
References: <20230412105810.GK15436@pengutronix.de>
 <20230412112232.422198-1-a.fatoum@pengutronix.de>
Message-ID: <20230413072619.GL15436@pengutronix.de>

On Wed, Apr 12, 2023 at 01:22:32PM +0200, Ahmad Fatoum wrote:
> Apparently, .dword is not supported for 32-bit ARM builds.
> 
> Let's define ASM_PTR that expands to either .dword or .word and use
> that instead.
> 
> The definition is taken from RISCV_PTR in arch/riscv/include/asm/asm.h.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
> Sascha, how about this?
> ---
>  include/asm-generic/pointer.h | 30 ++++++++++++++++++++++++++++++
>  scripts/gen-dtb-s             |  5 +++--
>  2 files changed, 33 insertions(+), 2 deletions(-)
>  create mode 100644 include/asm-generic/pointer.h
> 
> diff --git a/include/asm-generic/pointer.h b/include/asm-generic/pointer.h
> new file mode 100644
> index 000000000000..a0ea084b983c
> --- /dev/null
> +++ b/include/asm-generic/pointer.h
> @@ -0,0 +1,30 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +
> +#ifndef __ASM_GENERIC_PTR_H___
> +#define __ASM_GENERIC_PTR_H___
> +
> +#if __SIZEOF_POINTER__ == 8
> +#ifdef __ASSEMBLY__
> +#define ASM_PTR		.dword
> +#define ASM_SZPTR	8
> +#define ASM_LGPTR	3
> +#else
> +#define ASM_PTR		".dword"

We're still not there. .dword is not known by x86. I changed to .quad
now.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From a.fatoum at pengutronix.de  Thu Apr 13 01:45:47 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Apr 2023 10:45:47 +0200
Subject: [PATCH v2] kbuild: use printf instead of echo -e extension
Message-ID: <20230413084547.1331906-1-a.fatoum@pengutronix.de>

We are using echo -e, so the \n in the string being echo'd are
interpreted. As -e is not POSIX and dash doesn't provide it,
we use a strange /usr/bin/env echo -e construct hoping that
whatever non-builtin echo is first in the search path supports -e.

As the new lines are just used to separate CPP directives, we can
just pass the directives as $(CPP) flags. This has the same result,
but is potable and avoids NixOS complaining when building barebox.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - drop echo -e eltogether after Sascha pointed out why it needs
    /usr/bin/env.

Tested with two fragments:
  - dts variable is defined for the DT it references
  - fragments are included (checked with #warning)
  - fragment change triggers rebuild
  - original DT change triggers rebuild
  - fragmentless case works ok
    
 scripts/Makefile.lib | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 4deaa5dfa73c..befd47ed6600 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -372,8 +372,8 @@ $(obj)/%.dtb.z: $(obj)/%.dtb FORCE
 dts-frags = $(subst $(quote),,$(CONFIG_EXTERNAL_DTS_FRAGMENTS))
 quiet_cmd_dtc = DTC     $@
 # For compatibility between make 4.2 and 4.3
-cmd_dtc = /usr/bin/env echo -e '$(pound)define $(subst -,_,$(*F))_dts 1\n'$(foreach f,$< $(2),'$(pound)include "$(f)"\n') | \
-	$(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) - ; \
+cmd_dtc = echo | $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) \
+	-D'$(subst -,_,$(*F))_dts=1' $(foreach f,$< $(2),-include '$(f)') - ; \
 	$(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 \
 		-i $(srctree)/arch/$(SRCARCH)/dts $(DTC_FLAGS) \
 		-i $(srctree)/dts/src/$(SRCARCH) \
-- 
2.39.2



From sha at pengutronix.de  Thu Apr 13 02:20:43 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Thu, 13 Apr 2023 11:20:43 +0200
Subject: [PATCH v2] kbuild: use printf instead of echo -e extension
In-Reply-To: <20230413084547.1331906-1-a.fatoum@pengutronix.de>
References: <20230413084547.1331906-1-a.fatoum@pengutronix.de>
Message-ID: <20230413092043.GW19113@pengutronix.de>

Hi Ahmad,

The subject seems outdated, you are not using printf at all here.

On Thu, Apr 13, 2023 at 10:45:47AM +0200, Ahmad Fatoum wrote:
> We are using echo -e, so the \n in the string being echo'd are
> interpreted. As -e is not POSIX and dash doesn't provide it,
> we use a strange /usr/bin/env echo -e construct hoping that
> whatever non-builtin echo is first in the search path supports -e.
> 
> As the new lines are just used to separate CPP directives, we can
> just pass the directives as $(CPP) flags. This has the same result,
> but is potable and avoids NixOS complaining when building barebox.

s/potable/portable/

> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
> v1 -> v2:
>   - drop echo -e eltogether after Sascha pointed out why it needs
>     /usr/bin/env.
> 
> Tested with two fragments:
>   - dts variable is defined for the DT it references
>   - fragments are included (checked with #warning)
>   - fragment change triggers rebuild
>   - original DT change triggers rebuild
>   - fragmentless case works ok
>     
>  scripts/Makefile.lib | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index 4deaa5dfa73c..befd47ed6600 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -372,8 +372,8 @@ $(obj)/%.dtb.z: $(obj)/%.dtb FORCE
>  dts-frags = $(subst $(quote),,$(CONFIG_EXTERNAL_DTS_FRAGMENTS))
>  quiet_cmd_dtc = DTC     $@
>  # For compatibility between make 4.2 and 4.3
> -cmd_dtc = /usr/bin/env echo -e '$(pound)define $(subst -,_,$(*F))_dts 1\n'$(foreach f,$< $(2),'$(pound)include "$(f)"\n') | \
> -	$(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) - ; \
> +cmd_dtc = echo | $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) \
> +	-D'$(subst -,_,$(*F))_dts=1' $(foreach f,$< $(2),-include '$(f)') - ; \

Good idea to get rid of the echo -e dependency entirely, I like it :)

You could replace the '-' for stdin with /dev/null and then drop the
echo |. Maybe this makes it a bit easier to read.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From a.fatoum at pengutronix.de  Thu Apr 13 02:40:20 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Apr 2023 11:40:20 +0200
Subject: [PATCH v2] kbuild: use printf instead of echo -e extension
In-Reply-To: <20230413092043.GW19113@pengutronix.de>
References: <20230413084547.1331906-1-a.fatoum@pengutronix.de>
 <20230413092043.GW19113@pengutronix.de>
Message-ID: <169e8325-9b89-5cb1-cd90-cf5a0f817b02@pengutronix.de>

On 13.04.23 11:20, Sascha Hauer wrote:
> Hi Ahmad,
> 
> The subject seems outdated, you are not using printf at all here.

Oh right. I tried printf first, but foreach concatenates with
spaces in-between and printf ignores everything not referenced
by the format string...

> On Thu, Apr 13, 2023 at 10:45:47AM +0200, Ahmad Fatoum wrote:
>> We are using echo -e, so the \n in the string being echo'd are
>> interpreted. As -e is not POSIX and dash doesn't provide it,
>> we use a strange /usr/bin/env echo -e construct hoping that
>> whatever non-builtin echo is first in the search path supports -e.
>>
>> As the new lines are just used to separate CPP directives, we can
>> just pass the directives as $(CPP) flags. This has the same result,
>> but is potable and avoids NixOS complaining when building barebox.
> 
> s/potable/portable/

Will fix.

> Good idea to get rid of the echo -e dependency entirely, I like it :)
> 
> You could replace the '-' for stdin with /dev/null and then drop the
> echo |. Maybe this makes it a bit easier to read.

I had thought about that, but deemed

  In file included from <command-line>:3:
  /home/afa/fragment1.dts:6:2: warning: #warning hey [-Wcpp]

to be less confusing than it mentioning /dev/null. Now that I actually
tried it out though, the warning also references command-line, so
you will change for v3.

Thanks,
Ahmad

> 
> Sascha
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



From a.fatoum at pengutronix.de  Thu Apr 13 02:43:15 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 13 Apr 2023 11:43:15 +0200
Subject: [PATCH v3] kbuild: drop reliance on echo -e extension for DT fragments
Message-ID: <20230413094315.1432917-1-a.fatoum@pengutronix.de>

We are using echo -e, so the \n in the string being echo'd are
interpreted. As -e is not POSIX and dash doesn't provide it,
we use a strange /usr/bin/env echo -e construct hoping that
whatever non-builtin echo is first in the search path supports -e.

As the new lines are just used to separate CPP directives, we can
just pass the directives as $(CPP) flags. This has the same result,
but is portable and avoids NixOS complaining when building barebox.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v2 -> v3:
  - drop comment around $(pound) use, which no longer applies
  - reword commit message title and fix typo in body (Sascha)
  - use cpp /dev/null instead of empty echo | cpp (Sascha)
v1 -> v2:
  - drop echo -e eltogether after Sascha pointed out why it needs
    /usr/bin/env.
---
 scripts/Makefile.lib | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 4deaa5dfa73c..51beff56aeb8 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -371,9 +371,8 @@ $(obj)/%.dtb.z: $(obj)/%.dtb FORCE
 
 dts-frags = $(subst $(quote),,$(CONFIG_EXTERNAL_DTS_FRAGMENTS))
 quiet_cmd_dtc = DTC     $@
-# For compatibility between make 4.2 and 4.3
-cmd_dtc = /usr/bin/env echo -e '$(pound)define $(subst -,_,$(*F))_dts 1\n'$(foreach f,$< $(2),'$(pound)include "$(f)"\n') | \
-	$(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) - ; \
+cmd_dtc = $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) \
+	-D'$(subst -,_,$(*F))_dts=1' $(foreach f,$< $(2),-include '$(f)') /dev/null ; \
 	$(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 \
 		-i $(srctree)/arch/$(SRCARCH)/dts $(DTC_FLAGS) \
 		-i $(srctree)/dts/src/$(SRCARCH) \
-- 
2.39.2



From sha at pengutronix.de  Fri Apr 14 00:30:23 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Fri, 14 Apr 2023 09:30:23 +0200
Subject: [PATCH] commands: menu: enable help text parsing for sphinx docs
In-Reply-To: <20230412090105.4160849-1-a.fatoum@pengutronix.de>
References: <20230412090105.4160849-1-a.fatoum@pengutronix.de>
Message-ID: <20230414073023.GA13543@pengutronix.de>

On Wed, Apr 12, 2023 at 11:01:05AM +0200, Ahmad Fatoum wrote:
> Use of the macros is required, so Documentation/gen_commands.py may
> format it into ReST for the documentation.
> 
> Reported-by: Leonard G?hrs <l.goehrs at pengutronix.de>
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  commands/menu.c | 107 ++++++++++++++++++++++++------------------------
>  1 file changed, 54 insertions(+), 53 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/commands/menu.c b/commands/menu.c
> index 7a01aff28066..e0fe09b5088b 100644
> --- a/commands/menu.c
> +++ b/commands/menu.c
> @@ -406,64 +406,65 @@ end:
>  	return 1;
>  }
>  
> -static const __maybe_unused char cmd_menu_help[] =
> -"Manage Menu:\n"
> -"  -m  menu\n"
> -"  -l  list\n"
> -"  -s  show\n"
> +BAREBOX_CMD_HELP_START(menu)
> +BAREBOX_CMD_HELP_TEXT("Manage Menu:")
> +BAREBOX_CMD_HELP_OPT ("-m", "menu")
> +BAREBOX_CMD_HELP_OPT ("-l", "list")
> +BAREBOX_CMD_HELP_OPT ("-s", "show")
> +BAREBOX_CMD_HELP_TEXT("")
>  #if defined(CONFIG_CMD_MENU_MANAGEMENT)
> -"Advanced menu management:\n"
> -"  -e  menu entry\n"
> -"  -a  add\n"
> -"  -r  remove\n"
> -"  -S  select\n"
> +BAREBOX_CMD_HELP_TEXT("Advanced menu management:")
> +BAREBOX_CMD_HELP_OPT ("-e", "menu entry")
> +BAREBOX_CMD_HELP_OPT ("-a", "add")
> +BAREBOX_CMD_HELP_OPT ("-r", "remove")
> +BAREBOX_CMD_HELP_OPT ("-S", "select")
> +BAREBOX_CMD_HELP_TEXT("")
>  #endif
> -"\n"
> -"Show menu:\n"
> -"  (-A auto select delay)\n"
> -"  (-d auto select description)\n"
> -"  menu -s -m MENU [-A delay] [-d auto_display]\n"
> -"\n"
> -"List menu:\n"
> -"  menu -l\n"
> -"\n"
> +BAREBOX_CMD_HELP_TEXT("Show menu:")
> +BAREBOX_CMD_HELP_OPT ("-A", "auto select delay")
> +BAREBOX_CMD_HELP_OPT ("-d", "auto select description")
> +BAREBOX_CMD_HELP_TEXT("\tmenu -s -m MENU [-A delay] [-d auto_display]")
> +BAREBOX_CMD_HELP_TEXT("")
> +BAREBOX_CMD_HELP_TEXT("List menu:")
> +BAREBOX_CMD_HELP_TEXT("\tmenu -l\n")
> +BAREBOX_CMD_HELP_TEXT("")
>  #if defined(CONFIG_CMD_MENU_MANAGEMENT)
> -"Add a menu:\n"
> -"  menu -a -m NAME -d DESC\n"
> -"\n"
> -"Remove a menu:\n"
> -"  menu -r -m NAME\n"
> -"\n"
> -"Add an entry:\n"
> -"  (-R for do no exit the menu after executing the command)\n"
> -"  (-b for box style 1 for selected)\n"
> -"  (and optional -c for the command to run when we change the state)\n"
> -"  menu -e -a -m MENU -c COMMAND [-R] [-b 0|1] -d DESC\n"
> -
> -"Add a submenu entry:\n"
> -"  (-R is not needed)\n"
> -"  (-b for box style 1 for selected)\n"
> -"  (and -c is not needed)\n"
> -"  menu -e -a -m MENU -u submenu -d [-b 0|1] DESC\n"
> -"\n"
> -"Remove an entry:\n"
> -"  menu -e -r -m NAME -n ENTRY\n"
> -"\n"
> -"Select an entry:\n"
> -"  menu -m <menu> -S -n ENTRY\n"
> -"\n"
> -"List menu:\n"
> -"  menu -e -l [menu]\n"
> -"\n"
> -"Menu examples:\n"
> -"  menu -a -m boot -d \"Boot Menu\"\n"
> -"  menu -e -a -m boot -c boot -d \"Boot\"\n"
> -"  menu -e -a -m boot -c reset -d \"Reset\"\n"
> +BAREBOX_CMD_HELP_TEXT("Add a menu:")
> +BAREBOX_CMD_HELP_TEXT("\tmenu -a -m NAME -d DESC")
> +BAREBOX_CMD_HELP_TEXT("")
> +BAREBOX_CMD_HELP_TEXT("Remove a menu:")
> +BAREBOX_CMD_HELP_TEXT("\tmenu -r -m NAME")
> +BAREBOX_CMD_HELP_TEXT("")
> +BAREBOX_CMD_HELP_TEXT("Add an entry:")
> +BAREBOX_CMD_HELP_TEXT("\t(-R for do no exit the menu after executing the command)")
> +BAREBOX_CMD_HELP_TEXT("\t(-b for box style 1 for selected)")
> +BAREBOX_CMD_HELP_TEXT("\t(and optional -c for the command to run when we change the state)")
> +BAREBOX_CMD_HELP_TEXT("\tmenu -e -a -m MENU -c COMMAND [-R] [-b 0|1] -d DESC")
> +BAREBOX_CMD_HELP_TEXT("")
> +BAREBOX_CMD_HELP_TEXT("Add a submenu entry:")
> +BAREBOX_CMD_HELP_TEXT("\t(-R is not needed)")
> +BAREBOX_CMD_HELP_TEXT("\t(-b for box style 1 for selected)")
> +BAREBOX_CMD_HELP_TEXT("\t(and -c is not needed)")
> +BAREBOX_CMD_HELP_TEXT("\tmenu -e -a -m MENU -u submenu -d [-b 0|1] DESC")
> +BAREBOX_CMD_HELP_TEXT("")
> +BAREBOX_CMD_HELP_TEXT("Remove an entry:")
> +BAREBOX_CMD_HELP_TEXT("\tmenu -e -r -m NAME -n ENTRY")
> +BAREBOX_CMD_HELP_TEXT("")
> +BAREBOX_CMD_HELP_TEXT("Select an entry:")
> +BAREBOX_CMD_HELP_TEXT("\tmenu -m <menu> -S -n ENTRY")
> +BAREBOX_CMD_HELP_TEXT("")
> +BAREBOX_CMD_HELP_TEXT("List menu:")
> +BAREBOX_CMD_HELP_TEXT("\tmenu -e -l [menu]")
> +BAREBOX_CMD_HELP_TEXT("")
> +BAREBOX_CMD_HELP_TEXT("Menu examples:")
> +BAREBOX_CMD_HELP_TEXT("\tmenu -a -m boot -d \"Boot Menu\"")
> +BAREBOX_CMD_HELP_TEXT("\tmenu -e -a -m boot -c boot -d \"Boot\"")
> +BAREBOX_CMD_HELP_TEXT("\tmenu -e -a -m boot -c reset -d \"Reset\"")
>  #else
> -"Menu example:\n"
> +BAREBOX_CMD_HELP_TEXT("Menu example:")
>  #endif
> -"  menu -s -m boot\n"
> -;
> +BAREBOX_CMD_HELP_TEXT("\tmenu -s -m boot")
> +BAREBOX_CMD_HELP_END
>  
>  BAREBOX_CMD_START(menu)
>  	.cmd		= do_menu,
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Fri Apr 14 00:31:26 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Fri, 14 Apr 2023 09:31:26 +0200
Subject: [PATCH v3] kbuild: drop reliance on echo -e extension for DT
 fragments
In-Reply-To: <20230413094315.1432917-1-a.fatoum@pengutronix.de>
References: <20230413094315.1432917-1-a.fatoum@pengutronix.de>
Message-ID: <20230414073126.GB13543@pengutronix.de>

On Thu, Apr 13, 2023 at 11:43:15AM +0200, Ahmad Fatoum wrote:
> We are using echo -e, so the \n in the string being echo'd are
> interpreted. As -e is not POSIX and dash doesn't provide it,
> we use a strange /usr/bin/env echo -e construct hoping that
> whatever non-builtin echo is first in the search path supports -e.
> 
> As the new lines are just used to separate CPP directives, we can
> just pass the directives as $(CPP) flags. This has the same result,
> but is portable and avoids NixOS complaining when building barebox.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
> v2 -> v3:
>   - drop comment around $(pound) use, which no longer applies
>   - reword commit message title and fix typo in body (Sascha)
>   - use cpp /dev/null instead of empty echo | cpp (Sascha)
> v1 -> v2:
>   - drop echo -e eltogether after Sascha pointed out why it needs
>     /usr/bin/env.
> ---
>  scripts/Makefile.lib | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index 4deaa5dfa73c..51beff56aeb8 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -371,9 +371,8 @@ $(obj)/%.dtb.z: $(obj)/%.dtb FORCE
>  
>  dts-frags = $(subst $(quote),,$(CONFIG_EXTERNAL_DTS_FRAGMENTS))
>  quiet_cmd_dtc = DTC     $@
> -# For compatibility between make 4.2 and 4.3
> -cmd_dtc = /usr/bin/env echo -e '$(pound)define $(subst -,_,$(*F))_dts 1\n'$(foreach f,$< $(2),'$(pound)include "$(f)"\n') | \
> -	$(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) - ; \
> +cmd_dtc = $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) \
> +	-D'$(subst -,_,$(*F))_dts=1' $(foreach f,$< $(2),-include '$(f)') /dev/null ; \
>  	$(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 \
>  		-i $(srctree)/arch/$(SRCARCH)/dts $(DTC_FLAGS) \
>  		-i $(srctree)/dts/src/$(SRCARCH) \
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From hcl at datarespons.no  Fri Apr 14 00:47:08 2023
From: hcl at datarespons.no (=?utf-8?B?SGFucyBDaHJpc3RpYW4gTMO4bnN0YWQ=?=)
Date: Fri, 14 Apr 2023 07:47:08 +0000
Subject: imx8 - gpc: Support IMX8 Lite
In-Reply-To: <20230315091343.4cf3v4ob3fyu3yha@pengutronix.de>
References: <20230315070531.9697-1-hcl@datarespons.com>
 <20230315091343.4cf3v4ob3fyu3yha@pengutronix.de>
Message-ID: <D9091FED-AF96-4414-AF7D-0A0CB9F3A3FD@datarespons.no>

After applying NXP kernel 6.1 branch (6.1-1.0-x-imx) I can confirm a fix is needed in kernel as well.
In order to avoid specific DT for i.MX8MP Lite, the probe function in soc/imx/imx8m-blk-ctrl.c should consult fuse settings and skip the pm_genpd_init for functions not available.

I believe this should be properly handled as the Lite version is more applicable (and cost effective) for a broad range of applications.

Hans Christian L?nstad

> 15. mar. 2023 kl. 10:13 skrev Marco Felsch <m.felsch at pengutronix.de>:
> 
> Hi Hans,
> 
> the subject should be:
> 
> soc: imx: gpcv2: add i.MX8MP Lite support
> 
> On 23-03-15, Hans Christian Lonstad wrote:
>> IMX8 Lite lacks some functionality and hence the corresponding
>   ^
> i.MX8MP Lite
> 
>> power domains (8, 11, 12, 13).
>> This results in Barebox error messages and unfortunately a failed
>> Linux kernel boot.
>> Add a "Lite" specific table selected using device tree compatible
>> clause.
>> 
>> Note that this should probably be related to the feature controller.
> 
> What did you mean by this note? Also do we need this support within
> Linux as well?
> 
>> Signed-off-by: Hans Christian Lonstad <hcl at Datarespons.com>
>> 
>> diff --git a/drivers/soc/imx/gpcv2.c b/drivers/soc/imx/gpcv2.c
>> index b662363f79..40998c42c5 100644
>> --- a/drivers/soc/imx/gpcv2.c
>> +++ b/drivers/soc/imx/gpcv2.c
>> @@ -1053,6 +1053,192 @@ static const struct imx_pgc_domain imx8mp_pgc_domains[] = {
>> 	},
>> };
>> 
>> +static const struct imx_pgc_domain imx8mpl_pgc_domains[] = {
>> +	[IMX8MP_POWER_DOMAIN_MIPI_PHY1] = {
>> +		.genpd = {
>> +			.name = "mipi-phy1",
>> +		},
>> +		.bits = {
>> +			.pxx = IMX8MP_MIPI_PHY1_SW_Pxx_REQ,
>> +			.map = IMX8MP_MIPI_PHY1_A53_DOMAIN,
>> +		},
>> +		.pgc = BIT(IMX8MP_PGC_MIPI1),
>> +	},
>> +
>> +	[IMX8MP_POWER_DOMAIN_PCIE_PHY] = {
>> +		.genpd = {
>> +			.name = "pcie-phy1",
>> +		},
>> +		.bits = {
>> +			.pxx = IMX8MP_PCIE_PHY_SW_Pxx_REQ,
>> +			.map = IMX8MP_PCIE_PHY_A53_DOMAIN,
>> +		},
>> +		.pgc = BIT(IMX8MP_PGC_PCIE),
>> +	},
>> +
>> +	[IMX8MP_POWER_DOMAIN_USB1_PHY] = {
>> +		.genpd = {
>> +			.name = "usb-otg1",
>> +		},
>> +		.bits = {
>> +			.pxx = IMX8MP_USB1_PHY_Pxx_REQ,
>> +			.map = IMX8MP_USB1_PHY_A53_DOMAIN,
>> +		},
>> +		.pgc = BIT(IMX8MP_PGC_USB1),
>> +	},
>> +
>> +	[IMX8MP_POWER_DOMAIN_USB2_PHY] = {
>> +		.genpd = {
>> +			.name = "usb-otg2",
>> +		},
>> +		.bits = {
>> +			.pxx = IMX8MP_USB2_PHY_Pxx_REQ,
>> +			.map = IMX8MP_USB2_PHY_A53_DOMAIN,
>> +		},
>> +		.pgc = BIT(IMX8MP_PGC_USB2),
>> +	},
>> +
>> +	[IMX8MP_POWER_DOMAIN_MLMIX] = {
>> +		.genpd = {
>> +			.name = "mlmix",
>> +		},
>> +		.bits = {
>> +			.pxx = IMX8MP_MLMIX_Pxx_REQ,
>> +			.map = IMX8MP_MLMIX_A53_DOMAIN,
>> +			.hskreq = IMX8MP_MLMIX_PWRDNREQN,
>> +			.hskack = IMX8MP_MLMIX_PWRDNACKN,
>> +		},
>> +		.pgc = BIT(IMX8MP_PGC_MLMIX),
>> +		.keep_clocks = true,
>> +	},
>> +
>> +	[IMX8MP_POWER_DOMAIN_AUDIOMIX] = {
>> +		.genpd = {
>> +			.name = "audiomix",
>> +		},
>> +		.bits = {
>> +			.pxx = IMX8MP_AUDIOMIX_Pxx_REQ,
>> +			.map = IMX8MP_AUDIOMIX_A53_DOMAIN,
>> +			.hskreq = IMX8MP_AUDIOMIX_PWRDNREQN,
>> +			.hskack = IMX8MP_AUDIOMIX_PWRDNACKN,
>> +		},
>> +		.pgc = BIT(IMX8MP_PGC_AUDIOMIX),
>> +		.keep_clocks = true,
>> +	},
>> +
>> +	[IMX8MP_POWER_DOMAIN_GPU2D] = {
>> +		.genpd = {
>> +			.name = "gpu2d",
>> +		},
>> +		.bits = {
>> +			.pxx = IMX8MP_GPU_2D_Pxx_REQ,
>> +			.map = IMX8MP_GPU2D_A53_DOMAIN,
>> +		},
>> +		.pgc = BIT(IMX8MP_PGC_GPU2D),
>> +	},
>> +
>> +	[IMX8MP_POWER_DOMAIN_GPUMIX] = {
>> +		.genpd = {
>> +			.name = "gpumix",
>> +		},
>> +		.bits = {
>> +			.pxx = IMX8MP_GPU_SHARE_LOGIC_Pxx_REQ,
>> +			.map = IMX8MP_GPUMIX_A53_DOMAIN,
>> +			.hskreq = IMX8MP_GPUMIX_PWRDNREQN,
>> +			.hskack = IMX8MP_GPUMIX_PWRDNACKN,
>> +		},
>> +		.pgc = BIT(IMX8MP_PGC_GPUMIX),
>> +		.keep_clocks = true,
>> +	},
>> +
>> +	[IMX8MP_POWER_DOMAIN_GPU3D] = {
>> +		.genpd = {
>> +			.name = "gpu3d",
>> +		},
>> +		.bits = {
>> +			.pxx = IMX8MP_GPU_3D_Pxx_REQ,
>> +			.map = IMX8MP_GPU3D_A53_DOMAIN,
>> +		},
>> +		.pgc = BIT(IMX8MP_PGC_GPU3D),
>> +	},
>> +
>> +	[IMX8MP_POWER_DOMAIN_MEDIAMIX] = {
>> +		.genpd = {
>> +			.name = "mediamix",
>> +		},
>> +		.bits = {
>> +			.pxx = IMX8MP_MEDIMIX_Pxx_REQ,
>> +			.map = IMX8MP_MEDIAMIX_A53_DOMAIN,
>> +			.hskreq = IMX8MP_MEDIAMIX_PWRDNREQN,
>> +			.hskack = IMX8MP_MEDIAMIX_PWRDNACKN,
>> +		},
>> +		.pgc = BIT(IMX8MP_PGC_MEDIAMIX),
>> +		.keep_clocks = true,
>> +	},
>> +
>> +	[IMX8MP_POWER_DOMAIN_HDMIMIX] = {
>> +		.genpd = {
>> +			.name = "hdmimix",
>> +		},
>> +		.bits = {
>> +			.pxx = IMX8MP_HDMIMIX_Pxx_REQ,
>> +			.map = IMX8MP_HDMIMIX_A53_DOMAIN,
>> +			.hskreq = IMX8MP_HDMIMIX_PWRDNREQN,
>> +			.hskack = IMX8MP_HDMIMIX_PWRDNACKN,
>> +		},
>> +		.pgc = BIT(IMX8MP_PGC_HDMIMIX),
>> +		.keep_clocks = true,
>> +	},
>> +
>> +	[IMX8MP_POWER_DOMAIN_HDMI_PHY] = {
>> +		.genpd = {
>> +			.name = "hdmi-phy",
>> +		},
>> +		.bits = {
>> +			.pxx = IMX8MP_HDMI_PHY_Pxx_REQ,
>> +			.map = IMX8MP_HDMI_PHY_A53_DOMAIN,
>> +		},
>> +		.pgc = BIT(IMX8MP_PGC_HDMI),
>> +	},
>> +
>> +	[IMX8MP_POWER_DOMAIN_MIPI_PHY2] = {
>> +		.genpd = {
>> +			.name = "mipi-phy2",
>> +		},
>> +		.bits = {
>> +			.pxx = IMX8MP_MIPI_PHY2_Pxx_REQ,
>> +			.map = IMX8MP_MIPI_PHY2_A53_DOMAIN,
>> +		},
>> +		.pgc = BIT(IMX8MP_PGC_MIPI2),
>> +	},
>> +
>> +	[IMX8MP_POWER_DOMAIN_HSIOMIX] = {
>> +		.genpd = {
>> +			.name = "hsiomix",
>> +		},
>> +		.bits = {
>> +			.pxx = IMX8MP_HSIOMIX_Pxx_REQ,
>> +			.map = IMX8MP_HSIOMIX_A53_DOMAIN,
>> +			.hskreq = IMX8MP_HSIOMIX_PWRDNREQN,
>> +			.hskack = IMX8MP_HSIOMIX_PWRDNACKN,
>> +		},
>> +		.pgc = BIT(IMX8MP_PGC_HSIOMIX),
>> +		.keep_clocks = true,
>> +	},
>> +
>> +	[IMX8MP_POWER_DOMAIN_MEDIAMIX_ISPDWP] = {
>> +		.genpd = {
>> +			.name = "mediamix-isp-dwp",
>> +		},
>> +		.bits = {
>> +			.pxx = IMX8MP_MEDIA_ISP_DWP_Pxx_REQ,
>> +			.map = IMX8MP_MEDIA_ISPDWP_A53_DOMAIN,
>> +		},
>> +		.pgc = BIT(IMX8MP_PGC_MEDIA_ISP_DWP),
>> +	},
>> +};
>> +
>> +
> 
> delete one.
> 
>> static const struct imx_pgc_regs imx8mp_pgc_regs = {
>> 	.map = IMX8MP_GPC_PGC_CPU_MAPPING,
>> 	.pup = IMX8MP_GPC_PU_PGC_SW_PUP_REQ,
>> @@ -1065,6 +1251,12 @@ static const struct imx_pgc_domain_data imx8mp_pgc_domain_data = {
>> 	.pgc_regs = &imx8mp_pgc_regs,
>> };
>> 
>> +static const struct imx_pgc_domain_data imx8mpl_pgc_domain_data = {
>> +	.domains = imx8mpl_pgc_domains,
>> +	.domains_num = ARRAY_SIZE(imx8mpl_pgc_domains),
>> +	.pgc_regs = &imx8mp_pgc_regs,
>> +};
>> +
>> static const struct imx_pgc_domain imx8mn_pgc_domains[] = {
>> 	[IMX8MN_POWER_DOMAIN_HSIOMIX] = {
>> 		.genpd = {
>> @@ -1302,6 +1494,7 @@ static const struct of_device_id imx_gpcv2_dt_ids[] = {
>> 	{ .compatible = "fsl,imx8mm-gpc", .data = &imx8mm_pgc_domain_data, },
>> 	{ .compatible = "fsl,imx8mn-gpc", .data = &imx8mn_pgc_domain_data, },
>> 	{ .compatible = "fsl,imx8mp-gpc", .data = &imx8mp_pgc_domain_data, },
>> +	{ .compatible = "fsl,imx8mpl-gpc", .data = &imx8mpl_pgc_domain_data, },
> 				^
> This compatible is does not exist.
> 
> Regards,
>  Marco
> 
>> 	{ .compatible = "fsl,imx8mq-gpc", .data = &imx8m_pgc_domain_data, },
>> 	{ }
>> };
>> 
>> 


From a.fatoum at pengutronix.de  Fri Apr 14 00:59:14 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Apr 2023 09:59:14 +0200
Subject: imx8 - gpc: Support IMX8 Lite
In-Reply-To: <D9091FED-AF96-4414-AF7D-0A0CB9F3A3FD@datarespons.no>
References: <20230315070531.9697-1-hcl@datarespons.com>
 <20230315091343.4cf3v4ob3fyu3yha@pengutronix.de>
 <D9091FED-AF96-4414-AF7D-0A0CB9F3A3FD@datarespons.no>
Message-ID: <e597040b-7c6e-0c65-878b-c47c768b242e@pengutronix.de>

Hello Hans.

On 14.04.23 09:47, Hans Christian L?nstad wrote:
> After applying NXP kernel 6.1 branch (6.1-1.0-x-imx) I can confirm a fix is needed in kernel as well.
> In order to avoid specific DT for i.MX8MP Lite, the probe function in soc/imx/imx8m-blk-ctrl.c should consult fuse settings and skip the pm_genpd_init for functions not available.
> 
> I believe this should be properly handled as the Lite version is more applicable (and cost effective) for a broad range of applications.

The consensus is that this is the job of the device tree. i.MX8MPL users need
to either use a DT which omits the nodes in question or the bootloader needs
to patch these nodes away. The feature controller supports patching the kernel
DT, so what's missing is adding i.MX8MP Lite support to it.

Cheers,
Ahmad

> 
> Hans Christian L?nstad
> 
>> 15. mar. 2023 kl. 10:13 skrev Marco Felsch <m.felsch at pengutronix.de>:
>>
>> Hi Hans,
>>
>> the subject should be:
>>
>> soc: imx: gpcv2: add i.MX8MP Lite support
>>
>> On 23-03-15, Hans Christian Lonstad wrote:
>>> IMX8 Lite lacks some functionality and hence the corresponding
>>   ^
>> i.MX8MP Lite
>>
>>> power domains (8, 11, 12, 13).
>>> This results in Barebox error messages and unfortunately a failed
>>> Linux kernel boot.
>>> Add a "Lite" specific table selected using device tree compatible
>>> clause.
>>>
>>> Note that this should probably be related to the feature controller.
>>
>> What did you mean by this note? Also do we need this support within
>> Linux as well?
>>
>>> Signed-off-by: Hans Christian Lonstad <hcl at Datarespons.com>
>>>
>>> diff --git a/drivers/soc/imx/gpcv2.c b/drivers/soc/imx/gpcv2.c
>>> index b662363f79..40998c42c5 100644
>>> --- a/drivers/soc/imx/gpcv2.c
>>> +++ b/drivers/soc/imx/gpcv2.c
>>> @@ -1053,6 +1053,192 @@ static const struct imx_pgc_domain imx8mp_pgc_domains[] = {
>>> 	},
>>> };
>>>
>>> +static const struct imx_pgc_domain imx8mpl_pgc_domains[] = {
>>> +	[IMX8MP_POWER_DOMAIN_MIPI_PHY1] = {
>>> +		.genpd = {
>>> +			.name = "mipi-phy1",
>>> +		},
>>> +		.bits = {
>>> +			.pxx = IMX8MP_MIPI_PHY1_SW_Pxx_REQ,
>>> +			.map = IMX8MP_MIPI_PHY1_A53_DOMAIN,
>>> +		},
>>> +		.pgc = BIT(IMX8MP_PGC_MIPI1),
>>> +	},
>>> +
>>> +	[IMX8MP_POWER_DOMAIN_PCIE_PHY] = {
>>> +		.genpd = {
>>> +			.name = "pcie-phy1",
>>> +		},
>>> +		.bits = {
>>> +			.pxx = IMX8MP_PCIE_PHY_SW_Pxx_REQ,
>>> +			.map = IMX8MP_PCIE_PHY_A53_DOMAIN,
>>> +		},
>>> +		.pgc = BIT(IMX8MP_PGC_PCIE),
>>> +	},
>>> +
>>> +	[IMX8MP_POWER_DOMAIN_USB1_PHY] = {
>>> +		.genpd = {
>>> +			.name = "usb-otg1",
>>> +		},
>>> +		.bits = {
>>> +			.pxx = IMX8MP_USB1_PHY_Pxx_REQ,
>>> +			.map = IMX8MP_USB1_PHY_A53_DOMAIN,
>>> +		},
>>> +		.pgc = BIT(IMX8MP_PGC_USB1),
>>> +	},
>>> +
>>> +	[IMX8MP_POWER_DOMAIN_USB2_PHY] = {
>>> +		.genpd = {
>>> +			.name = "usb-otg2",
>>> +		},
>>> +		.bits = {
>>> +			.pxx = IMX8MP_USB2_PHY_Pxx_REQ,
>>> +			.map = IMX8MP_USB2_PHY_A53_DOMAIN,
>>> +		},
>>> +		.pgc = BIT(IMX8MP_PGC_USB2),
>>> +	},
>>> +
>>> +	[IMX8MP_POWER_DOMAIN_MLMIX] = {
>>> +		.genpd = {
>>> +			.name = "mlmix",
>>> +		},
>>> +		.bits = {
>>> +			.pxx = IMX8MP_MLMIX_Pxx_REQ,
>>> +			.map = IMX8MP_MLMIX_A53_DOMAIN,
>>> +			.hskreq = IMX8MP_MLMIX_PWRDNREQN,
>>> +			.hskack = IMX8MP_MLMIX_PWRDNACKN,
>>> +		},
>>> +		.pgc = BIT(IMX8MP_PGC_MLMIX),
>>> +		.keep_clocks = true,
>>> +	},
>>> +
>>> +	[IMX8MP_POWER_DOMAIN_AUDIOMIX] = {
>>> +		.genpd = {
>>> +			.name = "audiomix",
>>> +		},
>>> +		.bits = {
>>> +			.pxx = IMX8MP_AUDIOMIX_Pxx_REQ,
>>> +			.map = IMX8MP_AUDIOMIX_A53_DOMAIN,
>>> +			.hskreq = IMX8MP_AUDIOMIX_PWRDNREQN,
>>> +			.hskack = IMX8MP_AUDIOMIX_PWRDNACKN,
>>> +		},
>>> +		.pgc = BIT(IMX8MP_PGC_AUDIOMIX),
>>> +		.keep_clocks = true,
>>> +	},
>>> +
>>> +	[IMX8MP_POWER_DOMAIN_GPU2D] = {
>>> +		.genpd = {
>>> +			.name = "gpu2d",
>>> +		},
>>> +		.bits = {
>>> +			.pxx = IMX8MP_GPU_2D_Pxx_REQ,
>>> +			.map = IMX8MP_GPU2D_A53_DOMAIN,
>>> +		},
>>> +		.pgc = BIT(IMX8MP_PGC_GPU2D),
>>> +	},
>>> +
>>> +	[IMX8MP_POWER_DOMAIN_GPUMIX] = {
>>> +		.genpd = {
>>> +			.name = "gpumix",
>>> +		},
>>> +		.bits = {
>>> +			.pxx = IMX8MP_GPU_SHARE_LOGIC_Pxx_REQ,
>>> +			.map = IMX8MP_GPUMIX_A53_DOMAIN,
>>> +			.hskreq = IMX8MP_GPUMIX_PWRDNREQN,
>>> +			.hskack = IMX8MP_GPUMIX_PWRDNACKN,
>>> +		},
>>> +		.pgc = BIT(IMX8MP_PGC_GPUMIX),
>>> +		.keep_clocks = true,
>>> +	},
>>> +
>>> +	[IMX8MP_POWER_DOMAIN_GPU3D] = {
>>> +		.genpd = {
>>> +			.name = "gpu3d",
>>> +		},
>>> +		.bits = {
>>> +			.pxx = IMX8MP_GPU_3D_Pxx_REQ,
>>> +			.map = IMX8MP_GPU3D_A53_DOMAIN,
>>> +		},
>>> +		.pgc = BIT(IMX8MP_PGC_GPU3D),
>>> +	},
>>> +
>>> +	[IMX8MP_POWER_DOMAIN_MEDIAMIX] = {
>>> +		.genpd = {
>>> +			.name = "mediamix",
>>> +		},
>>> +		.bits = {
>>> +			.pxx = IMX8MP_MEDIMIX_Pxx_REQ,
>>> +			.map = IMX8MP_MEDIAMIX_A53_DOMAIN,
>>> +			.hskreq = IMX8MP_MEDIAMIX_PWRDNREQN,
>>> +			.hskack = IMX8MP_MEDIAMIX_PWRDNACKN,
>>> +		},
>>> +		.pgc = BIT(IMX8MP_PGC_MEDIAMIX),
>>> +		.keep_clocks = true,
>>> +	},
>>> +
>>> +	[IMX8MP_POWER_DOMAIN_HDMIMIX] = {
>>> +		.genpd = {
>>> +			.name = "hdmimix",
>>> +		},
>>> +		.bits = {
>>> +			.pxx = IMX8MP_HDMIMIX_Pxx_REQ,
>>> +			.map = IMX8MP_HDMIMIX_A53_DOMAIN,
>>> +			.hskreq = IMX8MP_HDMIMIX_PWRDNREQN,
>>> +			.hskack = IMX8MP_HDMIMIX_PWRDNACKN,
>>> +		},
>>> +		.pgc = BIT(IMX8MP_PGC_HDMIMIX),
>>> +		.keep_clocks = true,
>>> +	},
>>> +
>>> +	[IMX8MP_POWER_DOMAIN_HDMI_PHY] = {
>>> +		.genpd = {
>>> +			.name = "hdmi-phy",
>>> +		},
>>> +		.bits = {
>>> +			.pxx = IMX8MP_HDMI_PHY_Pxx_REQ,
>>> +			.map = IMX8MP_HDMI_PHY_A53_DOMAIN,
>>> +		},
>>> +		.pgc = BIT(IMX8MP_PGC_HDMI),
>>> +	},
>>> +
>>> +	[IMX8MP_POWER_DOMAIN_MIPI_PHY2] = {
>>> +		.genpd = {
>>> +			.name = "mipi-phy2",
>>> +		},
>>> +		.bits = {
>>> +			.pxx = IMX8MP_MIPI_PHY2_Pxx_REQ,
>>> +			.map = IMX8MP_MIPI_PHY2_A53_DOMAIN,
>>> +		},
>>> +		.pgc = BIT(IMX8MP_PGC_MIPI2),
>>> +	},
>>> +
>>> +	[IMX8MP_POWER_DOMAIN_HSIOMIX] = {
>>> +		.genpd = {
>>> +			.name = "hsiomix",
>>> +		},
>>> +		.bits = {
>>> +			.pxx = IMX8MP_HSIOMIX_Pxx_REQ,
>>> +			.map = IMX8MP_HSIOMIX_A53_DOMAIN,
>>> +			.hskreq = IMX8MP_HSIOMIX_PWRDNREQN,
>>> +			.hskack = IMX8MP_HSIOMIX_PWRDNACKN,
>>> +		},
>>> +		.pgc = BIT(IMX8MP_PGC_HSIOMIX),
>>> +		.keep_clocks = true,
>>> +	},
>>> +
>>> +	[IMX8MP_POWER_DOMAIN_MEDIAMIX_ISPDWP] = {
>>> +		.genpd = {
>>> +			.name = "mediamix-isp-dwp",
>>> +		},
>>> +		.bits = {
>>> +			.pxx = IMX8MP_MEDIA_ISP_DWP_Pxx_REQ,
>>> +			.map = IMX8MP_MEDIA_ISPDWP_A53_DOMAIN,
>>> +		},
>>> +		.pgc = BIT(IMX8MP_PGC_MEDIA_ISP_DWP),
>>> +	},
>>> +};
>>> +
>>> +
>>
>> delete one.
>>
>>> static const struct imx_pgc_regs imx8mp_pgc_regs = {
>>> 	.map = IMX8MP_GPC_PGC_CPU_MAPPING,
>>> 	.pup = IMX8MP_GPC_PU_PGC_SW_PUP_REQ,
>>> @@ -1065,6 +1251,12 @@ static const struct imx_pgc_domain_data imx8mp_pgc_domain_data = {
>>> 	.pgc_regs = &imx8mp_pgc_regs,
>>> };
>>>
>>> +static const struct imx_pgc_domain_data imx8mpl_pgc_domain_data = {
>>> +	.domains = imx8mpl_pgc_domains,
>>> +	.domains_num = ARRAY_SIZE(imx8mpl_pgc_domains),
>>> +	.pgc_regs = &imx8mp_pgc_regs,
>>> +};
>>> +
>>> static const struct imx_pgc_domain imx8mn_pgc_domains[] = {
>>> 	[IMX8MN_POWER_DOMAIN_HSIOMIX] = {
>>> 		.genpd = {
>>> @@ -1302,6 +1494,7 @@ static const struct of_device_id imx_gpcv2_dt_ids[] = {
>>> 	{ .compatible = "fsl,imx8mm-gpc", .data = &imx8mm_pgc_domain_data, },
>>> 	{ .compatible = "fsl,imx8mn-gpc", .data = &imx8mn_pgc_domain_data, },
>>> 	{ .compatible = "fsl,imx8mp-gpc", .data = &imx8mp_pgc_domain_data, },
>>> +	{ .compatible = "fsl,imx8mpl-gpc", .data = &imx8mpl_pgc_domain_data, },
>> 				^
>> This compatible is does not exist.
>>
>> Regards,
>>  Marco
>>
>>> 	{ .compatible = "fsl,imx8mq-gpc", .data = &imx8m_pgc_domain_data, },
>>> 	{ }
>>> };
>>>
>>>
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



From markus.burri at mt.com  Fri Apr 14 02:40:20 2023
From: markus.burri at mt.com (Markus Burri)
Date: Fri, 14 Apr 2023 11:40:20 +0200
Subject: [PATCH v1] Add bootchooser command option for active boot target
Message-ID: <20230414094020.2389226-1-markus.burri@mt.com>

Add bootchooser command option to extract and save the active target.
The information about active target are stored into two variables
(bootchooser.active_target and bootchooser.active_boot)
This information may be used into scripts to do actions related to the active
target before starting it.

Signed-off-by: Markus Burri <markus.burri at mt.com>

Gbp-Pq: Name 0058-Add-command-for-next-boot-target.patch
---
 Documentation/user/bootchooser.rst |  6 ++++++
 commands/bootchooser.c             | 12 +++++++++++-
 common/bootchooser.c               | 21 +++++++++++++++++++++
 include/bootchooser.h              |  1 +
 4 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/Documentation/user/bootchooser.rst b/Documentation/user/bootchooser.rst
index 8456e11..68ec1b6 100644
--- a/Documentation/user/bootchooser.rst
+++ b/Documentation/user/bootchooser.rst
@@ -168,6 +168,12 @@ options not specific to any boot target.
   set of ``global.bootchooser.<targetname>.<variablename>`` variables must exist.
 ``global.bootchooser.last_chosen``
   *bootchooser* sets this to the boot target that was chosen on last boot (index).
+``global.bootchooser.active_target``
+  Set to the active boot target that will boot next.
+  Call *bootchooser -n* to update the value.
+``global.bootchooser.active_boot``
+  Set to the boot device of the active target that will boot next. 
+  Call *bootchooser -n* to update the value.
 
 .. _bootchooser,setup_example:
 
diff --git a/commands/bootchooser.c b/commands/bootchooser.c
index ac763a6..20bd2d6 100644
--- a/commands/bootchooser.c
+++ b/commands/bootchooser.c
@@ -59,8 +59,9 @@ static int do_bootchooser(int argc, char *argv[])
 	int info = 0;
 	bool done_something = false;
 	bool last_boot_successful = false;
+	bool active_boot_target = false;
 
-	while ((opt = getopt(argc, argv, "a:p:is")) > 0) {
+	while ((opt = getopt(argc, argv, "a:p:ins")) > 0) {
 		switch (opt) {
 		case 'a':
 			if (!strcmp(optarg, "default"))
@@ -77,6 +78,9 @@ static int do_bootchooser(int argc, char *argv[])
 		case 'i':
 			info = 1;
 			break;
+		case 'n':
+			active_boot_target = true;
+			break;
 		case 's':
 			last_boot_successful = true;
 			break;
@@ -120,6 +124,11 @@ static int do_bootchooser(int argc, char *argv[])
 		done_something = true;
 	}
 
+	if (active_boot_target) {
+		bootchooser_active_target(bootchooser);
+		done_something = true;
+	}
+
 	if (!done_something) {
 		printf("Nothing to do\n");
 		ret = COMMAND_ERROR_USAGE;
@@ -137,6 +146,7 @@ BAREBOX_CMD_HELP_TEXT("Options:")
 BAREBOX_CMD_HELP_OPT ("-a <n|default> [TARGETS]",  "set remaining attempts of given targets to 'n' or the default attempts")
 BAREBOX_CMD_HELP_OPT ("-p <n|default> [TARGETS]",  "set priority of given targets to 'n' or the default priority")
 BAREBOX_CMD_HELP_OPT ("-i",  "Show information about the bootchooser")
+BAREBOX_CMD_HELP_OPT ("-n",  "Save active boot target to bootchooser.active_target and active boot device to bootchooser.active_boot")
 BAREBOX_CMD_HELP_OPT ("-s",  "Mark the last boot successful")
 BAREBOX_CMD_HELP_END
 
diff --git a/common/bootchooser.c b/common/bootchooser.c
index c08db03..1ec29e6 100644
--- a/common/bootchooser.c
+++ b/common/bootchooser.c
@@ -619,6 +619,27 @@ void bootchooser_info(struct bootchooser *bc)
 	       bc->last_chosen->name : "unknown");
 }
 
+/**
+ * bootchooser_active_target - Save information about active boot target
+ * @bc: The bootchooser
+ */
+void bootchooser_active_target(struct bootchooser *bc)
+{
+	struct bootchooser_target *target;
+
+	list_for_each_entry(target, &bc->targets, list) {
+		if (bootchooser_target_ok(target, NULL)) {
+			if (bc->verbose) {
+				pr_info("bootchooser.active_target=%s\n", target->name);
+				pr_info("bootchooser.active_boot=%s\n", target->boot);
+			}
+			nvvar_add("bootchooser.active_target", target->name);
+			nvvar_add("bootchooser.active_boot", target->boot);
+			return;
+		}
+	}
+}
+
 /**
  * bootchooser_get_target - get the target that shall be booted next
  * @bc:		The bootchooser
diff --git a/include/bootchooser.h b/include/bootchooser.h
index 7822c01..9825593 100644
--- a/include/bootchooser.h
+++ b/include/bootchooser.h
@@ -12,6 +12,7 @@ int bootchooser_save(struct bootchooser *bootchooser);
 int bootchooser_put(struct bootchooser *bootchooser);
 
 void bootchooser_info(struct bootchooser *bootchooser);
+void bootchooser_active_target(struct bootchooser *bc);
 
 int bootchooser_boot(struct bootchooser *bc);
 
-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 14 02:49:10 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Apr 2023 11:49:10 +0200
Subject: [PATCH v1] Add bootchooser command option for active boot target
In-Reply-To: <20230414094020.2389226-1-markus.burri@mt.com>
References: <20230414094020.2389226-1-markus.burri@mt.com>
Message-ID: <f454aee9-3e78-c1bc-f448-3355e3613d14@pengutronix.de>

Hello Markus,

On 14.04.23 11:40, Markus Burri wrote:
> Add bootchooser command option to extract and save the active target.
> The information about active target are stored into two variables
> (bootchooser.active_target and bootchooser.active_boot)
> This information may be used into scripts to do actions related to the active
> target before starting it.

Can you share an example script that depends on your new bootchooser -n feature
to aid review?

> 
> Signed-off-by: Markus Burri <markus.burri at mt.com>
> 
> Gbp-Pq: Name 0058-Add-command-for-next-boot-target.patch
> ---
>  Documentation/user/bootchooser.rst |  6 ++++++
>  commands/bootchooser.c             | 12 +++++++++++-
>  common/bootchooser.c               | 21 +++++++++++++++++++++
>  include/bootchooser.h              |  1 +
>  4 files changed, 39 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/user/bootchooser.rst b/Documentation/user/bootchooser.rst
> index 8456e11..68ec1b6 100644
> --- a/Documentation/user/bootchooser.rst
> +++ b/Documentation/user/bootchooser.rst
> @@ -168,6 +168,12 @@ options not specific to any boot target.
>    set of ``global.bootchooser.<targetname>.<variablename>`` variables must exist.
>  ``global.bootchooser.last_chosen``
>    *bootchooser* sets this to the boot target that was chosen on last boot (index).
> +``global.bootchooser.active_target``
> +  Set to the active boot target that will boot next.
> +  Call *bootchooser -n* to update the value.
> +``global.bootchooser.active_boot``
> +  Set to the boot device of the active target that will boot next. 
> +  Call *bootchooser -n* to update the value.
>  
>  .. _bootchooser,setup_example:
>  
> diff --git a/commands/bootchooser.c b/commands/bootchooser.c
> index ac763a6..20bd2d6 100644
> --- a/commands/bootchooser.c
> +++ b/commands/bootchooser.c
> @@ -59,8 +59,9 @@ static int do_bootchooser(int argc, char *argv[])
>  	int info = 0;
>  	bool done_something = false;
>  	bool last_boot_successful = false;
> +	bool active_boot_target = false;
>  
> -	while ((opt = getopt(argc, argv, "a:p:is")) > 0) {
> +	while ((opt = getopt(argc, argv, "a:p:ins")) > 0) {
>  		switch (opt) {
>  		case 'a':
>  			if (!strcmp(optarg, "default"))
> @@ -77,6 +78,9 @@ static int do_bootchooser(int argc, char *argv[])
>  		case 'i':
>  			info = 1;
>  			break;
> +		case 'n':
> +			active_boot_target = true;
> +			break;
>  		case 's':
>  			last_boot_successful = true;
>  			break;
> @@ -120,6 +124,11 @@ static int do_bootchooser(int argc, char *argv[])
>  		done_something = true;
>  	}
>  
> +	if (active_boot_target) {
> +		bootchooser_active_target(bootchooser);
> +		done_something = true;
> +	}
> +
>  	if (!done_something) {
>  		printf("Nothing to do\n");
>  		ret = COMMAND_ERROR_USAGE;
> @@ -137,6 +146,7 @@ BAREBOX_CMD_HELP_TEXT("Options:")
>  BAREBOX_CMD_HELP_OPT ("-a <n|default> [TARGETS]",  "set remaining attempts of given targets to 'n' or the default attempts")
>  BAREBOX_CMD_HELP_OPT ("-p <n|default> [TARGETS]",  "set priority of given targets to 'n' or the default priority")
>  BAREBOX_CMD_HELP_OPT ("-i",  "Show information about the bootchooser")
> +BAREBOX_CMD_HELP_OPT ("-n",  "Save active boot target to bootchooser.active_target and active boot device to bootchooser.active_boot")
>  BAREBOX_CMD_HELP_OPT ("-s",  "Mark the last boot successful")
>  BAREBOX_CMD_HELP_END
>  
> diff --git a/common/bootchooser.c b/common/bootchooser.c
> index c08db03..1ec29e6 100644
> --- a/common/bootchooser.c
> +++ b/common/bootchooser.c
> @@ -619,6 +619,27 @@ void bootchooser_info(struct bootchooser *bc)
>  	       bc->last_chosen->name : "unknown");
>  }
>  
> +/**
> + * bootchooser_active_target - Save information about active boot target
> + * @bc: The bootchooser
> + */
> +void bootchooser_active_target(struct bootchooser *bc)
> +{
> +	struct bootchooser_target *target;
> +
> +	list_for_each_entry(target, &bc->targets, list) {
> +		if (bootchooser_target_ok(target, NULL)) {
> +			if (bc->verbose) {
> +				pr_info("bootchooser.active_target=%s\n", target->name);
> +				pr_info("bootchooser.active_boot=%s\n", target->boot);
> +			}
> +			nvvar_add("bootchooser.active_target", target->name);
> +			nvvar_add("bootchooser.active_boot", target->boot);
> +			return;
> +		}
> +	}
> +}
> +
>  /**
>   * bootchooser_get_target - get the target that shall be booted next
>   * @bc:		The bootchooser
> diff --git a/include/bootchooser.h b/include/bootchooser.h
> index 7822c01..9825593 100644
> --- a/include/bootchooser.h
> +++ b/include/bootchooser.h
> @@ -12,6 +12,7 @@ int bootchooser_save(struct bootchooser *bootchooser);
>  int bootchooser_put(struct bootchooser *bootchooser);
>  
>  void bootchooser_info(struct bootchooser *bootchooser);
> +void bootchooser_active_target(struct bootchooser *bc);
>  
>  int bootchooser_boot(struct bootchooser *bc);
>  

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



From a.fatoum at pengutronix.de  Fri Apr 14 05:27:22 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Apr 2023 14:27:22 +0200
Subject: EXTERNAL - [PATCH v1] Add bootchooser command option for active
 boot target
In-Reply-To: <PA4PR03MB748854E525009BC8F015D570EF999@PA4PR03MB7488.eurprd03.prod.outlook.com>
References: <20230414094020.2389226-1-markus.burri@mt.com>
 <f454aee9-3e78-c1bc-f448-3355e3613d14@pengutronix.de>
 <PA4PR03MB748854E525009BC8F015D570EF999@PA4PR03MB7488.eurprd03.prod.outlook.com>
Message-ID: <7c13d1e3-452f-5b91-4511-d64c531f0145@pengutronix.de>

Hello Markus,

(Adding the list back to Cc)

On 14.04.23 12:49, Burri Markus LabTec wrote:
> Hello Ahmad
> 
> Here is example script:
> 
> #!/bin/sh
> bootchooser -n
> #Execute all hook scripts found on active target
> HOOKDIR="/mnt/${nv.bootchooser.active_boot}/boot/barebox-hooks"
> cd ${HOOKDIR}
> for HOOK in *; do
>     echo "run barebox-hook: \'${HOOK}\'"
>     . ${HOOKDIR}/${HOOK}
> done
> cd /

I assume this is an init script? This script will execute
the hooks of the old rootfs once before booting the new rootfs.

This doesn't sound like a good idea.

Fundamentally, the barebox environment is not power-fail safe,
that's why bootchooser is using barebox-state. So writing nv
variables without user interaction is not ok.

Did you know that you can have scripts as bootchooser targets?
Instead of e.g. bootchooser.system0.boot=mmc0.1, you can add
/env/boot/system0 and then do whatever you want there before 
calling boot mmc0. Would that suffice?

Cheers,
Ahmad

 
> -----Original Message-----
> From: Ahmad Fatoum <a.fatoum at pengutronix.de> 
> Sent: Freitag, 14. April 2023 11:49
> To: Burri Markus LabTec <Markus.Burri at mt.com>; barebox at lists.infradead.org
> Subject: Re: EXTERNAL - [PATCH v1] Add bootchooser command option for active boot target
> 
> Hello Markus,
> 
> On 14.04.23 11:40, Markus Burri wrote:
>> Add bootchooser command option to extract and save the active target.
>> The information about active target are stored into two variables 
>> (bootchooser.active_target and bootchooser.active_boot) This 
>> information may be used into scripts to do actions related to the 
>> active target before starting it.
> 
> Can you share an example script that depends on your new bootchooser -n feature to aid review?
> 
>>
>> Signed-off-by: Markus Burri <markus.burri at mt.com>
>>
>> Gbp-Pq: Name 0058-Add-command-for-next-boot-target.patch
>> ---
>>  Documentation/user/bootchooser.rst |  6 ++++++
>>  commands/bootchooser.c             | 12 +++++++++++-
>>  common/bootchooser.c               | 21 +++++++++++++++++++++
>>  include/bootchooser.h              |  1 +
>>  4 files changed, 39 insertions(+), 1 deletion(-)
>>
>> diff --git a/Documentation/user/bootchooser.rst 
>> b/Documentation/user/bootchooser.rst
>> index 8456e11..68ec1b6 100644
>> --- a/Documentation/user/bootchooser.rst
>> +++ b/Documentation/user/bootchooser.rst
>> @@ -168,6 +168,12 @@ options not specific to any boot target.
>>    set of ``global.bootchooser.<targetname>.<variablename>`` variables must exist.
>>  ``global.bootchooser.last_chosen``
>>    *bootchooser* sets this to the boot target that was chosen on last boot (index).
>> +``global.bootchooser.active_target``
>> +  Set to the active boot target that will boot next.
>> +  Call *bootchooser -n* to update the value.
>> +``global.bootchooser.active_boot``
>> +  Set to the boot device of the active target that will boot next. 
>> +  Call *bootchooser -n* to update the value.
>>  
>>  .. _bootchooser,setup_example:
>>  
>> diff --git a/commands/bootchooser.c b/commands/bootchooser.c index 
>> ac763a6..20bd2d6 100644
>> --- a/commands/bootchooser.c
>> +++ b/commands/bootchooser.c
>> @@ -59,8 +59,9 @@ static int do_bootchooser(int argc, char *argv[])
>>  	int info = 0;
>>  	bool done_something = false;
>>  	bool last_boot_successful = false;
>> +	bool active_boot_target = false;
>>  
>> -	while ((opt = getopt(argc, argv, "a:p:is")) > 0) {
>> +	while ((opt = getopt(argc, argv, "a:p:ins")) > 0) {
>>  		switch (opt) {
>>  		case 'a':
>>  			if (!strcmp(optarg, "default"))
>> @@ -77,6 +78,9 @@ static int do_bootchooser(int argc, char *argv[])
>>  		case 'i':
>>  			info = 1;
>>  			break;
>> +		case 'n':
>> +			active_boot_target = true;
>> +			break;
>>  		case 's':
>>  			last_boot_successful = true;
>>  			break;
>> @@ -120,6 +124,11 @@ static int do_bootchooser(int argc, char *argv[])
>>  		done_something = true;
>>  	}
>>  
>> +	if (active_boot_target) {
>> +		bootchooser_active_target(bootchooser);
>> +		done_something = true;
>> +	}
>> +
>>  	if (!done_something) {
>>  		printf("Nothing to do\n");
>>  		ret = COMMAND_ERROR_USAGE;
>> @@ -137,6 +146,7 @@ BAREBOX_CMD_HELP_TEXT("Options:")  
>> BAREBOX_CMD_HELP_OPT ("-a <n|default> [TARGETS]",  "set remaining 
>> attempts of given targets to 'n' or the default attempts")  
>> BAREBOX_CMD_HELP_OPT ("-p <n|default> [TARGETS]",  "set priority of 
>> given targets to 'n' or the default priority")  BAREBOX_CMD_HELP_OPT 
>> ("-i",  "Show information about the bootchooser")
>> +BAREBOX_CMD_HELP_OPT ("-n",  "Save active boot target to 
>> +bootchooser.active_target and active boot device to 
>> +bootchooser.active_boot")
>>  BAREBOX_CMD_HELP_OPT ("-s",  "Mark the last boot successful")  
>> BAREBOX_CMD_HELP_END
>>  
>> diff --git a/common/bootchooser.c b/common/bootchooser.c index 
>> c08db03..1ec29e6 100644
>> --- a/common/bootchooser.c
>> +++ b/common/bootchooser.c
>> @@ -619,6 +619,27 @@ void bootchooser_info(struct bootchooser *bc)
>>  	       bc->last_chosen->name : "unknown");  }
>>  
>> +/**
>> + * bootchooser_active_target - Save information about active boot 
>> +target
>> + * @bc: The bootchooser
>> + */
>> +void bootchooser_active_target(struct bootchooser *bc) {
>> +	struct bootchooser_target *target;
>> +
>> +	list_for_each_entry(target, &bc->targets, list) {
>> +		if (bootchooser_target_ok(target, NULL)) {
>> +			if (bc->verbose) {
>> +				pr_info("bootchooser.active_target=%s\n", target->name);
>> +				pr_info("bootchooser.active_boot=%s\n", target->boot);
>> +			}
>> +			nvvar_add("bootchooser.active_target", target->name);
>> +			nvvar_add("bootchooser.active_boot", target->boot);
>> +			return;
>> +		}
>> +	}
>> +}
>> +
>>  /**
>>   * bootchooser_get_target - get the target that shall be booted next
>>   * @bc:		The bootchooser
>> diff --git a/include/bootchooser.h b/include/bootchooser.h index 
>> 7822c01..9825593 100644
>> --- a/include/bootchooser.h
>> +++ b/include/bootchooser.h
>> @@ -12,6 +12,7 @@ int bootchooser_save(struct bootchooser 
>> *bootchooser);  int bootchooser_put(struct bootchooser *bootchooser);
>>  
>>  void bootchooser_info(struct bootchooser *bootchooser);
>> +void bootchooser_active_target(struct bootchooser *bc);
>>  
>>  int bootchooser_boot(struct bootchooser *bc);
>>  
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



From Markus.Burri at mt.com  Fri Apr 14 05:41:05 2023
From: Markus.Burri at mt.com (Burri Markus LabTec)
Date: Fri, 14 Apr 2023 12:41:05 +0000
Subject: EXTERNAL - [PATCH v1] Add bootchooser command option for active
 boot target
In-Reply-To: <7c13d1e3-452f-5b91-4511-d64c531f0145@pengutronix.de>
References: <20230414094020.2389226-1-markus.burri@mt.com>
 <f454aee9-3e78-c1bc-f448-3355e3613d14@pengutronix.de>
 <PA4PR03MB748854E525009BC8F015D570EF999@PA4PR03MB7488.eurprd03.prod.outlook.com>
 <7c13d1e3-452f-5b91-4511-d64c531f0145@pengutronix.de>
Message-ID: <PA4PR03MB7488B5A455A50A14BB7E44A5EF999@PA4PR03MB7488.eurprd03.prod.outlook.com>

Hello Ahmad

The Idea is to run some scripts stored in the rootfs before booting the system. In our case e.g we enable led according to customer needs. This is stored in to rootfs where the customer is able to update without update barebox
The new command option will store this information in a variable where I can use this information in the init script.
It sound that a script as bootchooser target will fit my requirement. I didn't know that. I will try
Thx

Best regards Markus
 

-----Original Message-----
From: Ahmad Fatoum <a.fatoum at pengutronix.de> 
Sent: Freitag, 14. April 2023 14:27
To: Burri Markus LabTec <Markus.Burri at mt.com>
Cc: barebox at lists.infradead.org
Subject: Re: EXTERNAL - [PATCH v1] Add bootchooser command option for active boot target

Hello Markus,

(Adding the list back to Cc)

On 14.04.23 12:49, Burri Markus LabTec wrote:
> Hello Ahmad
> 
> Here is example script:
> 
> #!/bin/sh
> bootchooser -n
> #Execute all hook scripts found on active target 
> HOOKDIR="/mnt/${nv.bootchooser.active_boot}/boot/barebox-hooks"
> cd ${HOOKDIR}
> for HOOK in *; do
>     echo "run barebox-hook: \'${HOOK}\'"
>     . ${HOOKDIR}/${HOOK}
> done
> cd /

I assume this is an init script? This script will execute the hooks of the old rootfs once before booting the new rootfs.

This doesn't sound like a good idea.

Fundamentally, the barebox environment is not power-fail safe, that's why bootchooser is using barebox-state. So writing nv variables without user interaction is not ok.

Did you know that you can have scripts as bootchooser targets?
Instead of e.g. bootchooser.system0.boot=mmc0.1, you can add
/env/boot/system0 and then do whatever you want there before calling boot mmc0. Would that suffice?

Cheers,
Ahmad

 
> -----Original Message-----
> From: Ahmad Fatoum <a.fatoum at pengutronix.de>
> Sent: Freitag, 14. April 2023 11:49
> To: Burri Markus LabTec <Markus.Burri at mt.com>; 
> barebox at lists.infradead.org
> Subject: Re: EXTERNAL - [PATCH v1] Add bootchooser command option for 
> active boot target
> 
> Hello Markus,
> 
> On 14.04.23 11:40, Markus Burri wrote:
>> Add bootchooser command option to extract and save the active target.
>> The information about active target are stored into two variables 
>> (bootchooser.active_target and bootchooser.active_boot) This 
>> information may be used into scripts to do actions related to the 
>> active target before starting it.
> 
> Can you share an example script that depends on your new bootchooser -n feature to aid review?
> 
>>
>> Signed-off-by: Markus Burri <markus.burri at mt.com>
>>
>> Gbp-Pq: Name 0058-Add-command-for-next-boot-target.patch
>> ---
>>  Documentation/user/bootchooser.rst |  6 ++++++
>>  commands/bootchooser.c             | 12 +++++++++++-
>>  common/bootchooser.c               | 21 +++++++++++++++++++++
>>  include/bootchooser.h              |  1 +
>>  4 files changed, 39 insertions(+), 1 deletion(-)
>>
>> diff --git a/Documentation/user/bootchooser.rst
>> b/Documentation/user/bootchooser.rst
>> index 8456e11..68ec1b6 100644
>> --- a/Documentation/user/bootchooser.rst
>> +++ b/Documentation/user/bootchooser.rst
>> @@ -168,6 +168,12 @@ options not specific to any boot target.
>>    set of ``global.bootchooser.<targetname>.<variablename>`` variables must exist.
>>  ``global.bootchooser.last_chosen``
>>    *bootchooser* sets this to the boot target that was chosen on last boot (index).
>> +``global.bootchooser.active_target``
>> +  Set to the active boot target that will boot next.
>> +  Call *bootchooser -n* to update the value.
>> +``global.bootchooser.active_boot``
>> +  Set to the boot device of the active target that will boot next. 
>> +  Call *bootchooser -n* to update the value.
>>  
>>  .. _bootchooser,setup_example:
>>  
>> diff --git a/commands/bootchooser.c b/commands/bootchooser.c index
>> ac763a6..20bd2d6 100644
>> --- a/commands/bootchooser.c
>> +++ b/commands/bootchooser.c
>> @@ -59,8 +59,9 @@ static int do_bootchooser(int argc, char *argv[])
>>  	int info = 0;
>>  	bool done_something = false;
>>  	bool last_boot_successful = false;
>> +	bool active_boot_target = false;
>>  
>> -	while ((opt = getopt(argc, argv, "a:p:is")) > 0) {
>> +	while ((opt = getopt(argc, argv, "a:p:ins")) > 0) {
>>  		switch (opt) {
>>  		case 'a':
>>  			if (!strcmp(optarg, "default"))
>> @@ -77,6 +78,9 @@ static int do_bootchooser(int argc, char *argv[])
>>  		case 'i':
>>  			info = 1;
>>  			break;
>> +		case 'n':
>> +			active_boot_target = true;
>> +			break;
>>  		case 's':
>>  			last_boot_successful = true;
>>  			break;
>> @@ -120,6 +124,11 @@ static int do_bootchooser(int argc, char *argv[])
>>  		done_something = true;
>>  	}
>>  
>> +	if (active_boot_target) {
>> +		bootchooser_active_target(bootchooser);
>> +		done_something = true;
>> +	}
>> +
>>  	if (!done_something) {
>>  		printf("Nothing to do\n");
>>  		ret = COMMAND_ERROR_USAGE;
>> @@ -137,6 +146,7 @@ BAREBOX_CMD_HELP_TEXT("Options:") 
>> BAREBOX_CMD_HELP_OPT ("-a <n|default> [TARGETS]",  "set remaining 
>> attempts of given targets to 'n' or the default attempts") 
>> BAREBOX_CMD_HELP_OPT ("-p <n|default> [TARGETS]",  "set priority of 
>> given targets to 'n' or the default priority")  BAREBOX_CMD_HELP_OPT 
>> ("-i",  "Show information about the bootchooser")
>> +BAREBOX_CMD_HELP_OPT ("-n",  "Save active boot target to 
>> +bootchooser.active_target and active boot device to
>> +bootchooser.active_boot")
>>  BAREBOX_CMD_HELP_OPT ("-s",  "Mark the last boot successful") 
>> BAREBOX_CMD_HELP_END
>>  
>> diff --git a/common/bootchooser.c b/common/bootchooser.c index
>> c08db03..1ec29e6 100644
>> --- a/common/bootchooser.c
>> +++ b/common/bootchooser.c
>> @@ -619,6 +619,27 @@ void bootchooser_info(struct bootchooser *bc)
>>  	       bc->last_chosen->name : "unknown");  }
>>  
>> +/**
>> + * bootchooser_active_target - Save information about active boot 
>> +target
>> + * @bc: The bootchooser
>> + */
>> +void bootchooser_active_target(struct bootchooser *bc) {
>> +	struct bootchooser_target *target;
>> +
>> +	list_for_each_entry(target, &bc->targets, list) {
>> +		if (bootchooser_target_ok(target, NULL)) {
>> +			if (bc->verbose) {
>> +				pr_info("bootchooser.active_target=%s\n", target->name);
>> +				pr_info("bootchooser.active_boot=%s\n", target->boot);
>> +			}
>> +			nvvar_add("bootchooser.active_target", target->name);
>> +			nvvar_add("bootchooser.active_boot", target->boot);
>> +			return;
>> +		}
>> +	}
>> +}
>> +
>>  /**
>>   * bootchooser_get_target - get the target that shall be booted next
>>   * @bc:		The bootchooser
>> diff --git a/include/bootchooser.h b/include/bootchooser.h index
>> 7822c01..9825593 100644
>> --- a/include/bootchooser.h
>> +++ b/include/bootchooser.h
>> @@ -12,6 +12,7 @@ int bootchooser_save(struct bootchooser 
>> *bootchooser);  int bootchooser_put(struct bootchooser *bootchooser);
>>  
>>  void bootchooser_info(struct bootchooser *bootchooser);
>> +void bootchooser_active_target(struct bootchooser *bc);
>>  
>>  int bootchooser_boot(struct bootchooser *bc);
>>  
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From a.fatoum at pengutronix.de  Fri Apr 14 05:46:54 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Apr 2023 14:46:54 +0200
Subject: EXTERNAL - [PATCH v1] Add bootchooser command option for active
 boot target
In-Reply-To: <PA4PR03MB7488B5A455A50A14BB7E44A5EF999@PA4PR03MB7488.eurprd03.prod.outlook.com>
References: <20230414094020.2389226-1-markus.burri@mt.com>
 <f454aee9-3e78-c1bc-f448-3355e3613d14@pengutronix.de>
 <PA4PR03MB748854E525009BC8F015D570EF999@PA4PR03MB7488.eurprd03.prod.outlook.com>
 <7c13d1e3-452f-5b91-4511-d64c531f0145@pengutronix.de>
 <PA4PR03MB7488B5A455A50A14BB7E44A5EF999@PA4PR03MB7488.eurprd03.prod.outlook.com>
Message-ID: <b8847e00-0e27-c7f8-af75-977fa41fa64e@pengutronix.de>

Hello Markus,

On 14.04.23 14:41, Burri Markus LabTec wrote:
> Hello Ahmad
> 
> The Idea is to run some scripts stored in the rootfs before booting the system. In our case e.g we enable led according to customer needs. This is stored in to rootfs where the customer is able to update without update barebox

Once you give your customer the ability to run arbitrary code, they will run
arbitrary code, e.g. apply an overlay to the kernel DT or tune kernel
command line argument. With your init script approach, you could apply
old overlays when booting a new kernel, which can lead to very surprising
results.

> The new command option will store this information in a variable where I can use this information in the init script.
> It sound that a script as bootchooser target will fit my requirement. I didn't know that. I will try

I am not opposed to give these scripts knowledge of what bootchooser target
is executed, see untested patch below. But it should be the boot scripts
that run hooks, not an init script on a subsequent boot.

Cheers,
Ahmad

---
 common/bootchooser.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/common/bootchooser.c b/common/bootchooser.c
index 08d05e885250..3d400af08ef1 100644
--- a/common/bootchooser.c
+++ b/common/bootchooser.c
@@ -827,6 +827,7 @@ static int bootchooser_boot_one(struct bootchooser *bc, int *tryagain)
                goto out;
        }

+       globalvar_add_simple("bootchooser.active", target->name);
        system = basprintf("bootchooser.active=%s", target->name);
        globalvar_add_simple("linux.bootargs.bootchooser", system);
        free(system);
@@ -854,6 +855,7 @@ static int bootchooser_boot_one(struct bootchooser *bc, int *tryagain)
        *tryagain = 1;
 out:
        globalvar_set_match("linux.bootargs.bootchooser", NULL);
+       globalvar_set_match("bootchooser.active", NULL);

        bootentries_free(entries);

@@ -976,3 +978,5 @@ BAREBOX_MAGICVAR(global.bootchooser.default_priority,
                 "bootchooser: Default priority for a target");
 BAREBOX_MAGICVAR(global.bootchooser.state_prefix,
                 "bootchooser: state name prefix, empty for nv backend");
+BAREBOX_MAGICVAR(global.bootchooser.active,
+                "bootchooser: holds name of active bootchooser target during boot");



From a.fatoum at pengutronix.de  Fri Apr 14 06:26:51 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Apr 2023 15:26:51 +0200
Subject: [PATCH master] ARM: i.MX6: fix DEBUG_LL use
Message-ID: <20230414132651.1703346-1-a.fatoum@pengutronix.de>

Below mentioned commit added a select DEBUG_IMX_UART for all supported
i.MX variants apart from the i.MX6Q. Let's do likewise there, so
DEBUG_LL may be enabled without errors about missing PUTC_LL definition.

Fixes: 0fff6cb9bb4f ("ARM: i.MX: Only provide PUTC_LL() when activated")
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/common/Kconfig b/common/Kconfig
index d951947463a2..ac3df75acbc5 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1342,6 +1342,7 @@ config DEBUG_IMX53_UART
 config DEBUG_IMX6Q_UART
 	bool "i.MX6Q Debug UART"
 	depends on ARCH_IMX6
+	select DEBUG_IMX_UART
 	help
 	  Say Y here if you want kernel low-level debugging support
 	  on i.MX6Q.
-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 14 07:11:54 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Apr 2023 16:11:54 +0200
Subject: [PATCH] fixup! scripts: gen-dtb-s: reference OF IMD entries automatically
Message-ID: <20230414141154.2988598-1-a.fatoum@pengutronix.de>

While the reference is just there, so linker garbage collection doesn't
remove it, it's still a reference and it will be relocated.

This means it must be aligned, otherwise we will crash doing an unaligned
access during relocation if device tree size isn't evenly divisible by
pointer length...

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 scripts/gen-dtb-s | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
index 6a624e0bd5d0..f6fa1525933e 100755
--- a/scripts/gen-dtb-s
+++ b/scripts/gen-dtb-s
@@ -51,6 +51,7 @@ echo ".incbin \"$dtb\""
 echo "__dtb_${name}_end:"
 echo ".global __dtb_${name}_end"
 if [ "$imd" = "y" ]; then
+	echo ".balign ASM_SZPTR"
 	echo "ASM_PTR __barebox_imd_OF_${name}"
 fi
 echo ".balign STRUCT_ALIGNMENT"
@@ -70,6 +71,7 @@ echo ".incbin \"$dtb.z\""
 echo "__dtb_z_${name}_end:"
 echo ".global __dtb_z_${name}_end"
 if [ "$imd" = "y" ]; then
+	echo ".balign ASM_SZPTR"
 	echo "ASM_PTR __barebox_imd_OF_${name}"
 fi
 echo ".balign STRUCT_ALIGNMENT"
-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 14 07:17:03 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Apr 2023 16:17:03 +0200
Subject: [PATCH] usb: misc: onboard_hub: sync compatibles with kernel
Message-ID: <20230414141703.3112251-1-a.fatoum@pengutronix.de>

A couple more USB hub compatibles ave been added to the kernel in the
meantime, so let's import them.

While at it, make onboard_hub_match static. It's not used anywhere else.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/usb/misc/onboard_usb_hub.h | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/misc/onboard_usb_hub.h b/drivers/usb/misc/onboard_usb_hub.h
index e90be47b6735..aca5f50eb0da 100644
--- a/drivers/usb/misc/onboard_usb_hub.h
+++ b/drivers/usb/misc/onboard_usb_hub.h
@@ -22,14 +22,31 @@ static const struct onboard_hub_pdata ti_tusb8041_data = {
 	.reset_us = 3000,
 };
 
-const struct of_device_id onboard_hub_match[] = {
+static const struct onboard_hub_pdata genesys_gl850g_data = {
+	.reset_us = 3,
+};
+
+static const struct onboard_hub_pdata genesys_gl852g_data = {
+	.reset_us = 50,
+};
+
+static const struct onboard_hub_pdata vialab_vl817_data = {
+	.reset_us = 10,
+};
+
+static const struct of_device_id onboard_hub_match[] = {
 	{ .compatible = "usb424,2514", .data = &microchip_usb424_data, },
+	{ .compatible = "usb424,2517", .data = &microchip_usb424_data, },
 	{ .compatible = "usb451,8140", .data = &ti_tusb8041_data, },
 	{ .compatible = "usb451,8142", .data = &ti_tusb8041_data, },
+	{ .compatible = "usb5e3,608", .data = &genesys_gl850g_data, },
+	{ .compatible = "usb5e3,610", .data = &genesys_gl852g_data, },
 	{ .compatible = "usbbda,411", .data = &realtek_rts5411_data, },
 	{ .compatible = "usbbda,5411", .data = &realtek_rts5411_data, },
 	{ .compatible = "usbbda,414", .data = &realtek_rts5411_data, },
 	{ .compatible = "usbbda,5414", .data = &realtek_rts5411_data, },
+	{ .compatible = "usb2109,817", .data = &vialab_vl817_data, },
+	{ .compatible = "usb2109,2817", .data = &vialab_vl817_data, },
 	{}
 };
 
-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 14 07:52:59 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Apr 2023 16:52:59 +0200
Subject: [PATCH v2 5/5] net: designware: eqos: pass physical device to DMA API
In-Reply-To: <20230414145259.3644816-1-a.fatoum@pengutronix.de>
References: <20230414145259.3644816-1-a.fatoum@pengutronix.de>
Message-ID: <20230414145259.3644816-6-a.fatoum@pengutronix.de>

The Ethernet interface device is just a child of the physical device with
no DT node assigned. As such, it lacks all DMA settings that may be
set in the DT. Fix this by using the hardware device instead.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/net/designware_eqos.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/net/designware_eqos.c b/drivers/net/designware_eqos.c
index ee5a10a007e9..2e2a1cf8bff3 100644
--- a/drivers/net/designware_eqos.c
+++ b/drivers/net/designware_eqos.c
@@ -687,7 +687,6 @@ static void eqos_stop(struct eth_device *edev)
 static int eqos_send(struct eth_device *edev, void *packet, int length)
 {
 	struct eqos *eqos = edev->priv;
-	struct device *dev = &eqos->netdev.dev;
 	struct eqos_desc *tx_desc;
 	dma_addr_t dma;
 	u32 des3;
@@ -697,8 +696,8 @@ static int eqos_send(struct eth_device *edev, void *packet, int length)
 	eqos->tx_currdescnum++;
 	eqos->tx_currdescnum %= EQOS_DESCRIPTORS_TX;
 
-	dma = dma_map_single(dev, packet, length, DMA_TO_DEVICE);
-	if (dma_mapping_error(dev, dma))
+	dma = dma_map_single(edev->parent, packet, length, DMA_TO_DEVICE);
+	if (dma_mapping_error(edev->parent, dma))
 		return -EFAULT;
 
 	tx_desc->des0 = (unsigned long)dma;
@@ -717,7 +716,7 @@ static int eqos_send(struct eth_device *edev, void *packet, int length)
 				  !(des3 & EQOS_DESC3_OWN),
 				  100 * USEC_PER_MSEC);
 
-	dma_unmap_single(dev, dma, length, DMA_TO_DEVICE);
+	dma_unmap_single(edev->parent, dma, length, DMA_TO_DEVICE);
 
 	if (ret == -ETIMEDOUT)
 		eqos_dbg(eqos, "TX timeout\n");
@@ -764,7 +763,7 @@ static int eqos_recv(struct eth_device *edev)
 
 static int eqos_init_resources(struct eqos *eqos)
 {
-	struct device *dev = eqos->netdev.parent;
+	struct eth_device *edev = &eqos->netdev;
 	int ret = -ENOMEM;
 	void *descs;
 	void *p;
@@ -785,8 +784,8 @@ static int eqos_init_resources(struct eqos *eqos)
 		struct eqos_desc *rx_desc = &eqos->rx_descs[i];
 		dma_addr_t dma;
 
-		dma = dma_map_single(dev, p, EQOS_MAX_PACKET_SIZE, DMA_FROM_DEVICE);
-		if (dma_mapping_error(dev, dma)) {
+		dma = dma_map_single(edev->parent, p, EQOS_MAX_PACKET_SIZE, DMA_FROM_DEVICE);
+		if (dma_mapping_error(edev->parent, dma)) {
 			ret = -EFAULT;
 			goto err_free_rx_bufs;
 		}
-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 14 07:52:54 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Apr 2023 16:52:54 +0200
Subject: [PATCH v2 0/5] dma: pass physical device to DMA API
Message-ID: <20230414145259.3644816-1-a.fatoum@pengutronix.de>

This splits off the non-contentions parts of my dma-coherency series:
https://lore.barebox.org/barebox/20230221080524.607241-1-a.fatoum at pengutronix.de/

Only change is a typo fix in a comment, but no other changes.

Ahmad Fatoum (5):
  usb: dwc3: populate parent of xHCI dev
  usb: xhci: pass physical device to DMA API
  net: rtl8169: pass physical device for DMA API
  firmware: zynqmp-fpga: pass physical device to DMA API
  net: designware: eqos: pass physical device to DMA API

 drivers/base/resource.c        |  6 ++++--
 drivers/firmware/zynqmp-fpga.c |  7 ++++---
 drivers/net/designware_eqos.c  | 13 ++++++-------
 drivers/net/rtl8169.c          |  9 +++++----
 drivers/usb/dwc3/host.c        |  8 ++++----
 drivers/usb/host/xhci-ring.c   |  8 ++++----
 drivers/usb/host/xhci.c        |  6 +++++-
 include/driver.h               | 12 ++++++++++--
 8 files changed, 42 insertions(+), 27 deletions(-)

-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 14 07:52:58 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Apr 2023 16:52:58 +0200
Subject: [PATCH v2 4/5] firmware: zynqmp-fpga: pass physical device to DMA API
In-Reply-To: <20230414145259.3644816-1-a.fatoum@pengutronix.de>
References: <20230414145259.3644816-1-a.fatoum@pengutronix.de>
Message-ID: <20230414145259.3644816-5-a.fatoum@pengutronix.de>

The manager device is just a child of the physical device with no
DT node assigned. As such, it lacks all DMA settings that may be
set in the DT. Fix this by using the hardware device instead.

Cc: Michael Tretter <m.tretter at pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/firmware/zynqmp-fpga.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/firmware/zynqmp-fpga.c b/drivers/firmware/zynqmp-fpga.c
index 2544d015d6b7..fe3a7df6d30f 100644
--- a/drivers/firmware/zynqmp-fpga.c
+++ b/drivers/firmware/zynqmp-fpga.c
@@ -197,6 +197,7 @@ static void zynqmp_fpga_show_header(const struct device *dev,
 static int fpgamgr_program_finish(struct firmware_handler *fh)
 {
 	struct fpgamgr *mgr = container_of(fh, struct fpgamgr, fh);
+	struct device *hw_dev = mgr->dev.parent;
 	u32 *buf_aligned;
 	u32 buf_size;
 	u32 *body;
@@ -254,9 +255,9 @@ static int fpgamgr_program_finish(struct firmware_handler *fh)
 		memcpy((u32 *)buf_aligned, body, body_length);
 	buf_aligned[body_length / sizeof(*buf_aligned)] = body_length;
 
-	addr = dma_map_single(&mgr->dev, buf_aligned,
+	addr = dma_map_single(hw_dev, buf_aligned,
 			      body_length + sizeof(buf_size), DMA_TO_DEVICE);
-	if (dma_mapping_error(&mgr->dev, addr)) {
+	if (dma_mapping_error(hw_dev, addr)) {
 		status = -EFAULT;
 		goto err_free_dma;
 	}
@@ -267,7 +268,7 @@ static int fpgamgr_program_finish(struct firmware_handler *fh)
 		buf_size = addr + body_length;
 
 	status = mgr->eemi_ops->fpga_load((u64)addr, buf_size, flags);
-	dma_unmap_single(&mgr->dev, addr, body_length + sizeof(buf_size),
+	dma_unmap_single(hw_dev, addr, body_length + sizeof(buf_size),
 			 DMA_TO_DEVICE);
 	if (status < 0)
 		dev_err(&mgr->dev, "unable to load fpga\n");
-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 14 07:52:57 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Apr 2023 16:52:57 +0200
Subject: [PATCH v2 3/5] net: rtl8169: pass physical device for DMA API
In-Reply-To: <20230414145259.3644816-1-a.fatoum@pengutronix.de>
References: <20230414145259.3644816-1-a.fatoum@pengutronix.de>
Message-ID: <20230414145259.3644816-4-a.fatoum@pengutronix.de>

It shouldn't matter for now, but DMA API should always be called for the
physical device, i.e. the struct device underlying the struct pci_device.
This the Ethernet device interface parent, so use that instead.

Cc: Denis Orlov <denorl2009 at gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/net/rtl8169.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/net/rtl8169.c b/drivers/net/rtl8169.c
index ffc4ef238b0b..cbcd065980e5 100644
--- a/drivers/net/rtl8169.c
+++ b/drivers/net/rtl8169.c
@@ -216,6 +216,7 @@ static void __set_rx_mode(struct rtl8169_priv *priv)
 
 static void rtl8169_init_ring(struct rtl8169_priv *priv)
 {
+	struct eth_device *edev = &priv->edev;
 	int i;
 
 	priv->cur_rx = priv->cur_tx = 0;
@@ -223,13 +224,13 @@ static void rtl8169_init_ring(struct rtl8169_priv *priv)
 	priv->tx_desc = dma_alloc_coherent(NUM_TX_DESC * sizeof(struct bufdesc),
 					   &priv->tx_desc_phys);
 	priv->tx_buf = malloc(NUM_TX_DESC * PKT_BUF_SIZE);
-	priv->tx_buf_phys = dma_map_single(&priv->edev.dev, priv->tx_buf,
+	priv->tx_buf_phys = dma_map_single(edev->parent, priv->tx_buf,
 					   NUM_TX_DESC * PKT_BUF_SIZE, DMA_TO_DEVICE);
 
 	priv->rx_desc = dma_alloc_coherent(NUM_RX_DESC * sizeof(struct bufdesc),
 					   &priv->rx_desc_phys);
 	priv->rx_buf = malloc(NUM_RX_DESC * PKT_BUF_SIZE);
-	priv->rx_buf_phys = dma_map_single(&priv->edev.dev, priv->rx_buf,
+	priv->rx_buf_phys = dma_map_single(edev->parent, priv->rx_buf,
 					   NUM_RX_DESC * PKT_BUF_SIZE, DMA_FROM_DEVICE);
 
 	for (i = 0; i < NUM_RX_DESC; i++) {
@@ -479,13 +480,13 @@ static void rtl8169_eth_halt(struct eth_device *edev)
 
 	pci_clear_master(priv->pci_dev);
 
-	dma_unmap_single(&edev->dev, priv->tx_buf_phys, NUM_TX_DESC * PKT_BUF_SIZE,
+	dma_unmap_single(edev->parent, priv->tx_buf_phys, NUM_TX_DESC * PKT_BUF_SIZE,
 			 DMA_TO_DEVICE);
 	free(priv->tx_buf);
 	dma_free_coherent((void *)priv->tx_desc, priv->tx_desc_phys,
 			  NUM_TX_DESC * sizeof(struct bufdesc));
 
-	dma_unmap_single(&edev->dev, priv->rx_buf_phys, NUM_RX_DESC * PKT_BUF_SIZE,
+	dma_unmap_single(edev->parent, priv->rx_buf_phys, NUM_RX_DESC * PKT_BUF_SIZE,
 			 DMA_FROM_DEVICE);
 	free(priv->rx_buf);
 	dma_free_coherent((void *)priv->rx_desc, priv->rx_desc_phys,
-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 14 07:52:56 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Apr 2023 16:52:56 +0200
Subject: [PATCH v2 2/5] usb: xhci: pass physical device to DMA API
In-Reply-To: <20230414145259.3644816-1-a.fatoum@pengutronix.de>
References: <20230414145259.3644816-1-a.fatoum@pengutronix.de>
Message-ID: <20230414145259.3644816-3-a.fatoum@pengutronix.de>

The xHCI device is just a child of the DWC3 with no DT node assigned.
As such, it lacks all DMA settings that may be set in the DT.
Fix this by using the hardware device instead in case the xHCI lacks
its own DT node.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/usb/host/xhci-ring.c | 8 ++++----
 drivers/usb/host/xhci.c      | 6 +++++-
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 4654ab14862f..995772f92722 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -594,7 +594,7 @@ int xhci_bulk_tx(struct usb_device *udev, unsigned long pipe,
 		memcpy(bounce, buffer, length);
 	}
 
-	map = addr = dma_map_single(ctrl->dev, bounce, length, direction);
+	map = addr = dma_map_single(ctrl->host.hw_dev, bounce, length, direction);
 
 	dev_dbg(&udev->dev, "pipe=0x%lx, buffer=%p, length=%d\n",
 		pipe, buffer, length);
@@ -740,7 +740,7 @@ int xhci_bulk_tx(struct usb_device *udev, unsigned long pipe,
 	record_transfer_result(udev, event, length);
 	xhci_acknowledge_event(ctrl);
 
-	dma_unmap_single(ctrl->dev, map, length, direction);
+	dma_unmap_single(ctrl->host.hw_dev, map, length, direction);
 
 	if (usb_pipein(pipe))
 		memcpy(buffer, bounce, length);
@@ -895,7 +895,7 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned long pipe,
 	if (length > 0) {
 		if (req->requesttype & USB_DIR_IN)
 			field |= TRB_DIR_IN;
-		map = buf_64 = dma_map_single(ctrl->dev, buffer, length, direction);
+		map = buf_64 = dma_map_single(ctrl->host.hw_dev, buffer, length, direction);
 
 		trb_fields[0] = lower_32_bits(buf_64);
 		trb_fields[1] = upper_32_bits(buf_64);
@@ -947,7 +947,7 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned long pipe,
 
 	/* Invalidate buffer to make it available to usb-core */
 	if (length > 0)
-		dma_unmap_single(ctrl->dev, map, length, direction);
+		dma_unmap_single(ctrl->host.hw_dev, map, length, direction);
 
 	if (GET_COMP_CODE(le32_to_cpu(event->trans_event.transfer_len))
 			== COMP_SHORT_TX) {
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index f5cc6dac57d8..f149e784524d 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1359,7 +1359,11 @@ int xhci_register(struct xhci_ctrl *ctrl)
 	 */
 	host->no_desc_before_addr = true;
 
-	host->hw_dev = dev;
+	/*
+	 * If xHCI doesn't have its own DT node, it'll be a child of a
+	 * physical USB host controller device that should be used for DMA
+	 */
+	host->hw_dev = dev_of_node(dev) ? dev : dev->parent;
 	host->submit_int_msg = xhci_submit_int_msg;
 	host->submit_control_msg = xhci_submit_control_msg;
 	host->submit_bulk_msg = xhci_submit_bulk_msg;
-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 14 07:52:55 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Apr 2023 16:52:55 +0200
Subject: [PATCH v2 1/5] usb: dwc3: populate parent of xHCI dev
In-Reply-To: <20230414145259.3644816-1-a.fatoum@pengutronix.de>
References: <20230414145259.3644816-1-a.fatoum@pengutronix.de>
Message-ID: <20230414145259.3644816-2-a.fatoum@pengutronix.de>

Reparent xHCIs instantiated from DWC3 controllers to their parents
instead of them being direct children of the bus. Apart from improving
devinfo/drvinfo output, this should introduce no functional change.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/base/resource.c |  6 ++++--
 drivers/usb/dwc3/host.c |  8 ++++----
 include/driver.h        | 12 ++++++++++--
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/base/resource.c b/drivers/base/resource.c
index 3725c79eb9d4..0d6f200a9d51 100644
--- a/drivers/base/resource.c
+++ b/drivers/base/resource.c
@@ -57,13 +57,15 @@ int device_add_resource(struct device *dev, const char *resname,
 	return device_add_resources(dev, &res, 1);
 }
 
-struct device *add_generic_device(const char* devname, int id, const char *resname,
+struct device *add_child_device(struct device *parent,
+		const char* devname, int id, const char *resname,
 		resource_size_t start, resource_size_t size, unsigned int flags,
 		void *pdata)
 {
 	struct device *dev;
 
 	dev = device_alloc(devname, id);
+	dev->parent = parent;
 	dev->platform_data = pdata;
 	device_add_resource(dev, resname, start, size, flags);
 
@@ -71,7 +73,7 @@ struct device *add_generic_device(const char* devname, int id, const char *resna
 
 	return dev;
 }
-EXPORT_SYMBOL(add_generic_device);
+EXPORT_SYMBOL(add_child_device);
 
 struct device *add_generic_device_res(const char* devname, int id,
 		struct resource *res, int nb, void *pdata)
diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
index e377c4068ad2..281d016a86aa 100644
--- a/drivers/usb/dwc3/host.c
+++ b/drivers/usb/dwc3/host.c
@@ -24,14 +24,14 @@ int dwc3_host_init(struct dwc3 *dwc)
 		return PTR_ERR(io);
 	}
 
-	dwc->xhci = add_generic_device("xHCI", DEVICE_ID_DYNAMIC, NULL,
-				       io->start, resource_size(io),
-				       IORESOURCE_MEM, NULL);
+	dwc->xhci = add_child_device(dev, "xHCI", DEVICE_ID_DYNAMIC, NULL,
+				     io->start, resource_size(io),
+				     IORESOURCE_MEM, NULL);
 	if (!dwc->xhci) {
 		dev_err(dev, "Failed to register xHCI device\n");
 		return -ENODEV;
 	}
-	
+
 	return 0;
 }
 
diff --git a/include/driver.h b/include/driver.h
index 4b367e31fd78..033b12748c12 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -283,13 +283,21 @@ int device_add_resource(struct device *dev, const char *resname,
 
 int device_add_data(struct device *dev, const void *data, size_t size);
 
+struct device *add_child_device(struct device *parent,
+				const char* devname, int id, const char *resname,
+				resource_size_t start, resource_size_t size, unsigned int flags,
+				void *pdata);
+
 /*
  * register a generic device
  * with only one resource
  */
-struct device *add_generic_device(const char* devname, int id, const char *resname,
+static inline struct device *add_generic_device(const char* devname, int id, const char *resname,
 		resource_size_t start, resource_size_t size, unsigned int flags,
-		void *pdata);
+		void *pdata)
+{
+	return add_child_device(NULL, devname, id, resname, start, size, flags, pdata);
+}
 
 /*
  * register a generic device
-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 14 08:20:32 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Apr 2023 17:20:32 +0200
Subject: [PATCH master] libfile: don't leak file descriptors in compare_file
Message-ID: <20230414152032.3783908-1-a.fatoum@pengutronix.de>

Depending on the state of environment, running

  while saveenv; do true; done

Can quickly lead to:

  saving environment
  could not open /dev/mmc2.barebox-environment: error 24
  saveenv: error 24

Because the leaked file descriptors gobble up the 128 we have
preallocated. Fix this.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 lib/libfile.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/libfile.c b/lib/libfile.c
index b967232d198e..ebd1de3d8e4d 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -542,8 +542,10 @@ int compare_file(const char *f1, const char *f2)
 	if (ret)
 		goto err_out2;
 
-	if (s1.st_size != s2.st_size)
-		return 1;
+	if (s1.st_size != s2.st_size) {
+		ret = 1;
+		goto err_out2;
+	}
 
 	buf1 = xmalloc(RW_BUF_SIZE);
 	buf2 = xmalloc(RW_BUF_SIZE);
-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 14 10:14:21 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Apr 2023 19:14:21 +0200
Subject: [PATCH master] arm: error out if __LINUX_ARM_ARCH__ is undefined
Message-ID: <20230414171421.1745965-1-a.fatoum@pengutronix.de>

With recent multiarch (really, multiplatform) rework, oldconfig will
reask users what platforms they want to build for. The default is N,
so holding return (or an olddefconfig) will just disable all boards and
with it all CPUs leading to a cryptic torrent of:

  arch/arm/include/asm/swab.h:31:28: warning: "__LINUX_ARM_ARCH__" is not defined, evaluates to 0 [-Wundef]
     31 | #if defined(__KERNEL__) && __LINUX_ARM_ARCH__ >= 6
        |                            ^~~~~~~~~~~~~~~~~~

Make user experience a bit better by printing an error message instead.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/arm/Makefile                 | 1 +
 arch/arm/include/asm/arch-check.h | 9 +++++++++
 2 files changed, 10 insertions(+)
 create mode 100644 arch/arm/include/asm/arch-check.h

diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 9bd7db6ba9f8..a506f1e3a3e5 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -42,6 +42,7 @@ endif
 # Note that GCC does not numerically define an architecture version
 # macro, but instead defines a whole series of macros which makes
 # testing for a specific architecture or later rather impossible.
+arch-y				:= -include asm/arch-check.h
 arch-$(CONFIG_CPU_64v8)		:= -D__LINUX_ARM_ARCH__=8 $(call cc-option,-march=armv8-a)
 arch-$(CONFIG_CPU_32v7)		:=-D__LINUX_ARM_ARCH__=7 $(call cc-option,-march=armv7-a,-march=armv5t -Wa$(comma)-march=armv7-a)
 arch-$(CONFIG_CPU_32v6)		:=-D__LINUX_ARM_ARCH__=6 $(call cc-option,-march=armv6,-march=armv5t -Wa$(comma)-march=armv6)
diff --git a/arch/arm/include/asm/arch-check.h b/arch/arm/include/asm/arch-check.h
new file mode 100644
index 000000000000..2cf1b624a4de
--- /dev/null
+++ b/arch/arm/include/asm/arch-check.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ARM_ASM_ARCH_CHECK_H__
+#define __ARM_ASM_ARCH_CHECK_H__
+
+#ifndef __LINUX_ARM_ARCH__
+#error No boards/CPUs selected in Kconfig
+#endif
+
+#endif
-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 14 10:47:53 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Apr 2023 19:47:53 +0200
Subject: [PATCH] mci: bcm2835: Print less errors
Message-ID: <20230414174753.1926245-1-a.fatoum@pengutronix.de>

Some commands are expected to time out, for example when a non
SDIO card is tested for being an SDIO card. Just return -ETIMEDOUT
in that case and leave error message prints to the core.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/mci/mci-bcm2835.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mci/mci-bcm2835.c b/drivers/mci/mci-bcm2835.c
index bcdf1b6196de..477a3b83a0e3 100644
--- a/drivers/mci/mci-bcm2835.c
+++ b/drivers/mci/mci-bcm2835.c
@@ -148,7 +148,7 @@ static int bcm2835_mci_request(struct mci_host *mci, struct mci_cmd *cmd,
 		      command << 16 | transfer_mode);
 
 	ret = bcm2835_mci_wait_command_done(host);
-	if (ret) {
+	if (ret && ret != -ETIMEDOUT) {
 		dev_err(host->hw_dev, "Error while executing command %d\n",
 				cmd->cmdidx);
 		dev_err(host->hw_dev, "Status: 0x%X, Interrupt: 0x%X\n",
-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 14 10:48:54 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Apr 2023 19:48:54 +0200
Subject: [PATCH v2 master] mci: bcm2835: return command timeout silently
Message-ID: <20230414174854.1927428-1-a.fatoum@pengutronix.de>

Some commands are expected to time out, for example when a non
SDIO card is tested for being an SDIO card. Just return -ETIMEDOUT
in that case and leave error message prints to the core.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - target master
  - reword commit message title
---
 drivers/mci/mci-bcm2835.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mci/mci-bcm2835.c b/drivers/mci/mci-bcm2835.c
index bcdf1b6196de..477a3b83a0e3 100644
--- a/drivers/mci/mci-bcm2835.c
+++ b/drivers/mci/mci-bcm2835.c
@@ -148,7 +148,7 @@ static int bcm2835_mci_request(struct mci_host *mci, struct mci_cmd *cmd,
 		      command << 16 | transfer_mode);
 
 	ret = bcm2835_mci_wait_command_done(host);
-	if (ret) {
+	if (ret && ret != -ETIMEDOUT) {
 		dev_err(host->hw_dev, "Error while executing command %d\n",
 				cmd->cmdidx);
 		dev_err(host->hw_dev, "Status: 0x%X, Interrupt: 0x%X\n",
-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 14 11:35:45 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Apr 2023 20:35:45 +0200
Subject: [PATCH 2/2] ARM: rpi: fixup prefix property from VideoCore FDT
In-Reply-To: <20230414183545.2039170-1-a.fatoum@pengutronix.de>
References: <20230414183545.2039170-1-a.fatoum@pengutronix.de>
Message-ID: <20230414183545.2039170-2-a.fatoum@pengutronix.de>

barebox will warn about lack of these properties when network booting.
To make network booted barebox behave identically to flashed barebox,
let's unconditionally copy them from VideoCore FDT into fixed up FDT.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/arm/boards/raspberry-pi/rpi-common.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/arch/arm/boards/raspberry-pi/rpi-common.c b/arch/arm/boards/raspberry-pi/rpi-common.c
index 3ed4510296ea..319a3d85ead5 100644
--- a/arch/arm/boards/raspberry-pi/rpi-common.c
+++ b/arch/arm/boards/raspberry-pi/rpi-common.c
@@ -256,6 +256,21 @@ static enum reset_src_type rpi_decode_pm_rsts(struct device_node *chosen,
 	return RESET_UKWN;
 }
 
+static int rpi_vc_fdt_fixup(struct device_node *root, void *data)
+{
+	const struct device_node *vc_chosen = data;
+	struct device_node *chosen;
+
+	chosen = of_create_node(root, "/chosen");
+	if (!chosen)
+		return -ENOMEM;
+
+	of_copy_property(vc_chosen, "overlay_prefix", chosen);
+	of_copy_property(vc_chosen, "os_prefix", chosen);
+
+	return 0;
+}
+
 static u32 rpi_boot_mode, rpi_boot_part;
 /* Extract useful information from the VideoCore FDT we got.
  * Some parameters are defined here:
@@ -289,6 +304,8 @@ static void rpi_vc_fdt_parse(void *fdt)
 		goto out;
 	}
 
+	of_register_fixup(rpi_vc_fdt_fixup, of_dup(chosen));
+
 	bootloader = of_find_node_by_name(chosen, "bootloader");
 
 	str = of_read_vc_string(chosen, "bootargs");
-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 14 11:35:44 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 14 Apr 2023 20:35:44 +0200
Subject: [PATCH 1/2] of: implement of_copy_property
Message-ID: <20230414183545.2039170-1-a.fatoum@pengutronix.de>

For use in fixups, it can be useful to copy a property verbatim from the
barebox DT to the kernel DT. Add a helper that does just that.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/of/base.c           | 16 ++++++++++++++++
 include/of.h                | 10 ++++++++++
 test/self/of_manipulation.c |  2 +-
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 01bb7e3906b4..5644e8e9534d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2318,6 +2318,22 @@ struct property *of_rename_property(struct device_node *np,
 	return pp;
 }
 
+struct property *of_copy_property(const struct device_node *src,
+				  const char *propname,
+				  struct device_node *dst)
+{
+	struct property *prop;
+
+	prop = of_find_property(src, propname, NULL);
+	if (!prop)
+		return NULL;
+
+	return of_new_property(dst, propname,
+			       of_property_get_value(prop), prop->length);
+}
+EXPORT_SYMBOL_GPL(of_copy_property);
+
+
 /**
  * of_set_property - create a property for a given node
  * @node - the node
diff --git a/include/of.h b/include/of.h
index 22358f5579ec..4b0266fd3118 100644
--- a/include/of.h
+++ b/include/of.h
@@ -152,6 +152,9 @@ extern struct property *__of_new_property(struct device_node *node,
 extern void of_delete_property(struct property *pp);
 extern struct property *of_rename_property(struct device_node *np,
 					   const char *old_name, const char *new_name);
+extern struct property *of_copy_property(const struct device_node *src,
+					 const char *propname,
+					 struct device_node *dst);
 
 extern struct device_node *of_find_node_by_name(struct device_node *from,
 	const char *name);
@@ -576,6 +579,13 @@ static inline struct property *__of_new_property(struct device_node *node,
 	return NULL;
 }
 
+static inline struct property *of_copy_property(const struct device_node *src,
+						const char *propname,
+						struct device_node *dst)
+{
+	return NULL;
+}
+
 static inline void of_delete_property(struct property *pp)
 {
 }
diff --git a/test/self/of_manipulation.c b/test/self/of_manipulation.c
index f7f95fa269af..64913ac1eab8 100644
--- a/test/self/of_manipulation.c
+++ b/test/self/of_manipulation.c
@@ -63,7 +63,7 @@ static void test_of_basics(struct device_node *root)
 	of_property_write_u32(node2, "property2", 2);
 
 	of_property_write_u32(node1, "property3", 1);
-	of_property_write_u32(node1, "property2", 2);
+	of_copy_property(node2, "property2", node1);
 	of_rename_property(node1, "property3", "property1");
 
 	assert_equal(node1, node2);
-- 
2.39.2



From a.fatoum at pengutronix.de  Sat Apr 15 01:34:47 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Sat, 15 Apr 2023 10:34:47 +0200
Subject: [PATCH master] ARM64: setupc: don't invoke KASAN before relocation
Message-ID: <20230415083447.3069903-1-a.fatoum@pengutronix.de>

Plain memset and memcpy are checked by KASAN if enabled before calling
unchecked __memset and __memcpy respectively.

KASAN uses a kasan_initialized variable as first condition in its memory
check, but that only works after relocation. For that reason, we must
take care not to invoke KASAN before then. This was done for ARM32, but
was missing for ARM64. Do so now.

This fixes an annoying issue where network booting a KASAN-enabled barebox
twice in a row would fail: The first happened to work because the memory
kasan_initialized was placed at was zero. The second would behave
erratically, because BSS initialization would silently fail and barebox
static storage would then be initialized with the final values of the
previous run.

Fixes: 932ef7a02e2f ("ARM: Add KASan support")
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
I wondered if there's a way to print a KASAN error that early, but it's
not easy. Calling even global_variable_offset() in kasan_report caused
infinite recursion, despite use of __no_sanitize_address. Printing
unconditionally could be a way around this.
---
 arch/arm/cpu/setupc_64.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/cpu/setupc_64.S b/arch/arm/cpu/setupc_64.S
index d64281c148fc..f38f893be90b 100644
--- a/arch/arm/cpu/setupc_64.S
+++ b/arch/arm/cpu/setupc_64.S
@@ -14,7 +14,7 @@ ENTRY(setup_c)
 	mov	x1, #0
 	ldr	x2, =__bss_stop
 	sub	x2, x2, x0
-	bl	memset			/* clear bss */
+	bl	__memset		/* clear bss */
 	mov	x30, x15
 	ret
 ENDPROC(setup_c)
@@ -63,7 +63,7 @@ ENTRY(relocate_to_adr)
 	sub	x19, x19, x1		/* sub address where we are actually running */
 	add	x19, x19, x0		/* add address where we are going to run */
 
-	bl	memcpy			/* copy binary */
+	bl	__memcpy		/* copy binary */
 
 	bl	sync_caches_for_execution
 
-- 
2.39.2



From sha at pengutronix.de  Sun Apr 16 23:52:56 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Apr 2023 08:52:56 +0200
Subject: [PATCH master] ARM64: setupc: don't invoke KASAN before
 relocation
In-Reply-To: <20230415083447.3069903-1-a.fatoum@pengutronix.de>
References: <20230415083447.3069903-1-a.fatoum@pengutronix.de>
Message-ID: <20230417065256.GC13543@pengutronix.de>

On Sat, Apr 15, 2023 at 10:34:47AM +0200, Ahmad Fatoum wrote:
> Plain memset and memcpy are checked by KASAN if enabled before calling
> unchecked __memset and __memcpy respectively.
> 
> KASAN uses a kasan_initialized variable as first condition in its memory
> check, but that only works after relocation. For that reason, we must
> take care not to invoke KASAN before then. This was done for ARM32, but
> was missing for ARM64. Do so now.
> 
> This fixes an annoying issue where network booting a KASAN-enabled barebox
> twice in a row would fail: The first happened to work because the memory
> kasan_initialized was placed at was zero. The second would behave
> erratically, because BSS initialization would silently fail and barebox
> static storage would then be initialized with the final values of the
> previous run.
> 
> Fixes: 932ef7a02e2f ("ARM: Add KASan support")
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>

Applied, thanks

Sascha

> ---
> I wondered if there's a way to print a KASAN error that early, but it's
> not easy. Calling even global_variable_offset() in kasan_report caused
> infinite recursion, despite use of __no_sanitize_address. Printing
> unconditionally could be a way around this.
> ---
>  arch/arm/cpu/setupc_64.S | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm/cpu/setupc_64.S b/arch/arm/cpu/setupc_64.S
> index d64281c148fc..f38f893be90b 100644
> --- a/arch/arm/cpu/setupc_64.S
> +++ b/arch/arm/cpu/setupc_64.S
> @@ -14,7 +14,7 @@ ENTRY(setup_c)
>  	mov	x1, #0
>  	ldr	x2, =__bss_stop
>  	sub	x2, x2, x0
> -	bl	memset			/* clear bss */
> +	bl	__memset		/* clear bss */
>  	mov	x30, x15
>  	ret
>  ENDPROC(setup_c)
> @@ -63,7 +63,7 @@ ENTRY(relocate_to_adr)
>  	sub	x19, x19, x1		/* sub address where we are actually running */
>  	add	x19, x19, x0		/* add address where we are going to run */
>  
> -	bl	memcpy			/* copy binary */
> +	bl	__memcpy		/* copy binary */
>  
>  	bl	sync_caches_for_execution
>  
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Sun Apr 16 23:53:35 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Apr 2023 08:53:35 +0200
Subject: [PATCH v2 master] mci: bcm2835: return command timeout silently
In-Reply-To: <20230414174854.1927428-1-a.fatoum@pengutronix.de>
References: <20230414174854.1927428-1-a.fatoum@pengutronix.de>
Message-ID: <20230417065335.GD13543@pengutronix.de>

On Fri, Apr 14, 2023 at 07:48:54PM +0200, Ahmad Fatoum wrote:
> Some commands are expected to time out, for example when a non
> SDIO card is tested for being an SDIO card. Just return -ETIMEDOUT
> in that case and leave error message prints to the core.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
> v1 -> v2:
>   - target master
>   - reword commit message title
> ---
>  drivers/mci/mci-bcm2835.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/mci/mci-bcm2835.c b/drivers/mci/mci-bcm2835.c
> index bcdf1b6196de..477a3b83a0e3 100644
> --- a/drivers/mci/mci-bcm2835.c
> +++ b/drivers/mci/mci-bcm2835.c
> @@ -148,7 +148,7 @@ static int bcm2835_mci_request(struct mci_host *mci, struct mci_cmd *cmd,
>  		      command << 16 | transfer_mode);
>  
>  	ret = bcm2835_mci_wait_command_done(host);
> -	if (ret) {
> +	if (ret && ret != -ETIMEDOUT) {
>  		dev_err(host->hw_dev, "Error while executing command %d\n",
>  				cmd->cmdidx);
>  		dev_err(host->hw_dev, "Status: 0x%X, Interrupt: 0x%X\n",
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Sun Apr 16 23:55:16 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Apr 2023 08:55:16 +0200
Subject: [PATCH master] arm: error out if __LINUX_ARM_ARCH__ is undefined
In-Reply-To: <20230414171421.1745965-1-a.fatoum@pengutronix.de>
References: <20230414171421.1745965-1-a.fatoum@pengutronix.de>
Message-ID: <20230417065516.GE13543@pengutronix.de>

On Fri, Apr 14, 2023 at 07:14:21PM +0200, Ahmad Fatoum wrote:
> With recent multiarch (really, multiplatform) rework, oldconfig will
> reask users what platforms they want to build for. The default is N,
> so holding return (or an olddefconfig) will just disable all boards and
> with it all CPUs leading to a cryptic torrent of:
> 
>   arch/arm/include/asm/swab.h:31:28: warning: "__LINUX_ARM_ARCH__" is not defined, evaluates to 0 [-Wundef]
>      31 | #if defined(__KERNEL__) && __LINUX_ARM_ARCH__ >= 6
>         |                            ^~~~~~~~~~~~~~~~~~
> 
> Make user experience a bit better by printing an error message instead.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  arch/arm/Makefile                 | 1 +
>  arch/arm/include/asm/arch-check.h | 9 +++++++++
>  2 files changed, 10 insertions(+)
>  create mode 100644 arch/arm/include/asm/arch-check.h

Applied, thanks

Sascha

> 
> diff --git a/arch/arm/Makefile b/arch/arm/Makefile
> index 9bd7db6ba9f8..a506f1e3a3e5 100644
> --- a/arch/arm/Makefile
> +++ b/arch/arm/Makefile
> @@ -42,6 +42,7 @@ endif
>  # Note that GCC does not numerically define an architecture version
>  # macro, but instead defines a whole series of macros which makes
>  # testing for a specific architecture or later rather impossible.
> +arch-y				:= -include asm/arch-check.h
>  arch-$(CONFIG_CPU_64v8)		:= -D__LINUX_ARM_ARCH__=8 $(call cc-option,-march=armv8-a)
>  arch-$(CONFIG_CPU_32v7)		:=-D__LINUX_ARM_ARCH__=7 $(call cc-option,-march=armv7-a,-march=armv5t -Wa$(comma)-march=armv7-a)
>  arch-$(CONFIG_CPU_32v6)		:=-D__LINUX_ARM_ARCH__=6 $(call cc-option,-march=armv6,-march=armv5t -Wa$(comma)-march=armv6)
> diff --git a/arch/arm/include/asm/arch-check.h b/arch/arm/include/asm/arch-check.h
> new file mode 100644
> index 000000000000..2cf1b624a4de
> --- /dev/null
> +++ b/arch/arm/include/asm/arch-check.h
> @@ -0,0 +1,9 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +#ifndef __ARM_ASM_ARCH_CHECK_H__
> +#define __ARM_ASM_ARCH_CHECK_H__
> +
> +#ifndef __LINUX_ARM_ARCH__
> +#error No boards/CPUs selected in Kconfig
> +#endif
> +
> +#endif
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Sun Apr 16 23:57:06 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Apr 2023 08:57:06 +0200
Subject: [PATCH master] libfile: don't leak file descriptors in
 compare_file
In-Reply-To: <20230414152032.3783908-1-a.fatoum@pengutronix.de>
References: <20230414152032.3783908-1-a.fatoum@pengutronix.de>
Message-ID: <20230417065706.GF13543@pengutronix.de>

On Fri, Apr 14, 2023 at 05:20:32PM +0200, Ahmad Fatoum wrote:
> Depending on the state of environment, running
> 
>   while saveenv; do true; done
> 
> Can quickly lead to:
> 
>   saving environment
>   could not open /dev/mmc2.barebox-environment: error 24
>   saveenv: error 24
> 
> Because the leaked file descriptors gobble up the 128 we have
> preallocated. Fix this.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  lib/libfile.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/lib/libfile.c b/lib/libfile.c
> index b967232d198e..ebd1de3d8e4d 100644
> --- a/lib/libfile.c
> +++ b/lib/libfile.c
> @@ -542,8 +542,10 @@ int compare_file(const char *f1, const char *f2)
>  	if (ret)
>  		goto err_out2;
>  
> -	if (s1.st_size != s2.st_size)
> -		return 1;
> +	if (s1.st_size != s2.st_size) {
> +		ret = 1;
> +		goto err_out2;
> +	}
>  
>  	buf1 = xmalloc(RW_BUF_SIZE);
>  	buf2 = xmalloc(RW_BUF_SIZE);
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Sun Apr 16 23:58:08 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Apr 2023 08:58:08 +0200
Subject: [PATCH master] ARM: i.MX6: fix DEBUG_LL use
In-Reply-To: <20230414132651.1703346-1-a.fatoum@pengutronix.de>
References: <20230414132651.1703346-1-a.fatoum@pengutronix.de>
Message-ID: <20230417065808.GG13543@pengutronix.de>

On Fri, Apr 14, 2023 at 03:26:51PM +0200, Ahmad Fatoum wrote:
> Below mentioned commit added a select DEBUG_IMX_UART for all supported
> i.MX variants apart from the i.MX6Q. Let's do likewise there, so
> DEBUG_LL may be enabled without errors about missing PUTC_LL definition.
> 
> Fixes: 0fff6cb9bb4f ("ARM: i.MX: Only provide PUTC_LL() when activated")
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  common/Kconfig | 1 +
>  1 file changed, 1 insertion(+)

Applied, thanks

Sascha

> 
> diff --git a/common/Kconfig b/common/Kconfig
> index d951947463a2..ac3df75acbc5 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -1342,6 +1342,7 @@ config DEBUG_IMX53_UART
>  config DEBUG_IMX6Q_UART
>  	bool "i.MX6Q Debug UART"
>  	depends on ARCH_IMX6
> +	select DEBUG_IMX_UART
>  	help
>  	  Say Y here if you want kernel low-level debugging support
>  	  on i.MX6Q.
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Sun Apr 16 23:58:50 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Apr 2023 08:58:50 +0200
Subject: [PATCH] usb: misc: onboard_hub: sync compatibles with kernel
In-Reply-To: <20230414141703.3112251-1-a.fatoum@pengutronix.de>
References: <20230414141703.3112251-1-a.fatoum@pengutronix.de>
Message-ID: <20230417065850.GH13543@pengutronix.de>

On Fri, Apr 14, 2023 at 04:17:03PM +0200, Ahmad Fatoum wrote:
> A couple more USB hub compatibles ave been added to the kernel in the
> meantime, so let's import them.
> 
> While at it, make onboard_hub_match static. It's not used anywhere else.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  drivers/usb/misc/onboard_usb_hub.h | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/usb/misc/onboard_usb_hub.h b/drivers/usb/misc/onboard_usb_hub.h
> index e90be47b6735..aca5f50eb0da 100644
> --- a/drivers/usb/misc/onboard_usb_hub.h
> +++ b/drivers/usb/misc/onboard_usb_hub.h
> @@ -22,14 +22,31 @@ static const struct onboard_hub_pdata ti_tusb8041_data = {
>  	.reset_us = 3000,
>  };
>  
> -const struct of_device_id onboard_hub_match[] = {
> +static const struct onboard_hub_pdata genesys_gl850g_data = {
> +	.reset_us = 3,
> +};
> +
> +static const struct onboard_hub_pdata genesys_gl852g_data = {
> +	.reset_us = 50,
> +};
> +
> +static const struct onboard_hub_pdata vialab_vl817_data = {
> +	.reset_us = 10,
> +};
> +
> +static const struct of_device_id onboard_hub_match[] = {
>  	{ .compatible = "usb424,2514", .data = &microchip_usb424_data, },
> +	{ .compatible = "usb424,2517", .data = &microchip_usb424_data, },
>  	{ .compatible = "usb451,8140", .data = &ti_tusb8041_data, },
>  	{ .compatible = "usb451,8142", .data = &ti_tusb8041_data, },
> +	{ .compatible = "usb5e3,608", .data = &genesys_gl850g_data, },
> +	{ .compatible = "usb5e3,610", .data = &genesys_gl852g_data, },
>  	{ .compatible = "usbbda,411", .data = &realtek_rts5411_data, },
>  	{ .compatible = "usbbda,5411", .data = &realtek_rts5411_data, },
>  	{ .compatible = "usbbda,414", .data = &realtek_rts5411_data, },
>  	{ .compatible = "usbbda,5414", .data = &realtek_rts5411_data, },
> +	{ .compatible = "usb2109,817", .data = &vialab_vl817_data, },
> +	{ .compatible = "usb2109,2817", .data = &vialab_vl817_data, },
>  	{}
>  };
>  
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Mon Apr 17 00:00:58 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Apr 2023 09:00:58 +0200
Subject: [PATCH] fixup! scripts: gen-dtb-s: reference OF IMD entries
 automatically
In-Reply-To: <20230414141154.2988598-1-a.fatoum@pengutronix.de>
References: <20230414141154.2988598-1-a.fatoum@pengutronix.de>
Message-ID: <20230417070058.GI13543@pengutronix.de>

On Fri, Apr 14, 2023 at 04:11:54PM +0200, Ahmad Fatoum wrote:
> While the reference is just there, so linker garbage collection doesn't
> remove it, it's still a reference and it will be relocated.
> 
> This means it must be aligned, otherwise we will crash doing an unaligned
> access during relocation if device tree size isn't evenly divisible by
> pointer length...
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  scripts/gen-dtb-s | 2 ++
>  1 file changed, 2 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
> index 6a624e0bd5d0..f6fa1525933e 100755
> --- a/scripts/gen-dtb-s
> +++ b/scripts/gen-dtb-s
> @@ -51,6 +51,7 @@ echo ".incbin \"$dtb\""
>  echo "__dtb_${name}_end:"
>  echo ".global __dtb_${name}_end"
>  if [ "$imd" = "y" ]; then
> +	echo ".balign ASM_SZPTR"
>  	echo "ASM_PTR __barebox_imd_OF_${name}"
>  fi
>  echo ".balign STRUCT_ALIGNMENT"
> @@ -70,6 +71,7 @@ echo ".incbin \"$dtb.z\""
>  echo "__dtb_z_${name}_end:"
>  echo ".global __dtb_z_${name}_end"
>  if [ "$imd" = "y" ]; then
> +	echo ".balign ASM_SZPTR"
>  	echo "ASM_PTR __barebox_imd_OF_${name}"
>  fi
>  echo ".balign STRUCT_ALIGNMENT"
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Mon Apr 17 00:05:54 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Apr 2023 09:05:54 +0200
Subject: [PATCH v2 0/5] dma: pass physical device to DMA API
In-Reply-To: <20230414145259.3644816-1-a.fatoum@pengutronix.de>
References: <20230414145259.3644816-1-a.fatoum@pengutronix.de>
Message-ID: <20230417070554.GJ13543@pengutronix.de>

On Fri, Apr 14, 2023 at 04:52:54PM +0200, Ahmad Fatoum wrote:
> This splits off the non-contentions parts of my dma-coherency series:
> https://lore.barebox.org/barebox/20230221080524.607241-1-a.fatoum at pengutronix.de/
> 
> Only change is a typo fix in a comment, but no other changes.
> 
> Ahmad Fatoum (5):
>   usb: dwc3: populate parent of xHCI dev
>   usb: xhci: pass physical device to DMA API
>   net: rtl8169: pass physical device for DMA API
>   firmware: zynqmp-fpga: pass physical device to DMA API
>   net: designware: eqos: pass physical device to DMA API

Applied, thanks

Sascha

> 
>  drivers/base/resource.c        |  6 ++++--
>  drivers/firmware/zynqmp-fpga.c |  7 ++++---
>  drivers/net/designware_eqos.c  | 13 ++++++-------
>  drivers/net/rtl8169.c          |  9 +++++----
>  drivers/usb/dwc3/host.c        |  8 ++++----
>  drivers/usb/host/xhci-ring.c   |  8 ++++----
>  drivers/usb/host/xhci.c        |  6 +++++-
>  include/driver.h               | 12 ++++++++++--
>  8 files changed, 42 insertions(+), 27 deletions(-)
> 
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sha at pengutronix.de  Mon Apr 17 00:08:47 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Apr 2023 09:08:47 +0200
Subject: [PATCH 1/2] of: implement of_copy_property
In-Reply-To: <20230414183545.2039170-1-a.fatoum@pengutronix.de>
References: <20230414183545.2039170-1-a.fatoum@pengutronix.de>
Message-ID: <20230417070847.GK13543@pengutronix.de>

On Fri, Apr 14, 2023 at 08:35:44PM +0200, Ahmad Fatoum wrote:
> For use in fixups, it can be useful to copy a property verbatim from the
> barebox DT to the kernel DT. Add a helper that does just that.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  drivers/of/base.c           | 16 ++++++++++++++++
>  include/of.h                | 10 ++++++++++
>  test/self/of_manipulation.c |  2 +-
>  3 files changed, 27 insertions(+), 1 deletion(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 01bb7e3906b4..5644e8e9534d 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -2318,6 +2318,22 @@ struct property *of_rename_property(struct device_node *np,
>  	return pp;
>  }
>  
> +struct property *of_copy_property(const struct device_node *src,
> +				  const char *propname,
> +				  struct device_node *dst)
> +{
> +	struct property *prop;
> +
> +	prop = of_find_property(src, propname, NULL);
> +	if (!prop)
> +		return NULL;
> +
> +	return of_new_property(dst, propname,
> +			       of_property_get_value(prop), prop->length);
> +}
> +EXPORT_SYMBOL_GPL(of_copy_property);
> +
> +
>  /**
>   * of_set_property - create a property for a given node
>   * @node - the node
> diff --git a/include/of.h b/include/of.h
> index 22358f5579ec..4b0266fd3118 100644
> --- a/include/of.h
> +++ b/include/of.h
> @@ -152,6 +152,9 @@ extern struct property *__of_new_property(struct device_node *node,
>  extern void of_delete_property(struct property *pp);
>  extern struct property *of_rename_property(struct device_node *np,
>  					   const char *old_name, const char *new_name);
> +extern struct property *of_copy_property(const struct device_node *src,
> +					 const char *propname,
> +					 struct device_node *dst);
>  
>  extern struct device_node *of_find_node_by_name(struct device_node *from,
>  	const char *name);
> @@ -576,6 +579,13 @@ static inline struct property *__of_new_property(struct device_node *node,
>  	return NULL;
>  }
>  
> +static inline struct property *of_copy_property(const struct device_node *src,
> +						const char *propname,
> +						struct device_node *dst)
> +{
> +	return NULL;
> +}
> +
>  static inline void of_delete_property(struct property *pp)
>  {
>  }
> diff --git a/test/self/of_manipulation.c b/test/self/of_manipulation.c
> index f7f95fa269af..64913ac1eab8 100644
> --- a/test/self/of_manipulation.c
> +++ b/test/self/of_manipulation.c
> @@ -63,7 +63,7 @@ static void test_of_basics(struct device_node *root)
>  	of_property_write_u32(node2, "property2", 2);
>  
>  	of_property_write_u32(node1, "property3", 1);
> -	of_property_write_u32(node1, "property2", 2);
> +	of_copy_property(node2, "property2", node1);
>  	of_rename_property(node1, "property3", "property1");
>  
>  	assert_equal(node1, node2);
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From Markus.Burri at mt.com  Mon Apr 17 02:42:39 2023
From: Markus.Burri at mt.com (Burri Markus LabTec)
Date: Mon, 17 Apr 2023 09:42:39 +0000
Subject: EXTERNAL - [PATCH v1] Add bootchooser command option for active
 boot target
In-Reply-To: <b8847e00-0e27-c7f8-af75-977fa41fa64e@pengutronix.de>
References: <20230414094020.2389226-1-markus.burri@mt.com>
 <f454aee9-3e78-c1bc-f448-3355e3613d14@pengutronix.de>
 <PA4PR03MB748854E525009BC8F015D570EF999@PA4PR03MB7488.eurprd03.prod.outlook.com>
 <7c13d1e3-452f-5b91-4511-d64c531f0145@pengutronix.de>
 <PA4PR03MB7488B5A455A50A14BB7E44A5EF999@PA4PR03MB7488.eurprd03.prod.outlook.com>
 <b8847e00-0e27-c7f8-af75-977fa41fa64e@pengutronix.de>
Message-ID: <PA4PR03MB7488267E1064820DC94F3E00EF9C9@PA4PR03MB7488.eurprd03.prod.outlook.com>

Hi Ahmad
I removed my init script and replaced it by a script added to bootchooser.system0.boot=<script>.
This fit my requirements and therefor the patch is obsolete.
Thanks for your support.
Best regards Markus

-----Original Message-----
From: Ahmad Fatoum <a.fatoum at pengutronix.de> 
Sent: Freitag, 14. April 2023 14:47
To: Burri Markus LabTec <Markus.Burri at mt.com>
Cc: barebox at lists.infradead.org
Subject: Re: EXTERNAL - [PATCH v1] Add bootchooser command option for active boot target

Hello Markus,

On 14.04.23 14:41, Burri Markus LabTec wrote:
> Hello Ahmad
> 
> The Idea is to run some scripts stored in the rootfs before booting 
> the system. In our case e.g we enable led according to customer needs. 
> This is stored in to rootfs where the customer is able to update 
> without update barebox

Once you give your customer the ability to run arbitrary code, they will run arbitrary code, e.g. apply an overlay to the kernel DT or tune kernel command line argument. With your init script approach, you could apply old overlays when booting a new kernel, which can lead to very surprising results.

> The new command option will store this information in a variable where I can use this information in the init script.
> It sound that a script as bootchooser target will fit my requirement. 
> I didn't know that. I will try

I am not opposed to give these scripts knowledge of what bootchooser target is executed, see untested patch below. But it should be the boot scripts that run hooks, not an init script on a subsequent boot.

Cheers,
Ahmad

---
 common/bootchooser.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/common/bootchooser.c b/common/bootchooser.c index 08d05e885250..3d400af08ef1 100644
--- a/common/bootchooser.c
+++ b/common/bootchooser.c
@@ -827,6 +827,7 @@ static int bootchooser_boot_one(struct bootchooser *bc, int *tryagain)
                goto out;
        }

+       globalvar_add_simple("bootchooser.active", target->name);
        system = basprintf("bootchooser.active=%s", target->name);
        globalvar_add_simple("linux.bootargs.bootchooser", system);
        free(system);
@@ -854,6 +855,7 @@ static int bootchooser_boot_one(struct bootchooser *bc, int *tryagain)
        *tryagain = 1;
 out:
        globalvar_set_match("linux.bootargs.bootchooser", NULL);
+       globalvar_set_match("bootchooser.active", NULL);

        bootentries_free(entries);

@@ -976,3 +978,5 @@ BAREBOX_MAGICVAR(global.bootchooser.default_priority,
                 "bootchooser: Default priority for a target");  BAREBOX_MAGICVAR(global.bootchooser.state_prefix,
                 "bootchooser: state name prefix, empty for nv backend");
+BAREBOX_MAGICVAR(global.bootchooser.active,
+                "bootchooser: holds name of active bootchooser target 
+during boot");


From a.fatoum at pengutronix.de  Mon Apr 17 05:51:58 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Mon, 17 Apr 2023 14:51:58 +0200
Subject: [PATCH master] lib: genalloc: drop reliance on mmio-sram driver
Message-ID: <20230417125158.882170-1-a.fatoum@pengutronix.de>

The barebox mmio-sram driver just makes SRAMs available as /dev/sramX
devices. The genalloc stub depended on it without selecting CONFIG_SRAM.

Instead of making this dependency explicit, just call of_address_to_resource
and have no dependency on CONFIG_SRAM at all.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 lib/genalloc.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/genalloc.c b/lib/genalloc.c
index 906e2dd5f14b..2e9815c36b78 100644
--- a/lib/genalloc.c
+++ b/lib/genalloc.c
@@ -12,6 +12,7 @@
 #include <linux/genalloc.h>
 #include <linux/export.h>
 #include <of.h>
+#include <of_address.h>
 #include <driver.h>
 #include <linux/string.h>
 
@@ -98,8 +99,9 @@ EXPORT_SYMBOL(gen_pool_dma_zalloc);
 struct gen_pool *of_gen_pool_get(struct device_node *np,
 	const char *propname, int index)
 {
-	struct device *dev;
 	struct device_node *np_pool;
+	struct gen_pool gen_pool;
+	int ret;
 
 	np_pool = of_parse_phandle(np, propname, index);
 	if (!np_pool)
@@ -108,11 +110,11 @@ struct gen_pool *of_gen_pool_get(struct device_node *np,
 	if (!of_device_is_compatible(np_pool, "mmio-sram"))
 		return NULL;
 
-	dev = of_find_device_by_node(np_pool);
-	if (!dev)
+	ret = of_address_to_resource(np_pool, 0, &gen_pool.res);
+	if (ret)
 		return NULL;
 
-	return container_of(&dev->resource[0], struct gen_pool, res);
+	return memdup(&gen_pool, sizeof(gen_pool));
 }
 EXPORT_SYMBOL_GPL(of_gen_pool_get);
 #endif /* CONFIG_OF */
-- 
2.39.2



From a.fatoum at pengutronix.de  Mon Apr 17 09:42:55 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Mon, 17 Apr 2023 18:42:55 +0200
Subject: [PATCH 2/2] mci: imx-esdhc: add uSDHC eMMC DDR52 supprot
In-Reply-To: <20230417164255.1070012-1-a.fatoum@pengutronix.de>
References: <20230417164255.1070012-1-a.fatoum@pengutronix.de>
Message-ID: <20230417164255.1070012-2-a.fatoum@pengutronix.de>

The uSDHC available with the i.MX6/7/8 SoCs has support for DDR
clock operation. This is enabled by flipping a bit in
IMX_SDHCI_MIXCTRL and adjusting the clock divider calculation to
account for the automatic internal halving of the clock.

Let's do that to speed up boot from eMMC. How much effect this has
in practice is not constant. Comparing two Kingston eMMCs: DDR on the
older v4.5 connected to an i.MX6 did not yield any difference. On the
newer v5.1 one connected to an i.MX8MM, I observe a 70% improvement in
throughput: from 40MiB/s to 69.5 MiB/s.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/mci/imx-esdhc-common.c |  1 +
 drivers/mci/imx-esdhc.c        | 45 +++++++++++++++++++++++++++++-----
 drivers/mci/imx-esdhc.h        | 14 +++++++++++
 3 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/drivers/mci/imx-esdhc-common.c b/drivers/mci/imx-esdhc-common.c
index 27293e44b724..3c1ff9882432 100644
--- a/drivers/mci/imx-esdhc-common.c
+++ b/drivers/mci/imx-esdhc-common.c
@@ -160,6 +160,7 @@ int __esdhc_send_cmd(struct fsl_esdhc_host *host, struct mci_cmd *cmd,
 		mixctrl = xfertyp;
 		/* Keep the bits 22-25 of the register as is */
 		mixctrl |= (sdhci_read32(&host->sdhci, IMX_SDHCI_MIXCTRL) & (0xF << 22));
+		mixctrl |= mci_timing_is_ddr(host->sdhci.timing) ? MIX_CTRL_DDREN : 0;
 		sdhci_write32(&host->sdhci, IMX_SDHCI_MIXCTRL, mixctrl);
 	}
 
diff --git a/drivers/mci/imx-esdhc.c b/drivers/mci/imx-esdhc.c
index 2e2bc14ef95c..94f18fe2b3cf 100644
--- a/drivers/mci/imx-esdhc.c
+++ b/drivers/mci/imx-esdhc.c
@@ -43,9 +43,9 @@ esdhc_send_cmd(struct mci_host *mci, struct mci_cmd *cmd, struct mci_data *data)
 	return  __esdhc_send_cmd(host, cmd, data);
 }
 
-static void set_sysctl(struct mci_host *mci, u32 clock)
+static void set_sysctl(struct mci_host *mci, u32 clock, bool ddr)
 {
-	int div, pre_div;
+	int div, pre_div, ddr_pre_div = ddr ? 2 : 1;
 	struct fsl_esdhc_host *host = to_fsl_esdhc(mci);
 	int sdhc_clk = clk_get_rate(host->clk);
 	u32 clk;
@@ -65,11 +65,11 @@ static void set_sysctl(struct mci_host *mci, u32 clock)
 		pre_div = 1;
 	else if (sdhc_clk / 16 > clock)
 		for (; pre_div < 256; pre_div *= 2)
-			if ((sdhc_clk / pre_div) <= (clock * 16))
+			if ((sdhc_clk / (pre_div * ddr_pre_div)) <= (clock * 16))
 				break;
 
 	for (div = 1; div <= 16; div++)
-		if ((sdhc_clk / (div * pre_div)) <= clock)
+		if ((sdhc_clk / (div * pre_div * ddr_pre_div)) <= clock)
 			break;
 
 	cur_clock = sdhc_clk / pre_div / div;
@@ -103,12 +103,42 @@ static void set_sysctl(struct mci_host *mci, u32 clock)
 		   10 * MSECOND);
 }
 
+static void esdhc_set_timing(struct fsl_esdhc_host *host, enum mci_timing timing)
+{
+	u32 mixctrl;
+
+	mixctrl = sdhci_read32(&host->sdhci, IMX_SDHCI_MIXCTRL);
+	mixctrl &= ~MIX_CTRL_DDREN;
+
+	switch (timing) {
+	case MMC_TIMING_UHS_DDR50:
+	case MMC_TIMING_MMC_DDR52:
+		mixctrl |= MIX_CTRL_DDREN;
+		sdhci_write32(&host->sdhci, IMX_SDHCI_MIXCTRL, mixctrl);
+		break;
+	default:
+		sdhci_write32(&host->sdhci, IMX_SDHCI_MIXCTRL, mixctrl);
+	}
+
+	host->sdhci.timing = timing;
+}
+
 static void esdhc_set_ios(struct mci_host *mci, struct mci_ios *ios)
 {
 	struct fsl_esdhc_host *host = to_fsl_esdhc(mci);
 
+	/*
+	 * call esdhc_set_timing() before update the clock rate,
+	 * This is because current we support DDR and SDR timing,
+	 * Once the DDR_EN bit is set, the card clock will be
+	 * divide by 2 automatically. So need to do this before
+	 * setting clock rate.
+	 */
+	if (esdhc_is_usdhc(host) && host->sdhci.timing != ios->timing)
+		esdhc_set_timing(host, ios->timing);
+
 	/* Set the clock speed */
-	set_sysctl(mci, ios->clock);
+	set_sysctl(mci, ios->clock, mci_timing_is_ddr(ios->timing));
 
 	/* Set the bus width */
 	esdhc_clrbits32(host, SDHCI_HOST_CONTROL__POWER_CONTROL__BLOCK_GAP_CONTROL,
@@ -206,7 +236,7 @@ static int esdhc_init(struct mci_host *mci, struct device *dev)
 		esdhc_setbits32(host, ESDHC_DMA_SYSCTL, ESDHC_SYSCTL_DMA_SNOOP);
 
 	/* Set the initial clock speed */
-	set_sysctl(mci, 400000);
+	set_sysctl(mci, 400000, false);
 
 	sdhci_write32(&host->sdhci, SDHCI_INT_ENABLE, SDHCI_INT_CMD_COMPLETE |
 			SDHCI_INT_XFER_COMPLETE | SDHCI_INT_CARD_INT |
@@ -285,6 +315,9 @@ static int fsl_esdhc_probe(struct device *dev)
 	if (ret)
 		goto err_clk_disable;
 
+	if (esdhc_is_usdhc(host))
+		mci->host_caps |= MMC_CAP_MMC_3_3V_DDR | MMC_CAP_MMC_1_8V_DDR;
+
 	rate = clk_get_rate(host->clk);
 	host->mci.f_min = rate >> 12;
 	if (host->mci.f_min < 200000)
diff --git a/drivers/mci/imx-esdhc.h b/drivers/mci/imx-esdhc.h
index 0d8f157a7615..b14039757a7a 100644
--- a/drivers/mci/imx-esdhc.h
+++ b/drivers/mci/imx-esdhc.h
@@ -41,6 +41,20 @@
 
 #define IMX_SDHCI_WML		0x44
 #define IMX_SDHCI_MIXCTRL	0x48
+/* Imported from Linux Kernel drivers/mmc/host/sdhci-esdhc-imx.c */
+#define  MIX_CTRL_DDREN		BIT(3)
+#define  MIX_CTRL_DTDSEL_READ	BIT(4)
+#define  MIX_CTRL_AC23EN	BIT(7)
+#define  MIX_CTRL_EXE_TUNE	BIT(22)
+#define  MIX_CTRL_SMPCLK_SEL	BIT(23)
+#define  MIX_CTRL_AUTO_TUNE_EN	BIT(24)
+#define  MIX_CTRL_FBCLK_SEL	BIT(25)
+#define  MIX_CTRL_HS400_EN	BIT(26)
+#define  MIX_CTRL_HS400_ES	BIT(27)
+/* Bits 3 and 6 are not SDHCI standard definitions */
+#define  MIX_CTRL_SDHCI_MASK	0xb7
+/* Tuning bits */
+#define  MIX_CTRL_TUNING_MASK	0x03c00000
 #define IMX_SDHCI_DLL_CTRL	0x60
 #define IMX_SDHCI_MIX_CTRL_FBCLK_SEL	BIT(25)
 
-- 
2.39.2



From a.fatoum at pengutronix.de  Mon Apr 17 09:42:54 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Mon, 17 Apr 2023 18:42:54 +0200
Subject: [PATCH 1/2] mci: add eMMC DDR52 support
Message-ID: <20230417164255.1070012-1-a.fatoum@pengutronix.de>

The maximum card frequency that can be configured by barebox currently
is 50MHz for SD and 52MHz for eMMC. Higher speed modes require runtime
voltage switching or tuning sequences, which are not yet implemented.

Only exception is eMMC's DDR52: This mode was first introduced with
MMC 4.4 and can be used even at 3.3V.

This commit adds DDR52 support to the core. This introduces no functional
change, because host controllers must opt-in by setting the appropriate
host capabilities.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/mci/mci-core.c | 54 +++++++++++++++++++++++++++++++++++-------
 include/mci.h          | 19 +++++++++++++++
 2 files changed, 64 insertions(+), 9 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index f647cae8203b..86f468edfea6 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -135,6 +135,9 @@ static int mci_set_blocklen(struct mci *mci, unsigned len)
 {
 	struct mci_cmd cmd;
 
+	if (mci->host->timing == MMC_TIMING_MMC_DDR52)
+		return 0;
+
 	mci_setup_cmd(&cmd, MMC_CMD_SET_BLOCKLEN, len, MMC_RSP_R1);
 	return mci_send_cmd(mci, &cmd, NULL);
 }
@@ -649,11 +652,15 @@ static int mmc_change_freq(struct mci *mci)
 		return 0;
 	}
 
-	/* High Speed is set, there are two types: 52MHz and 26MHz */
-	if (cardtype & EXT_CSD_CARD_TYPE_52)
-		mci->card_caps |= MMC_CAP_MMC_HIGHSPEED_52MHZ | MMC_CAP_MMC_HIGHSPEED;
-	else
-		mci->card_caps |= MMC_CAP_MMC_HIGHSPEED;
+	mci->card_caps |= MMC_CAP_MMC_HIGHSPEED;
+
+	/* High Speed is set, there are three types: 26MHz, 52MHz, 52MHz DDR */
+	if (cardtype & EXT_CSD_CARD_TYPE_52) {
+		mci->card_caps |= MMC_CAP_MMC_HIGHSPEED_52MHZ;
+
+		if (cardtype & EXT_CSD_CARD_TYPE_DDR_1_8V)
+			mci->card_caps |= MMC_CAP_MMC_3_3V_DDR | MMC_CAP_MMC_1_8V_DDR;
+	}
 
 	if (IS_ENABLED(CONFIG_MCI_MMC_BOOT_PARTITIONS) &&
 			mci->ext_csd[EXT_CSD_REV] >= 3 && mci->ext_csd[EXT_CSD_BOOT_SIZE_MULT]) {
@@ -1170,15 +1177,20 @@ static int mci_startup_sd(struct mci *mci)
 static int mci_startup_mmc(struct mci *mci)
 {
 	struct mci_host *host = mci->host;
+	enum mci_timing timing_orig;
 	int err;
 	int idx = 0;
 	static unsigned ext_csd_bits[] = {
 		EXT_CSD_BUS_WIDTH_4,
 		EXT_CSD_BUS_WIDTH_8,
+		EXT_CSD_DDR_BUS_WIDTH_4,
+		EXT_CSD_DDR_BUS_WIDTH_8,
 	};
 	static unsigned bus_widths[] = {
 		MMC_BUS_WIDTH_4,
 		MMC_BUS_WIDTH_8,
+		MMC_BUS_WIDTH_4,
+		MMC_BUS_WIDTH_8,
 	};
 
 	/* if possible, speed up the transfer */
@@ -1191,6 +1203,8 @@ static int mci_startup_mmc(struct mci *mci)
 		host->timing = MMC_TIMING_MMC_HS;
 	}
 
+	timing_orig = host->timing;
+
 	mci_set_clock(mci, mci->tran_speed);
 
 	if (!(host->host_caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)))
@@ -1205,6 +1219,9 @@ static int mci_startup_mmc(struct mci *mci)
 	if (host->host_caps & MMC_CAP_8_BIT_DATA)
 		idx = 1;
 
+	if (mci_caps(mci) & MMC_CAP_MMC_1_8V_DDR)
+		idx += 2;
+
 	for (; idx >= 0; idx--) {
 
 		/*
@@ -1221,11 +1238,25 @@ static int mci_startup_mmc(struct mci *mci)
 			continue;
 		}
 
+		if (ext_csd_bits[idx] & EXT_CSD_DDR_FLAG)
+			host->timing = MMC_TIMING_MMC_DDR52;
+		else
+			host->timing = timing_orig;
+
+		dev_dbg(&mci->dev, "attempting buswidth %u%s\n", bus_widths[idx],
+			mci_timing_is_ddr(host->timing) ? " (DDR)" : "");
+
 		mci_set_bus_width(mci, bus_widths[idx]);
 
 		err = mmc_compare_ext_csds(mci, bus_widths[idx]);
-		if (!err)
-			break;
+		if (!err) {
+			if (host->timing == MMC_TIMING_MMC_DDR52) {
+				mci->read_bl_len = SECTOR_SIZE;
+				mci->write_bl_len = SECTOR_SIZE;
+			}
+
+			return 0;
+		}
 	}
 
 	return err;
@@ -1654,6 +1685,8 @@ static const char *mci_timing_tostr(unsigned timing)
 		return "MMC HS";
 	case MMC_TIMING_SD_HS:
 		return "SD HS";
+	case MMC_TIMING_MMC_DDR52:
+		return "MMC DDR52";
 	default:
 		return "unknown"; /* shouldn't happen */
 	}
@@ -1661,12 +1694,15 @@ static const char *mci_timing_tostr(unsigned timing)
 
 static void mci_print_caps(unsigned caps)
 {
-	printf("  capabilities: %s%s%s%s%s\n",
+	printf("  capabilities: %s%s%s%s%s%s%s%s\n",
 		caps & MMC_CAP_4_BIT_DATA ? "4bit " : "",
 		caps & MMC_CAP_8_BIT_DATA ? "8bit " : "",
 		caps & MMC_CAP_SD_HIGHSPEED ? "sd-hs " : "",
 		caps & MMC_CAP_MMC_HIGHSPEED ? "mmc-hs " : "",
-		caps & MMC_CAP_MMC_HIGHSPEED_52MHZ ? "mmc-52MHz " : "");
+		caps & MMC_CAP_MMC_HIGHSPEED_52MHZ ? "mmc-52MHz " : "",
+		caps & MMC_CAP_MMC_3_3V_DDR ? "ddr-3.3v " : "",
+		caps & MMC_CAP_MMC_1_8V_DDR ? "ddr-1.8v " : "",
+		caps & MMC_CAP_MMC_1_2V_DDR ? "ddr-1.2v " : "");
 }
 
 /**
diff --git a/include/mci.h b/include/mci.h
index d356f071f7f2..88712c35492e 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -51,6 +51,11 @@
 #define MMC_CAP_SD_HIGHSPEED		(1 << 3)
 #define MMC_CAP_MMC_HIGHSPEED		(1 << 4)
 #define MMC_CAP_MMC_HIGHSPEED_52MHZ	(1 << 5)
+#define MMC_CAP_MMC_3_3V_DDR		(1 << 7)	/* Host supports eMMC DDR 3.3V */
+#define MMC_CAP_MMC_1_8V_DDR		(1 << 8)	/* Host supports eMMC DDR 1.8V */
+#define MMC_CAP_MMC_1_2V_DDR		(1 << 9)	/* Host supports eMMC DDR 1.2V */
+#define MMC_CAP_DDR			(MMC_CAP_3_3V_DDR | MMC_CAP_1_8V_DDR | \
+					 MMC_CAP_1_2V_DDR)
 /* Mask of all caps for bus width */
 #define MMC_CAP_BIT_DATA_MASK		(MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)
 
@@ -308,6 +313,7 @@
 #define EXT_CSD_BUS_WIDTH_8	2	/* Card is in 8 bit mode */
 #define EXT_CSD_DDR_BUS_WIDTH_4	5	/* Card is in 4 bit DDR mode */
 #define EXT_CSD_DDR_BUS_WIDTH_8	6	/* Card is in 8 bit DDR mode */
+#define EXT_CSD_DDR_FLAG	BIT(2)	/* Flag for DDR mode */
 
 #define R1_ILLEGAL_COMMAND		(1 << 22)
 #define R1_STATUS(x)			(x & 0xFFF9A000)
@@ -410,6 +416,19 @@ enum mci_timing {
 	MMC_TIMING_MMC_HS400	= 8,
 };
 
+static inline bool mci_timing_is_ddr(enum mci_timing timing)
+{
+	switch (timing) {
+	case MMC_TIMING_UHS_DDR50:
+	case MMC_TIMING_MMC_HS200:
+	case MMC_TIMING_MMC_DDR52:
+	case MMC_TIMING_MMC_HS400:
+		return true;
+	default:
+		return false;
+	}
+}
+
 struct mci_ios {
 	unsigned int	clock;			/* clock rate */
 
-- 
2.39.2



From m.felsch at pengutronix.de  Tue Apr 18 00:27:12 2023
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Tue, 18 Apr 2023 09:27:12 +0200
Subject: [PATCH 1/2] mci: add eMMC DDR52 support
In-Reply-To: <20230417164255.1070012-1-a.fatoum@pengutronix.de>
References: <20230417164255.1070012-1-a.fatoum@pengutronix.de>
Message-ID: <20230418072712.pijqhlrlcyrkzoiy@pengutronix.de>

Hi Ahmad,

On 23-04-17, Ahmad Fatoum wrote:
> The maximum card frequency that can be configured by barebox currently
> is 50MHz for SD and 52MHz for eMMC. Higher speed modes require runtime
> voltage switching or tuning sequences, which are not yet implemented.
> 
> Only exception is eMMC's DDR52: This mode was first introduced with
> MMC 4.4 and can be used even at 3.3V.

Nice :)

> This commit adds DDR52 support to the core. This introduces no functional
> change, because host controllers must opt-in by setting the appropriate
> host capabilities.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  drivers/mci/mci-core.c | 54 +++++++++++++++++++++++++++++++++++-------
>  include/mci.h          | 19 +++++++++++++++
>  2 files changed, 64 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
> index f647cae8203b..86f468edfea6 100644
> --- a/drivers/mci/mci-core.c
> +++ b/drivers/mci/mci-core.c
> @@ -135,6 +135,9 @@ static int mci_set_blocklen(struct mci *mci, unsigned len)
>  {
>  	struct mci_cmd cmd;
>  
> +	if (mci->host->timing == MMC_TIMING_MMC_DDR52)
> +		return 0;
> +
>  	mci_setup_cmd(&cmd, MMC_CMD_SET_BLOCKLEN, len, MMC_RSP_R1);
>  	return mci_send_cmd(mci, &cmd, NULL);
>  }
> @@ -649,11 +652,15 @@ static int mmc_change_freq(struct mci *mci)
>  		return 0;
>  	}
>  
> -	/* High Speed is set, there are two types: 52MHz and 26MHz */
> -	if (cardtype & EXT_CSD_CARD_TYPE_52)
> -		mci->card_caps |= MMC_CAP_MMC_HIGHSPEED_52MHZ | MMC_CAP_MMC_HIGHSPEED;
> -	else
> -		mci->card_caps |= MMC_CAP_MMC_HIGHSPEED;
> +	mci->card_caps |= MMC_CAP_MMC_HIGHSPEED;
> +
> +	/* High Speed is set, there are three types: 26MHz, 52MHz, 52MHz DDR */
> +	if (cardtype & EXT_CSD_CARD_TYPE_52) {
> +		mci->card_caps |= MMC_CAP_MMC_HIGHSPEED_52MHZ;
> +
> +		if (cardtype & EXT_CSD_CARD_TYPE_DDR_1_8V)
> +			mci->card_caps |= MMC_CAP_MMC_3_3V_DDR | MMC_CAP_MMC_1_8V_DDR;
> +	}
>  
>  	if (IS_ENABLED(CONFIG_MCI_MMC_BOOT_PARTITIONS) &&
>  			mci->ext_csd[EXT_CSD_REV] >= 3 && mci->ext_csd[EXT_CSD_BOOT_SIZE_MULT]) {
> @@ -1170,15 +1177,20 @@ static int mci_startup_sd(struct mci *mci)
>  static int mci_startup_mmc(struct mci *mci)
>  {
>  	struct mci_host *host = mci->host;
> +	enum mci_timing timing_orig;
>  	int err;
>  	int idx = 0;
>  	static unsigned ext_csd_bits[] = {
>  		EXT_CSD_BUS_WIDTH_4,
>  		EXT_CSD_BUS_WIDTH_8,
> +		EXT_CSD_DDR_BUS_WIDTH_4,
> +		EXT_CSD_DDR_BUS_WIDTH_8,
>  	};
>  	static unsigned bus_widths[] = {
>  		MMC_BUS_WIDTH_4,
>  		MMC_BUS_WIDTH_8,
> +		MMC_BUS_WIDTH_4,
> +		MMC_BUS_WIDTH_8,

This is duplicated or should it be MMC_DDR_BUS_WIDTH_4/8?

>  	};
>  
>  	/* if possible, speed up the transfer */
> @@ -1191,6 +1203,8 @@ static int mci_startup_mmc(struct mci *mci)
>  		host->timing = MMC_TIMING_MMC_HS;
>  	}
>  
> +	timing_orig = host->timing;
> +
>  	mci_set_clock(mci, mci->tran_speed);
>  
>  	if (!(host->host_caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)))
> @@ -1205,6 +1219,9 @@ static int mci_startup_mmc(struct mci *mci)
>  	if (host->host_caps & MMC_CAP_8_BIT_DATA)
>  		idx = 1;
>  
> +	if (mci_caps(mci) & MMC_CAP_MMC_1_8V_DDR)
> +		idx += 2;
> +
>  	for (; idx >= 0; idx--) {
>  
>  		/*
> @@ -1221,11 +1238,25 @@ static int mci_startup_mmc(struct mci *mci)
>  			continue;
>  		}
>  
> +		if (ext_csd_bits[idx] & EXT_CSD_DDR_FLAG)
> +			host->timing = MMC_TIMING_MMC_DDR52;
> +		else
> +			host->timing = timing_orig;
> +
> +		dev_dbg(&mci->dev, "attempting buswidth %u%s\n", bus_widths[idx],
> +			mci_timing_is_ddr(host->timing) ? " (DDR)" : "");
> +
>  		mci_set_bus_width(mci, bus_widths[idx]);
>  
>  		err = mmc_compare_ext_csds(mci, bus_widths[idx]);
> -		if (!err)
> -			break;
> +		if (!err) {
> +			if (host->timing == MMC_TIMING_MMC_DDR52) {
> +				mci->read_bl_len = SECTOR_SIZE;
> +				mci->write_bl_len = SECTOR_SIZE;
> +			}
> +
> +			return 0;
> +		}
>  	}
>  
>  	return err;
> @@ -1654,6 +1685,8 @@ static const char *mci_timing_tostr(unsigned timing)
>  		return "MMC HS";
>  	case MMC_TIMING_SD_HS:
>  		return "SD HS";
> +	case MMC_TIMING_MMC_DDR52:
> +		return "MMC DDR52";
>  	default:
>  		return "unknown"; /* shouldn't happen */
>  	}
> @@ -1661,12 +1694,15 @@ static const char *mci_timing_tostr(unsigned timing)
>  
>  static void mci_print_caps(unsigned caps)
>  {
> -	printf("  capabilities: %s%s%s%s%s\n",
> +	printf("  capabilities: %s%s%s%s%s%s%s%s\n",
>  		caps & MMC_CAP_4_BIT_DATA ? "4bit " : "",
>  		caps & MMC_CAP_8_BIT_DATA ? "8bit " : "",
>  		caps & MMC_CAP_SD_HIGHSPEED ? "sd-hs " : "",
>  		caps & MMC_CAP_MMC_HIGHSPEED ? "mmc-hs " : "",
> -		caps & MMC_CAP_MMC_HIGHSPEED_52MHZ ? "mmc-52MHz " : "");
> +		caps & MMC_CAP_MMC_HIGHSPEED_52MHZ ? "mmc-52MHz " : "",
> +		caps & MMC_CAP_MMC_3_3V_DDR ? "ddr-3.3v " : "",
> +		caps & MMC_CAP_MMC_1_8V_DDR ? "ddr-1.8v " : "",
> +		caps & MMC_CAP_MMC_1_2V_DDR ? "ddr-1.2v " : "");

At the moment we only report what barebox does support, ddr-1.8v and
ddr-1.2v isn't supported. Do we really want to report this?

Regards,
  Marco

>  }
>  
>  /**
> diff --git a/include/mci.h b/include/mci.h
> index d356f071f7f2..88712c35492e 100644
> --- a/include/mci.h
> +++ b/include/mci.h
> @@ -51,6 +51,11 @@
>  #define MMC_CAP_SD_HIGHSPEED		(1 << 3)
>  #define MMC_CAP_MMC_HIGHSPEED		(1 << 4)
>  #define MMC_CAP_MMC_HIGHSPEED_52MHZ	(1 << 5)
> +#define MMC_CAP_MMC_3_3V_DDR		(1 << 7)	/* Host supports eMMC DDR 3.3V */
> +#define MMC_CAP_MMC_1_8V_DDR		(1 << 8)	/* Host supports eMMC DDR 1.8V */
> +#define MMC_CAP_MMC_1_2V_DDR		(1 << 9)	/* Host supports eMMC DDR 1.2V */
> +#define MMC_CAP_DDR			(MMC_CAP_3_3V_DDR | MMC_CAP_1_8V_DDR | \
> +					 MMC_CAP_1_2V_DDR)
>  /* Mask of all caps for bus width */
>  #define MMC_CAP_BIT_DATA_MASK		(MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)
>  
> @@ -308,6 +313,7 @@
>  #define EXT_CSD_BUS_WIDTH_8	2	/* Card is in 8 bit mode */
>  #define EXT_CSD_DDR_BUS_WIDTH_4	5	/* Card is in 4 bit DDR mode */
>  #define EXT_CSD_DDR_BUS_WIDTH_8	6	/* Card is in 8 bit DDR mode */
> +#define EXT_CSD_DDR_FLAG	BIT(2)	/* Flag for DDR mode */
>  
>  #define R1_ILLEGAL_COMMAND		(1 << 22)
>  #define R1_STATUS(x)			(x & 0xFFF9A000)
> @@ -410,6 +416,19 @@ enum mci_timing {
>  	MMC_TIMING_MMC_HS400	= 8,
>  };
>  
> +static inline bool mci_timing_is_ddr(enum mci_timing timing)
> +{
> +	switch (timing) {
> +	case MMC_TIMING_UHS_DDR50:
> +	case MMC_TIMING_MMC_HS200:
> +	case MMC_TIMING_MMC_DDR52:
> +	case MMC_TIMING_MMC_HS400:
> +		return true;
> +	default:
> +		return false;
> +	}
> +}
> +
>  struct mci_ios {
>  	unsigned int	clock;			/* clock rate */
>  
> -- 
> 2.39.2
> 
> 
> 


From m.felsch at pengutronix.de  Tue Apr 18 00:32:06 2023
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Tue, 18 Apr 2023 09:32:06 +0200
Subject: [PATCH 2/2] mci: imx-esdhc: add uSDHC eMMC DDR52 supprot
In-Reply-To: <20230417164255.1070012-2-a.fatoum@pengutronix.de>
References: <20230417164255.1070012-1-a.fatoum@pengutronix.de>
 <20230417164255.1070012-2-a.fatoum@pengutronix.de>
Message-ID: <20230418073206.obck53qrdg33blmo@pengutronix.de>

On 23-04-17, Ahmad Fatoum wrote:
> The uSDHC available with the i.MX6/7/8 SoCs has support for DDR
> clock operation. This is enabled by flipping a bit in
> IMX_SDHCI_MIXCTRL and adjusting the clock divider calculation to
> account for the automatic internal halving of the clock.
> 
> Let's do that to speed up boot from eMMC. How much effect this has
> in practice is not constant. Comparing two Kingston eMMCs: DDR on the
> older v4.5 connected to an i.MX6 did not yield any difference. On the
> newer v5.1 one connected to an i.MX8MM, I observe a 70% improvement in
> throughput: from 40MiB/s to 69.5 MiB/s.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>

Reviewed-by: Marco Felsch <m.felsch at pengutronix.de>

> ---
>  drivers/mci/imx-esdhc-common.c |  1 +
>  drivers/mci/imx-esdhc.c        | 45 +++++++++++++++++++++++++++++-----
>  drivers/mci/imx-esdhc.h        | 14 +++++++++++
>  3 files changed, 54 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/mci/imx-esdhc-common.c b/drivers/mci/imx-esdhc-common.c
> index 27293e44b724..3c1ff9882432 100644
> --- a/drivers/mci/imx-esdhc-common.c
> +++ b/drivers/mci/imx-esdhc-common.c
> @@ -160,6 +160,7 @@ int __esdhc_send_cmd(struct fsl_esdhc_host *host, struct mci_cmd *cmd,
>  		mixctrl = xfertyp;
>  		/* Keep the bits 22-25 of the register as is */
>  		mixctrl |= (sdhci_read32(&host->sdhci, IMX_SDHCI_MIXCTRL) & (0xF << 22));
> +		mixctrl |= mci_timing_is_ddr(host->sdhci.timing) ? MIX_CTRL_DDREN : 0;
>  		sdhci_write32(&host->sdhci, IMX_SDHCI_MIXCTRL, mixctrl);
>  	}
>  
> diff --git a/drivers/mci/imx-esdhc.c b/drivers/mci/imx-esdhc.c
> index 2e2bc14ef95c..94f18fe2b3cf 100644
> --- a/drivers/mci/imx-esdhc.c
> +++ b/drivers/mci/imx-esdhc.c
> @@ -43,9 +43,9 @@ esdhc_send_cmd(struct mci_host *mci, struct mci_cmd *cmd, struct mci_data *data)
>  	return  __esdhc_send_cmd(host, cmd, data);
>  }
>  
> -static void set_sysctl(struct mci_host *mci, u32 clock)
> +static void set_sysctl(struct mci_host *mci, u32 clock, bool ddr)
>  {
> -	int div, pre_div;
> +	int div, pre_div, ddr_pre_div = ddr ? 2 : 1;
>  	struct fsl_esdhc_host *host = to_fsl_esdhc(mci);
>  	int sdhc_clk = clk_get_rate(host->clk);
>  	u32 clk;
> @@ -65,11 +65,11 @@ static void set_sysctl(struct mci_host *mci, u32 clock)
>  		pre_div = 1;
>  	else if (sdhc_clk / 16 > clock)
>  		for (; pre_div < 256; pre_div *= 2)
> -			if ((sdhc_clk / pre_div) <= (clock * 16))
> +			if ((sdhc_clk / (pre_div * ddr_pre_div)) <= (clock * 16))
>  				break;
>  
>  	for (div = 1; div <= 16; div++)
> -		if ((sdhc_clk / (div * pre_div)) <= clock)
> +		if ((sdhc_clk / (div * pre_div * ddr_pre_div)) <= clock)
>  			break;
>  
>  	cur_clock = sdhc_clk / pre_div / div;
> @@ -103,12 +103,42 @@ static void set_sysctl(struct mci_host *mci, u32 clock)
>  		   10 * MSECOND);
>  }
>  
> +static void esdhc_set_timing(struct fsl_esdhc_host *host, enum mci_timing timing)
> +{
> +	u32 mixctrl;
> +
> +	mixctrl = sdhci_read32(&host->sdhci, IMX_SDHCI_MIXCTRL);
> +	mixctrl &= ~MIX_CTRL_DDREN;
> +
> +	switch (timing) {
> +	case MMC_TIMING_UHS_DDR50:
> +	case MMC_TIMING_MMC_DDR52:
> +		mixctrl |= MIX_CTRL_DDREN;
> +		sdhci_write32(&host->sdhci, IMX_SDHCI_MIXCTRL, mixctrl);
> +		break;
> +	default:
> +		sdhci_write32(&host->sdhci, IMX_SDHCI_MIXCTRL, mixctrl);
> +	}
> +
> +	host->sdhci.timing = timing;
> +}
> +
>  static void esdhc_set_ios(struct mci_host *mci, struct mci_ios *ios)
>  {
>  	struct fsl_esdhc_host *host = to_fsl_esdhc(mci);
>  
> +	/*
> +	 * call esdhc_set_timing() before update the clock rate,
> +	 * This is because current we support DDR and SDR timing,
> +	 * Once the DDR_EN bit is set, the card clock will be
> +	 * divide by 2 automatically. So need to do this before
> +	 * setting clock rate.
> +	 */
> +	if (esdhc_is_usdhc(host) && host->sdhci.timing != ios->timing)
> +		esdhc_set_timing(host, ios->timing);
> +
>  	/* Set the clock speed */
> -	set_sysctl(mci, ios->clock);
> +	set_sysctl(mci, ios->clock, mci_timing_is_ddr(ios->timing));
>  
>  	/* Set the bus width */
>  	esdhc_clrbits32(host, SDHCI_HOST_CONTROL__POWER_CONTROL__BLOCK_GAP_CONTROL,
> @@ -206,7 +236,7 @@ static int esdhc_init(struct mci_host *mci, struct device *dev)
>  		esdhc_setbits32(host, ESDHC_DMA_SYSCTL, ESDHC_SYSCTL_DMA_SNOOP);
>  
>  	/* Set the initial clock speed */
> -	set_sysctl(mci, 400000);
> +	set_sysctl(mci, 400000, false);
>  
>  	sdhci_write32(&host->sdhci, SDHCI_INT_ENABLE, SDHCI_INT_CMD_COMPLETE |
>  			SDHCI_INT_XFER_COMPLETE | SDHCI_INT_CARD_INT |
> @@ -285,6 +315,9 @@ static int fsl_esdhc_probe(struct device *dev)
>  	if (ret)
>  		goto err_clk_disable;
>  
> +	if (esdhc_is_usdhc(host))
> +		mci->host_caps |= MMC_CAP_MMC_3_3V_DDR | MMC_CAP_MMC_1_8V_DDR;
> +
>  	rate = clk_get_rate(host->clk);
>  	host->mci.f_min = rate >> 12;
>  	if (host->mci.f_min < 200000)
> diff --git a/drivers/mci/imx-esdhc.h b/drivers/mci/imx-esdhc.h
> index 0d8f157a7615..b14039757a7a 100644
> --- a/drivers/mci/imx-esdhc.h
> +++ b/drivers/mci/imx-esdhc.h
> @@ -41,6 +41,20 @@
>  
>  #define IMX_SDHCI_WML		0x44
>  #define IMX_SDHCI_MIXCTRL	0x48
> +/* Imported from Linux Kernel drivers/mmc/host/sdhci-esdhc-imx.c */
> +#define  MIX_CTRL_DDREN		BIT(3)
> +#define  MIX_CTRL_DTDSEL_READ	BIT(4)
> +#define  MIX_CTRL_AC23EN	BIT(7)
> +#define  MIX_CTRL_EXE_TUNE	BIT(22)
> +#define  MIX_CTRL_SMPCLK_SEL	BIT(23)
> +#define  MIX_CTRL_AUTO_TUNE_EN	BIT(24)
> +#define  MIX_CTRL_FBCLK_SEL	BIT(25)
> +#define  MIX_CTRL_HS400_EN	BIT(26)
> +#define  MIX_CTRL_HS400_ES	BIT(27)
> +/* Bits 3 and 6 are not SDHCI standard definitions */
> +#define  MIX_CTRL_SDHCI_MASK	0xb7
> +/* Tuning bits */
> +#define  MIX_CTRL_TUNING_MASK	0x03c00000
>  #define IMX_SDHCI_DLL_CTRL	0x60
>  #define IMX_SDHCI_MIX_CTRL_FBCLK_SEL	BIT(25)
>  
> -- 
> 2.39.2
> 
> 
> 


From a.fatoum at pengutronix.de  Tue Apr 18 00:36:32 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 18 Apr 2023 09:36:32 +0200
Subject: [PATCH 1/2] mci: add eMMC DDR52 support
In-Reply-To: <20230418072712.pijqhlrlcyrkzoiy@pengutronix.de>
References: <20230417164255.1070012-1-a.fatoum@pengutronix.de>
 <20230418072712.pijqhlrlcyrkzoiy@pengutronix.de>
Message-ID: <8bdc6be0-497a-8442-4694-5024a797fd64@pengutronix.de>

Hello Marco,

On 18.04.23 09:27, Marco Felsch wrote:
> Hi Ahmad,
> 
> On 23-04-17, Ahmad Fatoum wrote:
>> The maximum card frequency that can be configured by barebox currently
>> is 50MHz for SD and 52MHz for eMMC. Higher speed modes require runtime
>> voltage switching or tuning sequences, which are not yet implemented.
>>
>> Only exception is eMMC's DDR52: This mode was first introduced with
>> MMC 4.4 and can be used even at 3.3V.
> 
> Nice :)
> 
>> This commit adds DDR52 support to the core. This introduces no functional
>> change, because host controllers must opt-in by setting the appropriate
>> host capabilities.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
>> ---
>>  drivers/mci/mci-core.c | 54 +++++++++++++++++++++++++++++++++++-------
>>  include/mci.h          | 19 +++++++++++++++
>>  2 files changed, 64 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
>> index f647cae8203b..86f468edfea6 100644
>> --- a/drivers/mci/mci-core.c
>> +++ b/drivers/mci/mci-core.c
>> @@ -135,6 +135,9 @@ static int mci_set_blocklen(struct mci *mci, unsigned len)
>>  {
>>  	struct mci_cmd cmd;
>>  
>> +	if (mci->host->timing == MMC_TIMING_MMC_DDR52)
>> +		return 0;
>> +
>>  	mci_setup_cmd(&cmd, MMC_CMD_SET_BLOCKLEN, len, MMC_RSP_R1);
>>  	return mci_send_cmd(mci, &cmd, NULL);
>>  }
>> @@ -649,11 +652,15 @@ static int mmc_change_freq(struct mci *mci)
>>  		return 0;
>>  	}
>>  
>> -	/* High Speed is set, there are two types: 52MHz and 26MHz */
>> -	if (cardtype & EXT_CSD_CARD_TYPE_52)
>> -		mci->card_caps |= MMC_CAP_MMC_HIGHSPEED_52MHZ | MMC_CAP_MMC_HIGHSPEED;
>> -	else
>> -		mci->card_caps |= MMC_CAP_MMC_HIGHSPEED;
>> +	mci->card_caps |= MMC_CAP_MMC_HIGHSPEED;
>> +
>> +	/* High Speed is set, there are three types: 26MHz, 52MHz, 52MHz DDR */
>> +	if (cardtype & EXT_CSD_CARD_TYPE_52) {
>> +		mci->card_caps |= MMC_CAP_MMC_HIGHSPEED_52MHZ;
>> +
>> +		if (cardtype & EXT_CSD_CARD_TYPE_DDR_1_8V)
>> +			mci->card_caps |= MMC_CAP_MMC_3_3V_DDR | MMC_CAP_MMC_1_8V_DDR;
>> +	}
>>  
>>  	if (IS_ENABLED(CONFIG_MCI_MMC_BOOT_PARTITIONS) &&
>>  			mci->ext_csd[EXT_CSD_REV] >= 3 && mci->ext_csd[EXT_CSD_BOOT_SIZE_MULT]) {
>> @@ -1170,15 +1177,20 @@ static int mci_startup_sd(struct mci *mci)
>>  static int mci_startup_mmc(struct mci *mci)
>>  {
>>  	struct mci_host *host = mci->host;
>> +	enum mci_timing timing_orig;
>>  	int err;
>>  	int idx = 0;
>>  	static unsigned ext_csd_bits[] = {
>>  		EXT_CSD_BUS_WIDTH_4,
>>  		EXT_CSD_BUS_WIDTH_8,
>> +		EXT_CSD_DDR_BUS_WIDTH_4,
>> +		EXT_CSD_DDR_BUS_WIDTH_8,
>>  	};
>>  	static unsigned bus_widths[] = {
>>  		MMC_BUS_WIDTH_4,
>>  		MMC_BUS_WIDTH_8,
>> +		MMC_BUS_WIDTH_4,
>> +		MMC_BUS_WIDTH_8,
> 
> This is duplicated or should it be MMC_DDR_BUS_WIDTH_4/8?

The trial sequence I had in mind originally was:

  DDR 8-bit -> DDR 4-bit -> SDR 8-bit -> SDR 4-bit

That's how U-Boot does it. I compared with Linux and there we have:

  SDR 8-bit -> SDR 4-bit and then depending on the result, either
  DDR 8-bit or DDR 4-bit

Given that DDR is not a 100% improvement in my testing, I should
rather do it like Linux does and prefer SDR 8-bit over DDR 4-bit.

I will do this for v2.

This also fixes a bug with the code: If host doesn't support 8-bit
MMC, we would still not test for 8-bit SDR, but would for 8-bit DDR.

>> @@ -1661,12 +1694,15 @@ static const char *mci_timing_tostr(unsigned timing)
>>  
>>  static void mci_print_caps(unsigned caps)
>>  {
>> -	printf("  capabilities: %s%s%s%s%s\n",
>> +	printf("  capabilities: %s%s%s%s%s%s%s%s\n",
>>  		caps & MMC_CAP_4_BIT_DATA ? "4bit " : "",
>>  		caps & MMC_CAP_8_BIT_DATA ? "8bit " : "",
>>  		caps & MMC_CAP_SD_HIGHSPEED ? "sd-hs " : "",
>>  		caps & MMC_CAP_MMC_HIGHSPEED ? "mmc-hs " : "",
>> -		caps & MMC_CAP_MMC_HIGHSPEED_52MHZ ? "mmc-52MHz " : "");
>> +		caps & MMC_CAP_MMC_HIGHSPEED_52MHZ ? "mmc-52MHz " : "",
>> +		caps & MMC_CAP_MMC_3_3V_DDR ? "ddr-3.3v " : "",
>> +		caps & MMC_CAP_MMC_1_8V_DDR ? "ddr-1.8v " : "",
>> +		caps & MMC_CAP_MMC_1_2V_DDR ? "ddr-1.2v " : "");
> 
> At the moment we only report what barebox does support, ddr-1.8v and
> ddr-1.2v isn't supported. Do we really want to report this?

DDR 1.8V on eMMC is not dynamically selected, but 1.2v is. So this
series works for both 3.3v and 1.8v. I don't see a problem with reporting
1.2v support for cards. No host will set this as long we don't have
voltage switching.

Cheers,
Ahmad

> 
> Regards,
>   Marco
> 
>>  }
>>  
>>  /**
>> diff --git a/include/mci.h b/include/mci.h
>> index d356f071f7f2..88712c35492e 100644
>> --- a/include/mci.h
>> +++ b/include/mci.h
>> @@ -51,6 +51,11 @@
>>  #define MMC_CAP_SD_HIGHSPEED		(1 << 3)
>>  #define MMC_CAP_MMC_HIGHSPEED		(1 << 4)
>>  #define MMC_CAP_MMC_HIGHSPEED_52MHZ	(1 << 5)
>> +#define MMC_CAP_MMC_3_3V_DDR		(1 << 7)	/* Host supports eMMC DDR 3.3V */
>> +#define MMC_CAP_MMC_1_8V_DDR		(1 << 8)	/* Host supports eMMC DDR 1.8V */
>> +#define MMC_CAP_MMC_1_2V_DDR		(1 << 9)	/* Host supports eMMC DDR 1.2V */
>> +#define MMC_CAP_DDR			(MMC_CAP_3_3V_DDR | MMC_CAP_1_8V_DDR | \
>> +					 MMC_CAP_1_2V_DDR)
>>  /* Mask of all caps for bus width */
>>  #define MMC_CAP_BIT_DATA_MASK		(MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)
>>  
>> @@ -308,6 +313,7 @@
>>  #define EXT_CSD_BUS_WIDTH_8	2	/* Card is in 8 bit mode */
>>  #define EXT_CSD_DDR_BUS_WIDTH_4	5	/* Card is in 4 bit DDR mode */
>>  #define EXT_CSD_DDR_BUS_WIDTH_8	6	/* Card is in 8 bit DDR mode */
>> +#define EXT_CSD_DDR_FLAG	BIT(2)	/* Flag for DDR mode */
>>  
>>  #define R1_ILLEGAL_COMMAND		(1 << 22)
>>  #define R1_STATUS(x)			(x & 0xFFF9A000)
>> @@ -410,6 +416,19 @@ enum mci_timing {
>>  	MMC_TIMING_MMC_HS400	= 8,
>>  };
>>  
>> +static inline bool mci_timing_is_ddr(enum mci_timing timing)
>> +{
>> +	switch (timing) {
>> +	case MMC_TIMING_UHS_DDR50:
>> +	case MMC_TIMING_MMC_HS200:
>> +	case MMC_TIMING_MMC_DDR52:
>> +	case MMC_TIMING_MMC_HS400:
>> +		return true;
>> +	default:
>> +		return false;
>> +	}
>> +}
>> +
>>  struct mci_ios {
>>  	unsigned int	clock;			/* clock rate */
>>  
>> -- 
>> 2.39.2
>>
>>
>>
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



From a.fatoum at pengutronix.de  Tue Apr 18 02:30:36 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 18 Apr 2023 11:30:36 +0200
Subject: [PATCH v2 1/5] mci: core: drop unused DDR/SDR constants
Message-ID: <20230418093040.1865982-1-a.fatoum@pengutronix.de>

These macros are unused and will be replaced by their Linux counterparts
in a follow up patch, so drop them.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - new patch
---
 include/mci.h | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/include/mci.h b/include/mci.h
index d356f071f7f2..c38567303241 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -420,12 +420,6 @@ struct mci_ios {
 #define MMC_BUS_WIDTH_8		3
 
 	enum mci_timing	timing;			/* timing specification used */
-
-#define MMC_SDR_MODE		0
-#define MMC_1_2V_DDR_MODE	1
-#define MMC_1_8V_DDR_MODE	2
-#define MMC_1_2V_SDR_MODE	3
-#define MMC_1_8V_SDR_MODE	4
 };
 
 struct mci;
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 18 02:30:40 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 18 Apr 2023 11:30:40 +0200
Subject: [PATCH v2 5/5] mci: imx-esdhc: add uSDHC eMMC DDR52 support
In-Reply-To: <20230418093040.1865982-1-a.fatoum@pengutronix.de>
References: <20230418093040.1865982-1-a.fatoum@pengutronix.de>
Message-ID: <20230418093040.1865982-5-a.fatoum@pengutronix.de>

The uSDHC available with the i.MX6/7/8 SoCs has support for DDR
clock operation. This is enabled by flipping a bit in
IMX_SDHCI_MIXCTRL and adjusting the clock divider calculation to
account for the automatic internal halving of the clock.

Let's do that to speed up boot from eMMC. How much effect this has
in practice is not constant. Comparing two Kingston eMMCs: DDR on the
older v4.5 connected to an i.MX6 did not yield any difference. On the
newer v5.1 one connected to an i.MX8MM, I observe a 70% improvement in
sequential read throughput: from 40MiB/s to 69.5 MiB/s.

Reviewed-by: Marco Felsch <m.felsch at pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - added Marco's Reviewed-by
---
 drivers/mci/imx-esdhc-common.c |  1 +
 drivers/mci/imx-esdhc.c        | 45 +++++++++++++++++++++++++++++-----
 drivers/mci/imx-esdhc.h        | 14 +++++++++++
 3 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/drivers/mci/imx-esdhc-common.c b/drivers/mci/imx-esdhc-common.c
index 27293e44b724..3c1ff9882432 100644
--- a/drivers/mci/imx-esdhc-common.c
+++ b/drivers/mci/imx-esdhc-common.c
@@ -160,6 +160,7 @@ int __esdhc_send_cmd(struct fsl_esdhc_host *host, struct mci_cmd *cmd,
 		mixctrl = xfertyp;
 		/* Keep the bits 22-25 of the register as is */
 		mixctrl |= (sdhci_read32(&host->sdhci, IMX_SDHCI_MIXCTRL) & (0xF << 22));
+		mixctrl |= mci_timing_is_ddr(host->sdhci.timing) ? MIX_CTRL_DDREN : 0;
 		sdhci_write32(&host->sdhci, IMX_SDHCI_MIXCTRL, mixctrl);
 	}
 
diff --git a/drivers/mci/imx-esdhc.c b/drivers/mci/imx-esdhc.c
index 2e2bc14ef95c..94f18fe2b3cf 100644
--- a/drivers/mci/imx-esdhc.c
+++ b/drivers/mci/imx-esdhc.c
@@ -43,9 +43,9 @@ esdhc_send_cmd(struct mci_host *mci, struct mci_cmd *cmd, struct mci_data *data)
 	return  __esdhc_send_cmd(host, cmd, data);
 }
 
-static void set_sysctl(struct mci_host *mci, u32 clock)
+static void set_sysctl(struct mci_host *mci, u32 clock, bool ddr)
 {
-	int div, pre_div;
+	int div, pre_div, ddr_pre_div = ddr ? 2 : 1;
 	struct fsl_esdhc_host *host = to_fsl_esdhc(mci);
 	int sdhc_clk = clk_get_rate(host->clk);
 	u32 clk;
@@ -65,11 +65,11 @@ static void set_sysctl(struct mci_host *mci, u32 clock)
 		pre_div = 1;
 	else if (sdhc_clk / 16 > clock)
 		for (; pre_div < 256; pre_div *= 2)
-			if ((sdhc_clk / pre_div) <= (clock * 16))
+			if ((sdhc_clk / (pre_div * ddr_pre_div)) <= (clock * 16))
 				break;
 
 	for (div = 1; div <= 16; div++)
-		if ((sdhc_clk / (div * pre_div)) <= clock)
+		if ((sdhc_clk / (div * pre_div * ddr_pre_div)) <= clock)
 			break;
 
 	cur_clock = sdhc_clk / pre_div / div;
@@ -103,12 +103,42 @@ static void set_sysctl(struct mci_host *mci, u32 clock)
 		   10 * MSECOND);
 }
 
+static void esdhc_set_timing(struct fsl_esdhc_host *host, enum mci_timing timing)
+{
+	u32 mixctrl;
+
+	mixctrl = sdhci_read32(&host->sdhci, IMX_SDHCI_MIXCTRL);
+	mixctrl &= ~MIX_CTRL_DDREN;
+
+	switch (timing) {
+	case MMC_TIMING_UHS_DDR50:
+	case MMC_TIMING_MMC_DDR52:
+		mixctrl |= MIX_CTRL_DDREN;
+		sdhci_write32(&host->sdhci, IMX_SDHCI_MIXCTRL, mixctrl);
+		break;
+	default:
+		sdhci_write32(&host->sdhci, IMX_SDHCI_MIXCTRL, mixctrl);
+	}
+
+	host->sdhci.timing = timing;
+}
+
 static void esdhc_set_ios(struct mci_host *mci, struct mci_ios *ios)
 {
 	struct fsl_esdhc_host *host = to_fsl_esdhc(mci);
 
+	/*
+	 * call esdhc_set_timing() before update the clock rate,
+	 * This is because current we support DDR and SDR timing,
+	 * Once the DDR_EN bit is set, the card clock will be
+	 * divide by 2 automatically. So need to do this before
+	 * setting clock rate.
+	 */
+	if (esdhc_is_usdhc(host) && host->sdhci.timing != ios->timing)
+		esdhc_set_timing(host, ios->timing);
+
 	/* Set the clock speed */
-	set_sysctl(mci, ios->clock);
+	set_sysctl(mci, ios->clock, mci_timing_is_ddr(ios->timing));
 
 	/* Set the bus width */
 	esdhc_clrbits32(host, SDHCI_HOST_CONTROL__POWER_CONTROL__BLOCK_GAP_CONTROL,
@@ -206,7 +236,7 @@ static int esdhc_init(struct mci_host *mci, struct device *dev)
 		esdhc_setbits32(host, ESDHC_DMA_SYSCTL, ESDHC_SYSCTL_DMA_SNOOP);
 
 	/* Set the initial clock speed */
-	set_sysctl(mci, 400000);
+	set_sysctl(mci, 400000, false);
 
 	sdhci_write32(&host->sdhci, SDHCI_INT_ENABLE, SDHCI_INT_CMD_COMPLETE |
 			SDHCI_INT_XFER_COMPLETE | SDHCI_INT_CARD_INT |
@@ -285,6 +315,9 @@ static int fsl_esdhc_probe(struct device *dev)
 	if (ret)
 		goto err_clk_disable;
 
+	if (esdhc_is_usdhc(host))
+		mci->host_caps |= MMC_CAP_MMC_3_3V_DDR | MMC_CAP_MMC_1_8V_DDR;
+
 	rate = clk_get_rate(host->clk);
 	host->mci.f_min = rate >> 12;
 	if (host->mci.f_min < 200000)
diff --git a/drivers/mci/imx-esdhc.h b/drivers/mci/imx-esdhc.h
index 0d8f157a7615..b14039757a7a 100644
--- a/drivers/mci/imx-esdhc.h
+++ b/drivers/mci/imx-esdhc.h
@@ -41,6 +41,20 @@
 
 #define IMX_SDHCI_WML		0x44
 #define IMX_SDHCI_MIXCTRL	0x48
+/* Imported from Linux Kernel drivers/mmc/host/sdhci-esdhc-imx.c */
+#define  MIX_CTRL_DDREN		BIT(3)
+#define  MIX_CTRL_DTDSEL_READ	BIT(4)
+#define  MIX_CTRL_AC23EN	BIT(7)
+#define  MIX_CTRL_EXE_TUNE	BIT(22)
+#define  MIX_CTRL_SMPCLK_SEL	BIT(23)
+#define  MIX_CTRL_AUTO_TUNE_EN	BIT(24)
+#define  MIX_CTRL_FBCLK_SEL	BIT(25)
+#define  MIX_CTRL_HS400_EN	BIT(26)
+#define  MIX_CTRL_HS400_ES	BIT(27)
+/* Bits 3 and 6 are not SDHCI standard definitions */
+#define  MIX_CTRL_SDHCI_MASK	0xb7
+/* Tuning bits */
+#define  MIX_CTRL_TUNING_MASK	0x03c00000
 #define IMX_SDHCI_DLL_CTRL	0x60
 #define IMX_SDHCI_MIX_CTRL_FBCLK_SEL	BIT(25)
 
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 18 02:30:38 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 18 Apr 2023 11:30:38 +0200
Subject: [PATCH v2 3/5] mci: core: factor out MMC bus width selection for reuse
In-Reply-To: <20230418093040.1865982-1-a.fatoum@pengutronix.de>
References: <20230418093040.1865982-1-a.fatoum@pengutronix.de>
Message-ID: <20230418093040.1865982-3-a.fatoum@pengutronix.de>

Higher speed modes like DDR52 and HS200 can operate at both 8-bit and
4-bit bus widths. To make it easier to support these, split up
mci_startup_mmc, so the refactored parts can be called with different
timings later on.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - new patch
---
 drivers/mci/mci-core.c | 95 ++++++++++++++++++++++++++++--------------
 1 file changed, 64 insertions(+), 31 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 2abed0011722..bd5299e7a4f8 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1167,34 +1167,51 @@ static int mci_startup_sd(struct mci *mci)
 	return 0;
 }
 
-static int mci_startup_mmc(struct mci *mci)
+static u32 mci_bus_width_ext_csd_bits(enum mci_bus_width bus_width)
+{
+	switch (bus_width) {
+	case MMC_BUS_WIDTH_8:
+		return EXT_CSD_BUS_WIDTH_8;
+	case MMC_BUS_WIDTH_4:
+		return EXT_CSD_BUS_WIDTH_4;
+	case MMC_BUS_WIDTH_1:
+	default:
+		return EXT_CSD_BUS_WIDTH_1;
+	}
+}
+
+static int mci_mmc_try_bus_width(struct mci *mci, enum mci_bus_width bus_width)
 {
-	struct mci_host *host = mci->host;
+	u32 ext_csd_bits;
 	int err;
+
+	ext_csd_bits = mci_bus_width_ext_csd_bits(bus_width);
+
+	err = mci_switch(mci, EXT_CSD_BUS_WIDTH, ext_csd_bits);
+	if (err < 0)
+		return err;
+
+	mci_set_bus_width(mci, bus_width);
+
+	err = mmc_compare_ext_csds(mci, bus_width);
+	if (err < 0)
+		return err;
+
+	return bus_width;
+}
+
+static int mci_mmc_select_bus_width(struct mci *mci)
+{
+	struct mci_host *host = mci->host;
+	int ret;
 	int idx = 0;
-	static unsigned ext_csd_bits[] = {
-		EXT_CSD_BUS_WIDTH_4,
-		EXT_CSD_BUS_WIDTH_8,
-	};
 	static enum mci_bus_width bus_widths[] = {
 		MMC_BUS_WIDTH_4,
 		MMC_BUS_WIDTH_8,
 	};
 
-	/* if possible, speed up the transfer */
-	if (mci_caps(mci) & MMC_CAP_MMC_HIGHSPEED) {
-		if (mci->card_caps & MMC_CAP_MMC_HIGHSPEED_52MHZ)
-			mci->tran_speed = 52000000;
-		else
-			mci->tran_speed = 26000000;
-
-		host->timing = MMC_TIMING_MMC_HS;
-	}
-
-	mci_set_clock(mci, mci->tran_speed);
-
 	if (!(host->host_caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)))
-		return 0;
+		return MMC_BUS_WIDTH_1;
 
 	/*
 	 * Unlike SD, MMC cards dont have a configuration register to notify
@@ -1206,7 +1223,6 @@ static int mci_startup_mmc(struct mci *mci)
 		idx = 1;
 
 	for (; idx >= 0; idx--) {
-
 		/*
 		 * Host is capable of 8bit transfer, then switch
 		 * the device to work in 8bit transfer mode. If the
@@ -1214,21 +1230,38 @@ static int mci_startup_mmc(struct mci *mci)
 		 * 4bit transfer mode. On success set the corresponding
 		 * bus width on the host.
 		 */
-		err = mci_switch(mci, EXT_CSD_BUS_WIDTH, ext_csd_bits[idx]);
-		if (err) {
-			if (idx == 0)
-				dev_warn(&mci->dev, "Changing MMC bus width failed: %d\n", err);
-			continue;
-		}
+		ret = mci_mmc_try_bus_width(mci, bus_widths[idx]);
+		if (ret > 0)
+			break;
+	}
 
-		mci_set_bus_width(mci, bus_widths[idx]);
+	return ret;
+}
 
-		err = mmc_compare_ext_csds(mci, bus_widths[idx]);
-		if (!err)
-			break;
+static int mci_startup_mmc(struct mci *mci)
+{
+	struct mci_host *host = mci->host;
+	int ret;
+
+	/* if possible, speed up the transfer */
+	if (mci_caps(mci) & MMC_CAP_MMC_HIGHSPEED) {
+		if (mci->card_caps & MMC_CAP_MMC_HIGHSPEED_52MHZ)
+			mci->tran_speed = 52000000;
+		else
+			mci->tran_speed = 26000000;
+
+		host->timing = MMC_TIMING_MMC_HS;
 	}
 
-	return err;
+	mci_set_clock(mci, mci->tran_speed);
+
+	ret = mci_mmc_select_bus_width(mci);
+	if (ret < 0) {
+		dev_warn(&mci->dev, "Changing MMC bus width failed: %d\n", ret);
+		return ret;
+	}
+
+	return 0;
 }
 
 /**
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 18 02:30:37 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 18 Apr 2023 11:30:37 +0200
Subject: [PATCH v2 2/5] mci: introduce new dedicated enum mmc_bus_width type
In-Reply-To: <20230418093040.1865982-1-a.fatoum@pengutronix.de>
References: <20230418093040.1865982-1-a.fatoum@pengutronix.de>
Message-ID: <20230418093040.1865982-2-a.fatoum@pengutronix.de>

To make it clearer that a bus width of 8 is not equal to integer 8,
let's give it a dedicated type. No functional change.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - new patch
---
 drivers/mci/mci-core.c |  6 +++---
 include/mci.h          | 20 ++++++++++----------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index f647cae8203b..2abed0011722 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -864,7 +864,7 @@ static void mci_set_clock(struct mci *mci, unsigned clock)
  * @param mci MCI instance
  * @param width New interface bit width (1, 4 or 8)
  */
-static void mci_set_bus_width(struct mci *mci, unsigned width)
+static void mci_set_bus_width(struct mci *mci, enum mci_bus_width width)
 {
 	struct mci_host *host = mci->host;
 
@@ -1055,7 +1055,7 @@ static void mci_extract_card_dsr_imp_from_csd(struct mci *mci)
 	mci->dsr_imp = UNSTUFF_BITS(mci->csd, 76, 1);
 }
 
-static int mmc_compare_ext_csds(struct mci *mci, unsigned bus_width)
+static int mmc_compare_ext_csds(struct mci *mci, enum mci_bus_width bus_width)
 {
 	u8 *bw_ext_csd;
 	int err;
@@ -1176,7 +1176,7 @@ static int mci_startup_mmc(struct mci *mci)
 		EXT_CSD_BUS_WIDTH_4,
 		EXT_CSD_BUS_WIDTH_8,
 	};
-	static unsigned bus_widths[] = {
+	static enum mci_bus_width bus_widths[] = {
 		MMC_BUS_WIDTH_4,
 		MMC_BUS_WIDTH_8,
 	};
diff --git a/include/mci.h b/include/mci.h
index c38567303241..a3f6d619b361 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -410,16 +410,16 @@ enum mci_timing {
 	MMC_TIMING_MMC_HS400	= 8,
 };
 
-struct mci_ios {
-	unsigned int	clock;			/* clock rate */
-
-	unsigned char	bus_width;		/* data bus width */
-
-#define MMC_BUS_WIDTH_1		0
-#define MMC_BUS_WIDTH_4		2
-#define MMC_BUS_WIDTH_8		3
+enum mci_bus_width {
+	MMC_BUS_WIDTH_1		= 0,
+	MMC_BUS_WIDTH_4		= 2,
+	MMC_BUS_WIDTH_8		= 3,
+};
 
-	enum mci_timing	timing;			/* timing specification used */
+struct mci_ios {
+	unsigned int		clock;			/* clock rate */
+	enum mci_bus_width	bus_width;		/* data bus width */
+	enum mci_timing		timing;			/* timing specification used */
 };
 
 struct mci;
@@ -434,7 +434,7 @@ struct mci_host {
 	unsigned f_min;		/**< host interface lower limit */
 	unsigned f_max;		/**< host interface upper limit */
 	unsigned clock;		/**< Current clock used to talk to the card */
-	unsigned bus_width;	/**< used data bus width to the card */
+	enum mci_bus_width bus_width;	/**< used data bus width to the card */
 	enum mci_timing timing;	/**< used timing specification to the card */
 	unsigned max_req_size;
 	unsigned dsr_val;	/**< optional dsr value */
-- 
2.39.2



From a.fatoum at pengutronix.de  Tue Apr 18 02:30:39 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Tue, 18 Apr 2023 11:30:39 +0200
Subject: [PATCH v2 4/5] mci: add eMMC DDR52 support
In-Reply-To: <20230418093040.1865982-1-a.fatoum@pengutronix.de>
References: <20230418093040.1865982-1-a.fatoum@pengutronix.de>
Message-ID: <20230418093040.1865982-4-a.fatoum@pengutronix.de>

The maximum card frequency that can be configured by barebox currently
is 50MHz for SD and 52MHz for eMMC. Higher speed modes require runtime
voltage switching or tuning sequences, which are not yet implemented.

Only exception is eMMC's DDR52: This mode was first introduced with
MMC 4.4 and can be used even at 3.3V.

This commit adds DDR52 support to the core. This introduces no functional
change, because host controllers must opt-in by setting the appropriate
host capabilities. In cases where it's enabled, bus width determination
happens as usual and then if possible, the resulting bus width will be
attempted with DDR. If that fails, we revert back to SDR.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - don't attempt 8-bit DDR if 8-bit SDR is not supported
  - try SDR speed modes first before going DDR
  - refactor a bit, so extension for HS200/HS400 is easier
---
 drivers/mci/mci-core.c | 60 +++++++++++++++++++++++++++++++++++-------
 include/mci.h          | 19 +++++++++++++
 2 files changed, 70 insertions(+), 9 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index bd5299e7a4f8..6d0d6473770c 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -135,6 +135,9 @@ static int mci_set_blocklen(struct mci *mci, unsigned len)
 {
 	struct mci_cmd cmd;
 
+	if (mci->host->timing == MMC_TIMING_MMC_DDR52)
+		return 0;
+
 	mci_setup_cmd(&cmd, MMC_CMD_SET_BLOCKLEN, len, MMC_RSP_R1);
 	return mci_send_cmd(mci, &cmd, NULL);
 }
@@ -649,11 +652,15 @@ static int mmc_change_freq(struct mci *mci)
 		return 0;
 	}
 
-	/* High Speed is set, there are two types: 52MHz and 26MHz */
-	if (cardtype & EXT_CSD_CARD_TYPE_52)
-		mci->card_caps |= MMC_CAP_MMC_HIGHSPEED_52MHZ | MMC_CAP_MMC_HIGHSPEED;
-	else
-		mci->card_caps |= MMC_CAP_MMC_HIGHSPEED;
+	mci->card_caps |= MMC_CAP_MMC_HIGHSPEED;
+
+	/* High Speed is set, there are three types: 26MHz, 52MHz, 52MHz DDR */
+	if (cardtype & EXT_CSD_CARD_TYPE_52) {
+		mci->card_caps |= MMC_CAP_MMC_HIGHSPEED_52MHZ;
+
+		if (cardtype & EXT_CSD_CARD_TYPE_DDR_1_8V)
+			mci->card_caps |= MMC_CAP_MMC_3_3V_DDR | MMC_CAP_MMC_1_8V_DDR;
+	}
 
 	if (IS_ENABLED(CONFIG_MCI_MMC_BOOT_PARTITIONS) &&
 			mci->ext_csd[EXT_CSD_REV] >= 3 && mci->ext_csd[EXT_CSD_BOOT_SIZE_MULT]) {
@@ -1180,17 +1187,25 @@ static u32 mci_bus_width_ext_csd_bits(enum mci_bus_width bus_width)
 	}
 }
 
-static int mci_mmc_try_bus_width(struct mci *mci, enum mci_bus_width bus_width)
+static int mci_mmc_try_bus_width(struct mci *mci, enum mci_bus_width bus_width,
+				 enum mci_timing timing)
 {
 	u32 ext_csd_bits;
 	int err;
 
+	dev_dbg(&mci->dev, "attempting buswidth %u%s\n", 1 << bus_width,
+		mci_timing_is_ddr(timing) ? " (DDR)" : "");
+
 	ext_csd_bits = mci_bus_width_ext_csd_bits(bus_width);
 
+	if (mci_timing_is_ddr(timing))
+		ext_csd_bits |= EXT_CSD_DDR_FLAG;
+
 	err = mci_switch(mci, EXT_CSD_BUS_WIDTH, ext_csd_bits);
 	if (err < 0)
 		return err;
 
+	mci->host->timing = timing;
 	mci_set_bus_width(mci, bus_width);
 
 	err = mmc_compare_ext_csds(mci, bus_width);
@@ -1230,7 +1245,7 @@ static int mci_mmc_select_bus_width(struct mci *mci)
 		 * 4bit transfer mode. On success set the corresponding
 		 * bus width on the host.
 		 */
-		ret = mci_mmc_try_bus_width(mci, bus_widths[idx]);
+		ret = mci_mmc_try_bus_width(mci, bus_widths[idx], host->timing);
 		if (ret > 0)
 			break;
 	}
@@ -1238,6 +1253,24 @@ static int mci_mmc_select_bus_width(struct mci *mci)
 	return ret;
 }
 
+static int mci_mmc_select_hs_ddr(struct mci *mci)
+{
+	struct mci_host *host = mci->host;
+	int ret;
+
+	if (!(mci_caps(mci) & MMC_CAP_MMC_1_8V_DDR))
+		return 0;
+
+	ret = mci_mmc_try_bus_width(mci, host->bus_width, MMC_TIMING_MMC_DDR52);
+	if (ret < 0)
+		return mci_mmc_try_bus_width(mci, host->bus_width, MMC_TIMING_MMC_HS);
+
+	mci->read_bl_len = SECTOR_SIZE;
+	mci->write_bl_len = SECTOR_SIZE;
+
+	return 0;
+}
+
 static int mci_startup_mmc(struct mci *mci)
 {
 	struct mci_host *host = mci->host;
@@ -1255,7 +1288,11 @@ static int mci_startup_mmc(struct mci *mci)
 
 	mci_set_clock(mci, mci->tran_speed);
 
+	/* find out maximum bus width and then try DDR if supported */
 	ret = mci_mmc_select_bus_width(mci);
+	if (ret > MMC_BUS_WIDTH_1 && mci->tran_speed == 52000000)
+		ret = mci_mmc_select_hs_ddr(mci);
+
 	if (ret < 0) {
 		dev_warn(&mci->dev, "Changing MMC bus width failed: %d\n", ret);
 		return ret;
@@ -1687,6 +1724,8 @@ static const char *mci_timing_tostr(unsigned timing)
 		return "MMC HS";
 	case MMC_TIMING_SD_HS:
 		return "SD HS";
+	case MMC_TIMING_MMC_DDR52:
+		return "MMC DDR52";
 	default:
 		return "unknown"; /* shouldn't happen */
 	}
@@ -1694,12 +1733,15 @@ static const char *mci_timing_tostr(unsigned timing)
 
 static void mci_print_caps(unsigned caps)
 {
-	printf("  capabilities: %s%s%s%s%s\n",
+	printf("  capabilities: %s%s%s%s%s%s%s%s\n",
 		caps & MMC_CAP_4_BIT_DATA ? "4bit " : "",
 		caps & MMC_CAP_8_BIT_DATA ? "8bit " : "",
 		caps & MMC_CAP_SD_HIGHSPEED ? "sd-hs " : "",
 		caps & MMC_CAP_MMC_HIGHSPEED ? "mmc-hs " : "",
-		caps & MMC_CAP_MMC_HIGHSPEED_52MHZ ? "mmc-52MHz " : "");
+		caps & MMC_CAP_MMC_HIGHSPEED_52MHZ ? "mmc-52MHz " : "",
+		caps & MMC_CAP_MMC_3_3V_DDR ? "ddr-3.3v " : "",
+		caps & MMC_CAP_MMC_1_8V_DDR ? "ddr-1.8v " : "",
+		caps & MMC_CAP_MMC_1_2V_DDR ? "ddr-1.2v " : "");
 }
 
 /**
diff --git a/include/mci.h b/include/mci.h
index a3f6d619b361..3e93f378e4a3 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -51,6 +51,11 @@
 #define MMC_CAP_SD_HIGHSPEED		(1 << 3)
 #define MMC_CAP_MMC_HIGHSPEED		(1 << 4)
 #define MMC_CAP_MMC_HIGHSPEED_52MHZ	(1 << 5)
+#define MMC_CAP_MMC_3_3V_DDR		(1 << 7)	/* Host supports eMMC DDR 3.3V */
+#define MMC_CAP_MMC_1_8V_DDR		(1 << 8)	/* Host supports eMMC DDR 1.8V */
+#define MMC_CAP_MMC_1_2V_DDR		(1 << 9)	/* Host supports eMMC DDR 1.2V */
+#define MMC_CAP_DDR			(MMC_CAP_3_3V_DDR | MMC_CAP_1_8V_DDR | \
+					 MMC_CAP_1_2V_DDR)
 /* Mask of all caps for bus width */
 #define MMC_CAP_BIT_DATA_MASK		(MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)
 
@@ -308,6 +313,7 @@
 #define EXT_CSD_BUS_WIDTH_8	2	/* Card is in 8 bit mode */
 #define EXT_CSD_DDR_BUS_WIDTH_4	5	/* Card is in 4 bit DDR mode */
 #define EXT_CSD_DDR_BUS_WIDTH_8	6	/* Card is in 8 bit DDR mode */
+#define EXT_CSD_DDR_FLAG	BIT(2)	/* Flag for DDR mode */
 
 #define R1_ILLEGAL_COMMAND		(1 << 22)
 #define R1_STATUS(x)			(x & 0xFFF9A000)
@@ -410,6 +416,19 @@ enum mci_timing {
 	MMC_TIMING_MMC_HS400	= 8,
 };
 
+static inline bool mci_timing_is_ddr(enum mci_timing timing)
+{
+	switch (timing) {
+	case MMC_TIMING_UHS_DDR50:
+	case MMC_TIMING_MMC_HS200:
+	case MMC_TIMING_MMC_DDR52:
+	case MMC_TIMING_MMC_HS400:
+		return true;
+	default:
+		return false;
+	}
+}
+
 enum mci_bus_width {
 	MMC_BUS_WIDTH_1		= 0,
 	MMC_BUS_WIDTH_4		= 2,
-- 
2.39.2



From sha at pengutronix.de  Wed Apr 19 00:03:17 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Apr 2023 09:03:17 +0200
Subject: v2023.04.0
Message-ID: <20230419070317.GP13543@pengutronix.de>


Hi all,

I am happy to announce barebox-2023.04.0.

We have several interesting changes this time. First of all barebox now
supports building for multiple ARM SoCs in a single config. We now have
a multi_v7_defconfig (for bcm283x, i.MX, Omap, Rockchip, stm32mp and
vexpress) and a multi_v8_defconfig (bcm283x, i.MX, Omap, Rockchip and
zynqmp), more SoCs can be added later.
Furthermore the device tree overlay support can now patch the barebox
live tree, along with prbing additional devices enabled in an overlay.
This can help in cases when a generic board has different runtime
detectable extension boards detected during runtime. This works well for
regular platform devices and also for I2C devices, not so well for SPI
devices currently.
With this release barebox gains NXP Layerscape LS1021A support along
with the LS1021A IOT board support.
Some old boards/architectures have been removed this time. the Samsung
S3C support was removed as all supported boards were really old and
no longer actively maintained. Also the i.MX boards which haven't been
switched to device tree support have been removed, with this i.MX is
now device tree only. For the AT91 architecture all boards have been
moved over to multi image support, which allowed us to get rid of some
defconfig files.

Overall this is one of the bigger barebox releases. See below for a full
list of changes that went into this release.

Have fun!
 Sascha

--------------------------------8<----------------------------

Ahmad Fatoum (35):
      gpio: gpioinfo: use dev_name to get device name
      gpio: pca953x: sync DT compatibles with Linux
      gpio: pca953x: add optional support for regulator and reset GPIO
      blspec: support higher verbosity levels for boot
      ARM: i.MX8M: add option to install OP-TEE
      drivers: implement of_optee_fixup helper function
      ARM: i.MX8M: fixup op-tee nodes
      drivers: drop unneeded CONFIG_CRYPTO_HW guard
      of: base: factor out of_merge_nodes from of_copy_node
      of: support of_ensure_probed for top-level machine device
      boards: qemu-virt: ensure board driver probe at postcore_initcall level
      boards: qemu-virt: support passing in FIT public key
      net: dsa: abort registration when master is unresolvable
      hush: pacify clang -Wparentheses-equality warning
      ARM: dts: i.MX8MP: snps,dis-u2-freeclk-exists-quirk
      pinctrl: stm32: Remove check for pins-are-numbered
      test: riscv: fix YAMLs after defconfig rename
      RISC-V: board-dt-2nd: fix hang in startup
      RISC-V: sifive: disable non-functional SPI nodes
      video: qemu-ramfb: reduce -ENODEV lo level to debug
      gpiolib: fix gpio label generation with gpiod_get
      test: emulate.pl: fix firmware use with non-tuxmake out-of-tree build
      RISC-V: restrict GCC optimization some more
      RISC-V: configs: rv64i_defconfig: disable SBI serial
      net: dsa: realtek: include needed headers directly
      net: linux/mdio.h: add missing init.h header
      Kbuild: export CROSS_PKG_CONFIG
      treewide: fix includes missed by multiarch support
      mci: dw_mmc: make reset optional
      treewide: add missing device tree artifact cleanup where needed
      ARM64: setupc: don't invoke KASAN before relocation
      mci: bcm2835: return command timeout silently
      arm: error out if __LINUX_ARM_ARCH__ is undefined
      libfile: don't leak file descriptors in compare_file
      ARM: i.MX6: fix DEBUG_LL use

Albert Schwarzkopf (1):
      scripts: imx: Ignore ';' and '\n' in quotes

Denis Orlov (8):
      dma: use dma/cpu conversions correctly in dma_map/unmap_single
      MIPS: dma-default: use virtual addresses when flushing caches
      MIPS: dma-default: do not flush caches in dma_sync_single_* excessively
      lib: string: remove duplicated function
      MIPS: bootm: do not free fdt pointer that contains an error
      MIPS: bootm: do not leak memory on error in of_overlay_load_firmware()
      MIPS: bootm: remove unnecessary phys/virt conversions
      common: elf: use proper field to get segment memory size

Johannes Zink (1):
      Documentation: devicetree: list automatic boot argument fixups

Jules Maselbas (1):
      usb: dwc2: Fix memory leak in probe error path

Marco Felsch (1):
      ARM: boards: protonic-imx6: fix bbu_handler device paths

Oleksij Rempel (1):
      ARM: boards: protonic-imx6: fix board probe for LANMCU

Renaud Barbier (4):
      Subject: [PATCH 1/1] ARM:lib32: add architected timer
      ARM: add LS1021A to Layerscape machine support
      ARM: Layerscape: Add LS1021A IOT board support
      ARM: LS1021A: slow boot

Roland Hieber (1):
      Documentation: imx: improve reboot mode section

Sam Ravnborg (2):
      ARM: sama5d4_wifx: fix build with moved mach files
      ARM: add sama5d4_wifx to at91_multi_defconfig

Sascha Hauer (116):
      ARM: remove samsung arch
      mci: remove s3c driver
      mtd: nand: remove s3c driver
      serial: remove s3c driver
      video: remove s3c driver
      ARM: mxs: remove unused mach/clock.h
      ARM: imx: remove unused mach/clock.h
      ARM: rockchip: drop mach/timer.h
      ARM: i.MX: Move imxfb.h to include/platform_data/
      pinctrl: rockchip: Fix uninitialized var warning
      ARM: at91: remove unnecessary configs
      ARM: at91: Switch all boards to multiimage
      at91: consolidate usb-a963 128m images
      ARM: pxa: Move plat/ include files to mach/
      scripts: dtc: disable interrupt_provider warnings
      ARM: dts: digic4: Fix dtc warnings
      ARM: dts: ep7212-clep7212: Fix dtc warnings
      ARM: dts: Fix dtc warnings in state nodes
      ARM: dts: Fix dtc warnings in barebox,environment nodes
      ARM: dts: imx7d-peb-av-02: Fix dtc warning
      ARM: dts: imx7d-peb-eval-02: Fix dtc warnings
      ARM: dts: imx6ull-jozacp: Move regulators out of subnode
      ARM: i.MX: Remove old boards
      ARM: i.MX: Remove config CONFIG_ARCH_TEXT_BASE
      ARM: i.MX: Sort board Kconfig entries
      ARM: i.MX: let boards depend on 32/64bit
      ARM: add ENTRY_FUNCTION_HEAD macro
      ARM: mvebu: Use ENTRY_FUNCTION_HEAD
      ARM: at91: Use ENTRY_FUNCTION_HEAD
      ARM: Drop HAVE_MACH_ARM_HEAD
      ARM: drop CONFIG_HAS_ASM_DEBUG_LL
      regulator: pfuze: remove unused include
      ARM: drop unused zynq code in Makefile
      ARM: drop unused mvebu code in Makefile
      ARM: drop unused am35xx code in Makefile
      ARM: Makefile: Drop board-y
      ARM: i.MX: Add missing include
      ARM: stm32mp_defconfig: Enable remaining boards
      usb: dwc3: Use clk_bulk_get_all()
      mci: imx-esdhc-pbl: add missing include
      ARM: i.MX: Move mach header files to include/mach/imx
      ARM: Rockchip: Move mach header files to include/mach/rockchip
      ARM: Zynqmp: Move mach header files to include/mach/zynqmp
      ARM: mvebu: Move mach header files to include/mach/mvebu
      ARM: davinci: Move mach header files to include/mach/davinci
      ARM: bcm283x: Move mach header files to include/mach/bcm283x
      ARM: stm32mp: Move mach header files to include/mach/stm32mp
      ARM: zynq: Move mach header files to include/mach/zynq
      ARM: vexpress: Move mach header files to include/mach/vexpress
      ARM: versatile: Move mach header files to include/mach/versatile
      ARM: layerscape: Move mach header files to include/mach/layerscape
      ARM: tegra: Move mach header files to include/mach/tegra
      ARM: uemd: Move mach header files to include/mach/uemd
      ARM: socfpga: Move mach header files to include/mach/socfpga
      ARM: pxa: Move mach header files to include/mach/pxa
      ARM: omap: Move mach header files to include/mach/omap
      ARM: nomadik: Move mach header files to include/mach/nomadik
      ARM: mxs: Move mach header files to include/mach/mxs
      ARM: ep93xx: Move mach header files to include/mach/ep93xx
      ARM: digic: Move mach header files to include/mach/digic
      ARM: clps711x: Move mach header files to include/mach/clps711x
      ARM: at91: Move mach header files to include/mach/at91
      ARM: Drop mach dir include path
      include/mach/: use unique double inclusion protectors
      ARM: i.MX: Add missing include
      ARM: i.MX: Only provide PUTC_LL() when activated
      debug_ll ns16550: Do not define PUTC_LL()
      debug_ll ns16550: Use CONFIG_BAUDRATE
      ARM: Rockchip: Use ns16550 debug_ll helper
      ARM: Rockchip: Only provide PUTC_LL() when activated
      ARM: omap: Use ns16550 debug_ll helper
      ARM: omap: Only provide PUTC_LL() when activated
      ARM: omap: usbboot: Enable USB communication when needed
      ARM: omap: Make multi-arch safe
      ARM: Rockchip: Make safe for multi-arch
      pm_domains: Enable explicitly when we have power-domain providers
      ARM: add multi-arch support
      ARM: omap: Add support for multi-arch
      ARM: zynqmp: Add multi-arch support
      ARM: i.MX: move board selection into menu
      ARM: stm32mp: Only provide PUTC_LL() when activated
      ARM: stm32mp: Make safe for multi-arch
      ARM: stm32mp: Add multi-arch support
      ARM: vexpress: Drop unnecessary initcall
      ARM: vexpress: Only provide PUTC_LL() when activated
      ARM: vexpress: Add multi-arch support
      ARM: bcm283x: Only provide PUTC_LL() when activated
      ARM: bcm283x: Add multi-arch support
      ARM: Add multi_v7_defconfig
      ARM: Add multi_v8_defconfig
      clk: Rockchip: Fix arrays out of bounds access
      kbuild: Add target to build dtb overlay files
      driver: Add rescan hook to struct device
      i2c: implement rescan
      spi: Directly register SPI device
      spi: reduce scope of 'chip'
      spi: implement rescan
      ARM: Do not print exception stacktrace in panic
      of_overlay: Add option to apply overlay to live tree
      dts: update to v6.3-rc1
      dts: update to v6.3-rc2
      Merge branch 'for-next/arm' into next
      Merge branch 'for-next/dtc-warnings' into next
      Merge branch 'for-next/dts' into next
      Merge branch 'for-next/mips' into next
      Merge branch 'for-next/misc' into next
      Merge branch 'for-next/of-overlay' into next
      Merge branch 'next'
      net: macb: Adjust zynq compatibles to upstream device trees
      ARM: dts: rockchip: remove unused rk3568 dtsi files
      Revert "of: support of_ensure_probed for top-level machine device"
      Revert "boards: qemu-virt: ensure board driver probe at postcore_initcall level"
      Revert "boards: qemu-virt: support passing in FIT public key"
      ARM: i.MX: iim: Fix imx_iim_reg_write() return type
      arm: rockchip: radxa-rock3: Fix SD/eMMC device numbers
      Release v2023.04.0

Wolfram Sang (5):
      commands: edit: fix typo in Kconfig help text
      commands: nand: add missing parameters to help
      mtd: nand: atmel: legacy: add 'algo' to use
      mtd: nand: atmel: legacy: use proper ecc_shift
      mtd: nand: atmel: legacy: remove superfluous code

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From a.fatoum at pengutronix.de  Wed Apr 19 01:57:05 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Wed, 19 Apr 2023 10:57:05 +0200
Subject: SHA256 API in RK3568 rkimage deprecated since OpenSSL 3.0
Message-ID: <55246453-c5ad-5499-bb6b-c652c7330bc9@pengutronix.de>

Hi,

Just a heads up:

Building barebox rockchip_v8_defconfig on a system with openssl-3.0.8 emits
a couple of deprecation warnings:

  scripts/rkimage.c: In function ?sha256?:
  rkimage.c:27:9: warning: ?SHA256_Init? is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
     27 |         SHA256_Init(&sha256);
        |         ^~~~~~~~~~~

I think that this would be a good occasion to get rid of the OpenSSL dependency
here. We have a simplified SHA256 API already usable in PBL, so it should be
doable to make this accessible to host tool build like we already do for CRC32.

Cheers,
Ahmad

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From andreas at kemnade.info  Thu Apr 20 12:52:55 2023
From: andreas at kemnade.info (Andreas Kemnade)
Date: Thu, 20 Apr 2023 21:52:55 +0200
Subject: [PATCH] ARM: i.MX: bbu: fix compilation without CONFIG_BAREBOX_UPDATE
Message-ID: <20230420195255.1153119-1-andreas@kemnade.info>

Fix
include/mach/imx/bbu.h:208:1: error: expected identifier or ?(? before ?{? token

Signed-off-by: Andreas Kemnade <andreas at kemnade.info>
---
 include/mach/imx/bbu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/mach/imx/bbu.h b/include/mach/imx/bbu.h
index 451ae15740..50657d9895 100644
--- a/include/mach/imx/bbu.h
+++ b/include/mach/imx/bbu.h
@@ -204,7 +204,7 @@ imx7_bbu_internal_spi_i2c_register_handler(const char *name, char *devicefile,
 
 static inline int
 imx8m_bbu_internal_flexspi_nor_register_handler(const char *name, const char *devicefile,
-						unsigned long flags);
+						unsigned long flags)
 {
 	return -ENOSYS;
 }
-- 
2.39.2



From a.fatoum at pengutronix.de  Thu Apr 20 13:09:28 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Apr 2023 22:09:28 +0200
Subject: [PATCH] commands: implement of_compatible command
Message-ID: <20230420200928.2237187-1-a.fatoum@pengutronix.de>

Currently, the usual way within scripts to differentiate between machines
is to compare global.model or global.hostname. Both are suboptimal,
because they may change between releases or overridden by the user.

In C code, the machine compatible is used for this purpose. Add a new
of_compatible command that makes of_machine_is_compatible/
of_device_is_compatible available to scripts. Example use:

/env/init/fixups:

  #!/bin/sh

  if of_compatible -k radxa,rock3a ; then
    of_property -df mmc0 sd-uhs-sdr104
  fi

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 commands/Kconfig         |  15 +++++
 commands/Makefile        |   1 +
 commands/of_compatible.c | 139 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 155 insertions(+)
 create mode 100644 commands/of_compatible.c

diff --git a/commands/Kconfig b/commands/Kconfig
index b9abd8565523..59e8d6fb382d 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2201,6 +2201,21 @@ config CMD_LSMOD
 	help
 	  List loaded barebox modules.
 
+config CMD_OF_COMPATIBLE
+	tristate
+	select OFTREE
+	prompt "of_compatible"
+	help
+	  Check DT node's compatible
+
+	  Usage: [-fFnk] [COMPAT]
+
+	  Options:
+          	-f dtb	work on dtb instead of internal devicetree
+          	-F	apply fixups on devicetree before compare
+          	-n node	node path or alias to compare its comptible (default is /)
+          	-k	compare $global.of.kernel.add_machine_compatible as well
+
 config CMD_OF_DIFF
 	tristate
 	select OFTREE
diff --git a/commands/Makefile b/commands/Makefile
index e5cc21f1970a..0ac84076f83d 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -82,6 +82,7 @@ obj-$(CONFIG_CMD_USB)		+= usb.o
 obj-$(CONFIG_CMD_TIME)		+= time.o
 obj-$(CONFIG_CMD_UPTIME)	+= uptime.o
 obj-$(CONFIG_CMD_OFTREE)	+= oftree.o
+obj-$(CONFIG_CMD_OF_COMPATIBLE)	+= of_compatible.o
 obj-$(CONFIG_CMD_OF_DIFF)	+= of_diff.o
 obj-$(CONFIG_CMD_OF_PROPERTY)	+= of_property.o
 obj-$(CONFIG_CMD_OF_NODE)	+= of_node.o
diff --git a/commands/of_compatible.c b/commands/of_compatible.c
new file mode 100644
index 000000000000..e4684f23b71d
--- /dev/null
+++ b/commands/of_compatible.c
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-FileCopyrightText: ? 2023 Ahmad Fatoum <a.fatoum at pengutronix.de>
+
+#include <common.h>
+#include <libfile.h>
+#include <fdt.h>
+#include <of.h>
+#include <command.h>
+#include <complete.h>
+#include <errno.h>
+#include <getopt.h>
+
+static int do_of_compatible(int argc, char *argv[])
+{
+	int opt;
+	int ret = 0;
+	bool fix = false, kernel_compat = false;
+	struct device_node *root = NULL, *node, *of_free = NULL;
+	char *dtbfile = NULL;
+	const char *compat, *nodename = "/";
+
+	while ((opt = getopt(argc, argv, "f:n:Fk")) > 0) {
+		switch (opt) {
+		case 'f':
+			dtbfile = optarg;
+			break;
+		case 'n':
+			nodename = optarg;
+			break;
+		case 'F':
+			fix = true;
+			break;
+		case 'k':
+			kernel_compat = true;
+			break;
+		default:
+			return COMMAND_ERROR_USAGE;
+		}
+	}
+
+	if (argc - optind != 1)
+		return COMMAND_ERROR_USAGE;
+
+	compat = argv[optind];
+
+	if (dtbfile) {
+		size_t size;
+		void *fdt;
+
+		fdt = read_file(dtbfile, &size);
+		if (!fdt) {
+			printf("unable to read %s: %s\n", dtbfile, strerror(errno));
+			return -errno;
+		}
+
+		root = of_unflatten_dtb(fdt, size);
+
+		free(fdt);
+
+		if (IS_ERR(root)) {
+			ret = PTR_ERR(root);
+			goto out;
+		}
+
+		of_free = root;
+	} else {
+		root = of_get_root_node();
+
+		if (fix) {
+			/* create a copy of internal devicetree */
+			void *fdt;
+			fdt = of_flatten_dtb(root);
+			root = of_unflatten_dtb(fdt, fdt_totalsize(fdt));
+
+			free(fdt);
+
+			if (IS_ERR(root)) {
+				ret = PTR_ERR(root);
+				goto out;
+			}
+
+			of_free = root;
+		}
+	}
+
+	if (fix) {
+		ret = of_fix_tree(root);
+		if (ret)
+			goto out;
+	}
+
+	node = of_find_node_by_path_or_alias(root, nodename);
+	if (!node) {
+		printf("Cannot find nodepath %s\n", nodename);
+		ret = -ENOENT;
+		goto out;
+	}
+
+	if (kernel_compat) {
+		const char *compat_override;
+
+		if (node->parent) {
+			printf("-k only valid for root node\n");
+			ret = COMMAND_ERROR_USAGE;
+			goto out;
+		}
+
+		compat_override = barebox_get_of_machine_compatible() ?: "";
+		if (strcmp(compat_override, compat) == 0) {
+			ret = 0;
+			goto out;
+		}
+	}
+
+	ret = !of_device_is_compatible(node, compat);
+
+out:
+	if (of_free)
+		of_delete_node(of_free);
+
+	return ret;
+}
+
+BAREBOX_CMD_HELP_START(of_compatible)
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT  ("-f dtb",  "work on dtb instead of internal devicetree")
+BAREBOX_CMD_HELP_OPT  ("-F",      "apply fixups on devicetree before compare")
+BAREBOX_CMD_HELP_OPT  ("-n NODE", "node path or alias to compare its compatible (default is /)")
+BAREBOX_CMD_HELP_OPT  ("-k",      "compare $global.of.kernel.add_machine_compatible as well")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(of_compatible)
+	.cmd		= do_of_compatible,
+	BAREBOX_CMD_DESC("Check DT node's compatible")
+	BAREBOX_CMD_OPTS("[-fFnk] [COMPAT]")
+	BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+	BAREBOX_CMD_COMPLETE(empty_complete)
+	BAREBOX_CMD_HELP(cmd_of_compatible_help)
+BAREBOX_CMD_END
-- 
2.39.2



From a.fatoum at pengutronix.de  Thu Apr 20 13:15:10 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Apr 2023 22:15:10 +0200
Subject: [PATCH] commands: add new of_fixup command to list and disable DT
 fixups
In-Reply-To: <20230221100818.GC10447@pengutronix.de>
References: <20230217203148.2902038-1-a.fatoum@pengutronix.de>
 <20230221100818.GC10447@pengutronix.de>
Message-ID: <f54e8087-0bf2-cbc9-5ed0-df06e2027350@pengutronix.de>

Hello Sascha,

On 21.02.23 11:08, Sascha Hauer wrote:
> On Fri, Feb 17, 2023 at 09:31:48PM +0100, Ahmad Fatoum wrote:
>> For debugging, it can be useful to disable a fixup to rule out it causing
>> issues. For platforms supporting kallsyms, we can readily allow enabling
>> and disabling fixups by name, so let's add a command that does just that.
>>
>> Suggested-by: Daniel Br?t <danek.brat at gmail.com>
>> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
>> ---
>>  commands/Kconfig    | 15 ++++++++
>>  commands/Makefile   |  1 +
>>  commands/of_fixup.c | 86 +++++++++++++++++++++++++++++++++++++++++++++
>>  common/kallsyms.c   |  8 ++---
>>  common/oftree.c     | 17 +++++----
>>  drivers/of/Kconfig  |  6 ++++
>>  include/kallsyms.h  |  4 +++
>>  include/of.h        | 10 ++++++
>>  8 files changed, 137 insertions(+), 10 deletions(-)
>>  create mode 100644 commands/of_fixup.c
>>
>> +static int do_of_fixup(int argc, char *argv[])
>> +{
>> +	struct of_fixup *of_fixup;
>> +	int opt, enable = -1;
>> +
>> +	while ((opt = getopt(argc, argv, "ed")) > 0) {
>> +		switch (opt) {
>> +		case 'e':
>> +			enable = 1;
>> +			break;
>> +		case 'd':
>> +			enable = 0;
>> +			break;
>> +		default:
>> +			return COMMAND_ERROR_USAGE;
>> +		}
>> +	}
>> +
>> +	argv += optind;
>> +	argc -= optind;
>> +
>> +	if ((enable < 0 && argc > 0) || (enable >= 0 && argc == 0))
>> +		return COMMAND_ERROR_USAGE;
>> +
>> +	list_for_each_entry(of_fixup, &of_fixup_list, list) {
>> +		int i;
>> +		ulong addr = (ulong)of_fixup->fixup;
>> +		char sym[KSYM_SYMBOL_LEN];
>> +		const char *name;
>> +
>> +		name = kallsyms_lookup(addr, NULL, NULL, NULL, sym);
>> +		if (!name) {
>> +			sprintf(sym, "<0x%lx>", addr);
>> +			name = sym;
>> +		}
> 
> Does this fallback make sense? kallsyms_lookup() should always return a
> name, otherwise something is really wrong.

Fixup may be registered within a module, which barebox kallsyms doesn't
yet support.

> 
>> +
>> +		if (enable == -1) {
>> +			printf("%s(0x%p)%s\n", name, of_fixup->context,
>> +			       of_fixup->disabled ? " [DISABELD]" : "");
> 
> s/DISABELD/DISABLED/

Will fix.

> We can have the same fixup function with different contexts, that's why
> you print the context pointer here. Shouldn't we then have a way to
> disable a specific fixup, like "of_fixup -d mtd_partition_fixup(0x2fed7a00)"?

The command is meant for quick testing. To make sense of context pointers,
a map file or an instrumented barebox is needed, so it's not that useful
to be able to filter by context pointer IMO.

> 
> Sascha
> 
>> +config OF_FIXUP_TOGGLE
>> +	bool
>> +	help
>> +	  This is selected when some device tree fixups may be selectively
>> +	  disabled.
> 
> Why does this have an extra config option? It doesn't look like it's
> saving a lot of binary space.

I can drop it, sure.

Cheers,
Ahmad

> 
> Sascha
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



From a.fatoum at pengutronix.de  Thu Apr 20 13:32:19 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Thu, 20 Apr 2023 22:32:19 +0200
Subject: [PATCH v2] commands: add new of_fixup command to list and disable DT fixups
Message-ID: <20230420203219.2255564-1-a.fatoum@pengutronix.de>

barebox can already dry run fixups with of_diff - +, but there's no way
to selectively disable a fixup to rule out it causing issues.

For platforms supporting kallsyms, we can readily allow enabling
and disabling fixups by name, so let's add a command that does just that
to aid in debugging.

Suggested-by: Daniel Br?t <danek.brat at gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
v1 -> v2:
  - extend commit message a bit
  - fix typo (Sascha)
  - drop CONFIG_OF_FIXUP_TOGGLE
  - print warning message when all specified fixups are non-existent
---
 commands/Kconfig    | 14 +++++++
 commands/Makefile   |  1 +
 commands/of_fixup.c | 93 +++++++++++++++++++++++++++++++++++++++++++++
 common/kallsyms.c   |  8 ++--
 common/oftree.c     | 14 ++++---
 include/kallsyms.h  |  4 ++
 include/of.h        | 10 +++++
 7 files changed, 134 insertions(+), 10 deletions(-)
 create mode 100644 commands/of_fixup.c

diff --git a/commands/Kconfig b/commands/Kconfig
index e4452cd42d45..3becc88129c1 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2283,6 +2283,20 @@ config CMD_OF_DISPLAY_TIMINGS
 		  -s path	select display-timings and register oftree fixup
 		  -f dtb	work on dtb. Has no effect on -s option
 
+config CMD_OF_FIXUP
+	tristate
+	select OFTREE
+	depends on KALLSYMS
+	prompt "of_fixup"
+	help
+	  List and enable/disable fixups
+
+	  Usage: of_fixup [-de] [fixups...]
+
+	  Options:
+		-d		disable fixup
+	  	-e		re-enable fixup
+
 config CMD_OF_FIXUP_STATUS
 	tristate
 	select OFTREE
diff --git a/commands/Makefile b/commands/Makefile
index ec59137d7e12..0ac84076f83d 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -88,6 +88,7 @@ obj-$(CONFIG_CMD_OF_PROPERTY)	+= of_property.o
 obj-$(CONFIG_CMD_OF_NODE)	+= of_node.o
 obj-$(CONFIG_CMD_OF_DUMP)	+= of_dump.o
 obj-$(CONFIG_CMD_OF_DISPLAY_TIMINGS)	+= of_display_timings.o
+obj-$(CONFIG_CMD_OF_FIXUP)	+= of_fixup.o
 obj-$(CONFIG_CMD_OF_FIXUP_STATUS)	+= of_fixup_status.o
 obj-$(CONFIG_CMD_OF_OVERLAY)	+= of_overlay.o
 obj-$(CONFIG_CMD_MAGICVAR)	+= magicvar.o
diff --git a/commands/of_fixup.c b/commands/of_fixup.c
new file mode 100644
index 000000000000..d667afb5b107
--- /dev/null
+++ b/commands/of_fixup.c
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/*
+ * of_fixup.c - List and remove OF fixups
+ */
+
+#include <common.h>
+#include <kallsyms.h>
+#include <of.h>
+#include <command.h>
+#include <malloc.h>
+#include <complete.h>
+#include <getopt.h>
+#include <string.h>
+
+static int do_of_fixup(int argc, char *argv[])
+{
+	struct of_fixup *of_fixup;
+	int opt, enable = -1;
+	bool did_fixup = false;
+
+	while ((opt = getopt(argc, argv, "ed")) > 0) {
+		switch (opt) {
+		case 'e':
+			enable = 1;
+			break;
+		case 'd':
+			enable = 0;
+			break;
+		default:
+			return COMMAND_ERROR_USAGE;
+		}
+	}
+
+	argv += optind;
+	argc -= optind;
+
+	if ((enable < 0 && argc > 0) || (enable >= 0 && argc == 0))
+		return COMMAND_ERROR_USAGE;
+
+	list_for_each_entry(of_fixup, &of_fixup_list, list) {
+		int i;
+		ulong addr = (ulong)of_fixup->fixup;
+		char sym[KSYM_SYMBOL_LEN];
+		const char *name;
+
+		name = kallsyms_lookup(addr, NULL, NULL, NULL, sym);
+		if (!name) {
+			sprintf(sym, "<0x%lx>", addr);
+			name = sym;
+		}
+
+		if (enable == -1) {
+			printf("%s(0x%p)%s\n", name, of_fixup->context,
+			       of_fixup->disabled ? " [DISABLED]" : "");
+			continue;
+		}
+
+		for (i = 0; i < argc; i++) {
+			if (strcmp(name, argv[i]) != 0)
+				continue;
+
+			of_fixup->disabled = !enable;
+			did_fixup = true;
+		}
+	}
+
+	if (argc && !did_fixup) {
+		printf("none of the specified fixups found\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+BAREBOX_CMD_HELP_START(of_fixup)
+BAREBOX_CMD_HELP_TEXT("Disable or re-enable an already registered fixup for the device tree.")
+BAREBOX_CMD_HELP_TEXT("Call without arguments to list all fixups")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT("-d",  "disable fixup")
+BAREBOX_CMD_HELP_OPT("-e",  "re-enable fixup")
+BAREBOX_CMD_HELP_OPT("fixups",  "List of fixups to enable or disable")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(of_fixup)
+	.cmd	= do_of_fixup,
+	BAREBOX_CMD_DESC("list and enable/disable fixups")
+	BAREBOX_CMD_OPTS("[-de] [fixups...]")
+	BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+	BAREBOX_CMD_COMPLETE(empty_complete)
+	BAREBOX_CMD_HELP(cmd_of_fixup_help)
+BAREBOX_CMD_END
diff --git a/common/kallsyms.c b/common/kallsyms.c
index a9b2b9368992..3c5904f8a833 100644
--- a/common/kallsyms.c
+++ b/common/kallsyms.c
@@ -165,10 +165,10 @@ static unsigned long get_symbol_pos(unsigned long addr,
  *   It resides in a module.
  * - We also guarantee that modname will be valid until rescheduled.
  */
-static const char *kallsyms_lookup(unsigned long addr,
-				   unsigned long *symbolsize,
-				   unsigned long *offset,
-				   char **modname, char *namebuf)
+const char *kallsyms_lookup(unsigned long addr,
+			    unsigned long *symbolsize,
+			    unsigned long *offset,
+			    char **modname, char *namebuf)
 {
 	namebuf[KSYM_NAME_LEN - 1] = 0;
 	namebuf[0] = 0;
diff --git a/common/oftree.c b/common/oftree.c
index 4beadc5aaa89..1f751cc0ac89 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -350,13 +350,12 @@ int of_register_set_status_fixup(const char *path, bool status)
 	return of_register_fixup(of_fixup_status, (void *)data);
 }
 
-struct of_fixup {
-	int (*fixup)(struct device_node *, void *);
-	void *context;
-	struct list_head list;
-};
+LIST_HEAD(of_fixup_list);
 
-static LIST_HEAD(of_fixup_list);
+static inline bool of_fixup_disabled(struct of_fixup *fixup)
+{
+    return fixup->disabled;
+}
 
 int of_register_fixup(int (*fixup)(struct device_node *, void *), void *context)
 {
@@ -401,6 +400,9 @@ int of_fix_tree(struct device_node *node)
 	of_overlay_load_firmware_clear();
 
 	list_for_each_entry(of_fixup, &of_fixup_list, list) {
+		if (of_fixup_disabled(of_fixup))
+			continue;
+
 		ret = of_fixup->fixup(node, of_fixup->context);
 		if (ret)
 			pr_warn("Failed to fixup node in %pS: %s\n",
diff --git a/include/kallsyms.h b/include/kallsyms.h
index e0b3ff7cd503..f61efc9e0c42 100644
--- a/include/kallsyms.h
+++ b/include/kallsyms.h
@@ -6,6 +6,10 @@
 #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s]") + (KSYM_NAME_LEN - 1) + \
 		2*(BITS_PER_LONG*3/10) + (MODULE_NAME_LEN - 1) + 1)
 unsigned long kallsyms_lookup_name(const char *name);
+const char *kallsyms_lookup(unsigned long addr,
+			    unsigned long *symbolsize,
+			    unsigned long *offset,
+			    char **modname, char *namebuf);
 
 /* Look up a kernel symbol and return it in a text buffer. */
 int sprint_symbol(char *buffer, unsigned long address);
diff --git a/include/of.h b/include/of.h
index 22358f5579ec..5cdea4329330 100644
--- a/include/of.h
+++ b/include/of.h
@@ -331,6 +331,16 @@ int of_find_path_by_node(struct device_node *node, char **outpath, unsigned flag
 struct device_node *of_find_node_by_devpath(struct device_node *root, const char *path);
 int of_register_fixup(int (*fixup)(struct device_node *, void *), void *context);
 int of_unregister_fixup(int (*fixup)(struct device_node *, void *), void *context);
+
+struct of_fixup {
+	int (*fixup)(struct device_node *, void *);
+	void *context;
+	struct list_head list;
+	bool disabled;
+};
+
+extern struct list_head of_fixup_list;
+
 int of_register_set_status_fixup(const char *node, bool status);
 struct device_node *of_find_node_by_alias(struct device_node *root,
 		const char *alias);
-- 
2.39.2



From andreas at kemnade.info  Thu Apr 20 23:22:29 2023
From: andreas at kemnade.info (Andreas Kemnade)
Date: Fri, 21 Apr 2023 08:22:29 +0200
Subject: [PATCH] ARM: i.MX: bbu: fix compilation without
 CONFIG_BAREBOX_UPDATE
In-Reply-To: <20230420195255.1153119-1-andreas@kemnade.info>
References: <20230420195255.1153119-1-andreas@kemnade.info>
Message-ID: <20230421082229.1b2d537e@aktux>

On Thu, 20 Apr 2023 21:52:55 +0200
Andreas Kemnade <andreas at kemnade.info> wrote:

> Fix
> include/mach/imx/bbu.h:208:1: error: expected identifier or ?(? before ?{? token
> 
> Signed-off-by: Andreas Kemnade <andreas at kemnade.info>

should probably have added a fixes:
Fixes: 6e0cb133be ("ARM: i.MX: bbu: add FlexSPI update handler")


From sha at pengutronix.de  Thu Apr 20 23:29:56 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Fri, 21 Apr 2023 08:29:56 +0200
Subject: [PATCH v2 1/5] mci: core: drop unused DDR/SDR constants
In-Reply-To: <20230418093040.1865982-1-a.fatoum@pengutronix.de>
References: <20230418093040.1865982-1-a.fatoum@pengutronix.de>
Message-ID: <20230421062956.GS13543@pengutronix.de>

On Tue, Apr 18, 2023 at 11:30:36AM +0200, Ahmad Fatoum wrote:
> These macros are unused and will be replaced by their Linux counterparts
> in a follow up patch, so drop them.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
> v1 -> v2:
>   - new patch
> ---
>  include/mci.h | 6 ------
>  1 file changed, 6 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/include/mci.h b/include/mci.h
> index d356f071f7f2..c38567303241 100644
> --- a/include/mci.h
> +++ b/include/mci.h
> @@ -420,12 +420,6 @@ struct mci_ios {
>  #define MMC_BUS_WIDTH_8		3
>  
>  	enum mci_timing	timing;			/* timing specification used */
> -
> -#define MMC_SDR_MODE		0
> -#define MMC_1_2V_DDR_MODE	1
> -#define MMC_1_8V_DDR_MODE	2
> -#define MMC_1_2V_SDR_MODE	3
> -#define MMC_1_8V_SDR_MODE	4
>  };
>  
>  struct mci;
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From m.felsch at pengutronix.de  Thu Apr 20 23:55:38 2023
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Fri, 21 Apr 2023 08:55:38 +0200
Subject: [PATCH] ARM: i.MX: bbu: fix compilation without
 CONFIG_BAREBOX_UPDATE
In-Reply-To: <20230420195255.1153119-1-andreas@kemnade.info>
References: <20230420195255.1153119-1-andreas@kemnade.info>
Message-ID: <20230421065538.xlb7a7nxlyapop6s@pengutronix.de>

Hi Andreas,

On 23-04-20, Andreas Kemnade wrote:
> Fix
> include/mach/imx/bbu.h:208:1: error: expected identifier or ?(? before ?{? token

argh.. thanks a lot.

> Signed-off-by: Andreas Kemnade <andreas at kemnade.info>

Reviewed-by: Marco Felsch <m.felsch at pengutronix.de>

> ---
>  include/mach/imx/bbu.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/mach/imx/bbu.h b/include/mach/imx/bbu.h
> index 451ae15740..50657d9895 100644
> --- a/include/mach/imx/bbu.h
> +++ b/include/mach/imx/bbu.h
> @@ -204,7 +204,7 @@ imx7_bbu_internal_spi_i2c_register_handler(const char *name, char *devicefile,
>  
>  static inline int
>  imx8m_bbu_internal_flexspi_nor_register_handler(const char *name, const char *devicefile,
> -						unsigned long flags);
> +						unsigned long flags)
>  {
>  	return -ENOSYS;
>  }
> -- 
> 2.39.2
> 
> 
> 


From a.fatoum at pengutronix.de  Fri Apr 21 03:06:38 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 21 Apr 2023 12:06:38 +0200
Subject: [PATCH 1/5] asm-generic: atomic: implement atomic_inc/dec_return stubs
In-Reply-To: <20230421100642.2867651-1-a.fatoum@pengutronix.de>
References: <20230421100642.2867651-1-a.fatoum@pengutronix.de>
Message-ID: <20230421100642.2867651-2-a.fatoum@pengutronix.de>

We don't have forced preemption in barebox, so we can implement these
functions with normal increment/decrement operators.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 include/asm-generic/atomic.h | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
index 6e63b8e8e7b9..45fc5da57594 100644
--- a/include/asm-generic/atomic.h
+++ b/include/asm-generic/atomic.h
@@ -77,16 +77,19 @@ static inline void atomic_sub(int i, volatile atomic_t *v)
 	v->counter -= i;
 }
 
-static inline void atomic_inc(volatile atomic_t *v)
+static inline int atomic_inc_return(volatile atomic_t *v)
 {
-	v->counter += 1;
+	return ++v->counter;
 }
 
-static inline void atomic_dec(volatile atomic_t *v)
+static inline int atomic_dec_return(volatile atomic_t *v)
 {
-	v->counter -= 1;
+	return --v->counter;
 }
 
+#define atomic_inc(v) ((void)atomic_inc_return(v))
+#define atomic_dec(v) ((void)atomic_dec_return(v))
+
 static inline int atomic_dec_and_test(volatile atomic_t *v)
 {
 	int val;
-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 21 03:06:37 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 21 Apr 2023 12:06:37 +0200
Subject: [PATCH 0/5] ARM: stm32mp: enable UBS hubs on DKx
Message-ID: <20230421100642.2867651-1-a.fatoum@pengutronix.de>

I am not sure this worked for a while, but the DT binding changed.
Let's sync with the kernel driver and enable the necessary config
options and some other stuff noticed as well.

Ahmad Fatoum (5):
  asm-generic: atomic: implement atomic_inc/dec_return stubs
  phy: stm32-usphyc: sync with Linux v6.3-rc5
  ARM: stm32mp: defconfig: enable use of DKx USB hubs
  clk: bulk: return -EPROBE_DEFER in silence
  ARM: stm32mp: dkx: enable deep probe

 arch/arm/boards/stm32mp15xx-dkx/board.c |   2 +
 arch/arm/configs/stm32mp_defconfig      |   3 +
 drivers/clk/clk-bulk.c                  |   5 +-
 drivers/phy/phy-stm32-usbphyc.c         | 321 ++++++++++++++++++++++--
 include/asm-generic/atomic.h            |  11 +-
 include/linux/units.h                   | 111 ++++++++
 6 files changed, 421 insertions(+), 32 deletions(-)
 create mode 100644 include/linux/units.h

-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 21 03:06:42 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 21 Apr 2023 12:06:42 +0200
Subject: [PATCH 5/5] ARM: stm32mp: dkx: enable deep probe
In-Reply-To: <20230421100642.2867651-1-a.fatoum@pengutronix.de>
References: <20230421100642.2867651-1-a.fatoum@pengutronix.de>
Message-ID: <20230421100642.2867651-6-a.fatoum@pengutronix.de>

This wasn't enabled before, because the USB parts needed some love to be
deep probe compatible. This has been done in the meantime, so let's
enable it. No functional change expected, except that probe deferral
shouldn't happen anymore.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/arm/boards/stm32mp15xx-dkx/board.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/boards/stm32mp15xx-dkx/board.c b/arch/arm/boards/stm32mp15xx-dkx/board.c
index b00781769ba5..1783c5ca17af 100644
--- a/arch/arm/boards/stm32mp15xx-dkx/board.c
+++ b/arch/arm/boards/stm32mp15xx-dkx/board.c
@@ -2,6 +2,7 @@
 #include <common.h>
 #include <init.h>
 #include <mach/stm32mp/bbu.h>
+#include <deep-probe.h>
 
 static int dkx_probe(struct device *dev)
 {
@@ -23,6 +24,7 @@ static const struct of_device_id dkx_of_match[] = {
 	{ .compatible = "st,stm32mp157c-dk2", .data = "STM32MP157C-DK2" },
 	{ /* sentinel */ },
 };
+BAREBOX_DEEP_PROBE_ENABLE(dkx_of_match);
 
 static struct driver dkx_board_driver = {
 	.name = "board-stm32mp15xx-dkx",
-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 21 03:06:40 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 21 Apr 2023 12:06:40 +0200
Subject: [PATCH 3/5] ARM: stm32mp: defconfig: enable use of DKx USB hubs
In-Reply-To: <20230421100642.2867651-1-a.fatoum@pengutronix.de>
References: <20230421100642.2867651-1-a.fatoum@pengutronix.de>
Message-ID: <20230421100642.2867651-4-a.fatoum@pengutronix.de>

The DK1/DK2 boards have an on-board USB-Hub with togglable power supply,
which is connected to the SoC's EHCI. Enable the necessary options to
make it usable. This was tested with the mass storage support (barebox
being host, not gadget), so enable that as well.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/arm/configs/stm32mp_defconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm/configs/stm32mp_defconfig b/arch/arm/configs/stm32mp_defconfig
index f6c6ca71b15c..df73102ba1c0 100644
--- a/arch/arm/configs/stm32mp_defconfig
+++ b/arch/arm/configs/stm32mp_defconfig
@@ -115,6 +115,9 @@ CONFIG_MTD_SST25L=y
 CONFIG_USB_HOST=y
 CONFIG_USB_DWC2_HOST=y
 CONFIG_USB_DWC2_GADGET=y
+CONFIG_USB_EHCI=y
+CONFIG_USB_STORAGE=y
+CONFIG_USB_ONBOARD_HUB=y
 CONFIG_USB_GADGET=y
 CONFIG_USB_GADGET_DFU=y
 CONFIG_USB_GADGET_SERIAL=y
-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 21 03:06:39 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 21 Apr 2023 12:06:39 +0200
Subject: [PATCH 2/5] phy: stm32-usphyc: sync with Linux v6.3-rc5
In-Reply-To: <20230421100642.2867651-1-a.fatoum@pengutronix.de>
References: <20230421100642.2867651-1-a.fatoum@pengutronix.de>
Message-ID: <20230421100642.2867651-3-a.fatoum@pengutronix.de>

DT binding changed in the meantime and the PHY is now clock provider
to the EHCI. Sync the driver to enable use of the EHCI.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/phy/phy-stm32-usbphyc.c | 321 +++++++++++++++++++++++++++++---
 include/linux/units.h           | 111 +++++++++++
 2 files changed, 406 insertions(+), 26 deletions(-)
 create mode 100644 include/linux/units.h

diff --git a/drivers/phy/phy-stm32-usbphyc.c b/drivers/phy/phy-stm32-usbphyc.c
index 3ccbc7b9027a..ac82b019f44c 100644
--- a/drivers/phy/phy-stm32-usbphyc.c
+++ b/drivers/phy/phy-stm32-usbphyc.c
@@ -14,11 +14,14 @@
 #include <linux/phy/phy.h>
 #include <linux/reset.h>
 #include <linux/math64.h>
+#include <asm-generic/atomic.h>
 #include <linux/usb/phy.h>
+#include <linux/units.h>
 
 #define STM32_USBPHYC_PLL	0x0
 #define STM32_USBPHYC_MISC	0x8
 #define STM32_USBPHYC_MONITOR(X) (0x108 + ((X) * 0x100))
+#define STM32_USBPHYC_TUNE(X)	(0x10C + ((X) * 0x100))
 #define STM32_USBPHYC_VERSION	0x3F4
 
 /* STM32_USBPHYC_PLL bit fields */
@@ -40,6 +43,83 @@
 #define STM32_USBPHYC_MON_SEL_LOCKP 0x1F
 #define STM32_USBPHYC_MON_OUT_LOCKP BIT(3)
 
+/* STM32_USBPHYC_TUNE bit fields */
+#define INCURREN		BIT(0)
+#define INCURRINT		BIT(1)
+#define LFSCAPEN		BIT(2)
+#define HSDRVSLEW		BIT(3)
+#define HSDRVDCCUR		BIT(4)
+#define HSDRVDCLEV		BIT(5)
+#define HSDRVCURINCR		BIT(6)
+#define FSDRVRFADJ		BIT(7)
+#define HSDRVRFRED		BIT(8)
+#define HSDRVCHKITRM		GENMASK(12, 9)
+#define HSDRVCHKZTRM		GENMASK(14, 13)
+#define OTPCOMP			GENMASK(19, 15)
+#define SQLCHCTL		GENMASK(21, 20)
+#define HDRXGNEQEN		BIT(22)
+#define HSRXOFF			GENMASK(24, 23)
+#define HSFALLPREEM		BIT(25)
+#define SHTCCTCTLPROT		BIT(26)
+#define STAGSEL			BIT(27)
+
+enum boosting_vals {
+	BOOST_1000_UA = 1000,
+	BOOST_2000_UA = 2000,
+};
+
+enum dc_level_vals {
+	DC_NOMINAL,
+	DC_PLUS_5_TO_7_MV,
+	DC_PLUS_10_TO_14_MV,
+	DC_MINUS_5_TO_7_MV,
+	DC_MAX,
+};
+
+enum current_trim {
+	CUR_NOMINAL,
+	CUR_PLUS_1_56_PCT,
+	CUR_PLUS_3_12_PCT,
+	CUR_PLUS_4_68_PCT,
+	CUR_PLUS_6_24_PCT,
+	CUR_PLUS_7_8_PCT,
+	CUR_PLUS_9_36_PCT,
+	CUR_PLUS_10_92_PCT,
+	CUR_PLUS_12_48_PCT,
+	CUR_PLUS_14_04_PCT,
+	CUR_PLUS_15_6_PCT,
+	CUR_PLUS_17_16_PCT,
+	CUR_PLUS_19_01_PCT,
+	CUR_PLUS_20_58_PCT,
+	CUR_PLUS_22_16_PCT,
+	CUR_PLUS_23_73_PCT,
+	CUR_MAX,
+};
+
+enum impedance_trim {
+	IMP_NOMINAL,
+	IMP_MINUS_2_OHMS,
+	IMP_MINUS_4_OMHS,
+	IMP_MINUS_6_OHMS,
+	IMP_MAX,
+};
+
+enum squelch_level {
+	SQLCH_NOMINAL,
+	SQLCH_PLUS_7_MV,
+	SQLCH_MINUS_5_MV,
+	SQLCH_PLUS_14_MV,
+	SQLCH_MAX,
+};
+
+enum rx_offset {
+	NO_RX_OFFSET,
+	RX_OFFSET_PLUS_5_MV,
+	RX_OFFSET_PLUS_10_MV,
+	RX_OFFSET_MINUS_5_MV,
+	RX_OFFSET_MAX,
+};
+
 /* STM32_USBPHYC_VERSION bit fields */
 #define MINREV			GENMASK(3, 0)
 #define MAJREV			GENMASK(7, 4)
@@ -47,7 +127,6 @@
 #define PLL_FVCO_MHZ		2880
 #define PLL_INFF_MIN_RATE_HZ	19200000
 #define PLL_INFF_MAX_RATE_HZ	38400000
-#define HZ_PER_MHZ		1000000L
 
 struct pll_params {
 	u8 ndiv;
@@ -57,30 +136,34 @@ struct pll_params {
 struct stm32_usbphyc_phy {
 	struct phy *phy;
 	struct stm32_usbphyc *usbphyc;
+	struct regulator *vbus;
 	u32 index;
 	bool active;
+	u32 tune;
 };
 
 struct stm32_usbphyc {
 	struct device *dev;
 	void __iomem *base;
 	struct clk *clk;
+	struct reset_control *rst;
 	struct stm32_usbphyc_phy **phys;
 	int nphys;
 	struct regulator *vdda1v1;
 	struct regulator *vdda1v8;
-	int n_pll_cons;
+	atomic_t n_pll_cons;
+	struct clk_hw clk48_hw;
 	int switch_setup;
 };
 
 static inline void stm32_usbphyc_set_bits(void __iomem *reg, u32 bits)
 {
-	writel(readl(reg) | bits, reg);
+	writel_relaxed(readl_relaxed(reg) | bits, reg);
 }
 
 static inline void stm32_usbphyc_clr_bits(void __iomem *reg, u32 bits)
 {
-	writel(readl(reg) & ~bits, reg);
+	writel_relaxed(readl_relaxed(reg) & ~bits, reg);
 }
 
 static int stm32_usbphyc_regulators_enable(struct stm32_usbphyc *usbphyc)
@@ -168,7 +251,7 @@ static int stm32_usbphyc_pll_init(struct stm32_usbphyc *usbphyc)
 	if (pll_params.frac)
 		usbphyc_pll |= PLLFRACCTL | frac;
 
-	writel(usbphyc_pll, usbphyc->base + STM32_USBPHYC_PLL);
+	writel_relaxed(usbphyc_pll, usbphyc->base + STM32_USBPHYC_PLL);
 
 	dev_dbg(usbphyc->dev, "input clk freq=%dHz, ndiv=%lu, frac=%lu\n",
 		clk_rate, FIELD_GET(PLLNDIV, usbphyc_pll),
@@ -185,7 +268,7 @@ static int __stm32_usbphyc_pll_disable(struct stm32_usbphyc *usbphyc)
 	stm32_usbphyc_clr_bits(pll_reg, PLLEN);
 
 	/* Wait for minimum width of powerdown pulse (ENABLE = Low) */
-	if (readl_poll_timeout(pll_reg, pllen, !(pllen & PLLEN), 50))
+	if (readl_relaxed_poll_timeout(pll_reg, pllen, !(pllen & PLLEN), 50))
 		dev_err(usbphyc->dev, "PLL not reset\n");
 
 	return stm32_usbphyc_regulators_disable(usbphyc);
@@ -194,7 +277,7 @@ static int __stm32_usbphyc_pll_disable(struct stm32_usbphyc *usbphyc)
 static int stm32_usbphyc_pll_disable(struct stm32_usbphyc *usbphyc)
 {
 	/* Check if a phy port is still active or clk48 in use */
-	if (--usbphyc->n_pll_cons > 0)
+	if (atomic_dec_return(&usbphyc->n_pll_cons) > 0)
 		return 0;
 
 	return __stm32_usbphyc_pll_disable(usbphyc);
@@ -203,14 +286,14 @@ static int stm32_usbphyc_pll_disable(struct stm32_usbphyc *usbphyc)
 static int stm32_usbphyc_pll_enable(struct stm32_usbphyc *usbphyc)
 {
 	void __iomem *pll_reg = usbphyc->base + STM32_USBPHYC_PLL;
-	bool pllen = readl(pll_reg) & PLLEN;
+	bool pllen = readl_relaxed(pll_reg) & PLLEN;
 	int ret;
 
 	/*
 	 * Check if a phy port or clk48 prepare has configured the pll
 	 * and ensure the PLL is enabled
 	 */
-	if (++usbphyc->n_pll_cons > 1 && pllen)
+	if (atomic_inc_return(&usbphyc->n_pll_cons) > 1 && pllen)
 		return 0;
 
 	if (pllen) {
@@ -222,7 +305,7 @@ static int stm32_usbphyc_pll_enable(struct stm32_usbphyc *usbphyc)
 
 		ret = __stm32_usbphyc_pll_disable(usbphyc);
 		if (ret)
-			return ret;
+			goto dec_n_pll_cons;
 	}
 
 	ret = stm32_usbphyc_regulators_enable(usbphyc);
@@ -241,7 +324,7 @@ reg_disable:
 	stm32_usbphyc_regulators_disable(usbphyc);
 
 dec_n_pll_cons:
-	usbphyc->n_pll_cons--;
+	atomic_dec(&usbphyc->n_pll_cons);
 
 	return ret;
 }
@@ -261,10 +344,10 @@ static int stm32_usbphyc_phy_init(struct phy *phy)
 		return ret;
 
 	/* Check that PLL Lock input to PHY is High */
-	writel(monsel, usbphyc->base + reg_mon);
-	ret = readl_poll_timeout(usbphyc->base + reg_mon, monout,
-				 (monout & STM32_USBPHYC_MON_OUT_LOCKP),
-				 1000);
+	writel_relaxed(monsel, usbphyc->base + reg_mon);
+	ret = readl_relaxed_poll_timeout(usbphyc->base + reg_mon, monout,
+					 (monout & STM32_USBPHYC_MON_OUT_LOCKP),
+					 1000);
 	if (ret) {
 		dev_err(usbphyc->dev, "PLL Lock input to PHY is Low (val=%x)\n",
 			(u32)(monout & STM32_USBPHYC_MON_OUT));
@@ -285,7 +368,9 @@ static int stm32_usbphyc_phy_init(struct phy *phy)
 	return 0;
 
 pll_disable:
-	return stm32_usbphyc_pll_disable(usbphyc);
+	stm32_usbphyc_pll_disable(usbphyc);
+
+	return ret;
 }
 
 static int stm32_usbphyc_phy_exit(struct phy *phy)
@@ -298,11 +383,177 @@ static int stm32_usbphyc_phy_exit(struct phy *phy)
 	return stm32_usbphyc_pll_disable(usbphyc);
 }
 
+static int stm32_usbphyc_phy_power_on(struct phy *phy)
+{
+	struct stm32_usbphyc_phy *usbphyc_phy = phy_get_drvdata(phy);
+
+	if (usbphyc_phy->vbus)
+		return regulator_enable(usbphyc_phy->vbus);
+
+	return 0;
+}
+
+static int stm32_usbphyc_phy_power_off(struct phy *phy)
+{
+	struct stm32_usbphyc_phy *usbphyc_phy = phy_get_drvdata(phy);
+
+	if (usbphyc_phy->vbus)
+		return regulator_disable(usbphyc_phy->vbus);
+
+	return 0;
+}
+
 static const struct phy_ops stm32_usbphyc_phy_ops = {
 	.init = stm32_usbphyc_phy_init,
 	.exit = stm32_usbphyc_phy_exit,
+	.power_on = stm32_usbphyc_phy_power_on,
+	.power_off = stm32_usbphyc_phy_power_off,
 };
 
+static int stm32_usbphyc_clk48_prepare(struct clk_hw *hw)
+{
+	struct stm32_usbphyc *usbphyc = container_of(hw, struct stm32_usbphyc, clk48_hw);
+
+	return stm32_usbphyc_pll_enable(usbphyc);
+}
+
+static void stm32_usbphyc_clk48_unprepare(struct clk_hw *hw)
+{
+	struct stm32_usbphyc *usbphyc = container_of(hw, struct stm32_usbphyc, clk48_hw);
+
+	stm32_usbphyc_pll_disable(usbphyc);
+}
+
+static unsigned long stm32_usbphyc_clk48_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
+{
+	return 48000000;
+}
+
+static const struct clk_ops usbphyc_clk48_ops = {
+	.enable = stm32_usbphyc_clk48_prepare,
+	.disable = stm32_usbphyc_clk48_unprepare,
+	.recalc_rate = stm32_usbphyc_clk48_recalc_rate,
+};
+
+static int stm32_usbphyc_clk48_register(struct stm32_usbphyc *usbphyc)
+{
+	struct device_node *node = usbphyc->dev->of_node;
+	struct clk_init_data init = { };
+	int ret = 0;
+
+	init.name = "ck_usbo_48m";
+	init.ops = &usbphyc_clk48_ops;
+
+	usbphyc->clk48_hw.init = &init;
+
+	ret = clk_hw_register(usbphyc->dev, &usbphyc->clk48_hw);
+	if (ret)
+		return ret;
+
+	return of_clk_add_hw_provider(node, of_clk_hw_simple_get, &usbphyc->clk48_hw);
+}
+
+static void stm32_usbphyc_phy_tuning(struct stm32_usbphyc *usbphyc,
+				     struct device_node *np, u32 index)
+{
+	struct stm32_usbphyc_phy *usbphyc_phy = usbphyc->phys[index];
+	u32 reg = STM32_USBPHYC_TUNE(index);
+	u32 otpcomp, val;
+	int ret;
+
+	/* Backup OTP compensation code */
+	otpcomp = FIELD_GET(OTPCOMP, readl_relaxed(usbphyc->base + reg));
+
+	ret = of_property_read_u32(np, "st,current-boost-microamp", &val);
+	if (ret != -EINVAL) {
+		if (!ret && (val == BOOST_1000_UA || val == BOOST_2000_UA)) {
+			val = (val == BOOST_2000_UA) ? 1 : 0;
+			usbphyc_phy->tune |= INCURREN | FIELD_PREP(INCURRINT, val);
+		} else {
+			dev_warn(usbphyc->dev, "phy%d: invalid st,current-boost-microamp\n", index);
+		}
+	}
+
+	if (!of_property_read_bool(np, "st,no-lsfs-fb-cap"))
+		usbphyc_phy->tune |= LFSCAPEN;
+
+	if (of_property_read_bool(np, "st,decrease-hs-slew-rate"))
+		usbphyc_phy->tune |= HSDRVSLEW;
+
+	ret = of_property_read_u32(np, "st,tune-hs-dc-level", &val);
+	if (ret != -EINVAL) {
+		if (!ret && val < DC_MAX) {
+			if (val == DC_MINUS_5_TO_7_MV) {/* Decreases HS driver DC level */
+				usbphyc_phy->tune |= HSDRVDCCUR;
+			} else if (val > 0) {		/* Increases HS driver DC level */
+				val = (val == DC_PLUS_10_TO_14_MV) ? 1 : 0;
+				usbphyc_phy->tune |= HSDRVCURINCR | FIELD_PREP(HSDRVDCLEV, val);
+			}
+		} else {
+			dev_warn(usbphyc->dev, "phy%d: invalid st,tune-hs-dc-level\n", index);
+		}
+	}
+
+	if (of_property_read_bool(np, "st,enable-fs-rftime-tuning"))
+		usbphyc_phy->tune |= FSDRVRFADJ;
+
+	if (of_property_read_bool(np, "st,enable-hs-rftime-reduction"))
+		usbphyc_phy->tune |= HSDRVRFRED;
+
+	ret = of_property_read_u32(np, "st,trim-hs-current", &val);
+	if (ret != -EINVAL) {
+		if (!ret && val < CUR_MAX)
+			usbphyc_phy->tune |= FIELD_PREP(HSDRVCHKITRM, val);
+		else
+			dev_warn(usbphyc->dev, "phy%d: invalid st,trim-hs-current\n", index);
+	}
+
+	ret = of_property_read_u32(np, "st,trim-hs-impedance", &val);
+	if (ret != -EINVAL) {
+		if (!ret && val < IMP_MAX)
+			usbphyc_phy->tune |= FIELD_PREP(HSDRVCHKZTRM, val);
+		else
+			dev_warn(usbphyc->dev, "phy%d: invalid st,trim-hs-impedance\n", index);
+	}
+
+	ret = of_property_read_u32(np, "st,tune-squelch-level", &val);
+	if (ret != -EINVAL) {
+		if (!ret && val < SQLCH_MAX)
+			usbphyc_phy->tune |= FIELD_PREP(SQLCHCTL, val);
+		else
+			dev_warn(usbphyc->dev, "phy%d: invalid st,tune-squelch\n", index);
+	}
+
+	if (of_property_read_bool(np, "st,enable-hs-rx-gain-eq"))
+		usbphyc_phy->tune |= HDRXGNEQEN;
+
+	ret = of_property_read_u32(np, "st,tune-hs-rx-offset", &val);
+	if (ret != -EINVAL) {
+		if (!ret && val < RX_OFFSET_MAX)
+			usbphyc_phy->tune |= FIELD_PREP(HSRXOFF, val);
+		else
+			dev_warn(usbphyc->dev, "phy%d: invalid st,tune-hs-rx-offset\n", index);
+	}
+
+	if (of_property_read_bool(np, "st,no-hs-ftime-ctrl"))
+		usbphyc_phy->tune |= HSFALLPREEM;
+
+	if (!of_property_read_bool(np, "st,no-lsfs-sc"))
+		usbphyc_phy->tune |= SHTCCTCTLPROT;
+
+	if (of_property_read_bool(np, "st,enable-hs-tx-staggering"))
+		usbphyc_phy->tune |= STAGSEL;
+
+	/* Restore OTP compensation code */
+	usbphyc_phy->tune |= FIELD_PREP(OTPCOMP, otpcomp);
+
+	/*
+	 * By default, if no st,xxx tuning property is used, usbphyc_phy->tune is equal to
+	 * STM32_USBPHYC_TUNE reset value (LFSCAPEN | SHTCCTCTLPROT | OTPCOMP).
+	 */
+	writel_relaxed(usbphyc_phy->tune, usbphyc->base + reg);
+}
+
 static void stm32_usbphyc_switch_setup(struct stm32_usbphyc *usbphyc,
 				       u32 utmi_switch)
 {
@@ -399,8 +650,8 @@ static int stm32_usbphyc_probe(struct device *dev)
 	 * Wait for minimum width of powerdown pulse (ENABLE = Low):
 	 * we have to ensure the PLL is disabled before phys initialization.
 	 */
-	if (readl_poll_timeout(usbphyc->base + STM32_USBPHYC_PLL,
-			       pllen, !(pllen & PLLEN), 50)) {
+	if (readl_relaxed_poll_timeout(usbphyc->base + STM32_USBPHYC_PLL,
+				       pllen, !(pllen & PLLEN), 50)) {
 		dev_warn(usbphyc->dev, "PLL not reset\n");
 		ret = -EPROBE_DEFER;
 		goto clk_disable;
@@ -416,17 +667,15 @@ static int stm32_usbphyc_probe(struct device *dev)
 
 	usbphyc->vdda1v1 = regulator_get(dev, "vdda1v1");
 	if (IS_ERR(usbphyc->vdda1v1)) {
-		ret = PTR_ERR(usbphyc->vdda1v1);
-		if (ret != -EPROBE_DEFER)
-			dev_err(dev, "failed to get vdda1v1 supply: %d\n", ret);
+		ret = dev_err_probe(dev, PTR_ERR(usbphyc->vdda1v1),
+				    "failed to get vdda1v1 supply\n");
 		goto clk_disable;
 	}
 
 	usbphyc->vdda1v8 = regulator_get(dev, "vdda1v8");
 	if (IS_ERR(usbphyc->vdda1v8)) {
-		ret = PTR_ERR(usbphyc->vdda1v8);
-		if (ret != -EPROBE_DEFER)
-			dev_err(dev, "failed to get vdda1v8 supply: %d\n", ret);
+		ret = dev_err_probe(dev, PTR_ERR(usbphyc->vdda1v8),
+				    "failed to get vdda1v8 supply\n");
 		goto clk_disable;
 	}
 
@@ -456,6 +705,8 @@ static int stm32_usbphyc_probe(struct device *dev)
 		ret = of_property_read_u32(child, "reg", &index);
 		if (ret || index > usbphyc->nphys) {
 			dev_err(&phy->dev, "invalid reg property: %d\n", ret);
+			if (!ret)
+				ret = -EINVAL;
 			goto clk_disable;
 		}
 
@@ -468,6 +719,17 @@ static int stm32_usbphyc_probe(struct device *dev)
 		usbphyc->phys[port]->index = index;
 		usbphyc->phys[port]->active = false;
 
+		usbphyc->phys[port]->vbus = regulator_get(&phy->dev, "vbus");
+		if (IS_ERR(usbphyc->phys[port]->vbus)) {
+			ret = PTR_ERR(usbphyc->phys[port]->vbus);
+			if (ret == -EPROBE_DEFER)
+				goto clk_disable;
+			usbphyc->phys[port]->vbus = NULL;
+		}
+
+		/* Configure phy tuning */
+		stm32_usbphyc_phy_tuning(usbphyc, child, index);
+
 		port++;
 	}
 
@@ -478,8 +740,14 @@ static int stm32_usbphyc_probe(struct device *dev)
 		goto clk_disable;
 	}
 
-	version = readl(usbphyc->base + STM32_USBPHYC_VERSION);
-	dev_info(dev, "registered rev: %lu.%lu\n",
+	ret = stm32_usbphyc_clk48_register(usbphyc);
+	if (ret) {
+		dev_err(dev, "failed to register ck_usbo_48m clock: %d\n", ret);
+		goto clk_disable;
+	}
+
+	version = readl_relaxed(usbphyc->base + STM32_USBPHYC_VERSION);
+	dev_info(dev, "registered rev:%lu.%lu\n",
 		 FIELD_GET(MAJREV, version), FIELD_GET(MINREV, version));
 
 	return 0;
@@ -512,6 +780,7 @@ static const struct of_device_id stm32_usbphyc_of_match[] = {
 	{ .compatible = "st,stm32mp1-usbphyc", },
 	{ /* sentinel */ },
 };
+MODULE_DEVICE_TABLE(of, stm32_usbphyc_of_match);
 
 static struct driver stm32_usbphyc_driver = {
 	.name = "stm32-usbphyc",
diff --git a/include/linux/units.h b/include/linux/units.h
new file mode 100644
index 000000000000..120a2fc87b13
--- /dev/null
+++ b/include/linux/units.h
@@ -0,0 +1,111 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_UNITS_H
+#define _LINUX_UNITS_H
+
+#include <linux/kernel.h>
+
+/* Metric prefixes in accordance with Syst?me international (d'unit?s) */
+#define PETA	1000000000000000ULL
+#define TERA	1000000000000ULL
+#define GIGA	1000000000UL
+#define MEGA	1000000UL
+#define KILO	1000UL
+#define HECTO	100UL
+#define DECA	10UL
+#define DECI	10UL
+#define CENTI	100UL
+#define MILLI	1000UL
+#define MICRO	1000000UL
+#define NANO	1000000000UL
+#define PICO	1000000000000ULL
+#define FEMTO	1000000000000000ULL
+
+#define NANOHZ_PER_HZ		1000000000UL
+#define MICROHZ_PER_HZ		1000000UL
+#define MILLIHZ_PER_HZ		1000UL
+#define HZ_PER_KHZ		1000UL
+#define KHZ_PER_MHZ		1000UL
+#define HZ_PER_MHZ		1000000UL
+
+#define MILLIWATT_PER_WATT	1000UL
+#define MICROWATT_PER_MILLIWATT	1000UL
+#define MICROWATT_PER_WATT	1000000UL
+
+#define ABSOLUTE_ZERO_MILLICELSIUS -273150
+
+static inline long milli_kelvin_to_millicelsius(long t)
+{
+	return t + ABSOLUTE_ZERO_MILLICELSIUS;
+}
+
+static inline long millicelsius_to_milli_kelvin(long t)
+{
+	return t - ABSOLUTE_ZERO_MILLICELSIUS;
+}
+
+#define MILLIDEGREE_PER_DEGREE 1000
+#define MILLIDEGREE_PER_DECIDEGREE 100
+
+static inline long kelvin_to_millicelsius(long t)
+{
+	return milli_kelvin_to_millicelsius(t * MILLIDEGREE_PER_DEGREE);
+}
+
+static inline long millicelsius_to_kelvin(long t)
+{
+	t = millicelsius_to_milli_kelvin(t);
+
+	return DIV_ROUND_CLOSEST(t, MILLIDEGREE_PER_DEGREE);
+}
+
+static inline long deci_kelvin_to_celsius(long t)
+{
+	t = milli_kelvin_to_millicelsius(t * MILLIDEGREE_PER_DECIDEGREE);
+
+	return DIV_ROUND_CLOSEST(t, MILLIDEGREE_PER_DEGREE);
+}
+
+static inline long celsius_to_deci_kelvin(long t)
+{
+	t = millicelsius_to_milli_kelvin(t * MILLIDEGREE_PER_DEGREE);
+
+	return DIV_ROUND_CLOSEST(t, MILLIDEGREE_PER_DECIDEGREE);
+}
+
+/**
+ * deci_kelvin_to_millicelsius_with_offset - convert Kelvin to Celsius
+ * @t: temperature value in decidegrees Kelvin
+ * @offset: difference between Kelvin and Celsius in millidegrees
+ *
+ * Return: temperature value in millidegrees Celsius
+ */
+static inline long deci_kelvin_to_millicelsius_with_offset(long t, long offset)
+{
+	return t * MILLIDEGREE_PER_DECIDEGREE - offset;
+}
+
+static inline long deci_kelvin_to_millicelsius(long t)
+{
+	return milli_kelvin_to_millicelsius(t * MILLIDEGREE_PER_DECIDEGREE);
+}
+
+static inline long millicelsius_to_deci_kelvin(long t)
+{
+	t = millicelsius_to_milli_kelvin(t);
+
+	return DIV_ROUND_CLOSEST(t, MILLIDEGREE_PER_DECIDEGREE);
+}
+
+static inline long kelvin_to_celsius(long t)
+{
+	return t + DIV_ROUND_CLOSEST(ABSOLUTE_ZERO_MILLICELSIUS,
+				     MILLIDEGREE_PER_DEGREE);
+}
+
+static inline long celsius_to_kelvin(long t)
+{
+	return t - DIV_ROUND_CLOSEST(ABSOLUTE_ZERO_MILLICELSIUS,
+				     MILLIDEGREE_PER_DEGREE);
+}
+
+#endif /* _LINUX_UNITS_H */
-- 
2.39.2



From a.fatoum at pengutronix.de  Fri Apr 21 03:06:41 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 21 Apr 2023 12:06:41 +0200
Subject: [PATCH 4/5] clk: bulk: return -EPROBE_DEFER in silence
In-Reply-To: <20230421100642.2867651-1-a.fatoum@pengutronix.de>
References: <20230421100642.2867651-1-a.fatoum@pengutronix.de>
Message-ID: <20230421100642.2867651-5-a.fatoum@pengutronix.de>

-EPROBE_DEFER is only an error if driver core doesn't expect it. Change
it, so error message is only printed for other kinds of errors.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/clk/clk-bulk.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/clk-bulk.c b/drivers/clk/clk-bulk.c
index 37982db9aa55..db775dc40b39 100644
--- a/drivers/clk/clk-bulk.c
+++ b/drivers/clk/clk-bulk.c
@@ -88,8 +88,9 @@ static int __must_check of_clk_bulk_get(struct device_node *np, int num_clks,
 		clks[i].clk = of_clk_get(np, i);
 		if (IS_ERR(clks[i].clk)) {
 			ret = PTR_ERR(clks[i].clk);
-			pr_err("%s: Failed to get clk index: %d ret: %pe\n",
-				np->name, i, clks[i].clk);
+			if (ret != -EPROBE_DEFER)
+				pr_err("%s: Failed to get clk index: %d ret: %pe\n",
+				       np->name, i, clks[i].clk);
 			clks[i].clk = NULL;
 			goto err;
 		}
-- 
2.39.2



From m.felsch at pengutronix.de  Fri Apr 21 03:36:57 2023
From: m.felsch at pengutronix.de (Marco Felsch)
Date: Fri, 21 Apr 2023 12:36:57 +0200
Subject: [PATCH 3/5] ARM: stm32mp: defconfig: enable use of DKx USB hubs
In-Reply-To: <20230421100642.2867651-4-a.fatoum@pengutronix.de>
References: <20230421100642.2867651-1-a.fatoum@pengutronix.de>
 <20230421100642.2867651-4-a.fatoum@pengutronix.de>
Message-ID: <20230421103657.bhety2z5srjrzhqa@pengutronix.de>

Hi Ahmad,

On 23-04-21, Ahmad Fatoum wrote:
> The DK1/DK2 boards have an on-board USB-Hub with togglable power supply,
> which is connected to the SoC's EHCI. Enable the necessary options to
> make it usable. This was tested with the mass storage support (barebox
> being host, not gadget), so enable that as well.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  arch/arm/configs/stm32mp_defconfig | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/arch/arm/configs/stm32mp_defconfig b/arch/arm/configs/stm32mp_defconfig
> index f6c6ca71b15c..df73102ba1c0 100644
> --- a/arch/arm/configs/stm32mp_defconfig
> +++ b/arch/arm/configs/stm32mp_defconfig
> @@ -115,6 +115,9 @@ CONFIG_MTD_SST25L=y
>  CONFIG_USB_HOST=y
>  CONFIG_USB_DWC2_HOST=y
>  CONFIG_USB_DWC2_GADGET=y
> +CONFIG_USB_EHCI=y
> +CONFIG_USB_STORAGE=y
> +CONFIG_USB_ONBOARD_HUB=y

While USB_EHCI and USB_STORAGE is already part of the the
mulit_v7_defconfig, USB_ONBOARD_HUB isn't. Can you please enable it
there as well?

Regards,
  Marco

>  CONFIG_USB_GADGET=y
>  CONFIG_USB_GADGET_DFU=y
>  CONFIG_USB_GADGET_SERIAL=y
> -- 
> 2.39.2
> 
> 
> 


From a.fatoum at pengutronix.de  Fri Apr 21 03:51:30 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 21 Apr 2023 12:51:30 +0200
Subject: [PATCH 3/5] ARM: stm32mp: defconfig: enable use of DKx USB hubs
In-Reply-To: <20230421103657.bhety2z5srjrzhqa@pengutronix.de>
References: <20230421100642.2867651-1-a.fatoum@pengutronix.de>
 <20230421100642.2867651-4-a.fatoum@pengutronix.de>
 <20230421103657.bhety2z5srjrzhqa@pengutronix.de>
Message-ID: <487ad019-b97d-39bd-cf2c-8a81c0fcdc2c@pengutronix.de>

Hello Marco,

On 21.04.23 12:36, Marco Felsch wrote:
> Hi Ahmad,
> 
> On 23-04-21, Ahmad Fatoum wrote:
>> The DK1/DK2 boards have an on-board USB-Hub with togglable power supply,
>> which is connected to the SoC's EHCI. Enable the necessary options to
>> make it usable. This was tested with the mass storage support (barebox
>> being host, not gadget), so enable that as well.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
>> ---
>>  arch/arm/configs/stm32mp_defconfig | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/arch/arm/configs/stm32mp_defconfig b/arch/arm/configs/stm32mp_defconfig
>> index f6c6ca71b15c..df73102ba1c0 100644
>> --- a/arch/arm/configs/stm32mp_defconfig
>> +++ b/arch/arm/configs/stm32mp_defconfig
>> @@ -115,6 +115,9 @@ CONFIG_MTD_SST25L=y
>>  CONFIG_USB_HOST=y
>>  CONFIG_USB_DWC2_HOST=y
>>  CONFIG_USB_DWC2_GADGET=y
>> +CONFIG_USB_EHCI=y
>> +CONFIG_USB_STORAGE=y
>> +CONFIG_USB_ONBOARD_HUB=y
> 
> While USB_EHCI and USB_STORAGE is already part of the the
> mulit_v7_defconfig, USB_ONBOARD_HUB isn't. Can you please enable it
> there as well?

I just sent a separate patch to that effect.

Cheers,
Ahmad

> 
> Regards,
>   Marco
> 
>>  CONFIG_USB_GADGET=y
>>  CONFIG_USB_GADGET_DFU=y
>>  CONFIG_USB_GADGET_SERIAL=y
>> -- 
>> 2.39.2
>>
>>
>>
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



From a.fatoum at pengutronix.de  Fri Apr 21 03:41:40 2023
From: a.fatoum at pengutronix.de (Ahmad Fatoum)
Date: Fri, 21 Apr 2023 12:41:40 +0200
Subject: [PATCH] ARM: configs: multi_v7_defconfig: enable CONFIG_USB_ONBOARD_HUB
Message-ID: <20230421104140.2879999-1-a.fatoum@pengutronix.de>

This is needed for at least the STM32MP1 discovery and evaluation kits,
which use the onboard USB hub binding to model the 3v3 voltage regulator
supplying the on-board USB hub.

Suggested-by: Marco Felsch <m.felsch at pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 arch/arm/configs/multi_v7_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/multi_v7_defconfig b/arch/arm/configs/multi_v7_defconfig
index d83e503671d9..f8eca18ff30c 100644
--- a/arch/arm/configs/multi_v7_defconfig
+++ b/arch/arm/configs/multi_v7_defconfig
@@ -254,6 +254,7 @@ CONFIG_USB_DWC2_GADGET=y
 CONFIG_USB_EHCI=y
 CONFIG_USB_ULPI=y
 CONFIG_USB_STORAGE=y
+CONFIG_USB_ONBOARD_HUB=y
 CONFIG_USB_GADGET=y
 CONFIG_USB_GADGET_DFU=y
 CONFIG_USB_GADGET_SERIAL=y
-- 
2.39.2



From ahmad at a3f.at  Mon Apr 24 04:55:48 2023
From: ahmad at a3f.at (Ahmad Fatoum)
Date: Mon, 24 Apr 2023 13:55:48 +0200
Subject: [PATCH 2/2] treewide: use non-executable stack annotations for blobs
In-Reply-To: <20230424115548.114858-1-ahmad@a3f.at>
References: <20230424115548.114858-1-ahmad@a3f.at>
Message-ID: <20230424115548.114858-2-ahmad@a3f.at>

We are building the non-sandbox platforms with -z noexecstack, because
the ELF section attributes don't matter. This is different for sandbox,
where we compile assembly files directly only for embedding blobs.
This currently yields a build warning:

  binutils-2.39/bin/ld: warning: defaultenv/defaultenv-2-reboot-mode.bbenv.gz.o:
          missing .note.GNU-stack section implies executable stack
  binutils-2.39/bin/ld: NOTE: This behaviour is deprecated and will be removed
          in a future version of the linker

Let's add the non-executable stack annotations, so sandbox may run with
non-executable stack. This way we are left with a single linker
warning that needs to be resolved:

   binutils-2.39/bin/ld: warning: barebox has a LOAD segment with RWX permissions

Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
---
 lib/logo/Makefile    | 1 +
 scripts/Makefile.lib | 2 ++
 scripts/gen-dtb-s    | 1 +
 scripts/gen-dtbo-s   | 1 +
 4 files changed, 5 insertions(+)

diff --git a/lib/logo/Makefile b/lib/logo/Makefile
index 382701fb365c..9c14105e88bf 100644
--- a/lib/logo/Makefile
+++ b/lib/logo/Makefile
@@ -26,6 +26,7 @@ quiet_cmd_logo_S = LOGO.S  $@
 cmd_logo_S =							\
 (								\
 	echo '\#include <asm/barebox.lds.h>';			\
+	echo '.section .note.GNU-stack,"",%progbits';		\
 	echo '.section .bblogo.rodata.$(subst -,_,$(*F)),"a"';	\
 	echo '.balign STRUCT_ALIGNMENT';			\
 	echo '.global __bblogo_$(subst -,_,$(*F))_start';	\
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 51beff56aeb8..90cfa579e5d5 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -391,6 +391,7 @@ quiet_cmd_env_S = ENV.S   $@
 cmd_env_S =							\
 (								\
 	echo '\#include <asm/barebox.lds.h>';			\
+	echo '.section .note.GNU-stack,"",%progbits';		\
 	echo '.section .bbenv.rodata.$(subst -,_,$(*F)),"a"';	\
 	echo '.balign STRUCT_ALIGNMENT';			\
 	echo '.global __bbenv_$(subst -,_,$(*F))_start';	\
@@ -540,6 +541,7 @@ quiet_cmd_imximage__S_dcd= DCD_S   $@
 cmd_imximage_S_dcd=						\
 (								\
 	echo '\#include <asm/barebox.lds.h>';			\
+	echo '.section .note.GNU-stack,"",%progbits';		\
 	echo '.balign STRUCT_ALIGNMENT';			\
 	echo '.global $(subst -,_,$(*F))_start';		\
 	echo '$(subst -,_,$(*F))_start:';			\
diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
index f6fa1525933e..d6fbdd5aaf8a 100755
--- a/scripts/gen-dtb-s
+++ b/scripts/gen-dtb-s
@@ -6,6 +6,7 @@ imd=$3
 
 echo "#include <asm/barebox.lds.h>"
 echo "#include <asm-generic/pointer.h>"
+echo ".section .note.GNU-stack,\"\",%progbits"
 
 le32() {
 	printf ".byte 0x%02x, 0x%02x, 0x%02x, 0x%02x\n" \
diff --git a/scripts/gen-dtbo-s b/scripts/gen-dtbo-s
index 06f78609ed28..a7e272a0890d 100755
--- a/scripts/gen-dtbo-s
+++ b/scripts/gen-dtbo-s
@@ -4,6 +4,7 @@ name=$1
 dtbo=$2
 
 echo "#include <asm/barebox.lds.h>"
+echo ".section .note.GNU-stack,\"\",%progbits"
 
 echo ".section .dtb.rodata.${name}_dtbo,\"a\""
 echo ".balign STRUCT_ALIGNMENT"
-- 
2.38.4



From ahmad at a3f.at  Mon Apr 24 04:55:47 2023
From: ahmad at a3f.at (Ahmad Fatoum)
Date: Mon, 24 Apr 2023 13:55:47 +0200
Subject: [PATCH 1/2] test: self: printf: compile test with -Wno-format-security
Message-ID: <20230424115548.114858-1-ahmad@a3f.at>

For testing purposes, the test code uses a variable for the format
string at places, which -Wformat-security doesn't like.

The printf test was copied over from the kernel, which sets
-Wno-format-security globally. This may not be needed for barebox yet,
but let's set at least for this one file.

Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
---
 test/self/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/test/self/Makefile b/test/self/Makefile
index d55d9133be23..98ebd1fd66c1 100644
--- a/test/self/Makefile
+++ b/test/self/Makefile
@@ -3,6 +3,7 @@
 obj-$(CONFIG_SELFTEST) += core.o
 obj-$(CONFIG_SELFTEST_MALLOC) += malloc.o
 obj-$(CONFIG_SELFTEST_PRINTF) += printf.o
+CFLAGS_printf.o += -Wno-format-security
 obj-$(CONFIG_SELFTEST_PROGRESS_NOTIFIER) += progress-notifier.o
 obj-$(CONFIG_SELFTEST_OF_MANIPULATION) += of_manipulation.o of_manipulation.dtb.o
 obj-$(CONFIG_SELFTEST_ENVIRONMENT_VARIABLES) += envvar.o
-- 
2.38.4



From ahmad at a3f.at  Mon Apr 24 04:59:07 2023
From: ahmad at a3f.at (Ahmad Fatoum)
Date: Mon, 24 Apr 2023 13:59:07 +0200
Subject: [PATCH 1/2] regulator: core: add debug print for regulator_resolve_supply
Message-ID: <20230424115908.115474-1-ahmad@a3f.at>

Starting with commit 324bd9bbe7e8 ("regulator: recursively enable/disable
regulator dependency tree"), regulator operations may affect more than
just the one regulator being enabled. Place a debug print, so it's
easier to follow the dependency chain.

Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
---
 drivers/regulator/core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 3eb4746fb757..97f359d6d29f 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -141,6 +141,8 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
 	if (!supply_name)
 		return 0;
 
+	dev_dbg(rdev->dev, "resolving %s\n", supply_name);
+
 	supply = regulator_get(rdev->dev, supply_name);
 	if (IS_ERR(supply)) {
 		if (deep_probe_is_supported())
-- 
2.38.4



From ahmad at a3f.at  Mon Apr 24 04:59:08 2023
From: ahmad at a3f.at (Ahmad Fatoum)
Date: Mon, 24 Apr 2023 13:59:08 +0200
Subject: [PATCH 2/2] test: self: add basic regulator selftest
In-Reply-To: <20230424115908.115474-1-ahmad@a3f.at>
References: <20230424115908.115474-1-ahmad@a3f.at>
Message-ID: <20230424115908.115474-2-ahmad@a3f.at>

This simple test verifies registration and always-on enabling and disabling
work as they should. It may be extended in future to support more
complex cases.

Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
---
 test/self/Kconfig             |   5 +
 test/self/Makefile            |   1 +
 test/self/regulator.c         | 188 ++++++++++++++++++++++++++++++++++
 test/self/test_regulator.dtso |  43 ++++++++
 4 files changed, 237 insertions(+)
 create mode 100644 test/self/regulator.c
 create mode 100644 test/self/test_regulator.dtso

diff --git a/test/self/Kconfig b/test/self/Kconfig
index ce5048c70ec9..ea436aa34664 100644
--- a/test/self/Kconfig
+++ b/test/self/Kconfig
@@ -36,6 +36,7 @@ config SELFTEST_ENABLE_ALL
 	imply SELFTEST_FS_RAMFS
 	imply SELFTEST_TFTP
 	imply SELFTEST_JSON
+	imply SELFTEST_REGULATOR
 	help
 	  Selects all self-tests compatible with current configuration
 
@@ -69,4 +70,8 @@ config SELFTEST_JSON
 	bool "JSON selftest"
 	depends on JSMN
 
+config SELFTEST_REGULATOR
+	bool "Regulator selftest"
+	depends on REGULATOR && OFDEVICE
+
 endif
diff --git a/test/self/Makefile b/test/self/Makefile
index 98ebd1fd66c1..a5dc1531dc11 100644
--- a/test/self/Makefile
+++ b/test/self/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_SELFTEST_OF_MANIPULATION) += of_manipulation.o of_manipulation.dtb.
 obj-$(CONFIG_SELFTEST_ENVIRONMENT_VARIABLES) += envvar.o
 obj-$(CONFIG_SELFTEST_FS_RAMFS) += ramfs.o
 obj-$(CONFIG_SELFTEST_JSON) += json.o
+obj-$(CONFIG_SELFTEST_REGULATOR) += regulator.o test_regulator.dtbo.o
 
 clean-files := *.dtb *.dtb.S .*.dtc .*.pre .*.dts *.dtb.z
 clean-files += *.dtbo *.dtbo.S .*.dtso
diff --git a/test/self/regulator.c b/test/self/regulator.c
new file mode 100644
index 000000000000..cfbfd0490385
--- /dev/null
+++ b/test/self/regulator.c
@@ -0,0 +1,188 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#define DEBUG 1
+#include <common.h>
+#include <bselftest.h>
+#include <driver.h>
+#include <of.h>
+#include <regulator.h>
+#include <linux/regulator/of_regulator.h>
+
+struct test_regulator {
+	struct device *dev;
+};
+
+struct test_regulator_cfg {
+	struct regulator_desc desc;
+	struct regulator_dev rdev;
+};
+
+BSELFTEST_GLOBALS();
+
+static bool __ok(bool cond, const char *func, int line)
+{
+	total_tests++;
+	if (!cond) {
+		failed_tests++;
+		printf("%s:%d: assertion failure\n", func, line);
+		return false;
+	}
+
+	return true;
+}
+
+#define ok(cond) \
+	__ok(cond, __func__, __LINE__)
+
+static void test_regulator_selfref_always_on(struct device *dev)
+{
+	ok(1 == 1);
+}
+
+static int test_regulator_enable_noop(struct regulator_dev *rdev)
+{
+	dev_dbg(rdev->dev, "enabling %s-supply\n", rdev->desc->supply_name);
+	failed_tests--;
+	return 0;
+}
+
+static int test_regulator_disable_noop(struct regulator_dev *rdev)
+{
+	dev_dbg(rdev->dev, "disabling %s-supply\n", rdev->desc->supply_name);
+	failed_tests--;
+	return 0;
+}
+
+static const struct regulator_ops test_regulator_ops_range = {
+	.enable		= test_regulator_enable_noop,
+	.disable	= test_regulator_disable_noop,
+};
+
+enum {
+	/*
+	 * This is intentionally ordered that way to test registering
+	 * an always-on regulator before its sibling that it depends on
+	 */
+	TEST_LDO1,
+	TEST_BUCK,
+	TEST_LDO2,
+	TEST_REGULATORS_NUM
+};
+
+static struct test_regulator_cfg test_pmic_reg[] = {
+	[TEST_BUCK] = {{
+		 .supply_name = "buck",
+		 .ops = &test_regulator_ops_range,
+	}},
+	[TEST_LDO1] = {{
+		 .supply_name = "ldo1",
+		 .ops = &test_regulator_ops_range,
+	}},
+	[TEST_LDO2] = {{
+		.supply_name = "ldo2",
+		.ops = &test_regulator_ops_range,
+	}},
+};
+
+static struct of_regulator_match test_reg_matches[] = {
+	[TEST_BUCK] = { .name = "BUCK", .desc = &test_pmic_reg[TEST_BUCK].desc },
+	[TEST_LDO1] = { .name = "LDO1", .desc = &test_pmic_reg[TEST_LDO1].desc },
+	[TEST_LDO2] = { .name = "LDO2", .desc = &test_pmic_reg[TEST_LDO2].desc },
+};
+
+static int test_regulator_register(struct test_regulator *priv, int id,
+				    struct of_regulator_match *match,
+				    struct test_regulator_cfg *cfg)
+{
+	struct device *dev = priv->dev;
+	int ret;
+
+	if (!match->of_node) {
+		dev_warn(dev, "Skip missing DTB regulator %s\n", match->name);
+		return 0;
+	}
+
+	cfg->rdev.desc = &cfg->desc;
+	cfg->rdev.dev = dev;
+
+	ret = of_regulator_register(&cfg->rdev, match->of_node);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to register %s regulator\n",
+				     match->name);
+
+	dev_dbg(dev, "registered %s\n", match->name);
+
+	return 0;
+}
+
+static int regulator_probe(struct device *dev)
+{
+	size_t nregulators = ARRAY_SIZE(test_pmic_reg);
+	struct device_node *np = dev->of_node;
+	struct test_regulator *priv;
+	int ret, i;
+
+	priv = xzalloc(sizeof(*priv));
+	priv->dev = dev;
+
+	total_tests += 2;
+	failed_tests += 2;
+
+	np = of_get_child_by_name(np, "regulators");
+	if (!np)
+		return -ENOENT;
+
+	ret = of_regulator_match(dev, np, test_reg_matches, nregulators);
+	if (ret < 0)
+		return ret;
+
+	ok(ret == TEST_REGULATORS_NUM);
+
+	for (i = 0; i < nregulators; i++) {
+		ret = test_regulator_register(priv, i, &test_reg_matches[i],
+					      &test_pmic_reg[i]);
+		ok(ret == 0);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
+static const struct of_device_id test_regulator_of_match[] = {
+	{ .compatible = "barebox,regulator-self-test" },
+	{ /* sentintel */ },
+};
+
+static struct driver regulator_test_driver = {
+	.name = "regulator-test",
+	.probe = regulator_probe,
+	.of_match_table = test_regulator_of_match,
+};
+
+static struct device_d *dev;
+
+static void test_regulator(void)
+{
+	extern char __dtbo_test_regulator_start[];
+	struct device_node *overlay;
+	int ret;
+
+	if (!dev) {
+		ret = platform_driver_register(&regulator_test_driver);
+		if (ret)
+			return;
+
+		overlay = of_unflatten_dtb(__dtbo_test_regulator_start, INT_MAX);
+		of_overlay_apply_tree(of_get_root_node(), overlay);
+		of_probe();
+
+		dev = of_find_device_by_node_path("/regulator-self-test-pmic");
+
+		ok(dev->driver != NULL);
+	}
+
+	test_regulator_selfref_always_on(dev);
+}
+bselftest(core, test_regulator);
diff --git a/test/self/test_regulator.dtso b/test/self/test_regulator.dtso
new file mode 100644
index 000000000000..65d2b130988d
--- /dev/null
+++ b/test/self/test_regulator.dtso
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+/dts-v1/;
+/plugin/;
+
+&{/} {
+	regulator_test_fixed: regulator-self-test-fixed {
+		compatible = "regulator-fixed";
+		regulator-name = "test_fixed";
+		regulator-min-microvolt = <3300000>;
+		regulator-max-microvolt = <3300000>;
+	};
+
+	regulator-self-test-pmic {
+		compatible = "barebox,regulator-self-test";
+
+		buck-supply = <&regulator_test_fixed>;
+		ldo1-supply = <&test_pmic_buck>;
+		ldo2-supply = <&test_pmic_buck>;
+
+		regulators {
+			test_pmic_buck: BUCK {
+				regulator-name = "buck";
+				regulator-min-microvolt = <330000>;
+				regulator-max-microvolt = <330000>;
+			};
+
+			test_pmic_ldo1: LDO1 {
+				regulator-name = "ldo1";
+				regulator-always-on;
+				regulator-boot-on;
+				regulator-min-microvolt = <180000>;
+				regulator-max-microvolt = <180000>;
+			};
+
+			test_pmic_ldo2: LDO2 {
+				regulator-name = "ldo2";
+				regulator-min-microvolt = <180000>;
+				regulator-max-microvolt = <180000>;
+			};
+		};
+	};
+};
-- 
2.38.4



From ahmad at a3f.at  Mon Apr 24 05:02:11 2023
From: ahmad at a3f.at (Ahmad Fatoum)
Date: Mon, 24 Apr 2023 14:02:11 +0200
Subject: [PATCH] clk: implement clk_to_clk_hw using container_of_safe
Message-ID: <20230424120211.115610-1-ahmad@a3f.at>

We basically opencode container_of_safe. The kernel implementation of
container_of has also got a better diagnostic for mismatched arguments,
so let's import it and use it.

Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
---
 include/linux/clk.h          |  3 ++-
 include/linux/container_of.h | 40 ++++++++++++++++++++++++++++++++++++
 include/linux/kernel.h       | 12 +----------
 3 files changed, 43 insertions(+), 12 deletions(-)
 create mode 100644 include/linux/container_of.h

diff --git a/include/linux/clk.h b/include/linux/clk.h
index 29c697a00bd9..c78132d40582 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -13,6 +13,7 @@
 #include <linux/err.h>
 #include <linux/spinlock.h>
 #include <linux/stringify.h>
+#include <linux/container_of.h>
 #include <xfuncs.h>
 
 struct device;
@@ -296,7 +297,7 @@ static inline struct clk *clk_hw_to_clk(const struct clk_hw *hw)
 
 static inline struct clk_hw *clk_to_clk_hw(const struct clk *clk)
 {
-	return IS_ERR(clk) ? ERR_CAST(clk) : (struct clk_hw *)container_of(clk, struct clk_hw, clk);
+	return container_of_safe(clk, struct clk_hw, clk);
 }
 
 struct clk_div_table {
diff --git a/include/linux/container_of.h b/include/linux/container_of.h
new file mode 100644
index 000000000000..2f4944b791b8
--- /dev/null
+++ b/include/linux/container_of.h
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_CONTAINER_OF_H
+#define _LINUX_CONTAINER_OF_H
+
+#include <linux/build_bug.h>
+#include <linux/err.h>
+
+#define typeof_member(T, m)	typeof(((T*)0)->m)
+
+/**
+ * container_of - cast a member of a structure out to the containing structure
+ * @ptr:	the pointer to the member.
+ * @type:	the type of the container struct this is embedded in.
+ * @member:	the name of the member within the struct.
+ *
+ */
+#define container_of(ptr, type, member) ({				\
+	void *__mptr = (void *)(ptr);					\
+	static_assert(__same_type(*(ptr), ((type *)0)->member) ||	\
+		      __same_type(*(ptr), void),			\
+		      "pointer type mismatch in container_of()");	\
+	((type *)(__mptr - offsetof(type, member))); })
+
+/**
+ * container_of_safe - cast a member of a structure out to the containing structure
+ * @ptr:	the pointer to the member.
+ * @type:	the type of the container struct this is embedded in.
+ * @member:	the name of the member within the struct.
+ *
+ * If IS_ERR_OR_NULL(ptr), ptr is returned unchanged.
+ */
+#define container_of_safe(ptr, type, member) ({				\
+	void *__mptr = (void *)(ptr);					\
+	static_assert(__same_type(*(ptr), ((type *)0)->member) ||	\
+		      __same_type(*(ptr), void),			\
+		      "pointer type mismatch in container_of_safe()");	\
+	IS_ERR_OR_NULL(__mptr) ? ERR_CAST(__mptr) :			\
+		((type *)(__mptr - offsetof(type, member))); })
+
+#endif	/* _LINUX_CONTAINER_OF_H */
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 44fc02df0bf9..0eb7bd21fe93 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -7,6 +7,7 @@
 #include <linux/barebox-wrapper.h>
 #include <linux/limits.h>
 #include <linux/math64.h>
+#include <linux/container_of.h>
 
 #define ALIGN(x, a)		__ALIGN_MASK(x, (typeof(x))(a) - 1)
 #define ALIGN_DOWN(x, a)	ALIGN((x) - ((a) - 1), (a))
@@ -256,17 +257,6 @@ extern int hex_to_bin(char ch);
 extern int __must_check hex2bin(u8 *dst, const char *src, size_t count);
 extern char *bin2hex(char *dst, const void *src, size_t count);
 
-/**
- * container_of - cast a member of a structure out to the containing structure
- * @ptr:	the pointer to the member.
- * @type:	the type of the container struct this is embedded in.
- * @member:	the name of the member within the struct.
- *
- */
-#define container_of(ptr, type, member) ({			\
-	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
-	(type *)( (char *)__mptr - offsetof(type,member) );})
-
 /*
  * swap - swap value of @a and @b
  */
-- 
2.38.4



From ahmad at a3f.at  Mon Apr 24 05:17:59 2023
From: ahmad at a3f.at (Ahmad Fatoum)
Date: Mon, 24 Apr 2023 14:17:59 +0200
Subject: [PATCH 1/7] sandbox: watchdog: handle missing stickypage gracefully
Message-ID: <20230424121805.150434-1-ahmad@a3f.at>

To enable simulation of $global.system.reset in sandbox, the watchdog
driver writes the reset-source into the stickypage for readout during
subsequent barebox startup. This is an optional feature, so it should
happen before watchdog registration, but not break watchdog operation if
not available.

Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
---
 arch/sandbox/board/watchdog.c           | 28 +++++++++----------------
 arch/sandbox/include/asm/reset_source.h | 16 ++++++++++++++
 2 files changed, 26 insertions(+), 18 deletions(-)
 create mode 100644 arch/sandbox/include/asm/reset_source.h

diff --git a/arch/sandbox/board/watchdog.c b/arch/sandbox/board/watchdog.c
index 54e87cdde4ab..5bffad81195e 100644
--- a/arch/sandbox/board/watchdog.c
+++ b/arch/sandbox/board/watchdog.c
@@ -7,7 +7,7 @@
 #include <of.h>
 #include <watchdog.h>
 #include <linux/nvmem-consumer.h>
-#include <reset_source.h>
+#include <asm/reset_source.h>
 
 struct sandbox_watchdog {
 	struct watchdog wdd;
@@ -30,7 +30,7 @@ static int sandbox_watchdog_set_timeout(struct watchdog *wdd, unsigned int timeo
 	if (timeout > wdd->timeout_max)
 		return -EINVAL;
 
-	nvmem_cell_write(wd->reset_source_cell, &(u8) { RESET_WDG }, 1);
+	sandbox_save_reset_source(wd->reset_source_cell, RESET_WDG);
 
 	linux_watchdog_set_timeout(timeout);
 	return 0;
@@ -41,7 +41,6 @@ static int sandbox_watchdog_probe(struct device *dev)
 	struct device_node *np = dev->of_node;
 	struct sandbox_watchdog *wd;
 	struct watchdog *wdd;
-	int ret;
 
 	wd = xzalloc(sizeof(*wd));
 
@@ -50,24 +49,17 @@ static int sandbox_watchdog_probe(struct device *dev)
 	wdd->set_timeout = sandbox_watchdog_set_timeout;
 	wdd->timeout_max = 1000;
 
-	wd->cant_disable = of_property_read_bool(np, "barebox,cant-disable");
-
-	ret = watchdog_register(wdd);
-	if (ret) {
-		dev_err(dev, "Failed to register watchdog device\n");
-		return ret;
-	}
-
-	wd->reset_source_cell = of_nvmem_cell_get(dev->of_node,
-						  "reset-source");
+	wd->reset_source_cell = of_nvmem_cell_get(np, "reset-source");
 	if (IS_ERR(wd->reset_source_cell)) {
-		dev_warn(dev, "No reset source info available: %pe\n", wd->reset_source_cell);
-		goto out;
+		if (PTR_ERR(wd->reset_source_cell) != -EPROBE_DEFER)
+			dev_warn(dev, "No reset source info available: %pe\n",
+				 wd->reset_source_cell);
+		wd->reset_source_cell = NULL;
 	}
 
-out:
-	dev_info(dev, "probed\n");
-	return 0;
+	wd->cant_disable = of_property_read_bool(np, "barebox,cant-disable");
+
+	return watchdog_register(wdd);
 }
 
 
diff --git a/arch/sandbox/include/asm/reset_source.h b/arch/sandbox/include/asm/reset_source.h
new file mode 100644
index 000000000000..1690299c4718
--- /dev/null
+++ b/arch/sandbox/include/asm/reset_source.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __SANDBOX_RESET_SOURCE_H
+#define __SANDBOX_RESET_SOURCE_H
+
+#include <reset_source.h>
+#include <linux/nvmem-consumer.h>
+
+static inline void sandbox_save_reset_source(struct nvmem_cell *reset_source_cell,
+					     enum reset_src_type src)
+{
+	if (reset_source_cell)
+		WARN_ON(nvmem_cell_write(reset_source_cell, &(u8) { src }, 1) <= 0);
+}
+
+#endif
-- 
2.38.4



From ahmad at a3f.at  Mon Apr 24 05:18:00 2023
From: ahmad at a3f.at (Ahmad Fatoum)
Date: Mon, 24 Apr 2023 14:18:00 +0200
Subject: [PATCH 2/7] sandbox: power: handle missing stickypage gracefully
In-Reply-To: <20230424121805.150434-1-ahmad@a3f.at>
References: <20230424121805.150434-1-ahmad@a3f.at>
Message-ID: <20230424121805.150434-2-ahmad@a3f.at>

To enable simulation of $global.system.reset in sandbox, the power
driver writes the reset-source into the stickypage for readout during
subsequent barebox startup. This is an optional feature, so it should
happen before watchdog registration, but not break watchdog operation if
not available.

Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
---
 arch/sandbox/board/power.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/arch/sandbox/board/power.c b/arch/sandbox/board/power.c
index 51f0968447c4..4adc8d7455fc 100644
--- a/arch/sandbox/board/power.c
+++ b/arch/sandbox/board/power.c
@@ -5,7 +5,7 @@
 #include <poweroff.h>
 #include <restart.h>
 #include <mach/linux.h>
-#include <reset_source.h>
+#include <asm/reset_source.h>
 #include <linux/nvmem-consumer.h>
 
 struct sandbox_power {
@@ -18,7 +18,8 @@ static void sandbox_poweroff(struct poweroff_handler *poweroff)
 {
 	struct sandbox_power *power = container_of(poweroff, struct sandbox_power, poweroff);
 
-	nvmem_cell_write(power->reset_source_cell, &(u8) { RESET_POR }, 1);
+	sandbox_save_reset_source(power->reset_source_cell, RESET_POR);
+
 	linux_exit();
 }
 
@@ -29,11 +30,9 @@ static void sandbox_rst_hang(struct restart_handler *rst)
 
 static void sandbox_rst_reexec(struct restart_handler *rst)
 {
-	u8 reason = RESET_RST;
 	struct sandbox_power *power = container_of(rst, struct sandbox_power, rst_reexec);
 
-	if (!IS_ERR(power->reset_source_cell))
-		WARN_ON(nvmem_cell_write(power->reset_source_cell, &reason, 1) <= 0);
+	sandbox_save_reset_source(power->reset_source_cell, RESET_RST);
 
 	linux_reexec();
 }
@@ -69,7 +68,10 @@ static int sandbox_power_probe(struct device *dev)
 	power->reset_source_cell = of_nvmem_cell_get(dev->of_node,
 						     "reset-source");
 	if (IS_ERR(power->reset_source_cell)) {
-		dev_warn(dev, "No reset source info available: %pe\n", power->reset_source_cell);
+		if (PTR_ERR(power->reset_source_cell) != -EPROBE_DEFER)
+			dev_warn(dev, "No reset source info available: %pe\n",
+				 power->reset_source_cell);
+		power->reset_source_cell = NULL;
 		return 0;
 	}
 
-- 
2.38.4



From ahmad at a3f.at  Mon Apr 24 05:18:01 2023
From: ahmad at a3f.at (Ahmad Fatoum)
Date: Mon, 24 Apr 2023 14:18:01 +0200
Subject: [PATCH 3/7] sandbox: hostfile: don't warn on failed hostfile fixup
In-Reply-To: <20230424121805.150434-1-ahmad@a3f.at>
References: <20230424121805.150434-1-ahmad@a3f.at>
Message-ID: <20230424121805.150434-3-ahmad@a3f.at>

The node is not deleted, so the hostfile driver will probe the node in
any case and error will just be printed twice. Thus drop the checks from
the fixup.

Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
---
 arch/sandbox/board/hostfile.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/arch/sandbox/board/hostfile.c b/arch/sandbox/board/hostfile.c
index 436a7503befa..424f16acd5fc 100644
--- a/arch/sandbox/board/hostfile.c
+++ b/arch/sandbox/board/hostfile.c
@@ -257,23 +257,14 @@ static int of_hostfile_map_fixup(struct device_node *root, void *ctx)
 
 		ret = linux_open_hostfile(&hf);
 		if (ret)
-			goto out;
+			continue;
 
 		reg[0] = hf.base;
 		reg[1] = hf.size;
 
-		ret = of_property_write_u64_array(node, "reg", reg, ARRAY_SIZE(reg));
-		if (ret)
-			goto out;
-
-		ret = of_property_write_bool(node, "barebox,blockdev", hf.is_blockdev);
-		if (ret)
-			goto out;
-
-		ret = of_property_write_u32(node, "barebox,fd", hf.fd);
-out:
-		if (ret)
-			pr_err("error fixing up %s: %pe\n", hf.devname, ERR_PTR(ret));
+		of_property_write_u64_array(node, "reg", reg, ARRAY_SIZE(reg));
+		of_property_write_bool(node, "barebox,blockdev", hf.is_blockdev);
+		of_property_write_u32(node, "barebox,fd", hf.fd);
 	}
 
 	return 0;
-- 
2.38.4



From ahmad at a3f.at  Mon Apr 24 05:18:03 2023
From: ahmad at a3f.at (Ahmad Fatoum)
Date: Mon, 24 Apr 2023 14:18:03 +0200
Subject: [PATCH 5/7] driver: be explicit about supported #feature-cells
In-Reply-To: <20230424121805.150434-1-ahmad@a3f.at>
References: <20230424121805.150434-1-ahmad@a3f.at>
Message-ID: <20230424121805.150434-5-ahmad@a3f.at>

A feature controller may control the activation of multiple devices.
This is represented by a single index argument in the API. Thus any
value higher than #feature-cells = <1>; is unsupported, so let's be
explicit about that. #feature-cells = <0>; specs will just be
interpreted as if the argument was a 0.

Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
---
 drivers/base/featctrl.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/base/featctrl.c b/drivers/base/featctrl.c
index abe21698ede7..f40b1f04bc1f 100644
--- a/drivers/base/featctrl.c
+++ b/drivers/base/featctrl.c
@@ -53,10 +53,13 @@ static struct feature_controller *featctrl_get_from_provider(struct of_phandle_a
 	if (ret < 0)
 		return ERR_PTR(ret);
 
+	if (spec->args_count > 1)
+		return ERR_PTR(-EINVAL);
+
 	/* Check if we have such a controller in our array */
 	list_for_each_entry(featctrl, &of_feature_controllers, list) {
 		if (dev_of_node(featctrl->dev) == spec->np) {
-			*gateid = spec->args[0];
+			*gateid = spec->args_count ? spec->args[0] : 0;
 			return featctrl;
 		}
 	}
-- 
2.38.4



From ahmad at a3f.at  Mon Apr 24 05:18:02 2023
From: ahmad at a3f.at (Ahmad Fatoum)
Date: Mon, 24 Apr 2023 14:18:02 +0200
Subject: [PATCH 4/7] treewide: drop trailing space
In-Reply-To: <20230424121805.150434-1-ahmad@a3f.at>
References: <20230424121805.150434-1-ahmad@a3f.at>
Message-ID: <20230424121805.150434-4-ahmad@a3f.at>

Found by manual inspection of the output of:

  rg '\s+$' | rg -v dts/

Patch can be verified by observing that no diff results from:

  git show --ignore-space-at-eol

Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
---
 Documentation/boards/ibase-mi991af.rst                    | 2 +-
 Documentation/user/state.rst                              | 2 +-
 arch/arm/boards/boundarydevices-nitrogen6/Makefile        | 2 +-
 arch/arm/boards/ls1046ardb/board.c                        | 2 +-
 arch/arm/boards/protonic-imx6/flash-header-lanmcu.imxcfg  | 2 +-
 arch/arm/boards/protonic-imx6/flash-header-plybas.imxcfg  | 2 +-
 arch/arm/boards/protonic-imx6/flash-header-plym2m.imxcfg  | 2 +-
 arch/arm/boards/protonic-imx6/flash-header-prti6q.imxcfg  | 2 +-
 arch/arm/boards/protonic-imx6/flash-header-prtmvt.imxcfg  | 2 +-
 arch/arm/boards/protonic-imx6/flash-header-prtrvt.imxcfg  | 2 +-
 arch/arm/boards/protonic-imx6/flash-header-prtvt7.imxcfg  | 2 +-
 arch/arm/boards/protonic-imx6/flash-header-vicut1.imxcfg  | 2 +-
 arch/arm/boards/protonic-imx6/flash-header-vicut1q.imxcfg | 2 +-
 arch/arm/boards/protonic-imx6/flash-header-vicutp.imxcfg  | 2 +-
 arch/arm/boards/zii-imx8mq-dev/ddr_init.c                 | 2 +-
 arch/arm/dts/imx6qdl-nitrogen6_max.dtsi                   | 2 +-
 arch/arm/dts/vf610.dtsi                                   | 2 +-
 arch/arm/dts/zynq-7000.dtsi                               | 2 +-
 arch/arm/mach-at91/sam9263_ll.c                           | 4 ++--
 arch/arm/mach-omap/am33xx_bbu_nand.c                      | 2 +-
 commands/of_overlay.c                                     | 2 +-
 drivers/clk/clk-qoric.c                                   | 2 +-
 drivers/ddr/fsl/ctrl_regs.c                               | 2 +-
 drivers/mtd/nand/Kconfig                                  | 2 +-
 drivers/mtd/nand/nand_omap_gpmc.c                         | 2 +-
 drivers/net/usb/ax88179_178a.c                            | 2 +-
 drivers/regulator/core.c                                  | 2 +-
 drivers/serial/serial_omap4_usbboot.c                     | 2 +-
 include/crypto/des.h                                      | 2 +-
 include/linux/idr.h                                       | 2 +-
 include/tlsf.h                                            | 6 +++---
 scripts/socfpga_import_preloader                          | 2 +-
 32 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/Documentation/boards/ibase-mi991af.rst b/Documentation/boards/ibase-mi991af.rst
index a22e5fcf795b..8e40a0d657b0 100644
--- a/Documentation/boards/ibase-mi991af.rst
+++ b/Documentation/boards/ibase-mi991af.rst
@@ -40,4 +40,4 @@ To continue please proceed with barebox :ref:`barebox_on_uefi` documentation.
 Links
 -----
 
-  * https://www.ibase.com.tw/english/ProductDetail/EmbeddedComputing/MI991 
+  * https://www.ibase.com.tw/english/ProductDetail/EmbeddedComputing/MI991
diff --git a/Documentation/user/state.rst b/Documentation/user/state.rst
index a0e27d4fe847..594c2c15945b 100644
--- a/Documentation/user/state.rst
+++ b/Documentation/user/state.rst
@@ -24,7 +24,7 @@ barebox itself uses a *state* driver to access the variables in the
 persistent memory.
 
 Currently there is only one implementation, enabled by
-``CONFIG_STATE_DRV=y``. Without driver, the state framework will silently 
+``CONFIG_STATE_DRV=y``. Without driver, the state framework will silently
 fail and be non-functional.
 
 For the Linux run-time there is a userspace tool_ to do
diff --git a/arch/arm/boards/boundarydevices-nitrogen6/Makefile b/arch/arm/boards/boundarydevices-nitrogen6/Makefile
index b365c8eab067..da63d2625f7a 100644
--- a/arch/arm/boards/boundarydevices-nitrogen6/Makefile
+++ b/arch/arm/boards/boundarydevices-nitrogen6/Makefile
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-obj-y += board.o 
+obj-y += board.o
 lwl-y += lowlevel.o
diff --git a/arch/arm/boards/ls1046ardb/board.c b/arch/arm/boards/ls1046ardb/board.c
index 921629d2a840..ee70171ca3d3 100644
--- a/arch/arm/boards/ls1046ardb/board.c
+++ b/arch/arm/boards/ls1046ardb/board.c
@@ -33,7 +33,7 @@ struct nxid {
 	u8 mac_count;     /* 0x40        Number of MAC addresses */
 	u8 mac_flag;      /* 0x41        MAC table flags */
 	u8 mac[MAX_NUM_PORTS][6];     /* 0x42 - 0xa1 MAC addresses */
-	u8 res_2[90];     /* 0xa2 - 0xfb Reserved */	
+	u8 res_2[90];     /* 0xa2 - 0xfb Reserved */
 	u32 crc;          /* 0xfc - 0xff CRC32 checksum */
 } __packed;
 
diff --git a/arch/arm/boards/protonic-imx6/flash-header-lanmcu.imxcfg b/arch/arm/boards/protonic-imx6/flash-header-lanmcu.imxcfg
index e6e37672aa3e..7deaaa9b7b34 100644
--- a/arch/arm/boards/protonic-imx6/flash-header-lanmcu.imxcfg
+++ b/arch/arm/boards/protonic-imx6/flash-header-lanmcu.imxcfg
@@ -61,7 +61,7 @@ wm 32 0x021b001c 0x04008040
 
 /* MPZQHWCTRL */
 wm 32 0x021b0800 0xa1390003 /* ZQ mode = 3  force calibration */
-wm 32 0x021b4800 0xa1390003 
+wm 32 0x021b4800 0xa1390003
 
 wm 32 0x021b0020 MDREF_64KHZ
 
diff --git a/arch/arm/boards/protonic-imx6/flash-header-plybas.imxcfg b/arch/arm/boards/protonic-imx6/flash-header-plybas.imxcfg
index 16f2f596c773..c9c9d076f587 100644
--- a/arch/arm/boards/protonic-imx6/flash-header-plybas.imxcfg
+++ b/arch/arm/boards/protonic-imx6/flash-header-plybas.imxcfg
@@ -63,7 +63,7 @@ wm 32 0x021b001c 0x04008040
 
 /* MPZQHWCTRL */
 wm 32 0x021b0800 0xa1390003 /* ZQ mode = 3  force calibration */
-wm 32 0x021b4800 0xa1390003 
+wm 32 0x021b4800 0xa1390003
 
 wm 32 0x021b0020 MDREF_64KHZ
 
diff --git a/arch/arm/boards/protonic-imx6/flash-header-plym2m.imxcfg b/arch/arm/boards/protonic-imx6/flash-header-plym2m.imxcfg
index 1692c1e08771..71df95b96853 100644
--- a/arch/arm/boards/protonic-imx6/flash-header-plym2m.imxcfg
+++ b/arch/arm/boards/protonic-imx6/flash-header-plym2m.imxcfg
@@ -63,7 +63,7 @@ wm 32 0x021b001c 0x04008040
 
 /* MPZQHWCTRL */
 wm 32 0x021b0800 0xa1390003 /* ZQ mode = 3  force calibration */
-wm 32 0x021b4800 0xa1390003 
+wm 32 0x021b4800 0xa1390003
 
 wm 32 0x021b0020 MDREF_64KHZ
 
diff --git a/arch/arm/boards/protonic-imx6/flash-header-prti6q.imxcfg b/arch/arm/boards/protonic-imx6/flash-header-prti6q.imxcfg
index 2d0064e8c1cb..deced6901bc7 100644
--- a/arch/arm/boards/protonic-imx6/flash-header-prti6q.imxcfg
+++ b/arch/arm/boards/protonic-imx6/flash-header-prti6q.imxcfg
@@ -65,7 +65,7 @@ wm 32 0x021b001c 0x04008040
 
 /* MPZQHWCTRL */
 wm 32 0x021b0800 0xa1390003 /* ZQ mode = 3  force calibration */
-wm 32 0x021b4800 0xa1390003 
+wm 32 0x021b4800 0xa1390003
 
 wm 32 0x021b0020 MDREF_64KHZ
 
diff --git a/arch/arm/boards/protonic-imx6/flash-header-prtmvt.imxcfg b/arch/arm/boards/protonic-imx6/flash-header-prtmvt.imxcfg
index 887811fa4240..58530910fc63 100644
--- a/arch/arm/boards/protonic-imx6/flash-header-prtmvt.imxcfg
+++ b/arch/arm/boards/protonic-imx6/flash-header-prtmvt.imxcfg
@@ -63,7 +63,7 @@ wm 32 0x021b001c 0x04008040
 
 /* MPZQHWCTRL */
 wm 32 0x021b0800 0xa1390003 /* ZQ mode = 3  force calibration */
-wm 32 0x021b4800 0xa1390003 
+wm 32 0x021b4800 0xa1390003
 
 wm 32 0x021b0020 MDREF_64KHZ
 
diff --git a/arch/arm/boards/protonic-imx6/flash-header-prtrvt.imxcfg b/arch/arm/boards/protonic-imx6/flash-header-prtrvt.imxcfg
index 16f2f596c773..c9c9d076f587 100644
--- a/arch/arm/boards/protonic-imx6/flash-header-prtrvt.imxcfg
+++ b/arch/arm/boards/protonic-imx6/flash-header-prtrvt.imxcfg
@@ -63,7 +63,7 @@ wm 32 0x021b001c 0x04008040
 
 /* MPZQHWCTRL */
 wm 32 0x021b0800 0xa1390003 /* ZQ mode = 3  force calibration */
-wm 32 0x021b4800 0xa1390003 
+wm 32 0x021b4800 0xa1390003
 
 wm 32 0x021b0020 MDREF_64KHZ
 
diff --git a/arch/arm/boards/protonic-imx6/flash-header-prtvt7.imxcfg b/arch/arm/boards/protonic-imx6/flash-header-prtvt7.imxcfg
index 7f2662567e6b..5073458a0302 100644
--- a/arch/arm/boards/protonic-imx6/flash-header-prtvt7.imxcfg
+++ b/arch/arm/boards/protonic-imx6/flash-header-prtvt7.imxcfg
@@ -61,7 +61,7 @@ wm 32 0x021b001c 0x04008040
 
 /* MPZQHWCTRL */
 wm 32 0x021b0800 0xa1390003 /* ZQ mode = 3  force calibration */
-wm 32 0x021b4800 0xa1390003 
+wm 32 0x021b4800 0xa1390003
 
 wm 32 0x021b0020 MDREF_64KHZ
 
diff --git a/arch/arm/boards/protonic-imx6/flash-header-vicut1.imxcfg b/arch/arm/boards/protonic-imx6/flash-header-vicut1.imxcfg
index b86a32be0c2c..a879229923bb 100644
--- a/arch/arm/boards/protonic-imx6/flash-header-vicut1.imxcfg
+++ b/arch/arm/boards/protonic-imx6/flash-header-vicut1.imxcfg
@@ -63,7 +63,7 @@ wm 32 0x021b001c 0x04008040
 
 /* MPZQHWCTRL */
 wm 32 0x021b0800 0xa1390003 /* ZQ mode = 3  force calibration */
-wm 32 0x021b4800 0xa1390003 
+wm 32 0x021b4800 0xa1390003
 
 wm 32 0x021b0020 MDREF_64KHZ
 
diff --git a/arch/arm/boards/protonic-imx6/flash-header-vicut1q.imxcfg b/arch/arm/boards/protonic-imx6/flash-header-vicut1q.imxcfg
index 3abb21b70e32..8e41a410df5b 100644
--- a/arch/arm/boards/protonic-imx6/flash-header-vicut1q.imxcfg
+++ b/arch/arm/boards/protonic-imx6/flash-header-vicut1q.imxcfg
@@ -66,7 +66,7 @@ wm 32 0x021b001c 0x04008040
 
 /* MPZQHWCTRL */
 wm 32 0x021b0800 0xa1390003 /* ZQ mode = 3  force calibration */
-wm 32 0x021b4800 0xa1390003 
+wm 32 0x021b4800 0xa1390003
 
 wm 32 0x021b0020 MDREF_64KHZ
 
diff --git a/arch/arm/boards/protonic-imx6/flash-header-vicutp.imxcfg b/arch/arm/boards/protonic-imx6/flash-header-vicutp.imxcfg
index a8178fe2580b..54a86a0008a6 100644
--- a/arch/arm/boards/protonic-imx6/flash-header-vicutp.imxcfg
+++ b/arch/arm/boards/protonic-imx6/flash-header-vicutp.imxcfg
@@ -126,7 +126,7 @@ wm 32 0x021b001c 0x04008040
 
 /* MPZQHWCTRL */
 wm 32 0x021b0800 0xa1390003 /* ZQ mode = 3  force calibration */
-wm 32 0x021b4800 0xa1390003 
+wm 32 0x021b4800 0xa1390003
 
 wm 32 0x021b0020 MDREF_64KHZ
 
diff --git a/arch/arm/boards/zii-imx8mq-dev/ddr_init.c b/arch/arm/boards/zii-imx8mq-dev/ddr_init.c
index 902d0ee3cd6e..2d4133fb1375 100644
--- a/arch/arm/boards/zii-imx8mq-dev/ddr_init.c
+++ b/arch/arm/boards/zii-imx8mq-dev/ddr_init.c
@@ -178,7 +178,7 @@ void ddr_init(void)
 	reg32_write(DDRC_SWCTL(0), 0x0000);
 	/*
 	 * ------------------- 9 -------------------
-	 * Set DFIMISC.dfi_init_start to 1 
+	 * Set DFIMISC.dfi_init_start to 1
 	 *  -----------------------------------------
 	 */
 	reg32_write(DDRC_DFIMISC(0), 0x00000030);
diff --git a/arch/arm/dts/imx6qdl-nitrogen6_max.dtsi b/arch/arm/dts/imx6qdl-nitrogen6_max.dtsi
index 5d301289f3ed..0f6d17ad6ce5 100644
--- a/arch/arm/dts/imx6qdl-nitrogen6_max.dtsi
+++ b/arch/arm/dts/imx6qdl-nitrogen6_max.dtsi
@@ -39,7 +39,7 @@
  *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  *     OTHER DEALINGS IN THE SOFTWARE.
  */
- 
+
 / {
 	chosen {
 		environment {
diff --git a/arch/arm/dts/vf610.dtsi b/arch/arm/dts/vf610.dtsi
index 3060031b8aaf..d1297e952c00 100644
--- a/arch/arm/dts/vf610.dtsi
+++ b/arch/arm/dts/vf610.dtsi
@@ -9,4 +9,4 @@
 		mmc0 = &esdhc0;
 		mmc1 = &esdhc1;
 	};
-};	
+};
diff --git a/arch/arm/dts/zynq-7000.dtsi b/arch/arm/dts/zynq-7000.dtsi
index 3791f743a47d..f7a0d70babef 100644
--- a/arch/arm/dts/zynq-7000.dtsi
+++ b/arch/arm/dts/zynq-7000.dtsi
@@ -8,7 +8,7 @@
 		clocks = <&clkc 10>, <&clkc 43>;
 		clock-names = "ref_clk", "pclk";
 		status = "disabled";
-		
+
 		#address-cells = <1>;
 		#size-cells = <0>;
 	};
diff --git a/arch/arm/mach-at91/sam9263_ll.c b/arch/arm/mach-at91/sam9263_ll.c
index 2beeaccd618e..8855a679fdf2 100644
--- a/arch/arm/mach-at91/sam9263_ll.c
+++ b/arch/arm/mach-at91/sam9263_ll.c
@@ -17,12 +17,12 @@ static void sam9263_pmc_init(const struct sam92_pmc_config *config)
 	/* Setting PLL A and divider A */
 	at91_pmc_cfg_plla(IOMEM(AT91SAM926X_BASE_PMC),
 			  AT91_PMC_MUL_(config->mula) |
-			  AT91_PMC_OUT_2 |		// 190 to 240 MHz		
+			  AT91_PMC_OUT_2 |		// 190 to 240 MHz
 			  config->diva,			// Divider
 			  0);
 
 	/* Selection of Master Clock and Processor Clock */
-	 
+
 	/* PCK = PLLA = 2 * MCK */
 	at91_pmc_cfg_mck(IOMEM(AT91SAM926X_BASE_PMC),
 			 AT91_PMC_CSS_SLOW
diff --git a/arch/arm/mach-omap/am33xx_bbu_nand.c b/arch/arm/mach-omap/am33xx_bbu_nand.c
index 2041cf3c0b46..40e382780a9c 100644
--- a/arch/arm/mach-omap/am33xx_bbu_nand.c
+++ b/arch/arm/mach-omap/am33xx_bbu_nand.c
@@ -213,7 +213,7 @@ static int nand_update_handler_complete(struct bbu_handler *handler,
 
 		buf = xzalloc(mtd->erasesize);
 		memcpy(buf, data->image, data->len);
-	
+
 		for (i = 0; i < 4; i++) {
 			if (mtd_peb_is_bad(mtd, i)) {
 				pr_info("PEB%d is bad, skipping\n", i);
diff --git a/commands/of_overlay.c b/commands/of_overlay.c
index b80f371c5c93..b0ca57749bf6 100644
--- a/commands/of_overlay.c
+++ b/commands/of_overlay.c
@@ -36,7 +36,7 @@ static int do_of_overlay(int argc, char *argv[])
 		printf("Support for live tree overlays is disabled. Enable CONFIG_OF_OVERLAY_LIVE\n");
 		return 1;
 	}
-		
+
 	fdt = read_file(argv[optind], &size);
 	if (!fdt) {
 		printf("cannot read %s\n", argv[optind]);
diff --git a/drivers/clk/clk-qoric.c b/drivers/clk/clk-qoric.c
index f7dbf7230d9f..667ce6df298b 100644
--- a/drivers/clk/clk-qoric.c
+++ b/drivers/clk/clk-qoric.c
@@ -592,7 +592,7 @@ static void __init clockgen_init(struct device_node *np,
 		pr_err("sysclk not found: %pe\n", clockgen.sysclk);
 		return;
 	}
-	
+
 	clockgen.coreclk = of_clk_get(clockgen.node, 1);
 	if (IS_ERR(clockgen.coreclk))
 		clockgen.coreclk = NULL;
diff --git a/drivers/ddr/fsl/ctrl_regs.c b/drivers/ddr/fsl/ctrl_regs.c
index b0d98a929c5d..7c882946b9df 100644
--- a/drivers/ddr/fsl/ctrl_regs.c
+++ b/drivers/ddr/fsl/ctrl_regs.c
@@ -284,7 +284,7 @@ static void set_timing_cfg_0(struct fsl_ddr_controller *c)
 		/*
 		 * for single quad-rank DIMM and two-slot DIMMs
 		 * to avoid ODT overlap
-		 */ 
+		 */
 		switch (avoid_odt_overlap(c, dimm_params)) {
 		case 2:
 			twrt_mclk = 2;
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 1cfd65f40816..f50b860c45c3 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -40,7 +40,7 @@ config NAND_IMX
 	  "MXC" series:  i.MX21/25/27/31/35/51/53.
 
 	  This is not for the "MXS" series i.MX processors (23 & 28), or i.MX6
-	  and later, which use the GPMI NAND controller from the MXS series. 
+	  and later, which use the GPMI NAND controller from the MXS series.
 	  See the i.MX 'mxs' driver for those chips.
 
 config NAND_FSL_IFC
diff --git a/drivers/mtd/nand/nand_omap_gpmc.c b/drivers/mtd/nand/nand_omap_gpmc.c
index c5e50d27c862..ab3618300511 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -54,7 +54,7 @@
  * Copyright (c) 2004 Micron Technology Inc.
  * Copyright (c) 2004 David Brownell
  *
- * 
+ *
  */
 
 #include <common.h>
diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c
index 318eb9be026c..c6108c488be6 100644
--- a/drivers/net/usb/ax88179_178a.c
+++ b/drivers/net/usb/ax88179_178a.c
@@ -469,7 +469,7 @@ static int ax88179_rx_fixup(struct usbnet *dev, void *buf, int len)
 			__func__, frame_pos, pkt_len);
 
 		net_receive(&dev->edev, buf + frame_pos, pkt_len);
-		
+
 		pkt_hdr++;
 		frame_pos += ((pkt_len + 7) & 0xfff8) - 2;
 	}
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 97f359d6d29f..f914641c8777 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -287,7 +287,7 @@ static struct regulator_internal *of_regulator_get(struct device *dev,
 
 	ret = of_device_ensure_probed(node);
 	if (ret) {
-		/* 
+		/*
 		 * If "barebox,allow-dummy-supply" property is set for regulator
 		 * provider allow use of dummy regulator (NULL is returned).
 		 * Check regulator node and its parent if this setting is set
diff --git a/drivers/serial/serial_omap4_usbboot.c b/drivers/serial/serial_omap4_usbboot.c
index 709398966ff2..6592be4f353b 100644
--- a/drivers/serial/serial_omap4_usbboot.c
+++ b/drivers/serial/serial_omap4_usbboot.c
@@ -54,7 +54,7 @@ static int serial_omap4_usbboot_probe(struct device *dev)
 	ret = omap4_usbboot_open();
 	if (ret)
 		return ret;
-	
+
 	priv = xzalloc(sizeof(*priv));
 
 	priv->cdev.dev = dev;
diff --git a/include/crypto/des.h b/include/crypto/des.h
index abc3d9c59d01..645a9c9969eb 100644
--- a/include/crypto/des.h
+++ b/include/crypto/des.h
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 
-/* 
+/*
  * DES & Triple DES EDE Cipher Algorithms.
  */
 
diff --git a/include/linux/idr.h b/include/linux/idr.h
index 8a0f452d766d..50c9e3f81ade 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
  * include/linux/idr.h
- * 
+ *
  * 2002-10-18  written by Jim Houston jim.houston at ccur.com
  *	Copyright (C) 2002 by Concurrent Computer Corporation
  *
diff --git a/include/tlsf.h b/include/tlsf.h
index 161176d5ac84..3fa220371577 100644
--- a/include/tlsf.h
+++ b/include/tlsf.h
@@ -11,10 +11,10 @@
 **
 ** This implementation was written to the specification
 ** of the document, therefore no GPL restrictions apply.
-** 
+**
 ** Copyright (c) 2006-2016, Matthew Conte
 ** All rights reserved.
-** 
+**
 ** Redistribution and use in source and binary forms, with or without
 ** modification, are permitted provided that the following conditions are met:
 **     * Redistributions of source code must retain the above copyright
@@ -25,7 +25,7 @@
 **     * Neither the name of the copyright holder nor the
 **       names of its contributors may be used to endorse or promote products
 **       derived from this software without specific prior written permission.
-** 
+**
 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
diff --git a/scripts/socfpga_import_preloader b/scripts/socfpga_import_preloader
index 2bec9f2d2173..bd54e1b913ba 100755
--- a/scripts/socfpga_import_preloader
+++ b/scripts/socfpga_import_preloader
@@ -8,7 +8,7 @@ usage() {
 	  -b|--board <BOARD_DIRECTORY>
 	optional:
 	  -e|--embedded-sdk <ALTERA_EMBEDDED_SDK>"
-	echo "EXAMPLE: $0 -i ~/cv_soc_devkit_ghrd/hps_isw_handoff/soc_system_hps_0/ -b arch/arm/boards/altera-socdk -e ~/altera-embedded-sdk/" 
+	echo "EXAMPLE: $0 -i ~/cv_soc_devkit_ghrd/hps_isw_handoff/soc_system_hps_0/ -b arch/arm/boards/altera-socdk -e ~/altera-embedded-sdk/"
 	exit 1
 }
 
-- 
2.38.4



From ahmad at a3f.at  Mon Apr 24 05:18:04 2023
From: ahmad at a3f.at (Ahmad Fatoum)
Date: Mon, 24 Apr 2023 14:18:04 +0200
Subject: [PATCH 6/7] featctrl: drop useless NULL check
In-Reply-To: <20230424121805.150434-1-ahmad@a3f.at>
References: <20230424121805.150434-1-ahmad@a3f.at>
Message-ID: <20230424121805.150434-6-ahmad@a3f.at>

The only instance of calling featctrl_get_from_provider looks like this:

  featctrl = featctrl_get_from_provider(&featctrl_args, &gateid);

Given that the function is static, there's no need to protect against
either argument being NULL, so drop the check.

Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
---
 drivers/base/featctrl.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/base/featctrl.c b/drivers/base/featctrl.c
index f40b1f04bc1f..0b81f801058d 100644
--- a/drivers/base/featctrl.c
+++ b/drivers/base/featctrl.c
@@ -46,9 +46,6 @@ static struct feature_controller *featctrl_get_from_provider(struct of_phandle_a
 	struct feature_controller *featctrl;
 	int ret;
 
-	if (!spec)
-		return ERR_PTR(-EINVAL);
-
 	ret = of_device_ensure_probed(spec->np);
 	if (ret < 0)
 		return ERR_PTR(ret);
-- 
2.38.4



From ahmad at a3f.at  Mon Apr 24 05:18:05 2023
From: ahmad at a3f.at (Ahmad Fatoum)
Date: Mon, 24 Apr 2023 14:18:05 +0200
Subject: [PATCH 7/7] sandbox: hostfile: add feature controller support
In-Reply-To: <20230424121805.150434-1-ahmad@a3f.at>
References: <20230424121805.150434-1-ahmad@a3f.at>
Message-ID: <20230424121805.150434-7-ahmad@a3f.at>

Keeping the tradition of making the sandbox more complex than it needs
to in order to exercise more parts of barebox, let's allow hostfiles to
be feature controllers: This allows specifying optional hostfiles in the
DT: If the hostfile is unavailable, the nodes pointing at the hostfile
can be gated by it, so they behaves as if they were disabled.

This is useful for the stickypage, which results in a number of ugly
errors whenever it's unavailable.

Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
---
 arch/sandbox/board/hostfile.c          | 30 +++++++++++++++++++++++---
 arch/sandbox/configs/sandbox_defconfig |  2 ++
 arch/sandbox/dts/sandbox.dts           |  4 ++++
 drivers/base/Kconfig                   |  2 +-
 4 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/arch/sandbox/board/hostfile.c b/arch/sandbox/board/hostfile.c
index 424f16acd5fc..d0f400787d7a 100644
--- a/arch/sandbox/board/hostfile.c
+++ b/arch/sandbox/board/hostfile.c
@@ -24,6 +24,7 @@
 #include <errno.h>
 #include <linux/err.h>
 #include <mach/hostfile.h>
+#include <featctrl.h>
 #include <xfuncs.h>
 
 struct hf_priv {
@@ -33,6 +34,7 @@ struct hf_priv {
 	};
 	const char *filename;
 	int fd;
+	struct feature_controller feat;
 };
 
 static ssize_t hf_read(struct hf_priv *priv, void *buf, size_t count, loff_t offset, ulong flags)
@@ -96,18 +98,41 @@ static void hf_info(struct device *dev)
 	printf("file: %s\n", priv->filename);
 }
 
+static int hostfile_feat_check(struct feature_controller *feat, int idx)
+{
+	struct hf_priv *priv = container_of(feat, struct hf_priv, feat);
+
+	return priv->fd >= 0 ? FEATCTRL_OKAY : FEATCTRL_GATED;
+}
+
 static int hf_probe(struct device *dev)
 {
 	struct device_node *np = dev->of_node;
 	struct hf_priv *priv = xzalloc(sizeof(*priv));
 	struct cdev *cdev;
-	bool is_blockdev;
+	bool is_featctrl = false, is_blockdev;
 	u64 reg[2];
 	int err;
 
 	if (!np)
 		return -ENODEV;
 
+	dev->priv = priv;
+	priv->fd = -1;
+
+	if (IS_ENABLED(CONFIG_FEATURE_CONTROLLER) &&
+	    of_property_read_bool(np, "barebox,feature-controller")) {
+		priv->feat.dev = dev;
+		priv->feat.check = hostfile_feat_check;
+
+		err = feature_controller_register(&priv->feat);
+		if (err)
+			return err;
+
+		is_featctrl = true;
+	}
+
+
 	err = of_property_read_u64_array(np, "reg", reg, ARRAY_SIZE(reg));
 	if (err)
 		return err;
@@ -120,10 +145,9 @@ static int hf_probe(struct device *dev)
 		return err;
 
 	if (priv->fd < 0)
-		return priv->fd;
+		return is_featctrl ? 0 : priv->fd;
 
 	dev->info = hf_info;
-	dev->priv = priv;
 
 	is_blockdev = of_property_read_bool(np, "barebox,blockdev");
 
diff --git a/arch/sandbox/configs/sandbox_defconfig b/arch/sandbox/configs/sandbox_defconfig
index 16138d9274c4..1bb98c550c43 100644
--- a/arch/sandbox/configs/sandbox_defconfig
+++ b/arch/sandbox/configs/sandbox_defconfig
@@ -96,7 +96,9 @@ CONFIG_NET_NFS=y
 CONFIG_NET_NETCONSOLE=y
 CONFIG_NET_SNTP=y
 CONFIG_NET_FASTBOOT=y
+CONFIG_FEATURE_CONTROLLER=y
 CONFIG_OFDEVICE=y
+# CONFIG_FEATURE_CONTROLLER_FIXUP is not set
 CONFIG_OF_BAREBOX_DRIVERS=y
 CONFIG_OF_BAREBOX_ENV_IN_FS=y
 CONFIG_OF_OVERLAY_LIVE=y
diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index 5b2cab219e2a..75c633c5909f 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -31,6 +31,8 @@
 		backend = <&part_state>;
 		backend-storage-type = "direct";
 		backend-stridesize = <64>;
+		/* suppres sandbox warnings when stickypage is missing */
+		barebox,feature-gates = <&stickypage>;
 
 		#address-cells = <1>;
 		#size-cells = <1>;
@@ -58,6 +60,8 @@
 		barebox,filename = "$build/stickypage.bin";
 		reg = <0 0 0 4096>;
 		barebox,cdev; /* no caching allowed */
+		barebox,feature-controller;
+		#feature-cells = <0>;
 
 		bmode: reboot-mode {
 			compatible = "nvmem-reboot-mode";
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index 3788231b6e82..612a84be33e7 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -4,6 +4,6 @@ config PM_GENERIC_DOMAINS
 	bool
 
 config FEATURE_CONTROLLER
-	bool "Feature controller support" if COMPILE_TEST
+	bool "Feature controller support" if COMPILE_TEST || SANDBOX
 
 source "drivers/base/regmap/Kconfig"
-- 
2.38.4



From s.hauer at pengutronix.de  Tue Apr 25 06:35:34 2023
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Apr 2023 15:35:34 +0200
Subject: [PATCH 1/2] ARM: vexpress: Disable non working devices
Message-ID: <20230425133535.273920-1-s.hauer@pengutronix.de>

Disable some non working devices in the vexpress dts files to
avoid error messages during runtime. vexpress_defconfig has the
drivers for these devices disabled, but with multi_v7_defconfig
the driver are enabled. To make vexpress more usable with
multi_v7_defconfig disable the non working devices in the device
tree.

/timer at 1e000600 doesn't work because our arm,cortex-a9-twd-timer
implementation needs a clock which the dts doesn't provide. We don't
need this as we use another timer anyway.

/bus at 40000000/motherboard-bus at 40000000/leds/ and /leds/ are a gpio-leds
devices which need a GPIO driver which doesn't exist in barebox

/bus at 40000000/motherboard-bus at 40000000/iofpga at 7,00000000/compact-flash at 1a000/
/bus at 8000000/motherboard-bus at 8000000/iofpga-bus at 300000000/compact-flash at 1a0000/
are ata-generic devices. The driver times out probing the device. While
it doesn't issue an error message it delays starting up the board for
several seconds.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/dts/vexpress-v2p-ca15.dts |  8 ++++++++
 arch/arm/dts/vexpress-v2p-ca9.dts  | 12 ++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/arch/arm/dts/vexpress-v2p-ca15.dts b/arch/arm/dts/vexpress-v2p-ca15.dts
index 78d0025909..cdf7bd37d5 100644
--- a/arch/arm/dts/vexpress-v2p-ca15.dts
+++ b/arch/arm/dts/vexpress-v2p-ca15.dts
@@ -28,3 +28,11 @@
 		};
 	};
 };
+
+&{/leds} {
+	status = "disabled";
+};
+
+&{/bus at 8000000/motherboard-bus at 8000000/iofpga-bus at 300000000/compact-flash at 1a0000/} {
+	status = "disabled";
+};
diff --git a/arch/arm/dts/vexpress-v2p-ca9.dts b/arch/arm/dts/vexpress-v2p-ca9.dts
index a43628e7ce..113548bedb 100644
--- a/arch/arm/dts/vexpress-v2p-ca9.dts
+++ b/arch/arm/dts/vexpress-v2p-ca9.dts
@@ -91,3 +91,15 @@
 		};
 	};
 };
+
+&{/timer at 1e000600} {
+	status = "disabled";
+};
+
+&{/bus at 40000000/motherboard-bus at 40000000/leds/} {
+	status = "disabled";
+};
+
+&{/bus at 40000000/motherboard-bus at 40000000/iofpga at 7,00000000/compact-flash at 1a000/} {
+	status = "disabled";
+};
-- 
2.39.2



From s.hauer at pengutronix.de  Tue Apr 25 06:35:35 2023
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Apr 2023 15:35:35 +0200
Subject: [PATCH 2/2] ARM: remove vexpress_defconfig
In-Reply-To: <20230425133535.273920-1-s.hauer@pengutronix.de>
References: <20230425133535.273920-1-s.hauer@pengutronix.de>
Message-ID: <20230425133535.273920-2-s.hauer@pengutronix.de>

vexpress is now covered by multi_v7_defconfig. To reduce the number of
defconfigs remove vexpress_defconfig. While at it add a hint to the
documentation how to build the vexpress images.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 Documentation/boards/arm-qemu-vexpress.rst |  3 +
 arch/arm/configs/vexpress_defconfig        | 76 ----------------------
 2 files changed, 3 insertions(+), 76 deletions(-)
 delete mode 100644 arch/arm/configs/vexpress_defconfig

diff --git a/Documentation/boards/arm-qemu-vexpress.rst b/Documentation/boards/arm-qemu-vexpress.rst
index 010eae04a2..335af46990 100644
--- a/Documentation/boards/arm-qemu-vexpress.rst
+++ b/Documentation/boards/arm-qemu-vexpress.rst
@@ -7,6 +7,9 @@ ARM Qemu vexpress
 Running barebox on QEMU vexpress machine
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
+Images for the vexpress platform are built as part of the
+multi_v7_defconfig.
+
 Usage::
 
 	$ qemu-system-arm -m 1024M \
diff --git a/arch/arm/configs/vexpress_defconfig b/arch/arm/configs/vexpress_defconfig
deleted file mode 100644
index d58ca7ebd0..0000000000
--- a/arch/arm/configs/vexpress_defconfig
+++ /dev/null
@@ -1,76 +0,0 @@
-CONFIG_ARCH_VEXPRESS=y
-CONFIG_MACH_VEXPRESS=y
-CONFIG_MACH_VIRT=y
-CONFIG_AEABI=y
-CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
-CONFIG_MALLOC_SIZE=0x0
-CONFIG_MALLOC_TLSF=y
-CONFIG_KALLSYMS=y
-CONFIG_PROMPT="vexpress: "
-CONFIG_HUSH_FANCY_PROMPT=y
-CONFIG_CMDLINE_EDITING=y
-CONFIG_AUTO_COMPLETE=y
-CONFIG_MENU=y
-CONFIG_BOOTM_SHOW_TYPE=y
-CONFIG_BOOTM_VERBOSE=y
-CONFIG_BOOTM_INITRD=y
-CONFIG_CONSOLE_ACTIVATE_ALL=y
-CONFIG_CONSOLE_ALLOW_COLOR=y
-CONFIG_PARTITION_DISK_EFI=y
-CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
-CONFIG_CMD_DMESG=y
-CONFIG_LONGHELP=y
-CONFIG_CMD_IOMEM=y
-CONFIG_CMD_MEMINFO=y
-# CONFIG_CMD_BOOTU is not set
-CONFIG_CMD_GO=y
-CONFIG_CMD_LOADB=y
-CONFIG_CMD_RESET=y
-CONFIG_CMD_UIMAGE=y
-CONFIG_CMD_PARTITION=y
-CONFIG_CMD_EXPORT=y
-CONFIG_CMD_PRINTENV=y
-CONFIG_CMD_SAVEENV=y
-CONFIG_CMD_FILETYPE=y
-CONFIG_CMD_UNCOMPRESS=y
-CONFIG_CMD_SLEEP=y
-CONFIG_CMD_DHCP=y
-CONFIG_CMD_PING=y
-CONFIG_CMD_TFTP=y
-CONFIG_CMD_ECHO_E=y
-CONFIG_CMD_EDIT=y
-CONFIG_CMD_LOGIN=y
-CONFIG_CMD_MENU=y
-CONFIG_CMD_MENU_MANAGEMENT=y
-CONFIG_CMD_PASSWD=y
-CONFIG_CMD_READLINE=y
-CONFIG_CMD_TIMEOUT=y
-CONFIG_CMD_CRC=y
-CONFIG_CMD_CRC_CMP=y
-CONFIG_CMD_CLK=y
-CONFIG_CMD_DETECT=y
-CONFIG_CMD_POWEROFF=y
-CONFIG_CMD_OFTREE=y
-CONFIG_NET=y
-CONFIG_NET_NFS=y
-CONFIG_NET_NETCONSOLE=y
-CONFIG_OF_BAREBOX_DRIVERS=y
-CONFIG_SERIAL_AMBA_PL011=y
-CONFIG_VIRTIO_CONSOLE=y
-CONFIG_DRIVER_NET_SMC91111=y
-# CONFIG_SPI is not set
-CONFIG_MTD=y
-CONFIG_MTD_CONCAT=y
-CONFIG_DRIVER_CFI=y
-CONFIG_VIRTIO_BLK=y
-CONFIG_MCI=y
-CONFIG_MCI_MMCI=y
-CONFIG_HWRNG=y
-CONFIG_HW_RANDOM_VIRTIO=y
-# CONFIG_PINCTRL is not set
-CONFIG_VIRTIO_MMIO=y
-CONFIG_FS_EXT4=y
-CONFIG_FS_TFTP=y
-CONFIG_FS_FAT=y
-CONFIG_DIGEST_SHA1_GENERIC=y
-CONFIG_DIGEST_SHA256_GENERIC=y
-- 
2.39.2



From m.olbrich at pengutronix.de  Wed Apr 26 01:46:59 2023
From: m.olbrich at pengutronix.de (Michael Olbrich)
Date: Wed, 26 Apr 2023 10:46:59 +0200
Subject: [PATCH] net: ifup: pass hostname and linuxdevname to linux with DHCP
Message-ID: <20230426084659.4002852-1-m.olbrich@pengutronix.de>

Barebox always uses the hostname in the DHCP request. To configure
kernel networking, use the long ip= syntax for DHCP and set the hostname
as well. This way, Barebox and Linux use the same hostname in the DHCP
request.
Also set the device if linuxdevname is configured. This is already done
for static configurations. Do the same for DHCP.

Signed-off-by: Michael Olbrich <m.olbrich at pengutronix.de>
---
 net/ifup.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/net/ifup.c b/net/ifup.c
index 1870f7401714..18ab1363c748 100644
--- a/net/ifup.c
+++ b/net/ifup.c
@@ -159,8 +159,8 @@ out:
 
 static void set_linux_bootarg(struct eth_device *edev)
 {
+	char *bootarg;
 	if (edev->global_mode == ETH_MODE_STATIC) {
-		char *bootarg;
 		IPaddr_t serverip;
 		IPaddr_t gateway;
 
@@ -176,7 +176,11 @@ static void set_linux_bootarg(struct eth_device *edev)
 		dev_set_param(&edev->dev, "linux.bootargs", bootarg);
 		free(bootarg);
 	} else if (edev->global_mode == ETH_MODE_DHCP) {
-		dev_set_param(&edev->dev, "linux.bootargs", "ip=dhcp");
+		bootarg = basprintf("ip=::::%s:%s:dhcp",
+				barebox_get_hostname(),
+				edev->linuxdevname ? edev->linuxdevname : "");
+		dev_set_param(&edev->dev, "linux.bootargs", bootarg);
+		free(bootarg);
 	}
 }
 
-- 
2.39.2



From s.hauer at pengutronix.de  Wed Apr 26 02:03:51 2023
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Apr 2023 11:03:51 +0200
Subject: [PATCH 0/3] Compile boards only when firmware is present
Message-ID: <20230426090354.1350981-1-s.hauer@pengutronix.de>

We have recently introduced ARM multi_*_defconfig files to compile
for multiple SoC families in a single config. Before these can
successfully be compiled a bunch of firmware files need to be present
in the source tree. This can be inconvenient for users as they have
to grab the firmware files from several sources before they can
compile these configs, even though they might be only interested
in a single board.

To solve this make the boards depending on a firmware file selectable
only when the firmware is actually present. With this the
multi_*_defconfigs can always be built. Boards with missing firmware
files will be skipped from compilation automatically.

The next step might be to introduce a Kconfig option (or use existing
COMPILE_TEST option) to provide dummy files for the missing firmware
files which could help for compile testing.

Sascha

Sascha Hauer (3):
  Kconfig: source Kconfig.include earlier
  ARM: Rockchip: make boards only selectable when firmware is present
  ARM: i.MX: make boards selectable only when firmware files are present

 Kconfig                        |  2 +
 arch/arm/mach-imx/Kconfig      | 74 ++++++++++++++++++++++------------
 arch/arm/mach-rockchip/Kconfig | 11 +++--
 firmware/Kconfig               | 21 ++++++++++
 lib/kasan/Kconfig              |  2 -
 5 files changed, 80 insertions(+), 30 deletions(-)

-- 
2.39.2



From s.hauer at pengutronix.de  Wed Apr 26 02:03:52 2023
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Apr 2023 11:03:52 +0200
Subject: [PATCH 1/3] Kconfig: source Kconfig.include earlier
In-Reply-To: <20230426090354.1350981-1-s.hauer@pengutronix.de>
References: <20230426090354.1350981-1-s.hauer@pengutronix.de>
Message-ID: <20230426090354.1350981-2-s.hauer@pengutronix.de>

kconfig.include is included where first needed. Include it at the top
so that all Kconfig files can use it.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 Kconfig           | 2 ++
 lib/kasan/Kconfig | 2 --
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Kconfig b/Kconfig
index 7e9b892129..49bd17c89f 100644
--- a/Kconfig
+++ b/Kconfig
@@ -6,6 +6,8 @@
 #
 mainmenu "Barebox/$(ARCH) $(KERNELVERSION) Configuration"
 
+source "scripts/Kconfig.include"
+
 source "arch/$(SRCARCH)/Kconfig"
 
 source "common/Kconfig"
diff --git a/lib/kasan/Kconfig b/lib/kasan/Kconfig
index 46fc4f263b..e96638304c 100644
--- a/lib/kasan/Kconfig
+++ b/lib/kasan/Kconfig
@@ -1,7 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-source "scripts/Kconfig.include"
-
 config HAVE_ARCH_KASAN
 	bool
 
-- 
2.39.2



From s.hauer at pengutronix.de  Wed Apr 26 02:03:53 2023
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Apr 2023 11:03:53 +0200
Subject: [PATCH 2/3] ARM: Rockchip: make boards only selectable when firmware is present
In-Reply-To: <20230426090354.1350981-1-s.hauer@pengutronix.de>
References: <20230426090354.1350981-1-s.hauer@pengutronix.de>
Message-ID: <20230426090354.1350981-3-s.hauer@pengutronix.de>

The RK356x based boards need a sdram-init.bin file in the board
directory. Make the boards selectable only when the file is present
to avoid failing compilation when the file is missing.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-rockchip/Kconfig | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
index 0bce83ecee..7acbd87473 100644
--- a/arch/arm/mach-rockchip/Kconfig
+++ b/arch/arm/mach-rockchip/Kconfig
@@ -69,30 +69,35 @@ if 64BIT
 
 config MACH_RK3568_EVB
 	select ARCH_RK3568
+	depends on $(success,test -e $(srctree)/arch/arm/boards/rockchip-rk3568-evb/sdram-init.bin)
 	bool "RK3568 EVB"
 	help
 	  Say Y here if you are using a RK3568 EVB
 
 config MACH_RK3568_BPI_R2PRO
 	select ARCH_RK3568
+	depends on $(success,test -e $(srctree)/arch/arm/boards/rockchip-rk3568-bpi-r2pro/sdram-init.bin)
 	bool "RK3568 BPI R2PRO"
 	help
 	  Say Y here if you are using a RK3568 Bananpi R2 Pro
 
 config MACH_PINE64_QUARTZ64
 	select ARCH_RK3568
+	depends on $(success,test -e $(srctree)/arch/arm/boards/pine64-quartz64/sdram-init.bin)
 	bool "Pine64 Quartz64"
 	help
 	  Say Y here if you are using a Pine64 Quartz64
 
 config MACH_RADXA_ROCK3
-       select ARCH_RK3568
-       bool "Radxa ROCK3"
-       help
+	select ARCH_RK3568
+	depends on $(success,test -e $(srctree)/arch/arm/boards/radxa-rock3/sdram-init.bin)
+	bool "Radxa ROCK3"
+	help
 	  Say Y here if you are using a Radxa ROCK3
 
 config MACH_RADXA_CM3
 	select ARCH_RK3568
+	depends on $(success,test -e $(srctree)/arch/arm/boards/radxa-cm3/sdram-init.bin)
 	bool "Radxa CM3"
 	help
 	  Say Y here if you are using a Radxa CM3
-- 
2.39.2



From s.hauer at pengutronix.de  Wed Apr 26 02:03:54 2023
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Apr 2023 11:03:54 +0200
Subject: [PATCH 3/3] ARM: i.MX: make boards selectable only when firmware files are present
In-Reply-To: <20230426090354.1350981-1-s.hauer@pengutronix.de>
References: <20230426090354.1350981-1-s.hauer@pengutronix.de>
Message-ID: <20230426090354.1350981-4-s.hauer@pengutronix.de>

Some i.MX boards need firmware files in the source tree. Make the boards
depending on firmware files selectable only when the firmware is there
to avoid failing compilation.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-imx/Kconfig | 74 ++++++++++++++++++++++++++-------------
 firmware/Kconfig          | 21 +++++++++++
 2 files changed, 70 insertions(+), 25 deletions(-)

diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index ef0e5fc561..e10e84faa7 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -555,11 +555,35 @@ if 64BIT
 
 comment "i.MX8M boards"
 
+if !FIRMWARE_IMX_LPDDR4_PMU_TRAIN
+comment "LPDDR4 firmware files missing, some boards are not selectable"
+endif
+
+if !FIRMWARE_IMX_DDR4_PMU_TRAIN
+comment "DDR4 firmware files missing, some boards are not selectable"
+endif
+
+if !FIRMWARE_IMX8MM_ATF
+comment "i.MX8MM TF-A files missing, i.MX8MM boards are disabled"
+endif
+
+if !FIRMWARE_IMX8MQ_ATF
+comment "i.MX8MQ TF-A files missing, i.MX8MQ boards are disabled"
+endif
+
+if !FIRMWARE_IMX8MN_ATF
+comment "i.MX8MN TF-A files missing, i.MX8MN boards are disabled"
+endif
+
+if !FIRMWARE_IMX8MP_ATF
+comment "i.MX8MP TF-A files missing, i.MX8MP boards are disabled"
+endif
+
 config MACH_INNOCOMM_WB15
 	bool "InnoComm WB15 (i.MX8MM) EVK"
 	select ARCH_IMX8MM
-	select FIRMWARE_IMX_LPDDR4_PMU_TRAIN
-	select FIRMWARE_IMX8MM_ATF
+	depends on FIRMWARE_IMX_LPDDR4_PMU_TRAIN
+	depends on FIRMWARE_IMX8MM_ATF
 	select ARM_SMCCC
 	select MCI_IMX_ESDHC_PBL
 	select IMX8M_DRAM
@@ -570,8 +594,8 @@ config MACH_INNOCOMM_WB15
 config MACH_MNT_REFORM
 	bool "MNT Reform"
 	select ARCH_IMX8MQ
-	select FIRMWARE_IMX_LPDDR4_PMU_TRAIN
-	select FIRMWARE_IMX8MQ_ATF
+	depends on FIRMWARE_IMX_LPDDR4_PMU_TRAIN
+	depends on FIRMWARE_IMX8MQ_ATF
 	select ARM_SMCCC
 	select MCI_IMX_ESDHC_PBL
 	select I2C_IMX_EARLY
@@ -579,8 +603,8 @@ config MACH_MNT_REFORM
 config MACH_NXP_IMX8MM_EVK
 	bool "NXP i.MX8MM EVK Board"
 	select ARCH_IMX8MM
-	select FIRMWARE_IMX_LPDDR4_PMU_TRAIN
-	select FIRMWARE_IMX8MM_ATF
+	depends on FIRMWARE_IMX_LPDDR4_PMU_TRAIN
+	depends on FIRMWARE_IMX8MM_ATF
 	select ARM_SMCCC
 	select MCI_IMX_ESDHC_PBL
 	select IMX8M_DRAM
@@ -590,9 +614,9 @@ config MACH_NXP_IMX8MM_EVK
 config MACH_NXP_IMX8MN_EVK
 	bool "NXP i.MX8MN EVK Board"
 	select ARCH_IMX8MN
-	select FIRMWARE_IMX_LPDDR4_PMU_TRAIN
-	select FIRMWARE_IMX_DDR4_PMU_TRAIN
-	select FIRMWARE_IMX8MN_ATF
+	depends on FIRMWARE_IMX_LPDDR4_PMU_TRAIN
+	depends on FIRMWARE_IMX_DDR4_PMU_TRAIN
+	depends on FIRMWARE_IMX8MN_ATF
 	select ARM_SMCCC
 	select MCI_IMX_ESDHC_PBL
 	select IMX8M_DRAM
@@ -601,8 +625,8 @@ config MACH_NXP_IMX8MN_EVK
 config MACH_NXP_IMX8MP_EVK
 	bool "NXP i.MX8MP EVK Board"
 	select ARCH_IMX8MP
-	select FIRMWARE_IMX_LPDDR4_PMU_TRAIN
-	select FIRMWARE_IMX8MP_ATF
+	depends on FIRMWARE_IMX_LPDDR4_PMU_TRAIN
+	depends on FIRMWARE_IMX8MP_ATF
 	select ARM_SMCCC
 	select MCI_IMX_ESDHC_PBL
 	select IMX8M_DRAM
@@ -611,24 +635,24 @@ config MACH_NXP_IMX8MP_EVK
 config MACH_NXP_IMX8MQ_EVK
 	bool "NXP i.MX8MQ EVK Board"
 	select ARCH_IMX8MQ
-	select FIRMWARE_IMX_LPDDR4_PMU_TRAIN
-	select FIRMWARE_IMX8MQ_ATF
+	depends on FIRMWARE_IMX_LPDDR4_PMU_TRAIN
+	depends on FIRMWARE_IMX8MQ_ATF
 	select ARM_SMCCC
 	select MCI_IMX_ESDHC_PBL
 
 config MACH_PHYTEC_SOM_IMX8MQ
 	bool "Phytec i.MX8M SOM"
 	select ARCH_IMX8MQ
-	select FIRMWARE_IMX_LPDDR4_PMU_TRAIN
-	select FIRMWARE_IMX8MQ_ATF
+	depends on FIRMWARE_IMX_LPDDR4_PMU_TRAIN
+	depends on FIRMWARE_IMX8MQ_ATF
 	select ARM_SMCCC
 	select MCI_IMX_ESDHC_PBL
 
 config MACH_POLYHEX_DEBIX
 	bool "Polyhex DEBIX Model-A/B (i.MX8MP) Board"
 	select ARCH_IMX8MP
-	select FIRMWARE_IMX_LPDDR4_PMU_TRAIN
-	select FIRMWARE_IMX8MP_ATF
+	depends on FIRMWARE_IMX_LPDDR4_PMU_TRAIN
+	depends on FIRMWARE_IMX8MP_ATF
 	select ARM_SMCCC
 	select MCI_IMX_ESDHC_PBL
 	select IMX8M_DRAM
@@ -637,8 +661,8 @@ config MACH_POLYHEX_DEBIX
 config MACH_PROTONIC_IMX8M
 	bool "Protonic-Holland i.MX8Mx based boards"
 	select ARCH_IMX8MM
-	select FIRMWARE_IMX_LPDDR4_PMU_TRAIN
-	select FIRMWARE_IMX8MM_ATF
+	depends on FIRMWARE_IMX_LPDDR4_PMU_TRAIN
+	depends on FIRMWARE_IMX8MM_ATF
 	select ARM_SMCCC
 	select MCI_IMX_ESDHC_PBL
 	select IMX8M_DRAM
@@ -647,8 +671,8 @@ config MACH_PROTONIC_IMX8M
 config MACH_TQ_MBA8MPXL
 	bool "TQ i.MX8MP Dual/Quad on MBa8MPxL Board"
 	select ARCH_IMX8MP
-	select FIRMWARE_IMX_LPDDR4_PMU_TRAIN
-	select FIRMWARE_IMX8MP_ATF
+	depends on FIRMWARE_IMX_LPDDR4_PMU_TRAIN
+	depends on FIRMWARE_IMX8MP_ATF
 	select ARM_SMCCC
 	select MCI_IMX_ESDHC_PBL
 	select IMX8M_DRAM
@@ -657,8 +681,8 @@ config MACH_TQ_MBA8MPXL
 config MACH_VARISCITE_DT8MCUSTOMBOARD_IMX8MP
 	bool "Variscite DT8MCustomBoard with DART-MX8M-PLUS"
 	select ARCH_IMX8MP
-	select FIRMWARE_IMX_LPDDR4_PMU_TRAIN
-	select FIRMWARE_IMX8MP_ATF
+	depends on FIRMWARE_IMX_LPDDR4_PMU_TRAIN
+	depends on FIRMWARE_IMX8MP_ATF
 	select ARM_SMCCC
 	select MCI_IMX_ESDHC_PBL
 	select IMX8M_DRAM
@@ -667,8 +691,8 @@ config MACH_VARISCITE_DT8MCUSTOMBOARD_IMX8MP
 config MACH_ZII_IMX8MQ_DEV
 	bool "ZII i.MX8MQ based devices"
 	select ARCH_IMX8MQ
-	select FIRMWARE_IMX_LPDDR4_PMU_TRAIN
-	select FIRMWARE_IMX8MQ_ATF
+	depends on FIRMWARE_IMX_LPDDR4_PMU_TRAIN
+	depends on FIRMWARE_IMX8MQ_ATF
 	select ARM_SMCCC
 	select MCI_IMX_ESDHC_PBL
 	select MACH_ZII_COMMON
diff --git a/firmware/Kconfig b/firmware/Kconfig
index a12a8f3044..0f76a836af 100644
--- a/firmware/Kconfig
+++ b/firmware/Kconfig
@@ -8,33 +8,54 @@ config EXTRA_FIRMWARE_DIR
 
 config FIRMWARE_IMX_LPDDR4_PMU_TRAIN
 	bool
+	default y
+	depends on $(success,test -e $(srctree)/firmware/lpddr4_pmu_train_1d_dmem.bin)
+	depends on $(success,test -e $(srctree)/firmware/lpddr4_pmu_train_1d_imem.bin)
+	depends on $(success,test -e $(srctree)/firmware/lpddr4_pmu_train_2d_dmem.bin)
+	depends on $(success,test -e $(srctree)/firmware/lpddr4_pmu_train_2d_imem.bin)
 
 config FIRMWARE_IMX_DDR4_PMU_TRAIN
 	bool
+	default y
+	depends on $(success,test -e $(srctree)/firmware/ddr4_dmem_1d.bin)
+	depends on $(success,test -e $(srctree)/firmware/ddr4_dmem_2d.bin)
+	depends on $(success,test -e $(srctree)/firmware/ddr4_imem_1d.bin)
+	depends on $(success,test -e $(srctree)/firmware/ddr4_imem_2d.bin)
 
 config FIRMWARE_IMX8MM_ATF
 	bool
+	default y
+	depends on $(success,test -e $(srctree)/firmware/imx8mm-bl31.bin)
 
 config FIRMWARE_IMX8MN_ATF
 	bool
+	default y
+	depends on $(success,test -e $(srctree)/firmware/imx8mn-bl31.bin)
 
 config FIRMWARE_IMX8MP_ATF
 	bool
+	default y
+	depends on $(success,test -e $(srctree)/firmware/imx8mp-bl31.bin)
 
 config FIRMWARE_IMX8MQ_ATF
 	bool
+	default y
+	depends on $(success,test -e $(srctree)/firmware/imx8mq-bl31.bin)
 
 config FIRMWARE_IMX8MM_OPTEE
 	bool "install OP-TEE on i.MX8MM boards"
 	depends on FIRMWARE_IMX8MM_ATF && PBL_OPTEE
+	depends on $(success,test -e $(srctree)/firmware/imx8mm-bl32.bin)
 
 config FIRMWARE_IMX8MN_OPTEE
 	bool "install OP-TEE on i.MX8MN boards"
 	depends on FIRMWARE_IMX8MN_ATF && PBL_OPTEE
+	depends on $(success,test -e $(srctree)/firmware/imx8mn-bl32.bin)
 
 config FIRMWARE_IMX8MP_OPTEE
 	bool "install OP-TEE on i.MX8MP boards"
 	depends on FIRMWARE_IMX8MP_ATF && PBL_OPTEE
+	depends on $(success,test -e $(srctree)/firmware/imx8mp-bl32.bin)
 
 config FIRMWARE_CCBV2_OPTEE
 	bool
-- 
2.39.2



From andreas at kemnade.info  Wed Apr 26 12:09:36 2023
From: andreas at kemnade.info (Andreas Kemnade)
Date: Wed, 26 Apr 2023 21:09:36 +0200
Subject: rn5t618 vs. rn5t568
Message-ID: <20230426210936.7531e177@aktux>

Hi,

just looked a bit around in the source and stumbled across drivers/mfd/rn5t568.c

It contains
 * MFD core driver for Ricoh RN5T618 PMIC

but the filename is rn5t568.c That is very confusing.
 a compatible ricoh,rn5t568 (but 567) does not exist in the kernel.

So which chip this is really about? Did not analyse things deeper yet.

I am also curious because I wrote most stuff in the kernel about the rn5t618/rc5t619.

Regards,
Andreas


From sha at pengutronix.de  Thu Apr 27 00:36:30 2023
From: sha at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Apr 2023 09:36:30 +0200
Subject: rn5t618 vs. rn5t568
In-Reply-To: <20230426210936.7531e177@aktux>
References: <20230426210936.7531e177@aktux>
Message-ID: <20230427073630.GT13543@pengutronix.de>

On Wed, Apr 26, 2023 at 09:09:36PM +0200, Andreas Kemnade wrote:
> Hi,
> 
> just looked a bit around in the source and stumbled across drivers/mfd/rn5t568.c
> 
> It contains
>  * MFD core driver for Ricoh RN5T618 PMIC
> 
> but the filename is rn5t568.c That is very confusing.
>  a compatible ricoh,rn5t568 (but 567) does not exist in the kernel.
> 
> So which chip this is really about? Did not analyse things deeper yet.
> 
> I am also curious because I wrote most stuff in the kernel about the rn5t618/rc5t619.

J?rgen had to support the rn5t568 which is not yet supported in Linux.
He took the Kernel rn5t618.c driver and adjusted it accordingly. J?rgen
can't remember exactly, but he said the chips are quite similar.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Apr 27 06:18:45 2023
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Apr 2023 15:18:45 +0200
Subject: [PATCH] mci: dove: Add unhandled enumeration value
Message-ID: <20230427131845.1325365-1-s.hauer@pengutronix.de>

Fixes:

drivers/mci/dove-sdhci.c: In function 'dove_sdhci_mci_set_ios':
drivers/mci/dove-sdhci.c:185:9: warning: enumeration value 'MMC_BUS_WIDTH_1' not handled in switch [-Wswitch]

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/dove-sdhci.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/mci/dove-sdhci.c b/drivers/mci/dove-sdhci.c
index ff75bb8059..0c73441d5a 100644
--- a/drivers/mci/dove-sdhci.c
+++ b/drivers/mci/dove-sdhci.c
@@ -189,6 +189,8 @@ static void dove_sdhci_mci_set_ios(struct mci_host *mci, struct mci_ios *ios)
 	case MMC_BUS_WIDTH_4:
 		val |= SDHCI_CTRL_4BITBUS;
 		break;
+	case MMC_BUS_WIDTH_1:
+		break;
 	}
 
 	if (ios->clock > 26000000)
-- 
2.39.2



From wsa at kernel.org  Thu Apr 27 10:25:50 2023
From: wsa at kernel.org (Wolfram Sang)
Date: Thu, 27 Apr 2023 19:25:50 +0200
Subject: [PATCH 0/3] mtd: nand: atmel: legacy: fix boot on USB-A9G20
In-Reply-To: <ZBn/ShAwKik7TdvZ@ravnborg.org>
References: <20230319154909.24047-1-wsa@kernel.org>
 <ZBdZxskg+JPzUY0t@ravnborg.org>
 <ZBd+Z+qn9rjuvp6S@sai.fritz.box>
 <20230321085848.GI7446@pengutronix.de>
 <ZBnnbU1SUkNm4ryz@sai.fritz.box>
 <ZBn/ShAwKik7TdvZ@ravnborg.org>
Message-ID: <ZEqwHm8i8z+wueOz@sai>


> > I accidently erased it, so my journey for unbricking the device began.
> > at91bootstrap, openocd, barebox - they all once supported A9G20, but
> > nowadays all of them were broken. Well, I fixed openocd and barebox
> > mostly so far, the bootstrap is still the missing piece.
> 
> You may be hit by the newer gcc optimize the delays in
> the sdram init code in at91bootstrap.

The issue was something else: SAM-BA failed to flash the bootstrap
because it couldn't get the SDRAM initialized before. I still didn't
figure out why. Flashing the bootstrap with barebox never got it
executed. I now found out that SAM-BA is modifying one vector at runtime
before flashing. What is 'endaddress of blob in RAM' becomes 'filesize
of blob'. If I modify my binary bootstrap like this, I can flash it with
barebox and finally have a working device again. Phew!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20230427/1ccb03eb/attachment.sig>

From wsa at kernel.org  Thu Apr 27 10:26:21 2023
From: wsa at kernel.org (Wolfram Sang)
Date: Thu, 27 Apr 2023 19:26:21 +0200
Subject: [PATCH 0/3] mtd: nand: atmel: legacy: fix boot on USB-A9G20
In-Reply-To: <20230321085848.GI7446@pengutronix.de>
References: <20230319154909.24047-1-wsa@kernel.org>
 <ZBdZxskg+JPzUY0t@ravnborg.org>
 <ZBd+Z+qn9rjuvp6S@sai.fritz.box>
 <20230321085848.GI7446@pengutronix.de>
Message-ID: <ZEqwPa5hQFnpE584@sai>

Hi Sascha,

> Anyway, what's really missing is DT support. I scribbled a patch to get
> you started in case you are motivated. Basically it's: Compile in the
> device tree, throw away all the device registration from the board code,
> see where it gets you and fix the fallout ;)

So, I tried this patch and if the fallout was just some errnos or
devices missing, I would have fixed it. Sadly, the actual fallout is
that the board doesn't boot without any printing. This needs more
debugging than what I am willing to invest currently. But I can bring
the device to Prague if someone from PTX wants to try.

All the best,

   Wolfram
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20230427/59624d1c/attachment.sig>

From wsa at kernel.org  Thu Apr 27 11:47:16 2023
From: wsa at kernel.org (Wolfram Sang)
Date: Thu, 27 Apr 2023 20:47:16 +0200
Subject: [PATCH 0/2] ARM: at91: usb-a9g20: make it work out of the box again
Message-ID: <20230427184718.105393-1-wsa@kernel.org>

Here are the remaining two patches to make a (for me) useable barebox
with the defconfig and no other patches. Comments welcome!

Wolfram Sang (2):
  ARM: at91: usb-a926x: remove nand partitions from config
  defconfigs: usb-a9g20: update to a working version

 .../boards/usb-a926x/defaultenv-usb-a926x/config  |  4 ----
 arch/arm/configs/usb_a9g20_defconfig              | 15 ++++++---------
 2 files changed, 6 insertions(+), 13 deletions(-)

-- 
2.35.1



From wsa at kernel.org  Thu Apr 27 11:47:17 2023
From: wsa at kernel.org (Wolfram Sang)
Date: Thu, 27 Apr 2023 20:47:17 +0200
Subject: [PATCH 1/2] ARM: at91: usb-a926x: remove nand partitions from config
In-Reply-To: <20230427184718.105393-1-wsa@kernel.org>
References: <20230427184718.105393-1-wsa@kernel.org>
Message-ID: <20230427184718.105393-2-wsa@kernel.org>

We define partitions as well in the board file. Leading to:

New partition nand0.at91bootstrap (0x00000000-0x0001ffff) on nand0 overlaps with partition at91bootstrap_raw (0x00000000-0x0001ffff), not creating it
cannot create nand0.at91bootstrap: Invalid argument
addpart: Invalid argument

So, remove it from the config file.

Signed-off-by: Wolfram Sang <wsa at kernel.org>
---

Or shall I rather remove it from the board file?

 arch/arm/boards/usb-a926x/defaultenv-usb-a926x/config | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/arch/arm/boards/usb-a926x/defaultenv-usb-a926x/config b/arch/arm/boards/usb-a926x/defaultenv-usb-a926x/config
index 49199ba391..f9159cb946 100644
--- a/arch/arm/boards/usb-a926x/defaultenv-usb-a926x/config
+++ b/arch/arm/boards/usb-a926x/defaultenv-usb-a926x/config
@@ -29,10 +29,6 @@ kernelimage=zImage
 #kernelimage=Image
 #kernelimage=Image.lzo
 
-nand_device=atmel_nand
-nand_parts="128k(at91bootstrap),256k(barebox)ro,128k(bareboxenv),128k(bareboxenv2),128k(oftree),4M(kernel),120M(rootfs),-(data)"
-rootfs_mtdblock_nand=6
-
 autoboot_timeout=3
 
 bootargs="console=ttyS0,115200"
-- 
2.35.1



From wsa at kernel.org  Thu Apr 27 11:47:18 2023
From: wsa at kernel.org (Wolfram Sang)
Date: Thu, 27 Apr 2023 20:47:18 +0200
Subject: [PATCH 2/2] defconfigs: usb-a9g20: update to a working version
In-Reply-To: <20230427184718.105393-1-wsa@kernel.org>
References: <20230427184718.105393-1-wsa@kernel.org>
Message-ID: <20230427184718.105393-3-wsa@kernel.org>

The defconfig needs to be updated to get a usable barebox:

We need bigger malloc because of the increasing kernel size, soft ECC so
NAND will work, ifup and relocatable for easier development. Fix the
prompt while here. Sadly, because of size restrictions, FAT, NFS, menus,
netconsole, and SHA1 have to go.

Signed-off-by: Wolfram Sang <wsa at kernel.org>
---
 arch/arm/configs/usb_a9g20_defconfig | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/arch/arm/configs/usb_a9g20_defconfig b/arch/arm/configs/usb_a9g20_defconfig
index 20b1f27b9e..56f78ba7a8 100644
--- a/arch/arm/configs/usb_a9g20_defconfig
+++ b/arch/arm/configs/usb_a9g20_defconfig
@@ -5,9 +5,11 @@ CONFIG_AEABI=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
 CONFIG_BAREBOX_MAX_IMAGE_SIZE=0x40000
+CONFIG_MALLOC_SIZE=0x800000
 CONFIG_EXPERIMENTAL=y
 CONFIG_MALLOC_TLSF=y
-CONFIG_PROMPT="USB-9G20:"
+CONFIG_RELOCATABLE=y
+CONFIG_PROMPT="USB-A9G20:"
 CONFIG_PROMPT_HUSH_PS2="y"
 CONFIG_HUSH_FANCY_PROMPT=y
 CONFIG_CMDLINE_EDITING=y
@@ -33,16 +35,14 @@ CONFIG_CMD_EXPORT=y
 CONFIG_CMD_PRINTENV=y
 CONFIG_CMD_SAVEENV=y
 CONFIG_CMD_MD5SUM=y
-CONFIG_CMD_SHA1SUM=y
 CONFIG_CMD_SLEEP=y
 CONFIG_CMD_DHCP=y
+CONFIG_NET_CMD_IFUP=y
 CONFIG_CMD_PING=y
 CONFIG_CMD_TFTP=y
 CONFIG_CMD_ECHO_E=y
 CONFIG_CMD_EDIT=y
 CONFIG_CMD_LOGIN=y
-CONFIG_CMD_MENU=y
-CONFIG_CMD_MENU_MANAGEMENT=y
 CONFIG_CMD_PASSWD=y
 CONFIG_CMD_READLINE=y
 CONFIG_CMD_TIMEOUT=y
@@ -53,14 +53,13 @@ CONFIG_CMD_SPI=y
 CONFIG_CMD_LED_TRIGGER=y
 CONFIG_CMD_OFTREE=y
 CONFIG_NET=y
-CONFIG_NET_NFS=y
-CONFIG_NET_NETCONSOLE=y
 CONFIG_NET_RESOLV=y
 CONFIG_DRIVER_NET_MACB=y
 CONFIG_DRIVER_SPI_ATMEL=y
 CONFIG_MTD=y
 # CONFIG_MTD_OOB_DEVICE is not set
 CONFIG_NAND=y
+CONFIG_MTD_NAND_ECC_SOFT=y
 CONFIG_NAND_ATMEL=y
 CONFIG_USB_GADGET=y
 CONFIG_USB_GADGET_DFU=y
@@ -72,7 +71,5 @@ CONFIG_MMC_SPI_CRC_ON=y
 CONFIG_LED=y
 CONFIG_LED_GPIO=y
 CONFIG_LED_TRIGGERS=y
+# CONFIG_VIRTIO_MENU is not set
 CONFIG_FS_TFTP=y
-CONFIG_FS_FAT=y
-CONFIG_FS_FAT_WRITE=y
-CONFIG_FS_FAT_LFN=y
-- 
2.35.1



