From 75d3a0a5b1ccdf9064fab5f369f4413c623b526f Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Wed, 9 Aug 2017 11:29:24 +0100 Subject: [PATCH 1/3] Add check for correct firmware when flashing to a devices It's using the product string for now, but there are other things that we could check too. Use -i to ignore the check. rad1o badge will always pass the check because it uses "HackRF" as the product string, whichis a substring of both other devices.. --- host/hackrf-tools/src/hackrf_spiflash.c | 64 ++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/host/hackrf-tools/src/hackrf_spiflash.c b/host/hackrf-tools/src/hackrf_spiflash.c index aa30dfcd..c4b66894 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,51 @@ static struct option long_options[] = { { 0, 0, 0, 0 }, }; +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: + //This is somewhat problematic, + // it's a substring of the others + dev_str = "HackRF"; + str_len = 6; + break; + default: + printf("Unknown Board ID"); + return 1; + } + 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 +163,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 +188,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 +330,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) { From 46945205f25d60125d6925310263c3a9ed3c5fe2 Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Thu, 10 Aug 2017 16:12:40 +0100 Subject: [PATCH 2/3] Add USB product string for rad1o badge --- firmware/hackrf_usb/usb_descriptor.c | 8 ++++++++ 1 file changed, 8 insertions(+) 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 From fb24c389a414cb17cfeffdff25e235194fd9a201 Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Fri, 11 Aug 2017 08:00:01 +0100 Subject: [PATCH 3/3] Fix issue with rad1o compatibility check string --- host/hackrf-tools/src/hackrf_spiflash.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_spiflash.c b/host/hackrf-tools/src/hackrf_spiflash.c index c4b66894..ffed119a 100644 --- a/host/hackrf-tools/src/hackrf_spiflash.c +++ b/host/hackrf-tools/src/hackrf_spiflash.c @@ -59,6 +59,11 @@ 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; @@ -77,18 +82,16 @@ int compatibility_check(uint8_t* data, int length, hackrf_device* device) str_len = 10; break; case BOARD_ID_RAD1O: - //This is somewhat problematic, - // it's a substring of the others - dev_str = "HackRF"; - str_len = 6; + 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