# where built files are stored
BUILD_DIR=build/
-BOOTCD_VERSION="3.0-beta0.4"
+BOOTCD_VERSION="3.0"
FULL_VERSION_STRING="PlanetLab BootCD"
OUTPUT_IMAGE_NAME='PlanetLab-BootCD'
INITRD_BYTES_PER_INODE=1024
+# make sure the boot manager source is checked out in the same directory
+# as the bootcd_v3 repository
+BOOTMANAGER_DIR=../bootmanager/
+
+if [ ! -d $BOOTMANAGER_DIR ]; then
+ echo "the bootmanager repository needs to be checked out at the same"
+ echo "level as this directory, for the merge_hw_tables.py script"
+ exit
+fi
+
+
function usage()
{
echo "Usage: build.sh <action> [<configuration>]"
KERNEL=$CD_ROOT/boot/vmlinuz-*
mv -f $KERNEL $CD_ROOT/usr/isolinux/kernel
+ echo "moving /usr/bin/find and /usr/bin/dirname to /bin"
+ mv $CD_ROOT/usr/bin/find $CD_ROOT/bin/
+ mv $CD_ROOT/usr/bin/dirname $CD_ROOT/bin/
+
echo "creating version files"
echo "$FULL_VERSION_STRING" > $CD_ROOT/usr/isolinux/pl_version
echo "$FULL_VERSION_STRING" > $CD_ROOT/pl_version
pci_map_file=`find $CD_ROOT/lib/modules/ -name modules.pcimap | head -1`
module_dep_file=`find $CD_ROOT/lib/modules/ -name modules.dep | head -1`
pci_table=$CD_ROOT/usr/share/hwdata/pcitable
- ./scripts/rewrite-pcitable.py $module_dep_file $pci_map_file $pci_table \
- $CD_ROOT/etc/pl_pcitable
+ $BOOTMANAGER_DIR/source/merge_hw_tables.py \
+ $module_dep_file $pci_map_file $pci_table $CD_ROOT/etc/pl_pcitable
dd if=/dev/zero of=$INITRD bs=1M count=$RAMDISK_SIZE
mkfs.ext2 -F -m 0 -i $INITRD_BYTES_PER_INODE $INITRD
echo "pl_hwinit: loading floppy device driver"
/sbin/modprobe floppy
+
+# always wait a bit between loading the usb drivers, and checking /sys/
+# for usb devices (this isn't necessarily for waiting for mass storage files,
+# that is done below)
+echo "pl_hwinit: waiting for usb system to initialize."
+/bin/sleep 10s
+
+# sometimes, flash devices take a while to initialize. in fact, the kernel
+# intentionally waits 5 seconds for a device to 'settle'. some take even longer
+# to show up. if there are any mass storage devices on the system, try to
+# delay until they come online, up to a max delay of 30s.
+
+# the way this will be done is to look for files in /sys/devices that are named
+# 'bInterfaceClass', these will be a list of the usb devices on the system, and
+# their primary usb device interface class ids. The base directory these files
+# exist in will be the full path to the /sys/device entry for that device.
+# for each mass storage devices (they have an interface class value of 08),
+# we wait for a new symbolic link named 'driver' to exist in that directory,
+# indicating the kernel loaded a driver for that device.
+
+# usb interface class id for mass storage
+INTERFACE_CLASS_MASS_STORAGE="08"
+
+# how long to wait in seconds before continuing on if devices
+# aren't available
+MAX_USB_WAIT_TIME=30
+
+# low long in seconds to wait between checks
+PER_CHECK_USB_WAIT_TIME=5
+
+
+# find out if the device identified by the /sys dir has a module
+# loaded for it. check for a symlink in the dir named driver.
+function does_device_dir_have_driver()
+{
+ if [[ -h "$1/driver" ]]; then
+ return 1
+ else
+ return 0
+ fi
+}
+
+wait_dev_list=""
+for interface_class_file in `/bin/find /sys/devices -name 'bInterfaceClass'`; do
+ interface_class=`cat $interface_class_file`
+ if [[ "$interface_class" == $INTERFACE_CLASS_MASS_STORAGE ]]; then
+ wait_dev_list="$wait_dev_list "`/bin/dirname $interface_class_file`
+ fi
+done
+
+if [[ -n "$wait_dev_list" ]]; then
+ echo "pl_hwinit: found USB mass storage device(s). Attempting to wait"
+ echo "pl_hwinit: up to $MAX_USB_WAIT_TIME seconds for them to come online."
+
+ total_wait_time=0
+ success=0
+ while [[ $total_wait_time < $MAX_USB_WAIT_TIME ]]; do
+
+ total_wait_time=$(($total_wait_time+$PER_CHECK_USB_WAIT_TIME))
+
+ echo "pl_hwinit: waiting $PER_CHECK_USB_WAIT_TIME seconds."
+ /bin/sleep $PER_CHECK_USB_WAIT_TIME
+
+ all_devices_online=1
+ for device_dir in $wait_dev_list; do
+ does_device_dir_have_driver $device_dir
+ if [[ "$?" -eq 0 ]]; then
+ all_devices_online=0
+ fi
+ done
+
+ if [[ $all_devices_online -eq 1 ]]; then
+ success=1
+ echo "pl_hwinit: looks like the devices are now online."
+ break;
+ else
+ echo "pl_hwinit: not all devices online yet, waiting..."
+ fi
+ done
+
+ if [[ $success -eq 1 ]]; then
+ echo "pl_hwinit: Succesfully waited for USB mass storage devices"
+ echo "pl_hwinit: to come online."
+ else
+ echo "pl_hwinit: One or more USB mass storage devices did not"
+ echo "pl_hwinit: initialize in time. Continuing anyway."
+ fi
+fi
+
# (no other configuration file found)
DEFAULT_NET_CONF=0
+
net_init_failed()
{
echo
echo "pl_netinit: network initialization failed,"
echo "pl_netinit: shutting down machine in two hours"
- /bin/sleep 7200
+ /bin/sleep 2h
/sbin/shutdown -h now
exit 1
}
echo "pl_netinit: looking for node configuration file on flash based devices"
- echo "pl_netinit: waiting for flash devices if any to come online"
- # some usb flash based devices take a couple of seconds to initialize
- # also, try to read the partition table off the device to make sure
- # it shows up in /sys/block
- /bin/sleep 10s
-
# make the sd* expansion fail to an empty string if there are no sd
# devices
shopt -s nullglob
# device for it.
echo "pl_netinit: looking for a device with mac address $NET_DEVICE"
- pushd .
- cd /sys/class/net
+ pushd /sys/class/net
for device in *; do
dev_address=`cat $device/address`
if [[ "$dev_address" == "$NET_DEVICE" ]]; then
fi
done
popd
-
-elif [[ -n "$PRIMARY_DEV" ]]; then
- # the user specified a virtual ethernet device to use.
- ETH_DEVICE=$PRIMARY_DEV
- echo "pl_netinit: using user specified device $ETH_DEVICE"
-
else
ETH_DEVICE=$DEFAULT_NET_DEV
echo "pl_netinit: using default device $ETH_DEVICE"
# actually check to make sure ifconfig <device> succeeds
/sbin/ifconfig $ETH_DEVICE up 2>&1 > /dev/null
if [[ $? -ne 0 ]]; then
- echo "pl_netinit: device $ETH_DEVICE does not exist,"
- echo "pl_netinit: this is due to either the device not existing,"
- echo "pl_netinit: or its device drivers not being loaded"
+ echo "pl_netinit: device $ETH_DEVICE does not exist, most likely"
+ echo "pl_netinit: this cd does not have hardware support for your"
+ echo "pl_netinit: network adapter. please send the following lines"
+ echo "pl_netinit: to PlanetLab Support: support@planet-lab.org"
+ echo "pl_netinit: for further assistance"
+ echo
+ /sbin/lspci -n | /bin/grep "Class 0200"
+ echo
+
net_init_failed
fi
+++ /dev/null
-#!/usr/bin/env python
-
-"""
-The point of this small utility is to take a file in the format
-of /lib/modules/`uname -r`/modules.pcimap and /usr/share/hwdata/pcitable
-and output a condensed, more easily used format for module detection. This is
-done by first getting a list of all the built modules, then loading the
-pci ids for each of those modules from modules.pcimap, then finally merging
-in the contents of pcitable (for built modules only). The result should be
-a file with a pretty comprehensive mapping of pci ids to module names.
-
-The output is used by the PlanetLab boot cd (3.0+) and the pl_hwinit script
-to load all the applicable modules by scanning lspci output.
-
-
-
-Expected format of file modules.dep includes lines of:
-
-/full/module/path/mod.ko: <dependencies>
-
-Expected format of file modules.pcimap includes lines of:
-
-# pci_module vendor device subvendor subdevice class class_mask driver_data
-cciss 0x00000e11 0x0000b060 0x00000e11 0x00004070 0x00000000 0x00000000 0x0
-cciss 0x00000e11 0x0000b178 0x00000e11 0x00004070 0x00000000 0x00000000 0x0
-
-Expected format of file pcitable includes lines of:
-
-# ("%d\t%d\t%s\t"%s"\n", vendid, devid, moduleName, cardDescription)
-# or ("%d\t%d\t%d\t%d\t%s\t"%s"\n", vendid, devid, subvendid, subdevid, moduleNa
-# me, cardDescription)
-0x0e11 0x0508 "tmspci" "Compaq|Netelligent 4/16 Token Ring"
-0x1000 0x0407 0x8086 0x0532 "megaraid" "Storage RAID Controller SRCU42X"
-
-Lines listing a module name of ignore or unknown from pcitable are skipped
-
-
-
-Output format, for each line that matches the above lines:
-cciss 0e11:b060 0e11:b178
-
-If no pci ids are found for a particular module:
-
-sd_mod none:none
-"""
-
-import os, sys
-import string
-
-
-def usage():
- print( "\nUsage:" )
- print( "rewrite-pcitable.py <modules.dep> <modules.pcimap> " \
- "<pcitable> [<output>]" )
- print( "" )
-
-
-if len(sys.argv) < 4:
- usage()
- sys.exit(1)
-
-
-# open modules.dep (for list of built modules)
-modulesdep_file_name= sys.argv[1]
-try:
- modulesdep_file= file(modulesdep_file_name,"r")
-except IOError:
- sys.stderr.write( "Unable to open modules.dep: %s\n" % modulesdep_file_name )
- usage()
- sys.exit(1)
-
-# open modules.pcimap
-pcimap_file_name= sys.argv[2]
-try:
- pcimap_file= file(pcimap_file_name,"r")
-except IOError:
- sys.stderr.write( "Unable to open modules.pcimap: %s\n" % pcimap_file_name )
- usage()
- sys.exit(1)
-
-# open pcitable
-pcitable_file_name= sys.argv[3]
-try:
- pcitable_file= file(pcitable_file_name,"r")
-except IOError:
- sys.stderr.write( "Unable to open pcitable: %s\n" % pcitable_file_name )
- usage()
- sys.exit(1)
-
-# finally, if we are supposed to output to a file, open that too
-if len(sys.argv) > 4:
- output_file_name= sys.argv[4]
- try:
- output_file= file(output_file_name,"w")
- except IOError:
- sys.stderr.write( "Unable to open %s for writing.\n" % output_file )
- sys.exit(1)
-else:
- output_file= sys.stdout
-
-
-# associative array to store all matches of module -> ['vendor:device',..]
-# entries
-all_modules= {}
-
-
-# first step, create an associative array of all the built modules
-for line in modulesdep_file:
- parts= string.split(line,":")
- if len(parts) < 2:
- continue
-
- full_mod_path= parts[0]
- parts= string.split(full_mod_path,"/")
- module_name= parts[len(parts)-1]
- module_name_len= len(module_name)
- if module_name[module_name_len-3:] == ".ko":
- all_modules[module_name[:-3]]= []
-
-
-# now, parse the pcimap and add devices
-line_num= 0
-for line in pcimap_file:
- line_num= line_num+1
-
- # skip blank lines, or lines that begin with # (comments)
- line= string.strip(line)
- if len(line) == 0:
- continue
-
- if line[0] == "#":
- continue
-
- line_parts= string.split(line)
- if line_parts is None or len(line_parts) != 8:
- sys.stderr.write( "Skipping line %d in pcimap (incorrect format)\n" %
- line_num )
- continue
-
- # first two parts are always vendor / device id
- module= line_parts[0]
- vendor_id= line_parts[1]
- device_id= line_parts[2]
-
-
- # valid vendor and devices are 10 chars (0xXXXXXXXX) and begin with 0x
- if len(vendor_id) != 10 or len(device_id) != 10:
- sys.stderr.write( "Skipping line %d in pcimap (invalid vendor/device " \
- "id length)\n" % line_num )
- continue
-
- if string.lower(vendor_id[:2]) != "0x" \
- or string.lower(device_id[:2]) != "0x":
- sys.stderr.write( "Skipping line %d in pcimap (invalid vendor/device " \
- "id format)\n" % line_num )
- continue
-
- # cut down the ids, only need last 4 bytes
- # start at 6 = (10 total chars - 4 last chars need)
- vendor_id= string.lower(vendor_id[6:])
- device_id= string.lower(device_id[6:])
-
- full_id= "%s:%s" % (vendor_id, device_id)
-
- if all_modules.has_key(module):
- if full_id not in all_modules[module]:
- all_modules[module].append( full_id )
- else:
- # normally shouldn't get here, as the list is prepopulated with all
- # the built modules
- all_modules[module]= [full_id,]
-
-
-# parse pcitable, add any more ids for the devices
-line_num= 0
-for line in pcitable_file:
- line_num= line_num+1
-
- # skip blank lines, or lines that begin with # (comments)
- line= string.strip(line)
- if len(line) == 0:
- continue
-
- if line[0] == "#":
- continue
-
- line_parts= string.split(line)
- if line_parts is None or len(line_parts) < 4:
- sys.stderr.write( "Skipping line %d in pcitable (incorrect format)\n" %
- line_num )
- continue
-
- # vendor id is always the first field, device the second. also,
- # strip off first two chars (the 0x)
- vendor_id= string.lower(line_parts[0][2:])
- device_id= string.lower(line_parts[1][2:])
-
- full_id= "%s:%s" % (vendor_id, device_id)
-
- # if the first char of the third field is a double quote, the third field
- # is a module, else if the first char of the third field is a 0 (zero),
- # the fifth field is the module name.
- # it would nice if there was any easy way to split a string on spaces,
- # but recognize quoted strings, so they wouldn't be split up. that is
- # the reason for this wierd check
- if line_parts[2][0] == '"':
- module= line_parts[2]
- elif line_parts[2][0] == '0':
- module= line_parts[4]
- else:
- sys.stderr.write( "Skipping line %d in pcitable (incorrect format)\n" %
- line_num )
- continue
-
- # remove the first and last char of module (quote marks)
- module= module[1:]
- module= module[:len(module)-1]
-
- # now add it if we don't already have this module -> id mapping
- if all_modules.has_key(module):
- if full_id not in all_modules[module]:
- all_modules[module].append( full_id )
- else:
- # don't add any modules from pcitable that we don't already know about
- pass
-
-
-for module in all_modules.keys():
- devices= all_modules[module]
- if len(devices) > 0:
- devices_str= string.join( all_modules[module], " " )
- output_file.write( "%s %s\n" % (module,devices_str) )
-
-
-output_file.close()
-pcitable_file.close()
-pcimap_file.close()
-modulesdep_file.close()
-