From f96bef205b4496e0b4561d82b41eebef7ebc993b Mon Sep 17 00:00:00 2001 From: Brian Padalino Date: Tue, 27 Aug 2013 20:05:57 -0400 Subject: [PATCH] Don't freak out if the calibration information is not there. --- .../libraries/libbladeRF/src/backend/libusb.c | 12 ++--- host/libraries/libbladeRF/src/bladerf.c | 9 ++++ .../libbladeRF/src/device_identifier.c | 2 +- host/utilities/bladeRF-cli/src/main.c | 52 ++++++++++--------- 4 files changed, 44 insertions(+), 31 deletions(-) diff --git a/host/libraries/libbladeRF/src/backend/libusb.c b/host/libraries/libbladeRF/src/backend/libusb.c index 6506b778..0016e77a 100644 --- a/host/libraries/libbladeRF/src/backend/libusb.c +++ b/host/libraries/libbladeRF/src/backend/libusb.c @@ -736,12 +736,12 @@ static int lusb_get_otp(struct bladerf *dev, char *otp) int read_size = dev->speed ? 256 : 64; int nbytes; - for (nbytes = 0; nbytes < 256; nbytes += read_size) { + for (nbytes = 0; nbytes < 256; nbytes += status) { status = libusb_control_transfer( lusb->handle, LIBUSB_RECIPIENT_INTERFACE | - LIBUSB_REQUEST_TYPE_VENDOR | - EP_DIR_IN, + LIBUSB_REQUEST_TYPE_VENDOR | + EP_DIR_IN, BLADE_USB_CMD_READ_OTP, 0, 0, @@ -749,11 +749,11 @@ static int lusb_get_otp(struct bladerf *dev, char *otp) read_size, BLADERF_LIBUSB_TIMEOUT_MS); if (status < 0) { - dbg_printf("Failed to read OTP with errno=%d: %s\n", errno, strerror(errno)); - break; + dbg_printf("Failed to read OTP (%d): %s\n", status, libusb_error_name(status)); + return error_libusb2bladerf(status); } } - return status; + return 0; } static int lusb_get_cal(struct bladerf *dev, char *cal) { diff --git a/host/libraries/libbladeRF/src/bladerf.c b/host/libraries/libbladeRF/src/bladerf.c index 0718e78e..c393f6b6 100644 --- a/host/libraries/libbladeRF/src/bladerf.c +++ b/host/libraries/libbladeRF/src/bladerf.c @@ -116,16 +116,22 @@ int bladerf_open(struct bladerf **device, const char *dev_id) if (!status) { status = bladerf_get_and_cache_vctcxo_trim(dev); + } else { + dbg_printf( "Could not extract serial number\n" ) ; } if (!status) { status = bladerf_get_and_cache_fpga_size(dev); + } else { + dbg_printf( "Could not extract VCTCXO trim value\n" ) ; } if (!status) { dbg_printf("%s: fw=v%d.%d serial=%s trim=0x%.4x fpga_size=%d\n", __FUNCTION__, dev->fw_major, dev->fw_minor, dev->serial, dev->dac_trim, dev->fpga_size); + } else { + dbg_printf( "Could not extract FPGA size\n" ) ; } } else { printf("********************************************************************************\n"); @@ -133,6 +139,9 @@ int bladerf_open(struct bladerf **device, const char *dev_id) printf("* wget http://nuand.com/fx3/latest.img ; bladeRF-cli -b -f latest.img\n"); printf("********************************************************************************\n"); } + + /* All status in here is not fatal, so whatever */ + status = 0 ; } return status; diff --git a/host/libraries/libbladeRF/src/device_identifier.c b/host/libraries/libbladeRF/src/device_identifier.c index 2761b4db..ce25f9e7 100644 --- a/host/libraries/libbladeRF/src/device_identifier.c +++ b/host/libraries/libbladeRF/src/device_identifier.c @@ -161,7 +161,7 @@ int str2devinfo(const char *dev_id_const, struct bladerf_devinfo *d) bladerf_init_devinfo(d); /* No device indentifier -- pick anything we can find */ - if (!dev_id_const || strlen(dev_id_const) == 0) { + if ( dev_id_const == NULL || strlen(dev_id_const) == 0) { return 0; } diff --git a/host/utilities/bladeRF-cli/src/main.c b/host/utilities/bladeRF-cli/src/main.c index 0d4fa778..07173d8c 100644 --- a/host/utilities/bladeRF-cli/src/main.c +++ b/host/utilities/bladeRF-cli/src/main.c @@ -189,15 +189,12 @@ static void print_error_need_devarg() static int open_device(struct rc_config *rc, struct cli_state *state, int status) { if (!status) { - if (rc->device) { - status = bladerf_open(&state->dev, rc->device); - if (status) { - fprintf(stderr, "Failed to open device: %s\n", - bladerf_strerror(status)); - status = -1; - } - } else { - status = bladerf_open(&state->dev, NULL); + status = bladerf_open(&state->dev, rc->device); + if (status) { + fprintf(stderr, "Failed to open device (%s): %s\n", + rc->device ? rc->device : "NULL", + bladerf_strerror(status)); + status = -1; } } @@ -309,18 +306,30 @@ int main(int argc, char *argv[]) if (!exit_immediately) { /* Conditionally performed items, depending on runtime config */ status = open_device(&rc, state, status); - if (status) + if (status) { fprintf(stderr, "Could not open device\n"); - status = flash_fw(&rc, state, status); - if (status) - fprintf(stderr, "Could not flash firmware\n"); - status = load_fpga(&rc, state, status); - if (status) - fprintf(stderr, "Could not load fpga\n"); - status = open_script(&rc, state, status); - if (status) - fprintf(stderr, "Could not load scripts\n"); + goto main__issues ; + } + status = flash_fw(&rc, state, status); + if (status) { + fprintf(stderr, "Could not flash firmware\n"); + goto main__issues ; + } + + status = load_fpga(&rc, state, status); + if (status) { + fprintf(stderr, "Could not load fpga\n"); + goto main__issues ; + } + + status = open_script(&rc, state, status); + if (status) { + fprintf(stderr, "Could not load scripts\n"); + goto main__issues ; + } + +main__issues: /* These items are no longer needed */ free(rc.device); rc.device = NULL; @@ -334,11 +343,6 @@ int main(int argc, char *argv[]) free(rc.script_file); rc.script_file = NULL; - if (status) { - fprintf(stderr, "Could not launch interactive shell\n"); - return 2; - } - /* Exit cleanly when configured for batch mode. Remember that this is * implicit with some commands */ if (!rc.batch_mode || state->script != NULL) {