diff --git a/firmware_common/bladeRF.h b/firmware_common/bladeRF.h index ee0526f3..a2b00fa5 100644 --- a/firmware_common/bladeRF.h +++ b/firmware_common/bladeRF.h @@ -2,7 +2,7 @@ #define _BLADERF_FIRMWARE_COMMON_H_ #define BLADERF_IOCTL_BASE 'N' -#define BLADE_QUERY_VERSION _IOR(BLADERF_IOCTL_BASE, 0, struct bladeRF_version) +#define BLADE_QUERY_VERSION _IOR(BLADERF_IOCTL_BASE, 0, struct bladerf_fx3_version) #define BLADE_QUERY_FPGA_STATUS _IOR(BLADERF_IOCTL_BASE, 1, unsigned int) #define BLADE_BEGIN_PROG _IOR(BLADERF_IOCTL_BASE, 2, unsigned int) #define BLADE_END_PROG _IOR(BLADERF_IOCTL_BASE, 3, unsigned int) @@ -50,10 +50,12 @@ #define BLADE_USB_CMD_INVALIDATE_CAL_CACHE 111 #define BLADE_USB_CMD_REFRESH_CAL_CACHE 112 +#define BLADE_USB_STR_INDEX_DEV_VER 4 + #define CAL_BUFFER_SIZE 256 #define CAL_PAGE 768 -struct bladeRF_version { +struct bladerf_fx3_version { unsigned short major; unsigned short minor; }; diff --git a/fx3_firmware/bladeRF.c b/fx3_firmware/bladeRF.c index 2c82d65c..d03dc27e 100644 --- a/fx3_firmware/bladeRF.c +++ b/fx3_firmware/bladeRF.c @@ -317,7 +317,7 @@ CyBool_t NuandHandleVendorRequest( unsigned int ret; uint8_t use_feature; CyBool_t fpgaProg; - struct bladeRF_version ver; + struct bladerf_fx3_version ver; CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS; int retStatus; uint16_t readC; diff --git a/host/common/include/conversions.h b/host/common/include/conversions.h index 0e1162d1..01541371 100644 --- a/host/common/include/conversions.h +++ b/host/common/include/conversions.h @@ -7,6 +7,7 @@ #define CONVERSIONS_H__ #include +#include #include "host_config.h" /** @@ -95,4 +96,19 @@ unsigned int str2uint_suffix(const char *str, unsigned int min, unsigned int max, const struct numeric_suffix suffixes[], int num_suffixes, bool *ok); +/** + * Convert a string to a bladerf_version + * + * Accepted inputs are in the form: X.Y.Z or X.Y.Z- + * + * @param[in] string Version string to convert + * @param[out] version Version structure to populate. For a valid string, + * the describe member will point to the provided + * string argument. The contents of this structure + * are undefined when this function returns -1. + * + * @return 0 on success, -1 if provided string is invalid + */ +int str2version(const char *str, struct bladerf_version *version); + #endif diff --git a/host/common/src/conversions.c b/host/common/src/conversions.c index dc2282f2..054d632e 100644 --- a/host/common/src/conversions.c +++ b/host/common/src/conversions.c @@ -120,7 +120,7 @@ unsigned int str2uint_suffix(const char *str, unsigned int min, if (ok) { *ok = false; } - + return 0; } @@ -150,3 +150,47 @@ unsigned int str2uint_suffix(const char *str, unsigned int min, /* Truncate the floating point value to an integer and return it */ return (unsigned int)value; } + +int str2version(const char *str, struct bladerf_version *version) +{ + unsigned long tmp; + const char *start = str; + char *end; + + /* Major version */ + errno = 0; + tmp = strtoul(start, &end, 10); + if (errno != 0 || tmp > UINT16_MAX || end == start || *end != '.') { + return -1; + } + version->major = tmp; + + /* Minor version */ + if (end[0] == '\0' || end[1] == '\0') { + return -1; + } + errno = 0; + start = &end[1]; + tmp = strtoul(start, &end, 10); + if (errno != 0 || tmp > UINT16_MAX || end == start || *end != '.') { + return -1; + } + version->minor = tmp; + + /* Patch version */ + if (end[0] == '\0' || end[1] == '\0') { + return -1; + } + errno = 0; + start = &end[1]; + tmp = strtoul(start, &end, 10); + if (errno != 0 || tmp > UINT16_MAX || end == start || + (*end != '-' && *end != '\0')) { + return -1; + } + version->patch = tmp; + + version->describe = str; + + return 0; +} diff --git a/host/libraries/libbladeRF/CMakeLists.txt b/host/libraries/libbladeRF/CMakeLists.txt index 21d8f182..6c9b0b9b 100644 --- a/host/libraries/libbladeRF/CMakeLists.txt +++ b/host/libraries/libbladeRF/CMakeLists.txt @@ -14,7 +14,7 @@ project(libbladeRF C) ################################################################################ set(VERSION_INFO_MAJOR 0) -set(VERSION_INFO_MINOR 5) +set(VERSION_INFO_MINOR 6) set(VERSION_INFO_PATCH 0) set(VERSION_INFO_EXTRA "git") include(Version) diff --git a/host/libraries/libbladeRF/include/libbladeRF.h b/host/libraries/libbladeRF/include/libbladeRF.h index 61d631eb..a595d2ae 100644 --- a/host/libraries/libbladeRF/include/libbladeRF.h +++ b/host/libraries/libbladeRF/include/libbladeRF.h @@ -111,6 +111,20 @@ struct bladerf_stats { uint64_t tx_throughput; }; +/** + * Version structure for FPGA, firmware, libbladeRF, and associated utilities + */ +struct bladerf_version { + uint16_t major; /**< Major version */ + uint16_t minor; /**< Minor version */ + uint16_t patch; /**< Patch version */ + const char *describe; /**< Version string with any additional suffix + * information. + * + * @warning Do not attempt to modify or + * free() this string. */ +}; + /** * Sample format */ @@ -828,30 +842,14 @@ API_EXPORT int bladerf_get_fpga_size(struct bladerf *dev, /** * Query firmware version * - * @param[in] dev Device handle - * @param[out] major Firmware major version - * @param[out] minor Firmware minor version + * @param[in] dev Device handle + * @param[out] version Updated to contain firmware version * - * @return 0 on success, value from \ref RETCODES list on failure + * @return 0 on success, value from \ref RETCODES list upon failing to retrieve + * this information from the device. */ -API_EXPORT int bladerf_get_fw_version(struct bladerf *dev, - unsigned int *major, - unsigned int *minor); - -/** - * Query detailed firmware version string - * - * NOTE: Function will populate the ver return parameter with a single - * '?' if any errors are encountered while getting the version string. - * - * @param[in] dev Device handle - * @param[out] ver Firmware string - * @param[in] len Length of the buffer for the version string - * - */ -API_EXPORT void bladerf_get_fw_version_string(struct bladerf *dev, - char *ver, - size_t len); +API_EXPORT int bladerf_fw_version(struct bladerf *dev, + struct bladerf_version *version); /** * Check FPGA configuration status @@ -867,15 +865,13 @@ API_EXPORT int bladerf_is_fpga_configured(struct bladerf *dev); /** * Query FPGA version * - * @param[in] dev Device handle - * @param[out] major FPGA major version - * @param[out] minor FPGA minor version + * @param[in] dev Device handle + * @param[out] version Updated to contain firmware version * * @return 0 on success, value from \ref RETCODES list on failure */ -API_EXPORT int bladerf_get_fpga_version(struct bladerf *dev, - unsigned int *major, - unsigned int *minor); +API_EXPORT int bladerf_fpga_version(struct bladerf *dev, + struct bladerf_version *version); /** * Obtain device statistics @@ -1104,22 +1100,11 @@ API_EXPORT bool bladerf_devstr_matches(const char *dev_str, API_EXPORT const char * bladerf_strerror(int error); /** - * Get libbladeRF version information. + * Get libbladeRF version information * - * The parameters are optional and may be set to NULL if not needed - * - * param[out] major Major version - * param[out] minor Minor version - * param[out] patch Patch version - * - * @warning Do not attempt to modify the returned string. - * - * @return Version string. This value will contain git information for - * non-release builds (i.e., a short changeset and "dirty" status) + * @param[out] version libbladeRF version information */ -API_EXPORT const char * bladerf_version(unsigned int *major, - unsigned int *minor, - unsigned int *patch); +API_EXPORT void bladerf_version(struct bladerf_version *version); /** * Sets the filter level for displayed log messages. Messages that are at diff --git a/host/libraries/libbladeRF/src/backend/libusb.c b/host/libraries/libbladeRF/src/backend/libusb.c index d3b5a6b0..edbaf099 100644 --- a/host/libraries/libbladeRF/src/backend/libusb.c +++ b/host/libraries/libbladeRF/src/backend/libusb.c @@ -13,6 +13,7 @@ #include "ezusb.h" #include "bladerf_priv.h" #include "backend/libusb.h" +#include "conversions.h" #include "minmax.h" #include "log.h" @@ -449,7 +450,33 @@ static int lusb_open(struct bladerf **device, struct bladerf_devinfo *info) if( bladerf_devinfo_matches( &thisinfo, info ) ) { /* Allocate backend structure and populate*/ - dev = (struct bladerf *)malloc(sizeof(struct bladerf)); + dev = (struct bladerf *)calloc(1, sizeof(struct bladerf)); + if (!dev) { + log_error("Skipping instance %d due to failed allocation: " + "device handle.\n", thisinfo.instance); + continue; + } + + dev->fpga_version_str = calloc(1, BLADERF_VERSION_STR_MAX + 1); + if (!dev->fpga_version_str) { + log_error("Skipping instance %d due to failed allocation: " + "FPGA version string.\n", thisinfo.instance); + free(dev); + dev = NULL; + continue; + } + + dev->fw_version_str = calloc(1, BLADERF_VERSION_STR_MAX + 1); + if (!dev->fw_version_str) { + log_error("Skipping instance %d due to failed allocation\n", + thisinfo.instance); + free(dev); + dev = NULL; + continue; + } + + + lusb = (struct bladerf_lusb *)malloc(sizeof(struct bladerf_lusb)); if (!dev || !lusb) { @@ -458,8 +485,6 @@ static int lusb_open(struct bladerf **device, struct bladerf_devinfo *info) lusb = NULL; dev = NULL; - log_warning("Skipping instance %d due to memory allocation " - "error", thisinfo.instance); continue; } @@ -483,14 +508,19 @@ static int lusb_open(struct bladerf **device, struct bladerf_devinfo *info) goto lusb_open__err_device_list; } - bladerf_get_fw_version(dev, &dev->fw_major, &dev->fw_minor); - if (dev->fw_major < FW_LEGACY_ALT_SETTING_MAJOR || - (dev->fw_major == FW_LEGACY_ALT_SETTING_MAJOR && dev->fw_minor < FW_LEGACY_ALT_SETTING_MINOR)) { + status = bladerf_fw_version(dev, &dev->fw_version); + if (status < 0) { + goto lusb_open__err_device_list; + } + + if (dev->fw_version.major < FW_LEGACY_ALT_SETTING_MAJOR || + (dev->fw_version.major == FW_LEGACY_ALT_SETTING_MAJOR && + dev->fw_version.minor < FW_LEGACY_ALT_SETTING_MINOR)) { dev->legacy = LEGACY_ALT_SETTING; } - if (dev->fw_major < FW_LEGACY_CONFIG_IF_MAJOR || - (dev->fw_major == FW_LEGACY_CONFIG_IF_MAJOR && dev->fw_minor < FW_LEGACY_CONFIG_IF_MINOR)) { + if (dev->fw_version.major < FW_LEGACY_CONFIG_IF_MAJOR || + (dev->fw_version.major == FW_LEGACY_CONFIG_IF_MAJOR && dev->fw_version.minor < FW_LEGACY_CONFIG_IF_MINOR)) { dev->legacy |= LEGACY_CONFIG_IF; } @@ -598,6 +628,7 @@ static int lusb_load_fpga(struct bladerf *dev, uint8_t *image, size_t image_size } else { status = change_setting(dev, USB_IF_CONFIG); } + if(status < 0) { status = error_libusb2bladerf(status); bladerf_set_error(&dev->error, ETYPE_LIBBLADERF, status); @@ -623,7 +654,7 @@ static int lusb_load_fpga(struct bladerf *dev, uint8_t *image, size_t image_size return status; } - /* End programming */ + /* End programming */ status = end_fpga_programming(dev); if (status) { status = error_libusb2bladerf(status); @@ -1287,18 +1318,13 @@ static int lusb_get_cal(struct bladerf *dev, char *cal) { read_size, CAL_BUFFER_SIZE, (uint8_t*)cal); } -static int lusb_get_fw_version(struct bladerf *dev, - unsigned int *maj, unsigned int *min) +/* FW < 1.5.0 does not have version strings */ +static int lusb_fw_version_legacy(struct bladerf *dev, + struct bladerf_version *version) { int status; - /* FIXME We're playing with fire here - these structures need to be - * serialized/deserialized when communicating them between the - * host and the FX3. If the contents are change to not - * conveniently land on word boundaries and the struct is - * padded, we'll run into trouble. - */ - struct bladeRF_version fw_ver; + struct bladerf_fx3_version fw_ver; struct bladerf_lusb *lusb = dev->backend; status = libusb_control_transfer( @@ -1316,39 +1342,52 @@ static int lusb_get_fw_version(struct bladerf *dev, if (status < 0) { status = BLADERF_ERR_IO; - *maj = *min = 0; } else { - *maj = (unsigned int) LE16_TO_HOST(fw_ver.major); - *min = (unsigned int) LE16_TO_HOST(fw_ver.minor); + version->major = LE16_TO_HOST(fw_ver.major); + version->minor = LE16_TO_HOST(fw_ver.minor); + version->patch = 0; + version->describe = dev->fw_version_str; + snprintf(dev->fw_version_str, BLADERF_VERSION_STR_MAX, "%d.%d.%d", + version->major, version->minor, version->patch); status = 0; } return status; } -static void lusb_get_fw_version_string(struct bladerf *dev, - char *ver, size_t len) +static int lusb_fw_version(struct bladerf *dev, + struct bladerf_version *version) { int status; struct bladerf_lusb *lusb = dev->backend; - /* TODO: String descriptor index should probably be in a common header */ - status = libusb_get_string_descriptor_ascii(lusb->handle, 4, (unsigned char *)ver, len); + status = libusb_get_string_descriptor_ascii(lusb->handle, + BLADE_USB_STR_INDEX_DEV_VER, + (unsigned char *)dev->fw_version_str, + BLADERF_VERSION_STR_MAX); - /* If we ran into an issue, populate with single questionmark */ + /* If we ran into an issue, we're likely dealing with an older firmware. + * Fall back to the legacy version*/ if (status < 0) { - *ver = '?'; + status = lusb_fw_version_legacy(dev, version); + } else { + status = str2version(dev->fw_version_str, version); + if (status != 0) { + status = BLADERF_ERR_UNEXPECTED; + } } - return; + return status; } -static int lusb_get_fpga_version(struct bladerf *dev, - unsigned int *maj, unsigned int *min) +static int lusb_fpga_version(struct bladerf *dev, + struct bladerf_version *version) { - log_warning("FPGA currently does not have a version number.\n"); - *maj = 0; - *min = 0; + log_debug("FPGA currently does not have a version number.\n"); + version->major = 0; + version->minor = 0; + version->patch = 0; + version->describe = dev->fpga_version_str; return 0; } @@ -2037,9 +2076,8 @@ const struct bladerf_fn bladerf_lusb_fn = { FIELD_INIT(.get_cal, lusb_get_cal), FIELD_INIT(.get_otp, lusb_get_otp), - FIELD_INIT(.get_fw_version, lusb_get_fw_version), - FIELD_INIT(.get_fw_version_string, lusb_get_fw_version_string), - FIELD_INIT(.get_fpga_version, lusb_get_fpga_version), + FIELD_INIT(.fw_version, lusb_fw_version), + FIELD_INIT(.fpga_version, lusb_fpga_version), FIELD_INIT(.get_device_speed, lusb_get_device_speed), FIELD_INIT(.config_gpio_write, lusb_config_gpio_write), diff --git a/host/libraries/libbladeRF/src/backend/linux.c b/host/libraries/libbladeRF/src/backend/linux.c index 1e9a8a7a..8b9456ee 100644 --- a/host/libraries/libbladeRF/src/backend/linux.c +++ b/host/libraries/libbladeRF/src/backend/linux.c @@ -431,26 +431,31 @@ static int linux_get_cal(struct bladerf *dev, char *cal) } /* XXX: For realsies */ -static int linux_get_fpga_version(struct bladerf *dev, unsigned int *maj, unsigned int *min) +static int linux_fpga_version(struct bladerf *dev, + struct bladerf_version *version) { - log_warning("FPGA currently does not have a version number.\n"); - *min = *maj = 0; + log_debug("FPGA currently does not have a version number.\n"); + version->major = version ->minor = version->patch = 0; + version->describe = dev->fpga_version_str; return 0; } -static int linux_get_fw_version(struct bladerf *dev, - unsigned int *major, unsigned int *minor) +/* TODO: Add support for patch version and string */ +static int linux_fw_version(struct bladerf *dev, + struct bladerf_version *version) { int status; - struct bladeRF_version ver; + struct bladerf_fx3_version ver; struct bladerf_linux *backend = (struct bladerf_linux *)dev->backend; - assert(dev && major && minor); - status = ioctl(backend->fd, BLADE_QUERY_VERSION, &ver); if (!status) { - *major = ver.major; - *minor = ver.minor; + version->major = ver.major; + version->minor = ver.minor; + version->patch = 0; + version->describe = dev->fw_version_str; + snprintf(dev->fw_version_str, BLADERF_VERSION_STR_MAX, "%d.%d.%d", + version->major, version->minor, version->patch); return 0; } @@ -752,9 +757,8 @@ const struct bladerf_fn bladerf_linux_fn = { FIELD_INIT(.get_cal, linux_get_cal), FIELD_INIT(.get_otp, linux_get_otp), - FIELD_INIT(.get_fw_version, linux_get_fw_version), - FIELD_INIT(.get_fw_version_string, NULL), - FIELD_INIT(.get_fpga_version, linux_get_fpga_version), + FIELD_INIT(.fw_version, linux_fw_version), + FIELD_INIT(.fpga_version, linux_fpga_version), FIELD_INIT(.get_device_speed, linux_get_device_speed), FIELD_INIT(.config_gpio_write, linux_config_gpio_write), diff --git a/host/libraries/libbladeRF/src/bladerf.c b/host/libraries/libbladeRF/src/bladerf.c index 2bc6169c..1bb114da 100644 --- a/host/libraries/libbladeRF/src/bladerf.c +++ b/host/libraries/libbladeRF/src/bladerf.c @@ -133,8 +133,8 @@ int bladerf_open(struct bladerf **device, const char *dev_id) /* If any of these routines failed, the dev structure should * still have had it's fields dummied, so they're safe to * print here (i.e., not uninitialized) */ - log_debug("%s: fw=v%d.%d serial=%s trim=0x%.4x fpga_size=%d\n", - __FUNCTION__, dev->fw_major, dev->fw_minor, + log_debug("%s: fw=v%s serial=%s trim=0x%.4x fpga_size=%d\n", + __FUNCTION__, dev->fw_version.describe, dev->ident.serial, dev->dac_trim, dev->fpga_size); } @@ -580,7 +580,6 @@ int bladerf_init_stream(struct bladerf_stream **stream, void bladerf_deinit_stream(struct bladerf_stream *stream) { - size_t i; while(stream->state != STREAM_DONE && stream->state != STREAM_IDLE) { @@ -641,15 +640,9 @@ int bladerf_get_fpga_size(struct bladerf *dev, bladerf_fpga_size *size) return 0; } -int bladerf_get_fw_version(struct bladerf *dev, - unsigned int *major, unsigned int *minor) +int bladerf_fw_version(struct bladerf *dev, struct bladerf_version *version) { - return dev->fn->get_fw_version(dev, major, minor); -} - -void bladerf_get_fw_version_string(struct bladerf *dev, char *ver, size_t len) -{ - return dev->fn->get_fw_version_string(dev, ver, len); + return dev->fn->fw_version(dev, version); } int bladerf_is_fpga_configured(struct bladerf *dev) @@ -657,10 +650,9 @@ int bladerf_is_fpga_configured(struct bladerf *dev) return dev->fn->is_fpga_configured(dev); } -int bladerf_get_fpga_version(struct bladerf *dev, - unsigned int *major, unsigned int *minor) +int bladerf_fpga_version(struct bladerf *dev, struct bladerf_version *version) { - return dev->fn->get_fpga_version(dev, major, minor); + return dev->fn->fpga_version(dev, version); } int bladerf_stats(struct bladerf *dev, struct bladerf_stats *stats) @@ -854,23 +846,12 @@ const char * bladerf_strerror(int error) } } -const char * bladerf_version(unsigned int *major, - unsigned int *minor, - unsigned int *patch) +void bladerf_version(struct bladerf_version *version) { - if (major) { - *major = LIBBLADERF_VERSION_MAJOR; - } - - if (minor) { - *minor = LIBBLADERF_VERSION_MINOR; - } - - if (patch) { - *patch = LIBBLADERF_VERSION_PATCH; - } - - return LIBBLADERF_VERSION; + version->major = LIBBLADERF_VERSION_MAJOR; + version->minor = LIBBLADERF_VERSION_MINOR; + version->patch = LIBBLADERF_VERSION_PATCH; + version->describe = LIBBLADERF_VERSION; } bladerf_log_level bladerf_log_set_verbosity(bladerf_log_level level) diff --git a/host/libraries/libbladeRF/src/bladerf_priv.h b/host/libraries/libbladeRF/src/bladerf_priv.h index 596bfc77..f5d29d26 100644 --- a/host/libraries/libbladeRF/src/bladerf_priv.h +++ b/host/libraries/libbladeRF/src/bladerf_priv.h @@ -98,9 +98,8 @@ struct bladerf_fn { /* Platform information */ int (*get_cal)(struct bladerf *dev, char *cal); int (*get_otp)(struct bladerf *dev, char *otp); - int (*get_fw_version)(struct bladerf *dev, unsigned int *maj, unsigned int *min); - void (*get_fw_version_string)(struct bladerf *dev, char *ver, size_t len); - int (*get_fpga_version)(struct bladerf *dev, unsigned int *maj, unsigned int *min); + int (*fw_version)(struct bladerf *dev, struct bladerf_version *version); + int (*fpga_version)(struct bladerf *dev, struct bladerf_version *version); int (*get_device_speed)(struct bladerf *dev, int *speed); /* Configuration GPIO accessors */ @@ -138,6 +137,8 @@ struct bladerf_fn { #define FW_LEGACY_CONFIG_IF_MINOR 4 #define LEGACY_CONFIG_IF 2 +#define BLADERF_VERSION_STR_MAX 32 + struct bladerf { struct bladerf_devinfo ident; /* Identifying information */ @@ -145,7 +146,10 @@ struct bladerf { uint16_t dac_trim; bladerf_fpga_size fpga_size; - unsigned int fw_major, fw_minor; + char *fw_version_str; + char *fpga_version_str; + + struct bladerf_version fw_version; int legacy; int speed; /* The device's USB speed, 0 is HS, 1 is SS */ diff --git a/host/utilities/bladeRF-cli/CMakeLists.txt b/host/utilities/bladeRF-cli/CMakeLists.txt index b6eba68f..7b6bff77 100644 --- a/host/utilities/bladeRF-cli/CMakeLists.txt +++ b/host/utilities/bladeRF-cli/CMakeLists.txt @@ -12,7 +12,7 @@ project(bladeRF-cli C) set(VERSION_INFO_MAJOR 0) set(VERSION_INFO_MINOR 4) -set(VERSION_INFO_PATCH 0) +set(VERSION_INFO_PATCH 1) set(VERSION_INFO_EXTRA "git") include(Version) diff --git a/host/utilities/bladeRF-cli/src/cmd/cmd.c b/host/utilities/bladeRF-cli/src/cmd/cmd.c index 0a705d00..360d1eda 100644 --- a/host/utilities/bladeRF-cli/src/cmd/cmd.c +++ b/host/utilities/bladeRF-cli/src/cmd/cmd.c @@ -293,11 +293,11 @@ static const struct cmd cmd_table[] = { { FIELD_INIT(.names, cmd_names_ver), FIELD_INIT(.exec, cmd_version), - FIELD_INIT(.desc, "Device and firmware versions"), + FIELD_INIT(.desc, "Host software and device version information"), FIELD_INIT(.help, "version\n" "\n" - "Prints version information for device and firmware.\n" + "Prints version information for both host software and the current device\n" ) }, { diff --git a/host/utilities/bladeRF-cli/src/cmd/version.c b/host/utilities/bladeRF-cli/src/cmd/version.c index c6d5d197..11894cee 100644 --- a/host/utilities/bladeRF-cli/src/cmd/version.c +++ b/host/utilities/bladeRF-cli/src/cmd/version.c @@ -1,18 +1,24 @@ #include "cmd.h" +#include "version.h" #include int cmd_version(struct cli_state *state, int argc, char **argv) { int status; - unsigned int fw_major, fw_minor; - unsigned int fpga_major, fpga_minor; char serial[BLADERF_SERIAL_LENGTH] = { 0 }; bladerf_fpga_size fpga_size; uint16_t dac_trim; - char version[32] = { 0 }; + struct bladerf_version fw_version, fpga_version, lib_version; bool fpga_loaded = false; + bladerf_version(&lib_version); + + printf("\n"); + printf("bladeRF-cli version: " BLADERF_CLI_VERSION "\n"); + printf("libbladeRF version: %s\n", lib_version.describe); + printf("\n"); + if (state->dev == NULL) { return CMD_RET_NODEV; } @@ -22,19 +28,17 @@ int cmd_version(struct cli_state *state, int argc, char **argv) return status; } else if (status) { fpga_loaded = true; - status = bladerf_get_fpga_version(state->dev, &fpga_major, &fpga_minor); + status = bladerf_fpga_version(state->dev, &fpga_version); if (status < 0) { return status; } } - status = bladerf_get_fw_version(state->dev, &fw_major, &fw_minor); + status = bladerf_fw_version(state->dev, &fw_version); if (status < 0) { return status; } - bladerf_get_fw_version_string(state->dev, version, sizeof(version)); - status = bladerf_get_serial(state->dev, serial); if (status < 0) { return status; @@ -50,21 +54,21 @@ int cmd_version(struct cli_state *state, int argc, char **argv) return status; } + printf("Firmware version: %s\n", fw_version.describe); - printf("\n"); - printf("Serial #: %s\n", serial); - printf("VCTCXO DAC calibration: 0x%.4x\n", dac_trim); - if (fpga_size != 0) { - printf("FPGA size: %d KLE\n", fpga_size); - } else { - printf("FPGA size: Unknown\n"); - } - printf("Firmware version: %u.%u\n", fw_major, fw_minor); - printf("Firmware string: %s\n", version); if (fpga_loaded) { - printf("FPGA version: %u.%u\n", fpga_major, fpga_minor); + printf("FPGA version: %s\n", fpga_version.describe); } else { - printf("FPGA version: Unknown (FPGA not loaded)\n"); + printf("FPGA version: Unknown (FPGA not loaded)\n"); + } + + /* TODO: Move these into an info command */ + printf("Serial #: %s\n", serial); + printf("VCTCXO DAC calibration: 0x%.4x\n", dac_trim); + if (fpga_size != 0) { + printf("FPGA size: %d KLE\n", fpga_size); + } else { + printf("FPGA size: Unknown\n"); } printf("\n"); diff --git a/host/utilities/bladeRF-cli/src/main.c b/host/utilities/bladeRF-cli/src/main.c index 9f7aa10f..c6a3b833 100644 --- a/host/utilities/bladeRF-cli/src/main.c +++ b/host/utilities/bladeRF-cli/src/main.c @@ -318,7 +318,9 @@ int main(int argc, char *argv[]) printf(BLADERF_CLI_VERSION "\n"); exit_immediately = true; } else if (rc.show_lib_version) { - printf("%s\n", bladerf_version(NULL, NULL, NULL)); + struct bladerf_version version; + bladerf_version(&version); + printf("%s\n", version.describe); exit_immediately = true; } else if (rc.probe) { status = cmd_handle(state, "probe"); diff --git a/host/utilities/bladeRF-flash/CMakeLists.txt b/host/utilities/bladeRF-flash/CMakeLists.txt index 18a60c35..b29d4fab 100644 --- a/host/utilities/bladeRF-flash/CMakeLists.txt +++ b/host/utilities/bladeRF-flash/CMakeLists.txt @@ -12,7 +12,7 @@ project(bladeRF-flash C) set(VERSION_INFO_MAJOR 0) set(VERSION_INFO_MINOR 4) -set(VERSION_INFO_PATCH 0) +set(VERSION_INFO_PATCH 1) set(VERSION_INFO_EXTRA "git") include(Version) diff --git a/host/utilities/bladeRF-flash/src/main.c b/host/utilities/bladeRF-flash/src/main.c index 889effd0..3accad84 100644 --- a/host/utilities/bladeRF-flash/src/main.c +++ b/host/utilities/bladeRF-flash/src/main.c @@ -623,7 +623,9 @@ int main(int argc, char *argv[]) printf(BLADERF_FLASH_VERSION "\n"); return 0; } else if (rc.show_lib_version) { - printf("%s\n", bladerf_version(NULL, NULL, NULL)); + struct bladerf_version version; + bladerf_version(&version); + printf("%s\n", version.describe); return 0; }