From 515717a6f74d331f4ef08ccb267243fd6e7347d4 Mon Sep 17 00:00:00 2001 From: robin Date: Wed, 31 Aug 2022 13:37:47 +0200 Subject: [PATCH 1/5] added additional info and error message for --force option - changed the -f and -F help texts - added an error message if a force load failed --- README.md | 22 ++++++++++++---------- main.cpp | 25 +++++++++++++++---------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 569e8b2..7a0c307 100644 --- a/README.md +++ b/README.md @@ -105,12 +105,13 @@ TARGET SELECTION: --address Filter devices by USB device address -f, --force - Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing - the command (unless the command itself is a 'reboot') the device will be rebooted back to application mode + Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the + command (unless the command itself is a 'reboot') the device will be rebooted back to application mode. Make sure the device + is using USB CDC (USB stdio) -F, --force-no-reboot - Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing - the command (unless the command itself is a 'reboot') the device will be left connected and accessible to picotool, but - without the RPI-RP2 drive mounted + Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the + command (unless the command itself is a 'reboot') the device will be left connected and accessible to picotool, but without + the RPI-RP2 drive mounted. Make sure the device is using USB CDC (USB stdio) To target a file The file name @@ -213,12 +214,13 @@ OPTIONS: --address Filter devices by USB device address -f, --force - Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing - the command (unless the command itself is a 'reboot') the device will be rebooted back to application mode + Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the + command (unless the command itself is a 'reboot') the device will be rebooted back to application mode. Make sure the device + is using USB CDC (USB stdio) -F, --force-no-reboot - Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing - the command (unless the command itself is a 'reboot') the device will be left connected and accessible to picotool, but - without the RPI-RP2 drive mounted + Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the + command (unless the command itself is a 'reboot') the device will be left connected and accessible to picotool, but without + the RPI-RP2 drive mounted. Make sure the device is using USB CDC (USB stdio) File to save to The file name diff --git a/main.cpp b/main.cpp index 0f4c5b1..0953c2f 100644 --- a/main.cpp +++ b/main.cpp @@ -298,8 +298,8 @@ auto device_selection = (option("--address") & integer("addr").min_value(1).max_value(127).set(settings.address) .if_missing([] { return "missing address"; })) % "Filter devices by USB device address" #if !defined(_WIN32) - + option('f', "--force").set(settings.force) % "Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the command (unless the command itself is a 'reboot') the device will be rebooted back to application mode" + - option('F', "--force-no-reboot").set(settings.force_no_reboot) % "Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the command (unless the command itself is a 'reboot') the device will be left connected and accessible to picotool, but without the RPI-RP2 drive mounted" + + option('f', "--force").set(settings.force) % "Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the command (unless the command itself is a 'reboot') the device will be rebooted back to application mode. Make sure the device is using USB CDC (USB stdio)" + + option('F', "--force-no-reboot").set(settings.force_no_reboot) % "Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the command (unless the command itself is a 'reboot') the device will be left connected and accessible to picotool, but without the RPI-RP2 drive mounted. Make sure the device is using USB CDC (USB stdio)" #endif ).min(0).doc_non_optional(true); @@ -1564,26 +1564,31 @@ void info_guts(memory_access &raw_access) { } string missing_device_string(bool wasRetry) { - char b[256]; + const size_t bufferLen = 512; + char b[bufferLen]; if (wasRetry) { - strcpy(b, "Despite the reboot attempt, no "); + strncpy(b, "Despite the reboot attempt, no ", bufferLen); } else { - strcpy(b, "No "); + strncpy(b, "No ", bufferLen); } - char *buf = b + strlen(b); + char *bufErrorMessage = b + strnlen(b, bufferLen); if (settings.address != -1) { if (settings.bus != -1) { - sprintf(buf, "accessible RP2040 device in BOOTSEL mode was found at bus %d, address %d.", settings.bus, settings.address); + snprintf(bufErrorMessage, bufferLen, "accessible RP2040 device in BOOTSEL mode was found at bus %d, address %d.", settings.bus, settings.address); } else { - sprintf(buf, "accessible RP2040 devices in BOOTSEL mode were found with address %d.", settings.address); + snprintf(bufErrorMessage, bufferLen, "accessible RP2040 devices in BOOTSEL mode were found with address %d.", settings.address); } } else { if (settings.bus != -1) { - sprintf(buf, "accessible RP2040 devices in BOOTSEL mode were found found on bus %d.", settings.bus); + snprintf(bufErrorMessage, bufferLen, "accessible RP2040 devices in BOOTSEL mode were found found on bus %d.", settings.bus); } else { - sprintf(buf, "accessible RP2040 devices in BOOTSEL mode were found."); + snprintf(bufErrorMessage, bufferLen, "accessible RP2040 devices in BOOTSEL mode were found."); } } + if (settings.force) { + char* bufForceError = b + strnlen(b, bufferLen); + snprintf(bufForceError, bufferLen, "\nTo force a device into BOOTSEL mode, make sure the RP2040 is configured to use USB-CDC (USB stdio)."); + } return b; } From 88ae3087818e071cfdded36a03401f2c35dfe33a Mon Sep 17 00:00:00 2001 From: robin Date: Wed, 31 Aug 2022 13:39:36 +0200 Subject: [PATCH 2/5] added missing dash in USB-CDC string --- README.md | 4 ++-- main.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7a0c307..b150c97 100644 --- a/README.md +++ b/README.md @@ -107,11 +107,11 @@ TARGET SELECTION: -f, --force Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the command (unless the command itself is a 'reboot') the device will be rebooted back to application mode. Make sure the device - is using USB CDC (USB stdio) + is using USB-CDC (USB stdio) -F, --force-no-reboot Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the command (unless the command itself is a 'reboot') the device will be left connected and accessible to picotool, but without - the RPI-RP2 drive mounted. Make sure the device is using USB CDC (USB stdio) + the RPI-RP2 drive mounted. Make sure the device is using USB-CDC (USB stdio) To target a file The file name diff --git a/main.cpp b/main.cpp index 0953c2f..55d1084 100644 --- a/main.cpp +++ b/main.cpp @@ -298,8 +298,8 @@ auto device_selection = (option("--address") & integer("addr").min_value(1).max_value(127).set(settings.address) .if_missing([] { return "missing address"; })) % "Filter devices by USB device address" #if !defined(_WIN32) - + option('f', "--force").set(settings.force) % "Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the command (unless the command itself is a 'reboot') the device will be rebooted back to application mode. Make sure the device is using USB CDC (USB stdio)" + - option('F', "--force-no-reboot").set(settings.force_no_reboot) % "Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the command (unless the command itself is a 'reboot') the device will be left connected and accessible to picotool, but without the RPI-RP2 drive mounted. Make sure the device is using USB CDC (USB stdio)" + + option('f', "--force").set(settings.force) % "Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the command (unless the command itself is a 'reboot') the device will be rebooted back to application mode. Make sure the device is using USB-CDC (USB stdio)" + + option('F', "--force-no-reboot").set(settings.force_no_reboot) % "Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the command (unless the command itself is a 'reboot') the device will be left connected and accessible to picotool, but without the RPI-RP2 drive mounted. Make sure the device is using USB-CDC (USB stdio)" #endif ).min(0).doc_non_optional(true); From 0510533156a2ec62f95b46233640732e3245bab3 Mon Sep 17 00:00:00 2001 From: robin Date: Wed, 31 Aug 2022 14:23:31 +0200 Subject: [PATCH 3/5] added another missing dash in USB-CDC string --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b150c97..c8899dd 100644 --- a/README.md +++ b/README.md @@ -216,11 +216,11 @@ OPTIONS: -f, --force Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the command (unless the command itself is a 'reboot') the device will be rebooted back to application mode. Make sure the device - is using USB CDC (USB stdio) + is using USB-CDC (USB stdio) -F, --force-no-reboot Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the command (unless the command itself is a 'reboot') the device will be left connected and accessible to picotool, but without - the RPI-RP2 drive mounted. Make sure the device is using USB CDC (USB stdio) + the RPI-RP2 drive mounted. Make sure the device is using USB-CDC (USB stdio) File to save to The file name From 6acb4f8b6c7eff83c100fe52e85a236eec70bfc0 Mon Sep 17 00:00:00 2001 From: robin Date: Thu, 1 Sep 2022 14:38:29 +0200 Subject: [PATCH 4/5] adjusted snprintf buffer length to appropriate length --- main.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/main.cpp b/main.cpp index 55d1084..8bf43b3 100644 --- a/main.cpp +++ b/main.cpp @@ -1571,23 +1571,25 @@ string missing_device_string(bool wasRetry) { } else { strncpy(b, "No ", bufferLen); } - char *bufErrorMessage = b + strnlen(b, bufferLen); + int currentLength = strnlen(b, bufferLen); + char *bufErrorMessage = b + currentLength; if (settings.address != -1) { if (settings.bus != -1) { - snprintf(bufErrorMessage, bufferLen, "accessible RP2040 device in BOOTSEL mode was found at bus %d, address %d.", settings.bus, settings.address); + snprintf(bufErrorMessage, bufferLen - currentLength, "accessible RP2040 device in BOOTSEL mode was found at bus %d, address %d.", settings.bus, settings.address); } else { - snprintf(bufErrorMessage, bufferLen, "accessible RP2040 devices in BOOTSEL mode were found with address %d.", settings.address); + snprintf(bufErrorMessage, bufferLen - currentLength, "accessible RP2040 devices in BOOTSEL mode were found with address %d.", settings.address); } } else { if (settings.bus != -1) { - snprintf(bufErrorMessage, bufferLen, "accessible RP2040 devices in BOOTSEL mode were found found on bus %d.", settings.bus); + snprintf(bufErrorMessage, bufferLen - currentLength, "accessible RP2040 devices in BOOTSEL mode were found found on bus %d.", settings.bus); } else { - snprintf(bufErrorMessage, bufferLen, "accessible RP2040 devices in BOOTSEL mode were found."); + snprintf(bufErrorMessage, bufferLen - currentLength, "accessible RP2040 devices in BOOTSEL mode were found."); } } if (settings.force) { - char* bufForceError = b + strnlen(b, bufferLen); - snprintf(bufForceError, bufferLen, "\nTo force a device into BOOTSEL mode, make sure the RP2040 is configured to use USB-CDC (USB stdio)."); + currentLength = strnlen(b, bufferLen); + char* bufForceError = b + currentLength; + snprintf(bufForceError, bufferLen - currentLength, "\nTo force a device into BOOTSEL mode, make sure the RP2040 is configured to use USB-CDC (USB stdio)."); } return b; } From 4800ccca25f30628af18829acd7177a5f5286dd5 Mon Sep 17 00:00:00 2001 From: robin Date: Thu, 1 Sep 2022 15:36:54 +0200 Subject: [PATCH 5/5] removed redundant "found" in string --- main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 8bf43b3..2c565e3 100644 --- a/main.cpp +++ b/main.cpp @@ -1581,7 +1581,7 @@ string missing_device_string(bool wasRetry) { } } else { if (settings.bus != -1) { - snprintf(bufErrorMessage, bufferLen - currentLength, "accessible RP2040 devices in BOOTSEL mode were found found on bus %d.", settings.bus); + snprintf(bufErrorMessage, bufferLen - currentLength, "accessible RP2040 devices in BOOTSEL mode were found on bus %d.", settings.bus); } else { snprintf(bufErrorMessage, bufferLen - currentLength, "accessible RP2040 devices in BOOTSEL mode were found."); }