Merge branch '2023-05-31-assorted-fixes-and-improvements' into next

- Makefile logic fixes, address some issues that clang uncovers on ARM,
  assorted code cleanups
diff --git a/Makefile b/Makefile
index 3f5249c..65098ad 100644
--- a/Makefile
+++ b/Makefile
@@ -1812,7 +1812,7 @@
 		rm -f $@; \
 		touch $@ ; \
 	fi
-include/generated/env.in: include/generated/env.txt FORCE
+include/generated/env.in: include/generated/env.txt
 	$(call cmd,gen_envp)
 
 # Regenerate the environment if it changes
@@ -1830,7 +1830,7 @@
 		touch $@ ; \
 	fi
 
-include/generated/env.txt: $(wildcard $(ENV_FILE)) FORCE
+include/generated/env.txt: $(wildcard $(ENV_FILE))
 	$(call cmd,envc)
 
 # Write out the resulting environment, converted to a C string
diff --git a/arch/arm/include/asm/linkage.h b/arch/arm/include/asm/linkage.h
index dbe4b4e..73bf25b 100644
--- a/arch/arm/include/asm/linkage.h
+++ b/arch/arm/include/asm/linkage.h
@@ -1,7 +1,7 @@
 #ifndef __ASM_LINKAGE_H
 #define __ASM_LINKAGE_H
 
-#define __ALIGN .align 0
-#define __ALIGN_STR ".align 0"
+#define __ALIGN .p2align 2
+#define __ALIGN_STR ".p2align 2"
 
 #endif
diff --git a/cmd/fdt.c b/cmd/fdt.c
index aae3278..2401ea8 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -733,7 +733,7 @@
 
 		gd->fdt_blob = blob;
 		cfg_noffset = fit_conf_get_node(working_fdt, NULL);
-		if (!cfg_noffset) {
+		if (cfg_noffset < 0) {
 			printf("Could not find configuration node: %s\n",
 			       fdt_strerror(cfg_noffset));
 			return CMD_RET_FAILURE;
diff --git a/cmd/fs.c b/cmd/fs.c
index 5ad1164..6044f73 100644
--- a/cmd/fs.c
+++ b/cmd/fs.c
@@ -20,7 +20,7 @@
 	"determine a file's size",
 	"<interface> <dev[:part]> <filename>\n"
 	"    - Find file 'filename' from 'dev' on 'interface'\n"
-	"      and determine its size."
+	"      determine its size, and store in the 'filesize' variable."
 );
 
 static int do_load_wrapper(struct cmd_tbl *cmdtp, int flag, int argc,
diff --git a/cmd/legacy-mtd-utils.c b/cmd/legacy-mtd-utils.c
index ac7139f..5903a90 100644
--- a/cmd/legacy-mtd-utils.c
+++ b/cmd/legacy-mtd-utils.c
@@ -88,6 +88,11 @@
 		return -1;
 	}
 
+	if (*size == 0) {
+		debug("ERROR: Invalid size 0\n");
+		return -1;
+	}
+
 print:
 	printf("device %d ", *idx);
 	if (*size == chipsize)
diff --git a/cmd/sf.c b/cmd/sf.c
index 11b9c25..55bef2f 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -353,6 +353,11 @@
 	if (ret != 1)
 		return CMD_RET_USAGE;
 
+	if (size == 0) {
+		debug("ERROR: Invalid size 0\n");
+		return CMD_RET_FAILURE;
+	}
+
 	/* Consistency checking */
 	if (offset + size > flash->size) {
 		printf("ERROR: attempting %s past flash size (%#x)\n",
diff --git a/cmd/version.c b/cmd/version.c
index 190ef6a..87e1fa4 100644
--- a/cmd/version.c
+++ b/cmd/version.c
@@ -19,6 +19,8 @@
 	U_BOOT_TIME " " U_BOOT_TZ ")" CONFIG_IDENT_STRING
 
 const char version_string[] = U_BOOT_VERSION_STRING;
+const unsigned short version_num = U_BOOT_VERSION_NUM;
+const unsigned char version_num_patch = U_BOOT_VERSION_NUM_PATCH;
 
 static int do_version(struct cmd_tbl *cmdtp, int flag, int argc,
 		      char *const argv[])
diff --git a/common/cli_hush.c b/common/cli_hush.c
index 171069f..cee8724 100644
--- a/common/cli_hush.c
+++ b/common/cli_hush.c
@@ -324,7 +324,7 @@
 /* I can almost use ordinary FILE *.  Is open_memstream() universally
  * available?  Where is it documented? */
 struct in_str {
-	const char *p;
+	const unsigned char *p;
 #ifndef __U_BOOT__
 	char peek_buf[2];
 #endif
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 72078a8..801c4b5 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -331,7 +331,7 @@
 
 	conf_noffset = fit_conf_get_node((const void *)header,
 					 fit_uname_config);
-	if (conf_noffset <= 0)
+	if (conf_noffset < 0)
 		return 0;
 
 	for (idx = 0;
diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
index 516dda6..b2ee5f1 100644
--- a/drivers/dfu/dfu.c
+++ b/drivers/dfu/dfu.c
@@ -135,6 +135,7 @@
 			a = s;
 		do {
 			part = strsep(&a, ";");
+			part = skip_spaces(part);
 			ret = dfu_alt_add(dfu, i, d, part);
 			if (ret)
 				return ret;
@@ -629,6 +630,7 @@
 
 	for (i = 0; i < dfu_alt_num; i++) {
 		s = strsep(&env, ";");
+		s = skip_spaces(s);
 		ret = dfu_alt_add(dfu, interface, devstr, s);
 		if (ret) {
 			/* We will free "dfu" in dfu_free_entities() */
diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
index 621146b..4e9d9b7 100644
--- a/drivers/fastboot/fb_common.c
+++ b/drivers/fastboot/fb_common.c
@@ -135,7 +135,7 @@
 	s = env_get("fastboot_bootcmd");
 	if (s) {
 		run_command(s, CMD_FLAG_ENV);
-	} else {
+	} else if (IS_ENABLED(CONFIG_CMD_BOOTM)) {
 		static char boot_addr_start[20];
 		static char *const bootm_args[] = {
 			"bootm", boot_addr_start, NULL
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 1af6af8..72c1076 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -2262,7 +2262,7 @@
 		return 0;
 
 	if (!mmc->ext_csd)
-		memset(ext_csd_bkup, 0, sizeof(ext_csd_bkup));
+		memset(ext_csd_bkup, 0, MMC_MAX_BLOCK_LEN);
 
 	err = mmc_send_ext_csd(mmc, ext_csd);
 	if (err)
diff --git a/fs/semihostingfs.c b/fs/semihostingfs.c
index 96eb334..3592338 100644
--- a/fs/semihostingfs.c
+++ b/fs/semihostingfs.c
@@ -57,8 +57,12 @@
 {
 	long fd, size, ret;
 
+	/* Try to open existing file */
 	fd = smh_open(filename, MODE_READ | MODE_BINARY | MODE_PLUS);
 	if (fd < 0)
+		/* Create new file */
+		fd = smh_open(filename, MODE_WRITE | MODE_BINARY);
+	if (fd < 0)
 		return fd;
 	ret = smh_seek(fd, pos);
 	if (ret < 0) {
diff --git a/include/version_string.h b/include/version_string.h
index a89a6e4..a7d07e4 100644
--- a/include/version_string.h
+++ b/include/version_string.h
@@ -4,5 +4,7 @@
 #define	__VERSION_STRING_H__
 
 extern const char version_string[];
+extern const unsigned short version_num;
+extern const unsigned char version_num_patch;
 
 #endif	/* __VERSION_STRING_H__ */
diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c
index 7c4189e..a8d4b47 100644
--- a/lib/acpi/acpi_table.c
+++ b/lib/acpi/acpi_table.c
@@ -11,8 +11,7 @@
 #include <log.h>
 #include <mapmem.h>
 #include <tables_csum.h>
-#include <timestamp.h>
-#include <version.h>
+#include <version_string.h>
 #include <acpi/acpi_table.h>
 #include <asm/global_data.h>
 #include <dm/acpi.h>
@@ -25,12 +24,12 @@
  * to have valid date. So for U-Boot version 2021.04 OEM_REVISION is set to
  * value 0x20210401.
  */
-#define OEM_REVISION ((((U_BOOT_VERSION_NUM / 1000) % 10) << 28) | \
-		      (((U_BOOT_VERSION_NUM / 100) % 10) << 24) | \
-		      (((U_BOOT_VERSION_NUM / 10) % 10) << 20) | \
-		      ((U_BOOT_VERSION_NUM % 10) << 16) | \
-		      (((U_BOOT_VERSION_NUM_PATCH / 10) % 10) << 12) | \
-		      ((U_BOOT_VERSION_NUM_PATCH % 10) << 8) | \
+#define OEM_REVISION ((((version_num / 1000) % 10) << 28) | \
+		      (((version_num / 100) % 10) << 24) | \
+		      (((version_num / 10) % 10) << 20) | \
+		      ((version_num % 10) << 16) | \
+		      (((version_num_patch / 10) % 10) << 12) | \
+		      ((version_num_patch % 10) << 8) | \
 		      0x01)
 
 int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags)
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 13a35ea..1a8c8d7 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -23,6 +23,7 @@
 
 ifdef CONFIG_RISCV
 always += boothart.efi
+targets += boothart.o
 endif
 
 ifneq ($(CONFIG_CMD_BOOTEFI_HELLO_COMPILE),)
@@ -32,10 +33,12 @@
 
 ifeq ($(CONFIG_GENERATE_ACPI_TABLE),)
 always += dtbdump.efi
+targets += dtbdump.o
 endif
 
 ifdef CONFIG_EFI_LOAD_FILE2_INITRD
 always += initrddump.efi
+targets += initrddump.o
 endif
 
 obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 7362a39..f5ab7af 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -186,7 +186,7 @@
 # Modified for U-Boot
 dtc_cpp_flags  = -Wp,-MD,$(depfile).pre.tmp -nostdinc                    \
 		 $(UBOOTINCLUDE)                                         \
-		 -I$(srctree)/arch/$(ARCH)/dts                           \
+		 -I$(dir $<)                                             \
 		 -I$(srctree)/arch/$(ARCH)/dts/include                   \
 		 -I$(srctree)/include                                    \
 		 -D__ASSEMBLY__                                          \
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
index 9634fc2..818f715 100644
--- a/test/dm/acpi.c
+++ b/test/dm/acpi.c
@@ -11,10 +11,8 @@
 #include <dm.h>
 #include <malloc.h>
 #include <mapmem.h>
-#include <timestamp.h>
-#include <version.h>
 #include <tables_csum.h>
-#include <version.h>
+#include <version_string.h>
 #include <acpi/acpigen.h>
 #include <acpi/acpi_device.h>
 #include <acpi/acpi_table.h>
@@ -26,12 +24,12 @@
 
 #define BUF_SIZE		4096
 
-#define OEM_REVISION ((((U_BOOT_VERSION_NUM / 1000) % 10) << 28) | \
-		      (((U_BOOT_VERSION_NUM / 100) % 10) << 24) | \
-		      (((U_BOOT_VERSION_NUM / 10) % 10) << 20) | \
-		      ((U_BOOT_VERSION_NUM % 10) << 16) | \
-		      (((U_BOOT_VERSION_NUM_PATCH / 10) % 10) << 12) | \
-		      ((U_BOOT_VERSION_NUM_PATCH % 10) << 8) | \
+#define OEM_REVISION ((((version_num / 1000) % 10) << 28) | \
+		      (((version_num / 100) % 10) << 24) | \
+		      (((version_num / 10) % 10) << 20) | \
+		      ((version_num % 10) << 16) | \
+		      (((version_num_patch / 10) % 10) << 12) | \
+		      ((version_num_patch % 10) << 8) | \
 		      0x01)
 
 /**