Re: [PATCH u-boot-marvell 10/10] tools: kwboot: Update references with public links

2022-03-03 Thread Stefan Roese

On 3/2/22 11:49, Pali Rohár wrote:

Public documents about BootROM of some Marvell SoCs are available in the
public Web Archive. Put this information into source code.

Signed-off-by: Pali Rohár 


Reviewed-by: Stefan Roese 
Tested-by: Stefan Roese 

Thanks,
Stefan


---
  tools/kwboot.c | 31 ---
  1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/tools/kwboot.c b/tools/kwboot.c
index cd1879246a85..69d1be0f4823 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -7,9 +7,34 @@
   * (c) 2021 Pali Rohár 
   * (c) 2021 Marek Behún 
   *
- * References: marvell.com, "88F6180, 88F6190, 88F6192, and 88F6281
- *   Integrated Controller: Functional Specifications" December 2,
- *   2008. Chapter 24.2 "BootROM Firmware".
+ * References:
+ * - "88F6180, 88F6190, 88F6192, and 88F6281: Integrated Controller: Functional
+ *   Specifications" December 2, 2008. Chapter 24.2 "BootROM Firmware".
+ *   
https://web.archive.org/web/20130730091033/https://www.marvell.com/embedded-processors/kirkwood/assets/FS_88F6180_9x_6281_OpenSource.pdf
+ * - "88AP510: High-Performance SoC with Integrated CPU, 2D/3D Graphics
+ *   Processor, and High-Definition Video Decoder: Functional Specifications"
+ *   August 3, 2011. Chapter 5 "BootROM Firmware"
+ *   
https://web.archive.org/web/20120130172443/https://www.marvell.com/application-processors/armada-500/assets/Armada-510-Functional-Spec.pdf
+ * - "88F6710, 88F6707, and 88F6W11: ARMADA(R) 370 SoC: Functional 
Specifications"
+ *   May 26, 2014. Chapter 6 "BootROM Firmware".
+ *   
https://web.archive.org/web/20140617183701/https://www.marvell.com/embedded-processors/armada-300/assets/ARMADA370-FunctionalSpec-datasheet.pdf
+ * - "MV78230, MV78260, and MV78460: ARMADA(R) XP Family of Highly Integrated
+ *   Multi-Core ARMv7 Based SoC Processors: Functional Specifications"
+ *   May 29, 2014. Chapter 6 "BootROM Firmware".
+ *   
https://web.archive.org/web/20180829171131/https://www.marvell.com/embedded-processors/armada-xp/assets/ARMADA-XP-Functional-SpecDatasheet.pdf
+ * - "ARMADA(R) 375 Value-Performance Dual Core CPU System on Chip: Functional
+ *   Specifications" Doc. No. MV-S109377-00, Rev. A. September 18, 2013.
+ *   Chapter 7 "Boot Sequence"
+ *   CONFIDENTIAL, no public documentation available
+ * - "88F6810, 88F6811, 88F6821, 88F6W21, 88F6820, and 88F6828: ARMADA(R) 38x
+ *   Family High-Performance Single/Dual CPU System on Chip: Functional
+ *   Specifications" Doc. No. MV-S109094-00, Rev. C. August 2, 2015.
+ *   Chapter 7 "Boot Flow"
+ *   CONFIDENTIAL, no public documentation available
+ * - "88F6920, 88F6925 and 88F6928: ARMADA(R) 39x High-Performance Dual Core 
CPU
+ *   System on Chip Functional Specifications" Doc. No. MV-S109896-00, Rev. B.
+ *   December 22, 2015. Chapter 7 "Boot Flow"
+ *   CONFIDENTIAL, no public documentation available
   */
  
  #include "kwbimage.h"


Viele Grüße,
Stefan Roese

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


Re: [PATCH u-boot-marvell 09/10] tools: kwboot: Update doc about Avanta

2022-03-03 Thread Stefan Roese

On 3/2/22 11:49, Pali Rohár wrote:

Testes proved that current kwboot version supports also Avanta SoCs.
It looks like that Avanta SoCs are using same kwbimage format as Armada.

Signed-off-by: Pali Rohár 
Tested-by: Tony Dinh 


Reviewed-by: Stefan Roese 
Tested-by: Stefan Roese 

Thanks,
Stefan


---
  doc/kwboot.1   | 2 +-
  tools/kwboot.c | 6 +++---
  2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/doc/kwboot.1 b/doc/kwboot.1
index bda049bde56f..f555ff26a259 100644
--- a/doc/kwboot.1
+++ b/doc/kwboot.1
@@ -11,7 +11,7 @@ kwboot \- Boot Marvell Kirkwood (and others 32-bit) SoCs over 
a serial link.
  .SH "DESCRIPTION"
  
  The \fBkwboot\fP program boots boards based on Marvell's 32-bit

-platforms including Kirkwood, Dove, A370, AXP, A375, A38x
+platforms including Kirkwood, Dove, Avanta, A370, AXP, A375, A38x
  and A39x over their integrated UART. Boot image files will typically
  contain a second stage boot loader, such as U-Boot. The image file
  must conform to Marvell's BootROM firmware image format
diff --git a/tools/kwboot.c b/tools/kwboot.c
index 11aca00bf1e6..cd1879246a85 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -1,7 +1,7 @@
  /*
   * Boot a Marvell SoC, with Xmodem over UART0.
- *  supports Kirkwood, Dove, Armada 370, Armada XP, Armada 375, Armada 38x and
- *   Armada 39x
+ *  supports Kirkwood, Dove, Avanta, Armada 370, Armada XP, Armada 375,
+ *   Armada 38x and Armada 39x.
   *
   * (c) 2012 Daniel Stodden 
   * (c) 2021 Pali Rohár 
@@ -1990,7 +1990,7 @@ kwboot_usage(FILE *stream, char *progname)
progname);
fprintf(stream, "\n");
fprintf(stream,
-   "  -b : boot  with preamble (Kirkwood, Armada 
370/XP/375/38x/39x)\n");
+   "  -b : boot  with preamble (Kirkwood, Avanta, Armada 
370/XP/375/38x/39x)\n");
fprintf(stream,
"  -D : boot  without preamble (Dove)\n");
fprintf(stream, "  -b: enter xmodem boot mode\n");


Viele Grüße,
Stefan Roese

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


Re: [PATCH u-boot-marvell 08/10] tools: kwboot: Update manpage

2022-03-03 Thread Stefan Roese

On 3/2/22 11:49, Pali Rohár wrote:

Document -D, -b, -d, -q and -s options.

Add common examples how to use kwboot.

Add information about Armada 38x BootROM bug for debug console mode and how
to workaround it.

Signed-off-by: Pali Rohár 


Reviewed-by: Stefan Roese 
Tested-by: Stefan Roese 

Thanks,
Stefan


---
  doc/kwboot.1 | 103 +--
  1 file changed, 99 insertions(+), 4 deletions(-)

diff --git a/doc/kwboot.1 b/doc/kwboot.1
index acdea891d9f0..bda049bde56f 100644
--- a/doc/kwboot.1
+++ b/doc/kwboot.1
@@ -1,4 +1,4 @@
-.TH KWBOOT 1 "2021-08-25"
+.TH KWBOOT 1 "2022-03-02"
  
  .SH NAME

  kwboot \- Boot Marvell Kirkwood (and others 32-bit) SoCs over a serial link.
@@ -47,6 +47,48 @@ code in it's header which may also print some output via 
UART (for
  example U-Boot SPL does this). In such a case, this output is also
  written to stdout after the header is sent.
  
+.TP

+.B "\-b"
+Do only handshake on \fITTY\fP without uploading any file. File upload
+could be done later via option \fB\-D\fP or via any other Xmodem
+application, like \fBsx\fP(1).
+
+.TP
+.B "\-d"
+Do special handshake on \fITTY\fP for console debug mode.
+
+This will instruct BootROM to enter builtin simple console debug mode.
+Should be combined with option \fB\-t\fP.
+
+To get a BootROM help, type this command followed by ENTER key:
+
+.RS 1.2i
+.TP
+.B ?
+.RE
+.IP
+
+Armada 38x BootROM has a bug which cause that BootROM's standard output
+is turned off on UART when SPI-NOR contains valid boot image. Nevertheless
+BootROM's standard input and BootROM's terminal echo are active and working
+fine. To workaround this BootROM bug with standard output, it is possible
+to manually overwrite BootROM variables stored in SRAM which BootROM use
+for checking if standard output is enabled or not. To enable BootROM
+standard output on UART, type this command folled by ENTER key:
+
+.RS 1.2i
+.TP
+.B w 0x40034100 1
+.RE
+
+.TP
+.BI "\-D" " image"
+Upload file \fIimage\fP over \fITTY\fP without initial handshake.
+
+This method is used primary on Dove platforms, where BootROM does
+not support initial handshake for entering UART upload mode and
+strapping pins (exported via e.g. buttons) are used instead.
+
  .TP
  .BI "\-p"
  Obsolete. Does nothing.
@@ -55,13 +97,33 @@ In the past, when this option was used, the program patched 
the header
  in the image prior upload, to "UART boot" type. This is now done by
  default.
  
+.TP

+.B "\-q"
+Obsolete. Does nothing.
+
+It is unknown whether it did something in the past.
+
+.TP
+.BI "\-s" " response-timeout"
+Specify custom response timeout when doing handshake. Default value is 50 ms.
+It is the timeout between sending two consecutive handshake patterns, meaning
+how long to wait for response from BootROM. Affects only option \fB\-b\fP with
+image file and option \fB\-d\fP.
+
+Option \fB-a\fP specify response timeout suitable for Armada XP BootROM and
+currently it is 1000 ms.
+
+Some testing showed that specifying 24 ms as response timeout make handshake
+with Armada 385 BootROM more stable.
+
  .TP
  .BI "\-t"
  Run a terminal program, connecting standard input and output to
  .RB \fITTY\fP.
  
-If used in combination with \fB-b\fP, terminal mode is entered

-immediately following a successful image upload.
+If used in combination with \fB\-b\fP, \fB\-D\fP or \fB\-d\fP option,
+terminal mode is entered immediately following a successful image upload
+or successful handshake (if not doing image upload).
  
  If standard I/O streams connect to a console, this mode will terminate

  after receiving \fBctrl-\e\fP followed by \fBc\fP from console input.
@@ -85,9 +147,42 @@ Tested values for \fIbaudrate\fP for Armada 38x include: 
115200,
  230400, 460800, 50, 576000, 921600, 100, 1152000, 150,
  200, 250, 3125000, 400 and 520.
  
+.SH "EXAMPLES"

+
+Instruct BootROM to enter boot Xmodem boot mode, send \fIu-boot-spl.kwb\fP
+kwbimage file via Xmodem on \fI/dev/ttyUSB0\fP at 115200 Bd and run terminal
+program:
+.IP
+.B kwboot -b u-boot-spl.kwb -t /dev/ttyUSB0
+
+.PP
+Instruct BootROM to enter boot Xmodem boot mode, send header of
+\fIu-boot-spl.kwb\fP kwbimage file via Xmodem at 115200 Bd, then instruct
+BootROM to change baudrate to 520 Bd, send data part of the kwbimage
+file via Xmodem at high speed and finally run terminal program:
+.IP
+.B kwboot -b u-boot-spl.kwb -B 520 -t /dev/ttyUSB0
+
+.PP
+Only send \fIu-boot-spl.kwb\fP kwbimage file via Xmodem on \fI/dev/ttyUSB0\fP
+at 115200 Bd:
+.IP
+.B kwboot -D u-boot-spl.kwb /dev/ttyUSB0
+
+.PP
+Instruct BootROM to enter console debug mode and run terminal program on
+\fI/dev/ttyUSB0\fP at 115200 Bd:
+.IP
+.B kwboot -d -t /dev/ttyUSB0
+
+.PP
+Only run terminal program on \fI/dev/ttyUSB0\fP at 115200 Bd:
+.IP
+.B kwboot -t /dev/ttyUSB0
+
  .SH "SEE ALSO"
  .PP
-\fBmkimage\fP(1)
+\fBmkimage\fP(1), \fBsx\fP(1)
  
  .SH "AUTHORS"
  


Viele Grüße,
Stefan Roese

--
DENX 

Re: [PATCH u-boot-marvell 07/10] tools: kwboot: Update usage

2022-03-03 Thread Stefan Roese

On 3/2/22 11:49, Pali Rohár wrote:

Add all supported Armada SoCs and document -b and -d options in usage.

Signed-off-by: Pali Rohár 


Reviewed-by: Stefan Roese 
Tested-by: Stefan Roese 

Thanks,
Stefan


---
  tools/kwboot.c | 7 ---
  1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 26cfe6dea6a7..11aca00bf1e6 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -1986,14 +1986,15 @@ static void
  kwboot_usage(FILE *stream, char *progname)
  {
fprintf(stream,
-   "Usage: %s [OPTIONS] [-b  | -D  ] [-B  ] 
\n",
+   "Usage: %s [OPTIONS] [-b  | -D  | -b | -d ] [-B  ] 
[-t] \n",
progname);
fprintf(stream, "\n");
fprintf(stream,
-   "  -b : boot  with preamble (Kirkwood, Armada 
370/XP)\n");
+   "  -b : boot  with preamble (Kirkwood, Armada 
370/XP/375/38x/39x)\n");
fprintf(stream,
"  -D : boot  without preamble (Dove)\n");
-   fprintf(stream, "  -d: enter debug mode\n");
+   fprintf(stream, "  -b: enter xmodem boot mode\n");
+   fprintf(stream, "  -d: enter console debug mode\n");
fprintf(stream, "  -a: use timings for Armada XP\n");
fprintf(stream, "  -s : use specific response-timeout\n");
fprintf(stream,


Viele Grüße,
Stefan Roese

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


Re: [PATCH u-boot-marvell 06/10] tools: kwboot: Add support for backspace key in mini terminal

2022-03-03 Thread Stefan Roese

On 3/2/22 11:49, Pali Rohár wrote:

Marvell BootROM recognize only '\b' byte as backspace. Use terminfo
for retrieving current backspace sequence and replace any occurrence of
backspace sequence by the '\b' byte.

Reading terminfo database is possible via tigetstr() function from system
library libtinfo.so.*. So link kwboot with -ltinfo.

Normally terminfo functions are in  system header file. But this
header file conflicts with U-Boot "termios_linux.h" header file. So declare
terminfo functions manually.

Signed-off-by: Pali Rohár 


Reviewed-by: Stefan Roese 
Tested-by: Stefan Roese 

Thanks,
Stefan


---
  tools/Makefile |   2 +-
  tools/kwboot.c | 109 +++--
  2 files changed, 97 insertions(+), 14 deletions(-)

diff --git a/tools/Makefile b/tools/Makefile
index c4a06dd9ba36..dca773b909b4 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -200,7 +200,7 @@ hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl
  HOSTCFLAGS_mkexynosspl.o := -pedantic
  
  HOSTCFLAGS_kwboot.o += -pthread

-HOSTLDLIBS_kwboot += -pthread
+HOSTLDLIBS_kwboot += -pthread -ltinfo
  
  ifdtool-objs := $(LIBFDT_OBJS) ifdtool.o

  hostprogs-$(CONFIG_X86) += ifdtool
diff --git a/tools/kwboot.c b/tools/kwboot.c
index 3ab49e74bb67..26cfe6dea6a7 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -36,6 +36,13 @@
  #include 
  #endif
  
+/*

+ * These functions are in  header file, but this header file conflicts
+ * with "termios_linux.h" header file. So declare these functions manually.
+ */
+extern int setupterm(const char *, int, int *);
+extern char *tigetstr(const char *);
+
  /*
   * Marvell BootROM UART Sensing
   */
@@ -1376,37 +1383,84 @@ kwboot_xmodem(int tty, const void *_img, size_t size, 
int baudrate)
  }
  
  static int

-kwboot_term_pipe(int in, int out, const char *quit, int *s)
+kwboot_term_pipe(int in, int out, const char *quit, int *s, const char *kbs, 
int *k)
  {
char buf[128];
-   ssize_t nin;
+   ssize_t nin, noff;
  
  	nin = read(in, buf, sizeof(buf));

if (nin <= 0)
return -1;
  
-	if (quit) {

+   noff = 0;
+
+   if (quit || kbs) {
int i;
  
  		for (i = 0; i < nin; i++) {

-   if (buf[i] == quit[*s]) {
+   if ((quit || kbs) &&
+   (!quit || buf[i] != quit[*s]) &&
+   (!kbs || buf[i] != kbs[*k])) {
+   const char *prefix;
+   int plen;
+
+   if (quit && kbs) {
+   prefix = (*s >= *k) ? quit : kbs;
+   plen = (*s >= *k) ? *s : *k;
+   } else if (quit) {
+   prefix = quit;
+   plen = *s;
+   } else {
+   prefix = kbs;
+   plen = *k;
+   }
+
+   if (plen > i && kwboot_write(out, prefix, plen - 
i) < 0)
+   return -1;
+   }
+
+   if (quit && buf[i] == quit[*s]) {
(*s)++;
if (!quit[*s]) {
nin = (i > *s) ? (i - *s) : 0;
break;
}
-   } else {
-   if (*s > i && kwboot_write(out, quit, *s - i) < 
0)
-   return -1;
+   } else if (quit) {
*s = 0;
}
+
+   if (kbs && buf[i] == kbs[*k]) {
+   (*k)++;
+   if (!kbs[*k]) {
+   if (i > *k + noff &&
+   kwboot_write(out, buf + noff, i - *k - 
noff) < 0)
+   return -1;
+   /*
+* Replace backspace key by '\b' (0x08)
+* byte which is the only recognized
+* backspace byte by Marvell BootROM.
+*/
+   if (write(out, "\x08", 1) < 0)
+   return -1;
+   noff = i + 1;
+   *k = 0;
+   }
+   } else if (kbs) {
+   *k = 0;
+   }
}
  
-		if (i == nin)

-   nin -= (nin > *s) ? *s : nin;
+   if (i == nin) {
+   

Re: [PATCH u-boot-marvell 05/10] tools: kwboot: Fix sending and processing debug message pattern (-d option)

2022-03-03 Thread Stefan Roese

On 3/2/22 11:49, Pali Rohár wrote:

-d option is currently broken. In most cases BootROM does not detect this
message pattern. For sending debug message pattern it is needed to do same
steps as for boot message pattern.

Implement sending debug message pattern via same separate thread like it is
for boot message pattern.

Checking if BootROM entered into UART debug mode is different than
detecting UART boot mode. When in boot mode, BootROM sends xmodem NAK
bytes. When in debug mode, BootROM activates console echo and reply back
every written byte (extept \r\n which is interpreted as executing command
and \b which is interpreting as removing the last sent byte).

So in kwboot, check that BootROM send back at least 4 debug message
patterns as a echo reply for debug message patterns which kwboot is sending
in the loop.

Then there is another observation, if host writes too many bytes (as
command) then BootROM command line buffer may overflow after trying to
execute such long command. To workaround this overflow, it is enough to
remove bytes from the input line buffer by sending 3 \b bytes for every
sent character. So do it.

With this change, it is possbile to enter into the UART debug mode with
kwboot -d option.

Signed-off-by: Pali Rohár 


Reviewed-by: Stefan Roese 
Tested-by: Stefan Roese 

Thanks,
Stefan


---
  tools/kwboot.c | 139 +++--
  1 file changed, 123 insertions(+), 16 deletions(-)

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 9fd90b9bec71..3ab49e74bb67 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -881,30 +881,139 @@ kwboot_bootmsg(int tty)
  static int
  kwboot_debugmsg(int tty)
  {
-   int rc;
+   unsigned char buf[8192];
+   pthread_t write_thread;
+   int rc, err, i, pos;
+   size_t off;
  
-	kwboot_printv("Sending debug message. Please reboot the target...");

+   /* flush input and output queue */
+   tcflush(tty, TCIOFLUSH);
  
-	do {

-   char buf[16];
+   rc = kwboot_msg_start_thread(_thread, , kwboot_msg_debug);
+   if (rc) {
+   perror("Failed to start write thread");
+   return rc;
+   }
  
-		rc = tcflush(tty, TCIOFLUSH);

-   if (rc)
-   break;
+   kwboot_printv("Sending debug message. Please reboot the target...");
+   kwboot_spinner();
  
-		rc = kwboot_tty_send(tty, kwboot_msg_debug, sizeof(kwboot_msg_debug), 0);

-   if (rc)
+   err = 0;
+   off = 0;
+   while (1) {
+   /* Read immediately all bytes in queue without waiting */
+   rc = read(tty, buf + off, sizeof(buf) - off);
+   if ((rc < 0 && errno == EINTR) || rc == 0) {
+   continue;
+   } else if (rc < 0) {
+   err = errno;
break;
-
-   rc = kwboot_tty_recv(tty, buf, 16, msg_rsp_timeo);
+   }
+   off += rc - 1;
  
  		kwboot_spinner();
  
-	} while (rc);

+   /*
+* Check if we received at least 4 debug message patterns
+* (console echo from BootROM) in cyclic buffer
+*/
+
+   for (pos = 0; pos < sizeof(kwboot_msg_debug); pos++)
+   if (buf[off] == kwboot_msg_debug[(pos + off) % 
sizeof(kwboot_msg_debug)])
+   break;
+
+   for (i = off; i >= 0; i--)
+   if (buf[i] != kwboot_msg_debug[(pos + i) % 
sizeof(kwboot_msg_debug)])
+   break;
+
+   off -= i;
+
+   if (off >= 4 * sizeof(kwboot_msg_debug))
+   break;
+
+   /* If not move valid suffix from end of the buffer to the 
beginning of buffer */
+   memmove(buf, buf + i + 1, off);
+   }
  
  	kwboot_printv("\n");
  
-	return rc;

+   rc = kwboot_msg_stop_thread(write_thread);
+   if (rc) {
+   perror("Failed to stop write thread");
+   return rc;
+   }
+
+   if (err) {
+   errno = err;
+   perror("Failed to read response for debug message pattern");
+   return -1;
+   }
+
+   /* flush output queue with remaining debug message patterns */
+   rc = tcflush(tty, TCOFLUSH);
+   if (rc) {
+   perror("Failed to flush output queue");
+   return rc;
+   }
+
+   kwboot_printv("Clearing input buffer...\n");
+
+   /*
+* Wait until BootROM transmit all remaining echo characters.
+* Experimentally it was measured that for Armada 385 BootROM
+* it is required to wait at least 0.415s. So wait 0.5s.
+*/
+   usleep(500 * 1000);
+
+   /*
+* In off variable is stored number of characters received after the
+* successful detection of echo reply. So these characters are console
+* echo for other following debug message 

Re: [PATCH u-boot-marvell 04/10] tools: kwboot: Use separate thread for sending boot message pattern

2022-03-03 Thread Stefan Roese

On 3/2/22 11:49, Pali Rohár wrote:

After BootROM successfully detects boot message pattern on UART it waits
until host stop sending data on UART. For example Armada 385 BootROM
requires that host does not send anything on UART at least 24 ms. If host
is still sending something then BootROM waits (possibly infinitely).

BootROM successfully detects boot message pattern if it receives it in
small period of time after power on.

So to ensure that host put BootROM into UART boot mode, host must send
continuous stream of boot message pattern with a small gap (for A385 at
least 24 ms) after series of pattern. But this gap cannot be too often or
too long to ensure that it does not cover whole BootROM time window when it
is detecting for boot message pattern.

Therefore it is needed to do following steps in cycle without any delay:
1. send series of boot message pattern over UART
2. wait until kernel transmit all data
3. sleep small period of time

At the same time, host needs to monitor input queue, data received on the
UART and checking if it contains NAK byte by which BootROM informs that
xmodem transfer is ready.

But it is not possible to wait until kernel transmit all data on UART and
at the same time in the one process to also wait for input data. This is
limitation of POSIX tty API and also by linux kernel that it does not
provide asynchronous function for waiting until all data are transmitted.
There is only synchronous variant tcdrain().

So to correctly implement this handshake on systems with linux kernel, it
is needed to use tcdrain() in separate thread.

Implement sending of boot message pattern in one thread and reading of
reply in the main thread. Use pthread library for threads.

This change makes UART booting on Armada 385 more reliable. It is possible
to start kwboot and power on board after minute and kwboot correctly put
board into UART boot mode.

Old implementation without separate thread has an issue that it read just
one byte from UART input queue and then it send 128 message pattern to the
output queue. If some noise was on UART then kwboot was not able to read
BootROM response as its input queue was just overflowed and kwboot was
sending more data than receiving.

This change basically fixed above issue too.

Signed-off-by: Pali Rohár 


Reviewed-by: Stefan Roese 
Tested-by: Stefan Roese 

Thanks,
Stefan


---
  tools/Makefile |   3 ++
  tools/kwboot.c | 120 +
  2 files changed, 104 insertions(+), 19 deletions(-)

diff --git a/tools/Makefile b/tools/Makefile
index df941e0dca8d..c4a06dd9ba36 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -199,6 +199,9 @@ hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl
  hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl
  HOSTCFLAGS_mkexynosspl.o := -pedantic
  
+HOSTCFLAGS_kwboot.o += -pthread

+HOSTLDLIBS_kwboot += -pthread
+
  ifdtool-objs := $(LIBFDT_OBJS) ifdtool.o
  hostprogs-$(CONFIG_X86) += ifdtool
  
diff --git a/tools/kwboot.c b/tools/kwboot.c

index 4e2acb52458a..9fd90b9bec71 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -28,6 +28,7 @@
  #include 
  #include 
  #include 
+#include 
  
  #ifdef __linux__

  #include "termios_linux.h"
@@ -717,37 +718,120 @@ out:
return rc;
  }
  
+static void *

+kwboot_msg_write_handler(void *arg)
+{
+   int tty = *(int *)((void **)arg)[0];
+   const void *msg = ((void **)arg)[1];
+   int rsp_timeo = msg_rsp_timeo;
+   int i, dummy_oldtype;
+
+   /* allow to cancel this thread at any time */
+   pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, _oldtype);
+
+   while (1) {
+   /* write 128 samples of message pattern into the output queue 
without waiting */
+   for (i = 0; i < 128; i++) {
+   if (kwboot_tty_send(tty, msg, 8, 1) < 0) {
+   perror("\nFailed to send message pattern");
+   exit(1);
+   }
+   }
+   /* wait until output queue is transmitted and then make pause */
+   if (tcdrain(tty) < 0) {
+   perror("\nFailed to send message pattern");
+   exit(1);
+   }
+   /* BootROM requires pause on UART after it detects message 
pattern */
+   usleep(rsp_timeo * 1000);
+   }
+}
+
+static int
+kwboot_msg_start_thread(pthread_t *thread, int *tty, void *msg)
+{
+   void *arg[2];
+   int rc;
+
+   arg[0] = tty;
+   arg[1] = msg;
+   rc = pthread_create(thread, NULL, kwboot_msg_write_handler, arg);
+   if (rc) {
+   errno = rc;
+   return -1;
+   }
+
+   return 0;
+}
+
+static int
+kwboot_msg_stop_thread(pthread_t thread)
+{
+   int rc;
+
+   rc = pthread_cancel(thread);
+   if (rc) {
+   errno = rc;
+   return -1;
+   }
+
+   rc = pthread_join(thread, NULL);
+   if (rc) {
+   

Re: [PATCH u-boot-marvell 03/10] tools: kwboot: Cleanup bootmsg and debugmsg variables

2022-03-03 Thread Stefan Roese

On 3/2/22 11:49, Pali Rohár wrote:

Function kwboot_debugmsg() is always called with kwboot_msg_debug as msg
and function kwboot_bootmsg() with kwboot_msg_debug as msg. Function
kwboot_bootmsg() is never called with NULL msg.

Simplify, cleanup and remove dead code.

No functional change.

Signed-off-by: Pali Rohár 


Reviewed-by: Stefan Roese 
Tested-by: Stefan Roese 

Thanks,
Stefan


---
  tools/kwboot.c | 31 ++-
  1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 4dfb1038b4ff..4e2acb52458a 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -718,17 +718,14 @@ out:
  }
  
  static int

-kwboot_bootmsg(int tty, void *msg)
+kwboot_bootmsg(int tty)
  {
struct kwboot_block block;
int rc;
char c;
int count;
  
-	if (msg == NULL)

-   kwboot_printv("Please reboot the target into UART boot 
mode...");
-   else
-   kwboot_printv("Sending boot message. Please reboot the 
target...");
+   kwboot_printv("Sending boot message. Please reboot the target...");
  
  	do {

rc = tcflush(tty, TCIOFLUSH);
@@ -736,7 +733,7 @@ kwboot_bootmsg(int tty, void *msg)
break;
  
  		for (count = 0; count < 128; count++) {

-   rc = kwboot_tty_send(tty, msg, 8, 0);
+   rc = kwboot_tty_send(tty, kwboot_msg_boot, 
sizeof(kwboot_msg_boot), 0);
if (rc)
break;
}
@@ -798,7 +795,7 @@ kwboot_bootmsg(int tty, void *msg)
  }
  
  static int

-kwboot_debugmsg(int tty, void *msg)
+kwboot_debugmsg(int tty)
  {
int rc;
  
@@ -811,7 +808,7 @@ kwboot_debugmsg(int tty, void *msg)

if (rc)
break;
  
-		rc = kwboot_tty_send(tty, msg, 8, 0);

+   rc = kwboot_tty_send(tty, kwboot_msg_debug, 
sizeof(kwboot_msg_debug), 0);
if (rc)
break;
  
@@ -1737,8 +1734,8 @@ main(int argc, char **argv)

  {
const char *ttypath, *imgpath;
int rv, rc, tty, term;
-   void *bootmsg;
-   void *debugmsg;
+   int bootmsg;
+   int debugmsg;
void *img;
size_t size;
size_t after_img_rsv;
@@ -1748,8 +1745,8 @@ main(int argc, char **argv)
  
  	rv = 1;

tty = -1;
-   bootmsg = NULL;
-   debugmsg = NULL;
+   bootmsg = 0;
+   debugmsg = 0;
imgpath = NULL;
img = NULL;
term = 0;
@@ -1771,7 +1768,7 @@ main(int argc, char **argv)
case 'b':
if (imgpath || bootmsg || debugmsg)
goto usage;
-   bootmsg = kwboot_msg_boot;
+   bootmsg = 1;
if (prev_optind == optind)
goto usage;
if (optind < argc - 1 && argv[optind] && 
argv[optind][0] != '-')
@@ -1781,14 +1778,14 @@ main(int argc, char **argv)
case 'D':
if (imgpath || bootmsg || debugmsg)
goto usage;
-   bootmsg = NULL;
+   bootmsg = 0;
imgpath = optarg;
break;
  
  		case 'd':

if (imgpath || bootmsg || debugmsg)
goto usage;
-   debugmsg = kwboot_msg_debug;
+   debugmsg = 1;
break;
  
  		case 'p':

@@ -1869,13 +1866,13 @@ main(int argc, char **argv)
}
  
  	if (debugmsg) {

-   rc = kwboot_debugmsg(tty, debugmsg);
+   rc = kwboot_debugmsg(tty);
if (rc) {
perror("debugmsg");
goto out;
}
} else if (bootmsg) {
-   rc = kwboot_bootmsg(tty, bootmsg);
+   rc = kwboot_bootmsg(tty);
if (rc) {
perror("bootmsg");
goto out;


Viele Grüße,
Stefan Roese

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


Re: [PATCH u-boot-marvell 02/10] tools: kwboot: Remove msg_req_delay

2022-03-03 Thread Stefan Roese

On 3/2/22 11:49, Pali Rohár wrote:

Variable msg_req_delay is set but never used. So completely remove it.

Signed-off-by: Pali Rohár 


Reviewed-by: Stefan Roese 
Tested-by: Stefan Roese 

Thanks,
Stefan


---
  tools/kwboot.c | 7 +--
  1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 5a7c53ce8929..4dfb1038b4ff 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -48,11 +48,9 @@ static unsigned char kwboot_msg_debug[] = {
  };
  
  /* Defines known to work on Kirkwood */

-#define KWBOOT_MSG_REQ_DELAY   10 /* ms */
  #define KWBOOT_MSG_RSP_TIMEO  50 /* ms */
  
  /* Defines known to work on Armada XP */

-#define KWBOOT_MSG_REQ_DELAY_AXP   1000 /* ms */
  #define KWBOOT_MSG_RSP_TIMEO_AXP  1000 /* ms */
  
  /*

@@ -285,7 +283,6 @@ static const char kwb_baud_magic[16] = "$baudratechange";
  
  static int kwboot_verbose;
  
-static int msg_req_delay = KWBOOT_MSG_REQ_DELAY;

  static int msg_rsp_timeo = KWBOOT_MSG_RSP_TIMEO;
  static int blk_rsp_timeo = KWBOOT_BLK_RSP_TIMEO;
  
@@ -1725,7 +1722,6 @@ kwboot_usage(FILE *stream, char *progname)

"  -D : boot  without preamble (Dove)\n");
fprintf(stream, "  -d: enter debug mode\n");
fprintf(stream, "  -a: use timings for Armada XP\n");
-   fprintf(stream, "  -q :  use specific request-delay\n");
fprintf(stream, "  -s : use specific response-timeout\n");
fprintf(stream,
"  -o : use specific xmodem block timeout\n");
@@ -1804,12 +1800,11 @@ main(int argc, char **argv)
break;
  
  		case 'a':

-   msg_req_delay = KWBOOT_MSG_REQ_DELAY_AXP;
msg_rsp_timeo = KWBOOT_MSG_RSP_TIMEO_AXP;
break;
  
  		case 'q':

-   msg_req_delay = atoi(optarg);
+   /* nop, for backward compatibility */
break;
  
  		case 's':


Viele Grüße,
Stefan Roese

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


Re: [PATCH u-boot-marvell 01/10] tools: kwboot: Check for return value of kwboot_tty_send() and tcflush()

2022-03-03 Thread Stefan Roese

On 3/2/22 11:49, Pali Rohár wrote:

Failure of kwboot_tty_send() and tcflush() functions is fatal, it does not
make sense to continue. So return error back to the caller like in other
places where are called these functions.

Signed-off-by: Pali Rohár 


Reviewed-by: Stefan Roese 
Tested-by: Stefan Roese 

Thanks,
Stefan


---
  tools/kwboot.c | 30 +++---
  1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 2d2d545d8258..5a7c53ce8929 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -740,10 +740,8 @@ kwboot_bootmsg(int tty, void *msg)
  
  		for (count = 0; count < 128; count++) {

rc = kwboot_tty_send(tty, msg, 8, 0);
-   if (rc) {
-   usleep(msg_req_delay * 1000);
-   continue;
-   }
+   if (rc)
+   break;
}
  
  		rc = kwboot_tty_recv(tty, , 1, msg_rsp_timeo);

@@ -772,11 +770,19 @@ kwboot_bootmsg(int tty, void *msg)
 */
  
  	/* flush output queue with remaining boot message patterns */

-   tcflush(tty, TCOFLUSH);
+   rc = tcflush(tty, TCOFLUSH);
+   if (rc) {
+   perror("Failed to flush output queue");
+   return rc;
+   }
  
  	/* send one xmodem packet with 0xff bytes to force BootROM to re-sync */

memset(, 0xff, sizeof(block));
-   kwboot_tty_send(tty, , sizeof(block), 0);
+   rc = kwboot_tty_send(tty, , sizeof(block), 0);
+   if (rc) {
+   perror("Failed to send sync sequence");
+   return rc;
+   }
  
  	/*

 * Sending 132 bytes via 115200B/8-N-1 takes 11.45 ms, reading 132 bytes
@@ -785,7 +791,11 @@ kwboot_bootmsg(int tty, void *msg)
usleep(30 * 1000);
  
  	/* flush remaining NAK replies from input queue */

-   tcflush(tty, TCIFLUSH);
+   rc = tcflush(tty, TCIFLUSH);
+   if (rc) {
+   perror("Failed to flush input queue");
+   return rc;
+   }
  
  	return 0;

  }
@@ -805,10 +815,8 @@ kwboot_debugmsg(int tty, void *msg)
break;
  
  		rc = kwboot_tty_send(tty, msg, 8, 0);

-   if (rc) {
-   usleep(msg_req_delay * 1000);
-   continue;
-   }
+   if (rc)
+   break;
  
  		rc = kwboot_tty_recv(tty, buf, 16, msg_rsp_timeo);
  


Viele Grüße,
Stefan Roese

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


Re: [PATCH u-boot-marvell 00/10] tools: kwboot: Fix boot and terminal mode

2022-03-03 Thread Stefan Roese

Hi Pali,

On 3/2/22 11:49, Pali Rohár wrote:

This patch series fixes sending boot and debug patterns by doing it in
separate thread. Entering BootROM debug mode via '-d' option is now more
stable and working fine on Armada 385. There is also support for backspace
key and updated documentation.

Stefan and Tony, could you test this patch series on more Marvell boards
which you have? Specially if '-d' option is working too.


I've never used '-d' before. Seems to work though on my Armada XP
board:

$ ./tools/kwboot -B 115200 -t 
/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0 -d

kwboot version 2022.04-rc3-01493-g756122ad25a9
Sending debug message. Please reboot the target...-
Clearing input buffer...
[Type Ctrl-\ + c to quit]

>
>help
h/? - print this help screen
r <0x> - read memory address 0x
w <0x> <0x> - write 0x to address 0x
j <0x> - jump to address 0x
x  - select SAR boot source X and restart

Also UART booting still works.

Thanks,
Stefan


*** BLURB HERE ***

Pali Rohár (10):
   tools: kwboot: Check for return value of kwboot_tty_send() and
 tcflush()
   tools: kwboot: Remove msg_req_delay
   tools: kwboot: Cleanup bootmsg and debugmsg variables
   tools: kwboot: Use separate thread for sending boot message pattern
   tools: kwboot: Fix sending and processing debug message pattern (-d
 option)
   tools: kwboot: Add support for backspace key in mini terminal
   tools: kwboot: Update usage
   tools: kwboot: Update manpage
   tools: kwboot: Update doc about Avanta
   tools: kwboot: Update references with public links

  doc/kwboot.1   | 105 ++-
  tools/Makefile |   3 +
  tools/kwboot.c | 462 -
  3 files changed, 483 insertions(+), 87 deletions(-)



Viele Grüße,
Stefan Roese

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


Re: [PATCH] drivers: rtc: fix null pointer access in armada38x_rtc_reset

2022-03-03 Thread Stefan Roese

On 2/28/22 10:31, fber...@outlook.fr wrote:

From: Francois Berder 

Replace null pointer by pointer to device registers when calling
armada38x_rtc_write.

Signed-off-by: Francois Berder 


Reviewed-by: Stefan Roese 

Thanks,
Stefan



---

  drivers/rtc/armada38x.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/rtc/armada38x.c b/drivers/rtc/armada38x.c
index 2d264acf77..2af64e3912 100644
--- a/drivers/rtc/armada38x.c
+++ b/drivers/rtc/armada38x.c
@@ -121,7 +121,7 @@ static int armada38x_rtc_reset(struct udevice *dev)
armada38x_rtc_write(0, rtc, RTC_CONF_TEST);
mdelay(500);
armada38x_rtc_write(0, rtc, RTC_TIME);
-   armada38x_rtc_write(BIT(0) | BIT(1), 0, RTC_STATUS);
+   armada38x_rtc_write(BIT(0) | BIT(1), rtc, RTC_STATUS);
}
  
  	return 0;


Viele Grüße,
Stefan Roese

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


Re: [PATCH] arm: kirkwood: nas220: Add DM Ethernet, SATA, GPIO

2022-03-03 Thread Stefan Roese

Hi Hajo,

On 3/1/22 12:57, Hajo Noerenberg wrote:

On 02/25/2022 00:19 Tony Dinh wrote:

Hi Hajo,

I've added Stefan to the reviewers. And please see a couple of minor
comments below.

On Thu, Feb 24, 2022 at 5:48 AM Hajo Noerenberg
 wrote:


Bring the NAS220 board up to current standards. This is basically an adaptation 
of the changes Tony Dinh implemented for the Dockstar board.

- Add CONFIG_DM_ETH and associated configs
- Remove CONFIG_CMD_IDE, add CONFIG_CMD_SATA and associated configs
- Add CONFIG_CMD_GPIO to have a handy way to to respond to button presses 
during boot phase
- Some minor changes to the comments
- Tested with my NAS220 hardware: ETH/USB/SATA/GPIO ok

- Note: I am collecting various information and patches for the family of 
Blackarmor NAS boards at https://github.com/hn/seagate-blackarmor-nas



Patch v2:
- implemented the changes suggested by Tony Dinh
- Remove CONFIG_SYS_SATA_MAX_DEVICE from nas220.h, got there by mistake
- add DTS file to MAINTAINERS

- Thanks, Tony


Signed-off-by: Hajo Noerenberg 


Please send the next patch version as a new mail instead of replying to
the old thread.

Looks good in general. Please find some more comments below.


---
  board/Seagate/nas220/MAINTAINERS |  1 +
  board/Seagate/nas220/nas220.c| 68 +++-
  configs/nas220_defconfig | 13 +-
  include/configs/nas220.h | 36 ++---
  4 files changed, 47 insertions(+), 71 deletions(-)

diff --git a/board/Seagate/nas220/MAINTAINERS b/board/Seagate/nas220/MAINTAINERS
index f2df7ea64f..6033f93cf4 100644
--- a/board/Seagate/nas220/MAINTAINERS
+++ b/board/Seagate/nas220/MAINTAINERS
@@ -4,3 +4,4 @@ S:  Maintained
  F:board/Seagate/nas220/
  F:include/configs/nas220.h
  F:configs/nas220_defconfig
+F: arch/arm/dts/kirkwood-blackarmor-nas220.dts
diff --git a/board/Seagate/nas220/nas220.c b/board/Seagate/nas220/nas220.c
index cd2bbdad1c..fdbf321ff9 100644
--- a/board/Seagate/nas220/nas220.c
+++ b/board/Seagate/nas220/nas220.c
@@ -10,17 +10,22 @@
  
  #include 

  #include 
-#include 
-#include 
-#include 
-#include 
+#include 
+#include 
  #include 
  #include 
-#include 
-#include 
+#include 
+#include 
+#include 
  
  DECLARE_GLOBAL_DATA_PTR;
  
+/* blue power led, board power, sata0, sata1 */

+#define NAS220_GE_OE_LOW (~(BIT(12) | BIT(14) | BIT(24) | BIT(28)))
+#define NAS220_GE_OE_HIGH (~(0))
+#define NAS220_GE_OE_VAL_LOW (BIT(12) | BIT(14) | BIT(24) | BIT(28))
+#define NAS220_GE_OE_VAL_HIGH (0)
+
  int board_early_init_f(void)
  {
/*
@@ -43,9 +48,9 @@ int board_early_init_f(void)
MPP9_TW_SCK,
MPP10_UART0_TXD,
MPP11_UART0_RXD,
-   MPP12_GPO,
+   MPP12_GPO,  /* blue power led */
MPP13_GPIO,
-   MPP14_GPIO,
+   MPP14_GPIO, /* board power */
MPP15_SATA0_ACTn,
MPP16_SATA1_ACTn,
MPP17_SATA0_PRESENTn,
@@ -55,12 +60,12 @@ int board_early_init_f(void)
MPP21_GPIO,
MPP22_GPIO,
MPP23_GPIO,
-   MPP24_GPIO,
+   MPP24_GPIO, /* sata0 power */
MPP25_GPIO,
-   MPP26_GPIO,
+   MPP26_GPIO, /* power button */
MPP27_GPIO,
-   MPP28_GPIO,
-   MPP29_GPIO,
+   MPP28_GPIO, /* sata1 power */
+   MPP29_GPIO, /* reset button */
MPP30_GPIO,
MPP31_GPIO,
MPP32_GPIO,
@@ -73,6 +78,11 @@ int board_early_init_f(void)
return 0;
  }
  
+int board_eth_init(struct bd_info *bis)

+{
+   return cpu_eth_init(bis);
+}
+
  int board_init(void)
  {
/*
@@ -85,37 +95,3 @@ int board_init(void)
  
  	return 0;

  }
-
-#ifdef CONFIG_RESET_PHY_R
-/* Configure and enable MV88E1116 PHY */
-void reset_phy(void)
-{
-   u16 reg;
-   u16 devadr;
-   char *name = "egiga0";
-
-   if (miiphy_set_current_dev(name))
-   return;
-
-   /* command to read PHY dev address */
-   if (miiphy_read(name, 0xEE, 0xEE, (u16 *))) {
-   printf("Err..%s could not read PHY dev address\n", __func__);
-   return;
-   }
-
-   /*
-* Enable RGMII delay on Tx and Rx for CPU port
-* Ref: sec 4.7.2 of chip datasheet
-*/
-   miiphy_write(name, devadr, MV88E1116_PGADR_REG, 2);
-   miiphy_read(name, devadr, MV88E1116_MAC_CTRL_REG, );
-   reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL);
-   miiphy_write(name, devadr, MV88E1116_MAC_CTRL_REG, reg);
-   miiphy_write(name, devadr, MV88E1116_PGADR_REG, 0);
-
-   /* reset the phy */
-   miiphy_reset(name, devadr);
-
-   printf("88E1116 Initialized on %s\n", name);
-}
-#endif /* CONFIG_RESET_PHY_R */
diff --git a/configs/nas220_defconfig 

Re: [PATCH u-boot-marvell] arm64: a37xx: pinctrl: Fix PWM pins indexes

2022-03-03 Thread Stefan Roese

On 2/28/22 15:59, Marek Behún wrote:

From: Marek Behún 

Commit 5534fb4f4833 ("arm64: a37xx: pinctrl: Correct PWM pins
definitions") introduced bogus definitions os PWM pins: all 4 pins have
index 11, instead of having indexes 11, 12, 13, 14.

Fix this.

Signed-off-by: Marek Behún 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


---
  drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c 
b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
index 1cf1f06f10..e76ef153e6 100644
--- a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
+++ b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
@@ -162,11 +162,11 @@ static struct armada_37xx_pin_group 
armada_37xx_nb_groups[] = {
PIN_GRP_GPIO("emmc_nb", 27, 9, BIT(2), "emmc"),
PIN_GRP_GPIO_3("pwm0", 11, 1, BIT(3) | BIT(20), 0, BIT(20), BIT(3),
   "pwm", "led"),
-   PIN_GRP_GPIO_3("pwm1", 11, 1, BIT(4) | BIT(21), 0, BIT(21), BIT(4),
+   PIN_GRP_GPIO_3("pwm1", 12, 1, BIT(4) | BIT(21), 0, BIT(21), BIT(4),
   "pwm", "led"),
-   PIN_GRP_GPIO_3("pwm2", 11, 1, BIT(5) | BIT(22), 0, BIT(22), BIT(5),
+   PIN_GRP_GPIO_3("pwm2", 13, 1, BIT(5) | BIT(22), 0, BIT(22), BIT(5),
   "pwm", "led"),
-   PIN_GRP_GPIO_3("pwm3", 11, 1, BIT(6) | BIT(23), 0, BIT(23), BIT(6),
+   PIN_GRP_GPIO_3("pwm3", 14, 1, BIT(6) | BIT(23), 0, BIT(23), BIT(6),
   "pwm", "led"),
PIN_GRP_GPIO("pmic1", 7, 1, BIT(7), "pmic"),
PIN_GRP_GPIO("pmic0", 6, 1, BIT(8), "pmic"),


Viele Grüße,
Stefan Roese

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


Re: [PATCH] ARM: mvebu: x530: clearfog: Add ODT configuration

2022-03-03 Thread Stefan Roese

On 3/1/22 01:53, Chris Packham wrote:

Commit 369e532691e0 ("ddr: marvell: a38x: allow board specific ODT
configuration") added the odt_config member to struct
mv_ddr_topology_map ahead of the clk_enable and ck_delay members. This
means that any boards that configured either of clk_enable or ck_delay
needed to have their board topology updated. This affects the x530 and
clearfog boards. Other A38x boards don't touch any of the trailing
members of mv_ddr_topology_map so don't need updating.

Fixes: 369e532691e0 ("ddr: marvell: a38x: allow board specific ODT 
configuration")
Signed-off-by: Chris Packham 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


---

  board/alliedtelesis/x530/x530.c| 1 +
  board/solidrun/clearfog/clearfog.c | 1 +
  2 files changed, 2 insertions(+)

diff --git a/board/alliedtelesis/x530/x530.c b/board/alliedtelesis/x530/x530.c
index 8b31045a0743..c0ec2afa3011 100644
--- a/board/alliedtelesis/x530/x530.c
+++ b/board/alliedtelesis/x530/x530.c
@@ -73,6 +73,7 @@ static struct mv_ddr_topology_map board_topology_map = {
{0},/* timing parameters */
{ {0} },/* electrical configuration */
{0},/* electrical parameters */
+   0,  /* ODT configuration */
0,  /* Clock enable mask */
160 /* Clock delay */
  };
diff --git a/board/solidrun/clearfog/clearfog.c 
b/board/solidrun/clearfog/clearfog.c
index c920cf8d6b50..03adb591d826 100644
--- a/board/solidrun/clearfog/clearfog.c
+++ b/board/solidrun/clearfog/clearfog.c
@@ -147,6 +147,7 @@ static struct mv_ddr_topology_map board_topology_map = {
{0},/* timing parameters */
{ {0} },/* electrical configuration */
{0,},   /* electrical parameters */
+   0,  /* ODT configuration */
0x3,/* clock enable mask */
  };
  


Viele Grüße,
Stefan Roese

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


Re: [PATCH] .mailmap: Record all address for main U-Boot contributor

2022-03-03 Thread Stefan Roese

On 3/1/22 12:43, Michal Simek wrote:

Based on looking at top contributors it was seen that top statistics from
top contributors don't include all contributions from different email
addresses. That's why I checked all top contributors are checked it.

git shortlog -n $START..$END -e -s

The patch is adding mapping for Bin Meng, Marek Vasut, Masahiro Yamada,
Michal Simek, Tom Rini, Wolfgang Denk.
And also use mapping for Stefan Roese and Wolfgang Denk to be properly
counted.

Signed-off-by: Michal Simek 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


---


$ git shortlog -n 
0b666f81da14bf46cada222856762f7fd6641c26..a900c7f8161b74fc66ec715e68e7244b53f04298
 -e -s | head
   7585 Simon Glass 
   4894 Tom Rini 
   3526 Wolfgang Denk 
   2660 Marek Vasut 
   2144 Masahiro Yamada 
   1916 Heinrich Schuchardt 
   1905 Stefan Roese 
   1775 Michal Simek 
   1503 Bin Meng 
952 Patrick Delaunay 

Please let me know if I did any mistake.

---
  .mailmap | 22 --
  1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/.mailmap b/.mailmap
index b36ae66719e2..36fc1164a2ba 100644
--- a/.mailmap
+++ b/.mailmap
@@ -22,6 +22,7 @@ Andreas Bießmann 
  Aneesh V 
  Anup Patel  
  Atish Patra  
+Bin Meng  
  Boris Brezillon  
  Boris Brezillon  
  Dirk Behme 
@@ -35,7 +36,15 @@ Jagan Teki 
  Jernej Skrabec  
  Igor Opaniuk  
  Igor Opaniuk  
+Marek Vasut  
+Marek Vasut  
+Marek Vasut  
  Markus Klotzbuecher 
+Masahiro Yamada  
+Masahiro Yamada  
+Michal Simek  
+Michal Simek  
+Michal Simek  
  Nicolas Saenz Julienne  
  Patrice Chotard  
  Patrick Delaunay  
@@ -47,10 +56,19 @@ Ricardo Ribalda  

  Ruchika Gupta  
  Sandeep Paulraj 
  Shaohui Xie 
-Stefan Roese 
+Stefan Roese  
  Stefano Babic 
+Tom Rini  
  TsiChung Liew 
-Wolfgang Denk 
+Wolfgang Denk  
+Wolfgang Denk  
+Wolfgang Denk  
+Wolfgang Denk  
+Wolfgang Denk  
+Wolfgang Denk  
+Wolfgang Denk  
+Wolfgang Denk  
+Wolfgang Denk  
  York Sun 
  York Sun 
  Łukasz Majewski 


Viele Grüße,
Stefan Roese

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


Re: [PATCH u-boot-mvebu] watchdog: armada_37xx: Probe driver also when watchdog is already running

2022-03-03 Thread Stefan Roese

On 2/23/22 14:21, Pali Rohár wrote:

If Armada 37xx watchdog is started before U-Boot then CNTR_CTRL_ACTIVE bit
is set, U-Boot armada-37xx-wdt.c driver fails to initialize and so U-Boot
is unable to use or kick this watchdog.

Do not check for CNTR_CTRL_ACTIVE bit and always initialize watchdog. Same
behavior is implemented in Linux kernel driver.

This change allows to activate watchdog in firmware which loads U-Boot.

Signed-off-by: Pali Rohár 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


---
  drivers/watchdog/armada-37xx-wdt.c | 17 +++--
  1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/drivers/watchdog/armada-37xx-wdt.c 
b/drivers/watchdog/armada-37xx-wdt.c
index 2e119b9b5aad..bacebbc7926a 100644
--- a/drivers/watchdog/armada-37xx-wdt.c
+++ b/drivers/watchdog/armada-37xx-wdt.c
@@ -58,13 +58,11 @@ static void counter_disable(struct a37xx_wdt *priv, int id)
clrbits_le32(priv->reg + CNTR_CTRL(id), CNTR_CTRL_ENABLE);
  }
  
-static int init_counter(struct a37xx_wdt *priv, int id, u32 mode, u32 trig_src)

+static void init_counter(struct a37xx_wdt *priv, int id, u32 mode, u32 
trig_src)
  {
u32 reg;
  
  	reg = readl(priv->reg + CNTR_CTRL(id));

-   if (reg & CNTR_CTRL_ACTIVE)
-   return -EBUSY;
  
  	reg &= ~(CNTR_CTRL_MODE_MASK | CNTR_CTRL_PRESCALE_MASK |

 CNTR_CTRL_TRIG_SRC_MASK);
@@ -79,8 +77,6 @@ static int init_counter(struct a37xx_wdt *priv, int id, u32 
mode, u32 trig_src)
reg |= trig_src;
  
  	writel(reg, priv->reg + CNTR_CTRL(id));

-
-   return 0;
  }
  
  static int a37xx_wdt_reset(struct udevice *dev)

@@ -116,16 +112,9 @@ static int a37xx_wdt_expire_now(struct udevice *dev, ulong 
flags)
  static int a37xx_wdt_start(struct udevice *dev, u64 ms, ulong flags)
  {
struct a37xx_wdt *priv = dev_get_priv(dev);
-   int err;
-
-   err = init_counter(priv, 0, CNTR_CTRL_MODE_ONESHOT, 0);
-   if (err < 0)
-   return err;
  
-	err = init_counter(priv, 1, CNTR_CTRL_MODE_HWSIG,

-  CNTR_CTRL_TRIG_SRC_PREV_CNTR);
-   if (err < 0)
-   return err;
+   init_counter(priv, 0, CNTR_CTRL_MODE_ONESHOT, 0);
+   init_counter(priv, 1, CNTR_CTRL_MODE_HWSIG, 
CNTR_CTRL_TRIG_SRC_PREV_CNTR);
  
  	priv->timeout = ms * priv->clk_rate / 1000 / CNTR_CTRL_PRESCALE_MIN;
  


Viele Grüße,
Stefan Roese

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


Re: [PATCH u-boot-marvell] arm: a37xx: pci: Fix a3700_fdt_fix_pcie_regions() function again

2022-03-03 Thread Stefan Roese

On 2/23/22 13:52, Marek Behún wrote:

From: Pali Rohár 

The a3700_fdt_fix_pcie_regions() function still computes nonsense.

It computes the fixup offset from the PCI address taken from the first
row of the "ranges" array, which means that:
- PCI address must equal CPU address (otherwise the computed fix offset
   will be wrong),
- the first row must contain the lowest address.

This is the case for the default device-tree, which is why we didn't
notice it.

It also adds the fixup offset to all PCI and CPU addresses, which is
wrong.

Instead:
1) The fixup offset must be computed from the CPU address, not PCI
address.

2) The fixup offset must be computed from the row containing the lowest
CPU address, which is not necessarily contained in the first row.

3) The PCI address - the address to which the PCIe controller remaps the
address space as seen from the point of view of the PCIe device -
must be fixed by the fix offset in the same way as the CPU address
only in the special case when the CPU adn PCI addresses are the same.
Same addresses means that remapping is disabled, and thus if we
change the CPU address, we need also to change the PCI address so
that the remapping is still disabled afterwards.

Consider an example:
   The ranges entries contain:
 PCI address   CPU address
 7000  EA00
 E900  E900
 EB00  EB00

   By default CPU PCIe window is at:E800 - F000
   Consider the case when TF-A moves it to: F200 - FA00

   Until now the function would take the PCI address of the first entry:
   7000, and the new base, F200, to compute the fix offset:
   F200 - 7000 = 8200, and then add 820 to all addresses,
   resulting in
 PCI address   CPU address
 F200  6C00
 6B00  6B00
 6D00  6D00
   which is complete nonsense - none of the CPU addresses is in the
   requested window.

   Now it will take the lowest CPU address, which is in second row,
   E900, and compute the fix offset F200 - E900 = 0900,
   and then add it to all CPU addresses and those PCI addresses which
   equal to their corresponding CPU addresses, resulting in
 PCI address   CPU address
 7000  F300
 F200  F200
 F400  F400
   where all of the CPU addresses are in the needed window.

Fixes: 4a82fca8e330 ("arm: a37xx: pci: Fix a3700_fdt_fix_pcie_regions() 
function")
Signed-off-by: Pali Rohár 
Signed-off-by: Marek Behún 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


---
  arch/arm/mach-mvebu/armada3700/cpu.c | 81 +++-
  1 file changed, 55 insertions(+), 26 deletions(-)

diff --git a/arch/arm/mach-mvebu/armada3700/cpu.c 
b/arch/arm/mach-mvebu/armada3700/cpu.c
index 23492f49da..52b5109b73 100644
--- a/arch/arm/mach-mvebu/armada3700/cpu.c
+++ b/arch/arm/mach-mvebu/armada3700/cpu.c
@@ -316,8 +316,8 @@ static int fdt_setprop_inplace_u32_partial(void *blob, int 
node,
  
  int a3700_fdt_fix_pcie_regions(void *blob)

  {
-   int acells, pacells, scells;
-   u32 base, fix_offset;
+   u32 base, lowest_cpu_addr, fix_offset;
+   int pci_cells, cpu_cells, size_cells;
const u32 *ranges;
int node, pnode;
int ret, i, len;
@@ -331,51 +331,80 @@ int a3700_fdt_fix_pcie_regions(void *blob)
return node;
  
  	ranges = fdt_getprop(blob, node, "ranges", );

-   if (!ranges || len % sizeof(u32))
-   return -ENOENT;
+   if (!ranges || !len || len % sizeof(u32))
+   return -EINVAL;
  
  	/*

 * The "ranges" property is an array of
-* {}
+*   {}
+* where number of PCI address cells and size cells is stored in the
+* "#address-cells" and "#size-cells" properties of the same node
+* containing the "ranges" property and number of CPU address cells
+* is stored in the parent's "#address-cells" property.
 *
-* All 3 elements can span a diffent number of cells. Fetch their sizes.
+* All 3 elements can span a diffent number of cells. Fetch them.
 */
pnode = fdt_parent_offset(blob, node);
-   acells = fdt_address_cells(blob, node);
-   pacells = fdt_address_cells(blob, pnode);
-   scells = fdt_size_cells(blob, node);
+   pci_cells = fdt_address_cells(blob, node);
+   cpu_cells = fdt_address_cells(blob, pnode);
+   size_cells = fdt_size_cells(blob, node);
  
-	/* Child PCI addresses always use 3 cells */

-   if (acells != 3)
-   return -ENOENT;
+   /* PCI addresses always use 3 cells */
+   if (pci_cells != 3)
+   return -EINVAL;
+
+   /* CPU addresses on Armada 37xx always use 2 cells */
+   if (cpu_cells != 2)
+   return -EINVAL;
+
+   for (i = 0; i < len / sizeof(u32);
+i += pci_cells + cpu_cells + size_cells) {
+   

Re: [PATCH 24/27] imx: imx8ulp_evk: enlarge CONFIG_NR_DRAM_BANKS

2022-03-03 Thread Peng Fan (OSS)




On 2022/2/26 21:28, Fabio Estevam wrote:

Hi Peng,

On Mon, Feb 14, 2022 at 9:09 AM Peng Fan (OSS)  wrote:


From: Peng Fan 

When TEE is present, the DRAM maybe split to two parts,
so enlarge CONFIG_NR_DRAM_BANKS


I think this description is confusing.

CONFIG_NR_DRAM_BANKS should be set according to how many DDR chips are
connected.

The usage of TEE is not relevant to CONFIG_NR_DRAM_BANKS.


TEE locates in the middle of DRAM memory space, it will split
the DRAM. I not have other idea how to support this without
enlarge CONFIG_NR_DRAM_BANKS.

Thanks,
Peng.





Re: [PATCH 02/27] imx: imx8ulp: include pcc/cgc header in clock header

2022-03-03 Thread Peng Fan (OSS)




On 2022/2/26 21:34, Fabio Estevam wrote:

On Mon, Feb 14, 2022 at 9:08 AM Peng Fan (OSS)  wrote:


From: Peng Fan 

Only including clock.h could simplify header files.


Sorry, I don't understand this commit log.


Signed-off-by: Peng Fan 
---
  arch/arm/include/asm/arch-imx8ulp/clock.h | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/arch/arm/include/asm/arch-imx8ulp/clock.h 
b/arch/arm/include/asm/arch-imx8ulp/clock.h
index c0f32cc087..d7c92f7058 100644
--- a/arch/arm/include/asm/arch-imx8ulp/clock.h
+++ b/arch/arm/include/asm/arch-imx8ulp/clock.h
@@ -6,6 +6,9 @@
  #ifndef _ASM_ARCH_IMX8ULP_CLOCK_H
  #define _ASM_ARCH_IMX8ULP_CLOCK_H

+#include 
+#include 


Please explain why you need to include these two header files.


No need to include pcc/cgc header file both for users, only need
include clock.h

Thanks,
Peng.





Re: [PATCH u-boot-marvell 00/10] tools: kwboot: Fix boot and terminal mode

2022-03-03 Thread Tony Dinh
Hi Pali,

It seems the problem was with the ActionTec MI424WR-I board quirk. It
has nothing to do with the new kwboot on Avanta SoC. Sorry for the
false alarm!

I spent a couple hours running with various delays for the option -s,
even with 50, and it all works fine!  Uhm... So I went back to the
default run (without -s) and it also worked. All these tests were done
with a cold start each time.

So that's when I realized  it was probably a quirk with this board.
Sometimes the warm boot caused problems for the serial port. But the
new kwboot will work whenever I coldstart (power cycle).

Thanks for a new and improved kwboot!

Tested-by: Tony Dinh 

Thanks,
Tony




On Thu, Mar 3, 2022 at 4:05 PM Pali Rohár  wrote:
>
> Hello!
>
> On Thursday 03 March 2022 15:58:41 Tony Dinh wrote:
> > Hi Pali,
> >
> > Here is the test report.
> >
> > 1. Kirkwood SoC
> >
> > Tested with Seagate GoFlex Home board (88F6281):
> > - Everything is working fine as before.
> > - kwboot -d also works to get BootROM into debug mode.
> > - At the BootROM command line, x 0x5 selected boot source NAND, and
> > started booting from u-boot in NAND successfully.
> >
> > 
> > ./kwboot -t -B 115200 /dev/ttyUSB0 -d
> > kwboot version 2022.04-rc3-2-gf64aac4a69-dirty
> > Sending debug message. Please reboot the target.../
> > Clearing input buffer...
> > [Type Ctrl-\ + c to quit]
> > >x 0x5
> > 
> >
> > 2. Armada SoC
> >
> > Tested with Globalscale Technologies Mirabox (Armada 370)
> > - Everything is working fine as before
> > - kwboot -d also works to get BootROM into debug mode
> >
> > 
> > ./kwboot -t  -B 115200 /dev/ttyUSB2 -d
> > kwboot version 2022.04-rc3-2-gf64aac4a69-dirty
> > Sending debug message. Please reboot the target.../
> > Clearing input buffer...
> > [Type Ctrl-\ + c to quit]
> >
> > >help
> > h/? - print this help screen
> > r <0x> - read memory address 0x
> > w <0x> <0x> - write 0xYYY
> > Y to address 0x
> > j <0x> - jump to address 0x
> > x  - select SAR boot source X and restart
> > >
> > 
>
> Thank you for testing. Nice to see that -d is working!
>
> > 3. Dove SoC
> >
> > Tested with HP Thin Client T5335z (Dove 88AP510)
> > - Everything is working as before.
> > - No change in behavior since the last test. IOW, u-boot image was
> > transferred successfully, but the BootROM did not start u-boot, as
> > described here:
> > https://lists.denx.de/pipermail/u-boot/2022-February/475494.html
> >
> > 4. Avanta ȘoC
> >
> > Tested with the ActionTec MI424WR-I (88F6560 A0)
> >
> > - This kwboot version is broken for this board. The header and image
> > were not transferred at all.
> > - The last tested and working kwboot version was built on Feb 15th (up
> > until and including patch
> > tools-kwbimage-Support-for-parsing-extended-v0-format.patch)
>
> Ou. This needs to be fixed.
>
> Could you try adjust "-s" argument? Default value is 50. My tests showed
> that Armada 385 is better detected with value 24. And some old
> documentation says that Armada XP needs value 1000.
>
> >
> > Thanks,
> > Tony
> >
> >
> > On Wed, Mar 2, 2022 at 1:18 PM Tony Dinh  wrote:
> > >
> > > Hi Pali,
> > >
> > >
> > > On Wed, Mar 2, 2022 at 1:03 PM Pali Rohár  wrote:
> > > >
> > > > On Wednesday 02 March 2022 12:51:25 Tony Dinh wrote:
> > > > > Hi Pali,
> > > > >
> > > > > The patch did not apply cleanly to the master branch (I downloaded the
> > > > > series from patchwork). Do you have a link where I can use it?
> > > >
> > > > Hello, this patch series depends on following kwboot patch:
> > > > https://patchwork.ozlabs.org/project/uboot/patch/20220218112413.10009-1-p...@kernel.org/
> > >
> > > That was it. I will try to kwboot a few different boxes and let you know.
> > >
> > > Thanks,
> > > Tony
> > >
> > > > > Thanks,
> > > > > Tony
> > > > >
> > > > >
> > > > >
> > > > > On Wed, Mar 2, 2022 at 2:52 AM Pali Rohár  wrote:
> > > > > >
> > > > > > This patch series fixes sending boot and debug patterns by doing it 
> > > > > > in
> > > > > > separate thread. Entering BootROM debug mode via '-d' option is now 
> > > > > > more
> > > > > > stable and working fine on Armada 385. There is also support for 
> > > > > > backspace
> > > > > > key and updated documentation.
> > > > > >
> > > > > > Stefan and Tony, could you test this patch series on more Marvell 
> > > > > > boards
> > > > > > which you have? Specially if '-d' option is working too.
> > > > > >
> > > > > > *** BLURB HERE ***
> > > > > >
> > > > > > Pali Rohár (10):
> > > > > >   tools: kwboot: Check for return value of kwboot_tty_send() and
> > > > > > tcflush()
> > > > > >   tools: kwboot: Remove msg_req_delay
> > > > > >   tools: kwboot: Cleanup bootmsg and debugmsg variables
> > > > > >   tools: kwboot: Use separate thread for sending boot message 
> > > > > > pattern
> > > > > >   tools: kwboot: Fix sending and processing debug message pattern 
> > > > > > (-d
> > > > > > option)
> > > > > >   tools: kwboot: Add 

Re: [PATCH] usb: dwc3: Add support for usb3-phy PHY configuration

2022-03-03 Thread Marek Vasut

On 3/3/22 09:40, Bin Meng wrote:

On Wed, Feb 23, 2022 at 10:56 PM Michal Simek  wrote:


When usb3-phy label is found, PHY driver is called and serdes line is
initialized. This is preparation for serdes/psgtr driver to configure GT
lines based on description in DT.

Signed-off-by: Michal Simek 
---

  drivers/usb/dwc3/dwc3-generic.c | 17 +
  1 file changed, 17 insertions(+)



Reviewed-by: Bin Meng 


Applied, thanks.


Re: [PATCH 1/2] x86: Add an enum name for the GNVS firmware type

2022-03-03 Thread Simon Glass
Hi Bin,

On Thu, 3 Mar 2022 at 01:49, Bin Meng  wrote:
>
> Hi Simon,
>
> On Tue, Mar 1, 2022 at 6:18 AM Simon Glass  wrote:
> >
> > This enum is currently anonymous. Add a name so it can be used in the
> > code.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> >  arch/x86/include/asm/intel_gnvs.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/x86/include/asm/intel_gnvs.h 
> > b/arch/x86/include/asm/intel_gnvs.h
> > index fc743dc928..b12d7f9485 100644
> > --- a/arch/x86/include/asm/intel_gnvs.h
> > +++ b/arch/x86/include/asm/intel_gnvs.h
> > @@ -47,7 +47,7 @@ enum {
> > BINF_RW_B = 2
> >  };
> >
> > -enum {
> > +enum cros_fw_type_t {
>
> The name indicates this is chrome os only, but it should be a generic name, 
> no?
>
> > FIRMWARE_TYPE_AUTO_DETECT = -1,
> > FIRMWARE_TYPE_RECOVERY = 0,
> > FIRMWARE_TYPE_NORMAL = 1,

Well, this field is only used on Chromium OS. It has its own section
of the GNVS.

Regards,
Simon


Re: [PATCH v2 07/10] tpm: rng: Move the TPM RNG functionality to driver model

2022-03-03 Thread Simon Glass
Hi Sughosh,

On Thu, 3 Mar 2022 at 05:07, Sughosh Ganu  wrote:
>
> hi Simon,
>
> On Thu, 3 Mar 2022 at 09:17, Simon Glass  wrote:
> >
> > Hi Sughosh,
> >
> > On Tue, 1 Mar 2022 at 21:36, Sughosh Ganu  wrote:
> > >
> > > hi Simon,
> > >
> > > On Tue, 1 Mar 2022 at 20:28, Simon Glass  wrote:
> > > >
> > > > Hi Sughosh,
> > > >
> > > > On Mon, 28 Feb 2022 at 05:07, Sughosh Ganu  
> > > > wrote:
> > > > >
> > > > > Currently, the TPM random number generator(RNG) functions are defined
> > > > > as part of the library functions under the corresponding tpm files for
> > > > > tpmv1 and tpmv2. Move the RNG functionality under TPM RNG drivers
> > > > > complying with the driver model.
> > > > >
> > > > > Also make changes to the tpm_get_random function to have it call the
> > > > > TPM RNG driver functions instead of the library functions.
> > > > >
> > > > > Signed-off-by: Sughosh Ganu 
> > > > > ---
> > > > >
> > > > > Changes since V1:
> > > > > * Added existing copyrights for the rng functions taken from the tpm
> > > > >   library routines
> > > > > * Return -EIO for TPM command returning an error
> > > > > * Simplify the logic in tpm_get_random based on the review comments
> > > > >   from Ilias
> > > > >
> > > > >  drivers/rng/Makefile   |  1 +
> > > > >  drivers/rng/tpm1_rng.c | 87 
> > > > > ++
> > > > >  drivers/rng/tpm2_rng.c | 86 +
> > > > >  lib/tpm-v1.c   | 44 -
> > > > >  lib/tpm-v2.c   | 44 -
> > > > >  lib/tpm_api.c  | 23 +--
> > > > >  6 files changed, 193 insertions(+), 92 deletions(-)
> > > > >  create mode 100644 drivers/rng/tpm1_rng.c
> > > > >  create mode 100644 drivers/rng/tpm2_rng.c
> > > > >
> > > > > diff --git a/drivers/rng/Makefile b/drivers/rng/Makefile
> > > > > index 39f7ee3f03..129cfbd006 100644
> > > > > --- a/drivers/rng/Makefile
> > > > > +++ b/drivers/rng/Makefile
> > > > > @@ -10,3 +10,4 @@ obj-$(CONFIG_RNG_MSM) += msm_rng.o
> > > > >  obj-$(CONFIG_RNG_STM32MP1) += stm32mp1_rng.o
> > > > >  obj-$(CONFIG_RNG_ROCKCHIP) += rockchip_rng.o
> > > > >  obj-$(CONFIG_RNG_IPROC200) += iproc_rng200.o
> > > > > +obj-$(CONFIG_TPM) += tpm1_rng.o tpm2_rng.o
> > > > > diff --git a/drivers/rng/tpm1_rng.c b/drivers/rng/tpm1_rng.c
> > > > > new file mode 100644
> > > > > index 00..7e629756b3
> > > > > --- /dev/null
> > > > > +++ b/drivers/rng/tpm1_rng.c
> > > > > @@ -0,0 +1,87 @@
> > > > > +// SPDX-License-Identifier: GPL-2.0+
> > > > > +/*
> > > > > + * Copyright (c) 2013 The Chromium OS Authors.
> > > > > + * Coypright (c) 2013 Guntermann & Drunck GmbH
> > > > > + * Copyright (c) 2022, Linaro Limited
> > > > > + */
> > > > > +
> > > > > +#include 
> > > > > +#include 
> > > > > +#include 
> > > > > +#include 
> > > > > +#include 
> > > > > +
> > > > > +#include 
> > > > > +
> > > > > +#define TPM_HEADER_SIZE10
> > > > > +
> > > > > +#define TPMV1_DATA_OFFSET  14
> > > > > +
> > > > > +/**
> > > > > + * tpm1_rng_read() - Read the random bytes from TPMv1 device
> > > > > + * @param dev  TPMv1 RNG device
> > > > > + * @param data data buffer to write random bytes
> > > > > + * @param countnumber of random bytes to read from
> > > > > + *  the device
> > > > > + *
> > > > > + * Function to read the random bytes from the RNG pseudo device
> > > > > + * built into the TPMv1 device. Reads 'count' number of bytes
> > > > > + * from the random number generator and copies them into the
> > > > > + * 'data' buffer.
> > > > > + *
> > > > > + * Return: 0 if OK, -ve on error.
> > > > > + *
> > > > > + */
> > > > > +static int tpm1_rng_read(struct udevice *dev, void *data, size_t 
> > > > > count)
> > > > > +{
> > > > > +   const u8 command[14] = {
> > > > > +   0x0, 0xc1,  /* TPM_TAG */
> > > > > +   0x0, 0x0, 0x0, 0xe, /* parameter size */
> > > > > +   0x0, 0x0, 0x0, 0x46,/* TPM_COMMAND_CODE */
> > > > > +   };
> > > > > +   const size_t length_offset = TPM_HEADER_SIZE;
> > > > > +   const size_t data_size_offset = TPM_HEADER_SIZE;
> > > > > +   const size_t data_offset = TPMV1_DATA_OFFSET;
> > > > > +   u8 buf[COMMAND_BUFFER_SIZE], response[COMMAND_BUFFER_SIZE];
> > > > > +   size_t response_length = sizeof(response);
> > > > > +   u32 data_size;
> > > > > +   u8 *out = data;
> > > > > +
> > > >
> > > > The current model is that all TPM calls are set up in lib/tpm and I
> > > > don't think we should change it. You should be able to move these
> > > > functions into lib/tpm and add your random_read function to tpm_api.h
> > >
> > > I moved these functions under separate drivers as I thought that
> > > looked cleaner as against exporting the driver interface in
> >
> > But you are now creating TPM messages in a different file so I don't
> > think it is cleaner. The message pack/unpack 

Re: [PATCH v2 08/10] tpm: Add the RNG child device

2022-03-03 Thread Simon Glass
Hi Sughosh,

On Thu, 3 Mar 2022 at 05:11, Sughosh Ganu  wrote:
>
> hi Simon,
>
> On Thu, 3 Mar 2022 at 09:18, Simon Glass  wrote:
> >
> > Hi Sughosh,
> >
> > On Tue, 1 Mar 2022 at 21:53, Sughosh Ganu  wrote:
> > >
> > > hi Simon,
> > >
> > > On Tue, 1 Mar 2022 at 20:29, Simon Glass  wrote:
> > > >
> > > > Hi Sughosh,
> > > >
> > > > On Mon, 28 Feb 2022 at 05:07, Sughosh Ganu  
> > > > wrote:
> > > > >
> > > > > The TPM device comes with the random number generator(RNG)
> > > > > functionality which is built into the TPM device. Add logic to add the
> > > > > RNG child device in the TPM uclass post probe callback.
> > > > >
> > > > > The RNG device can then be used to pass a set of random bytes to the
> > > > > linux kernel, need for address space randomisation through the
> > > > > EFI_RNG_PROTOCOL interface.
> > > > >
> > > > > Signed-off-by: Sughosh Ganu 
> > > > > ---
> > > > >
> > > > > Changes since V1: None
> > > > >
> > > > >  drivers/tpm/tpm-uclass.c | 58 
> > > > > +---
> > > > >  1 file changed, 54 insertions(+), 4 deletions(-)
> > > > >
> > > > > diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c
> > > > > index 8619da89d8..383cc7bc48 100644
> > > > > --- a/drivers/tpm/tpm-uclass.c
> > > > > +++ b/drivers/tpm/tpm-uclass.c
> > > > > @@ -16,6 +16,11 @@
> > > > >  #include 
> > > > >  #include "tpm_internal.h"
> > > > >
> > > > > +#include 
> > > > > +
> > > > > +#define TPM_RNG1_DRV_NAME  "tpm1-rng"
> > > > > +#define TPM_RNG2_DRV_NAME  "tpm2-rng"
> > > > > +
> > > > >  bool is_tpm1(struct udevice *dev)
> > > > >  {
> > > > > return IS_ENABLED(CONFIG_TPM_V1) && tpm_get_version(dev) == 
> > > > > TPM_V1;
> > > > > @@ -147,12 +152,57 @@ int tpm_xfer(struct udevice *dev, const uint8_t 
> > > > > *sendbuf, size_t send_size,
> > > > > return 0;
> > > > >  }
> > > > >
> > > > > +#if IS_ENABLED(CONFIG_TPM)
> > > >
> > > > This should be in the Makefile so that we only build this file if TPM
> > > > is enabled.
> > >
> > > The Makefile allows for the tpm uclass driver to be built for SPL and
> > > TPL stages as well. The addition of the RNG device is to be done only
> > > in the u-boot proper stage, since we enable RNG support only in u-boot
> > > proper. Thanks.
> >
> > Well in that case, create a new SPL_TPM_RAND or similar to control
> > enabling it in SPL. It should be explicit.
>
> I think it is easier to just protect the child addition functions
> under CONFIG_TPM rather than create SPL_RNG and TPL_RNG symbols. We
> don't have any requirement for generating random numbers in the SPL
> and TPL stages. I feel that creating new symbols just for the sake of
> not putting a check for CONFIG_TPM is a bit of an overkill, especially
> since we do not have any requirement for RNG devices in the SPL/TPL
> stages.

What does checking for CONFIG_TPM have to do with SPL and TPL? If that
option is enabled, the feature will be active in SPL and TPL too.

Also I see another problem, on further examination. You cannot start
up the TPM in the pre_probe() function. That needs to be done under
board control. E.g. for coral it happens in the TPL (or soon VPL)
phase so cannot be done again in U-Boot proper.

So perhaps we need to remember the state of the TPM (using SPL handoff
perhaps). Also you probably need to move the startup stuff to the RNG
itself.

Perhaps we could add a new function to handle this, which can be
called from your rand driver.

int tpm_ensure_started(struct udevice *dev, enum tpm_startup_type mode)

Regards,
Simon


Re: [PATCH 00/17] arm: semihosting: Cleanups and new features

2022-03-03 Thread Linus Walleij
Hi Sean,

I like the ambition in this series!

On Thu, Mar 3, 2022 at 9:44 PM Sean Anderson  wrote:

> The main device affected by these changes is vexpress64, so I'd appreciate
> if Linus (or anyone else) could try booting.

I am currently on parental leave and pretty far removed from that hardware
and have very little bandwidth. I added Andre Przywara to the header
(include him in the future) because currently he does much more U-Boot
work on these platforms than me.

The actual user of the semihosting commands is (IIRC) FVP, the software-only
version of vexpress-variants. The semihosting creates software traps
inside the emulated environment.

Yours,
Linus Walleij


Re: [PATCH u-boot-marvell 00/10] tools: kwboot: Fix boot and terminal mode

2022-03-03 Thread Pali Rohár
Hello!

On Thursday 03 March 2022 15:58:41 Tony Dinh wrote:
> Hi Pali,
> 
> Here is the test report.
> 
> 1. Kirkwood SoC
> 
> Tested with Seagate GoFlex Home board (88F6281):
> - Everything is working fine as before.
> - kwboot -d also works to get BootROM into debug mode.
> - At the BootROM command line, x 0x5 selected boot source NAND, and
> started booting from u-boot in NAND successfully.
> 
> 
> ./kwboot -t -B 115200 /dev/ttyUSB0 -d
> kwboot version 2022.04-rc3-2-gf64aac4a69-dirty
> Sending debug message. Please reboot the target.../
> Clearing input buffer...
> [Type Ctrl-\ + c to quit]
> >x 0x5
> 
> 
> 2. Armada SoC
> 
> Tested with Globalscale Technologies Mirabox (Armada 370)
> - Everything is working fine as before
> - kwboot -d also works to get BootROM into debug mode
> 
> 
> ./kwboot -t  -B 115200 /dev/ttyUSB2 -d
> kwboot version 2022.04-rc3-2-gf64aac4a69-dirty
> Sending debug message. Please reboot the target.../
> Clearing input buffer...
> [Type Ctrl-\ + c to quit]
> 
> >help
> h/? - print this help screen
> r <0x> - read memory address 0x
> w <0x> <0x> - write 0xYYY
> Y to address 0x
> j <0x> - jump to address 0x
> x  - select SAR boot source X and restart
> >
> 

Thank you for testing. Nice to see that -d is working!

> 3. Dove SoC
> 
> Tested with HP Thin Client T5335z (Dove 88AP510)
> - Everything is working as before.
> - No change in behavior since the last test. IOW, u-boot image was
> transferred successfully, but the BootROM did not start u-boot, as
> described here:
> https://lists.denx.de/pipermail/u-boot/2022-February/475494.html
> 
> 4. Avanta ȘoC
> 
> Tested with the ActionTec MI424WR-I (88F6560 A0)
> 
> - This kwboot version is broken for this board. The header and image
> were not transferred at all.
> - The last tested and working kwboot version was built on Feb 15th (up
> until and including patch
> tools-kwbimage-Support-for-parsing-extended-v0-format.patch)

Ou. This needs to be fixed.

Could you try adjust "-s" argument? Default value is 50. My tests showed
that Armada 385 is better detected with value 24. And some old
documentation says that Armada XP needs value 1000.

> 
> Thanks,
> Tony
> 
> 
> On Wed, Mar 2, 2022 at 1:18 PM Tony Dinh  wrote:
> >
> > Hi Pali,
> >
> >
> > On Wed, Mar 2, 2022 at 1:03 PM Pali Rohár  wrote:
> > >
> > > On Wednesday 02 March 2022 12:51:25 Tony Dinh wrote:
> > > > Hi Pali,
> > > >
> > > > The patch did not apply cleanly to the master branch (I downloaded the
> > > > series from patchwork). Do you have a link where I can use it?
> > >
> > > Hello, this patch series depends on following kwboot patch:
> > > https://patchwork.ozlabs.org/project/uboot/patch/20220218112413.10009-1-p...@kernel.org/
> >
> > That was it. I will try to kwboot a few different boxes and let you know.
> >
> > Thanks,
> > Tony
> >
> > > > Thanks,
> > > > Tony
> > > >
> > > >
> > > >
> > > > On Wed, Mar 2, 2022 at 2:52 AM Pali Rohár  wrote:
> > > > >
> > > > > This patch series fixes sending boot and debug patterns by doing it in
> > > > > separate thread. Entering BootROM debug mode via '-d' option is now 
> > > > > more
> > > > > stable and working fine on Armada 385. There is also support for 
> > > > > backspace
> > > > > key and updated documentation.
> > > > >
> > > > > Stefan and Tony, could you test this patch series on more Marvell 
> > > > > boards
> > > > > which you have? Specially if '-d' option is working too.
> > > > >
> > > > > *** BLURB HERE ***
> > > > >
> > > > > Pali Rohár (10):
> > > > >   tools: kwboot: Check for return value of kwboot_tty_send() and
> > > > > tcflush()
> > > > >   tools: kwboot: Remove msg_req_delay
> > > > >   tools: kwboot: Cleanup bootmsg and debugmsg variables
> > > > >   tools: kwboot: Use separate thread for sending boot message pattern
> > > > >   tools: kwboot: Fix sending and processing debug message pattern (-d
> > > > > option)
> > > > >   tools: kwboot: Add support for backspace key in mini terminal
> > > > >   tools: kwboot: Update usage
> > > > >   tools: kwboot: Update manpage
> > > > >   tools: kwboot: Update doc about Avanta
> > > > >   tools: kwboot: Update references with public links
> > > > >
> > > > >  doc/kwboot.1   | 105 ++-
> > > > >  tools/Makefile |   3 +
> > > > >  tools/kwboot.c | 462 
> > > > > -
> > > > >  3 files changed, 483 insertions(+), 87 deletions(-)
> > > > >
> > > > > --
> > > > > 2.20.1
> > > > >


Re: [PATCH u-boot-marvell 00/10] tools: kwboot: Fix boot and terminal mode

2022-03-03 Thread Tony Dinh
Hi Pali,

Here is the test report.

1. Kirkwood SoC

Tested with Seagate GoFlex Home board (88F6281):
- Everything is working fine as before.
- kwboot -d also works to get BootROM into debug mode.
- At the BootROM command line, x 0x5 selected boot source NAND, and
started booting from u-boot in NAND successfully.


./kwboot -t -B 115200 /dev/ttyUSB0 -d
kwboot version 2022.04-rc3-2-gf64aac4a69-dirty
Sending debug message. Please reboot the target.../
Clearing input buffer...
[Type Ctrl-\ + c to quit]
>x 0x5


2. Armada SoC

Tested with Globalscale Technologies Mirabox (Armada 370)
- Everything is working fine as before
- kwboot -d also works to get BootROM into debug mode


./kwboot -t  -B 115200 /dev/ttyUSB2 -d
kwboot version 2022.04-rc3-2-gf64aac4a69-dirty
Sending debug message. Please reboot the target.../
Clearing input buffer...
[Type Ctrl-\ + c to quit]

>help
h/? - print this help screen
r <0x> - read memory address 0x
w <0x> <0x> - write 0xYYY
Y to address 0x
j <0x> - jump to address 0x
x  - select SAR boot source X and restart
>


3. Dove SoC

Tested with HP Thin Client T5335z (Dove 88AP510)
- Everything is working as before.
- No change in behavior since the last test. IOW, u-boot image was
transferred successfully, but the BootROM did not start u-boot, as
described here:
https://lists.denx.de/pipermail/u-boot/2022-February/475494.html

4. Avanta ȘoC

Tested with the ActionTec MI424WR-I (88F6560 A0)

- This kwboot version is broken for this board. The header and image
were not transferred at all.
- The last tested and working kwboot version was built on Feb 15th (up
until and including patch
tools-kwbimage-Support-for-parsing-extended-v0-format.patch)


Thanks,
Tony


On Wed, Mar 2, 2022 at 1:18 PM Tony Dinh  wrote:
>
> Hi Pali,
>
>
> On Wed, Mar 2, 2022 at 1:03 PM Pali Rohár  wrote:
> >
> > On Wednesday 02 March 2022 12:51:25 Tony Dinh wrote:
> > > Hi Pali,
> > >
> > > The patch did not apply cleanly to the master branch (I downloaded the
> > > series from patchwork). Do you have a link where I can use it?
> >
> > Hello, this patch series depends on following kwboot patch:
> > https://patchwork.ozlabs.org/project/uboot/patch/20220218112413.10009-1-p...@kernel.org/
>
> That was it. I will try to kwboot a few different boxes and let you know.
>
> Thanks,
> Tony
>
> > > Thanks,
> > > Tony
> > >
> > >
> > >
> > > On Wed, Mar 2, 2022 at 2:52 AM Pali Rohár  wrote:
> > > >
> > > > This patch series fixes sending boot and debug patterns by doing it in
> > > > separate thread. Entering BootROM debug mode via '-d' option is now more
> > > > stable and working fine on Armada 385. There is also support for 
> > > > backspace
> > > > key and updated documentation.
> > > >
> > > > Stefan and Tony, could you test this patch series on more Marvell boards
> > > > which you have? Specially if '-d' option is working too.
> > > >
> > > > *** BLURB HERE ***
> > > >
> > > > Pali Rohár (10):
> > > >   tools: kwboot: Check for return value of kwboot_tty_send() and
> > > > tcflush()
> > > >   tools: kwboot: Remove msg_req_delay
> > > >   tools: kwboot: Cleanup bootmsg and debugmsg variables
> > > >   tools: kwboot: Use separate thread for sending boot message pattern
> > > >   tools: kwboot: Fix sending and processing debug message pattern (-d
> > > > option)
> > > >   tools: kwboot: Add support for backspace key in mini terminal
> > > >   tools: kwboot: Update usage
> > > >   tools: kwboot: Update manpage
> > > >   tools: kwboot: Update doc about Avanta
> > > >   tools: kwboot: Update references with public links
> > > >
> > > >  doc/kwboot.1   | 105 ++-
> > > >  tools/Makefile |   3 +
> > > >  tools/kwboot.c | 462 -
> > > >  3 files changed, 483 insertions(+), 87 deletions(-)
> > > >
> > > > --
> > > > 2.20.1
> > > >


[PATCH v3 11/12] arm: dts: rockchip: sync rk3288-veyron DT from Linux

2022-03-03 Thread Johan Jonker
Sync rk3288-veyron DT from Linux version 5.17.

Signed-off-by: Johan Jonker 
---

Changed V3:
  update
  change reg size

Changed V2:
  update
  add label spi_flash veyron
---
 arch/arm/dts/rk3288-veyron-analog-audio.dtsi  |  99 +++
 .../dts/rk3288-veyron-broadcom-bluetooth.dtsi |  22 +
 arch/arm/dts/rk3288-veyron-chromebook.dtsi| 115 ++--
 arch/arm/dts/rk3288-veyron-edp.dtsi   | 141 
 arch/arm/dts/rk3288-veyron-jerry.dts  | 506 +++---
 arch/arm/dts/rk3288-veyron-mickey.dts | 343 +++---
 arch/arm/dts/rk3288-veyron-minnie.dts | 441 +++-
 arch/arm/dts/rk3288-veyron-sdmmc.dtsi |  89 +++
 arch/arm/dts/rk3288-veyron-speedy.dts | 303 ++--
 arch/arm/dts/rk3288-veyron.dtsi   | 645 ++
 10 files changed, 1799 insertions(+), 905 deletions(-)
 create mode 100644 arch/arm/dts/rk3288-veyron-analog-audio.dtsi
 create mode 100644 arch/arm/dts/rk3288-veyron-broadcom-bluetooth.dtsi
 create mode 100644 arch/arm/dts/rk3288-veyron-edp.dtsi
 create mode 100644 arch/arm/dts/rk3288-veyron-sdmmc.dtsi

diff --git a/arch/arm/dts/rk3288-veyron-analog-audio.dtsi 
b/arch/arm/dts/rk3288-veyron-analog-audio.dtsi
new file mode 100644
index ..51208d16
--- /dev/null
+++ b/arch/arm/dts/rk3288-veyron-analog-audio.dtsi
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Google Veyron (and derivatives) fragment for the  max98090 audio
+ * codec and analog headphone jack.
+ *
+ * Copyright 2016 Google, Inc
+ */
+
+/ {
+   sound {
+   compatible = "rockchip,rockchip-audio-max98090";
+   pinctrl-names = "default";
+   pinctrl-0 = <_det>, <_det>;
+   rockchip,model = "VEYRON-I2S";
+   rockchip,i2s-controller = <>;
+   rockchip,audio-codec = <>;
+   rockchip,hp-det-gpios = < RK_PA5 GPIO_ACTIVE_HIGH>;
+   rockchip,mic-det-gpios = < RK_PB3 GPIO_ACTIVE_LOW>;
+   rockchip,headset-codec = <>;
+   rockchip,hdmi-codec = <>;
+   };
+};
+
+ {
+   max98090: max98090@10 {
+   compatible = "maxim,max98090";
+   reg = <0x10>;
+   interrupt-parent = <>;
+   interrupts = ;
+   clock-names = "mclk";
+   clocks = < SCLK_I2S0_OUT>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_codec>;
+   };
+};
+
+ {
+   headsetcodec: ts3a227e@3b {
+   compatible = "ti,ts3a227e";
+   reg = <0x3b>;
+   interrupt-parent = <>;
+   interrupts = ;
+   pinctrl-names = "default";
+   pinctrl-0 = <_int_l>;
+   ti,micbias = <7>;   /* MICBIAS = 2.8V */
+   };
+};
+
+ {
+   status = "okay";
+};
+
+_domains {
+   audio-supply = <_codec>;
+};
+
+ {
+   vcc10-supply = <_sys>;
+
+   regulators {
+   vcc18_codec: LDO_REG6 {
+   regulator-name = "vcc18_codec";
+   regulator-always-on;
+   regulator-boot-on;
+   regulator-min-microvolt = <180>;
+   regulator-max-microvolt = <180>;
+   regulator-state-mem {
+   regulator-off-in-suspend;
+   };
+   };
+   };
+};
+
+ {
+   codec {
+   hp_det: hp-det {
+   rockchip,pins = <6 RK_PA5 RK_FUNC_GPIO _pull_up>;
+   };
+
+   /*
+* HACK: We're going to _pull down_ this _active low_ interrupt
+* so that it never fires.  We don't need this interrupt because
+* we've got a ts3a227e chip but the driver requires it.
+*/
+   int_codec: int-codec {
+   rockchip,pins = <6 RK_PA7 RK_FUNC_GPIO _pull_down>;
+   };
+
+   mic_det: mic-det {
+   rockchip,pins = <6 RK_PB3 RK_FUNC_GPIO _pull_up>;
+   };
+   };
+
+   headset {
+   ts3a227e_int_l: ts3a227e-int-l {
+   rockchip,pins = <0 RK_PA3 RK_FUNC_GPIO _pull_up>;
+   };
+   };
+};
diff --git a/arch/arm/dts/rk3288-veyron-broadcom-bluetooth.dtsi 
b/arch/arm/dts/rk3288-veyron-broadcom-bluetooth.dtsi
new file mode 100644
index ..a10d25ac
--- /dev/null
+++ b/arch/arm/dts/rk3288-veyron-broadcom-bluetooth.dtsi
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Google Veyron (and derivatives) fragment for the Broadcom 43450 bluetooth
+ * chip.
+ *
+ * Copyright 2019 Google, Inc
+ */
+
+ {
+   bluetooth {
+   pinctrl-names = "default";
+   pinctrl-0 = <_host_wake_l>, <_enable_l>,
+   <_dev_wake>;
+
+   compatible = "brcm,bcm43540-bt";
+   host-wakeup-gpios   = < RK_PD7 GPIO_ACTIVE_HIGH>;
+

[PATCH v3 10/12] arm: dts: rockchip: sync rk3288 DT boards from Linux

2022-03-03 Thread Johan Jonker
Sync rk3288 DT boards that have support both in
Linux 5.17 as in U-boot.

Signed-off-by: Johan Jonker 
---

Change V3:
  update
  change reg size
  delete more files

Changed V2:
  update
  change led labels
---
 arch/arm/dts/rk3288-firefly-u-boot.dtsi |   4 +-
 arch/arm/dts/rk3288-firefly.dts |  17 +-
 arch/arm/dts/rk3288-firefly.dtsi| 161 +--
 arch/arm/dts/rk3288-miqi-u-boot.dtsi|   2 +-
 arch/arm/dts/rk3288-miqi.dts| 431 ++-
 arch/arm/dts/rk3288-miqi.dtsi   | 418 --
 arch/arm/dts/rk3288-phycore-rdk.dts | 109 +++--
 arch/arm/dts/rk3288-phycore-som.dtsi| 111 +
 arch/arm/dts/rk3288-popmetal.dts| 505 +-
 arch/arm/dts/rk3288-popmetal.dtsi   | 545 
 arch/arm/dts/rk3288-rock2-som.dtsi  |  91 ++--
 arch/arm/dts/rk3288-rock2-square.dts| 215 +++---
 arch/arm/dts/rk3288-tinker-s.dts|   9 +-
 arch/arm/dts/rk3288-tinker.dts  |  30 +-
 arch/arm/dts/rk3288-tinker.dtsi | 405 +-
 15 files changed, 1554 insertions(+), 1499 deletions(-)
 delete mode 100644 arch/arm/dts/rk3288-miqi.dtsi
 delete mode 100644 arch/arm/dts/rk3288-popmetal.dtsi

diff --git a/arch/arm/dts/rk3288-firefly-u-boot.dtsi 
b/arch/arm/dts/rk3288-firefly-u-boot.dtsi
index cc84d7c4..c43d3281 100644
--- a/arch/arm/dts/rk3288-firefly-u-boot.dtsi
+++ b/arch/arm/dts/rk3288-firefly-u-boot.dtsi
@@ -14,11 +14,11 @@
leds {
u-boot,dm-pre-reloc;
 
-   work {
+   work_led: led-0 {
u-boot,dm-pre-reloc;
};
 
-   power {
+   power_led: led-1 {
u-boot,dm-pre-reloc;
};
};
diff --git a/arch/arm/dts/rk3288-firefly.dts b/arch/arm/dts/rk3288-firefly.dts
index 72982efd..313459da 100644
--- a/arch/arm/dts/rk3288-firefly.dts
+++ b/arch/arm/dts/rk3288-firefly.dts
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0+ OR X11
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
 /*
  * Copyright (c) 2014, 2015 FUKAUMI Naoki 
  */
@@ -9,31 +9,22 @@
 / {
model = "Firefly-RK3288";
compatible = "firefly,firefly-rk3288", "rockchip,rk3288";
-
-   chosen {
-   stdout-path = 
-   };
 };
 
  {
-   gpios = < 0 GPIO_ACTIVE_LOW>;
+   gpios = < RK_PA0 GPIO_ACTIVE_LOW>;
 };
 
  {
act8846 {
pmic_vsel: pmic-vsel {
-   rockchip,pins = <7 14 RK_FUNC_GPIO _output_low>;
+   rockchip,pins = <7 RK_PB6 RK_FUNC_GPIO 
_output_low>;
};
};
 
ir {
ir_int: ir-int {
-   rockchip,pins = <7 0 RK_FUNC_GPIO _pull_up>;
-   };
-   };
-   usb_host {
-   host_vbus_drv: host-vbus-drv {
-   rockchip,pins = <0 14 RK_FUNC_GPIO _pull_none>;
+   rockchip,pins = <7 RK_PA0 RK_FUNC_GPIO _pull_up>;
};
};
 };
diff --git a/arch/arm/dts/rk3288-firefly.dtsi b/arch/arm/dts/rk3288-firefly.dtsi
index 1117d391..96d768ac 100644
--- a/arch/arm/dts/rk3288-firefly.dtsi
+++ b/arch/arm/dts/rk3288-firefly.dtsi
@@ -1,15 +1,38 @@
-// SPDX-License-Identifier: GPL-2.0+ OR X11
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
 /*
  * Copyright (c) 2014, 2015 FUKAUMI Naoki 
  */
 
+#include 
 #include "rk3288.dtsi"
 
 / {
-   memory {
+   memory@0 {
+   device_type = "memory";
reg = <0 0x8000>;
};
 
+   adc-keys {
+   compatible = "adc-keys";
+   io-channels = < 1>;
+   io-channel-names = "buttons";
+   keyup-threshold-microvolt = <180>;
+
+   button-recovery {
+   label = "Recovery";
+   linux,code = ;
+   press-threshold-microvolt = <0>;
+   };
+   };
+
+   dovdd_1v8: dovdd-1v8-regulator {
+   compatible = "regulator-fixed";
+   regulator-name = "dovdd_1v8";
+   regulator-min-microvolt = <180>;
+   regulator-max-microvolt = <180>;
+   vin-supply = <_dvp>;
+   };
+
ext_gmac: external-gmac-clock {
compatible = "fixed-clock";
#clock-cells = <0>;
@@ -26,11 +49,11 @@
keys: gpio-keys {
compatible = "gpio-keys";
 
-   button@0 {
-   gpio-key,wakeup = <1>;
-   gpios = < 5 GPIO_ACTIVE_LOW>;
+   power {
+   wakeup-source;
+   gpios = < RK_PA5 GPIO_ACTIVE_LOW>;
label = "GPIO Power";
-   linux,code = <116>;
+   linux,code = ;
pinctrl-names = "default";
pinctrl-0 = <_key>;
};
@@ -39,24 +62,24 @@

[PATCH v3 12/12] rockchip: fix boot_devices constants

2022-03-03 Thread Johan Jonker
The DT node name pattern in mmc-controller.yaml for mmc
is "^mmc(@.*)?$". The Rockchip mmc nodes have been synced
with Linux, so update the boot_devices constants as well.

Signed-off-by: Johan Jonker 
Reviewed-by: Simon Glass 
---
 arch/arm/mach-rockchip/rk3188/rk3188.c | 4 ++--
 arch/arm/mach-rockchip/rk322x/rk322x.c | 4 ++--
 arch/arm/mach-rockchip/rk3288/rk3288.c | 4 ++--
 arch/arm/mach-rockchip/rk3328/rk3328.c | 4 ++--
 arch/arm/mach-rockchip/rk3368/rk3368.c | 4 ++--
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/arm/mach-rockchip/rk3188/rk3188.c 
b/arch/arm/mach-rockchip/rk3188/rk3188.c
index 5a02914e..df8fa156 100644
--- a/arch/arm/mach-rockchip/rk3188/rk3188.c
+++ b/arch/arm/mach-rockchip/rk3188/rk3188.c
@@ -21,8 +21,8 @@
 #define GRF_BASE   0x20008000
 
 const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
-   [BROM_BOOTSOURCE_EMMC] = "/dwmmc@1021c000",
-   [BROM_BOOTSOURCE_SD] = "/dwmmc@10214000",
+   [BROM_BOOTSOURCE_EMMC] = "/mmc@1021c000",
+   [BROM_BOOTSOURCE_SD] = "/mmc@10214000",
 };
 
 #ifdef CONFIG_DEBUG_UART_BOARD_INIT
diff --git a/arch/arm/mach-rockchip/rk322x/rk322x.c 
b/arch/arm/mach-rockchip/rk322x/rk322x.c
index ad4ac62e..a304795f 100644
--- a/arch/arm/mach-rockchip/rk322x/rk322x.c
+++ b/arch/arm/mach-rockchip/rk322x/rk322x.c
@@ -9,8 +9,8 @@
 #include 
 
 const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
-   [BROM_BOOTSOURCE_EMMC] = "/dwmmc@3002",
-   [BROM_BOOTSOURCE_SD] = "/dwmmc@3000",
+   [BROM_BOOTSOURCE_EMMC] = "/mmc@3002",
+   [BROM_BOOTSOURCE_SD] = "/mmc@3000",
 };
 
 #ifdef CONFIG_DEBUG_UART_BOARD_INIT
diff --git a/arch/arm/mach-rockchip/rk3288/rk3288.c 
b/arch/arm/mach-rockchip/rk3288/rk3288.c
index bc20bc5a..3ad28875 100644
--- a/arch/arm/mach-rockchip/rk3288/rk3288.c
+++ b/arch/arm/mach-rockchip/rk3288/rk3288.c
@@ -28,8 +28,8 @@ DECLARE_GLOBAL_DATA_PTR;
 #define GRF_BASE   0xff77
 
 const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
-   [BROM_BOOTSOURCE_EMMC] = "/dwmmc@ff0f",
-   [BROM_BOOTSOURCE_SD] = "/dwmmc@ff0c",
+   [BROM_BOOTSOURCE_EMMC] = "/mmc@ff0f",
+   [BROM_BOOTSOURCE_SD] = "/mmc@ff0c",
 };
 
 #ifdef CONFIG_SPL_BUILD
diff --git a/arch/arm/mach-rockchip/rk3328/rk3328.c 
b/arch/arm/mach-rockchip/rk3328/rk3328.c
index ec3336cb..de17b886 100644
--- a/arch/arm/mach-rockchip/rk3328/rk3328.c
+++ b/arch/arm/mach-rockchip/rk3328/rk3328.c
@@ -21,8 +21,8 @@ DECLARE_GLOBAL_DATA_PTR;
 #define FW_DDR_CON_REG 0xFF7C0040
 
 const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
-   [BROM_BOOTSOURCE_EMMC] = "/rksdmmc@ff52",
-   [BROM_BOOTSOURCE_SD] = "/rksdmmc@ff50",
+   [BROM_BOOTSOURCE_EMMC] = "/mmc@ff52",
+   [BROM_BOOTSOURCE_SD] = "/mmc@ff50",
 };
 
 static struct mm_region rk3328_mem_map[] = {
diff --git a/arch/arm/mach-rockchip/rk3368/rk3368.c 
b/arch/arm/mach-rockchip/rk3368/rk3368.c
index 9b7132d4..d0a6107e 100644
--- a/arch/arm/mach-rockchip/rk3368/rk3368.c
+++ b/arch/arm/mach-rockchip/rk3368/rk3368.c
@@ -58,8 +58,8 @@ static struct mm_region rk3368_mem_map[] = {
 struct mm_region *mem_map = rk3368_mem_map;
 
 const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = {
-   [BROM_BOOTSOURCE_EMMC] = "/dwmmc@ff0f",
-   [BROM_BOOTSOURCE_SD] = "/dwmmc@ff0c",
+   [BROM_BOOTSOURCE_EMMC] = "/mmc@ff0f",
+   [BROM_BOOTSOURCE_SD] = "/mmc@ff0c",
 };
 
 #ifdef CONFIG_ARCH_EARLY_INIT_R
-- 
2.20.1



[PATCH v3 09/12] arm: dts: rockchip: sync rk3288.dtsi from Linux

2022-03-03 Thread Johan Jonker
Sync rk3288.dtsi from Linux version 5.17.

Signed-off-by: Johan Jonker 
---

Changed V3:
  change reg size

Changed V2:
  rename mipi_dsi0 label
  move io_domains
  remove hdmi_audio veyron node
  change memory@0 reg size
---
 arch/arm/dts/rk3288-evb.dtsi |2 +-
 arch/arm/dts/rk3288-miqi.dtsi|   28 +-
 arch/arm/dts/rk3288-phycore-som.dtsi |   30 +-
 arch/arm/dts/rk3288-popmetal.dtsi|   30 +-
 arch/arm/dts/rk3288-thermal.dtsi |   87 --
 arch/arm/dts/rk3288-veyron-jerry.dts |6 -
 arch/arm/dts/rk3288-veyron.dtsi  |   33 +-
 arch/arm/dts/rk3288.dtsi | 1367 +-
 8 files changed, 970 insertions(+), 613 deletions(-)
 delete mode 100644 arch/arm/dts/rk3288-thermal.dtsi

diff --git a/arch/arm/dts/rk3288-evb.dtsi b/arch/arm/dts/rk3288-evb.dtsi
index 04902c0b..72da8847 100644
--- a/arch/arm/dts/rk3288-evb.dtsi
+++ b/arch/arm/dts/rk3288-evb.dtsi
@@ -448,7 +448,7 @@
status = "okay";
 };
 
-_dsi0 {
+_dsi {
status = "disabled";
rockchip,panel = <>;
display-timings {
diff --git a/arch/arm/dts/rk3288-miqi.dtsi b/arch/arm/dts/rk3288-miqi.dtsi
index cb80cbf2..b1c286c9 100644
--- a/arch/arm/dts/rk3288-miqi.dtsi
+++ b/arch/arm/dts/rk3288-miqi.dtsi
@@ -18,21 +18,6 @@
clock-output-names = "ext_gmac";
};
 
-   io_domains: io-domains {
-   compatible = "rockchip,rk3288-io-voltage-domain";
-   rockchip,grf = <>;
-
-   audio-supply = <_33>;
-   flash0-supply = <_flash>;
-   flash1-supply = <_lan>;
-   gpio30-supply = <_io>;
-   gpio1830-supply = <_io>;
-   lcdc-supply = <_io>;
-   sdcard-supply = <_sd>;
-   wifi-supply = <_18>;
-   };
-
-
leds {
compatible = "gpio-leds";
 
@@ -277,6 +262,19 @@
status = "okay";
 };
 
+_domains {
+   status = "okay";
+
+   audio-supply = <_33>;
+   flash0-supply = <_flash>;
+   flash1-supply = <_lan>;
+   gpio30-supply = <_io>;
+   gpio1830-supply = <_io>;
+   lcdc-supply = <_io>;
+   sdcard-supply = <_sd>;
+   wifi-supply = <_18>;
+};
+
  {
pcfg_output_high: pcfg-output-high {
output-high;
diff --git a/arch/arm/dts/rk3288-phycore-som.dtsi 
b/arch/arm/dts/rk3288-phycore-som.dtsi
index 821525f7..8ac695c8 100644
--- a/arch/arm/dts/rk3288-phycore-som.dtsi
+++ b/arch/arm/dts/rk3288-phycore-som.dtsi
@@ -71,22 +71,6 @@
clock-output-names = "ext_gmac";
};
 
-   io_domains: io_domains {
-   compatible = "rockchip,rk3288-io-voltage-domain";
-
-   status = "okay";
-   sdcard-supply = <_io_sd>;
-   flash0-supply = <_emmc_io>;
-   flash1-supply = <_misc_1v8>;
-   gpio1830-supply = <_3v3_io>;
-   gpio30-supply = <_3v3_io>;
-   bb-supply = <_3v3_io>;
-   dvp-supply = <_3v3_io>;
-   lcdc-supply = <_3v3_io>;
-   wifi-supply = <_3v3_io>;
-   audio-supply = <_3v3_io>;
-   };
-
leds: user-leds {
compatible = "gpio-leds";
pinctrl-names = "default";
@@ -197,6 +181,20 @@
ddc-i2c-bus = <>;
 };
 
+_domains {
+   status = "okay";
+   sdcard-supply = <_io_sd>;
+   flash0-supply = <_emmc_io>;
+   flash1-supply = <_misc_1v8>;
+   gpio1830-supply = <_3v3_io>;
+   gpio30-supply = <_3v3_io>;
+   bb-supply = <_3v3_io>;
+   dvp-supply = <_3v3_io>;
+   lcdc-supply = <_3v3_io>;
+   wifi-supply = <_3v3_io>;
+   audio-supply = <_3v3_io>;
+};
+
  {
status = "okay";
clock-frequency = <40>;
diff --git a/arch/arm/dts/rk3288-popmetal.dtsi 
b/arch/arm/dts/rk3288-popmetal.dtsi
index 63785eb5..bcd8fded 100644
--- a/arch/arm/dts/rk3288-popmetal.dtsi
+++ b/arch/arm/dts/rk3288-popmetal.dtsi
@@ -69,22 +69,6 @@
};
};
 
-   io_domains: io-domains {
-   compatible = "rockchip,rk3288-io-voltage-domain";
-   rockchip,grf = <>;
-
-   audio-supply = <_33>;
-   bb-supply = <_io>;
-   dvp-supply = <_dvp>;
-   flash0-supply = <_flash>;
-   flash1-supply = <_lan>;
-   gpio30-supply = <_io>;
-   gpio1830-supply = <_io>;
-   lcdc-supply = <_io>;
-   sdcard-supply = <_sd>;
-   wifi-supply = <_wl>;
-   };
-
ir: ir-receiver {
compatible = "gpio-ir-receiver";
gpios = < 6 GPIO_ACTIVE_LOW>;
@@ -441,6 +425,20 @@
status = "okay";
 };
 
+_domains {
+   status = "okay";
+   audio-supply = <_33>;
+   bb-supply = <_io>;
+   dvp-supply = <_dvp>;
+   flash0-supply = <_flash>;
+   flash1-supply = <_lan>;
+   gpio30-supply = <_io>;
+   gpio1830-supply = <_io>;
+   lcdc-supply = <_io>;
+   

[PATCH v3 04/12] arm: dts: rockchip: sync rk322x.dtsi from Linux

2022-03-03 Thread Johan Jonker
Sync rk322x.dtsi from Linux version 5.17.

Signed-off-by: Johan Jonker 
---

Changed V2:
  update
  rename usb20_otg label
---
 arch/arm/dts/rk3229-evb.dts |   2 +-
 arch/arm/dts/rk322x.dtsi| 846 +---
 2 files changed, 695 insertions(+), 153 deletions(-)

diff --git a/arch/arm/dts/rk3229-evb.dts b/arch/arm/dts/rk3229-evb.dts
index 66a3ba23..d2681d1a 100644
--- a/arch/arm/dts/rk3229-evb.dts
+++ b/arch/arm/dts/rk3229-evb.dts
@@ -69,6 +69,6 @@
status = "okay";
 };
 
-_otg {
+_otg {
status = "okay";
 };
diff --git a/arch/arm/dts/rk322x.dtsi b/arch/arm/dts/rk322x.dtsi
index 3245da3c..8eed9e3a 100644
--- a/arch/arm/dts/rk322x.dtsi
+++ b/arch/arm/dts/rk322x.dtsi
@@ -1,7 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright (c) 2017 Fuzhou Rockchip Electronics Co., Ltd.
- */
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
 
 #include 
 #include 
@@ -9,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 
 / {
#address-cells = <1>;
@@ -20,8 +18,7 @@
serial0 = 
serial1 = 
serial2 = 
-   mmc0 = 
-   mmc1 = 
+   spi0 = 
};
 
cpus {
@@ -33,13 +30,11 @@
compatible = "arm,cortex-a7";
reg = <0xf00>;
resets = < SRST_CORE0>;
-   operating-points = <
-   /* KHzuV */
-816000 100
-   >;
+   operating-points-v2 = <_opp_table>;
#cooling-cells = <2>; /* min followed by max */
clock-latency = <4>;
clocks = < ARMCLK>;
+   enable-method = "psci";
};
 
cpu1: cpu@f01 {
@@ -47,6 +42,9 @@
compatible = "arm,cortex-a7";
reg = <0xf01>;
resets = < SRST_CORE1>;
+   operating-points-v2 = <_opp_table>;
+   #cooling-cells = <2>; /* min followed by max */
+   enable-method = "psci";
};
 
cpu2: cpu@f02 {
@@ -54,6 +52,9 @@
compatible = "arm,cortex-a7";
reg = <0xf02>;
resets = < SRST_CORE2>;
+   operating-points-v2 = <_opp_table>;
+   #cooling-cells = <2>; /* min followed by max */
+   enable-method = "psci";
};
 
cpu3: cpu@f03 {
@@ -61,23 +62,37 @@
compatible = "arm,cortex-a7";
reg = <0xf03>;
resets = < SRST_CORE3>;
+   operating-points-v2 = <_opp_table>;
+   #cooling-cells = <2>; /* min followed by max */
+   enable-method = "psci";
};
};
 
-   amba {
-   compatible = "simple-bus";
-   #address-cells = <1>;
-   #size-cells = <1>;
-   ranges;
+   cpu0_opp_table: opp-table-0 {
+   compatible = "operating-points-v2";
+   opp-shared;
 
-   pdma: pdma@110f {
-   compatible = "arm,pl330", "arm,primecell";
-   reg = <0x110f 0x4000>;
-   interrupts = ,
-;
-   #dma-cells = <1>;
-   clocks = < ACLK_DMAC>;
-   clock-names = "apb_pclk";
+   opp-40800 {
+   opp-hz = /bits/ 64 <40800>;
+   opp-microvolt = <95>;
+   clock-latency-ns = <4>;
+   opp-suspend;
+   };
+   opp-6 {
+   opp-hz = /bits/ 64 <6>;
+   opp-microvolt = <975000>;
+   };
+   opp-81600 {
+   opp-hz = /bits/ 64 <81600>;
+   opp-microvolt = <100>;
+   };
+   opp-100800 {
+   opp-hz = /bits/ 64 <100800>;
+   opp-microvolt = <1175000>;
+   };
+   opp-12 {
+   opp-hz = /bits/ 64 <12>;
+   opp-microvolt = <1275000>;
};
};
 
@@ -90,6 +105,11 @@
interrupt-affinity = <>, <>, <>, <>;
};
 
+   psci {
+   compatible = "arm,psci-1.0", "arm,psci-0.2";
+   method = "smc";
+   };
+
timer {
compatible = "arm,armv7-timer";
arm,cpu-registers-not-fw-configured;
@@ -107,12 +127,15 @@
#clock-cells = <0>;
};
 
+   display_subsystem: 

[PATCH v3 08/12] arm: dts: rockchip: move all rk3288 u-boot specific properties in separate dtsi files

2022-03-03 Thread Johan Jonker
In order to sync rk3288.dtsi from Linux it needed to
move all u-boot specific properties in separate dtsi files.

Signed-off-by: Johan Jonker 
---

Changed V3:
  add u-boot,dm-pre-reloc to noc node
  change reg size rk3288-u-boot.dtsi

Changed V2:
  combine U-boot specific changes
  add bus_intmem label
  use current led node name
---
 arch/arm/dts/rk3288-evb-u-boot.dtsi   | 11 +++
 arch/arm/dts/rk3288-evb.dts   | 11 ---
 arch/arm/dts/rk3288-firefly-u-boot.dtsi   | 31 +++
 arch/arm/dts/rk3288-firefly.dts   | 17 
 arch/arm/dts/rk3288-firefly.dtsi  |  3 -
 arch/arm/dts/rk3288-miqi-u-boot.dtsi  | 20 +
 arch/arm/dts/rk3288-miqi.dts  | 11 ---
 arch/arm/dts/rk3288-miqi.dtsi |  2 -
 arch/arm/dts/rk3288-phycore-rdk-u-boot.dtsi   | 44 ++
 arch/arm/dts/rk3288-phycore-rdk.dts   | 18 -
 arch/arm/dts/rk3288-phycore-som.dtsi  |  6 --
 arch/arm/dts/rk3288-popmetal-u-boot.dtsi  | 11 +++
 arch/arm/dts/rk3288-popmetal.dts  | 11 ---
 arch/arm/dts/rk3288-rock2-square-u-boot.dtsi  | 30 +++
 arch/arm/dts/rk3288-rock2-square.dts  | 18 -
 arch/arm/dts/rk3288-u-boot.dtsi   | 80 ---
 arch/arm/dts/rk3288-veyron-jerry-u-boot.dtsi  | 14 
 arch/arm/dts/rk3288-veyron-jerry.dts  | 11 ---
 arch/arm/dts/rk3288-veyron-mickey-u-boot.dtsi | 14 
 arch/arm/dts/rk3288-veyron-mickey.dts | 11 ---
 arch/arm/dts/rk3288-veyron-minnie-u-boot.dtsi | 14 
 arch/arm/dts/rk3288-veyron-minnie.dts | 11 ---
 arch/arm/dts/rk3288-veyron-u-boot.dtsi| 62 ++
 arch/arm/dts/rk3288-veyron.dtsi   | 39 -
 arch/arm/dts/rk3288.dtsi  | 49 +---
 25 files changed, 321 insertions(+), 228 deletions(-)
 create mode 100644 arch/arm/dts/rk3288-phycore-rdk-u-boot.dtsi
 create mode 100644 arch/arm/dts/rk3288-rock2-square-u-boot.dtsi
 create mode 100644 arch/arm/dts/rk3288-veyron-jerry-u-boot.dtsi
 create mode 100644 arch/arm/dts/rk3288-veyron-mickey-u-boot.dtsi
 create mode 100644 arch/arm/dts/rk3288-veyron-minnie-u-boot.dtsi

diff --git a/arch/arm/dts/rk3288-evb-u-boot.dtsi 
b/arch/arm/dts/rk3288-evb-u-boot.dtsi
index 8ac7840f..c8f51207 100644
--- a/arch/arm/dts/rk3288-evb-u-boot.dtsi
+++ b/arch/arm/dts/rk3288-evb-u-boot.dtsi
@@ -5,6 +5,17 @@
 
 #include "rk3288-u-boot.dtsi"
 
+ {
+   rockchip,pctl-timing = <0x215 0xc8 0x0 0x35 0x26 0x2 0x70 0x2000d
+   0x6 0x0 0x8 0x4 0x17 0x24 0xd 0x6
+   0x4 0x8 0x4 0x76 0x4 0x0 0x30 0x0
+   0x1 0x2 0x2 0x4 0x0 0x0 0xc0 0x4
+   0x8 0x1f4>;
+   rockchip,phy-timing = <0x48d7dd93 0x187008d8 0x121076
+   0x0 0xc3 0x6 0x2>;
+   rockchip,sdram-params = <0x20d266a4 0x5b6 2 53300 6 9 0>;
+};
+
  {
u-boot,dm-pre-reloc;
 };
diff --git a/arch/arm/dts/rk3288-evb.dts b/arch/arm/dts/rk3288-evb.dts
index eac91a87..bb24a96c 100644
--- a/arch/arm/dts/rk3288-evb.dts
+++ b/arch/arm/dts/rk3288-evb.dts
@@ -15,17 +15,6 @@
};
 };
 
- {
-   rockchip,pctl-timing = <0x215 0xc8 0x0 0x35 0x26 0x2 0x70 0x2000d
-   0x6 0x0 0x8 0x4 0x17 0x24 0xd 0x6
-   0x4 0x8 0x4 0x76 0x4 0x0 0x30 0x0
-   0x1 0x2 0x2 0x4 0x0 0x0 0xc0 0x4
-   0x8 0x1f4>;
-   rockchip,phy-timing = <0x48d7dd93 0x187008d8 0x121076
-   0x0 0xc3 0x6 0x2>;
-   rockchip,sdram-params = <0x20d266a4 0x5b6 2 53300 6 9 0>;
-};
-
  {
status = "okay";
 };
diff --git a/arch/arm/dts/rk3288-firefly-u-boot.dtsi 
b/arch/arm/dts/rk3288-firefly-u-boot.dtsi
index 8b9c3831..cc84d7c4 100644
--- a/arch/arm/dts/rk3288-firefly-u-boot.dtsi
+++ b/arch/arm/dts/rk3288-firefly-u-boot.dtsi
@@ -5,6 +5,37 @@
 
 #include "rk3288-u-boot.dtsi"
 
+/ {
+   config {
+   u-boot,dm-pre-reloc;
+   u-boot,boot-led = "firefly:green:power";
+   };
+
+   leds {
+   u-boot,dm-pre-reloc;
+
+   work {
+   u-boot,dm-pre-reloc;
+   };
+
+   power {
+   u-boot,dm-pre-reloc;
+   };
+   };
+};
+
+ {
+   rockchip,pctl-timing = <0x29a 0xc8 0x1f8 0x42 0x4e 0x4 0xea 0xa
+   0x5 0x0 0xa 0x7 0x19 0x24 0xa 0x7
+   0x5 0xa 0x5 0x200 0x5 0x10 0x40 0x0
+   0x1 0x7 0x7 0x4 0xc 0x43 0x100 0x0
+   0x5 0x0>;
+   rockchip,phy-timing = <0x48f9aab4 0xea0910 0x1002c200
+   0xa60 0x40 0x10 0x0>;
+   /* Add a dummy value to cause of-platdata think this is bytes */
+   rockchip,sdram-params = <0x30B25564 0x627 3 66600 3 9 1>;
+};
+
  {
u-boot,dm-pre-reloc;
 };
diff --git a/arch/arm/dts/rk3288-firefly.dts b/arch/arm/dts/rk3288-firefly.dts
index 1cff04e7..72982efd 100644
--- a/arch/arm/dts/rk3288-firefly.dts
+++ b/arch/arm/dts/rk3288-firefly.dts
@@ -13,23 +13,6 @@
chosen {

[PATCH v3 07/12] rockchip: rk3288-cru: sync the clock dt-binding header from Linux

2022-03-03 Thread Johan Jonker
In order to update the DT for rk3288
sync the clock dt-binding header.
This is the state as of v5.17 in Linux.
Keep SCLK_MAC_PLL in use for rk3288 clock driver.

Signed-off-by: Johan Jonker 
Reviewed-by: Simon Glass 
---
 include/dt-bindings/clock/rk3288-cru.h | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/include/dt-bindings/clock/rk3288-cru.h 
b/include/dt-bindings/clock/rk3288-cru.h
index e368d767..453f6671 100644
--- a/include/dt-bindings/clock/rk3288-cru.h
+++ b/include/dt-bindings/clock/rk3288-cru.h
@@ -1,9 +1,12 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
+/* SPDX-License-Identifier: GPL-2.0-or-later */
 /*
  * Copyright (c) 2014 MundoReader S.L.
  * Author: Heiko Stuebner 
  */
 
+#ifndef _DT_BINDINGS_CLK_ROCKCHIP_RK3288_H
+#define _DT_BINDINGS_CLK_ROCKCHIP_RK3288_H
+
 /* core clocks */
 #define PLL_APLL   1
 #define PLL_DPLL   2
@@ -74,6 +77,9 @@
 #define SCLK_USBPHY480M_SRC122
 #define SCLK_PVTM_CORE 123
 #define SCLK_PVTM_GPU  124
+#define SCLK_CRYPTO125
+#define SCLK_MIPIDSI_24M   126
+#define SCLK_VIP_OUT   127
 
 #define SCLK_MAC_PLL   150
 #define SCLK_MAC   151
@@ -153,6 +159,9 @@
 #define PCLK_DDRUPCTL1 366
 #define PCLK_PUBL1 367
 #define PCLK_WDT   368
+#define PCLK_EFUSE256  369
+#define PCLK_EFUSE1024 370
+#define PCLK_ISP_IN371
 
 /* hclk gates */
 #define HCLK_GPS   448
@@ -368,3 +377,5 @@
 #define SRST_TSP_CLKIN0189
 #define SRST_TSP_CLKIN1190
 #define SRST_TSP_27M   191
+
+#endif
-- 
2.20.1



[PATCH v3 06/12] rockchip: rk3288-power: sync power domain dt-binding header from Linux

2022-03-03 Thread Johan Jonker
In order to update the DT for rk3288
sync the power domain dt-binding header.
This is the state as of v5.17 in Linux.
Change location to be more in line with other SoCs.

Signed-off-by: Johan Jonker 
---

Changed V2:
  changed include rk3288.dtsi
---
 arch/arm/dts/rk3288.dtsi  |  2 +-
 include/dt-bindings/power-domain/rk3288.h | 11 
 include/dt-bindings/power/rk3288-power.h  | 32 +++
 3 files changed, 33 insertions(+), 12 deletions(-)
 delete mode 100644 include/dt-bindings/power-domain/rk3288.h
 create mode 100644 include/dt-bindings/power/rk3288-power.h

diff --git a/arch/arm/dts/rk3288.dtsi b/arch/arm/dts/rk3288.dtsi
index 22bb06ce..2086dbfd 100644
--- a/arch/arm/dts/rk3288.dtsi
+++ b/arch/arm/dts/rk3288.dtsi
@@ -5,7 +5,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include "skeleton.dtsi"
diff --git a/include/dt-bindings/power-domain/rk3288.h 
b/include/dt-bindings/power-domain/rk3288.h
deleted file mode 100644
index ca68c114..
--- a/include/dt-bindings/power-domain/rk3288.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef __DT_BINDINGS_POWER_DOMAIN_RK3288_H__
-#define __DT_BINDINGS_POWER_DOMAIN_RK3288_H__
-
-/* RK3288 power domain index */
-#define RK3288_PD_GPU  0
-#define RK3288_PD_VIO  1
-#define RK3288_PD_VIDEO2
-#define RK3288_PD_HEVC 3
-#define RK3288_PD_PERI 4
-
-#endif
diff --git a/include/dt-bindings/power/rk3288-power.h 
b/include/dt-bindings/power/rk3288-power.h
new file mode 100644
index ..f710b56c
--- /dev/null
+++ b/include/dt-bindings/power/rk3288-power.h
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __DT_BINDINGS_POWER_RK3288_POWER_H__
+#define __DT_BINDINGS_POWER_RK3288_POWER_H__
+
+/**
+ * RK3288 Power Domain and Voltage Domain Summary.
+ */
+
+/* VD_CORE */
+#define RK3288_PD_A17_00
+#define RK3288_PD_A17_11
+#define RK3288_PD_A17_22
+#define RK3288_PD_A17_33
+#define RK3288_PD_SCU  4
+#define RK3288_PD_DEBUG5
+#define RK3288_PD_MEM  6
+
+/* VD_LOGIC */
+#define RK3288_PD_BUS  7
+#define RK3288_PD_PERI 8
+#define RK3288_PD_VIO  9
+#define RK3288_PD_ALIVE10
+#define RK3288_PD_HEVC 11
+#define RK3288_PD_VIDEO12
+
+/* VD_GPU */
+#define RK3288_PD_GPU  13
+
+/* VD_PMU */
+#define RK3288_PD_PMU  14
+
+#endif
-- 
2.20.1



[PATCH v3 05/12] arm: dts: rockchip: sync rk3229-evb.dts from Linux

2022-03-03 Thread Johan Jonker
Sync rk3229-evb.dts from Linux version 5.17.

Signed-off-by: Johan Jonker 
---
 arch/arm/dts/rk3229-evb.dts | 212 +---
 arch/arm/dts/rk3229.dtsi|  52 +
 2 files changed, 249 insertions(+), 15 deletions(-)
 create mode 100644 arch/arm/dts/rk3229.dtsi

diff --git a/arch/arm/dts/rk3229-evb.dts b/arch/arm/dts/rk3229-evb.dts
index d2681d1a..797476e8 100644
--- a/arch/arm/dts/rk3229-evb.dts
+++ b/arch/arm/dts/rk3229-evb.dts
@@ -1,21 +1,32 @@
-// SPDX-License-Identifier: GPL-2.0+ OR X11
-/*
- * (C) Copyright 2017 Rockchip Electronics Co., Ltd.
- */
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
 
 /dts-v1/;
 
-#include "rk322x.dtsi"
+#include 
+#include "rk3229.dtsi"
 
 / {
model = "Rockchip RK3229 Evaluation board";
compatible = "rockchip,rk3229-evb", "rockchip,rk3229";
 
+   aliases {
+   mmc0 = 
+   };
+
memory@6000 {
device_type = "memory";
reg = <0x6000 0x4000>;
};
 
+   dc_12v: dc-12v-regulator {
+   compatible = "regulator-fixed";
+   regulator-name = "dc_12v";
+   regulator-always-on;
+   regulator-boot-on;
+   regulator-min-microvolt = <1200>;
+   regulator-max-microvolt = <1200>;
+   };
+
ext_gmac: ext_gmac {
compatible = "fixed-clock";
clock-frequency = <12500>;
@@ -23,6 +34,18 @@
#clock-cells = <0>;
};
 
+   vcc_host: vcc-host-regulator {
+   compatible = "regulator-fixed";
+   enable-active-high;
+   gpio = < RK_PC4 GPIO_ACTIVE_HIGH>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_vbus_drv>;
+   regulator-name = "vcc_host";
+   regulator-always-on;
+   regulator-boot-on;
+   vin-supply = <_sys>;
+   };
+
vcc_phy: vcc-phy-regulator {
compatible = "regulator-fixed";
enable-active-high;
@@ -31,7 +54,95 @@
regulator-max-microvolt = <180>;
regulator-always-on;
regulator-boot-on;
+   vin-supply = <_1v8>;
+   };
+
+   vcc_sys: vcc-sys-regulator {
+   compatible = "regulator-fixed";
+   regulator-name = "vcc_sys";
+   regulator-always-on;
+   regulator-boot-on;
+   regulator-min-microvolt = <500>;
+   regulator-max-microvolt = <500>;
+   vin-supply = <_12v>;
+   };
+
+   vccio_1v8: vccio-1v8-regulator {
+   compatible = "regulator-fixed";
+   regulator-name = "vccio_1v8";
+   regulator-min-microvolt = <180>;
+   regulator-max-microvolt = <180>;
+   regulator-always-on;
+   vin-supply = <_sys>;
+   };
+
+   vccio_3v3: vccio-3v3-regulator {
+   compatible = "regulator-fixed";
+   regulator-name = "vccio_3v3";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   regulator-always-on;
+   vin-supply = <_sys>;
+   };
+
+   vdd_arm: vdd-arm-regulator {
+   compatible = "pwm-regulator";
+   pwms = < 0 25000 1>;
+   pwm-supply = <_sys>;
+   regulator-name = "vdd_arm";
+   regulator-min-microvolt = <95>;
+   regulator-max-microvolt = <140>;
+   regulator-always-on;
+   regulator-boot-on;
};
+
+   vdd_log: vdd-log-regulator {
+   compatible = "pwm-regulator";
+   pwms = < 0 25000 1>;
+   pwm-supply = <_sys>;
+   regulator-name = "vdd_log";
+   regulator-min-microvolt = <100>;
+   regulator-max-microvolt = <130>;
+   regulator-always-on;
+   regulator-boot-on;
+   };
+
+   gpio_keys {
+   compatible = "gpio-keys";
+   autorepeat;
+   pinctrl-names = "default";
+   pinctrl-0 = <_key>;
+
+   power_key: power-key {
+   label = "GPIO Key Power";
+   gpios = < 23 GPIO_ACTIVE_LOW>;
+   linux,code = ;
+   debounce-interval = <100>;
+   wakeup-source;
+   };
+   };
+};
+
+ {
+   cpu-supply = <_arm>;
+};
+
+ {
+   cpu-supply = <_arm>;
+};
+
+ {
+   cpu-supply = <_arm>;
+};
+
+ {
+   cpu-supply = <_arm>;
+};
+
+ {
+   cap-mmc-highspeed;
+   non-removable;
+   status = "okay";
 };
 
  {
@@ -50,25 +161,96 @@
status = "okay";
 };
 
- {
+_domains {
status = "okay";
+
+   vccio1-supply = <_3v3>;
+   vccio2-supply = <_1v8>;
+   vccio4-supply = <_3v3>;
 };
 
- {
+ {
+   

[PATCH v3 03/12] arm: dts: rockchip: move all rk322x u-boot specific properties in separate dtsi files

2022-03-03 Thread Johan Jonker
In order to sync rk322x.dtsi from Linux, move all
U-boot specific properties in separate dtsi files.

Signed-off-by: Johan Jonker 
---

Changed V3:
  add include "rockchip-u-boot.dtsi"
---
 arch/arm/dts/rk3229-evb-u-boot.dtsi | 28 +++
 arch/arm/dts/rk3229-evb.dts | 17 -
 arch/arm/dts/rk322x-u-boot.dtsi | 56 +
 arch/arm/dts/rk322x.dtsi| 37 ---
 4 files changed, 84 insertions(+), 54 deletions(-)
 create mode 100644 arch/arm/dts/rk3229-evb-u-boot.dtsi
 create mode 100644 arch/arm/dts/rk322x-u-boot.dtsi

diff --git a/arch/arm/dts/rk3229-evb-u-boot.dtsi 
b/arch/arm/dts/rk3229-evb-u-boot.dtsi
new file mode 100644
index ..b65149c2
--- /dev/null
+++ b/arch/arm/dts/rk3229-evb-u-boot.dtsi
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+
+#include "rk322x-u-boot.dtsi"
+
+/ {
+   chosen {
+   stdout-path = 
+   };
+};
+
+ {
+   rockchip,pctl-timing = <0x96 0xC8 0x1F3 0xF 0x804D 0x4 0x4E 0x6 0x3
+   0x0 0x6 0x5 0xC 0x10 0x6 0x4 0x4
+   0x5 0x4 0x200 0x3 0xA 0x40 0x0 0x1
+   0x5 0x5 0x3 0xC 0x1E 0x100 0x0 0x4
+   0x0 0x924>;
+   rockchip,phy-timing = <0x220 0x1 0x0 0x0 0x0 0x4 0x60>;
+   rockchip,sdram-params = <0x428B188 0x0 0x21 0x472 0x15
+   0 300 3 0 120>;
+};
+
+ {
+   u-boot,dm-pre-reloc;
+};
+
+ {
+   u-boot,dm-pre-reloc;
+};
diff --git a/arch/arm/dts/rk3229-evb.dts b/arch/arm/dts/rk3229-evb.dts
index 632cdc9b..66a3ba23 100644
--- a/arch/arm/dts/rk3229-evb.dts
+++ b/arch/arm/dts/rk3229-evb.dts
@@ -11,10 +11,6 @@
model = "Rockchip RK3229 Evaluation board";
compatible = "rockchip,rk3229-evb", "rockchip,rk3229";
 
-   chosen {
-   stdout-path = 
-   };
-
memory@6000 {
device_type = "memory";
reg = <0x6000 0x4000>;
@@ -38,17 +34,6 @@
};
 };
 
- {
-   rockchip,pctl-timing = <0x96 0xC8 0x1F3 0xF 0x804D 0x4 0x4E 0x6 0x3
-   0x0 0x6 0x5 0xC 0x10 0x6 0x4 0x4
-   0x5 0x4 0x200 0x3 0xA 0x40 0x0 0x1
-   0x5 0x5 0x3 0xC 0x1E 0x100 0x0 0x4
-   0x0 0x924>;
-   rockchip,phy-timing = <0x220 0x1 0x0 0x0 0x0 0x4 0x60>;
-   rockchip,sdram-params = <0x428B188 0x0 0x21 0x472 0x15
-   0 300 3 0 120>;
-};
-
  {
assigned-clocks = < SCLK_MAC_EXTCLK>, < SCLK_MAC>;
assigned-clock-parents = <_gmac>, < SCLK_MAC_EXTCLK>;
@@ -66,7 +51,6 @@
 };
 
  {
-   u-boot,dm-pre-reloc;
status = "okay";
 };
 
@@ -82,7 +66,6 @@
 };
 
  {
-   u-boot,dm-pre-reloc;
status = "okay";
 };
 
diff --git a/arch/arm/dts/rk322x-u-boot.dtsi b/arch/arm/dts/rk322x-u-boot.dtsi
new file mode 100644
index ..79c41e48
--- /dev/null
+++ b/arch/arm/dts/rk322x-u-boot.dtsi
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include "rockchip-u-boot.dtsi"
+
+/ {
+   bus_intmem@1008 {
+   compatible = "mmio-sram";
+   reg = <0x1008 0x9000>;
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0 0x1008 0x9000>;
+
+   smp-sram@0 {
+   compatible = "rockchip,rk322x-smp-sram";
+   reg = <0x00 0x10>;
+   };
+
+   ddr_sram: ddr-sram@1000 {
+   compatible = "rockchip,rk322x-ddr-sram";
+   reg = <0x1000 0x8000>;
+   };
+   };
+
+   dmc: dmc@1120 {
+   compatible = "rockchip,rk3228-dmc", "syscon";
+   reg = <0x1120 0x3fc
+  0x1200 0x400>;
+   rockchip,cru = <>;
+   rockchip,grf = <>;
+   rockchip,msch = <_msch>;
+   rockchip,sram = <_sram>;
+   u-boot,dm-pre-reloc;
+   };
+
+   service_msch: syscon@3109 {
+   compatible = "rockchip,rk3228-msch", "syscon";
+   reg = <0x3109 0x2000>;
+   u-boot,dm-pre-reloc;
+   };
+};
+
+ {
+   u-boot,dm-pre-reloc;
+};
+
+ {
+   max-frequency = <15000>;
+};
+
+ {
+   u-boot,dm-pre-reloc;
+};
+
+ {
+   max-frequency = <15000>;
+};
diff --git a/arch/arm/dts/rk322x.dtsi b/arch/arm/dts/rk322x.dtsi
index 4a8be5da..3245da3c 100644
--- a/arch/arm/dts/rk322x.dtsi
+++ b/arch/arm/dts/rk322x.dtsi
@@ -107,22 +107,6 @@
#clock-cells = <0>;
};
 
-   bus_intmem@1008 {
-   compatible = "mmio-sram";
-   reg = <0x1008 0x9000>;
-   #address-cells = <1>;
-   #size-cells = <1>;
-   ranges = <0 0x1008 0x9000>;
-   smp-sram@0 {
-   compatible = "rockchip,rk322x-smp-sram";
-   reg = <0x00 0x10>;
-   };
-   ddr_sram: ddr-sram@1000 {
-   

[PATCH v3 02/12] rockchip: rk3228-cru: sync the clock dt-binding header from Linux

2022-03-03 Thread Johan Jonker
In order to update the DT for rk3228
sync the clock dt-binding header.
This is the state as of v5.17 in Linux.

Signed-off-by: Johan Jonker 
Reviewed-by: Simon Glass 
---
 include/dt-bindings/clock/rk3228-cru.h | 54 +-
 1 file changed, 52 insertions(+), 2 deletions(-)

diff --git a/include/dt-bindings/clock/rk3228-cru.h 
b/include/dt-bindings/clock/rk3228-cru.h
index 1217d523..de550ea5 100644
--- a/include/dt-bindings/clock/rk3228-cru.h
+++ b/include/dt-bindings/clock/rk3228-cru.h
@@ -1,6 +1,7 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
+/* SPDX-License-Identifier: GPL-2.0-or-later */
 /*
- * (C) Copyright 2017 Rockchip Electronics Co., Ltd.
+ * Copyright (c) 2015 Rockchip Electronics Co. Ltd.
+ * Author: Jeffy Chen 
  */
 
 #ifndef _DT_BINDINGS_CLK_ROCKCHIP_RK3228_H
@@ -39,6 +40,7 @@
 #define SCLK_EMMC_DRV  117
 #define SCLK_SDMMC_SAMPLE  118
 #define SCLK_SDIO_SAMPLE   119
+#define SCLK_SDIO_SRC  120
 #define SCLK_EMMC_SAMPLE   121
 #define SCLK_VOP   122
 #define SCLK_HDMI_HDCP 123
@@ -51,6 +53,18 @@
 #define SCLK_MAC_TX130
 #define SCLK_MAC_PHY   131
 #define SCLK_MAC_OUT   132
+#define SCLK_VDEC_CABAC133
+#define SCLK_VDEC_CORE 134
+#define SCLK_RGA   135
+#define SCLK_HDCP  136
+#define SCLK_HDMI_CEC  137
+#define SCLK_CRYPTO138
+#define SCLK_TSP   139
+#define SCLK_HSADC 140
+#define SCLK_WIFI  141
+#define SCLK_OTGPHY0   142
+#define SCLK_OTGPHY1   143
+#define SCLK_HDMI_PHY  144
 
 /* dclk gates */
 #define DCLK_VOP   190
@@ -58,15 +72,32 @@
 
 /* aclk gates */
 #define ACLK_DMAC  194
+#define ACLK_CPU   195
+#define ACLK_VPU_PRE   196
+#define ACLK_RKVDEC_PRE197
+#define ACLK_RGA_PRE   198
+#define ACLK_IEP_PRE   199
+#define ACLK_HDCP_PRE  200
+#define ACLK_VOP_PRE   201
+#define ACLK_VPU   202
+#define ACLK_RKVDEC203
+#define ACLK_IEP   204
+#define ACLK_RGA   205
+#define ACLK_HDCP  206
 #define ACLK_PERI  210
 #define ACLK_VOP   211
 #define ACLK_GMAC  212
+#define ACLK_GPU   213
 
 /* pclk gates */
 #define PCLK_GPIO0 320
 #define PCLK_GPIO1 321
 #define PCLK_GPIO2 322
 #define PCLK_GPIO3 323
+#define PCLK_VIO_H2P   324
+#define PCLK_HDCP  325
+#define PCLK_EFUSE_1024326
+#define PCLK_EFUSE_256 327
 #define PCLK_GRF   329
 #define PCLK_I2C0  332
 #define PCLK_I2C1  333
@@ -79,6 +110,7 @@
 #define PCLK_TSADC 344
 #define PCLK_PWM   350
 #define PCLK_TIMER 353
+#define PCLK_CPU   354
 #define PCLK_PERI  363
 #define PCLK_HDMI_CTRL 364
 #define PCLK_HDMI_PHY  365
@@ -94,6 +126,24 @@
 #define HCLK_SDMMC 456
 #define HCLK_SDIO  457
 #define HCLK_EMMC  459
+#define HCLK_CPU   460
+#define HCLK_VPU_PRE   461
+#define HCLK_RKVDEC_PRE462
+#define HCLK_VIO_PRE   463
+#define HCLK_VPU   464
+#define HCLK_RKVDEC465
+#define HCLK_VIO   466
+#define HCLK_RGA   467
+#define HCLK_IEP   468
+#define HCLK_VIO_H2P   469
+#define HCLK_HDCP_MMU  470
+#define HCLK_HOST0 471
+#define HCLK_HOST1 472
+#define HCLK_HOST2 473
+#define HCLK_OTG   474
+#define HCLK_TSP   475
+#define HCLK_M_CRYPTO  476
+#define HCLK_S_CRYPTO  477
 #define HCLK_PERI  478
 
 #define CLK_NR_CLKS(HCLK_PERI + 1)
-- 
2.20.1



[PATCH v3 01/12] rockchip: rk3228-power: sync power domain dt-binding header from Linux

2022-03-03 Thread Johan Jonker
In order to update the DT for rk3228
sync the power domain dt-binding header.
This is the state as of v5.17 in Linux.

Signed-off-by: Johan Jonker 
Reviewed-by: Simon Glass 
---
 include/dt-bindings/power/rk3228-power.h | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 include/dt-bindings/power/rk3228-power.h

diff --git a/include/dt-bindings/power/rk3228-power.h 
b/include/dt-bindings/power/rk3228-power.h
new file mode 100644
index ..6a8dc1bf
--- /dev/null
+++ b/include/dt-bindings/power/rk3228-power.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __DT_BINDINGS_POWER_RK3228_POWER_H__
+#define __DT_BINDINGS_POWER_RK3228_POWER_H__
+
+/**
+ * RK3228 idle id Summary.
+ */
+
+#define RK3228_PD_CORE 0
+#define RK3228_PD_MSCH 1
+#define RK3228_PD_BUS  2
+#define RK3228_PD_SYS  3
+#define RK3228_PD_VIO  4
+#define RK3228_PD_VOP  5
+#define RK3228_PD_VPU  6
+#define RK3228_PD_RKVDEC   7
+#define RK3228_PD_GPU  8
+#define RK3228_PD_PERI 9
+#define RK3228_PD_GMAC 10
+
+#endif
-- 
2.20.1



Re: [PATCH v2 23/25] rockchip: Support building the all output files in binman

2022-03-03 Thread Peter Geis
On Thu, Mar 3, 2022 at 4:17 PM Alper Nebi Yasak
 wrote:
>
> On 03/03/2022 01:16, Peter Geis wrote:
> > On Wed, Feb 23, 2022 at 6:04 PM Simon Glass  wrote:
> >> diff --git a/arch/arm/dts/rockchip-u-boot.dtsi 
> >> b/arch/arm/dts/rockchip-u-boot.dtsi
> >> index eae3ee715d..64e4466489 100644
> >> --- a/arch/arm/dts/rockchip-u-boot.dtsi
> >> +++ b/arch/arm/dts/rockchip-u-boot.dtsi
> >> @@ -17,13 +17,93 @@
> >> filename = "u-boot-rockchip.bin";
> >> pad-byte = <0xff>;
> >>
> >> -   blob {
> >> -   filename = "idbloader.img";
> >> +#ifdef CONFIG_TPL
> >> +   mkimage {
> >> +   args = "-n", CONFIG_SYS_SOC, "-T", "rksd";
> >> +
> >> +   u-boot-tpl {
> >> +   };
> >> +   };
> >> +
> >> +   u-boot-spl {
> >> };
> >> +#elif defined(CONFIG_SPL) /* SPL only */
> >> +   mkimage {
> >> +   args = "-n", CONFIG_SYS_SOC, "-T", "rksd";
> >> +
> >> +   u-boot-spl {
> >> +   };
> >> +   };
> >> +#endif
> >> +#if defined(CONFIG_SPL_FIT) && defined(CONFIG_ARM64)
> >> +   fit: fit {
> >> +   description = "FIT image for U-Boot with bl31 
> >> (TF-A)";
> >> +   #address-cells = <1>;
> >> +   fit,fdt-list = "of-list";
> >> +   fit,external-offset = ;
> >
> > You need:
> > offset = ;
> > here or the image is located at the wrong location.
>
> Thanks for confirming this.
>
> > The image produced is not functional however, because it swaps the
> > firmware node with the loadable-1 node.
> > Working image:
> >  Configuration 0 (config_1)
> >   Description:  rk3399-pinephone-pro.dtb
> >   Kernel:   unavailable
> >   Firmware: atf_1
> >   FDT:  fdt_1
> >   Loadables:uboot
> > atf_2
> > atf_3
> >
> > Non working image produced from this:
> >  Configuration 0 (config-1)
> >   Description:  rk3399-rockpro64.dtb
> >   Kernel:   unavailable
> >   Firmware: u-boot
> >   FDT:  fdt-1
> >   Loadables:atf-1
> > atf-2
> > atf-3
>
> And also this. I encountered the same things on rk3399-gru-kevin,
> mentioned them in my reply [1] to v1 but I guess Simon missed it.
>
> [1] My reply to v1 of this patch
> https://lore.kernel.org/u-boot/d50a7e13-7113-8c95-1861-cbc6c1000...@gmail.com/

Yes, that's the solution I ended up with as well.
Funnily enough, it seems loadables has a limit of five items, meaning
the newest rk356x ATF images which have four binaries, u-boot, and
optee trigger an error.

>
> > Also, it still doesn't support passing two separate files to mkimage
> > at the same time, required for proper support of rk33xx_SPI generation
> > and for rk35xx in general.
>
> I got v1 of this booting from SPI, but on a board that doesn't use TPL.
> I see in doc/boards/rockchip.rst that one would indeed pass TPL+SPL to
> mkimage as two different files. I don't know how they're processed or
> anything about the rksd/rkspi formats though.

RKSPI mode splits the image up into 2048 chunks, and pads each chunk
with 2048 of blank space.
For some reason the rk32/rk33 bootrom SPI code reads only 2048 out of
each 4096 chunk.
Delightfully this seems to have been fixed in rk35xx.

>
> > Please see my standalone patch for what I hacked together to get that 
> > working:
> > http://patchwork.ozlabs.org/project/uboot/patch/20220301024826.1228290-1-pgwipe...@gmail.com/
> > Note: those images are not functional either due to this issue.
> >
> > A wishlist item would be for it to produce the original idbloader.img
> > and u-boot.itb files, at least for now.
> >
> > Thanks!
> > Very Respectfully,
> > Peter Geis


Re: [RFC] [PATCH] binman: support mkimage split files

2022-03-03 Thread Alper Nebi Yasak
On 01/03/2022 05:48, Peter Geis wrote:
> Good Evening,
> 
> I successfully tested your v2 patch series to create a bootable sdcard
> image out of the box for rockpro64-rk3399.
> Unfortunately, rk356x and rk3399-spi modes are broken, due to the
> inability to pass multiple images to mkimage at the same time.
> rk3399-spi mode is already supported manually, see:
> https://elixir.bootlin.com/u-boot/v2022.04-rc3/source/doc/board/rockchip/rockchip.rst#L182
> 
> rk356x is currently only supported manually, the image built by the old
> Makefile method is non functional. (u-boot-rockchip.bin)
> 
> Knowing absolutely nothing about python, I've hacked together something
> that works for splitting the image in the way mkimage expects.
> The file name passed to mkimage with the -d flag is:
> ./mkimage.simple-bin.mkimage.1:./mkimage.simple-bin.mkimage.2
> 
> I definitely don't expect this to be accepted as is, I just use it as an
> example of what we need to fully support this in binman.
> Adding the following allows me to build images automatically for rk356x:
> 
> mkimage {
>   args = "-n", CONFIG_SYS_SOC, "-T", "rksd";
>   mkimage,separate_files;

Adding a property to toggle this sounds reasonable to me. The prefix
might not be necessary, and I think dashes are preferred to underscores
in property names.

> 
>   ddrl {
>   type = "blob-ext";
>   filename = "rk3568_ddr_1560MHz_v1.12.bin";
>   };
> 
>   u-boot-spl {
>   };
> };
> 
> This is my first attempt to use in-reply-to, so I hope this works.

FYI, I see it as a reply to 00/25 of the series.

> 
> Thanks,
> Peter Geis
> 
> Signed-off-by: Peter Geis 
> ---
>  tools/binman/entry.py | 43 ++-
>  tools/binman/etype/mkimage.py |  3 ++-
>  2 files changed, 34 insertions(+), 12 deletions(-)
> 
> diff --git a/tools/binman/entry.py b/tools/binman/entry.py
> index 249f117ace56..48e552fc6af3 100644
> --- a/tools/binman/entry.py
> +++ b/tools/binman/entry.py
> @@ -114,6 +114,8 @@ class Entry(object):
>  self.bintools = {}
>  self.missing_bintools = []
>  self.update_hash = True
> +self.fname_tmp = str()
> +self.index = 0
>  
>  @staticmethod
>  def FindEntryClass(etype, expanded):
> @@ -1134,7 +1136,7 @@ features to produce new behaviours.
>  """
>  self.update_hash = update_hash
>  
> -def collect_contents_to_file(self, entries, prefix, fake_size=0):
> +def collect_contents_to_file(self, entries, prefix, fake_size=0, 
> separate=False):
>  """Put the contents of a list of entries into a file
>  
>  Args:
> @@ -1152,13 +1154,32 @@ features to produce new behaviours.
>  str: Unique portion of filename (or None if no data)
>  """
>  data = b''
> -for entry in entries:
> -# First get the input data and put it in a file. If not 
> available,
> -# try later.
> -if not entry.ObtainContents(fake_size=fake_size):
> -return None, None, None
> -data += entry.GetData()
> -uniq = self.GetUniqueName()
> -fname = tools.get_output_filename(f'{prefix}.{uniq}')
> -tools.write_file(fname, data)
> -return data, fname, uniq
> +if separate is False:
> +for entry in entries:
> +# First get the input data and put it in a file. If not 
> available,
> +# try later.
> +if not entry.ObtainContents(fake_size=fake_size):
> +return None, None, None
> +data += entry.GetData()
> +uniq = self.GetUniqueName()
> +fname = tools.get_output_filename(f'{prefix}.{uniq}')
> +tools.write_file(fname, data)
> +return data, fname, uniq
> +else:
> +for entry in entries:
> +self.index = (self.index + 1)
> +if (self.index > 2):
> +print('BINMAN Warn: mkimage only supports a maximum of 
> two separate files')
> +break
> +# First get the input data and put it in a file. If not 
> available,
> +# try later.
> +if not entry.ObtainContents(fake_size=fake_size):
> +return None, None, None
> +data = entry.GetData()
> +uniq = self.GetUniqueName()
> +fname = 
> tools.get_output_filename(f'{prefix}.{uniq}.{self.index}')
> +tools.write_file(fname, data)
> +self.fname_tmp = [''.join(self.fname_tmp),fname]
> +fname = ':'.join(self.fname_tmp)
> +uniq = self.GetUniqueName()
> +return data, fname, uniq

I would keep this function as-is and call it multiple times in the
mkimage etype code below (once per subentry), and also do the
mkimage-specific checks and 'file1:file2' argument joining there as well.

> diff 

Re: [PATCH v2 23/25] rockchip: Support building the all output files in binman

2022-03-03 Thread Alper Nebi Yasak
On 03/03/2022 01:16, Peter Geis wrote:
> On Wed, Feb 23, 2022 at 6:04 PM Simon Glass  wrote:
>> diff --git a/arch/arm/dts/rockchip-u-boot.dtsi 
>> b/arch/arm/dts/rockchip-u-boot.dtsi
>> index eae3ee715d..64e4466489 100644
>> --- a/arch/arm/dts/rockchip-u-boot.dtsi
>> +++ b/arch/arm/dts/rockchip-u-boot.dtsi
>> @@ -17,13 +17,93 @@
>> filename = "u-boot-rockchip.bin";
>> pad-byte = <0xff>;
>>
>> -   blob {
>> -   filename = "idbloader.img";
>> +#ifdef CONFIG_TPL
>> +   mkimage {
>> +   args = "-n", CONFIG_SYS_SOC, "-T", "rksd";
>> +
>> +   u-boot-tpl {
>> +   };
>> +   };
>> +
>> +   u-boot-spl {
>> };
>> +#elif defined(CONFIG_SPL) /* SPL only */
>> +   mkimage {
>> +   args = "-n", CONFIG_SYS_SOC, "-T", "rksd";
>> +
>> +   u-boot-spl {
>> +   };
>> +   };
>> +#endif
>> +#if defined(CONFIG_SPL_FIT) && defined(CONFIG_ARM64)
>> +   fit: fit {
>> +   description = "FIT image for U-Boot with bl31 
>> (TF-A)";
>> +   #address-cells = <1>;
>> +   fit,fdt-list = "of-list";
>> +   fit,external-offset = ;
> 
> You need:
> offset = ;
> here or the image is located at the wrong location.

Thanks for confirming this.

> The image produced is not functional however, because it swaps the
> firmware node with the loadable-1 node.
> Working image:
>  Configuration 0 (config_1)
>   Description:  rk3399-pinephone-pro.dtb
>   Kernel:   unavailable
>   Firmware: atf_1
>   FDT:  fdt_1
>   Loadables:uboot
> atf_2
> atf_3
> 
> Non working image produced from this:
>  Configuration 0 (config-1)
>   Description:  rk3399-rockpro64.dtb
>   Kernel:   unavailable
>   Firmware: u-boot
>   FDT:  fdt-1
>   Loadables:atf-1
> atf-2
> atf-3

And also this. I encountered the same things on rk3399-gru-kevin,
mentioned them in my reply [1] to v1 but I guess Simon missed it.

[1] My reply to v1 of this patch
https://lore.kernel.org/u-boot/d50a7e13-7113-8c95-1861-cbc6c1000...@gmail.com/

> Also, it still doesn't support passing two separate files to mkimage
> at the same time, required for proper support of rk33xx_SPI generation
> and for rk35xx in general.

I got v1 of this booting from SPI, but on a board that doesn't use TPL.
I see in doc/boards/rockchip.rst that one would indeed pass TPL+SPL to
mkimage as two different files. I don't know how they're processed or
anything about the rksd/rkspi formats though.

> Please see my standalone patch for what I hacked together to get that working:
> http://patchwork.ozlabs.org/project/uboot/patch/20220301024826.1228290-1-pgwipe...@gmail.com/
> Note: those images are not functional either due to this issue.
> 
> A wishlist item would be for it to produce the original idbloader.img
> and u-boot.itb files, at least for now.
> 
> Thanks!
> Very Respectfully,
> Peter Geis


Re: [PATCH v2 22/25] rockchip: Include binman script in 64-bit boards

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> Include the rockchip-u-boot.dtsi file with 64-bit boards and enable binman
> so that these boards can also use it, rather than using special Makefile
> rules and scripts.
> 
> This does not change the Makefile nor remove any scripts, but sets it up
> so that this is possible.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> (no changes since v1)
> 
>  arch/arm/dts/px30-u-boot.dtsi  | 2 ++
>  arch/arm/dts/rk3308-u-boot.dtsi| 2 ++
>  arch/arm/dts/rk3326-odroid-go2-u-boot.dtsi | 2 ++
>  arch/arm/dts/rk3328-u-boot.dtsi| 2 ++
>  arch/arm/dts/rk3368-u-boot.dtsi| 1 +
>  arch/arm/dts/rk3399-u-boot.dtsi| 5 +++--
>  arch/arm/dts/rk3568-u-boot.dtsi| 2 ++
>  arch/arm/mach-rockchip/Kconfig | 6 ++
>  8 files changed, 20 insertions(+), 2 deletions(-)

Reviewed-by: Alper Nebi Yasak 


Re: [PATCH v2 20/25] binman: Support splitting an ELF file into multiple nodes

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> Some boards need to load an ELF file using the 'loadables' property, but
> the file has segments at different memory addresses. This means that it
> cannot be supplied as a flat binary.
> 
> Allow generating a separate node in the FIT for each segment in the ELF,
> with a different load address for each.
> 
> Also add checks that the fit,xxx directives are valid.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> Changes in v2:
> - Rewrite this to use the new FIT entry-type implementation
> - Rename op-tee to tee-os
> 
>  tools/binman/entries.rst | 146 
>  tools/binman/etype/fit.py| 230 ++-
>  tools/binman/ftest.py| 147 
>  tools/binman/test/226_fit_split_elf.dts  |  67 ++
>  tools/binman/test/227_fit_bad_dir.dts|   9 +
>  tools/binman/test/228_fit_bad_dir_config.dts |   9 +
>  6 files changed, 598 insertions(+), 10 deletions(-)
>  create mode 100644 tools/binman/test/226_fit_split_elf.dts
>  create mode 100644 tools/binman/test/227_fit_bad_dir.dts
>  create mode 100644 tools/binman/test/228_fit_bad_dir_config.dts
> 
> [...]
> 
> diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py
> index 30b20a07a2..63d552ed19 100644> > [...]
> 
> @@ -154,6 +159,149 @@ class Entry_fit(Entry_section):
>  
>  Note that if no devicetree files are provided (with '-a of-list' as 
> above)
>  then no nodes will be generated.
> +
> +Generating nodes from an ELF file (split-elf)
> +~
> +
> +This uses the node as a template to generate multiple nodes. The 
> following
> +special properties are available:
> +
> +split-elf
> +Split an ELF file into a separate node for each segment. This uses 
> the
> +node as a template to generate multiple nodes. The following special
> +properties are available:
> +
> +fit,load
> +Generates a `load = <...>` property with the load address of the
> +segmnet

segmnet -> segment, missed it the first time around.

> +
> +fit,entry
> +Generates a `entry = <...>` property with the entry address of 
> the
> +ELF. This is only produced for the first entry
> +
> +fit,data
> +Generates a `data = <...>` property with the contents of the 
> segment
> +
> +fit,loadables
> +Generates a `loadable = <...>` property with a list of the 
> generated
> +nodes (including all nodes if this operation is used multiple 
> times)
> 
> [...]
>  
> @@ -363,11 +514,20 @@ class Entry_fit(Entry_section):
>  fname = tools.get_input_filename(fdt_fname + '.dtb')
>  with fsw.add_node(node_name):
>  for pname, prop in node.props.items():
> -val = prop.bytes.replace(
> -b'NAME', tools.to_bytes(fdt_fname))
> -val = val.replace(
> -b'SEQ', tools.to_bytes(str(seq + 1)))
> -fsw.property(pname, val)
> +if pname == 'fit,loadables':
> +val = '\0'.join(self._loadables) + '\0'
> +fsw.property('loadables', 
> val.encode('utf-8'))
> +elif pname == 'fit,operation':
> +pass
> +elif pname.startswith('fit,'):
> +self._raise(base_node, node,
> +f"Unknown directive '{pname}'")
> +else:
> +val = prop.bytes.replace(
> +b'NAME', tools.to_bytes(fdt_fname))
> +val = val.replace(
> +b'SEQ', tools.to_bytes(str(seq + 1)))
> +fsw.property(pname, val)

I get two distinct "loadables" properties with this config fragment,
and fdtget and mkimage -l only considers the first one:

  @config-SEQ {
 description = "NAME.dtb";
 fdt = "fdt-SEQ";
 firmware = "atf-1";
 loadables = "u-boot";
 fit,loadables;
  };

  $ fdtget simple-bin.fit.fit /configurations/config-1 -p
  description
  fdt
  firmware
  loadables
  loadables

  $ fdtget simple-bin.fit.fit /configurations/config-1 loadables
  u-boot

  $ mkimage -l simple-bin.fit.fit
  FIT description: FIT image for U-Boot with bl31 (TF-A)
  Created: Thu Feb 24 17:36:36 2022
   Image 0 (u-boot)
Description:  U-Boot (64-bit)
Created:  Thu Feb 24 17:36:36 2022
Type: Standalone Program
Compression:  uncompressed
Data Size:727192 Bytes = 710.15 KiB = 0.69 MiB
Architecture: AArch64
Load Address: 0x0020
Entry Point:  

Re: [PATCH v2 19/25] binman: Keep a separate list of entries for fit

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> The current implementation sets up the FIT entries but then deletes the
> 'generator' ones so they don't appear in the final image.

They still show up in the fdtmap if I add one to rockchip-u-boot.dtsi:

  $ binman ls -i u-boot-rockchip.bin
  NameImage-pos  Size Entry-typeOffset
  -
  main-section0   103520  section 0
mkimage   01a000  mkimage 0
fit   1a000e8d74  fit 1a000
  u-boot  1a644b1898  section   644
u-boot-nodtb  1a644b1898  u-boot-nodtb0
  @atf-SEQ00  section 0
atf-bl31  00  atf-bl310
  @tee-SEQ00  section 0
tee-os00  tee-os  0
  @fdt-SEQ00  section 0
fdtmap   102d74  79c  fdtmap 102d74

But not simple-bin.map:

  ImagePosOffset  Size  Name
      00103520  main-section
       0001a000  mkimage
  0001a000   0001a000  000e8d74  fit
  0001a6440644  000b1898  u-boot
  0001a644   000b1898  u-boot-nodtb
  00102d74   00102d74  079c  fdtmap

This happens in v1 as well, but I hadn't checked it then.

(The "fit" size and "fdtmap" offset are off by 0x10 too, but I'm not
sure why yet.)

> This is a bit clumsy. We cannot build the image more than once, since the
> generator entries are lost during the first build. Binman requires that
> calling BuildSectionData() multiple times returns a valid result each
> time.

I think the generator entries should be turned into concrete entries and
be removed in _gen_entries(), so BuildSectionData() should work on the
entries that were generated. This way the individual entries would show
up in fdtmap and could be binman-extracted/replaced as well.

For FDTs we can generate blob entries for each file, for ELFs maybe we
can split them into files like the script used to do (bl31_0x.bin)
and do the same?

Maybe some new entry types, "data" for arbitrary data unrelated to a
file whose contents we can set, or "elf-segment" that can extract a
segment from an ELF file (but I don't like the information loss there).

> Keep a separate, private list which includes the generator nodes and use
> that where needed, to correct this problem. Ensure that the missing list
> includes removed generator entries too.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> (no changes since v1)

I'm more and more convinced that generator nodes needs a thorough
redesign, but the patch is consistent with status quo, so:

Reviewed-by: Alper Nebi Yasak 

>  tools/binman/etype/fit.py | 33 -
>  1 file changed, 28 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py
> index e1b056f56e..30b20a07a2 100644
> --- a/tools/binman/etype/fit.py
> +++ b/tools/binman/etype/fit.py
> @@ -163,10 +163,15 @@ class Entry_fit(Entry_section):
>  key: relative path to entry Node (from the base of the FIT)
>  value: Entry_section object comprising the contents of this
>  node
> +_priv_entries: Internal copy of _entries which includes 
> 'generator'
> +entries which are used to create the FIT, but should not be
> +processed as real entries. This is set up once we have the
> +entries

Maybe this could be "_templates" or "_entry_generators" and only keep
track of the generator entries.

>  """
>  super().__init__(section, etype, node)
>  self._fit = None
>  self._fit_props = {}
> +self._priv_entries = {}
>  
>  for pname, prop in self._node.props.items():
>  if pname.startswith('fit,'):
>  
> [...]


Re: [PATCH v2 18/25] binman: Update fit to use node instead of subnode

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> It doesn't make sense to use 'subnode' as a function parameter since it
> is just a 'node' so far as the function is concerned. Update two functions
> to use 'node' instead.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> (no changes since v1)
> 
>  tools/binman/etype/fit.py | 16 
>  1 file changed, 8 insertions(+), 8 deletions(-)

Reviewed-by: Alper Nebi Yasak 


Re: [PATCH v2 17/25] binman: Add a consistent way to report errors with fit

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> Add a new function to handling reporting errors within a particular
> subnode of the FIT description. This can be used to make the format of
> these errors consistent.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> (no changes since v1)
> 
>  tools/binman/etype/fit.py | 33 +
>  tools/binman/ftest.py |  2 +-
>  2 files changed, 26 insertions(+), 9 deletions(-)

Reviewed-by: Alper Nebi Yasak 

I don't like entry.Raise(msg) in general, if it were me I would define
Exception subclasses and e.g. raise CustomError(self, subnode) for the
various error conditions, but that's beside the point.

> diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py
> index 70966028e8..50a9179f9f 100644
> --- a/tools/binman/etype/fit.py
> +++ b/tools/binman/etype/fit.py
> [...]
> @@ -273,6 +274,20 @@ class Entry_fit(Entry_section):
>  
>  return tools.read_file(output_fname)
>  
> +def _raise(self, base_node, node, msg):
> +"""Raise an error with a paticular FIT subnode
> +
> +Args:
> +base_node (Node): Base Node of the FIT (with 'description' 
> property)
> +node (Node): FIT subnode containing the error
> +msg (str): Message to report
> +
> +Raises:
> +ValueError, as requested
> +"""
> +rel_path = node.path[len(base_node.path) + 1:]

Can base_node be anything except self._node here, why not use that?

> +self.Raise(f"subnode '{rel_path}': {msg}")

The names are a bit inconsistent, but I guess you intend to change
Entry.Raise() to Entry._raise() later on...

> +
>  def _build_input(self):
>  """Finish the FIT by adding the 'data' properties to it
>  
> [...]


Re: [PATCH v2 16/25] binman: Fix some pylint warnings in fit

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> Some warnings have crept in, so fix those that are easy to fix.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> (no changes since v1)
> 
>  tools/binman/etype/fit.py | 50 +++
>  1 file changed, 25 insertions(+), 25 deletions(-)

Reviewed-by: Alper Nebi Yasak 


Re: [PATCH v2 15/25] binman: Read the fit entries only once

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> At present the entries are read twice, once by the entry_Section class
> and once by the FIT implementation. This is harmless but can be confusing
> when debugging. Fix it.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> (no changes since v1)
> 
>  tools/binman/etype/fit.py | 1 -
>  1 file changed, 1 deletion(-)

This is actually necessary so that we can use 'self' as the section in
Entry.Create(self, ...) when creating /image/* sections, which requires
some section-related attributes set by super().ReadNode(). It was one of
the things I was planning to fix as well, thanks!

Reviewed-by: Alper Nebi Yasak 

> diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py
> index 2b82955226..7b0c94dfee 100644
> --- a/tools/binman/etype/fit.py
> +++ b/tools/binman/etype/fit.py
> @@ -185,7 +185,6 @@ class Entry_fit(Entry_section):
>  self.mkimage = None
>  
>  def ReadNode(self):
> -self.ReadEntries()
>  super().ReadNode()

The entire function can be removed, but I think some stuff from
__init__() actually belongs here so I'm fine with keeping it.

>  
>  def _get_operation(self, subnode):


Re: [PATCH v2 14/25] binman: Allow mkimage to use a non-zero fake-blob size

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> Unfortunately mkimage gets upset with zero-sized files. Update the
> ObtainContents() method to support specifying the size, if a fake blob is
> created.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> Changes in v2:
> - Add a patch to allow mkimage to use a non-zero fake-blob size
> 
>  tools/binman/entry.py | 11 ---
>  tools/binman/etype/_testing.py|  2 +-
>  tools/binman/etype/blob.py|  5 +++--
>  tools/binman/etype/mkimage.py | 13 -
>  tools/binman/etype/section.py |  2 +-
>  tools/binman/ftest.py | 10 ++
>  tools/binman/test/229_mkimage_missing.dts | 18 ++
>  7 files changed, 53 insertions(+), 8 deletions(-)
>  create mode 100644 tools/binman/test/229_mkimage_missing.dts

I don't exactly like this, but can't think of a nice alternative either.

Reviewed-by: Alper Nebi Yasak 

> [...]
> 
> diff --git a/tools/binman/etype/mkimage.py b/tools/binman/etype/mkimage.py
> index 9f4717e4ea..5f6def2287 100644
> --- a/tools/binman/etype/mkimage.py
> +++ b/tools/binman/etype/mkimage.py
> @@ -51,8 +51,9 @@ class Entry_mkimage(Entry):
>  self.ReadEntries()
>  
>  def ObtainContents(self):
> +# Use a non-zero size for any fake files to keep mkimage happy
>  data, input_fname, uniq = self.collect_contents_to_file(
> -self._mkimage_entries.values(), 'mkimage')
> +self._mkimage_entries.values(), 'mkimage', 1024)

I kind of want to say that mkimage-the-etype should be able to handle
here whatever it gets from subentries (maybe by writing a single-byte
file itself), and mkimage-the-executable should be able to handle
zero-size files, but I'm not confident in those opinions.

>  if data is None:
>  return False
>  output_fname = tools.get_output_filename('mkimage-out.%s' % uniq)
> [...]


Re: [PATCH v2 13/25] binman: Make fake blobs zero-sized by default

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> On x86 devices having even a small amount of data can cause an overlap
> between regions. For example, bayleybay complains when the intel-vga
> region overlaps with u-boot-ucode:
> 
>ImagePosOffset  Size  Name
>  0080  main-section
> ff80  0080  intel-descriptor
> ff800400  0080  intel-me
> fff0  00098f24  u-boot-with-ucode-ptr
> fff98f24  1aa0  u-boot-dtb-with-ucode
> fff9a9d0  0002a000  u-boot-ucode
> fffb  0080  intel-vga
>...
> 
> It is safer to use an empty file in most cases. Add an option to set the
> size for those uses that need it.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> Changes in v2:
> - Add a patch to make fake blobs zero-sized by default
> 
>  tools/binman/entry.py | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> diff --git a/tools/binman/entry.py b/tools/binman/entry.py

Reviewed-by: Alper Nebi Yasak 

Later on, I think adding 'min-size' and 'max-size' properties for
entries could be useful for a few things including this.


Re: [PATCH v2 12/25] binman: Change how faked blobs are created

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> At present fake blobs are created but internally an empty blob is used.
> Change it to use the contents of the faked file. Also return whether the
> blob was faked, in case the caller needs to know that.
> 
> Add a TODO to put fake blobs in their own directory.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> Changes in v2:
> - Add a patch to change how faked blobs are created
> 
>  tools/binman/binman.rst | 3 ++-
>  tools/binman/entry.py   | 9 ++---
>  tools/binman/etype/blob.py  | 7 ---
>  tools/binman/etype/blob_ext_list.py | 2 +-
>  4 files changed, 13 insertions(+), 8 deletions(-)

I feel a bit uneasy about all this fake file stuff, but can't figure out
exactly why. I guess the patch doesn't make it that worse.

Reviewed-by: Alper Nebi Yasak 

> diff --git a/tools/binman/binman.rst b/tools/binman/binman.rst
> index 85f8337a31..a90364f2fb 100644
> --- a/tools/binman/binman.rst
> +++ b/tools/binman/binman.rst
> @@ -1500,7 +1500,8 @@ Some ideas:
>  - Figure out how to make Fdt support changing the node order, so that
>Node.AddSubnode() can support adding a node before another, existing node.
>Perhaps it should completely regenerate the flat tree?
> -
> +- Put faked files into a separate subdir and remove them on start-up, to 
> avoid
> +  seeing them as 'real' files on a subsequent run

Do we need to create actual files, or is it a convenience thing for blob
entry types (because they already read their contents from files)?

Also, maybe it's better to create them somewhere in the /tmp/binman.*
directories so they disappear without effort.

>  
>  --
>  Simon Glass 
> diff --git a/tools/binman/entry.py b/tools/binman/entry.py
> index 00a13c5839..2fb0050da5 100644
> --- a/tools/binman/entry.py
> +++ b/tools/binman/entry.py
> @@ -997,15 +997,18 @@ features to produce new behaviours.
>  fname (str): Filename to check
>  
>  Returns:
> -fname (str): Filename of faked file
> +tuple:
> +fname (str): Filename of faked file
> +bool: True if the blob was faked, False if not
>  """
>  if self.allow_fake and not pathlib.Path(fname).is_file():
>  outfname = tools.get_output_filename(os.path.basename(fname))
>  with open(outfname, "wb") as out:
>  out.truncate(1024)
>  self.faked = True
> -return outfname
> -return fname
> +tout.info(f"Entry '{self._node.path}': Faked file '{outfname}'")
> +return outfname, True
> +return fname, False

Can't callers use self.faked for this?

I think I see an edge case when calling this multiple times for the same
filename, only the first call would recognize it being a fake file and
only the first-entry-to-call would consider itself faked.

>  
>  def CheckFakedBlobs(self, faked_blobs_list):
>  """Check if any entries in this section have faked external blobs
> diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py
> index 25ec5d26c9..89f089e740 100644
> --- a/tools/binman/etype/blob.py
> +++ b/tools/binman/etype/blob.py
> @@ -41,10 +41,11 @@ class Entry_blob(Entry):
>  self.external and self.section.GetAllowMissing())
>  # Allow the file to be missing
>  if not self._pathname:
> -self._pathname = self.check_fake_fname(self._filename)
> -self.SetContents(b'')
> +self._pathname, faked = self.check_fake_fname(self._filename)
>  self.missing = True
> -return True
> +if not faked:
> +self.SetContents(b'')
> +return True
>  
>  self.ReadBlobContents()
>  return True
>  
> [...]


Re: [PATCH v2 10/25] binman: Refactor fit to generate output at the end

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> At present the fit implementation creates the output tree while
> scanning the FIT description. Then it updates the tree later when the
> data is known.
> 
> This works, but is a bit confusing, since it requires mixing the scanning
> code with the generation code, with a fix-up step at the end.
> 
> It is actually possible to do this in two phases, one to scan everything
> and the other to generate the FIT. Thus the FIT is generated in one pass,
> when everything is known.

Doing it in one go makes sense to me as well. In general I like the way
distinct processing actions/steps are being split into their own blocks
or so, and I think this helps move things toward that.

> Update the code accordingly. The only functional change is that the 'data'
> property for each node are now last instead of first, which is really a
> more natural position. Update the affected test to deal with this.
> 
> One wrinkle is that the calculated properties (image-pos, size and offset)
> are now added before the FIT is generated. so we must filter these out
> when copying properties from the binman description to the FIT.
> 
> Most of the change here is splitting out some of the code from the
> ReadEntries() implementation into _BuildInput(). So despite the large
> diff, most of the code is the same. It is not feasible to split this patch
> up, so far as I can tell.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> Changes in v2:
> - Add new patch to refactor fit to generate output at the end
> 
>  tools/binman/etype/fit.py  | 178 ++---
>  tools/binman/ftest.py  |  13 +-
>  tools/binman/test/224_fit_bad_oper.dts |   2 -
>  3 files changed, 109 insertions(+), 84 deletions(-)

Reviewed-by: Alper Nebi Yasak 

I still wrote some weird ideas below, mostly for the future, since this
patch is mostly moving code around which is fine as is.

> diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py
> index 2d4c5f6545..61c72780e9 100644
> --- a/tools/binman/etype/fit.py
> +++ b/tools/binman/etype/fit.py
> @@ -209,6 +209,81 @@ class Entry_fit(Entry_section):
>  return oper
>  
>  def ReadEntries(self):
> +def _add_entries(base_node, depth, node):
> +"""Add entries for any nodes that need them
> +
> +Args:
> +base_node: Base Node of the FIT (with 'description' property)
> +depth: Current node depth (0 is the base 'fit' node)
> +node: Current node to process
> +
> +He we only need to provide binman entries which are used to 
> define

He -> Here ?

> +the 'data' for each image. We create an entry_Section for each.
> +"""
> +rel_path = node.path[len(base_node.path):]
> +in_images = rel_path.startswith('/images')
> +has_images = depth == 2 and in_images
> +if has_images:
> +# This node is a FIT subimage node (e.g. "/images/kernel")
> +# containing content nodes. We collect the subimage nodes and
> +# section entries for them here to merge the content subnodes
> +# together and put the merged contents in the subimage node's
> +# 'data' property later.
> +entry = Entry.Create(self.section, node, etype='section')
> +entry.ReadNode()

I plan to change 'self.section' to 'self' here later, fixes extracting
wrong contents for FIT subentries.

> +# The hash subnodes here are for mkimage, not binman.
> +entry.SetUpdateHash(False)
> +self._entries[rel_path] = entry
> +

I also plan to change this to a single-level node name instead of the
relative path, lets 'binman extract fit/u-boot' etc. run at all.

> +for subnode in node.subnodes:
> +_add_entries(base_node, depth + 1, subnode)
> +
> +_add_entries(self._node, 0, self._node)

I think it's especially visible here what I meant by switching away from
recursion: this recurses through every node but only does anything on
immediate subnodes of "/images" (for now?).

> +
> +def BuildSectionData(self, required):
> +"""Build FIT entry contents
> +
> +This adds the 'data' properties to the input ITB (Image-tree Binary)
> +then runs mkimage to process it.
> +
> +Args:
> +required: True if the data must be present, False if it is OK to
> +return None

I forgot to handle 'required' while converting FIT to section...

> +
> +Returns:
> +Contents of the section (bytes)
> +"""
> +data = self._BuildInput()
> +uniq = self.GetUniqueName()
> +input_fname = tools.get_output_filename('%s.itb' % uniq)
> +output_fname = tools.get_output_filename('%s.fit' % uniq)
> +tools.write_file(input_fname, data)
> +

Re: [PATCH v2 11/25] binman: Rename tools parameter to btools

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> This shadows the patman.tools library so rename it to avoid a pylint
> warning.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> (no changes since v1)
> 
>  tools/binman/entry.py| 4 ++--
>  tools/binman/etype/fit.py| 6 +++---
>  tools/binman/etype/gbb.py| 4 ++--
>  tools/binman/etype/intel_ifwi.py | 4 ++--
>  tools/binman/etype/mkimage.py| 4 ++--
>  tools/binman/etype/section.py| 4 ++--
>  tools/binman/etype/vblock.py | 4 ++--
>  7 files changed, 15 insertions(+), 15 deletions(-)

Reviewed-by: Alper Nebi Yasak 



Re: [PATCH v2 09/25] binman: Rename ExpandEntries to gen_entries

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> Leave the 'expand' term for use by entry types which have an expanded
> version of themselves. Rename this method to indicate that it generates
> subentries.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> Changes in v2:
> - Add patch to rename ExpandEntries to gen_entries
> 
>  tools/binman/control.py  | 2 +-
>  tools/binman/entry.py| 4 ++--
>  tools/binman/etype/blob_phase.py | 2 +-
>  tools/binman/etype/files.py  | 2 +-
>  tools/binman/etype/section.py| 6 +++---
>  5 files changed, 8 insertions(+), 8 deletions(-)

Reviewed-by: Alper Nebi Yasak 


Re: [PATCH v2 08/25] binman: Rename ExpandToLimit to extend_to_limit

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> The word 'expand' is used for entries which generate subentries. It is
> also used for entries that can have an '_expanded' version which is used
> to break out its contents.
> 
> Rather than talking about expanding an entry's size, use the term
> 'extending'. It is slightly more precise and avoids the above conflicts.
> 
> This change renders the old 'expand-size' property invalid, so add an
> error check for that.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> Changes in v2:
> - Add patch to rename ExpandToLimit to extend_to_limit
> 
>  tools/binman/binman.rst   |  2 +-
>  tools/binman/entry.py |  8 +---
>  tools/binman/etype/section.py | 10 +-
>  tools/binman/ftest.py |  8 
>  tools/binman/test/088_expand_size.dts |  8 
>  tools/binman/test/089_expand_size_bad.dts |  2 +-
>  tools/binman/test/225_expand_size_bad.dts | 10 ++
>  7 files changed, 34 insertions(+), 14 deletions(-)
>  create mode 100644 tools/binman/test/225_expand_size_bad.dts

I haven't ever used expand-size, but:

Reviewed-by: Alper Nebi Yasak 

> diff --git a/tools/binman/binman.rst b/tools/binman/binman.rst
> index 0061e43659..85f8337a31 100644
> --- a/tools/binman/binman.rst
> +++ b/tools/binman/binman.rst
> @@ -480,7 +480,7 @@ image-pos:
>  for each entry. This makes it easy to find out exactly where the entry
>  ended up in the image, regardless of parent sections, etc.
>  
> -expand-size:
> +extend-size:
>  Expand the size of this entry to fit available space. This space is only

Expand -> Extend

>  limited by the size of the image/section and the position of the next
>  entry.
> diff --git a/tools/binman/entry.py b/tools/binman/entry.py
> index de8526618d..a59eb56f14 100644
> --- a/tools/binman/entry.py
> +++ b/tools/binman/entry.py
> @@ -233,6 +233,8 @@ class Entry(object):
>  """
>  if 'pos' in self._node.props:
>  self.Raise("Please use 'offset' instead of 'pos'")
> +if 'expand-size' in self._node.props:
> +self.Raise("Please use 'extend-size' instead of 'expand-size'")
>  self.offset = fdt_util.GetInt(self._node, 'offset')
>  self.size = fdt_util.GetInt(self._node, 'size')
>  self.orig_offset = fdt_util.GetInt(self._node, 'orig-offset')
> @@ -260,7 +262,7 @@ class Entry(object):
> self.align_size)
>  self.align_end = fdt_util.GetInt(self._node, 'align-end')
>  self.offset_unset = fdt_util.GetBool(self._node, 'offset-unset')
> -self.expand_size = fdt_util.GetBool(self._node, 'expand-size')
> +self.expand_size = fdt_util.GetBool(self._node, 'extend-size')

Consider also changing the attribute name, I don't see many instances of
it with git-grep. Maybe even the test dts names.

>  self.missing_msg = fdt_util.GetString(self._node, 'missing-msg')
>  
>  # This is only supported by blobs and sections at present
> @@ -772,8 +774,8 @@ features to produce new behaviours.
>  name = '%s.%s' % (node.name, name)
>  return name
>  
> -def ExpandToLimit(self, limit):
> -"""Expand an entry so that it ends at the given offset limit"""
> +def extend_to_limit(self, limit):
> +"""Extent an entry so that it ends at the given offset limit"""

Extent -> Extend

>  if self.offset + self.size < limit:
>  self.size = limit - self.offset
>  # Request the contents again, since changing the size requires 
> that
> [...]


Re: [PATCH v2 07/25] binman: Tweak collect_contents_to_file() and docs

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> Update the return value of this function, fix the 'create' typo and
> update the documentation for clarity.
> 
> Signed-off-by: Simon Glass 
> Suggested-by: Alper Nebi Yasak 
> ---
> 
> Changes in v2:
> - Add new patch to tweak collect_contents_to_file() and docs
> 
>  tools/binman/binman.rst   | 25 +++--
>  tools/binman/entry.py |  8 
>  tools/binman/etype/mkimage.py |  2 +-
>  3 files changed, 20 insertions(+), 15 deletions(-)

Reviewed-by: Alper Nebi Yasak 


Re: [PATCH v2 06/25] elf: Rename load_segments() and module failure

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> Rename this function to make it clear that it only reads loadable
> segments. Also update the error for missing module to better match the
> message emitted by Python.
> 
> Signed-off-by: Simon Glass 
> Suggested-by: Alper Nebi Yasak 
> ---
> 
> Changes in v2:
> - Add new patch to rename load_segments() and module failure
> 
>  tools/binman/elf.py  |  6 +++---
>  tools/binman/elf_test.py | 18 +-
>  2 files changed, 12 insertions(+), 12 deletions(-)

Reviewed-by: Alper Nebi Yasak 


Re: [PATCH v2 05/25] dtoc: Tidy up implementation of AddStringList()

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> Refactor this to avoid a loop. Also add a test for an empty string.
> 
> Signed-off-by: Simon Glass 
> Suggested-by: Alper Nebi Yasak 
> ---
> 
> Changes in v2:
> - Add new patch to tidy up implementaiton of AddStringList()
> 
>  tools/dtoc/fdt.py  | 4 +---
>  tools/dtoc/test_fdt.py | 6 ++
>  2 files changed, 7 insertions(+), 3 deletions(-)

Reviewed-by: Alper Nebi Yasak 

> diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
> index c16909a876..d933972918 100644
> --- a/tools/dtoc/fdt.py
> +++ b/tools/dtoc/fdt.py
> @@ -516,9 +516,7 @@ class Node:
>  Returns:
>  Prop added
>  """
> -out = b''
> -for string in val:
> -out += bytes(string, 'utf-8') + b'\0'
> +out = b'\0'.join(bytes(s, 'utf-8') for s in val) + b'\0' if val else 
> b''

Meh, it turned out uglier than I thought it would be. Either is fine
really, I didn't add "Reviewed-by"s for v1 only because I thought you'd
need to send a v2 for the later FIT stuff anyway.

>  return self.AddData(prop_name, out)
>  
>  def AddInt(self, prop_name, val):
>  
> [...]


Re: [PATCH v2 04/25] spl: Correct Kconfig help for TPL_BINMAN_SYMBOLS

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> Fix the help which should refer to TPL, not SPL.
> 
> Signed-off-by: Simon Glass 
> Suggested-by: Alper Nebi Yasak 
> ---
> 
> Changes in v2:
> - Add new patch to correct Kconfig help for TPL_BINMAN_SYMBOLS
> 
>  common/spl/Kconfig | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Alper Nebi Yasak 


Re: [PATCH v2 03/25] moveconfig: Use re.fullmatch() to avoid extra check

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> Simplify the code by using the available function.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> Changes in v2:
> - Add new patch to use re.fullmatch() to avoid extra check
> 
>  tools/moveconfig.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Alper Nebi Yasak 

> diff --git a/tools/moveconfig.py b/tools/moveconfig.py
> index dea60f4661..4b0e2e250b 100755
> --- a/tools/moveconfig.py
> +++ b/tools/moveconfig.py
> @@ -1610,8 +1610,8 @@ def defconfig_matches(configs, re_match):
>  bool: True if any CONFIG matches the regex
>  """
>  for cfg in configs:
> -m_cfg = re_match.match(cfg)
> -if m_cfg and m_cfg.span()[1] == len(cfg):
> +m_cfg = re_match.fullmatch(cfg)
> +if m_cfg:

Could skip the variable entirely.

>  return True
>  return False
>  


Re: [PATCH v2 02/25] moveconfig: Remove remove_defconfig()

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> This is not necessary if simpler code is used. Use the split function and
> drop the unnecessary []
> 
> Signed-off-by: Simon Glass 
> Suggested-by: Alper Nebi Yasak 
> ---
> 
> Changes in v2:
> - Add new patch to remove remove_defconfig()
> 
>  tools/moveconfig.py | 13 +
>  1 file changed, 1 insertion(+), 12 deletions(-)

Reviewed-by: Alper Nebi Yasak 


Re: [PATCH v2 01/25] dtoc: Make GetArgs() more flexible

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 02:00, Simon Glass wrote:
> At present it is not possible to have arguments whic include spaces.

whic -> which

> Update the function to only split the args if the property is a single
> string. This is a bit inconsistent, but might still be useful.
> 
> Signed-off-by: Simon Glass 
> Suggested-by: Alper Nebi Yasak 
> ---
> 
> Changes in v2:
> - Add new patch to make GetArgs() more flexible
> 
>  tools/dtoc/fdt_util.py   | 8 ++--
>  tools/dtoc/test/dtoc_test_simple.dts | 2 ++
>  tools/dtoc/test_fdt.py   | 6 +-
>  3 files changed, 13 insertions(+), 3 deletions(-)

Reviewed-by: Alper Nebi Yasak 

The use cases and design needs more thinking still, but later.


Re: [PATCH 20/24] binman: Support splitting an ELF file into multiple nodes

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 01:59, Simon Glass wrote:
> On Tue, 15 Feb 2022 at 04:53, Alper Nebi Yasak  
> wrote:
>> On 08/02/2022 21:50, Simon Glass wrote:
>>> +fit,load
>>> +Generates a `load = <...>` property with the load address of the
>>> +segmnet
>>> +
>>> +fit,entry
>>> +Generates a `entry = <...>` property with the entry address of the
>>> +ELF. This is only produced for the first entry
>>> +
>>> +fit,data
>>> +Generates a `data = <...>` property with the contents of the 
>>> segment
>>
>> I think all these should be done by default. I don't see the point of
>> not setting the properties, or setting them manually to values that will
>> be the same for multiple nodes.
> 
> My intent is to make things discoverable and obvious, so that magic
> processing is explicit.

OK then.

>> Instead of putting these into the images subnode, we could have
>> images-level subnodes for the operations. For example, instead of the above:
>>
>>images@gen-fdt-nodes {
>>fdt-list = "of-list";
>>
>>fdt {
>>type = "flat_dt";
>>compression = "none";
>>};
>>};
> 
> What does that mean, though? I presume it creates a second images {}
> node, which is fine as dtc will merge them. But what about ordering?

I imagined images@oper, configurations@oper would be binman-only control
nodes that generate and append arbitrary nodes/entries inside whatever
node name precedes the @oper. The meaning of what's inside the @oper
nodes and what's generated would be solely defined by the operation.

Honestly, I didn't think of ordering because I assumed it didn't matter
inside FIT. It's a shortcoming of this design if it's important.

> I certainly prefer this in terms of elegance. I'm just not convinced
> that people will understand it as well.
> 
>>
>> We can remove the -SEQ if we always append a sequence number, and we can
>> set "description" to "NAME.dtb" when it's missing, or do the replacement
>> when it's given. We can go further and use "%s", "%(name)s" or "{name}"
>> instead of "NAME" for python-ish formatting and likewise for the
>> sequence number.
> 
> Yes, but again this adds more magic. For the Python formatting, we
> still need to restrict what is put in there - e.g. we cannot just eval
> an arbitrary varaible.

Python only formats with what you give it (except for f-strings):

>>> val = "test"
>>> vals = {"name": "rk3399-gru-kevin", "seq": 1}

>>> "conf-%(seq)d: %(name)s.dtb" % vals
'conf-1: rk3399-gru-kevin.dtb'

>>> "%(val)s" % vals
KeyError: 'val'

>>> "conf-{seq}: {name}.dtb".format(**vals)
'conf-1: rk3399-gru-kevin.dtb'

>>> "{val}".format(**vals)
KeyError: 'val'

But neither format style can go in a node name, so if you want the
sequence number explicit in those I guess we're stuck with -SEQ and
everything consistent with it.

>>> [...]
> 
> We should talk about this some more though. I'm a bit worried it will
> get complaints about too much magic. I am trying to make it obvious
> that nodes get generated in certain places.

OK. I know I'm too biased towards magic, so won't insist much on those
parts.

> [...]
> 
> Thanks for all the comments and ideas. I think this all need a little
> more thought...

I'll try replying to the v2 for the things changed in v2.


Re: [PATCH 09/24] dtoc: Support reading a list of arguments

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 01:58, Simon Glass wrote:
> On Tue, 15 Feb 2022 at 04:53, Alper Nebi Yasak  
> wrote:
>>> diff --git a/tools/dtoc/fdt_util.py b/tools/dtoc/fdt_util.py
>>> index 19eb13aef3..59e065884f 100644
>>> --- a/tools/dtoc/fdt_util.py
>>> +++ b/tools/dtoc/fdt_util.py
>>> @@ -184,6 +184,18 @@ def GetStringList(node, propname, default=None):
>>>  return [strval]
>>>  return value
>>>
>>> +def GetArgs(node, propname):
>>> +prop = node.props.get(propname)
>>> +if not prop:
>>> +raise ValueError(f"Node '{node.path}': Expected property 
>>> '{propname}'")
>>> +if prop.bytes:
>>> +value = GetStringList(node, propname)
>>> +else:
>>> +value = []
>>
>> Isn't GetStringList(node, propname, default=[]) enough here, why check
>> prop.bytes?
> 
> Because the default value is for when there is no such property. In
> this case there is a property, so the default will not be used.

Ah, it's the same as dict.get(). Don't know why I got confused there.

>>> +lists = [v.split() for v in value]
>>
>> Use shlex.split() to handle quotes inside the strings, so that we can
>> pass args with spaces inside them. e.g. mkimage -n "U-Boot v2022.04".
>> Or each list element could be a single argument with no splitting done.
>>
>> I also wish mkimage -n "U-Boot $(UBOOTRELEASE) for $(BOARD) board" from
>> Makefile was possible, but can't think of a great way.
> 
> That's actually not what I was trying to do. I want "-n first" to mean
> two args. It is like normally command-line processing.
> 
> Of course this means that it isn't possible to do what you want here.
> I am not sure of a good way to support that.
> 
> One way would be to only split into args if there is a single string
> in the list? I will try that for now.

That sounds like a reasonable middle ground if you really want to do
splitting.

>>> +args = [x for l in lists for x in l]
>>> +return args
>>> +
>>
>> Anyway, I don't think this belongs here as argument lists are not really
>> a device-tree construct. It would be better in a new binman entry type
>> ("command"?) which mkimage can subclass from.
> 
> Well I am trying to keep all typing stuff in here, i.e. everything
> that guesses what is meant by a DT property. That way I can have DT
> tests and expand as needed. I agree this is a borderline case, but I'm
> not sure it is a good to have lots of logic (that depends on the
> internal working of Fdt) in a different file. E.g. I hate all of this
> code and would like to refactor it to put more stuff in pylibfdt one
> day.

That's fair, and I like the idea of refactoring things into pylibfdt.

>>
>>>  def GetBool(node, propname, default=False):
>>>  """Get an boolean from a property
>>>
>>> diff --git a/tools/dtoc/test/dtoc_test_simple.dts 
>>> b/tools/dtoc/test/dtoc_test_simple.dts
>>> index 4c2c70af22..2d321fb034 100644
>>> --- a/tools/dtoc/test/dtoc_test_simple.dts
>>> +++ b/tools/dtoc/test/dtoc_test_simple.dts
>>> @@ -62,5 +62,6 @@
>>>
>>>   orig-node {
>>>   orig = <1 23 4>;
>>> + args = "-n first", "second", "-p", "123,456", "-x";
>>
>> Could be useful to add an argument with single quotes, and one with
>> escaped double quotes.
> 
> I reverted the shlex change in the end...can we do that in a separate
> patch? I think it has interesting implications for the Makefile and we
> should think about what tests to add and what the use cases are.

OK, but I'll need to focus on other things and might forget to ping
later for this...


Re: [PATCH 06/24] dtoc: Support adding a string list to a device tree

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 01:58, Simon Glass wrote:
> On Tue, 15 Feb 2022 at 04:53, Alper Nebi Yasak  
> wrote:
>> On 08/02/2022 21:49, Simon Glass wrote:
>>> diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
>>> index 32a7aa9829..e7197f8f12 100644
>>> --- a/tools/dtoc/fdt.py
>>> +++ b/tools/dtoc/fdt.py
>>> @@ -501,6 +501,24 @@ class Node:
>>>  val = bytes(val, 'utf-8')
>>>  return self.AddData(prop_name, val + b'\0')
>>>
>>> +def AddStringList(self, prop_name, val):
>>> +"""Add a new string-list property to a node
>>> +
>>> +The device tree is marked dirty so that the value will be written 
>>> to
>>> +the blob on the next sync.
>>> +
>>> +Args:
>>> +prop_name: Name of property to add
>>> +val (list of str): List of strings to add
>>> +
>>> +Returns:
>>> +Prop added
>>> +"""
>>> +out = b''
>>> +for string in val:
>>> +out += bytes(string, 'utf-8') + b'\0'
>>> +return self.AddData(prop_name, out)
>>
>> If val is an empty list this would try to set a zero-byte data, but then
>> the Prop class considers that a boolean True.
> 
> Yes, but I believe that is correct, isn't it? I did propose a change
> to DT bool props but it has not got anywhere.

I just wasn't sure about the semantics and wanted to highlight what
might be an edge case. Looking again, I think this is binary-wise
correct, but GetString and GetStringList would return True and [True]
for these boolean props where I'd want None and [].


Re: [PATCH 03/24] spl: x86: Correct the binman symbols for SPL

2022-03-03 Thread Alper Nebi Yasak
On 24/02/2022 01:58, Simon Glass wrote:
> Hi Alper,
> 
> On Tue, 15 Feb 2022 at 04:52, Alper Nebi Yasak  
> wrote:
>>
>> On 08/02/2022 21:49, Simon Glass wrote:
>>> These symbols are incorrect, meaning that binman cannot find the
>>> associated entry. This leads to errors like:
>>>
>>> binman: Section '/binman/simple-bin': Symbol '_binman_spl_prop_size'
>>>in entry '/binman/simple-bin/u-boot-spl/u-boot-spl-nodtb':
>>>Entry 'spl' not found in list (mkimage,u-boot-spl-nodtb,
>>>u-boot-spl-bss-pad,u-boot-spl-dtb,u-boot-spl,u-boot-img,main-section)
>>
>> I can't help but feel like this is a bug with entry expansion where the
>> name of the expanded node is ignored (and replaced by its type?) when it
>> comes to the symbols.

I think I misunderstood that error message. I thought this error was for
a board with the x86 dtsi where it wasn't finding an "spl" entry that
actually existed. Not seeing "spl" in the list I assumed its name was
being lost for some reason.

Now I realize it must be for a board where "u-boot-spl" exists instead
of "spl" (which the symbol was looking for), and you were correcting the
symbol to match that and furthermore fixing the x86 dtsi to match the
corrected symbol.

(Perhaps it was a Rockchip board, related to the rest of the series :P )

> 
> The problem is that there is only really one value for a symbol. E.g.
> U-Boot has an image-pos and it doesn't matter what you call it; it is
> the same value.
> 
> So does it make sense to disallow different names for the same thing?
> See testSymbol() which actually creates two SPLs and checks that both
> are updated. That is the opposite to what you are talking about, of
> course, since it is the properties of the 'u-boot' entry which are
> used to write into the SPL entries.
> 
> If we move to using the name instead, we could have two different
> copies of U-Boot in the image and each SPL could refer to a different
> one. At present this is done by puting the pairs into their own
> section.
> 
> I think this needs more discussionwhat do you think?

I think it's better to use the names, since there are reasonable cases
where an image would have multiple entries of the same type: A/B updates
and read-only recovery copies (like in Chrome OS firmware, or I guess
eventually with your VPL series?).

>From what I can tell, the symbols are indeed set based on the entry
names (not entry types), so multiple entries of the same type but with
different names should already be working fine -- except no symbols are
declared on the C side for arbitrary names. I guess putting multiple
copies in different sections with different "name-prefix" values works
fine the same way.

However I lightly suspect this might be breaking down a bit with entry
expansion, since the nodes generated in differently-named sections could
have the same name (the desired entry type), but didn't test it or
anything. I guess it works since the symbol would be declared for the
node-to-expand anyway, with the correctly unique name?

(Maybe the symbols might be based on the path instead, but that could be
very verbose. I see an idea in binman.rst for a C library that can read
binman things from device tree, which sounds nice for this as well.)


[PATCH 15/17] serial: Add semihosting driver

2022-03-03 Thread Sean Anderson
This adds a serial driver which uses semihosting calls to read and write
to the host's console. For convenience, if CONFIG_DM_SERIAL is enabled,
we will instantiate a serial driver. This allows users to enable this
driver (which has no physical device) without modifying their device
trees or board files. We also implement a non-DM driver for SPL, or for
much faster output in U-Boot proper.

There are three ways to print to the console:

Method Baud
== 
smh_putc in a loop   17
smh_puts160
smh_write with :tt 2000
== 

These speeds were mesured using a 175 character message with a J-Link
adapter. For reference, U-Boot typically prints around 2700 characters
during boot on this board. There are two major factors affecting the
speed of these functions. First, each breakpoint incurs a delay. Second,
each debugger memory transaction incurs a delay. smh_putc has a
breakpoint and memory transaction for every character. smh_puts has one
breakpoint, but still has to use a transaction for every character. This
is because we don't know the length up front, so OpenOCD has to check if
each character is nul. smh_write has only one breakpoint and one memory
transfer.

DM serial drivers can only implement a putc interface, so we are stuck
with the slowest API. Non-DM drivers can implement puts, which is vastly
more efficient. When the driver starts up, we try to open :tt. Since
this is an extension, this may fail. If it does, we fall back to
smh_puts. We don't check :semihosting-features, since there are
nonconforming imlementations (OpenOCD) which don't implement it (but
*do* implement :tt).

There is no non-blocking I/O available, so we don't implement pending.
This will cause __serial_tstc to always return true. If
CONFIG_SERIAL_RX_BUFFER is enabled, _serial_tstc will try and read
characters forever. To avoid this, we depend on this config being
disabled.

Signed-off-by: Sean Anderson 
---

 drivers/serial/Kconfig  |  22 ++
 drivers/serial/Makefile |   1 +
 drivers/serial/serial.c |   2 +
 drivers/serial/serial_semihosting.c | 108 
 4 files changed, 133 insertions(+)
 create mode 100644 drivers/serial/serial_semihosting.c

diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 345d1881f5..cc20759505 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -399,6 +399,15 @@ config DEBUG_UART_SANDBOX
  start up driver model. The driver will be available until the real
  driver model serial is running.
 
+config DEBUG_UART_SEMIHOSTING
+   bool "semihosting"
+   depends on SEMIHOSTING_SERIAL
+   help
+ Select this to enable the debug UART using the semihosting driver.
+ This provides basic serial output from the console without needing to
+ start up driver model. The driver will be available until the real
+ driver model serial is running.
+
 config DEBUG_UART_SIFIVE
bool "SiFive UART"
depends on SIFIVE_SERIAL
@@ -778,6 +787,19 @@ config SCIF_CONSOLE
  on systems with RCar or SH SoCs, say Y to this option. If unsure,
  say N.
 
+config SEMIHOSTING_SERIAL
+   bool "Semihosting UART support"
+   depends on SEMIHOSTING && !SERIAL_RX_BUFFER
+   help
+ Select this to enable a serial UART using semihosting. Special halt
+ instructions will be issued which an external debugger (such as a
+ JTAG emulator) may interpret. The debugger will display U-Boot's
+ console output on the host system.
+
+ Enable this option only if you are using a debugger which supports
+ semihosting. If you are not using a debugger, this driver will halt
+ the boot.
+
 config UNIPHIER_SERIAL
bool "Support for UniPhier on-chip UART"
depends on ARCH_UNIPHIER
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index 52e70aa191..b68b5e7b2b 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -52,6 +52,7 @@ endif
 obj-$(CONFIG_XILINX_UARTLITE) += serial_xuartlite.o
 obj-$(CONFIG_SANDBOX_SERIAL) += sandbox.o
 obj-$(CONFIG_SCIF_CONSOLE) += serial_sh.o
+obj-$(CONFIG_SEMIHOSTING_SERIAL) += serial_semihosting.o
 obj-$(CONFIG_ZYNQ_SERIAL) += serial_zynq.o
 obj-$(CONFIG_FSL_LPUART) += serial_lpuart.o
 obj-$(CONFIG_FSL_LINFLEXUART) += serial_linflexuart.o
diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c
index ebbd21916d..6cdbb89841 100644
--- a/drivers/serial/serial.c
+++ b/drivers/serial/serial.c
@@ -126,6 +126,7 @@ serial_initfunc(mxc_serial_initialize);
 serial_initfunc(ns16550_serial_initialize);
 serial_initfunc(pl01x_serial_initialize);
 serial_initfunc(pxa_serial_initialize);
+serial_initfunc(smh_serial_initialize);
 serial_initfunc(sh_serial_initialize);
 serial_initfunc(mtk_serial_initialize);
 
@@ -180,6 +181,7 @@ int serial_initialize(void)
ns16550_serial_initialize();

[PATCH 17/17] ls1046ardb: Add support for JTAG boot

2022-03-03 Thread Sean Anderson
This adds support for booting entirely from JTAG while using a
hard-coded RCW. With these steps, it is not necessary to program a
"good" RCW using CodeWarrior. The method here can be performed with any
JTAG adapter supported by OpenOCD, including the on-board CMSIS-DAP
(albeit very slowly).

These steps require LS1046A support in OpenOCD, which is currently in
the process of being upstreamed [1].

[1] https://review.openocd.org/c/openocd/+/6855

Signed-off-by: Sean Anderson 
---

 arch/arm/cpu/armv8/fsl-layerscape/spl.c |  2 +
 doc/board/nxp/ls1046ardb.rst| 71 +
 include/configs/ls1046ardb.h|  2 +
 3 files changed, 75 insertions(+)

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/spl.c 
b/arch/arm/cpu/armv8/fsl-layerscape/spl.c
index 564cc27c8b..1a7dde30a5 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/spl.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/spl.c
@@ -27,6 +27,8 @@ DECLARE_GLOBAL_DATA_PTR;
 
 u32 spl_boot_device(void)
 {
+   if (IS_ENABLED(CONFIG_SPL_SEMIHOSTING))
+   return BOOT_DEVICE_SMH;
 #ifdef CONFIG_SPL_MMC
return BOOT_DEVICE_MMC1;
 #endif
diff --git a/doc/board/nxp/ls1046ardb.rst b/doc/board/nxp/ls1046ardb.rst
index c73516c070..ffb9d4550b 100644
--- a/doc/board/nxp/ls1046ardb.rst
+++ b/doc/board/nxp/ls1046ardb.rst
@@ -109,3 +109,74 @@ SD boot and eMMC boot
 
 ``{ SW5[0:8], SW4[0] }`` should be ``0010__0``. eMMC is selected only if
 there is no SD card in the slot.
+
+JTAG boot
+^
+
+To recover a bricked board, or to perform initial programming, the ls1046
+supports using two hard-coded Reset Configuration Words (RCWs). Unfortunately,
+this configuration disables most functionality, including the uarts and 
ethernet.
+However, the SD/MMC and flash controllers are still functional. To get around
+the lack of a serial console, we will use ARM semihosting instead. When
+enabled, OpenOCD will interpret certain instructions as calls to the host
+operating system. This allows U-Boot to use the console, read/write files, or
+run arbitrary commands (!).
+
+When configuring U-Boot, ensure that ``CONFIG_SEMIHOSTING``,
+``CONFIG_SPL_SEMIHOSTING``, and ``CONFIG_SEMIHOSTING_SERIAL`` are enabled, and
+``CONFIG_SYS_NS16550`` is disabled. ``{ SW5[0:8], SW4[0] }`` should be
+``0100__0``. Additionally, ``SW4[7]`` should be set to ``0``. Connect to
+the "console" USB connector on the front of the enclosure.
+
+Create a new file called ``u-boot.tcl`` (or whatever you choose) with the
+following contents::
+
+# Load the configuration for the LS1046ARDB
+source [find board/nxp_rdb-ls1046a.cfg]
+# Initialize the scan chain
+init
+# Stop the processor
+halt
+# Enable semihosting
+arm semihosting enable
+# Load U-Boot SPL
+load_image spl/u-boot-spl 0 elf
+# Start executing SPL at the beginning of OCRAM
+resume 0x1000
+
+Then, launch openocd like::
+
+openocd -f u-boot.tcl
+
+You should see the U-boot SPL banner followed by the banner for U-Boot proper
+in the output of openocd. The CMSIS-DAP adapter is slow, so this can take a
+long time. If you don't see it, something has gone wrong. After a while, you
+should see the prompt. You can load an image using semihosting by running::
+
+=> load hostfs $loadaddr 
+
+Note that openocd's terminal is "cooked," so commands will only be sent to
+U-Boot when you press enter, and all commands will be echoed twice.
+Additionally, openocd will block when waiting for input, ignoring gdb, JTAG
+events, and Ctrl-Cs. To make openocd process these events, just hit enter.
+
+Using an external JTAG adapter
+""
+
+The CMSIS-DAP adapter can be rather slow. To speed up booting, use an external
+JTAG adapter. The following examples assume you are using a J-Link, though any
+adapter supported by OpenOCD will do. Ensure that ``SW4[7]`` is ``1``. Attach
+your jtag adapter to J22. Modify ``u-boot.tcl`` and replace the first two lines
+with the following::
+
+# Load the J-Link configuration (or whatever your adapter is)
+source [find interface/jlink.cfg]
+# Use JTAG, since the J-Link also supports SWD
+transport select jtag
+# The reset pin resets the whole CPU
+reset_config srst_only
+# Load the LS1046A config
+source [find target/ls1046a.cfg]
+
+You can proceed as normal through the rest of the steps above. I got a speedup
+of around 100x by using a J-Link.
diff --git a/include/configs/ls1046ardb.h b/include/configs/ls1046ardb.h
index 8ed1dceb23..ed549c33b6 100644
--- a/include/configs/ls1046ardb.h
+++ b/include/configs/ls1046ardb.h
@@ -143,6 +143,8 @@
 #endif
 #endif
 
+#define CONFIG_SPL_FS_LOAD_PAYLOAD_NAME "u-boot.img"
+
 #include 
 
 #endif /* __LS1046ARDB_H__ */
-- 
2.25.1



[PATCH 16/17] doc: smh: Update semihosting documentation

2022-03-03 Thread Sean Anderson
This documents the new semihosting features added in the past few
commits.

Signed-off-by: Sean Anderson 
---

 doc/usage/semihosting.rst | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/doc/usage/semihosting.rst b/doc/usage/semihosting.rst
index ed16e4d582..986a821819 100644
--- a/doc/usage/semihosting.rst
+++ b/doc/usage/semihosting.rst
@@ -34,10 +34,18 @@ Foundation and Base fastmodel simulators.
 Loading files
 -
 
-The semihosting code adds a "hostfs"::
+The semihosting code adds a "semihosting filesystem"::
 
-  smhload   [env var]
+  load hostfs  
 
 That will load an image from the host filesystem into RAM at the specified
-address and optionally store the load end address in the specified
-environment variable.
+address. If you are using U-Boot SPL, you can also use ``BOOT_DEVICE_SMH``
+which will load ``CONFIG_SPL_FS_LOAD_PAYLOAD_NAME``.
+
+Host console
+
+
+U-Boot can use the host's console instead of a physical serial device by
+enabling ``CONFIG_SERIAL_SEMIHOSTING``. If you don't have
+``CONFIG_DM_SERIAL`` enabled, make sure you disable any other serial
+drivers.
-- 
2.25.1



[PATCH 13/17] arm: smh: Remove smhload command

2022-03-03 Thread Sean Anderson
This command's functionality is now completely implemented by the
standard fs load command. Convert the vexpress64 boot command (which is
the only user) and remove the implementation.

Signed-off-by: Sean Anderson 
---

 arch/arm/lib/semihosting.c | 76 --
 configs/vexpress_aemv8a_semi_defconfig |  2 +-
 2 files changed, 1 insertion(+), 77 deletions(-)

diff --git a/arch/arm/lib/semihosting.c b/arch/arm/lib/semihosting.c
index 45cd566cfc..57ab25294f 100644
--- a/arch/arm/lib/semihosting.c
+++ b/arch/arm/lib/semihosting.c
@@ -10,8 +10,6 @@
  * available in silicon now, fastmodel usage makes less sense for them.
  */
 #include 
-#include 
-#include 
 #include 
 #include 
 
@@ -169,77 +167,3 @@ long smh_seek(long fd, long pos)
return smh_errno();
return 0;
 }
-
-static int smh_load_file(const char * const name, ulong load_addr,
-ulong *size)
-{
-   long fd;
-   long len;
-   long ret;
-
-   fd = smh_open(name, MODE_READ | MODE_BINARY);
-   if (fd < 0)
-   return fd;
-
-   len = smh_flen(fd);
-   if (len < 0) {
-   smh_close(fd);
-   return len;
-   }
-
-   ret = smh_read(fd, (void *)load_addr, len);
-   smh_close(fd);
-
-   if (ret == len) {
-   *size = len;
-   printf("loaded file %s from %08lX to %08lX, %08lX bytes\n",
-  name,
-  load_addr,
-  load_addr + len - 1,
-  len);
-   } else if (ret >= 0) {
-   ret = -EAGAIN;
-   }
-
-   if (ret < 0) {
-   printf("read failed: %ld\n", ret);
-   return ret;
-   }
-
-   return 0;
-}
-
-static int do_smhload(struct cmd_tbl *cmdtp, int flag, int argc,
- char *const argv[])
-{
-   if (argc == 3 || argc == 4) {
-   ulong load_addr;
-   ulong size = 0;
-   int ret;
-   char size_str[64];
-
-   load_addr = hextoul(argv[2], NULL);
-   if (!load_addr)
-   return -1;
-
-   ret = smh_load_file(argv[1], load_addr, );
-   if (ret < 0)
-   return CMD_RET_FAILURE;
-
-   /* Optionally save returned end to the environment */
-   if (argc == 4) {
-   sprintf(size_str, "0x%08lx", size);
-   env_set(argv[3], size_str);
-   }
-   } else {
-   return CMD_RET_USAGE;
-   }
-   return 0;
-}
-
-U_BOOT_CMD(smhload, 4, 0, do_smhload, "load a file using semihosting",
-  " 0x [end var]\n"
-  "- load a semihosted file to the address specified\n"
-  "  if the optional [end var] is specified, the end\n"
-  "  address of the file will be stored in this environment\n"
-  "  variable.\n");
diff --git a/configs/vexpress_aemv8a_semi_defconfig 
b/configs/vexpress_aemv8a_semi_defconfig
index 82a5b52f1e..d7771f6260 100644
--- a/configs/vexpress_aemv8a_semi_defconfig
+++ b/configs/vexpress_aemv8a_semi_defconfig
@@ -17,7 +17,7 @@ CONFIG_ANDROID_BOOT_IMAGE=y
 CONFIG_BOOTDELAY=1
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="console=ttyAMA0 earlycon=pl011,0x1c09 debug user_debug=31 
loglevel=9"
-CONFIG_BOOTCOMMAND="if smhload ${boot_name} ${boot_addr_r}; then   set 
bootargs;   abootimg addr ${boot_addr_r};   abootimg get dtb --index=0 
fdt_addr_r;   bootm ${boot_addr_r} ${boot_addr_r}   ${fdt_addr_r}; else;   set 
fdt_high 0x;   set initrd_high 0x;   smhload 
${kernel_name} ${kernel_addr};   smhload ${fdtfile} ${fdt_addr_r};   smhload 
${ramdisk_name} ${ramdisk_addr_r}   ramdisk_end;   fdt addr ${fdt_addr_r}; fdt 
resize;   fdt chosen ${ramdisk_addr_r} ${ramdisk_end};   booti $kernel_addr - 
$fdt_addr_r; fi"
+CONFIG_BOOTCOMMAND="if load hostfs ${boot_addr_r} ${boot_name}; then   set 
bootargs;   abootimg addr ${boot_addr_r};   abootimg get dtb --index=0 
fdt_addr_r;   bootm ${boot_addr_r} ${boot_addr_r}   ${fdt_addr_r}; else;   set 
fdt_high 0x;   set initrd_high 0x;   load 
hostfs ${kernel_addr} ${kernel_name};   load hostfs ${fdt_addr_r} ${fdtfile};   
load ${ramdisk_addr_r} ${ramdisk_name};   fdt addr ${fdt_addr_r}; fdt resize;   
fdt chosen ${ramdisk_addr_r} ${filesize};   booti $kernel_addr - $fdt_addr_r; 
fi"
 # CONFIG_DISPLAY_CPUINFO is not set
 # CONFIG_DISPLAY_BOARDINFO is not set
 CONFIG_SYS_PROMPT="VExpress64# "
-- 
2.25.1



[PATCH 14/17] arm: smh: Add some functions for working with the host console

2022-03-03 Thread Sean Anderson
This adds three wrappers around the semihosting commands for reading and
writing to the host console. We use the more standard getc/putc/puts
names instead of readc/writec/write0 for familiarity.

Signed-off-by: Sean Anderson 
---

 arch/arm/lib/semihosting.c | 18 ++
 include/semihosting.h  | 19 +++
 2 files changed, 37 insertions(+)

diff --git a/arch/arm/lib/semihosting.c b/arch/arm/lib/semihosting.c
index 57ab25294f..7595dbc4a9 100644
--- a/arch/arm/lib/semihosting.c
+++ b/arch/arm/lib/semihosting.c
@@ -15,8 +15,11 @@
 
 #define SYSOPEN0x01
 #define SYSCLOSE   0x02
+#define SYSWRITEC  0x03
+#define SYSWRITE0  0x04
 #define SYSWRITE   0x05
 #define SYSREAD0x06
+#define SYSREADC   0x07
 #define SYSSEEK0x0A
 #define SYSFLEN0x0C
 #define SYSERRNO   0x13
@@ -167,3 +170,18 @@ long smh_seek(long fd, long pos)
return smh_errno();
return 0;
 }
+
+int smh_getc(void)
+{
+   return smh_trap(SYSREADC, NULL);
+}
+
+void smh_putc(char ch)
+{
+   smh_trap(SYSWRITEC, );
+}
+
+void smh_puts(const char *s)
+{
+   smh_trap(SYSWRITE0, (char *)s);
+}
diff --git a/include/semihosting.h b/include/semihosting.h
index b53c650444..6f3c29786c 100644
--- a/include/semihosting.h
+++ b/include/semihosting.h
@@ -86,4 +86,23 @@ long smh_flen(long fd);
  */
 long smh_seek(long fd, long pos);
 
+/**
+ * smh_getc() - Read a character from stdin
+ *
+ * Return: The character read, or a negative error on failure
+ */
+int smh_getc(void);
+
+/**
+ * smh_putc() - Print a character on stdout
+ * @ch: The character to print
+ */
+void smh_putc(char ch);
+
+/**
+ * smh_write0() - Print a nul-terminated string on stdout
+ * @s: The string to print
+ */
+void smh_puts(const char *s);
+
 #endif /* _SEMIHOSTING_H */
-- 
2.25.1



[PATCH 12/17] cmd: fdt: Use start/size for chosen instead of start/end

2022-03-03 Thread Sean Anderson
Most U-Boot command deal with start/size instead of start/end. Convert
the "fdt chosen" command to use these semantics as well. The only user
of this subcommand is vexpress, so convert the smhload command to use
this as well. We don't bother renaming the variable in vexpress64's
bootcommand, since it will be rewritten in the next commit.

Signed-off-by: Sean Anderson 
---

 arch/arm/lib/semihosting.c | 16 
 cmd/fdt.c  |  6 +++---
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/arch/arm/lib/semihosting.c b/arch/arm/lib/semihosting.c
index d08003cef1..45cd566cfc 100644
--- a/arch/arm/lib/semihosting.c
+++ b/arch/arm/lib/semihosting.c
@@ -171,7 +171,7 @@ long smh_seek(long fd, long pos)
 }
 
 static int smh_load_file(const char * const name, ulong load_addr,
-ulong *end_addr)
+ulong *size)
 {
long fd;
long len;
@@ -191,11 +191,11 @@ static int smh_load_file(const char * const name, ulong 
load_addr,
smh_close(fd);
 
if (ret == len) {
-   *end_addr = load_addr + len - 1;
+   *size = len;
printf("loaded file %s from %08lX to %08lX, %08lX bytes\n",
   name,
   load_addr,
-  *end_addr,
+  load_addr + len - 1,
   len);
} else if (ret >= 0) {
ret = -EAGAIN;
@@ -214,22 +214,22 @@ static int do_smhload(struct cmd_tbl *cmdtp, int flag, 
int argc,
 {
if (argc == 3 || argc == 4) {
ulong load_addr;
-   ulong end_addr = 0;
+   ulong size = 0;
int ret;
-   char end_str[64];
+   char size_str[64];
 
load_addr = hextoul(argv[2], NULL);
if (!load_addr)
return -1;
 
-   ret = smh_load_file(argv[1], load_addr, _addr);
+   ret = smh_load_file(argv[1], load_addr, );
if (ret < 0)
return CMD_RET_FAILURE;
 
/* Optionally save returned end to the environment */
if (argc == 4) {
-   sprintf(end_str, "0x%08lx", end_addr);
-   env_set(argv[3], end_str);
+   sprintf(size_str, "0x%08lx", size);
+   env_set(argv[3], size_str);
}
} else {
return CMD_RET_USAGE;
diff --git a/cmd/fdt.c b/cmd/fdt.c
index 2a207bf2b5..7d7cae88a2 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -638,7 +638,7 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
 
if (argc == 4) {
initrd_start = hextoul(argv[2], NULL);
-   initrd_end = hextoul(argv[3], NULL);
+   initrd_end = initrd_start + hextoul(argv[3], NULL) - 1;
}
 
fdt_chosen(working_fdt);
@@ -1083,8 +1083,8 @@ static char fdt_help_text[] =
"fdt rsvmem print- Show current mem reserves\n"
"fdt rsvmem add  - Add a mem reserve\n"
"fdt rsvmem delete- Delete a mem reserves\n"
-   "fdt chosen [ ]  - Add/update the /chosen branch in 
the tree\n"
-   "/ - initrd 
start/end addr\n"
+   "fdt chosen [ ] - Add/update the /chosen branch in 
the tree\n"
+   "/ - initrd start 
addr/size\n"
 #if defined(CONFIG_FIT_SIGNATURE)
"fdt checksign []  - check FIT signature\n"
" - addr of key blob\n"
-- 
2.25.1



[PATCH 11/17] fs: Add semihosting filesystem

2022-03-03 Thread Sean Anderson
This adds a filesystem which is backed by the host's filesystem. It is
modeled off of sandboxfs, which has very similar aims. Semihosting
doesn't support listing directories (except with SYS_SYSTEM), so neither
do we. it's possible to optimize a bit for the common case of reading a
whole file by omitting a call to smh_seek, but this is left as a future
optimization.

Signed-off-by: Sean Anderson 
---

 disk/part.c |   4 +-
 fs/Makefile |   1 +
 fs/fs.c |  20 +++
 fs/semihostingfs.c  | 115 
 include/fs.h|   1 +
 include/semihostingfs.h |  21 
 6 files changed, 160 insertions(+), 2 deletions(-)
 create mode 100644 fs/semihostingfs.c
 create mode 100644 include/semihostingfs.h

diff --git a/disk/part.c b/disk/part.c
index 49e39a24e8..b95405bb49 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -455,7 +455,7 @@ int blk_get_device_part_str(const char *ifname, const char 
*dev_part_str,
int part;
struct disk_partition tmpinfo;
 
-#ifdef CONFIG_SANDBOX
+#if IS_ENABLED(CONFIG_SANDBOX) || IS_ENABLED(CONFIG_SEMIHOSTING)
/*
 * Special-case a pseudo block device "hostfs", to allow access to the
 * host's own filesystem.
@@ -467,7 +467,7 @@ int blk_get_device_part_str(const char *ifname, const char 
*dev_part_str,
info->blksz = 0;
info->bootable = 0;
strcpy((char *)info->type, BOOT_PART_TYPE);
-   strcpy((char *)info->name, "Sandbox host");
+   strcpy((char *)info->name, "Host filesystem");
 #if CONFIG_IS_ENABLED(PARTITION_UUIDS)
info->uuid[0] = 0;
 #endif
diff --git a/fs/Makefile b/fs/Makefile
index 937cbcf6e8..c25d022946 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_FS_FAT) += fat/
 obj-$(CONFIG_FS_JFFS2) += jffs2/
 obj-$(CONFIG_CMD_REISER) += reiserfs/
 obj-$(CONFIG_SANDBOX) += sandbox/
+obj-$(CONFIG_SEMIHOSTING) += semihostingfs.o
 obj-$(CONFIG_CMD_UBIFS) += ubifs/
 obj-$(CONFIG_YAFFS2) += yaffs2/
 obj-$(CONFIG_CMD_ZFS) += zfs/
diff --git a/fs/fs.c b/fs/fs.c
index 023f89cafe..bba010ea99 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -246,6 +247,25 @@ static struct fstype_info fstypes[] = {
.ln = fs_ln_unsupported,
},
 #endif
+#ifdef CONFIG_SEMIHOSTING
+   {
+   .fstype = FS_TYPE_SEMIHOSTING,
+   .name = "semihosting",
+   .null_dev_desc_ok = true,
+   .probe = smh_fs_set_blk_dev,
+   .close = fs_close_unsupported,
+   .ls = fs_ls_unsupported,
+   .exists = fs_exists_unsupported,
+   .size = smh_fs_size,
+   .read = smh_fs_read,
+   .write = smh_fs_write,
+   .uuid = fs_uuid_unsupported,
+   .opendir = fs_opendir_unsupported,
+   .unlink = fs_unlink_unsupported,
+   .mkdir = fs_mkdir_unsupported,
+   .ln = fs_ln_unsupported,
+   },
+#endif
 #ifdef CONFIG_CMD_UBIFS
{
.fstype = FS_TYPE_UBIFS,
diff --git a/fs/semihostingfs.c b/fs/semihostingfs.c
new file mode 100644
index 00..96eb3349a2
--- /dev/null
+++ b/fs/semihostingfs.c
@@ -0,0 +1,115 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2022, Sean Anderson 
+ * Copyright (c) 2012, Google Inc.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int smh_fs_set_blk_dev(struct blk_desc *rbdd, struct disk_partition *info)
+{
+   /*
+* Only accept a NULL struct blk_desc for the semihosting, which is when
+* hostfs interface is used
+*/
+   return !!rbdd;
+}
+
+static int smh_fs_read_at(const char *filename, loff_t pos, void *buffer,
+ loff_t maxsize, loff_t *actread)
+{
+   long fd, size, ret;
+
+   fd = smh_open(filename, MODE_READ | MODE_BINARY);
+   if (fd < 0)
+   return fd;
+   ret = smh_seek(fd, pos);
+   if (ret < 0) {
+   smh_close(fd);
+   return ret;
+   }
+   if (!maxsize) {
+   size = smh_flen(fd);
+   if (ret < 0) {
+   smh_close(fd);
+   return size;
+   }
+
+   maxsize = size;
+   }
+
+   size = smh_read(fd, buffer, maxsize);
+   smh_close(fd);
+   if (size < 0)
+   return size;
+
+   *actread = size;
+   return 0;
+}
+
+static int smh_fs_write_at(const char *filename, loff_t pos, void *buffer,
+  loff_t towrite, loff_t *actwrite)
+{
+   long fd, size, ret;
+
+   fd = smh_open(filename, MODE_READ | MODE_BINARY | MODE_PLUS);
+   if (fd < 0)
+   return fd;
+   ret = smh_seek(fd, pos);
+   if (ret < 0) {
+   smh_close(fd);
+   

[PATCH 10/17] spl: Add semihosting boot method

2022-03-03 Thread Sean Anderson
This adds a boot method for loading the next stage from the host. It is
mostly modeled off of spl_load_image_ext. I am not really sure why/how
spl_load_image_fat uses three different methods to load the image, but
the simple case seems to work OK for now.

To control the presence of this boot method, we add a config symbol.
While we're at it, we update the original semihosting config symbol.

I think semihosting has some advantages of other forms of JTAG boot.
Common other ways to boot from JTAG include:

- Implementing DDR initialization through JTAG (typically with dozens of
  lines of TCL) and then loading U-Boot. The DDR initialization
  typically uses hard-coded register writes, and is not easily adapted
  to different boards. BOOT_DEVICE_SMH allows booting with SPL,
  leveraging U-Boot's existing DDR initialization code. This is the
  method used by NXP's CodeWarrior IDE on Layerscape processors (see
  AN12270).
- Loading a bootloader into SDRAM, waiting for it to initialize DDR, and
  then loading U-Boot. This is tricky, because the debugger must stop the
  boot after the bootloader has completed its work. Trying to load
  U-Boot too early can cause failure to boot. This is the method used by
  Xilinx with its Zynq(MP) processors.
- Loading SPL with BOOT_DEVICE_RAM and breaking before SPL loads the
  image to load U-Boot at the appropriate place. This can be a bit
  tricky, because the load address is dependent on the header size. An
  elf with symbols must also be used in order to stop at the appropriate
  point. BOOT_DEVICE_SMH can be viewed as an extension of this process,
  where SPL automatically stops and tells the host where to place the
  image.

Signed-off-by: Sean Anderson 
---

 arch/arm/Kconfig | 25 +++--
 arch/arm/include/asm/spl.h   |  1 +
 common/spl/Makefile  |  1 +
 common/spl/spl_semihosting.c | 71 
 4 files changed, 94 insertions(+), 4 deletions(-)
 create mode 100644 common/spl/spl_semihosting.c

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 391a77c2b4..5cacb292b5 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -403,11 +403,28 @@ config ARM_SMCCC
  firmware (for example, PSCI) according to SMCCC.
 
 config SEMIHOSTING
-   bool "support boot from semihosting"
+   bool "Support ARM semihosting"
help
- In emulated environments, semihosting is a way for
- the hosted environment to call out to the emulator to
- retrieve files from the host machine.
+ Semihosting is a method for a target to communicate with a host
+ debugger. It uses special instructions which the debugger will trap
+ on and interpret. This allows U-Boot to read/write files, print to
+ the console, and execute arbitrary commands on the host system.
+
+ Enabling this option will add support for reading and writing files
+ on the host system. If you don't have a debugger attached then trying
+ to do this will likely cause U-Boot to hang. Say 'n' if you are 
unsure.
+
+config SPL_SEMIHOSTING
+   bool "Support ARM semihosting in SPL"
+   help
+ Semihosting is a method for a target to communicate with a host
+ debugger. It uses special instructions which the debugger will trap
+ on and interpret. This allows U-Boot to read/write files, print to
+ the console, and execute arbitrary commands on the host system.
+
+ Enabling this option will add support for reading and writing files
+ on the host system. If you don't have a debugger attached then trying
+ to do this will likely cause U-Boot to hang. Say 'n' if you are 
unsure.
 
 config SYS_THUMB_BUILD
bool "Build U-Boot using the Thumb instruction set"
diff --git a/arch/arm/include/asm/spl.h b/arch/arm/include/asm/spl.h
index e568af2561..b5790bd0bc 100644
--- a/arch/arm/include/asm/spl.h
+++ b/arch/arm/include/asm/spl.h
@@ -30,6 +30,7 @@ enum {
BOOT_DEVICE_DFU,
BOOT_DEVICE_XIP,
BOOT_DEVICE_BOOTROM,
+   BOOT_DEVICE_SMH,
BOOT_DEVICE_NONE
 };
 #endif
diff --git a/common/spl/Makefile b/common/spl/Makefile
index db8fd36a26..e71e7bee66 100644
--- a/common/spl/Makefile
+++ b/common/spl/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_$(SPL_TPL_)USB_STORAGE) += spl_usb.o
 obj-$(CONFIG_$(SPL_TPL_)FS_FAT) += spl_fat.o
 obj-$(CONFIG_$(SPL_TPL_)FS_EXT4) += spl_ext.o
 obj-$(CONFIG_$(SPL_TPL_)SATA) += spl_sata.o
+obj-$(CONFIG_$(SPL_TPL_)SEMIHOSTING) += spl_semihosting.o
 obj-$(CONFIG_$(SPL_TPL_)DFU) += spl_dfu.o
 obj-$(CONFIG_$(SPL_TPL_)SPI_LOAD) += spl_spi.o
 obj-$(CONFIG_$(SPL_TPL_)RAM_SUPPORT) += spl_ram.o
diff --git a/common/spl/spl_semihosting.c b/common/spl/spl_semihosting.c
new file mode 100644
index 00..df6aeb2951
--- /dev/null
+++ b/common/spl/spl_semihosting.c
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2022 Sean Anderson 
+ */
+
+#include 
+#include 

[PATCH 09/17] arm: smh: Add some file manipulation commands

2022-03-03 Thread Sean Anderson
In order to add filesystem support, we will need to be able to seek and
write files. Add the appropriate helper functions.

Signed-off-by: Sean Anderson 
---

 arch/arm/lib/semihosting.c | 67 +++---
 include/semihosting.h  | 20 
 2 files changed, 76 insertions(+), 11 deletions(-)

diff --git a/arch/arm/lib/semihosting.c b/arch/arm/lib/semihosting.c
index 2943f7b82f..d08003cef1 100644
--- a/arch/arm/lib/semihosting.c
+++ b/arch/arm/lib/semihosting.c
@@ -1,15 +1,13 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
+ * Copyright (C) 2022 Sean Anderson 
  * Copyright 2014 Broadcom Corporation
  */
 
 /*
- * Minimal semihosting implementation for reading files into memory. If more
- * features like writing files or console output are required they can be
- * added later. This code has been tested on arm64/aarch64 fastmodel only.
- * An untested placeholder exists for armv7 architectures, but since they
- * are commonly available in silicon now, fastmodel usage makes less sense
- * for them.
+ * This code has been tested on arm64/aarch64 fastmodel only.  An untested
+ * placeholder exists for armv7 architectures, but since they are commonly
+ * available in silicon now, fastmodel usage makes less sense for them.
  */
 #include 
 #include 
@@ -19,7 +17,9 @@
 
 #define SYSOPEN0x01
 #define SYSCLOSE   0x02
+#define SYSWRITE   0x05
 #define SYSREAD0x06
+#define SYSSEEK0x0A
 #define SYSFLEN0x0C
 #define SYSERRNO   0x13
 
@@ -80,14 +80,22 @@ long smh_open(const char *fname, enum smh_open_mode mode)
return fd;
 }
 
+/**
+ * struct smg_rdwr_s - Arguments for read and write
+ * @fd: A file descriptor returned from smh_open()
+ * @memp: Pointer to a buffer of memory of at least @len bytes
+ * @len: The number of bytes to read or write
+ */
+struct smh_rdwr_s {
+   long fd;
+   void *memp;
+   size_t len;
+};
+
 long smh_read(long fd, void *memp, size_t len)
 {
long ret;
-   struct smh_read_s {
-   long fd;
-   void *memp;
-   size_t len;
-   } read;
+   struct smh_rdwr_s read;
 
debug("%s: fd %ld, memp %p, len %zu\n", __func__, fd, memp, len);
 
@@ -101,6 +109,24 @@ long smh_read(long fd, void *memp, size_t len)
return len - ret;
 }
 
+long smh_write(long fd, const void *memp, size_t len, ulong *written)
+{
+   long ret;
+   struct smh_rdwr_s write;
+
+   debug("%s: fd %ld, memp %p, len %zu\n", __func__, fd, memp, len);
+
+   write.fd = fd;
+   write.memp = (void *)memp;
+   write.len = len;
+
+   ret = smh_trap(SYSWRITE, );
+   *written = len - ret;
+   if (ret)
+   return smh_errno();
+   return 0;
+}
+
 long smh_close(long fd)
 {
long ret;
@@ -125,6 +151,25 @@ long smh_flen(long fd)
return ret;
 }
 
+long smh_seek(long fd, long pos)
+{
+   long ret;
+   struct smh_seek_s {
+   long fd;
+   long pos;
+   } seek;
+
+   debug("%s: fd %ld pos %ld\n", __func__, fd, pos);
+
+   seek.fd = fd;
+   seek.pos = pos;
+
+   ret = smh_trap(SYSSEEK, );
+   if (ret)
+   return smh_errno();
+   return 0;
+}
+
 static int smh_load_file(const char * const name, ulong load_addr,
 ulong *end_addr)
 {
diff --git a/include/semihosting.h b/include/semihosting.h
index d8337b6269..b53c650444 100644
--- a/include/semihosting.h
+++ b/include/semihosting.h
@@ -50,6 +50,17 @@ long smh_open(const char *fname, enum smh_open_mode mode);
  */
 long smh_read(long fd, void *memp, size_t len);
 
+/**
+ * smh_write() - Write data to a file
+ * @fd: A file descriptor returned from smh_open()
+ * @memp: Pointer to a buffer of memory of at least @len bytes
+ * @len: The number of bytes to read
+ * @written: Pointer which will be updated with the actual bytes written
+ *
+ * Return: 0 on success or negative error on failure
+ */
+long smh_write(long fd, const void *memp, size_t len, ulong *written);
+
 /**
  * smh_close() - Close an open file
  * @fd: A file descriptor returned from smh_open()
@@ -66,4 +77,13 @@ long smh_close(long fd);
  */
 long smh_flen(long fd);
 
+/**
+ * smh_seek() - Seek to a position in a file
+ * @fd: A file descriptor returned from smh_open()
+ * @pos: The offset (in bytes) to seek to
+ *
+ * Return: 0 on success or negative error on failure
+ */
+long smh_seek(long fd, long pos);
+
 #endif /* _SEMIHOSTING_H */
-- 
2.25.1



[PATCH 05/17] arm: smh: Export semihosting functions

2022-03-03 Thread Sean Anderson
This exports semihosting functions for use in other files. The header is
in include/ and not arm/include/asm because I anticipate that RISC-V may
want to add their own implementation at some point.

smh_len_fd has been renamed to smh_flen to more closely match the
semihosting spec.

Signed-off-by: Sean Anderson 
---

 arch/arm/lib/semihosting.c | 11 ++-
 include/semihosting.h  | 14 ++
 2 files changed, 20 insertions(+), 5 deletions(-)
 create mode 100644 include/semihosting.h

diff --git a/arch/arm/lib/semihosting.c b/arch/arm/lib/semihosting.c
index 9fd82459b2..c38892fdd8 100644
--- a/arch/arm/lib/semihosting.c
+++ b/arch/arm/lib/semihosting.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define SYSOPEN0x01
 #define SYSCLOSE   0x02
@@ -45,7 +46,7 @@ static noinline long smh_trap(unsigned int sysnum, void *addr)
  * Open a file on the host. Mode is "r" or "rb" currently. Returns a file
  * descriptor or -1 on error.
  */
-static long smh_open(const char *fname, char *modestr)
+long smh_open(const char *fname, char *modestr)
 {
long fd;
unsigned long mode;
@@ -84,7 +85,7 @@ static long smh_open(const char *fname, char *modestr)
 /*
  * Read 'len' bytes of file into 'memp'. Returns 0 on success, else failure
  */
-static long smh_read(long fd, void *memp, size_t len)
+long smh_read(long fd, void *memp, size_t len)
 {
long ret;
struct smh_read_s {
@@ -118,7 +119,7 @@ static long smh_read(long fd, void *memp, size_t len)
 /*
  * Close the file using the file descriptor
  */
-static long smh_close(long fd)
+long smh_close(long fd)
 {
long ret;
 
@@ -134,7 +135,7 @@ static long smh_close(long fd)
 /*
  * Get the file length from the file descriptor
  */
-static long smh_len_fd(long fd)
+long smh_flen(long fd)
 {
long ret;
 
@@ -158,7 +159,7 @@ static int smh_load_file(const char * const name, ulong 
load_addr,
if (fd == -1)
return -1;
 
-   len = smh_len_fd(fd);
+   len = smh_flen(fd);
if (len < 0) {
smh_close(fd);
return -1;
diff --git a/include/semihosting.h b/include/semihosting.h
new file mode 100644
index 00..3843863046
--- /dev/null
+++ b/include/semihosting.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2022 Sean Anderson 
+ */
+
+#ifndef _SEMIHOSTING_H
+#define _SEMIHOSTING_H
+
+long smh_open(const char *fname, char *modestr);
+long smh_read(long fd, void *memp, size_t len);
+long smh_close(long fd);
+long smh_flen(long fd);
+
+#endif /* _SEMIHOSTING_H */
-- 
2.25.1



[PATCH 08/17] arm: smh: Document functions in header

2022-03-03 Thread Sean Anderson
This adds some documentation for semihosting functions in the header.

Signed-off-by: Sean Anderson 
---

 arch/arm/lib/semihosting.c |  9 -
 include/semihosting.h  | 32 
 2 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/arch/arm/lib/semihosting.c b/arch/arm/lib/semihosting.c
index 1686457685..2943f7b82f 100644
--- a/arch/arm/lib/semihosting.c
+++ b/arch/arm/lib/semihosting.c
@@ -80,9 +80,6 @@ long smh_open(const char *fname, enum smh_open_mode mode)
return fd;
 }
 
-/*
- * Read 'len' bytes of file into 'memp'. Returns 0 on success, else failure
- */
 long smh_read(long fd, void *memp, size_t len)
 {
long ret;
@@ -104,9 +101,6 @@ long smh_read(long fd, void *memp, size_t len)
return len - ret;
 }
 
-/*
- * Close the file using the file descriptor
- */
 long smh_close(long fd)
 {
long ret;
@@ -119,9 +113,6 @@ long smh_close(long fd)
return 0;
 }
 
-/*
- * Get the file length from the file descriptor
- */
 long smh_flen(long fd)
 {
long ret;
diff --git a/include/semihosting.h b/include/semihosting.h
index cf54819192..d8337b6269 100644
--- a/include/semihosting.h
+++ b/include/semihosting.h
@@ -29,9 +29,41 @@ enum smh_open_mode {
MODE_APPEND = 0x8,
 };
 
+/**
+ * smh_open() - Open a file on the host
+ * @fname: The name of the file to open
+ * @mode: The mode to use when opening the file
+ *
+ * Return: Either a file descriptor or a negative error on failure
+ */
 long smh_open(const char *fname, enum smh_open_mode mode);
+
+/**
+ * smh_read() - Read data from a file
+ * @fd: A file descriptor returned from smh_open()
+ * @memp: Pointer to a buffer of memory of at least @len bytes
+ * @len: The number of bytes to read
+ *
+ * Return:
+ * * The number of bytes read on success, with 0 indicating %EOF
+ * * A negative error on failure
+ */
 long smh_read(long fd, void *memp, size_t len);
+
+/**
+ * smh_close() - Close an open file
+ * @fd: A file descriptor returned from smh_open()
+ *
+ * Return: 0 on success or negative error on failure
+ */
 long smh_close(long fd);
+
+/**
+ * smh_flen() - Get the length of a file
+ * @fd: A file descriptor returned from smh_open()
+ *
+ * Return: The length of the file, in bytes, or a negative error on failure
+ */
 long smh_flen(long fd);
 
 #endif /* _SEMIHOSTING_H */
-- 
2.25.1



[PATCH 06/17] arm: smh: Use numeric modes for smh_open

2022-03-03 Thread Sean Anderson
There's no point in using string constants for smh_open if we are just
going to have to parse them. Instead, use numeric modes. The user needs
to be a bit careful with these, since they are much closer semantically
to string modes used by fopen(3) than the numeric modes used with
open(2).

Signed-off-by: Sean Anderson 
---

 arch/arm/lib/semihosting.c | 21 +++--
 include/semihosting.h  | 25 -
 2 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/arch/arm/lib/semihosting.c b/arch/arm/lib/semihosting.c
index c38892fdd8..b983cc3935 100644
--- a/arch/arm/lib/semihosting.c
+++ b/arch/arm/lib/semihosting.c
@@ -22,9 +22,6 @@
 #define SYSREAD0x06
 #define SYSFLEN0x0C
 
-#define MODE_READ  0x0
-#define MODE_READBIN   0x1
-
 /*
  * Call the handler
  */
@@ -46,28 +43,16 @@ static noinline long smh_trap(unsigned int sysnum, void 
*addr)
  * Open a file on the host. Mode is "r" or "rb" currently. Returns a file
  * descriptor or -1 on error.
  */
-long smh_open(const char *fname, char *modestr)
+long smh_open(const char *fname, enum smh_open_mode mode)
 {
long fd;
-   unsigned long mode;
struct smh_open_s {
const char *fname;
unsigned long mode;
size_t len;
} open;
 
-   debug("%s: file \'%s\', mode \'%s\'\n", __func__, fname, modestr);
-
-   /* Check the file mode */
-   if (!(strcmp(modestr, "r"))) {
-   mode = MODE_READ;
-   } else if (!(strcmp(modestr, "rb"))) {
-   mode = MODE_READBIN;
-   } else {
-   printf("%s: ERROR mode \'%s\' not supported\n", __func__,
-  modestr);
-   return -1;
-   }
+   debug("%s: file \'%s\', mode \'%u\'\n", __func__, fname, mode);
 
open.fname = fname;
open.len = strlen(fname);
@@ -155,7 +140,7 @@ static int smh_load_file(const char * const name, ulong 
load_addr,
long len;
long ret;
 
-   fd = smh_open(name, "rb");
+   fd = smh_open(name, MODE_READ | MODE_BINARY);
if (fd == -1)
return -1;
 
diff --git a/include/semihosting.h b/include/semihosting.h
index 3843863046..cf54819192 100644
--- a/include/semihosting.h
+++ b/include/semihosting.h
@@ -6,7 +6,30 @@
 #ifndef _SEMIHOSTING_H
 #define _SEMIHOSTING_H
 
-long smh_open(const char *fname, char *modestr);
+/**
+ * enum smh_open_mode - Numeric file modes for use with smh_open()
+ * MODE_READ: 'r'
+ * MODE_BINARY: 'b'
+ * MODE_PLUS: '+'
+ * MODE_WRITE: 'w'
+ * MODE_APPEND: 'a'
+ *
+ * These modes represent the mode string used by fopen(3) in a form which can
+ * be passed to smh_open(). These do NOT correspond directly to %O_RDONLY,
+ * %O_CREAT, etc; see fopen(3) for details. In particular, @MODE_PLUS
+ * effectively results in adding %O_RDWR, and @MODE_WRITE will add %O_TRUNC.
+ * For compatibility, @MODE_BINARY should be added when opening non-text files
+ * (such as images).
+ */
+enum smh_open_mode {
+   MODE_READ   = 0x0,
+   MODE_BINARY = 0x1,
+   MODE_PLUS   = 0x2,
+   MODE_WRITE  = 0x4,
+   MODE_APPEND = 0x8,
+};
+
+long smh_open(const char *fname, enum smh_open_mode mode);
 long smh_read(long fd, void *memp, size_t len);
 long smh_close(long fd);
 long smh_flen(long fd);
-- 
2.25.1



[PATCH 07/17] arm: smh: Return errno on error

2022-03-03 Thread Sean Anderson
Instead of printing in what are now library functions, try to return a
numeric error code. This also adjust some functions (such as read) to
behave more similarly to read(2). For example, we now return the number
of bytes read instead of failing immediately on a short read.

Signed-off-by: Sean Anderson 
---

 arch/arm/lib/semihosting.c | 67 --
 1 file changed, 36 insertions(+), 31 deletions(-)

diff --git a/arch/arm/lib/semihosting.c b/arch/arm/lib/semihosting.c
index b983cc3935..1686457685 100644
--- a/arch/arm/lib/semihosting.c
+++ b/arch/arm/lib/semihosting.c
@@ -21,6 +21,7 @@
 #define SYSCLOSE   0x02
 #define SYSREAD0x06
 #define SYSFLEN0x0C
+#define SYSERRNO   0x13
 
 /*
  * Call the handler
@@ -39,10 +40,24 @@ static noinline long smh_trap(unsigned int sysnum, void 
*addr)
return result;
 }
 
-/*
- * Open a file on the host. Mode is "r" or "rb" currently. Returns a file
- * descriptor or -1 on error.
+/**
+ * smh_errno() - Read the host's errno
+ *
+ * This gets the value of the host's errno and negates it. The host's errno may
+ * or may not be set, so only call this function if a previous semihosting call
+ * has failed.
+ *
+ * Return: a negative error value
  */
+static int smh_errno(void)
+{
+   long ret = smh_trap(SYSERRNO, NULL);
+
+   if (ret > 0 && ret < INT_MAX)
+   return -ret;
+   return -EIO;
+}
+
 long smh_open(const char *fname, enum smh_open_mode mode)
 {
long fd;
@@ -61,9 +76,7 @@ long smh_open(const char *fname, enum smh_open_mode mode)
/* Open the file on the host */
fd = smh_trap(SYSOPEN, );
if (fd == -1)
-   printf("%s: ERROR fd %ld for file \'%s\'\n", __func__, fd,
-  fname);
-
+   return smh_errno();
return fd;
 }
 
@@ -86,19 +99,9 @@ long smh_read(long fd, void *memp, size_t len)
read.len = len;
 
ret = smh_trap(SYSREAD, );
-   if (ret < 0) {
-   /*
-* The ARM handler allows for returning partial lengths,
-* but in practice this never happens so rather than create
-* hard to maintain partial read loops and such, just fail
-* with an error message.
-*/
-   printf("%s: ERROR ret %ld, fd %ld, len %zu memp %p\n",
-  __func__, ret, fd, len, memp);
-   return -1;
-   }
-
-   return 0;
+   if (ret < 0)
+   return smh_errno();
+   return len - ret;
 }
 
 /*
@@ -112,9 +115,8 @@ long smh_close(long fd)
 
ret = smh_trap(SYSCLOSE, );
if (ret == -1)
-   printf("%s: ERROR fd %ld\n", __func__, fd);
-
-   return ret;
+   return smh_errno();
+   return 0;
 }
 
 /*
@@ -128,8 +130,7 @@ long smh_flen(long fd)
 
ret = smh_trap(SYSFLEN, );
if (ret == -1)
-   printf("%s: ERROR ret %ld, fd %ld\n", __func__, ret, fd);
-
+   return smh_errno();
return ret;
 }
 
@@ -141,28 +142,32 @@ static int smh_load_file(const char * const name, ulong 
load_addr,
long ret;
 
fd = smh_open(name, MODE_READ | MODE_BINARY);
-   if (fd == -1)
-   return -1;
+   if (fd < 0)
+   return fd;
 
len = smh_flen(fd);
if (len < 0) {
smh_close(fd);
-   return -1;
+   return len;
}
 
ret = smh_read(fd, (void *)load_addr, len);
smh_close(fd);
 
-   if (ret == 0) {
+   if (ret == len) {
*end_addr = load_addr + len - 1;
printf("loaded file %s from %08lX to %08lX, %08lX bytes\n",
   name,
   load_addr,
   *end_addr,
   len);
-   } else {
-   printf("read failed\n");
-   return 0;
+   } else if (ret >= 0) {
+   ret = -EAGAIN;
+   }
+
+   if (ret < 0) {
+   printf("read failed: %ld\n", ret);
+   return ret;
}
 
return 0;
-- 
2.25.1



[PATCH 04/17] arm: smh: Add semihosting entry to MAINTAINERS

2022-03-03 Thread Sean Anderson
These files are spread all over the tree, so just use a regex. Orphaned
for now, since this is more of a "one-off" series. Though I'll be happy
to review patches.

Signed-off-by: Sean Anderson 
---

 MAINTAINERS | 4 
 1 file changed, 4 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index fb171e0c68..8d9792c8b2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1148,6 +1148,10 @@ F:   arch/sandbox/
 F: doc/arch/sandbox.rst
 F: include/dt-bindings/*/sandbox*.h
 
+SEMIHOSTING
+S: Orphaned
+N: semihosting
+
 SETEXPR
 M: Roland Gaudig 
 S: Maintained
-- 
2.25.1



[PATCH 03/17] doc: ls1046ardb: Expand boot mode section

2022-03-03 Thread Sean Anderson
This adds some additional info about booting from different sources,
including the correct switch positions.

Signed-off-by: Sean Anderson 
---

 doc/board/nxp/ls1046ardb.rst | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/doc/board/nxp/ls1046ardb.rst b/doc/board/nxp/ls1046ardb.rst
index 4bfeaa93dd..c73516c070 100644
--- a/doc/board/nxp/ls1046ardb.rst
+++ b/doc/board/nxp/ls1046ardb.rst
@@ -95,6 +95,17 @@ Start Address  End AddressDescriptionSize
 
 Booting Options
 ---
-- QSPI boot
-- SD boot
-- eMMC boot
+
+NB: The reference manual documents the RCW source with the *least-significant
+bit first*.
+
+QSPI boot
+^
+
+This is the default. ``{ SW5[0:8], SW4[0] }`` should be ``0010_0010_0``.
+
+SD boot and eMMC boot
+^
+
+``{ SW5[0:8], SW4[0] }`` should be ``0010__0``. eMMC is selected only if
+there is no SD card in the slot.
-- 
2.25.1



[PATCH 02/17] nxp: ls1046ardb: Convert README to rST

2022-03-03 Thread Sean Anderson
This converts the readme for this board to rST. I have tried not to
change any semantics from the original (though I did convert MB to M).

Signed-off-by: Sean Anderson 
---

 board/freescale/ls1046ardb/MAINTAINERS |   1 +
 board/freescale/ls1046ardb/README  |  76 ---
 doc/board/nxp/index.rst|   1 +
 doc/board/nxp/ls1046ardb.rst   | 100 +
 4 files changed, 102 insertions(+), 76 deletions(-)
 delete mode 100644 board/freescale/ls1046ardb/README
 create mode 100644 doc/board/nxp/ls1046ardb.rst

diff --git a/board/freescale/ls1046ardb/MAINTAINERS 
b/board/freescale/ls1046ardb/MAINTAINERS
index efdea22bde..3c8cfe720d 100644
--- a/board/freescale/ls1046ardb/MAINTAINERS
+++ b/board/freescale/ls1046ardb/MAINTAINERS
@@ -14,3 +14,4 @@ F:configs/ls1046ardb_tfa_SECURE_BOOT_defconfig
 F: configs/ls1046ardb_SECURE_BOOT_defconfig
 F: configs/ls1046ardb_sdcard_SECURE_BOOT_defconfig
 F: configs/ls1046ardb_qspi_SECURE_BOOT_defconfig
+F: doc/board/nxp/ls1046ardb.rst
diff --git a/board/freescale/ls1046ardb/README 
b/board/freescale/ls1046ardb/README
deleted file mode 100644
index 90c44f4bce..00
--- a/board/freescale/ls1046ardb/README
+++ /dev/null
@@ -1,76 +0,0 @@
-Overview
-
-The LS1046A Reference Design Board (RDB) is a high-performance computing,
-evaluation, and development platform that supports the QorIQ LS1046A
-LayerScape Architecture processor. The LS1046ARDB provides SW development
-platform for the Freescale LS1046A processor series, with a complete
-debugging environment. The LS1046A RDB is lead-free and RoHS-compliant.
-
-LS1046A SoC Overview
-
-Please refer arch/arm/cpu/armv8/fsl-layerscape/doc/README.soc for LS1046A
-SoC overview.
-
- LS1046ARDB board Overview
- ---
- - SERDES1 Connections, 4 lanes supporting:
-  - Lane0: 10GBase-R with x1 RJ45 connector
-  - Lane1: 10GBase-R Cage
-  - Lane2: SGMII.5
-  - Lane3: SGMII.6
- - SERDES2 Connections, 4 lanes supporting:
-  - Lane0: PCIe1 with miniPCIe slot
-  - Lane1: PCIe2 with PCIe x2 slot
-  - Lane2: PCIe3 with PCIe x4 slot
-  - Lane3: SATA
- - DDR Controller
- - 8GB 64bits DDR4 SDRAM. Support rates of up to 2133MT/s
- -IFC/Local Bus
-- One 512 MB NAND flash with ECC support
-- CPLD connection
- - USB 3.0
-- one Type A port, one Micro-AB port
- - SDHC: connects directly to a full SD/MMC slot
- - DSPI: 64 MB high-speed flash Memory for boot code and storage (up to 108MHz)
- - 4 I2C controllers
- - UART
-   - Two 4-pin serial ports at up to 115.2 Kbit/s
-   - Two DB9 D-Type connectors supporting one Serial port each
- - ARM JTAG support
-
-Memory map from core's view
-
-Start Address   End Address DescriptionSize
-0x00__ - 0x00_000F_  Secure Boot ROM   1MB
-0x00_0100_ - 0x00_0FFF_  CCSRBAR   240MB
-0x00_1000_ - 0x00_1000_  OCRAM064KB
-0x00_1001_ - 0x00_1001_  OCRAM164KB
-0x00_2000_ - 0x00_20FF_  DCSR  16MB
-0x00_7E80_ - 0x00_7E80_  IFC - NAND Flash  64KB
-0x00_7FB0_ - 0x00_7FB0_0FFF  IFC - CPLD4KB
-0x00_8000_ - 0x00__  DRAM1 2GB
-0x05__ - 0x05_07FF_  QMAN S/W Portal   128M
-0x05_0800_ - 0x05_0FFF_  BMAN S/W Portal   128M
-0x08_8000_ - 0x09__  DRAM2 6GB
-0x40__ - 0x47__  PCI Express1  32G
-0x48__ - 0x4F__  PCI Express2  32G
-0x50__ - 0x57__  PCI Express3  32G
-
-QSPI flash map:
-Start AddressEnd Address Description   Size
-0x00_4000_ - 0x00_400F_  RCW + PBI 1MB
-0x00_4010_ - 0x00_402F_  U-Boot2MB
-0x00_4030_ - 0x00_403F_  U-Boot Env1MB
-0x00_4040_ - 0x00_405F_  PPA   2MB
-0x00_4060_ - 0x00_408F_  Secure boot header
-+ bootscript   3MB
-0x00_4090_ - 0x00_4093_  FMan ucode256KB
-0x00_4094_ - 0x00_4097_  QE/uQE firmware   256KB
-0x00_4098_ - 0x00_40FF_  Reserved  6MB
-0x00_4100_ - 0x00_43FF_  FIT Image 48MB
-
-Booting Options

-a) QSPI boot
-b) SD boot
-c) eMMC boot
diff --git a/doc/board/nxp/index.rst b/doc/board/nxp/index.rst
index 63956287c5..4514b8951b 100644
--- a/doc/board/nxp/index.rst
+++ b/doc/board/nxp/index.rst
@@ -13,6 +13,7 @@ NXP Semiconductors
imx8qxp_mek
imxrt1020-evk
imxrt1050-evk
+   ls1046ardb
mx6sabreauto
mx6sabresd
mx6ul_14x14_evk
diff --git a/doc/board/nxp/ls1046ardb.rst b/doc/board/nxp/ls1046ardb.rst
new file mode 100644
index 00..4bfeaa93dd
--- /dev/null
+++ b/doc/board/nxp/ls1046ardb.rst
@@ -0,0 +1,100 @@
+.. SPDX-License-Identifier: 

[PATCH 00/17] arm: semihosting: Cleanups and new features

2022-03-03 Thread Sean Anderson
This cleans up the semihosting code and adds the following new features:

- hostfs support (like sandbox)
- support for being used as a SPL boot device
- serial device support

The main device affected by these changes is vexpress64, so I'd appreciate
if Linus (or anyone else) could try booting.

These changes are motivated by bringup for ls1046a. When forcing JTAG
boot, this device disables most communication peripherals, including
serial and ethernet devices. This appears to be fixed in later
generation devices, but we are stuck with it for now. Semihosting
provides an easy way to run a few console commands.

Future work could include modifying one of the reset handlers to catch
semihosting calls not handled by a debugger. This would allow using the
same U-Boot when booting from JTAG and when booting normally.
Additionally, we could use puts in more places. DM serial is especially
slow with semihisting because all we have is putc.

The patches in this series are organized as follows:
0-3: rST conversions and other documentation updates
4-8: Semihosting cleanups
9-13: Filesystem support (including SPL boot device)
14-15: Serial support
16: Documentation update
17: JTAG boot support for LS1046A

Patch 17 depends on [1].

[1] 
https://lore.kernel.org/u-boot/20220222183840.1355337-2-sean.ander...@seco.com/


Sean Anderson (17):
  doc: Convert semihosting readme to rST
  nxp: ls1046ardb: Convert README to rST
  doc: ls1046ardb: Expand boot mode section
  arm: smh: Add semihosting entry to MAINTAINERS
  arm: smh: Export semihosting functions
  arm: smh: Use numeric modes for smh_open
  arm: smh: Return errno on error
  arm: smh: Document functions in header
  arm: smh: Add some file manipulation commands
  spl: Add semihosting boot method
  fs: Add semihosting filesystem
  cmd: fdt: Use start/size for chosen instead of start/end
  arm: smh: Remove smhload command
  arm: smh: Add some functions for working with the host console
  serial: Add semihosting driver
  doc: smh: Update semihosting documentation
  ls1046ardb: Add support for JTAG boot

 MAINTAINERS |   4 +
 arch/arm/Kconfig|  25 ++-
 arch/arm/cpu/armv8/fsl-layerscape/spl.c |   2 +
 arch/arm/include/asm/spl.h  |   1 +
 arch/arm/lib/semihosting.c  | 209 ++--
 board/freescale/ls1046ardb/MAINTAINERS  |   1 +
 board/freescale/ls1046ardb/README   |  76 -
 cmd/fdt.c   |   6 +-
 common/spl/Makefile |   1 +
 common/spl/spl_semihosting.c|  71 
 configs/vexpress_aemv8a_semi_defconfig  |   2 +-
 disk/part.c |   4 +-
 doc/README.semihosting  |  38 -
 doc/board/nxp/index.rst |   1 +
 doc/board/nxp/ls1046ardb.rst| 182 +
 doc/usage/index.rst |   1 +
 doc/usage/semihosting.rst   |  51 ++
 drivers/serial/Kconfig  |  22 +++
 drivers/serial/Makefile |   1 +
 drivers/serial/serial.c |   2 +
 drivers/serial/serial_semihosting.c | 108 
 fs/Makefile |   1 +
 fs/fs.c |  20 +++
 fs/semihostingfs.c  | 115 +
 include/configs/ls1046ardb.h|   2 +
 include/fs.h|   1 +
 include/semihosting.h   | 108 
 include/semihostingfs.h |  21 +++
 28 files changed, 832 insertions(+), 244 deletions(-)
 delete mode 100644 board/freescale/ls1046ardb/README
 create mode 100644 common/spl/spl_semihosting.c
 delete mode 100644 doc/README.semihosting
 create mode 100644 doc/board/nxp/ls1046ardb.rst
 create mode 100644 doc/usage/semihosting.rst
 create mode 100644 drivers/serial/serial_semihosting.c
 create mode 100644 fs/semihostingfs.c
 create mode 100644 include/semihosting.h
 create mode 100644 include/semihostingfs.h

-- 
2.25.1



[PATCH 01/17] doc: Convert semihosting readme to rST

2022-03-03 Thread Sean Anderson
This converts the semihosting readme to rST. I have tried to make only
cosmetic changes, but I did fix up the first link (which was broken).

Signed-off-by: Sean Anderson 
---

 doc/usage/index.rst   |  1 +
 .../semihosting.rst}  | 35 +++
 2 files changed, 21 insertions(+), 15 deletions(-)
 rename doc/{README.semihosting => usage/semihosting.rst} (53%)

diff --git a/doc/usage/index.rst b/doc/usage/index.rst
index 964d761e13..569da2bdd1 100644
--- a/doc/usage/index.rst
+++ b/doc/usage/index.rst
@@ -11,6 +11,7 @@ Use U-Boot
netconsole
partitions
cmdline
+   semihosting
 
 Shell commands
 --
diff --git a/doc/README.semihosting b/doc/usage/semihosting.rst
similarity index 53%
rename from doc/README.semihosting
rename to doc/usage/semihosting.rst
index f382d0131e..ed16e4d582 100644
--- a/doc/README.semihosting
+++ b/doc/usage/semihosting.rst
@@ -1,35 +1,40 @@
-SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright 2014 Broadcom Corporation.
- */
+.. SPDX-License-Identifier: GPL-2.0+
+.. Copyright 2014 Broadcom Corporation.
+
+Semihosting
+===
 
 Semihosting is ARM's way of having a real or virtual target communicate
 with a host or host debugger for basic operations such as file I/O,
-console I/O, etc. Please see
-http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0471c/Bgbjjgij.html
 for more information.
+console I/O, etc. Please see `Arm's semihosting documentation
+`_ for more
+information.
 
 For developing on armv8 virtual fastmodel platforms, semihosting is a
 valuable tool since it allows access to image/configuration files before
 eMMC or other NV media are available.
 
 There are two main ARM virtual Fixed Virtual Platform (FVP) models,
-Versatile Express (VE) FVP and BASE FVP (See
-http://www.arm.com/products/tools/models/fast-models/foundation-model.php)
+`Versatile Express (VE) FVP and BASE FVP
+`_.
 The initial vexpress64 u-boot board created here runs on the VE virtual
 platform using the license-free Foundation_v8 simulator. Fortunately,
 the Foundation_v8 simulator also supports the BASE_FVP model which
 companies can purchase licenses for and contain much more functionality.
-So we can, in u-boot, run either model by either using the VE FVP (default),
-or turning on CONFIG_BASE_FVP for the more full featured model.
+So we can, in U-Boot, run either model by either using the VE FVP (default),
+or turning on ``CONFIG_BASE_FVP`` for the more full featured model.
 
-Rather than create a new armv8 board similar to armltd/vexpress64, add
-semihosting calls to the existing one, enabled with CONFIG_SEMIHOSTING
-and CONFIG_BASE_FVP both set. Also reuse the existing board config file
+Rather than create a new armv8 board similar to ``armltd/vexpress64``, add
+semihosting calls to the existing one, enabled with ``CONFIG_SEMIHOSTING``
+and ``CONFIG_BASE_FVP`` both set. Also reuse the existing board config file
 vexpress_aemv8.h but differentiate the two models by the presence or
-absence of CONFIG_BASE_FVP. This change is tested and works on both the
+absence of ``CONFIG_BASE_FVP``. This change is tested and works on both the
 Foundation and Base fastmodel simulators.
 
-The semihosting code adds a command:
+Loading files
+-
+
+The semihosting code adds a "hostfs"::
 
   smhload   [env var]
 
-- 
2.25.1



Re: [PATCH v2 5/5] clk: scmi: register scmi clocks with CCF

2022-03-03 Thread Tom Rini
On Mon, Feb 21, 2022 at 09:22:42AM +0100, Etienne Carriere wrote:

> Implements SCMI APIs to retrieve the number exposed SCMI clocks using
> SCMI_PROTOCOL_ATTRIBUTES messages and the names of the clocks using
> SCMI_CLOCK_ATTRIBUTES messages.
> 
> This change updates sandbox SCMI clock test driver to manage these
> 2 new message IDs.
> 
> Cc: Lukasz Majewski 
> Cc: Sean Anderson 
> Cc: Clement Leger 
> Cc: Patrick Delaunay 
> Reviewed-by: Patrick Delaunay 
> Signed-off-by: Gabriel Fernandez 
> Signed-off-by: Etienne Carriere 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 4/5] firmware: scmi: fix sandbox and related tests for clock discovery

2022-03-03 Thread Tom Rini
On Mon, Feb 21, 2022 at 09:22:41AM +0100, Etienne Carriere wrote:

> Updates sandbox SCMI clock driver and tests since enabling CCF will
> mandate clock discovery that is all exposed SCMI clocks shall be
> discovered at initialization. For this reason, sandbox SCMI clock
> driver must emulate all clocks exposed by SCMI server, not only those
> effectively consumed by some other U-Boot devices.
> 
> Therefore the sandbox SCMI test driver exposes 3 clocks (IDs 0, 1 and 2)
> and sandbox SCMI clock consumer driver gets 2 of them.
> 
> Cc: Simon Glass 
> Reviewed-by: Patrick Delaunay 
> Signed-off-by: Etienne Carriere 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 3/5] scmi: change parameter dev in devm_scmi_process_msg

2022-03-03 Thread Tom Rini
On Mon, Feb 21, 2022 at 09:22:40AM +0100, Etienne Carriere wrote:

> Changes devm_scmi_process_msg() first argument from target parent device
> to current SCMI device and lookup the SCMI agent device among SCMI device
> parents for find the SCMI agent operator needed for communication with
> the firmware.
> 
> This change is needed in order to support CCF in clk_scmi driver unless
> what CCF will fail to find the right udevice related to exposed SCMI
> clocks.
> 
> This patch allows to simplify the caller sequence, using SCMI device
> reference as parameter instead of knowing SCMI uclass topology. This
> change also adds some protection in case devm_scmi_process_msg() API
> function is called for an invalid device type.
> 
> Cc: Lukasz Majewski 
> Cc: Sean Anderson 
> Cc: Jaehoon Chung 
> Cc: Patrick Delaunay 
> Reviewed-by: Patrick Delaunay 
> Signed-off-by: Etienne Carriere 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 2/5] sandbox: scmi: test against a single scmi agent

2022-03-03 Thread Tom Rini
On Mon, Feb 21, 2022 at 09:22:39AM +0100, Etienne Carriere wrote:

> As per DT bindings since Linux kernel v5.14, the device tree can define
> only 1 SCMI agent node that is named scmi [1]. As a consequence, change
> implementation of the SCMI driver test through sandbox architecture to
> reflect that.
> 
> This change updates sandbox test DT and sandbox SCMI driver accordingly
> since all these are impacted.
> 
> Cc: Simon Glass 
> Reviewed-by: Patrick Delaunay 
> Signed-off-by: Etienne Carriere 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 1/5] doc: binding: scmi: link to latest Linux kernel binding

2022-03-03 Thread Tom Rini
On Mon, Feb 21, 2022 at 09:22:38AM +0100, Etienne Carriere wrote:

> Changes SCMI bindings documentation to relate to Linux kernel
> source tree that recently changed the bindings description to YAML
> format.
> 
> Reviewed-by: Patrick Delaunay 
> Signed-off-by: Etienne Carriere 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v4 0/5] fs/erofs: new filesystem

2022-03-03 Thread Tom Rini
On Thu, Mar 03, 2022 at 10:51:18PM +0800, Huang Jianan wrote:

> Hi Tom,
> 
> Would you mind taking some time to check if this version meets
> the requirements ?So we could have a chance to be merged
> into the next version ?
> 
> I have triggered a CI via Github PR based on this version :
> https://github.com/u-boot/u-boot/pull/133

It seems fine, yes.  The thing about that PR is that it doesn't use a
custom build of the Docker container that also has the tools, so the FS
tests aren't actually run.  I'll do that when I get to testing and
applying this, but if you can do that before hand to ensure the tests
really do run and pass, especially on Azure where things can be a tiny
bit trickier (since source directory is enforced read-only), that would
be great.

> 
> Thanks,
> Jianan
> 
> 在 2022/2/26 15:05, Huang Jianan 写道:
> > Changes since v3:
> >   - update tools/docker/Dockerfile;
> > 
> > Changes since v2:
> >   - sync up with erofs-utils 1.4;
> >   - update lib/lz4 to v1.8.3;
> >   - add test for filesystem functions;
> > 
> > Changes since v1:
> >   - fix the inconsistency between From and SoB;
> >   - add missing license header;
> > 
> > Huang Jianan (5):
> >fs/erofs: add erofs filesystem support
> >lib/lz4: update LZ4 decompressor module
> >fs/erofs: add lz4 decompression support
> >fs/erofs: add filesystem commands
> >test/py: Add tests for the erofs
> > 
> >   MAINTAINERS |   9 +
> >   cmd/Kconfig |   6 +
> >   cmd/Makefile|   1 +
> >   cmd/erofs.c |  42 ++
> >   configs/sandbox_defconfig   |   1 +
> >   fs/Kconfig  |   2 +
> >   fs/Makefile |   1 +
> >   fs/erofs/Kconfig|  21 +
> >   fs/erofs/Makefile   |   9 +
> >   fs/erofs/data.c | 311 +
> >   fs/erofs/decompress.c   |  78 
> >   fs/erofs/decompress.h   |  24 +
> >   fs/erofs/erofs_fs.h | 436 ++
> >   fs/erofs/fs.c   | 267 +++
> >   fs/erofs/internal.h | 313 +
> >   fs/erofs/namei.c| 252 +++
> >   fs/erofs/super.c| 105 +
> >   fs/erofs/zmap.c | 601 
> >   fs/fs.c |  22 +
> >   include/erofs.h |  19 +
> >   include/fs.h|   1 +
> >   include/u-boot/lz4.h|  49 ++
> >   lib/lz4.c   | 679 
> >   lib/lz4_wrapper.c   |  23 +-
> >   test/py/tests/test_fs/test_erofs.py | 211 +
> >   tools/docker/Dockerfile |   1 +
> >   26 files changed, 3269 insertions(+), 215 deletions(-)
> >   create mode 100644 cmd/erofs.c
> >   create mode 100644 fs/erofs/Kconfig
> >   create mode 100644 fs/erofs/Makefile
> >   create mode 100644 fs/erofs/data.c
> >   create mode 100644 fs/erofs/decompress.c
> >   create mode 100644 fs/erofs/decompress.h
> >   create mode 100644 fs/erofs/erofs_fs.h
> >   create mode 100644 fs/erofs/fs.c
> >   create mode 100644 fs/erofs/internal.h
> >   create mode 100644 fs/erofs/namei.c
> >   create mode 100644 fs/erofs/super.c
> >   create mode 100644 fs/erofs/zmap.c
> >   create mode 100644 include/erofs.h
> >   create mode 100644 test/py/tests/test_fs/test_erofs.py
> > 
> 

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 12/12] rockchip: fix boot_devices constants

2022-03-03 Thread Johan Jonker



On 3/3/22 15:37, Johan Jonker wrote:
> Hi Simon,
> 
> Thank you for your test report.
> As I don't always have the hardware, could the board maintainers help me
> identify u-boot specific property differences with Linux that need to be
> moved to a dtsi file.
> 
> Will send a new serie with fixes.
> 
> Johan
> 
> ===
> 
> After I sync rk3288.dtsi I get this warning.
> fdt64_t is generated by a script and is not something that I can update
> the regmap_init_mem_plat function for.
> Any advice here?


A possible solution with:

config ROCKCHIP_RK3288
select PHYS_64BIT

Adding PHYS_64BIT leads to other warning like this:

drivers/video/rockchip/rk_vop.c: In function ‘rk_vop_probe’:
drivers/video/rockchip/rk_vop.c:449:15: warning: cast to pointer from
integer of different size [-Wint-to-pointer-cast]
  priv->regs = (struct rk3288_vop *)dev_read_addr(dev);

Conclusion: a direct rk3288.dtsi sync from Linux with 64bit gives too
much work to drivers or DT reg changes.

Will look at a partial upgrade without reg size change.

Johan

> 
> ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make chromebook_jerry_defconfig
> 
>CC  spl/drivers/ram/rockchip/sdram_rk3288.o
> drivers/ram/rockchip/sdram_rk3288.c: In function ‘conv_of_plat’:
> drivers/ram/rockchip/sdram_rk3288.c:1032:41: warning: passing argument 2
> of ‘regmap_init_mem_plat’ from incompatible pointer type
> [-Wincompatible-pointer-types]
>   ret = regmap_init_mem_plat(dev, of_plat->reg,
>   ~~~^
> In file included from drivers/ram/rockchip/sdram_rk3288.c:18:
> include/regmap.h:391:58: note: expected ‘fdt_val_t *’ {aka ‘unsigned int
> *’} but argument is of type ‘fdt64_t *’ {aka ‘long long unsigned int *’}
>  int regmap_init_mem_plat(struct udevice *dev, fdt_val_t *reg, int count,
> 
> 
> On 3/3/22 04:37, Simon Glass wrote:
>> Hi Johan,
>>
>> On Mon, 28 Feb 2022 at 18:48, Johan Jonker  wrote:
>>>
>>> The DT node name pattern in mmc-controller.yaml for mmc
>>> is "^mmc(@.*)?$". The Rockchip mmc nodes have been synced
>>> with Linux, so update the boot_devices constants as well.
>>>
>>> Signed-off-by: Johan Jonker 
>>> Reviewed-by: Simon Glass 
>>> ---
>>>  arch/arm/mach-rockchip/rk3188/rk3188.c | 4 ++--
>>>  arch/arm/mach-rockchip/rk322x/rk322x.c | 4 ++--
>>>  arch/arm/mach-rockchip/rk3288/rk3288.c | 4 ++--
>>>  arch/arm/mach-rockchip/rk3328/rk3328.c | 4 ++--
>>>  arch/arm/mach-rockchip/rk3368/rk3368.c | 4 ++--
>>>  5 files changed, 10 insertions(+), 10 deletions(-)
>>
> 
>> I tested this series on snow and it seems fine.
>>
>> I tried it on jerry and got:
>>
>> DRAM init failed: -19
> 
>   noc: syscon@ffac {
>   compatible = "rockchip,rk3288-noc", "syscon";
>   reg = <0x0 0xffac 0x0 0x2000>;
> 
> Forgot something. Does that help or is there more that needs to be fixed?
> 
> ==>   u-boot,dm-pre-reloc;
> 
>   };
> 
> TODO: Must change/update dmc/noc reg size when I sync rk3288.dtsi.
> 
>>
>> It also seemed fine on bob although my display is not coming up, for
>> different reasons.
> 
> In SPL or full U-boot?
> 
> rk3288-veyron-chromebook.dtsi:
> 
>   aliases {
>   i2c20 = _tunnel;
>   video0 = 
>   video1 = 
>   };
> 
> Is this video alias something U-boot specific?
> Fixing U-boot video is beyond my U-boot knowledge.
> 
>>
>> Regards
>>
>> Simon


Re: [PULL] u-boot-at91-fixes-2022.04-a

2022-03-03 Thread Tom Rini
On Thu, Mar 03, 2022 at 10:08:29AM +, eugen.hris...@microchip.com wrote:

> Hello Tom,
> 
> Please pull tag u-boot-at91-fixes-2022.04-a , the first set of at91 
> fixes for the next cycle 2022.04 .
> 
> This fixes set includes only a single fix for the Ethernet on sama7g5ek 
> board which is broken at the moment.
> 
> Thanks,
> Eugen
> 
> 
> 
> The following changes since commit df887a045a1d726bbd654ef266e5cbe8cc0c2db3:
> 
>Prepare v2022.04-rc1 (2022-01-31 17:57:32 -0500)
> 
> are available in the Git repository at:
> 
>https://source.denx.de/u-boot/custodians/u-boot-at91.git 
> tags/u-boot-at91-fixes-2022.04-a
> 
> for you to fetch changes up to 17a9f3f53d644d025a1a9e6d3a61fc71adf8b9d8:
> 
>ARM: dts: at91: sama7g5ek: disable slew rate for GMACs non MDIO pins 
> (2022-02-04 13:53:58 +0200)
> 

I assume these dts changes are going upstream already and applied to
u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: pull request of u-boot-fsl-qoriq for v2022.04

2022-03-03 Thread Tom Rini
On Thu, Mar 03, 2022 at 06:05:47AM +, Priyanka Jain wrote:

> Dear Tom,
> 
> Please find my pull-request for u-boot-fsl-qoriq/master
> https://github.com/u-boot/u-boot/pull/132
> 
> Summary
> 
> Update and fixes for sl28, lx2, pblimage generation for some powerpc products
> 
> Regards
> Priyanka

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 06/14] misc: Add support for nvmem cells

2022-03-03 Thread Sean Anderson
Hi Simon,

On 3/1/22 9:58 AM, Simon Glass wrote:
> Hi Sean,
> 
> On Mon, 28 Feb 2022 at 09:43, Sean Anderson  wrote:
>>
>>
>>
>> On 2/26/22 1:36 PM, Simon Glass wrote:
>> > Hi Sean,
>> >
>> > On Mon, 7 Feb 2022 at 16:42, Sean Anderson  wrote:
>> >>
>> >> This adds support for "nvmem cells" as seen in Linux. The nvmem device
>> >> class in Linux is used for various assorted ROMs and EEPROMs. In this
>> >> sense, it is similar to UCLASS_MISC, but also includes
>> >> UCLASS_I2C_EEPROM, UCLASS_RTC, and UCLASS_MTD. While nvmem devices can
>> >> be accessed directly, they are most often used by reading/writing
>> >> contiguous values called "cells". Cells typically hold information like
>> >> calibration, versions, or configuration (such as mac addresses).
>> >>
>> >> nvmem devices can specify "cells" in their device tree:
>> >>
>> >> qfprom: eeprom@70 {
>> >> #address-cells = <1>;
>> >> #size-cells = <1>;
>> >> reg = <0x0070 0x10>;
>> >>
>> >> /* ... */
>> >>
>> >> tsens_calibration: calib@404 {
>> >> reg = <0x404 0x10>;
>> >> };
>> >> };
>> >>
>> >> which can then be referenced like:
>> >>
>> >> tsens {
>> >> /* ... */
>> >> nvmem-cells = <_calibration>;
>> >> nvmem-cell-names = "calibration";
>> >> };
>> >>
>> >> The tsens driver could then read the calibration value like:
>> >>
>> >> struct nvmem_cell cal_cell;
>> >> u8 cal[16];
>> >> nvmem_cell_get_by_name(dev, "calibration", _cell);
>> >> nvmem_cell_read(_cell, cal, sizeof(cal));
>> >>
>> >> Because nvmem devices are not all of the same uclass, supported uclasses
>> >> must register a nvmem_interface struct. This allows CONFIG_NVMEM to be
>> >> enabled without depending on specific uclasses. At the moment,
>> >> nvmem_interface is very bare-bones, and assumes that no initialization
>> >> is necessary. However, this could be amended in the future.
>> >>
>> >> Although I2C_EEPROM and MISC are quite similar (and could likely be
>> >> unified), they present different read/write function signatures. To
>> >> abstract over this, NVMEM uses the same read/write signature as Linux.
>> >> In particular, short read/writes are not allowed, which is allowed by
>> >> MISC.
>> >>
>> >> The functionality implemented by nvmem cells is very similar to that
>> >> provided by i2c_eeprom_partition. "fixed-partition"s for eeproms does
>> >> not seem to have made its way into Linux or into any device tree other
>> >> than sandbox. It is possible that with the introduction of this API it
>> >> would be possible to remove it.
>> >>
>> >> Signed-off-by: Sean Anderson 
>> >> ---
>> >>
>> >>  MAINTAINERS   |   7 ++
>> >>  doc/api/index.rst |   1 +
>> >>  doc/api/nvmem.rst |   7 ++
>> >>  drivers/misc/Kconfig  |  16 
>> >>  drivers/misc/Makefile |   1 +
>> >>  drivers/misc/nvmem.c  | 109 +
>> >>  include/nvmem.h   | 185 ++
>> >>  7 files changed, 326 insertions(+)
>> >>  create mode 100644 doc/api/nvmem.rst
>> >>  create mode 100644 drivers/misc/nvmem.c
>> >>  create mode 100644 include/nvmem.h
>> >
>> > Here I think it would be better to add a new uclass so that drivers
>> > which support it can add a child device in that uclass. This is done
>> > in lots of places in U-Boot.
>>
>> I'm not sure exactly what you have in mind. The issue is that there are at
>> least 6 uclasses which I would like to support:
>>
>> - UCLASS_MISC
>> - UCLASS_I2C_EEPROM
>> - UCLASS_RTC
>> - UCLASS_MTD
>> - UCLASS_FUSE (doesn't exist yet, but probably should)
>> - Possibly UCLASS_PMIC
>>
>> Most of these uclasses have existing interfaces which expose an NVMEM-like 
>> API,
>> in addition to other uclass-specific functionality. Instead of having an
>> additional API which drivers must implement, I would like to leverage these
>> existing APIs to make adding NVMEM support as painless as possible. NVMEM is
>> more of a "meta-uclass" which allows us to leverage existing read/write
>> functions in uclasses. If any additional devices are to be created, they need
>> to be created by the nvmem subsystem, or by the supported uclasses, rather 
>> than
>> in drivers.
> 
> I may be missing something as I have not looked in detail at your API changes.
> 
> But the way to have a consistent API is to use a uclass. We do this
> with BLK. When a PMIC have GPIOs, RTC and regulators, we add them as
> child devices. We also have it with bootstd, where a bootdev is
> created as a child device of a storage device. We can put the required
> stuff in a helper function. We can even avoid any new code in the
> drivers by using the pending event system.
> 
> Can you first help me understand what is wrong with using a new uclass?

I suppose it could be done this way.

Effectively, we are "picking" out two 

Re: [PATCH] arm: Add AM335x based CBC board

2022-03-03 Thread Tom Rini
On Thu, Mar 03, 2022 at 03:48:46PM +0100, Lukasz Majewski wrote:
> Hi Tom,
> 
> > On Thu, Mar 03, 2022 at 03:07:47PM +0100, Lukasz Majewski wrote:
> > > Hi Tom,
> > >   
> > > > On Thu, Mar 03, 2022 at 10:27:10AM +0100, Lukasz Majewski wrote:  
> > > > > Hi Tom,
> > > > > 
> > > > > > This commit adds CBC board to U-Boot.
> > > > > > 
> > > > > > U-Boot 2022.04-rc1-00271-g930634a4c9 (Feb 21 2022 - 15:08:13
> > > > > > +0100)
> > > > > > 
> > > > > > CPU  : AM335X-GP rev 2.1
> > > > > > Model: AM335x Bosch CBC
> > > > > > DRAM:  512 MiB
> > > > > > Core:  198 devices, 14 uclasses, devicetree: separate
> > > > > > MMC:   OMAP SD/MMC: 2, OMAP SD/MMC: 0, OMAP SD/MMC: 1
> > > > > > Loading Environment from MMC... OK
> > > > > > Boot Device is eMMC
> > > > > > CBC Variant found: BCT531
> > > > > > Net:   eth2: ethernet@4a10
> > > > > > Hit any key to stop autoboot:  0
> > > > > > 
> > > > > > Signed-off-by: Lukasz Majewski 
> > > > > > 
> > > > > > ---
> > > > > > 
> > > > > >  arch/arm/Kconfig|   1 +
> > > > > >  arch/arm/dts/Makefile   |   1 +
> > > > > >  arch/arm/dts/am335x-cbc-u-boot.dtsi |  18 ++
> > > > > >  arch/arm/dts/am335x-cbc.dts | 309
> > > > > >  arch/arm/dts/am335x-cbc.dtsi|
> > > > > > 136 +
> > > > 
> > > > Is this dts upstream?
> > > >   
> > > 
> > > No, not yet. This is the smallest required DTS for this board (and
> > > hence it is a subset of the full blown Linux kernel DTS).
> > > 
> > > (Shall it be first accepted to the Linux kernel?)  
> > 
> > Everything that's not -u-boot.dtsi stuff needs to be at least in
> > linux-next first, yes.  For all SoCs, not just am33xx.
> > 
> 
> But then I do have a question - what if I don't need the whole DTS
> accepted to Linux?
> 
> Would it be OK, to provide just a subset (to save space)?

If it's something that belongs to a U-Boot binding we haven't
upstreamed, it goes in -u-boot.dtsi.  Otherwise it goes in the full DTS
which gets upstreamed, even if the kernel doesn't use it, since that's
where DTS files live currently.

-- 
Tom


signature.asc
Description: PGP signature


Re: phy_connect_dev calling phy_reset???

2022-03-03 Thread Tim Harvey
On Mon, Feb 28, 2022 at 12:01 PM Tim Harvey  wrote:
>
> Greetings,
>
> I'm wondering if it is proper in U-Boot for phy_connect_dev() to
> always call phy_reset() which generates a soft reset via BMCR_RESET.
>
> For some (or most?) PHY's this resets specific PHY config such as
> RGMII delays and LED configuration that may have been configured by
> firmware running prior to U-Boot (SPL/TPL).
>
> I believe there was some discussion and thrash about this in the Linux
> kernel in the past and while I can't find the discussion or patches I
> see that for the current kernel BMCR_RESET is in genphy_soft_reset
> which() is not called in the generic phy_connect() but instead only
> called by a handful of phy drivers which I would expect is ok as those
> phy drivers would also be re-configuring the PHY.
>
> Specifically I have an issue with this with a board that has custom
> firmware code that runs prior to U-Boot and the BMCR reset is undoing
> specific PHY config that I've done in this firmware causing me to look
> at implementing PHY drivers in U-Boot that otherwise would not be
> needed.
>

Joe and Ramon,

Do you have any comment on removing the call to phy_reset in
phy_connect_dev? Linux delegates calling genphy_soft_reset to the phy
drivers that need to whereas U-Boot seems to take the opposite
approach requireing a phy driver to set PHY_FLAG_BROKEN_RESET to skip
the reset. I think U-Boot should follow Linux and not perform a reset
without a PHY driver specifically needing it.

Best regards,

Tim


Re: [EXT] Re: [PATCH v8 01/15] crypto/fsl: Add support for CAAM Job ring driver model

2022-03-03 Thread Stefano Babic

Hi,

On 03.03.22 14:41, Gaurav Jain wrote:

Hi Stefano

As we have not received any response from imx6dl_mamoj board maintainer.
I propose the below solution

--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -49,8 +49,8 @@ config USE_IMXIMG_PLUGIN  config IMX_HAB
-   select FSL_CAAM if HAS_CAAM
-   imply CMD_DEKBLOB if HAS_CAAM
+   imply FSL_CAAM if HAS_CAAM
+   imply CMD_DEKBLOB if FSL_CAAM
  Help



IMO this is ok, I was also wrong, Marek is not the maintainer of this 
board. This was the only board with broken build - let's say, I will 
still wait a couple of days, and if there is no comments, I will apply 
your series (but then V10). I can apply this fix myself, no need to post 
the series again (I have not seen any other comment or request to change).


Regards,
Stefano


--- a/configs/imx6dl_mamoj_defconfig
+++ b/configs/imx6dl_mamoj_defconfig
@@ -59,3 +59,4 @@ CONFIG_USB_GADGET_MANUFACTURER="FSL"
+CONFIG_FSL_CAAM=n

Need your help to review this or suggest any other solution.

Regards
Gaurav Jain


-Original Message-
From: Stefano Babic 
Sent: Thursday, March 3, 2022 6:32 PM
To: Gaurav Jain ; Stefano Babic ; u-
b...@lists.denx.de; Marek Vasut 
Cc: Fabio Estevam ; Peng Fan ;
Simon Glass ; Priyanka Jain ; Ye
Li ; Horia Geanta ; Ji Luo
; Franck Lenormand ; Silvano Di
Ninno ; Sahil Malhotra ;
Pankaj Gupta ; Varun Sethi ; dl-
uboot-imx ; Shengzhou Liu ;
Mingkai Hu ; Rajesh Bhagat ;
Meenakshi Aggarwal ; Wasim Khan
; Alison Wang ; Pramod
Kumar ; Andy Tang ;
Adrian Alonso ; Vladimir Oltean 
Subject: Re: [EXT] Re: [PATCH v8 01/15] crypto/fsl: Add support for CAAM Job
ring driver model

Caution: EXT Email

On 03.03.22 13:44, Gaurav Jain wrote:

Hello Stefano

A gentle reminder!!
Need your help to check the proposed solution to fix imx6dl_mamoj SPL size

issue shared in last mail.

Ouch...is there a solution ? I confess I have not seen, is there an answer by
Marek ?

Regards,
Stefano



Regards
Gaurav Jain


-Original Message-
From: Gaurav Jain
Sent: Friday, February 25, 2022 12:33 PM
To: Stefano Babic ; u-boot@lists.denx.de; Marek Vasut

Cc: Fabio Estevam ; Peng Fan ;
Simon Glass ; Priyanka Jain
; Ye Li ; Horia Geanta
; Ji Luo ; Franck Lenormand
; Silvano Di Ninno
; Sahil Malhotra ;
Pankaj Gupta ; Varun Sethi ;
dl- uboot-imx ; Shengzhou Liu
; Mingkai Hu ; Rajesh
Bhagat ; Meenakshi Aggarwal
; Wasim Khan ;

Alison

Wang ; Pramod Kumar

;

Andy Tang ; Adrian Alonso ;
Vladimir Oltean 
Subject: RE: [EXT] Re: [PATCH v8 01/15] crypto/fsl: Add support for
CAAM Job ring driver model

Hello Stefano


-Original Message-
From: Gaurav Jain
Sent: Friday, February 11, 2022 3:09 PM
To: Stefano Babic ; u-boot@lists.denx.de; Marek
Vasut 
Cc: Fabio Estevam ; Peng Fan ;
Simon Glass ; Priyanka Jain
; Ye Li ; Horia Geanta
; Ji Luo ; Franck Lenormand
; Silvano Di Ninno
; Sahil Malhotra ;
Pankaj Gupta ; Varun Sethi ;
dl- uboot-imx ; Shengzhou Liu
; Mingkai Hu ; Rajesh
Bhagat ; Meenakshi Aggarwal
; Wasim Khan ;

Alison

Wang ; Pramod Kumar

;

Andy Tang ; Adrian Alonso
; Vladimir Oltean 
Subject: RE: [EXT] Re: [PATCH v8 01/15] crypto/fsl: Add support for
CAAM Job ring driver model

Hello Marek

A gentle reminder!!
Please help to check if some feature can be dropped in SPL from
imx6dl_mamoj board so that CAAM driver model patches can be accepted.

Regards
Gaurav Jain


-Original Message-
From: Gaurav Jain
Sent: Monday, February 7, 2022 12:43 PM
To: Stefano Babic ; u-boot@lists.denx.de; Marek
Vasut 
Cc: Fabio Estevam ; Peng Fan
; Simon Glass ; Priyanka Jain
; Ye Li ; Horia Geanta
; Ji Luo ; Franck Lenormand
; Silvano Di Ninno
; Sahil Malhotra ;
Pankaj Gupta ; Varun Sethi ;
dl- uboot-imx ; Shengzhou Liu
; Mingkai Hu ; Rajesh
Bhagat ; Meenakshi Aggarwal
; Wasim Khan ;

Alison

Wang ; Pramod Kumar

;

Andy Tang ; Adrian Alonso
; Vladimir Oltean 
Subject: RE: [EXT] Re: [PATCH v8 01/15] crypto/fsl: Add support for
CAAM Job ring driver model

Hello Marek


-Original Message-
From: Stefano Babic 
Sent: Saturday, February 5, 2022 7:46 PM
To: Gaurav Jain ; u-boot@lists.denx.de
Cc: Stefano Babic ; Fabio Estevam
; Peng Fan ; Simon Glass
; Priyanka Jain ; Ye Li
; Horia Geanta ; Ji Luo
; Franck Lenormand ;
Silvano Di Ninno ; Sahil Malhotra
; Pankaj Gupta ;
Varun Sethi ; dl-uboot-imx ;
Shengzhou Liu ; Mingkai Hu
; Rajesh Bhagat ;
Meenakshi Aggarwal ; Wasim Khan
;

Alison

Wang ; Pramod Kumar

;

Andy Tang ; Adrian Alonso
; Vladimir Oltean ;
Marek Vasut 
Subject: [EXT] Re: [PATCH v8 01/15] crypto/fsl: Add support for
CAAM Job ring driver model

Caution: EXT Email

Hi Gaurav,

rather I still have issues to run CI with this applied. The reason
is that this adds an overhead to SPL and it breaks the board
imx6dl_mamoj because SPL exceeds the maximum size for a DL SOC.

See
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2F
so
ur
ce.d
enx.de%2Fu-boot%2Fcustodians%2Fu-boot-imx%2F-
%2Fjobs%2F387370data=04%7C01%7Cgaurav.jain%40nxp.com%7

C

3a

2

73










Re: [PATCH v4 0/5] fs/erofs: new filesystem

2022-03-03 Thread Huang Jianan

Hi Tom,

Would you mind taking some time to check if this version meets
the requirements ?So we could have a chance to be merged
into the next version ?

I have triggered a CI via Github PR based on this version :
https://github.com/u-boot/u-boot/pull/133

Thanks,
Jianan

在 2022/2/26 15:05, Huang Jianan 写道:

Changes since v3:
  - update tools/docker/Dockerfile;

Changes since v2:
  - sync up with erofs-utils 1.4;
  - update lib/lz4 to v1.8.3;
  - add test for filesystem functions;

Changes since v1:
  - fix the inconsistency between From and SoB;
  - add missing license header;

Huang Jianan (5):
   fs/erofs: add erofs filesystem support
   lib/lz4: update LZ4 decompressor module
   fs/erofs: add lz4 decompression support
   fs/erofs: add filesystem commands
   test/py: Add tests for the erofs

  MAINTAINERS |   9 +
  cmd/Kconfig |   6 +
  cmd/Makefile|   1 +
  cmd/erofs.c |  42 ++
  configs/sandbox_defconfig   |   1 +
  fs/Kconfig  |   2 +
  fs/Makefile |   1 +
  fs/erofs/Kconfig|  21 +
  fs/erofs/Makefile   |   9 +
  fs/erofs/data.c | 311 +
  fs/erofs/decompress.c   |  78 
  fs/erofs/decompress.h   |  24 +
  fs/erofs/erofs_fs.h | 436 ++
  fs/erofs/fs.c   | 267 +++
  fs/erofs/internal.h | 313 +
  fs/erofs/namei.c| 252 +++
  fs/erofs/super.c| 105 +
  fs/erofs/zmap.c | 601 
  fs/fs.c |  22 +
  include/erofs.h |  19 +
  include/fs.h|   1 +
  include/u-boot/lz4.h|  49 ++
  lib/lz4.c   | 679 
  lib/lz4_wrapper.c   |  23 +-
  test/py/tests/test_fs/test_erofs.py | 211 +
  tools/docker/Dockerfile |   1 +
  26 files changed, 3269 insertions(+), 215 deletions(-)
  create mode 100644 cmd/erofs.c
  create mode 100644 fs/erofs/Kconfig
  create mode 100644 fs/erofs/Makefile
  create mode 100644 fs/erofs/data.c
  create mode 100644 fs/erofs/decompress.c
  create mode 100644 fs/erofs/decompress.h
  create mode 100644 fs/erofs/erofs_fs.h
  create mode 100644 fs/erofs/fs.c
  create mode 100644 fs/erofs/internal.h
  create mode 100644 fs/erofs/namei.c
  create mode 100644 fs/erofs/super.c
  create mode 100644 fs/erofs/zmap.c
  create mode 100644 include/erofs.h
  create mode 100644 test/py/tests/test_fs/test_erofs.py





  1   2   >