4 The point of this small utility is to take a file in the format
5 of /lib/modules/`uname -r`/modules.pcimap and output a condensed, more
6 easily used format for module detection
8 The output is used by the PlanetLab boot cd (3.0+) and the pl_hwinit script
9 to load all the applicable modules by scanning lspci output.
11 Excepted format of file includes lines of:
13 # pci_module vendor device subvendor subdevice class class_mask driver_data
14 cciss 0x00000e11 0x0000b060 0x00000e11 0x00004070 0x00000000 0x00000000 0x0
15 cciss 0x00000e11 0x0000b178 0x00000e11 0x00004070 0x00000000 0x00000000 0x0
17 Output format, for each line that matches the above lines:
18 cciss 0e11:b060 0e11:b178
27 print( "rewrite-pcitable.py <pcitable> [<output>]" )
36 pcitable_file_name= sys.argv[1]
38 pcitable_file= file(pcitable_file_name,"r")
40 sys.stderr.write( "Unable to open: %s\n" % pcitable_file_name )
44 output_file_name= sys.argv[2]
46 output_file= file(output_file_name,"w")
48 sys.stderr.write( "Unable to open %s for writing.\n" % output_file )
51 output_file= sys.stdout
56 # associative array to store all matches of module -> ['vendor:device',..]
60 for line in pcitable_file:
63 # skip blank lines, or lines that begin with # (comments)
64 line= string.strip(line)
71 line_parts= string.split(line)
72 if line_parts is None or len(line_parts) != 8:
73 sys.stderr.write( "Skipping line %d (incorrect format)\n" % line_num )
76 # first two parts are always vendor / device id
78 vendor_id= line_parts[1]
79 device_id= line_parts[2]
82 # valid vendor and devices are 10 chars (0xXXXXXXXX) and begin with 0x
83 if len(vendor_id) != 10 or len(device_id) != 10:
84 sys.stderr.write( "Skipping line %d (invalid vendor/device id length)\n"
88 if string.lower(vendor_id[:2]) != "0x" \
89 or string.lower(device_id[:2]) != "0x":
90 sys.stderr.write( "Skipping line %d (invalid vendor/device id format)\n"
94 # cut down the ids, only need last 4 bytes
95 # start at 6 = (10 total chars - 4 last chars need)
96 vendor_id= string.lower(vendor_id[6:])
97 device_id= string.lower(device_id[6:])
99 full_id= "%s:%s" % (vendor_id, device_id)
101 if all_modules.has_key(module):
102 all_modules[module].append( full_id )
104 all_modules[module]= [full_id,]
106 for module in all_modules.keys():
107 devices= string.join( all_modules[module], " " )
108 output_file.write( "%s %s\n" % (module,devices) )
112 pcitable_file.close()