From eb3d128a8d9876d82ab31220cae16632335e2626 Mon Sep 17 00:00:00 2001 From: Ryan Thompson Date: Wed, 22 Nov 2023 13:01:56 -0600 Subject: [PATCH] libbladeRF: image: bladerf_image_print_metadata added Ex: Magic: bladeRF Version: 0.1.0 Timestamp: 655e530f Serial: Address: 0 Length: 0 --- .../libraries/libbladeRF/include/libbladeRF.h | 21 +++++++++++++++++++ .../libbladeRF/src/board/bladerf1/image.c | 17 +++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/host/libraries/libbladeRF/include/libbladeRF.h b/host/libraries/libbladeRF/include/libbladeRF.h index 0d8a30a2..92805d56 100644 --- a/host/libraries/libbladeRF/include/libbladeRF.h +++ b/host/libraries/libbladeRF/include/libbladeRF.h @@ -3432,6 +3432,27 @@ struct bladerf_image *CALL_CONV bladerf_alloc_cal_image( API_EXPORT void CALL_CONV bladerf_free_image(struct bladerf_image *image); +/** + * @brief Prints the metadata of a bladeRF image structure. + * + * This function displays the metadata of a provided `bladerf_image` structure. + * It includes information such as the magic number, version, timestamp, serial number, + * address, and length of the image. The function will return an error code if the + * provided image pointer is `NULL`. + * + * @pre The image should have been allocated using bladerf_alloc_image(). + * + * @note This function only prints the metadata of the image and does not + * perform any operations on the image data itself. + * + * @param[in] image Pointer to the `bladerf_image` structure whose metadata is to be printed. + * It should not be `NULL`. + * + * @return 0 on success, BLADERF_ERR_MEM if the image pointer is `NULL`. + */ +API_EXPORT +int CALL_CONV bladerf_image_print_metadata(const struct bladerf_image *image); + /** * Write a flash image to a file. * diff --git a/host/libraries/libbladeRF/src/board/bladerf1/image.c b/host/libraries/libbladeRF/src/board/bladerf1/image.c index dacfcc92..c3380573 100644 --- a/host/libraries/libbladeRF/src/board/bladerf1/image.c +++ b/host/libraries/libbladeRF/src/board/bladerf1/image.c @@ -281,6 +281,23 @@ static int unpack_image(struct bladerf_image *img, uint8_t *buf, size_t len) return 0; } +int bladerf_image_print_metadata(const struct bladerf_image *image) { + if (!image) { + return BLADERF_ERR_MEM; + } + + printf("Magic: %s\n", image->magic); + printf("Version: %d.%d.%d\n", + image->version.major, image->version.minor, image->version.patch); + printf("Timestamp: %" PRIx64 "\n", image->timestamp); + printf("Serial: %s\n", image->serial); + printf("Address: %x\n", image->address); + printf("Length: %u\n", image->length); + fflush(stdout); + + return 0; +} + int bladerf_image_write(struct bladerf *dev, struct bladerf_image *img, const char *file) {