freebsd11_network: Adopt the generation of usbdevs.h.

The only thing using it at present is the "pegasus" driver, so it
already doesn't make a lot of sense to keep it in src/apps/devices.
Since in the future it will be used by FreeBSD USB network drivers,
it makes sense for the FreeBSD compat layer to adopt it.

Also some related cleanup to the awk files -- they are now stored
in a "tools" subdirectory, which is more similar to where FreeBSD does it.
We are also now using FreeBSD's usbdevs2h.awk instead of NetBSD's,
as this seems to fit with the overall schema.
This commit is contained in:
Augustin Cavalier
2018-07-09 23:09:21 -04:00
parent 131c64ad4a
commit 9fcd8dadfe
6 changed files with 143 additions and 109 deletions
@@ -13,8 +13,7 @@ KernelAddon pegasus :
if_aue.c if_aue.c
; ;
# driver.c currently needs usbdevs.h so we make its path available and adds dependency
ObjectHdrs [ FGristFiles driver$(SUFOBJ) if_aue$(SUFOBJ) ] ObjectHdrs [ FGristFiles driver$(SUFOBJ) if_aue$(SUFOBJ) ]
: [ FDirName $(TARGET_COMMON_DEBUG_OBJECT_DIR_$(TARGET_PACKAGING_ARCH)) apps : [ FDirName $(TARGET_COMMON_DEBUG_OBJECT_DIR_$(TARGET_PACKAGING_ARCH)) libs
devices ] ; compat freebsd11_network ] ;
Includes [ FGristFiles driver.c if_aue.c ] : <src!apps!devices>usbdevs.h ; Includes [ FGristFiles driver.c if_aue.c ] : <src!libs!compat!freebsd11_network>usbdevs.h ;
-19
View File
@@ -25,25 +25,6 @@ actions ISAPnPHeaderGen1
ISAPnPHeaderGen [ FGristFiles isapnpids.h ] : isapnp_devids.txt : devlist2h.awk ; ISAPnPHeaderGen [ FGristFiles isapnpids.h ] : isapnp_devids.txt : devlist2h.awk ;
rule USBDevsHeaderGen
{
SEARCH on $(2) = $(SEARCH_SOURCE) ;
SEARCH on $(3) = $(SEARCH_SOURCE) ;
Depends $(1) : $(2) $(3) ;
MakeLocateArch $(<) ;
USBDevsHeaderGen1 $(1) : $(2) $(3) ;
LocalClean clean : $(<) ;
}
actions USBDevsHeaderGen1
{
gawk -v HEADERFILE=$(1[1]) -v DATAFILE=$(1[2]) -f $(2[2]) $(2[1])
}
USBDevsHeaderGen [ FGristFiles usbdevs.h usbdevs_data.h ] : usbdevs
: usb_devlist2h.awk ;
rule PCIHeaderGen rule PCIHeaderGen
{ {
SEARCH on $(3) = $(SEARCH_SOURCE) ; SEARCH on $(3) = $(SEARCH_SOURCE) ;
+20 -1
View File
@@ -52,7 +52,7 @@ KernelStaticLibrary libfreebsd11_network.a :
rule MIIHeaderGen rule MIIHeaderGen
{ {
SEARCH on $(2) = [ FDirName $(SUBDIR) compat dev mii ] ; SEARCH on $(2) = [ FDirName $(SUBDIR) compat dev mii ] ;
SEARCH on $(3) = $(SEARCH_SOURCE) ; SEARCH on $(3) = [ FDirName $(SUBDIR) tools ] ;
Depends $(1) : $(2) $(3) ; Depends $(1) : $(2) $(3) ;
MakeLocateArch $(<) ; MakeLocateArch $(<) ;
@@ -66,3 +66,22 @@ actions MIIHeaderGen1
} }
MIIHeaderGen [ FGristFiles miidevs.h ] : miidevs : miidevs2h.awk ; MIIHeaderGen [ FGristFiles miidevs.h ] : miidevs : miidevs2h.awk ;
rule USBDevsHeaderGen
{
SEARCH on $(2) = [ FDirName $(SUBDIR) compat dev usb ] ;
SEARCH on $(3) = [ FDirName $(SUBDIR) tools ] ;
Depends $(1) : $(2) $(3) ;
MakeLocateArch $(<) ;
USBDevsHeaderGen1 $(1) : $(2) $(3) ;
LocalClean clean : $(<) ;
}
actions USBDevsHeaderGen1
{
gawk -v HEADERFILE=$(1[1]) -v DATAFILE=$(1[2]) -f $(2[2]) $(2[1])
}
USBDevsHeaderGen [ FGristFiles usbdevs.h usbdevs_data.h ] : usbdevs
: usbdevs2h.awk ;
@@ -1,5 +1,9 @@
#! /usr/bin/awk -f #! /usr/bin/awk -f
# $NetBSD: devlist2h.awk,v 1.11 2003/12/15 07:32:21 jmc Exp $ #-
# $NetBSD: usb/devlist2h.awk,v 1.9 2001/01/18 20:28:22 jdolecek Exp $
# $FreeBSD$
#
# SPDX-License-Identifier: BSD-4-Clause
# #
# Copyright (c) 1995, 1996 Christopher G. Demetriou # Copyright (c) 1995, 1996 Christopher G. Demetriou
# All rights reserved. # All rights reserved.
@@ -29,152 +33,134 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# #
BEGIN {
nproducts = nvendors = blanklines = 0 function usage()
dfile=DATAFILE {
hfile=HEADERFILE print "usage: usbdevs2h.awk <srcfile> [-d|-h]";
exit 1;
} }
NR == 1 {
VERSION = $0
gsub("\\$", "", VERSION)
printf("/*\n") > dfile function header(file)
{
printf("/*\n") > file
printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \ printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
> dfile > file
printf(" *\n") > dfile printf(" *\n") > file
printf(" * generated from:\n") > dfile printf(" * generated from:\n") > file
printf(" *\t%s\n", VERSION) > dfile printf(" *\t%s\n", VERSION) > file
printf(" */\n") > dfile printf(" */\n") > file
printf("/*\n") > hfile
printf(" * THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.\n") \
> hfile
printf(" *\n") > hfile
printf(" * generated from:\n") > hfile
printf(" *\t%s\n", VERSION) > hfile
printf(" */\n") > hfile
next
} }
NF > 0 && $1 == "vendor" {
function vendor(hfile)
{
nvendors++ nvendors++
vendorindex[$2] = nvendors; # record index for this name, for later. vendorindex[$2] = nvendors; # record index for this name, for later.
vendors[nvendors, 1] = $2; # name vendors[nvendors, 1] = $2; # name
vendors[nvendors, 2] = $3; # id vendors[nvendors, 2] = $3; # id
printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1], if (hfile)
vendors[nvendors, 2]) > hfile printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1],
vendors[nvendors, 2]) > hfile
i = 3; f = 4; i = 3; f = 4;
# comments # comments
ocomment = oparen = 0 ocomment = oparen = 0
if (f <= NF) { if (f <= NF) {
printf("\t/* ") > hfile if (hfile)
printf("\t/* ") > hfile
ocomment = 1; ocomment = 1;
} }
while (f <= NF) { while (f <= NF) {
if ($f == "#") { if ($f == "#") {
printf("(") > hfile if (hfile)
printf("(") > hfile
oparen = 1 oparen = 1
f++ f++
continue continue
} }
if (oparen) { if (oparen) {
printf("%s", $f) > hfile if (hfile)
if (f < NF) printf("%s", $f) > hfile
if (f < NF && hfile)
printf(" ") > hfile printf(" ") > hfile
f++ f++
continue continue
} }
vendors[nvendors, i] = $f vendors[nvendors, i] = $f
printf("%s", vendors[nvendors, i]) > hfile if (hfile)
if (f < NF) printf("%s", vendors[nvendors, i]) > hfile
if (f < NF && hfile)
printf(" ") > hfile printf(" ") > hfile
i++; f++; i++; f++;
} }
if (oparen) if (oparen && hfile)
printf(")") > hfile printf(")") > hfile
if (ocomment) if (ocomment && hfile)
printf(" */") > hfile printf(" */") > hfile
printf("\n") > hfile if (hfile)
printf("\n") > hfile
next
} }
NF > 0 && $1 == "product" {
function product(hfile)
{
nproducts++ nproducts++
products[nproducts, 1] = $2; # vendor name products[nproducts, 1] = $2; # vendor name
products[nproducts, 2] = $3; # product id products[nproducts, 2] = $3; # product id
products[nproducts, 3] = $4; # id products[nproducts, 3] = $4; # id
printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", products[nproducts, 1], if (hfile)
products[nproducts, 2], products[nproducts, 3]) > hfile printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", \
products[nproducts, 1], products[nproducts, 2], \
products[nproducts, 3]) > hfile
i=4; f = 5; i=4; f = 5;
# comments # comments
ocomment = oparen = 0 ocomment = oparen = 0
if (f <= NF) { if (f <= NF) {
printf("\t/* ") > hfile if (hfile)
printf("\t/* ") > hfile
ocomment = 1; ocomment = 1;
} }
while (f <= NF) { while (f <= NF) {
if ($f == "#") { if ($f == "#") {
printf("(") > hfile if (hfile)
printf("(") > hfile
oparen = 1 oparen = 1
f++ f++
continue continue
} }
if (oparen) { if (oparen) {
printf("%s", $f) > hfile if (hfile)
if (f < NF) printf("%s", $f) > hfile
if (f < NF && hfile)
printf(" ") > hfile printf(" ") > hfile
f++ f++
continue continue
} }
products[nproducts, i] = $f products[nproducts, i] = $f
printf("%s", products[nproducts, i]) > hfile if (hfile)
if (f < NF) printf("%s", products[nproducts, i]) > hfile
if (f < NF && hfile)
printf(" ") > hfile printf(" ") > hfile
i++; f++; i++; f++;
} }
if (oparen) if (oparen && hfile)
printf(")") > hfile printf(")") > hfile
if (ocomment) if (ocomment && hfile)
printf(" */") > hfile printf(" */") > hfile
printf("\n") > hfile if (hfile)
printf("\n") > hfile
next
} }
function dump_dfile(dfile)
{ {
if ($0 == "")
blanklines++
print $0 > hfile
if (blanklines < 2)
print $0 > dfile
}
END {
# print out the match tables
printf("\n") > dfile printf("\n") > dfile
printf("typedef uint16 usb_vendor_id_t;\n") > dfile
printf("typedef uint16 usb_product_id_t;\n") > dfile
printf("struct usb_knowndev {\n") > dfile
printf(" usb_vendor_id_t vendor;\n") > dfile
printf(" usb_product_id_t product;\n") > dfile
printf(" int flags;\n") > dfile
printf(" char *vendorname, *productname;\n") > dfile
printf("};\n") > dfile
printf("\n") > dfile
printf("#define USB_KNOWNDEV_NOPROD 0x01 /* match on vendor only */\n") > dfile
printf("\n") > dfile
printf("const struct usb_knowndev usb_knowndevs[] = {\n") > dfile printf("const struct usb_knowndev usb_knowndevs[] = {\n") > dfile
for (i = 1; i <= nproducts; i++) { for (i = 1; i <= nproducts; i++) {
printf("\t{\n") > dfile printf("\t{\n") > dfile
printf("\t USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n", printf("\t USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
products[i, 1], products[i, 1], products[i, 2]) \ products[i, 1], products[i, 1], products[i, 2]) > dfile
> dfile
printf("\t ") > dfile printf("\t ") > dfile
printf("0") > dfile printf("0") > dfile
printf(",\n") > dfile printf(",\n") > dfile
@@ -183,7 +169,7 @@ END {
printf("\t \"") > dfile printf("\t \"") > dfile
j = 3; j = 3;
needspace = 0; needspace = 0;
while ((vendi, j) in vendors) { while (vendors[vendi, j] != "") {
if (needspace) if (needspace)
printf(" ") > dfile printf(" ") > dfile
printf("%s", vendors[vendi, j]) > dfile printf("%s", vendors[vendi, j]) > dfile
@@ -195,7 +181,7 @@ END {
printf("\t \"") > dfile printf("\t \"") > dfile
j = 4; j = 4;
needspace = 0; needspace = 0;
while ((i, j) in products) { while (products[i, j] != "") {
if (needspace) if (needspace)
printf(" ") > dfile printf(" ") > dfile
printf("%s", products[i, j]) > dfile printf("%s", products[i, j]) > dfile
@@ -207,14 +193,12 @@ END {
} }
for (i = 1; i <= nvendors; i++) { for (i = 1; i <= nvendors; i++) {
printf("\t{\n") > dfile printf("\t{\n") > dfile
printf("\t USB_VENDOR_%s, 0,\n", vendors[i, 1]) \ printf("\t USB_VENDOR_%s, 0,\n", vendors[i, 1]) > dfile
> dfile printf("\t USB_KNOWNDEV_NOPROD,\n") > dfile
printf("\t USB_KNOWNDEV_NOPROD,\n") \
> dfile
printf("\t \"") > dfile printf("\t \"") > dfile
j = 3; j = 3;
needspace = 0; needspace = 0;
while ((i, j) in vendors) { while (vendors[i, j] != "") {
if (needspace) if (needspace)
printf(" ") > dfile printf(" ") > dfile
printf("%s", vendors[i, j]) > dfile printf("%s", vendors[i, j]) > dfile
@@ -227,6 +211,57 @@ END {
} }
printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
printf("};\n") > dfile printf("};\n") > dfile
close(dfile) }
close(hfile)
BEGIN {
nproducts = nvendors = 0
dfile=DATAFILE
hfile=HEADERFILE
# Process the command line
for (i = 1; i < ARGC; i++) {
arg = ARGV[i];
if (arg !~ /^-[dh]+$/ && arg !~ /devs$/)
usage();
# if (arg ~ /^-.*d/)
# dfile="usbdevs_data.h"
# if (arg ~ /^-.*h/)
# hfile="usbdevs.h"
if (arg ~ /devs$/)
srcfile = arg;
}
ARGC = 1;
line=0;
while ((getline < srcfile) > 0) {
line++;
if (line == 1) {
VERSION = $0
gsub("\\$", "", VERSION)
if (dfile)
header(dfile)
if (hfile)
header(hfile)
continue;
}
if ($1 == "vendor") {
vendor(hfile)
continue
}
if ($1 == "product") {
product(hfile)
continue
}
if ($0 == "")
blanklines++
if (hfile)
print $0 > hfile
if (blanklines < 2 && dfile)
print $0 > dfile
}
# print out the match tables
if (dfile)
dump_dfile(dfile)
} }