Commit d49cfc14 authored by Dominik Ermel's avatar Dominik Ermel Committed by Andrzej Puzdrowski
Browse files

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: default avatarDominik Ermel <dominik.ermel@nordicsemi.no>
parent c5faf431
Loading
Loading
Loading
Loading
+15 −3
Changes for boot/boot_serial/src/boot_serial.c: 15 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -124,6 +124,10 @@ extern int bs_peruser_system_specific(const struct nmgr_hdr *hdr,
                                      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 @@ u32toa(char *tgt, uint32_t val)
    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 @@ bs_list_img_ver(char *dst, int maxlen, struct image_version *ver)
    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.
+3 −0
Changes for boot/zephyr/include/mcuboot_config/mcuboot_config.h: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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