Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error message if --force fails #57

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

playduck
Copy link

This PR is in response to issue #56.

Using -f or -F requires the RP2040 to have enabled USB-CDC.
As this isn't immediately obvious this PR adds a short reminder if a load command with a force flag fails.
This also adds a small sentence to the help load text.

Running ./picotool load binary.elf -f with no responding device now outputs:

No accessible RP2040 devices in BOOTSEL mode were found.
To force a device into BOOTSEL mode, make sure the RP2040 is configured to use USB-CDC (USB stdio).

The help load text now reads (note the last sentence):

-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)

I've also modified the the printing routine for the error message to use snprintf and strncpy to avoid potential string-length issues as is good practice.

- changed the -f and -F help texts
- added an error message if a force load failed
README.md Outdated
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing hyphen in USB-CDC here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No hyphen is needed (example) and I don't think I've ever seen it written with a hyphen. I usually write it as "USB CDC ACM".

README.md Outdated
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing hyphen in USB-CDC here?

@lurch
Copy link
Contributor

lurch commented Aug 31, 2022

this PR adds a short reminder if a load command with a force flag fails.

It actually appears to be any command that uses the force flag, not just the load command? IMHO the behaviour you've implemented is what I'd expect, it's just that the PR description is a bit misleading 😉

@playduck
Copy link
Author

Added both missing dashes, must've missed them the first time around.

It actually appears to be any command that uses the force flag

Yes, I've just been testing it with load only, but other commands behave the same:

./picotool info -f
No accessible RP2040 devices in BOOTSEL mode were found.
To force a device into BOOTSEL mode, make sure the RP2040 is configured to use USB-CDC (USB stdio).

main.cpp Outdated
}
}
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).");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're using snprintf to prevent string-overflows, do you also need to pass in a smaller value than bufferLen if the string b already contains some content?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, the same holds for the bufErrorMessage strings above.

The length argument should be something along the lines of bufferLen - strnlen(b, bufferLen). I'm not sure if this causes an off-by-one error regarding the null terminator (e.g. should it be bufferLen - strnlen(b, bufferLen) - 1 or not)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this causes an off-by-one error

I dunno either 🤷‍♂️ I'm more of a Python programmer than a C programmer 😉

@playduck
Copy link
Author

playduck commented Sep 1, 2022

I subtracted the current string length from the maximum allowed length of the snprintf calls.
This still produces the same output but is now more robust against buffer-overflows.

main.cpp Outdated
}
} else {
if (settings.bus != -1) {
sprintf(buf, "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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, I just noticed that this says "found found" (even in the original) 😆
Would you mind fixing that at the same time please?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, my line-wrapping broke the line right between the two and I didn't notice it either.
It's fixed now.

@kilograham
Copy link
Contributor

kilograham commented Feb 9, 2023

it isn't strictly limited to USB stdio (though may be in practice as no one else implements the interface)

Perhaps "Force a device not in BOOTSEL mode but running compatible code (e.g. USB stdio)"

merge conflicts were only in main.cpp.

resolved by accepting all incoming changes and modifying the newly added error message in line 1607 to conform to all other messages

no other conflicts or changes
@lurch
Copy link
Contributor

lurch commented Feb 19, 2023

You probably want to change this to be based against develop instead of master? And whilst doing that, be aware of the change introduced in #72 😉

}
}
if (settings.force) {
snprintf(buf, buf_len, "\nTo force a device into BOOTSEL mode, make sure the RP2040 is configured to use USB-CDC (USB stdio).");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to recalculate buf and buf_len, otherwise you'll just be overwriting the previous text rather than appending to it?

@will-v-pi will-v-pi added this to the 1.6.1 milestone Jul 27, 2024
@will-v-pi will-v-pi modified the milestones: 1.6.1, 1.7.0 Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants