Merge tag 'arc-fixes-for-2020.01-rc2' of https://gitlab.denx.de/u-boot/custodians/u-boot-arc

ARC fixes for v2020.01-rc2

The main change is move to DM_MMC of yet 2 another ARC boards:
AXS101 & IoTDK.

Among that we improve handling of stock-formatted SD-cards of high volume
on EM SDP as well as introduction of reset driver for HSDK which is required
for prepser reinitialization of some peripherals like USB etc.
diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml
index 11d5a61..862cced 100644
--- a/.azure-pipelines.yml
+++ b/.azure-pipelines.yml
@@ -265,7 +265,7 @@
           . /tmp/venv/bin/activate
           pip install -r test/py/requirements.txt
           export UBOOT_TRAVIS_BUILD_DIR=/tmp/.bm-work/${TEST_PY_BD};
-          export PATH=/opt/qemu/bin:/tmp/uboot-test-hooks/bin:/usr/bin:/bin;
+          export PATH=/opt/qemu/bin:/tmp/uboot-test-hooks/bin:${PATH};
           export PYTHONPATH=/tmp/uboot-test-hooks/py/travis-ci;
           if [[ "${TEST_PY_BD}" != "" ]]; then
               ./test/py/test.py --bd ${TEST_PY_BD} ${TEST_PY_ID} -k "${TEST_PY_TEST_SPEC:-not a_test_which_does_not_exist}" --build-dir "$UBOOT_TRAVIS_BUILD_DIR";
diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c
index 2046cb5..f3af88d 100644
--- a/arch/sandbox/cpu/cpu.c
+++ b/arch/sandbox/cpu/cpu.c
@@ -246,8 +246,7 @@
 	return 0;
 }
 
-void sandbox_write(const void *addr, unsigned int val,
-		   enum sandboxio_size_t size)
+void sandbox_write(void *addr, unsigned int val, enum sandboxio_size_t size)
 {
 	struct sandbox_state *state = state_get_current();
 
diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h
index 4a35c41..ad6c29a 100644
--- a/arch/sandbox/include/asm/io.h
+++ b/arch/sandbox/include/asm/io.h
@@ -46,8 +46,7 @@
 phys_addr_t map_to_sysmem(const void *ptr);
 
 unsigned int sandbox_read(const void *addr, enum sandboxio_size_t size);
-void sandbox_write(const void *addr, unsigned int val,
-		   enum sandboxio_size_t size);
+void sandbox_write(void *addr, unsigned int val, enum sandboxio_size_t size);
 
 #define readb(addr) sandbox_read((const void *)addr, SB_SIZE_8)
 #define readw(addr) sandbox_read((const void *)addr, SB_SIZE_16)
@@ -55,11 +54,11 @@
 #ifdef CONFIG_SANDBOX64
 #define readq(addr) sandbox_read((const void *)addr, SB_SIZE_64)
 #endif
-#define writeb(v, addr) sandbox_write((const void *)addr, v, SB_SIZE_8)
-#define writew(v, addr) sandbox_write((const void *)addr, v, SB_SIZE_16)
-#define writel(v, addr) sandbox_write((const void *)addr, v, SB_SIZE_32)
+#define writeb(v, addr) sandbox_write((void *)addr, v, SB_SIZE_8)
+#define writew(v, addr) sandbox_write((void *)addr, v, SB_SIZE_16)
+#define writel(v, addr) sandbox_write((void *)addr, v, SB_SIZE_32)
 #ifdef CONFIG_SANDBOX64
-#define writeq(v, addr) sandbox_write((const void *)addr, v, SB_SIZE_64)
+#define writeq(v, addr) sandbox_write((void *)addr, v, SB_SIZE_64)
 #endif
 
 /*
diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h
index cd2b9e3..b885e1a 100644
--- a/arch/sandbox/include/asm/test.h
+++ b/arch/sandbox/include/asm/test.h
@@ -213,4 +213,15 @@
  */
 uint sandbox_pci_read_bar(u32 barval, int type, uint size);
 
+/**
+ * sandbox_set_enable_memio() - Enable readl/writel() for sandbox
+ *
+ * Normally these I/O functions do nothing with sandbox. Certain tests need them
+ * to work as for other architectures, so this function can be used to enable
+ * them.
+ *
+ * @enable: true to enable, false to disable
+ */
+void sandbox_set_enable_memio(bool enable);
+
 #endif
diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index 1cb0bc1..99a3bc5 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -1387,7 +1387,7 @@
 #endif
 	"env print [-a | name ...] - print environment\n"
 #if defined(CONFIG_CMD_NVEDIT_EFI)
-	"env print -e [name ...] - print UEFI environment\n"
+	"env print -e [-guid guid|-all][-n] [name ...] - print UEFI environment\n"
 #endif
 #if defined(CONFIG_CMD_RUN)
 	"env run var [...] - run commands in an environment variable\n"
@@ -1399,7 +1399,8 @@
 #endif
 #endif
 #if defined(CONFIG_CMD_NVEDIT_EFI)
-	"env set -e name [arg ...] - set UEFI variable; unset if 'arg' not specified\n"
+	"env set -e [-nv][-bs][-rt][-a][-i addr,size][-v] name [arg ...]\n"
+	"    - set UEFI variable; unset if '-i' or 'arg' not specified\n"
 #endif
 	"env set [-f] name [arg ...]\n";
 #endif
@@ -1428,8 +1429,9 @@
 	"print environment variables",
 	"[-a]\n    - print [all] values of all environment variables\n"
 #if defined(CONFIG_CMD_NVEDIT_EFI)
-	"printenv -e [name ...]\n"
+	"printenv -e [-guid guid|-all][-n] [name ...]\n"
 	"    - print UEFI variable 'name' or all the variables\n"
+	"      \"-n\": suppress dumping variable's value\n"
 #endif
 	"printenv name ...\n"
 	"    - print value of environment variable 'name'",
@@ -1459,9 +1461,16 @@
 	setenv, CONFIG_SYS_MAXARGS, 0,	do_env_set,
 	"set environment variables",
 #if defined(CONFIG_CMD_NVEDIT_EFI)
-	"-e [-nv] name [value ...]\n"
+	"-e [-guid guid][-nv][-bs][-rt][-a][-v]\n"
+	"        [-i addr,size name], or [name [value ...]]\n"
 	"    - set UEFI variable 'name' to 'value' ...'\n"
-	"      'nv' option makes the variable non-volatile\n"
+	"      \"-guid\": set vendor guid\n"
+	"      \"-nv\": set non-volatile attribute\n"
+	"      \"-bs\": set boot-service attribute\n"
+	"      \"-rt\": set runtime attribute\n"
+	"      \"-a\": append-write\n"
+	"      \"-i addr,size\": use <addr,size> as variable's value\n"
+	"      \"-v\": verbose message\n"
 	"    - delete UEFI variable 'name' if 'value' not specified\n"
 #endif
 	"setenv [-f] name value ...\n"
diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c
index ede4cd5..8ea0da0 100644
--- a/cmd/nvedit_efi.c
+++ b/cmd/nvedit_efi.c
@@ -13,6 +13,7 @@
 #include <exports.h>
 #include <hexdump.h>
 #include <malloc.h>
+#include <mapmem.h>
 #include <linux/kernel.h>
 
 /*
@@ -34,15 +35,49 @@
 	{EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS, "AT"},
 };
 
+static const struct {
+	efi_guid_t guid;
+	char *text;
+} efi_guid_text[] = {
+	/* signature database */
+	{EFI_GLOBAL_VARIABLE_GUID, "EFI_GLOBAL_VARIABLE_GUID"},
+};
+
+/* "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" */
+static char unknown_guid[37];
+
+/**
+ * efi_guid_to_str() - convert guid to readable name
+ *
+ * @guid:	GUID
+ * Return:	string for GUID
+ *
+ * convert guid to readable name
+ */
+static const char *efi_guid_to_str(const efi_guid_t *guid)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(efi_guid_text); i++)
+		if (!guidcmp(guid, &efi_guid_text[i].guid))
+			return efi_guid_text[i].text;
+
+	uuid_bin_to_str((unsigned char *)guid->b, unknown_guid,
+			UUID_STR_FORMAT_GUID);
+
+	return unknown_guid;
+}
+
 /**
  * efi_dump_single_var() - show information about a UEFI variable
  *
  * @name:	Name of the variable
  * @guid:	Vendor GUID
+ * @verbose:	if true, dump data
  *
  * Show information encoded in one UEFI variable
  */
-static void efi_dump_single_var(u16 *name, efi_guid_t *guid)
+static void efi_dump_single_var(u16 *name, const efi_guid_t *guid, bool verbose)
 {
 	u32 attributes;
 	u8 *data;
@@ -68,7 +103,7 @@
 	if (ret != EFI_SUCCESS)
 		goto out;
 
-	printf("%ls:", name);
+	printf("%ls:\n    %s:", name, efi_guid_to_str(guid));
 	for (count = 0, i = 0; i < ARRAY_SIZE(efi_var_attrs); i++)
 		if (attributes & efi_var_attrs[i].mask) {
 			if (count)
@@ -79,7 +114,9 @@
 			puts(efi_var_attrs[i].text);
 		}
 	printf(", DataSize = 0x%zx\n", size);
-	print_hex_dump("    ", DUMP_PREFIX_OFFSET, 16, 1, data, size, true);
+	if (verbose)
+		print_hex_dump("    ", DUMP_PREFIX_OFFSET, 16, 1,
+			       data, size, true);
 
 out:
 	free(data);
@@ -90,11 +127,13 @@
  *
  * @argc:	Number of arguments (variables)
  * @argv:	Argument (variable name) array
+ * @verbose:	if true, dump data
  * Return:	CMD_RET_SUCCESS on success, or CMD_RET_RET_FAILURE
  *
  * Show information encoded in named UEFI variables
  */
-static int efi_dump_vars(int argc,  char * const argv[])
+static int efi_dump_vars(int argc,  char * const argv[],
+			 const efi_guid_t *guid, bool verbose)
 {
 	u16 *var_name16, *p;
 	efi_uintn_t buf_size, size;
@@ -119,8 +158,7 @@
 		p = var_name16;
 		utf8_utf16_strcpy(&p, argv[0]);
 
-		efi_dump_single_var(var_name16,
-				    (efi_guid_t *)&efi_global_variable_guid);
+		efi_dump_single_var(var_name16, guid, verbose);
 	}
 
 	free(var_name16);
@@ -128,20 +166,56 @@
 	return CMD_RET_SUCCESS;
 }
 
+static bool match_name(int argc, char * const argv[], u16 *var_name16)
+{
+	char *buf, *p;
+	size_t buflen;
+	int i;
+	bool result = false;
+
+	buflen = utf16_utf8_strlen(var_name16) + 1;
+	buf = calloc(1, buflen);
+	if (!buf)
+		return result;
+
+	p = buf;
+	utf16_utf8_strcpy(&p, var_name16);
+
+	for (i = 0; i < argc; argc--, argv++) {
+		if (!strcmp(buf, argv[i])) {
+			result = true;
+			goto out;
+		}
+	}
+
+out:
+	free(buf);
+
+	return result;
+}
+
 /**
- * efi_dump_vars() - show information about all the UEFI variables
+ * efi_dump_var_all() - show information about all the UEFI variables
  *
+ * @argc:	Number of arguments (variables)
+ * @argv:	Argument (variable name) array
+ * @verbose:	if true, dump data
  * Return:	CMD_RET_SUCCESS on success, or CMD_RET_RET_FAILURE
  *
  * Show information encoded in all the UEFI variables
  */
-static int efi_dump_var_all(void)
+static int efi_dump_var_all(int argc,  char * const argv[],
+			    const efi_guid_t *guid_p, bool verbose)
 {
 	u16 *var_name16, *p;
 	efi_uintn_t buf_size, size;
 	efi_guid_t guid;
 	efi_status_t ret;
 
+	if (argc && guid_p)
+		/* simplified case */
+		return efi_dump_vars(argc, argv, guid_p, verbose);
+
 	buf_size = 128;
 	var_name16 = malloc(buf_size);
 	if (!var_name16)
@@ -171,7 +245,9 @@
 			return CMD_RET_FAILURE;
 		}
 
-		efi_dump_single_var(var_name16, &guid);
+		if ((!guid_p || !guidcmp(guid_p, &guid)) &&
+		    (!argc || match_name(argc, argv, var_name16)))
+			efi_dump_single_var(var_name16, &guid, verbose);
 	}
 
 	free(var_name16);
@@ -189,12 +265,15 @@
  * Return:	CMD_RET_SUCCESS on success, or CMD_RET_RET_FAILURE
  *
  * This function is for "env print -e" or "printenv -e" command:
- *   => env print -e [var [...]]
+ *   => env print -e [-n] [-guid <guid> | -all] [var [...]]
  * If one or more variable names are specified, show information
  * named UEFI variables, otherwise show all the UEFI variables.
  */
 int do_env_print_efi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
+	efi_guid_t guid;
+	const efi_guid_t *guid_p;
+	bool default_guid, guid_any, verbose;
 	efi_status_t ret;
 
 	/* Initialize EFI drivers */
@@ -205,12 +284,47 @@
 		return CMD_RET_FAILURE;
 	}
 
-	if (argc > 1)
-		/* show specified UEFI variables */
-		return efi_dump_vars(--argc, ++argv);
+	default_guid = true;
+	guid_any = false;
+	verbose = true;
+	for (argc--, argv++; argc > 0 && argv[0][0] == '-'; argc--, argv++) {
+		if (!strcmp(argv[0], "-guid")) {
+			if (argc == 1)
+				return CMD_RET_USAGE;
+
+			/* -a already specified */
+			if (!default_guid & guid_any)
+				return CMD_RET_USAGE;
+
+			argc--;
+			argv++;
+			if (uuid_str_to_bin(argv[0], guid.b,
+					    UUID_STR_FORMAT_GUID))
+				return CMD_RET_USAGE;
+			default_guid = false;
+		} else if (!strcmp(argv[0], "-all")) {
+			/* -guid already specified */
+			if (!default_guid && !guid_any)
+				return CMD_RET_USAGE;
+
+			guid_any = true;
+			default_guid = false;
+		} else if (!strcmp(argv[0], "-n")) {
+			verbose = false;
+		} else {
+			return CMD_RET_USAGE;
+		}
+	}
+
+	if (guid_any)
+		guid_p = NULL;
+	else if (default_guid)
+		guid_p = &efi_global_variable_guid;
+	else
+		guid_p = (const efi_guid_t *)guid.b;
 
 	/* enumerate and show all UEFI variables */
-	return efi_dump_var_all();
+	return efi_dump_var_all(argc, argv, guid_p, verbose);
 }
 
 /**
@@ -339,18 +453,22 @@
  * Return:	CMD_RET_SUCCESS on success, or CMD_RET_RET_FAILURE
  *
  * This function is for "env set -e" or "setenv -e" command:
- *   => env set -e var [value ...]]
+ *   => env set -e [-guid guid][-nv][-bs][-rt][-a][-v]
+ *		   [-i address,size] var, or
+ *                 var [value ...]
  * Encode values specified and set given UEFI variable.
  * If no value is specified, delete the variable.
  */
 int do_env_set_efi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-	char *var_name, *value = NULL;
-	efi_uintn_t size = 0;
-	u16 *var_name16 = NULL, *p;
-	size_t len;
+	char *var_name, *value, *ep;
+	ulong addr;
+	efi_uintn_t size;
 	efi_guid_t guid;
 	u32 attributes;
+	bool default_guid, verbose, value_on_memory;
+	u16 *var_name16 = NULL, *p;
+	size_t len;
 	efi_status_t ret;
 
 	if (argc == 1)
@@ -364,32 +482,88 @@
 		return CMD_RET_FAILURE;
 	}
 
+	/*
+	 * attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS |
+	 *	     EFI_VARIABLE_RUNTIME_ACCESS;
+	 */
+	value = NULL;
+	size = 0;
+	attributes = 0;
+	guid = efi_global_variable_guid;
+	default_guid = true;
+	verbose = false;
+	value_on_memory = false;
+	for (argc--, argv++; argc > 0 && argv[0][0] == '-'; argc--, argv++) {
+		if (!strcmp(argv[0], "-guid")) {
+			if (argc == 1)
+				return CMD_RET_USAGE;
+
-	attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS |
-		     EFI_VARIABLE_RUNTIME_ACCESS;
-	if (!strcmp(argv[1], "-nv")) {
-		attributes |= EFI_VARIABLE_NON_VOLATILE;
-		argc--;
-		argv++;
-		if (argc == 1)
-			return CMD_RET_SUCCESS;
+			argc--;
+			argv++;
+			if (uuid_str_to_bin(argv[0], guid.b,
+					    UUID_STR_FORMAT_GUID)) {
+				printf("## Guid not specified or in XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX format\n");
+				return CMD_RET_FAILURE;
+			}
+			default_guid = false;
+		} else if (!strcmp(argv[0], "-bs")) {
+			attributes |= EFI_VARIABLE_BOOTSERVICE_ACCESS;
+		} else if (!strcmp(argv[0], "-rt")) {
+			attributes |= EFI_VARIABLE_RUNTIME_ACCESS;
+		} else if (!strcmp(argv[0], "-nv")) {
+			attributes |= EFI_VARIABLE_NON_VOLATILE;
+		} else if (!strcmp(argv[0], "-a")) {
+			attributes |= EFI_VARIABLE_APPEND_WRITE;
+		} else if (!strcmp(argv[0], "-i")) {
+			/* data comes from memory */
+			if (argc == 1)
+				return CMD_RET_USAGE;
+
+			argc--;
+			argv++;
+			addr = simple_strtoul(argv[0], &ep, 16);
+			if (*ep != ',')
+				return CMD_RET_USAGE;
+
+			size = simple_strtoul(++ep, NULL, 16);
+			if (!size)
+				return CMD_RET_FAILURE;
+			value_on_memory = true;
+		} else if (!strcmp(argv[0], "-v")) {
+			verbose = true;
+		} else {
+			return CMD_RET_USAGE;
+		}
 	}
+	if (!argc)
+		return CMD_RET_USAGE;
 
-	var_name = argv[1];
-	if (argc == 2) {
-		/* delete */
-		value = NULL;
-		size = 0;
-	} else { /* set */
-		argc -= 2;
-		argv += 2;
+	var_name = argv[0];
+	if (default_guid)
+		guid = efi_global_variable_guid;
 
-		for ( ; argc > 0; argc--, argv++)
+	if (verbose) {
+		printf("GUID: %s\n", efi_guid_to_str((const efi_guid_t *)
+						     &guid));
+		printf("Attributes: 0x%x\n", attributes);
+	}
+
+	/* for value */
+	if (value_on_memory)
+		value = map_sysmem(addr, 0);
+	else if (argc > 1)
+		for (argc--, argv++; argc > 0; argc--, argv++)
 			if (append_value(&value, &size, argv[0]) < 0) {
 				printf("## Failed to process an argument, %s\n",
 				       argv[0]);
 				ret = CMD_RET_FAILURE;
 				goto out;
 			}
+
+	if (size && verbose) {
+		printf("Value:\n");
+		print_hex_dump("    ", DUMP_PREFIX_OFFSET,
+			       16, 1, value, size, true);
 	}
 
 	len = utf8_utf16_strnlen(var_name, strlen(var_name));
@@ -402,17 +576,42 @@
 	p = var_name16;
 	utf8_utf16_strncpy(&p, var_name, len + 1);
 
-	guid = efi_global_variable_guid;
 	ret = EFI_CALL(efi_set_variable(var_name16, &guid, attributes,
 					size, value));
+	unmap_sysmem(value);
 	if (ret == EFI_SUCCESS) {
 		ret = CMD_RET_SUCCESS;
 	} else {
-		printf("## Failed to set EFI variable\n");
+		const char *msg;
+
+		switch (ret) {
+		case EFI_NOT_FOUND:
+			msg = " (not found)";
+			break;
+		case EFI_WRITE_PROTECTED:
+			msg = " (read only)";
+			break;
+		case EFI_INVALID_PARAMETER:
+			msg = " (invalid parameter)";
+			break;
+		case EFI_SECURITY_VIOLATION:
+			msg = " (validation failed)";
+			break;
+		case EFI_OUT_OF_RESOURCES:
+			msg = " (out of memory)";
+			break;
+		default:
+			msg = "";
+			break;
+		}
+		printf("## Failed to set EFI variable%s\n", msg);
 		ret = CMD_RET_FAILURE;
 	}
 out:
-	free(value);
+	if (value_on_memory)
+		unmap_sysmem(value);
+	else
+		free(value);
 	free(var_name16);
 
 	return ret;
diff --git a/common/board_f.c b/common/board_f.c
index 591f18f..e3591cb 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -588,6 +588,7 @@
 static int reserve_bloblist(void)
 {
 #ifdef CONFIG_BLOBLIST
+	gd->start_addr_sp &= ~0xf;
 	gd->start_addr_sp -= CONFIG_BLOBLIST_SIZE;
 	gd->new_bloblist = map_sysmem(gd->start_addr_sp, CONFIG_BLOBLIST_SIZE);
 #endif
@@ -695,6 +696,7 @@
 		      gd->bootstage, gd->new_bootstage, size);
 		memcpy(gd->new_bootstage, gd->bootstage, size);
 		gd->bootstage = gd->new_bootstage;
+		bootstage_relocate();
 	}
 #endif
 
diff --git a/common/board_r.c b/common/board_r.c
index d6fb504..c1ecb06 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -670,7 +670,6 @@
 #ifdef CONFIG_SYS_NONCACHED_MEMORY
 	initr_noncached,
 #endif
-	bootstage_relocate,
 #ifdef CONFIG_OF_LIVE
 	initr_of_live,
 #endif
diff --git a/common/bootstage.c b/common/bootstage.c
index 56ef91a..e8b7bbf 100644
--- a/common/bootstage.c
+++ b/common/bootstage.c
@@ -10,9 +10,10 @@
  */
 
 #include <common.h>
-#include <linux/libfdt.h>
 #include <malloc.h>
+#include <spl.h>
 #include <linux/compiler.h>
+#include <linux/libfdt.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -41,24 +42,34 @@
 };
 
 struct bootstage_hdr {
-	uint32_t version;	/* BOOTSTAGE_VERSION */
-	uint32_t count;		/* Number of records */
-	uint32_t size;		/* Total data size (non-zero if valid) */
-	uint32_t magic;		/* Unused */
+	u32 version;		/* BOOTSTAGE_VERSION */
+	u32 count;		/* Number of records */
+	u32 size;		/* Total data size (non-zero if valid) */
+	u32 magic;		/* Magic number */
+	u32 next_id;		/* Next ID to use for bootstage */
 };
 
 int bootstage_relocate(void)
 {
 	struct bootstage_data *data = gd->bootstage;
 	int i;
+	char *ptr;
+
+	/* Figure out where to relocate the strings to */
+	ptr = (char *)(data + 1);
 
 	/*
 	 * Duplicate all strings.  They may point to an old location in the
 	 * program .text section that can eventually get trashed.
 	 */
 	debug("Relocating %d records\n", data->rec_count);
-	for (i = 0; i < data->rec_count; i++)
-		data->record[i].name = strdup(data->record[i].name);
+	for (i = 0; i < data->rec_count; i++) {
+		const char *from = data->record[i].name;
+
+		strcpy(ptr, from);
+		data->record[i].name = ptr;
+		ptr += strlen(ptr) + 1;
+	}
 
 	return 0;
 }
@@ -372,7 +383,6 @@
 	const struct bootstage_record *rec;
 	char buf[20];
 	char *ptr = base, *end = ptr + size;
-	uint32_t count;
 	int i;
 
 	if (hdr + 1 > (struct bootstage_hdr *)end) {
@@ -383,21 +393,15 @@
 	/* Write an arbitrary version number */
 	hdr->version = BOOTSTAGE_VERSION;
 
-	/* Count the number of records, and write that value first */
-	for (rec = data->record, i = count = 0; i < data->rec_count;
-	     i++, rec++) {
-		if (rec->id != 0)
-			count++;
-	}
-	hdr->count = count;
+	hdr->count = data->rec_count;
 	hdr->size = 0;
 	hdr->magic = BOOTSTAGE_MAGIC;
+	hdr->next_id = data->next_id;
 	ptr += sizeof(*hdr);
 
 	/* Write the records, silently stopping when we run out of space */
-	for (rec = data->record, i = 0; i < data->rec_count; i++, rec++) {
+	for (rec = data->record, i = 0; i < data->rec_count; i++, rec++)
 		append_data(&ptr, end, rec, sizeof(*rec));
-	}
 
 	/* Write the name strings */
 	for (rec = data->record, i = 0; i < data->rec_count; i++, rec++) {
@@ -478,6 +482,8 @@
 	for (rec = data->record + data->next_id, i = 0; i < hdr->count;
 	     i++, rec++) {
 		rec->name = ptr;
+		if (spl_phase() == PHASE_SPL)
+			rec->name = strdup(ptr);
 
 		/* Assume no data corruption here */
 		ptr += strlen(ptr) + 1;
@@ -485,6 +491,7 @@
 
 	/* Mark the records as read */
 	data->rec_count += hdr->count;
+	data->next_id = hdr->next_id;
 	debug("Unstashed %d records\n", hdr->count);
 
 	return 0;
@@ -492,7 +499,17 @@
 
 int bootstage_get_size(void)
 {
-	return sizeof(struct bootstage_data);
+	struct bootstage_data *data = gd->bootstage;
+	struct bootstage_record *rec;
+	int size;
+	int i;
+
+	size = sizeof(struct bootstage_data);
+	for (rec = data->record, i = 0; i < data->rec_count;
+	     i++, rec++)
+		size += strlen(rec->name) + 1;
+
+	return size;
 }
 
 int bootstage_init(bool first)
diff --git a/common/fdt_support.c b/common/fdt_support.c
index baf7924..6834399 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -1566,7 +1566,7 @@
 			 uint64_t *val, int cells)
 {
 	const fdt32_t *prop32 = &prop[cell_off];
-	const fdt64_t *prop64 = (const fdt64_t *)&prop[cell_off];
+	const unaligned_fdt64_t *prop64 = (const fdt64_t *)&prop[cell_off];
 
 	if ((cell_off + cells) > prop_len)
 		return -FDT_ERR_NOSPACE;
diff --git a/common/spl/spl.c b/common/spl/spl.c
index a9d3e84..f1ad8dc 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -18,6 +18,7 @@
 #include <version.h>
 #include <image.h>
 #include <malloc.h>
+#include <mapmem.h>
 #include <dm/root.h>
 #include <linux/compiler.h>
 #include <fdt_support.h>
@@ -396,13 +397,25 @@
 		gd->malloc_ptr = 0;
 	}
 #endif
-	ret = bootstage_init(true);
+	ret = bootstage_init(u_boot_first_phase());
 	if (ret) {
 		debug("%s: Failed to set up bootstage: ret=%d\n", __func__,
 		      ret);
 		return ret;
 	}
-	bootstage_mark_name(BOOTSTAGE_ID_START_SPL, "spl");
+#ifdef CONFIG_BOOTSTAGE_STASH
+	if (!u_boot_first_phase()) {
+		const void *stash = map_sysmem(CONFIG_BOOTSTAGE_STASH_ADDR,
+					       CONFIG_BOOTSTAGE_STASH_SIZE);
+
+		ret = bootstage_unstash(stash, CONFIG_BOOTSTAGE_STASH_SIZE);
+		if (ret)
+			debug("%s: Failed to unstash bootstage: ret=%d\n",
+			      __func__, ret);
+	}
+#endif /* CONFIG_BOOTSTAGE_STASH */
+	bootstage_mark_name(spl_phase() == PHASE_TPL ? BOOTSTAGE_ID_START_TPL :
+			    BOOTSTAGE_ID_START_SPL, SPL_TPL_NAME);
 #if CONFIG_IS_ENABLED(LOG)
 	ret = log_init();
 	if (ret) {
@@ -418,7 +431,8 @@
 		}
 	}
 	if (CONFIG_IS_ENABLED(DM)) {
-		bootstage_start(BOOTSTATE_ID_ACCUM_DM_SPL, "dm_spl");
+		bootstage_start(BOOTSTATE_ID_ACCUM_DM_SPL,
+				spl_phase() == PHASE_TPL ? "dm tpl" : "dm_spl");
 		/* With CONFIG_SPL_OF_PLATDATA, bring in all devices */
 		ret = dm_init_and_scan(!CONFIG_IS_ENABLED(OF_PLATDATA));
 		bootstage_accum(BOOTSTATE_ID_ACCUM_DM_SPL);
@@ -704,8 +718,9 @@
 	debug("SPL malloc() used 0x%lx bytes (%ld KB)\n", gd->malloc_ptr,
 	      gd->malloc_ptr / 1024);
 #endif
+	bootstage_mark_name(spl_phase() == PHASE_TPL ? BOOTSTAGE_ID_END_TPL :
+			    BOOTSTAGE_ID_END_SPL, "end " SPL_TPL_NAME);
 #ifdef CONFIG_BOOTSTAGE_STASH
-	bootstage_mark_name(BOOTSTAGE_ID_END_SPL, "end_spl");
 	ret = bootstage_stash((void *)CONFIG_BOOTSTAGE_STASH_ADDR,
 			      CONFIG_BOOTSTAGE_STASH_SIZE);
 	if (ret)
diff --git a/common/splash.c b/common/splash.c
index 0bcedbb..e7d8477 100644
--- a/common/splash.c
+++ b/common/splash.c
@@ -144,8 +144,6 @@
 	vidconsole_put_string(dev, buf);
 	vidconsole_position_cursor(dev, 0, row);
 }
-#else
-static inline void splash_display_banner(void) { }
 #endif /* CONFIG_DM_VIDEO && !CONFIG_HIDE_LOGO_VERSION */
 
 /*
@@ -177,7 +175,9 @@
 	if (x || y)
 		goto end;
 
+#if defined(CONFIG_DM_VIDEO) && !defined(CONFIG_HIDE_LOGO_VERSION)
 	splash_display_banner();
+#endif
 end:
 	return ret;
 }
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index e8f58b3..ca8978f 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -580,6 +580,7 @@
 	desc = dev_get_uclass_platdata(dev);
 	desc->if_type = if_type;
 	desc->blksz = blksz;
+	desc->log2blksz = LOG2(desc->blksz);
 	desc->lba = lba;
 	desc->part_type = PART_TYPE_UNKNOWN;
 	desc->bdev = dev;
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 297f0a0..8f0eab2 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -57,7 +57,7 @@
 
 int ofnode_read_u64(ofnode node, const char *propname, u64 *outp)
 {
-	const fdt64_t *cell;
+	const unaligned_fdt64_t *cell;
 	int len;
 
 	assert(ofnode_valid(node));
diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index d1d12ee..e9e55c9 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -462,5 +462,5 @@
 
 	reg &= ~mask;
 
-	return regmap_write(map, offset, reg | val);
+	return regmap_write(map, offset, reg | (val & mask));
 }
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index 36f4d1c..c520ef1 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -6,6 +6,8 @@
  * Pavel Herrmann <morpheus.ibis@gmail.com>
  */
 
+#define LOG_CATEGORY LOGC_DM
+
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
@@ -303,7 +305,7 @@
 	int ret;
 
 	*devp = NULL;
-	debug("%s: %d %d\n", __func__, find_req_seq, seq_or_req_seq);
+	log_debug("%d %d\n", find_req_seq, seq_or_req_seq);
 	if (seq_or_req_seq == -1)
 		return -ENODEV;
 	ret = uclass_get(id, &uc);
@@ -311,15 +313,16 @@
 		return ret;
 
 	uclass_foreach_dev(dev, uc) {
-		debug("   - %d %d '%s'\n", dev->req_seq, dev->seq, dev->name);
+		log_debug("   - %d %d '%s'\n",
+			  dev->req_seq, dev->seq, dev->name);
 		if ((find_req_seq ? dev->req_seq : dev->seq) ==
 				seq_or_req_seq) {
 			*devp = dev;
-			debug("   - found\n");
+			log_debug("   - found\n");
 			return 0;
 		}
 	}
-	debug("   - not found\n");
+	log_debug("   - not found\n");
 
 	return -ENODEV;
 }
diff --git a/include/bootstage.h b/include/bootstage.h
index 5e7e242..d105ae0 100644
--- a/include/bootstage.h
+++ b/include/bootstage.h
@@ -170,6 +170,8 @@
 	 * rough boot timing information.
 	 */
 	BOOTSTAGE_ID_AWAKE,
+	BOOTSTAGE_ID_START_TPL,
+	BOOTSTAGE_ID_END_TPL,
 	BOOTSTAGE_ID_START_SPL,
 	BOOTSTAGE_ID_END_SPL,
 	BOOTSTAGE_ID_START_UBOOT_F,
diff --git a/include/linux/libfdt_env.h b/include/linux/libfdt_env.h
index e2bf79c..e49fcd7 100644
--- a/include/linux/libfdt_env.h
+++ b/include/linux/libfdt_env.h
@@ -16,6 +16,7 @@
 typedef __be16 fdt16_t;
 typedef __be32 fdt32_t;
 typedef __be64 fdt64_t;
+typedef __be64 unaligned_fdt64_t __aligned(4);
 
 #define fdt32_to_cpu(x) be32_to_cpu(x)
 #define cpu_to_fdt32(x) cpu_to_be32(x)
diff --git a/include/regmap.h b/include/regmap.h
index 0854200..9ada1af 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -295,7 +295,8 @@
  * @map:	The map returned by regmap_init_mem*()
  * @offset:	Offset of the memory
  * @mask:	Mask to apply to the read value
- * @val:	Value to apply to the value to write
+ * @val:	Value to OR with the read value after masking. Note that any
+ *	bits set in @val which are not set in @mask are ignored
  * Return: 0 if OK, -ve on error
  */
 int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val);
diff --git a/include/test/ut.h b/include/test/ut.h
index 19bcb8c..fbfde10 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -61,7 +61,8 @@
 	if (val1 != val2) {						\
 		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr1 " == " #expr2,				\
-			 "Expected %d, got %d", val1, val2);		\
+			 "Expected %#x (%d), got %#x (%d)", val1, val1,	\
+			 val2, val2);					\
 		return CMD_RET_FAILURE;					\
 	}								\
 }
diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index d0daf7b..46f35bc 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -5,14 +5,12 @@
  *  Copyright (c) 2017 Rob Clark
  */
 
-#include <env.h>
-#include <malloc.h>
-#include <charset.h>
+#include <common.h>
 #include <efi_loader.h>
-#include <hexdump.h>
 #include <env_internal.h>
+#include <hexdump.h>
+#include <malloc.h>
 #include <search.h>
-#include <uuid.h>
 
 #define READ_ONLY BIT(31)
 
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 17736ce..125d9db 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -242,7 +242,7 @@
 uint64_t fdtdec_get_uint64(const void *blob, int node, const char *prop_name,
 			   uint64_t default_val)
 {
-	const uint64_t *cell64;
+	const unaligned_fdt64_t *cell64;
 	int length;
 
 	cell64 = fdt_getprop(blob, node, prop_name, &length);
diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
index 62e6381..1138c70 100644
--- a/lib/tiny-printf.c
+++ b/lib/tiny-printf.c
@@ -157,7 +157,8 @@
  *       decimal).
  */
 
-static void pointer(struct printf_info *info, const char *fmt, void *ptr)
+static void __maybe_unused pointer(struct printf_info *info, const char *fmt,
+				   void *ptr)
 {
 #ifdef DEBUG
 	unsigned long num = (uintptr_t)ptr;
@@ -266,6 +267,21 @@
 						div_out(info, &num, div);
 				}
 				break;
+			case 'p':
+#ifdef DEBUG
+				pointer(info, fmt, va_arg(va, void *));
+				/*
+				 * Skip this because it pulls in _ctype which is
+				 * 256 bytes, and we don't generally implement
+				 * pointer anyway
+				 */
+				while (isalnum(fmt[0]))
+					fmt++;
+				break;
+#else
+				islong = true;
+				/* no break */
+#endif
 			case 'x':
 				if (islong) {
 					num = va_arg(va, unsigned long);
@@ -287,11 +303,6 @@
 			case 's':
 				p = va_arg(va, char*);
 				break;
-			case 'p':
-				pointer(info, fmt, va_arg(va, void *));
-				while (isalnum(fmt[0]))
-					fmt++;
-				break;
 			case '%':
 				out(info, '%');
 			default:
@@ -398,3 +409,9 @@
 
 	return ret;
 }
+
+void print_grouped_ull(unsigned long long int_val, int digits)
+{
+	/* Don't try to print the upper 32-bits */
+	printf("%ld ", (ulong)int_val);
+}
diff --git a/test/dm/regmap.c b/test/dm/regmap.c
index 82de295..6fd1f20 100644
--- a/test/dm/regmap.c
+++ b/test/dm/regmap.c
@@ -99,18 +99,27 @@
 	struct regmap *map;
 	uint reg;
 
+	sandbox_set_enable_memio(true);
 	ut_assertok(uclass_get_device(UCLASS_SYSCON, 0, &dev));
 	map = syscon_get_regmap(dev);
 	ut_assertok_ptr(map);
 
 	ut_assertok(regmap_write(map, 0, 0xcacafafa));
-	ut_assertok(regmap_write(map, 3, 0x55aa2211));
+	ut_assertok(regmap_write(map, 5, 0x55aa2211));
 
 	ut_assertok(regmap_read(map, 0, &reg));
-	ut_assertok(regmap_read(map, 3, &reg));
+	ut_asserteq(0xcacafafa, reg);
+	ut_assertok(regmap_read(map, 5, &reg));
+	ut_asserteq(0x55aa2211, reg);
 
+	ut_assertok(regmap_read(map, 0, &reg));
+	ut_asserteq(0xcacafafa, reg);
 	ut_assertok(regmap_update_bits(map, 0, 0xff00ff00, 0x55aa2211));
-	ut_assertok(regmap_update_bits(map, 3, 0x00ff00ff, 0xcacafada));
+	ut_assertok(regmap_read(map, 0, &reg));
+	ut_asserteq(0x55ca22fa, reg);
+	ut_assertok(regmap_update_bits(map, 5, 0x00ff00ff, 0xcacafada));
+	ut_assertok(regmap_read(map, 5, &reg));
+	ut_asserteq(0x55ca22da, reg);
 
 	return 0;
 }
@@ -130,6 +139,7 @@
 		u32 val3;
 	};
 
+	sandbox_set_enable_memio(true);
 	ut_assertok(uclass_get_device(UCLASS_SYSCON, 0, &dev));
 	map = syscon_get_regmap(dev);
 	ut_assertok_ptr(map);
@@ -138,7 +148,9 @@
 	regmap_set(map, struct layout, val3, 0x55aa2211);
 
 	ut_assertok(regmap_get(map, struct layout, val0, &reg));
+	ut_asserteq(0xcacafafa, reg);
 	ut_assertok(regmap_get(map, struct layout, val3, &reg));
+	ut_asserteq(0x55aa2211, reg);
 
 	return 0;
 }
@@ -159,6 +171,7 @@
 
 	start = get_timer(0);
 
+	ut_assertok(regmap_write(map, 0, 0x0));
 	ut_asserteq(-ETIMEDOUT,
 		    regmap_read_poll_timeout_test(map, 0, reg,
 						  (reg == 0xcacafafa),
diff --git a/tools/patman/func_test.py b/tools/patman/func_test.py
index 50a2741..2321f9e 100644
--- a/tools/patman/func_test.py
+++ b/tools/patman/func_test.py
@@ -198,9 +198,9 @@
         line += 4
         self.assertEqual(expected, tools.ToUnicode(lines[line]))
 
-        self.assertEqual(('%s %s, %s' % (args[0], rick, stefan)),
+        self.assertEqual(('%s %s\0%s' % (args[0], rick, stefan)),
                          tools.ToUnicode(cc_lines[0]))
-        self.assertEqual(('%s %s, %s, %s, %s' % (args[1], fred, ed, rick,
+        self.assertEqual(('%s %s\0%s\0%s\0%s' % (args[1], fred, ed, rick,
                                      stefan)), tools.ToUnicode(cc_lines[1]))
 
         expected = '''
diff --git a/tools/patman/patman.py b/tools/patman/patman.py
index 9605a36..0187ebe 100755
--- a/tools/patman/patman.py
+++ b/tools/patman/patman.py
@@ -112,7 +112,7 @@
     for line in fd.readlines():
         match = re_line.match(line)
         if match and match.group(1) == args[0]:
-            for cc in match.group(2).split(', '):
+            for cc in match.group(2).split('\0'):
                 cc = cc.strip()
                 if cc:
                     print(cc)
diff --git a/tools/patman/series.py b/tools/patman/series.py
index 67103f0..d667d9b 100644
--- a/tools/patman/series.py
+++ b/tools/patman/series.py
@@ -243,13 +243,13 @@
             if limit is not None:
                 cc = cc[:limit]
             all_ccs += cc
-            print(commit.patch, ', '.join(sorted(set(cc))), file=fd)
+            print(commit.patch, '\0'.join(sorted(set(cc))), file=fd)
             self._generated_cc[commit.patch] = cc
 
         if cover_fname:
             cover_cc = gitutil.BuildEmailList(self.get('cover_cc', ''))
             cover_cc = [tools.FromUnicode(m) for m in cover_cc]
-            cc_list = ', '.join([tools.ToUnicode(x)
+            cc_list = '\0'.join([tools.ToUnicode(x)
                                  for x in sorted(set(cover_cc + all_ccs))])
             print(cover_fname, cc_list.encode('utf-8'), file=fd)