Merge U-Boot v2020.01 into master

Merges away nearly all of our Android changes; we are left with a few
recent changes to add hard disk support to the env subsystem and some
hacks for rockpi4.

Bug: 147107640
Change-Id: Ifa62cc29e44d46066434e5af199c7b2108910024
Signed-off-by: Alistair Delva <adelva@google.com>
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..9cc9320
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,128 @@
+// Copyright 2018 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// NOTE: image-sig (RSA signature) support is broken because the U-Boot code
+// requires API features from openssl which are not provided by boringssl
+
+cc_defaults {
+    name: "uboot_host_defaults",
+
+    cflags: [
+        "-D__KERNEL_STRICT_NAMES",
+        "-D_GNU_SOURCE",
+        "-DMKIMAGE_DTC=\"dtc\"",
+        "-DUSE_HOSTCC",
+        "-Wno-missing-field-initializers",
+        "-Wno-pointer-arith",
+        "-Wno-unused-parameter",
+        "-Wno-visibility",
+        "-Wno-sign-compare",
+        "-include linux/kconfig.h",
+        "-include compiler.h",
+    ],
+
+    local_include_dirs: [
+        "prebuilt-intermediates",
+    ],
+
+    target: {
+        darwin: {
+            enabled: false,
+        },
+    },
+}
+
+cc_binary_host {
+    name: "mkimage",
+
+    defaults: ["uboot_host_defaults"],
+
+    srcs: [
+        "common/bootm.c",
+        "common/hash.c",
+        "common/image.c",
+        "common/image-fit.c",
+        "lib/crc16.c",
+        "lib/crc32.c",
+        "lib/fdtdec.c",
+        "lib/fdtdec_common.c",
+        "lib/libfdt/fdt_region.c",
+        "lib/libfdt/fdt_ro.c",
+        "lib/md5.c",
+        "lib/rc4.c",
+        "lib/sha1.c",
+        "lib/sha256.c",
+        "tools/aisimage.c",
+        "tools/atmelimage.c",
+        "tools/default_image.c",
+        "tools/fit_common.c",
+        "tools/fit_image.c",
+        "tools/gpimage.c",
+        "tools/gpimage-common.c",
+        "tools/image-host.c",
+        "tools/imagetool.c",
+        "tools/imx8image.c",
+        "tools/imx8mimage.c",
+        "tools/imximage.c",
+        "tools/kwbimage.c",
+        "tools/libfdt/fdt.c",
+        "tools/libfdt/fdt_addresses.c",
+        "tools/libfdt/fdt_empty_tree.c",
+        "tools/libfdt/fdt_overlay.c",
+        "tools/libfdt/fdt_rw.c",
+        "tools/libfdt/fdt_strerror.c",
+        "tools/libfdt/fdt_sw.c",
+        "tools/libfdt/fdt_wip.c",
+        "tools/lpc32xximage.c",
+        "tools/mkimage.c",
+        "tools/mtk_image.c",
+        "tools/mxsimage.c",
+        "tools/omapimage.c",
+        "tools/os_support.c",
+        "tools/pbl_crc32.c",
+        "tools/pblimage.c",
+        "tools/rkcommon.c",
+        "tools/rkimage.c",
+        "tools/rksd.c",
+        "tools/rkspi.c",
+        "tools/socfpgaimage.c",
+        "tools/stm32image.c",
+        "tools/ublimage.c",
+        "tools/vybridimage.c",
+        "tools/zynqimage.c",
+        "tools/zynqmpbif.c",
+        "tools/zynqmpimage.c",
+    ],
+
+    local_include_dirs: [
+        "scripts/dtc/libfdt",
+        "tools",
+    ],
+}
+
+cc_binary_host {
+    name: "mkenvimage",
+
+    defaults: ["uboot_host_defaults"],
+
+    srcs: [
+        "lib/crc32.c",
+        "tools/mkenvimage.c",
+        "tools/os_support.c",
+    ],
+
+    local_include_dirs: [
+        "tools",
+    ],
+}
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..486e18d
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,153 @@
+SPDX-License-Identifier: GPL-2.0
+
+  U-Boot is Free Software.  It is copyrighted by Wolfgang Denk and
+many others who contributed code (see the actual source code and the
+git commit messages for details).  You can redistribute U-Boot and/or
+modify it under the terms of version 2 of the GNU General Public
+License as published by the Free Software Foundation.  Most of it can
+also be distributed, at your option, under any later version of the
+GNU General Public License -- see individual files for exceptions.
+
+  NOTE! This license does *not* cover the so-called "standalone"
+applications that use U-Boot services by means of the jump table
+provided by U-Boot exactly for this purpose - this is merely
+considered normal use of U-Boot, and does *not* fall under the
+heading of "derived work" -- see file  Licenses/Exceptions  for
+details.
+
+  Also note that the GPL and the other licenses are copyrighted by
+the Free Software Foundation and other organizations, but the
+instance of code that they refer to (the U-Boot source code) is
+copyrighted by me and others who actually wrote it.
+-- Wolfgang Denk
+
+
+Like many other projects, U-Boot has a tradition of including big
+blocks of License headers in all files.  This not only blows up the
+source code with mostly redundant information, but also makes it very
+difficult to generate License Clearing Reports.  An additional problem
+is that even the same licenses are referred to by a number of
+slightly varying text blocks (full, abbreviated, different
+indentation, line wrapping and/or white space, with obsolete address
+information, ...) which makes automatic processing a nightmare.
+
+To make this easier, such license headers in the source files will be
+replaced with a single line reference to Unique License Identifiers
+as defined by the Linux Foundation's SPDX project [1].
+
+If a "SPDX-License-Identifier:" line references more than one Unique
+License Identifier, then this means that the respective file can be
+used under the terms of either of these licenses, i. e. with
+
+	SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
+
+you can choose between GPL-2.0+ and BSD-3-Clause licensing.
+
+We use the SPDX Unique License Identifiers here; these are available
+at [2].
+
+License identifier syntax
+-------------------------
+
+1. Placement:
+
+   The SPDX license identifier in U-Boot files shall be added at the first
+   possible line in a file which can contain a comment.  For the majority
+   or files this is the first line, except for scripts which require the
+   '#!PATH_TO_INTERPRETER' in the first line.  For those scripts the SPDX
+   identifier goes into the second line.
+
+|
+
+2. Style:
+
+   The SPDX license identifier is added in form of a comment.  The comment
+   style depends on the file type::
+
+      C source:	// SPDX-License-Identifier: <SPDX License Expression>
+      C header:	/* SPDX-License-Identifier: <SPDX License Expression> */
+      ASM:	/* SPDX-License-Identifier: <SPDX License Expression> */
+      scripts:	# SPDX-License-Identifier: <SPDX License Expression>
+      .rst:	.. SPDX-License-Identifier: <SPDX License Expression>
+      .dts{i}:	// SPDX-License-Identifier: <SPDX License Expression>
+
+   If a specific tool cannot handle the standard comment style, then the
+   appropriate comment mechanism which the tool accepts shall be used. This
+   is the reason for having the "/\* \*/" style comment in C header
+   files. There was build breakage observed with generated .lds files where
+   'ld' failed to parse the C++ comment. This has been fixed by now, but
+   there are still older assembler tools which cannot handle C++ style
+   comments.
+
+|
+
+3. Syntax:
+
+   A <SPDX License Expression> is either an SPDX short form license
+   identifier found on the SPDX License List, or the combination of two
+   SPDX short form license identifiers separated by "WITH" when a license
+   exception applies. When multiple licenses apply, an expression consists
+   of keywords "AND", "OR" separating sub-expressions and surrounded by
+   "(", ")" .
+
+   License identifiers for licenses like [L]GPL with the 'or later' option
+   are constructed by using a "+" for indicating the 'or later' option.::
+
+      // SPDX-License-Identifier: GPL-2.0+
+      // SPDX-License-Identifier: LGPL-2.1+
+
+   WITH should be used when there is a modifier to a license needed.
+   For example, the linux kernel UAPI files use the expression::
+
+      // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
+      // SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note
+
+   Other examples using WITH exceptions found in the linux kernel are::
+
+      // SPDX-License-Identifier: GPL-2.0 WITH mif-exception
+      // SPDX-License-Identifier: GPL-2.0+ WITH GCC-exception-2.0
+
+   Exceptions can only be used with particular License identifiers. The
+   valid License identifiers are listed in the tags of the exception text
+   file.
+
+   OR should be used if the file is dual licensed and only one license is
+   to be selected.  For example, some dtsi files are available under dual
+   licenses::
+
+      // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
+
+   Examples from U-Boot for license expressions in dual licensed files::
+
+      // SPDX-License-Identifier: GPL-2.0 OR MIT
+      // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
+
+   AND should be used if the file has multiple licenses whose terms all
+   apply to use the file. For example, if code is inherited from another
+   project and permission has been given to put it in U-Boot, but the
+   original license terms need to remain in effect::
+
+      // SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) AND MIT
+
+   Another other example where both sets of license terms need to be
+   adhered to is::
+
+      // SPDX-License-Identifier: GPL-1.0+ AND LGPL-2.1+
+
+[1] http://spdx.org/
+[2] http://spdx.org/licenses/
+
+Full name					SPDX Identifier	OSI Approved	File name		URI
+=======================================================================================================================================
+GNU General Public License v2.0 only		GPL-2.0		Y		gpl-2.0.txt		http://www.gnu.org/licenses/gpl-2.0.txt
+GNU General Public License v2.0 or later	GPL-2.0+	Y		gpl-2.0.txt		http://www.gnu.org/licenses/gpl-2.0.txt
+GNU Library General Public License v2 or later	LGPL-2.0+	Y		lgpl-2.0.txt		http://www.gnu.org/licenses/old-licenses/lgpl-2.0.txt
+GNU Lesser General Public License v2.1 or later	LGPL-2.1+	Y		lgpl-2.1.txt		http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
+eCos license version 2.0			eCos-2.0			eCos-2.0.txt		http://www.gnu.org/licenses/ecos-license.html
+BSD 2-Clause License				BSD-2-Clause	Y		bsd-2-clause.txt	http://spdx.org/licenses/BSD-2-Clause
+BSD 3-clause "New" or "Revised" License		BSD-3-Clause	Y		bsd-3-clause.txt	http://spdx.org/licenses/BSD-3-Clause#licenseText
+IBM PIBS (PowerPC Initialization and		IBM-pibs			ibm-pibs.txt
+	Boot Software) license
+ISC License					ISC		Y		isc.txt			https://spdx.org/licenses/ISC
+SIL OPEN FONT LICENSE (OFL-1.1)			OFL-1.1		Y		OFL.txt			https://spdx.org/licenses/OFL-1.1.html
+X11 License					X11				x11.txt			https://spdx.org/licenses/X11.html
diff --git a/METADATA b/METADATA
new file mode 100644
index 0000000..8085b17
--- /dev/null
+++ b/METADATA
@@ -0,0 +1,17 @@
+name: "u-boot"
+description:
+    ""
+
+third_party {
+  url {
+    type: HOMEPAGE
+    value: "http://www.denx.de/wiki/U-Boot/WebHome"
+  }
+  url {
+    type: ARCHIVE
+    value: "git://git.denx.de/u-boot.git"
+  }
+  version: "2020.01"
+  last_upgrade_date { year: 2020 month: 1 day: 23 }
+  license_type: RESTRICTED
+}
diff --git a/MODULE_LICENSE_GPL b/MODULE_LICENSE_GPL
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_GPL
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..486e18d
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,153 @@
+SPDX-License-Identifier: GPL-2.0
+
+  U-Boot is Free Software.  It is copyrighted by Wolfgang Denk and
+many others who contributed code (see the actual source code and the
+git commit messages for details).  You can redistribute U-Boot and/or
+modify it under the terms of version 2 of the GNU General Public
+License as published by the Free Software Foundation.  Most of it can
+also be distributed, at your option, under any later version of the
+GNU General Public License -- see individual files for exceptions.
+
+  NOTE! This license does *not* cover the so-called "standalone"
+applications that use U-Boot services by means of the jump table
+provided by U-Boot exactly for this purpose - this is merely
+considered normal use of U-Boot, and does *not* fall under the
+heading of "derived work" -- see file  Licenses/Exceptions  for
+details.
+
+  Also note that the GPL and the other licenses are copyrighted by
+the Free Software Foundation and other organizations, but the
+instance of code that they refer to (the U-Boot source code) is
+copyrighted by me and others who actually wrote it.
+-- Wolfgang Denk
+
+
+Like many other projects, U-Boot has a tradition of including big
+blocks of License headers in all files.  This not only blows up the
+source code with mostly redundant information, but also makes it very
+difficult to generate License Clearing Reports.  An additional problem
+is that even the same licenses are referred to by a number of
+slightly varying text blocks (full, abbreviated, different
+indentation, line wrapping and/or white space, with obsolete address
+information, ...) which makes automatic processing a nightmare.
+
+To make this easier, such license headers in the source files will be
+replaced with a single line reference to Unique License Identifiers
+as defined by the Linux Foundation's SPDX project [1].
+
+If a "SPDX-License-Identifier:" line references more than one Unique
+License Identifier, then this means that the respective file can be
+used under the terms of either of these licenses, i. e. with
+
+	SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
+
+you can choose between GPL-2.0+ and BSD-3-Clause licensing.
+
+We use the SPDX Unique License Identifiers here; these are available
+at [2].
+
+License identifier syntax
+-------------------------
+
+1. Placement:
+
+   The SPDX license identifier in U-Boot files shall be added at the first
+   possible line in a file which can contain a comment.  For the majority
+   or files this is the first line, except for scripts which require the
+   '#!PATH_TO_INTERPRETER' in the first line.  For those scripts the SPDX
+   identifier goes into the second line.
+
+|
+
+2. Style:
+
+   The SPDX license identifier is added in form of a comment.  The comment
+   style depends on the file type::
+
+      C source:	// SPDX-License-Identifier: <SPDX License Expression>
+      C header:	/* SPDX-License-Identifier: <SPDX License Expression> */
+      ASM:	/* SPDX-License-Identifier: <SPDX License Expression> */
+      scripts:	# SPDX-License-Identifier: <SPDX License Expression>
+      .rst:	.. SPDX-License-Identifier: <SPDX License Expression>
+      .dts{i}:	// SPDX-License-Identifier: <SPDX License Expression>
+
+   If a specific tool cannot handle the standard comment style, then the
+   appropriate comment mechanism which the tool accepts shall be used. This
+   is the reason for having the "/\* \*/" style comment in C header
+   files. There was build breakage observed with generated .lds files where
+   'ld' failed to parse the C++ comment. This has been fixed by now, but
+   there are still older assembler tools which cannot handle C++ style
+   comments.
+
+|
+
+3. Syntax:
+
+   A <SPDX License Expression> is either an SPDX short form license
+   identifier found on the SPDX License List, or the combination of two
+   SPDX short form license identifiers separated by "WITH" when a license
+   exception applies. When multiple licenses apply, an expression consists
+   of keywords "AND", "OR" separating sub-expressions and surrounded by
+   "(", ")" .
+
+   License identifiers for licenses like [L]GPL with the 'or later' option
+   are constructed by using a "+" for indicating the 'or later' option.::
+
+      // SPDX-License-Identifier: GPL-2.0+
+      // SPDX-License-Identifier: LGPL-2.1+
+
+   WITH should be used when there is a modifier to a license needed.
+   For example, the linux kernel UAPI files use the expression::
+
+      // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
+      // SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note
+
+   Other examples using WITH exceptions found in the linux kernel are::
+
+      // SPDX-License-Identifier: GPL-2.0 WITH mif-exception
+      // SPDX-License-Identifier: GPL-2.0+ WITH GCC-exception-2.0
+
+   Exceptions can only be used with particular License identifiers. The
+   valid License identifiers are listed in the tags of the exception text
+   file.
+
+   OR should be used if the file is dual licensed and only one license is
+   to be selected.  For example, some dtsi files are available under dual
+   licenses::
+
+      // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
+
+   Examples from U-Boot for license expressions in dual licensed files::
+
+      // SPDX-License-Identifier: GPL-2.0 OR MIT
+      // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
+
+   AND should be used if the file has multiple licenses whose terms all
+   apply to use the file. For example, if code is inherited from another
+   project and permission has been given to put it in U-Boot, but the
+   original license terms need to remain in effect::
+
+      // SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) AND MIT
+
+   Another other example where both sets of license terms need to be
+   adhered to is::
+
+      // SPDX-License-Identifier: GPL-1.0+ AND LGPL-2.1+
+
+[1] http://spdx.org/
+[2] http://spdx.org/licenses/
+
+Full name					SPDX Identifier	OSI Approved	File name		URI
+=======================================================================================================================================
+GNU General Public License v2.0 only		GPL-2.0		Y		gpl-2.0.txt		http://www.gnu.org/licenses/gpl-2.0.txt
+GNU General Public License v2.0 or later	GPL-2.0+	Y		gpl-2.0.txt		http://www.gnu.org/licenses/gpl-2.0.txt
+GNU Library General Public License v2 or later	LGPL-2.0+	Y		lgpl-2.0.txt		http://www.gnu.org/licenses/old-licenses/lgpl-2.0.txt
+GNU Lesser General Public License v2.1 or later	LGPL-2.1+	Y		lgpl-2.1.txt		http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
+eCos license version 2.0			eCos-2.0			eCos-2.0.txt		http://www.gnu.org/licenses/ecos-license.html
+BSD 2-Clause License				BSD-2-Clause	Y		bsd-2-clause.txt	http://spdx.org/licenses/BSD-2-Clause
+BSD 3-clause "New" or "Revised" License		BSD-3-Clause	Y		bsd-3-clause.txt	http://spdx.org/licenses/BSD-3-Clause#licenseText
+IBM PIBS (PowerPC Initialization and		IBM-pibs			ibm-pibs.txt
+	Boot Software) license
+ISC License					ISC		Y		isc.txt			https://spdx.org/licenses/ISC
+SIL OPEN FONT LICENSE (OFL-1.1)			OFL-1.1		Y		OFL.txt			https://spdx.org/licenses/OFL-1.1.html
+X11 License					X11				x11.txt			https://spdx.org/licenses/X11.html
diff --git a/OWNERS b/OWNERS
new file mode 100644
index 0000000..9af4d31
--- /dev/null
+++ b/OWNERS
@@ -0,0 +1,2 @@
+adelva@google.com
+schuffelen@google.com
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
new file mode 100644
index 0000000..ca5a558
--- /dev/null
+++ b/PREUPLOAD.cfg
@@ -0,0 +1,2 @@
+[Builtin Hooks]
+checkpatch = true
diff --git a/arch/arm/config.mk b/arch/arm/config.mk
index f256031..bf9cbac 100644
--- a/arch/arm/config.mk
+++ b/arch/arm/config.mk
@@ -65,8 +65,8 @@
 checkgcc6:
 	@if test "$(call cc-name)" = "gcc" -a \
 			"$(call cc-version)" -lt "0600"; then \
-		echo '*** Your GCC is older than 6.0 and is not supported'; \
-		false; \
+		echo -n '*** Your GCC is older than 6.0 and will not be '; \
+		echo 'supported starting in v2018.01.'; \
 	fi
 
 
diff --git a/arch/arm/dts/rk3399-rock-pi-4-u-boot.dtsi b/arch/arm/dts/rk3399-rock-pi-4-u-boot.dtsi
index c17e769..4222ed6 100644
--- a/arch/arm/dts/rk3399-rock-pi-4-u-boot.dtsi
+++ b/arch/arm/dts/rk3399-rock-pi-4-u-boot.dtsi
@@ -8,7 +8,7 @@
 
 / {
 	chosen {
-		u-boot,spl-boot-order = "same-as-spl", &sdhci, &sdmmc;
+		u-boot,spl-boot-order = &sdmmc, &sdhci;
 	};
 };
 
diff --git a/arch/x86/dts/Makefile b/arch/x86/dts/Makefile
index d4bdf62..deb82cf 100644
--- a/arch/x86/dts/Makefile
+++ b/arch/x86/dts/Makefile
@@ -15,6 +15,7 @@
 	efi-x86_payload.dtb \
 	galileo.dtb \
 	minnowmax.dtb \
+	qemu-x86_cuttlefish.dtb \
 	qemu-x86_i440fx.dtb \
 	qemu-x86_q35.dtb \
 	theadorable-x86-dfi-bt700.dtb \
diff --git a/arch/x86/dts/qemu-x86_cuttlefish.dts b/arch/x86/dts/qemu-x86_cuttlefish.dts
new file mode 100644
index 0000000..fd60166
--- /dev/null
+++ b/arch/x86/dts/qemu-x86_cuttlefish.dts
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019, Google, Inc.
+ */
+
+/dts-v1/;
+
+#include "qemu-x86_i440fx.dts"
+
+&serial {
+	reg = <0x2f8 8>;
+};
diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index 81d94cd..6a1024f 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -49,6 +49,7 @@
 	defined(CONFIG_ENV_IS_IN_NAND)		|| \
 	defined(CONFIG_ENV_IS_IN_NVRAM)		|| \
 	defined(CONFIG_ENV_IS_IN_ONENAND)	|| \
+	defined(CONFIG_ENV_IS_IN_RAW_DISK)	|| \
 	defined(CONFIG_ENV_IS_IN_SATA)		|| \
 	defined(CONFIG_ENV_IS_IN_SPI_FLASH)	|| \
 	defined(CONFIG_ENV_IS_IN_REMOTE)	|| \
diff --git a/configs/cf-x86_defconfig b/configs/cf-x86_defconfig
new file mode 100644
index 0000000..6d40589
--- /dev/null
+++ b/configs/cf-x86_defconfig
@@ -0,0 +1,40 @@
+CONFIG_X86=y
+CONFIG_SYS_TEXT_BASE=0xFFF00000
+CONFIG_MAX_CPUS=2
+CONFIG_SMP=y
+CONFIG_GENERATE_PIRQ_TABLE=y
+CONFIG_GENERATE_MP_TABLE=y
+CONFIG_GENERATE_ACPI_TABLE=y
+CONFIG_NR_DRAM_BANKS=8
+CONFIG_BUILD_ROM=y
+CONFIG_ANDROID_BOOT_IMAGE=y
+CONFIG_SYS_CONSOLE_INFO_QUIET=y
+CONFIG_DISPLAY_BOARDINFO_LATE=y
+CONFIG_ANDROID_BOOTLOADER=y
+CONFIG_LAST_STAGE_INIT=y
+CONFIG_ANDROID_AB=y
+CONFIG_HUSH_PARSER=y
+CONFIG_CMD_CPU=y
+# CONFIG_CMD_FLASH is not set
+CONFIG_CMD_GPT=y
+# CONFIG_RANDOM_UUID is not set
+CONFIG_CMD_PART=y
+# CONFIG_CMD_SETEXPR is not set
+CONFIG_CMD_BOOT_ANDROID=y
+CONFIG_CMD_DHCP=y
+# CONFIG_CMD_NFS is not set
+CONFIG_CMD_PING=y
+CONFIG_CMD_TIME=y
+CONFIG_CMD_QFW=y
+CONFIG_CMD_EXT2=y
+CONFIG_CMD_EXT4=y
+CONFIG_CMD_EXT4_WRITE=y
+CONFIG_CMD_FAT=y
+CONFIG_CMD_FS_GENERIC=y
+CONFIG_DEFAULT_DEVICE_TREE="qemu-x86_cuttlefish"
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
+CONFIG_CPU=y
+CONFIG_ENV_IS_IN_RAW_DISK=y
+CONFIG_ENV_RAW_DISK_INTERFACE="virtio"
+CONFIG_ENV_RAW_DISK_DEVICE_AND_PART="0:1"
diff --git a/configs/rock-pi-4-rk3399_defconfig b/configs/rock-pi-4-rk3399_defconfig
index 2c01bf1..a4c9be4 100644
--- a/configs/rock-pi-4-rk3399_defconfig
+++ b/configs/rock-pi-4-rk3399_defconfig
@@ -19,15 +19,19 @@
 CONFIG_CMD_GPT=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_USB=y
-# CONFIG_CMD_SETEXPR is not set
 CONFIG_CMD_TIME=y
 CONFIG_SPL_OF_CONTROL=y
 CONFIG_DEFAULT_DEVICE_TREE="rk3399-rock-pi-4"
 CONFIG_OF_SPL_REMOVE_PROPS="pinctrl-0 pinctrl-names clock-names interrupt-parent assigned-clocks assigned-clock-rates assigned-clock-parents"
 CONFIG_ENV_IS_IN_MMC=y
+CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_ROCKCHIP_GPIO=y
+CONFIG_DM_GPIO=y
+CONFIG_CMD_GPIO=y
 CONFIG_SYS_I2C_ROCKCHIP=y
+CONFIG_MISC=y
+CONFIG_ROCKCHIP_EFUSE=y
 CONFIG_MMC_DW=y
 CONFIG_MMC_DW_ROCKCHIP=y
 CONFIG_MMC_SDHCI=y
diff --git a/drivers/mmc/rockchip_sdhci.c b/drivers/mmc/rockchip_sdhci.c
index dd3d557..d771080 100644
--- a/drivers/mmc/rockchip_sdhci.c
+++ b/drivers/mmc/rockchip_sdhci.c
@@ -58,7 +58,8 @@
 		printf("%s fail to get clk\n", __func__);
 	}
 
-	host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD;
+	host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD |
+		SDHCI_QUIRK_BROKEN_HISPD_MODE;
 	host->max_clk = max_frequency;
 	/*
 	 * The sdhci-driver only supports 4bit and 8bit, as sdhci_setup_cfg
diff --git a/env/Kconfig b/env/Kconfig
index ed12609..9da448c 100644
--- a/env/Kconfig
+++ b/env/Kconfig
@@ -6,8 +6,8 @@
 		     !ENV_IS_IN_FAT && !ENV_IS_IN_FLASH && \
 		     !ENV_IS_IN_MMC && !ENV_IS_IN_NAND && \
 		     !ENV_IS_IN_NVRAM && !ENV_IS_IN_ONENAND && \
-		     !ENV_IS_IN_REMOTE && !ENV_IS_IN_SPI_FLASH && \
-		     !ENV_IS_IN_UBI
+		     !ENV_IS_IN_RAW_DISK && !ENV_IS_IN_REMOTE && \
+		     !ENV_IS_IN_SPI_FLASH && !ENV_IS_IN_UBI
 	help
 	  Define this if you don't want to or can't have an environment stored
 	  on a storage medium. In this case the environment will still exist
@@ -64,6 +64,13 @@
 	help
 	  Define this if you want to use the EXT4 file system for the environment.
 
+config ENV_IS_IN_RAW_DISK
+	bool "Environment is in a raw partition on a hard disk"
+	depends on !CHAIN_OF_TRUST
+	help
+	  Define this if you want to use a raw disk or partition for the
+	  environment.
+
 config ENV_IS_IN_FLASH
 	bool "Environment in flash memory"
 	depends on !CHAIN_OF_TRUST
@@ -461,6 +468,30 @@
 	                   If none, first valid partition in device D. If no
 	                   partition table then means device D.
 
+config ENV_RAW_DISK_INTERFACE
+	string "Name of the block device for the environment"
+	depends on ENV_IS_IN_RAW_DISK
+	help
+	  Define this to a string that is the name of the block device.
+
+config ENV_RAW_DISK_DEVICE_AND_PART
+	string "Device and partition for where to store the environment image"
+	depends on ENV_IS_IN_RAW_DISK
+	help
+	  Define this to a string to specify the partition of the device. It can
+	  be as following:
+
+	    "D:P", "D:0", "D", "D:" or "D:auto" (D, P are integers. And P >= 1)
+	       - "D:P": device D partition P. Error occurs if device D has no
+	                partition table.
+	       - "D:0": device D.
+	       - "D" or "D:": device D partition 1 if device D has partition
+	                      table, or the whole device D if has no partition
+	                      table.
+	       - "D:auto": first partition in device D with bootable flag set.
+	                   If none, first valid partition in device D. If no
+	                   partition table then means device D.
+
 config ENV_EXT4_FILE
 	string "Name of the EXT4 file to use for the environment"
 	depends on ENV_IS_IN_EXT4
diff --git a/env/Makefile b/env/Makefile
index 90144d6..55bf913 100644
--- a/env/Makefile
+++ b/env/Makefile
@@ -28,6 +28,7 @@
 obj-$(CONFIG_$(SPL_TPL_)ENV_IS_NOWHERE) += nowhere.o
 obj-$(CONFIG_$(SPL_TPL_)ENV_IS_IN_MMC) += mmc.o
 obj-$(CONFIG_$(SPL_TPL_)ENV_IS_IN_FAT) += fat.o
+obj-$(CONFIG_$(SPL_TPL_)ENV_IS_IN_RAW_DISK) += raw_disk.o
 obj-$(CONFIG_$(SPL_TPL_)ENV_IS_IN_EXT4) += ext4.o
 obj-$(CONFIG_$(SPL_TPL_)ENV_IS_IN_NAND) += nand.o
 obj-$(CONFIG_$(SPL_TPL_)ENV_IS_IN_SPI_FLASH) += sf.o
diff --git a/env/env.c b/env/env.c
index 9237bb9..7c1a9ac 100644
--- a/env/env.c
+++ b/env/env.c
@@ -71,6 +71,9 @@
 #ifdef CONFIG_ENV_IS_IN_NVRAM
 	ENVL_NVRAM,
 #endif
+#ifdef CONFIG_ENV_IS_IN_RAW_DISK
+	ENVL_RAW_DISK,
+#endif
 #ifdef CONFIG_ENV_IS_IN_REMOTE
 	ENVL_REMOTE,
 #endif
diff --git a/env/raw_disk.c b/env/raw_disk.c
new file mode 100644
index 0000000..4f9cb50
--- /dev/null
+++ b/env/raw_disk.c
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (c) Copyright 2019 by Google, Inc
+ *
+ * Author:
+ *   David Anderson <dvander@google.com>
+ */
+
+#include <common.h>
+
+#include <command.h>
+#include <dm/device.h>
+#include <environment.h>
+#include <linux/stddef.h>
+#include <malloc.h>
+#include <memalign.h>
+#include <search.h>
+#include <errno.h>
+#include <mmc.h>
+#include <virtio_types.h>
+#include <virtio.h>
+
+#ifdef CONFIG_CMD_SAVEENV
+static int env_raw_disk_save(void)
+{
+	ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1);
+	struct blk_desc *dev_desc = NULL;
+	disk_partition_t info;
+	uint blk_cnt, n;
+	int part, err;
+
+	err = env_export(env_new);
+	if (err)
+		return err;
+
+	part = blk_get_device_part_str(CONFIG_ENV_RAW_DISK_INTERFACE,
+					CONFIG_ENV_RAW_DISK_DEVICE_AND_PART,
+					&dev_desc, &info, 1);
+	if (part < 0)
+		return 1;
+
+	printf("Writing to disk...");
+
+	blk_cnt = ALIGN(CONFIG_ENV_SIZE, info.blksz) / info.blksz;
+	n = blk_dwrite(dev_desc, info.start, blk_cnt, (u_char *)env_new);
+	if (n != blk_cnt) {
+		puts("failed\n");
+		return 1;
+	}
+
+	puts("done\n");
+	return 0;
+}
+#endif /* CONFIG_CMD_SAVEENV */
+
+static int env_raw_disk_load(void)
+{
+	ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
+	struct blk_desc *dev_desc = NULL;
+	disk_partition_t info;
+	uint blk_cnt, n;
+	int part;
+
+#ifdef CONFIG_MMC
+	if (!strcmp(CONFIG_ENV_RAW_DISK_INTERFACE, "mmc"))
+		mmc_initialize(NULL);
+#endif
+#ifdef CONFIG_VIRTIO
+	if (!strcmp(CONFIG_ENV_RAW_DISK_INTERFACE, "virtio"))
+		virtio_init();
+#endif
+
+	part = blk_get_device_part_str(CONFIG_ENV_RAW_DISK_INTERFACE,
+					CONFIG_ENV_RAW_DISK_DEVICE_AND_PART,
+					&dev_desc, &info, 1);
+	if (part < 0) {
+		set_default_env(NULL, 0);
+		return -EINVAL;
+	}
+
+	blk_cnt = ALIGN(CONFIG_ENV_SIZE, info.blksz) / info.blksz;
+	n = blk_dread(dev_desc, info.start, blk_cnt, buf);
+	if (n != blk_cnt) {
+		set_default_env(NULL, 0);
+		return -EIO;
+	}
+
+	return env_import(buf, 1);
+}
+
+U_BOOT_ENV_LOCATION(raw_disk) = {
+	.location	= ENVL_RAW_DISK,
+	ENV_NAME("Raw Disk")
+	.load		= env_raw_disk_load,
+#ifdef CONFIG_CMD_SAVEENV
+	.save		= env_save_ptr(env_raw_disk_save),
+#endif
+};
+
diff --git a/include/configs/rk3399_common.h b/include/configs/rk3399_common.h
index 127ca1f..a475867 100644
--- a/include/configs/rk3399_common.h
+++ b/include/configs/rk3399_common.h
@@ -63,8 +63,15 @@
 	"fdtfile=" CONFIG_DEFAULT_FDT_FILE "\0" \
 	"partitions=" PARTS_DEFAULT \
 	ROCKCHIP_DEVICE_SETTINGS \
-	BOOTENV
-
+	BOOTENV \
+	"importbootenv="                                         \
+		"if mmc dev 0 0; then if mmc dev 1 0; then; else"    \
+			"if mmc read ${kernel_addr_r} 0x1fc0 0x40; then" \
+				"env import -b ${kernel_addr_r};"            \
+				"echo Loaded environment from MMC0;"         \
+			"fi; "                                           \
+		"fi; "                                               \
+	"distro_bootcmd=$distro_bootcmd; run importbootenv;\0"
 #endif
 
 /* enable usb config for usb ether */
diff --git a/include/configs/rockchip-common.h b/include/configs/rockchip-common.h
index 68e1105..1be2de2 100644
--- a/include/configs/rockchip-common.h
+++ b/include/configs/rockchip-common.h
@@ -51,11 +51,11 @@
 #endif
 #define PARTS_DEFAULT \
 	"uuid_disk=${uuid_gpt_disk};" \
-	"name=loader1,start=32K,size=4000K,uuid=${uuid_gpt_loader1};" \
+	"name=loader1,start=32K,size=4032K,uuid=${uuid_gpt_loader1};" \
+	"name=env,start=4064K,size=32K,uuid=${uuid_gpt_env};" \
 	"name=loader2,start=8MB,size=4MB,uuid=${uuid_gpt_loader2};" \
 	"name=trust,size=4M,uuid=${uuid_gpt_atf};" \
-	"name=boot,size=112M,bootable,uuid=${uuid_gpt_boot};" \
-	"name=rootfs,size=-,uuid="ROOT_UUID
+	"name=rootfs,bootable,size=-,uuid="ROOT_UUID
 
 #endif
 
diff --git a/include/env_internal.h b/include/env_internal.h
index 90a4df8..4c38361 100644
--- a/include/env_internal.h
+++ b/include/env_internal.h
@@ -130,6 +130,7 @@
 	ENVL_NAND,
 	ENVL_NVRAM,
 	ENVL_ONENAND,
+	ENVL_RAW_DISK,
 	ENVL_REMOTE,
 	ENVL_SPI_FLASH,
 	ENVL_UBI,
diff --git a/prebuilt-intermediates/bootm.h b/prebuilt-intermediates/bootm.h
new file mode 120000
index 0000000..e045d8c
--- /dev/null
+++ b/prebuilt-intermediates/bootm.h
@@ -0,0 +1 @@
+../include/bootm.h
\ No newline at end of file
diff --git a/prebuilt-intermediates/bootstage.h b/prebuilt-intermediates/bootstage.h
new file mode 120000
index 0000000..e10131e
--- /dev/null
+++ b/prebuilt-intermediates/bootstage.h
@@ -0,0 +1 @@
+../include/bootstage.h
\ No newline at end of file
diff --git a/prebuilt-intermediates/command.h b/prebuilt-intermediates/command.h
new file mode 120000
index 0000000..3d918c0
--- /dev/null
+++ b/prebuilt-intermediates/command.h
@@ -0,0 +1 @@
+../include/command.h
\ No newline at end of file
diff --git a/prebuilt-intermediates/compiler.h b/prebuilt-intermediates/compiler.h
new file mode 120000
index 0000000..715e568
--- /dev/null
+++ b/prebuilt-intermediates/compiler.h
@@ -0,0 +1 @@
+../include/compiler.h
\ No newline at end of file
diff --git a/prebuilt-intermediates/env.h b/prebuilt-intermediates/env.h
new file mode 120000
index 0000000..6be9b5a
--- /dev/null
+++ b/prebuilt-intermediates/env.h
@@ -0,0 +1 @@
+../include/env.h
\ No newline at end of file
diff --git a/prebuilt-intermediates/fdt_support.h b/prebuilt-intermediates/fdt_support.h
new file mode 120000
index 0000000..b515e50
--- /dev/null
+++ b/prebuilt-intermediates/fdt_support.h
@@ -0,0 +1 @@
+../include/fdt_support.h
\ No newline at end of file
diff --git a/prebuilt-intermediates/generated/autoconf.h b/prebuilt-intermediates/generated/autoconf.h
new file mode 100644
index 0000000..710cecc
--- /dev/null
+++ b/prebuilt-intermediates/generated/autoconf.h
@@ -0,0 +1 @@
+/* Empty */
diff --git a/prebuilt-intermediates/generated/timestamp_autogenerated.h b/prebuilt-intermediates/generated/timestamp_autogenerated.h
new file mode 100644
index 0000000..9ce5c78
--- /dev/null
+++ b/prebuilt-intermediates/generated/timestamp_autogenerated.h
@@ -0,0 +1,3 @@
+#define U_BOOT_DATE "Jan 1 2000"
+#define U_BOOT_TIME "00:00:00"
+#define U_BOOT_TZ "0000"
diff --git a/prebuilt-intermediates/generated/version_autogenerated.h b/prebuilt-intermediates/generated/version_autogenerated.h
new file mode 100644
index 0000000..dd319f7
--- /dev/null
+++ b/prebuilt-intermediates/generated/version_autogenerated.h
@@ -0,0 +1 @@
+#define PLAIN_VERSION "2020.01"
diff --git a/prebuilt-intermediates/hash.h b/prebuilt-intermediates/hash.h
new file mode 120000
index 0000000..3d1f761
--- /dev/null
+++ b/prebuilt-intermediates/hash.h
@@ -0,0 +1 @@
+../include/hash.h
\ No newline at end of file
diff --git a/prebuilt-intermediates/image.h b/prebuilt-intermediates/image.h
new file mode 120000
index 0000000..ff803f7
--- /dev/null
+++ b/prebuilt-intermediates/image.h
@@ -0,0 +1 @@
+../include/image.h
\ No newline at end of file
diff --git a/prebuilt-intermediates/imx8image.h b/prebuilt-intermediates/imx8image.h
new file mode 120000
index 0000000..4f7192c
--- /dev/null
+++ b/prebuilt-intermediates/imx8image.h
@@ -0,0 +1 @@
+../include/imx8image.h
\ No newline at end of file
diff --git a/prebuilt-intermediates/imximage.h b/prebuilt-intermediates/imximage.h
new file mode 120000
index 0000000..85bcd1f
--- /dev/null
+++ b/prebuilt-intermediates/imximage.h
@@ -0,0 +1 @@
+../include/imximage.h
\ No newline at end of file
diff --git a/prebuilt-intermediates/linker_lists.h b/prebuilt-intermediates/linker_lists.h
new file mode 120000
index 0000000..fadc1cf
--- /dev/null
+++ b/prebuilt-intermediates/linker_lists.h
@@ -0,0 +1 @@
+../include/linker_lists.h
\ No newline at end of file
diff --git a/prebuilt-intermediates/linux/compiler-clang.h b/prebuilt-intermediates/linux/compiler-clang.h
new file mode 120000
index 0000000..c5b66b4
--- /dev/null
+++ b/prebuilt-intermediates/linux/compiler-clang.h
@@ -0,0 +1 @@
+../../include/linux/compiler-clang.h
\ No newline at end of file
diff --git a/prebuilt-intermediates/linux/compiler.h b/prebuilt-intermediates/linux/compiler.h
new file mode 120000
index 0000000..e1089ac
--- /dev/null
+++ b/prebuilt-intermediates/linux/compiler.h
@@ -0,0 +1 @@
+../../include/linux/compiler.h
\ No newline at end of file
diff --git a/prebuilt-intermediates/linux/kconfig.h b/prebuilt-intermediates/linux/kconfig.h
new file mode 120000
index 0000000..0acd2ec
--- /dev/null
+++ b/prebuilt-intermediates/linux/kconfig.h
@@ -0,0 +1 @@
+../../include/linux/kconfig.h
\ No newline at end of file
diff --git a/prebuilt-intermediates/linux/kernel.h b/prebuilt-intermediates/linux/kernel.h
new file mode 100644
index 0000000..c149791
--- /dev/null
+++ b/prebuilt-intermediates/linux/kernel.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+#include_next <linux/kernel.h>
+
+/* Workarounds for imx8image.c which uses kernel macros on host side */
+
+#ifndef ALIGN
+#define ALIGN(x,a)		__ALIGN_MASK((x),(typeof(x))(a)-1)
+#endif
+
+#ifndef __ALIGN_MASK
+#define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
+#endif
diff --git a/prebuilt-intermediates/linux/libfdt.h b/prebuilt-intermediates/linux/libfdt.h
new file mode 120000
index 0000000..fb14cd34
--- /dev/null
+++ b/prebuilt-intermediates/linux/libfdt.h
@@ -0,0 +1 @@
+../../include/linux/libfdt.h
\ No newline at end of file
diff --git a/prebuilt-intermediates/linux/libfdt_env.h b/prebuilt-intermediates/linux/libfdt_env.h
new file mode 120000
index 0000000..9070c9d
--- /dev/null
+++ b/prebuilt-intermediates/linux/libfdt_env.h
@@ -0,0 +1 @@
+../../include/linux/libfdt_env.h
\ No newline at end of file
diff --git a/prebuilt-intermediates/rc4.h b/prebuilt-intermediates/rc4.h
new file mode 120000
index 0000000..976089d
--- /dev/null
+++ b/prebuilt-intermediates/rc4.h
@@ -0,0 +1 @@
+../include/rc4.h
\ No newline at end of file
diff --git a/prebuilt-intermediates/tee b/prebuilt-intermediates/tee
new file mode 120000
index 0000000..7212bf0
--- /dev/null
+++ b/prebuilt-intermediates/tee
@@ -0,0 +1 @@
+../include/tee
\ No newline at end of file
diff --git a/prebuilt-intermediates/timestamp.h b/prebuilt-intermediates/timestamp.h
new file mode 120000
index 0000000..ea7a630
--- /dev/null
+++ b/prebuilt-intermediates/timestamp.h
@@ -0,0 +1 @@
+../include/timestamp.h
\ No newline at end of file
diff --git a/prebuilt-intermediates/u-boot b/prebuilt-intermediates/u-boot
new file mode 120000
index 0000000..0d1a07f
--- /dev/null
+++ b/prebuilt-intermediates/u-boot
@@ -0,0 +1 @@
+../include/u-boot
\ No newline at end of file
diff --git a/prebuilt-intermediates/version.h b/prebuilt-intermediates/version.h
new file mode 120000
index 0000000..bb57607
--- /dev/null
+++ b/prebuilt-intermediates/version.h
@@ -0,0 +1 @@
+../include/version.h
\ No newline at end of file
diff --git a/prebuilt-intermediates/watchdog.h b/prebuilt-intermediates/watchdog.h
new file mode 120000
index 0000000..d214f99
--- /dev/null
+++ b/prebuilt-intermediates/watchdog.h
@@ -0,0 +1 @@
+../include/watchdog.h
\ No newline at end of file