Re: [PATCH v2] usb: gadget: ether: split start/stop from init/halt

2023-01-26 Thread Niel Fourie

Hi Kevin,

On 25/01/2023 23:50, Kevin Hilman wrote:

Niel Fourie  writes:


Split out _usb_eth_start() from _usb_eth_init() and
usb_eth_stop() from _usb_eth_halt(). Now _usb_eth_init() only
initialises and registers the gadget device, which _usb_eth_halt()
reverses, and together are used for probing and removing the
device. The _usb_eth_start() and _usb_eth_stop() functions connect
and disconnect the gadget as expected by the start()/stop()
callbacks.

Previously the gadget device was probed on every start() and
removed on every stop(), which is inconsistent with other DM_ETH
drivers.


By suggestion from Marek, I was testing this patch and discovered that
it broke fastboot over USB support.  With this patch applied on top of
v2022.10, I'm seeing:

=> fastboot 0
couldn't find an available UDC
g_dnl_register: failed!, error: -19

Kevin


Thank you very much! That is another use case that I have not thought 
about and I will look into it. Unfortunately the side effects of the 
patch is not trivial, so I highly appreciate the feedback.


Best regards,
Niel Fourie

--
DENX Software Engineering GmbH,Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de


[RFC][PATCH] usb: dwc3: gadget: workaround for Netconsole hang

2023-01-23 Thread Niel Fourie
In dwc3_remove_requests(), the while loops clearing out request
lists req_queued and request_list may loop infinitely as the last
remaining elements in these lists end up not pointing to their
respective list_head structures. This workaround detects and
replaces the last element with the expected list_head to break out
of these loops. No memory is leaked as the previous last element gets
reused.

This issue occurs when Netconsole is active over Ethernet gadget,
and the cause it is still unclear. Any ideas?

Signed-off-by: Niel Fourie 
Cc: Marek Vasut 
---
 drivers/usb/dwc3/gadget.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index eb416b832a..61f3e367cb 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -538,6 +538,14 @@ static void dwc3_remove_requests(struct dwc3 *dwc, struct 
dwc3_ep *dep)
req = next_request(>req_queued);
 
dwc3_gadget_giveback(dep, req, -ESHUTDOWN);
+   /* FIXME! */
+   if (dep->req_queued.next == dep->req_queued.prev &&
+   dep->req_queued.next != >req_queued) {
+   printf("Stuck? Emptying req_queued... head=%lx, 
next=%lx;\n",
+  (ulong)>req_queued, 
(ulong)dep->req_queued.next);
+   dep->req_queued.next = >req_queued;
+   dep->req_queued.prev = >req_queued;
+   }
}
}
 
@@ -545,6 +553,14 @@ static void dwc3_remove_requests(struct dwc3 *dwc, struct 
dwc3_ep *dep)
req = next_request(>request_list);
 
dwc3_gadget_giveback(dep, req, -ESHUTDOWN);
+   /* FIXME! */
+   if (dep->request_list.next == dep->request_list.prev &&
+   dep->request_list.next != >request_list) {
+   printf("Stuck? Emptying request_list... head=%lx, 
next=%lx;\n",
+  (ulong)>request_list, 
(ulong)dep->request_list.next);
+   dep->request_list.next = >request_list;
+   dep->request_list.prev = >request_list;
+   }
}
 }
 
-- 
2.39.0



Re: [PATCH v2] usb: gadget: ether: split start/stop from init/halt

2023-01-23 Thread Niel Fourie

Hi Marek

On 20/01/2023 19:42, Marek Vasut wrote:

On 1/20/23 18:15, Niel Fourie wrote:

[...]

Same question as in V1 below.


+static int _usb_eth_start(struct ether_priv *priv)
+{
+    unsigned long timeout = USB_CONNECT_TIMEOUT;
+    struct eth_dev *dev = >ethdev;
+    unsigned long ts;
+    if (!dev->gadget)
+    return -1;
+
+    dev->network_started = 0;



Will this work on systems which already have netconsole active ? I think 
this would break the netconsole connection, since the network would be 
reinitialized, won't it ?


Good question, sorry for being unclear in my previous email. The upper 
layers appear to do a good job of taking the connection down and then 
bringing it up again when the network_started calls remain where they 
are. Here is an example run (copied from the serial console with console 
multiplexing enabled), where the last two dhcp calls were happily issued 
over the Netconsole:


u-boot=> bind /soc@0/usb@32f10100/usb@3810 dwc3-generic-peripheral
u-boot=> bind /soc@0/usb@32f10100/usb@3810 usb_ether
u-boot=> setenv autoload no
u-boot=> setenv ethact eth2
u-boot=> setenv nc 'setenv stdout serial,nc;setenv stdin serial,nc'
u-boot=> setenv ncip 10.42.0.1
u-boot=> dhcp
using dwc3-gadget, OUT ep2out IN ep1in STATUS ep3in
MAC de:ad:be:ef:00:01
HOST MAC de:ad:be:ef:00:00
high speed config #1: 2 mA, Ethernet Gadget, using CDC Ethernet
ep1in is already disabled
ep2out is already disabled
USB network up!
BOOTP broadcast 1
DHCP client bound to address 10.42.0.65 (193 ms)
u-boot=> run nc
u-boot=> high speed config #1: 2 mA, Ethernet Gadget, using CDC Ethernet
ep1in is already disabled
ep2out is already disabled
USB network up!

u-boot=> dhcp
BOOTP broadcast 1
DHCP client bound to address 10.42.0.65 (153 ms)
u-boot=> high speed config #1: 2 mA, Ethernet Gadget, using CDC Ethernet
ep1in is already disabled
ep2out is already disabled
USB network up!

u-boot=> dhcp
BOOTP broadcast 1
DHCP client bound to address 10.42.0.65 (144 ms)
u-boot=> Stuck? Emptying request_list... head=bdf617c8, next=bdf64c88;
high speed config #1: 2 mA, Ethernet Gadget, using CDC Ethernet
ep1in is already disabled
ep2out is already disabled
USB network up!

u-boot=>

The "Stuck? Emptying request_list... head=bdf617c8, next=bdf64c88;" 
message comes from the dwc3 workaround I mentioned in the previous 
email. I will share it later as RFC, because I am a bit stumped at how 
the list_head ends up not being in the list when Netconsole is enabled.


I would expect this assignment to be in _init and _stop , not in _start 
callback.


I tried moving the dev->network_started as you requested, and it caused 
the driver to hang, on (say) the second "dhcp" command, even without 
Netconsole enabled. Unfortunately GDB was not particularly helpful in 
getting a backtrace for identifying exactly where/why.


But I wonder whether the current ethernet uclass interface running code 
does not make the entire network_started mechanism obsolete. See the 
patch which you referenced previously in related patch:


fa795f45254 ("net: eth-uclass: avoid running start() twice without stop()")


From what I could gather from my testing (shown above) it appears to 
working as expected, but I admit I am not sure how/why. The 
dev->network_started variable appears to be specific to the ether.c 
file, and does not directly interact with the other layers, like eth-uclass.


I wish I could give you a better explanation...

Best regards,
Niel Fourie

--
DENX Software Engineering GmbH,Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de


Re: [PATCH] usb: gadget: ether: split start/stop from init/halt

2023-01-20 Thread Niel Fourie

Hi Marek

On 18/12/2022 02:51, Marek Vasut wrote:

On 12/16/22 17:35, lu...@denx.de wrote:

Hi Marek,


Hi,

[...]


Should "[PATCH v2] net: eth-uclass: revalidate priv after stop() in
eth_halt()" be dropped ? It seems this patch fully replaces it.


That old patch only exists for in case there were showstopper issues 
with the new patch which I missed, or as a stopgap if major changes 
were needed first. I did my best to test the new patch on the hardware 
I have, but if any other gadget drivers were to misbehave, I would not 
know about it, for example. But if you are happy with this new patch, 
that old patch could gladly be dropped.


The new patch is by far preferable. If you can sort out the 
network_started comment, I would like to pick this via usb/next.


I did some more testing and I found that keeping network_started as it 
is works best, so I did not change it for v2 of this patch.


Unfortunately during local testing (on imx8mp), I uncovered an issue in 
the dwc3 gadget driver causing it to hang. I have a workaround, but I am 
still looking into fixing the root cause, and that would have to be 
fixed in a separate patch series.


Similar issues might also still crop up with other gadget drivers.

Best regards,
Niel Fourie

--
DENX Software Engineering GmbH,Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de


[PATCH v2] usb: gadget: ether: split start/stop from init/halt

2023-01-20 Thread Niel Fourie
Split out _usb_eth_start() from _usb_eth_init() and
usb_eth_stop() from _usb_eth_halt(). Now _usb_eth_init() only
initialises and registers the gadget device, which _usb_eth_halt()
reverses, and together are used for probing and removing the
device. The _usb_eth_start() and _usb_eth_stop() functions connect
and disconnect the gadget as expected by the start()/stop()
callbacks.

Previously the gadget device was probed on every start() and
removed on every stop(), which is inconsistent with other DM_ETH
drivers.

Signed-off-by: Niel Fourie 
Cc: Marek Vasut 
Cc: Lukasz Majewski 
Cc: Ramon Fried 
---
Changes for v2:
- fixed variable declaration order
- removed non-DM_ETH code due to upstream removal during rebasing

 drivers/usb/gadget/ether.c | 51 +-
 1 file changed, 39 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 85c971e4c4..914427eb77 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -2274,15 +2274,11 @@ fail:
 
 /*-*/
 static void _usb_eth_halt(struct ether_priv *priv);
+static void _usb_eth_stop(struct ether_priv *priv);
 
 static int _usb_eth_init(struct ether_priv *priv)
 {
-   struct eth_dev *dev = >ethdev;
-   struct usb_gadget *gadget;
-   unsigned long ts;
int ret;
-   unsigned long timeout = USB_CONNECT_TIMEOUT;
-
ret = usb_gadget_initialize(0);
if (ret)
return ret;
@@ -2322,14 +2318,26 @@ static int _usb_eth_init(struct ether_priv *priv)
priv->eth_driver.resume = eth_resume;
if (usb_gadget_register_driver(>eth_driver) < 0)
goto fail;
+   return 0;
+fail:
+   _usb_eth_halt(priv);
+   return -1;
+}
 
-   dev->network_started = 0;
+static int _usb_eth_start(struct ether_priv *priv)
+{
+   unsigned long timeout = USB_CONNECT_TIMEOUT;
+   struct eth_dev *dev = >ethdev;
+   unsigned long ts;
 
+   if (!dev->gadget)
+   return -1;
+
+   dev->network_started = 0;
packet_received = 0;
packet_sent = 0;
 
-   gadget = dev->gadget;
-   usb_gadget_connect(gadget);
+   usb_gadget_connect(dev->gadget);
 
if (env_get("cdc_connect_timeout"))
timeout = dectoul(env_get("cdc_connect_timeout"), NULL) * 
CONFIG_SYS_HZ;
@@ -2347,6 +2355,7 @@ static int _usb_eth_init(struct ether_priv *priv)
rx_submit(dev, dev->rx_req, 0);
return 0;
 fail:
+   _usb_eth_stop(priv);
_usb_eth_halt(priv);
return -1;
 }
@@ -2426,11 +2435,10 @@ static int _usb_eth_recv(struct ether_priv *priv)
return 0;
 }
 
-static void _usb_eth_halt(struct ether_priv *priv)
+static void _usb_eth_stop(struct ether_priv *priv)
 {
struct eth_dev *dev = >ethdev;
 
-   /* If the gadget not registered, simple return */
if (!dev->gadget)
return;
 
@@ -2454,6 +2462,14 @@ static void _usb_eth_halt(struct ether_priv *priv)
usb_gadget_handle_interrupts(0);
dev->network_started = 0;
}
+}
+
+static void _usb_eth_halt(struct ether_priv *priv)
+{
+   struct eth_dev *dev = >ethdev;
+
+   if (!dev->gadget)
+   return;
 
usb_gadget_unregister_driver(>eth_driver);
usb_gadget_release(0);
@@ -2463,7 +2479,7 @@ static int usb_eth_start(struct udevice *dev)
 {
struct ether_priv *priv = dev_get_priv(dev);
 
-   return _usb_eth_init(priv);
+   return _usb_eth_start(priv);
 }
 
 static int usb_eth_send(struct udevice *dev, void *packet, int length)
@@ -2513,7 +2529,7 @@ static void usb_eth_stop(struct udevice *dev)
 {
struct ether_priv *priv = dev_get_priv(dev);
 
-   _usb_eth_halt(priv);
+   _usb_eth_stop(priv);
 }
 
 static int usb_eth_probe(struct udevice *dev)
@@ -2527,6 +2543,16 @@ static int usb_eth_probe(struct udevice *dev)
get_ether_addr(CONFIG_USBNET_DEV_ADDR, pdata->enetaddr);
eth_env_set_enetaddr("usbnet_devaddr", pdata->enetaddr);
 
+   return _usb_eth_init(priv);
+
+   return 0;
+}
+
+static int usb_eth_remove(struct udevice *dev)
+{
+   struct ether_priv *priv = dev_get_priv(dev);
+
+   _usb_eth_halt(priv);
return 0;
 }
 
@@ -2562,6 +2588,7 @@ U_BOOT_DRIVER(eth_usb) = {
.name   = "usb_ether",
.id = UCLASS_ETH,
.probe  = usb_eth_probe,
+   .remove = usb_eth_remove,
.ops= _eth_ops,
.priv_auto  = sizeof(struct ether_priv),
.plat_auto  = sizeof(struct eth_pdata),
-- 
2.39.0



Re: [PATCH] usb: gadget: ether: split start/stop from init/halt

2022-12-13 Thread Niel Fourie

Hi Marek,

On 12/12/2022 17:46, Marek Vasut wrote:

On 12/12/22 16:29, Niel Fourie wrote:

Split out _usb_eth_start() from _usb_eth_init() and
usb_eth_stop() from _usb_eth_halt(). Now _usb_eth_init() only
initialises and registers the gadget device, which _usb_eth_halt()
reverses, and together are used for probing and removing the
device. The _usb_eth_start() and _usb_eth_stop() functions connect
and disconnect the gadget as expected by the start()/stop()
callbacks.

Previously the gadget device was probed on every start() and
removed on every stop(), which is inconsistent with other DM_ETH
drivers. For non-DM gadget drivers the old behaviour has been
retained.


Does this mean the udevice pointer and associated private date are 
retained during the entire operation of the USB gadget , i.e. even 
between stop/start cycles ?


In the DM_ETH case, yes. The drivers/devices remain registered the whole 
time between _usb_eth_init() and _usb_eth_halt(), and the need for 
revalidating the private data pointer falls away as was done in my 
previous patch.


I tested this on imx8mp with the dwc3 gadget driver, and the data 
structures, specifically the private data, remained intact from probe() 
until remove(). I also tested that probing again after removal works as 
expected.


I tested the non-DM_ETH case on an iMX6 Phytec Mira (pcm058) which uses 
the ci_udc.c driver, which appears to not support DM_ETH yet. In that 
case the gadget drivers get registered/unregistered in 
usb_eth_init()/usb_eth_halt().


The legacy non-DM_ETH implementation uses init()/halt() similarly to 
start()/stop() in the DM_ETH implementation, but had no further 
equivalent for probe()/remove() in struct eth_device. When the Ethernet 
gadget was ported to DM_ETH, this difference most likely lead to the 
existing implementation.


I unfortunately did not have other devices on hand to test against, so I 
am hoping that there are no other surprises.


Best regards,
Niel Fourie

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de


[PATCH] usb: gadget: ether: split start/stop from init/halt

2022-12-12 Thread Niel Fourie
Split out _usb_eth_start() from _usb_eth_init() and
usb_eth_stop() from _usb_eth_halt(). Now _usb_eth_init() only
initialises and registers the gadget device, which _usb_eth_halt()
reverses, and together are used for probing and removing the
device. The _usb_eth_start() and _usb_eth_stop() functions connect
and disconnect the gadget as expected by the start()/stop()
callbacks.

Previously the gadget device was probed on every start() and
removed on every stop(), which is inconsistent with other DM_ETH
drivers. For non-DM gadget drivers the old behaviour has been
retained.

Signed-off-by: Niel Fourie 
Cc: Marek Vasut 
Cc: Lukasz Majewski 
Cc: Ramon Fried 
---
 drivers/usb/gadget/ether.c | 58 +-
 1 file changed, 45 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 43aec7ffa70..a75b4eeb5bb 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -2305,15 +2305,11 @@ fail:
 
 /*-*/
 static void _usb_eth_halt(struct ether_priv *priv);
+static void _usb_eth_stop(struct ether_priv *priv);
 
 static int _usb_eth_init(struct ether_priv *priv)
 {
-   struct eth_dev *dev = >ethdev;
-   struct usb_gadget *gadget;
-   unsigned long ts;
int ret;
-   unsigned long timeout = USB_CONNECT_TIMEOUT;
-
ret = usb_gadget_initialize(0);
if (ret)
return ret;
@@ -2353,14 +2349,26 @@ static int _usb_eth_init(struct ether_priv *priv)
priv->eth_driver.resume = eth_resume;
if (usb_gadget_register_driver(>eth_driver) < 0)
goto fail;
+   return 0;
+fail:
+   _usb_eth_halt(priv);
+   return -1;
+}
 
-   dev->network_started = 0;
+static int _usb_eth_start(struct ether_priv *priv)
+{
+   unsigned long ts;
+   unsigned long timeout = USB_CONNECT_TIMEOUT;
+   struct eth_dev *dev = >ethdev;
+
+   if (!dev->gadget)
+   return -1;
 
+   dev->network_started = 0;
packet_received = 0;
packet_sent = 0;
 
-   gadget = dev->gadget;
-   usb_gadget_connect(gadget);
+   usb_gadget_connect(dev->gadget);
 
if (env_get("cdc_connect_timeout"))
timeout = dectoul(env_get("cdc_connect_timeout"), NULL) * 
CONFIG_SYS_HZ;
@@ -2378,6 +2386,7 @@ static int _usb_eth_init(struct ether_priv *priv)
rx_submit(dev, dev->rx_req, 0);
return 0;
 fail:
+   _usb_eth_stop(priv);
_usb_eth_halt(priv);
return -1;
 }
@@ -2457,11 +2466,10 @@ static int _usb_eth_recv(struct ether_priv *priv)
return 0;
 }
 
-static void _usb_eth_halt(struct ether_priv *priv)
+static void _usb_eth_stop(struct ether_priv *priv)
 {
struct eth_dev *dev = >ethdev;
 
-   /* If the gadget not registered, simple return */
if (!dev->gadget)
return;
 
@@ -2485,6 +2493,14 @@ static void _usb_eth_halt(struct ether_priv *priv)
usb_gadget_handle_interrupts(0);
dev->network_started = 0;
}
+}
+
+static void _usb_eth_halt(struct ether_priv *priv)
+{
+   struct eth_dev *dev = >ethdev;
+
+   if (!dev->gadget)
+   return;
 
usb_gadget_unregister_driver(>eth_driver);
usb_gadget_release(0);
@@ -2493,9 +2509,13 @@ static void _usb_eth_halt(struct ether_priv *priv)
 #ifndef CONFIG_DM_ETH
 static int usb_eth_init(struct eth_device *netdev, struct bd_info *bd)
 {
+   int ret;
struct ether_priv *priv = (struct ether_priv *)netdev->priv;
 
-   return _usb_eth_init(priv);
+   ret = _usb_eth_init(priv);
+   if (!ret)
+   ret = _usb_eth_start(priv);
+   return ret;
 }
 
 static int usb_eth_send(struct eth_device *netdev, void *packet, int length)
@@ -2536,6 +2556,7 @@ void usb_eth_halt(struct eth_device *netdev)
 {
struct ether_priv *priv = (struct ether_priv *)netdev->priv;
 
+   _usb_eth_stop(priv);
_usb_eth_halt(priv);
 }
 
@@ -2559,7 +2580,7 @@ static int usb_eth_start(struct udevice *dev)
 {
struct ether_priv *priv = dev_get_priv(dev);
 
-   return _usb_eth_init(priv);
+   return _usb_eth_start(priv);
 }
 
 static int usb_eth_send(struct udevice *dev, void *packet, int length)
@@ -2609,7 +2630,7 @@ static void usb_eth_stop(struct udevice *dev)
 {
struct ether_priv *priv = dev_get_priv(dev);
 
-   _usb_eth_halt(priv);
+   _usb_eth_stop(priv);
 }
 
 static int usb_eth_probe(struct udevice *dev)
@@ -2623,6 +2644,16 @@ static int usb_eth_probe(struct udevice *dev)
get_ether_addr(CONFIG_USBNET_DEV_ADDR, pdata->enetaddr);
eth_env_set_enetaddr("usbnet_devaddr", pdata->enetaddr);
 
+   return _usb_eth_init(priv);
+
+   return 0;
+}
+
+static int usb_eth_remove(struct udevice *dev)
+{
+  

[PATCH v2] net: eth-uclass: revalidate priv after stop() in eth_halt()

2022-12-12 Thread Niel Fourie
In eth_halt(), reread and revalidate priv after calling stop(),
as it may have been freed, leaving a dangling pointer.

In the ethernet gadget implementation, the gadget device gets
probed during start() and removed during stop(), which includes
freeing `uclass_priv_` to which `priv` is pointing. Writing to
`priv` after stop() may corrupt the `fd` member of `struct
malloc_chunk`, which represents the freed block, and could cause
hard-to-debug crashes on subsequent calls to malloc()/free().

Signed-off-by: Niel Fourie 
Cc: Ramon Fried 
Cc: Marek Vasut 
Cc: Lukasz Majewski 
---
Changes for v2:
- Revalidate priv instead of changing state before stop()
- Added explanational comment

This patch my be dropped if the patch which addresses the root cause
("usb: gadget: ether: split start/stop from init/halt") is accepted.

 net/eth-uclass.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index f41da4b37b3..7d5783b5cab 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -341,8 +341,11 @@ void eth_halt(void)
priv = dev_get_uclass_priv(current);
if (!priv || !priv->running)
return;
-
eth_get_ops(current)->stop(current);
+   /* Ethernet gadget frees priv during stop, workaround until fixed... */
+   priv = dev_get_uclass_priv(current);
+   if (!priv || !priv->running)
+   return;
priv->state = ETH_STATE_PASSIVE;
priv->running = false;
 }
-- 
2.38.1



Re: [PATCH] net: eth-uclass: change state before stop() in eth_halt()

2022-12-05 Thread Niel Fourie

Hi Marek,

On 05/12/2022 13:06, Niel Fourie wrote:
[...]

It does however show that this patch introduces a bug -- this patch 
changes the order in which priv->state = ETH_STATE_PASSIVE; is 
assigned from _after_ the ->stop callback to _before_ the -> stop 
callback. This breaks drivers/net/ldpaa_eth/ldpaa_eth.c which checks 
the priv->state in its ->stop callback, either on its own in non-DM 
case, or in eth_is_active() implementation in DM case. With this 
patch, the interface would never be stopped in the ->stop callback, 
because the condition (net_dev->state == ETH_STATE_PASSIVE) test in 
the ldpaa stop callback implementation would always be true.




In drivers/net/ldpaa_eth/ldpaa_eth.c:ldpaa_eth_stop(), priv is of type
struct ldpaa_eth_priv*, defined in drivers/net/ldpaa_eth/ldpaa_eth.h and 
is accessed using dev_get_priv().


In net/eth-uclass.c:eht_halt(), priv is of type struct eth_device_priv* 
and defined in the same .c file, and is accessed using 
dev_get_uclass_priv(). As the structure is local to this file, nothing 
outside of this file should have any knowledge of its contents, and 
changing of the order of the calls should only impact this file.


I sincerely hope that these two are not interfering with each other, 
otherwise we have much bigger problems...




Shucks, I was thrown off by the the fact that net_dev is of type struct 
eth_device, and its member state is separate from struct 
eth_device_state and its member state, that I missed the implication of 
eth_is_active() *setting* the value of struct eth_device_priv's state 
not *reading* it.


Well spotted, you are correct. The patch in its current form would 
introduce that bug. Thank you for finding that.


Adding back the call to dev_get_uclass_priv() to get priv and validating 
it again *after* stop() as it was done before commit fa795f45254 ("net: 
eth-uclass: avoid running start() twice without stop()") would fix this, 
and perhaps also make the issue with stop() and Ethernet gadget more 
obvious. A comment on why it needs to be repeated would also be useful. 
Would this be an acceptable improvement?


I agree that fixing the USB ethernet gadget is still the best solution, 
but until that happens, we could at least limit everyone's pain.


Best regards,
Niel Fourie

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de


Re: [PATCH] net: eth-uclass: change state before stop() in eth_halt()

2022-12-05 Thread Niel Fourie

Hi Marek,

On 04/12/2022 03:17, Marek Vasut wrote:

On 12/2/22 11:36, Niel Fourie wrote:

Hi Marek,


Hi,


On 01/12/2022 11:44, Marek Vasut wrote:

On 12/1/22 09:24, Lukasz Majewski wrote:

On Wed, 30 Nov 2022 17:42:25 +0100
Niel Fourie  wrote:


In eth_halt(), change the private uclass state before calling
stop() instead of afterwards, to avoid writing to memory which
may have been freed during stop().

In the ethernet gadget implementation, the gadget device gets
probed during start() and removed during stop(), which includes
freeing `uclass_priv_` to which `priv` is pointing. Writing to
`priv` after stop() may corrupt the `fd` member of `struct
malloc_chunk`, which represents the freed block, and could cause
hard-to-debug crashes on subsequent calls to malloc()/free().

Signed-off-by: Niel Fourie 
Cc: Ramon Fried 
Cc: Marek Vasut 
Cc: Lukasz Majewski 
---
  net/eth-uclass.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index f41da4b37b3..bc3b9751e32 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -342,9 +342,9 @@ void eth_halt(void)
  if (!priv || !priv->running)
  return;
-    eth_get_ops(current)->stop(current);
  priv->state = ETH_STATE_PASSIVE;
  priv->running = false;
+    eth_get_ops(current)->stop(current);
  }
  int eth_is_active(struct udevice *dev)


Reviewed-by: Lukasz Majewski 


How come nobody triggered this problem with regular ethernet in U-Boot ?

If this is isolated to USB gadget ethernet, then please do not hack 
around this in core networking code, but rather fix the USB ethernet 
gadget itself. It seems that gadget code should not unregister the 
gadget in drivers/usb/gadget/ether.c _usb_eth_halt() , at least not 
fully.


The reason is simple, the regular ethernet drivers do not get removed 
on stop() like for the gadget ethernet driver, and in their case 
`priv` is still valid.


The suggestion for a proper fix is in the last paragraph above -- do not 
unregister the usb ethernet gadget device in halt(), keep the gadget 
device registered. Then the priv pointer would be valid. (*)


I agree on your point that reworking the ethernet gadget code would be 
preferable, but this would be a much bigger effort (and if I were to 
do it, I would probably introduce even more bugs). I am not certain 
whether this would not also affect the non-DM gadget implementation as 
well, which still contain drivers like ci_udc.c which does not appear 
to have been ported to DM gadget yet? (I only see DM USB there...)


That said, I am not certain whether this is not also bug, as I am not 
certain whether the assumption that `priv` should be available after 
stop() is valid or not.


The documentation at 
https://source.denx.de/u-boot/u-boot/-/blob/master/doc/develop/driver-model/ethernet.rst?plain=1#L135 states:


The **stop** function should turn off / disable the hardware and place 
it back in its reset state.  It can be called at any time (before any 
call to the related start() function), so make sure it can handle this 
sort of thing.


The ->stop callback is supposed to stop the interface, turn off its DMA, 
but NOT deallocate the device (and its associated data) behind it.


In such a complete reset state I am not certain whether the assumption 
that `priv` should exist is still valid, at least not without another 
call to dev_get_uclass_priv() and revalidating it first?


In case a device is probe()d, its private data are also allocated and 
available, so yes, 'priv' pointer should still be valid.


Granted, the usb gadget driver implementation is problematic, and it 
definitely belongs on the TODO list.


That being said, priv not being valid at this stage is not a new 
problem, as validation for it after stop() was explicitly added in 
commit c3211708 ("net: eth-uclass: Fix for DM USB ethernet support") for 
this reason 4 years ago. Fortunately in that case, it just fixed a null 
pointer de-reference, not corruption of freed memory.


Lastly, this assumption that priv is still valid is rather new and it 
was introduced here:


https://source.denx.de/u-boot/u-boot/-/commit/fa795f452541ce07b33be603de36cac3c5d7dfcf


I disagree, the device private data are valid during the entire lifespan 
of the device. That assumption has been baked into the driver model 
itself and far predates that commit.


In case of a usb ethernet, the lifespan of the device starts with the 
'bind' command which triggers the ->bind callback, and first use which 
triggers its ->probe callback. The lifespan ends with 'unbind' command 
or OS boot, which triggers ->remove callback and ->unbind callbacks.


This commit appears to be a workaround for drivers which cannot deal 
with stop() being called at any time as required in the above quoted 
documentation.


This commit prevents network device ->start() from being called multiple 
times, which is a valid precaution, as calling start while t

Re: [PATCH] net: eth-uclass: change state before stop() in eth_halt()

2022-12-02 Thread Niel Fourie

Hi Marek,

On 01/12/2022 11:44, Marek Vasut wrote:

On 12/1/22 09:24, Lukasz Majewski wrote:

On Wed, 30 Nov 2022 17:42:25 +0100
Niel Fourie  wrote:


In eth_halt(), change the private uclass state before calling
stop() instead of afterwards, to avoid writing to memory which
may have been freed during stop().

In the ethernet gadget implementation, the gadget device gets
probed during start() and removed during stop(), which includes
freeing `uclass_priv_` to which `priv` is pointing. Writing to
`priv` after stop() may corrupt the `fd` member of `struct
malloc_chunk`, which represents the freed block, and could cause
hard-to-debug crashes on subsequent calls to malloc()/free().

Signed-off-by: Niel Fourie 
Cc: Ramon Fried 
Cc: Marek Vasut 
Cc: Lukasz Majewski 
---
  net/eth-uclass.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index f41da4b37b3..bc3b9751e32 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -342,9 +342,9 @@ void eth_halt(void)
  if (!priv || !priv->running)
  return;
-    eth_get_ops(current)->stop(current);
  priv->state = ETH_STATE_PASSIVE;
  priv->running = false;
+    eth_get_ops(current)->stop(current);
  }
  int eth_is_active(struct udevice *dev)


Reviewed-by: Lukasz Majewski 


How come nobody triggered this problem with regular ethernet in U-Boot ?

If this is isolated to USB gadget ethernet, then please do not hack 
around this in core networking code, but rather fix the USB ethernet 
gadget itself. It seems that gadget code should not unregister the 
gadget in drivers/usb/gadget/ether.c _usb_eth_halt() , at least not fully.


The reason is simple, the regular ethernet drivers do not get removed on 
stop() like for the gadget ethernet driver, and in their case `priv` is 
still valid.


I agree on your point that reworking the ethernet gadget code would be 
preferable, but this would be a much bigger effort (and if I were to do 
it, I would probably introduce even more bugs). I am not certain whether 
this would not also affect the non-DM gadget implementation as well, 
which still contain drivers like ci_udc.c which does not appear to have 
been ported to DM gadget yet? (I only see DM USB there...)


That said, I am not certain whether this is not also bug, as I am not 
certain whether the assumption that `priv` should be available after 
stop() is valid or not.


The documentation at 
https://source.denx.de/u-boot/u-boot/-/blob/master/doc/develop/driver-model/ethernet.rst?plain=1#L135 
states:


The **stop** function should turn off / disable the hardware and place 
it back in its reset state.  It can be called at any time (before any 
call to the related start() function), so make sure it can handle this 
sort of thing.


In such a complete reset state I am not certain whether the assumption 
that `priv` should exist is still valid, at least not without another 
call to dev_get_uclass_priv() and revalidating it first?


Lastly, this assumption that priv is still valid is rather new and it 
was introduced here:


https://source.denx.de/u-boot/u-boot/-/commit/fa795f452541ce07b33be603de36cac3c5d7dfcf

This commit appears to be a workaround for drivers which cannot deal 
with stop() being called at any time as required in the above quoted 
documentation.


I would consider adding a workaround to a workaround in this case to be 
the lesser evil, as tracking down this bug in the first place was like 
looking for a needle in a haystack. This change would at least save 
everybody else from strange crashes in particular configurations without 
any negative impact. But this is fortunately not my decision. :)


Best regards,
Niel Fourie

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de


[PATCH] net: eth-uclass: change state before stop() in eth_halt()

2022-11-30 Thread Niel Fourie
In eth_halt(), change the private uclass state before calling
stop() instead of afterwards, to avoid writing to memory which
may have been freed during stop().

In the ethernet gadget implementation, the gadget device gets
probed during start() and removed during stop(), which includes
freeing `uclass_priv_` to which `priv` is pointing. Writing to
`priv` after stop() may corrupt the `fd` member of `struct
malloc_chunk`, which represents the freed block, and could cause
hard-to-debug crashes on subsequent calls to malloc()/free().

Signed-off-by: Niel Fourie 
Cc: Ramon Fried 
Cc: Marek Vasut 
Cc: Lukasz Majewski 
---
 net/eth-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index f41da4b37b3..bc3b9751e32 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -342,9 +342,9 @@ void eth_halt(void)
if (!priv || !priv->running)
return;
 
-   eth_get_ops(current)->stop(current);
priv->state = ETH_STATE_PASSIVE;
priv->running = false;
+   eth_get_ops(current)->stop(current);
 }
 
 int eth_is_active(struct udevice *dev)
-- 
2.38.1



[PATCH] ARM: pcm058: Match mainline Linux NAND ECC layout/behaviour

2021-03-22 Thread Niel Fourie
Enabled "fsl,legacy-bch-geometry" in U-Boot device tree overlay
to match the legacy BCH geometry layout, which mainline Linux
applies when "fsl,use-minimum-ecc" is not specified in the device
tree.

Reinstated SYS_NAND_ONFI_DETECTION, which when disabled, masked
the mismatch on SOMs with Winbond NAND flash chips.

Signed-off-by: Niel Fourie 
---
 arch/arm/dts/imx6q-phytec-mira-rdk-nand-u-boot.dtsi | 5 +
 include/configs/pcm058.h| 1 +
 2 files changed, 6 insertions(+)

diff --git a/arch/arm/dts/imx6q-phytec-mira-rdk-nand-u-boot.dtsi 
b/arch/arm/dts/imx6q-phytec-mira-rdk-nand-u-boot.dtsi
index 8555be16966..0bea652beea 100644
--- a/arch/arm/dts/imx6q-phytec-mira-rdk-nand-u-boot.dtsi
+++ b/arch/arm/dts/imx6q-phytec-mira-rdk-nand-u-boot.dtsi
@@ -40,3 +40,8 @@
  {
u-boot,dm-spl;
 };
+
+ {
+   fsl,legacy-bch-geometry;
+};
+
diff --git a/include/configs/pcm058.h b/include/configs/pcm058.h
index 4f03699117b..bc48e809498 100644
--- a/include/configs/pcm058.h
+++ b/include/configs/pcm058.h
@@ -19,6 +19,7 @@
 
 /* Enable NAND support */
 #define CONFIG_SYS_MAX_NAND_DEVICE 1
+#define CONFIG_SYS_NAND_ONFI_DETECTION
 
 /* Physical Memory Map */
 #define PHYS_SDRAM MMDC0_ARB_BASE_ADDR
-- 
2.30.2



[PATCH v2 3/3] PowerPC: keymile: Add support for kmcent2 board

2021-01-21 Thread Niel Fourie
Add basic support for the Hitachi Power Grids kmcent2 board, based
on the NXP QorIQ T1040 SoC.

Signed-off-by: Valentin Longchamp 
Signed-off-by: Rainer Boschung 
Signed-off-by: Niel Fourie 
Cc: Holger Brunck 
Cc: Heiko Schocher 
Cc: Priyanka Jain 
Cc: Stefan Roese 
---
Changes in v2:
- Sorted header includes as far as possible
- Removed all  includes
- Fixed block comment formatting
- Removed unnecessary #ifdefs
- Used if with IS_ENABLED() instead of #ifdefs where possible
- Moved MTDPARTS_DEFAULT/MTDIDS_DEFAULT to defconfig
- Fixed misc other formatting issues

 arch/powerpc/cpu/mpc85xx/Kconfig |   4 +
 arch/powerpc/dts/Makefile|   1 +
 arch/powerpc/dts/kmcent2-u-boot.dtsi |  97 +
 board/keymile/Kconfig|   1 +
 board/keymile/common/ivm.c   |   5 +
 board/keymile/kmcent2/Kconfig|  17 +
 board/keymile/kmcent2/MAINTAINERS|   8 +
 board/keymile/kmcent2/Makefile   |  15 +
 board/keymile/kmcent2/ddr.c  |  88 +
 board/keymile/kmcent2/kmcent2.c  | 353 ++
 board/keymile/kmcent2/law.c  |  24 ++
 board/keymile/kmcent2/tlb.c  | 104 ++
 configs/kmcent2_defconfig|  92 +
 include/configs/kmcent2.h| 513 +++
 14 files changed, 1322 insertions(+)
 create mode 100644 arch/powerpc/dts/kmcent2-u-boot.dtsi
 create mode 100644 board/keymile/kmcent2/Kconfig
 create mode 100644 board/keymile/kmcent2/MAINTAINERS
 create mode 100644 board/keymile/kmcent2/Makefile
 create mode 100644 board/keymile/kmcent2/ddr.c
 create mode 100644 board/keymile/kmcent2/kmcent2.c
 create mode 100644 board/keymile/kmcent2/law.c
 create mode 100644 board/keymile/kmcent2/tlb.c
 create mode 100644 configs/kmcent2_defconfig
 create mode 100644 include/configs/kmcent2.h

diff --git a/arch/powerpc/cpu/mpc85xx/Kconfig b/arch/powerpc/cpu/mpc85xx/Kconfig
index 54c7fd9522..c1a3770671 100644
--- a/arch/powerpc/cpu/mpc85xx/Kconfig
+++ b/arch/powerpc/cpu/mpc85xx/Kconfig
@@ -256,6 +256,10 @@ config TARGET_KMP204X
bool "Support kmp204x"
select VENDOR_KM
 
+config TARGET_KMCENT2
+   bool "Support kmcent2"
+   select VENDOR_KM
+
 config TARGET_XPEDITE520X
bool "Support xpedite520x"
select ARCH_MPC8548
diff --git a/arch/powerpc/dts/Makefile b/arch/powerpc/dts/Makefile
index 266d345f72..3ecda36538 100644
--- a/arch/powerpc/dts/Makefile
+++ b/arch/powerpc/dts/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0+
 
+dtb-$(CONFIG_TARGET_KMCENT2) += kmcent2.dtb
 dtb-$(CONFIG_TARGET_KMCOGE5NE) += kmcoge5ne.dtb
 dtb-$(CONFIG_TARGET_KMETER1) += kmeter1.dtb
 dtb-$(CONFIG_TARGET_KMOPTI2) += kmopti2.dtb
diff --git a/arch/powerpc/dts/kmcent2-u-boot.dtsi 
b/arch/powerpc/dts/kmcent2-u-boot.dtsi
new file mode 100644
index 00..ab76a9f122
--- /dev/null
+++ b/arch/powerpc/dts/kmcent2-u-boot.dtsi
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * (C) Copyright 2021  Niel Fourie 
+ */
+
+#include 
+
+/ {
+
+   aliases {
+   spi0 = "/soc@ffe00/spi@11";
+   i2c0 = "/soc@ffe00/i2c@118000";
+   i2c1 = "/soc@ffe00/i2c@118000/mux@70/i2c@0";
+   i2c2 = "/soc@ffe00/i2c@118000/mux@70/i2c@1";
+   i2c3 = "/soc@ffe00/i2c@118000/mux@70/i2c@7";
+   i2c4 = "/soc@ffe00/i2c@118100";
+   /delete-property/ pci1;
+   /delete-property/ pci2;
+   /delete-property/ pci3;
+   };
+
+   chosen {
+   stdout-path = "/soc@ffe00/serial@11c500";
+   };
+
+   soc@ffe00 {
+   u-boot,dm-pre-reloc;
+   spi@11 {
+   /* This documents where km_fpgacfg should be appear */
+   fpga@0 {
+   compatible = "keymile,fpga-conf";
+   reg = <0>;
+   spi-max-frequency = <2500>;
+   };
+   };
+
+   sdhc@114000 {
+   status = "okay";
+   };
+
+   i2c@118000 {
+   u-boot,dm-pre-reloc;
+   mux@70 {
+   i2c@1 { /* IVM bus */
+   reg = <1>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+   };
+   };
+   };
+
+   serial@11c500 {
+   u-boot,dm-pre-reloc;
+   clock-frequency = <2>;
+   };
+
+   fman@40 {
+   ethernet@e {
+   phy-c

[PATCH v2 2/3] keymile: common: update to set_env_hex(), fix "pram" radix

2021-01-21 Thread Niel Fourie
Replace instances of sprintf()/set_env() for setting hexadecimal
values with set_env_hex().

In set_km_env() the "pram" variable was set to an hexadecimal
value, while initr_mem() expects an unsigned decimal, so use
set_env_ulong() instead.

Signed-off-by: Niel Fourie 
Cc: Holger Brunck 
Cc: Heiko Schocher 
Cc: Priyanka Jain 
Cc: Stefan Roese 
---
Changes in v2:
- Replaced all relevant sprintf()/set_env() instances with
  set_env_hex()/set_env_ulong(), instead of only correcting
  the sprintf() formatting for "pram" radix to "%ul"

 board/keymile/common/common.c | 22 ++
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/board/keymile/common/common.c b/board/keymile/common/common.c
index df507e2790..71af1751ef 100644
--- a/board/keymile/common/common.c
+++ b/board/keymile/common/common.c
@@ -41,7 +41,6 @@ DECLARE_GLOBAL_DATA_PTR;
  */
 int set_km_env(void)
 {
-   uchar buf[32];
unsigned int pnvramaddr;
unsigned int pram;
unsigned int varaddr;
@@ -51,8 +50,7 @@ int set_km_env(void)
 
pnvramaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM
- CONFIG_KM_PNVRAM;
-   sprintf((char *)buf, "0x%x", pnvramaddr);
-   env_set("pnvramaddr", (char *)buf);
+   env_set_hex("pnvramaddr", pnvramaddr);
 
/* try to read rootfssize (ram image) from environment */
p = env_get("rootfssize");
@@ -60,16 +58,13 @@ int set_km_env(void)
strict_strtoul(p, 16, );
pram = (rootfssize + CONFIG_KM_RESERVED_PRAM + CONFIG_KM_PHRAM +
CONFIG_KM_PNVRAM) / 0x400;
-   sprintf((char *)buf, "0x%x", pram);
-   env_set("pram", (char *)buf);
+   env_set_ulong("pram", pram);
 
varaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM;
-   sprintf((char *)buf, "0x%x", varaddr);
-   env_set("varaddr", (char *)buf);
+   env_set_hex("varaddr", varaddr);
 
kernelmem = gd->ram_size - 0x400 * pram;
-   sprintf((char *)buf, "0x%x", kernelmem);
-   env_set("kernelmem", (char *)buf);
+   env_set_hex("kernelmem", kernelmem);
 
return 0;
 }
@@ -243,7 +238,6 @@ static int do_checkboardidhwk(struct cmd_tbl *cmdtp, int 
flag, int argc,
p = env_get("hwkey");
if (p)
rc = strict_strtoul(p, 16, );
-
if (rc != 0) {
printf("strict_strtoul returns error: %d", rc);
return rc;
@@ -305,15 +299,11 @@ static int do_checkboardidhwk(struct cmd_tbl *cmdtp, int 
flag, int argc,
 * set the values in environment variables.
 */
if (bid == ivmbid && hwkey == ivmhwkey) {
-   char buf[10];
-
found = 1;
envbid   = bid;
envhwkey = hwkey;
-   sprintf(buf, "%lx", bid);
-   env_set("boardid", buf);
-   sprintf(buf, "%lx", hwkey);
-   env_set("hwkey", buf);
+   env_set_hex("boardid", bid);
+   env_set_hex("hwkey", hwkey);
}
} /* end while( ! found ) */
}
-- 
2.29.2



[PATCH v2 1/3] PowerPC: dts: Pulled in kmcent2 dts files from Linux 5.10

2021-01-21 Thread Niel Fourie
Pulled in the kmcent2.dts and all its dependents from Linux 5.10,
commit 2c85ebc57b3e upstream. Replaced the license text with
SPDX License Identifiers.

Signed-off-by: Niel Fourie 
Reviewed-by: Stefan Roese 
Cc: Holger Brunck 
Cc: Heiko Schocher 
Cc: Priyanka Jain 
Cc: Stefan Roese 
---
Changes in v2:
- Reviewed by Stefan Roese 

 arch/powerpc/dts/elo3-dma-0.dtsi   |  55 ++
 arch/powerpc/dts/elo3-dma-1.dtsi   |  55 ++
 arch/powerpc/dts/kmcent2.dts   | 338 
 arch/powerpc/dts/qoriq-bman1.dtsi  |  14 +
 arch/powerpc/dts/qoriq-duart-0.dtsi|  24 +
 arch/powerpc/dts/qoriq-duart-1.dtsi|  24 +
 arch/powerpc/dts/qoriq-esdhc-0.dtsi|  13 +
 arch/powerpc/dts/qoriq-espi-0.dtsi |  14 +
 arch/powerpc/dts/qoriq-mpic.dtsi   |  79 +++
 arch/powerpc/dts/qoriq-qman3.dtsi  |  14 +
 arch/powerpc/dts/qoriq-sata2-0.dtsi|  12 +
 arch/powerpc/dts/qoriq-sata2-1.dtsi|  12 +
 arch/powerpc/dts/qoriq-sec5.0-0.dtsi   |  83 +++
 arch/powerpc/dts/qoriq-usb2-dr-0.dtsi  |  14 +
 arch/powerpc/dts/qoriq-usb2-mph-0.dtsi |  14 +
 arch/powerpc/dts/t1040si-post.dtsi | 727 +
 arch/powerpc/dts/t104xsi-pre.dtsi  |  88 +++
 17 files changed, 1580 insertions(+)
 create mode 100644 arch/powerpc/dts/elo3-dma-0.dtsi
 create mode 100644 arch/powerpc/dts/elo3-dma-1.dtsi
 create mode 100644 arch/powerpc/dts/kmcent2.dts
 create mode 100644 arch/powerpc/dts/qoriq-bman1.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-duart-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-duart-1.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-esdhc-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-espi-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-mpic.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-qman3.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-sata2-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-sata2-1.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-sec5.0-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-usb2-dr-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-usb2-mph-0.dtsi
 create mode 100644 arch/powerpc/dts/t1040si-post.dtsi
 create mode 100644 arch/powerpc/dts/t104xsi-pre.dtsi

diff --git a/arch/powerpc/dts/elo3-dma-0.dtsi b/arch/powerpc/dts/elo3-dma-0.dtsi
new file mode 100644
index 00..c3f7737256
--- /dev/null
+++ b/arch/powerpc/dts/elo3-dma-0.dtsi
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * QorIQ Elo3 DMA device tree stub [ controller @ offset 0x10 ]
+ *
+ * Copyright 2013 Freescale Semiconductor Inc.
+ */
+
+dma0: dma@100300 {
+   #address-cells = <1>;
+   #size-cells = <1>;
+   compatible = "fsl,elo3-dma";
+   reg = <0x100300 0x4>,
+ <0x100600 0x4>;
+   ranges = <0x0 0x100100 0x500>;
+   dma-channel@0 {
+   compatible = "fsl,eloplus-dma-channel";
+   reg = <0x0 0x80>;
+   interrupts = <28 2 0 0>;
+   };
+   dma-channel@80 {
+   compatible = "fsl,eloplus-dma-channel";
+   reg = <0x80 0x80>;
+   interrupts = <29 2 0 0>;
+   };
+   dma-channel@100 {
+   compatible = "fsl,eloplus-dma-channel";
+   reg = <0x100 0x80>;
+   interrupts = <30 2 0 0>;
+   };
+   dma-channel@180 {
+   compatible = "fsl,eloplus-dma-channel";
+   reg = <0x180 0x80>;
+   interrupts = <31 2 0 0>;
+   };
+   dma-channel@300 {
+   compatible = "fsl,eloplus-dma-channel";
+   reg = <0x300 0x80>;
+   interrupts = <76 2 0 0>;
+   };
+   dma-channel@380 {
+   compatible = "fsl,eloplus-dma-channel";
+   reg = <0x380 0x80>;
+   interrupts = <77 2 0 0>;
+   };
+   dma-channel@400 {
+   compatible = "fsl,eloplus-dma-channel";
+   reg = <0x400 0x80>;
+   interrupts = <78 2 0 0>;
+   };
+   dma-channel@480 {
+   compatible = "fsl,eloplus-dma-channel";
+   reg = <0x480 0x80>;
+   interrupts = <79 2 0 0>;
+   };
+};
diff --git a/arch/powerpc/dts/elo3-dma-1.dtsi b/arch/powerpc/dts/elo3-dma-1.dtsi
new file mode 100644
index 00..a61c88649c
--- /dev/null
+++ b/arch/powerpc/dts/elo3-dma-1.dtsi
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * QorIQ Elo3 DMA device tree stub [ controller @ offset 0x101000 ]
+ *
+ * Copyright 2013 Freescale Semiconductor Inc.
+ */
+
+dma1: dma@101300 {
+   #address-cells = <1>;
+   #size-cells = <1>;
+   compatible = "fsl,elo3-dma";
+   reg = <0x101300 0x4>,
+ <0x101600 0x4>;
+   ranges = <0x0 0x101100 0x500>;
+   dma-channel@0 {

[PATCH v2 0/3] PowerPC: keymile: Add support for kmcent2 board

2021-01-21 Thread Niel Fourie
This patch series adds basic support for the Hitachi Power Grids
(previously Keymile and ABB) kmcent2 board, based on the NXP QorIQ
T1040 SoC.

Patch 1/3 pulls in the device trees from Linux 5.10
Patch 2/3 fixes a minor bug common to all the Keymile boards.
Patch 3/3 finally adds the U-boot support for the kmcent2

Changes in v2:
- DTs pulled in from Linux reviewed
- In common.c, use set_env_hex()/set_env_ulong()
- Sort header includes, remove  includes
- Removed unnecessary #ifdefs
- Moved MTDPARTS_DEFAULT/MTDIDS_DEFAULT to defconfig

Niel Fourie (3):
  PowerPC: dts: Pulled in kmcent2 dts files from Linux 5.10
  keymile: common: update to set_env_hex(), fix "pram" radix
  PowerPC: keymile: Add support for kmcent2 board

 arch/powerpc/cpu/mpc85xx/Kconfig   |   4 +
 arch/powerpc/dts/Makefile  |   1 +
 arch/powerpc/dts/elo3-dma-0.dtsi   |  55 ++
 arch/powerpc/dts/elo3-dma-1.dtsi   |  55 ++
 arch/powerpc/dts/kmcent2-u-boot.dtsi   |  97 
 arch/powerpc/dts/kmcent2.dts   | 338 
 arch/powerpc/dts/qoriq-bman1.dtsi  |  14 +
 arch/powerpc/dts/qoriq-duart-0.dtsi|  24 +
 arch/powerpc/dts/qoriq-duart-1.dtsi|  24 +
 arch/powerpc/dts/qoriq-esdhc-0.dtsi|  13 +
 arch/powerpc/dts/qoriq-espi-0.dtsi |  14 +
 arch/powerpc/dts/qoriq-mpic.dtsi   |  79 +++
 arch/powerpc/dts/qoriq-qman3.dtsi  |  14 +
 arch/powerpc/dts/qoriq-sata2-0.dtsi|  12 +
 arch/powerpc/dts/qoriq-sata2-1.dtsi|  12 +
 arch/powerpc/dts/qoriq-sec5.0-0.dtsi   |  83 +++
 arch/powerpc/dts/qoriq-usb2-dr-0.dtsi  |  14 +
 arch/powerpc/dts/qoriq-usb2-mph-0.dtsi |  14 +
 arch/powerpc/dts/t1040si-post.dtsi | 727 +
 arch/powerpc/dts/t104xsi-pre.dtsi  |  88 +++
 board/keymile/Kconfig  |   1 +
 board/keymile/common/common.c  |  22 +-
 board/keymile/common/ivm.c |   5 +
 board/keymile/kmcent2/Kconfig  |  17 +
 board/keymile/kmcent2/MAINTAINERS  |   8 +
 board/keymile/kmcent2/Makefile |  15 +
 board/keymile/kmcent2/ddr.c|  88 +++
 board/keymile/kmcent2/kmcent2.c| 353 
 board/keymile/kmcent2/law.c|  24 +
 board/keymile/kmcent2/tlb.c| 104 
 configs/kmcent2_defconfig  |  92 
 include/configs/kmcent2.h  | 513 +
 32 files changed, 2908 insertions(+), 16 deletions(-)
 create mode 100644 arch/powerpc/dts/elo3-dma-0.dtsi
 create mode 100644 arch/powerpc/dts/elo3-dma-1.dtsi
 create mode 100644 arch/powerpc/dts/kmcent2-u-boot.dtsi
 create mode 100644 arch/powerpc/dts/kmcent2.dts
 create mode 100644 arch/powerpc/dts/qoriq-bman1.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-duart-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-duart-1.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-esdhc-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-espi-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-mpic.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-qman3.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-sata2-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-sata2-1.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-sec5.0-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-usb2-dr-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-usb2-mph-0.dtsi
 create mode 100644 arch/powerpc/dts/t1040si-post.dtsi
 create mode 100644 arch/powerpc/dts/t104xsi-pre.dtsi
 create mode 100644 board/keymile/kmcent2/Kconfig
 create mode 100644 board/keymile/kmcent2/MAINTAINERS
 create mode 100644 board/keymile/kmcent2/Makefile
 create mode 100644 board/keymile/kmcent2/ddr.c
 create mode 100644 board/keymile/kmcent2/kmcent2.c
 create mode 100644 board/keymile/kmcent2/law.c
 create mode 100644 board/keymile/kmcent2/tlb.c
 create mode 100644 configs/kmcent2_defconfig
 create mode 100644 include/configs/kmcent2.h

-- 
2.29.2



Re: [PATCH 3/3] PowerPC: keymile: Add support for kmcent2 board

2021-01-21 Thread Niel Fourie
.nor,nand0=ffa00.flash"
+
+#define MTDPARTS_DEFAULT    "mtdparts="    \
+    "fe800.nor:"    \
+    "128k(RCW),"    \
+    "128k(fman),"    \
+    "128k(QE),"    \
+    "128k(zarlink),"    \
+    "512k(res),"    \
+    "62m(" CONFIG_KM_UBI_PARTITION_NAME_BOOT "),"    \
+    "128k(envred),"    \
+    "128k(env),"    \
+    "768k(u-boot);"    \
+    "ffa00.flash:"    \
+    "-(" CONFIG_KM_UBI_PARTITION_NAME_APP ");"


These MTD defines have been moved to Kconfig. Please don't add them to
the board config header. And please also check for other macros in the
config header, if they are defined in Kconfig and should be configured
via "make menuconfig" instead.



Okay, I will add it there. The only reason it was kept here was its 
length and the two defines embedded inside it; MTDIDS_DEFAULT was kept 
because the defines go together.





+/*
+ * Serial Port - controlled on board with jumper J8
+ * open - index 2
+ * shorted - index 1
+ * Retain non-DM serial port for debug purposes.
+ */
+#if !defined(CONFIG_DM_SERIAL)
+#define CONFIG_CONS_INDEX1
+#define CONFIG_SYS_NS16550_SERIAL
+#define CONFIG_SYS_NS16550_REG_SIZE1
+#define CONFIG_SYS_NS16550_CLK(get_bus_freq(0) / 2)
+#define CONFIG_SYS_NS16550_COM1(CONFIG_SYS_CCSRBAR + 0x11C500)
+#endif


Is CONFIG_DM_SERIAL set? Always? If yes, remove the #ifdef please.


I have to admit that I found being able to disable CONFIG_DM_SERIAL 
incredibly useful while debugging the DT and DM (especially with 
CONFIG_DM_DEBUG enabled), as DM_SERIAL only starts up during that 
process. I would appreciate if we could keep this one...





As mentioned above, please double-check if some of the macros are
available in Kconfig and move them over to the config/foo.h file
instead if available in Kconfig.


With the exceptions of MTDPARTS_DEFAULT and MTDIDS_DEFAULT, I originally 
did go through each of these defines, and moved everything that could 
into the defconfig already. Everything else would require editing the 
Kconfigs themselves. Some macros above do exist in the Kconfig, but are 
tied to different platforms, etc. This is unfortunately one of the snags 
of this platform.


Thank you for the review!

Best regards,
Niel Fourie

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de


Re: [PATCH 2/3] keymile: common: Fix pram variable radix

2021-01-21 Thread Niel Fourie

Hi Stefan

On 19/01/2021 16:13, Stefan Roese wrote:

Hi Niel,

On 08.01.21 11:53, Niel Fourie wrote:

In set_km_env() the pram variable was set to an hexadecimal value,
while initr_mem() expects an unsigned decimal. Set the pram variable
to an unsigned decimal instead.

Signed-off-by: Niel Fourie 
Cc: Holger Brunck 
Cc: Heiko Schocher 
Cc: Priyanka Jain 
---
  board/keymile/common/common.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/board/keymile/common/common.c 
b/board/keymile/common/common.c

index 03c7ce9da7..106787efd5 100644
--- a/board/keymile/common/common.c
+++ b/board/keymile/common/common.c
@@ -60,7 +60,7 @@ int set_km_env(void)
  strict_strtoul(p, 16, );
  pram = (rootfssize + CONFIG_KM_RESERVED_PRAM + CONFIG_KM_PHRAM +
  CONFIG_KM_PNVRAM) / 0x400;
-    sprintf((char *)buf, "0x%x", pram);
+    sprintf((char *)buf, "%u", pram);
  env_set("pram", (char *)buf);


Why don't you switch to using a different env_set_foo() API instead?
Like env_set_ulong() in this case? Or env_set_hex() in the HEX case.
This could also be done for some other env_set cases in this file as
well to reduce code size and complexity.


Thank you for the suggestion, I realised I was simply trying to change 
as little as possible.


I replaced all instances of sprintf()/env_set() for numerical values in 
this file to env_set_hex()/env_set_ulong() instead.


I also considered use env_get_hex() where applicable, but it uses 
simple_strtoul() instead of strict_strtoul(), therefore changing the 
behaviour, so I left it as-is instead.


Best regards,
Niel Fourie

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de


Re: [PATCH 1/3] PowerPC: dts: Pulled in kmcent2 dts files from Linux 5.10

2021-01-21 Thread Niel Fourie

Hi Stefan,

On 19/01/2021 16:06, Stefan Roese wrote:

Hi Niel,

On 08.01.21 11:53, Niel Fourie wrote:

Pulled in the kmcent2.dts and all its dependents from Linux 5.10,
commit 2c85ebc57b3e upstream. Replaced the license text with
SPDX License Identifiers.


I assume that you did not change the license itself (e.g. change MIT to
GPL etc) but only moved from non SPDX to SPDX indentifiers?


Yes, the licenses themselves were not changed, just replaced with SPDX 
identifiers.


I would suggest to also submit these changes to the Linux kernel (if
not done already). So that the files are identical in the next release
revision.

Is no license is changed:

Reviewed-by: Stefan Roese 


Thanks!



Best regards,
Niel Fourie

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de


[PATCH 3/3] PowerPC: keymile: Add support for kmcent2 board

2021-01-08 Thread Niel Fourie
Add basic support for the Hitachi Power Grids kmcent2 board, based
on the NXP QorIQ T1040 SoC.

Signed-off-by: Valentin Longchamp 
Signed-off-by: Rainer Boschung 
Signed-off-by: Niel Fourie 
Cc: Holger Brunck 
Cc: Heiko Schocher 
Cc: Priyanka Jain 
---
 arch/powerpc/cpu/mpc85xx/Kconfig |   4 +
 arch/powerpc/dts/Makefile|   1 +
 arch/powerpc/dts/kmcent2-u-boot.dtsi |  97 +
 board/keymile/Kconfig|   1 +
 board/keymile/common/ivm.c   |   5 +
 board/keymile/kmcent2/Kconfig|  17 +
 board/keymile/kmcent2/MAINTAINERS|   8 +
 board/keymile/kmcent2/Makefile   |  15 +
 board/keymile/kmcent2/ddr.c  |  88 +
 board/keymile/kmcent2/kmcent2.c  | 349 +
 board/keymile/kmcent2/law.c  |  40 ++
 board/keymile/kmcent2/tlb.c  | 120 ++
 configs/kmcent2_defconfig|  90 +
 include/configs/kmcent2.h| 537 +++
 14 files changed, 1372 insertions(+)
 create mode 100644 arch/powerpc/dts/kmcent2-u-boot.dtsi
 create mode 100644 board/keymile/kmcent2/Kconfig
 create mode 100644 board/keymile/kmcent2/MAINTAINERS
 create mode 100644 board/keymile/kmcent2/Makefile
 create mode 100644 board/keymile/kmcent2/ddr.c
 create mode 100644 board/keymile/kmcent2/kmcent2.c
 create mode 100644 board/keymile/kmcent2/law.c
 create mode 100644 board/keymile/kmcent2/tlb.c
 create mode 100644 configs/kmcent2_defconfig
 create mode 100644 include/configs/kmcent2.h

diff --git a/arch/powerpc/cpu/mpc85xx/Kconfig b/arch/powerpc/cpu/mpc85xx/Kconfig
index 54c7fd9522..c1a3770671 100644
--- a/arch/powerpc/cpu/mpc85xx/Kconfig
+++ b/arch/powerpc/cpu/mpc85xx/Kconfig
@@ -256,6 +256,10 @@ config TARGET_KMP204X
bool "Support kmp204x"
select VENDOR_KM
 
+config TARGET_KMCENT2
+   bool "Support kmcent2"
+   select VENDOR_KM
+
 config TARGET_XPEDITE520X
bool "Support xpedite520x"
select ARCH_MPC8548
diff --git a/arch/powerpc/dts/Makefile b/arch/powerpc/dts/Makefile
index 266d345f72..3ecda36538 100644
--- a/arch/powerpc/dts/Makefile
+++ b/arch/powerpc/dts/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0+
 
+dtb-$(CONFIG_TARGET_KMCENT2) += kmcent2.dtb
 dtb-$(CONFIG_TARGET_KMCOGE5NE) += kmcoge5ne.dtb
 dtb-$(CONFIG_TARGET_KMETER1) += kmeter1.dtb
 dtb-$(CONFIG_TARGET_KMOPTI2) += kmopti2.dtb
diff --git a/arch/powerpc/dts/kmcent2-u-boot.dtsi 
b/arch/powerpc/dts/kmcent2-u-boot.dtsi
new file mode 100644
index 00..ab76a9f122
--- /dev/null
+++ b/arch/powerpc/dts/kmcent2-u-boot.dtsi
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * (C) Copyright 2021  Niel Fourie 
+ */
+
+#include 
+
+/ {
+
+   aliases {
+   spi0 = "/soc@ffe00/spi@11";
+   i2c0 = "/soc@ffe00/i2c@118000";
+   i2c1 = "/soc@ffe00/i2c@118000/mux@70/i2c@0";
+   i2c2 = "/soc@ffe00/i2c@118000/mux@70/i2c@1";
+   i2c3 = "/soc@ffe00/i2c@118000/mux@70/i2c@7";
+   i2c4 = "/soc@ffe00/i2c@118100";
+   /delete-property/ pci1;
+   /delete-property/ pci2;
+   /delete-property/ pci3;
+   };
+
+   chosen {
+   stdout-path = "/soc@ffe00/serial@11c500";
+   };
+
+   soc@ffe00 {
+   u-boot,dm-pre-reloc;
+   spi@11 {
+   /* This documents where km_fpgacfg should be appear */
+   fpga@0 {
+   compatible = "keymile,fpga-conf";
+   reg = <0>;
+   spi-max-frequency = <2500>;
+   };
+   };
+
+   sdhc@114000 {
+   status = "okay";
+   };
+
+   i2c@118000 {
+   u-boot,dm-pre-reloc;
+   mux@70 {
+   i2c@1 { /* IVM bus */
+   reg = <1>;
+   #address-cells = <1>;
+   #size-cells = <0>;
+   };
+   };
+   };
+
+   serial@11c500 {
+   u-boot,dm-pre-reloc;
+   clock-frequency = <2>;
+   };
+
+   fman@40 {
+   ethernet@e {
+   phy-connection-type = "sgmii";
+   };
+
+   ethernet@e2000 {
+   phy-connection-type = "sgmii";
+   };
+
+   ethernet@e8000 {
+   phy-connection-type = "rgmii-id";
+

[PATCH 1/3] PowerPC: dts: Pulled in kmcent2 dts files from Linux 5.10

2021-01-08 Thread Niel Fourie
Pulled in the kmcent2.dts and all its dependents from Linux 5.10,
commit 2c85ebc57b3e upstream. Replaced the license text with
SPDX License Identifiers.

Signed-off-by: Niel Fourie 
Cc: Holger Brunck 
Cc: Heiko Schocher 
Cc: Priyanka Jain 
---
 arch/powerpc/dts/elo3-dma-0.dtsi   |  55 ++
 arch/powerpc/dts/elo3-dma-1.dtsi   |  55 ++
 arch/powerpc/dts/kmcent2.dts   | 338 
 arch/powerpc/dts/qoriq-bman1.dtsi  |  14 +
 arch/powerpc/dts/qoriq-duart-0.dtsi|  24 +
 arch/powerpc/dts/qoriq-duart-1.dtsi|  24 +
 arch/powerpc/dts/qoriq-esdhc-0.dtsi|  13 +
 arch/powerpc/dts/qoriq-espi-0.dtsi |  14 +
 arch/powerpc/dts/qoriq-mpic.dtsi   |  79 +++
 arch/powerpc/dts/qoriq-qman3.dtsi  |  14 +
 arch/powerpc/dts/qoriq-sata2-0.dtsi|  12 +
 arch/powerpc/dts/qoriq-sata2-1.dtsi|  12 +
 arch/powerpc/dts/qoriq-sec5.0-0.dtsi   |  83 +++
 arch/powerpc/dts/qoriq-usb2-dr-0.dtsi  |  14 +
 arch/powerpc/dts/qoriq-usb2-mph-0.dtsi |  14 +
 arch/powerpc/dts/t1040si-post.dtsi | 727 +
 arch/powerpc/dts/t104xsi-pre.dtsi  |  88 +++
 17 files changed, 1580 insertions(+)
 create mode 100644 arch/powerpc/dts/elo3-dma-0.dtsi
 create mode 100644 arch/powerpc/dts/elo3-dma-1.dtsi
 create mode 100644 arch/powerpc/dts/kmcent2.dts
 create mode 100644 arch/powerpc/dts/qoriq-bman1.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-duart-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-duart-1.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-esdhc-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-espi-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-mpic.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-qman3.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-sata2-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-sata2-1.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-sec5.0-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-usb2-dr-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-usb2-mph-0.dtsi
 create mode 100644 arch/powerpc/dts/t1040si-post.dtsi
 create mode 100644 arch/powerpc/dts/t104xsi-pre.dtsi

diff --git a/arch/powerpc/dts/elo3-dma-0.dtsi b/arch/powerpc/dts/elo3-dma-0.dtsi
new file mode 100644
index 00..c3f7737256
--- /dev/null
+++ b/arch/powerpc/dts/elo3-dma-0.dtsi
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * QorIQ Elo3 DMA device tree stub [ controller @ offset 0x10 ]
+ *
+ * Copyright 2013 Freescale Semiconductor Inc.
+ */
+
+dma0: dma@100300 {
+   #address-cells = <1>;
+   #size-cells = <1>;
+   compatible = "fsl,elo3-dma";
+   reg = <0x100300 0x4>,
+ <0x100600 0x4>;
+   ranges = <0x0 0x100100 0x500>;
+   dma-channel@0 {
+   compatible = "fsl,eloplus-dma-channel";
+   reg = <0x0 0x80>;
+   interrupts = <28 2 0 0>;
+   };
+   dma-channel@80 {
+   compatible = "fsl,eloplus-dma-channel";
+   reg = <0x80 0x80>;
+   interrupts = <29 2 0 0>;
+   };
+   dma-channel@100 {
+   compatible = "fsl,eloplus-dma-channel";
+   reg = <0x100 0x80>;
+   interrupts = <30 2 0 0>;
+   };
+   dma-channel@180 {
+   compatible = "fsl,eloplus-dma-channel";
+   reg = <0x180 0x80>;
+   interrupts = <31 2 0 0>;
+   };
+   dma-channel@300 {
+   compatible = "fsl,eloplus-dma-channel";
+   reg = <0x300 0x80>;
+   interrupts = <76 2 0 0>;
+   };
+   dma-channel@380 {
+   compatible = "fsl,eloplus-dma-channel";
+   reg = <0x380 0x80>;
+   interrupts = <77 2 0 0>;
+   };
+   dma-channel@400 {
+   compatible = "fsl,eloplus-dma-channel";
+   reg = <0x400 0x80>;
+   interrupts = <78 2 0 0>;
+   };
+   dma-channel@480 {
+   compatible = "fsl,eloplus-dma-channel";
+   reg = <0x480 0x80>;
+   interrupts = <79 2 0 0>;
+   };
+};
diff --git a/arch/powerpc/dts/elo3-dma-1.dtsi b/arch/powerpc/dts/elo3-dma-1.dtsi
new file mode 100644
index 00..a61c88649c
--- /dev/null
+++ b/arch/powerpc/dts/elo3-dma-1.dtsi
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * QorIQ Elo3 DMA device tree stub [ controller @ offset 0x101000 ]
+ *
+ * Copyright 2013 Freescale Semiconductor Inc.
+ */
+
+dma1: dma@101300 {
+   #address-cells = <1>;
+   #size-cells = <1>;
+   compatible = "fsl,elo3-dma";
+   reg = <0x101300 0x4>,
+ <0x101600 0x4>;
+   ranges = <0x0 0x101100 0x500>;
+   dma-channel@0 {
+   compatible = "fsl,eloplus-dma-channel";
+  

[PATCH 2/3] keymile: common: Fix pram variable radix

2021-01-08 Thread Niel Fourie
In set_km_env() the pram variable was set to an hexadecimal value,
while initr_mem() expects an unsigned decimal. Set the pram variable
to an unsigned decimal instead.

Signed-off-by: Niel Fourie 
Cc: Holger Brunck 
Cc: Heiko Schocher 
Cc: Priyanka Jain 
---
 board/keymile/common/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/board/keymile/common/common.c b/board/keymile/common/common.c
index 03c7ce9da7..106787efd5 100644
--- a/board/keymile/common/common.c
+++ b/board/keymile/common/common.c
@@ -60,7 +60,7 @@ int set_km_env(void)
strict_strtoul(p, 16, );
pram = (rootfssize + CONFIG_KM_RESERVED_PRAM + CONFIG_KM_PHRAM +
CONFIG_KM_PNVRAM) / 0x400;
-   sprintf((char *)buf, "0x%x", pram);
+   sprintf((char *)buf, "%u", pram);
env_set("pram", (char *)buf);
 
varaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM;
-- 
2.29.2



[PATCH 0/3] PowerPC: keymile: Add support for kmcent2 board

2021-01-08 Thread Niel Fourie
This patch series adds basic support for the Hitachi Power Grids
(previously Keymile and ABB) kmcent2 board, based on the NXP QorIQ
T1040 SoC.

Patch 1/3 pulls in the device trees from Linux 5.10
Patch 2/3 fixes a minor bug common to all the Keymile boards.
Patch 3/3 finally adds the U-boot support for the kmcent2

Niel Fourie (3):
  PowerPC: dts: Pulled in kmcent2 dts files from Linux 5.10
  keymile: common: Fix pram variable radix
  PowerPC: keymile: Add support for kmcent2 board

 arch/powerpc/cpu/mpc85xx/Kconfig   |   4 +
 arch/powerpc/dts/Makefile  |   1 +
 arch/powerpc/dts/elo3-dma-0.dtsi   |  55 ++
 arch/powerpc/dts/elo3-dma-1.dtsi   |  55 ++
 arch/powerpc/dts/kmcent2-u-boot.dtsi   |  97 
 arch/powerpc/dts/kmcent2.dts   | 338 
 arch/powerpc/dts/qoriq-bman1.dtsi  |  14 +
 arch/powerpc/dts/qoriq-duart-0.dtsi|  24 +
 arch/powerpc/dts/qoriq-duart-1.dtsi|  24 +
 arch/powerpc/dts/qoriq-esdhc-0.dtsi|  13 +
 arch/powerpc/dts/qoriq-espi-0.dtsi |  14 +
 arch/powerpc/dts/qoriq-mpic.dtsi   |  79 +++
 arch/powerpc/dts/qoriq-qman3.dtsi  |  14 +
 arch/powerpc/dts/qoriq-sata2-0.dtsi|  12 +
 arch/powerpc/dts/qoriq-sata2-1.dtsi|  12 +
 arch/powerpc/dts/qoriq-sec5.0-0.dtsi   |  83 +++
 arch/powerpc/dts/qoriq-usb2-dr-0.dtsi  |  14 +
 arch/powerpc/dts/qoriq-usb2-mph-0.dtsi |  14 +
 arch/powerpc/dts/t1040si-post.dtsi | 727 +
 arch/powerpc/dts/t104xsi-pre.dtsi  |  88 +++
 board/keymile/Kconfig  |   1 +
 board/keymile/common/common.c  |   2 +-
 board/keymile/common/ivm.c |   5 +
 board/keymile/kmcent2/Kconfig  |  17 +
 board/keymile/kmcent2/MAINTAINERS  |   8 +
 board/keymile/kmcent2/Makefile |  15 +
 board/keymile/kmcent2/ddr.c|  88 +++
 board/keymile/kmcent2/kmcent2.c| 349 
 board/keymile/kmcent2/law.c|  40 ++
 board/keymile/kmcent2/tlb.c| 120 
 configs/kmcent2_defconfig  |  90 +++
 include/configs/kmcent2.h  | 537 ++
 32 files changed, 2953 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/dts/elo3-dma-0.dtsi
 create mode 100644 arch/powerpc/dts/elo3-dma-1.dtsi
 create mode 100644 arch/powerpc/dts/kmcent2-u-boot.dtsi
 create mode 100644 arch/powerpc/dts/kmcent2.dts
 create mode 100644 arch/powerpc/dts/qoriq-bman1.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-duart-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-duart-1.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-esdhc-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-espi-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-mpic.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-qman3.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-sata2-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-sata2-1.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-sec5.0-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-usb2-dr-0.dtsi
 create mode 100644 arch/powerpc/dts/qoriq-usb2-mph-0.dtsi
 create mode 100644 arch/powerpc/dts/t1040si-post.dtsi
 create mode 100644 arch/powerpc/dts/t104xsi-pre.dtsi
 create mode 100644 board/keymile/kmcent2/Kconfig
 create mode 100644 board/keymile/kmcent2/MAINTAINERS
 create mode 100644 board/keymile/kmcent2/Makefile
 create mode 100644 board/keymile/kmcent2/ddr.c
 create mode 100644 board/keymile/kmcent2/kmcent2.c
 create mode 100644 board/keymile/kmcent2/law.c
 create mode 100644 board/keymile/kmcent2/tlb.c
 create mode 100644 configs/kmcent2_defconfig
 create mode 100644 include/configs/kmcent2.h

-- 
2.29.2



[PATCH] dm: spi: Fix spi_free_slave() freed memory write

2020-12-16 Thread Niel Fourie
Remove setting slave->dev to NULL after the device_remove() call.

The slave pointer points to dev->parent_priv, which has already
been freed by device_free(), called from device_remove() in the
preceding line. Writing to slave->dev may cause corruption of the
dlmalloc free chunk forward pointer of the previously freed chunk.

Signed-off-by: Niel Fourie 
Cc: Simon Glass 
---
 drivers/spi/spi-uclass.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
index 55a8eed8901..a16ac9280fd 100644
--- a/drivers/spi/spi-uclass.c
+++ b/drivers/spi/spi-uclass.c
@@ -428,7 +428,6 @@ struct spi_slave *spi_setup_slave(unsigned int busnum, 
unsigned int cs,
 void spi_free_slave(struct spi_slave *slave)
 {
device_remove(slave->dev, DM_REMOVE_NORMAL);
-   slave->dev = NULL;
 }
 
 int spi_slave_ofdata_to_platdata(struct udevice *dev,
-- 
2.28.0



[PATCH] arm: imx6q: pcm058: Rework SPI NOR configuration

2020-07-24 Thread Niel Fourie
Enable CONFIG_SPL_DM_SPI_FLASH to be able to boot from SPI NOR,
modify the offset of U-boot proper in the SPI NOR, so the
difference in offset matches between SPL and U-boot matches that of
the SD Card, allowing u-boot-with-spl.imx to also be copied to SPI
NOR at an offset of 0x400. Update the README to reflect this
change.

Signed-off-by: Niel Fourie 
Cc: Stefano Babic 
---
 board/phytec/pcm058/README | 20 
 configs/pcm058_defconfig   |  3 ++-
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/board/phytec/pcm058/README b/board/phytec/pcm058/README
index 02be0994fc..687366bffb 100644
--- a/board/phytec/pcm058/README
+++ b/board/phytec/pcm058/README
@@ -61,17 +61,21 @@ Then, clear the SPI flash:
 => sf probe
 => sf erase 0x0 0x100
 
-Load the SPL from raw MMC into memory and copy to the SPI. The SPL is maximum
-392*512-byte blocks in size therefore 0x188 blocks, totaling 0x31000 bytes:
+Load the equivalent of u-boot-with-spl.imx from the raw MMC into memory and
+copy to the SPI. The SPL is expected at an offset of 0x400, and its size is
+maximum 392*512-byte blocks in size, therefore 0x188 blocks, totaling 0x31000
+bytes. Assume U-boot should fit into 640KiB, therefore 0x500 512-byte blocks,
+totalling 0xA bytes. Adding these together:
 
-=> mmc read ${loadaddr} 0x2 0x188
-=> sf write ${loadaddr} 0x400 0x31000
+=> mmc read ${loadaddr} 0x2 0x688
+=> sf write ${loadaddr} 0x400 0xD1000
 
-Load the U-boot binary into memory and copy to the SPI. U-boot should fit into
-640KiB, so 0x500 512-byte blocks, totalling 0xA bytes:
+The SPL is located at offset 0x400, and U-boot at 0x31400 in SPI flash, as to
+match the SD Card layout. This would allow, instead of reading from the SD Card
+above, with networking and TFTP correctly configured, the equivalent of:
 
-=> mmc read ${loadaddr} 0x18a 0x500
-=> sf write ${loadaddr} 0x4 0xA
+=> tftp u-boot-with-spl.imx
+=> sf write ${fileaddr} 0x400 ${filesize}
 
 The default NAND bootscripts expect a single MTD partition named "rootfs",
 which in turn contains the UBI volumes "fit" (which contains the kernel fit-
diff --git a/configs/pcm058_defconfig b/configs/pcm058_defconfig
index c491cbf9a0..b085a7dd0c 100644
--- a/configs/pcm058_defconfig
+++ b/configs/pcm058_defconfig
@@ -7,7 +7,7 @@ CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_ENV_SIZE=0x4000
 CONFIG_ENV_OFFSET=0x10
 CONFIG_ENV_SECT_SIZE=0x1
-CONFIG_SYS_SPI_U_BOOT_OFFS=0x4
+CONFIG_SYS_SPI_U_BOOT_OFFS=0x31400
 CONFIG_MX6_OCRAM_256KB=y
 CONFIG_TARGET_PCM058=y
 CONFIG_SPL_TEXT_BASE=0x00908000
@@ -34,6 +34,7 @@ CONFIG_SPL_SEPARATE_BSS=y
 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR=0x18a
 CONFIG_SPL_DMA=y
 CONFIG_SPL_FS_EXT4=y
+CONFIG_SPL_DM_SPI_FLASH=y
 CONFIG_SPL_SPI_LOAD=y
 CONFIG_SPL_WATCHDOG_SUPPORT=y
 CONFIG_SPL_YMODEM_SUPPORT=y
-- 
2.26.2



[PATCH 4/4] arm: imx6q: pcm058: Convert pcm058 to use DM with DTs

2020-05-19 Thread Niel Fourie
Convert pcm058 support to use device trees and the driver model.
Add rudimentary boot scripts to the environment, expand README.

Signed-off-by: Niel Fourie 
Cc: Stefano Babic 
---
 arch/arm/dts/Makefile |   1 +
 .../imx6q-phytec-mira-rdk-nand-u-boot.dtsi|  42 +++
 arch/arm/mach-imx/mx6/Kconfig |   4 +
 board/phytec/pcm058/README|  51 +++
 board/phytec/pcm058/pcm058.c  | 324 ++
 configs/pcm058_defconfig  |  42 ++-
 include/configs/pcm058.h  |  69 ++--
 7 files changed, 178 insertions(+), 355 deletions(-)
 create mode 100644 arch/arm/dts/imx6q-phytec-mira-rdk-nand-u-boot.dtsi

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index ca663a86f2..4df74c5207 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -663,6 +663,7 @@ dtb-y += \
imx6q-nitrogen6x.dtb \
imx6q-novena.dtb \
imx6q-pico.dtb \
+   imx6q-phytec-mira-rdk-nand.dtb \
imx6q-sabreauto.dtb \
imx6q-sabrelite.dtb \
imx6q-sabresd.dtb \
diff --git a/arch/arm/dts/imx6q-phytec-mira-rdk-nand-u-boot.dtsi 
b/arch/arm/dts/imx6q-phytec-mira-rdk-nand-u-boot.dtsi
new file mode 100644
index 00..8555be1696
--- /dev/null
+++ b/arch/arm/dts/imx6q-phytec-mira-rdk-nand-u-boot.dtsi
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020
+ * Niel Fourie, DENX Software Engineering, lu...@denx.de.
+ */
+#include "imx6qdl-u-boot.dtsi"
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+_uart2 {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+_usdhc1 {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
+
+_ecspi1 {
+   u-boot,dm-spl;
+};
+
+ {
+   u-boot,dm-spl;
+};
diff --git a/arch/arm/mach-imx/mx6/Kconfig b/arch/arm/mach-imx/mx6/Kconfig
index fa6e1112e6..fdee0d4f64 100644
--- a/arch/arm/mach-imx/mx6/Kconfig
+++ b/arch/arm/mach-imx/mx6/Kconfig
@@ -511,6 +511,10 @@ config TARGET_PCM058
bool "Phytec PCM058 i.MX6 Quad"
select BOARD_LATE_INIT
select SUPPORT_SPL
+   select MX6Q
+   select DM
+   select OF_CONTROL
+   imply CMD_DM
 
 config TARGET_PFLA02
bool "Phytec PFLA02 (PhyFlex) i.MX6 Quad"
diff --git a/board/phytec/pcm058/README b/board/phytec/pcm058/README
index 3327135645..02be0994fc 100644
--- a/board/phytec/pcm058/README
+++ b/board/phytec/pcm058/README
@@ -33,3 +33,54 @@ is present, then the RBL tries to load SPL from the SD Card, 
if not,
 RBL loads from SPI-NOR. The SPL tries then to load from the same
 device where SPL was loaded (SD or SPI). Booting from NAND is
 not supported.
+
+Flashing U-Boot onto an SD card
+---
+
+After a successful build, the generated SPL and U-boot binaries can be copied
+to an SD card. Adjust the SD card device as necessary:
+
+$ sudo dd if=u-boot-with-spl.imx of=/dev/mmcblk0 bs=1k seek=1
+
+This is equivalent to separately copying the SPL and U-boot using:
+
+$ sudo dd if=SPL of=/dev/mmcblk0 bs=1k seek=1
+$ sudo dd if=u-boot-dtb.img of=/dev/mmcblk0 bs=1k seek=197
+
+The default bootscripts expect a kernel fit-image file named "fitImage" in the
+first partition and Linux ext4 rootfs in the second partition.
+
+Flashing U-boot to the SPI Flash, for booting Linux from NAND
+-
+
+The SD card created above can also be used to install the SPL and U-boot into
+the SPI flash. Boot U-boot from the SD card as above, and stop at the autoboot.
+
+Then, clear the SPI flash:
+
+=> sf probe
+=> sf erase 0x0 0x100
+
+Load the SPL from raw MMC into memory and copy to the SPI. The SPL is maximum
+392*512-byte blocks in size therefore 0x188 blocks, totaling 0x31000 bytes:
+
+=> mmc read ${loadaddr} 0x2 0x188
+=> sf write ${loadaddr} 0x400 0x31000
+
+Load the U-boot binary into memory and copy to the SPI. U-boot should fit into
+640KiB, so 0x500 512-byte blocks, totalling 0xA bytes:
+
+=> mmc read ${loadaddr} 0x18a 0x500
+=> sf write ${loadaddr} 0x4 0xA
+
+The default NAND bootscripts expect a single MTD partition named "rootfs",
+which in turn contains the UBI volumes "fit" (which contains the kernel fit-
+image) and "root" (which contains a ubifs root filesystem).
+
+The "bootm_size" variable in the environment
+
+
+By default, U-boot relocates the device tree towards the upper end of the RAM,
+which kernels using CONFIG_HIGHMEM=y may not be able to access during early
+boot. With the bootm_size variable set to 0x3000, U-boot relocates the
+device tree to below this address instead.
diff --git a/board/phytec/pcm058/pcm058.c b/board/phytec/pcm058/pcm058.c
index 820b5fde14..d5c5177393 100644
--- a/board/phytec/pcm058/pcm058.c
+++ b/board/phy

[PATCH 3/4] arm: imx6q: pcm058: change MAINTAINER

2020-05-19 Thread Niel Fourie
Change the MAINTAINER of pcm058.

Signed-off-by: Niel Fourie 
Cc: Stefano Babic 
---
 board/phytec/pcm058/MAINTAINERS | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/board/phytec/pcm058/MAINTAINERS b/board/phytec/pcm058/MAINTAINERS
index b0ca40277f..909dfc44af 100644
--- a/board/phytec/pcm058/MAINTAINERS
+++ b/board/phytec/pcm058/MAINTAINERS
@@ -1,6 +1,7 @@
 PHYTEC PHYBOARD MIRA
-M: Stefano Babic 
+M: Niel Fourie 
 S: Maintained
 F: board/phytec/pcm058/
 F: include/configs/pcm058.h
 F: configs/pcm058_defconfig
+F: arch/arm/dts/imx6q-phytec-mira-rdk-nand-u-boot.dtsi
-- 
2.26.2



[PATCH 2/4] arm: dts: imx6q: Add Linux dts files for Phytec Mira

2020-05-19 Thread Niel Fourie
Add Phytec Mira device tree files, for use with pcm058.
>From Linux 5.6, commit 7111951b8d49 upstream

Signed-off-by: Niel Fourie 
Cc: Stefano Babic 
---
 arch/arm/dts/imx6q-phytec-mira-rdk-nand.dts  |  72 
 arch/arm/dts/imx6qdl-phytec-mira.dtsi| 390 +++
 arch/arm/dts/imx6qdl-phytec-phycore-som.dtsi | 287 ++
 3 files changed, 749 insertions(+)
 create mode 100644 arch/arm/dts/imx6q-phytec-mira-rdk-nand.dts
 create mode 100644 arch/arm/dts/imx6qdl-phytec-mira.dtsi
 create mode 100644 arch/arm/dts/imx6qdl-phytec-phycore-som.dtsi

diff --git a/arch/arm/dts/imx6q-phytec-mira-rdk-nand.dts 
b/arch/arm/dts/imx6q-phytec-mira-rdk-nand.dts
new file mode 100644
index 00..65d2e483c1
--- /dev/null
+++ b/arch/arm/dts/imx6q-phytec-mira-rdk-nand.dts
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (C) 2018 PHYTEC Messtechnik GmbH
+ * Author: Christian Hemp 
+ */
+
+/dts-v1/;
+#include "imx6q.dtsi"
+#include "imx6qdl-phytec-phycore-som.dtsi"
+#include "imx6qdl-phytec-mira.dtsi"
+
+/ {
+   model = "PHYTEC phyBOARD-Mira Quad Carrier-Board with NAND";
+   compatible = "phytec,imx6q-pbac06-nand", "phytec,imx6q-pbac06",
+"phytec,imx6qdl-pcm058", "fsl,imx6q";
+
+   chosen {
+   stdout-path = 
+   };
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+_rtc {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
diff --git a/arch/arm/dts/imx6qdl-phytec-mira.dtsi 
b/arch/arm/dts/imx6qdl-phytec-mira.dtsi
new file mode 100644
index 00..9ebd438dce
--- /dev/null
+++ b/arch/arm/dts/imx6qdl-phytec-mira.dtsi
@@ -0,0 +1,390 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (C) 2018 PHYTEC Messtechnik GmbH
+ * Author: Christian Hemp 
+ */
+
+
+/ {
+   aliases {
+   rtc0 = _rtc;
+   };
+
+   backlight: backlight {
+   compatible = "pwm-backlight";
+   brightness-levels = <0 4 8 16 32 64 128 255>;
+   default-brightness-level = <7>;
+   power-supply = <_backlight>;
+   pwms = < 0 500>;
+   status = "okay";
+   };
+
+   gpio_leds: leds {
+   compatible = "gpio-leds";
+   pinctrl-names = "default";
+   pinctrl-0 = <_gpioleds>;
+   status = "disabled";
+
+   red {
+   label = "phyboard-mira:red";
+   gpios = < 22 GPIO_ACTIVE_HIGH>;
+   };
+
+   green {
+   label = "phyboard-mira:green";
+   gpios = < 23 GPIO_ACTIVE_HIGH>;
+   };
+
+   blue {
+   label = "phyboard-mira:blue";
+   gpios = < 24 GPIO_ACTIVE_HIGH>;
+   linux,default-trigger = "mmc0";
+   };
+   };
+
+   reg_backlight: regulator-backlight {
+   compatible = "regulator-fixed";
+   regulator-name = "backlight_3v3";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-always-on;
+   };
+
+   reg_en_switch: regulator-en-switch {
+   compatible = "regulator-fixed";
+   pinctrl-names = "default";
+   pinctrl-0 = <_en_switch>;
+   regulator-name = "Enable Switch";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   enable-active-high;
+   gpio = < 4 GPIO_ACTIVE_HIGH>;
+   regulator-always-on;
+   };
+
+   reg_flexcan1: regulator-flexcan1 {
+   compatible = "regulator-fixed";
+   pinctrl-names = "default";
+   pinctrl-0 = <_flexcan1_en>;
+   regulator-name = "flexcan1-reg";
+   regulator-min-microvolt = <150>;
+   regulator-max-microvolt = <150>;
+   gpio = < 20 GPIO_ACTIVE_HIGH>;
+   enable-active-high;
+   };
+
+   reg_panel: regulator-panel {
+   compatible = &quo

[PATCH 1/4] dts-bindings: regulator: Add dlg,da9063-regulator

2020-05-19 Thread Niel Fourie
Add da9063-regulator bindings from Linux 5.6:
commit 7111951b8d49 upstream

Signed-off-by: Niel Fourie 
Cc: Stefano Babic 
---
 .../dt-bindings/regulator/dlg,da9063-regulator.h | 16 
 1 file changed, 16 insertions(+)
 create mode 100644 include/dt-bindings/regulator/dlg,da9063-regulator.h

diff --git a/include/dt-bindings/regulator/dlg,da9063-regulator.h 
b/include/dt-bindings/regulator/dlg,da9063-regulator.h
new file mode 100644
index 00..1de710dd08
--- /dev/null
+++ b/include/dt-bindings/regulator/dlg,da9063-regulator.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _DT_BINDINGS_REGULATOR_DLG_DA9063_H
+#define _DT_BINDINGS_REGULATOR_DLG_DA9063_H
+
+/*
+ * These buck mode constants may be used to specify values in device tree
+ * properties (e.g. regulator-initial-mode).
+ * A description of the following modes is in the manufacturers datasheet.
+ */
+
+#define DA9063_BUCK_MODE_SLEEP 1
+#define DA9063_BUCK_MODE_SYNC  2
+#define DA9063_BUCK_MODE_AUTO  3
+
+#endif
-- 
2.26.2



[PATCH 0/4] arm: imx6q: pcm058: Convert support to use DM with DTs

2020-05-19 Thread Niel Fourie
This patch series updates the existing pcm058 board support to use device
trees with driver model. The first two patches in the series pulls in the
unmodified Linux dt-binding and dts files. The third patch changes the
maintainer. The last patch contains the required changes.

Niel Fourie (4):
  dts-bindings: regulator: Add dlg,da9063-regulator
  arm: dts: imx6q: Add Linux dts files for Phytec Mira
  arm: imx6q: pcm058: change MAINTAINER
  arm: imx6q: pcm058: Convert pcm058 to use DM with DTs

 arch/arm/dts/Makefile |   1 +
 .../imx6q-phytec-mira-rdk-nand-u-boot.dtsi|  42 ++
 arch/arm/dts/imx6q-phytec-mira-rdk-nand.dts   |  72 
 arch/arm/dts/imx6qdl-phytec-mira.dtsi | 390 ++
 arch/arm/dts/imx6qdl-phytec-phycore-som.dtsi  | 287 +
 arch/arm/mach-imx/mx6/Kconfig |   4 +
 board/phytec/pcm058/MAINTAINERS   |   3 +-
 board/phytec/pcm058/README|  51 +++
 board/phytec/pcm058/pcm058.c  | 324 +--
 configs/pcm058_defconfig  |  42 +-
 include/configs/pcm058.h  |  69 ++--
 .../regulator/dlg,da9063-regulator.h  |  16 +
 12 files changed, 945 insertions(+), 356 deletions(-)
 create mode 100644 arch/arm/dts/imx6q-phytec-mira-rdk-nand-u-boot.dtsi
 create mode 100644 arch/arm/dts/imx6q-phytec-mira-rdk-nand.dts
 create mode 100644 arch/arm/dts/imx6qdl-phytec-mira.dtsi
 create mode 100644 arch/arm/dts/imx6qdl-phytec-phycore-som.dtsi
 create mode 100644 include/dt-bindings/regulator/dlg,da9063-regulator.h

-- 
2.26.2



Re: [RFC PATCH 1/1] Makefile: Expand legacy (non-DM) driver warnings

2020-03-30 Thread Niel Fourie

Hi Simon

On 3/28/20 9:05 PM, Simon Glass wrote:

Hi Niel,

On Wed, 25 Mar 2020 at 07:47, Niel Fourie  wrote:


Expand warnings printed by Makefile after compile when legacy
drivers are in use. These include:

- CONFIG_HAVE_BLOCK_DEVICE without CONFIG_BLK
- CONFIG_BOOTCOUNT_LIMIT without CONFIG_DM_BOOTCOUNT
- CONFIG_MTD without CONFIG_DM_MTD
- CONFIG_PHYLIB without CONFIG_DM_MDIO
- CONFIG_POWER, also without CONFIG_DM_PMIC
- Absence of CONFIG_RAM and CONFIG_SPL_RAM

Also replaced existing CONFIG_DM_SPI warning for consistency.
Removed CONFIG_BLK requirement for CONFIG_DM_USB, as all USB
devices not block devices.

Signed-off-by: Niel Fourie 
Cc: Simon Glass 
---
  Makefile | 73 +++-
  1 file changed, 67 insertions(+), 6 deletions(-)


Could we add instructions on what should be done? It seems a little
unclear to me.


Yes, sure. I am still a little uncertain on how to correctly create a 
sensible RFC patch.


My question is basically: How useful would you consider having more of 
these warnings in the Makefile, if at all? I am the least certain of the 
last one with CONFIG_RAM and CONFIG_SPL_RAM.


For background, I explored the driver model and then I had a look at how 
much legacy there was still around. I found some further defines and 
conditions which could be turned into legacy warnings in the Makefile 
for some more visibility. Any even further such warnings would mostly 
involve checking the defines for the individual legacy drivers, which I 
do not really consider viable.


Testing of these warnings, especially automated, would be a challenge. I 
have a heavily butchered Sandbox build which triggers most of the legacy 
warnings in the Makefile, but I would not want to inflict it on anybody 
else.


Best regard,
Niel Fourie

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de


[PATCH v3 1/1] cmd: blkls: Add blkls command

2020-03-30 Thread Niel Fourie
Add a command to print a list of available block device drivers,
and for each, the list of known block devices.

Signed-off-by: Niel Fourie 
Cc: Simon Glass 
Cc: Stefan Roese 
Reviewed-by: Simon Glass 
Reviewed-by: Stefan Roese 
---
Changes in v2:
- Removed legacy block device variant of blkls and its test.
- Handle return value of uclass_get().
- Removed unnecessary ifdefs, fixed Kconfig depends.

Changes is v3:
- Removed redundant "default n" in Kconfig.
- Corrected included headers, fixed formatting.
- Corrected license of the test.

 cmd/Kconfig |  7 +
 cmd/Makefile|  1 +
 cmd/lsblk.c | 51 +
 test/py/tests/test_lsblk.py | 13 ++
 4 files changed, 72 insertions(+)
 create mode 100644 cmd/lsblk.c
 create mode 100644 test/py/tests/test_lsblk.py

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 6403bc45a5..52c14d5420 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1047,6 +1047,13 @@ config CMD_LOADS
help
  Load an S-Record file over serial line
 
+config CMD_LSBLK
+   depends on BLK
+   bool "lsblk - list block drivers and devices"
+   help
+ Print list of available block device drivers, and for each, the list
+ of known block devices.
+
 config CMD_MMC
bool "mmc"
help
diff --git a/cmd/Makefile b/cmd/Makefile
index f1dd513a4b..6f80974a55 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -83,6 +83,7 @@ obj-$(CONFIG_CMD_LED) += led.o
 obj-$(CONFIG_CMD_LICENSE) += license.o
 obj-y += load.o
 obj-$(CONFIG_CMD_LOG) += log.o
+obj-$(CONFIG_CMD_LSBLK) += lsblk.o
 obj-$(CONFIG_ID_EEPROM) += mac.o
 obj-$(CONFIG_CMD_MD5SUM) += md5sum.o
 obj-$(CONFIG_CMD_MEMORY) += mem.o
diff --git a/cmd/lsblk.c b/cmd/lsblk.c
new file mode 100644
index 00..b3e8394203
--- /dev/null
+++ b/cmd/lsblk.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2020
+ * Niel Fourie, DENX Software Engineering, lu...@denx.de.
+ */
+
+#include 
+#include 
+
+static int do_lsblk(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+   struct driver *d = ll_entry_start(struct driver, driver);
+   const int n_ents = ll_entry_count(struct driver, driver);
+   struct driver *entry;
+   struct udevice *udev;
+   struct uclass *uc;
+   struct blk_desc *desc;
+   int ret, i;
+
+   ret = uclass_get(UCLASS_BLK, );
+   if (ret) {
+   puts("Could not get BLK uclass.\n");
+   return CMD_RET_FAILURE;
+   }
+   puts("Block Driver  Devices\n");
+   puts("-\n");
+   for (entry = d; entry < d + n_ents; entry++) {
+   if (entry->id != UCLASS_BLK)
+   continue;
+   i = 0;
+   printf("%-20.20s", entry->name);
+   uclass_foreach_dev(udev, uc) {
+   if (udev->driver != entry)
+   continue;
+   desc = dev_get_uclass_platdata(udev);
+   printf("%c %s %u", i ? ',' : ':',
+  blk_get_if_type_name(desc->if_type),
+  desc->devnum);
+   i++;
+   }
+   if (!i)
+   puts(": ");
+   puts("\n");
+   }
+
+   return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(lsblk, 1, 0, do_lsblk, "list block drivers and devices",
+  "- display list of block device drivers and attached block devices"
+);
diff --git a/test/py/tests/test_lsblk.py b/test/py/tests/test_lsblk.py
new file mode 100644
index 00..40ffe01263
--- /dev/null
+++ b/test/py/tests/test_lsblk.py
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (C) 2020
+# Niel Fourie, DENX Software Engineering, lu...@denx.de
+
+import pytest
+
+@pytest.mark.buildconfigspec('blk')
+@pytest.mark.buildconfigspec('cmd_lsblk')
+def test_lsblk(u_boot_console):
+"""Test that `lsblk` prints a result which includes `host`."""
+output = u_boot_console.run_command('lsblk')
+assert "Block Driver" in output
+assert "sandbox_host_blk" in output
-- 
2.25.1



[PATCH v2 1/1] cmd: blkls: Add blkls command

2020-03-27 Thread Niel Fourie
Add a command to print a list of available block device drivers,
and for each, the list of known block devices.

Signed-off-by: Niel Fourie 
Cc: Simon Glass 
Cc: Stefan Roese 
---
Changes in v2:
- Removed legacy block device variant of blkls and its test.
- Handle return value of uclass_get().
- Removed unnecessary ifdefs, fixed Kconfig depends.

 cmd/Kconfig |  8 ++
 cmd/Makefile|  1 +
 cmd/lsblk.c | 52 +
 test/py/tests/test_lsblk.py | 13 ++
 4 files changed, 74 insertions(+)
 create mode 100644 cmd/lsblk.c
 create mode 100644 test/py/tests/test_lsblk.py

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 6403bc45a5..891299b9b6 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1047,6 +1047,14 @@ config CMD_LOADS
help
  Load an S-Record file over serial line
 
+config CMD_LSBLK
+   depends on BLK
+   bool "lsblk - list block drivers and devices"
+   default n
+   help
+ Print list of available block device drivers, and for each, the list
+ of known block devices.
+
 config CMD_MMC
bool "mmc"
help
diff --git a/cmd/Makefile b/cmd/Makefile
index f1dd513a4b..6f80974a55 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -83,6 +83,7 @@ obj-$(CONFIG_CMD_LED) += led.o
 obj-$(CONFIG_CMD_LICENSE) += license.o
 obj-y += load.o
 obj-$(CONFIG_CMD_LOG) += log.o
+obj-$(CONFIG_CMD_LSBLK) += lsblk.o
 obj-$(CONFIG_ID_EEPROM) += mac.o
 obj-$(CONFIG_CMD_MD5SUM) += md5sum.o
 obj-$(CONFIG_CMD_MEMORY) += mem.o
diff --git a/cmd/lsblk.c b/cmd/lsblk.c
new file mode 100644
index 00..3c1630710c
--- /dev/null
+++ b/cmd/lsblk.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2020
+ * Niel Fourie, DENX Software Engineering, lu...@denx.de.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+static int do_lsblk(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+   struct driver *d = ll_entry_start(struct driver, driver);
+   const int n_ents = ll_entry_count(struct driver, driver);
+   struct driver *entry;
+   struct udevice *udev;
+   struct uclass *uc;
+   struct blk_desc *desc;
+   int ret, i;
+
+   ret = uclass_get(UCLASS_BLK, );
+   if (ret) {
+   puts("Could not get BLK uclass.\n");
+   return CMD_RET_FAILURE;
+   }
+   puts("Block Driver  Devices\n");
+   puts("-\n");
+   for (entry = d; entry < d + n_ents; entry++) {
+   if (entry->id != UCLASS_BLK)
+   continue;
+   i = 0;
+   printf("%-20.20s", entry->name);
+   uclass_foreach_dev(udev, uc) {
+   if (udev->driver != entry)
+   continue;
+   desc = dev_get_uclass_platdata(udev);
+   printf("%c %s %u", i ? ',' : ':',
+  blk_get_if_type_name(desc->if_type),
+  desc->devnum);
+   i++;
+   }
+   if (!i)
+   puts(": ");
+   puts("\n");
+   }
+   return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(lsblk, 1, 0, do_lsblk, "list block drivers and devices",
+  "- display list of block device drivers and attached block devices"
+);
diff --git a/test/py/tests/test_lsblk.py b/test/py/tests/test_lsblk.py
new file mode 100644
index 00..80f43ff1ed
--- /dev/null
+++ b/test/py/tests/test_lsblk.py
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020
+# Niel Fourie, DENX Software Engineering, lu...@denx.de
+
+import pytest
+
+@pytest.mark.buildconfigspec('blk')
+@pytest.mark.buildconfigspec('cmd_lsblk')
+def test_lsblk(u_boot_console):
+"""Test that `lsblk` prints a result which includes `host`."""
+output = u_boot_console.run_command('lsblk')
+assert "Block Driver" in output
+assert "sandbox_host_blk" in output
-- 
2.25.1



Re: [PATCH 1/1] cmd: blkls: Add blkls command

2020-03-25 Thread Niel Fourie

Hi Stefan,

On 3/25/20 3:13 PM, Stefan Roese wrote:

+config CMD_LSBLK
+    depends on HAVE_BLOCK_DEVICE


You depend on CONFIG_HAVE_BLOCK_DEVICE here...


+
+#if CONFIG_IS_ENABLED(HAVE_BLOCK_DEVICE)


... so this #ifdef should not be necessary, right?


Oops, you are right... I forgot to take out the #ifdef after adding the 
Kconfig dependency. Will fix. Well spotted, thanks!


Best regards,
Niel Fourie

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de


[PATCH 1/1] cmd: blkls: Add blkls command

2020-03-25 Thread Niel Fourie
Add a command to print a list of available block device drivers,
and for each, the list of known block devices.

Signed-off-by: Niel Fourie 
---
 cmd/Kconfig |  8 
 cmd/Makefile|  1 +
 cmd/lsblk.c | 83 +
 test/py/tests/test_lsblk.py | 23 ++
 4 files changed, 115 insertions(+)
 create mode 100644 cmd/lsblk.c
 create mode 100644 test/py/tests/test_lsblk.py

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 6403bc45a5..ee6ff467ae 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1047,6 +1047,14 @@ config CMD_LOADS
help
  Load an S-Record file over serial line
 
+config CMD_LSBLK
+   depends on HAVE_BLOCK_DEVICE
+   bool "lsblk - list block drivers and devices"
+   default n
+   help
+ Print list of available block device drivers, and for each, the list
+ of known block devices.
+
 config CMD_MMC
bool "mmc"
help
diff --git a/cmd/Makefile b/cmd/Makefile
index f1dd513a4b..6f80974a55 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -83,6 +83,7 @@ obj-$(CONFIG_CMD_LED) += led.o
 obj-$(CONFIG_CMD_LICENSE) += license.o
 obj-y += load.o
 obj-$(CONFIG_CMD_LOG) += log.o
+obj-$(CONFIG_CMD_LSBLK) += lsblk.o
 obj-$(CONFIG_ID_EEPROM) += mac.o
 obj-$(CONFIG_CMD_MD5SUM) += md5sum.o
 obj-$(CONFIG_CMD_MEMORY) += mem.o
diff --git a/cmd/lsblk.c b/cmd/lsblk.c
new file mode 100644
index 00..575a1c9277
--- /dev/null
+++ b/cmd/lsblk.c
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2020
+ * Niel Fourie, DENX Software Engineering, lu...@denx.de.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#if CONFIG_IS_ENABLED(HAVE_BLOCK_DEVICE)
+#if CONFIG_IS_ENABLED(BLK)
+static int do_lsblk(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+   struct driver *d = ll_entry_start(struct driver, driver);
+   const int n_ents = ll_entry_count(struct driver, driver);
+   struct driver *entry;
+   struct udevice *udev;
+   struct uclass *uc;
+   struct blk_desc *desc;
+   int i;
+
+   puts("Block Driver  Devices\n");
+   puts("-\n");
+   uclass_get(UCLASS_BLK, );
+   for (entry = d; entry < d + n_ents; entry++) {
+   if (entry->id != UCLASS_BLK)
+   continue;
+   i = 0;
+   printf("%-20.20s", entry->name);
+   uclass_foreach_dev(udev, uc) {
+   if (udev->driver != entry)
+   continue;
+   desc = dev_get_uclass_platdata(udev);
+   printf("%c %s %u", i ? ',' : ':',
+  blk_get_if_type_name(desc->if_type),
+  desc->devnum);
+   i++;
+   }
+   if (!i)
+   puts(": ");
+   puts("\n");
+   }
+   return CMD_RET_SUCCESS;
+}
+#else
+static int do_lsblk(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+   struct blk_driver *drv = ll_entry_start(struct blk_driver, blk_driver);
+   const int n_ents = ll_entry_count(struct blk_driver, blk_driver);
+   struct blk_driver *entry;
+   struct blk_desc *desc;
+   int i, j;
+
+   puts("Block Driver  Devices\n");
+   puts("-\n");
+   for (entry = drv; entry != drv + n_ents; entry++) {
+   i = 0;
+   printf("%-20.20s", entry->if_typename);
+   for (j = 0; j < entry->max_devs; j++) {
+   desc = >desc[j];
+   if (!entry->get_dev)
+   continue;
+   if (entry->get_dev(j, ))
+   continue;
+   if (desc->type == DEV_TYPE_UNKNOWN)
+   continue;
+   printf("%c %s %u", i ? ',' : ':', entry->if_typename,
+  desc->devnum);
+   i++;
+   }
+   if (!i)
+   puts(": ");
+   puts("\n");
+   }
+   return CMD_RET_SUCCESS;
+}
+#endif /* CONFIG_IS_ENABLED(BLK) */
+U_BOOT_CMD(lsblk, 1, 0, do_lsblk, "list block drivers and devices",
+  "- display list of block device drivers and attached block devices"
+);
+#endif /* CONFIG_IS_ENABLED(HAVE_BLOCK_DEVICE) */
diff --git a/test/py/tests/test_lsblk.py b/test/py/tests/test_lsblk.py
new file mode 100644
index 00..f4b36b581e
--- /dev/null
+++ b/test/py/tests/test_lsblk.py
@@ -0,0 +1,23 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020
+# Niel Fourie, DENX Software Engineering, lu...@denx.de
+
+import 

[RFC PATCH 1/1] Makefile: Expand legacy (non-DM) driver warnings

2020-03-25 Thread Niel Fourie
Expand warnings printed by Makefile after compile when legacy
drivers are in use. These include:

- CONFIG_HAVE_BLOCK_DEVICE without CONFIG_BLK
- CONFIG_BOOTCOUNT_LIMIT without CONFIG_DM_BOOTCOUNT
- CONFIG_MTD without CONFIG_DM_MTD
- CONFIG_PHYLIB without CONFIG_DM_MDIO
- CONFIG_POWER, also without CONFIG_DM_PMIC
- Absence of CONFIG_RAM and CONFIG_SPL_RAM

Also replaced existing CONFIG_DM_SPI warning for consistency.
Removed CONFIG_BLK requirement for CONFIG_DM_USB, as all USB
devices not block devices.

Signed-off-by: Niel Fourie 
Cc: Simon Glass 
---
 Makefile | 73 +++-
 1 file changed, 67 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index fa687f13a5..0df58ca7c1 100644
--- a/Makefile
+++ b/Makefile
@@ -963,11 +963,6 @@ cmd_cfgcheck = $(srctree)/scripts/check-config.sh $2 \
 all:   $(ALL-y)
 ifeq ($(CONFIG_DEPRECATED),y)
$(warning "You have deprecated configuration options enabled in your 
.config! Please check your configuration.")
-ifeq ($(CONFIG_SPI),y)
-ifneq ($(CONFIG_DM_SPI)$(CONFIG_OF_CONTROL),yy)
-   $(warning "The relevant config item with associated code will remove in 
v2019.07 release.")
-endif
-endif
 endif
 ifneq ($(CONFIG_DM),y)
@echo >&2 "= WARNING =="
@@ -988,7 +983,7 @@ ifneq 
($(CONFIG_DM_MMC)$(CONFIG_OF_CONTROL)$(CONFIG_BLK),yyy)
 endif
 endif
 ifeq ($(CONFIG_USB),y)
-ifneq ($(CONFIG_DM_USB)$(CONFIG_OF_CONTROL)$(CONFIG_BLK),yyy)
+ifneq ($(CONFIG_DM_USB)$(CONFIG_OF_CONTROL),yy)
@echo >&2 "= WARNING =="
@echo >&2 "This board does not use CONFIG_DM_USB. Please update"
@echo >&2 "the board to use CONFIG_DM_USB before the v2019.07 release."
@@ -1046,6 +1041,16 @@ ifeq ($(CONFIG_OF_EMBED),y)
@echo >&2 "See doc/README.fdt-control for more info."
@echo >&2 ""
 endif
+ifeq ($(CONFIG_SPI),y)
+ifneq ($(CONFIG_DM_SPI)$(CONFIG_OF_CONTROL),yy)
+   @echo >&2 "= WARNING =="
+   @echo >&2 "This board uses CONFIG_SPI without having CONFIG_DM_SPI"
+   @echo >&2 "enabled. Please update the board before the v2019.07 
release."
+   @echo >&2 "Failure to update by the deadline may result in board 
removal."
+   @echo >&2 "See doc/driver-model/migration.rst for more info."
+   @echo >&2 ""
+endif
+endif
 ifeq ($(CONFIG_SPI_FLASH),y)
 ifneq ($(CONFIG_DM_SPI_FLASH)$(CONFIG_OF_CONTROL),yy)
@echo >&2 "= WARNING =="
@@ -1078,6 +1083,62 @@ ifneq ($(CONFIG_DM_ETH),y)
@echo >&2 ""
 endif
 endif
+ifeq ($(CONFIG_HAVE_BLOCK_DEVICE),y)
+ifneq ($(CONFIG_BLK),y)
+   @echo >&2 "= WARNING =="
+   @echo >&2 "This board uses CONFIG_HAVE_BLOCK_DEVICE but does not"
+   @echo >&2 "have CONFIG_BLK enabled. This implies legacy block"
+   @echo >&2 "device support is enabled without driver model (DM)."
+   @echo >&2 ""
+endif
+endif
+ifeq ($(CONFIG_BOOTCOUNT_LIMIT),y)
+ifneq ($(CONFIG_DM_BOOTCOUNT),y)
+   @echo >&2 "= WARNING =="
+   @echo >&2 "This board uses CONFIG_BOOTCOUNT_LIMIT without"
+   @echo >&2 "having CONFIG_DM_BOOTCOUNT enabled. This implies a"
+   @echo >&2 "legacy bootcounter without driver model (DM) support."
+   @echo >&2 ""
+endif
+endif
+ifeq ($(CONFIG_MTD),y)
+ifneq ($(CONFIG_DM_MTD),y)
+   @echo >&2 "= WARNING =="
+   @echo >&2 "This board uses CONFIG_MTD without having CONFIG_DM_MTD"
+   @echo >&2 "enabled. This implies legacy MTD support, without"
+   @echo >&2 "driver model (DM)."
+   @echo >&2 ""
+endif
+endif
+ifeq ($(CONFIG_PHYLIB),y)
+ifneq ($(CONFIG_DM_MDIO),y)
+   @echo >&2 "= WARNING =="
+   @echo >&2 "This board uses CONFIG_PHYLIB, without having"
+   @echo >&2 "CONFIG_DM_MDIO enabled. This implies legacy ethernet"
+   @echo >&2 "phy support, without driver m

[PATCH v3 2/3] cmd: fs: Add command to list supported fs types

2020-03-24 Thread Niel Fourie
Added command "fstypes" to list supported/included filesystems.

Signed-off-by: Niel Fourie 
Cc: Simon Glass 
Reviewed-by: Simon Glass 
---
Changes in v2:
- Add Python test
Changes in v3:
- Rewrote comment for do_fs_types() in fs.h

 cmd/fs.c | 11 +++
 fs/fs.c  | 20 
 include/fs.h | 11 +++
 test/py/tests/test_fs/test_fs_cmd.py | 12 
 4 files changed, 54 insertions(+)
 create mode 100644 test/py/tests/test_fs/test_fs_cmd.py

diff --git a/cmd/fs.c b/cmd/fs.c
index db74767b7b..26b47bd001 100644
--- a/cmd/fs.c
+++ b/cmd/fs.c
@@ -99,3 +99,14 @@ U_BOOT_CMD(
"fstype  : \n"
"- set environment variable to filesystem type\n"
 );
+
+static int do_fstypes_wrapper(cmd_tbl_t *cmdtp, int flag, int argc,
+ char * const argv[])
+{
+   return do_fs_types(cmdtp, flag, argc, argv);
+}
+
+U_BOOT_CMD(
+   fstypes, 1, 1, do_fstypes_wrapper,
+   "List supported filesystem types", ""
+);
diff --git a/fs/fs.c b/fs/fs.c
index 0c66d60477..3e38b2e27a 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -900,3 +900,23 @@ int do_ln(cmd_tbl_t *cmdtp, int flag, int argc, char * 
const argv[],
 
return 0;
 }
+
+int do_fs_types(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+   struct fstype_info *drv = fstypes;
+   const int n_ents = ARRAY_SIZE(fstypes);
+   struct fstype_info *entry;
+   int i = 0;
+
+   puts("Supported filesystems");
+   for (entry = drv; entry != drv + n_ents; entry++) {
+   if (entry->fstype != FS_TYPE_ANY) {
+   printf("%c %s", i ? ',' : ':', entry->name);
+   i++;
+   }
+   }
+   if (!i)
+   puts(": ");
+   puts("\n");
+   return CMD_RET_SUCCESS;
+}
diff --git a/include/fs.h b/include/fs.h
index 37e35c2120..514c248e50 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -254,4 +254,15 @@ int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char 
* const argv[],
  */
 int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 
+/**
+ * do_fs_types - List supported filesystems.
+ *
+ * @cmdtp: Command information for fstypes
+ * @flag: Command flags (CMD_FLAG_...)
+ * @argc: Number of arguments
+ * @argv: List of arguments
+ * @return result (see enum command_ret_t)
+ */
+int do_fs_types(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+
 #endif /* _FS_H */
diff --git a/test/py/tests/test_fs/test_fs_cmd.py 
b/test/py/tests/test_fs/test_fs_cmd.py
new file mode 100644
index 00..86ba92e025
--- /dev/null
+++ b/test/py/tests/test_fs/test_fs_cmd.py
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020
+# Niel Fourie, DENX Software Engineering, lu...@denx.de
+
+import pytest
+
+@pytest.mark.buildconfigspec('cmd_fs_generic')
+def test_dm_compat(u_boot_console):
+"""Test that `fstypes` prints a result which includes `sandbox`."""
+output = u_boot_console.run_command('fstypes')
+assert "Supported filesystems:" in output
+assert "sandbox" in output
-- 
2.25.1



[PATCH v3 1/3] cmd: part: Add subcommand to list supported partition tables

2020-03-24 Thread Niel Fourie
Add a subcommand "types" to the part command, which lists the supported
partition table types.

Signed-off-by: Niel Fourie 
Cc: Simon Glass 
Reviewed-by: Simon Glass 
---
Changes in v2:
- Add Python test
Changes in v3:
- none

 cmd/part.c | 27 +--
 test/py/tests/test_part.py | 14 ++
 2 files changed, 39 insertions(+), 2 deletions(-)
 create mode 100644 test/py/tests/test_part.py

diff --git a/cmd/part.c b/cmd/part.c
index 5e4e45ca6d..fae5df7b71 100644
--- a/cmd/part.c
+++ b/cmd/part.c
@@ -182,6 +182,26 @@ static int do_part_number(int argc, char * const argv[])
return do_part_info(argc, argv, CMD_PART_INFO_NUMBER);
 }
 
+static int do_part_types(int argc, char * const argv[])
+{
+   struct part_driver *drv = ll_entry_start(struct part_driver,
+part_driver);
+   const int n_ents = ll_entry_count(struct part_driver, part_driver);
+   struct part_driver *entry;
+   int i = 0;
+
+   puts("Supported partition tables");
+
+   for (entry = drv; entry != drv + n_ents; entry++) {
+   printf("%c %s", i ? ',' : ':', entry->name);
+   i++;
+   }
+   if (!i)
+   puts(": ");
+   puts("\n");
+   return CMD_RET_SUCCESS;
+}
+
 static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
if (argc < 2)
@@ -197,7 +217,8 @@ static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
return do_part_size(argc - 2, argv + 2);
else if (!strcmp(argv[1], "number"))
return do_part_number(argc - 2, argv + 2);
-
+   else if (!strcmp(argv[1], "types"))
+   return do_part_types(argc - 2, argv + 2);
return CMD_RET_USAGE;
 }
 
@@ -221,5 +242,7 @@ U_BOOT_CMD(
"  part can be either partition number or partition name\n"
"part number\n"
"- set environment variable to the partition number using the 
partition name\n"
-   "  part must be specified as partition name"
+   "  part must be specified as partition name\n"
+   "part types\n"
+   "- list supported partition table types"
 );
diff --git a/test/py/tests/test_part.py b/test/py/tests/test_part.py
new file mode 100644
index 000000..cba9804510
--- /dev/null
+++ b/test/py/tests/test_part.py
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020
+# Niel Fourie, DENX Software Engineering, lu...@denx.de
+
+import pytest
+
+@pytest.mark.buildconfigspec('cmd_part')
+@pytest.mark.buildconfigspec('partitions')
+@pytest.mark.buildconfigspec('efi_partition')
+def test_dm_compat(u_boot_console):
+"""Test that `part types` prints a result which includes `EFI`."""
+output = u_boot_console.run_command('part types')
+assert "Supported partition tables:" in output
+assert "EFI" in output
-- 
2.25.1



[PATCH v3 0/3] cmd: add driver, fs and part type listing commands

2020-03-24 Thread Niel Fourie
This series adds commands for listing the supported partition tables,
listing supported filesystems and expands Driver Model listing commands.

The existing "dm drivers" command, which lists the DM drivers and their
compatibility strings, segmentation faulted on drivers for which of_match
was unpopulated (which appears to not be uncommon). This was fixed, and
the command was renamed "dm compat", and a new more extensive "dm drivers"
command was added, which list all DM drivers and for each, their uclass
id, uclass driver and the device names for active driver instances. The
purpose is show available drivers, but also to highlight unused drivers
or drivers with uclass ids without uclass drivers, etc.

The following commands were added:
-"part types", lists partition tables supported
-"fstypes", lists filesystem types supported
-"dm compat", lists drivers and their compatibility strings (equivalent
  to existing "dm drivers" command)
-"dm drivers", lists all DM drivers, and for each their uclass id,
  uclass driver and the device names for active driver instances.
-"dm static", lists all DM drivers which use static platform data
  (instead of the device tree).

These patches were tested in the Sandbox and on the Wandboard
i.MX6Quad Board rev B1.

Changes in v2:
- Rebased on https://patchwork.ozlabs.org/patch/1234460/
- Added Python tests
- Fixed minor typographical errors
Changes in v3:
- Rewrote comment for do_fs_types() in fs.h

Niel Fourie (3):
  cmd: part: Add subcommand to list supported partition tables
  cmd: fs: Add command to list supported fs types
  cmd: dm: Fixed/Added DM driver listing subcommands

 cmd/dm.c | 22 ++-
 cmd/fs.c | 11 ++
 cmd/part.c   | 27 +-
 drivers/core/dump.c  | 55 +++-
 fs/fs.c  | 20 ++
 include/dm/util.h|  6 +++
 include/fs.h | 11 ++
 test/py/tests/test_dm.py | 22 ++-
 test/py/tests/test_fs/test_fs_cmd.py | 12 ++
 test/py/tests/test_part.py   | 14 +++
 10 files changed, 194 insertions(+), 6 deletions(-)
 create mode 100644 test/py/tests/test_fs/test_fs_cmd.py
 create mode 100644 test/py/tests/test_part.py

-- 
2.25.1



[PATCH v3 3/3] cmd: dm: Fixed/Added DM driver listing subcommands

2020-03-24 Thread Niel Fourie
Renamed dm "drivers" subcommand to "compat" (as it listed
compatibility strings) and prevent it from segfaulting when
drivers have no of_match populated.

Added a new "drivers" subcommand to dump a list of all known DM
drivers and for each, their uclass id, uclass driver and names of
attached devices.

Added a new "static" subcommand to dump a list of DM drivers with
statically defined platform data.

Signed-off-by: Niel Fourie 
Cc: Simon Glass 
Cc: Sean Anderson 
Reviewed-by: Simon Glass 
---
Depends on: https://patchwork.ozlabs.org/patch/1234460/

Changes in v2:
- Add/extend Python tests
- Fixed minor formatting/typographical errors
Changes in v3:
- none

 cmd/dm.c | 22 +++-
 drivers/core/dump.c  | 55 +++-
 include/dm/util.h|  6 +
 test/py/tests/test_dm.py | 22 ++--
 4 files changed, 101 insertions(+), 4 deletions(-)

diff --git a/cmd/dm.c b/cmd/dm.c
index 7a90685f8b..fa7eba6a17 100644
--- a/cmd/dm.c
+++ b/cmd/dm.c
@@ -48,11 +48,29 @@ static int do_dm_dump_drivers(cmd_tbl_t *cmdtp, int flag, 
int argc,
return 0;
 }
 
+static int do_dm_dump_driver_compat(cmd_tbl_t *cmdtp, int flag, int argc,
+   char * const argv[])
+{
+   dm_dump_driver_compat();
+
+   return 0;
+}
+
+static int do_dm_dump_static_driver_info(cmd_tbl_t *cmdtp, int flag, int argc,
+char * const argv[])
+{
+   dm_dump_static_driver_info();
+
+   return 0;
+}
+
 static cmd_tbl_t test_commands[] = {
U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
U_BOOT_CMD_MKENT(devres, 1, 1, do_dm_dump_devres, "", ""),
U_BOOT_CMD_MKENT(drivers, 1, 1, do_dm_dump_drivers, "", ""),
+   U_BOOT_CMD_MKENT(compat, 1, 1, do_dm_dump_driver_compat, "", ""),
+   U_BOOT_CMD_MKENT(static, 1, 1, do_dm_dump_static_driver_info, "", ""),
 };
 
 static __maybe_unused void dm_reloc(void)
@@ -94,5 +112,7 @@ U_BOOT_CMD(
"tree  Dump driver model tree ('*' = activated)\n"
"dm uclassDump list of instances for each uclass\n"
"dm devresDump list of device resources for each device\n"
-   "dm drivers   Dump list of drivers and their compatible strings"
+   "dm drivers   Dump list of drivers with uclass and instances\n"
+   "dm compatDump list of drivers with compatibility strings\n"
+   "dm staticDump list of drivers with static platform data"
 );
diff --git a/drivers/core/dump.c b/drivers/core/dump.c
index b5046398d4..e96d59f861 100644
--- a/drivers/core/dump.c
+++ b/drivers/core/dump.c
@@ -97,7 +97,7 @@ void dm_dump_uclass(void)
}
 }
 
-void dm_dump_drivers(void)
+void dm_dump_driver_compat(void)
 {
struct driver *d = ll_entry_start(struct driver, driver);
const int n_ents = ll_entry_count(struct driver, driver);
@@ -116,3 +116,56 @@ void dm_dump_drivers(void)
printf("%-20.20s\n", entry->name);
}
 }
+
+void dm_dump_drivers(void)
+{
+   struct driver *d = ll_entry_start(struct driver, driver);
+   const int n_ents = ll_entry_count(struct driver, driver);
+   struct driver *entry;
+   struct udevice *udev;
+   struct uclass *uc;
+   int i;
+
+   puts("Driveruid uclass   Devices\n");
+   puts("--\n");
+
+   for (entry = d; entry < d + n_ents; entry++) {
+   uclass_get(entry->id, );
+
+   printf("%-25.25s %-3.3d %-20.20s ", entry->name, entry->id,
+  uc ? uc->uc_drv->name : "");
+
+   if (!uc) {
+   puts("\n");
+   continue;
+   }
+
+   i = 0;
+   uclass_foreach_dev(udev, uc) {
+   if (udev->driver != entry)
+   continue;
+   if (i)
+   printf("%-51.51s", "");
+
+   printf("%-25.25s\n", udev->name);
+   i++;
+   }
+   if (!i)
+   puts("\n");
+   }
+}
+
+void dm_dump_static_driver_info(void)
+{
+   struct driver_info *drv = ll_entry_start(struct driver_info,
+driver_info);
+   const int n_ents = ll_entry_count(struct driver_info, driver_info);
+   struct driver_info *entry;
+
+   puts("Driver   

Re: [PATCH v2 3/3] cmd: dm: Fixed/Added DM driver listing subcommands

2020-03-20 Thread Niel Fourie

Hi Sean,

On 3/19/20 7:37 PM, Sean Anderson wrote:


diff --git a/test/py/tests/test_dm.py b/test/py/tests/test_dm.py
index f6fbf8ba4c..97203b536e 100644
--- a/test/py/tests/test_dm.py
+++ b/test/py/tests/test_dm.py
@@ -4,14 +4,32 @@
  import pytest
  
  @pytest.mark.buildconfigspec('cmd_dm')

-def test_dm_drivers(u_boot_console):
-"""Test that each driver in `dm tree` is also listed in `dm drivers`."""
+def test_dm_compat(u_boot_console):
+"""Test that each driver in `dm tree` is also listed in `dm compat`."""
  response = u_boot_console.run_command('dm tree')
  driver_index = response.find('Driver')
  assert driver_index != -1
  drivers = (line[driver_index:].split()[0]
 for line in response[:-1].split('\n')[2:])
  
+response = u_boot_console.run_command('dm compat')

+for driver in drivers:
+assert driver in response
+


Why is the above marked as being added? These lines are present in the
patch which adds the original test.



Well spotted! I had to give it a second look before I grasped what 
happened there... My tests were all based on yours, and it turns out 
that the last 4 lines of my last test, test_dm_static(), exactly matches 
those 4 lines in your original patch. And as I had changed the command 
to run in your test from "dm driver" to "dm compat", git decided to just 
insert all of my changes in one block in the middle of what was 
originally your test. At the bottom of the patch you can still see your 
original code:


+@pytest.mark.buildconfigspec('cmd_dm')
+def test_dm_static(u_boot_console):
+"""Test that each driver in `dm static` is also listed in `dm 
drivers`."""

+response = u_boot_console.run_command('dm static')
+drivers = (line[:25].rstrip() for line in 
response[:-1].split('\n')[2:])

 response = u_boot_console.run_command('dm drivers')
 for driver in drivers:
 assert driver in response

Best regards,
Niel Fourie

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de


[PATCH v2 3/3] cmd: dm: Fixed/Added DM driver listing subcommands

2020-03-19 Thread Niel Fourie
Renamed dm "drivers" subcommand to "compat" (as it listed
compatibility strings) and prevent it from segfaulting when
drivers have no of_match populated.

Added a new "drivers" subcommand to dump a list of all known DM
drivers and for each, their uclass id, uclass driver and names of
attached devices.

Added a new "static" subcommand to dump a list of DM drivers with
statically defined platform data.

Signed-off-by: Niel Fourie 
CC: Simon Glass 
CC: Sean Anderson 
---
Depends on: https://patchwork.ozlabs.org/patch/1234460/

Changes in v2:
- Add/extend Python tests
- Fixed minor formatting/typographical errors

 cmd/dm.c | 22 +++-
 drivers/core/dump.c  | 55 +++-
 include/dm/util.h|  6 +
 test/py/tests/test_dm.py | 22 ++--
 4 files changed, 101 insertions(+), 4 deletions(-)

diff --git a/cmd/dm.c b/cmd/dm.c
index 7a90685f8b..fa7eba6a17 100644
--- a/cmd/dm.c
+++ b/cmd/dm.c
@@ -48,11 +48,29 @@ static int do_dm_dump_drivers(cmd_tbl_t *cmdtp, int flag, 
int argc,
return 0;
 }
 
+static int do_dm_dump_driver_compat(cmd_tbl_t *cmdtp, int flag, int argc,
+   char * const argv[])
+{
+   dm_dump_driver_compat();
+
+   return 0;
+}
+
+static int do_dm_dump_static_driver_info(cmd_tbl_t *cmdtp, int flag, int argc,
+char * const argv[])
+{
+   dm_dump_static_driver_info();
+
+   return 0;
+}
+
 static cmd_tbl_t test_commands[] = {
U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
U_BOOT_CMD_MKENT(devres, 1, 1, do_dm_dump_devres, "", ""),
U_BOOT_CMD_MKENT(drivers, 1, 1, do_dm_dump_drivers, "", ""),
+   U_BOOT_CMD_MKENT(compat, 1, 1, do_dm_dump_driver_compat, "", ""),
+   U_BOOT_CMD_MKENT(static, 1, 1, do_dm_dump_static_driver_info, "", ""),
 };
 
 static __maybe_unused void dm_reloc(void)
@@ -94,5 +112,7 @@ U_BOOT_CMD(
"tree  Dump driver model tree ('*' = activated)\n"
"dm uclassDump list of instances for each uclass\n"
"dm devresDump list of device resources for each device\n"
-   "dm drivers   Dump list of drivers and their compatible strings"
+   "dm drivers   Dump list of drivers with uclass and instances\n"
+   "dm compatDump list of drivers with compatibility strings\n"
+   "dm staticDump list of drivers with static platform data"
 );
diff --git a/drivers/core/dump.c b/drivers/core/dump.c
index b5046398d4..e96d59f861 100644
--- a/drivers/core/dump.c
+++ b/drivers/core/dump.c
@@ -97,7 +97,7 @@ void dm_dump_uclass(void)
}
 }
 
-void dm_dump_drivers(void)
+void dm_dump_driver_compat(void)
 {
struct driver *d = ll_entry_start(struct driver, driver);
const int n_ents = ll_entry_count(struct driver, driver);
@@ -116,3 +116,56 @@ void dm_dump_drivers(void)
printf("%-20.20s\n", entry->name);
}
 }
+
+void dm_dump_drivers(void)
+{
+   struct driver *d = ll_entry_start(struct driver, driver);
+   const int n_ents = ll_entry_count(struct driver, driver);
+   struct driver *entry;
+   struct udevice *udev;
+   struct uclass *uc;
+   int i;
+
+   puts("Driveruid uclass   Devices\n");
+   puts("--\n");
+
+   for (entry = d; entry < d + n_ents; entry++) {
+   uclass_get(entry->id, );
+
+   printf("%-25.25s %-3.3d %-20.20s ", entry->name, entry->id,
+  uc ? uc->uc_drv->name : "");
+
+   if (!uc) {
+   puts("\n");
+   continue;
+   }
+
+   i = 0;
+   uclass_foreach_dev(udev, uc) {
+   if (udev->driver != entry)
+   continue;
+   if (i)
+   printf("%-51.51s", "");
+
+   printf("%-25.25s\n", udev->name);
+   i++;
+   }
+   if (!i)
+   puts("\n");
+   }
+}
+
+void dm_dump_static_driver_info(void)
+{
+   struct driver_info *drv = ll_entry_start(struct driver_info,
+driver_info);
+   const int n_ents = ll_entry_count(struct driver_info, driver_info);
+   struct driver_info *entry;
+
+   puts("DriverAddress\n");
+   puts("---

[PATCH v2 1/3] cmd: part: Add subcommand to list supported partition tables

2020-03-19 Thread Niel Fourie
Add a subcommand "types" to the part command, which lists the supported
partition table types.

Signed-off-by: Niel Fourie 
CC: Simon Glass 
---
Changes in v2:
- Add Python test

 cmd/part.c | 27 +--
 test/py/tests/test_part.py | 14 ++
 2 files changed, 39 insertions(+), 2 deletions(-)
 create mode 100644 test/py/tests/test_part.py

diff --git a/cmd/part.c b/cmd/part.c
index 5e4e45ca6d..fae5df7b71 100644
--- a/cmd/part.c
+++ b/cmd/part.c
@@ -182,6 +182,26 @@ static int do_part_number(int argc, char * const argv[])
return do_part_info(argc, argv, CMD_PART_INFO_NUMBER);
 }
 
+static int do_part_types(int argc, char * const argv[])
+{
+   struct part_driver *drv = ll_entry_start(struct part_driver,
+part_driver);
+   const int n_ents = ll_entry_count(struct part_driver, part_driver);
+   struct part_driver *entry;
+   int i = 0;
+
+   puts("Supported partition tables");
+
+   for (entry = drv; entry != drv + n_ents; entry++) {
+   printf("%c %s", i ? ',' : ':', entry->name);
+   i++;
+   }
+   if (!i)
+   puts(": ");
+   puts("\n");
+   return CMD_RET_SUCCESS;
+}
+
 static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
if (argc < 2)
@@ -197,7 +217,8 @@ static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
return do_part_size(argc - 2, argv + 2);
else if (!strcmp(argv[1], "number"))
return do_part_number(argc - 2, argv + 2);
-
+   else if (!strcmp(argv[1], "types"))
+   return do_part_types(argc - 2, argv + 2);
return CMD_RET_USAGE;
 }
 
@@ -221,5 +242,7 @@ U_BOOT_CMD(
"  part can be either partition number or partition name\n"
"part number\n"
"- set environment variable to the partition number using the 
partition name\n"
-   "  part must be specified as partition name"
+   "  part must be specified as partition name\n"
+   "part types\n"
+   "- list supported partition table types"
 );
diff --git a/test/py/tests/test_part.py b/test/py/tests/test_part.py
new file mode 100644
index 000000..cba9804510
--- /dev/null
+++ b/test/py/tests/test_part.py
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020
+# Niel Fourie, DENX Software Engineering, lu...@denx.de
+
+import pytest
+
+@pytest.mark.buildconfigspec('cmd_part')
+@pytest.mark.buildconfigspec('partitions')
+@pytest.mark.buildconfigspec('efi_partition')
+def test_dm_compat(u_boot_console):
+"""Test that `part types` prints a result which includes `EFI`."""
+output = u_boot_console.run_command('part types')
+assert "Supported partition tables:" in output
+assert "EFI" in output
-- 
2.25.1



[PATCH v2 2/3] cmd: fs: Add command to list supported fs types

2020-03-19 Thread Niel Fourie
Added command "fstypes" to list supported/included filesystems.

Signed-off-by: Niel Fourie 
CC: Simon Glass 
---
Changes in v2:
- Add Python test

 cmd/fs.c | 11 +++
 fs/fs.c  | 20 
 include/fs.h |  5 +
 test/py/tests/test_fs/test_fs_cmd.py | 12 
 4 files changed, 48 insertions(+)
 create mode 100644 test/py/tests/test_fs/test_fs_cmd.py

diff --git a/cmd/fs.c b/cmd/fs.c
index db74767b7b..26b47bd001 100644
--- a/cmd/fs.c
+++ b/cmd/fs.c
@@ -99,3 +99,14 @@ U_BOOT_CMD(
"fstype  : \n"
"- set environment variable to filesystem type\n"
 );
+
+static int do_fstypes_wrapper(cmd_tbl_t *cmdtp, int flag, int argc,
+ char * const argv[])
+{
+   return do_fs_types(cmdtp, flag, argc, argv);
+}
+
+U_BOOT_CMD(
+   fstypes, 1, 1, do_fstypes_wrapper,
+   "List supported filesystem types", ""
+);
diff --git a/fs/fs.c b/fs/fs.c
index 0c66d60477..3e38b2e27a 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -900,3 +900,23 @@ int do_ln(cmd_tbl_t *cmdtp, int flag, int argc, char * 
const argv[],
 
return 0;
 }
+
+int do_fs_types(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+   struct fstype_info *drv = fstypes;
+   const int n_ents = ARRAY_SIZE(fstypes);
+   struct fstype_info *entry;
+   int i = 0;
+
+   puts("Supported filesystems");
+   for (entry = drv; entry != drv + n_ents; entry++) {
+   if (entry->fstype != FS_TYPE_ANY) {
+   printf("%c %s", i ? ',' : ':', entry->name);
+   i++;
+   }
+   }
+   if (!i)
+   puts(": ");
+   puts("\n");
+   return CMD_RET_SUCCESS;
+}
diff --git a/include/fs.h b/include/fs.h
index 37e35c2120..b3fd0b179d 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -254,4 +254,9 @@ int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * 
const argv[],
  */
 int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 
+/*
+ * List supported filesystems.
+ */
+int do_fs_types(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+
 #endif /* _FS_H */
diff --git a/test/py/tests/test_fs/test_fs_cmd.py 
b/test/py/tests/test_fs/test_fs_cmd.py
new file mode 100644
index 00..86ba92e025
--- /dev/null
+++ b/test/py/tests/test_fs/test_fs_cmd.py
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020
+# Niel Fourie, DENX Software Engineering, lu...@denx.de
+
+import pytest
+
+@pytest.mark.buildconfigspec('cmd_fs_generic')
+def test_dm_compat(u_boot_console):
+"""Test that `fstypes` prints a result which includes `sandbox`."""
+output = u_boot_console.run_command('fstypes')
+assert "Supported filesystems:" in output
+assert "sandbox" in output
-- 
2.25.1



[PATCH v2 0/3] cmd: add driver, fs and part type listing commands

2020-03-19 Thread Niel Fourie
This series adds commands for listing the supported partition tables,
listing supported filesystems and expands Driver Model listing commands.

The existing "dm drivers" command, which lists the DM drivers and their
compatibility strings, segmentation faulted on drivers for which of_match
was unpopulated (which appears to not be uncommon). This was fixed, and
the command was renamed "dm compat", and a new more extensive "dm drivers"
command was added, which list all DM drivers and for each, their uclass
id, uclass driver and the device names for active driver instances. The
purpose is show available drivers, but also to highlight unused drivers
or drivers with uclass ids without uclass drivers, etc.

The following commands were added:
-"part types", lists partition tables supported
-"fstypes", lists filesystem types supported
-"dm compat", lists drivers and their compatibility strings (equivalent
  to existing "dm drivers" command)
-"dm drivers", lists all DM drivers, and for each their uclass id,
  uclass driver and the device names for active driver instances.
-"dm static", lists all DM drivers which use static platform data
  (instead of the device tree).

These patches were tested in the Sandbox and on the Wandboard
i.MX6Quad Board rev B1.

Changes in v2:
- Rebased on https://patchwork.ozlabs.org/patch/1234460/
- Added Python tests
- Fixed minor typographical errors

Niel Fourie (3):
  cmd: part: Add subcommand to list supported partition tables
  cmd: fs: Add command to list supported fs types
  cmd: dm: Fixed/Added DM driver listing subcommands

 cmd/dm.c | 22 ++-
 cmd/fs.c | 11 ++
 cmd/part.c   | 27 +-
 drivers/core/dump.c  | 55 +++-
 fs/fs.c  | 20 ++
 include/dm/util.h|  6 +++
 include/fs.h |  5 +++
 test/py/tests/test_dm.py | 22 ++-
 test/py/tests/test_fs/test_fs_cmd.py | 12 ++
 test/py/tests/test_part.py   | 14 +++
 10 files changed, 188 insertions(+), 6 deletions(-)
 create mode 100644 test/py/tests/test_fs/test_fs_cmd.py
 create mode 100644 test/py/tests/test_part.py

-- 
2.25.1



Re: [PATCH 3/3] cmd: dm: Fixed/Added DM driver listing subcommands

2020-03-18 Thread Niel Fourie

Hi Tom,

On 3/17/20 7:51 PM, Sean Anderson wrote:

On 3/17/20 10:09 AM, Niel Fourie wrote:

Renamed dm "drivers" subcommand to "compat" (as it listed
compatibility strings) and prevent it from segfaulting when
drivers have no of_match populated.

Added a new "drivers" subcommand to dump a list of all known DM
drivers and for each, their uclass id, uclass driver and names of
attached devices.

Added a new "static" subcommand to dump a list of DM drivers with
statically defined platform data.

Signed-off-by: Niel Fourie 
CC: Simon Glass 
---
  cmd/dm.c| 24 --
  drivers/core/dump.c | 60 -
  include/dm/util.h   |  6 +
  3 files changed, 87 insertions(+), 3 deletions(-)



In drivers/core/dump.c:
  
-void dm_dump_drivers(void)

+void dm_dump_driver_compat(void)
  {
struct driver *d = ll_entry_start(struct driver, driver);
const int n_ents = ll_entry_count(struct driver, driver);
@@ -107,6 +107,9 @@ void dm_dump_drivers(void)
puts("DriverCompatible\n");
puts("\n");
for (entry = d; entry < d + n_ents; entry++) {
+   if (!entry->of_match) {
+   continue;
+   }


This should have been fixed in version 2 of the patch [1].

[1] https://patchwork.ozlabs.org/patch/1234460/



Should I rebase my series on the version 2 of the above patch, or should 
I simply include that change in my series instead? Thanks in advance!


Best regards,
Niel Fourie

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de


Re: [PATCH 3/3] cmd: dm: Fixed/Added DM driver listing subcommands

2020-03-18 Thread Niel Fourie

Hi Sean, Simon,

I will write tests for all of these cases as Simon requested. Thanks, it 
did not occur to me.


On 3/17/20 7:51 PM, Sean Anderson wrote:

-void dm_dump_drivers(void)
+void dm_dump_driver_compat(void)
  {
struct driver *d = ll_entry_start(struct driver, driver);
const int n_ents = ll_entry_count(struct driver, driver);
@@ -107,6 +107,9 @@ void dm_dump_drivers(void)
puts("DriverCompatible\n");
puts("\n");
for (entry = d; entry < d + n_ents; entry++) {
+   if (!entry->of_match) {
+   continue;
+   }


This should have been fixed in version 2 of the patch [1].


Ah, I didn't know of that patch. I'll ask Tom whether I should rebase my 
patches on top of that change or not.



+
+void dm_dump_drivers(void)
+{
+   struct driver *d = ll_entry_start(struct driver, driver);
+   const int n_ents = ll_entry_count(struct driver, driver);
+   struct driver *entry;
+   struct udevice *udev;
+   struct uclass *uc;
+   int i;
+
+   puts("Driveruid uclass   Devices\n");
+   for (i = 0; i < 77; i++)
+   putc('-');


Can you print these dashes in a way which makes it obvious that they are
the correct length? E.g. do something like

puts("Driveruid uclass   Devices\n");
puts("--\n");



Ah, I was lining the dashes up with the contents instead of the heading. 
I will fix all cases to be like the above. Thanks!



+void dm_dump_static_driver_info(void)
+{
+   struct driver_info *drv = ll_entry_start(struct driver_info,
+driver_info);
+   const int n_ents = ll_entry_count(struct driver_info, driver_info);
+   struct driver_info *entry;
+
+   puts("Driver   Address\n");
+   puts("--\n");
+   for (entry = drv; entry != drv + n_ents; entry++) {
+   printf("%-20.20s @%08lx\n", entry->name,
+  (ulong)map_to_sysmem(entry->platdata));
+   }
+}


Just curious, what were you using this for?


In general I was looking for ways to query list-able capabilities of 
U-boot at run time, to show anomalies and to highlight legacy/non-ideal 
implementations when possible; it is hard to fix a problem which you 
can't see it.


Because the U_BOOT_DEVICE() devices should be used sparingly and do not 
appear in the device tree, I felt that it was useful to list them to see 
their impact. The address is useful to for eyeballing the platform data 
with md.b to distinguish between multiple driver instances...


In the hunt against legacy drivers, I am also looking at ways of 
listing/highlighting other problem-children at run time, but whether 
those patches will see light-of-day is another matter...


Best regards,
Niel Fourie

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de


[PATCH 3/3] cmd: dm: Fixed/Added DM driver listing subcommands

2020-03-17 Thread Niel Fourie
Renamed dm "drivers" subcommand to "compat" (as it listed
compatibility strings) and prevent it from segfaulting when
drivers have no of_match populated.

Added a new "drivers" subcommand to dump a list of all known DM
drivers and for each, their uclass id, uclass driver and names of
attached devices.

Added a new "static" subcommand to dump a list of DM drivers with
statically defined platform data.

Signed-off-by: Niel Fourie 
CC: Simon Glass 
---
 cmd/dm.c| 24 --
 drivers/core/dump.c | 60 -
 include/dm/util.h   |  6 +
 3 files changed, 87 insertions(+), 3 deletions(-)

diff --git a/cmd/dm.c b/cmd/dm.c
index 108707c298..a17ef6a1bb 100644
--- a/cmd/dm.c
+++ b/cmd/dm.c
@@ -48,11 +48,29 @@ static int do_dm_dump_drivers(cmd_tbl_t *cmdtp, int flag, 
int argc,
return 0;
 }
 
+static int do_dm_dump_driver_compat(cmd_tbl_t *cmdtp, int flag, int argc,
+   char * const argv[])
+{
+   dm_dump_driver_compat();
+
+   return 0;
+}
+
+static int do_dm_dump_static_driver_info(cmd_tbl_t *cmdtp, int flag, int argc,
+char * const argv[])
+{
+   dm_dump_static_driver_info();
+
+   return 0;
+}
+
 static cmd_tbl_t test_commands[] = {
U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
U_BOOT_CMD_MKENT(devres, 1, 1, do_dm_dump_devres, "", ""),
U_BOOT_CMD_MKENT(drivers, 1, 1, do_dm_dump_drivers, "", ""),
+   U_BOOT_CMD_MKENT(compat, 1, 1, do_dm_dump_driver_compat, "", ""),
+   U_BOOT_CMD_MKENT(static, 1, 1, do_dm_dump_static_driver_info, "", ""),
 };
 
 static __maybe_unused void dm_reloc(void)
@@ -91,8 +109,10 @@ static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char 
* const argv[])
 U_BOOT_CMD(
dm, 3,  1,  do_dm,
"Driver model low level access",
-   "tree  Dump driver model tree ('*' = activated)\n"
+   "dm tree  Dump driver model tree ('*' = activated)\n"
"dm uclassDump list of instances for each uclass\n"
"dm devresDump list of device resources for each device\n"
-   "dm drivers   Dump list of drivers and their compatible strings\n"
+   "dm drivers   Dump list of drivers with uclass and instances\n"
+   "dm compatDump list of drivers with compatibility strings\n"
+   "dm staticDump list of drivers with static platform data\n"
 );
diff --git a/drivers/core/dump.c b/drivers/core/dump.c
index e73ebeabcc..a42bfb577f 100644
--- a/drivers/core/dump.c
+++ b/drivers/core/dump.c
@@ -97,7 +97,7 @@ void dm_dump_uclass(void)
}
 }
 
-void dm_dump_drivers(void)
+void dm_dump_driver_compat(void)
 {
struct driver *d = ll_entry_start(struct driver, driver);
const int n_ents = ll_entry_count(struct driver, driver);
@@ -107,6 +107,9 @@ void dm_dump_drivers(void)
puts("DriverCompatible\n");
puts("\n");
for (entry = d; entry < d + n_ents; entry++) {
+   if (!entry->of_match) {
+   continue;
+   }
for (match = entry->of_match; match->compatible; match++)
printf("%-20.20s  %s\n",
   match == entry->of_match ? entry->name : "",
@@ -115,3 +118,58 @@ void dm_dump_drivers(void)
printf("%-20.20s\n", entry->name);
}
 }
+
+void dm_dump_drivers(void)
+{
+   struct driver *d = ll_entry_start(struct driver, driver);
+   const int n_ents = ll_entry_count(struct driver, driver);
+   struct driver *entry;
+   struct udevice *udev;
+   struct uclass *uc;
+   int i;
+
+   puts("Driveruid uclass   Devices\n");
+   for (i = 0; i < 77; i++)
+   putc('-');
+   putc('\n');
+
+   for (entry = d; entry < d + n_ents; entry++) {
+   uclass_get(entry->id, );
+
+   printf("%-25.25s %-3.3d %-20.20s ", entry->name, entry->id,
+  uc ? uc->uc_drv->name : "");
+
+   if (!uc) {
+   puts("\n");
+   continue;
+   }
+
+   i = 0;
+   uclass_foreach_dev(udev, uc) {
+   if (udev->driver != entry)
+   continue;
+   if (i)
+   printf("%-51.51s", "");

[PATCH 2/3] cmd: fs: Add command to list supported fs types

2020-03-17 Thread Niel Fourie
Added command "fstypes" to list supported/included filesystems.

Signed-off-by: Niel Fourie 
CC: Simon Glass 
---
 cmd/fs.c | 11 +++
 fs/fs.c  | 20 
 include/fs.h |  5 +
 3 files changed, 36 insertions(+)

diff --git a/cmd/fs.c b/cmd/fs.c
index db74767b7b..26b47bd001 100644
--- a/cmd/fs.c
+++ b/cmd/fs.c
@@ -99,3 +99,14 @@ U_BOOT_CMD(
"fstype  : \n"
"- set environment variable to filesystem type\n"
 );
+
+static int do_fstypes_wrapper(cmd_tbl_t *cmdtp, int flag, int argc,
+ char * const argv[])
+{
+   return do_fs_types(cmdtp, flag, argc, argv);
+}
+
+U_BOOT_CMD(
+   fstypes, 1, 1, do_fstypes_wrapper,
+   "List supported filesystem types", ""
+);
diff --git a/fs/fs.c b/fs/fs.c
index 0c66d60477..3e38b2e27a 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -900,3 +900,23 @@ int do_ln(cmd_tbl_t *cmdtp, int flag, int argc, char * 
const argv[],
 
return 0;
 }
+
+int do_fs_types(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+   struct fstype_info *drv = fstypes;
+   const int n_ents = ARRAY_SIZE(fstypes);
+   struct fstype_info *entry;
+   int i = 0;
+
+   puts("Supported filesystems");
+   for (entry = drv; entry != drv + n_ents; entry++) {
+   if (entry->fstype != FS_TYPE_ANY) {
+   printf("%c %s", i ? ',' : ':', entry->name);
+   i++;
+   }
+   }
+   if (!i)
+   puts(": ");
+   puts("\n");
+   return CMD_RET_SUCCESS;
+}
diff --git a/include/fs.h b/include/fs.h
index 37e35c2120..b3fd0b179d 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -254,4 +254,9 @@ int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * 
const argv[],
  */
 int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 
+/*
+ * List supported filesystems.
+ */
+int do_fs_types(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+
 #endif /* _FS_H */
-- 
2.24.1



[PATCH 1/3] cmd: part: Add subcommand to list supported partition tables

2020-03-17 Thread Niel Fourie
Add a subcommand "types" to the part command, which lists the supported
partition table types.

Signed-off-by: Niel Fourie 
CC: Simon Glass 
---
 cmd/part.c | 27 +--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/cmd/part.c b/cmd/part.c
index 5e4e45ca6d..fae5df7b71 100644
--- a/cmd/part.c
+++ b/cmd/part.c
@@ -182,6 +182,26 @@ static int do_part_number(int argc, char * const argv[])
return do_part_info(argc, argv, CMD_PART_INFO_NUMBER);
 }
 
+static int do_part_types(int argc, char * const argv[])
+{
+   struct part_driver *drv = ll_entry_start(struct part_driver,
+part_driver);
+   const int n_ents = ll_entry_count(struct part_driver, part_driver);
+   struct part_driver *entry;
+   int i = 0;
+
+   puts("Supported partition tables");
+
+   for (entry = drv; entry != drv + n_ents; entry++) {
+   printf("%c %s", i ? ',' : ':', entry->name);
+   i++;
+   }
+   if (!i)
+   puts(": ");
+   puts("\n");
+   return CMD_RET_SUCCESS;
+}
+
 static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
if (argc < 2)
@@ -197,7 +217,8 @@ static int do_part(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
return do_part_size(argc - 2, argv + 2);
else if (!strcmp(argv[1], "number"))
return do_part_number(argc - 2, argv + 2);
-
+   else if (!strcmp(argv[1], "types"))
+   return do_part_types(argc - 2, argv + 2);
return CMD_RET_USAGE;
 }
 
@@ -221,5 +242,7 @@ U_BOOT_CMD(
"  part can be either partition number or partition name\n"
"part number\n"
"- set environment variable to the partition number using the 
partition name\n"
-   "  part must be specified as partition name"
+   "  part must be specified as partition name\n"
+   "part types\n"
+   "- list supported partition table types"
 );
-- 
2.24.1



[PATCH 0/3] cmd: add driver, fs and part type listing commands

2020-03-17 Thread Niel Fourie
This series adds commands for listing the supported partition tables,
listing supported filesystems and expands Driver Model listing commands.

The existing "dm drivers" command, which lists the DM drivers and their
compatibility strings, segmentation faulted on drivers for which of_match
was unpopulated (which appears to not be uncommon). This was fixed, and
the command was renamed "dm compat", and a new more extensive "dm drivers"
command was added, which list all DM drivers and for each, their uclass
id, uclass driver and the device names for active driver instances. The
purpose is show available drivers, but also to highlight unused drivers
or drivers with uclass ids without uclass drivers, etc.

The following commands were added:
-"part types", lists partition tables supported
-"fstypes", lists filesystem types supported
-"dm compat", lists drivers and their compatibility strings (equivalent
  to existing "dm drivers" command)
-"dm drivers", lists all DM drivers, and for each their uclass id,
  uclass driver and the device names for active driver instances.
-"dm static", lists all DM drivers which use static platform data
  (instead of the device tree).

These patches were tested in the Sandbox and on the Wandboard
i.MX6Quad Board rev B1.

Niel Fourie (3):
  cmd: part: Add subcommand to list supported partition tables
  cmd: fs: Add command to list supported fs types
  cmd: dm: Fixed/Added DM driver listing subcommands

 cmd/dm.c| 24 --
 cmd/fs.c| 11 +
 cmd/part.c  | 27 ++--
 drivers/core/dump.c | 60 -
 fs/fs.c | 20 +++
 include/dm/util.h   |  6 +
 include/fs.h|  5 
 7 files changed, 148 insertions(+), 5 deletions(-)

-- 
2.24.1



[U-Boot] [PATCH v6] ARM: am335x: Add phyCORE AM335x R2 support

2019-05-08 Thread Niel Fourie
Support for Phytech phyCORE AM335x R2 SOM (PCL060) on the Phytec
phyBOARD-Wega AM335x.

CPU  : AM335X-GP rev 2.1
Model: Phytec AM335x phyBOARD-WEGA
DRAM:  256 MiB
NAND:  256 MiB
MMC:   OMAP SD/MMC: 0
eth0: ethernet@4a10

Working:
 - Eth0
 - i2C
 - MMC/SD
 - NAND
 - UART
 - USB (host)

Device trees were taken from Linux mainline:
commit 37624b58542f ("Linux 5.1-rc7")

Signed-off-by: Niel Fourie 
Reviewed-by: Heiko Schocher 
---

Notes:
Changes for v6:
- RAM initialisation reworked to detect available memory
- Remove memory section from am335x-wega-rdk-u-boot.dtsi

Changes for v5:
- Revert proposed moving of sections to am33xx-u-boot.dtsi
- Remove redundant/incorrect lines from am33xx-u-boot.dtsi
- Add missing changelog

Changes for v4:
- Propose abstracting common sections to am33xx-u-boot.dtsi
- Remove dead Falcon mode code
- Remove non-DM I2C support for TPS65910 I2C

Changes for v3:
- Added kernel revision of upstream Linux dtsi files
- Place TARGET_PHYCORE_AM335X_R2 alphabetically in Kconfig
- Rework TPS65910 I2C init code
- Remove non-DM USB board macros
- Minor tweaks

Changes for v2:
- Remove formatting changes to upstream Linux dtsi files
- Remove incorrectly added MACH_TYPE
- Rename board from phycore_pcl060 to phycore_am335x_r2
- Implement selecting memory size from device tree
- Remove non-DM Ethernet board code
- General clean-up

 arch/arm/dts/Makefile  |   3 +-
 arch/arm/dts/am335x-phycore-som.dtsi   | 322 +
 arch/arm/dts/am335x-wega-rdk-u-boot.dtsi   |  27 ++
 arch/arm/dts/am335x-wega-rdk.dts   |  23 ++
 arch/arm/dts/am335x-wega.dtsi  | 230 +++
 arch/arm/mach-omap2/Kconfig|   1 +
 arch/arm/mach-omap2/am33xx/Kconfig |   7 +
 board/phytec/phycore_am335x_r2/Kconfig |  15 +
 board/phytec/phycore_am335x_r2/MAINTAINERS |   7 +
 board/phytec/phycore_am335x_r2/Makefile|  11 +
 board/phytec/phycore_am335x_r2/board.c | 259 +
 board/phytec/phycore_am335x_r2/board.h |  24 ++
 board/phytec/phycore_am335x_r2/mux.c   | 117 
 configs/phycore-am335x-r2-wega_defconfig   |  79 +
 include/configs/phycore_am335x_r2.h| 130 +
 15 files changed, 1254 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/am335x-phycore-som.dtsi
 create mode 100644 arch/arm/dts/am335x-wega-rdk-u-boot.dtsi
 create mode 100644 arch/arm/dts/am335x-wega-rdk.dts
 create mode 100644 arch/arm/dts/am335x-wega.dtsi
 create mode 100644 board/phytec/phycore_am335x_r2/Kconfig
 create mode 100644 board/phytec/phycore_am335x_r2/MAINTAINERS
 create mode 100644 board/phytec/phycore_am335x_r2/Makefile
 create mode 100644 board/phytec/phycore_am335x_r2/board.c
 create mode 100644 board/phytec/phycore_am335x_r2/board.h
 create mode 100644 board/phytec/phycore_am335x_r2/mux.c
 create mode 100644 configs/phycore-am335x-r2-wega_defconfig
 create mode 100644 include/configs/phycore_am335x_r2.h

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 8e082f2840..381a64ae13 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -264,7 +264,8 @@ dtb-$(CONFIG_AM33XX) += \
am335x-chiliboard.dtb \
am335x-sl50.dtb \
am335x-base0033.dtb \
-   am335x-guardian.dtb
+   am335x-guardian.dtb \
+   am335x-wega-rdk.dtb
 dtb-$(CONFIG_AM43XX) += am437x-gp-evm.dtb am437x-sk-evm.dtb\
am43x-epos-evm.dtb \
am437x-idk-evm.dtb \
diff --git a/arch/arm/dts/am335x-phycore-som.dtsi 
b/arch/arm/dts/am335x-phycore-som.dtsi
new file mode 100644
index 00..8d7c19e5e1
--- /dev/null
+++ b/arch/arm/dts/am335x-phycore-som.dtsi
@@ -0,0 +1,322 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2015 Phytec Messtechnik GmbH
+ * Author: Teresa Remmet 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include "am33xx.dtsi"
+#include 
+
+/ {
+   model = "Phytec AM335x phyCORE";
+   compatible = "phytec,am335x-phycore-som", "ti,am33xx";
+
+   aliases {
+   rtc0 = _rtc;
+   rtc1 = 
+   };
+
+   cpus {
+   cpu@0 {
+   cpu0-supply = <_reg>;
+   };
+   };
+
+   memory@8000 {
+   device_type = "memory";
+   reg = <0x8000 0x1000>; /* 256 MB */
+   };
+
+   regulators {
+   compatible = "simple-bus";
+
+   vcc5v: fixedregulator0 {
+   compatible = "regulator-fixed";
+   regulator-name = "vcc5v";
+   regulator-min-microvolt = <5000

Re: [U-Boot] [PATCH v5] ARM: am335x: Add phyCORE AM335x R2 support

2019-05-07 Thread Niel Fourie

Hi Tom,

On 5/7/19 3:19 PM, Tom Rini wrote:

On Tue, May 07, 2019 at 11:39:12AM +0200, Niel Fourie wrote:

Hi Tom,

On 5/6/19 7:24 PM, Tom Rini wrote:

On Mon, May 06, 2019 at 06:44:48PM +0200, Niel Fourie wrote:

Hi Tom,

On 5/6/19 4:18 PM, Tom Rini wrote:

On Mon, May 06, 2019 at 04:02:53PM +0200, Niel Fourie wrote:


Support for Phytech phyCORE AM335x R2 SOM (PCL060) on the Phytec
phyBOARD-Wega AM335x.

CPU  : AM335X-GP rev 2.1
Model: Phytec AM335x phyBOARD-WEGA
DRAM:  256 MiB
NAND:  256 MiB
MMC:   OMAP SD/MMC: 0
eth0: ethernet@4a10

Working:
  - Eth0
  - i2C
  - MMC/SD
  - NAND
  - UART
  - USB (host)

Device trees were taken from Linux mainline:
commit 37624b58542f ("Linux 5.1-rc7")

Signed-off-by: Niel Fourie 

[snip]


void sdram_init(void)
{
/* Configure memory to maximum supported size for detection */
int ram_type_index = PHYCORE_R2_MT41K512M16HA125IT_1024MB;
config_ddr(DDR_CLK_MHZ, ,
   _timings[ram_type_index].ddr3_data,
   _cmd_ctrl_data,
   _timings[ram_type_index].ddr3_emif_reg_data,
   0);

/* Detect memory physically present */
gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
CONFIG_MAX_RAM_BANK_SIZE);

/* Reconfigure memory for actual detected size */
switch (gd->ram_size) {
case SZ_1G:
ram_type_index = PHYCORE_R2_MT41K512M16HA125IT_1024MB;
break;
case SZ_512M:
ram_type_index = PHYCORE_R2_MT41K256M16TW107IT_512MB;
break;
case SZ_256M:
default:
ram_type_index = PHYCORE_R2_MT41K128M16JT_256MB;
break;
}
config_ddr(DDR_CLK_MHZ, ,
   _timings[ram_type_index].ddr3_data,
   _cmd_ctrl_data,
   _timings[ram_type_index].ddr3_emif_reg_data,
   0);
}

The ugliest part of this is, as you pointed out, that directly after this is
called, get_ram_size() will be called again from sdram_init(). But it at
least noninvasive, and no longer requires the device tree.


I don't think it's safe to call config_ddr twice, especially with the
possibly wrong parameters.  What's barebox doing in this case, being
told the presumably correct DDR size in the device tree?


Good point. Barebox uses the above mechanism to detect the memory size, and
I could find no equivalent memory size specified in its internal device
tree.


Configure for 1GB and then see how much we can actually talk to?


Yes. If you are interested, you can see their implementation here [1], 
where get_minimal_timings() returns the configuration for 1GiB; 
everything is in that file. (I did credit the author.)


[1] 
https://git.pengutronix.de/cgit/barebox/tree/arch/arm/boards/phytec-som-am335x/lowlevel.c#n167



Marek originally proposed using the memory size specified in the device tree
as an improvement over specifying the size in the defconfig (as in v1 of the
patch).


But then you aren't populating 3 device trees nor making it clear / easy
to say which module you're on, and then still need to change the config
for which DT you're picking up.  These SOMs really don't provide any
run-time method to see which one you're on?  There's no GPIOs to poke?


Agreed, the device tree solution is inferior to autodetection. The SOMs 
manual makes no mention of how different variants can be 
distinguished/detected, and the board specific code in Barebox (written 
by Phytec) does not contain any other detection code (except for the 
RAM), like checking GPIOs. Unfortunately there is no publicly available 
schematic, so I can't be completely sure. So I am going to assume it, 
there is no other way of detection.


Best regards,
Niel Fourie

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v5] ARM: am335x: Add phyCORE AM335x R2 support

2019-05-07 Thread Niel Fourie

Hi Tom,

On 5/6/19 7:24 PM, Tom Rini wrote:

On Mon, May 06, 2019 at 06:44:48PM +0200, Niel Fourie wrote:

Hi Tom,

On 5/6/19 4:18 PM, Tom Rini wrote:

On Mon, May 06, 2019 at 04:02:53PM +0200, Niel Fourie wrote:


Support for Phytech phyCORE AM335x R2 SOM (PCL060) on the Phytec
phyBOARD-Wega AM335x.

CPU  : AM335X-GP rev 2.1
Model: Phytec AM335x phyBOARD-WEGA
DRAM:  256 MiB
NAND:  256 MiB
MMC:   OMAP SD/MMC: 0
eth0: ethernet@4a10

Working:
  - Eth0
  - i2C
  - MMC/SD
  - NAND
  - UART
  - USB (host)

Device trees were taken from Linux mainline:
commit 37624b58542f ("Linux 5.1-rc7")

Signed-off-by: Niel Fourie 

[snip]


void sdram_init(void)
{
/* Configure memory to maximum supported size for detection */
int ram_type_index = PHYCORE_R2_MT41K512M16HA125IT_1024MB;
config_ddr(DDR_CLK_MHZ, ,
   _timings[ram_type_index].ddr3_data,
   _cmd_ctrl_data,
   _timings[ram_type_index].ddr3_emif_reg_data,
   0);

/* Detect memory physically present */
gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
CONFIG_MAX_RAM_BANK_SIZE);

/* Reconfigure memory for actual detected size */
switch (gd->ram_size) {
case SZ_1G:
ram_type_index = PHYCORE_R2_MT41K512M16HA125IT_1024MB;
break;
case SZ_512M:
ram_type_index = PHYCORE_R2_MT41K256M16TW107IT_512MB;
break;
case SZ_256M:
default:
ram_type_index = PHYCORE_R2_MT41K128M16JT_256MB;
break;
}
config_ddr(DDR_CLK_MHZ, ,
   _timings[ram_type_index].ddr3_data,
   _cmd_ctrl_data,
   _timings[ram_type_index].ddr3_emif_reg_data,
   0);
}

The ugliest part of this is, as you pointed out, that directly after this is
called, get_ram_size() will be called again from sdram_init(). But it at
least noninvasive, and no longer requires the device tree.


I don't think it's safe to call config_ddr twice, especially with the
possibly wrong parameters.  What's barebox doing in this case, being
told the presumably correct DDR size in the device tree?


Good point. Barebox uses the above mechanism to detect the memory size, 
and I could find no equivalent memory size specified in its internal 
device tree.


Marek originally proposed using the memory size specified in the device 
tree as an improvement over specifying the size in the defconfig (as in 
v1 of the patch).


Best regards,
Niel Fourie

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v5] ARM: am335x: Add phyCORE AM335x R2 support

2019-05-06 Thread Niel Fourie

Hi Tom,

On 5/6/19 4:18 PM, Tom Rini wrote:

On Mon, May 06, 2019 at 04:02:53PM +0200, Niel Fourie wrote:


Support for Phytech phyCORE AM335x R2 SOM (PCL060) on the Phytec
phyBOARD-Wega AM335x.

CPU  : AM335X-GP rev 2.1
Model: Phytec AM335x phyBOARD-WEGA
DRAM:  256 MiB
NAND:  256 MiB
MMC:   OMAP SD/MMC: 0
eth0: ethernet@4a10

Working:
  - Eth0
  - i2C
  - MMC/SD
  - NAND
  - UART
  - USB (host)

Device trees were taken from Linux mainline:
commit 37624b58542f ("Linux 5.1-rc7")

Signed-off-by: Niel Fourie 
+void sdram_init(void)
+{
+   int ram_type_index = PHYCORE_R2_MT41K128M16JT_256MB;
+
+   if (fdtdec_setup_mem_size_base())
+   gd->ram_size = SZ_256M;
+
+   switch (gd->ram_size) {
+   case SZ_1G:
+   ram_type_index = PHYCORE_R2_MT41K512M16HA125IT_1024MB;
+   break;
+   case SZ_512M:
+   ram_type_index = PHYCORE_R2_MT41K256M16TW107IT_512MB;
+   break;
+   case SZ_256M:
+   default:
+   ram_type_index = PHYCORE_R2_MT41K128M16JT_256MB;
+   break;
+   }
+
+   config_ddr(DDR_CLK_MHZ, ,
+  _timings[ram_type_index].ddr3_data,
+  _cmd_ctrl_data,
+  _timings[ram_type_index].ddr3_emif_reg_data, 0);
+}


This is wrong.  sdram_init() is called by
arch/arm/mach-omap2/am33xx/board.c::dram_init() which then sets
gd->ram_size based on what get_ram_size() determines.  So this is all
just a wrapper around how the various parts of the am33xx generations
call some form of config_ddr().  And what you have here is a lot of
unused code about which module provides how much memory.  I assume
there's some run-time method to determine which module you're on and
thus determine that correct parameters to pass in for the chip that's in
use.  If you're not there yet then just make sdram_init() call
config_ddr(...) with the correct enum for the 256M chip and then update
this when you have real detection.


Thanks for that input, you are right. I could not find any documented 
way to detect the exact module we are running on, but as you pointed out 
we can use get_ram_size() to find the size of the installed RAM. This is 
in fact exactly what barebox did, I just missed it. How is this for a 
replacement of the above?


void sdram_init(void)
{
/* Configure memory to maximum supported size for detection */
int ram_type_index = PHYCORE_R2_MT41K512M16HA125IT_1024MB;
config_ddr(DDR_CLK_MHZ, ,
   _timings[ram_type_index].ddr3_data,
   _cmd_ctrl_data,
   _timings[ram_type_index].ddr3_emif_reg_data,
   0);

/* Detect memory physically present */
gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
CONFIG_MAX_RAM_BANK_SIZE);

/* Reconfigure memory for actual detected size */
switch (gd->ram_size) {
case SZ_1G:
ram_type_index = PHYCORE_R2_MT41K512M16HA125IT_1024MB;
break;
case SZ_512M:
ram_type_index = PHYCORE_R2_MT41K256M16TW107IT_512MB;
break;
case SZ_256M:
default:
ram_type_index = PHYCORE_R2_MT41K128M16JT_256MB;
break;
}
config_ddr(DDR_CLK_MHZ, ,
   _timings[ram_type_index].ddr3_data,
   _cmd_ctrl_data,
   _timings[ram_type_index].ddr3_emif_reg_data,
   0);
}

The ugliest part of this is, as you pointed out, that directly after 
this is called, get_ram_size() will be called again from sdram_init(). 
But it at least noninvasive, and no longer requires the device tree.


Best regards,
Niel Fourie

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v5] ARM: am335x: Add phyCORE AM335x R2 support

2019-05-06 Thread Niel Fourie
Support for Phytech phyCORE AM335x R2 SOM (PCL060) on the Phytec
phyBOARD-Wega AM335x.

CPU  : AM335X-GP rev 2.1
Model: Phytec AM335x phyBOARD-WEGA
DRAM:  256 MiB
NAND:  256 MiB
MMC:   OMAP SD/MMC: 0
eth0: ethernet@4a10

Working:
 - Eth0
 - i2C
 - MMC/SD
 - NAND
 - UART
 - USB (host)

Device trees were taken from Linux mainline:
commit 37624b58542f ("Linux 5.1-rc7")

Signed-off-by: Niel Fourie 

---
Changes for v2:
- Remove formatting changes to upstream Linux dtsi files
- Remove incorrectly added MACH_TYPE
- Rename board from phycore_pcl060 to phycore_am335x_r2
- Implement selecting memory size from device tree
- Remove non-DM Ethernet board code
- General clean-up

Changes for v3:
- Added kernel revision of upstream Linux dtsi files
- Place TARGET_PHYCORE_AM335X_R2 alphabetically in Kconfig
- Rework TPS65910 I2C init code
- Remove non-DM USB board macros
- Minor tweaks

Changes for v4:
- Propose abstracting common sections to am33xx-u-boot.dtsi
- Remove dead Falcon mode code
- Remove non-DM I2C support for TPS65910 I2C

Changes for v5:
- Revert proposed moving of sections to am33xx-u-boot.dtsi
- Remove redundant/incorrect lines from am33xx-u-boot.dtsi
- Add missing changelog

 arch/arm/dts/Makefile  |   3 +-
 arch/arm/dts/am335x-phycore-som.dtsi   | 322 +
 arch/arm/dts/am335x-wega-rdk-u-boot.dtsi   |  31 ++
 arch/arm/dts/am335x-wega-rdk.dts   |  23 ++
 arch/arm/dts/am335x-wega.dtsi  | 230 +++
 arch/arm/mach-omap2/Kconfig|   1 +
 arch/arm/mach-omap2/am33xx/Kconfig |   7 +
 board/phytec/phycore_am335x_r2/Kconfig |  15 +
 board/phytec/phycore_am335x_r2/MAINTAINERS |   7 +
 board/phytec/phycore_am335x_r2/Makefile|  11 +
 board/phytec/phycore_am335x_r2/board.c | 252 
 board/phytec/phycore_am335x_r2/board.h |  24 ++
 board/phytec/phycore_am335x_r2/mux.c   | 117 
 configs/phycore-am335x-r2-wega_defconfig   |  79 +
 include/configs/phycore_am335x_r2.h| 130 +
 15 files changed, 1251 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/am335x-phycore-som.dtsi
 create mode 100644 arch/arm/dts/am335x-wega-rdk-u-boot.dtsi
 create mode 100644 arch/arm/dts/am335x-wega-rdk.dts
 create mode 100644 arch/arm/dts/am335x-wega.dtsi
 create mode 100644 board/phytec/phycore_am335x_r2/Kconfig
 create mode 100644 board/phytec/phycore_am335x_r2/MAINTAINERS
 create mode 100644 board/phytec/phycore_am335x_r2/Makefile
 create mode 100644 board/phytec/phycore_am335x_r2/board.c
 create mode 100644 board/phytec/phycore_am335x_r2/board.h
 create mode 100644 board/phytec/phycore_am335x_r2/mux.c
 create mode 100644 configs/phycore-am335x-r2-wega_defconfig
 create mode 100644 include/configs/phycore_am335x_r2.h

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 8e082f2840..381a64ae13 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -264,7 +264,8 @@ dtb-$(CONFIG_AM33XX) += \
am335x-chiliboard.dtb \
am335x-sl50.dtb \
am335x-base0033.dtb \
-   am335x-guardian.dtb
+   am335x-guardian.dtb \
+   am335x-wega-rdk.dtb
 dtb-$(CONFIG_AM43XX) += am437x-gp-evm.dtb am437x-sk-evm.dtb\
am43x-epos-evm.dtb \
am437x-idk-evm.dtb \
diff --git a/arch/arm/dts/am335x-phycore-som.dtsi 
b/arch/arm/dts/am335x-phycore-som.dtsi
new file mode 100644
index 00..8d7c19e5e1
--- /dev/null
+++ b/arch/arm/dts/am335x-phycore-som.dtsi
@@ -0,0 +1,322 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2015 Phytec Messtechnik GmbH
+ * Author: Teresa Remmet 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include "am33xx.dtsi"
+#include 
+
+/ {
+   model = "Phytec AM335x phyCORE";
+   compatible = "phytec,am335x-phycore-som", "ti,am33xx";
+
+   aliases {
+   rtc0 = _rtc;
+   rtc1 = 
+   };
+
+   cpus {
+   cpu@0 {
+   cpu0-supply = <_reg>;
+   };
+   };
+
+   memory@8000 {
+   device_type = "memory";
+   reg = <0x8000 0x1000>; /* 256 MB */
+   };
+
+   regulators {
+   compatible = "simple-bus";
+
+   vcc5v: fixedregulator0 {
+   compatible = "regulator-fixed";
+   regulator-name = "vcc5v";
+   regulator-min-microvolt = <500>;
+   regulator-max-microvolt = <500>;
+   regulator-boot-on;
+   regulator-always-on;
+   };
+   };
+};
+
+/* Crypto Module */
+ {
+   status = "okay";
+};
+
+ {
+   stat

Re: [U-Boot] [PATCH v4] ARM: am335x: Add phyCORE AM335x R2 support

2019-05-06 Thread Niel Fourie

Hi Tom,

On 5/3/19 4:07 PM, Tom Rini wrote:

On Fri, May 03, 2019 at 01:28:02PM +0200, Niel Fourie wrote:
[snip]

diff --git a/arch/arm/dts/am33xx-u-boot.dtsi b/arch/arm/dts/am33xx-u-boot.dtsi
index 78f5e2c4d3..a58734e441 100644
--- a/arch/arm/dts/am33xx-u-boot.dtsi
+++ b/arch/arm/dts/am33xx-u-boot.dtsi


Sorry, I had not fully understood the implications of moving these 
changes to am33xx-u-boot.dtsi, so will move them back to 
am335x-wega-rdk-u-boot.dtsi where they belong. As Marek also pointed 
out, they belong in a seperate patch from this one anyways.



@@ -6,6 +6,17 @@
  
  / {

ocp {
+   u-boot,dm-spl;
u-boot,dm-pre-reloc;


First off, this is wrong.  In the code (see drivers/core/ofnode.c and
drivers/core/util.c) everywhere we check for u-boot,dm-spl we've already
checked for u-boot,dm-pre-reloc and returned true.  So all of these kind
of changes above need to be fixed.



Thanks, now I understand the mechanism. Will fix!


};
+
+   memory@8000 {
+   u-boot,dm-spl;
+   u-boot,dm-pre-reloc;
+   };
+};
+
+ {
+   u-boot,dm-spl;
+   u-boot,dm-pre-reloc;
  };


Second, where are you seeing that we need these nodes to be moved to be
available earlier?  Thanks!


In my case, I needed "ocp" because it is the parent of mmc1, and I used 
DM wherever I could, including for MMC in the SPL. I needed "memory" 
because the RAM size is specified in the device tree for RAM 
initialisation. After double checking, it appears that scm is in fact 
redundant (I included it for DDR3 and pin muxing). But, as this is 
likely not the case for everyone, I will move them back to 
am335x-wega-rdk-u-boot.dtsi as mentioned before.


Thanks for your feedback.

Best regards,
Niel Fourie

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v4] ARM: am335x: Add phyCORE AM335x R2 support

2019-05-03 Thread Niel Fourie
Support for Phytech phyCORE AM335x R2 SOM (PCL060) on the Phytec
phyBOARD-Wega AM335x.

CPU  : AM335X-GP rev 2.1
Model: Phytec AM335x phyBOARD-WEGA
DRAM:  256 MiB
NAND:  256 MiB
MMC:   OMAP SD/MMC: 0
eth0: ethernet@4a10

Working:
 - Eth0
 - i2C
 - MMC/SD
 - NAND
 - UART
 - USB (host)

Device trees were taken from Linux mainline:
commit 37624b58542fb9f2 ("Linux 5.1-rc7")

Signed-off-by: Niel Fourie 
---
 arch/arm/dts/Makefile  |   3 +-
 arch/arm/dts/am335x-phycore-som.dtsi   | 322 +
 arch/arm/dts/am335x-wega-rdk-u-boot.dtsi   |  27 ++
 arch/arm/dts/am335x-wega-rdk.dts   |  23 ++
 arch/arm/dts/am335x-wega.dtsi  | 230 +++
 arch/arm/dts/am33xx-u-boot.dtsi|  11 +
 arch/arm/mach-omap2/Kconfig|   1 +
 arch/arm/mach-omap2/am33xx/Kconfig |   7 +
 board/phytec/phycore_am335x_r2/Kconfig |  15 +
 board/phytec/phycore_am335x_r2/MAINTAINERS |   7 +
 board/phytec/phycore_am335x_r2/Makefile|  11 +
 board/phytec/phycore_am335x_r2/board.c | 252 
 board/phytec/phycore_am335x_r2/board.h |  24 ++
 board/phytec/phycore_am335x_r2/mux.c   | 117 
 configs/phycore-am335x-r2-wega_defconfig   |  78 +
 include/configs/phycore_am335x_r2.h| 130 +
 16 files changed, 1257 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/am335x-phycore-som.dtsi
 create mode 100644 arch/arm/dts/am335x-wega-rdk-u-boot.dtsi
 create mode 100644 arch/arm/dts/am335x-wega-rdk.dts
 create mode 100644 arch/arm/dts/am335x-wega.dtsi
 create mode 100644 board/phytec/phycore_am335x_r2/Kconfig
 create mode 100644 board/phytec/phycore_am335x_r2/MAINTAINERS
 create mode 100644 board/phytec/phycore_am335x_r2/Makefile
 create mode 100644 board/phytec/phycore_am335x_r2/board.c
 create mode 100644 board/phytec/phycore_am335x_r2/board.h
 create mode 100644 board/phytec/phycore_am335x_r2/mux.c
 create mode 100644 configs/phycore-am335x-r2-wega_defconfig
 create mode 100644 include/configs/phycore_am335x_r2.h

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index dfa5b02958..4736980468 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -262,7 +262,8 @@ dtb-$(CONFIG_AM33XX) += \
am335x-chiliboard.dtb \
am335x-sl50.dtb \
am335x-base0033.dtb \
-   am335x-guardian.dtb
+   am335x-guardian.dtb \
+   am335x-wega-rdk.dtb
 dtb-$(CONFIG_AM43XX) += am437x-gp-evm.dtb am437x-sk-evm.dtb\
am43x-epos-evm.dtb \
am437x-idk-evm.dtb \
diff --git a/arch/arm/dts/am335x-phycore-som.dtsi 
b/arch/arm/dts/am335x-phycore-som.dtsi
new file mode 100644
index 00..8d7c19e5e1
--- /dev/null
+++ b/arch/arm/dts/am335x-phycore-som.dtsi
@@ -0,0 +1,322 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2015 Phytec Messtechnik GmbH
+ * Author: Teresa Remmet 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include "am33xx.dtsi"
+#include 
+
+/ {
+   model = "Phytec AM335x phyCORE";
+   compatible = "phytec,am335x-phycore-som", "ti,am33xx";
+
+   aliases {
+   rtc0 = _rtc;
+   rtc1 = 
+   };
+
+   cpus {
+   cpu@0 {
+   cpu0-supply = <_reg>;
+   };
+   };
+
+   memory@8000 {
+   device_type = "memory";
+   reg = <0x8000 0x1000>; /* 256 MB */
+   };
+
+   regulators {
+   compatible = "simple-bus";
+
+   vcc5v: fixedregulator0 {
+   compatible = "regulator-fixed";
+   regulator-name = "vcc5v";
+   regulator-min-microvolt = <500>;
+   regulator-max-microvolt = <500>;
+   regulator-boot-on;
+   regulator-always-on;
+   };
+   };
+};
+
+/* Crypto Module */
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+/* Ethernet */
+_pinmux {
+   ethernet0_pins: pinmux_ethernet0 {
+   pinctrl-single,pins = <
+   AM33XX_IOPAD(0x90c, PIN_INPUT_PULLDOWN | MUX_MODE1) 
/* mii1_crs.rmii1_crs_dv */
+   AM33XX_IOPAD(0x910, PIN_INPUT_PULLDOWN | MUX_MODE1) 
/* mii1_rxerr.rmii1_rxerr */
+   AM33XX_IOPAD(0x914, PIN_OUTPUT | MUX_MODE1) 
/* mii1_txen.rmii1_txen */
+   AM33XX_IOPAD(0x924, PIN_OUTPUT | MUX_MODE1) 
/* mii1_txd1.rmii1_txd1 */
+   AM33XX_IOPAD(0x928, PIN_OUTPUT | MUX_MODE1) 
/* mii1_txd0.rmii1_txd0 */
+   AM33XX_IOPAD(0x93c, PIN_INPUT_PULLDOWN | MUX_MODE1)

[U-Boot] [PATCH v3] ARM: am335x: Add phyCORE AM335x R2 support

2019-05-02 Thread Niel Fourie
Support for Phytech phyCORE AM335x R2 SOM (PCL060) on the Phytec
phyBOARD-Wega AM335x.

CPU  : AM335X-GP rev 2.1
Model: Phytec AM335x phyBOARD-WEGA
DRAM:  256 MiB
NAND:  256 MiB
MMC:   OMAP SD/MMC: 0
eth0: ethernet@4a10

Working:
 - Eth0
 - i2C
 - MMC/SD
 - NAND
 - UART
 - USB (host)

Device trees were taken from Linux mainline revision
37624b58542fb9f2d9a70e6ea006ef8a5f66c30b

Signed-off-by: Niel Fourie 
---
 arch/arm/dts/Makefile  |   3 +-
 arch/arm/dts/am335x-phycore-som.dtsi   | 322 +
 arch/arm/dts/am335x-wega-rdk-u-boot.dtsi   |  40 +++
 arch/arm/dts/am335x-wega-rdk.dts   |  23 ++
 arch/arm/dts/am335x-wega.dtsi  | 230 +++
 arch/arm/mach-omap2/Kconfig|   1 +
 arch/arm/mach-omap2/am33xx/Kconfig |   7 +
 board/phytec/phycore_am335x_r2/Kconfig |  15 +
 board/phytec/phycore_am335x_r2/MAINTAINERS |   7 +
 board/phytec/phycore_am335x_r2/Makefile|  11 +
 board/phytec/phycore_am335x_r2/board.c | 263 +
 board/phytec/phycore_am335x_r2/board.h |  24 ++
 board/phytec/phycore_am335x_r2/mux.c   | 117 
 configs/phycore-am335x-r2-wega_defconfig   |  79 +
 include/configs/phycore_am335x_r2.h| 130 +
 15 files changed, 1271 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/am335x-phycore-som.dtsi
 create mode 100644 arch/arm/dts/am335x-wega-rdk-u-boot.dtsi
 create mode 100644 arch/arm/dts/am335x-wega-rdk.dts
 create mode 100644 arch/arm/dts/am335x-wega.dtsi
 create mode 100644 board/phytec/phycore_am335x_r2/Kconfig
 create mode 100644 board/phytec/phycore_am335x_r2/MAINTAINERS
 create mode 100644 board/phytec/phycore_am335x_r2/Makefile
 create mode 100644 board/phytec/phycore_am335x_r2/board.c
 create mode 100644 board/phytec/phycore_am335x_r2/board.h
 create mode 100644 board/phytec/phycore_am335x_r2/mux.c
 create mode 100644 configs/phycore-am335x-r2-wega_defconfig
 create mode 100644 include/configs/phycore_am335x_r2.h

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index b4dc57edbd..611be64314 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -262,7 +262,8 @@ dtb-$(CONFIG_AM33XX) += \
am335x-chiliboard.dtb \
am335x-sl50.dtb \
am335x-base0033.dtb \
-   am335x-guardian.dtb
+   am335x-guardian.dtb \
+   am335x-wega-rdk.dtb
 dtb-$(CONFIG_AM43XX) += am437x-gp-evm.dtb am437x-sk-evm.dtb\
am43x-epos-evm.dtb \
am437x-idk-evm.dtb \
diff --git a/arch/arm/dts/am335x-phycore-som.dtsi 
b/arch/arm/dts/am335x-phycore-som.dtsi
new file mode 100644
index 00..8d7c19e5e1
--- /dev/null
+++ b/arch/arm/dts/am335x-phycore-som.dtsi
@@ -0,0 +1,322 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2015 Phytec Messtechnik GmbH
+ * Author: Teresa Remmet 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include "am33xx.dtsi"
+#include 
+
+/ {
+   model = "Phytec AM335x phyCORE";
+   compatible = "phytec,am335x-phycore-som", "ti,am33xx";
+
+   aliases {
+   rtc0 = _rtc;
+   rtc1 = 
+   };
+
+   cpus {
+   cpu@0 {
+   cpu0-supply = <_reg>;
+   };
+   };
+
+   memory@8000 {
+   device_type = "memory";
+   reg = <0x8000 0x1000>; /* 256 MB */
+   };
+
+   regulators {
+   compatible = "simple-bus";
+
+   vcc5v: fixedregulator0 {
+   compatible = "regulator-fixed";
+   regulator-name = "vcc5v";
+   regulator-min-microvolt = <500>;
+   regulator-max-microvolt = <500>;
+   regulator-boot-on;
+   regulator-always-on;
+   };
+   };
+};
+
+/* Crypto Module */
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+/* Ethernet */
+_pinmux {
+   ethernet0_pins: pinmux_ethernet0 {
+   pinctrl-single,pins = <
+   AM33XX_IOPAD(0x90c, PIN_INPUT_PULLDOWN | MUX_MODE1) 
/* mii1_crs.rmii1_crs_dv */
+   AM33XX_IOPAD(0x910, PIN_INPUT_PULLDOWN | MUX_MODE1) 
/* mii1_rxerr.rmii1_rxerr */
+   AM33XX_IOPAD(0x914, PIN_OUTPUT | MUX_MODE1) 
/* mii1_txen.rmii1_txen */
+   AM33XX_IOPAD(0x924, PIN_OUTPUT | MUX_MODE1) 
/* mii1_txd1.rmii1_txd1 */
+   AM33XX_IOPAD(0x928, PIN_OUTPUT | MUX_MODE1) 
/* mii1_txd0.rmii1_txd0 */
+   AM33XX_IOPAD(0x93c, PIN_INPUT_PULLDOWN | MUX_MODE1) 
/* mii1_rxd1.rmii1_rxd1 */
+  

Re: [U-Boot] [PATCH v2] ARM: am335x: Add phyCORE AM335x R2 support

2019-05-02 Thread Niel Fourie

Hi All,

Thank you Marek for the feedback. I addressed all of your concerns, the 
most important of is mentioned below:


On 4/25/19 12:52 PM, Marek Vasut wrote:

The Linux commit from which the DTs came is missing.


Added


Keep the list sorted alphabetically please. (PHY... is below PCM...)



Fixed. Sorry, that was as howler.


Just curious , was there ever AM335x_R1 ? Why do we use the _R2 suffix
here ?> 


The AM335x (without the R2) was the Phytec pcm051. So I stuck with 
adding R2 to distinguish the two. (I don't have a pcm051, so I did not 
want to mess with it.)



+#ifndef CONFIG_DM_I2C


CONFIG_IS_ENABLED(DM_I2C)



This one is causing some headaches. I can't find any references to 
CONFIG_SPL_DM_I2C, even though we actually use DM for I2C in the SPL, so 
that change causes things to break a bit. As an improvement, I changed 
the code to use #if defined(CONFIG_DM_I2C) instead of #ifndef. We could 
always simply drop the Non-DM support instead, I guess?


On 4/25/19 12:43 PM, Marek Vasut wrote:> Take a look at
> configs/am335x_evm_defconfig:CONFIG_DM_USB_GADGET=y
>
> Maybe we can at least get rid of some of the hard-coded USB non-DM
> stuff.

I simply removed the hard-coded USB stuff, as the DM_USB was already 
enabled and working anyways. DM_USB_GADGET was also enabled. Thanks for 
the recommendation.


Best regards,
Niel Fourie

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2] ARM: am335x: Add phyCORE AM335x R2 support

2019-04-25 Thread Niel Fourie
Support for Phytech phyCORE AM335x R2 SOM (PCL060) on the Phytec
phyBOARD-Wega AM335x.

CPU  : AM335X-GP rev 2.1
Model: Phytec AM335x phyBOARD-WEGA
DRAM:  256 MiB
NAND:  256 MiB
MMC:   OMAP SD/MMC: 0
eth0: ethernet@4a10

Working:
 - Eth0
 - i2C
 - MMC/SD
 - NAND
 - UART
 - USB (host)

Signed-off-by: Niel Fourie 
---
 arch/arm/dts/Makefile  |   3 +-
 arch/arm/dts/am335x-phycore-som.dtsi   | 322 +
 arch/arm/dts/am335x-wega-rdk-u-boot.dtsi   |  40 +++
 arch/arm/dts/am335x-wega-rdk.dts   |  23 ++
 arch/arm/dts/am335x-wega.dtsi  | 230 +++
 arch/arm/mach-omap2/Kconfig|   1 +
 arch/arm/mach-omap2/am33xx/Kconfig |   7 +
 board/phytec/phycore_am335x_r2/Kconfig |  15 +
 board/phytec/phycore_am335x_r2/MAINTAINERS |   7 +
 board/phytec/phycore_am335x_r2/Makefile|  11 +
 board/phytec/phycore_am335x_r2/board.c | 262 +
 board/phytec/phycore_am335x_r2/board.h |  24 ++
 board/phytec/phycore_am335x_r2/mux.c   | 117 
 configs/phycore-am335x-r2-wega_defconfig   |  79 +
 include/configs/phycore_am335x_r2.h| 138 +
 15 files changed, 1278 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/am335x-phycore-som.dtsi
 create mode 100644 arch/arm/dts/am335x-wega-rdk-u-boot.dtsi
 create mode 100644 arch/arm/dts/am335x-wega-rdk.dts
 create mode 100644 arch/arm/dts/am335x-wega.dtsi
 create mode 100644 board/phytec/phycore_am335x_r2/Kconfig
 create mode 100644 board/phytec/phycore_am335x_r2/MAINTAINERS
 create mode 100644 board/phytec/phycore_am335x_r2/Makefile
 create mode 100644 board/phytec/phycore_am335x_r2/board.c
 create mode 100644 board/phytec/phycore_am335x_r2/board.h
 create mode 100644 board/phytec/phycore_am335x_r2/mux.c
 create mode 100644 configs/phycore-am335x-r2-wega_defconfig
 create mode 100644 include/configs/phycore_am335x_r2.h

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 5fe998914a..0a876997ed 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -253,7 +253,8 @@ dtb-$(CONFIG_AM33XX) += \
am335x-chiliboard.dtb \
am335x-sl50.dtb \
am335x-base0033.dtb \
-   am335x-guardian.dtb
+   am335x-guardian.dtb \
+   am335x-wega-rdk.dtb
 dtb-$(CONFIG_AM43XX) += am437x-gp-evm.dtb am437x-sk-evm.dtb\
am43x-epos-evm.dtb \
am437x-idk-evm.dtb \
diff --git a/arch/arm/dts/am335x-phycore-som.dtsi 
b/arch/arm/dts/am335x-phycore-som.dtsi
new file mode 100644
index 00..8d7c19e5e1
--- /dev/null
+++ b/arch/arm/dts/am335x-phycore-som.dtsi
@@ -0,0 +1,322 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2015 Phytec Messtechnik GmbH
+ * Author: Teresa Remmet 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include "am33xx.dtsi"
+#include 
+
+/ {
+   model = "Phytec AM335x phyCORE";
+   compatible = "phytec,am335x-phycore-som", "ti,am33xx";
+
+   aliases {
+   rtc0 = _rtc;
+   rtc1 = 
+   };
+
+   cpus {
+   cpu@0 {
+   cpu0-supply = <_reg>;
+   };
+   };
+
+   memory@8000 {
+   device_type = "memory";
+   reg = <0x8000 0x1000>; /* 256 MB */
+   };
+
+   regulators {
+   compatible = "simple-bus";
+
+   vcc5v: fixedregulator0 {
+   compatible = "regulator-fixed";
+   regulator-name = "vcc5v";
+   regulator-min-microvolt = <500>;
+   regulator-max-microvolt = <500>;
+   regulator-boot-on;
+   regulator-always-on;
+   };
+   };
+};
+
+/* Crypto Module */
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+/* Ethernet */
+_pinmux {
+   ethernet0_pins: pinmux_ethernet0 {
+   pinctrl-single,pins = <
+   AM33XX_IOPAD(0x90c, PIN_INPUT_PULLDOWN | MUX_MODE1) 
/* mii1_crs.rmii1_crs_dv */
+   AM33XX_IOPAD(0x910, PIN_INPUT_PULLDOWN | MUX_MODE1) 
/* mii1_rxerr.rmii1_rxerr */
+   AM33XX_IOPAD(0x914, PIN_OUTPUT | MUX_MODE1) 
/* mii1_txen.rmii1_txen */
+   AM33XX_IOPAD(0x924, PIN_OUTPUT | MUX_MODE1) 
/* mii1_txd1.rmii1_txd1 */
+   AM33XX_IOPAD(0x928, PIN_OUTPUT | MUX_MODE1) 
/* mii1_txd0.rmii1_txd0 */
+   AM33XX_IOPAD(0x93c, PIN_INPUT_PULLDOWN | MUX_MODE1) 
/* mii1_rxd1.rmii1_rxd1 */
+   AM33XX_IOPAD(0x940, PIN_INPUT_PULLDOWN | MUX_MODE1) 
/* mii1_r

Re: [U-Boot] [PATCH] phycore-pcl060: U-boot support for Phytec phyCORE PCL060

2019-04-25 Thread Niel Fourie

Hi All,

On 4/19/19 11:47 AM, Marek Vasut wrote:

---
  arch/arm/dts/Makefile|   3 +-
  arch/arm/dts/am335x-phycore-som.dtsi | 327 ++
  arch/arm/dts/am335x-wega-rdk-u-boot.dtsi |  35 +++
  arch/arm/dts/am335x-wega-rdk.dts |  23 ++
  arch/arm/dts/am335x-wega.dtsi| 231 +++


The DTs come from Linux kernel, but which version of Linux ?
Which exact commit ? Did you modify them in any way ?


I pulled these in from current Linux Mainline. I added SPDX headers and 
reformatted some lines to for line length (but I have reverted the line 
lengths in my follow-up patch).



[...]


Here [1] it says the name of the SoM is PCM-060 , what is PCL-060 ?

[1]
https://www.phytec.eu/product-eu/system-on-modules/phycore-am335x-download/
  [...]



I renamed everything to variants of phycore_am335x_r2 as previously 
discussed.



DRAM size should come from DT, we don't need another custom config
option. Look at fdtdec_setup_mem_size_base() and
fdtdec_setup_memory_banksize().



Done, thank you for the suggestion. I also took inspiration for the data 
structure as suggested by Wadim Egorov.





diff --git a/include/configs/phycore_pcl060.h b/include/configs/phycore_pcl060.h
new file mode 100644
index 00..982c96b267
--- /dev/null
+++ b/include/configs/phycore_pcl060.h
@@ -0,0 +1,141 @@


[...]


+/*
+ * USB configuration
+ */
+#define CONFIG_AM335X_USB0
+#define CONFIG_AM335X_USB0_MODEMUSB_PERIPHERAL
+#define CONFIG_AM335X_USB1
+#define CONFIG_AM335X_USB1_MODE MUSB_HOST


Can't the USB settings be extracted from DT ?


Unfortunately, these defines are referenced within 
arch/arm/mach-omap2/am335x/board.c, which I would rather not want to 
break at this time.


Other than that, I implemented all points, along with some further 
refinement/clean-up.


Best regards,
Niel Fourie

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-21 Fax: +49-8142-66989-80  Email: lu...@denx.de
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] phycore-pcl060: U-boot support for Phytec phyCORE PCL060

2019-04-18 Thread Niel Fourie
Support for Phytech phyCORE AM335x R2 SOM (PCL060) on the Phytec
phyBOARD-Wega AM335x.

CPU  : AM335X-GP rev 2.1
Model: Phytec AM335x phyBOARD-WEGA
DRAM:  256 MiB
NAND:  256 MiB
MMC:   OMAP SD/MMC: 0
eth0: ethernet@4a10

Working:
 - Eth0
 - i2C
 - MMC/SD
 - NAND
 - UART
 - USB (host)

Signed-off-by: Niel Fourie 
---
 arch/arm/dts/Makefile|   3 +-
 arch/arm/dts/am335x-phycore-som.dtsi | 327 ++
 arch/arm/dts/am335x-wega-rdk-u-boot.dtsi |  35 +++
 arch/arm/dts/am335x-wega-rdk.dts |  23 ++
 arch/arm/dts/am335x-wega.dtsi| 231 +++
 arch/arm/include/asm/mach-types.h|   1 +
 arch/arm/mach-omap2/Kconfig  |   1 +
 arch/arm/mach-omap2/am33xx/Kconfig   |   7 +
 board/phytec/phycore_pcl060/Kconfig  |  19 ++
 board/phytec/phycore_pcl060/MAINTAINERS  |   7 +
 board/phytec/phycore_pcl060/Makefile |  11 +
 board/phytec/phycore_pcl060/board.c  | 340 +++
 board/phytec/phycore_pcl060/board.h  |  24 ++
 board/phytec/phycore_pcl060/mux.c| 117 
 configs/phycore-pcl060-wega_defconfig|  80 ++
 include/configs/phycore_pcl060.h | 141 ++
 16 files changed, 1366 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/am335x-phycore-som.dtsi
 create mode 100644 arch/arm/dts/am335x-wega-rdk-u-boot.dtsi
 create mode 100644 arch/arm/dts/am335x-wega-rdk.dts
 create mode 100644 arch/arm/dts/am335x-wega.dtsi
 create mode 100644 board/phytec/phycore_pcl060/Kconfig
 create mode 100644 board/phytec/phycore_pcl060/MAINTAINERS
 create mode 100644 board/phytec/phycore_pcl060/Makefile
 create mode 100644 board/phytec/phycore_pcl060/board.c
 create mode 100644 board/phytec/phycore_pcl060/board.h
 create mode 100644 board/phytec/phycore_pcl060/mux.c
 create mode 100644 configs/phycore-pcl060-wega_defconfig
 create mode 100644 include/configs/phycore_pcl060.h

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 0aee8dfde0..a44a95d0a2 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -253,7 +253,8 @@ dtb-$(CONFIG_AM33XX) += \
am335x-chiliboard.dtb \
am335x-sl50.dtb \
am335x-base0033.dtb \
-   am335x-guardian.dtb
+   am335x-guardian.dtb \
+   am335x-wega-rdk.dtb
 dtb-$(CONFIG_AM43XX) += am437x-gp-evm.dtb am437x-sk-evm.dtb\
am43x-epos-evm.dtb \
am437x-idk-evm.dtb \
diff --git a/arch/arm/dts/am335x-phycore-som.dtsi 
b/arch/arm/dts/am335x-phycore-som.dtsi
new file mode 100644
index 00..a2478cc628
--- /dev/null
+++ b/arch/arm/dts/am335x-phycore-som.dtsi
@@ -0,0 +1,327 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2015 Phytec Messtechnik GmbH
+ * Author: Teresa Remmet 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include "am33xx.dtsi"
+#include 
+
+/ {
+   model = "Phytec AM335x phyCORE";
+   compatible = "phytec,am335x-phycore-som", "ti,am33xx";
+
+   aliases {
+   rtc0 = _rtc;
+   rtc1 = 
+   };
+
+   cpus {
+   cpu@0 {
+   cpu0-supply = <_reg>;
+   };
+   };
+
+   memory@8000 {
+   device_type = "memory";
+   reg = <0x8000 0x1000>; /* 256 MB */
+   };
+
+   regulators {
+   compatible = "simple-bus";
+
+   vcc5v: fixedregulator0 {
+   compatible = "regulator-fixed";
+   regulator-name = "vcc5v";
+   regulator-min-microvolt = <500>;
+   regulator-max-microvolt = <500>;
+   regulator-boot-on;
+   regulator-always-on;
+   };
+   };
+};
+
+/* Crypto Module */
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+/* Ethernet */
+_pinmux {
+   ethernet0_pins: pinmux_ethernet0 {
+   pinctrl-single,pins = <
+   AM33XX_IOPAD(0x90c, PIN_INPUT_PULLDOWN | MUX_MODE1) 
/* mii1_crs.rmii1_crs_dv */
+   AM33XX_IOPAD(0x910, PIN_INPUT_PULLDOWN | MUX_MODE1) 
/* mii1_rxerr.rmii1_rxerr */
+   AM33XX_IOPAD(0x914, PIN_OUTPUT | MUX_MODE1) 
/* mii1_txen.rmii1_txen */
+   AM33XX_IOPAD(0x924, PIN_OUTPUT | MUX_MODE1) 
/* mii1_txd1.rmii1_txd1 */
+   AM33XX_IOPAD(0x928, PIN_OUTPUT | MUX_MODE1) 
/* mii1_txd0.rmii1_txd0 */
+   AM33XX_IOPAD(0x93c, PIN_INPUT_PULLDOWN | MUX_MODE1) 
/* mii1_rxd1.rmii1_rxd1 */
+   AM33XX_IOPAD(0x940, PIN_INPUT_PULLDOWN | MUX_MODE1) 
/* mii1_r