Skip to content

Commit

Permalink
usb: Warn on test-ID usage in a unified location
Browse files Browse the repository at this point in the history
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
  • Loading branch information
chrysn authored and bergzand committed Jul 15, 2020
1 parent d068a39 commit e422d40
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 80 deletions.
11 changes: 11 additions & 0 deletions Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,17 @@ endif
@$(COLOR_ECHO) '$(COLOR_GREEN)Building application "$(APPLICATION)" for "$(BOARD)" with MCU "$(MCU)".$(COLOR_RESET)'
@$(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.
all $(BASELIBS) $(BUILDDEPS) ..in-docker-container: | $(CLEAN)

Expand Down
20 changes: 20 additions & 0 deletions dist/usb_id_testing
Original file line number Diff line number Diff line change
@@ -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
5 changes: 0 additions & 5 deletions examples/usbus_minimal/Kconfig

This file was deleted.

15 changes: 2 additions & 13 deletions examples/usbus_minimal/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ USEMODULE += usbus
USEMODULE += auto_init_usbus

# USB device vendor and product ID
export DEFAULT_VID = 1209
export DEFAULT_PID = 7D00
USB_VID ?= $(DEFAULT_VID)
USB_PID ?= $(DEFAULT_PID)
USB_VID ?= $(USB_VID_TESTING)
USB_PID ?= $(USB_PID_TESTING)

# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1
Expand All @@ -41,12 +39,3 @@ ifndef CONFIG_USB_PID
else
USB_PID = $(patsubst 0x%,%,$(CONFIG_USB_PID))
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
2 changes: 2 additions & 0 deletions sys/usb/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ endchoice
config USB_PID
hex "Product ID"
range 0x0000 0xFFFF
default 0x$(USB_PID_TESTING) if KCONFIG_USB
help
You must provide your own PID.

config USB_VID
hex "Vendor ID"
range 0x0000 0xFFFF
default 0x$(USB_VID_TESTING) if KCONFIG_USB
help
You must provide your own VID.

Expand Down
15 changes: 2 additions & 13 deletions tests/usbus/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,9 @@ FEATURES_PROVIDED += periph_usbdev
DISABLE_MODULE += auto_init_usbus

# USB device vendor and product ID
DEFAULT_VID = 1209
DEFAULT_PID = 7D00
USB_VID ?= $(DEFAULT_VID)
USB_PID ?= $(DEFAULT_PID)
USB_VID ?= $(USB_VID_TESTING)
USB_PID ?= $(USB_PID_TESTING)

CFLAGS += -DCONFIG_USB_VID=0x$(USB_VID) -DCONFIG_USB_PID=0x$(USB_PID)

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
17 changes: 0 additions & 17 deletions tests/usbus_cdc_acm_stdio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,4 @@ USEMODULE += shell
USEMODULE += shell_commands
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

.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
32 changes: 0 additions & 32 deletions tests/usbus_cdc_ecm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,4 @@ USEMODULE += shell
USEMODULE += shell_commands
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

# 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

0 comments on commit e422d40

Please sign in to comment.