Merge tag 'u-boot-atmel-fixes-2019.10-a' of https://gitlab.denx.de/u-boot/custodians/u-boot-atmel

First set of u-boot-atmel fixes for 2019.10 cycle:

This includes only tiny cleanups on env changes related to 2019.10 new
features: removal of duplicate env settings (otherwise there may be
warnings in building..) and a small fix for flashes on Gardena smart
gateway (requires nand bad block tables).
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 84e79bf..a1c5b4f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -145,6 +145,13 @@
   script:
     - make tools-only_config tools-only -j$(nproc)
 
+# Ensure env tools build
+Build envtools:
+  tags: [ 'all' ]
+  stage: testsuites
+  script:
+    - make tools-only_config envtools -j$(nproc)
+
 Run binman, buildman, dtoc and patman testsuites:
   tags: [ 'all' ]
   stage: testsuites
diff --git a/.travis.yml b/.travis.yml
index 59d2e97..0ce09e3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -361,6 +361,10 @@
     - name: "Build tools-only"
       script:
         - make tools-only_config tools-only -j$(nproc)
+    # Ensure env tools build
+    - name: "Build envtools"
+      script:
+        - make tools-only_config envtools -j$(nproc)
 
     # test/py
     - name: "test/py sandbox"
diff --git a/arch/arm/mach-rockchip/make_fit_atf.py b/arch/arm/mach-rockchip/make_fit_atf.py
index b9a1988..585edcf 100755
--- a/arch/arm/mach-rockchip/make_fit_atf.py
+++ b/arch/arm/mach-rockchip/make_fit_atf.py
@@ -82,7 +82,7 @@
     file.write('\t\t\tdescription = "%s";\n' % dtname)
     file.write('\t\t\tfirmware = "atf_1";\n')
     file.write('\t\t\tloadables = "uboot"')
-    if segments != 0:
+    if segments > 1:
         file.write(',')
     for i in range(1, segments):
         file.write('"atf_%d"' % (i + 1))
@@ -90,7 +90,7 @@
             file.write(',')
         else:
             file.write(';\n')
-    if segments == 0:
+    if segments <= 1:
         file.write(';\n')
     file.write('\t\t\tfdt = "fdt_1";\n')
     file.write('\t\t};\n')
diff --git a/arch/arm/mach-rockchip/misc.c b/arch/arm/mach-rockchip/misc.c
index fdb763c..c0e4fdb 100644
--- a/arch/arm/mach-rockchip/misc.c
+++ b/arch/arm/mach-rockchip/misc.c
@@ -70,7 +70,7 @@
 	}
 
 	/* read the cpu_id range from the efuses */
-	ret = misc_read(dev, cpuid_offset, cpuid, sizeof(cpuid));
+	ret = misc_read(dev, cpuid_offset, cpuid, cpuid_length);
 	if (ret) {
 		debug("%s: reading cpuid from the efuses failed\n",
 		      __func__);
diff --git a/include/env.h b/include/env.h
index a74a261..b72239f 100644
--- a/include/env.h
+++ b/include/env.h
@@ -9,6 +9,7 @@
 #ifndef __ENV_H
 #define __ENV_H
 
+#include <compiler.h>
 #include <stdbool.h>
 #include <linux/types.h>
 
diff --git a/lib/efi_loader/efi_unicode_collation.c b/lib/efi_loader/efi_unicode_collation.c
index 243c51a..c700be8 100644
--- a/lib/efi_loader/efi_unicode_collation.c
+++ b/lib/efi_loader/efi_unicode_collation.c
@@ -43,11 +43,6 @@
  * See the Unified Extensible Firmware Interface (UEFI) specification for
  * details.
  *
- * TODO:
- * The implementation does not follow the Unicode collation algorithm.
- * For ASCII characters it results in the same sort order as EDK2.
- * We could use table UNICODE_CAPITALIZATION_TABLE for better results.
- *
  * Return:	0: s1 == s2, > 0: s1 > s2, < 0: s1 < s2
  */
 static efi_intn_t EFIAPI efi_stri_coll(
diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c
index 48ee255..4c554c5 100644
--- a/lib/efi_loader/efi_variable.c
+++ b/lib/efi_loader/efi_variable.c
@@ -443,8 +443,6 @@
 	if (ret)
 		goto out;
 
-#define ACCESS_ATTR (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)
-
 	old_val = env_get(native_name);
 	if (old_val) {
 		old_val = parse_attr(old_val, &attr);
@@ -455,7 +453,9 @@
 			goto out;
 		}
 
-		if ((data_size == 0) || !(attributes & ACCESS_ATTR)) {
+		if ((data_size == 0 &&
+		     !(attributes & EFI_VARIABLE_APPEND_WRITE)) ||
+		    !attributes) {
 			/* delete the variable: */
 			env_set(native_name, NULL);
 			ret = EFI_SUCCESS;
@@ -470,7 +470,7 @@
 
 		if (attributes & EFI_VARIABLE_APPEND_WRITE) {
 			if (!prefix(old_val, "(blob)")) {
-				return EFI_DEVICE_ERROR;
+				ret = EFI_DEVICE_ERROR;
 				goto out;
 			}
 			old_size = strlen(old_val);
@@ -478,8 +478,9 @@
 			old_size = 0;
 		}
 	} else {
-		if ((data_size == 0) || !(attributes & ACCESS_ATTR) ||
-		    (attributes & EFI_VARIABLE_APPEND_WRITE)) {
+		if ((data_size == 0 &&
+		     !(attributes & EFI_VARIABLE_APPEND_WRITE)) ||
+		    !attributes) {
 			/* delete, but nothing to do */
 			ret = EFI_NOT_FOUND;
 			goto out;
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 95c9984..e2801f5 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -119,13 +119,6 @@
 
 static int have_redund_env;
 
-static unsigned char ENV_REDUND_ACTIVE = 1;
-/*
- * ENV_REDUND_OBSOLETE must be 0 to efficiently set it on NOR flash without
- * erasing
- */
-static unsigned char ENV_REDUND_OBSOLETE;
-
 #define DEFAULT_ENV_INSTANCE_STATIC
 #include <env_default.h>
 
@@ -1142,6 +1135,7 @@
 {
 	int rc;
 	struct erase_info_user erase;
+	char tmp = ENV_REDUND_OBSOLETE;
 
 	erase.start = DEVOFFSET(dev);
 	erase.length = DEVESIZE(dev);
@@ -1153,7 +1147,7 @@
 		return rc;
 	}
 	ioctl(fd, MEMUNLOCK, &erase);
-	rc = write(fd, &ENV_REDUND_OBSOLETE, sizeof(ENV_REDUND_OBSOLETE));
+	rc = write(fd, &tmp, sizeof(tmp));
 	ioctl(fd, MEMLOCK, &erase);
 	if (rc < 0)
 		perror("Could not set obsolete flag");