mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
usb: Warn on test-ID usage in a unified location
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: https://github.com/RIOT-OS/RIOT/issues/12273
This commit is contained in:
parent
028c0d4b3c
commit
250f6fdfa3
@ -662,6 +662,17 @@ endif
|
|||||||
@$(COLOR_ECHO) '$(COLOR_GREEN)Building application "$(APPLICATION)" for "$(BOARD)" with MCU "$(MCU)".$(COLOR_RESET)'
|
@$(COLOR_ECHO) '$(COLOR_GREEN)Building application "$(APPLICATION)" for "$(BOARD)" with MCU "$(MCU)".$(COLOR_RESET)'
|
||||||
@$(COLOR_ECHO)
|
@$(COLOR_ECHO)
|
||||||
|
|
||||||
|
# Exported for the benefit of Kconfig
|
||||||
|
export USB_VID_TESTING = 1209
|
||||||
|
export USB_PID_TESTING = 7D01
|
||||||
|
usb_id_check:
|
||||||
|
@if grep --quiet --ignore-case "^$(USB_VID) $(USB_PID)$$" $(RIOTBASE)/dist/usb_id_testing; then \
|
||||||
|
$(COLOR_ECHO) "$(COLOR_RED)Private testing pid.codes USB VID/PID used!, do not use it outside of test environments!$(COLOR_RESET)" 1>&2 ; \
|
||||||
|
$(COLOR_ECHO) "$(COLOR_RED)MUST NOT be used on any device redistributed, sold or manufactured, VID/PID is not unique!$(COLOR_RESET)" 1>&2 ; \
|
||||||
|
fi
|
||||||
|
.PHONY: usb_id_check
|
||||||
|
all: | usb_id_check
|
||||||
|
|
||||||
# The `clean` needs to be serialized before everything else.
|
# The `clean` needs to be serialized before everything else.
|
||||||
all $(BASELIBS) $(BUILDDEPS) ..in-docker-container: | $(CLEAN)
|
all $(BASELIBS) $(BUILDDEPS) ..in-docker-container: | $(CLEAN)
|
||||||
|
|
||||||
|
20
dist/usb_id_testing
vendored
Normal file
20
dist/usb_id_testing
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# This file contains all codes that should trigger the usb_id_check warning
|
||||||
|
# about a test PID being used
|
||||||
|
|
||||||
|
1209 0001
|
||||||
|
1209 0002
|
||||||
|
1209 0003
|
||||||
|
1209 0004
|
||||||
|
1209 0005
|
||||||
|
1209 0006
|
||||||
|
1209 0007
|
||||||
|
1209 0008
|
||||||
|
1209 0009
|
||||||
|
1209 000a
|
||||||
|
1209 000b
|
||||||
|
1209 000c
|
||||||
|
1209 000d
|
||||||
|
1209 000e
|
||||||
|
1209 000f
|
||||||
|
1209 0010
|
||||||
|
1209 7d01
|
@ -1,5 +0,0 @@
|
|||||||
config USB_VID
|
|
||||||
default 0x$(DEFAULT_VID) if KCONFIG_USB
|
|
||||||
|
|
||||||
config USB_PID
|
|
||||||
default 0x$(DEFAULT_PID) if KCONFIG_USB
|
|
@ -16,10 +16,8 @@ USEMODULE += usbus
|
|||||||
USEMODULE += auto_init_usbus
|
USEMODULE += auto_init_usbus
|
||||||
|
|
||||||
# USB device vendor and product ID
|
# USB device vendor and product ID
|
||||||
export DEFAULT_VID = 1209
|
USB_VID ?= $(USB_VID_TESTING)
|
||||||
export DEFAULT_PID = 7D00
|
USB_PID ?= $(USB_PID_TESTING)
|
||||||
USB_VID ?= $(DEFAULT_VID)
|
|
||||||
USB_PID ?= $(DEFAULT_PID)
|
|
||||||
|
|
||||||
# Change this to 0 show compiler invocation lines by default:
|
# Change this to 0 show compiler invocation lines by default:
|
||||||
QUIET ?= 1
|
QUIET ?= 1
|
||||||
@ -41,12 +39,3 @@ ifndef CONFIG_USB_PID
|
|||||||
else
|
else
|
||||||
USB_PID = $(patsubst 0x%,%,$(CONFIG_USB_PID))
|
USB_PID = $(patsubst 0x%,%,$(CONFIG_USB_PID))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.PHONY: usb_id_check
|
|
||||||
usb_id_check:
|
|
||||||
@if [ $(USB_VID) = $(DEFAULT_VID) -o $(USB_PID) = $(DEFAULT_PID) ] ; then \
|
|
||||||
$(COLOR_ECHO) "$(COLOR_RED)Private testing pid.codes USB VID/PID used!, do not use it outside of test environments!$(COLOR_RESET)" 1>&2 ; \
|
|
||||||
$(COLOR_ECHO) "$(COLOR_RED)MUST NOT be used on any device redistributed, sold or manufactured, VID/PID is not unique!$(COLOR_RESET)" 1>&2 ; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
all: | usb_id_check
|
|
||||||
|
@ -45,12 +45,14 @@ endchoice
|
|||||||
config USB_PID
|
config USB_PID
|
||||||
hex "Product ID"
|
hex "Product ID"
|
||||||
range 0x0000 0xFFFF
|
range 0x0000 0xFFFF
|
||||||
|
default 0x$(USB_PID_TESTING) if KCONFIG_USB
|
||||||
help
|
help
|
||||||
You must provide your own PID.
|
You must provide your own PID.
|
||||||
|
|
||||||
config USB_VID
|
config USB_VID
|
||||||
hex "Vendor ID"
|
hex "Vendor ID"
|
||||||
range 0x0000 0xFFFF
|
range 0x0000 0xFFFF
|
||||||
|
default 0x$(USB_VID_TESTING) if KCONFIG_USB
|
||||||
help
|
help
|
||||||
You must provide your own VID.
|
You must provide your own VID.
|
||||||
|
|
||||||
|
@ -6,20 +6,9 @@ FEATURES_PROVIDED += periph_usbdev
|
|||||||
DISABLE_MODULE += auto_init_usbus
|
DISABLE_MODULE += auto_init_usbus
|
||||||
|
|
||||||
# USB device vendor and product ID
|
# USB device vendor and product ID
|
||||||
DEFAULT_VID = 1209
|
USB_VID ?= $(USB_VID_TESTING)
|
||||||
DEFAULT_PID = 7D00
|
USB_PID ?= $(USB_PID_TESTING)
|
||||||
USB_VID ?= $(DEFAULT_VID)
|
|
||||||
USB_PID ?= $(DEFAULT_PID)
|
|
||||||
|
|
||||||
CFLAGS += -DCONFIG_USB_VID=0x$(USB_VID) -DCONFIG_USB_PID=0x$(USB_PID)
|
CFLAGS += -DCONFIG_USB_VID=0x$(USB_VID) -DCONFIG_USB_PID=0x$(USB_PID)
|
||||||
|
|
||||||
include $(RIOTBASE)/Makefile.include
|
include $(RIOTBASE)/Makefile.include
|
||||||
|
|
||||||
.PHONY: usb_id_check
|
|
||||||
usb_id_check:
|
|
||||||
@if [ $(USB_VID) = $(DEFAULT_VID) ] || [ $(USB_PID) = $(DEFAULT_PID) ] ; then \
|
|
||||||
$(COLOR_ECHO) "$(COLOR_RED)Private testing pid.codes USB VID/PID used!, do not use it outside of test environments!$(COLOR_RESET)" 1>&2 ; \
|
|
||||||
$(COLOR_ECHO) "$(COLOR_RED)MUST NOT be used on any device redistributed, sold or manufactured, VID/PID is not unique!$(COLOR_RESET)" 1>&2 ; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
all: | usb_id_check
|
|
||||||
|
@ -6,21 +6,4 @@ USEMODULE += shell
|
|||||||
USEMODULE += shell_commands
|
USEMODULE += shell_commands
|
||||||
USEMODULE += ps
|
USEMODULE += ps
|
||||||
|
|
||||||
# USB device vendor and product ID
|
|
||||||
DEFAULT_VID = 1209
|
|
||||||
DEFAULT_PID = 7D00
|
|
||||||
USB_VID ?= $(DEFAULT_VID)
|
|
||||||
USB_PID ?= $(DEFAULT_PID)
|
|
||||||
|
|
||||||
CFLAGS += -DCONFIG_USB_VID=0x$(USB_VID) -DCONFIG_USB_PID=0x$(USB_PID)
|
|
||||||
|
|
||||||
include $(RIOTBASE)/Makefile.include
|
include $(RIOTBASE)/Makefile.include
|
||||||
|
|
||||||
.PHONY: usb_id_check
|
|
||||||
usb_id_check:
|
|
||||||
@if [ $(USB_VID) = $(DEFAULT_VID) ] || [ $(USB_PID) = $(DEFAULT_PID) ] ; then \
|
|
||||||
$(COLOR_ECHO) "$(COLOR_RED)Private testing pid.codes USB VID/PID used!, do not use it outside of test environments!$(COLOR_RESET)" 1>&2 ; \
|
|
||||||
$(COLOR_ECHO) "$(COLOR_RED)MUST NOT be used on any device redistributed, sold or manufactured, VID/PID is not unique!$(COLOR_RESET)" 1>&2 ; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
all: | usb_id_check
|
|
||||||
|
@ -9,36 +9,4 @@ USEMODULE += shell
|
|||||||
USEMODULE += shell_commands
|
USEMODULE += shell_commands
|
||||||
USEMODULE += ps
|
USEMODULE += ps
|
||||||
|
|
||||||
# USB device vendor and product ID
|
|
||||||
# pid.codes test VID/PID, not globally unique
|
|
||||||
export DEFAULT_VID = 1209
|
|
||||||
export DEFAULT_PID = 7D00
|
|
||||||
USB_VID ?= $(DEFAULT_VID)
|
|
||||||
USB_PID ?= $(DEFAULT_PID)
|
|
||||||
|
|
||||||
include $(RIOTBASE)/Makefile.include
|
include $(RIOTBASE)/Makefile.include
|
||||||
|
|
||||||
# Set USB VID/PID via CFLAGS if not being set via Kconfig
|
|
||||||
ifndef CONFIG_USB_VID
|
|
||||||
CFLAGS += -DCONFIG_USB_VID=0x$(USB_VID)
|
|
||||||
else
|
|
||||||
USB_VID = $(patsubst 0x%,%,$(CONFIG_USB_VID))
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifndef CONFIG_USB_PID
|
|
||||||
CFLAGS += -DCONFIG_USB_PID=0x$(USB_PID)
|
|
||||||
else
|
|
||||||
USB_PID = $(patsubst 0x%,%,$(CONFIG_USB_PID))
|
|
||||||
endif
|
|
||||||
|
|
||||||
# There is a Kconfig in the app folder, we need to indicate not to run it by default
|
|
||||||
SHOULD_RUN_KCONFIG ?=
|
|
||||||
|
|
||||||
.PHONY: usb_id_check
|
|
||||||
usb_id_check:
|
|
||||||
@if [ $(USB_VID) = $(DEFAULT_VID) -o $(USB_PID) = $(DEFAULT_PID) ] ; then \
|
|
||||||
$(COLOR_ECHO) "$(COLOR_RED)Private testing pid.codes USB VID/PID used!, do not use it outside of test environments!$(COLOR_RESET)" 1>&2 ; \
|
|
||||||
$(COLOR_ECHO) "$(COLOR_RED)MUST NOT be used on any device redistributed, sold or manufactured, VID/PID is not unique!$(COLOR_RESET)" 1>&2 ; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
all: | usb_id_check
|
|
||||||
|
Loading…
Reference in New Issue
Block a user