diff --git a/firmware/hackrf_usb/usb_descriptor.c b/firmware/hackrf_usb/usb_descriptor.c index dd365405..fbe7acf5 100644 --- a/firmware/hackrf_usb/usb_descriptor.c +++ b/firmware/hackrf_usb/usb_descriptor.c @@ -217,6 +217,14 @@ uint8_t usb_descriptor_string_product[] = { 'k', 0x00, 'e', 0x00, 'r', 0x00, +#elif RAD1O + 12, // bLength + USB_DESCRIPTOR_TYPE_STRING, // bDescriptorType + 'r', 0x00, + 'a', 0x00, + 'd', 0x00, + '1', 0x00, + 'o', 0x00, #else 14, // bLength USB_DESCRIPTOR_TYPE_STRING, // bDescriptorType diff --git a/host/hackrf-tools/src/hackrf_spiflash.c b/host/hackrf-tools/src/hackrf_spiflash.c index aa30dfcd..ffed119a 100644 --- a/host/hackrf-tools/src/hackrf_spiflash.c +++ b/host/hackrf-tools/src/hackrf_spiflash.c @@ -51,6 +51,7 @@ static struct option long_options[] = { { "length", required_argument, 0, 'l' }, { "read", required_argument, 0, 'r' }, { "write", required_argument, 0, 'w' }, + { "compatibility", no_argument, 0, 'c' }, { "device", required_argument, 0, 'd' }, { "reset", no_argument, 0, 'R' }, { "verbose", no_argument, 0, 'v' }, @@ -58,6 +59,54 @@ static struct option long_options[] = { { 0, 0, 0, 0 }, }; +/* Check for USB product string descriptor text in firmware file + * It should match the appropriate one for the BOARD_ID + * If you're already running firmware that reports the wrong ID + * I can't help you, but you can use the -i optionto ignore (or DFU) + */ +int compatibility_check(uint8_t* data, int length, hackrf_device* device) +{ + int str_len, i,j; + bool match = false; + uint8_t board_id; + char* dev_str; + hackrf_board_id_read(device, &board_id); + switch(board_id) + { + case BOARD_ID_JAWBREAKER: + dev_str = "HackRF Jawbreaker"; + str_len = 17; + break; + case BOARD_ID_HACKRF_ONE: + dev_str = "HackRF One"; + str_len = 10; + break; + case BOARD_ID_RAD1O: + dev_str = "rad1o"; + str_len = 5; + break; + default: + printf("Unknown Board ID"); + return 1; + } + // Search for dev_str in uint8_t array of bytes that we're flashing + for(i=0; i: number of bytes to read (default: %d)\n", MAX_LENGTH); printf("\t-r, --read : Read data into file.\n"); printf("\t-w, --write : Write data from file.\n"); + printf("\t-i, --no-check: Skip check for firmware compatibility with target device.\n"); printf("\t-d, --device : Serial number of device, if multiple devices\n"); printf("\t-R, --reset: Reset HackRF after other operations.\n"); printf("\t-v, --verbose: Verbose output.\n"); @@ -116,11 +166,12 @@ int main(int argc, char** argv) FILE* fd = NULL; bool read = false; bool write = false; + bool ignore_compat_check = false; bool verbose = false; bool reset = false; uint16_t usb_api; - while ((opt = getopt_long(argc, argv, "a:l:r:w:d:vRh?", long_options, + while ((opt = getopt_long(argc, argv, "a:l:r:w:id:vRh?", long_options, &option_index)) != EOF) { switch (opt) { case 'a': @@ -140,6 +191,10 @@ int main(int argc, char** argv) write = true; path = optarg; break; + + case 'i': + ignore_compat_check = true; + break; case 'd': serial_number = optarg; @@ -278,6 +333,16 @@ int main(int argc, char** argv) fd = NULL; return EXIT_FAILURE; } + if(!ignore_compat_check) { + printf("Checking target device compatibility\n"); + result = compatibility_check(data, length, device); + if(result) { + printf("Compatibility test failed.\n"); + fclose(fd); + fd = NULL; + return EXIT_FAILURE; + } + } printf("Erasing SPI flash.\n"); result = hackrf_spiflash_erase(device); if (result != HACKRF_SUCCESS) {