From 448fa5f74c0db5c359b72ef4770a8bb84309c947 Mon Sep 17 00:00:00 2001 From: Bernhard Nortmann Date: Mon, 21 Nov 2016 10:17:43 +0100 Subject: [PATCH] fel: Add "--sid" option to select FEL device by SID Signed-off-by: Bernhard Nortmann --- fel.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/fel.c b/fel.c index 0a8c58b..2285031 100644 --- a/fel.c +++ b/fel.c @@ -987,6 +987,24 @@ static void felusb_list_devices(void) exit(devices > 0 ? EXIT_SUCCESS : EXIT_FAILURE); } +static void select_by_sid(const char *sid_arg, int *busnum, int *devnum) +{ + char sid[36]; + feldev_list_entry *list, *entry; + + list = list_fel_devices(NULL); + for (entry = list; entry->soc_version.soc_id; entry++) { + snprintf(sid, sizeof(sid), "%08x:%08x:%08x:%08x", + entry->SID[0], entry->SID[1], entry->SID[2], entry->SID[3]); + if (strcmp(sid, sid_arg) == 0) { + *busnum = entry->busnum; + *devnum = entry->devnum; + break; + } + } + free(list); +} + int main(int argc, char **argv) { bool uboot_autostart = false; /* flag for "uboot" command = U-Boot autostart */ @@ -994,6 +1012,7 @@ int main(int argc, char **argv) bool device_list = false; /* -l switch, prints device list and exits */ feldev_handle *handle; int busnum = -1, devnum = -1; + char *sid_arg = NULL; if (argc <= 1) { puts("sunxi-fel " VERSION "\n"); @@ -1002,6 +1021,7 @@ int main(int argc, char **argv) " -p, --progress \"write\" transfers show a progress bar\n" " -l, --list Enumerate all (USB) FEL devices and exit\n" " -d, --dev bus:devnum Use specific USB bus and device number\n" + " --sid SID Select device by SID key (exact match)\n" "\n" " spl file Load and execute U-Boot SPL\n" " If file additionally contains a main U-Boot binary\n" @@ -1062,6 +1082,11 @@ int main(int argc, char **argv) exit(1); } pr_info("Selecting USB Bus %03d Device %03d\n", busnum, devnum); + } + else if (strcmp(argv[1], "--sid") == 0 && argc > 2) { + sid_arg = argv[2]; + argc -= 1; + argv += 1; } else break; /* no valid (prefix) option detected, exit loop */ argc -= 1; @@ -1070,6 +1095,16 @@ int main(int argc, char **argv) if (device_list) felusb_list_devices(); /* and exit program afterwards */ + if (sid_arg) { + /* try to set busnum and devnum according to "--sid" option */ + select_by_sid(sid_arg, &busnum, &devnum); + if (busnum <= 0 || devnum <= 0) { + fprintf(stderr, "No matching FEL device found for SID '%s'\n", + sid_arg); + exit(1); + } + pr_info("Selecting FEL device %03d:%03d by SID\n", busnum, devnum); + } handle = feldev_open(busnum, devnum, AW_USB_VENDOR_ID, AW_USB_PRODUCT_ID);