boot_serial: zephyr: Use snprintf to format version string
Move formatting of version string to use snprintf, which Zephyr
provides, instead defining utility function for that purpose.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
diff --git a/boot/boot_serial/src/boot_serial.c b/boot/boot_serial/src/boot_serial.c
index e8c2fe2..4a0f1f8 100644
--- a/boot/boot_serial/src/boot_serial.c
+++ b/boot/boot_serial/src/boot_serial.c
@@ -124,6 +124,10 @@
const char *buffer,
int len, zcbor_state_t *cs);
+#define zcbor_tstr_put_lit_cast(state, string) \
+ zcbor_tstr_encode_ptr(state, (uint8_t *)string, sizeof(string) - 1)
+
+#ifndef MCUBOOT_USE_SNPRINTF
/*
* Convert version into string without use of snprintf().
*/
@@ -153,9 +157,6 @@
return dst - tgt;
}
-#define zcbor_tstr_put_lit_cast(state, string) \
- zcbor_tstr_encode_ptr(state, (uint8_t *)string, sizeof(string) - 1)
-
/*
* dst has to be able to fit "255.255.65535.4294967295" (25 characters).
*/
@@ -172,6 +173,17 @@
dst[off++] = '.';
off += u32toa(dst + off, ver->iv_build_num);
}
+#else
+/*
+ * dst has to be able to fit "255.255.65535.4294967295" (25 characters).
+ */
+static void
+bs_list_img_ver(char *dst, int maxlen, struct image_version *ver)
+{
+ snprintf(dst, maxlen, "%hu.%hu.%hu.%u", (uint16_t)ver->iv_major,
+ (uint16_t)ver->iv_minor, ver->iv_revision, ver->iv_build_num);
+}
+#endif /* !MCUBOOT_USE_SNPRINTF */
/*
* List images.
diff --git a/boot/zephyr/include/mcuboot_config/mcuboot_config.h b/boot/zephyr/include/mcuboot_config/mcuboot_config.h
index 91a6033..d56b92a 100644
--- a/boot/zephyr/include/mcuboot_config/mcuboot_config.h
+++ b/boot/zephyr/include/mcuboot_config/mcuboot_config.h
@@ -53,6 +53,9 @@
#endif
#endif
+/* Zephyr, regardless of C library used, provides snprintf */
+#define MCUBOOT_USE_SNPRINTF 1
+
#ifdef CONFIG_BOOT_HW_KEY
#define MCUBOOT_HW_KEY
#endif