Re: [PATCH u-boot-marvell 13/13] tools: kwboot: Resend first 3 xmodem retry packets immediately

2021-10-25 Thread Stefan Roese

On 25.10.21 15:13, Marek Behún wrote:

From: Pali Rohár 

Currently when kwboot receive some garbage reply which does not understand,
it waits 1s before it tries to resend packet again.

The most common error on UART is that receiver sees some bit flipped which
results in invalid reply.

This behavior slows down xmodem transfer over UART as basically on every
error kwboot is waiting one second.

To fix this, try to resend xmodem packet for first 3 attempts immediately
without any delay. If broken reply is received also after the 3 attempts,
continue retrying with 1s delay like it was before.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


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

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 16c5a84825..bb7cae9f05 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -851,7 +851,8 @@ kwboot_baud_magic_handle(int fd, char c, int baudrate)
  }
  
  static int

-kwboot_xm_recv_reply(int fd, char *c, int allow_non_xm, int *non_xm_print,
+kwboot_xm_recv_reply(int fd, char *c, int nak_on_non_xm,
+int allow_non_xm, int *non_xm_print,
 int baudrate, int *baud_changed)
  {
int timeout = allow_non_xm ? KWBOOT_HDR_RSP_TIMEO : blk_rsp_timeo;
@@ -904,6 +905,10 @@ kwboot_xm_recv_reply(int fd, char *c, int allow_non_xm, 
int *non_xm_print,
*non_xm_print = 1;
}
} else {
+   if (nak_on_non_xm) {
+   *c = NAK;
+   break;
+   }
timeout = recv_until - _now();
if (timeout < 0) {
errno = ETIMEDOUT;
@@ -937,7 +942,8 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int 
allow_non_xm,
*done_print = 1;
}
  
-		rc = kwboot_xm_recv_reply(fd, , allow_non_xm, _xm_print,

+   rc = kwboot_xm_recv_reply(fd, , retries < 3,
+ allow_non_xm, _xm_print,
  baudrate, _changed);
if (rc)
goto can;
@@ -979,7 +985,8 @@ kwboot_xm_finish(int fd)
if (rc)
return rc;
  
-		rc = kwboot_xm_recv_reply(fd, , 0, NULL, 0, NULL);

+   rc = kwboot_xm_recv_reply(fd, , retries < 3,
+ 0, NULL, 0, NULL);
if (rc)
return rc;
} while (c == NAK && retries++ < 16);




Viele Grüße,
Stefan

--
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 12/13] tools: kwboot: Change retry loop from decreasing to increasing

2021-10-25 Thread Stefan Roese

On 25.10.21 15:13, Marek Behún wrote:

From: Pali Rohár 

This patch does not change behavior of the code, just allows to implement
new changes more easily.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


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

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 5d7cb7a774..16c5a84825 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -925,7 +925,7 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int 
allow_non_xm,
  
  	*done_print = 0;
  
-	retries = 16;

+   retries = 0;
do {
rc = kwboot_tty_send(fd, block, sizeof(*block));
if (rc)
@@ -944,7 +944,7 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int 
allow_non_xm,
  
  		if (!allow_non_xm && c != ACK)

kwboot_progress(-1, '+');
-   } while (c == NAK && retries-- > 0);
+   } while (c == NAK && retries++ < 16);
  
  	if (non_xm_print)

kwboot_printv("\n");
@@ -973,7 +973,7 @@ kwboot_xm_finish(int fd)
  
  	kwboot_printv("Finishing transfer\n");
  
-	retries = 16;

+   retries = 0;
do {
rc = kwboot_tty_send_char(fd, EOT);
if (rc)
@@ -982,7 +982,7 @@ kwboot_xm_finish(int fd)
rc = kwboot_xm_recv_reply(fd, , 0, NULL, 0, NULL);
if (rc)
return rc;
-   } while (c == NAK && retries-- > 0);
+   } while (c == NAK && retries++ < 16);
  
  	return _xm_reply_to_error(c);

  }




Viele Grüße,
Stefan

--
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 11/13] tools: kwboot: Calculate real used space in kwbimage header when calling kwboot_img_grow_hdr()

2021-10-25 Thread Stefan Roese

On 25.10.21 15:13, Marek Behún wrote:

From: Pali Rohár 

Size of the header stored in kwbimage may be larger than real used size in
the kwbimage header. If there is unused space in kwbimage header then use
it for growing it. So update code to calculate used space of kwbimage
header.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


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

diff --git a/tools/kwboot.c b/tools/kwboot.c
index bb7555369c..5d7cb7a774 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -1318,11 +1318,20 @@ kwboot_img_grow_hdr(void *img, size_t *size, size_t 
grow)
  {
uint32_t hdrsz, datasz, srcaddr;
struct main_hdr_v1 *hdr = img;
+   struct opt_hdr_v1 *ohdr;
uint8_t *data;
  
  	srcaddr = le32_to_cpu(hdr->srcaddr);
  
-	hdrsz = kwbheader_size(img);

+   /* calculate real used space in kwbimage header */
+   if (kwbimage_version(img) == 0) {
+   hdrsz = kwbheader_size(img);
+   } else {
+   hdrsz = sizeof(*hdr);
+   for_each_opt_hdr_v1 (ohdr, hdr)
+   hdrsz += opt_hdr_v1_size(ohdr);
+   }
+
data = (uint8_t *)img + srcaddr;
datasz = *size - srcaddr;
  
@@ -1339,8 +1348,10 @@ kwboot_img_grow_hdr(void *img, size_t *size, size_t grow)
  
  	if (kwbimage_version(img) == 1) {

hdrsz += grow;
-   hdr->headersz_msb = hdrsz >> 16;
-   hdr->headersz_lsb = cpu_to_le16(hdrsz & 0x);
+   if (hdrsz > kwbheader_size(img)) {
+   hdr->headersz_msb = hdrsz >> 16;
+   hdr->headersz_lsb = cpu_to_le16(hdrsz & 0x);
+   }
}
  }
  




Viele Grüße,
Stefan

--
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 10/13] tools: kwboot: Do not modify kwbimage header before increasing its size

2021-10-25 Thread Stefan Roese

On 25.10.21 15:13, Marek Behún wrote:

From: Pali Rohár 

This ensures that kwboot_img_grow_hdr() function still sees valid kwbimage
header.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


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

diff --git a/tools/kwboot.c b/tools/kwboot.c
index adec4ec97d..bb7555369c 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -1352,17 +1352,18 @@ kwboot_add_bin_ohdr_v1(void *img, size_t *size, 
uint32_t binsz)
uint32_t num_args;
uint32_t offset;
uint32_t ohdrsz;
+   uint8_t *prev_ext;
  
  	if (hdr->ext & 0x1) {

for_each_opt_hdr_v1 (ohdr, img)
if (opt_hdr_v1_next(ohdr) == NULL)
break;
  
-		*opt_hdr_v1_ext(ohdr) |= 1;

-   ohdr = opt_hdr_v1_next(ohdr);
+   prev_ext = opt_hdr_v1_ext(ohdr);
+   ohdr = _opt_hdr_v1_next(ohdr);
} else {
-   hdr->ext |= 1;
ohdr = (void *)(hdr + 1);
+   prev_ext = >ext;
}
  
  	/*

@@ -1377,6 +1378,8 @@ kwboot_add_bin_ohdr_v1(void *img, size_t *size, uint32_t 
binsz)
ohdrsz = sizeof(*ohdr) + 4 + 4 * num_args + binsz + 4;
kwboot_img_grow_hdr(hdr, size, ohdrsz);
  
+	*prev_ext |= 1;

+
ohdr->headertype = OPT_HDR_V1_BINARY_TYPE;
ohdr->headersz_msb = ohdrsz >> 16;
ohdr->headersz_lsb = cpu_to_le16(ohdrsz & 0x);




Viele Grüße,
Stefan

--
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/13] tools: kwboot: Simplify code for aligning image header

2021-10-25 Thread Stefan Roese

On 25.10.21 15:13, Marek Behún wrote:

From: Pali Rohár 

Expression (hdrsz % KWBOOT_XM_BLKSZ) is non-zero therefore expression
(KWBOOT_XM_BLKSZ - hdrsz % KWBOOT_XM_BLKSZ) is always less than value
KWBOOT_XM_BLKSZ. So there is no need to add another modulo. Also rename
variable `offset` to `grow` which better describes what is stored in
this variable.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


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

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 7fd28aa754..adec4ec97d 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -1563,8 +1563,7 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)
}
  
  	if (hdrsz % KWBOOT_XM_BLKSZ) {

-   size_t offset = (KWBOOT_XM_BLKSZ - hdrsz % KWBOOT_XM_BLKSZ) %
-   KWBOOT_XM_BLKSZ;
+   size_t grow = KWBOOT_XM_BLKSZ - hdrsz % KWBOOT_XM_BLKSZ;
  
  		if (is_secure) {

fprintf(stderr, "Cannot align image with secure 
header\n");
@@ -1572,7 +1571,7 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)
}
  
  		kwboot_printv("Aligning image header to Xmodem block size\n");

-   kwboot_img_grow_hdr(img, size, offset);
+   kwboot_img_grow_hdr(img, size, grow);
}
  
  	hdr->checksum = kwboot_hdr_csum8(hdr) - csum;





Viele Grüße,
Stefan

--
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/13] tools: kwboot: Show verbose message when waiting for baudrate change magic

2021-10-25 Thread Stefan Roese

On 25.10.21 15:12, Marek Behún wrote:

From: Pali Rohár 

It is hard to debug why kwboot is failing when the last message is
'Finishing transfer' and no additional output. So show verbose message when
kwboot finished transfer and is waiting for baudrate change magic sequence.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


---
  tools/kwboot.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 6228838228..7fd28aa754 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -1065,7 +1065,7 @@ kwboot_xmodem(int tty, const void *_img, size_t size, int 
baudrate)
if (baudrate) {
char buf[sizeof(kwb_baud_magic)];
  
-		/* Wait 1s for baudrate change magic */

+   kwboot_printv("Waiting 1s for baudrate change magic\n");
rc = kwboot_tty_recv(tty, buf, sizeof(buf), 1000);
if (rc)
return rc;




Viele Grüße,
Stefan

--
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 07/13] tools: kwboot: Correctly set configuration of UART for BootROM messages

2021-10-25 Thread Stefan Roese

On 25.10.21 15:12, Marek Behún wrote:

From: Pali Rohár 

For kwbimage v1, tell BootROM to send BootROM messages to UART port number
0 (used also for UART booting) with default baudrate (which should be
115200) and do not touch UART MPP configuration.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


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

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 1131c2eb1c..6228838228 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -1507,6 +1507,17 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)
}
  
  	if (!is_secure) {

+   if (image_ver == 1) {
+   /*
+* Tell BootROM to send BootROM messages to UART port
+* number 0 (used also for UART booting) with default
+* baudrate (which should be 115200) and do not touch
+* UART MPP configuration.
+*/
+   hdr->options &= ~0x1F;
+   hdr->options |= MAIN_HDR_V1_OPT_BAUD_DEFAULT;
+   hdr->options |= 0 << 3;
+   }
if (image_ver == 0)
((struct main_hdr_v0 *)img)->nandeccmode = 
IBR_HDR_ECC_DISABLED;
hdr->nandpagesize = 0;




Viele Grüße,
Stefan

--
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/13] tools: kwboot: Recalculate 4-byte data checksum after injecting baudrate code

2021-10-25 Thread Stefan Roese

On 25.10.21 15:12, Marek Behún wrote:

From: Pali Rohár 

If data part of image is modified, update 4-byte data checksum.

It looks like A385 BootROM does not verify this checksum for image
loaded via UART, but we do not know if other BootROMs are also ignoring
it. It is always better to provide correct checksum.

Signed-off-by: Pali Rohár 
[ refactored ]
Signed-off-by: Marek Behún 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


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

diff --git a/tools/kwboot.c b/tools/kwboot.c
index bf26a667b7..1131c2eb1c 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -1544,6 +1544,9 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)
kwboot_printv("Injecting code for changing baudrate back\n");
_inject_baudrate_change_code(img, size, 1, baudrate, 115200);
  
+		/* Update the 32-bit data checksum */

+   *kwboot_img_csum32_ptr(img) = kwboot_img_csum32(img);
+
/* recompute header size */
hdrsz = kwbheader_size(hdr);
}




Viele Grüße,
Stefan

--
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 05/13] tools: kwboot: Inject baudrate change back code after data part

2021-10-25 Thread Stefan Roese

On 25.10.21 15:12, Marek Behún wrote:

From: Pali Rohár 

Some vendor U-Boot kwbimage binaries (e.g. those for A375) have load
address set to zero. Therefore it is not possible to inject code which
changes baudrate back to 115200 Bd before the data part.

So instead inject it after the data part and change kwbimage execution
address to that offset. Also store original execution address into
baudrate change code, so after it changes baudrate back to 115200 Bd, it
can jump to orignal address.

Signed-off-by: Pali Rohár 
[ refactored ]
Signed-off-by: Marek Behún 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


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

diff --git a/tools/kwboot.c b/tools/kwboot.c
index bc44301535..bf26a667b7 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -1295,34 +1295,22 @@ kwboot_img_is_secure(void *img)
  }
  
  static void *

-kwboot_img_grow_data_left(void *img, size_t *size, size_t grow)
+kwboot_img_grow_data_right(void *img, size_t *size, size_t grow)
  {
-   uint32_t hdrsz, datasz, srcaddr;
struct main_hdr_v1 *hdr = img;
-   uint8_t *data;
-
-   srcaddr = le32_to_cpu(hdr->srcaddr);
-
-   hdrsz = kwbheader_size(hdr);
-   data = (uint8_t *)img + srcaddr;
-   datasz = *size - srcaddr;
-
-   /* only move data if there is not enough space */
-   if (hdrsz + grow > srcaddr) {
-   size_t need = hdrsz + grow - srcaddr;
-
-   /* move data by enough bytes */
-   memmove(data + need, data, datasz);
-   *size += need;
-   srcaddr += need;
-   }
+   void *result;
  
-	srcaddr -= grow;

-   hdr->srcaddr = cpu_to_le32(srcaddr);
-   hdr->destaddr = cpu_to_le32(le32_to_cpu(hdr->destaddr) - grow);
+   /*
+* 32-bit checksum comes after end of image code, so we will be putting
+* new code there. So we get this pointer and then increase data size
+* (since increasing data size changes kwboot_img_csum32_ptr() return
+*  value).
+*/
+   result = kwboot_img_csum32_ptr(img);
hdr->blocksize = cpu_to_le32(le32_to_cpu(hdr->blocksize) + grow);
+   *size += grow;
  
-	return (uint8_t *)img + srcaddr;

+   return result;
  }
  
  static void

@@ -1400,14 +1388,20 @@ kwboot_add_bin_ohdr_v1(void *img, size_t *size, 
uint32_t binsz)
  }
  
  static void

-_copy_baudrate_change_code(struct main_hdr_v1 *hdr, void *dst, int pre,
-  int old_baud, int new_baud)
+_inject_baudrate_change_code(void *img, size_t *size, int pre,
+int old_baud, int new_baud)
  {
-   size_t codesz = sizeof(kwboot_baud_code);
-   uint8_t *code = dst;
+   uint32_t codesz = sizeof(kwboot_baud_code);
+   struct main_hdr_v1 *hdr = img;
+   uint8_t *code;
  
  	if (pre) {

-   size_t presz = sizeof(kwboot_pre_baud_code);
+   uint32_t presz = sizeof(kwboot_pre_baud_code);
+   uint32_t orig_datasz;
+
+   orig_datasz = le32_to_cpu(hdr->blocksize) - sizeof(uint32_t);
+
+   code = kwboot_img_grow_data_right(img, size, presz + codesz);
  
  		/*

 * We need to prepend code that loads lr register with original
@@ -1421,9 +1415,12 @@ _copy_baudrate_change_code(struct main_hdr_v1 *hdr, void 
*dst, int pre,
memcpy(code, kwboot_pre_baud_code, presz);
*(uint32_t *)code = hdr->execaddr;
  
-		hdr->execaddr = cpu_to_le32(le32_to_cpu(hdr->destaddr) + 4);

+   hdr->execaddr = cpu_to_le32(le32_to_cpu(hdr->destaddr) +
+   orig_datasz + 4);
  
  		code += presz;

+   } else {
+   code = kwboot_add_bin_ohdr_v1(img, size, codesz);
}
  
  	memcpy(code, kwboot_baud_code, codesz - 8);

@@ -1516,9 +1513,6 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)
}
  
  	if (baudrate) {

-   uint32_t codesz = sizeof(kwboot_baud_code);
-   void *code;
-
if (image_ver == 0) {
fprintf(stderr,
"Cannot inject code for changing baudrate into v0 
image header\n");
@@ -1539,20 +1533,16 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)
 */
kwboot_printv("Injecting binary header code for changing baudrate to 
%d Bd\n",
  baudrate);
-
-   code = kwboot_add_bin_ohdr_v1(img, size, codesz);
-   _copy_baudrate_change_code(hdr, code, 0, 115200, baudrate);
+   _inject_baudrate_change_code(img, size, 0, 115200, baudrate);
  
  		/*

 * Now inject code that changes the baudrate back to 115200 Bd.
-* This code is prepended to the data part of the image, so it
-* is executed before U-Boot proper.
+* This code 

Re: [PATCH u-boot-marvell 04/13] tools: kwboot: Validate 4-byte image data checksum

2021-10-25 Thread Stefan Roese

On 25.10.21 15:12, Marek Behún wrote:

From: Pali Rohár 

Data part of the image contains 4-byte checksum. Validate it when
processing the image.

Signed-off-by: Pali Rohár 
[ refactored ]
Signed-off-by: Marek Behún 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


---
  tools/kwboot.c | 34 ++
  1 file changed, 34 insertions(+)

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 4e29317f10..bc44301535 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -1251,6 +1251,37 @@ kwboot_hdr_csum8(const void *hdr)
return csum;
  }
  
+static uint32_t *

+kwboot_img_csum32_ptr(void *img)
+{
+   struct main_hdr_v1 *hdr = img;
+   uint32_t datasz;
+
+   datasz = le32_to_cpu(hdr->blocksize) - sizeof(uint32_t);
+
+   return img + le32_to_cpu(hdr->srcaddr) + datasz;
+}
+
+static uint32_t
+kwboot_img_csum32(const void *img)
+{
+   const struct main_hdr_v1 *hdr = img;
+   uint32_t datasz, csum = 0;
+   const uint32_t *data;
+
+   datasz = le32_to_cpu(hdr->blocksize) - sizeof(csum);
+   if (datasz % sizeof(uint32_t))
+   return 0;
+
+   data = img + le32_to_cpu(hdr->srcaddr);
+   while (datasz > 0) {
+   csum += le32_to_cpu(*data++);
+   datasz -= 4;
+   }
+
+   return cpu_to_le32(csum);
+}
+
  static int
  kwboot_img_is_secure(void *img)
  {
@@ -1462,6 +1493,9 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)
*size < le32_to_cpu(hdr->srcaddr) + le32_to_cpu(hdr->blocksize))
goto err;
  
+	if (kwboot_img_csum32(img) != *kwboot_img_csum32_ptr(img))

+   goto err;
+
is_secure = kwboot_img_is_secure(img);
  
  	if (hdr->blockid != IBR_HDR_UART_ID) {





Viele Grüße,
Stefan

--
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 03/13] tools: kwboot: Reserve enough space for patching kwbimage in memory

2021-10-25 Thread Stefan Roese

On 25.10.21 15:12, Marek Behún wrote:

From: Pali Rohár 

SPI image header and data parts do not have to be aligned to 128 byte
xmodem block size. So reserve additional memory for aligning header part
and additional memory for aligning data part.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


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

diff --git a/tools/kwboot.c b/tools/kwboot.c
index c55b41025b..4e29317f10 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -1672,8 +1672,10 @@ main(int argc, char **argv)
else
/* ensure we have enough space for baudrate change code */
after_img_rsv += KWBOOT_BAUDRATE_BIN_HEADER_SZ +
+KWBOOT_XM_BLKSZ +
 sizeof(kwboot_pre_baud_code) +
-sizeof(kwboot_baud_code);
+sizeof(kwboot_baud_code) +
+KWBOOT_XM_BLKSZ;
  
  	if (imgpath) {

img = kwboot_read_image(imgpath, , after_img_rsv);




Viele Grüße,
Stefan

--
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/13] tools: kwboot: Fix initialization of tty device

2021-10-25 Thread Stefan Roese

On 25.10.21 15:12, Marek Behún wrote:

From: Pali Rohár 

Explicitly disable 2 stop bits by clearing CSTOPB flag, disable modem
control flow by clearing CRTSCTS flag and do not send hangup after closing
device by clearing HUPCL flag.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


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

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 695d433b96..c55b41025b 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -657,6 +657,7 @@ kwboot_open_tty(const char *path, int baudrate)
  
  	cfmakeraw();

tio.c_cflag |= CREAD | CLOCAL;
+   tio.c_cflag &= ~(CSTOPB | HUPCL | CRTSCTS);
tio.c_cc[VMIN] = 1;
tio.c_cc[VTIME] = 0;
  




Viele Grüße,
Stefan

--
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/13] tools: kwboot: Initialize rfds to zero

2021-10-25 Thread Stefan Roese

On 25.10.21 15:12, Marek Behún wrote:

From: Pali Rohár 

Explicitly zero out the rfds fd_set with FD_ZERO() before using it.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


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

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 7e1be29623..695d433b96 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -1151,6 +1151,7 @@ kwboot_terminal(int tty)
fd_set rfds;
int nfds = 0;
  
+		FD_ZERO();

FD_SET(tty, );
nfds = nfds < tty ? tty : nfds;
  




Viele Grüße,
Stefan

--
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] doc: Remove the obsolete README.mpc74xx file

2021-10-25 Thread Stefan Roese

On 25.10.21 08:56, Thomas Huth wrote:

Support for the PPC74xx processors has been removed in commit
d928664f41 ("powerpc: 74xx_7xx: remove 74xx_7xx cpu support")
more than 6 years ago already. So the corresponding README file
can now be removed, too.

Signed-off-by: Thomas Huth 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


---
  doc/README.mpc74xx | 22 --
  1 file changed, 22 deletions(-)
  delete mode 100644 doc/README.mpc74xx

diff --git a/doc/README.mpc74xx b/doc/README.mpc74xx
deleted file mode 100644
index f81f1c2e89..00
--- a/doc/README.mpc74xx
+++ /dev/null
@@ -1,22 +0,0 @@
-This file contains status information for the port of U-Boot to the
-Motorola mpc74xx series of CPUs.
-
-Author: Josh Huber 
-   Mission Critical Linux, Inc.
-
-Currently the support for these CPUs is pretty minimal, but enough to
-get things going.  (much like the support for the Galileo Eval Board)
-
-There is a framework in place to enable the L2 cache, and to program
-the BATs.  Currently, there are still problems with the code which
-sets up the L2 cache, so it's not enabled. (IMHO, it shouldn't be
-anyway).  Additionally, there is support for enabling the MMU, which
-we also don't do.  The BATs are programmed just for the benefit of
-jumping into Linux in a sane configuration.
-
-Most of the code was based on other cpus supported by U-Boot.
-
-If you find any errors in the CPU setup code, please send us a note.
-
-Thanks,
-Josh




Viele Grüße,
Stefan

--
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 1/1] doc: remove AMCC PPC405 processor references

2021-10-25 Thread Stefan Roese

On 23.10.21 13:14, Heinrich Schuchardt wrote:

Support for PPC4XX processors has been removed. So we should not mention it
in the documentation.

Signed-off-by: Heinrich Schuchardt 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


---
  doc/README.bedbug | 22 --
  1 file changed, 22 deletions(-)

diff --git a/doc/README.bedbug b/doc/README.bedbug
index 35e9d2706a..1a2acd0f14 100644
--- a/doc/README.bedbug
+++ b/doc/README.bedbug
@@ -2,8 +2,6 @@ BEDBUG Support for U-Boot
  --
  
  These changes implement the bedbug (emBEDded deBUGger) debugger in U-Boot.

-A specific implementation is made for the AMCC 405 processor but other flavors
-can be easily implemented.
  
  #

  ### Modifications ###
@@ -12,25 +10,9 @@ can be easily implemented.
  ./common/Makefile
Included cmd_bedbug.c and bedbug.c in the Makefile.
  
-./common/command.c

-   Added bedbug commands to command table.
-
  ./common/board.c
Added call to initialize debugger on startup.
  
-./arch/powerpc/cpu/ppc4xx/Makefile

-   Added bedbug_405.c to the Makefile.
-
-./arch/powerpc/cpu/ppc4xx/start.S
-   Added code to handle the debug exception (0x2000) on the 405.
-   Also added code to handle critical exceptions since the debug
-   is treated as critical on the 405.
-
-./arch/powerpc/cpu/ppc4xx/traps.c
-   Added more detailed output for the program exception to tell
-   if it is an illegal instruction, privileged instruction or
-   a trap. Also added debug trap handler.
-
  ./include/ppc_asm.tmpl
Added code to handle critical exceptions
  
@@ -51,10 +33,6 @@ can be easily implemented.

hardware breakpoints and stepping through code.  These
routines are common to all PowerPC processors.
  
-./arch/powerpc/cpu/ppc4xx/bedbug_405.c

-   AMCC  PPC405 specific debugger routines.
-
-
  Bedbug support for the MPC860
  -
  




Viele Grüße,
Stefan

--
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: Fix comments about kwbimage structures

2021-10-25 Thread Stefan Roese

On 22.10.21 12:41, Pali Rohár wrote:

kwbimage v1 is used on more SoCs.

Signed-off-by: Pali Rohár 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


---
  arch/arm/mach-mvebu/spl.c | 2 +-
  cmd/mvebu/bubt.c  | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c
index b798c797cc27..04d9640b142d 100644
--- a/arch/arm/mach-mvebu/spl.c
+++ b/arch/arm/mach-mvebu/spl.c
@@ -72,7 +72,7 @@
  #define IBR_HDR_UART_ID   0x69
  #define IBR_HDR_SDIO_ID   0xAE
  
-/* Structure of the main header, version 1 (Armada 370/38x/XP) */

+/* Structure of the main header, version 1 (Armada 370/XP/375/38x/39x) */
  struct kwbimage_main_hdr_v1 {
uint8_t  blockid;   /* 0x0   */
uint8_t  flags; /* 0x1   */
diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c
index d4f381b6ad92..470fb0e92097 100644
--- a/cmd/mvebu/bubt.c
+++ b/cmd/mvebu/bubt.c
@@ -85,7 +85,7 @@ struct mvebu_image_info {
  };
  #endif
  
-/* Structure of the main header, version 1 (Armada 370/38x/XP) */

+/* Structure of the main header, version 1 (Armada 370/XP/375/38x/39x) */
  struct a38x_main_hdr_v1 {
u8  blockid;   /* 0x0   */
u8  flags; /* 0x1   */




Viele Grüße,
Stefan

--
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 3/3] arm: mvebu: Update name of kwbimage v1 field at offset 0x2-0x3

2021-10-25 Thread Stefan Roese

On 22.10.21 12:37, Pali Rohár wrote:

At this offset is stored nand page size.

Signed-off-by: Pali Rohár 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


---
  arch/arm/mach-mvebu/spl.c | 2 +-
  cmd/mvebu/bubt.c  | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c
index 04d9640b142d..cad3f0a48893 100644
--- a/arch/arm/mach-mvebu/spl.c
+++ b/arch/arm/mach-mvebu/spl.c
@@ -76,7 +76,7 @@
  struct kwbimage_main_hdr_v1 {
uint8_t  blockid;   /* 0x0   */
uint8_t  flags; /* 0x1   */
-   uint16_t reserved2; /* 0x2-0x3   */
+   uint16_t nandpagesize;  /* 0x2-0x3   */
uint32_t blocksize; /* 0x4-0x7   */
uint8_t  version;   /* 0x8   */
uint8_t  headersz_msb;  /* 0x9   */
diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c
index 470fb0e92097..a7f3ff3c6fc0 100644
--- a/cmd/mvebu/bubt.c
+++ b/cmd/mvebu/bubt.c
@@ -89,7 +89,7 @@ struct mvebu_image_info {
  struct a38x_main_hdr_v1 {
u8  blockid;   /* 0x0   */
u8  flags; /* 0x1   */
-   u16 reserved2; /* 0x2-0x3   */
+   u16 nandpagesize;  /* 0x2-0x3   */
u32 blocksize; /* 0x4-0x7   */
u8  version;   /* 0x8   */
u8  headersz_msb;  /* 0x9   */




Viele Grüße,
Stefan

--
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 2/3] tools: kwboot: Patch nandpagesize to zero also for v1 image

2021-10-25 Thread Stefan Roese

On 22.10.21 12:37, Pali Rohár wrote:

kwbimage v1 has also nandpagesize field. So set it to zero for both image
versions when image is not signed.

Signed-off-by: Pali Rohár 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


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

diff --git a/tools/kwboot.c b/tools/kwboot.c
index eb4f5ab87917..7e1be2962302 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -1428,13 +1428,6 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)
if (csum != hdr->checksum)
goto err;
  
-	if (image_ver == 0) {

-   struct main_hdr_v0 *hdr_v0 = img;
-
-   hdr_v0->nandeccmode = IBR_HDR_ECC_DISABLED;
-   hdr_v0->nandpagesize = 0;
-   }
-
srcaddr = le32_to_cpu(hdr->srcaddr);
  
  	switch (hdr->blockid) {

@@ -1480,6 +1473,12 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)
hdr->blockid = IBR_HDR_UART_ID;
}
  
+	if (!is_secure) {

+   if (image_ver == 0)
+   ((struct main_hdr_v0 *)img)->nandeccmode = 
IBR_HDR_ECC_DISABLED;
+   hdr->nandpagesize = 0;
+   }
+
if (baudrate) {
uint32_t codesz = sizeof(kwboot_baud_code);
void *code;




Viele Grüße,
Stefan

--
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 1/3] tools: kwbimage: Add support for NAND_PAGE_SIZE command also for v1 images

2021-10-25 Thread Stefan Roese

On 22.10.21 12:37, Pali Rohár wrote:

The NAND_PAGE_SIZE command is already supported by mkimage for v0 images,
but not for v1 images.

A38x and A39x BootROM supports reading NAND flash page size from v1 image
in the same way as Kirkwood BootROM from v0 image. It it documented in A38x
and A39x Functional Specification.

Signed-off-by: Pali Rohár 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


---
  tools/kwbimage.c | 3 +++
  tools/kwbimage.h | 2 +-
  2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index e9324baddba4..67c0c628ae9f 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -1231,6 +1231,9 @@ static void *image_create_v1(size_t *imagesz, struct 
image_tool_params *params,
e = image_find_option(IMAGE_CFG_NAND_BLKSZ);
if (e)
main_hdr->nandblocksize = e->nandblksz / (64 * 1024);
+   e = image_find_option(IMAGE_CFG_NAND_PAGESZ);
+   if (e)
+   main_hdr->nandpagesize = cpu_to_le16(e->nandpagesz);
e = image_find_option(IMAGE_CFG_NAND_BADBLK_LOCATION);
if (e)
main_hdr->nandbadblklocation = e->nandbadblklocation;
diff --git a/tools/kwbimage.h b/tools/kwbimage.h
index 126d482fe722..f1ba95c2fa5b 100644
--- a/tools/kwbimage.h
+++ b/tools/kwbimage.h
@@ -73,7 +73,7 @@ struct ext_hdr_v0 {
  struct main_hdr_v1 {
uint8_t  blockid;   /* 0x0   */
uint8_t  flags; /* 0x1   */
-   uint16_t reserved2; /* 0x2-0x3   */
+   uint16_t nandpagesize;  /* 0x2-0x3   */
uint32_t blocksize; /* 0x4-0x7   */
uint8_t  version;   /* 0x8   */
uint8_t  headersz_msb;  /* 0x9   */




Viele Grüße,
Stefan

--
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


[PATCH v3 34/35] efi: Support the efi command in the app

2021-10-25 Thread Simon Glass
At present the 'efi' command only works in the EFI payload. Update it to
work in the app too, so the memory map can be examined.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add new patch to support the efi command in the app

 cmd/Makefile  |  2 +-
 cmd/efi.c | 48 ---
 include/efi.h | 15 +++
 lib/efi/efi_app.c | 33 
 4 files changed, 82 insertions(+), 16 deletions(-)

diff --git a/cmd/Makefile b/cmd/Makefile
index ed3669411e6..3e9f23ebf30 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -58,7 +58,7 @@ obj-$(CONFIG_CMD_EXTENSION) += extension_board.o
 obj-$(CONFIG_CMD_ECHO) += echo.o
 obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o
 obj-$(CONFIG_CMD_EEPROM) += eeprom.o
-obj-$(CONFIG_EFI_STUB) += efi.o
+obj-$(CONFIG_EFI) += efi.o
 obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o
 obj-$(CONFIG_CMD_ELF) += elf.o
 obj-$(CONFIG_HUSH_PARSER) += exit.o
diff --git a/cmd/efi.c b/cmd/efi.c
index d2400acbbba..c0384e0db28 100644
--- a/cmd/efi.c
+++ b/cmd/efi.c
@@ -13,6 +13,8 @@
 #include 
 #include 
 
+DECLARE_GLOBAL_DATA_PTR;
+
 static const char *const type_name[] = {
"reserved",
"loader_code",
@@ -217,37 +219,53 @@ static void efi_print_mem_table(struct efi_mem_desc 
*desc, int desc_size,
 static int do_efi_mem(struct cmd_tbl *cmdtp, int flag, int argc,
  char *const argv[])
 {
-   struct efi_mem_desc *desc;
-   struct efi_entry_memmap *map;
+   struct efi_mem_desc *orig, *desc;
+   uint version, key;
+   int desc_size;
int size, ret;
bool skip_bs;
 
skip_bs = !argc || *argv[0] != 'a';
-   ret = efi_info_get(EFIET_MEMORY_MAP, (void **), );
-   switch (ret) {
-   case -ENOENT:
-   printf("No EFI table available\n");
-   goto done;
-   case -EPROTONOSUPPORT:
-   printf("Incorrect EFI table version\n");
-   goto done;
+   if (IS_ENABLED(CONFIG_EFI_APP)) {
+   ret = efi_get_mmap(, , , _size, );
+   if (ret) {
+   printf("Cannot read memory map (err=%d)\n", ret);
+   return CMD_RET_FAILURE;
+   }
+   } else {
+   struct efi_entry_memmap *map;
+
+   ret = efi_info_get(EFIET_MEMORY_MAP, (void **), );
+   switch (ret) {
+   case -ENOENT:
+   printf("No EFI table available\n");
+   goto done;
+   case -EPROTONOSUPPORT:
+   printf("Incorrect EFI table version\n");
+   goto done;
+   }
+   orig = map->desc;
+   desc_size = map->desc_size;
+   version = map->version;
}
-   printf("EFI table at %lx, memory map %p, size %x, version %x, descr. 
size %#x\n",
-  gd->arch.table, map, size, map->version, map->desc_size);
-   if (map->version != EFI_MEM_DESC_VERSION) {
+   printf("EFI table at %lx, memory map %p, size %x, key %x, version %x, 
descr. size %#x\n",
+  gd->arch.table, orig, size, key, version, desc_size);
+   if (version != EFI_MEM_DESC_VERSION) {
printf("Incorrect memory map version\n");
ret = -EPROTONOSUPPORT;
goto done;
}
 
-   desc = efi_build_mem_table(map->desc, size, map->desc_size, skip_bs);
+   desc = efi_build_mem_table(orig, size, desc_size, skip_bs);
if (!desc) {
ret = -ENOMEM;
goto done;
}
 
-   efi_print_mem_table(desc, map->desc_size, skip_bs);
+   efi_print_mem_table(desc, desc_size, skip_bs);
free(desc);
+   if (IS_ENABLED(CONFIG_EFI_APP))
+   free(orig);
 done:
if (ret)
printf("Error: %d\n", ret);
diff --git a/include/efi.h b/include/efi.h
index 1dc806a1267..8a43430d3df 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -610,4 +610,19 @@ int efi_store_memory_map(struct efi_priv *priv);
  */
 int efi_call_exit_boot_services(void);
 
+/**
+ * efi_get_mmap() - Get the memory map from EFI
+ *
+ * This is used in the app. The caller must free *@descp when done
+ *
+ * @descp: Returns allocated pointer to EFI memory map table
+ * @sizep: Returns size of table in bytes
+ * @keyp:  Returns memory-map key
+ * @desc_sizep:Returns size of each @desc_base record
+ * @versionp:  Returns version number of memory map
+ * @return 0 on success, -ve on error
+ */
+int efi_get_mmap(struct efi_mem_desc **descp, int *sizep, uint *keyp,
+int *desc_sizep, uint *versionp);
+
 #endif /* _LINUX_EFI_H */
diff --git a/lib/efi/efi_app.c b/lib/efi/efi_app.c
index 36e3f1de427..55fa1ac57d5 100644
--- a/lib/efi/efi_app.c
+++ b/lib/efi/efi_app.c
@@ -32,6 +32,39 @@ int efi_info_get(enum efi_entry_t type, void **datap, int 
*sizep)
return -ENOSYS;
 }
 
+int 

[PATCH v3 35/35] efi: Show the system-table revision

2021-10-25 Thread Simon Glass
Show the revision of this table this is can be important.

Alo update the 'efi table' entry to show the actual address of the EFI
table rather than our table that points to it. This saves a step and the
intermediate table has nothing else in it.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Add new patch to show the system-table revision

 arch/x86/cpu/efi/payload.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/x86/cpu/efi/payload.c b/arch/x86/cpu/efi/payload.c
index d2aa889a2b9..b7778565b19 100644
--- a/arch/x86/cpu/efi/payload.c
+++ b/arch/x86/cpu/efi/payload.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -296,8 +297,14 @@ void setup_efi_info(struct efi_info *efi_info)
 void efi_show_bdinfo(void)
 {
struct efi_entry_systable *table = NULL;
+   struct efi_system_table *sys_table;
int size, ret;
 
ret = efi_info_get(EFIET_SYS_TABLE, (void **), );
-   bdinfo_print_num_l("efi_table", (ulong)table);
+   if (!ret) {
+   bdinfo_print_num_l("efi_table", table->sys_table);
+   sys_table = (struct efi_system_table *)(uintptr_t)
+   table->sys_table;
+   bdinfo_print_num_l(" revision", sys_table->fw_revision);
+   }
 }
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 32/35] efi: Allow easy selection of serial-only operation

2021-10-25 Thread Simon Glass
Add info about how to select vidconsole or serial.

Also set up a demo boot command.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add a better boot command too

 include/configs/efi-x86_app.h | 25 +
 1 file changed, 25 insertions(+)

diff --git a/include/configs/efi-x86_app.h b/include/configs/efi-x86_app.h
index 6061a6db0a4..33afb7ca0f9 100644
--- a/include/configs/efi-x86_app.h
+++ b/include/configs/efi-x86_app.h
@@ -10,8 +10,33 @@
 
 #undef CONFIG_TPM_TIS_BASE_ADDRESS
 
+/*
+ * Select the output device: Put an 'x' prefix before one of these to disable 
it
+ */
+
+/*
+ * Video output - can normally continue after exit_boot_services has been
+ * called, since output to the display does not require EFI services at that
+ * point. U-Boot sets up the console memory and does its own drawing.
+ */
 #define CONFIG_STD_DEVICES_SETTINGS"stdin=serial\0" \
"stdout=vidconsole\0" \
"stderr=vidconsole\0"
 
+/*
+ * Serial output with no console. Run qemu with:
+ *
+ *-display none -serial mon:stdio
+ *
+ * This will hang or fail to output on the console after exit_boot_services is
+ * called.
+ */
+#define xCONFIG_STD_DEVICES_SETTINGS   "stdin=serial\0" \
+   "stdout=serial\0" \
+   "stderr=serial\0"
+
+#undef CONFIG_BOOTCOMMAND
+
+#define CONFIG_BOOTCOMMAND "part list efi 0; fatls efi 0:1"
+
 #endif
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 33/35] efi: Update efi_get_next_mem_desc() to avoid needing a map

2021-10-25 Thread Simon Glass
At present this function requires a pointer to struct efi_entry_memmap
but the only field used in there is the desc_size. We want to be able
to use it from the app, so update it to use desc_size directly.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/cpu/efi/payload.c |  8 
 cmd/efi.c  | 34 ++
 include/efi.h  |  4 ++--
 3 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/arch/x86/cpu/efi/payload.c b/arch/x86/cpu/efi/payload.c
index 3a9f7d72868..d2aa889a2b9 100644
--- a/arch/x86/cpu/efi/payload.c
+++ b/arch/x86/cpu/efi/payload.c
@@ -50,7 +50,7 @@ ulong board_get_usable_ram_top(ulong total_size)
 
end = (struct efi_mem_desc *)((ulong)map + size);
desc = map->desc;
-   for (; desc < end; desc = efi_get_next_mem_desc(map, desc)) {
+   for (; desc < end; desc = efi_get_next_mem_desc(desc, map->desc_size)) {
if (desc->type != EFI_CONVENTIONAL_MEMORY ||
desc->physical_start >= 1ULL << 32)
continue;
@@ -88,7 +88,7 @@ int dram_init(void)
end = (struct efi_mem_desc *)((ulong)map + size);
gd->ram_size = 0;
desc = map->desc;
-   for (; desc < end; desc = efi_get_next_mem_desc(map, desc)) {
+   for (; desc < end; desc = efi_get_next_mem_desc(desc, map->desc_size)) {
if (desc->type < EFI_MMAP_IO)
gd->ram_size += desc->num_pages << EFI_PAGE_SHIFT;
}
@@ -113,7 +113,7 @@ int dram_init_banksize(void)
desc = map->desc;
for (num_banks = 0;
 desc < end && num_banks < CONFIG_NR_DRAM_BANKS;
-desc = efi_get_next_mem_desc(map, desc)) {
+desc = efi_get_next_mem_desc(desc, map->desc_size)) {
/*
 * We only use conventional memory and ignore
 * anything less than 1MB.
@@ -196,7 +196,7 @@ unsigned int install_e820_map(unsigned int max_entries,
 
end = (struct efi_mem_desc *)((ulong)map + size);
for (desc = map->desc; desc < end;
-desc = efi_get_next_mem_desc(map, desc)) {
+desc = efi_get_next_mem_desc(desc, map->desc_size)) {
if (desc->num_pages == 0)
continue;
 
diff --git a/cmd/efi.c b/cmd/efi.c
index f2ed26bd4b2..d2400acbbba 100644
--- a/cmd/efi.c
+++ b/cmd/efi.c
@@ -75,16 +75,17 @@ static int h_cmp_entry(const void *v1, const void *v2)
 /**
  * efi_build_mem_table() - make a sorted copy of the memory table
  *
- * @map:   Pointer to EFI memory map table
+ * @desc_base: Pointer to EFI memory map table
  * @size:  Size of table in bytes
+ * @desc_size: Size of each @desc_base record
  * @skip_bs:   True to skip boot-time memory and merge it with conventional
  * memory. This will significantly reduce the number of table
  * entries.
  * Return: pointer to the new table. It should be freed with free() by the
  * caller.
  */
-static void *efi_build_mem_table(struct efi_entry_memmap *map, int size,
-bool skip_bs)
+static void *efi_build_mem_table(struct efi_mem_desc *desc_base, int size,
+int desc_size, bool skip_bs)
 {
struct efi_mem_desc *desc, *end, *base, *dest, *prev;
int count;
@@ -95,15 +96,16 @@ static void *efi_build_mem_table(struct efi_entry_memmap 
*map, int size,
debug("%s: Cannot allocate %#x bytes\n", __func__, size);
return NULL;
}
-   end = (struct efi_mem_desc *)((ulong)map + size);
-   count = ((ulong)end - (ulong)map->desc) / map->desc_size;
-   memcpy(base, map->desc, (ulong)end - (ulong)map->desc);
-   qsort(base, count, map->desc_size, h_cmp_entry);
+   end = (void *)desc_base + size;
+   count = ((ulong)end - (ulong)desc_base) / desc_size;
+   memcpy(base, desc_base, (ulong)end - (ulong)desc_base);
+   qsort(base, count, desc_size, h_cmp_entry);
prev = NULL;
addr = 0;
dest = base;
-   end = (struct efi_mem_desc *)((ulong)base + count * map->desc_size);
-   for (desc = base; desc < end; desc = efi_get_next_mem_desc(map, desc)) {
+   end = (struct efi_mem_desc *)((ulong)base + count * desc_size);
+   for (desc = base; desc < end;
+desc = efi_get_next_mem_desc(desc, desc_size)) {
bool merge = true;
u32 type = desc->type;
 
@@ -116,7 +118,7 @@ static void *efi_build_mem_table(struct efi_entry_memmap 
*map, int size,
if (skip_bs && is_boot_services(desc->type))
type = EFI_CONVENTIONAL_MEMORY;
 
-   memcpy(dest, desc, map->desc_size);
+   memcpy(dest, desc, desc_size);
dest->type = type;
if (!skip_bs || !prev)
merge = false;
@@ -131,7 +133,7 @@ static void *efi_build_mem_table(struct 

[PATCH v3 31/35] efi: Show when allocated pages are used

2021-10-25 Thread Simon Glass
Add a message here so that both paths of memory allocation are reported.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Use log_info() instead of printf()

 lib/efi/efi_app.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/efi/efi_app.c b/lib/efi/efi_app.c
index e454f1a1564..36e3f1de427 100644
--- a/lib/efi/efi_app.c
+++ b/lib/efi/efi_app.c
@@ -121,13 +121,14 @@ static efi_status_t setup_memory(struct efi_priv *priv)
ret = boot->allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
   priv->image_data_type, pages, );
if (ret) {
-   printf("(using pool %lx) ", ret);
+   log_info("(using pool %lx) ", ret);
priv->ram_base = (ulong)efi_malloc(priv, CONFIG_EFI_RAM_SIZE,
   );
if (!priv->ram_base)
return ret;
priv->use_pool_for_malloc = true;
} else {
+   log_info("(using allocated RAM address %lx) ", (ulong)addr);
priv->ram_base = addr;
}
gd->ram_size = pages << 12;
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 29/35] efi: Check for failure when initing the app

2021-10-25 Thread Simon Glass
The stub checks for failure with efi_init(). Add this for the app as well.
It is unlikely that anything can be done, but we may as well stop.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 lib/efi/efi_app.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/efi/efi_app.c b/lib/efi/efi_app.c
index 23a65c46fd4..e454f1a1564 100644
--- a/lib/efi/efi_app.c
+++ b/lib/efi/efi_app.c
@@ -325,8 +325,11 @@ efi_status_t EFIAPI efi_main(efi_handle_t image,
efi_status_t ret;
 
/* Set up access to EFI data structures */
-   efi_init(priv, "App", image, sys_table);
-
+   ret = efi_init(priv, "App", image, sys_table);
+   if (ret) {
+   printf("Failed to set up ARP: err=%lx\n", ret);
+   return ret;
+   }
efi_set_priv(priv);
 
/*
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 30/35] efi: Mention that efi_info_get() is only used in the stub

2021-10-25 Thread Simon Glass
This provides access to EFI tables after U-Boot has exited boot services.
It is not needed in the app since boot services remain alive and we can
just call them whenever needed.

Add a comment to explain this.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Fix 'as' typo

 include/efi.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/include/efi.h b/include/efi.h
index ed28c204140..69321cc5cc4 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -578,6 +578,10 @@ void efi_putc(struct efi_priv *priv, const char ch);
 /**
  * efi_info_get() - get an entry from an EFI table
  *
+ * This is called from U-Boot proper to read information set up by the EFI 
stub.
+ * It can only be used when running from the EFI stuff, not when U-Boot is
+ * running as an app.
+ *
  * @type:  Entry type to search for
  * @datap: Returns pointer to entry data
  * @sizep: Returns pointer to entry size
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 28/35] efi: Move exit_boot_services into a function

2021-10-25 Thread Simon Glass
At present this code is inline in the app and stub. But they do the same
thing. The difference is that the stub does it immediately and the app
doesn't want to do it until the end (when it boots a kernel) or not at
all, if returning to UEFI.

Move it into a function so it can be called as needed.

Also store the memory map so that it can be accessed within the app if
needed.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add a sentence about what the patch does

 include/efi.h  | 32 ++
 lib/efi/efi.c  | 68 ++
 lib/efi/efi_app.c  |  3 ++
 lib/efi/efi_stub.c | 66 
 4 files changed, 114 insertions(+), 55 deletions(-)

diff --git a/include/efi.h b/include/efi.h
index ca301db7cb5..ed28c204140 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -407,6 +407,12 @@ static inline struct efi_mem_desc *efi_get_next_mem_desc(
  * @sys_table: Pointer to system table
  * @boot: Pointer to boot-services table
  * @run: Pointer to runtime-services table
+ * @memmap_key: Key returned from get_memory_map()
+ * @memmap_desc: List of memory-map records
+ * @memmap_alloc: Amount of memory allocated for memory map list
+ * @memmap_size Size of memory-map list in bytes
+ * @memmap_desc_size: Size of an individual memory-map record, in bytes
+ * @memmap_version: Memory-map version
  *
  * @use_pool_for_malloc: true if all allocation should go through the EFI 
'pool'
  * methods allocate_pool() and free_pool(); false to use 'pages' methods
@@ -424,6 +430,12 @@ struct efi_priv {
struct efi_system_table *sys_table;
struct efi_boot_services *boot;
struct efi_runtime_services *run;
+   efi_uintn_t memmap_key;
+   struct efi_mem_desc *memmap_desc;
+   efi_uintn_t memmap_alloc;
+   efi_uintn_t memmap_size;
+   efi_uintn_t memmap_desc_size;
+   u32 memmap_version;
 
/* app: */
bool use_pool_for_malloc;
@@ -574,4 +586,24 @@ void efi_putc(struct efi_priv *priv, const char ch);
  */
 int efi_info_get(enum efi_entry_t type, void **datap, int *sizep);
 
+/**
+ * efi_store_memory_map() - Collect the memory-map info from EFI
+ *
+ * Collect the memory info and store it for later use, e.g. in calling
+ * exit_boot_services()
+ *
+ * @priv:  Pointer to private EFI structure
+ * @return 0 if OK, non-zero on error
+ */
+int efi_store_memory_map(struct efi_priv *priv);
+
+/**
+ * efi_call_exit_boot_services() - Handlet eh exit-boot-service procedure
+ *
+ * Tell EFI we don't want their boot services anymore
+ *
+ * @return 0 if OK, non-zero on error
+ */
+int efi_call_exit_boot_services(void);
+
 #endif /* _LINUX_EFI_H */
diff --git a/lib/efi/efi.c b/lib/efi/efi.c
index cd6bf47b180..20da88c9151 100644
--- a/lib/efi/efi.c
+++ b/lib/efi/efi.c
@@ -135,3 +135,71 @@ void efi_free(struct efi_priv *priv, void *ptr)
 
boot->free_pool(ptr);
 }
+
+int efi_store_memory_map(struct efi_priv *priv)
+{
+   struct efi_boot_services *boot = priv->sys_table->boottime;
+   efi_uintn_t size, desc_size;
+   efi_status_t ret;
+
+   /* Get the memory map so we can switch off EFI */
+   size = 0;
+   ret = boot->get_memory_map(, NULL, >memmap_key,
+  >memmap_desc_size,
+  >memmap_version);
+   if (ret != EFI_BUFFER_TOO_SMALL) {
+   printhex2(EFI_BITS_PER_LONG);
+   putc(' ');
+   printhex2(ret);
+   puts(" No memory map\n");
+   return ret;
+   }
+   /*
+* Since doing a malloc() may change the memory map and also we want to
+* be able to read the memory map in efi_call_exit_boot_services()
+* below, after more changes have happened
+*/
+   priv->memmap_alloc = size + 1024;
+   priv->memmap_size = priv->memmap_alloc;
+   priv->memmap_desc = efi_malloc(priv, size, );
+   if (!priv->memmap_desc) {
+   printhex2(ret);
+   puts(" No memory for memory descriptor\n");
+   return ret;
+   }
+
+   ret = boot->get_memory_map(>memmap_size, priv->memmap_desc,
+  >memmap_key, _size,
+  >memmap_version);
+   if (ret) {
+   printhex2(ret);
+   puts(" Can't get memory map\n");
+   return ret;
+   }
+
+   return 0;
+}
+
+int efi_call_exit_boot_services(void)
+{
+   struct efi_priv *priv = efi_get_priv();
+   const struct efi_boot_services *boot = priv->boot;
+   efi_uintn_t size;
+   u32 version;
+   efi_status_t ret;
+
+   size = priv->memmap_alloc;
+   ret = boot->get_memory_map(, priv->memmap_desc,
+  >memmap_key,
+  >memmap_desc_size, );
+   if (ret) {
+   printhex2(ret);
+   puts(" Can't get 

[PATCH v3 25/35] efi: Fix ll_boot_init() operation with the app

2021-10-25 Thread Simon Glass
This should return false when the EFI app is running, since UEFI has done
the required low-level init. Fix it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/init.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/init.h b/include/init.h
index c781789e367..6d682b02b05 100644
--- a/include/init.h
+++ b/include/init.h
@@ -15,7 +15,7 @@
 #include 
 
 /* Avoid using CONFIG_EFI_STUB directly as we may boot from other loaders */
-#ifdef CONFIG_EFI_STUB
+#ifdef CONFIG_EFI
 #define ll_boot_init() false
 #else
 #include 
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 27/35] efi: Share struct efi_priv between the app and stub code

2021-10-25 Thread Simon Glass
At present each of these has its own static variable and helper functions.
Move them into a shared file.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/efi.h  | 21 +
 lib/efi/efi.c  | 29 +
 lib/efi/efi_app.c  | 21 ++---
 lib/efi/efi_stub.c |  7 ---
 4 files changed, 56 insertions(+), 22 deletions(-)

diff --git a/include/efi.h b/include/efi.h
index 6622a733e6e..ca301db7cb5 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -474,6 +474,27 @@ extern char _binary_u_boot_bin_start[], 
_binary_u_boot_bin_end[];

EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
EFI_VARIABLE_APPEND_WRITE)
 
+/**
+ * efi_get_priv() - Get access to the EFI-private information
+ *
+ * This struct it used by both the stub and the app to record things about the
+ * EFI environment. It is not available in U-Boot proper after the stub has
+ * jumped there. Use efi_info_get() to obtain info in that case.
+ *
+ * @return pointer to private info
+ */
+struct efi_priv *efi_get_priv(void);
+
+/**
+ * efi_set_priv() - Set up a pointer to the EFI-private information
+ *
+ * This is called in the stub and app to record the location of this
+ * information.
+ *
+ * @priv: New location of private data
+ */
+void efi_set_priv(struct efi_priv *priv);
+
 /**
  * efi_get_sys_table() - Get access to the main EFI system table
  *
diff --git a/lib/efi/efi.c b/lib/efi/efi.c
index 69e52e45748..cd6bf47b180 100644
--- a/lib/efi/efi.c
+++ b/lib/efi/efi.c
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
+ * Functions shared by the app and stub
+ *
  * Copyright (c) 2015 Google, Inc
  *
  * EFI information obtained here:
@@ -17,6 +19,33 @@
 #include 
 #include 
 
+static struct efi_priv *global_priv;
+
+struct efi_priv *efi_get_priv(void)
+{
+   return global_priv;
+}
+
+void efi_set_priv(struct efi_priv *priv)
+{
+   global_priv = priv;
+}
+
+struct efi_system_table *efi_get_sys_table(void)
+{
+   return global_priv->sys_table;
+}
+
+struct efi_boot_services *efi_get_boot(void)
+{
+   return global_priv->boot;
+}
+
+unsigned long efi_get_ram_base(void)
+{
+   return global_priv->ram_base;
+}
+
 /*
  * Global declaration of gd.
  *
diff --git a/lib/efi/efi_app.c b/lib/efi/efi_app.c
index e38d46b15db..a0ae2a531ee 100644
--- a/lib/efi/efi_app.c
+++ b/lib/efi/efi_app.c
@@ -27,23 +27,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static struct efi_priv *global_priv;
-
-struct efi_system_table *efi_get_sys_table(void)
-{
-   return global_priv->sys_table;
-}
-
-struct efi_boot_services *efi_get_boot(void)
-{
-   return global_priv->boot;
-}
-
-unsigned long efi_get_ram_base(void)
-{
-   return global_priv->ram_base;
-}
-
 int efi_info_get(enum efi_entry_t type, void **datap, int *sizep)
 {
return -ENOSYS;
@@ -344,7 +327,7 @@ efi_status_t EFIAPI efi_main(efi_handle_t image,
/* Set up access to EFI data structures */
efi_init(priv, "App", image, sys_table);
 
-   global_priv = priv;
+   efi_set_priv(priv);
 
/*
 * Set up the EFI debug UART so that printf() works. This is
@@ -370,7 +353,7 @@ efi_status_t EFIAPI efi_main(efi_handle_t image,
 
 static void efi_exit(void)
 {
-   struct efi_priv *priv = global_priv;
+   struct efi_priv *priv = efi_get_priv();
 
free_memory(priv);
printf("U-Boot EFI exiting\n");
diff --git a/lib/efi/efi_stub.c b/lib/efi/efi_stub.c
index 156cbf0b928..bc4c3a48720 100644
--- a/lib/efi/efi_stub.c
+++ b/lib/efi/efi_stub.c
@@ -31,7 +31,6 @@
 #error "This file needs to be ported for use on architectures"
 #endif
 
-static struct efi_priv *global_priv;
 static bool use_uart;
 
 struct __packed desctab_info {
@@ -63,6 +62,8 @@ void _debug_uart_init(void)
 
 void putc(const char ch)
 {
+   struct efi_priv *priv = efi_get_priv();
+
if (ch == '\n')
putc('\r');
 
@@ -73,7 +74,7 @@ void putc(const char ch)
;
outb(ch, (ulong)_port->thr);
} else {
-   efi_putc(global_priv, ch);
+   efi_putc(priv, ch);
}
 }
 
@@ -313,7 +314,7 @@ efi_status_t EFIAPI efi_main(efi_handle_t image,
puts(" efi_init() failed\n");
return ret;
}
-   global_priv = priv;
+   efi_set_priv(priv);
 
cs32 = get_codeseg32();
if (cs32 < 0)
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 24/35] efi: Add comments to struct efi_priv

2021-10-25 Thread Simon Glass
This structure is uncommented. Fix it.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Drop comments that confuse sphinx
- Move device_path path change to its own patch

 include/efi.h | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/include/efi.h b/include/efi.h
index 77e599c256e..6622a733e6e 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -400,14 +400,37 @@ static inline struct efi_mem_desc *efi_get_next_mem_desc(
return (struct efi_mem_desc *)((ulong)desc + map->desc_size);
 }
 
+/**
+ * struct efi_priv - Information about the environment provided by EFI
+ *
+ * @parent_image: image passed into the EFI app or stub
+ * @sys_table: Pointer to system table
+ * @boot: Pointer to boot-services table
+ * @run: Pointer to runtime-services table
+ *
+ * @use_pool_for_malloc: true if all allocation should go through the EFI 
'pool'
+ * methods allocate_pool() and free_pool(); false to use 'pages' methods
+ * allocate_pages() and free_pages()
+ * @ram_base: Base address of RAM (size CONFIG_EFI_RAM_SIZE)
+ * @image_data_type: Type of the loaded image (e.g. EFI_LOADER_CODE)
+ *
+ * @info: Header of the info list, holding info collected by the stub and 
passed
+ * to U-Boot
+ * @info_size: Size of the info list, in bytes from @info
+ * @next_hdr: Pointer to where to put the next header when adding to the list
+ */
 struct efi_priv {
efi_handle_t parent_image;
struct efi_system_table *sys_table;
struct efi_boot_services *boot;
struct efi_runtime_services *run;
+
+   /* app: */
bool use_pool_for_malloc;
unsigned long ram_base;
unsigned int image_data_type;
+
+   /* stub: */
struct efi_info_hdr *info;
unsigned int info_size;
void *next_hdr;
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 26/35] efi: Add a few comments to the stub

2021-10-25 Thread Simon Glass
Comment some functions that need more information.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 lib/efi/efi_stub.c | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/lib/efi/efi_stub.c b/lib/efi/efi_stub.c
index b3393e47fae..156cbf0b928 100644
--- a/lib/efi/efi_stub.c
+++ b/lib/efi/efi_stub.c
@@ -225,6 +225,22 @@ static int get_codeseg32(void)
return cs32;
 }
 
+/**
+ * setup_info_table() - sets up a table containing information from EFI
+ *
+ * We must call exit_boot_services() before jumping out of the stub into U-Boot
+ * proper, so that U-Boot has full control of peripherals, memory, etc.
+ *
+ * Once we do this, we cannot call any boot-services functions so we must find
+ * out everything we need to before doing that.
+ *
+ * Set up a struct efi_info_hdr table which can hold various records (e.g.
+ * struct efi_entry_memmap) with information obtained from EFI.
+ *
+ * @priv: Pointer to our private information which contains the list
+ * @size: Size of the table to allocate
+ * @return 0 if OK, non-zero on error
+ */
 static int setup_info_table(struct efi_priv *priv, int size)
 {
struct efi_info_hdr *info;
@@ -248,6 +264,12 @@ static int setup_info_table(struct efi_priv *priv, int 
size)
return 0;
 }
 
+/**
+ * add_entry_addr() - Add a new entry to the efi_info list
+ *
+ * @priv: Pointer to our private information which contains the list
+ *
+ */
 static void add_entry_addr(struct efi_priv *priv, enum efi_entry_t type,
   void *ptr1, int size1, void *ptr2, int size2)
 {
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 23/35] efi: Drop device_path from struct efi_priv

2021-10-25 Thread Simon Glass
This is not used anywhere drop it.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Move device_path path change to its own patch

 include/efi.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/efi.h b/include/efi.h
index 908c5dc6ebd..77e599c256e 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -402,7 +402,6 @@ static inline struct efi_mem_desc *efi_get_next_mem_desc(
 
 struct efi_priv {
efi_handle_t parent_image;
-   struct efi_device_path *device_path;
struct efi_system_table *sys_table;
struct efi_boot_services *boot;
struct efi_runtime_services *run;
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 22/35] x86: efi: Add room for the binman definition in the dtb

2021-10-25 Thread Simon Glass
At present only 4KB of spare space is left in the DTB when building the
EFI app. Increase this to 32KB so there is plenty of space to insert the
binman definition. This cannot be expanded later (as with OF_SEPARATE)
because the ELF image has already been built.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/dts/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/dts/Makefile b/arch/x86/dts/Makefile
index be209aaaf8f..5c8c05ec499 100644
--- a/arch/x86/dts/Makefile
+++ b/arch/x86/dts/Makefile
@@ -24,7 +24,7 @@ dtb-y += bayleybay.dtb \
 
 targets += $(dtb-y)
 
-DTC_FLAGS += -R 4 -p 0x1000
+DTC_FLAGS += -R 4 -p $(if $(CONFIG_EFI_APP),0x8000,0x1000)
 
 PHONY += dtbs
 dtbs: $(addprefix $(obj)/, $(dtb-y))
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 21/35] x86: Don't process the kernel command line unless enabled

2021-10-25 Thread Simon Glass
If the 'bootm' command is not enabled then this code is not available and
this causes a link error. Fix it.

Note that for the EFI app, there is no indication of missing code. It just
hangs!

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/lib/zimage.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index 7ce02226ef9..9cc04490307 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -365,11 +365,14 @@ int setup_zimage(struct boot_params *setup_base, char 
*cmd_line, int auto_boot,
strcpy(cmd_line, (char *)cmdline_force);
else
build_command_line(cmd_line, auto_boot);
-   ret = bootm_process_cmdline(cmd_line, max_size, BOOTM_CL_ALL);
-   if (ret) {
-   printf("Cmdline setup failed (max_size=%x, 
bootproto=%x, err=%d)\n",
-  max_size, bootproto, ret);
-   return ret;
+   if (IS_ENABLED(CONFIG_CMD_BOOTM)) {
+   ret = bootm_process_cmdline(cmd_line, max_size,
+   BOOTM_CL_ALL);
+   if (ret) {
+   printf("Cmdline setup failed (max_size=%x, 
bootproto=%x, err=%d)\n",
+  max_size, bootproto, ret);
+   return ret;
+   }
}
printf("Kernel command line: \"");
puts(cmd_line);
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 19/35] bloblist: Support allocating the bloblist

2021-10-25 Thread Simon Glass
Typically the bloblist is positioned at a fixed address in memory until
relocation. This is convenient when it is set up in SPL or before
relocation.

But for EFI we want to set it up only when U-Boot proper is running. Add
a way to allocate it using malloc() and update the documentation to cover
this aspect of bloblist.

Note there are no tests of this feature at present, nor any direct testing
of bloblist_init().

This can be added, e.g. by making this option controllable at runtime.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 common/Kconfig   | 15 +--
 common/bloblist.c| 16 ++--
 common/board_f.c |  8 +++-
 doc/develop/bloblist.rst | 16 
 4 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index d6f77ab7b9c..00ccaf59fa4 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -719,6 +719,8 @@ config TPL_BLOBLIST
  This enables a bloblist in TPL. The bloblist is set up in TPL and
  passed to SPL and U-Boot proper.
 
+if BLOBLIST
+
 config BLOBLIST_SIZE
hex "Size of bloblist"
depends on BLOBLIST
@@ -729,17 +731,24 @@ config BLOBLIST_SIZE
  is set up in the first part of U-Boot to run (TPL, SPL or U-Boot
  proper), and this sane bloblist is used for subsequent stages.
 
+config BLOBLIST_ALLOC
+   bool "Allocate bloblist"
+   help
+ Allocate the bloblist using malloc(). This avoids the need to
+ specify a fixed address on systems where this is unknown or can
+ change at runtime.
+
 config BLOBLIST_ADDR
hex "Address of bloblist"
-   depends on BLOBLIST
default 0xc000 if SANDBOX
help
  Sets the address of the bloblist, set up by the first part of U-Boot
  which runs. Subsequent U-Boot stages typically use the same address.
 
+ This is not used if BLOBLIST_ALLOC is selected.
+
 config BLOBLIST_SIZE_RELOC
hex "Size of bloblist after relocation"
-   depends on BLOBLIST
default BLOBLIST_SIZE
help
  Sets the size of the bloblist in bytes after relocation. Since U-Boot
@@ -747,6 +756,8 @@ config BLOBLIST_SIZE_RELOC
  size than the one set up by SPL. This bloblist is set up during the
  relocation process.
 
+endif # BLOBLIST
+
 endmenu
 
 source "common/spl/Kconfig"
diff --git a/common/bloblist.c b/common/bloblist.c
index 1290fff8504..01b04103d91 100644
--- a/common/bloblist.c
+++ b/common/bloblist.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -416,10 +417,21 @@ int bloblist_init(void)
ret = bloblist_check(CONFIG_BLOBLIST_ADDR,
 CONFIG_BLOBLIST_SIZE);
if (ret) {
+   ulong addr;
+
log(LOGC_BLOBLIST, expected ? LOGL_WARNING : LOGL_DEBUG,
"Existing bloblist not found: creating new bloblist\n");
-   ret = bloblist_new(CONFIG_BLOBLIST_ADDR, CONFIG_BLOBLIST_SIZE,
-  0);
+   if (IS_ENABLED(CONFIG_BLOBLIST_ALLOC)) {
+   void *ptr = memalign(BLOBLIST_ALIGN,
+CONFIG_BLOBLIST_SIZE);
+
+   if (!ptr)
+   return log_msg_ret("alloc", -ENOMEM);
+   addr = map_to_sysmem(ptr);
+   } else {
+   addr = CONFIG_BLOBLIST_ADDR;
+   }
+   ret = bloblist_new(addr, CONFIG_BLOBLIST_SIZE, 0);
} else {
log(LOGC_BLOBLIST, LOGL_DEBUG, "Found existing bloblist\n");
}
diff --git a/common/board_f.c b/common/board_f.c
index 3dc0eaa59c5..c8d25b5e1de 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -655,8 +655,14 @@ static int reloc_bootstage(void)
 static int reloc_bloblist(void)
 {
 #ifdef CONFIG_BLOBLIST
-   if (gd->flags & GD_FLG_SKIP_RELOC)
+   /*
+* Relocate only if we are supposed to send it
+*/
+   if ((gd->flags & GD_FLG_SKIP_RELOC) &&
+   CONFIG_BLOBLIST_SIZE == CONFIG_BLOBLIST_SIZE_RELOC) {
+   debug("Not relocating bloblist\n");
return 0;
+   }
if (gd->new_bloblist) {
int size = CONFIG_BLOBLIST_SIZE;
 
diff --git a/doc/develop/bloblist.rst b/doc/develop/bloblist.rst
index 317ebc4919d..47274cf8e26 100644
--- a/doc/develop/bloblist.rst
+++ b/doc/develop/bloblist.rst
@@ -59,6 +59,22 @@ Bloblist provides a fairly simple API which allows blobs to 
be created and
 found. All access is via the blob's tag. Blob records are zeroed when added.
 
 
+Placing the bloblist
+
+
+The bloblist is typically positioned at a fixed address by TPL, or SPL. This
+is controlled by `CONFIG_BLOBLIST_ADDR`. But in some cases it is preferable to
+allocate the bloblist in the malloc() space. Use the `CONFIG_BLOBLIST_ALLOC`

[PATCH v3 18/35] efi: serial: Support arrow keys

2021-10-25 Thread Simon Glass
At present only the backspace key is supported in U-Boot, when running as
an EFI app. Add support for arrows, home and end as well, to make the CLI
more friendly.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/serial/serial_efi.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/serial/serial_efi.c b/drivers/serial/serial_efi.c
index 33ddbd6080c..0067576389d 100644
--- a/drivers/serial/serial_efi.c
+++ b/drivers/serial/serial_efi.c
@@ -24,6 +24,9 @@ struct serial_efi_priv {
bool have_key;
 };
 
+/* Convert a lower-case character to its ctrl-char equivalent */
+#define CTL_CH(c)  ((c) - 'a' + 1)
+
 int serial_efi_setbrg(struct udevice *dev, int baudrate)
 {
return 0;
@@ -49,6 +52,7 @@ static int serial_efi_get_key(struct serial_efi_priv *priv)
 static int serial_efi_getc(struct udevice *dev)
 {
struct serial_efi_priv *priv = dev_get_priv(dev);
+   char conv_scan[10] = {0, 'p', 'n', 'f', 'b', 'a', 'e', 0, 8};
int ret, ch;
 
ret = serial_efi_get_key(priv);
@@ -63,8 +67,11 @@ static int serial_efi_getc(struct udevice *dev)
 * key scan code of 8. Handle this so that backspace works correctly
 * in the U-Boot command line.
 */
-   if (!ch && priv->key.scan_code == 8)
-   ch = 8;
+   if (!ch && priv->key.scan_code < sizeof(conv_scan)) {
+   ch = conv_scan[priv->key.scan_code];
+   if (ch >= 'a')
+   ch -= 'a' - 1;
+   }
debug(" [%x %x %x] ", ch, priv->key.unicode_char, priv->key.scan_code);
 
return ch;
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 17/35] binman: Support updating the dtb in an ELF file

2021-10-25 Thread Simon Glass
WIth EFI we must embed the devicetree in an ELF image so that it is loaded
as part of the executable file. We want it to include the binman
definition in there also, which in some cases cannot be created until the
ELF (u-boot) is built. Add an option to binman to support writing the
updated dtb to the ELF file u-boot.out

This is useful with the EFI app, which is always packaged as an ELF file.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/binman/binman.rst| 36 ++
 tools/binman/cmdline.py|  2 +
 tools/binman/control.py| 11 +++
 tools/binman/elf.py| 21 ++
 tools/binman/ftest.py  | 83 +-
 tools/binman/test/Makefile | 10 ++-
 tools/binman/test/u_boot_binman_embed.c| 13 
 tools/binman/test/u_boot_binman_embed.lds  | 29 
 tools/binman/test/u_boot_binman_embed_sm.c | 13 
 9 files changed, 216 insertions(+), 2 deletions(-)
 create mode 100644 tools/binman/test/u_boot_binman_embed.c
 create mode 100644 tools/binman/test/u_boot_binman_embed.lds
 create mode 100644 tools/binman/test/u_boot_binman_embed_sm.c

diff --git a/tools/binman/binman.rst b/tools/binman/binman.rst
index 614df541c5a..35de93bd898 100644
--- a/tools/binman/binman.rst
+++ b/tools/binman/binman.rst
@@ -818,6 +818,42 @@ the 'warning' line in scripts/Makefile.lib to see what it 
has found::
# u_boot_dtsi_options_debug = $(u_boot_dtsi_options_raw)
 
 
+Updating an ELF file
+
+
+For the EFI app, where U-Boot is loaded from UEFI and runs as an app, there is
+no way to update the devicetree after U-Boot is built. Normally this works by
+creating a new u-boot.dtb.out with he updated devicetree, which is 
automatically
+built into the output image. With ELF this is not possible since the ELF is
+not part of an image, just a stand-along file. We must create an updated ELF
+file with the new devicetree.
+
+This is handled by the --update-fdt-in-elf option. It takes four arguments,
+separated by comma:
+
+   infile - filename of input ELF file, e.g. 'u-boot's
+   outfile- filename of output ELF file, e.g. 'u-boot.out'
+   begin_sym - symbol at the start of the embedded devicetree, e.g.
+   '__dtb_dt_begin'
+   end_sym   - symbol at the start of the embedded devicetree, e.g.
+   '__dtb_dt_end'
+
+When this flag is used, U-Boot does all the normal packaging, but as an
+additional step, it creates a new ELF file with the new devicetree embedded in
+it.
+
+If logging is enabled you will see a message like this::
+
+   Updating file 'u-boot' with data length 0x400a (16394) between symbols
+   '__dtb_dt_begin' and '__dtb_dt_end'
+
+There must be enough space for the updated devicetree. If not, an error like
+the following is produced::
+
+   ValueError: Not enough space in 'u-boot' for data length 0x400a (16394);
+   size is 0x1744 (5956)
+
+
 Entry Documentation
 ===
 
diff --git a/tools/binman/cmdline.py b/tools/binman/cmdline.py
index d6156df408b..23729f16dcc 100644
--- a/tools/binman/cmdline.py
+++ b/tools/binman/cmdline.py
@@ -71,6 +71,8 @@ controlled by a description in the board device tree.'''
  'given')
 build_parser.add_argument('-u', '--update-fdt', action='store_true',
 default=False, help='Update the binman node with offset/size info')
+build_parser.add_argument('--update-fdt-in-elf', type=str,
+help='Update an ELF file with the output dtb: 
infile,outfile,begin_sym,end_sym')
 
 entry_parser = subparsers.add_parser('entry-docs',
 help='Write out entry documentation (see entries.rst)')
diff --git a/tools/binman/control.py b/tools/binman/control.py
index 0dbcbc28e99..a56e65ace64 100644
--- a/tools/binman/control.py
+++ b/tools/binman/control.py
@@ -595,6 +595,13 @@ def Binman(args):
 tools.FinaliseOutputDir()
 return 0
 
+elf_params = None
+if args.update_fdt_in_elf:
+elf_params = args.update_fdt_in_elf.split(',')
+if len(elf_params) != 4:
+raise ValueError('Invalid args %s to --update-fdt-in-elf: expected 
infile,outfile,begin_sym,end_sym' %
+ elf_params)
+
 # Try to figure out which device tree contains our image description
 if args.dt:
 dtb_fname = args.dt
@@ -641,6 +648,10 @@ def Binman(args):
 for dtb_item in state.GetAllFdts():
 tools.WriteFile(dtb_item._fname, dtb_item.GetContents())
 
+if elf_params:
+data = state.GetFdtForEtype('u-boot-dtb').GetContents()
+elf.UpdateFile(*elf_params, data)
+
 if missing:
 tout.Warning("\nSome images are invalid")
 
diff --git a/tools/binman/elf.py b/tools/binman/elf.py
index 4aca4f847ce..de2bb4651fa 100644
--- a/tools/binman/elf.py
+++ b/tools/binman/elf.py
@@ -348,3 +348,24 @@ def DecodeElf(data, location):
 

[PATCH v3 14/35] binman: Support reading the offset of an ELF-file symbol

2021-10-25 Thread Simon Glass
Binman needs to be able to update the contents of an ELF file after it has
been build. To support this, add a function to locate the position of a
symbol's contents within the file.

Fix the comments on bss_data.c and Symbol while we are here.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/binman/elf.py  | 53 ++--
 tools/binman/elf_test.py | 37 ++
 tools/binman/test/Makefile   |  5 ++-
 tools/binman/test/bss_data.c |  2 +-
 tools/binman/test/embed_data.c   | 16 ++
 tools/binman/test/embed_data.lds | 23 ++
 6 files changed, 131 insertions(+), 5 deletions(-)
 create mode 100644 tools/binman/test/embed_data.c
 create mode 100644 tools/binman/test/embed_data.lds

diff --git a/tools/binman/elf.py b/tools/binman/elf.py
index 03b49d7163c..4aca4f847ce 100644
--- a/tools/binman/elf.py
+++ b/tools/binman/elf.py
@@ -24,7 +24,14 @@ try:
 except:  # pragma: no cover
 ELF_TOOLS = False
 
-Symbol = namedtuple('Symbol', ['section', 'address', 'size', 'weak'])
+# Information about an EFL symbol:
+# section (str): Name of the section containing this symbol
+# address (int): Address of the symbol (its value)
+# size (int): Size of the symbol in bytes
+# weak (bool): True if the symbol is weak
+# offset (int or None): Offset of the symbol's data in the ELF file, or None if
+#   not known
+Symbol = namedtuple('Symbol', ['section', 'address', 'size', 'weak', 'offset'])
 
 # Information about an ELF file:
 #data: Extracted program contents of ELF file (this would be loaded by an
@@ -71,8 +78,48 @@ def GetSymbols(fname, patterns):
 section, size =  parts[:2]
 if len(parts) > 2:
 name = parts[2] if parts[2] != '.hidden' else parts[3]
-syms[name] = Symbol(section, int(value, 16), int(size,16),
-flags[1] == 'w')
+syms[name] = Symbol(section, int(value, 16), int(size, 16),
+flags[1] == 'w', None)
+
+# Sort dict by address
+return OrderedDict(sorted(syms.items(), key=lambda x: x[1].address))
+
+def GetSymbolFileOffset(fname, patterns):
+"""Get the symbols from an ELF file
+
+Args:
+fname: Filename of the ELF file to read
+patterns: List of regex patterns to search for, each a string
+
+Returns:
+None, if the file does not exist, or Dict:
+  key: Name of symbol
+  value: Hex value of symbol
+"""
+def _GetFileOffset(elf, addr):
+for seg in elf.iter_segments():
+seg_end = seg['p_vaddr'] + seg['p_filesz']
+if seg.header['p_type'] == 'PT_LOAD':
+if addr >= seg['p_vaddr'] and addr < seg_end:
+return addr - seg['p_vaddr'] + seg['p_offset']
+
+if not ELF_TOOLS:
+raise ValueError('Python elftools package is not available')
+
+syms = {}
+with open(fname, 'rb') as fd:
+elf = ELFFile(fd)
+
+re_syms = re.compile('|'.join(patterns))
+for section in elf.iter_sections():
+if isinstance(section, SymbolTableSection):
+for symbol in section.iter_symbols():
+if not re_syms or re_syms.search(symbol.name):
+addr = symbol.entry['st_value']
+syms[symbol.name] = Symbol(
+section.name, addr, symbol.entry['st_size'],
+symbol.entry['st_info']['bind'] == 'STB_WEAK',
+_GetFileOffset(elf, addr))
 
 # Sort dict by address
 return OrderedDict(sorted(syms.items(), key=lambda x: x[1].address))
diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py
index bcccd78c0a1..ac69a95b654 100644
--- a/tools/binman/elf_test.py
+++ b/tools/binman/elf_test.py
@@ -6,6 +6,7 @@
 
 import os
 import shutil
+import struct
 import sys
 import tempfile
 import unittest
@@ -221,6 +222,42 @@ class TestElf(unittest.TestCase):
  elf.DecodeElf(data, load + 2))
 shutil.rmtree(outdir)
 
+def testEmbedData(self):
+"""Test for the GetSymbolFileOffset() function"""
+if not elf.ELF_TOOLS:
+self.skipTest('Python elftools not available')
+
+fname = self.ElfTestFile('embed_data')
+offset = elf.GetSymbolFileOffset(fname, ['embed_start', 'embed_end'])
+start = offset['embed_start'].offset
+end = offset['embed_end'].offset
+data = tools.ReadFile(fname)
+embed_data = data[start:end]
+expect = struct.pack('

[PATCH v3 16/35] binman: Tidy up comments on _DoTestFile()

2021-10-25 Thread Simon Glass
The comment for this function is missing an argument and the return value.
Fix it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/binman/ftest.py | 5 +
 1 file changed, 5 insertions(+)

diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 8199a4fc7e0..39a4b94cd0b 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -334,6 +334,11 @@ class TestFunctional(unittest.TestCase):
 extra_indirs: Extra input directories to add using -I
 threads: Number of threads to use (None for default, 0 for
 single-threaded)
+test_section_timeout: True to force the first time to timeout, as
+used in testThreadTimeout()
+
+Returns:
+int return code, 0 on success
 """
 args = []
 if debug:
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 15/35] binman: Allow timeout to occur in the image or its section

2021-10-25 Thread Simon Glass
At present testThreadTimeout() assumes that the expected timeout happens
first when building the section, but it can just as easily happen at the
top-level image. Update the test to cope with both.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/binman/ftest.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index cea3ebf2b9f..8199a4fc7e0 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -4565,8 +4565,7 @@ class TestFunctional(unittest.TestCase):
 with self.assertRaises(ValueError) as e:
 self._DoTestFile('202_section_timeout.dts',
  test_section_timeout=True)
-self.assertIn("Node '/binman/section@0': Timed out obtaining contents",
-  str(e.exception))
+self.assertIn("Timed out obtaining contents", str(e.exception))
 
 def testTiming(self):
 """Test output of timing information"""
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 13/35] binman: Report an error if test files fail to compile

2021-10-25 Thread Simon Glass
At present any error from the 'make' command is silently swallowed by the
test system. Fix this by showing it when detected.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/binman/elf_test.py | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py
index 7a128018d9f..bcccd78c0a1 100644
--- a/tools/binman/elf_test.py
+++ b/tools/binman/elf_test.py
@@ -70,8 +70,12 @@ def BuildElfTestFiles(target_dir):
 # correctly. So drop any make flags here.
 if 'MAKEFLAGS' in os.environ:
 del os.environ['MAKEFLAGS']
-tools.Run('make', '-C', target_dir, '-f',
-  os.path.join(testdir, 'Makefile'), 'SRC=%s/' % testdir)
+try:
+tools.Run('make', '-C', target_dir, '-f',
+  os.path.join(testdir, 'Makefile'), 'SRC=%s/' % testdir)
+except ValueError as e:
+# The test system seems to suppress this in a strange way
+print(e)
 
 
 class TestElf(unittest.TestCase):
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 20/35] x86: Allow booting a kernel from the EFI app

2021-10-25 Thread Simon Glass
At present this is disabled, but it should work so long as the kernel does
not need EFI services. Enable it and add a note about remaining work.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Update documentation

 arch/x86/lib/bootm.c   | 11 +++
 doc/develop/uefi/u-boot_on_efi.rst |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/arch/x86/lib/bootm.c b/arch/x86/lib/bootm.c
index 667e5e689e3..57cba5c65d3 100644
--- a/arch/x86/lib/bootm.c
+++ b/arch/x86/lib/bootm.c
@@ -179,10 +179,14 @@ int boot_linux_kernel(ulong setup_base, ulong 
load_address, bool image_64bit)
* U-Boot is setting them up that way for itself in
* arch/i386/cpu/cpu.c.
*
-   * Note that we cannot currently boot a kernel while running as
-   * an EFI application. Please use the payload option for that.
+   * Note: this is incomplete for EFI kernels!
+   *
+   * This can boot a kernel while running as an EFI application,
+   * but if the kernel requires EFI support then that support needs
+   * to be enabled first (see EFI_LOADER). Also the EFI information
+   * must enabled with setup_efi_info(). See setup_zimage() for
+   * how this is done with the stub.
*/
-#ifndef CONFIG_EFI_APP
__asm__ __volatile__ (
"movl $0, %%ebp\n"
"cli\n"
@@ -191,7 +195,6 @@ int boot_linux_kernel(ulong setup_base, ulong load_address, 
bool image_64bit)
[boot_params] "S"(setup_base),
"b"(0), "D"(0)
);
-#endif
}
 
/* We can't get to here */
diff --git a/doc/develop/uefi/u-boot_on_efi.rst 
b/doc/develop/uefi/u-boot_on_efi.rst
index f39be4a1ed9..7bd757ca645 100644
--- a/doc/develop/uefi/u-boot_on_efi.rst
+++ b/doc/develop/uefi/u-boot_on_efi.rst
@@ -267,7 +267,7 @@ This work could be extended in a number of ways:
 
 - Avoid turning off boot services in the stub. Instead allow U-Boot to make
   use of boot services in case it wants to. It is unclear what it might want
-  though.
+  though. It is better to use the app.
 
 Where is the code?
 --
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 12/35] patman: Use a ValueError exception if tools.Run() fails

2021-10-25 Thread Simon Glass
The Exception base class is a very vague and could be confusing to the
test system. Use the more specific ValueError exception instead.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 tools/patman/tools.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/patman/tools.py b/tools/patman/tools.py
index 710f1fdcd36..86c4f616206 100644
--- a/tools/patman/tools.py
+++ b/tools/patman/tools.py
@@ -349,7 +349,7 @@ def Run(name, *args, **kwargs):
 result = command.RunPipe([all_args], capture=True, capture_stderr=True,
  env=env, raise_on_error=False, binary=binary)
 if result.return_code:
-raise Exception("Error %d running '%s': %s" %
+raise ValueError("Error %d running '%s': %s" %
(result.return_code,' '.join(all_args),
 result.stderr))
 return result.stdout
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 11/35] efi: Locate all block devices in the app

2021-10-25 Thread Simon Glass
When starting the app, locate all block devices and make them available
to U-Boot. This allows listing partitions and accessing files in
filesystems.

EFI also has the concept of 'disks', meaning boot media. For now, this
is not obviously useful in U-Boot, but add code to at least locate these.
This can be expanded later as needed.

Series-changes; 2
- Store device path in struct efi_media_plat
- Don't export efi_bind_block()
- Only bind devices for media devices, not for partitions
- Show devices that are processed
- Update documentation

Signed-off-by: Simon Glass 
---

(no changes since v1)

 doc/develop/uefi/u-boot_on_efi.rst |   4 +-
 include/efi.h  |   6 +-
 include/efi_api.h  |  15 ++
 lib/efi/efi_app.c  | 223 +
 4 files changed, 243 insertions(+), 5 deletions(-)

diff --git a/doc/develop/uefi/u-boot_on_efi.rst 
b/doc/develop/uefi/u-boot_on_efi.rst
index 83de9309816..f39be4a1ed9 100644
--- a/doc/develop/uefi/u-boot_on_efi.rst
+++ b/doc/develop/uefi/u-boot_on_efi.rst
@@ -263,9 +263,7 @@ This work could be extended in a number of ways:
 
 - Figure out how to solve the interrupt problem
 
-- Add more drivers to the application side (e.g. block devices, USB,
-  environment access). This would mostly be an academic exercise as a strong
-  use case is not readily apparent, but it might be fun.
+- Add more drivers to the application side (e.g.USB, environment access).
 
 - Avoid turning off boot services in the stub. Instead allow U-Boot to make
   use of boot services in case it wants to. It is unclear what it might want
diff --git a/include/efi.h b/include/efi.h
index 0ec5913ddd1..908c5dc6ebd 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -419,10 +419,12 @@ struct efi_priv {
  *
  * @handle: handle of the controller on which this driver is installed
  * @blkio: block io protocol proxied by this driver
+ * @device_path: EFI path to the device
  */
 struct efi_media_plat {
-   efi_handle_thandle;
-   struct efi_block_io *blkio;
+   efi_handle_t handle;
+   struct efi_block_io *blkio;
+   struct efi_device_path *device_path;
 };
 
 /* Base address of the EFI image */
diff --git a/include/efi_api.h b/include/efi_api.h
index c8f959bb720..0e88b3e5dbe 100644
--- a/include/efi_api.h
+++ b/include/efi_api.h
@@ -1994,4 +1994,19 @@ struct efi_firmware_management_protocol {
const u16 *package_version_name);
 };
 
+#define EFI_DISK_IO_PROTOCOL_GUID  \
+   EFI_GUID(0xce345171, 0xba0b, 0x11d2, 0x8e, 0x4f, \
+0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
+
+struct efi_disk {
+   u64 revision;
+   efi_status_t (EFIAPI *read_disk)(struct efi_disk *this, u32 media_id,
+u64 offset, efi_uintn_t buffer_size,
+void *buffer);
+
+   efi_status_t (EFIAPI *write_disk)(struct efi_disk *this, u32 media_id,
+ u64 offset, efi_uintn_t buffer_size,
+ void *buffer);
+};
+
 #endif
diff --git a/lib/efi/efi_app.c b/lib/efi/efi_app.c
index f61665686c5..e38d46b15db 100644
--- a/lib/efi/efi_app.c
+++ b/lib/efi/efi_app.c
@@ -21,6 +21,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -46,6 +49,64 @@ int efi_info_get(enum efi_entry_t type, void **datap, int 
*sizep)
return -ENOSYS;
 }
 
+/**
+ * efi_print_str() - Print a UFT-16 string to the U-Boot console
+ *
+ * @str: String to print
+ */
+static void efi_print_str(const u16 *str)
+{
+   while (*str) {
+   int ch = *str++;
+
+   if (ch > ' ' && ch < 127)
+   putc(ch);
+   }
+}
+
+/**
+ * efi_bind_block() - bind a new block device to an EFI device
+ *
+ * Binds a new top-level EFI_MEDIA device as well as a child block device so
+ * that the block device can be accessed in U-Boot.
+ *
+ * The device can then be accessed using 'part list efi 0', 'fat ls efi 0:1',
+ * for example, just like any other interface type.
+ *
+ * @handle: handle of the controller on which this driver is installed
+ * @blkio: block io protocol proxied by this driver
+ * @device_path: EFI device path structure for this
+ * @len: Length of @device_path in bytes
+ * @devp: Returns the bound device
+ * @return 0 if OK, -ve on error
+ */
+int efi_bind_block(efi_handle_t handle, struct efi_block_io *blkio,
+  struct efi_device_path *device_path, int len,
+  struct udevice **devp)
+{
+   struct efi_media_plat plat;
+   struct udevice *dev;
+   char name[18];
+   int ret;
+
+   plat.handle = handle;
+   plat.blkio = blkio;
+   plat.device_path = malloc(device_path->length);
+   if (!plat.device_path)
+   return log_msg_ret("path", -ENOMEM);
+   memcpy(plat.device_path, device_path, device_path->length);
+   ret 

[PATCH v3 10/35] efi: Add a media/block driver for EFI block devices

2021-10-25 Thread Simon Glass
Add a block driver which handles read/write for EFI block devices. This
driver actually already exists ('efi_block') but is not really suitable
for use as a real U-Boot driver:

- The operations do not provide a udevice
- The code is designed for running as part of EFI loader, so uses
EFI_PRINT() and EFI_CALL().
- The bind method probes the device, which is not permitted
- It uses 'EFI' as its parent device

The new driver is more 'normal', just requiring its platform data be set
up in advance.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Drop mention of partitions from the commit message

 drivers/block/Kconfig   |  10 
 drivers/block/Makefile  |   1 +
 drivers/block/efi_blk.c | 115 
 include/efi.h   |  11 
 4 files changed, 137 insertions(+)
 create mode 100644 drivers/block/efi_blk.c

diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 755fdccb574..8235430497d 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -82,6 +82,16 @@ config EFI_MEDIA_SANDBOX
  EFI_MEDIA uclass. It does not do anything useful, since sandbox does
  not actually support running on top of UEFI.
 
+config EFI_MEDIA_BLK
+   bool "EFI media block driver"
+   depends on EFI_APP
+   default y
+   help
+ Enables a block driver for providing access to UEFI devices. This
+ allows use of block devices detected by the underlying UEFI
+ implementation. With this it is possible to use filesystems on these
+ devices, for example.
+
 endif  # EFI_MEDIA
 
 config IDE
diff --git a/drivers/block/Makefile b/drivers/block/Makefile
index 3778633da1d..b221a7c6eea 100644
--- a/drivers/block/Makefile
+++ b/drivers/block/Makefile
@@ -17,3 +17,4 @@ obj-$(CONFIG_$(SPL_TPL_)BLOCK_CACHE) += blkcache.o
 
 obj-$(CONFIG_EFI_MEDIA) += efi-media-uclass.o
 obj-$(CONFIG_EFI_MEDIA_SANDBOX) += sb_efi_media.o
+obj-$(CONFIG_EFI_MEDIA_BLK) += efi_blk.o
diff --git a/drivers/block/efi_blk.c b/drivers/block/efi_blk.c
new file mode 100644
index 000..c00b0cc0b1c
--- /dev/null
+++ b/drivers/block/efi_blk.c
@@ -0,0 +1,115 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Block driver for EFI devices
+ * This supports a media driver of UCLASS_EFI with a child UCLASS_BLK
+ * It allows block-level access to EFI devices made available via EFI boot
+ * services
+ *
+ * Copyright 2021 Google LLC
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct efi_block_plat {
+   struct efi_block_io *blkio;
+};
+
+/**
+ * Read from block device
+ *
+ * @dev:   device
+ * @blknr: first block to be read
+ * @blkcnt:number of blocks to read
+ * @buffer:output buffer
+ * Return: number of blocks transferred
+ */
+static ulong efi_bl_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
+void *buffer)
+{
+   struct efi_block_plat *plat = dev_get_plat(dev);
+   struct efi_block_io *io = plat->blkio;
+   efi_status_t ret;
+
+   log_debug("read buf=%p, block=%lx, count=%lx: ", buffer, (ulong)blknr,
+ (ulong)blkcnt);
+   ret = io->read_blocks(io, io->media->media_id, blknr,
+ blkcnt * io->media->block_size, buffer);
+   log_debug("ret=%lx (dec %ld)\n", ret & ~EFI_ERROR_MASK,
+ ret & ~EFI_ERROR_MASK);
+   if (ret)
+   return 0;
+
+   return blkcnt;
+}
+
+/**
+ * Write to block device
+ *
+ * @dev:   device
+ * @blknr: first block to be write
+ * @blkcnt:number of blocks to write
+ * @buffer:input buffer
+ * Return: number of blocks transferred
+ */
+static ulong efi_bl_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
+ const void *buffer)
+{
+   struct efi_block_plat *plat = dev_get_plat(dev);
+   struct efi_block_io *io = plat->blkio;
+   efi_status_t ret;
+
+   log_debug("write buf=%p, block=%lx, count=%lx: ", buffer, (ulong)blknr,
+ (ulong)blkcnt);
+   ret = io->write_blocks(io, io->media->media_id, blknr,
+  blkcnt * io->media->block_size, (void *)buffer);
+   log_debug("ret=%lx (dec %ld)\n", ret & ~EFI_ERROR_MASK,
+ ret & ~EFI_ERROR_MASK);
+   if (ret)
+   return 0;
+
+   return blkcnt;
+}
+
+/* Block device driver operators */
+static const struct blk_ops efi_blk_ops = {
+   .read   = efi_bl_read,
+   .write  = efi_bl_write,
+};
+
+U_BOOT_DRIVER(efi_block) = {
+   .name   = "efi_block",
+   .id = UCLASS_BLK,
+   .ops= _blk_ops,
+   .plat_auto  = sizeof(struct efi_block_plat),
+};
+
+static int efi_media_bind(struct udevice *dev)
+{
+   struct efi_media_plat *plat = dev_get_plat(dev);
+   struct efi_block_plat *blk_plat;
+   struct udevice *blk;
+   int ret;
+
+   ret = blk_create_devicef(dev, "efi_block", 

[PATCH v3 09/35] efi: Add EFI uclass for media

2021-10-25 Thread Simon Glass
At present UCLASS_EFI is used to represent an EFI filesystem among other
things. The description of this uclass is "EFI managed devices" which is
pretty vague. The only driver that uses this uclass is in fact not a real
U-Boot driver, since its operations do not include a struct udevice.

Rather than mess with this, create a new UCLASS_EFI_MEDIA uclass to handle
EFI media such as disks. Make this the uclass to use for EFI media so that
it can be used with 'part list', for example.

The existing implementation using UCLASS_EFI remains as is, for
discussion.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add MAINTAINERS entry
- Show the correct interface type with 'part list'
- Update the commit message to explain things better

 MAINTAINERS  |  3 +++
 arch/sandbox/dts/test.dts|  4 
 disk/part.c  |  5 -
 drivers/block/Kconfig| 23 +++
 drivers/block/Makefile   |  3 +++
 drivers/block/blk-uclass.c   |  2 +-
 drivers/block/efi-media-uclass.c | 15 +++
 drivers/block/sb_efi_media.c | 20 
 include/dm/uclass-id.h   |  1 +
 test/dm/Makefile |  1 +
 test/dm/efi_media.c  | 24 
 11 files changed, 99 insertions(+), 2 deletions(-)
 create mode 100644 drivers/block/efi-media-uclass.c
 create mode 100644 drivers/block/sb_efi_media.c
 create mode 100644 test/dm/efi_media.c

diff --git a/MAINTAINERS b/MAINTAINERS
index ca015e3f3e3..f807d0c44d9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -701,8 +701,11 @@ W: 
https://u-boot.readthedocs.io/en/latest/develop/uefi/u-boot_on_efi.html
 F: board/efi/efi-x86_app
 F: configs/efi-x86_app*
 F: doc/develop/uefi/u-boot_on_efi.rst
+F: drivers/block/efi-media-uclass.c
+F: drivers/block/sb_efi_media.c
 F: lib/efi/efi_app.c
 F: scripts/build-efi.sh
+F: test/dm/efi_media.c
 
 EFI PAYLOAD
 M: Heinrich Schuchardt 
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index e27d106466b..517c7f31cf7 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -498,6 +498,10 @@
compatible = "sandbox,clk-ccf";
};
 
+   efi-media {
+   compatible = "sandbox,efi-media";
+   };
+
eth@10002000 {
compatible = "sandbox,eth";
reg = <0x10002000 0x1000>;
diff --git a/disk/part.c b/disk/part.c
index a6a8f7052bd..2560f6a50bc 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -296,8 +296,11 @@ static void print_part_header(const char *type, struct 
blk_desc *dev_desc)
case IF_TYPE_VIRTIO:
puts("VirtIO");
break;
+   case IF_TYPE_EFI:
+   puts("EFI");
+   break;
default:
-   puts ("UNKNOWN");
+   puts("UNKNOWN");
break;
}
printf (" device %d  --   Partition Type: %s\n\n",
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 56a4eec05ac..755fdccb574 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -61,6 +61,29 @@ config TPL_BLOCK_CACHE
help
  This option enables the disk-block cache in TPL
 
+config EFI_MEDIA
+   bool "Support EFI media drivers"
+   default y if EFI || SANDBOX
+   help
+ Enable this to support media devices on top of UEFI. This enables
+ just the uclass so you also need a specific driver to make this do
+ anything.
+
+ For sandbox there is a test driver.
+
+if EFI_MEDIA
+
+config EFI_MEDIA_SANDBOX
+   bool "Sandbox EFI media driver"
+   depends on SANDBOX
+   default y
+   help
+ Enables a simple sandbox media driver, used for testing just the
+ EFI_MEDIA uclass. It does not do anything useful, since sandbox does
+ not actually support running on top of UEFI.
+
+endif  # EFI_MEDIA
+
 config IDE
bool "Support IDE controllers"
select HAVE_BLOCK_DEVICE
diff --git a/drivers/block/Makefile b/drivers/block/Makefile
index 94ab5c6f906..3778633da1d 100644
--- a/drivers/block/Makefile
+++ b/drivers/block/Makefile
@@ -14,3 +14,6 @@ obj-$(CONFIG_IDE) += ide.o
 endif
 obj-$(CONFIG_SANDBOX) += sandbox.o
 obj-$(CONFIG_$(SPL_TPL_)BLOCK_CACHE) += blkcache.o
+
+obj-$(CONFIG_EFI_MEDIA) += efi-media-uclass.o
+obj-$(CONFIG_EFI_MEDIA_SANDBOX) += sb_efi_media.o
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index 83682dcc181..2db7ce5de20 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -44,7 +44,7 @@ static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
[IF_TYPE_SATA]  = UCLASS_AHCI,
[IF_TYPE_HOST]  = UCLASS_ROOT,
[IF_TYPE_NVME]  = UCLASS_NVME,
-   [IF_TYPE_EFI]   = UCLASS_EFI,
+   [IF_TYPE_EFI]   = UCLASS_EFI_MEDIA,
[IF_TYPE_VIRTIO]= 

[PATCH v3 08/35] efi: Add video support to the app

2021-10-25 Thread Simon Glass
The current EFI video driver only works when running in the stub. In that
case the stub calls boot services (before jumping to U-Boot proper) and
copies the graphics info over to the efi table. This is necessary because
the stub exits boot services before jumping to U-Boot.

The app maintains access to boot services throughout its life, so does not
need to do this. Update the driver to support calling boot services
directly.

Enable video output for the app. Note that this uses the
EFI_GRAPHICS_OUTPUT_PROTOCOL protocol, even though it mentions vesa.

A sample qemu command-line for this case is:

   qemu-system-x86_64 -bios /usr/share/edk2.git/ovmf-ia32/OVMF-pure-efi.fd
   -drive id=disk,file=try.img,if=none,format=raw -nic none
   -device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add a note that EFI_GRAPHICS_OUTPUT_PROTOCOL is used
- Update documentation

 arch/x86/dts/efi-x86_app.dts   |  4 +++
 board/efi/efi-x86_app/Kconfig  |  4 +++
 doc/develop/uefi/u-boot_on_efi.rst |  2 +-
 drivers/video/Kconfig  |  2 +-
 drivers/video/efi.c| 45 --
 include/configs/efi-x86_app.h  |  6 ++--
 6 files changed, 50 insertions(+), 13 deletions(-)

diff --git a/arch/x86/dts/efi-x86_app.dts b/arch/x86/dts/efi-x86_app.dts
index 04e044a07a8..a5316e2a1a7 100644
--- a/arch/x86/dts/efi-x86_app.dts
+++ b/arch/x86/dts/efi-x86_app.dts
@@ -25,4 +25,8 @@
compatible = "efi,reset";
u-boot,dm-pre-reloc;
};
+   efi-fb {
+   compatible = "efi-fb";
+   };
+
 };
diff --git a/board/efi/efi-x86_app/Kconfig b/board/efi/efi-x86_app/Kconfig
index e412702eed7..ecd08d73146 100644
--- a/board/efi/efi-x86_app/Kconfig
+++ b/board/efi/efi-x86_app/Kconfig
@@ -12,4 +12,8 @@ config SYS_SOC
 config SYS_CONFIG_NAME
default "efi-x86_app"
 
+config BOARD_SPECIFIC_OPTIONS # dummy
+   def_bool y
+   imply VIDEO_EFI
+
 endif
diff --git a/doc/develop/uefi/u-boot_on_efi.rst 
b/doc/develop/uefi/u-boot_on_efi.rst
index d049f429fdc..83de9309816 100644
--- a/doc/develop/uefi/u-boot_on_efi.rst
+++ b/doc/develop/uefi/u-boot_on_efi.rst
@@ -263,7 +263,7 @@ This work could be extended in a number of ways:
 
 - Figure out how to solve the interrupt problem
 
-- Add more drivers to the application side (e.g. video, block devices, USB,
+- Add more drivers to the application side (e.g. block devices, USB,
   environment access). This would mostly be an academic exercise as a strong
   use case is not readily apparent, but it might be fun.
 
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 2f4650f8309..a58f87f479b 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -250,7 +250,7 @@ config VIDEO_COREBOOT
 
 config VIDEO_EFI
bool "Enable EFI framebuffer driver support"
-   depends on EFI_STUB
+   depends on EFI_STUB || EFI_APP
help
  Turn on this option to enable a framebuffeer driver when U-Boot is
  loaded as a payload (see README.u-boot_on_efi) by an EFI BIOS where
diff --git a/drivers/video/efi.c b/drivers/video/efi.c
index c248bd352a7..4e13a3efcb1 100644
--- a/drivers/video/efi.c
+++ b/drivers/video/efi.c
@@ -50,6 +50,28 @@ static void efi_find_pixel_bits(u32 mask, u8 *pos, u8 *size)
*size = len;
 }
 
+static int get_mode_info(struct vesa_mode_info *vesa)
+{
+   efi_guid_t efi_gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
+   struct efi_boot_services *boot = efi_get_boot();
+   struct efi_gop_mode *mode;
+   struct efi_gop *gop;
+   int ret;
+
+   if (!boot)
+   return log_msg_ret("sys", -ENOSYS);
+   ret = boot->locate_protocol(_gop_guid, NULL, (void **));
+   if (ret)
+   return log_msg_ret("prot", -ENOTSUPP);
+
+   mode = gop->mode;
+   vesa->phys_base_ptr = mode->fb_base;
+   vesa->x_resolution = mode->info->width;
+   vesa->y_resolution = mode->info->height;
+
+   return 0;
+}
+
 static int save_vesa_mode(struct vesa_mode_info *vesa)
 {
struct efi_entry_gopmode *mode;
@@ -57,16 +79,23 @@ static int save_vesa_mode(struct vesa_mode_info *vesa)
int size;
int ret;
 
-   ret = efi_info_get(EFIET_GOP_MODE, (void **), );
-   if (ret == -ENOENT) {
-   debug("efi graphics output protocol mode not found\n");
-   return -ENXIO;
+   if (IS_ENABLED(CONFIG_EFI_APP)) {
+   ret = get_mode_info(vesa);
+   if (ret) {
+   printf("efi graphics output protocol not found\n");
+   return -ENXIO;
+   }
+   } else {
+   ret = efi_info_get(EFIET_GOP_MODE, (void **), );
+   if (ret == -ENOENT) {
+   printf("efi graphics output protocol mode not found\n");
+   return -ENXIO;
+   }
+   

[PATCH v3 07/35] efi: Add a way to obtain boot services in the app

2021-10-25 Thread Simon Glass
Add a function to return this information along with a stub for the
efi_info_get() function, since calling it otherwise hangs U-Boot.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/efi.h |  8 +++-
 lib/efi/efi_app.c | 10 ++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/include/efi.h b/include/efi.h
index 18c13e0370a..b5835422b95 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -444,9 +444,15 @@ extern char _binary_u_boot_bin_start[], 
_binary_u_boot_bin_end[];
  *
  * @return pointer to EFI system table
  */
-
 struct efi_system_table *efi_get_sys_table(void);
 
+/**
+ * efi_get_boot() - Get access to the EFI boot services table
+ *
+ * @return pointer to EFI boot services table
+ */
+struct efi_boot_services *efi_get_boot(void);
+
 /**
  * efi_get_ram_base() - Find the base of RAM
  *
diff --git a/lib/efi/efi_app.c b/lib/efi/efi_app.c
index 907bacd716a..f61665686c5 100644
--- a/lib/efi/efi_app.c
+++ b/lib/efi/efi_app.c
@@ -31,11 +31,21 @@ struct efi_system_table *efi_get_sys_table(void)
return global_priv->sys_table;
 }
 
+struct efi_boot_services *efi_get_boot(void)
+{
+   return global_priv->boot;
+}
+
 unsigned long efi_get_ram_base(void)
 {
return global_priv->ram_base;
 }
 
+int efi_info_get(enum efi_entry_t type, void **datap, int *sizep)
+{
+   return -ENOSYS;
+}
+
 static efi_status_t setup_memory(struct efi_priv *priv)
 {
struct efi_boot_services *boot = priv->boot;
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 06/35] x86: Don't duplicate global_ptr in 64-bit EFI app

2021-10-25 Thread Simon Glass
This variable is already defined by the EFI code. Drop the duplicate
definition when building a 64-bit EFI app.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/cpu/x86_64/cpu.c  | 15 +--
 arch/x86/cpu/x86_64/misc.c | 16 
 lib/efi/efi.c  |  9 +
 3 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/arch/x86/cpu/x86_64/cpu.c b/arch/x86/cpu/x86_64/cpu.c
index 8f72c9951a1..a3674e8e29a 100644
--- a/arch/x86/cpu/x86_64/cpu.c
+++ b/arch/x86/cpu/x86_64/cpu.c
@@ -8,20 +8,7 @@
 #include 
 #include 
 #include 
-
-/*
- * Global declaration of gd.
- *
- * As we write to it before relocation we have to make sure it is not put into
- * a .bss section which may overlap a .rela section. Initialization forces it
- * into a .data section which cannot overlap any .rela section.
- */
-struct global_data *global_data_ptr = (struct global_data *)~0;
-
-void arch_setup_gd(gd_t *new_gd)
-{
-   global_data_ptr = new_gd;
-}
+#include 
 
 int cpu_has_64bit(void)
 {
diff --git a/arch/x86/cpu/x86_64/misc.c b/arch/x86/cpu/x86_64/misc.c
index 02587ff0c50..691b67ff68a 100644
--- a/arch/x86/cpu/x86_64/misc.c
+++ b/arch/x86/cpu/x86_64/misc.c
@@ -7,6 +7,22 @@
 #include 
 #include 
 
+DECLARE_GLOBAL_DATA_PTR;
+
+/*
+ * Global declaration of gd.
+ *
+ * As we write to it before relocation we have to make sure it is not put into
+ * a .bss section which may overlap a .rela section. Initialization forces it
+ * into a .data section which cannot overlap any .rela section.
+ */
+struct global_data *global_data_ptr = (struct global_data *)~0;
+
+void arch_setup_gd(gd_t *new_gd)
+{
+   global_data_ptr = new_gd;
+}
+
 int misc_init_r(void)
 {
return 0;
diff --git a/lib/efi/efi.c b/lib/efi/efi.c
index 0c16a5fdd38..69e52e45748 100644
--- a/lib/efi/efi.c
+++ b/lib/efi/efi.c
@@ -17,6 +17,15 @@
 #include 
 #include 
 
+/*
+ * Global declaration of gd.
+ *
+ * As we write to it before relocation we have to make sure it is not put into
+ * a .bss section which may overlap a .rela section. Initialization forces it
+ * into a .data section which cannot overlap any .rela section.
+ */
+struct global_data *global_data_ptr = (struct global_data *)~0;
+
 /*
  * Unfortunately we cannot access any code outside what is built especially
  * for the stub. lib/string.c is already being built for the U-Boot payload
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 04/35] x86: Create a 32/64-bit selection for the app

2021-10-25 Thread Simon Glass
Most EFI implementations use 64-bit but U-Boot only supports running as
a 32-bit app at present. While efi-x86_payload64 does boot from 64-bit
UEFI it immediately changes back to 32-bit before starting U-Boot.

In order to support a 64-bit U-Boot app, update the Kconfig to add an
option for 32/64 bit. Update the prompt for the existing option so it is
clear it relates to the stub. Move both up to just under the choice that
controls them, since this looks better and the menu.

Use CONFIG_EFI_APP in the Makefile instead of CONFIG_TARGET_EFI_APP,
since the latter is specific to a single target and we will have two.

Memory size is set to 32MB for now so that it can run on qemu without
increasing the default memory size. We may need to increase the default
later.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Update minimum RAM to 256MB!

Changes in v2:
- Expand the commit message to make things clearer

 arch/x86/cpu/intel_common/Makefile |  2 +-
 lib/efi/Kconfig| 34 +++---
 2 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/arch/x86/cpu/intel_common/Makefile 
b/arch/x86/cpu/intel_common/Makefile
index 8b9a810f66d..1dc17b45879 100644
--- a/arch/x86/cpu/intel_common/Makefile
+++ b/arch/x86/cpu/intel_common/Makefile
@@ -27,7 +27,7 @@ obj-y += fast_spi.o
 obj-y += lpc.o
 obj-y += lpss.o
 obj-$(CONFIG_$(SPL_)INTEL_GENERIC_WIFI) += generic_wifi.o
-ifndef CONFIG_TARGET_EFI_APP
+ifndef CONFIG_EFI_APP
 obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += microcode.o
 ifndef CONFIG_$(SPL_)X86_64
 obj-y += microcode.o
diff --git a/lib/efi/Kconfig b/lib/efi/Kconfig
index 93b85644920..15ce99e1a74 100644
--- a/lib/efi/Kconfig
+++ b/lib/efi/Kconfig
@@ -26,18 +26,26 @@ config EFI_STUB
 
 endchoice
 
-config EFI_RAM_SIZE
-   hex "Amount of EFI RAM for U-Boot"
+choice
+   prompt "EFI app 32/64-bit selection"
depends on EFI_APP
-   default 0x200
help
- Set the amount of EFI RAM which is claimed by U-Boot for its own
- use. U-Boot allocates this from EFI on start-up (along with a few
- other smaller amounts) and it can never be increased after that.
- It is used as the RAM size in with U-Boot.
+ EFI does not support mixing 32-bit and 64-bit modes. This is a
+ significant problem because it means that you must build a stub with
+ the correct type for EFI to load it correctly. If you are using
+ 32-bit EFI, select 32-bit here, else select 64-bit. Failure to do
+ this may produce no error message - it just won't start!
+
+config EFI_APP_32BIT
+   bool "Produce an app for running with 32-bit EFI"
+
+config EFI_APP_64BIT
+   bool "Produce an app for running with 64-bit EFI"
+
+endchoice
 
 choice
-   prompt "EFI 32/64-bit selection"
+   prompt "EFI stub 32/64-bit selection"
depends on EFI_STUB
help
  EFI does not support mixing 32-bit and 64-bit modes. This is a
@@ -53,3 +61,13 @@ config EFI_STUB_64BIT
bool "Produce a stub for running with 64-bit EFI"
 
 endchoice
+
+config EFI_RAM_SIZE
+   hex "Amount of EFI RAM for U-Boot"
+   depends on EFI_APP
+   default 0x1000
+   help
+ Set the amount of EFI RAM which is claimed by U-Boot for its own
+ use. U-Boot allocates this from EFI on start-up (along with a few
+ other smaller amounts) and it can never be increased after that.
+ It is used as the RAM size in with U-Boot.
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 03/35] efi: Drop the OF_EMBED warning for EFI

2021-10-25 Thread Simon Glass
For the EFI app, we must embed the devicetree in the ELF file since that
is the only thing that is run by UEFI. Drop the warning to avoid
confusion.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add new patch to drop the OF_EMBED warning for EFI

 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 5194e4dc782..fd2b328e021 100644
--- a/Makefile
+++ b/Makefile
@@ -1091,7 +1091,7 @@ endif
 ifeq ($(CONFIG_DEPRECATED),y)
$(warning "You have deprecated configuration options enabled in your 
.config! Please check your configuration.")
 endif
-ifeq ($(CONFIG_OF_EMBED),y)
+ifeq ($(CONFIG_OF_EMBED)$(CONFIG_EFI_APP),y)
@echo >&2 "= WARNING =="
@echo >&2 "CONFIG_OF_EMBED is enabled. This option should only"
@echo >&2 "be used for debugging purposes. Please use"
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 05/35] efi: Create a 64-bit app

2021-10-25 Thread Simon Glass
Most modern platforms use 64-bit EFI so it is useful to have a U-Boot app
that runs under that. Add a (non-functional) build for this.

Note that --whole-archive causes the gcc 9.2 linker to crash, so disable
this for now. Once this is resolved, things should work.

For now, avoid mentioning the documentation for the 64-bit app, since it
does not work.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Default to 256MB of RAM for U-Boot instead of 32MB

Changes in v2:
- Add MAINTAINERS entry
- Add a work-around to avoid a toolchain crash

 MAINTAINERS   |  3 ++
 Makefile  |  8 +++-
 arch/x86/cpu/u-boot-64.lds|  2 +
 arch/x86/cpu/x86_64/Makefile  |  4 ++
 arch/x86/cpu/x86_64/cpu.c | 17 
 arch/x86/cpu/x86_64/misc.c| 25 
 board/efi/Kconfig | 15 ++-
 board/efi/efi-x86_app/Kconfig |  2 +-
 board/efi/efi-x86_app/MAINTAINERS | 11 +-
 ..._app_defconfig => efi-x86_app32_defconfig} |  2 +-
 configs/efi-x86_app64_defconfig   | 39 +++
 doc/develop/uefi/u-boot_on_efi.rst|  6 +--
 12 files changed, 106 insertions(+), 28 deletions(-)
 create mode 100644 arch/x86/cpu/x86_64/misc.c
 rename configs/{efi-x86_app_defconfig => efi-x86_app32_defconfig} (97%)
 create mode 100644 configs/efi-x86_app64_defconfig

diff --git a/MAINTAINERS b/MAINTAINERS
index a46ef70d3cd..ca015e3f3e3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -698,6 +698,9 @@ M:  Simon Glass 
 M: Heinrich Schuchardt 
 S: Maintained
 W: https://u-boot.readthedocs.io/en/latest/develop/uefi/u-boot_on_efi.html
+F: board/efi/efi-x86_app
+F: configs/efi-x86_app*
+F: doc/develop/uefi/u-boot_on_efi.rst
 F: lib/efi/efi_app.c
 F: scripts/build-efi.sh
 
diff --git a/Makefile b/Makefile
index fd2b328e021..1f043c380a5 100644
--- a/Makefile
+++ b/Makefile
@@ -1753,12 +1753,16 @@ quiet_cmd_u-boot__ ?= LTO $@
-Wl,-Map,u-boot.map;
\
$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
 else
+# Note: Linking efi-x86_app64 causes a segfault in the linker at present
+# when using x86_64-linux-gnu-ld.bfd
+# For now, disable --whole-archive which makes things link, although not
+# correctly
 quiet_cmd_u-boot__ ?= LD  $@
   cmd_u-boot__ ?= $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_u-boot) -o $@  
\
-T u-boot.lds $(u-boot-init)
\
-   --whole-archive 
\
+   $(if $(CONFIG_EFI_APP_64BIT),,--whole-archive)  
\
$(u-boot-main)  
\
-   --no-whole-archive  
\
+   $(if $(CONFIG_EFI_APP_64BIT),,--no-whole-archive)   
\
$(PLATFORM_LIBS) -Map u-boot.map;   
\
$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
 endif
diff --git a/arch/x86/cpu/u-boot-64.lds b/arch/x86/cpu/u-boot-64.lds
index ee0812aefbc..92a30c2a387 100644
--- a/arch/x86/cpu/u-boot-64.lds
+++ b/arch/x86/cpu/u-boot-64.lds
@@ -15,7 +15,9 @@ SECTIONS
/DISCARD/ : { *(.u_boot_list_2_cmd_*) }
 #endif
 
+#ifdef CONFIG_SYS_TEXT_BASE
. = CONFIG_SYS_TEXT_BASE;   /* Location of bootcode in flash */
+#endif
__text_start = .;
 
.text.start : { *(.text.start); }
diff --git a/arch/x86/cpu/x86_64/Makefile b/arch/x86/cpu/x86_64/Makefile
index 400f0ffe397..e929563b2c1 100644
--- a/arch/x86/cpu/x86_64/Makefile
+++ b/arch/x86/cpu/x86_64/Makefile
@@ -4,3 +4,7 @@
 #
 
 obj-y += cpu.o interrupts.o setjmp.o
+
+ifndef CONFIG_EFI
+obj-y += misc.o
+endif
diff --git a/arch/x86/cpu/x86_64/cpu.c b/arch/x86/cpu/x86_64/cpu.c
index 90a766c3c57..8f72c9951a1 100644
--- a/arch/x86/cpu/x86_64/cpu.c
+++ b/arch/x86/cpu/x86_64/cpu.c
@@ -49,23 +49,6 @@ int x86_mp_init(void)
return 0;
 }
 
-int misc_init_r(void)
-{
-   return 0;
-}
-
-#ifndef CONFIG_SYS_COREBOOT
-int checkcpu(void)
-{
-   return 0;
-}
-
-int print_cpuinfo(void)
-{
-   return 0;
-}
-#endif
-
 int x86_cpu_reinit_f(void)
 {
return 0;
diff --git a/arch/x86/cpu/x86_64/misc.c b/arch/x86/cpu/x86_64/misc.c
new file mode 100644
index 000..02587ff0c50
--- /dev/null
+++ b/arch/x86/cpu/x86_64/misc.c
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2016 Google, Inc
+ * Written by Simon Glass 
+ */
+
+#include 
+#include 
+
+int misc_init_r(void)
+{
+   return 0;
+}
+
+#ifndef CONFIG_SYS_COREBOOT
+int checkcpu(void)
+{
+   return 0;
+}
+
+int print_cpuinfo(void)
+{
+   return 0;
+}
+#endif
diff --git a/board/efi/Kconfig b/board/efi/Kconfig
index 291bd2ca154..3df6e31c8ba 

[PATCH v3 01/35] efi: Add a script for building and testing U-Boot on UEFI

2021-10-25 Thread Simon Glass
It is quite complicated to run U-Boot on QEMU since we have four
different builds and they must use different versions of qemu and the
UEFI binaries.

Add a script to help.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Fix 'complicating' typo
- s/qemu/QEMU/

Changes in v2:
- Add MAINTAINERS entry
- Add support for creating a partition table with a filesystem inside
- Add support for running qemu with just a serial console (no display)

 MAINTAINERS|   1 +
 doc/develop/uefi/u-boot_on_efi.rst |  62 +
 scripts/build-efi.sh   | 193 +
 3 files changed, 256 insertions(+)
 create mode 100755 scripts/build-efi.sh

diff --git a/MAINTAINERS b/MAINTAINERS
index 5069f188065..a46ef70d3cd 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -699,6 +699,7 @@ M:  Heinrich Schuchardt 
 S: Maintained
 W: https://u-boot.readthedocs.io/en/latest/develop/uefi/u-boot_on_efi.html
 F: lib/efi/efi_app.c
+F: scripts/build-efi.sh
 
 EFI PAYLOAD
 M: Heinrich Schuchardt 
diff --git a/doc/develop/uefi/u-boot_on_efi.rst 
b/doc/develop/uefi/u-boot_on_efi.rst
index c9a41bc919f..4b2a733076d 100644
--- a/doc/develop/uefi/u-boot_on_efi.rst
+++ b/doc/develop/uefi/u-boot_on_efi.rst
@@ -96,6 +96,11 @@ that EFI does not support booting a 64-bit application from 
a 32-bit
 EFI (or vice versa). Also it will often fail to print an error message if
 you get this wrong.
 
+You may find the script `scripts/build-efi.sh` helpful for building and testing
+U-Boot on UEFI on QEMU. It also includes links to UEFI binaries dating from
+2021.
+
+See `Example run`_ for an example run.
 
 Inner workings
 --
@@ -191,6 +196,63 @@ of code is built this way (see the extra- line in 
lib/efi/Makefile).
 Everything else is built as a normal U-Boot, so is always 32-bit on x86 at
 present.
 
+Example run
+---
+
+This shows running with serial enabled (see `include/configs/efi-x86_app.h`)::
+
+   $ scripts/build-efi.sh -wsPr
+   Packaging efi-x86_app32
+   Running qemu-system-i386
+
+   BdsDxe: failed to load Boot0001 "UEFI QEMU HARDDISK QM5 " from 
PciRoot(0x0)/Pci(0x3,0x0)/Sata(0x0,0x,0x0): Not Found
+   BdsDxe: loading Boot0002 "EFI Internal Shell" from 
Fv(7CB8BDC9-F8EB-4F34-AAEA-3EE4AF6516A1)/FvFile(7C04A583-9E3E-4F1C-AD65-E05268D0B4D1)
+   BdsDxe: starting Boot0002 "EFI Internal Shell" from 
Fv(7CB8BDC9-F8EB-4F34-AAEA-3EE4AF6516A1)/FvFile(7C04A583-9E3E-4F1C-AD65-E05268D0B4D1)
+
+   UEFI Interactive Shell v2.2
+   EDK II
+   UEFI v2.70 (EDK II, 0x0001)
+   Mapping table
+ FS0: Alias(s):HD0a65535a1:;BLK1:
+ 
PciRoot(0x0)/Pci(0x3,0x0)/Sata(0x0,0x,0x0)/HD(1,GPT,0FFD5E61-3B0C-4326-8049-BDCDC910AF72,0x800,0xB000)
+BLK0: Alias(s):
+ PciRoot(0x0)/Pci(0x3,0x0)/Sata(0x0,0x,0x0)
+
+   Press ESC in 5 seconds to skip startup.nsh or any other key to continue.
+   Shell> fs0:u-boot-app.efi
+   U-Boot EFI App (using allocated RAM address 47d4000) key=8d4, image=06a6f610
+   starting
+
+
+   U-Boot 2022.01-rc4 (Sep 19 2021 - 14:03:20 -0600)
+
+   CPU: x86, vendor Intel, device 663h
+   DRAM:  32 MiB
+0: efi_media_0  PciRoot(0x0)/Pci(0x3,0x0)/Sata(0x0,0x,0x0)
+1:   
PciRoot(0x0)/Pci(0x3,0x0)/Sata(0x0,0x,0x0)/HD(1,GPT,0FFD5E61-3B0C-4326-8049-BDCDC910AF72,0x800,0xB000)
+   Loading Environment from nowhere... OK
+   Model: EFI x86 Application
+   Hit any key to stop autoboot:  0
+
+   Partition Map for EFI device 0  --   Partition Type: EFI
+
+   PartStart LBA   End LBAName
+   Attributes
+   Type GUID
+   Partition GUID
+ 1 0x0800  0xb7ff  "boot"
+   attrs:  0x
+   type:   ebd0a0a2-b9e5-4433-87c0-68b6b72699c7
+   guid:   0ffd5e61-3b0c-4326-8049-bdcdc910af72
+  19   startup.nsh
+  528384   u-boot-app.efi
+   10181   NvVars
+
+   3 file(s), 0 dir(s)
+
+   => QEMU: Terminated
+
+
 Future work
 ---
 This work could be extended in a number of ways:
diff --git a/scripts/build-efi.sh b/scripts/build-efi.sh
new file mode 100755
index 000..ce761840097
--- /dev/null
+++ b/scripts/build-efi.sh
@@ -0,0 +1,193 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Script to build an EFI thing suitable for booting with QEMU, possibly running
+# it also.
+
+# This just an example. It assumes that
+
+# - you build U-Boot in ${ubdir}/ where  is the U-Boot board config
+# - /mnt/x is a directory used for mounting
+# - you have access to the 'pure UEFI' builds for QEMU
+#
+# UEFI binaries for QEMU used for testing this script:
+#
+# OVMF-pure-efi.i386.fd at
+# 
https://drive.google.com/file/d/1jWzOAZfQqMmS2_dAK2G518GhIgj9r2RY/view?usp=sharing
+
+# OVMF-pure-efi.x64.fd at
+# 
https://drive.google.com/file/d/1c39YI9QtpByGQ4V0UNNQtGqttEzS-eFV/view?usp=sharing
+
+set -e
+
+usage() {
+   echo "Usage: $0 [-a | -p] [other opts]" 1>&2
+   echo 1>&2
+   echo "   -a   - 

[PATCH v3 02/35] efi: Enable DM_ETH for the app

2021-10-25 Thread Simon Glass
There is no need to avoid driver model for networking. Drop this.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add new patch to enable DM_ETH for the app

 configs/efi-x86_app_defconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/configs/efi-x86_app_defconfig b/configs/efi-x86_app_defconfig
index e9ee66250cf..3f7c9ba9008 100644
--- a/configs/efi-x86_app_defconfig
+++ b/configs/efi-x86_app_defconfig
@@ -32,7 +32,6 @@ CONFIG_ENV_OVERWRITE=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_REGMAP=y
 CONFIG_SYSCON=y
-# CONFIG_DM_ETH is not set
 # CONFIG_REGEX is not set
 # CONFIG_GZIP is not set
 CONFIG_EFI=y
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v3 00/35] efi: Improvements to U-Boot running on top of UEFI

2021-10-25 Thread Simon Glass
At present U-Boot can be built as an EFI app, but it is really just for
testing, with very few features. Instead, the payload build is used for
booting on top of UEFI, where U-Boot takes over the machine immediately
and supplies its own drivers.

But the app could be made more useful.

This series provides access to EFI block devices and the video console
within U-Boot. It also restructures the app to make it possible to boot
a kernel, although further work is needed to implement this.

This can be thought of as making U-Boot perform a little like 'grub', in
that it runs purely based on UEFI-provided services.

Of course a lot more work is required, but this is a start.

Note: It would be very useful to include qemu tests of the app and stub
in CI.

This is available at u-boot-dm/efi-working

Changes in v3:
- Add new patch to show the system-table revision
- Default to 256MB of RAM for U-Boot instead of 32MB
- Drop comments that confuse sphinx
- Fix 'complicating' typo
- Move device_path path change to its own patch
- Update minimum RAM to 256MB!
- s/qemu/QEMU/

Changes in v2:
- Add MAINTAINERS entry
- Add a better boot command too
- Add a note that EFI_GRAPHICS_OUTPUT_PROTOCOL is used
- Add a sentence about what the patch does
- Add a work-around to avoid a toolchain crash
- Add new patch to drop the OF_EMBED warning for EFI
- Add new patch to enable DM_ETH for the app
- Add new patch to support the efi command in the app
- Add support for creating a partition table with a filesystem inside
- Add support for running qemu with just a serial console (no display)
- Drop mention of partitions from the commit message
- Expand the commit message to make things clearer
- Fix 'as' typo
- Show the correct interface type with 'part list'
- Update documentation
- Update the commit message to explain things better
- Use log_info() instead of printf()

Simon Glass (35):
  efi: Add a script for building and testing U-Boot on UEFI
  efi: Enable DM_ETH for the app
  efi: Drop the OF_EMBED warning for EFI
  x86: Create a 32/64-bit selection for the app
  efi: Create a 64-bit app
  x86: Don't duplicate global_ptr in 64-bit EFI app
  efi: Add a way to obtain boot services in the app
  efi: Add video support to the app
  efi: Add EFI uclass for media
  efi: Add a media/block driver for EFI block devices
  efi: Locate all block devices in the app
  patman: Use a ValueError exception if tools.Run() fails
  binman: Report an error if test files fail to compile
  binman: Support reading the offset of an ELF-file symbol
  binman: Allow timeout to occur in the image or its section
  binman: Tidy up comments on _DoTestFile()
  binman: Support updating the dtb in an ELF file
  efi: serial: Support arrow keys
  bloblist: Support allocating the bloblist
  x86: Allow booting a kernel from the EFI app
  x86: Don't process the kernel command line unless enabled
  x86: efi: Add room for the binman definition in the dtb
  efi: Drop device_path from struct efi_priv
  efi: Add comments to struct efi_priv
  efi: Fix ll_boot_init() operation with the app
  efi: Add a few comments to the stub
  efi: Share struct efi_priv between the app and stub code
  efi: Move exit_boot_services into a function
  efi: Check for failure when initing the app
  efi: Mention that efi_info_get() is only used in the stub
  efi: Show when allocated pages are used
  efi: Allow easy selection of serial-only operation
  efi: Update efi_get_next_mem_desc() to avoid needing a map
  efi: Support the efi command in the app
  efi: Show the system-table revision

 MAINTAINERS   |   7 +
 Makefile  |  10 +-
 arch/sandbox/dts/test.dts |   4 +
 arch/x86/cpu/efi/payload.c|  17 +-
 arch/x86/cpu/intel_common/Makefile|   2 +-
 arch/x86/cpu/u-boot-64.lds|   2 +
 arch/x86/cpu/x86_64/Makefile  |   4 +
 arch/x86/cpu/x86_64/cpu.c |  32 +-
 arch/x86/cpu/x86_64/misc.c|  41 +++
 arch/x86/dts/Makefile |   2 +-
 arch/x86/dts/efi-x86_app.dts  |   4 +
 arch/x86/lib/bootm.c  |  11 +-
 arch/x86/lib/zimage.c |  13 +-
 board/efi/Kconfig |  15 +-
 board/efi/efi-x86_app/Kconfig |   6 +-
 board/efi/efi-x86_app/MAINTAINERS |  11 +-
 cmd/Makefile  |   2 +-
 cmd/efi.c |  78 +++--
 common/Kconfig|  15 +-
 common/bloblist.c |  16 +-
 common/board_f.c  |   8 +-
 ..._app_defconfig => efi-x86_app32_defconfig} |   3 +-
 configs/efi-x86_app64_defconfig   |  39 +++
 disk/part.c   |   5 +-
 doc/develop/bloblist.rst  |  16 +
 doc/develop/uefi/u-boot_on_efi.rst 

Re: [PATCH v2 05/39] x86: Show some EFI info with the bdinfo command

2021-10-25 Thread Simon Glass
Hi Heinrich,

On Mon, 18 Oct 2021 at 11:15, Heinrich Schuchardt  wrote:
>
> On 9/25/21 2:30 AM, Simon Glass wrote:
> > It is useful to see some basic EFI info with the command as it forms part
> > of the information about a board.
> >
> > Add a hook for this and show the table address as a start.
> >
> > While here, fix an invalid cast in setup_efi_info(). Note that this
> > function is using a data structure defined by Linux so we cannot change
> > it. Also note that ulong is used since this is the standard in U-Boot
> > (>6k uses), despite there being quite a bit of the more verbose uintptr_t
> > (930 uses).
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> > Changes in v2:
> > - Update commit message to mention why the data structure is like it is
> > - Update commit message to mention why ulong is used
> >
> >   arch/x86/cpu/efi/payload.c | 13 +++--
> >   arch/x86/include/asm/efi.h |  7 +++
> >   arch/x86/lib/Makefile  |  1 +
> >   arch/x86/lib/bdinfo.c  | 22 ++
> >   4 files changed, 41 insertions(+), 2 deletions(-)
> >   create mode 100644 arch/x86/lib/bdinfo.c
> >
> > diff --git a/arch/x86/cpu/efi/payload.c b/arch/x86/cpu/efi/payload.c
> > index 9a73b768e9b..3a9f7d72868 100644
> > --- a/arch/x86/cpu/efi/payload.c
> > +++ b/arch/x86/cpu/efi/payload.c
> > @@ -280,15 +280,24 @@ void setup_efi_info(struct efi_info *efi_info)
> >   }
> >   efi_info->efi_memdesc_size = map->desc_size;
> >   efi_info->efi_memdesc_version = map->version;
> > - efi_info->efi_memmap = (u32)(map->desc);
> > + efi_info->efi_memmap = (ulong)(map->desc);
> >   efi_info->efi_memmap_size = size - sizeof(struct efi_entry_memmap);
> >
> >   #ifdef CONFIG_EFI_STUB_64BIT
> >   efi_info->efi_systab_hi = table->sys_table >> 32;
> > - efi_info->efi_memmap_hi = (u64)(u32)(map->desc) >> 32;
> > + efi_info->efi_memmap_hi = (u64)(ulong)map->desc >> 32;
> >   signature = EFI64_LOADER_SIGNATURE;
> >   #else
> >   signature = EFI32_LOADER_SIGNATURE;
> >   #endif
> >   memcpy(_info->efi_loader_signature, signature, 4);
> >   }
> > +
> > +void efi_show_bdinfo(void)
> > +{
> > + struct efi_entry_systable *table = NULL;
> > + int size, ret;
> > +
> > + ret = efi_info_get(EFIET_SYS_TABLE, (void **), );
> > + bdinfo_print_num_l("efi_table", (ulong)table);
>
> Some properties of the UEFI API depend on the UEFI API version
> (EFI_SYSTEM_TABLE.FirmwareRevision)

OK I will add a patch.

>
> The revision of the EFI_FILE_PROTOCOL may also be relevant for U-Boot.
>
> Maybe you want to add this information in a later patch.

This is tricky because the protocol version is no-longer available
once the payload has loaded.

[..]

Regards,
Simon


Re: [PATCH 6/6] scripts: remove CONFIG_IS_ENABLED in config_whitelist.txt

2021-10-25 Thread Simon Glass
Hi Patrick,

On Fri, 22 Oct 2021 at 11:13, Patrick DELAUNAY
 wrote:
>
> Hi Simon
>
> On 10/14/21 5:09 PM, Simon Glass wrote:
> > Hi Patrick,
> >
> > On Mon, 4 Oct 2021 at 04:00, Patrick Delaunay
> >  wrote:
> >> Redefine the macro CONFIG_IS_ENABLED is not allowed,
> >> so this entry can be removed in whitelist file.
> >>
> >> Signed-off-by: Patrick Delaunay 
> >> ---
> >>
> >>   scripts/config_whitelist.txt | 1 -
> >>   1 file changed, 1 deletion(-)
> >>
> >> diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt
> >> index b3ebd20c57..41a0952c97 100644
> >> --- a/scripts/config_whitelist.txt
> >> +++ b/scripts/config_whitelist.txt
> >> @@ -649,7 +649,6 @@ CONFIG_IRAM_SIZE
> >>   CONFIG_IRAM_STACK
> >>   CONFIG_IRAM_TOP
> >>   CONFIG_IRDA_BASE
> >> -CONFIG_IS_ENABLED
> >>   CONFIG_JFFS2_DEV
> >>   CONFIG_JFFS2_LZO
> >>   CONFIG_JFFS2_NAND
> >> --
> >> 2.25.1
> >>
> > For this to work you need to actually remove it from the source tree
> > (which we can't), otherwise you get:
> >
> > Error: You must add new CONFIG options using Kconfig
> > The following new ad-hoc CONFIG options were detected:
> > CONFIG_IS_ENABLED
> >
> > I don't think this is worth it though, so I suggest dropping this patch.
> >
> > Regards,
> > Simon
>
>
> Yes ! sorry
>
> CONFIG_IS_ENABLED is present in u-boot.cfg,
>
> as CONFIG_VAL
>
>
> even if it is strange for these macro defined in "linux/kconfig.h"
>
> but agree to drop this tentative.
>
>
> Do you think I can remove the CONFIG_IS_ENABLED and CONFIG_VAL
>
> in u-boot.cfg when the file is generated ?

If you like.

Regards,
Simon


Re: [PATCH v2 15/39] efi: Add EFI uclass for media

2021-10-25 Thread Simon Glass
Hi Heinrich,

On Sat, 23 Oct 2021 at 06:31, Heinrich Schuchardt  wrote:
>
>
>
> On 9/25/21 02:30, Simon Glass wrote:
> > At present UCLASS_EFI is used to represent an EFI filesystem among other
>
> UCLASS_EFI is for UEFI drivers that provide the driver binding protocol.
>
> Your new UCLASS seems to be for U-Boot drivers consuming the
> EFI_BLOCK_IO_PROTOCOL.
>
> I agree that lib/efi_driver/efi_block_device.c is to much intertwined
> with the UEFI subsystem to easily merge it with your requirement. But it
> at least can serve as a template.

It did.

>
> > things. The description of this uclass is "EFI managed devices" which is
> > pretty vague. The only driver that uses this uclass is in fact not a real
> > U-Boot driver, since its operations do not include a struct udevice.
> >
> > Rather than mess with this, create a new UCLASS_EFI_MEDIA uclass to handle
> > EFI media such as disks. Make this the uclass to use for EFI media so that
>
> In UEFI speak MEDIA relates to:
>
> * block devices
> * firmware files
> * Bluetooth
> * REST services
> * etc
>
> Do you only mean block devices?

Sort of...it is a parent of a block device, like MMC or SCSI.

> Why can't you use UCLASS_BLK for your new driver?

That is the child. I need something to be the parent so that it actually works.

Regards,
Simon


Re: [PATCH v2 24/39] efi: serial: Support arrow keys

2021-10-25 Thread Simon Glass
Hi Heinrich,

On Mon, 18 Oct 2021 at 11:00, Heinrich Schuchardt  wrote:
>
> On 9/25/21 2:30 AM, Simon Glass wrote:
> > At present only the backspace key is supported in U-Boot, when running as
> > an EFI app. Add support for arrows, home and end as well, to make the CLI
> > more friendly.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> > (no changes since v1)
> >
> >   drivers/serial/serial_efi.c | 11 +--
> >   1 file changed, 9 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/serial/serial_efi.c b/drivers/serial/serial_efi.c
> > index 33ddbd6080c..0067576389d 100644
> > --- a/drivers/serial/serial_efi.c
> > +++ b/drivers/serial/serial_efi.c
> > @@ -24,6 +24,9 @@ struct serial_efi_priv {
> >   bool have_key;
> >   };
> >
> > +/* Convert a lower-case character to its ctrl-char equivalent */
> > +#define CTL_CH(c)((c) - 'a' + 1)
> > +
> >   int serial_efi_setbrg(struct udevice *dev, int baudrate)
> >   {
> >   return 0;
> > @@ -49,6 +52,7 @@ static int serial_efi_get_key(struct serial_efi_priv 
> > *priv)
> >   static int serial_efi_getc(struct udevice *dev)
> >   {
> >   struct serial_efi_priv *priv = dev_get_priv(dev);
> > + char conv_scan[10] = {0, 'p', 'n', 'f', 'b', 'a', 'e', 0, 8};
> >   int ret, ch;
> >
> >   ret = serial_efi_get_key(priv);
> > @@ -63,8 +67,11 @@ static int serial_efi_getc(struct udevice *dev)
> >* key scan code of 8. Handle this so that backspace works correctly
> >* in the U-Boot command line.
> >*/
> > - if (!ch && priv->key.scan_code == 8)
> > - ch = 8;
> > + if (!ch && priv->key.scan_code < sizeof(conv_scan))
> > + ch = conv_scan[priv->key.scan_code];
> > + if (ch >= 'a')
> > + ch -= 'a' - 1;
>
> All 23 EFI Scan Codes should be supported. Can't we use something like
> kbd_to_ansi364[] from drivers/input/input.c to create the appropriate
> escape sequences?

I think you are referring to this:

Table 107. EFI Scan Codes for EFI_SIMPLE_TEXT_INPUT_PROTOCOL
EFI Scan Code Description
0x00 Null scan code.
0x01 Move cursor up 1 row.
0x02 Move cursor down 1 row.
0x03 Move cursor right 1 column.
0x04 Move cursor left 1 column.
0x05 Home.
0x06 End.
0x07 Insert.
0x08 Delete.
0x09 Page Up.
0x0a Page Down.
0x0b Function 1.
0x0c Function 2.
0x0d Function 3.
0x0e Function 4.
0x0f Function 5.
0x10 Function 6.
0x11 Function 7.
0x12 Function 8.
0x13 Function 9.
0x14 Function 10.

Which ones (other than what I have added) do you think U-Boot
supports? I cannot find any.

Regards,
Simon


Re: [PATCH v2 09/39] efi: Drop the OF_EMBED warning for EFI

2021-10-25 Thread Simon Glass
Hi Heinrich,

On Sat, 23 Oct 2021 at 05:42, Heinrich Schuchardt  wrote:
>
>
>
> On 9/25/21 02:30, Simon Glass wrote:
> > For the EFI app, we must embed the devicetree in the ELF file since that
> > is the only thing that is run by UEFI. Drop the warning to avoid
> > confusion.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> > Changes in v2:
> > - Add new patch to drop the OF_EMBED warning for EFI
> >
> >   Makefile | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/Makefile b/Makefile
> > index a09f48f84b2..784efd4ef6e 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -1087,7 +1087,7 @@ endif
> >   ifeq ($(CONFIG_DEPRECATED),y)
> >   $(warning "You have deprecated configuration options enabled in your 
> > .config! Please check your configuration.")
> >   endif
> > -ifeq ($(CONFIG_OF_EMBED),y)
> > +ifeq ($(CONFIG_OF_EMBED)$(CONFIG_EFI_APP),y)
> >   @echo >&2 "= WARNING =="
> >   @echo >&2 "CONFIG_OF_EMBED is enabled. This option should only"
> >   @echo >&2 "be used for debugging purposes. Please use"
>
> There are 47 defconfigs and 5 include/configs/*.h using CONFIG_OF_EMBED.
> doc/board/intel/slimbootloader.rst and doc/board/coreboot/coreboot.rst
> require to use it for building U-Boot.
>
> Is there a migration requirement and plan?

Actually people were never supposed to use it.

I sent a series today which cleans this up quite a bit, so that I
think many of the boards using OF_EMBED can drop it. TBD though.

Regards,
Simon


Re: [PATCH v2 07/39] efi: Add a script for building and testing U-Boot on UEFI

2021-10-25 Thread Simon Glass
Hi Heinrich,

On Mon, 25 Oct 2021 at 13:40, Heinrich Schuchardt  wrote:
>
>
>
> On 9/25/21 02:30, Simon Glass wrote:
> > It is quite complicating to run U-Boot on qemu since we have four
> > different builds and they must use different versions of qemu and the
> > UEFI binaries.
> >
> > Add a script to help.
> >
> > Signed-off-by: Simon Glass 
>
> This patch seems not to work:
>
> $ scripts/build-efi.sh -wsPr
> Packaging efi-x86_app32
> cp: cannot stat '/tmp/b/efi-x86_app32/u-boot-app.efi': No such file or
> director
>
> The scripts lacks a step to build the EFI binary.
>
> If you expect the user to build it, you will find it in the current
> directory and not in some arbitrary subdirectory of /tmp.

Did you read the top of the script? It does not do the build, just the
package/run bit
>
> Temporary directories should be created with 'mktemp -d'. Using fixed
> paths (e.g. /tmp/b/) may lead to conflicts.

I'll make it a variable in v3. But we cannot use mktemp-d as the build
needs to stay around for multiple runs of this script.

Regards,
Simon


Re: [PATCH v2 06/39] x86: Tidy up global_data pointer for 64-bit

2021-10-25 Thread Simon Glass
Hi Heinrich,

On Mon, 18 Oct 2021 at 11:15, Heinrich Schuchardt  wrote:
>
> On 9/25/21 2:30 AM, Simon Glass wrote:
> > Add an extern declaration so that it is possible to use this macro in
> > files other than the one that defines it.
> >
> > Signed-off-by: Simon Glass 
> > Reviewed-by: Heinrich Schuchardt 
> > ---
> >
> > (no changes since v1)
> >
> >   arch/x86/cpu/x86_64/cpu.c  | 3 +++
> >   arch/x86/include/asm/global_data.h | 2 ++
> >   2 files changed, 5 insertions(+)
> >
> > diff --git a/arch/x86/cpu/x86_64/cpu.c b/arch/x86/cpu/x86_64/cpu.c
> > index 90a766c3c57..e090b1b478a 100644
> > --- a/arch/x86/cpu/x86_64/cpu.c
> > +++ b/arch/x86/cpu/x86_64/cpu.c
> > @@ -8,6 +8,9 @@
> >   #include 
> >   #include 
> >   #include 
> > +#include 
> > +
> > +DECLARE_GLOBAL_DATA_PTR;
> >
> >   /*
> >* Global declaration of gd.
> > diff --git a/arch/x86/include/asm/global_data.h 
> > b/arch/x86/include/asm/global_data.h
> > index 3e4044593c8..f95fb5a1931 100644
> > --- a/arch/x86/include/asm/global_data.h
> > +++ b/arch/x86/include/asm/global_data.h
> > @@ -133,6 +133,8 @@ struct arch_global_data {
> >   #ifndef __ASSEMBLY__
> >   # if defined(CONFIG_EFI_APP) || CONFIG_IS_ENABLED(X86_64)
> >
> > +extern struct global_data *global_data_ptr;
>
> You already have:
> arch/x86/include/asm/global_data.h:139:
> #define DECLARE_GLOBAL_DATA_PTR   extern struct global_data *global_data_ptr
>
> Why don't you use DECLARE_GLOBAL_DATA_PTR where needed?

I have no idea what I was thinking or how I got into this state. But
anyway, I don't think we need this patch. Thanks for catching it.

Regards,
Simon


[PATCH v3 3/3] rockchip: rk3568: add arch_cpu_init()

2021-10-25 Thread Nico Cheng
We configured the drive strength and security of EMMC in
arch_cpu_init().

Signed-off-by: Nico Cheng 
---

Changes in v3:
Replace configuration parameters of SGRF_SOC_CON4 with macro
definitions.

Changes in v2:
We use the rk_clrreg function instead of the writel to set eMMC sdmmc0 to
secure.
Modify comments to make them more explicit.

 arch/arm/mach-rockchip/rk3568/rk3568.c | 27 +++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-rockchip/rk3568/rk3568.c 
b/arch/arm/mach-rockchip/rk3568/rk3568.c
index 973b4f9dcb..22eeb77d41 100644
--- a/arch/arm/mach-rockchip/rk3568/rk3568.c
+++ b/arch/arm/mach-rockchip/rk3568/rk3568.c
@@ -11,9 +11,18 @@
 #include 
 #include 
 
-#define PMUGRF_BASE0xfdc2
-#define GRF_BASE   0xfdc6
-
+#define PMUGRF_BASE0xfdc2
+#define GRF_BASE   0xfdc6
+#define GRF_GPIO1B_DS_20x218
+#define GRF_GPIO1B_DS_30x21c
+#define GRF_GPIO1C_DS_00x220
+#define GRF_GPIO1C_DS_10x224
+#define GRF_GPIO1C_DS_20x228
+#define GRF_GPIO1C_DS_30x22c
+#define SGRF_BASE  0xFDD18000
+#define SGRF_SOC_CON4  0x10
+#define EMMC_HPROT_SECURE_CTRL 0x03
+#define SDMMC0_HPROT_SECURE_CTRL   0x01
 /* PMU_GRF_GPIO0D_IOMUX_L */
 enum {
GPIO0D1_SHIFT   = 4,
@@ -81,5 +90,17 @@ void board_debug_uart_init(void)
 
 int arch_cpu_init(void)
 {
+#ifdef CONFIG_SPL_BUILD
+   /* Set the emmc sdmmc0 to secure */
+   rk_clrreg(SGRF_BASE + SGRF_SOC_CON4, (EMMC_HPROT_SECURE_CTRL << 11
+   | SDMMC0_HPROT_SECURE_CTRL << 4));
+   /* set the emmc driver strength to level 2 */
+   writel(0x3f3f0707, GRF_BASE + GRF_GPIO1B_DS_2);
+   writel(0x3f3f0707, GRF_BASE + GRF_GPIO1B_DS_3);
+   writel(0x3f3f0707, GRF_BASE + GRF_GPIO1C_DS_0);
+   writel(0x3f3f0707, GRF_BASE + GRF_GPIO1C_DS_1);
+   writel(0x3f3f0707, GRF_BASE + GRF_GPIO1C_DS_2);
+   writel(0x3f3f0707, GRF_BASE + GRF_GPIO1C_DS_3);
+#endif
return 0;
 }
-- 
2.17.1





[PATCH v3 2/3] arm: dts: rockchip: rk3568: Enable sdhci and sdmmc0 node

2021-10-25 Thread Nico Cheng
Enable sdhci and sdmmc0 node in rk3568-u-boot.dtsi

Signed-off-by: Nico Cheng 
---

(no changes since v1)

 arch/arm/dts/rk3568-u-boot.dtsi | 17 +
 1 file changed, 17 insertions(+)

diff --git a/arch/arm/dts/rk3568-u-boot.dtsi b/arch/arm/dts/rk3568-u-boot.dtsi
index 1570f13fc7..5a80dda275 100644
--- a/arch/arm/dts/rk3568-u-boot.dtsi
+++ b/arch/arm/dts/rk3568-u-boot.dtsi
@@ -9,6 +9,10 @@
mmc1 = 
};
 
+   chosen {
+   u-boot,spl-boot-order = , 
+   };
+
dmc: dmc {
compatible = "rockchip,rk3568-dmc";
u-boot,dm-pre-reloc;
@@ -35,3 +39,16 @@
u-boot,dm-pre-reloc;
status = "okay";
 };
+
+ {
+   u-boot,dm-spl;
+   status = "okay";
+};
+
+ {
+   bus-width = <8>;
+   u-boot,dm-spl;
+   mmc-hs200-1_8v;
+   status = "okay";
+};
+
-- 
2.17.1





[PATCH v3 1/3] rockchip: Kconfig: Enable SPL support for rk3568

2021-10-25 Thread Nico Cheng
Enable SPL support in Kconfig and add some related option in
rk3568_common.h

Signed-off-by: Nico Cheng 
Signed-off-by: Jason Zhu 
---

(no changes since v1)

 arch/arm/mach-rockchip/Kconfig  |  2 ++
 configs/evb-rk3568_defconfig| 25 -
 include/configs/rk3568_common.h |  4 
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig
index b164afb529..21b9c381cf 100644
--- a/arch/arm/mach-rockchip/Kconfig
+++ b/arch/arm/mach-rockchip/Kconfig
@@ -260,6 +260,8 @@ config ROCKCHIP_RK3399
 config ROCKCHIP_RK3568
bool "Support Rockchip RK3568"
select ARM64
+   select SUPPORT_SPL
+   select SPL
select CLK
select PINCTRL
select RAM
diff --git a/configs/evb-rk3568_defconfig b/configs/evb-rk3568_defconfig
index a102a5a999..a145b71ac2 100644
--- a/configs/evb-rk3568_defconfig
+++ b/configs/evb-rk3568_defconfig
@@ -1,20 +1,42 @@
 CONFIG_ARM=y
 CONFIG_ARCH_ROCKCHIP=y
 CONFIG_SYS_TEXT_BASE=0x00a0
+CONFIG_SPL_LIBCOMMON_SUPPORT=y
+CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_NR_DRAM_BANKS=2
-CONFIG_DEFAULT_DEVICE_TREE="rk3568-evb"
 CONFIG_ROCKCHIP_RK3568=y
+CONFIG_SPL_ROCKCHIP_BACK_TO_BROM=y
+CONFIG_SPL_ROCKCHIP_COMMON_BOARD=y
+CONFIG_SPL_MMC_SUPPORT=y
+CONFIG_SPL_SERIAL_SUPPORT=y
+CONFIG_SPL_DRIVERS_MISC_SUPPORT=y
+CONFIG_SPL_STACK_R_ADDR=0x60
 CONFIG_TARGET_EVB_RK3568=y
 CONFIG_DEBUG_UART_BASE=0xFE66
 CONFIG_DEBUG_UART_CLOCK=2400
+CONFIG_DEFAULT_DEVICE_TREE="rk3568-evb"
 CONFIG_DEBUG_UART=y
+CONFIG_FIT=y
+CONFIG_FIT_VERBOSE=y
+CONFIG_SPL_LOAD_FIT=y
 CONFIG_DEFAULT_FDT_FILE="rockchip/rk3568-evb.dtb"
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
+# CONFIG_SPL_RAW_IMAGE_SUPPORT is not set
+CONFIG_SPL_STACK_R=y
+CONFIG_SPL_SEPARATE_BSS=y
+CONFIG_SPL_CRC32_SUPPORT=y
+CONFIG_SPL_ATF=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_MMC=y
 # CONFIG_CMD_SETEXPR is not set
+# CONFIG_SPL_DOS_PARTITION is not set
+CONFIG_SPL_OF_CONTROL=y
+CONFIG_OF_LIVE=y
 CONFIG_NET_RANDOM_ETHADDR=y
+CONFIG_SPL_REGMAP=y
+CONFIG_SPL_SYSCON=y
+CONFIG_SPL_CLK=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_SYS_I2C_ROCKCHIP=y
 CONFIG_MISC=y
@@ -28,6 +50,7 @@ CONFIG_ETH_DESIGNWARE=y
 CONFIG_GMAC_ROCKCHIP=y
 CONFIG_REGULATOR_PWM=y
 CONFIG_PWM_ROCKCHIP=y
+CONFIG_SPL_RAM=y
 CONFIG_DM_RESET=y
 CONFIG_BAUDRATE=150
 CONFIG_DEBUG_UART_SHIFT=2
diff --git a/include/configs/rk3568_common.h b/include/configs/rk3568_common.h
index b6568917ea..47fc91779e 100644
--- a/include/configs/rk3568_common.h
+++ b/include/configs/rk3568_common.h
@@ -18,6 +18,10 @@
 
 #define CONFIG_SYS_INIT_SP_ADDR0x00c0
 #define CONFIG_SYS_LOAD_ADDR   0x00c00800
+#define CONFIG_SPL_STACK   0x0040
+#define CONFIG_SPL_MAX_SIZE0x2
+#define CONFIG_SPL_BSS_START_ADDR  0x400
+#define CONFIG_SPL_BSS_MAX_SIZE0x4000
 #define CONFIG_SYS_BOOTM_LEN   (64 << 20)  /* 64M */
 
 #define CONFIG_SYS_SDRAM_BASE  0
-- 
2.17.1





[PATCH v3 0/3] Add SPL build support for RK3568

2021-10-25 Thread Nico Cheng


This series adds support for the rk3568 SOC, SPL load next-stage image from
eMMC will be supported after this series of patches.

Changes in v3:
Replace configuration parameters of SGRF_SOC_CON4 with macro
definitions.

Changes in v2:
We use the rk_clrreg function instead of the writel to set eMMC sdmmc0 to
secure.
Modify comments to make them more explicit.

Nico Cheng (3):
  rockchip: Kconfig: Enable SPL support for rk3568
  arm: dts: rockchip: rk3568: Enable sdhci and sdmmc0 node
  rockchip: rk3568: add arch_cpu_init()

 arch/arm/dts/rk3568-u-boot.dtsi| 17 
 arch/arm/mach-rockchip/Kconfig |  2 ++
 arch/arm/mach-rockchip/rk3568/rk3568.c | 27 +++---
 configs/evb-rk3568_defconfig   | 25 +++-
 include/configs/rk3568_common.h|  4 
 5 files changed, 71 insertions(+), 4 deletions(-)

-- 
2.17.1





Re: [PATCH] clk: introduce u-boot,ignore-clk-defaults

2021-10-25 Thread Sean Anderson

On 10/25/21 9:23 PM, Sean Anderson wrote:

On 10/25/21 11:18 AM, Simon Glass wrote:

Hi Sean,

On Sun, 24 Oct 2021 at 18:13, Sean Anderson  wrote:


On 10/14/21 10:19 PM, Simon Glass wrote:

Hi Peng, Sean,

On Thu, 14 Oct 2021 at 19:17, Peng Fan  wrote:



Subject: Re: [PATCH] clk: introduce u-boot,ignore-clk-defaults


On 10/13/21 5:37 AM, Peng Fan (OSS) wrote:

From: Peng Fan 

Current code has a force clk_set_defaults in multiple stages, U-Boot
reuse the same device tree and Linux Kernel device tree, but we not
register all the clks as Linux Kernel, so clk_set_defaults will fail
and cause the clk provider registeration fail.

So introduce a new property to ignore the default settings which could
be used by any node that wanna ignore default settings.

Signed-off-by: Peng Fan 
---
    doc/device-tree-bindings/device.txt | 3 +++
    drivers/clk/clk-uclass.c    | 3 +++
    2 files changed, 6 insertions(+)

diff --git a/doc/device-tree-bindings/device.txt
b/doc/device-tree-bindings/device.txt
index 73ce2a3b5b..fe34ced268 100644
--- a/doc/device-tree-bindings/device.txt
+++ b/doc/device-tree-bindings/device.txt
@@ -28,6 +28,9 @@ the acpi,compatible property.
    Linux will only load the driver if the device can be detected (e.g. on

I2C

    bus). Note that this is an out-of-tree Linux feature.

+Common device bindings that could be shared listed below:
+ - u-boot,ignore-clk-defaults : ignore the assigned-clock-parents
+   and assigned-clock-rates for a device that has the property.

    Example
    ---
diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index
493018b33e..6bf3179e7b 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -376,6 +376,9 @@ int clk_set_defaults(struct udevice *dev, enum

clk_defaults_stage stage)

  if (!dev_has_ofnode(dev))
  return 0;

+   if (ofnode_get_property(dev_ofnode(dev), "u-boot,ignore-clk-defaults",

NULL))

+   return 0;
+
  /*
   * To avoid setting defaults twice, don't set them before relocation.
   * However, still set them for SPL. And still set them if
explicitly



Why not just have the property ignore errors?


I think the force err return was done by Simon?



In the long term, it may be better to standardize that e.g. ENOENT means that
the clock doesn't exist. That way we can skip setting the defaults.
ENOSYS should probably be treated the same way (warn, but don't fail).


I am not sure whether people expect force error for ENOENT/ENOSYS in U-Boot.
For i.MX, I not expect force error.


Yes that is me, indeed. It's just that we should not silently ignore
errors. If we know the clock is optional, then the driver that knows
that can handle it. But if we start having things quietly fail,
debugging becomes a pain.


Can't we have them loudly fail instead?



That is how it works today, as I understand it. But some boards want
the defaults to be there but not to implement them in U-Boot. This
seems fair enough to me. Perhaps we could add something to each node
instead, to disable it?


u-boot,assigned-clock-status = "disabled";


Actually, I think that was Peng's idea in the first place :)

--Sean



Re: [PATCH] introduce CONFIG_DEVICE_TREE_INCLUDES

2021-10-25 Thread Simon Glass
Hi Rasmus,

On Tue, 28 Sept 2021 at 02:57, Rasmus Villemoes
 wrote:
>
> The build system already automatically looks for and includes an
> in-tree *-u-boot.dtsi when building the control .dtb. However, there
> are some things that are awkward to maintain in such an in-tree file,
> most notably the metadata associated to public keys used for verified
> boot.
>
> The only "official" API to get that metadata into the .dtb is via
> mkimage, as a side effect of building an actual signed image. But
> there are multiple problems with that. First of all, the final U-Boot
> (be it U-Boot proper or an SPL) image is built based on a binary
> image, the .dtb, and possibly some other binary artifacts. So
> modifying the .dtb after the build requires the meta-buildsystem
> (Yocto, buildroot, whatnot) to know about and repeat some of the steps
> that are already known to and handled by U-Boot's build system,
> resulting in needless duplication of code. It's also somewhat annoying
> and inconsistent to have a .dtb file in the build folder which is not
> generated by the command listed in the corresponding .cmd file (that
> of course applies to any generated file).
>
> So the contents of the /signature node really needs to be baked into
> the .dtb file when it is first created, which means providing the
> relevant data in the form of a .dtsi file. One could in theory put
> that data into the *-u-boot.dtsi file, but it's more convenient to be
> able to provide it externally: For example, when developing for a
> customer, it's common to use a set of dummy keys for development,
> while the consultants do not (and should not) have access to the
> actual keys used in production. For such a setup, it's easier if the
> keys used are chosen via the meta-buildsystem and the path(s) patched
> in during the configure step. And of course, nothing prevents anybody
> from having DEVICE_TREE_INCLUDES point at files maintained in git, or
> for that matter from including the public key metadata in the
> *-u-boot.dtsi directly and ignore this feature.
>
> There are other uses for this, e.g. in combination with ENV_IMPORT_FDT
> it can be used for providing the contents of the /config/environment
> node, so I don't want to tie this exclusively to use for verified
> boot.
>
> Signed-off-by: Rasmus Villemoes 
> ---
>
> Getting the public key metadata into .dtsi form can be done with a
> little scripting (roughly 'mkimage -K' of a dummy image followed by
> 'dtc -I dtb -O dts'). I have a script that does that, along with
> options to set 'required' and 'required-mode' properties, include
> u-boot,dm-spl properties in case one wants to check U-Boot proper from
> SPL with the verified boot mechanism, etc. I'm happy to share that
> script if this gets accepted, but it's moot if this is rejected.
>
> I have previously tried to get an fdt_add_pubkey tool accepted [1,2]
> to disentangle the kernel and u-boot builds (or u-boot and SPL builds
> for that matter!), but as I've since realized, that isn't quite enough
> - the above points re modifying the .dtb after it is created but
> before that is used to create further build artifacts still
> stand. However, such a tool could still be useful for creating the
> .dtsi info without the private keys being present, and my key2dtsi.sh
> script could easily be modified to use a tool like that should it ever
> appear.
>
> [1] 
> https://lore.kernel.org/u-boot/20200211094818.14219-3-rasmus.villem...@prevas.dk/
> [2] 
> https://lore.kernel.org/u-boot/2184f1e6dd6247e48133c76205fee...@kaspersky.com/
>
>  dts/Kconfig  | 9 +
>  scripts/Makefile.lib | 2 ++
>  2 files changed, 11 insertions(+)

Reviewed-by: Simon Glass 

I suggest adding this to the documentation somewhere in doc/develop/devicetree/

Getting the key into the U-Boot .dtb is normally done with mkimage, as
you say. I don't really understand why this approach is easier.

Also, is there any interest in using binman? It is designed to do the
'packaging' step right at the end, when all the bits are available and
just need to be put together.

I am trying to encourage people to move away from building from source
always, to a two-step process:

- build all the bits
- package them, update devicetree, etc.

https://u-boot.readthedocs.io/en/latest/develop/package/index.html

BTW if Roman can figure out how to send the patches I think that tool
would be useful too.

Regards,
Simon



>
> diff --git a/dts/Kconfig b/dts/Kconfig
> index dabe0080c1..593dddbaf0 100644
> --- a/dts/Kconfig
> +++ b/dts/Kconfig
> @@ -139,6 +139,15 @@ config DEFAULT_DEVICE_TREE
>   It can be overridden from the command line:
>   $ make DEVICE_TREE=
>
> +config DEVICE_TREE_INCLUDES
> +   string "Extra .dtsi files to include when building DT control"
> +   depends on OF_CONTROL
> +   help
> + U-Boot's control .dtb is usually built from an in-tree .dts
> + file, plus (if available) an in-tree U-Boot-specific .dtsi
> + file. 

Re: [PATCH v3 00/18] pxe: Refactoring to tidy up and prepare for bootflow

2021-10-25 Thread Simon Glass
Hi Ramon,

On Thu, 14 Oct 2021 at 12:48, Simon Glass  wrote:
>
> This collects together the patches previously sent relating to PXE.
>
> Firstly, it moves the boot code out of common/ and into a new boot/
> directory. This helps to collect these related files in one place, as
> common/ is quite large.
>
> Secondly, it provides patache so clean up the PXE code and refactor it
> into something closer to a module that can be called, teasing apart its
> reliance on the command-line interpreter to access filesystems and the
> like. Also it now uses function arguments and its own context struct
> internally rather than environment variables, which is very hard to
> follow. No core functional change is intended.
>
> Changes in v3:
> - Rebase to -master
>
> Changes in v2:
> - Rebase to -next
> - Split out from the bootmethod patches
>
> Simon Glass (18):
>   Create a new boot/ directory
>   pxe: Move API comments to the header files
>   pxe: Use a context pointer
>   pxe: Move do_getfile() into the context
>   pxe: Add a userdata field to the context
>   pxe: Tidy up the is_pxe global
>   pxe: Move pxe_utils files
>   pxe: Tidy up some comments in pxe_utils
>   pxe: Tidy up code style a little in pxe_utils
>   pxe: Move common parsing coding into pxe_util
>   pxe: Clean up the use of bootfile
>   pxe: Drop get_bootfile_path()
>   lib: Add tests for simple_itoa()
>   lib: Add a function to convert a string to a hex value
>   pxe: Return the file size from the getfile() function
>   pxe: Refactor sysboot to have one helper
>   doc: Move distro boot doc to rST
>   pxe: Allow calling the pxe_get logic directly
>
>  Kconfig   |   2 +
>  Makefile  |   3 +-
>  README|   1 +
>  common/Kconfig.boot => boot/Kconfig   |   0
>  boot/Makefile |  37 ++
>  {common => boot}/android_ab.c |   0
>  {common => boot}/boot_fit.c   |   0
>  {common => boot}/bootm.c  |   0
>  {common => boot}/bootm_os.c   |   0
>  {common => boot}/bootretry.c  |   0
>  {common => boot}/common_fit.c |   0
>  {common => boot}/fdt_region.c |   0
>  {common => boot}/image-android-dt.c   |   0
>  {common => boot}/image-android.c  |   0
>  {common => boot}/image-board.c|   0
>  {common => boot}/image-cipher.c   |   0
>  {common => boot}/image-fdt.c  |   0
>  {common => boot}/image-fit-sig.c  |   0
>  {common => boot}/image-fit.c  |   0
>  {common => boot}/image-host.c |   0
>  {common => boot}/image-sig.c  |   0
>  {common => boot}/image.c  |   0
>  {cmd => boot}/pxe_utils.c | 512 +++---
>  cmd/Makefile  |   4 +-
>  cmd/pxe.c | 136 +++---
>  cmd/pxe_utils.h   |  91 
>  cmd/sysboot.c | 114 +++--
>  common/Kconfig|   2 -
>  common/Makefile   |  22 -
>  doc/android/boot-image.rst|   2 +-
>  doc/{README.distro => develop/distro.rst} | 177 
>  doc/develop/index.rst |   1 +
>  include/pxe_utils.h   | 253 +++
>  include/vsprintf.h|  25 +-
>  lib/vsprintf.c|  20 +-
>  scripts/Makefile.spl  |   4 +-
>  test/print_ut.c   |  41 ++
>  tools/Makefile|  18 +-
>  38 files changed, 874 insertions(+), 591 deletions(-)
>  rename common/Kconfig.boot => boot/Kconfig (100%)
>  create mode 100644 boot/Makefile
>  rename {common => boot}/android_ab.c (100%)
>  rename {common => boot}/boot_fit.c (100%)
>  rename {common => boot}/bootm.c (100%)
>  rename {common => boot}/bootm_os.c (100%)
>  rename {common => boot}/bootretry.c (100%)
>  rename {common => boot}/common_fit.c (100%)
>  rename {common => boot}/fdt_region.c (100%)
>  rename {common => boot}/image-android-dt.c (100%)
>  rename {common => boot}/image-android.c (100%)
>  rename {common => boot}/image-board.c (100%)
>  rename {common => boot}/image-cipher.c (100%)
>  rename {common => boot}/image-fdt.c (100%)
>  rename {common => boot}/image-fit-sig.c (100%)
>  rename {common => boot}/image-fit.c (100%)
>  rename {common => boot}/image-host.c (100%)
>  rename {common => boot}/image-sig.c (100%)
>  rename {common => boot}/image.c (100%)
>  rename {cmd => boot}/pxe_utils.c (74%)
>  delete mode 100644 cmd/pxe_utils.h
>  rename doc/{README.distro => develop/distro.rst} (76%)
>  create mode 100644 include/pxe_utils.h
>
> --
> 2.33.0.1079.g6e70778dc9-goog
>

I see this series is assigned to you in patchwork. Did you see it? It
looks like you are network maintainer but that doesn't include the PXE
files for some reason...


Re: [PATCH] clk: introduce u-boot,ignore-clk-defaults

2021-10-25 Thread Sean Anderson

On 10/25/21 11:18 AM, Simon Glass wrote:

Hi Sean,

On Sun, 24 Oct 2021 at 18:13, Sean Anderson  wrote:


On 10/14/21 10:19 PM, Simon Glass wrote:

Hi Peng, Sean,

On Thu, 14 Oct 2021 at 19:17, Peng Fan  wrote:



Subject: Re: [PATCH] clk: introduce u-boot,ignore-clk-defaults


On 10/13/21 5:37 AM, Peng Fan (OSS) wrote:

From: Peng Fan 

Current code has a force clk_set_defaults in multiple stages, U-Boot
reuse the same device tree and Linux Kernel device tree, but we not
register all the clks as Linux Kernel, so clk_set_defaults will fail
and cause the clk provider registeration fail.

So introduce a new property to ignore the default settings which could
be used by any node that wanna ignore default settings.

Signed-off-by: Peng Fan 
---
doc/device-tree-bindings/device.txt | 3 +++
drivers/clk/clk-uclass.c| 3 +++
2 files changed, 6 insertions(+)

diff --git a/doc/device-tree-bindings/device.txt
b/doc/device-tree-bindings/device.txt
index 73ce2a3b5b..fe34ced268 100644
--- a/doc/device-tree-bindings/device.txt
+++ b/doc/device-tree-bindings/device.txt
@@ -28,6 +28,9 @@ the acpi,compatible property.
Linux will only load the driver if the device can be detected (e.g. on

I2C

bus). Note that this is an out-of-tree Linux feature.

+Common device bindings that could be shared listed below:
+ - u-boot,ignore-clk-defaults : ignore the assigned-clock-parents
+   and assigned-clock-rates for a device that has the property.

Example
---
diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index
493018b33e..6bf3179e7b 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -376,6 +376,9 @@ int clk_set_defaults(struct udevice *dev, enum

clk_defaults_stage stage)

  if (!dev_has_ofnode(dev))
  return 0;

+   if (ofnode_get_property(dev_ofnode(dev), "u-boot,ignore-clk-defaults",

NULL))

+   return 0;
+
  /*
   * To avoid setting defaults twice, don't set them before relocation.
   * However, still set them for SPL. And still set them if
explicitly



Why not just have the property ignore errors?


I think the force err return was done by Simon?



In the long term, it may be better to standardize that e.g. ENOENT means that
the clock doesn't exist. That way we can skip setting the defaults.
ENOSYS should probably be treated the same way (warn, but don't fail).


I am not sure whether people expect force error for ENOENT/ENOSYS in U-Boot.
For i.MX, I not expect force error.


Yes that is me, indeed. It's just that we should not silently ignore
errors. If we know the clock is optional, then the driver that knows
that can handle it. But if we start having things quietly fail,
debugging becomes a pain.


Can't we have them loudly fail instead?



That is how it works today, as I understand it. But some boards want
the defaults to be there but not to implement them in U-Boot. This
seems fair enough to me. Perhaps we could add something to each node
instead, to disable it?


u-boot,assigned-clock-status = "disabled";

?

--Sean



Re: [Query - 5 Mins] Information on U-BOOT FIT Malloc changes

2021-10-25 Thread Alex G.

On 10/25/21 6:55 PM, Spandan Mahadevegowda wrote:

Hello Alexandru,

I'm currently working on some POC on Pine64 that requires a Trusted 
Execution Environment. I was using U-Boot 2020.10 with SPL_FIT_GENERATOR 
and modified mksunxi_fit_atf.sh to accommodate OP-TEE. However, due to 
new changes in OPTEE and ARM_TF, I was required to update the components 
and as such had to change to the recent version of U-Boot.
I see that from the 2021.01 release and later, all ARM64 devices 
including sunxi boards were modified to use binman. I did the necessary 
changes in the latest u-boot to use my tee.bin and generate the 
u-boot-sunxi-with-spl.bin. However, when I run this on the board, I see 
that the SPL throws the "alloc space exhausted", "Could not get FIT 
buffer of 1694208 bytes" errors and I understand that this is due to the 
change in how SPL now loads images from your commit 
*03f1f78a9b44b5fd6fc09faf81639879d2d0f85f*. I am not very familiar with 
FIT and DTB handling, could you guild me with some pointers on how I can 
fix this?


Try increasing CONFIG_SYS_SPL_MALLOC_SIZE.

After debugging a little, I found that the BL31 (ARM-TF) does not find 
any DTB to load BL33 (UBOOT) after the BL31->BL32->BL31 (ARM-TF-> OPTEE 
-> ARM-TF) flow. In the Configuration, if I put "tee" as the first 
loadable, the OPTEE loads and does its initialization and gives back 
control to ARM-TF after which ARM-TF does not know where to find UBOOT. 
But if I put uboot first under loadable, ARM-TF does not find OPTEE 
(BL32). Any inputs from your end would greatly help me.


Thank you for your time and consideration,
--
Best Regards,
*Spandan Mahadevegowda*


[PATCH v5 15/26] arm: highbank: Add a fake devicetree file

2021-10-25 Thread Simon Glass
Add an empty file to prevent build errors when building with
CONFIG_OF_SEPARATE enabled.

Unfortunately there are no build instructions in the U-Boot tree to enable
a real file to be created.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/arm/dts/Makefile  |  2 ++
 arch/arm/dts/highbank.dts  | 14 ++
 configs/highbank_defconfig |  2 +-
 3 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/highbank.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 68ddf5933ea..2d9bfbe8efa 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -862,6 +862,8 @@ dtb-$(CONFIG_MX7) += imx7d-sdb.dtb \
 dtb-$(CONFIG_ARCH_MX7ULP) += imx7ulp-com.dtb \
imx7ulp-evk.dtb
 
+dtb-$(CONFIG_ARCH_HIGHBANK) += highbank.dtb
+
 dtb-$(CONFIG_ARCH_IMX8) += \
fsl-imx8qm-apalis.dtb \
fsl-imx8qm-mek.dtb \
diff --git a/arch/arm/dts/highbank.dts b/arch/arm/dts/highbank.dts
new file mode 100644
index 000..29ac48f5788
--- /dev/null
+++ b/arch/arm/dts/highbank.dts
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Dummy devicetre file for highbank board
+ *
+ * This is required to make the board build with CONFIG OF_SEPARATE
+ * There appears to be no in-tree documentation about this board at all.
+ *
+ * Copyright 2021 Google LLC
+ */
+
+/dts-v1/;
+
+/ {
+};
diff --git a/configs/highbank_defconfig b/configs/highbank_defconfig
index 43a070e7233..b9d325d391a 100644
--- a/configs/highbank_defconfig
+++ b/configs/highbank_defconfig
@@ -7,6 +7,7 @@ CONFIG_SYS_TEXT_BASE=0x8000
 CONFIG_NR_DRAM_BANKS=2
 CONFIG_ENV_SIZE=0x2000
 CONFIG_SYS_MALLOC_LEN=0x8
+CONFIG_DEFAULT_DEVICE_TREE="highbank"
 CONFIG_SYS_BOOTCOUNT_ADDR=0xfff3cf0c
 CONFIG_SYS_BOOTCOUNT_SINGLEWORD=y
 CONFIG_DISTRO_DEFAULTS=y
@@ -21,7 +22,6 @@ CONFIG_AUTOBOOT_KEYED_CTRLC=y
 # CONFIG_DISPLAY_BOARDINFO is not set
 CONFIG_MISC_INIT_R=y
 # CONFIG_CMD_SETEXPR is not set
-CONFIG_OF_BOARD=y
 CONFIG_ENV_IS_IN_NVRAM=y
 CONFIG_ENV_ADDR=0xFFF88000
 CONFIG_SCSI_AHCI=y
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v5 26/26] fdt: Don't call board_fdt_blob_setup() without OF_BOARD

2021-10-25 Thread Simon Glass
At present this override function is called even when OF_BOARD Is not
enabled. This makes it impossible to disable this feature and in fact
makes the OF_BOARD option useless.

Reinstate its intended purpose, so that it is possible to switch between
the appended devicetree and one provided by the board's custom function.

Signed-off-by: Simon Glass 
---

Changes in v5:
- Add new patches to clean up fdtdec_setup() and surrounds

 include/fdtdec.h |  7 +--
 lib/fdtdec.c | 17 +++--
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/include/fdtdec.h b/include/fdtdec.h
index 386f6611294..b2faa84008e 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -1170,8 +1170,11 @@ int fdtdec_resetup(int *rescan);
 
 /**
  * Board-specific FDT initialization. Returns the address to a device tree 
blob.
- * Called when CONFIG_OF_BOARD is defined, or if CONFIG_OF_SEPARATE is defined
- * and the board implements it.
+ * Called when CONFIG_OF_BOARD is defined.
+ *
+ * The existing devicetree is available at gd->fdt_blob
+ *
+ * @returns new devicetree blob pointer
  */
 void *board_fdt_blob_setup(void);
 
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 067c27d0aa3..da36dffec62 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1203,11 +1203,12 @@ static int uncompress_blob(const void *src, ulong 
sz_src, void **dstp)
return 0;
 }
 
-/*
- * For CONFIG_OF_SEPARATE, the board may optionally implement this to
- * provide and/or fixup the fdt.
+/**
+ * fdt_find_separate() - Find a devicetree at the end of the image
+ *
+ * @return pointer to FDT blob
  */
-__weak void *board_fdt_blob_setup(void)
+static void *fdt_find_separate(void)
 {
void *fdt_blob = NULL;
 #ifdef CONFIG_SPL_BUILD
@@ -1623,11 +1624,15 @@ int fdtdec_setup(void)
int ret;
 
/* The devicetree is typically appended to U-Boot */
-   if (IS_ENABLED(CONFIG_OF_SEPARATE) || IS_ENABLED(CONFIG_OF_BOARD))
-   gd->fdt_blob = board_fdt_blob_setup();
+   if (IS_ENABLED(CONFIG_OF_SEPARATE))
+   gd->fdt_blob = fdt_find_separate();
else /* embed dtb in ELF file for testing / development */
gd->fdt_blob = dtb_dt_embedded();
 
+   /* Allow the board to override the fdt address. */
+   if (IS_ENABLED(CONFIG_OF_BOARD))
+   gd->fdt_blob = board_fdt_blob_setup();
+
if (!IS_ENABLED(CONFIG_SPL_BUILD)) {
/* Allow the early environment to override the fdt address */
gd->fdt_blob = map_sysmem(env_get_ulong("fdtcontroladdr", 16,
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v5 25/26] fdt: Drop remaining preprocessor macros in fdtdec_setup()

2021-10-25 Thread Simon Glass
We only have two choices for obtaining the devicetree. Simplify the code
to make that clear.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 lib/fdtdec.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 0973cf0690b..067c27d0aa3 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1621,13 +1621,13 @@ static void setup_multi_dtb_fit(void)
 int fdtdec_setup(void)
 {
int ret;
-#ifdef CONFIG_OF_EMBED
-   /* Get a pointer to the FDT */
-   gd->fdt_blob = dtb_dt_embedded();
-#elif defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE)
-   /* Allow the board to override the fdt address. */
-   gd->fdt_blob = board_fdt_blob_setup();
-#endif
+
+   /* The devicetree is typically appended to U-Boot */
+   if (IS_ENABLED(CONFIG_OF_SEPARATE) || IS_ENABLED(CONFIG_OF_BOARD))
+   gd->fdt_blob = board_fdt_blob_setup();
+   else /* embed dtb in ELF file for testing / development */
+   gd->fdt_blob = dtb_dt_embedded();
+
if (!IS_ENABLED(CONFIG_SPL_BUILD)) {
/* Allow the early environment to override the fdt address */
gd->fdt_blob = map_sysmem(env_get_ulong("fdtcontroladdr", 16,
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v5 21/26] fdt: Drop CONFIG_SPL_BUILD check in fdtdec_setup()

2021-10-25 Thread Simon Glass
Move this to the header file to clean up the C code.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 include/fdtdec.h | 14 ++
 lib/fdtdec.c |  6 +-
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/include/fdtdec.h b/include/fdtdec.h
index 239814228d7..386f6611294 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -111,6 +111,20 @@ struct fdt_pci_addr {
 extern u8 __dtb_dt_begin[];/* embedded device tree blob */
 extern u8 __dtb_dt_spl_begin[];/* embedded device tree blob for 
SPL/TPL */
 
+/* Get a pointer to the embedded devicetree, if there is one, else NULL */
+static inline u8 *dtb_dt_embedded(void)
+{
+#ifdef CONFIG_OF_EMBED
+# ifdef CONFIG_SPL_BUILD
+   return __dtb_dt_spl_begin;
+# else
+   return __dtb_dt_begin;
+# endif
+#else
+   return NULL;
+#endif
+}
+
 /**
  * Compute the size of a resource.
  *
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 15a990e5b98..69877baaaf5 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1626,11 +1626,7 @@ int fdtdec_setup(void)
 #if CONFIG_IS_ENABLED(OF_CONTROL)
 # ifdef CONFIG_OF_EMBED
/* Get a pointer to the FDT */
-#  ifdef CONFIG_SPL_BUILD
-   gd->fdt_blob = __dtb_dt_spl_begin;
-#  else
-   gd->fdt_blob = __dtb_dt_begin;
-#  endif
+   gd->fdt_blob = dtb_dt_embedded();
 # elif defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE)
/* Allow the board to override the fdt address. */
gd->fdt_blob = board_fdt_blob_setup();
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v5 22/26] fdt: Drop #ifdef around board_fdt_blob_setup()

2021-10-25 Thread Simon Glass
This serves no purpose. Drop it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 lib/fdtdec.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 69877baaaf5..5a4cf440fa7 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1203,7 +1203,6 @@ static int uncompress_blob(const void *src, ulong sz_src, 
void **dstp)
return 0;
 }
 
-#if defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE)
 /*
  * For CONFIG_OF_SEPARATE, the board may optionally implement this to
  * provide and/or fixup the fdt.
@@ -1223,7 +1222,6 @@ __weak void *board_fdt_blob_setup(void)
 #endif
return fdt_blob;
 }
-#endif
 
 int fdtdec_set_ethernet_mac_address(void *fdt, const u8 *mac, size_t size)
 {
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v5 20/26] fdt: Drop #ifdefs with MULTI_DTB_FIT

2021-10-25 Thread Simon Glass
Refactor the code to drop the #ifdefs for this feature.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 dts/Kconfig   |  1 -
 include/asm-generic/global_data.h |  8 
 lib/fdtdec.c  | 31 +++
 3 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/dts/Kconfig b/dts/Kconfig
index 20ddc534a61..0f7e3ad7db7 100644
--- a/dts/Kconfig
+++ b/dts/Kconfig
@@ -176,7 +176,6 @@ endchoice
 
 config MULTI_DTB_FIT_UNCOMPRESS_SZ
hex "Size of memory reserved to uncompress the DTBs"
-   depends on (MULTI_DTB_FIT_GZIP || MULTI_DTB_FIT_LZO)
default 0x8000
help
   This is the size of this area where the DTBs are uncompressed.
diff --git a/include/asm-generic/global_data.h 
b/include/asm-generic/global_data.h
index 16fd305a65c..99daa20c765 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -512,6 +512,14 @@ static_assert(sizeof(struct global_data) == GD_SIZE);
 #define gd_acpi_ctx()  NULL
 #endif
 
+#if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
+#define gd_multi_dtb_fit() gd->multi_dtb_fit
+#define gd_set_multi_dtb_fit(_dtb) gd->multi_dtb_fit = _dtb
+#else
+#define gd_multi_dtb_fit() NULL
+#define gd_set_multi_dtb_fit(_dtb)
+#endif
+
 /**
  * enum gd_flags - global data flags
  *
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 58ea8f70cfe..15a990e5b98 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1146,11 +1146,10 @@ int fdtdec_setup_mem_size_base_lowest(void)
return 0;
 }
 
-#if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
-# if CONFIG_IS_ENABLED(MULTI_DTB_FIT_GZIP) ||\
-   CONFIG_IS_ENABLED(MULTI_DTB_FIT_LZO)
 static int uncompress_blob(const void *src, ulong sz_src, void **dstp)
 {
+#if CONFIG_IS_ENABLED(MULTI_DTB_FIT_GZIP) ||\
+   CONFIG_IS_ENABLED(MULTI_DTB_FIT_LZO)
size_t sz_out = CONFIG_VAL(MULTI_DTB_FIT_UNCOMPRESS_SZ);
bool gzip = 0, lzo = 0;
ulong sz_in = sz_src;
@@ -1175,11 +1174,11 @@ static int uncompress_blob(const void *src, ulong 
sz_src, void **dstp)
return -ENOMEM;
}
} else  {
-#  if CONFIG_IS_ENABLED(MULTI_DTB_FIT_USER_DEFINED_AREA)
+# if CONFIG_IS_ENABLED(MULTI_DTB_FIT_USER_DEFINED_AREA)
dst = (void *)CONFIG_VAL(MULTI_DTB_FIT_USER_DEF_ADDR);
-#  else
+# else
return -ENOTSUPP;
-#  endif
+# endif
}
 
if (CONFIG_IS_ENABLED(GZIP) && gzip)
@@ -1197,16 +1196,12 @@ static int uncompress_blob(const void *src, ulong 
sz_src, void **dstp)
return -EBADMSG;
}
*dstp = dst;
-   return 0;
-}
-# else
-static int uncompress_blob(const void *src, ulong sz_src, void **dstp)
-{
+#else
+   *dstp = (void *)src;
*dstp = (void *)src;
+#endif
return 0;
 }
-# endif
-#endif
 
 #if defined(CONFIG_OF_BOARD) || defined(CONFIG_OF_SEPARATE)
 /*
@@ -1603,7 +1598,6 @@ __weak int fdtdec_board_setup(const void *fdt_blob)
  */
 static void setup_multi_dtb_fit(void)
 {
-# if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
void *blob;
 
/*
@@ -1621,10 +1615,9 @@ static void setup_multi_dtb_fit(void)
 */
blob = locate_dtb_in_fit(gd->fdt_blob);
if (blob) {
-   gd->multi_dtb_fit = gd->fdt_blob;
+   gd_set_multi_dtb_fit(gd->fdt_blob);
gd->fdt_blob = blob;
}
-#endif /* # MULTI_DTB_FIT */
 }
 
 int fdtdec_setup(void)
@@ -1659,7 +1652,6 @@ int fdtdec_setup(void)
return ret;
 }
 
-#if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
 int fdtdec_resetup(int *rescan)
 {
void *fdt_blob;
@@ -1670,8 +1662,8 @@ int fdtdec_resetup(int *rescan)
 * FIT image stillpresent there. Save the time and space
 * required to uncompress it again.
 */
-   if (gd->multi_dtb_fit) {
-   fdt_blob = locate_dtb_in_fit(gd->multi_dtb_fit);
+   if (gd_multi_dtb_fit()) {
+   fdt_blob = locate_dtb_in_fit(gd_multi_dtb_fit());
 
if (fdt_blob == gd->fdt_blob) {
/*
@@ -1695,7 +1687,6 @@ int fdtdec_resetup(int *rescan)
*rescan = 0;
return 0;
 }
-#endif
 
 int fdtdec_decode_ram_size(const void *blob, const char *area, int board_id,
   phys_addr_t *basep, phys_size_t *sizep,
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v5 16/26] fdt: Make OF_BOARD a bool option

2021-10-25 Thread Simon Glass
This should not be a separate option from OF_SEPARATE. It is a run-time
option to override the devicetree, even if present.

Move the option out of the choice.

Disable BINMAN_FDT for a few boards which don't actually use it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 configs/qemu-ppce500_defconfig | 1 +
 configs/qemu-riscv32_spl_defconfig | 2 ++
 configs/qemu-riscv64_spl_defconfig | 1 +
 dts/Kconfig| 9 +
 4 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/configs/qemu-ppce500_defconfig b/configs/qemu-ppce500_defconfig
index 5bf3e8de37a..66411f73a11 100644
--- a/configs/qemu-ppce500_defconfig
+++ b/configs/qemu-ppce500_defconfig
@@ -54,4 +54,5 @@ CONFIG_VIRTIO_PCI=y
 CONFIG_VIRTIO_NET=y
 CONFIG_VIRTIO_BLK=y
 CONFIG_ADDR_MAP=y
+# CONFIG_BINMAN_FDT is not set
 CONFIG_PANIC_HANG=y
diff --git a/configs/qemu-riscv32_spl_defconfig 
b/configs/qemu-riscv32_spl_defconfig
index 3909c9a15ad..4621afb1a87 100644
--- a/configs/qemu-riscv32_spl_defconfig
+++ b/configs/qemu-riscv32_spl_defconfig
@@ -6,6 +6,7 @@ CONFIG_DEFAULT_DEVICE_TREE="qemu-virt32"
 CONFIG_SPL=y
 CONFIG_TARGET_QEMU_VIRT=y
 CONFIG_RISCV_SMODE=y
+# CONFIG_OF_BOARD_FIXUP is not set
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_SYS_LOAD_ADDR=0x8020
 CONFIG_FIT=y
@@ -18,3 +19,4 @@ CONFIG_OF_BOARD=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_DM_MTD=y
 CONFIG_SYSRESET_SBI=y
+# CONFIG_BINMAN_FDT is not set
diff --git a/configs/qemu-riscv64_spl_defconfig 
b/configs/qemu-riscv64_spl_defconfig
index 34d88da41b0..6f8ff91df9e 100644
--- a/configs/qemu-riscv64_spl_defconfig
+++ b/configs/qemu-riscv64_spl_defconfig
@@ -19,3 +19,4 @@ CONFIG_OF_BOARD=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_DM_MTD=y
 CONFIG_SYSRESET_SBI=y
+# CONFIG_BINMAN_FDT is not set
diff --git a/dts/Kconfig b/dts/Kconfig
index 99a7a8b0338..97ace4ec39c 100644
--- a/dts/Kconfig
+++ b/dts/Kconfig
@@ -100,7 +100,6 @@ choice
 
 config OF_SEPARATE
bool "Separate DTB for DT control"
-   depends on !SANDBOX
help
  If this option is enabled, the device tree will be built and
  placed as a separate u-boot.dtb file alongside the U-Boot image.
@@ -113,14 +112,16 @@ config OF_EMBED
  and development only and is not recommended for production devices.
  Boards in the mainline U-Boot tree should not use it.
 
+endchoice
+
 config OF_BOARD
bool "Provided by the board (e.g a previous loader) at runtime"
help
  If this option is enabled, the device tree will be provided by
- the board at runtime if the board supports it, instead of being
- bundled with the image.
+ the board at runtime if the board supports it. The device tree bundled
+ with the image (if any) will be overridden / ignored.
 
-endchoice
+ A device tree file must be provided in the tree.
 
 config DEFAULT_DEVICE_TREE
string "Default Device Tree for DT control"
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v5 18/26] doc: Update info on devicetree update

2021-10-25 Thread Simon Glass
Since OF_BOARD has been corrected to be a run-time option, we can drop
the historical info from this documentation.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 doc/develop/devicetree/dt_update.rst | 74 +++-
 1 file changed, 8 insertions(+), 66 deletions(-)

diff --git a/doc/develop/devicetree/dt_update.rst 
b/doc/develop/devicetree/dt_update.rst
index 3d4902e3592..4a1976f5b4b 100644
--- a/doc/develop/devicetree/dt_update.rst
+++ b/doc/develop/devicetree/dt_update.rst
@@ -32,66 +32,6 @@ that board on suitable hardware (or emulation). This is 
specified using the
 `CONFIG DEFAULT_DEVICE_TREE` option.
 
 
-Current situation (October 2021)
-~~
-
-As an aside, at present U-Boot allows `CONFIG_DEFAULT_DEVICE_TREE` to be empty,
-e.g. if `CONFIG_OF_BOARD` is used. This has unfortunately created an enormous
-amount of confusion and some wasted effort. This was not intended. Support for
-an empty `CONFIG_DEFAULT_DEVICE_TREE` will be dropped soon.
-
-Some of the problems created are:
-
-- It is not obvious that the devicetree is coming from another project
-
-- There is no way to see even a sample devicetree for these platform in U-Boot,
-  so it is hard to know what is going on, e.g. which devices are typically
-  present
-
-- The other project may not provide a way to support U-Boot's requirements for
-  devicetree, such as the /config node. Note: On the U-Boot mailing linst, this
-  was only discovered after weeks of discussion and confusion
-
-- For QEMU specifically, consulting two QEMU source files is required, for 
which
-  there are no references in U-Boot documentation. The code is generating a
-  devicetree, but it is not clear what controls affect this generation.
-
-Specifically on the changes in U-Bootm `CONFIG_OF_BOARD` was added in
-rpi_patch_ for Raspberry Pi, which does have an in-tree devicetree, but this
-feature has since been used for boards that don't
-
-Once this bug is fixed, CONFIG_OF_BOARD will override (at runtime) the
-evicetree suppled with U-Boot, but will otherwise use CONFIG_OF_SEPARATE for 
the
-in-tree build. So these two will become options, moving out of the 'choice' in
-`dts/Kconfig`.
-
-This means that there is a basic devicetree build in the U-Boot tree, for
-build-testing, consistency and documentation purposes, but at runtime U-Boot 
can
-accept its devicetree from another source. The in-tree devicetree may contain
-U-Boot-specific features (in u-boot*.dtsi files) and this may prove useful for
-the other project, so it can ensure that U-Boot functions correctly and 
supports
-all its expected features.
-
-To be clear, while U-Boot has its own copy of the devicetree source for each
-board, this must match the Linux source, perhaps with some u-boot.dtsi
-additions. The intent here is not to create a separate binding, just to provide
-a representative devicetree in U-Boot.
-
-Offending boards are:
-
-- rpi_4 and rpi_4_32b (other rpi boards do have an in-tree devicetree)
-- qemu_arm64
-- qemu_arm
-- qemu-ppce500
-- qemu-riscv32
-- qemu-riscv32_smode
-- qemu-riscv64
-- qemu-riscv64_smode
-
-All of these need to have a devicetree added in-tree. This is targeted to be
-fixed in the 2022.01 release.
-
-
 Building the devicetree
 ---
 
@@ -205,15 +145,18 @@ Operating System. Also, while Linux has a (sometimes 
extremely long) command
 line, U-Boot does not support this. The devicetree provides a more structured
 approach in any case.
 
+Note: Dicussions on adding a binding for this to the Linux devicetree bindings
+are ongoing as of October 2021.
+
 
 Devicetree in another project
 -
 
-In some cases U-Boot receive its devicetree at runtime from a program that 
calls
-it. For example ARM's Trusted Firmware A (`TF-A`_) may have a devicetree that 
it
-passes to U-Boot. This overrides any devicetree build by U-Boot. When packaging
-the firmware, the U-Boot devicetree may in fact be left out if it can be
-guaranteed that it will receive one from another project.
+In some cases U-Boot receives its devicetree at runtime from a program that
+calls it. For example ARM's Trusted Firmware A (`TF-A`_) may have a devicetree
+that it passes to U-Boot. This overrides any devicetree build by U-Boot. When
+packaging the firmware, the U-Boot devicetree may in fact be left out if it can
+be guaranteed that it will receive one from another project.
 
 In this case, the devicetree in the other project must track U-Boot's use of
 device tree, for the following reasons:
@@ -547,7 +490,6 @@ Overall, adding a second devicetree would create enormous 
confusion and
 complexity. It seems a lot cheaper to solve this by a change of attitude.
 
 
-.. _rpi_patch: 
https://patchwork.ozlabs.org/project/uboot/patch/20170402082520.32546-1-de...@google.com/
 .. _`TF-A`: https://www.trustedfirmware.org/projects/tf-a
 .. _`QEMU ARM`: https://github.com/qemu/qemu/blob/master/hw/arm/virt.c
 .. _`QEMU 

[PATCH v5 17/26] Drop CONFIG_BINMAN_STANDALONE_FDT

2021-10-25 Thread Simon Glass
This was added as a hack to work around not having an in-tree devicetree.
Now that this is fixed it is not needed.

Drop it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 Makefile|  3 +--
 dts/Kconfig | 18 --
 tools/binman/binman.rst | 20 
 3 files changed, 1 insertion(+), 40 deletions(-)

diff --git a/Makefile b/Makefile
index c0ea933cb63..09a5cea8cb8 100644
--- a/Makefile
+++ b/Makefile
@@ -943,7 +943,6 @@ endif
 endif
 INPUTS-$(CONFIG_TPL) += tpl/u-boot-tpl.bin
 INPUTS-$(CONFIG_OF_SEPARATE) += u-boot.dtb
-INPUTS-$(CONFIG_BINMAN_STANDALONE_FDT) += u-boot.dtb
 ifeq ($(CONFIG_SPL_FRAMEWORK),y)
 INPUTS-$(CONFIG_OF_SEPARATE) += u-boot-dtb.img
 endif
@@ -1407,7 +1406,7 @@ u-boot-lzma.img: u-boot.bin.lzma FORCE
 
 u-boot-dtb.img u-boot.img u-boot.kwb u-boot.pbl u-boot-ivt.img: \
$(if $(CONFIG_SPL_LOAD_FIT),u-boot-nodtb.bin \
-   $(if 
$(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_SANDBOX)$(CONFIG_BINMAN_STANDALONE_FDT),dts/dt.dtb)
 \
+   $(if 
$(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_SANDBOX),dts/dt.dtb) \
,$(UBOOT_BIN)) FORCE
$(call if_changed,mkimage)
$(BOARD_SIZE_CHECK)
diff --git a/dts/Kconfig b/dts/Kconfig
index 97ace4ec39c..20ddc534a61 100644
--- a/dts/Kconfig
+++ b/dts/Kconfig
@@ -16,24 +16,6 @@ config BINMAN
bool
select DTOC
 
-config BINMAN_STANDALONE_FDT
-   bool
-   depends on BINMAN
-   default y if OF_BOARD
-   help
- This option tells U-Boot build system that a standalone device tree
- source is explicitly required when using binman to package U-Boot.
-
- This is not necessary in a common scenario where a device tree source
- that contains the binman node is provided in the arch//dts
- directory for a specific board. Such device tree sources are built for
- OF_SEPARATE or OF_EMBED. However for a scenario like the board device
- tree blob is not provided in the U-Boot build tree, but fed to U-Boot
- in the runtime, e.g.: in the OF_BOARD case that it is passed by
- a prior stage bootloader. For such scenario, a standalone device tree
- blob containing binman node to describe how to package U-Boot should
- be provided explicitly.
-
 menu "Device Tree Control"
depends on SUPPORT_OF_CONTROL
 
diff --git a/tools/binman/binman.rst b/tools/binman/binman.rst
index 614df541c5a..f90dd3a5e5d 100644
--- a/tools/binman/binman.rst
+++ b/tools/binman/binman.rst
@@ -232,26 +232,6 @@ You can use other, more specific CONFIG options - see 
'Automatic .dtsi
 inclusion' below.
 
 
-Using binman with OF_BOARD
-
-
-Normally binman is used with a board configured with OF_SEPARATE or OF_EMBED.
-This is a typical scenario where a device tree source that contains the binman
-node is provided in the arch//dts directory for a specific board.
-
-However for a board configured with OF_BOARD, no device tree blob is provided
-in the U-Boot build phase hence the binman node information is not available.
-In order to support such use case, a new Kconfig option BINMAN_STANDALONE_FDT
-is introduced, to tell the build system that a standalone device tree blob
-containing binman node is explicitly required.
-
-Note there is a Kconfig option BINMAN_FDT which enables U-Boot run time to
-access information about binman entries, stored in the device tree in a binman
-node. Generally speaking, this option makes sense for OF_SEPARATE or OF_EMBED.
-For the other OF_CONTROL methods, it's quite possible binman node is not
-available as binman is invoked during the build phase, thus this option is not
-turned on by default for these OF_CONTROL methods.
-
 Access to binman entry offsets at run time (symbols)
 
 
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v5 19/26] fdt: Move MULTI_DTB_FIT handling out of fdtdec_setup()

2021-10-25 Thread Simon Glass
This logic is a bit convoluted for one function. Move the mulit-FIT part
into its own function.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 lib/fdtdec.c | 62 
 1 file changed, 38 insertions(+), 24 deletions(-)

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 688741108c7..58ea8f70cfe 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1591,13 +1591,46 @@ __weak int fdtdec_board_setup(const void *fdt_blob)
return 0;
 }
 
+/**
+ * setup_multi_dtb_fit() - locate the correct dtb from a FIT
+ *
+ * This supports the CONFIG_MULTI_DTB_FIT feature, looking for the dtb in a
+ * supplied FIT
+ *
+ * It accepts the current value of gd->fdt_blob, which points to the FIT, then
+ * updates that gd->fdt_blob, to point to the chosen dtb so that U-Boot uses 
the
+ * correct one
+ */
+static void setup_multi_dtb_fit(void)
+{
+# if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
+   void *blob;
+
+   /*
+* Try and uncompress the blob.
+* Unfortunately there is no way to know how big the input blob really
+* is. So let us set the maximum input size arbitrarily high. 16MB
+* ought to be more than enough for packed DTBs.
+*/
+   if (uncompress_blob(gd->fdt_blob, 0x100, ) == 0)
+   gd->fdt_blob = blob;
+
+   /*
+* Check if blob is a FIT images containings DTBs.
+* If so, pick the most relevant
+*/
+   blob = locate_dtb_in_fit(gd->fdt_blob);
+   if (blob) {
+   gd->multi_dtb_fit = gd->fdt_blob;
+   gd->fdt_blob = blob;
+   }
+#endif /* # MULTI_DTB_FIT */
+}
+
 int fdtdec_setup(void)
 {
int ret;
 #if CONFIG_IS_ENABLED(OF_CONTROL)
-# if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
-   void *fdt_blob;
-# endif
 # ifdef CONFIG_OF_EMBED
/* Get a pointer to the FDT */
 #  ifdef CONFIG_SPL_BUILD
@@ -1616,27 +1649,8 @@ int fdtdec_setup(void)
   (unsigned long)map_to_sysmem(gd->fdt_blob)), 0);
 # endif
 
-# if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
-   /*
-* Try and uncompress the blob.
-* Unfortunately there is no way to know how big the input blob really
-* is. So let us set the maximum input size arbitrarily high. 16MB
-* ought to be more than enough for packed DTBs.
-*/
-   if (uncompress_blob(gd->fdt_blob, 0x100, _blob) == 0)
-   gd->fdt_blob = fdt_blob;
-
-   /*
-* Check if blob is a FIT images containings DTBs.
-* If so, pick the most relevant
-*/
-   fdt_blob = locate_dtb_in_fit(gd->fdt_blob);
-   if (fdt_blob) {
-   gd->multi_dtb_fit = gd->fdt_blob;
-   gd->fdt_blob = fdt_blob;
-   }
-
-# endif
+   if (CONFIG_IS_ENABLED(MULTI_DTB_FIT))
+   setup_multi_dtb_fit();
 #endif
 
ret = fdtdec_prepare_fdt();
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v5 12/26] arm: xilinx_versal_virt: Add a devicetree file

2021-10-25 Thread Simon Glass
Add a devicetree file obtained from qemu for this board. This was obtained
with:

   qemu-system-aarch64 -M xlnx-versal-virt -machine dumpdtb=dtb.dtb

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/arm/dts/Makefile|   3 +-
 arch/arm/dts/xilinx-versal-virt.dts  | 307 +++
 configs/xilinx_versal_virt_defconfig |   1 +
 3 files changed, 310 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/xilinx-versal-virt.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 44835145f4b..0a30ad327cf 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -352,7 +352,8 @@ dtb-$(CONFIG_ARCH_ZYNQMP) += \
 dtb-$(CONFIG_ARCH_VERSAL) += \
versal-mini.dtb \
versal-mini-emmc0.dtb \
-   versal-mini-emmc1.dtb
+   versal-mini-emmc1.dtb \
+   xilinx-versal-virt.dtb
 dtb-$(CONFIG_ARCH_ZYNQMP_R5) += \
zynqmp-r5.dtb
 dtb-$(CONFIG_AM33XX) += \
diff --git a/arch/arm/dts/xilinx-versal-virt.dts 
b/arch/arm/dts/xilinx-versal-virt.dts
new file mode 100644
index 000..3712af9e7a4
--- /dev/null
+++ b/arch/arm/dts/xilinx-versal-virt.dts
@@ -0,0 +1,307 @@
+// SPDX-License-Identifier: GPL-2.0+ OR MIT
+/*
+ * Sample device tree for versal-virt board
+
+ * Copyright 2021 Google LLC
+ */
+
+/dts-v1/;
+
+/ {
+   compatible = "xlnx-versal-virt";
+   model = "Xilinx Versal Virtual development board";
+   #address-cells = <0x02>;
+   #size-cells = <0x02>;
+   interrupt-parent = <0x8000>;
+
+   memory@0 {
+   reg = <0x00 0x00 0x00 0x800>;
+   device_type = "memory";
+   };
+
+   clk25 {
+   u-boot,dm-pre-reloc;
+   compatible = "fixed-clock";
+   #clock-cells = <0x00>;
+   clock-frequency = <0x17d7840>;
+   phandle = <0x8003>;
+   };
+
+   clk125 {
+   u-boot,dm-pre-reloc;
+   compatible = "fixed-clock";
+   #clock-cells = <0x00>;
+   clock-frequency = <0x7735940>;
+   phandle = <0x8004>;
+   };
+
+   cpus {
+   #address-cells = <0x01>;
+   #size-cells = <0x00>;
+
+   cpu@0 {
+   compatible = "arm,cortex-a72";
+   device_type = "cpu";
+   reg = <0x00>;
+   };
+
+   cpu@1 {
+   compatible = "arm,cortex-a72";
+   device_type = "cpu";
+   reg = <0x01>;
+   };
+   };
+
+   rtc@f12a {
+   compatible = "xlnx,zynqmp-rtc";
+   reg = <0x00 0xf12a 0x00 0x1>;
+   interrupt-names = "alarm\0sec";
+   interrupts = <0x00 0x8e 0x04 0x00 0x8f 0x04>;
+   };
+
+   sdhci@f104 {
+   compatible = "arasan,sdhci-8.9a";
+   reg = <0x00 0xf104 0x00 0x1>;
+   interrupts = <0x00 0x7e 0x04>;
+   clock-names = "clk_xin\0clk_ahb";
+   clocks = <0x8003 0x8003>;
+   };
+
+   sdhci@f105 {
+   compatible = "arasan,sdhci-8.9a";
+   reg = <0x00 0xf105 0x00 0x1>;
+   interrupts = <0x00 0x80 0x04>;
+   clock-names = "clk_xin\0clk_ahb";
+   clocks = <0x8003 0x8003>;
+   };
+
+   usb@ff9d {
+   phandle = <0x8005>;
+   #size-cells = <0x02>;
+   #address-cells = <0x02>;
+   ranges;
+   clocks = <0x8003 0x8004>;
+   clock-names = "bus_clk\0ref_clk";
+   reg = <0x00 0xff9d 0x00 0x1>;
+   compatible = "xlnx,versal-dwc3";
+
+   dwc3@fe20 {
+   maximum-speed = "high-speed";
+   phandle = <0x8006>;
+   snps,mask_phy_reset;
+   snps,refclk_fladj;
+   snps,dis_u3_susphy_quirk;
+   snps,dis_u2_susphy_quirk;
+   phy-names = "usb3-phy";
+   dr_mode = "host";
+   #stream-id-cells = <0x01>;
+   snps,quirk-frame-length-adjustment = <0x20>;
+   interrupts = <0x00 0x16 0x04>;
+   interrupt-names = "dwc_usb3";
+   reg = <0x00 0xfe20 0x00 0x1>;
+   compatible = "snps,dwc3";
+   };
+   };
+
+   dma@ffa8 {
+   compatible = "xlnx,zynqmp-dma-1.0";
+   reg = <0x00 0xffa8 0x00 0x1000>;
+   interrupts = <0x00 0x3c 0x04>;
+   clock-names = "clk_main\0clk_apb";
+   clocks = <0x8003 0x8003>;
+   xlnx,bus-width = <0x40>;
+   };
+
+   dma@ffa9 {
+   compatible = "xlnx,zynqmp-dma-1.0";
+   reg = <0x00 0xffa9 0x00 0x1000>;
+   

[PATCH v5 13/26] arm: bcm7xxx: Add a devicetree file

2021-10-25 Thread Simon Glass
Add a dummy devicetree file for these boards. It seems to be possible to
obtain a real one from another bootloader called 'bolt' but I will leave
this to the maintainer.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/arm/dts/Makefile |  2 ++
 arch/arm/dts/bcm7xxx.dts  | 15 +++
 configs/bcm7260_defconfig |  1 +
 configs/bcm7445_defconfig |  1 +
 4 files changed, 19 insertions(+)
 create mode 100644 arch/arm/dts/bcm7xxx.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 0a30ad327cf..68ddf5933ea 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1083,6 +1083,8 @@ dtb-$(CONFIG_ARCH_BCM6858) += \
 
 dtb-$(CONFIG_TARGET_BCMNS3) += ns3-board.dtb
 
+dtb-$(CONFIG_ARCH_BCMSTB) += bcm7xxx.dtb
+
 dtb-$(CONFIG_ASPEED_AST2500) += ast2500-evb.dtb
 dtb-$(CONFIG_ASPEED_AST2600) += ast2600-evb.dtb
 
diff --git a/arch/arm/dts/bcm7xxx.dts b/arch/arm/dts/bcm7xxx.dts
new file mode 100644
index 000..799cc9caad4
--- /dev/null
+++ b/arch/arm/dts/bcm7xxx.dts
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Dummy devicetre file for bcm7260 board
+ *
+ * This is required to make the board build with CONFIG OF_SEPARATE
+ * In-tree document explains how to obtain a real devicetree using 'bolt' but
+ * I did not attempt this.
+ *
+ * Copyright 2021 Google LLC
+ */
+
+/dts-v1/;
+
+/ {
+};
diff --git a/configs/bcm7260_defconfig b/configs/bcm7260_defconfig
index 3afb909f712..89b5b01ad76 100644
--- a/configs/bcm7260_defconfig
+++ b/configs/bcm7260_defconfig
@@ -7,6 +7,7 @@ CONFIG_NR_DRAM_BANKS=1
 CONFIG_ENV_SIZE=0x1
 CONFIG_ENV_OFFSET=0x814800
 CONFIG_SYS_MALLOC_LEN=0x280
+CONFIG_DEFAULT_DEVICE_TREE="bcm7xxx"
 CONFIG_ENV_OFFSET_REDUND=0x824800
 CONFIG_SYS_LOAD_ADDR=0x0200
 CONFIG_FIT=y
diff --git a/configs/bcm7445_defconfig b/configs/bcm7445_defconfig
index 3726abd7354..92c1b36185a 100644
--- a/configs/bcm7445_defconfig
+++ b/configs/bcm7445_defconfig
@@ -8,6 +8,7 @@ CONFIG_ENV_SIZE=0x1
 CONFIG_ENV_OFFSET=0x1E
 CONFIG_ENV_SECT_SIZE=0x1
 CONFIG_SYS_MALLOC_LEN=0xa0
+CONFIG_DEFAULT_DEVICE_TREE="bcm7xxx"
 CONFIG_ENV_OFFSET_REDUND=0x1F
 CONFIG_SYS_LOAD_ADDR=0x0200
 CONFIG_FIT=y
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v5 09/26] arm: vexpress: Add a devicetree file for juno

2021-10-25 Thread Simon Glass
Add this file, obtained from the Linaro website[1], so there is a
reference file in the U-Boot tree.

Note that U-Boot does not normally need this at runtime, since
CONFIG_OF_BOARD is enabled. The previous firmware stage provides a
devicetree at runtime.


[1] https://releases.linaro.org/android/reference-lcr/juno/7.1-17.05/

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/arm/dts/Makefile  |3 +
 arch/arm/dts/juno-r2.dts   | 1038 
 configs/vexpress_aemv8a_juno_defconfig |1 +
 3 files changed, 1042 insertions(+)
 create mode 100644 arch/arm/dts/juno-r2.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index f5a02bec4e1..0be50ecd9c8 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1140,7 +1140,10 @@ dtb-$(CONFIG_TARGET_GE_BX50V3) += \
 dtb-$(CONFIG_TARGET_GE_B1X5V2) += imx6dl-b1x5v2.dtb
 dtb-$(CONFIG_TARGET_MX53PPD) += imx53-ppd.dtb
 
+# TODO(Linus Walleij ): Should us a single vexpress
+# Kconfig option to build all of these. See examples above.
 dtb-$(CONFIG_TARGET_VEXPRESS_CA9X4) += vexpress-v2p-ca9.dtb
+dtb-$(CONFIG_TARGET_VEXPRESS64_JUNO) += juno-r2.dtb
 
 dtb-$(CONFIG_TARGET_TOTAL_COMPUTE) += total_compute.dtb
 
diff --git a/arch/arm/dts/juno-r2.dts b/arch/arm/dts/juno-r2.dts
new file mode 100644
index 000..5a536d8100e
--- /dev/null
+++ b/arch/arm/dts/juno-r2.dts
@@ -0,0 +1,1038 @@
+// SPDX-License-Identifier: GPL-2.0+ OR MIT
+/*
+ * Sample device tree for juno
+
+ * Copyright 2021 Google LLC
+ */
+
+/dts-v1/;
+
+/ {
+   model = "ARM Juno development board (r2)";
+   compatible = "arm,juno-r2\0arm,juno";
+   interrupt-parent = <0x01>;
+   #address-cells = <0x02>;
+   #size-cells = <0x02>;
+
+   aliases {
+   serial0 = "/uart@7ff8";
+   };
+
+   chosen {
+   stdout-path = "serial0:115200n8";
+   };
+
+   psci {
+   compatible = "arm,psci-0.2";
+   method = "smc";
+   };
+
+   cpus {
+   #address-cells = <0x02>;
+   #size-cells = <0x00>;
+
+   cpu-map {
+
+   cluster0 {
+
+   core0 {
+   cpu = <0x02>;
+   };
+
+   core1 {
+   cpu = <0x03>;
+   };
+   };
+
+   cluster1 {
+
+   core0 {
+   cpu = <0x04>;
+   };
+
+   core1 {
+   cpu = <0x05>;
+   };
+
+   core2 {
+   cpu = <0x06>;
+   };
+
+   core3 {
+   cpu = <0x07>;
+   };
+   };
+   };
+
+   idle-states {
+   entry-method = "arm,psci";
+
+   cpu-sleep-0 {
+   compatible = "arm,idle-state";
+   arm,psci-suspend-param = <0x1>;
+   local-timer-stop;
+   entry-latency-us = <0x12c>;
+   exit-latency-us = <0x4b0>;
+   min-residency-us = <0x7d0>;
+   linux,phandle = <0x0a>;
+   phandle = <0x0a>;
+   };
+
+   cluster-sleep-0 {
+   compatible = "arm,idle-state";
+   arm,psci-suspend-param = <0x101>;
+   local-timer-stop;
+   entry-latency-us = <0x190>;
+   exit-latency-us = <0x4b0>;
+   min-residency-us = <0x9c4>;
+   linux,phandle = <0x0b>;
+   phandle = <0x0b>;
+   };
+   };
+
+   cpu@0 {
+   compatible = "arm,cortex-a72\0arm,armv8";
+   reg = <0x00 0x00>;
+   device_type = "cpu";
+   enable-method = "psci";
+   next-level-cache = <0x08>;
+   clocks = <0x09 0x00>;
+   cpu-idle-states = <0x0a 0x0b>;
+   sched-energy-costs = <0x0c 0x0d>;
+   #cooling-cells = <0x02>;
+   dynamic-power-coefficient = <0x1c2>;
+   linux,phandle = <0x02>;
+   phandle = <0x02>;
+   };
+
+   cpu@1 {
+   compatible = "arm,cortex-a72\0arm,armv8";
+

[PATCH v5 14/26] arm: qemu-ppce500: Add a devicetree file

2021-10-25 Thread Simon Glass
Add a devicetree file obtained from qemu for this board. This was obtained
with:

   qemu-system-ppc64 -machine ppce500 -cpu e6500 -M dumpdtb=dtb.dtb

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/powerpc/dts/Makefile |   1 +
 arch/powerpc/dts/qemu-ppce500.dts | 264 ++
 configs/qemu-ppce500_defconfig|   1 +
 3 files changed, 266 insertions(+)
 create mode 100644 arch/powerpc/dts/qemu-ppce500.dts

diff --git a/arch/powerpc/dts/Makefile b/arch/powerpc/dts/Makefile
index ceaa8ce5c82..66d22ae8a45 100644
--- a/arch/powerpc/dts/Makefile
+++ b/arch/powerpc/dts/Makefile
@@ -18,6 +18,7 @@ dtb-$(CONFIG_TARGET_P2041RDB) += p2041rdb.dtb
 dtb-$(CONFIG_TARGET_P3041DS) += p3041ds.dtb
 dtb-$(CONFIG_TARGET_P4080DS) += p4080ds.dtb
 dtb-$(CONFIG_TARGET_P5040DS) += p5040ds.dtb
+dtb-$(CONFIG_TARGET_QEMU_PPCE500) += qemu-ppce500.dtb
 dtb-$(CONFIG_TARGET_SOCRATES) += socrates.dtb
 dtb-$(CONFIG_TARGET_T1024RDB) += t1024rdb.dtb
 dtb-$(CONFIG_TARGET_T1042D4RDB) += t1042d4rdb.dtb
diff --git a/arch/powerpc/dts/qemu-ppce500.dts 
b/arch/powerpc/dts/qemu-ppce500.dts
new file mode 100644
index 000..92368e4d731
--- /dev/null
+++ b/arch/powerpc/dts/qemu-ppce500.dts
@@ -0,0 +1,264 @@
+// SPDX-License-Identifier: GPL-2.0+ OR MIT
+/*
+ * Sample device tree for qemu-ppce400
+
+ * Copyright 2021 Google LLC
+ */
+/dts-v1/;
+
+/ {
+   compatible = "fsl,qemu-e500";
+   model = "QEMU ppce500";
+   #size-cells = <0x02>;
+   #address-cells = <0x02>;
+
+   platform@f {
+   interrupt-parent = <0x8003>;
+   ranges = <0x00 0x0f 0x00 0x800>;
+   #address-cells = <0x01>;
+   #size-cells = <0x01>;
+   compatible = "qemu,platform\0simple-bus";
+   };
+
+   pci@fe0008000 {
+   #address-cells = <0x03>;
+   #size-cells = <0x02>;
+   #interrupt-cells = <0x01>;
+   clock-frequency = <0x3f940aa>;
+   reg = <0x0f 0xe0008000 0x00 0x1000>;
+   ranges = <0x200 0x00 0xe000 0x0c
+0x00 0x00 0x2000 0x100
+0x00 0x00 0x0f 0xe100
+0x00 0x1>;
+   fsl,msi = <0x8004>;
+   bus-range = <0x00 0xff>;
+   interrupts = <0x18 0x02>;
+   interrupt-parent = <0x8003>;
+   interrupt-map = <0x800 0x00 0x00 0x01 0x8003 0x02 0x01 0x800
+   0x00 0x00 0x02 0x8003 0x03 0x01 0x800 0x00
+   0x00 0x03 0x8003 0x04 0x01 0x800 0x00 0x00
+   0x04 0x8003 0x01 0x01 0x1000 0x00 0x00 0x01
+   0x8003 0x03 0x01 0x1000 0x00 0x00 0x02 0x8003
+   0x04 0x01 0x1000 0x00 0x00 0x03 0x8003 0x01
+   0x01 0x1000 0x00 0x00 0x04 0x8003 0x02 0x01
+   0x1800 0x00 0x00 0x01 0x8003 0x04 0x01 0x1800
+   0x00 0x00 0x02 0x8003 0x01 0x01 0x1800 0x00
+   0x00 0x03 0x8003 0x02 0x01 0x1800 0x00 0x00
+   0x04 0x8003 0x03 0x01 0x2000 0x00 0x00 0x01
+   0x8003 0x01 0x01 0x2000 0x00 0x00 0x02 0x8003
+   0x02 0x01 0x2000 0x00 0x00 0x03 0x8003 0x03
+   0x01 0x2000 0x00 0x00 0x04 0x8003 0x04 0x01
+   0x2800 0x00 0x00 0x01 0x8003 0x02 0x01 0x2800
+   0x00 0x00 0x02 0x8003 0x03 0x01 0x2800 0x00
+   0x00 0x03 0x8003 0x04 0x01 0x2800 0x00 0x00
+   0x04 0x8003 0x01 0x01 0x3000 0x00 0x00 0x01
+   0x8003 0x03 0x01 0x3000 0x00 0x00 0x02 0x8003
+   0x04 0x01 0x3000 0x00 0x00 0x03 0x8003 0x01
+   0x01 0x3000 0x00 0x00 0x04 0x8003 0x02 0x01
+   0x3800 0x00 0x00 0x01 0x8003 0x04 0x01 0x3800
+   0x00 0x00 0x02 0x8003 0x01 0x01 0x3800 0x00
+   0x00 0x03 0x8003 0x02 0x01 0x3800 0x00 0x00
+   0x04 0x8003 0x03 0x01 0x4000 0x00 0x00 0x01
+   0x8003 0x01 0x01 0x4000 0x00 0x00 0x02 0x8003
+   0x02 0x01 0x4000 0x00 0x00 0x03 0x8003 0x03
+   0x01 0x4000 0x00 0x00 0x04 0x8003 0x04 0x01
+   0x4800 0x00 0x00 0x01 0x8003 0x02 0x01 0x4800
+   0x00 0x00 0x02 0x8003 0x03 0x01 0x4800 0x00
+   0x00 0x03 0x8003 0x04 0x01 0x4800 0x00 0x00
+   0x04 0x8003 0x01 0x01 0x5000 0x00 0x00 0x01
+   0x8003 0x03 0x01 0x5000 0x00 0x00 0x02 0x8003
+   0x04 0x01 0x5000 0x00 0x00 0x03 0x8003 0x01
+   0x01 0x5000 0x00 0x00 0x04 0x8003 0x02 0x01
+   0x5800 0x00 0x00 0x01 0x8003 0x04 0x01 0x5800
+   0x00 0x00 0x02 0x8003 0x01 0x01 0x5800 0x00
+   0x00 0x03 0x8003 0x02 0x01 

[PATCH v5 08/26] arm: rpi: Add a devicetree file for rpi_4

2021-10-25 Thread Simon Glass
Add this file, obtained from the Raspbian boot disk, so there is a
reference devicetree in the U-Boot tree. The same one is used for
32- and 64-bit variants.

Note that U-Boot does not normally need this at runtime, since
CONFIG_OF_BOARD is enabled. The previous firmware stage provides a
devicetree at runtime.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/arm/dts/Makefile|3 +-
 arch/arm/dts/bcm2711-rpi-4-b.dts | 1958 ++
 configs/rpi_4_32b_defconfig  |1 +
 configs/rpi_4_defconfig  |1 +
 configs/rpi_arm64_defconfig  |1 +
 5 files changed, 1963 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/bcm2711-rpi-4-b.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index e70293bb849..f5a02bec4e1 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1068,7 +1068,8 @@ dtb-$(CONFIG_ARCH_BCM283X) += \
bcm2837-rpi-3-a-plus.dtb \
bcm2837-rpi-3-b.dtb \
bcm2837-rpi-3-b-plus.dtb \
-   bcm2837-rpi-cm3-io3.dtb
+   bcm2837-rpi-cm3-io3.dtb \
+   bcm2711-rpi-4-b.dtb
 
 dtb-$(CONFIG_ARCH_BCM63158) += \
bcm963158.dtb
diff --git a/arch/arm/dts/bcm2711-rpi-4-b.dts b/arch/arm/dts/bcm2711-rpi-4-b.dts
new file mode 100644
index 000..425e9fb91c4
--- /dev/null
+++ b/arch/arm/dts/bcm2711-rpi-4-b.dts
@@ -0,0 +1,1958 @@
+// SPDX-License-Identifier: GPL-2.0+ OR MIT
+/*
+ * Sample device tree for rpi_4
+
+ * Copyright 2021 Google LLC
+ */
+
+/dts-v1/;
+
+/memreserve/   0x 0x1000;
+/ {
+   compatible = "raspberrypi,4-model-b\0brcm,bcm2838\0brcm,bcm2837";
+   model = "Raspberry Pi 4 Model B";
+   interrupt-parent = <0x01>;
+   #address-cells = <0x02>;
+   #size-cells = <0x01>;
+
+   aliases {
+   serial0 = "/soc/serial@7e215040";
+   serial1 = "/soc/serial@7e201000";
+   audio = "/soc/audio";
+   aux = "/soc/aux@7e215000";
+   sound = "/soc/sound";
+   soc = "/soc";
+   dma = "/soc/dma@7e007000";
+   watchdog = "/soc/watchdog@7e10";
+   random = "/soc/rng@7e104000";
+   mailbox = "/soc/mailbox@7e00b880";
+   gpio = "/soc/gpio@7e20";
+   uart0 = "/soc/serial@7e201000";
+   sdhost = "/soc/mmc@7e202000";
+   mmc0 = "/soc/emmc2@7e34";
+   i2s = "/soc/i2s@7e203000";
+   spi0 = "/soc/spi@7e204000";
+   i2c0 = "/soc/i2c@7e205000";
+   uart1 = "/soc/serial@7e215040";
+   spi1 = "/soc/spi@7e215080";
+   spi2 = "/soc/spi@7e2150c0";
+   mmc = "/soc/mmc@7e30";
+   mmc1 = "/soc/mmcnr@7e30";
+   i2c1 = "/soc/i2c@7e804000";
+   i2c2 = "/soc/i2c@7e805000";
+   usb = "/soc/usb@7e98";
+   leds = "/leds";
+   fb = "/soc/fb";
+   thermal = "/soc/thermal@7d5d2200";
+   axiperf = "/soc/axiperf";
+   mmc2 = "/soc/mmc@7e202000";
+   ethernet0 = "/scb/genet@7d58";
+   };
+
+   chosen {
+   bootargs = "8250.nr_uarts=1 cma=64M";
+   };
+
+   thermal-zones {
+
+   cpu-thermal {
+   polling-delay-passive = <0x00>;
+   polling-delay = <0x3e8>;
+   thermal-sensors = <0x02>;
+   coefficients = <0xfe19 0x641b8>;
+   phandle = <0x2f>;
+
+   cooling-maps {
+   };
+   };
+   };
+
+   soc {
+   compatible = "simple-bus";
+   #address-cells = <0x01>;
+   #size-cells = <0x01>;
+   ranges = <0x7e00 0x00 0xfe00 0x180
+   0x7c00 0x00 0xfc00 0x200
+   0x4000 0x00 0xff80 0x80>;
+   dma-ranges = <0xc000 0x00 0x00 0x3c00>;
+   phandle = <0x30>;
+
+   txp@7e004000 {
+   compatible = "brcm,bcm2835-txp";
+   reg = <0x7e004000 0x20>;
+   interrupts = <0x00 0x4b 0x04>;
+   status = "disabled";
+   phandle = <0x31>;
+   };
+
+   dma@7e007000 {
+   compatible = "brcm,bcm2835-dma";
+   reg = <0x7e007000 0xb00>;
+   interrupts = <0x00 0x50 0x04 0x00 0x51 0x04 0x00 0x52
+   0x04 0x00 0x53 0x04 0x00 0x54 0x04 0x00
+   0x55 0x04 0x00 0x56 0x04 0x00 0x57 0x04
+   0x00 0x57 0x04 0x00 0x58 0x04 0x00 0x58
+   0x04>;
+   interrupt-names = 
"dma0\0dma1\0dma2\0dma3\0dma4\0dma5\0dma6\0dma7\0dma8\0dma9\0dma10";
+

[PATCH v5 11/26] arm: octeontx: Add a fake devicetree file

2021-10-25 Thread Simon Glass
Add an empty file to prevent build errors when building with
CONFIG_OF_SEPARATE enabled.

Unfortunately there are no build instructions in the U-Boot tree to enable
a real file to be created.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/arm/dts/Makefile|  3 +++
 arch/arm/dts/octeontx.dts| 14 ++
 configs/octeontx2_95xx_defconfig |  1 +
 configs/octeontx2_96xx_defconfig |  1 +
 configs/octeontx_81xx_defconfig  |  1 +
 configs/octeontx_83xx_defconfig  |  1 +
 6 files changed, 21 insertions(+)
 create mode 100644 arch/arm/dts/octeontx.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index a9c76bcf0a9..44835145f4b 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1133,6 +1133,9 @@ dtb-$(CONFIG_ARCH_MEDIATEK) += \
 
 dtb-$(CONFIG_XEN) += xenguest-arm64.dtb
 
+dtb-$(CONFIG_ARCH_OCTEONTX) += octeontx.dtb
+dtb-$(CONFIG_ARCH_OCTEONTX2) += octeontx.dtb
+
 dtb-$(CONFIG_TARGET_GE_BX50V3) += \
imx6q-bx50v3.dtb \
imx6q-b850v3.dtb \
diff --git a/arch/arm/dts/octeontx.dts b/arch/arm/dts/octeontx.dts
new file mode 100644
index 000..60a15f5df23
--- /dev/null
+++ b/arch/arm/dts/octeontx.dts
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Dummy devicetre file for octeontx2 boards
+ *
+ * This is required to make the board build with CONFIG OF_SEPARATE
+ * I could not find any in-tree documentation at all so this is a dummy file.
+ *
+ * Copyright 2021 Google LLC
+ */
+
+/dts-v1/;
+
+/ {
+};
diff --git a/configs/octeontx2_95xx_defconfig b/configs/octeontx2_95xx_defconfig
index 6d8457f1d07..fac4c50aec4 100644
--- a/configs/octeontx2_95xx_defconfig
+++ b/configs/octeontx2_95xx_defconfig
@@ -12,6 +12,7 @@ CONFIG_ENV_SECT_SIZE=0x1
 CONFIG_TARGET_OCTEONTX2_95XX=y
 CONFIG_SYS_MALLOC_LEN=0x4008000
 CONFIG_DM_GPIO=y
+CONFIG_DEFAULT_DEVICE_TREE="octeontx"
 CONFIG_DEBUG_UART_BASE=0x87e02800
 CONFIG_DEBUG_UART_CLOCK=2400
 CONFIG_DEBUG_UART=y
diff --git a/configs/octeontx2_96xx_defconfig b/configs/octeontx2_96xx_defconfig
index b72caef77d8..db883b5542c 100644
--- a/configs/octeontx2_96xx_defconfig
+++ b/configs/octeontx2_96xx_defconfig
@@ -10,6 +10,7 @@ CONFIG_ENV_SECT_SIZE=0x1
 CONFIG_TARGET_OCTEONTX2_96XX=y
 CONFIG_SYS_MALLOC_LEN=0x4008000
 CONFIG_DM_GPIO=y
+CONFIG_DEFAULT_DEVICE_TREE="octeontx"
 CONFIG_DEBUG_UART_BASE=0x87e02800
 CONFIG_DEBUG_UART_CLOCK=2400
 CONFIG_DEBUG_UART=y
diff --git a/configs/octeontx_81xx_defconfig b/configs/octeontx_81xx_defconfig
index 52678d59ff1..8309c29c091 100644
--- a/configs/octeontx_81xx_defconfig
+++ b/configs/octeontx_81xx_defconfig
@@ -12,6 +12,7 @@ CONFIG_ENV_SECT_SIZE=0x1
 CONFIG_TARGET_OCTEONTX_81XX=y
 CONFIG_SYS_MALLOC_LEN=0x4008000
 CONFIG_DM_GPIO=y
+CONFIG_DEFAULT_DEVICE_TREE="octeontx"
 CONFIG_DEBUG_UART_BASE=0x87e02800
 CONFIG_DEBUG_UART_CLOCK=2400
 CONFIG_DEBUG_UART=y
diff --git a/configs/octeontx_83xx_defconfig b/configs/octeontx_83xx_defconfig
index 3890c1e97d4..dae1d4880f8 100644
--- a/configs/octeontx_83xx_defconfig
+++ b/configs/octeontx_83xx_defconfig
@@ -10,6 +10,7 @@ CONFIG_ENV_SECT_SIZE=0x1
 CONFIG_TARGET_OCTEONTX_83XX=y
 CONFIG_SYS_MALLOC_LEN=0x4008000
 CONFIG_DM_GPIO=y
+CONFIG_DEFAULT_DEVICE_TREE="octeontx"
 CONFIG_DEBUG_UART_BASE=0x87e02800
 CONFIG_DEBUG_UART_CLOCK=2400
 CONFIG_DEBUG_UART=y
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v5 02/26] doc: Add documentation about devicetree usage

2021-10-25 Thread Simon Glass
At present some of the ideas and techniques behind devicetree in U-Boot
are assumed, implied or unsaid. Add some documentation to cover how
devicetree is build, how it can be modified and the rules about using
the various CONFIG_OF_... options.

Signed-off-by: Simon Glass 
Reviewed-by: Marcel Ziswiler 
---
This patch attracted quite a bit of discussion here:

https://patchwork.ozlabs.org/project/uboot/patch/20210909201033.755713-4-...@chromium.org/

I have not included the text suggested by François. While I agree that
it would be useful to have an introduction in this space, I do not agree
that we should have two devicetrees or that U-Boot should not have its own
things in the devicetree, so it is not clear to me what we should actually
write.

The 'Devicetree Control in U-Boot' docs were recently merged and these
provide some base info, for now.

Changes in v5:
- Bring into the OF_BOARD series
- Rebase to master and drop mention of OF_PRIOR_STAGE, since removed
- Refer to the 'control' DTB in the first paragraph
- Use QEMU instead of qemu

Changes in v3:
- Clarify the 'bug' refered to at the top
- Reword 'This means that there' paragraph to explain U-Boot-specific things
- Move to doc/develop/devicetree now that OF_CONTROL is in the docs

Changes in v2:
- Fix typos per Sean (thank you!) and a few others
- Add a 'Use of U-Boot /config node' section
- Drop mention of dm-verity since that actually uses the kernel cmdline
- Explain that OF_BOARD will still work after these changes (in
  'Once this bug is fixed...' paragraph)
- Expand a bit on the reason why the 'Current situation' is bad
- Clarify in a second place that Linux and U-Boot use the same devicetree
  in 'To be clear, while U-Boot...'
- Expand on why we should have rules for other projects in
  'Devicetree in another project'
- Add a comment as to why devicetree in U-Boot is not 'bad design'
- Reword 'in-tree U-Boot devicetree' to 'devicetree source in U-Boot'
- Rewrite 'Devicetree generated on-the-fly in another project' to cover
  points raised on v1
- Add 'Why does U-Boot have its nodes and properties?'
- Add 'Why not have two devicetrees?'

 doc/develop/devicetree/dt_update.rst | 556 +++
 doc/develop/devicetree/index.rst |   1 +
 2 files changed, 557 insertions(+)
 create mode 100644 doc/develop/devicetree/dt_update.rst

diff --git a/doc/develop/devicetree/dt_update.rst 
b/doc/develop/devicetree/dt_update.rst
new file mode 100644
index 000..3d4902e3592
--- /dev/null
+++ b/doc/develop/devicetree/dt_update.rst
@@ -0,0 +1,556 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Updating the devicetree
+===
+
+U-Boot uses devicetree for runtime configuration and storing required blobs or
+any other information it needs to operate. This is called the 'control'
+devicetree since it controls U-Boot. It is possible to update the control
+devicetree separately from actually building U-Boot. This provides a good 
degree
+of control and flexibility for firmware that uses U-Boot in conjunction with
+other project.
+
+There are many reasons why it is useful to modify the devicetree after building
+it:
+
+- Configuration can be changed, e.g. which UART to use
+- A serial number can be added
+- Public keys can be added to allow image verification
+- Console output can be changed (e.g. to select serial or vidconsole)
+
+This section describes how to work with devicetree to accomplish your goals.
+
+See also :doc:`../devicetree/control` for a basic summary of the available
+features.
+
+
+Devicetree source
+-
+
+Every board in U-Boot must include a devicetree sufficient to build and boot
+that board on suitable hardware (or emulation). This is specified using the
+`CONFIG DEFAULT_DEVICE_TREE` option.
+
+
+Current situation (October 2021)
+~~
+
+As an aside, at present U-Boot allows `CONFIG_DEFAULT_DEVICE_TREE` to be empty,
+e.g. if `CONFIG_OF_BOARD` is used. This has unfortunately created an enormous
+amount of confusion and some wasted effort. This was not intended. Support for
+an empty `CONFIG_DEFAULT_DEVICE_TREE` will be dropped soon.
+
+Some of the problems created are:
+
+- It is not obvious that the devicetree is coming from another project
+
+- There is no way to see even a sample devicetree for these platform in U-Boot,
+  so it is hard to know what is going on, e.g. which devices are typically
+  present
+
+- The other project may not provide a way to support U-Boot's requirements for
+  devicetree, such as the /config node. Note: On the U-Boot mailing linst, this
+  was only discovered after weeks of discussion and confusion
+
+- For QEMU specifically, consulting two QEMU source files is required, for 
which
+  there are no references in U-Boot documentation. The code is generating a
+  devicetree, but it is not clear what controls affect this generation.
+
+Specifically on the changes in U-Bootm `CONFIG_OF_BOARD` was added in
+rpi_patch_ for Raspberry 

[PATCH v5 10/26] arm: xenguest_arm64: Add a fake devicetree file

2021-10-25 Thread Simon Glass
Add an empty file to prevent build errors when building with
CONFIG_OF_SEPARATE enabled.

The build instructions in U-Boot do not provide enough detail to build a
useful devicetree, unfortunately.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/arm/dts/Makefile|  2 ++
 arch/arm/dts/xenguest-arm64.dts  | 15 +++
 configs/xenguest_arm64_defconfig |  1 +
 3 files changed, 18 insertions(+)
 create mode 100644 arch/arm/dts/xenguest-arm64.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 0be50ecd9c8..a9c76bcf0a9 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1131,6 +1131,8 @@ dtb-$(CONFIG_ARCH_MEDIATEK) += \
mt8516-pumpkin.dtb \
mt8518-ap1-emmc.dtb
 
+dtb-$(CONFIG_XEN) += xenguest-arm64.dtb
+
 dtb-$(CONFIG_TARGET_GE_BX50V3) += \
imx6q-bx50v3.dtb \
imx6q-b850v3.dtb \
diff --git a/arch/arm/dts/xenguest-arm64.dts b/arch/arm/dts/xenguest-arm64.dts
new file mode 100644
index 000..52d3b062248
--- /dev/null
+++ b/arch/arm/dts/xenguest-arm64.dts
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Dummy devicetre file for xenguest_arm64
+ *
+ * This is required to make the board build with CONFIG OF_SEPARATE
+ * Build instructions at xenguest_arm64.rst are inadequate for obtaining a real
+ * devicetree.
+ *
+ * Copyright 2021 Google LLC
+ */
+
+/dts-v1/;
+
+/ {
+};
diff --git a/configs/xenguest_arm64_defconfig b/configs/xenguest_arm64_defconfig
index b72e40a1399..8e32cd63229 100644
--- a/configs/xenguest_arm64_defconfig
+++ b/configs/xenguest_arm64_defconfig
@@ -4,6 +4,7 @@ CONFIG_TARGET_XENGUEST_ARM64=y
 CONFIG_SYS_TEXT_BASE=0x4008
 CONFIG_SYS_MALLOC_F_LEN=0x2000
 CONFIG_SYS_MALLOC_LEN=0x200
+CONFIG_DEFAULT_DEVICE_TREE="xenguest-arm64"
 CONFIG_IDENT_STRING=" xenguest"
 CONFIG_SYS_LOAD_ADDR=0x4000
 CONFIG_BOOTDELAY=10
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v5 06/26] arm: qemu: Add a devicetree file for qemu_arm64

2021-10-25 Thread Simon Glass
Add this file, generated from qemu, so there is a reference devicetree
in the U-Boot tree.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/arm/dts/Makefile|   2 +-
 arch/arm/dts/qemu-arm64.dts  | 381 +++
 configs/qemu_arm64_defconfig |   1 +
 3 files changed, 383 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/qemu-arm64.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 7ab8b145f3f..e70293bb849 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1153,7 +1153,7 @@ dtb-$(CONFIG_TARGET_IMX8MM_CL_IOT_GATE_OPTEE) += 
imx8mm-cl-iot-gate-optee.dtb
 
 dtb-$(CONFIG_TARGET_EA_LPC3250DEVKITV2) += lpc3250-ea3250.dtb
 
-dtb-$(CONFIG_ARCH_QEMU) += qemu-arm.dtb
+dtb-$(CONFIG_ARCH_QEMU) += qemu-arm.dtb qemu-arm64.dtb
 
 targets += $(dtb-y)
 
diff --git a/arch/arm/dts/qemu-arm64.dts b/arch/arm/dts/qemu-arm64.dts
new file mode 100644
index 000..7590e49cc84
--- /dev/null
+++ b/arch/arm/dts/qemu-arm64.dts
@@ -0,0 +1,381 @@
+// SPDX-License-Identifier: GPL-2.0+ OR MIT
+/*
+ * Sample device tree for qemu_arm64
+
+ * Copyright 2021 Google LLC
+ */
+
+/dts-v1/;
+
+/ {
+   interrupt-parent = <0x8001>;
+   #size-cells = <0x02>;
+   #address-cells = <0x02>;
+   compatible = "linux,dummy-virt";
+
+   psci {
+   migrate = <0xc405>;
+   cpu_on = <0xc403>;
+   cpu_off = <0x8402>;
+   cpu_suspend = <0xc401>;
+   method = "hvc";
+   compatible = "arm,psci-0.2\0arm,psci";
+   };
+
+   memory@4000 {
+   reg = <0x00 0x4000 0x00 0x800>;
+   device_type = "memory";
+   };
+
+   platform@c00 {
+   interrupt-parent = <0x8001>;
+   ranges = <0x00 0x00 0xc00 0x200>;
+   #address-cells = <0x01>;
+   #size-cells = <0x01>;
+   compatible = "qemu,platform\0simple-bus";
+   };
+
+   fw-cfg@902 {
+   dma-coherent;
+   reg = <0x00 0x902 0x00 0x18>;
+   compatible = "qemu,fw-cfg-mmio";
+   };
+
+   virtio_mmio@a00 {
+   dma-coherent;
+   interrupts = <0x00 0x10 0x01>;
+   reg = <0x00 0xa00 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a000200 {
+   dma-coherent;
+   interrupts = <0x00 0x11 0x01>;
+   reg = <0x00 0xa000200 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a000400 {
+   dma-coherent;
+   interrupts = <0x00 0x12 0x01>;
+   reg = <0x00 0xa000400 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a000600 {
+   dma-coherent;
+   interrupts = <0x00 0x13 0x01>;
+   reg = <0x00 0xa000600 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a000800 {
+   dma-coherent;
+   interrupts = <0x00 0x14 0x01>;
+   reg = <0x00 0xa000800 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a000a00 {
+   dma-coherent;
+   interrupts = <0x00 0x15 0x01>;
+   reg = <0x00 0xa000a00 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a000c00 {
+   dma-coherent;
+   interrupts = <0x00 0x16 0x01>;
+   reg = <0x00 0xa000c00 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a000e00 {
+   dma-coherent;
+   interrupts = <0x00 0x17 0x01>;
+   reg = <0x00 0xa000e00 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a001000 {
+   dma-coherent;
+   interrupts = <0x00 0x18 0x01>;
+   reg = <0x00 0xa001000 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a001200 {
+   dma-coherent;
+   interrupts = <0x00 0x19 0x01>;
+   reg = <0x00 0xa001200 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a001400 {
+   dma-coherent;
+   interrupts = <0x00 0x1a 0x01>;
+   reg = <0x00 0xa001400 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a001600 {
+   dma-coherent;
+   interrupts = <0x00 0x1b 0x01>;
+   reg = <0x00 0xa001600 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a001800 {
+   dma-coherent;
+   interrupts = <0x00 0x1c 0x01>;
+   reg = <0x00 0xa001800 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a001a00 

[PATCH v5 07/26] riscv: qemu: Add devicetree files for qemu_riscv32/64

2021-10-25 Thread Simon Glass
Add these files, generated from qemu, so there is a reference devicetree
in the U-Boot tree.

Split the existing qemu-virt into two, since we need a different
devicetree for 32- and 64-bit machines.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/riscv/dts/Makefile  |   2 +-
 arch/riscv/dts/qemu-virt.dts |   8 -
 arch/riscv/dts/qemu-virt32.dts   | 217 +++
 arch/riscv/dts/qemu-virt64.dts   | 217 +++
 configs/qemu-riscv32_defconfig   |   1 +
 configs/qemu-riscv32_smode_defconfig |   1 +
 configs/qemu-riscv32_spl_defconfig   |   2 +-
 configs/qemu-riscv64_defconfig   |   1 +
 configs/qemu-riscv64_smode_defconfig |   1 +
 configs/qemu-riscv64_spl_defconfig   |   2 +-
 10 files changed, 441 insertions(+), 11 deletions(-)
 delete mode 100644 arch/riscv/dts/qemu-virt.dts
 create mode 100644 arch/riscv/dts/qemu-virt32.dts
 create mode 100644 arch/riscv/dts/qemu-virt64.dts

diff --git a/arch/riscv/dts/Makefile b/arch/riscv/dts/Makefile
index b6e9166767b..90d3f35e6e3 100644
--- a/arch/riscv/dts/Makefile
+++ b/arch/riscv/dts/Makefile
@@ -2,7 +2,7 @@
 
 dtb-$(CONFIG_TARGET_AX25_AE350) += ae350_32.dtb ae350_64.dtb
 dtb-$(CONFIG_TARGET_MICROCHIP_ICICLE) += microchip-mpfs-icicle-kit.dtb
-dtb-$(CONFIG_TARGET_QEMU_VIRT) += qemu-virt.dtb
+dtb-$(CONFIG_TARGET_QEMU_VIRT) += qemu-virt32.dtb qemu-virt64.dtb
 dtb-$(CONFIG_TARGET_OPENPITON_RISCV64) += openpiton-riscv64.dtb
 dtb-$(CONFIG_TARGET_SIFIVE_UNLEASHED) += hifive-unleashed-a00.dtb
 dtb-$(CONFIG_TARGET_SIFIVE_UNMATCHED) += hifive-unmatched-a00.dtb
diff --git a/arch/riscv/dts/qemu-virt.dts b/arch/riscv/dts/qemu-virt.dts
deleted file mode 100644
index fecff542b91..000
--- a/arch/riscv/dts/qemu-virt.dts
+++ /dev/null
@@ -1,8 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright (C) 2021, Bin Meng 
- */
-
-/dts-v1/;
-
-#include "binman.dtsi"
diff --git a/arch/riscv/dts/qemu-virt32.dts b/arch/riscv/dts/qemu-virt32.dts
new file mode 100644
index 000..3c449413523
--- /dev/null
+++ b/arch/riscv/dts/qemu-virt32.dts
@@ -0,0 +1,217 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2021, Bin Meng 
+ */
+
+/dts-v1/;
+
+#include "binman.dtsi"
+
+/ {
+   #address-cells = <0x02>;
+   #size-cells = <0x02>;
+   compatible = "riscv-virtio";
+   model = "riscv-virtio,qemu";
+
+   fw-cfg@1010 {
+   dma-coherent;
+   reg = <0x00 0x1010 0x00 0x18>;
+   compatible = "qemu,fw-cfg-mmio";
+   };
+
+   flash@2000 {
+   bank-width = <0x04>;
+   reg = <0x00 0x2000 0x00 0x200
+   0x00 0x2200 0x00 0x200>;
+   compatible = "cfi-flash";
+   };
+
+   chosen {
+   bootargs = [00];
+   stdout-path = "/soc/uart@1000";
+   };
+
+   memory@8000 {
+   device_type = "memory";
+   reg = <0x00 0x8000 0x00 0x800>;
+   };
+
+   cpus {
+   #address-cells = <0x01>;
+   #size-cells = <0x00>;
+   timebase-frequency = <0x989680>;
+
+   cpu@0 {
+   phandle = <0x01>;
+   device_type = "cpu";
+   reg = <0x00>;
+   status = "okay";
+   compatible = "riscv";
+   riscv,isa = "rv32imafdcsu";
+   mmu-type = "riscv,sv32";
+
+   interrupt-controller {
+   #interrupt-cells = <0x01>;
+   interrupt-controller;
+   compatible = "riscv,cpu-intc";
+   phandle = <0x02>;
+   };
+   };
+
+   cpu-map {
+
+   cluster0 {
+
+   core0 {
+   cpu = <0x01>;
+   };
+   };
+   };
+   };
+
+   soc {
+   #address-cells = <0x02>;
+   #size-cells = <0x02>;
+   compatible = "simple-bus";
+   ranges;
+
+   rtc@101000 {
+   interrupts = <0x0b>;
+   interrupt-parent = <0x03>;
+   reg = <0x00 0x101000 0x00 0x1000>;
+   compatible = "google,goldfish-rtc";
+   };
+
+   uart@1000 {
+   interrupts = <0x0a>;
+   interrupt-parent = <0x03>;
+   clock-frequency = <0x384000>;
+   reg = <0x00 0x1000 0x00 0x100>;
+   compatible = "ns16550a";
+   };
+
+   poweroff {
+   value = <0x>;
+   offset = <0x00>;
+   regmap = <0x04>;
+

[PATCH v5 05/26] arm: qemu: Add a devicetree file for qemu_arm

2021-10-25 Thread Simon Glass
Add this file, generated from qemu, so there is a reference devicetree
in the U-Boot tree.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/arm/dts/Makefile  |   2 +
 arch/arm/dts/qemu-arm.dts  | 402 +
 configs/qemu_arm_defconfig |   1 +
 3 files changed, 405 insertions(+)
 create mode 100644 arch/arm/dts/qemu-arm.dts

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index a88aecc5bd9..7ab8b145f3f 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1153,6 +1153,8 @@ dtb-$(CONFIG_TARGET_IMX8MM_CL_IOT_GATE_OPTEE) += 
imx8mm-cl-iot-gate-optee.dtb
 
 dtb-$(CONFIG_TARGET_EA_LPC3250DEVKITV2) += lpc3250-ea3250.dtb
 
+dtb-$(CONFIG_ARCH_QEMU) += qemu-arm.dtb
+
 targets += $(dtb-y)
 
 # Add any required device tree compiler flags here
diff --git a/arch/arm/dts/qemu-arm.dts b/arch/arm/dts/qemu-arm.dts
new file mode 100644
index 000..fed558ced98
--- /dev/null
+++ b/arch/arm/dts/qemu-arm.dts
@@ -0,0 +1,402 @@
+// SPDX-License-Identifier: GPL-2.0+ OR MIT
+/*
+ * Sample device tree for qemu_arm
+
+ * Copyright 2021 Google LLC
+ */
+
+/dts-v1/;
+
+/ {
+   interrupt-parent = <0x8001>;
+   #size-cells = <0x02>;
+   #address-cells = <0x02>;
+   compatible = "linux,dummy-virt";
+
+   psci {
+   migrate = <0x8405>;
+   cpu_on = <0x8403>;
+   cpu_off = <0x8402>;
+   cpu_suspend = <0x8401>;
+   method = "hvc";
+   compatible = "arm,psci-0.2\0arm,psci";
+   };
+
+   memory@4000 {
+   reg = <0x00 0x4000 0x00 0x800>;
+   device_type = "memory";
+   };
+
+   platform@c00 {
+   interrupt-parent = <0x8001>;
+   ranges = <0x00 0x00 0xc00 0x200>;
+   #address-cells = <0x01>;
+   #size-cells = <0x01>;
+   compatible = "qemu,platform\0simple-bus";
+   };
+
+   fw-cfg@902 {
+   dma-coherent;
+   reg = <0x00 0x902 0x00 0x18>;
+   compatible = "qemu,fw-cfg-mmio";
+   };
+
+   virtio_mmio@a00 {
+   dma-coherent;
+   interrupts = <0x00 0x10 0x01>;
+   reg = <0x00 0xa00 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a000200 {
+   dma-coherent;
+   interrupts = <0x00 0x11 0x01>;
+   reg = <0x00 0xa000200 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a000400 {
+   dma-coherent;
+   interrupts = <0x00 0x12 0x01>;
+   reg = <0x00 0xa000400 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a000600 {
+   dma-coherent;
+   interrupts = <0x00 0x13 0x01>;
+   reg = <0x00 0xa000600 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a000800 {
+   dma-coherent;
+   interrupts = <0x00 0x14 0x01>;
+   reg = <0x00 0xa000800 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a000a00 {
+   dma-coherent;
+   interrupts = <0x00 0x15 0x01>;
+   reg = <0x00 0xa000a00 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a000c00 {
+   dma-coherent;
+   interrupts = <0x00 0x16 0x01>;
+   reg = <0x00 0xa000c00 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a000e00 {
+   dma-coherent;
+   interrupts = <0x00 0x17 0x01>;
+   reg = <0x00 0xa000e00 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a001000 {
+   dma-coherent;
+   interrupts = <0x00 0x18 0x01>;
+   reg = <0x00 0xa001000 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a001200 {
+   dma-coherent;
+   interrupts = <0x00 0x19 0x01>;
+   reg = <0x00 0xa001200 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a001400 {
+   dma-coherent;
+   interrupts = <0x00 0x1a 0x01>;
+   reg = <0x00 0xa001400 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a001600 {
+   dma-coherent;
+   interrupts = <0x00 0x1b 0x01>;
+   reg = <0x00 0xa001600 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a001800 {
+   dma-coherent;
+   interrupts = <0x00 0x1c 0x01>;
+   reg = <0x00 0xa001800 0x00 0x200>;
+   compatible = "virtio,mmio";
+   };
+
+   virtio_mmio@a001a00 {
+   dma-coherent;
+ 

[PATCH v5 04/26] arm: riscv: qemu: Explain how to extract the generated dt

2021-10-25 Thread Simon Glass
QEMU currently generates a devicetree for use with U-Boot. Explain how to
obtain it.

Also explain how to merge it to produce a devicetree with the U-Boot
features included.

Signed-off-by: Simon Glass 
---

Changes in v5:
- Merge RISC-V and ARM patches since they are similar

 doc/board/emulation/qemu-arm.rst   |  3 ++
 doc/board/emulation/qemu-riscv.rst |  3 ++
 doc/develop/devicetree/dt_qemu.rst | 48 ++
 doc/develop/devicetree/index.rst   |  1 +
 4 files changed, 55 insertions(+)
 create mode 100644 doc/develop/devicetree/dt_qemu.rst

diff --git a/doc/board/emulation/qemu-arm.rst b/doc/board/emulation/qemu-arm.rst
index 97b6ec64905..a39df046fc3 100644
--- a/doc/board/emulation/qemu-arm.rst
+++ b/doc/board/emulation/qemu-arm.rst
@@ -21,6 +21,9 @@ The 'virt' platform provides the following as the basic 
functionality:
 
 Additionally, a number of optional peripherals can be added to the PCI bus.
 
+See :doc:`../../develop/devicetree/dt_qemu` for information on how to see
+the devicetree actually generated by QEMU.
+
 Building U-Boot
 ---
 Set the CROSS_COMPILE environment variable as usual, and run:
diff --git a/doc/board/emulation/qemu-riscv.rst 
b/doc/board/emulation/qemu-riscv.rst
index 4b8e104a215..3409fff8117 100644
--- a/doc/board/emulation/qemu-riscv.rst
+++ b/doc/board/emulation/qemu-riscv.rst
@@ -13,6 +13,9 @@ The QEMU virt machine models a generic RISC-V virtual machine 
with support for
 the VirtIO standard networking and block storage devices. It has CLINT, PLIC,
 16550A UART devices in addition to VirtIO and it also uses device-tree to pass
 configuration information to guest software. It implements RISC-V privileged
+
+See :doc:`../../develop/devicetree/dt_qemu` for information on how to see
+the devicetree actually generated by QEMU.
 architecture spec v1.10.
 
 Building U-Boot
diff --git a/doc/develop/devicetree/dt_qemu.rst 
b/doc/develop/devicetree/dt_qemu.rst
new file mode 100644
index 000..1392a2cae97
--- /dev/null
+++ b/doc/develop/devicetree/dt_qemu.rst
@@ -0,0 +1,48 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Devicetree in QEMU
+==
+
+For QEMU on ARM, RISC-V and one PPC target, the devicetree is created on the
+fly by QEMU. It is intended for use in Linux but can be used by U-Boot also,
+so long as any nodes/properties needed by U-Boot are merged in.
+
+When `CONFIG_OF_BOARD` is enabled
+
+
+Obtaining the QEMU devicetree
+-
+
+Where QEMU generates its own devicetree to pass to U-Boot tou can use
+`-dtb u-boot.dtb` to force QEMU to use U-Boot's in-tree version.
+
+To obtain the devicetree that qemu generates, add `-machine dumpdtb=qemu.dtb`,
+e.g.::
+
+qemu-system-arm -machine virt -machine dumpdtb=qemu.dtb
+
+qemu-system-aarch64 -machine virt -machine dumpdtb=qemu.dtb
+
+qemu-system-riscv64 -machine virt -machine dumpdtb=qemu.dtb
+
+
+Merging in U-Boot nodes/properties
+--
+
+Various U-Boot features require nodes and properties in the U-Boot devicetree
+and at present QEMU is unaware of these. To use these you must manually merge
+in the appropriate pieces.
+
+One way to do this is with dtc. This command runs dtc on each .dtb file in 
turn,
+to produce a text file. It drops the duplicate header on the qemu one. Then it
+joins them up and runs them through dtc to compile the output::
+
+qemu-system-arm -machine virt -machine dumpdtb=qemu.dtb
+cat  <(dtc -I dtb qemu.dtb) <(dtc -I dtb  u-boot.dtb |grep -v /dts-v1/) 
|dtc - -o merged.dtb
+
+You can then run qemu with the merged devicetree, e.g.::
+
+qemu-system-arm -machine virt -nographic -bios u-boot.bin -dtb merged.dtb
+
+Note that there seems to be a bug in some versions of qemu where the output of
+dumpdtb does not quite match what is provided to U-Boot.
diff --git a/doc/develop/devicetree/index.rst b/doc/develop/devicetree/index.rst
index b5b33dfea0f..fc2fb41b1bb 100644
--- a/doc/develop/devicetree/index.rst
+++ b/doc/develop/devicetree/index.rst
@@ -12,3 +12,4 @@ build-time and runtime configuration.
intro
control
dt_update
+   dt_qemu
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v5 03/26] arm: qemu: Mention -nographic in the docs

2021-10-25 Thread Simon Glass
Without this option QEMU appears to hang. Add it to avoid confusion.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 doc/board/emulation/qemu-arm.rst | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/doc/board/emulation/qemu-arm.rst b/doc/board/emulation/qemu-arm.rst
index 8d7fda10f15..97b6ec64905 100644
--- a/doc/board/emulation/qemu-arm.rst
+++ b/doc/board/emulation/qemu-arm.rst
@@ -41,14 +41,15 @@ The minimal QEMU command line to get U-Boot up and running 
is:
 
 - For ARM::
 
-qemu-system-arm -machine virt -bios u-boot.bin
+qemu-system-arm -machine virt -nographic -bios u-boot.bin
 
 - For AArch64::
 
-qemu-system-aarch64 -machine virt -cpu cortex-a57 -bios u-boot.bin
+qemu-system-aarch64 -machine virt -nographic -cpu cortex-a57 -bios 
u-boot.bin
 
 Note that for some odd reason qemu-system-aarch64 needs to be explicitly
-told to use a 64-bit CPU or it will boot in 32-bit mode.
+told to use a 64-bit CPU or it will boot in 32-bit mode. The -nographic 
argument
+ensures that output appears on the terminal. Use Ctrl-A X to quit.
 
 Additional persistent U-boot environment support can be added as follows:
 
-- 
2.33.0.1079.g6e70778dc9-goog



[PATCH v5 01/26] sandbox: Remove OF_HOSTFILE

2021-10-25 Thread Simon Glass
From: Ilias Apalodimas 

OF_HOSTFILE is used on sandbox configs only.  Although it's pretty
unique not a source of any confusions,  we are better of having simple
config options for the DTB.
So let's replace that with the existing OF_BOARD.  This will make U-Boot
have only three different config options for the DTB origin.
- OF_SEPARATE, build separately from U-Boot
- OF_BOARD, board specific way of providing the DTB
- OF_EMBED embedded in the u-boot binary, but discouraged from being used
  in production

Signed-off-by: Ilias Apalodimas 
Signed-off-by: Simon Glass 
---

(no changes since v1)

 Makefile  |  6 +++---
 arch/sandbox/cpu/cpu.c| 21 -
 arch/sandbox/include/asm/u-boot-sandbox.h |  8 
 configs/sandbox64_defconfig   |  2 +-
 configs/sandbox_defconfig |  2 +-
 configs/sandbox_flattree_defconfig|  2 +-
 configs/sandbox_noinst_defconfig  |  2 +-
 configs/sandbox_spl_defconfig |  2 +-
 configs/tools-only_defconfig  |  2 +-
 doc/develop/devicetree/control.rst|  7 +++
 dts/Kconfig   |  9 -
 lib/fdtdec.c  |  5 -
 scripts/Makefile.spl  |  4 ++--
 13 files changed, 26 insertions(+), 46 deletions(-)

diff --git a/Makefile b/Makefile
index 5194e4dc782..c0ea933cb63 100644
--- a/Makefile
+++ b/Makefile
@@ -947,7 +947,7 @@ INPUTS-$(CONFIG_BINMAN_STANDALONE_FDT) += u-boot.dtb
 ifeq ($(CONFIG_SPL_FRAMEWORK),y)
 INPUTS-$(CONFIG_OF_SEPARATE) += u-boot-dtb.img
 endif
-INPUTS-$(CONFIG_OF_HOSTFILE) += u-boot.dtb
+INPUTS-$(CONFIG_SANDBOX) += u-boot.dtb
 ifneq ($(CONFIG_SPL_TARGET),)
 INPUTS-$(CONFIG_SPL) += $(CONFIG_SPL_TARGET:"%"=%)
 endif
@@ -1407,7 +1407,7 @@ u-boot-lzma.img: u-boot.bin.lzma FORCE
 
 u-boot-dtb.img u-boot.img u-boot.kwb u-boot.pbl u-boot-ivt.img: \
$(if $(CONFIG_SPL_LOAD_FIT),u-boot-nodtb.bin \
-   $(if 
$(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_OF_HOSTFILE)$(CONFIG_BINMAN_STANDALONE_FDT),dts/dt.dtb)
 \
+   $(if 
$(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_SANDBOX)$(CONFIG_BINMAN_STANDALONE_FDT),dts/dt.dtb)
 \
,$(UBOOT_BIN)) FORCE
$(call if_changed,mkimage)
$(BOARD_SIZE_CHECK)
@@ -1421,7 +1421,7 @@ MKIMAGEFLAGS_u-boot.itb += -B 0x8
 
 ifdef U_BOOT_ITS
 u-boot.itb: u-boot-nodtb.bin \
-   $(if 
$(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_OF_HOSTFILE),dts/dt.dtb) \
+   $(if 
$(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_SANDBOX),dts/dt.dtb) \
$(U_BOOT_ITS) FORCE
$(call if_changed,mkfitimage)
$(BOARD_SIZE_CHECK)
diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c
index 48636ab6391..bc67a5a5a10 100644
--- a/arch/sandbox/cpu/cpu.c
+++ b/arch/sandbox/cpu/cpu.c
@@ -291,44 +291,47 @@ void invalidate_dcache_range(unsigned long start, 
unsigned long stop)
 {
 }
 
-int sandbox_read_fdt_from_file(void)
+void *board_fdt_blob_setup(void)
 {
struct sandbox_state *state = state_get_current();
const char *fname = state->fdt_fname;
-   void *blob;
+   void *blob = NULL;
loff_t size;
int err;
int fd;
 
+   printf("SETUP BLOB\n");
blob = map_sysmem(CONFIG_SYS_FDT_LOAD_ADDR, 0);
if (!state->fdt_fname) {
err = fdt_create_empty_tree(blob, 256);
if (!err)
goto done;
printf("Unable to create empty FDT: %s\n", fdt_strerror(err));
-   return -EINVAL;
+   goto fail;
}
 
err = os_get_filesize(fname, );
if (err < 0) {
printf("Failed to file FDT file '%s'\n", fname);
-   return err;
+   goto fail;
}
fd = os_open(fname, OS_O_RDONLY);
if (fd < 0) {
printf("Failed to open FDT file '%s'\n", fname);
-   return -EACCES;
+   goto fail;
}
+
if (os_read(fd, blob, size) != size) {
os_close(fd);
-   return -EIO;
+   printf("Failed to read file '%s'\n", fname);
+   goto fail;
}
os_close(fd);
 
 done:
-   gd->fdt_blob = blob;
-
-   return 0;
+   return blob;
+fail:
+   return NULL;
 }
 
 ulong timer_get_boot_us(void)
diff --git a/arch/sandbox/include/asm/u-boot-sandbox.h 
b/arch/sandbox/include/asm/u-boot-sandbox.h
index 73b1897191d..56dc13c3eb1 100644
--- a/arch/sandbox/include/asm/u-boot-sandbox.h
+++ b/arch/sandbox/include/asm/u-boot-sandbox.h
@@ -76,14 +76,6 @@ int pci_unmap_physmem(const void *addr, unsigned long len,
  */
 void sandbox_set_enable_pci_map(int enable);
 
-/**
- * sandbox_read_fdt_from_file() - Read a device tree from a file
- *
- * Read a device tree file from a host file and set it up for use as the
- * control FDT.
- */
-int 

[PATCH v5 00/26] fdt: Make OF_BOARD a boolean option

2021-10-25 Thread Simon Glass
With Ilias' efforts we have dropped OF_PRIOR_STAGE and OF_HOSTFILE so
there are only three ways to obtain a devicetree:

   - OF_SEPARATE - the normal way, where the devicetree is built and
  appended to U-Boot
   - OF_EMBED - for development purposes, the devicetree is embedded in
  the ELF file (also used for EFI)
   - OF_BOARD - the board figures it out on its own

The last one is currently set up so that no devicetree is needed at all
in the U-Boot tree. Most boards do provide one, but some don't. Some
don't even provide instructions on how to boot on the board.

The problems with this approach are documented in another patch in this
series: "doc: Add documentation about devicetree usage"

In practice, OF_BOARD is not really distinct from OF_SEPARATE. Any board
can obtain its devicetree at runtime, even it is has a devicetree built
in U-Boot. This is because U-Boot may be a second-stage bootloader and its
caller may have a better idea about the hardware available in the machine.
This is the case with a few QEMU boards, for example.

So it makes no sense to have OF_BOARD as a 'choice'. It should be an
option, available with either OF_SEPARATE or OF_EMBED.

This series makes this change, adding various missing devicetree files
(and placeholders) to make the build work.

Note: If board maintainers are able to add their own patch to add the
files, some patches in this series can be dropped.

It also provides a few qemu clean-ups discovered along the way.

Note: This breaks the qemu-riscv64_spl test, which still needs
investigation.

[1] 
https://patchwork.ozlabs.org/project/uboot/patch/20210919215111.3830278-3-...@chromium.org/

Changes in v5:
- Bring into the OF_BOARD series
- Rebase to master and drop mention of OF_PRIOR_STAGE, since removed
- Refer to the 'control' DTB in the first paragraph
- Use QEMU instead of qemu
- Merge RISC-V and ARM patches since they are similar
- Add new patches to clean up fdtdec_setup() and surrounds

Changes in v3:
- Clarify the 'bug' refered to at the top
- Reword 'This means that there' paragraph to explain U-Boot-specific things
- Move to doc/develop/devicetree now that OF_CONTROL is in the docs

Changes in v2:
- Fix typos per Sean (thank you!) and a few others
- Add a 'Use of U-Boot /config node' section
- Drop mention of dm-verity since that actually uses the kernel cmdline
- Explain that OF_BOARD will still work after these changes (in
  'Once this bug is fixed...' paragraph)
- Expand a bit on the reason why the 'Current situation' is bad
- Clarify in a second place that Linux and U-Boot use the same devicetree
  in 'To be clear, while U-Boot...'
- Expand on why we should have rules for other projects in
  'Devicetree in another project'
- Add a comment as to why devicetree in U-Boot is not 'bad design'
- Reword 'in-tree U-Boot devicetree' to 'devicetree source in U-Boot'
- Rewrite 'Devicetree generated on-the-fly in another project' to cover
  points raised on v1
- Add 'Why does U-Boot have its nodes and properties?'
- Add 'Why not have two devicetrees?'

Ilias Apalodimas (1):
  sandbox: Remove OF_HOSTFILE

Simon Glass (25):
  doc: Add documentation about devicetree usage
  arm: qemu: Mention -nographic in the docs
  arm: riscv: qemu: Explain how to extract the generated dt
  arm: qemu: Add a devicetree file for qemu_arm
  arm: qemu: Add a devicetree file for qemu_arm64
  riscv: qemu: Add devicetree files for qemu_riscv32/64
  arm: rpi: Add a devicetree file for rpi_4
  arm: vexpress: Add a devicetree file for juno
  arm: xenguest_arm64: Add a fake devicetree file
  arm: octeontx: Add a fake devicetree file
  arm: xilinx_versal_virt: Add a devicetree file
  arm: bcm7xxx: Add a devicetree file
  arm: qemu-ppce500: Add a devicetree file
  arm: highbank: Add a fake devicetree file
  fdt: Make OF_BOARD a bool option
  Drop CONFIG_BINMAN_STANDALONE_FDT
  doc: Update info on devicetree update
  fdt: Move MULTI_DTB_FIT handling out of fdtdec_setup()
  fdt: Drop #ifdefs with MULTI_DTB_FIT
  fdt: Drop CONFIG_SPL_BUILD check in fdtdec_setup()
  fdt: Drop #ifdef around board_fdt_blob_setup()
  fdt: Use if() for fdtcontroladdr check
  fdt: Drop OF_CONTROL check in fdtdec_setup()
  fdt: Drop remaining preprocessor macros in fdtdec_setup()
  fdt: Don't call board_fdt_blob_setup() without OF_BOARD

 Makefile  |7 +-
 arch/arm/dts/Makefile |   20 +-
 arch/arm/dts/bcm2711-rpi-4-b.dts  | 1958 +
 arch/arm/dts/bcm7xxx.dts  |   15 +
 arch/arm/dts/highbank.dts |   14 +
 arch/arm/dts/juno-r2.dts  | 1038 +++
 arch/arm/dts/octeontx.dts |   14 +
 arch/arm/dts/qemu-arm.dts |  402 +
 arch/arm/dts/qemu-arm64.dts   |  381 
 arch/arm/dts/xenguest-arm64.dts   |   15 +
 arch/arm/dts/xilinx-versal-virt.dts   |  307 
 arch/powerpc/dts/Makefile |1 +
 

[PATCH v3 2/2] cmd: brcm: netXtreme commands

2021-10-25 Thread Roman Bacik
From: Bharat Gooty 

Following netXtreme commands are supported:
probe, remove.

Signed-off-by: Bharat Gooty 

Signed-off-by: Roman Bacik 
---

Changes in v3:
- remove commands set/get mac/speed
- add doc/bnxt.rst

 cmd/Kconfig   |  2 +
 cmd/broadcom/Kconfig  | 10 +
 cmd/broadcom/Makefile |  3 +-
 cmd/broadcom/bnxt.c   | 97 +++
 doc/usage/bnxt.rst| 35 
 doc/usage/index.rst   |  1 +
 6 files changed, 147 insertions(+), 1 deletion(-)
 create mode 100644 cmd/broadcom/Kconfig
 create mode 100644 cmd/broadcom/bnxt.c
 create mode 100644 doc/usage/bnxt.rst

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 5b30b13e438f..e054292dbcd0 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1953,6 +1953,8 @@ endmenu
 
 source "cmd/ti/Kconfig"
 
+source "cmd/broadcom/Kconfig"
+
 config CMD_BOOTSTAGE
bool "Enable the 'bootstage' command"
depends on BOOTSTAGE
diff --git a/cmd/broadcom/Kconfig b/cmd/broadcom/Kconfig
new file mode 100644
index ..6f16b09d1425
--- /dev/null
+++ b/cmd/broadcom/Kconfig
@@ -0,0 +1,10 @@
+menu "Broadcom specific command line interface"
+
+config BNXT_ETH_CMD
+   bool "BNXT commands"
+   depends on BNXT_ETH
+   help
+ Broadcom NXS ethernet controller commands. Commands supported are:-
+ Driver probe, Driver remove, Supported speeds, get/set MAC address 
and get/set Link speeds.
+
+endmenu
diff --git a/cmd/broadcom/Makefile b/cmd/broadcom/Makefile
index 62268d98d0dd..0027c1c15e5a 100644
--- a/cmd/broadcom/Makefile
+++ b/cmd/broadcom/Makefile
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0+
-# Copyright 2020 Broadcom
+# Copyright 2020-2021 Broadcom
 
 obj-y += chimp_boot.o
 obj-y += nitro_image_load.o
 obj-y += chimp_handshake.o
+obj-$(CONFIG_BNXT_ETH_CMD) += bnxt.o
diff --git a/cmd/broadcom/bnxt.c b/cmd/broadcom/bnxt.c
new file mode 100644
index ..ddc2ceb98863
--- /dev/null
+++ b/cmd/broadcom/bnxt.c
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2021 Broadcom
+ */
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int print_drv(u8 flag)
+{
+   printf("bnxt - Device ");
+   if (flag)
+   printf("already");
+   else
+   printf("not");
+
+   printf(" initialized\n");
+
+   return CMD_RET_SUCCESS;
+}
+
+static int bnxt_parse_input(int argc, char *const argv[])
+{
+   if (!strcmp(argv[2], "probe"))
+   return CMD_PROBE;
+   else if (!strcmp(argv[2], "remove"))
+   return CMD_REMOVE;
+
+   return CMD_UNKNOWN;
+}
+
+static int do_bnxt(struct cmd_tbl *cmdtp, int flag, int argc, char *const 
argv[])
+{
+   struct udevice *dev;
+   struct bnxt *bp;
+   char name[30];
+   int ret = CMD_RET_USAGE;
+   int cardnum;
+   int op;
+
+   printf("\n");
+   if (argc < 2)
+   return ret;
+
+   cardnum = simple_strtoul(argv[1], NULL, 10);
+   sprintf(name, "bnxt_eth%u", cardnum);
+   ret = uclass_get_device_by_name(UCLASS_ETH, name, );
+   if (ret)
+   return CMD_RET_USAGE;
+
+   bp = dev_get_priv(dev);
+   op = bnxt_parse_input(argc, argv);
+   ret = CMD_RET_USAGE;
+   switch (op) {
+   case CMD_PROBE:
+   if (!bp->drv_load)
+   ret = bnxt_drv_probe(dev);
+   else
+   ret = print_drv(1);
+   break;
+   case CMD_REMOVE:
+   ret = bnxt_drv_remove(dev);
+   break;
+   default:
+   if (op && !bp->drv_load)
+   ret = print_drv(0);
+   }
+
+   printf("\n");
+
+   return ret;
+}
+
+U_BOOT_CMD
+   (bnxt, 5, 1, do_bnxt,
+   "Broadcom NetXtreme-C/E Management",
+   /* */" probe\n"
+   " - Load Driver Instance.\n"
+   "bnxt  remove\n"
+   " - Unload Driver Instance.\n"
+);
diff --git a/doc/usage/bnxt.rst b/doc/usage/bnxt.rst
new file mode 100644
index ..4b0b7b22411a
--- /dev/null
+++ b/doc/usage/bnxt.rst
@@ -0,0 +1,35 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+bnxt command
+
+
+Synopsis
+
+
+::
+
+bnxt bnxt_eth# probe
+bnxt bnxt_eth# remove
+
+Description
+---
+
+The bnxt commands are used to load and unload the bnxt driver. The probe loads 
and remove unloads the driver.
+
+Example
+---
+
+::
+
+=> bnxt 0 probe
+=> bnxt 0 remove
+
+Configuration
+-
+
+The bnxt commands are only available if CONFIG_CMD_BNXT=y.
+
+Return value
+
+
+The return value $? is 0 if successful and nonzero error code if the command 
fails.
diff --git a/doc/usage/index.rst b/doc/usage/index.rst
index 356f2a56181b..834e8d274646 100644
--- a/doc/usage/index.rst
+++ b/doc/usage/index.rst
@@ -20,6 +20,7 @@ Shell commands
   

Re: [PATCH] introduce CONFIG_DEVICE_TREE_INCLUDES

2021-10-25 Thread Sean Anderson

Hi Roman,

On 9/28/21 5:55 AM, Roman Kopytin wrote:

Hi, all
I prepared 3 patches for fdt_add_pubkey adding.
But in our company infrastructure I can't use git send-email. Our IT can't help 
me to resolve issue.


It appears that Linux offers email hosting [1] for this purpose. However,
you need to already be a kernel developer. So you best choice may be
GMail.

--Sean

[1] https://korg.docs.kernel.org/linuxdev.html


[PATCH 1/1] env: superfluous check before free()

2021-10-25 Thread Heinrich Schuchardt
Free() checks if its argument in NULL. There is no need for the caller to
do the same.

Signed-off-by: Heinrich Schuchardt 
---
 env/flash.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/env/flash.c b/env/flash.c
index ebee9069e4..473e82454d 100644
--- a/env/flash.c
+++ b/env/flash.c
@@ -210,8 +210,7 @@ static int env_flash_save(void)
 perror:
flash_perror(rc);
 done:
-   if (saved_data)
-   free(saved_data);
+   free(saved_data);
/* try to re-protect */
flash_sect_protect(1, (ulong)flash_addr, end_addr);
flash_sect_protect(1, (ulong)flash_addr_new, end_addr_new);
@@ -298,8 +297,7 @@ static int env_flash_save(void)
 perror:
flash_perror(rc);
 done:
-   if (saved_data)
-   free(saved_data);
+   free(saved_data);
/* try to re-protect */
flash_sect_protect(1, (long)flash_addr, end_addr);
return rc;
-- 
2.32.0



[PATCH] dfu: Sort Kconfig entries alphabetically

2021-10-25 Thread Marek Vasut
The DFU_MTD Kconfig entry is in the wrong position, move it into the
correct alphabetically sorted position. No functional change.

Signed-off-by: Marek Vasut 
Cc: Lukasz Majewski 
Cc: Patrice Chotard 
Cc: Patrick Delaunay 
---
 drivers/dfu/Kconfig | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/dfu/Kconfig b/drivers/dfu/Kconfig
index 48e41bc2629..8d7f13dcb0b 100644
--- a/drivers/dfu/Kconfig
+++ b/drivers/dfu/Kconfig
@@ -38,6 +38,13 @@ config DFU_MMC
help
  This option enables using DFU to read and write to MMC based storage.
 
+config DFU_MTD
+   bool "MTD back end for DFU"
+   depends on DM_MTD
+   depends on CMD_MTDPARTS
+   help
+ This option enables using DFU to read and write to on any MTD device.
+
 config DFU_NAND
bool "NAND back end for DFU"
depends on CMD_MTDPARTS
@@ -72,13 +79,6 @@ config DFU_SF_PART
  This option enables the support of "part" and "partubi" target in
  SPI flash DFU back end.
 
-config DFU_MTD
-   bool "MTD back end for DFU"
-   depends on DM_MTD
-   depends on CMD_MTDPARTS
-   help
- This option enables using DFU to read and write to on any MTD device.
-
 config DFU_VIRT
bool "VIRTUAL flash back end for DFU"
help
-- 
2.33.0



  1   2   3   >