-
Notifications
You must be signed in to change notification settings - Fork 2k
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
usb: Warn on test-ID usage in a unified location #13382
usb: Warn on test-ID usage in a unified location #13382
Conversation
After some playing around with Kconfig, I've updated the PR to use the conversion from the example unconditionally. This might be a good point to think about how we want to deal with conflict between Kconfig and Makefile-based configuration, whether we want to, or whether we'll just let it wind up in conflicting CFLAGS or overridden variables like other such conflicts would currently. (Or not, and think about it later, but come back to this particular piece of code). |
I've added the check originally listed under "open issues" to the makefiles -- gives output that is readable more easily than an The |
@@ -37,7 +37,7 @@ extern "C" { | |||
#define CONFIG_USB_PID (0x7D00) | |||
#else | |||
#error Please configure your vendor and product IDs. For development, you may \ | |||
set CONFIG_USB_VID=0x1209 CONFIG_USB_PID=0x7D01. | |||
set USB_VID=${USB_VID_TESTING} USB_PID=${USB_PID_TESTING}. |
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.
Isn't this still CONFIG_USB_VID=${USB_VID_TESTING} CONFIG_USB_PID=${USB_PID_TESTING}
?
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.
When IDs are set in makefiles, currently (by rough convention in the examples, it's not like there is mechanism for that), they are set as USB_xID
make variables, and later set as -DCONFIG_USB_xID=${USB_xID}
.
Could certainly rename them to CONFIG_USB_xID
in the makefile, but then both make and Kconfig would write the same variable. That's easier in some parts, but then what would the condition be on which the makefile decides on whether to set CFLAGS += -DCONFIG_USB_xID=${CONFIG_USB_xID}
? (As I understand, Kconfig sets that automatically -- but when Kconfig is not in use, it'll still need manual exporting.)
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.
But it seems a bit odd to me that an error message that is present on one of our header files refers to a Makefile variable. As I see it, the message is indicating that you may set CONFIG_USB_xID
macros to the testing values. Also, I guess we could actually hard-code the testing values here as they are not likely to change?
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 error message tries to give concrete guidance as to what to do; previously that would have been setting something in the Makefile; currently it should be "configure however you configure your things", which is harder to express concisely.
I suppose this is easier when there is a unified name CONFIG_USB_xID
for both configuration ways, as "set CONFIG_USB_PID=7D01" can be understood both in a Makefile and a Kconfig context -- but for that I'd need a criterion based on which to decide whether a CFLAGS += -DCONFIG_USB_PID=...
is indicated. What can that criterion be?
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.
If we just indicate that the macros CONFIG_USB_xID
need to be configured, then the user can decide the way to do that, I don't know if it is up to the error message to define this.
But if we do want to give a 'concrete guidance', then this is fine, as CFLAGS is still the default configuration way for now.
Needs a rebase. |
7825077
to
123288c
Compare
Done (I guess I had that coming); still running some checks to see there were no conflicts, but so far it looks good. |
Looks like Murdock is not so happy about those warnings. |
Looks like Murdock is not so happy about those warnings.
It's not the warning, it's the errors (at least where I checked) -- and
they are justified, in that I did not capture all include locations for
all boards.
I'll start a local build on all boards to see whether I capture the
relevant code paths before I bother Murdock again.
|
Hrmpf -- unlike the platforms I previously tested this with, the complaining ones include I'll add the suitable defines around those inclusions, but it does have a subtle downside: If an application uses functions from usb.h but doesn't include it manually (because it only includes them via the board files), it will silently circumvent the protection. I'd say that's good enough; the only alternative I see is setting the USB_H_USER_IS_INTERNAL flag from the build system on all internal compilation units. |
With benpicco's discovery that the USB include through the general periph headers is not essential (cherry-picked from #12778), this should now be in a more useful state. |
Want to rebase & solve the merge conflict so we can see what Murdock thinks of this now? 🙂️ |
@chrysn I can rebase and push if you are short on time :) |
Thanks for the ping, I'm at it.
|
This * renames DEFAULT_xID to USB_xID_TESTING as it is not really a default (if anyting, the 7D00 is, and it's not that) * moves the check into Makefile * generalizes the check to all test PID/VID pairs * in doing so, fixes the "or" (which would have ruled out warning-free use of an allocated pid.codes number), and compares to the actual testing PID rather than the RIOT-peripheral PID * removes all occurrences of duplicated checks in examples or tests, leaving definitions only where they are needed * moves the Kconfig defaults of the usbus_minimal example into the main Kconfig, as these are good defaults for all cases when USB is enabled manually Closes: RIOT-OS#12273
This allows the check for test IDs to run independently of the configuration source, and provides a canonical point for the configurable (and tested) Makefile variable to enter CFLAGS.
That pair is reserved for cases when it can be set implicitly by the build system. The check could just as well be done in sys/include/usb.h, but this gives prettier output.
The clause was left over from moving the lines into the main configuration from an example config without understanding its relevance.
78c56cf
to
85d7042
Compare
I've pushed a rebased branch for Murdock to have a look at, but I'm right now baffled at one of the tests failing (the usbus_minimal example builds even when no VID/PID is set, which it shouldn't), looking into that. |
All fine from my tests -- I had just mixed up the tests/usbus and examples/usbus_minimal case. The latter really does opt in because it does nothing custom and is thus eligible for the 7D00 code -- but chooses to appear custom for the benefit of people starting from that example. |
Testing procedure:
|
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.
ACK, nice cleanup, tested all look OK.
Contribution description
As discussed in #12273 and prepared in #13148, there is still a lot of Makefile code that'd get copy-pasted around when applications are started from examples, or (worse) simply removed because it's annoying.
This moves the checks for whether to show a big red warning about using test VID/PIDs into the main build infrastructure.
In particular (quoting the commit), this
(if anyting, the 7D00 is, and it's not that)
use of an allocated pid.codes number), and compares to the actual
testing PID rather than the RIOT-peripheral PID
leaving definitions only where they are needed
Kconfig, as these are good defaults for all cases when USB is enabled
manually
Open issues
Setting variables currently take two independent paths, they either come from the environment and are set (manually still, I'd pull that over when the rest is clear) to CFLAGS, or they come from Kconfig with defines in CFLAGS and also set a
CONFIG_USB_VID
variable in addition to the define.The Kconfig-provided CFLAGS are hard to check, so I'd check the CONFIG_USB_VID, but then that'd be another checking path relative to the Makefile-based configuration.
It'd be tempting to change the USB_VID settings in the makefile-based configuration to CONFIG_USB_VID (as it's exported by Kconfig), but then there'd be a general CFLAGS addition that adds in those, and Kconfig's settings wind up there twice.
Is there a general pattern that has been established for such cases?
The code in USB: Use default VID/PID for RIOT-included peripherals #13148 fails to detect cases where the 1209:7D00 is set manually, which allows applications to claim that they only use RIOT internal peripherals even though they don't.
I'd like to add a check for this, but am not sure yet how sever it should be (red warning vs breaking), and whether to test in Makefile or in the C header.
Testing procedure
tests/usbus_cdc_acm
,tests/usbus_cdc_ecm
) build without any USB specific code in their Makefile, and show as 1209:7D00; they build without showing a warning.tests/usbus
) set their IDs to in two single lines and then show the warning at build time.examples/usbus_minimal
) can set them and get the warnings without actually copying the warning around.Issues/PRs references
Closes: #12273
[edit: Added last testing point]