altos: Add the ability to configure a different USB vendor ID
authorKeith Packard <keithp@keithp.com>
Thu, 19 Mar 2015 08:11:33 +0000 (01:11 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 19 Mar 2015 08:11:33 +0000 (01:11 -0700)
ChaosKey will use an OpenMoko vid/pid, so we need the ability to
configure a different USB vendor ID for each product.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/kernel/ao_product.c
src/util/ao-make-product.5c

index baee8dd6e7a810ad357ef76a0295e875f6733a96..c711a4d261bec9685fc210579a129e7f6bb77668 100644 (file)
@@ -49,7 +49,7 @@ AO_ROMCONFIG_SYMBOL(0x00aa) uint8_t ao_usb_descriptors [] =
        0x00,                   /*  bDeviceSubClass */
        0x00,                   /*  bDeviceProtocol */
        AO_USB_CONTROL_SIZE,    /*  bMaxPacketSize */
        0x00,                   /*  bDeviceSubClass */
        0x00,                   /*  bDeviceProtocol */
        AO_USB_CONTROL_SIZE,    /*  bMaxPacketSize */
-       LE_WORD(0xFFFE),        /*  idVendor */
+       LE_WORD(AO_idVendor_NUMBER),    /*  idVendor */
        LE_WORD(AO_idProduct_NUMBER),   /*  idProduct */
        LE_WORD(0x0100),        /*  bcdDevice */
        0x01,                   /*  iManufacturer */
        LE_WORD(AO_idProduct_NUMBER),   /*  idProduct */
        LE_WORD(0x0100),        /*  bcdDevice */
        0x01,                   /*  iManufacturer */
index 5f2eb8e895557a492405c016336cac51dd3eedea..3ab8d16ec474aba3403cc9a6654c24f4868eefa9 100644 (file)
@@ -1,54 +1,58 @@
-#!/bin/sh
+#!/usr/bin/nickle
 
 autoimport ParseArgs;
 
 
 autoimport ParseArgs;
 
+file  out = stdout;
+
 void
 write_ucs2(string a, string description)
 {
        int len = String::length(a);
 
 void
 write_ucs2(string a, string description)
 {
        int len = String::length(a);
 
-       printf("/* %s */\n", description);
-       printf("#define AO_%s_LEN 0x%02x\n", description, len * 2 + 2);
-       printf("#define AO_%s_STRING \"%s\"\n", description, a);
-       printf("#define AO_%s_UCS2", description);
+       File::fprintf(out, "/* %s */\n", description);
+       File::fprintf(out, "#define AO_%s_LEN 0x%02x\n", description, len * 2 + 2);
+       File::fprintf(out, "#define AO_%s_STRING \"%s\"\n", description, a);
+       File::fprintf(out, "#define AO_%s_UCS2", description);
        for (int i = 0; i < len; i++) {
                int     c = a[i];
                if (i > 0)
        for (int i = 0; i < len; i++) {
                int     c = a[i];
                if (i > 0)
-                       printf(",");
+                       File::fprintf(out, ",");
                if (0x20 <= c && c < 128)
                if (0x20 <= c && c < 128)
-                       printf(" '%c', 0", c);
+                       File::fprintf(out, " '%c', 0", c);
                else
                else
-                       printf(" LE_WORD(0x%04x),", c);
+                       File::fprintf(out, " LE_WORD(0x%04x),", c);
        }
        }
-       printf("\n\n");
+       File::fprintf(out, "\n\n");
 }
 
 void
 write_string(string a, string description)
 {
 }
 
 void
 write_string(string a, string description)
 {
-       printf ("/* %s */\n", description);
-       printf ("#define AO_%s_STRING \"%s\"\n", description, a);
+       File::fprintf(out, "/* %s */\n", description);
+       File::fprintf(out, "#define AO_%s_STRING \"%s\"\n", description, a);
 }
 
 void
 write_int(int a, string description)
 {
 }
 
 void
 write_int(int a, string description)
 {
-       printf ("/* %s */\n", description);
-       printf ("#define AO_%s_NUMBER %d\n\n", description, a);
+       File::fprintf(out, "/* %s */\n", description);
+       File::fprintf(out, "#define AO_%s_NUMBER %d\n\n", description, a);
 }
 
 void
 write_hex(int a, string description)
 {
 }
 
 void
 write_hex(int a, string description)
 {
-       printf ("/* %s */\n", description);
-       printf ("#define AO_%s_NUMBER 0x%04x\n\n", description, a);
+       File::fprintf(out, "/* %s */\n", description);
+       File::fprintf(out, "#define AO_%s_NUMBER 0x%04x\n\n", description, a);
 }
 
 string manufacturer = "altusmetrum.org";
 string product = "TeleMetrum";
 string version = "0.0";
 }
 
 string manufacturer = "altusmetrum.org";
 string product = "TeleMetrum";
 string version = "0.0";
+string output = "";
 int serial = 1;
 int user_argind = 0;
 int serial = 1;
 int user_argind = 0;
+int id_vendor = 0xfffe;
 int id_product = 0x000a;
 
 argdesc argd = {
 int id_product = 0x000a;
 
 argdesc argd = {
@@ -65,6 +69,12 @@ argdesc argd = {
                        .name = "product",
                        .expr_name = "prod",
                        .desc = "Product name." },
                        .name = "product",
                        .expr_name = "prod",
                        .desc = "Product name." },
+               {
+                       .var = { .arg_int = &id_vendor },
+                       .abbr = 'V',
+                       .name = "id_vendor",
+                       .expr_name = "id_v",
+                       .desc = "Vendor ID." },
                {
                        .var = { .arg_int = &id_product },
                        .abbr = 'i',
                {
                        .var = { .arg_int = &id_product },
                        .abbr = 'i',
@@ -83,6 +93,12 @@ argdesc argd = {
                        .name = "version",
                        .expr_name = "string",
                        .desc = "Program version." },
                        .name = "version",
                        .expr_name = "string",
                        .desc = "Program version." },
+               {
+                       .var = { .arg_string = &output },
+                       .abbr = 'o',
+                       .name = "output",
+                       .expr_name = "out",
+                       .desc = "Output file." },
        },
        .prog_name = "usb descriptors",
 };
        },
        .prog_name = "usb descriptors",
 };
@@ -92,11 +108,14 @@ main()
 {
        string[dim(argv)-1] nargv = {[n] = argv[n+1]};
        parseargs(&argd, &nargv);
 {
        string[dim(argv)-1] nargv = {[n] = argv[n+1]};
        parseargs(&argd, &nargv);
+       if (output != "")
+               out = File::open(output, "w");
        write_ucs2(manufacturer, "iManufacturer");
        write_ucs2(product, "iProduct");
        write_ucs2(sprintf("%06d", serial), "iSerial");
        write_int(serial, "iSerial");
        write_hex(id_product, "idProduct");
        write_ucs2(manufacturer, "iManufacturer");
        write_ucs2(product, "iProduct");
        write_ucs2(sprintf("%06d", serial), "iSerial");
        write_int(serial, "iSerial");
        write_hex(id_product, "idProduct");
+       write_hex(id_vendor, "idVendor");
        write_string(version, "iVersion");
 }
 
        write_string(version, "iVersion");
 }