bootutil: Move duplicate static inline functions to one header
The commit moves static common functions that have duplicate
definitions in bootutil_public.c and bootutil_misc.c to header
file to be included by both files.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
diff --git a/boot/bootutil/src/bootutil_misc.c b/boot/bootutil/src/bootutil_misc.c
index 9787005..f1160e4 100644
--- a/boot/bootutil/src/bootutil_misc.c
+++ b/boot/bootutil/src/bootutil_misc.c
@@ -35,6 +35,7 @@
#include "bootutil/image.h"
#include "bootutil/bootutil.h"
#include "bootutil_priv.h"
+#include "bootutil_misc.h"
#include "bootutil/bootutil_log.h"
#include "bootutil/fault_injection_hardening.h"
#ifdef MCUBOOT_ENC_IMAGES
@@ -185,39 +186,6 @@
return flash_area_get_size(fap) - off_from_end;
}
-static int
-boot_magic_decode(const uint8_t *magic)
-{
- if (memcmp(magic, BOOT_IMG_MAGIC, BOOT_MAGIC_SZ) == 0) {
- return BOOT_MAGIC_GOOD;
- }
- return BOOT_MAGIC_BAD;
-}
-
-static inline uint32_t
-boot_magic_off(const struct flash_area *fap)
-{
- return flash_area_get_size(fap) - BOOT_MAGIC_SZ;
-}
-
-static inline uint32_t
-boot_image_ok_off(const struct flash_area *fap)
-{
- return ALIGN_DOWN(boot_magic_off(fap) - BOOT_MAX_ALIGN, BOOT_MAX_ALIGN);
-}
-
-static inline uint32_t
-boot_copy_done_off(const struct flash_area *fap)
-{
- return boot_image_ok_off(fap) - BOOT_MAX_ALIGN;
-}
-
-static inline uint32_t
-boot_swap_size_off(const struct flash_area *fap)
-{
- return boot_swap_info_off(fap) - BOOT_MAX_ALIGN;
-}
-
#ifdef MCUBOOT_ENC_IMAGES
static inline uint32_t
boot_enc_key_off(const struct flash_area *fap, uint8_t slot)
diff --git a/boot/bootutil/src/bootutil_misc.h b/boot/bootutil/src/bootutil_misc.h
new file mode 100644
index 0000000..1fcaabd
--- /dev/null
+++ b/boot/bootutil/src/bootutil_misc.h
@@ -0,0 +1,52 @@
+/*
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Copyright (c) 2023 Nordic Semiconductor ASA
+ *
+ */
+#ifndef H_BOOTUTIL_MISC_
+#define H_BOOTUTIL_MISC_
+
+#include <string.h>
+#include <inttypes.h>
+#include <stddef.h>
+
+#include "bootutil/bootutil_public.h"
+#ifdef MCUBOOT_ENC_IMAGES
+#include "bootutil/enc_key.h"
+#endif
+
+static int
+boot_magic_decode(const uint8_t *magic)
+{
+ if (memcmp(magic, BOOT_IMG_MAGIC, BOOT_MAGIC_SZ) == 0) {
+ return BOOT_MAGIC_GOOD;
+ }
+ return BOOT_MAGIC_BAD;
+}
+
+static inline uint32_t
+boot_magic_off(const struct flash_area *fap)
+{
+ return flash_area_get_size(fap) - BOOT_MAGIC_SZ;
+}
+
+static inline uint32_t
+boot_image_ok_off(const struct flash_area *fap)
+{
+ return ALIGN_DOWN(boot_magic_off(fap) - BOOT_MAX_ALIGN, BOOT_MAX_ALIGN);
+}
+
+static inline uint32_t
+boot_copy_done_off(const struct flash_area *fap)
+{
+ return boot_image_ok_off(fap) - BOOT_MAX_ALIGN;
+}
+
+static inline uint32_t
+boot_swap_size_off(const struct flash_area *fap)
+{
+ return boot_swap_info_off(fap) - BOOT_MAX_ALIGN;
+}
+
+#endif /* H_BOOTUTIL_MISC_ */
diff --git a/boot/bootutil/src/bootutil_public.c b/boot/bootutil/src/bootutil_public.c
index c567892..e26cc09 100644
--- a/boot/bootutil/src/bootutil_public.c
+++ b/boot/bootutil/src/bootutil_public.c
@@ -49,6 +49,7 @@
#include "bootutil/boot_public_hooks.h"
#include "bootutil_priv.h"
+#include "bootutil_misc.h"
#ifdef CONFIG_MCUBOOT
BOOT_LOG_MODULE_DECLARE(mcuboot);
@@ -129,15 +130,6 @@
(sizeof boot_swap_tables / sizeof boot_swap_tables[0])
static int
-boot_magic_decode(const uint8_t *magic)
-{
- if (memcmp(magic, BOOT_IMG_MAGIC, BOOT_MAGIC_SZ) == 0) {
- return BOOT_MAGIC_GOOD;
- }
- return BOOT_MAGIC_BAD;
-}
-
-static int
boot_flag_decode(uint8_t flag)
{
if (flag != BOOT_FLAG_SET) {
@@ -146,24 +138,6 @@
return BOOT_FLAG_SET;
}
-static inline uint32_t
-boot_magic_off(const struct flash_area *fap)
-{
- return flash_area_get_size(fap) - BOOT_MAGIC_SZ;
-}
-
-static inline uint32_t
-boot_image_ok_off(const struct flash_area *fap)
-{
- return ALIGN_DOWN(boot_magic_off(fap) - BOOT_MAX_ALIGN, BOOT_MAX_ALIGN);
-}
-
-static inline uint32_t
-boot_copy_done_off(const struct flash_area *fap)
-{
- return boot_image_ok_off(fap) - BOOT_MAX_ALIGN;
-}
-
uint32_t
boot_swap_info_off(const struct flash_area *fap)
{