Skip to contentSkip to conversation

tools: Fix build without host OpenSSL

PATCH In review Alexander Dahl 3 participants 7 messages Dec 21, 2023 – Jan 12, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover tools: Fix build without host OpenSSL

Hei hei,

both patches of the series got a review and this is my last work day of the year, so I just incorporated the feedback, collected the tags, and send this out before returning to office in January.

Link to v2 with whole motivation text:
https://lore.kernel.org/u-boot/[email protected]/

Have some peaceful days everyone.

Greets
Alex

v2 -> v3:
* Rebased on v2024.01-rc5
* Removed a superflous new newline introduced in v1
* Collected tags

Alexander Dahl (1):
tools: kwbimage: Allow disabling build on non-mvebu platforms

Paul-Erwan Rio (1):
tools: fix build without LIBCRYPTO support

 arch/arm/mach-mvebu/Kconfig | 1 +
 include/image.h             | 2 +-
 tools/Kconfig               | 6 ++++++
 tools/Makefile              | 4 +++-
 tools/fit_image.c           | 2 +-
 tools/image-host.c          | 4 ++++
 tools/mkimage.c             | 5 +++--
 7 files changed, 19 insertions(+), 5 deletions(-)

base-commit: 97a897444235921ce19b4f8a3b27de6f5a9ab367

Signature · 1 line
2.39.2
#1 lore raw

PATCH v3 1/2 tools: kwbimage: Allow disabling build on non-mvebu platforms

Some users want to build with CONFIG_TOOLS_LIBCRYPTO disabled, which in general is possible for at least some boards. 32-bit mvebu however requires kwbimage for building SPL, and kwbimage has a hard dependency to host OpenSSL.

The new symbol CONFIG_TOOLS_KWBIMAGE allows disabling kwbimage build on non-mvebu platforms, and thus building without host libcrypto from OpenSSL.

Based on previous work and discussions, see links below.

---

Notes:
This is more or less a mashup of the patches of Pali and Marek, but considering the feedback given by Samuel on Pali's patch and considering what I thought was the preferred style in other parts of the Makefile.

v1 -> v2:
* removed a useless new newline added in v1
* collected tags

 arch/arm/mach-mvebu/Kconfig | 1 +
 tools/Kconfig               | 5 +++++
 tools/Makefile              | 4 +++-
 3 files changed, 9 insertions(+), 1 deletion(-)
arch/arm/mach-mvebu/Kconfig +1 -0
index c80d8587b14..2058c95ca2d 100644
@@ -15,6 +15,7 @@ config ARMADA_32BIT
 	select SUPPORT_SPL
 	select SYS_L2_PL310 if !SYS_L2CACHE_OFF
 	select TRANSLATION_OFFSET
+	select TOOLS_KWBIMAGE if SPL
 	select SPL_SYS_NO_VECTOR_TABLE if SPL
 	select ARCH_VERY_EARLY_INIT
 
tools/Kconfig +5 -0
index 6e23f44d550..f8632cd59d0 100644
@@ -25,6 +25,11 @@ config TOOLS_LIBCRYPTO
 	  This selection does not affect target features, such as runtime FIT
 	  signature verification.
 
+config TOOLS_KWBIMAGE
+	bool "Enable kwbimage support in host tools"
+	default y
+	select TOOLS_LIBCRYPTO
+
 config TOOLS_FIT
 	def_bool y
 	help
tools/Makefile +3 -1
index 1aa1e36137b..6a4280e3668 100644
@@ -94,6 +94,8 @@ LIBCRYPTO_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := \
 			generated/lib/fdt-libcrypto.o \
 			sunxi_toc0.o
 
+KWB_IMAGE_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := kwbimage.o
+
 ROCKCHIP_OBS = generated/lib/rc4.o rkcommon.o rkimage.o rksd.o rkspi.o
 
 # common objs for dumpimage and mkimage
@@ -114,7 +116,7 @@ dumpimage-mkimage-objs := aisimage.o \
 			imximage.o \
 			imx8image.o \
 			imx8mimage.o \
-			kwbimage.o \
+			$(KWB_IMAGE_OBJS-y) \
 			generated/lib/md5.o \
 			lpc32xximage.o \
 			mxsimage.o \
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH v3 1/2] tools: kwbimage: Allow disabling build on non-mvebu platforms

Quoted 11 lines · Alexander Dahl

Some users want to build with CONFIG_TOOLS_LIBCRYPTO disabled, which in general is possible for at least some boards. 32-bit mvebu however requires kwbimage for building SPL, and kwbimage has a hard dependency to host OpenSSL.

The new symbol CONFIG_TOOLS_KWBIMAGE allows disabling kwbimage build on non-mvebu platforms, and thus building without host libcrypto from OpenSSL.

Based on previous work and discussions, see links below.

Quoted 7 lines

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#3 lore raw

PATCH v3 2/2 tools: fix build without LIBCRYPTO support

In reply to Alexander Dahl

From: Paul-Erwan Rio <[email protected]>

Commit cb9faa6f98ae ("tools: Use a single target-independent config to enable OpenSSL") introduced a target-independent configuration to build crypto features in host tools.

But since commit 2c21256b27d7 ("hash: Use Kconfig to enable hashing in host tools and SPL") the build without OpenSSL is broken, due to FIT signature/encryption features. Add missing conditional compilation tokens to fix this.

---

Notes:
Added another guard around the header includes and slightly reworded the commit message. Otherwise it's the same patch as before, so I kept the author as is and only added my Tested-by:
I removed the Reviewed-by: from Simon from this patch, because of the changes mentioned and because the patch was based on an U-Boot three or four releases ago.

v1 -> v2:
* collected tags

 include/image.h    | 2 +-
 tools/Kconfig      | 1 +
 tools/fit_image.c  | 2 +-
 tools/image-host.c | 4 ++++
 tools/mkimage.c    | 5 +++--
 5 files changed, 10 insertions(+), 4 deletions(-)
include/image.h +1 -1
index 2e3cf839ee3..48b8a8995a4 100644
@@ -1391,7 +1391,7 @@ int calculate_hash(const void *data, int data_len, const char *algo,
  * device
  */
 #if defined(USE_HOSTCC)
-# if defined(CONFIG_FIT_SIGNATURE)
+# if CONFIG_IS_ENABLED(FIT_SIGNATURE)
 #  define IMAGE_ENABLE_SIGN	1
 #  define FIT_IMAGE_ENABLE_VERIFY	1
 #  include <openssl/evp.h>
tools/Kconfig +1 -0
index f8632cd59d0..f01ed783e6f 100644
@@ -51,6 +51,7 @@ config TOOLS_FIT_RSASSA_PSS
 	  Support the rsassa-pss signature scheme in the tools builds
 
 config TOOLS_FIT_SIGNATURE
+	depends on TOOLS_LIBCRYPTO
 	def_bool y
 	help
 	  Enable signature verification of FIT uImages in the tools builds
tools/fit_image.c +1 -1
index 71e031c8550..beef1fa86e2 100644
@@ -61,7 +61,7 @@ static int fit_add_file_data(struct image_tool_params *params, size_t size_inc,
 		ret = fit_set_timestamp(ptr, 0, time);
 	}
 
-	if (!ret)
+	if (CONFIG_IS_ENABLED(FIT_SIGNATURE) && !ret)
 		ret = fit_pre_load_data(params->keydir, dest_blob, ptr);
 
 	if (!ret) {
tools/image-host.c +4 -0
index ca4950312f9..90bc9f905f3 100644
@@ -14,8 +14,10 @@
 #include <image.h>
 #include <version.h>
 
+#if CONFIG_IS_ENABLED(FIT_SIGNATURE)
 #include <openssl/pem.h>
 #include <openssl/evp.h>
+#endif
 
 /**
  * fit_set_hash_value - set hash value in requested has node
@@ -1131,6 +1133,7 @@ static int fit_config_add_verification_data(const char *keydir,
 	return 0;
 }
 
+#if CONFIG_IS_ENABLED(FIT_SIGNATURE)
 /*
  * 0) open file (open)
  * 1) read certificate (PEM_read_X509)
@@ -1239,6 +1242,7 @@ int fit_pre_load_data(const char *keydir, void *keydest, void *fit)
  out:
 	return ret;
 }
+#endif
 
 int fit_cipher_data(const char *keydir, void *keydest, void *fit,
 		    const char *comment, int require_keys,
tools/mkimage.c +3 -2
index 6dfe3e1d42d..ac62ebbde9b 100644
@@ -115,7 +115,7 @@ static void usage(const char *msg)
 		"          -B => align size in hex for FIT structure and header\n"
 		"          -b => append the device tree binary to the FIT\n"
 		"          -t => update the timestamp in the FIT\n");
-#ifdef CONFIG_FIT_SIGNATURE
+#if CONFIG_IS_ENABLED(FIT_SIGNATURE)
 	fprintf(stderr,
 		"Signing / verified boot options: [-k keydir] [-K dtb] [ -c <comment>] [-p addr] [-r] [-N engine]\n"
 		"          -k => set directory containing private keys\n"
@@ -130,8 +130,9 @@ static void usage(const char *msg)
 		"          -o => algorithm to use for signing\n");
 #else
 	fprintf(stderr,
-		"Signing / verified boot not supported (CONFIG_FIT_SIGNATURE undefined)\n");
+		"Signing / verified boot not supported (CONFIG_TOOLS_FIT_SIGNATURE undefined)\n");
 #endif
+
 	fprintf(stderr, "       %s -V ==> print version information and exit\n",
 		params.cmdname);
 	fprintf(stderr, "Use '-T list' to see a list of available image types\n");
Signature · 1 line
2.39.2
Reviewed-by on v3 2/2
#4 lore raw

Re: [PATCH v3 2/2] tools: fix build without LIBCRYPTO support

Quoted 29 lines · Alexander Dahl

From: Paul-Erwan Rio <[email protected]>

Commit cb9faa6f98ae ("tools: Use a single target-independent config to enable OpenSSL") introduced a target-independent configuration to build crypto features in host tools.

But since commit 2c21256b27d7 ("hash: Use Kconfig to enable hashing in host tools and SPL") the build without OpenSSL is broken, due to FIT signature/encryption features. Add missing conditional compilation tokens to fix this.

---

Notes:
Added another guard around the header includes and slightly reworded the commit message. Otherwise it's the same patch as before, so I kept the author as is and only added my Tested-by:
I removed the Reviewed-by: from Simon from this patch, because of the changes mentioned and because the patch was based on an U-Boot three or four releases ago.

v1 -> v2:
* collected tags

Quoted 7 lines
 include/image.h    | 2 +-
 tools/Kconfig      | 1 +
 tools/fit_image.c  | 2 +-
 tools/image-host.c | 4 ++++
 tools/mkimage.c    | 5 +++--
 5 files changed, 10 insertions(+), 4 deletions(-)
#5 lore raw

Re: [PATCH v3 2/2] tools: fix build without LIBCRYPTO support

In reply to Alexander Dahl
Quoted 11 lines · Alexander Dahl

From: Paul-Erwan Rio <[email protected]>

Commit cb9faa6f98ae ("tools: Use a single target-independent config to enable OpenSSL") introduced a target-independent configuration to build crypto features in host tools.

But since commit 2c21256b27d7 ("hash: Use Kconfig to enable hashing in host tools and SPL") the build without OpenSSL is broken, due to FIT signature/encryption features. Add missing conditional compilation tokens to fix this.

Quoted 5 lines

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#6 lore raw
In reply to Alexander Dahl

Hello,

Am Thu, Dec 21, 2023 at 08:26:09AM +0100 schrieb Alexander Dahl:

Quoted 9 lines

Hei hei,

both patches of the series got a review and this is my last work day of the year, so I just incorporated the feedback, collected the tags, and send this out before returning to office in January.

Link to v2 with whole motivation text:
https://lore.kernel.org/u-boot/[email protected]/

Quoted 8 lines

Have some peaceful days everyone.

Greets
Alex

v2 -> v3:
* Rebased on v2024.01-rc5
* Removed a superflous new newline introduced in v1

This change was in v2 of course. I made the same mistake in the changelogs of the patches, where it should have been v2 -> v3 instead. Sorry for the confusion.

Greets
Alex

Quoted 34 lines

* Collected tags

Alexander Dahl (1):
tools: kwbimage: Allow disabling build on non-mvebu platforms

Paul-Erwan Rio (1):
tools: fix build without LIBCRYPTO support

 arch/arm/mach-mvebu/Kconfig | 1 +
 include/image.h             | 2 +-
 tools/Kconfig               | 6 ++++++
 tools/Makefile              | 4 +++-
 tools/fit_image.c           | 2 +-
 tools/image-host.c          | 4 ++++
 tools/mkimage.c             | 5 +++--
 7 files changed, 19 insertions(+), 5 deletions(-)

base-commit: 97a897444235921ce19b4f8a3b27de6f5a9ab367

Signature · 1 line
2.39.2