-
Notifications
You must be signed in to change notification settings - Fork 147
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
Extended parameters (-x
and -E
) improvements
#1844
Conversation
@MCUdude Very cool. Will review/add/comment in the next few days |
src/arduino.c
Outdated
@@ -131,9 +170,12 @@ void arduino_initpgm(PROGRAMMER *pgm) { | |||
stk500_initpgm(pgm); | |||
|
|||
strcpy(pgm->type, "Arduino"); | |||
PDATA(&pgm)->autoreset = true; // Auto-reset enabled by default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks wrong (because it probably is): Must be PDATA(pgm)
not PDATA(&pgm)
.I think this sets an unknown memory address to 1 (but not autoreset
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works this way, and I got a segfault if not. I'll look into it again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I know what happens: arduino_initpgm()
is called before pgm->setup()
which allocates the pdata structure. So, pgm->cookie
is NULL here (as it hasn't been initialised yet) and you get a seg-fault when you access it. PDATA(&pgm)->autorest
is a memory location in the PROGRAMMER sructure which is at the offset of autoreset from where the cookie pointer lives. This is defo not what you want! Either set PDATA(pgm)->autoreset
in pgm->setup()
or later but before the parameters are parsed. Or invert the logic: Use a variable noautoreset
that gets automatically initialised to zero. So you don't need to initialise that.
@MCUdude You'll have seen a couple of review comments. What I haven't done is compiling or testing the code (but you have the scope to see the number of auto-reset spikes, so that's best verified by yourself that the code does what you want it to do). I'll push code for urclock's |
And... this PR requires documentation in two places: |
Thanks for your feedback @stefanrueger! I have some comments though. BTW one thing we should look into that would make the extended parameters more helpful to a struggling user would be to print the |
-x autoreset
and -x no_autoreset
-x autoreset
and -x noautoreset
Vvv good point! It's a lot of work to add this to what feels like 1500 programmers, but a great idea. (I think urclock already does this, so it's only needed for 1499 programmers :) |
plus a few other minor things
How about something like this (separate print function): static int arduino_parseextparms(const PROGRAMMER *pgm, const LISTID extparms) {
const char *extended_param;
int attempts;
int rv = 0, help = 0;
for (LNODEID ln = lfirst(extparms); ln; ln = lnext(ln)) {
extended_param = ldata(ln);
if (sscanf(extended_param, "attempts=%i", &attempts) == 1) {
PDATA(pgm)->retry_attempts = attempts;
pmsg_info("setting number of retry attempts to %d\n", attempts);
continue;
}
if(str_eq(extended_param, "noautoreset")) {
PDATA(pgm)->autoreset = false;
continue;
}
if (str_eq(extended_param, "help")) {
help = 1;
rv = LIBAVRDUDE_EXIT;
}
if (!help) {
pmsg_error("invalid extended parameter %s\n", extended_param);
rv = -1;
}
msg_error("%s -c %s extended options:\n", progname, pgmid);
msg_error(" -xattempts=<n> Specify the number <n> of connection retry attempts\n");
msg_error(" -xnoautoreset Don't toggle RTS/DTR lines on port open to prevent a hardware reset\n");
msg_error(" -xhelp Show this help menu and exit\n");
return rv;
}
return rv;
} This will result in the following output:
|
Output looks great; and yes, both ways would work. |
… incorrect param is specified
@stefanrueger I've now pushed a fix for all programmers that supports extended parameters. I've done some minor code tweaks, but the main feature is that the help text gets printed if an invalid parameter is specified. Please review! |
BTW I'll update the docs one #1842 is merged, to prevent merge conflicts. |
... and generally massage messaging around -x parameters
@MCUdude I think your technique of printing the help message on invalid parameters is very elegant. Great code! I particularly like that the help message code resides inside the Seeing that this is a really neat usability improvement for AVRDUDE, would you want to extend your technique to the parsing of exit parameters (
Great code; a couple of comments
All? The commit overlooked
While reviewing the Please review my last two commits! I also happened upon a bug in old code where |
-x autoreset
and -x noautoreset
-x
) improvements
Thanks for the feedback @stefanrueger! I've done some work to EDIT: I've also fixed the broken auto-reset implementation in wiring.c, so this PR is ready for another review! |
-x
) improvements-x
and -E
) improvements
msg_error("%s -c %s extended options:\n", progname, pgmid); | ||
msg_error(" -x cs=<n> Sets the chip select line to CS<n> for supported programmers\n"); | ||
msg_error(" -x help Show this help menu and exit\n"); | ||
help = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The next line needs to be rv = LIBAVRDUDE_EXIT;
not return ...
I recommend checking all 22 treated programmers by running
avrdude -c ... -x invalid
avrdude -c ... -x help
to see whether there are surprises.
I don't think so with the possible exception of replacing All in all it's a really cool PR that substantially improves usability. Thanks a lot! Happy to merge once you confirm that you tested all programmers like here. |
I've just tested all the programmers that support extended parameters. Things are looking good! Docs need to be updated, but I think it's best to wait until #1842 has been merged. |
Speaking of docs, now is a good time to finally resolve #1711 by adding a new chapter or section to the avrdude.texi docs here? |
Add missing documentation from #1844
Adresses #1697.
I've added the
-x autoreset
to the AVR109 programmer so that compatible bootloaders can utilize this feature. I've also added the-x noautoreset
to thearduino
andwiring
programmers.@stefanrueger I didn't touch the Urclock implementation, since the way it deals with extra parameters is so different than the other. It would be great if you could look into this!
This PR is still a draft, so feedback is welcome.