diff mbox series

[6/6] Reorganize includes to have smaller files

Message ID 20230510120643.39588-7-sbabic@denx.de
State Changes Requested
Headers show
Series Cleanup and include restruct | expand

Commit Message

Stefano Babic May 10, 2023, 12:06 p.m. UTC
Some header file like util.h is definetly grown, and this can generate
dependencies between file. Try to cleanup this and move some definitions
to specific file. While all modules require util.h, just a few of them
require specific definitions.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 core/Makefile                      |   1 +
 core/artifacts_versions.c          |   1 +
 core/cpio_utils.c                  |   1 +
 core/hw-compatibility.c            | 114 +++++++++++++++++++++++++++++
 core/network_thread.c              |   1 +
 core/stream_interface.c            |   1 +
 core/swupdate.c                    |   2 +
 core/util.c                        | 101 +------------------------
 corelib/lua_interface.c            |   2 +
 corelib/verify_signature_mbedtls.c |   1 +
 handlers/archive_handler.c         |   2 +-
 handlers/boot_handler.c            |   3 +-
 handlers/copy_handler.c            |   2 +-
 handlers/delta_downloader.c        |   1 +
 handlers/delta_handler.c           |   2 +-
 handlers/diskformat_handler.c      |   1 +
 handlers/diskpart_handler.c        |   2 +-
 handlers/dummy_handler.c           |   2 +-
 handlers/flash_hamming1_handler.c  |   2 +-
 handlers/flash_handler.c           |   2 +-
 handlers/raw_handler.c             |   2 +-
 handlers/rdiff_handler.c           |   2 +-
 handlers/readback_handler.c        |   2 +-
 handlers/remote_handler.c          |   6 +-
 handlers/shell_scripthandler.c     |   2 +-
 handlers/ssbl_handler.c            |   2 +-
 handlers/swuforward_handler.c      |   2 +-
 handlers/ubivol_handler.c          |   2 +-
 handlers/ucfw_handler.c            |   2 +-
 handlers/uniqueuuid_handler.c      |   2 +-
 include/chained_handler.h          |   2 +-
 include/globals.h                  |   5 ++
 include/handler.h                  |   1 +
 include/hw-compatibility.h         |  17 +++++
 include/swupdate.h                 |  74 +------------------
 include/swupdate_image.h           |  77 +++++++++++++++++++
 include/util.h                     |  21 ++++--
 include/versions.h                 |  15 ++++
 parser/parse_external.c            |   1 +
 parser/parser.c                    |   1 +
 40 files changed, 283 insertions(+), 199 deletions(-)
 create mode 100644 core/hw-compatibility.c
 create mode 100644 include/hw-compatibility.h
 create mode 100644 include/swupdate_image.h
 create mode 100644 include/versions.h
diff mbox series

Patch

diff --git a/core/Makefile b/core/Makefile
index 90f1177..621e658 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -13,6 +13,7 @@  obj-y += swupdate.o \
 	 notifier.o \
 	 handler.o \
 	 bootloader.o \
+	 hw-compatibility.o \
 	 install_from_file.o \
 	 util.o \
 	 parser.o \
diff --git a/core/artifacts_versions.c b/core/artifacts_versions.c
index 22a363f..9170327 100644
--- a/core/artifacts_versions.c
+++ b/core/artifacts_versions.c
@@ -23,6 +23,7 @@ 
 #include "parselib.h"
 #include "swupdate_settings.h"
 #include "semver.h"
+#include "versions.h"
 
 /*
  * Read versions of components from a file, if provided
diff --git a/core/cpio_utils.c b/core/cpio_utils.c
index 489a12c..bcf4818 100644
--- a/core/cpio_utils.c
+++ b/core/cpio_utils.c
@@ -20,6 +20,7 @@ 
 
 #include "generated/autoconf.h"
 #include "cpiohdr.h"
+#include "swupdate.h"
 #include "util.h"
 #include "sslapi.h"
 #include "progress.h"
diff --git a/core/hw-compatibility.c b/core/hw-compatibility.c
new file mode 100644
index 0000000..7c6cd25
--- /dev/null
+++ b/core/hw-compatibility.c
@@ -0,0 +1,114 @@ 
+/*
+ * (C) Copyright 2023
+ * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
+ *
+ * SPDX-License-Identifier:     GPL-2.0-only
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include "util.h"
+#include "swupdate.h"
+#include "hw-compatibility.h"
+
+/*
+ * The HW revision of the board *MUST* be inserted
+ * in the sw-description file
+ */
+#ifdef CONFIG_HW_COMPATIBILITY
+int check_hw_compatibility(struct swupdate_cfg *cfg)
+{
+	struct hw_type *hw;
+	int ret;
+
+	ret = get_hw_revision(&cfg->hw);
+	if (ret < 0)
+		return -1;
+
+	TRACE("Hardware %s Revision: %s", cfg->hw.boardname, cfg->hw.revision);
+	LIST_FOREACH(hw, &cfg->hardware, next) {
+		if (hw &&
+		    (!hwid_match(hw->revision, cfg->hw.revision))) {
+			TRACE("Hardware compatibility verified");
+			return 0;
+		}
+	}
+
+	return -1;
+}
+#else
+int check_hw_compatibility(struct swupdate_cfg
+		__attribute__ ((__unused__)) *cfg)
+{
+	return 0;
+}
+#endif
+
+/*
+ * This function is strict bounded with the hardware
+ * It reads some GPIOs to get the hardware revision
+ */
+int get_hw_revision(struct hw_type *hw)
+{
+	FILE *fp;
+	int ret;
+	char *b1, *b2;
+#ifdef CONFIG_HW_COMPATIBILITY_FILE
+#define HW_FILE CONFIG_HW_COMPATIBILITY_FILE
+#else
+#define HW_FILE "/etc/hwrevision"
+#endif
+
+	if (!hw)
+		return -EINVAL;
+
+	/*
+	 * do not overwrite if it is already set
+	 * (maybe from command line)
+	 */
+	if (strlen(hw->boardname))
+		return 0;
+
+	memset(hw->boardname, 0, sizeof(hw->boardname));
+	memset(hw->revision, 0, sizeof(hw->revision));
+
+	/*
+	 * Not all boards have pins for revision number
+	 * check if there is a file containing theHW revision number
+	 */
+	fp = fopen(HW_FILE, "r");
+	if (!fp)
+		return -1;
+
+	ret = fscanf(fp, "%ms %ms", &b1, &b2);
+	fclose(fp);
+
+	if (ret != 2) {
+		TRACE("Cannot find Board Revision");
+		if(ret == 1)
+			free(b1);
+		return -1;
+	}
+
+	if ((strlen(b1) > (SWUPDATE_GENERAL_STRING_SIZE) - 1) ||
+		(strlen(b2) > (SWUPDATE_GENERAL_STRING_SIZE - 1))) {
+		ERROR("Board name or revision too long");
+		ret = -1;
+		goto out;
+	}
+
+	strlcpy(hw->boardname, b1, sizeof(hw->boardname));
+	strlcpy(hw->revision, b2, sizeof(hw->revision));
+
+	ret = 0;
+
+out:
+	free(b1);
+	free(b2);
+
+	return ret;
+}
+
+
diff --git a/core/network_thread.c b/core/network_thread.c
index 6e0a0ba..f4ee335 100644
--- a/core/network_thread.c
+++ b/core/network_thread.c
@@ -30,6 +30,7 @@ 
 #include "installer.h"
 #include "installer_priv.h"
 #include "swupdate.h"
+#include "hw-compatibility.h"
 #include "pctl.h"
 #include "generated/autoconf.h"
 #include "state.h"
diff --git a/core/stream_interface.c b/core/stream_interface.c
index 73990cc..798c285 100644
--- a/core/stream_interface.c
+++ b/core/stream_interface.c
@@ -45,6 +45,7 @@ 
 #include "pctl.h"
 #include "state.h"
 #include "bootloader.h"
+#include "hw-compatibility.h"
 
 #define BUFF_SIZE	 4096
 #define PERCENT_LB_INDEX	4
diff --git a/core/swupdate.c b/core/swupdate.c
index dff2baf..58e7541 100644
--- a/core/swupdate.c
+++ b/core/swupdate.c
@@ -48,6 +48,8 @@ 
 #include "pctl.h"
 #include "state.h"
 #include "bootloader.h"
+#include "versions.h"
+#include "hw-compatibility.h"
 
 #ifdef CONFIG_SYSTEMD
 #include <systemd/sd-daemon.h>
diff --git a/core/util.c b/core/util.c
index 20dec15..14bac1b 100644
--- a/core/util.c
+++ b/core/util.c
@@ -26,12 +26,13 @@ 
 #include <regex.h>
 #include <string.h>
 #include <dirent.h>
+#include "swupdate_dict.h"
+#include "swupdate_image.h"
 
 #if defined(__linux__)
 #include <sys/statvfs.h>
 #endif
 
-#include "swupdate.h"
 #include "util.h"
 #include "generated/autoconf.h"
 
@@ -322,71 +323,6 @@  int mkpath(char *dir, mode_t mode)
 	return 0;
 }
 
-/*
- * This function is strict bounded with the hardware
- * It reads some GPIOs to get the hardware revision
- */
-int get_hw_revision(struct hw_type *hw)
-{
-	FILE *fp;
-	int ret;
-	char *b1, *b2;
-#ifdef CONFIG_HW_COMPATIBILITY_FILE
-#define HW_FILE CONFIG_HW_COMPATIBILITY_FILE
-#else
-#define HW_FILE "/etc/hwrevision"
-#endif
-
-	if (!hw)
-		return -EINVAL;
-
-	/*
-	 * do not overwrite if it is already set
-	 * (maybe from command line)
-	 */
-	if (strlen(hw->boardname))
-		return 0;
-
-	memset(hw->boardname, 0, sizeof(hw->boardname));
-	memset(hw->revision, 0, sizeof(hw->revision));
-
-	/*
-	 * Not all boards have pins for revision number
-	 * check if there is a file containing theHW revision number
-	 */
-	fp = fopen(HW_FILE, "r");
-	if (!fp)
-		return -1;
-
-	ret = fscanf(fp, "%ms %ms", &b1, &b2);
-	fclose(fp);
-
-	if (ret != 2) {
-		TRACE("Cannot find Board Revision");
-		if(ret == 1)
-			free(b1);
-		return -1;
-	}
-
-	if ((strlen(b1) > (SWUPDATE_GENERAL_STRING_SIZE) - 1) ||
-		(strlen(b2) > (SWUPDATE_GENERAL_STRING_SIZE - 1))) {
-		ERROR("Board name or revision too long");
-		ret = -1;
-		goto out;
-	}
-
-	strlcpy(hw->boardname, b1, sizeof(hw->boardname));
-	strlcpy(hw->revision, b2, sizeof(hw->revision));
-
-	ret = 0;
-
-out:
-	free(b1);
-	free(b2);
-
-	return ret;
-}
-
 /**
  * hwid_match - try to match a literal or RE hwid
  * @rev: literal or RE specification
@@ -428,39 +364,6 @@  out:
 	return ret;
 }
 
-/*
- * The HW revision of the board *MUST* be inserted
- * in the sw-description file
- */
-#ifdef CONFIG_HW_COMPATIBILITY
-int check_hw_compatibility(struct swupdate_cfg *cfg)
-{
-	struct hw_type *hw;
-	int ret;
-
-	ret = get_hw_revision(&cfg->hw);
-	if (ret < 0)
-		return -1;
-
-	TRACE("Hardware %s Revision: %s", cfg->hw.boardname, cfg->hw.revision);
-	LIST_FOREACH(hw, &cfg->hardware, next) {
-		if (hw &&
-		    (!hwid_match(hw->revision, cfg->hw.revision))) {
-			TRACE("Hardware compatibility verified");
-			return 0;
-		}
-	}
-
-	return -1;
-}
-#else
-int check_hw_compatibility(struct swupdate_cfg
-		__attribute__ ((__unused__)) *cfg)
-{
-	return 0;
-}
-#endif
-
 uintmax_t
 from_ascii (char const *where, size_t digs, unsigned logbase)
 {
diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index 3268a7b..dd925b7 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -23,6 +23,8 @@ 
 #include "handler.h"
 #include "bootloader.h"
 #include "progress.h"
+#include "swupdate_image.h"
+#include "hw-compatibility.h"
 
 #define LUA_TYPE_PEMBSCR 1
 #define LUA_TYPE_HANDLER 2
diff --git a/corelib/verify_signature_mbedtls.c b/corelib/verify_signature_mbedtls.c
index 1894f56..e3928f1 100644
--- a/corelib/verify_signature_mbedtls.c
+++ b/corelib/verify_signature_mbedtls.c
@@ -8,6 +8,7 @@ 
 
 #include "sslapi.h"
 #include "util.h"
+#include "swupdate.h"
 
 static char *algo_upper(const char *algo)
 {
diff --git a/handlers/archive_handler.c b/handlers/archive_handler.c
index 0ca22ca..cc8aa0b 100644
--- a/handlers/archive_handler.c
+++ b/handlers/archive_handler.c
@@ -20,7 +20,7 @@ 
 #include <archive.h>
 #include <archive_entry.h>
 
-#include "swupdate.h"
+#include "swupdate_image.h"
 #include "handler.h"
 #include "util.h"
 
diff --git a/handlers/boot_handler.c b/handlers/boot_handler.c
index 1324015..c8ae0a0 100644
--- a/handlers/boot_handler.c
+++ b/handlers/boot_handler.c
@@ -14,8 +14,7 @@ 
 #include <errno.h>
 
 #include "generated/autoconf.h"
-#include "swupdate.h"
-#include "swupdate_dict.h"
+#include "swupdate_image.h"
 #include "handler.h"
 #include "util.h"
 #include "bootloader.h"
diff --git a/handlers/copy_handler.c b/handlers/copy_handler.c
index 29226e0..3a8c1e0 100644
--- a/handlers/copy_handler.c
+++ b/handlers/copy_handler.c
@@ -26,7 +26,7 @@ 
 #endif
 
 #include <pctl.h>
-#include "swupdate.h"
+#include "swupdate_image.h"
 #include "progress.h"
 #include "handler.h"
 #include "util.h"
diff --git a/handlers/delta_downloader.c b/handlers/delta_downloader.c
index 8bd07ac..e080092 100644
--- a/handlers/delta_downloader.c
+++ b/handlers/delta_downloader.c
@@ -31,6 +31,7 @@ 
 #include <zlib.h>
 #include <channel.h>
 #include <channel_curl.h>
+#include "swupdate_dict.h"
 #include "delta_handler.h"
 #include "delta_process.h"
 
diff --git a/handlers/delta_handler.c b/handlers/delta_handler.c
index 4ce49ff..d1ff783 100644
--- a/handlers/delta_handler.c
+++ b/handlers/delta_handler.c
@@ -28,7 +28,6 @@ 
 #include <stdlib.h>
 #include <errno.h>
 #include <string.h>
-#include <swupdate.h>
 #include <handler.h>
 #include <signal.h>
 #include <zck.h>
@@ -43,6 +42,7 @@ 
 #include "installer.h"
 #include "zchunk_range.h"
 #include "chained_handler.h"
+#include "swupdate_image.h"
 
 #define DEFAULT_MAX_RANGES	150	/* Apache has default = 200 */
 
diff --git a/handlers/diskformat_handler.c b/handlers/diskformat_handler.c
index d4c4520..742954a 100644
--- a/handlers/diskformat_handler.c
+++ b/handlers/diskformat_handler.c
@@ -12,6 +12,7 @@ 
 #include <blkid/blkid.h>
 #include <fs_interface.h>
 #include "progress.h"
+#include "swupdate_image.h"
 
 void diskformat_handler(void);
 
diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c
index 9f7e85b..e1056ef 100644
--- a/handlers/diskpart_handler.c
+++ b/handlers/diskpart_handler.c
@@ -22,7 +22,7 @@ 
 #include <uuid/uuid.h>
 #include <dirent.h>
 #include <libgen.h>
-#include "swupdate.h"
+#include "swupdate_image.h"
 #include "handler.h"
 #include "util.h"
 #include "progress.h"
diff --git a/handlers/dummy_handler.c b/handlers/dummy_handler.c
index c17b55d..c4cb03b 100644
--- a/handlers/dummy_handler.c
+++ b/handlers/dummy_handler.c
@@ -12,7 +12,7 @@ 
 #include <stdlib.h>
 #include <errno.h>
 
-#include "swupdate.h"
+#include "swupdate_image.h"
 #include "handler.h"
 #include "util.h"
 
diff --git a/handlers/flash_hamming1_handler.c b/handlers/flash_hamming1_handler.c
index 7cdb40a..34493ee 100644
--- a/handlers/flash_hamming1_handler.c
+++ b/handlers/flash_hamming1_handler.c
@@ -25,7 +25,7 @@ 
 #include <sys/ioctl.h>
 
 #include <mtd/mtd-user.h>
-#include "swupdate.h"
+#include "swupdate_image.h"
 #include "handler.h"
 #include "util.h"
 #include "flash.h"
diff --git a/handlers/flash_handler.c b/handlers/flash_handler.c
index 597827d..3cca02b 100644
--- a/handlers/flash_handler.c
+++ b/handlers/flash_handler.c
@@ -25,8 +25,8 @@ 
 #include <sys/ioctl.h>
 
 #include <mtd/mtd-user.h>
-#include "swupdate.h"
 #include "handler.h"
+#include "swupdate_image.h"
 #include "util.h"
 #include "flash.h"
 #include "progress.h"
diff --git a/handlers/raw_handler.c b/handlers/raw_handler.c
index cdd81d3..45f038a 100644
--- a/handlers/raw_handler.c
+++ b/handlers/raw_handler.c
@@ -24,7 +24,7 @@ 
 #include <errno.h>
 #include <libgen.h>
 
-#include "swupdate.h"
+#include "swupdate_image.h"
 #include "handler.h"
 #include "util.h"
 
diff --git a/handlers/rdiff_handler.c b/handlers/rdiff_handler.c
index ae14f0d..268ec6b 100644
--- a/handlers/rdiff_handler.c
+++ b/handlers/rdiff_handler.c
@@ -19,7 +19,7 @@ 
 #if defined(__FreeBSD__)
 #include <sys/param.h>
 #endif
-#include "swupdate.h"
+#include "swupdate_image.h"
 #include "handler.h"
 #include "util.h"
 
diff --git a/handlers/readback_handler.c b/handlers/readback_handler.c
index b4f2c91..4b910bd 100644
--- a/handlers/readback_handler.c
+++ b/handlers/readback_handler.c
@@ -18,8 +18,8 @@ 
 #include <linux/fs.h>
 #endif
 
-#include "swupdate.h"
 #include "handler.h"
+#include "swupdate_image.h"
 #include "sslapi.h"
 #include "util.h"
 
diff --git a/handlers/remote_handler.c b/handlers/remote_handler.c
index 7ed7b50..c4b83af 100644
--- a/handlers/remote_handler.c
+++ b/handlers/remote_handler.c
@@ -15,9 +15,9 @@ 
 #include <string.h>
 #include <zmq.h>
 
-#include <swupdate.h>
-#include <handler.h>
-#include <util.h>
+#include "handler.h"
+#include "util.h"
+#include "swupdate_image.h"
 
 #define MSG_FRAMES	2
 #define FRAME_CMD	0
diff --git a/handlers/shell_scripthandler.c b/handlers/shell_scripthandler.c
index a4b85e7..273b5a0 100644
--- a/handlers/shell_scripthandler.c
+++ b/handlers/shell_scripthandler.c
@@ -16,8 +16,8 @@ 
 #include <errno.h>
 #include <string.h>
 
-#include "swupdate.h"
 #include "handler.h"
+#include "swupdate_image.h"
 #include "util.h"
 #include "pctl.h"
 
diff --git a/handlers/ssbl_handler.c b/handlers/ssbl_handler.c
index 64280f7..93bd6f3 100644
--- a/handlers/ssbl_handler.c
+++ b/handlers/ssbl_handler.c
@@ -16,7 +16,7 @@ 
 #include <stddef.h>
 
 #include <mtd/mtd-user.h>
-#include "swupdate.h"
+#include "swupdate_image.h"
 #include "handler.h"
 #include "util.h"
 #include "flash.h"
diff --git a/handlers/swuforward_handler.c b/handlers/swuforward_handler.c
index 055fe21..468fbfb 100644
--- a/handlers/swuforward_handler.c
+++ b/handlers/swuforward_handler.c
@@ -29,12 +29,12 @@ 
 #include <stdlib.h>
 #include <errno.h>
 #include <string.h>
-#include <swupdate.h>
 #include <handler.h>
 #include <pthread.h>
 #include <util.h>
 #include <json-c/json.h>
 #include "parselib.h"
+#include "swupdate_image.h"
 #include "swuforward_handler.h"
 
 void swuforward_handler(void);
diff --git a/handlers/ubivol_handler.c b/handlers/ubivol_handler.c
index df68590..f9acf2d 100644
--- a/handlers/ubivol_handler.c
+++ b/handlers/ubivol_handler.c
@@ -15,7 +15,7 @@ 
 #include <string.h>
 
 #include <mtd/mtd-user.h>
-#include "swupdate.h"
+#include "swupdate_image.h"
 #include "handler.h"
 #include "flash.h"
 #include "util.h"
diff --git a/handlers/ucfw_handler.c b/handlers/ucfw_handler.c
index b750209..8d10a54 100644
--- a/handlers/ucfw_handler.c
+++ b/handlers/ucfw_handler.c
@@ -69,7 +69,7 @@ 
 #include <termios.h>
 #include <gpiod.h>
 
-#include "swupdate.h"
+#include "swupdate_image.h"
 #include "handler.h"
 #include "util.h"
 
diff --git a/handlers/uniqueuuid_handler.c b/handlers/uniqueuuid_handler.c
index 3ffb8f1..bb324de 100644
--- a/handlers/uniqueuuid_handler.c
+++ b/handlers/uniqueuuid_handler.c
@@ -21,7 +21,7 @@ 
 #include <ctype.h>
 #include <blkid/blkid.h>
 #include <sys/types.h>
-#include "swupdate.h"
+#include "swupdate_image.h"
 #include "handler.h"
 #include "util.h"
 
diff --git a/include/chained_handler.h b/include/chained_handler.h
index 0c74025..65ddac7 100644
--- a/include/chained_handler.h
+++ b/include/chained_handler.h
@@ -5,7 +5,7 @@ 
  * SPDX-License-Identifier:     GPL-2.0-only
  */
 
-#include "swupdate.h"
+#include "swupdate_image.h"
 struct chain_handler_data {
 	struct img_type img;
 };
diff --git a/include/globals.h b/include/globals.h
index a6274a1..a30ec7c 100644
--- a/include/globals.h
+++ b/include/globals.h
@@ -22,6 +22,11 @@ 
 #define MAX_BOOT_SCRIPT_LINE_LENGTH	1024
 #define MAX_SEEK_STRING_SIZE	32
 
+/*
+ * swupdate uses SHA256 hashes
+ */
+#define SHA256_HASH_LENGTH	32
+
 /* These are fixed path to temporary files */
 #define SCRIPTS_DIR_SUFFIX	"scripts/"
 #define DATADST_DIR_SUFFIX	"datadst/"
diff --git a/include/handler.h b/include/handler.h
index 2ca8817..40ff9c0 100644
--- a/include/handler.h
+++ b/include/handler.h
@@ -10,6 +10,7 @@ 
 #ifndef _HANDLER_H
 #define _HANDLER_H
 
+struct img_type;
 typedef enum {
 	NONE,
 	PREINSTALL,
diff --git a/include/hw-compatibility.h b/include/hw-compatibility.h
new file mode 100644
index 0000000..21e7381
--- /dev/null
+++ b/include/hw-compatibility.h
@@ -0,0 +1,17 @@ 
+/*
+ * (C) Copyright 2023
+ * Stefano Babic, sbabic@denx.de.
+ *
+ * SPDX-License-Identifier:     GPL-2.0-only
+ */
+
+#ifndef _SWUPDATE_HW_COMPATIBILITY_H
+#define _SWUPDATE_HW_COMPATIBILITY_H
+
+#include "swupdate.h"
+
+int check_hw_compatibility(struct swupdate_cfg *cfg);
+int get_hw_revision(struct hw_type *hw);
+
+#endif
+
diff --git a/include/swupdate.h b/include/swupdate.h
index 4cce892..e473e41 100644
--- a/include/swupdate.h
+++ b/include/swupdate.h
@@ -14,21 +14,7 @@ 
 #include "globals.h"
 #include "mongoose_interface.h"
 #include "swupdate_dict.h"
-
-#define BOOTVAR_TRANSACTION "recovery_status"
-
-/*
- * swupdate uses SHA256 hashes
- */
-#define SHA256_HASH_LENGTH	32
-
-typedef enum {
-	FLASH,
-	UBI,
-	FILEDEV,
-	PARTITION,
-	SCRIPT
-} imagetype_t;
+#include "swupdate_image.h"
 
 /*
  * this is used to indicate if a file
@@ -41,64 +27,6 @@  typedef enum {
 	INSTALL_FROM_STREAM
 } swupdate_file_t;
 
-typedef enum {
-	SKIP_NONE=0,
-	SKIP_SAME,
-	SKIP_HIGHER,
-	SKIP_SCRIPT
-} skip_t;
-
-enum {
-  COMPRESSED_FALSE,
-  COMPRESSED_TRUE,
-  COMPRESSED_ZLIB,
-  COMPRESSED_ZSTD,
-};
-
-struct sw_version {
-	char name[SWUPDATE_GENERAL_STRING_SIZE];
-	char version[SWUPDATE_GENERAL_STRING_SIZE];
-	int install_if_different;
-	int install_if_higher;
-	LIST_ENTRY(sw_version) next;
-};
-
-LIST_HEAD(swver, sw_version);
-
-struct img_type {
-	struct sw_version id;		/* This is used to compare versions */
-	char type[SWUPDATE_GENERAL_STRING_SIZE]; /* Handler name */
-	char fname[MAX_IMAGE_FNAME];	/* Filename in CPIO archive */
-	char volname[MAX_VOLNAME];	/* Useful for UBI	*/
-	char device[MAX_VOLNAME];	/* device associated with image if any */
-	char path[MAX_IMAGE_FNAME];	/* Path where image must be installed */
-	char mtdname[MAX_IMAGE_FNAME];	/* MTD device where image must be installed */
-	char type_data[SWUPDATE_GENERAL_STRING_SIZE];	/* Data for handler */
-	char extract_file[MAX_IMAGE_FNAME];
-	char filesystem[MAX_IMAGE_FNAME];
-	unsigned long long seek;
-	skip_t skip;
-	int provided;
-	int compressed;
-	int preserve_attributes; /* whether to preserve attributes in archives */
-	bool is_encrypted;
-	char ivt_ascii[33];
-	int install_directly;
-	int is_script;
-	int is_partitioner;
-	struct dict properties;
-	struct dict *bootloader; /* pointer to swupdate_cfg's bootloader dict for handlers to modify */
-	long long partsize;
-	int fdin;	/* Used for streaming file */
-	off_t offset;	/* offset in cpio file */
-	long long size;
-	unsigned int checksum;
-	unsigned char sha256[SHA256_HASH_LENGTH];	/* SHA-256 is 32 byte */
-	LIST_ENTRY(img_type) next;
-};
-
-LIST_HEAD(imglist, img_type);
-
 struct hw_type {
 	char boardname[SWUPDATE_GENERAL_STRING_SIZE];
 	char revision[SWUPDATE_GENERAL_STRING_SIZE];
diff --git a/include/swupdate_image.h b/include/swupdate_image.h
new file mode 100644
index 0000000..7f6c015
--- /dev/null
+++ b/include/swupdate_image.h
@@ -0,0 +1,77 @@ 
+/*
+ * (C) Copyright 2023
+ * Stefano Babic, sbabic@denx.de.
+ *
+ * SPDX-License-Identifier:     GPL-2.0-only
+ */
+
+#ifndef _SWUPDATE_IMAGE_H
+#define _SWUPDATE_IMAGE_H
+
+#include <sys/types.h>
+#include <stdbool.h>
+#include "bsdqueue.h"
+#include "globals.h"
+#include "swupdate_dict.h"
+
+typedef enum {
+	FLASH,
+	UBI,
+	FILEDEV,
+	PARTITION,
+	SCRIPT
+} imagetype_t;
+
+typedef enum {
+	SKIP_NONE=0,
+	SKIP_SAME,
+	SKIP_HIGHER,
+	SKIP_SCRIPT
+} skip_t;
+
+struct sw_version {
+	char name[SWUPDATE_GENERAL_STRING_SIZE];
+	char version[SWUPDATE_GENERAL_STRING_SIZE];
+	int install_if_different;
+	int install_if_higher;
+	LIST_ENTRY(sw_version) next;
+};
+
+LIST_HEAD(swver, sw_version);
+
+struct img_type {
+	struct sw_version id;		/* This is used to compare versions */
+	char type[SWUPDATE_GENERAL_STRING_SIZE]; /* Handler name */
+	char fname[MAX_IMAGE_FNAME];	/* Filename in CPIO archive */
+	char volname[MAX_VOLNAME];	/* Useful for UBI	*/
+	char device[MAX_VOLNAME];	/* device associated with image if any */
+	char path[MAX_IMAGE_FNAME];	/* Path where image must be installed */
+	char mtdname[MAX_IMAGE_FNAME];	/* MTD device where image must be installed */
+	char type_data[SWUPDATE_GENERAL_STRING_SIZE];	/* Data for handler */
+	char extract_file[MAX_IMAGE_FNAME];
+	char filesystem[MAX_IMAGE_FNAME];
+	unsigned long long seek;
+	skip_t skip;
+	int provided;
+	int compressed;
+	int preserve_attributes; /* whether to preserve attributes in archives */
+	bool is_encrypted;
+	char ivt_ascii[33];
+	int install_directly;
+	int is_script;
+	int is_partitioner;
+	struct dict properties;
+	struct dict *bootloader; /* pointer to swupdate_cfg's bootloader dict for handlers to modify */
+	long long partsize;
+	int fdin;	/* Used for streaming file */
+	off_t offset;	/* offset in cpio file */
+	long long size;
+	unsigned int checksum;
+	unsigned char sha256[SHA256_HASH_LENGTH];	/* SHA-256 is 32 byte */
+	LIST_ENTRY(img_type) next;
+};
+
+LIST_HEAD(imglist, img_type);
+
+#endif
+
diff --git a/include/util.h b/include/util.h
index 0d65c15..5baab13 100644
--- a/include/util.h
+++ b/include/util.h
@@ -12,12 +12,13 @@ 
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#include <stdbool.h>
 #if defined(__linux__)
 #include <linux/types.h>
 #endif
-#include "swupdate.h"
+#include "globals.h"
 #include "swupdate_status.h"
-#include "swupdate_settings.h"
+#include "swupdate_dict.h"
 #include "compat.h"
 
 #define NOTIFY_BUF_SIZE 	2048
@@ -32,6 +33,12 @@ 
 #define HWID_REGEXP_PREFIX	"#RE:"
 #define SWUPDATE_ALIGN(A,S)    (((A) + (S) - 1) & ~((S) - 1))
 
+#define BOOTVAR_TRANSACTION "recovery_status"
+
+struct img_type;
+struct imglist;
+struct hw_type;
+
 extern int loglevel;
 extern int exit_code;
 
@@ -48,6 +55,13 @@  typedef enum {
 	SERVER_ID_REQUESTED,
 } server_op_res_t;
 
+enum {
+  COMPRESSED_FALSE,
+  COMPRESSED_TRUE,
+  COMPRESSED_ZLIB,
+  COMPRESSED_ZSTD,
+};
+
 /*
  * loglevel is used into TRACE / ERROR
  * for values > LASTLOGLEVEL, it is an encoded field 
@@ -206,11 +220,8 @@  char *substring(const char *src, int first, int len);
 char *string_tolower(char *s);
 size_t snescape(char *dst, size_t n, const char *src);
 void freeargs (char **argv);
-int get_hw_revision(struct hw_type *hw);
-void get_sw_versions(swupdate_cfg_handle *handle, struct swupdate_cfg *sw);
 int compare_versions(const char* left_version, const char* right_version);
 int hwid_match(const char* rev, const char* hwrev);
-int check_hw_compatibility(struct swupdate_cfg *cfg);
 int count_elem_list(struct imglist *list);
 unsigned int count_string_array(const char **nodes);
 void free_string_array(char **nodes);
diff --git a/include/versions.h b/include/versions.h
new file mode 100644
index 0000000..b85f718
--- /dev/null
+++ b/include/versions.h
@@ -0,0 +1,15 @@ 
+/*
+ * (C) Copyright 2023
+ * Stefano Babic, sbabic@denx.de.
+ *
+ * SPDX-License-Identifier:     GPL-2.0-only
+ */
+
+#ifndef _SWUPDATE_VERSION_H
+#define _SWUPDATE_VERSION_H
+
+#include "swupdate_settings.h"
+void get_sw_versions(swupdate_cfg_handle *handle, struct swupdate_cfg *sw);
+
+#endif
+
diff --git a/parser/parse_external.c b/parser/parse_external.c
index c6ab4fe..bba0cab 100644
--- a/parser/parse_external.c
+++ b/parser/parse_external.c
@@ -15,6 +15,7 @@ 
 #include "generated/autoconf.h"
 #include "swupdate.h"
 #include "parsers.h"
+#include "hw-compatibility.h"
 
 #ifdef CONFIG_LUAEXTERNAL
 #include "lua.h"
diff --git a/parser/parser.c b/parser/parser.c
index cb7a373..f2d4948 100644
--- a/parser/parser.c
+++ b/parser/parser.c
@@ -20,6 +20,7 @@ 
 #include "bsdqueue.h"
 #include "util.h"
 #include "swupdate.h"
+#include "hw-compatibility.h"
 #include "parselib.h"
 #include "parsers.h"
 #include "swupdate_dict.h"