MacOS X ADB Keyboard and Mouse Override

MacOS X is fairly intelligent in its treatment of the ADB bus. At boot time it probes the bus for devices and loads drivers for any that it finds. Unfortunately, this approach causes a couple of problems. First, your keyboard and mouse must be connected at boot time or else you are left with no way to interact with your system short of sshing in over the network. (In their defense, Apple states up front that ADB is not intended to be hot-pluggable.) Second, certain Keyboard-Video-Mouse (KVM) switchboxes do not respond to OS X's ADB probing. Booting the OS while attached to one of these KVMs is difficult; you must boot the machine with a real keyboard and mouse directly attached and then "hot-swap" to the KVM cables. If you have more than a few ADB machines connected to your KVM switch this approach quickly becomes unmanageable.

I've solved these problems on my own systems via a couple of modifications to the OS X Darwin kernel and the ADB mouse driver. First, the ADB probing routine is modified to force the detection of a keyboard and mouse, even if they aren't found on the bus. Second, a new ADB mouse driver is used. This driver does not try to probe the mouse to determine its type; it simply assumes the mouse is a simple Type I or Type II mouse.


Files

WARNING: The files below are for OS X 10.2.6 ONLY. Using them with another version of OS X will almost certainly result in an unbootable or otherwise corrupt system. Be certain your "About This Mac" panel indicates "Version 10.2.6". If you are running an older version, use the Software Update control panel to upgrade to 10.2.6. If you are running a newer version, send me an email or use the source code links below and build your own versions.

  • Modified Darwin kernel image (10.2.6)
  •     [binary image]     [source code patch]
  • AppleADBNoProbeMouse driver (10.2.6)
  •     [binary package]     [source code]

    Installation Instructions

    The installation process is rather tricky, so be sure to set aside some time for the job. Follow these instructions carefully, especially the parts regarding installing the new kernel image. Mistakes there will likely result in an unbootable system. If you do happen to end up with a system that will not boot, refer to the section entitled, " Booting the Original Kernel".

    1. Several of the installation steps require administrative privileges so make sure you are logged in as an administrative user.

    2. Download the kernel binary image and the mouse driver binary package using the links above. You do not need the source code files unless you plan to compile the kernel or the driver yourself (in which case you probably don't need the rest of these instructions, either).

    3. Extract the Darwin kernel image and copy it to the root of your System disk.

    4. The kernel image file must be owned by 'root' and must belong to the 'wheel' group. In addition, execute permission must be revoked from all users and write permission must be revoked from group and other. To accomplish this, open a terminal window (Applications/Utiltities/Terminal.app) and execute the following commands, entering your admin password when prompted:
          sudo chown root /mach_kernel-10.2.6-forceadb
          sudo chgrp wheel /mach_kernel-10.2.6-forceadb
          sudo chmod a-x /mach_kernel-10.2.6-forceadb
          sudo chmod go-w /mach_kernel-10.2.6-forceadb
      The commands will execute and return silently if everything goes ok. If something goes wrong, an error message will be displayed.

    5. Verify the kernel image by listing part of the root directory with this command:
          ls -l /mach_kernel*
      (that -l is "dash ell" not "dash one")

      The result should look like this (with different time and date stamps, of course):

          -rw-r--r--  1 root     wheel  3737772 May  2 00:49 /mach_kernel
          -rw-r--r--  1 root     wheel  3728360 Jul  5 13:41 /mach_kernel-10.2.6-forceadb
      The "/mach_kernel" file is your original 10.2.6 kernel. We will leave this kernel alone so you can revert back to it at any time. "/mach_kernel-10.2.6-forceadb" is the new kernel we will be configuring your system to use instead.

    6. Now we must configure your OpenFirmware (OF) to boot this new kernel instead of the original kernel. To do this we will set the boot-file OF parameter to point to the new kernel. This takes a little work because we must, in addition to specifying the kernel filename, also specify the boot device (i.e., what disk and controller to boot from). This bit of information varies widely from machine to machine so we must do some investigation to figure it out.

      Start by going to the System Preferences panel and opening the Startup Disk pane. Choose the OS X system you normally boot to and click the "Restart..." button. Choose "Save and Restart" when prompted. Your computer will reboot.

      Although this step may seem redundant since the default OS X system is already selected it is important in order to get OS X to set the OF boot-device parameter correctly. We'll be viewing and using the value of this parameter in the next step. Do not skip this step!

    7. Once the machine has rebooted, open a Terminal window again and run this command:
          nvram boot-device
      This command displays the value of the OF boot-device parameter which tells us the OF name of the device you normally boot from. The exact text will depend on your configuration, but a typical example from my system is:
          ide1/@0:2,\\:tbxi
      The part before the comma is what we are interested in (ide1/@0:2 in my case).

    8. Now we will set the OF boot-file parameter using the boot device string we just determined and the name of the new kernel image file. Use a command like this:
          sudo nvram boot-file="<your-boot-device>,mach_kernel-10.2.6-forceadb"
      Replace <your-boot-device> with the name of your boot-device as determined above. Only use the portion of the boot-device string before the comma. For example, on my system I would run the following command:
          sudo nvram boot-file="ide1/@0:2,mach_kernel-10.2.6-forceadb"
      The command will execute and return silently if everything goes ok. If something goes wrong, an error message will be displayed.

    9. At this point you should reboot your system without an ADB keyboard or mouse attached. One the system has booted, open a Terminal window and run the following command:
          dmesg | grep ADB
      Note that the | character is a vertical bar (pipe), not an 'ell' or a one.

      You should see the following output:

          IOADBController: Forcing assignment of id 2.
          IOADBController: Forcing assignment of id 3.
          ADB present:c
      This indicates that the IOADBController (the driver for the ADB bus) did not find a keyboard or a mouse, but forced one to be configured anyway. You should be able to plug in a keyboard and it should operate properly. The mouse will not operate yet; we need to install the new mouse driver first.

      If you do not see the output shown above, double check your configuration, especially the value of the OF boot-file parameter configured in step #8.

      If your system does not boot at all, refer to the section below entitled, "Booting the Original Kernel".

    10. Now that the new kernel image is installed and running we can install the new ADB mouse driver. This driver supplements the standard ADB mouse driver, it does not replace it. OS X will attempt to load the original driver first. If that driver fails (i.e., if you don't have a mouse connected at boot or your KVM doesn't respond to the probe commands), it will fall back to this "NoProbe" driver. This driver is the same as the standard ADB mouse driver with two exceptions:
      1. It does not attempt to probe the mouse type; it assumes a standard Type I or Type II mouse.
      2. It does not support Type IV mice.

      Installation of the NoProbe ADB driver is simple:

      1. Extract the binary package, AppleADBNoProbeMouse.pkg, from the .sit file.
      2. Open AppleADBNoProbeMouse.pkg
      3. Authenticate using an account with Admin rights when prompted
      4. Select your primary system disk as the install location
      5. Perform a basic installation (there are no options to configure)

    11. Reboot your system once again, without an ADB keyboard or mouse attached. Once the system boots, attach your keyboard and mouse. Both should function normally.

    Booting the Original Kernel

    If you encounter problems during the installation of the new kernel image you may be left with a system that does not boot. Also, you may at some point wish to switch back to the original kernel when you no longer need the ADB override. There are two ways to accomplish this:
    1. Reset your OpenFirmware (PRAM) settings
      This is the simplest method, however it will cause you to lose any custom OF configuration you may have made. This includes things like boot arguments (ex: verbose or single user mode), and boot device (if you do not normally boot the default system).

      To reset your OF settings, boot your machine while holding down Command-Option-P-R. Note that you must do this on a directly-attached ADB or USB keyboard. The machine will reset every few seconds as long as you continue holding the keys down. After a few resets, let go of the keys and the machine should boot from the default boot device and load the original mach kernel image.

    2. Reset your boot-file OF parameter
      The boot-file OF parameter determines which kernel image is loaded. By resetting this parameter we can cause the machine to boot the default kernel image without affecting any other OF parameters. There are two ways to do this, depending on whether you can boot into OS X or not.

      1. If you can boot into OS X, do so and run the following command in a Terminal window:
              sudo nvram boot-file=""

      2. If you cannot boot into OS X, boot your machine while holding down Command-Option-O-F. Note that you must do this on a directly-attached ADB or USB keyboard. After a few seconds you should be given a white screen with black text. It should look something like this:
              Apple Powermac1,1 1,1f4 BootROM built on 04/09/99 at 13:57:32
              Copyright 1994-1999 Apple Computer, Inc.
              All Rights Reserved.
        
              OpenFirmware 3.1.1
        
              To continue booting, type "mac-boot" and press return.
              To shut down, type "shut-down" and press return.
        
               ok
              0 >
        (The dates and version numbers will probably be different on your machine.)

        At the 0 > prompt, run this command:

              printenv boot-file
        The current value of boot-file should be displayed. You can write this down for future reference if you're so inclined. To reset the value, run this command:
              setenv boot-file
        Now you can run
              mac-boot
        to continue the bootup process. Your machine will boot the default kernel.


    Feel free to send questions and comments to me at
    akropel1@rochester.rr.com.

    Copyright (c) 2003 by Adam Kropelin, All Rights Reserved.