[PATCH] Fix for USB media not found at boot

Hans Petter Selasky hselasky at c2i.net
Sat Oct 3 07:52:32 UTC 2009


On Friday 02 October 2009 23:11:21 Scott Long wrote:
> All,
>
> I have a candidate patch to fix the problem with USB boot media not being
> found in time at boot, leading to the "mountroot" prompt instead of a
> booting system.  Please apply both patches below and let me know if it
> works for you.

Hi,

Your patch looks OK. Some checkpoints however:

Does your patch work if ehci/ohci/uhci is kldloaded after system startup?

Does your patch work if CAM is not in the kernel?

I have a simple imporovement to your patch:

I would just add a synchronously blocking call to the end of "usb_bus_attach".

Something like:

#ifdef USB_HAVE_CAM
static void
usb_cam_wait_cb(void *arg)
{
	struct usb_bus *bus = *(struct usb_bus **)arg;

    USB_BUS_LOCK(bus);
    *(struct usb_bus **)arg = NULL;
	wakeup(arg);
    USB_BUS_UNLOCK(bus);
}

static void
usb_wait_cam(struct usb_bus *bus)
{
    struct intr_config_hook *hook;
    void *temp = bus;
    hook = malloc(sizeof(*hook), M_TEMP, M_ZERO);
    hook->ich_func = usb_wait_cam_cb;
    hook->ich_arg = &temp;

	config_intrhook_establish(hook);

    USB_BUS_LOCK(bus);
    if (temp != NULL)
		mtx_sleep(&temp, &bus->bus_mtx, 0, "WCAM", 0);
    USB_BUS_UNLOCK(bus);
}
#endif

That way makes the code more simple and avoids a race with the CAM callback 
being called after that the hardware is detached. For example if the Host 
Controller resides on a removable device.

There are some more USB_HAVE_XXX in sys/dev/usb/usb_freebsd.h .

--HPS



More information about the freebsd-current mailing list