configure option --vidpid to specify USB device ID

This commit is contained in:
NIIBE Yutaka 2012-05-11 14:09:14 +09:00
parent a0a1b8177b
commit ac28ee171c
9 changed files with 108 additions and 28 deletions

2
.gitignore vendored
View File

@ -11,4 +11,4 @@ src/gnuk.dmp
src/gnuk.elf
src/gnuk.hex
src/gnuk.map
src/random_bits
src/*.inc

View File

@ -1,5 +1,16 @@
2012-05-11 Niibe Yutaka <gniibe@fsij.org>
* src/configure (--vidpid): New mandatory option.
* GNUK_USB_DEVICE_ID: New file.
* src/usb_desc.c (gnukDeviceDescriptor): Include
usb-vid-pid-ver.c.inc.
(gnukStringVendor, gnukStringProduct): Remove. It's in the
file, usb-string-vender-product.c.inc.
* src/Makefile.in (distclean): Delete *.inc.
* src/usb_prop.c (vcom_port_setup_with_nodata) Rename.
(vcom_port_data_setup): Rename and fix return value.

View File

@ -1,2 +1,3 @@
# VID:PID bcdDev Product_STRING Vender_STRING
234b:0000 0200 FSIJ USB Token Free Software Initiative of Japan
##########<TAB> ##<TAB> ##########<TAB> #################

4
NEWS
View File

@ -4,6 +4,10 @@ Gnuk NEWS - User visible changes
Released 2012-05-XX, by NIIBE Yutaka
** New mandatory option '--vidpid' for configure
You must specify USB vendor ID and product ID for Gnuk.
The file GNUK_USB_DEVICE_ID lists valid USB device IDs.
** New USB stack
Gnuk used to use USB stack of USB-FS-Device_Lib by ST. Now, it has
original implementation. Hopefully, size and quality are improved.

46
README
View File

@ -226,6 +226,47 @@ Gnuk is distributed with external source code.
Cortex-M3.
USB vendor ID and product ID (USB device ID)
============================================
When you have a vender ID and assign a product ID for Gnuk, please
contact Niibe, so that it is listed to the file GNUK_USB_DEVICE_ID.
When you modify Gnuk and install it to device, you should replace
"FSIJ" in the string gnukStringSerial to yours, so that it can be
checked as device serial number.
FSIJ allows you to use USB device ID of FSIJ (234b:0000) for devices
with Gnuk under one of following conditions:
* For everyone for experiment purpose:
- You must not distribute a binary with FSIJ's USB device ID, but
must use the binary by yourself only for your experiment. Note
that "Distributing binary" includes distributing a device which
holds the binary.
* For general individuals:
- You must use your Gnuk device with a card serial number
generated by chip unique ID or with the one *not* by FSIJ.
* For individuals with explicit permission from FSIJ.
- You should have an assigned card serial number by FSIJ,
please use that number for your device.
(There a file 'GNUK_SERIAL_NUMBER' in the official release.)
FSIJ could permit companies or business entities to use USB device ID
of FSIJ for devices with unmodified version of Gnuk, provided they
support Free Software and respect users' freedom for computing.
Please ask FSIJ for permission.
Otherwise, companies which want to distribute Gnuk devices, please use
your own USB vendor ID and product ID. When you modify Gnuk, please
replace "FSIJ" in the string gnukStringSerial to yours.
Host Requirements
=================
@ -268,7 +309,10 @@ Change directory to `src':
Then, run `configure':
$ ./configure
$ ./configure --vidpid <VID:PID>
Here, you need to specify USB vendor ID and product ID.
Please read section 'USB vendor ID and product ID' above.
Type:

View File

@ -213,4 +213,4 @@ include $(CHIBIOS)/os/ports/GCC/ARM/rules.mk
MCFLAGS= -mcpu=$(MCU) -mfix-cortex-m3-ldrd
distclean: clean
-rm -f Makefile gnuk.ld config.h
-rm -f Makefile gnuk.ld config.h *.inc

42
src/configure vendored
View File

@ -21,6 +21,7 @@
# Default settings
help=no
vidpid=none
target=OLIMEX_STM32_H103
verbose=no
with_dfu=default
@ -38,10 +39,12 @@ for option; do
case $option in
-h | --help)
help=yes ;;
--target=*)
target=$optarg ;;
-v | --verbose)
verbose=yes ;;
--vidpid=*)
vidpid=$optarg ;;
--target=*)
target=$optarg ;;
--enable-debug)
debug=yes ;;
--disable-debug)
@ -76,6 +79,7 @@ Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit [no]
--vidpid=VID:PID specify vendor/product ID [<NONE>]
--target=TARGET specify target [OLIMEX_STM32_H103]
supported targes are:
OLIMEX_STM32_H103
@ -94,6 +98,40 @@ EOF
exit 0
fi
if test "$vidpid" = "none"; then
echo "Please specify Vendor ID and Product ID by --vidpid option."
exit 1
fi
if !(IFS=" "
while read VIDPID VERSION PRODUCT VENDOR; do
if test "$vidpid" = "$VIDPID"; then
(echo $VIDPID | sed -n -e "s%^\([0-9a-f][0-9a-f]\)\([0-9a-f][0-9a-f]\):\([0-9a-f][0-9a-f]\)\([0-9a-f][0-9a-f]\)$% 0x\2, 0x\1, /* idVendor */\n 0x\4, 0x\3, /* idProduct */%p"
echo $VERSION | sed -n -e "s%^\([0-9a-f][0-9a-f]\)\([0-9a-f][0-9a-f]\)$% 0x\2, 0x\1, /* bcdDevice */%p"
) > usb-vid-pid-ver.c.inc
(echo 'static const uint8_t gnukStringVendor[] = {'
echo " ${#VENDOR}*2+2, /* bLength */"
echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */"
echo " /* Manufacturer: \"$VENDOR\" */"
echo $VENDOR | sed -n -e "s/\(........\)/\1\n/gp" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "s/ $//p"
echo '};'
echo
echo 'static const uint8_t gnukStringProduct[] = {'
echo " ${#PRODUCT}*2+2, /* bLength */"
echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */"
echo " /* Product name: \"$PRODUCT\" */"
echo $PRODUCT | sed -n -e "s/\(........\)/\1\n/gp" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "s/ $//p"
echo '};'
) >usb-string-vendor-product.c.inc
exit 0
fi
done; exit 1) < ../GNUK_USB_DEVICE_ID
then
echo "Please specify valid Vendor ID and Product ID."
echo "Check ../GNUK_USB_DEVICE_ID."
exit 1
fi
BOARD_DIR=../boards/$target
if test -d $BOARD_DIR; then
echo "Configured for target: $target"

View File

@ -161,7 +161,7 @@ extern msg_t USBthread (void *arg);
#define LED_TIMEOUT_STOP MS2ST(500)
#define ID_OFFSET 12
#define ID_OFFSET 22
static void
device_initialize_once (void)
{

View File

@ -22,9 +22,7 @@ static const uint8_t gnukDeviceDescriptor[] = {
0x00, /* bDeviceSubClass */
0x00, /* bDeviceProtocol */
0x40, /* bMaxPacketSize0 */
0x4b, 0x23, /* idVendor = 0x234b (FSIJ) */
0x00, 0x00, /* idProduct = 0x0000 (FSIJ USB Token) */
0x00, 0x02, /* bcdDevice = 2.00 */
#include "usb-vid-pid-ver.c.inc"
1, /* Index of string descriptor describing manufacturer */
2, /* Index of string descriptor describing product */
3, /* Index of string descriptor describing the device's serial number */
@ -255,28 +253,12 @@ static const uint8_t gnukStringLangID[] = {
0x09, 0x04 /* LangID = 0x0409: US-English */
};
static const uint8_t gnukStringVendor[] = {
33*2+2, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType*/
/* Manufacturer: "Free Software Initiative of Japan" */
'F', 0, 'r', 0, 'e', 0, 'e', 0, ' ', 0, 'S', 0, 'o', 0, 'f', 0,
't', 0, 'w', 0, 'a', 0, 'r', 0, 'e', 0, ' ', 0, 'I', 0, 'n', 0,
'i', 0, 't', 0, 'i', 0, 'a', 0, 't', 0, 'i', 0, 'v', 0, 'e', 0,
' ', 0, 'o', 0, 'f', 0, ' ', 0, 'J', 0, 'a', 0, 'p', 0, 'a', 0,
'n', 0
};
static const uint8_t gnukStringProduct[] = {
14*2+2, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
/* Product name: "FSIJ USB Token" */
'F', 0, 'S', 0, 'I', 0, 'J', 0, ' ', 0, 'U', 0, 'S', 0, 'B', 0,
' ', 0, 'T', 0, 'o', 0, 'k', 0, 'e', 0, 'n', 0
};
#include "usb-string-vender-product.c.inc"
const uint8_t gnukStringSerial[] = {
13*2+2, /* bLength */
18*2+2, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
'F', 0, 'S', 0, 'I', 0, 'J', 0, '-', 0,
'0', 0, '.', 0, '1', 0, '7', 0, /* Version number of Gnuk */
'-', 0,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,