Merge branch '2020-08-27-misc-fixes'

- Fix for gd->ram_top and bootm_size calculations
- Assorted Kconfig entry cleanups / fixes.
- Make checkpatch.pl error on fdt_high/initrd_high=0xffffffff
- Resync scripts/setlocalversion
- Other minor bugfixes
diff --git a/arch/Kconfig b/arch/Kconfig
index e4a0a02..683e384 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -12,6 +12,7 @@
 	bool "ARC architecture"
 	select ARC_TIMER
 	select CLK
+	select DM
 	select HAVE_PRIVATE_LIBGCC
 	select SUPPORT_OF_CONTROL
 	select TIMER
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 30c26b5..0761dbb 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -860,7 +860,7 @@
 config CMD_ADC
 	bool "adc - Access Analog to Digital Converters info and data"
 	select ADC
-	select DM_REGULATOR
+	depends on DM_REGULATOR
 	help
 	  Shows ADC device info and permit printing one-shot analog converted
 	  data from a named Analog to Digital Converter.
diff --git a/cmd/mem.c b/cmd/mem.c
index 190e2b9..9df5eb0 100644
--- a/cmd/mem.c
+++ b/cmd/mem.c
@@ -30,10 +30,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#ifndef CONFIG_SYS_MEMTEST_SCRATCH
-#define CONFIG_SYS_MEMTEST_SCRATCH 0
-#endif
-
 /* Create a compile-time value */
 #ifdef MEM_SUPPORT_64BIT_DATA
 #define SUPPORT_64BIT_DATA 1
diff --git a/common/image.c b/common/image.c
index 9d7d5c1..da8bccd 100644
--- a/common/image.c
+++ b/common/image.c
@@ -694,6 +694,9 @@
 	size = gd->bd->bi_memsize;
 #endif
 
+	if (start + size > gd->ram_top)
+		size = gd->ram_top - start;
+
 	s = env_get("bootm_low");
 	if (s)
 		tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
diff --git a/configs/khadas-vim2_defconfig b/configs/khadas-vim2_defconfig
index b6d5dbd..1435781 100644
--- a/configs/khadas-vim2_defconfig
+++ b/configs/khadas-vim2_defconfig
@@ -43,6 +43,7 @@
 CONFIG_MESON_GXL_USB_PHY=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_MESON_GXL=y
+CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_RESET=y
 CONFIG_DEBUG_UART_ANNOUNCE=y
diff --git a/configs/khadas-vim_defconfig b/configs/khadas-vim_defconfig
index 2a57cfb..d075dd1 100644
--- a/configs/khadas-vim_defconfig
+++ b/configs/khadas-vim_defconfig
@@ -39,6 +39,7 @@
 CONFIG_MESON_GXL_USB_PHY=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_MESON_GXL=y
+CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_RESET=y
 CONFIG_DEBUG_UART_ANNOUNCE=y
diff --git a/configs/libretech-ac_defconfig b/configs/libretech-ac_defconfig
index d5a812c..e898fb1 100644
--- a/configs/libretech-ac_defconfig
+++ b/configs/libretech-ac_defconfig
@@ -53,6 +53,7 @@
 CONFIG_PINCTRL_MESON_GXL=y
 CONFIG_POWER_DOMAIN=y
 CONFIG_MESON_GX_VPU_POWER_DOMAIN=y
+CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_RESET=y
 CONFIG_DEBUG_UART_ANNOUNCE=y
diff --git a/configs/libretech-cc_defconfig b/configs/libretech-cc_defconfig
index dce861b..65ad7f5 100644
--- a/configs/libretech-cc_defconfig
+++ b/configs/libretech-cc_defconfig
@@ -40,6 +40,7 @@
 CONFIG_PINCTRL_MESON_GXL=y
 CONFIG_POWER_DOMAIN=y
 CONFIG_MESON_GX_VPU_POWER_DOMAIN=y
+CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_RESET=y
 CONFIG_DEBUG_UART_ANNOUNCE=y
diff --git a/configs/libretech-s905d-pc_defconfig b/configs/libretech-s905d-pc_defconfig
index 225a21f..c99a6c5 100644
--- a/configs/libretech-s905d-pc_defconfig
+++ b/configs/libretech-s905d-pc_defconfig
@@ -48,6 +48,7 @@
 CONFIG_PINCTRL_MESON_GXL=y
 CONFIG_POWER_DOMAIN=y
 CONFIG_MESON_GX_VPU_POWER_DOMAIN=y
+CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_RESET=y
 CONFIG_DEBUG_UART_ANNOUNCE=y
diff --git a/configs/libretech-s912-pc_defconfig b/configs/libretech-s912-pc_defconfig
index 005dc0b..7975c59 100644
--- a/configs/libretech-s912-pc_defconfig
+++ b/configs/libretech-s912-pc_defconfig
@@ -47,6 +47,7 @@
 CONFIG_PINCTRL_MESON_GXL=y
 CONFIG_POWER_DOMAIN=y
 CONFIG_MESON_GX_VPU_POWER_DOMAIN=y
+CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_RESET=y
 CONFIG_DEBUG_UART_ANNOUNCE=y
diff --git a/configs/odroid-c2_defconfig b/configs/odroid-c2_defconfig
index 3c53233..82bae79 100644
--- a/configs/odroid-c2_defconfig
+++ b/configs/odroid-c2_defconfig
@@ -40,6 +40,7 @@
 CONFIG_PINCTRL_MESON_GXBB=y
 CONFIG_POWER_DOMAIN=y
 CONFIG_MESON_GX_VPU_POWER_DOMAIN=y
+CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_REGULATOR_GPIO=y
 CONFIG_DM_RESET=y
diff --git a/configs/stm32mp15_basic_defconfig b/configs/stm32mp15_basic_defconfig
index 2094183..a8c4112 100644
--- a/configs/stm32mp15_basic_defconfig
+++ b/configs/stm32mp15_basic_defconfig
@@ -116,6 +116,7 @@
 CONFIG_DM_PMIC=y
 # CONFIG_SPL_PMIC_CHILDREN is not set
 CONFIG_PMIC_STPMIC1=y
+CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_REGULATOR_GPIO=y
 CONFIG_DM_REGULATOR_STM32_VREFBUF=y
diff --git a/configs/stm32mp15_dhcom_basic_defconfig b/configs/stm32mp15_dhcom_basic_defconfig
index c70414e..7668fd0 100644
--- a/configs/stm32mp15_dhcom_basic_defconfig
+++ b/configs/stm32mp15_dhcom_basic_defconfig
@@ -114,6 +114,7 @@
 CONFIG_DM_PMIC=y
 # CONFIG_SPL_PMIC_CHILDREN is not set
 CONFIG_PMIC_STPMIC1=y
+CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_REGULATOR_GPIO=y
 CONFIG_DM_REGULATOR_STM32_VREFBUF=y
diff --git a/configs/stm32mp15_dhcor_basic_defconfig b/configs/stm32mp15_dhcor_basic_defconfig
index 1e1aa86..aa38451 100644
--- a/configs/stm32mp15_dhcor_basic_defconfig
+++ b/configs/stm32mp15_dhcor_basic_defconfig
@@ -108,6 +108,7 @@
 CONFIG_DM_PMIC=y
 # CONFIG_SPL_PMIC_CHILDREN is not set
 CONFIG_PMIC_STPMIC1=y
+CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_REGULATOR_GPIO=y
 CONFIG_DM_REGULATOR_STM32_VREFBUF=y
diff --git a/configs/stm32mp15_trusted_defconfig b/configs/stm32mp15_trusted_defconfig
index 8d59d84..0792884 100644
--- a/configs/stm32mp15_trusted_defconfig
+++ b/configs/stm32mp15_trusted_defconfig
@@ -94,6 +94,7 @@
 CONFIG_PINCTRL_STMFX=y
 CONFIG_DM_PMIC=y
 CONFIG_PMIC_STPMIC1=y
+CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_REGULATOR_GPIO=y
 CONFIG_DM_REGULATOR_STM32_VREFBUF=y
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 06d39df..c19d09b 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -260,6 +260,7 @@
 
 config PCIE_ROCKCHIP
 	bool "Enable Rockchip PCIe driver"
+	depends on ARCH_ROCKCHIP
 	select DM_PCI
 	select PHY_ROCKCHIP_PCIE
 	default y if ROCKCHIP_RK3399
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 756a4ec..34881a1 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -113,14 +113,14 @@
 	---help---
 	  Enable a polling mechanism for USB keyboard.
 
-	config SYS_USB_EVENT_POLL
-		bool "Interrupt polling"
+config SYS_USB_EVENT_POLL
+    bool "Interrupt polling"
 
-	config SYS_USB_EVENT_POLL_VIA_INT_QUEUE
-		bool "Poll via interrupt queue"
+config SYS_USB_EVENT_POLL_VIA_INT_QUEUE
+    bool "Poll via interrupt queue"
 
-	config SYS_USB_EVENT_POLL_VIA_CONTROL_EP
-		bool "Poll via control EP"
+config SYS_USB_EVENT_POLL_VIA_CONTROL_EP
+    bool "Poll via control EP"
 
 endchoice
 
diff --git a/env/Kconfig b/env/Kconfig
index af4d9cb..b59ba31 100644
--- a/env/Kconfig
+++ b/env/Kconfig
@@ -72,6 +72,7 @@
 config ENV_IS_IN_EXT4
 	bool "Environment is in a EXT4 filesystem"
 	depends on !CHAIN_OF_TRUST
+	select FS_EXT4
 	select EXT4_WRITE
 	help
 	  Define this if you want to use the EXT4 file system for the environment.
diff --git a/lib/rsa/rsa-sign.c b/lib/rsa/rsa-sign.c
index 40ca1e1..1f0d81b 100644
--- a/lib/rsa/rsa-sign.c
+++ b/lib/rsa/rsa-sign.c
@@ -708,7 +708,7 @@
 		return -ENOMEM;
 	}
 	ctx = BN_CTX_new();
-	if (!tmp) {
+	if (!ctx) {
 		fprintf(stderr, "Out of memory (bignum context)\n");
 		return -ENOMEM;
 	}
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 3932362..4bed2b0 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2359,6 +2359,12 @@
 		ERROR("BARRED_INCLUDE_IN_HDR",
 		      "Avoid including common.h and dm.h in header files\n" . $herecurr);
 	}
+
+	# Do not disable fdt / initrd relocation
+	if ($rawline =~ /.*(fdt|initrd)_high=0xffffffff/) {
+		ERROR("DISABLE_FDT_OR_INITRD_RELOC",
+		     "fdt or initrd relocation disabled at boot time\n" . $herecurr);
+	}
 }
 
 sub process {
diff --git a/scripts/setlocalversion b/scripts/setlocalversion
index 8564bed..c1c0435 100755
--- a/scripts/setlocalversion
+++ b/scripts/setlocalversion
@@ -1,4 +1,5 @@
 #!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
 #
 # This scripts adds local version information from the version
 # control systems git, mercurial (hg) and subversion (svn).
@@ -44,11 +45,11 @@
 
 	# Check for git and a git repo.
 	if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
-	   head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
+	   head=$(git rev-parse --verify --short HEAD 2>/dev/null); then
 
 		# If we are at a tagged commit (like "v2.6.30-rc6"), we ignore
 		# it, because this version is defined in the top level Makefile.
-		if [ -z "`git describe --exact-match 2>/dev/null`" ]; then
+		if [ -z "$(git describe --exact-match 2>/dev/null)" ]; then
 
 			# If only the short version is requested, don't bother
 			# running further git commands
@@ -58,7 +59,7 @@
 			fi
 			# If we are past a tagged commit (like
 			# "v2.6.30-rc5-302-g72357d5"), we pretty print it.
-			if atag="`git describe 2>/dev/null`"; then
+			if atag="$(git describe 2>/dev/null)"; then
 				echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
 
 			# If we don't have a tag at all we print -g{commitish}.
@@ -69,11 +70,19 @@
 
 		# Is this git on svn?
 		if git config --get svn-remote.svn.url >/dev/null; then
-			printf -- '-svn%s' "`git svn find-rev $head`"
+			printf -- '-svn%s' "$(git svn find-rev $head)"
 		fi
 
-		# Check for uncommitted changes
-		if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
+		# Check for uncommitted changes.
+		# First, with git-status, but --no-optional-locks is only
+		# supported in git >= 2.14, so fall back to git-diff-index if
+		# it fails. Note that git-diff-index does not refresh the
+		# index, so it may give misleading results. See
+		# git-update-index(1), git-diff-index(1), and git-status(1).
+		if {
+			git --no-optional-locks status -uno --porcelain 2>/dev/null ||
+			git diff-index --name-only HEAD
+		} | grep -qvE '^(.. )?scripts/package'; then
 			printf '%s' -dirty
 		fi
 
@@ -82,15 +91,15 @@
 	fi
 
 	# Check for mercurial and a mercurial repo.
-	if test -d .hg && hgid=`hg id 2>/dev/null`; then
+	if test -d .hg && hgid=$(hg id 2>/dev/null); then
 		# Do we have an tagged version?  If so, latesttagdistance == 1
-		if [ "`hg log -r . --template '{latesttagdistance}'`" == "1" ]; then
-			id=`hg log -r . --template '{latesttag}'`
+		if [ "$(hg log -r . --template '{latesttagdistance}')" = "1" ]; then
+			id=$(hg log -r . --template '{latesttag}')
 			printf '%s%s' -hg "$id"
 		else
-			tag=`printf '%s' "$hgid" | cut -d' ' -f2`
+			tag=$(printf '%s' "$hgid" | cut -d' ' -f2)
 			if [ -z "$tag" -o "$tag" = tip ]; then
-				id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
+				id=$(printf '%s' "$hgid" | sed 's/[+ ].*//')
 				printf '%s%s' -hg "$id"
 			fi
 		fi
@@ -106,8 +115,8 @@
 	fi
 
 	# Check for svn and a svn repo.
-	if rev=`LANG= LC_ALL= LC_MESSAGES=C svn info 2>/dev/null | grep '^Last Changed Rev'`; then
-		rev=`echo $rev | awk '{print $NF}'`
+	if rev=$(LANG= LC_ALL= LC_MESSAGES=C svn info 2>/dev/null | grep '^Last Changed Rev'); then
+		rev=$(echo $rev | awk '{print $NF}')
 		printf -- '-svn%s' "$rev"
 
 		# All done with svn
@@ -117,7 +126,7 @@
 
 collect_files()
 {
-	local file res
+	local file res=
 
 	for file; do
 		case "$file" in
@@ -142,12 +151,12 @@
 
 if test -e include/config/auto.conf; then
 	# We are interested only in CONFIG_LOCALVERSION and
-        # CONFIG_LOCALVERSION_AUTO, so extract these in a safe
-        # way (i.e. w/o sourcing auto.conf)
+	# CONFIG_LOCALVERSION_AUTO, so extract these in a safe
+	# way (i.e. w/o sourcing auto.conf)
 	CONFIG_LOCALVERSION=`cat include/config/auto.conf | awk -F '=' '/^CONFIG_LOCALVERSION=/ {print $2}'`
 	CONFIG_LOCALVERSION_AUTO=`cat include/config/auto.conf | awk -F '=' '/^CONFIG_LOCALVERSION_AUTO=/ {print $2}'`
 else
-	echo "Error: kernelrelease not valid - run 'make prepare' to update it"
+	echo "Error: kernelrelease not valid - run 'make prepare' to update it" >&2
 	exit 1
 fi
 
diff --git a/test/lib/Makefile b/test/lib/Makefile
index ada62fe..22236f8 100644
--- a/test/lib/Makefile
+++ b/test/lib/Makefile
@@ -7,7 +7,7 @@
 obj-$(CONFIG_EFI_SECURE_BOOT) += efi_image_region.o
 obj-y += hexdump.o
 obj-y += lmb.o
-obj-y += sscanf.o
+obj-$(CONFIG_SSCANF) += sscanf.o
 obj-y += string.o
 obj-$(CONFIG_ERRNO_STR) += test_errno_str.o
 obj-$(CONFIG_UT_LIB_ASN1) += asn1.o