merge with mainline
This commit is contained in:
commit
16c7cb32c8
80 changed files with 5101 additions and 1687 deletions
|
@ -78,6 +78,12 @@ grub_libusb_devices (void)
|
|||
return GRUB_USB_ERR_NONE;
|
||||
}
|
||||
|
||||
void
|
||||
grub_usb_poll_devices (void)
|
||||
{
|
||||
/* TODO: recheck grub_usb_devs */
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
grub_usb_iterate (int (*hook) (grub_usb_device_t dev))
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -612,8 +612,23 @@ grub_uhci_portstatus (grub_usb_controller_t dev,
|
|||
status = grub_uhci_readreg16 (u, reg);
|
||||
grub_dprintf ("uhci", "detect=0x%02x\n", status);
|
||||
|
||||
if (!enable) /* We don't need reset port */
|
||||
{
|
||||
/* Disable the port. */
|
||||
grub_uhci_writereg16 (u, reg, 0 << 2);
|
||||
grub_dprintf ("uhci", "waiting for the port to be disabled\n");
|
||||
endtime = grub_get_time_ms () + 1000;
|
||||
while ((grub_uhci_readreg16 (u, reg) & (1 << 2)))
|
||||
if (grub_get_time_ms () > endtime)
|
||||
return grub_error (GRUB_ERR_IO, "UHCI Timed out");
|
||||
|
||||
status = grub_uhci_readreg16 (u, reg);
|
||||
grub_dprintf ("uhci", ">3detect=0x%02x\n", status);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
/* Reset the port. */
|
||||
grub_uhci_writereg16 (u, reg, enable << 9);
|
||||
grub_uhci_writereg16 (u, reg, 1 << 9);
|
||||
|
||||
/* Wait for the reset to complete. XXX: How long exactly? */
|
||||
grub_millisleep (50); /* For root hub should be nominaly 50ms */
|
||||
|
@ -623,16 +638,20 @@ grub_uhci_portstatus (grub_usb_controller_t dev,
|
|||
grub_millisleep (10);
|
||||
|
||||
/* Enable the port. */
|
||||
grub_uhci_writereg16 (u, reg, enable << 2);
|
||||
grub_uhci_writereg16 (u, reg, 1 << 2);
|
||||
grub_millisleep (10);
|
||||
|
||||
grub_dprintf ("uhci", "waiting for the port to be enabled\n");
|
||||
|
||||
endtime = grub_get_time_ms () + 1000;
|
||||
while (! (grub_uhci_readreg16 (u, reg) & (1 << 2)))
|
||||
while (! ((status = grub_uhci_readreg16 (u, reg)) & (1 << 2)))
|
||||
if (grub_get_time_ms () > endtime)
|
||||
return grub_error (GRUB_ERR_IO, "UHCI Timed out");
|
||||
|
||||
/* Reset bit Connect Status Change */
|
||||
grub_uhci_writereg16 (u, reg, status | (1 << 1));
|
||||
|
||||
/* Read final port status */
|
||||
status = grub_uhci_readreg16 (u, reg);
|
||||
grub_dprintf ("uhci", ">3detect=0x%02x\n", status);
|
||||
|
||||
|
@ -641,7 +660,7 @@ grub_uhci_portstatus (grub_usb_controller_t dev,
|
|||
}
|
||||
|
||||
static grub_usb_speed_t
|
||||
grub_uhci_detect_dev (grub_usb_controller_t dev, int port)
|
||||
grub_uhci_detect_dev (grub_usb_controller_t dev, int port, int *changed)
|
||||
{
|
||||
struct grub_uhci *u = (struct grub_uhci *) dev->data;
|
||||
int reg;
|
||||
|
@ -661,6 +680,9 @@ grub_uhci_detect_dev (grub_usb_controller_t dev, int port)
|
|||
|
||||
grub_dprintf ("uhci", "detect=0x%02x port=%d\n", status, port);
|
||||
|
||||
/* Connect Status Change bit - it detects change of connection */
|
||||
*changed = ((status & (1 << 1)) != 0);
|
||||
|
||||
if (! (status & 1))
|
||||
return GRUB_USB_SPEED_NONE;
|
||||
else if (status & (1 << 8))
|
||||
|
|
|
@ -21,8 +21,10 @@
|
|||
#include <grub/mm.h>
|
||||
#include <grub/usb.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/list.h>
|
||||
|
||||
static grub_usb_controller_dev_t grub_usb_list;
|
||||
struct grub_usb_attach_desc *attach_hooks;
|
||||
|
||||
void
|
||||
grub_usb_controller_dev_register (grub_usb_controller_dev_t usb)
|
||||
|
@ -164,7 +166,7 @@ grub_usb_device_initialize (grub_usb_device_t dev)
|
|||
* max. size of packet */
|
||||
dev->descdev.maxsize0 = 0; /* invalidating, for safety only, can be removed if it is sure it is zero here */
|
||||
err = grub_usb_get_descriptor (dev, GRUB_USB_DESCRIPTOR_DEVICE,
|
||||
0, 8, (char *) &dev->descdev);
|
||||
0, 8, (char *) &dev->descdev);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
|
@ -232,3 +234,75 @@ grub_usb_device_initialize (grub_usb_device_t dev)
|
|||
|
||||
return err;
|
||||
}
|
||||
|
||||
void grub_usb_device_attach (grub_usb_device_t dev)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* XXX: Just check configuration 0 for now. */
|
||||
for (i = 0; i < dev->config[0].descconf->numif; i++)
|
||||
{
|
||||
struct grub_usb_desc_if *interf;
|
||||
struct grub_usb_attach_desc *desc;
|
||||
|
||||
interf = dev->config[0].interf[i].descif;
|
||||
|
||||
grub_dprintf ("usb", "iterate: interf=%d, class=%d, subclass=%d, protocol=%d\n",
|
||||
i, interf->class, interf->subclass, interf->protocol);
|
||||
|
||||
if (dev->config[0].interf[i].attached)
|
||||
continue;
|
||||
|
||||
for (desc = attach_hooks; desc; desc = desc->next)
|
||||
if (interf->class == desc->class && desc->hook (dev, 0, i))
|
||||
dev->config[0].interf[i].attached = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
grub_usb_register_attach_hook_class (struct grub_usb_attach_desc *desc)
|
||||
{
|
||||
auto int usb_iterate (grub_usb_device_t dev);
|
||||
|
||||
int usb_iterate (grub_usb_device_t usbdev)
|
||||
{
|
||||
struct grub_usb_desc_device *descdev = &usbdev->descdev;
|
||||
int i;
|
||||
|
||||
if (descdev->class != 0 || descdev->subclass || descdev->protocol != 0
|
||||
|| descdev->configcnt == 0)
|
||||
return 0;
|
||||
|
||||
/* XXX: Just check configuration 0 for now. */
|
||||
for (i = 0; i < usbdev->config[0].descconf->numif; i++)
|
||||
{
|
||||
struct grub_usb_desc_if *interf;
|
||||
|
||||
interf = usbdev->config[0].interf[i].descif;
|
||||
|
||||
grub_dprintf ("usb", "iterate: interf=%d, class=%d, subclass=%d, protocol=%d\n",
|
||||
i, interf->class, interf->subclass, interf->protocol);
|
||||
|
||||
if (usbdev->config[0].interf[i].attached)
|
||||
continue;
|
||||
|
||||
if (interf->class != desc->class)
|
||||
continue;
|
||||
if (desc->hook (usbdev, 0, i))
|
||||
usbdev->config[0].interf[i].attached = 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
desc->next = attach_hooks;
|
||||
attach_hooks = desc;
|
||||
|
||||
grub_usb_iterate (usb_iterate);
|
||||
}
|
||||
|
||||
void
|
||||
grub_usb_unregister_attach_hook_class (struct grub_usb_attach_desc *desc)
|
||||
{
|
||||
grub_list_remove (GRUB_AS_LIST_P (&attach_hooks), GRUB_AS_LIST (desc));
|
||||
}
|
||||
|
|
|
@ -23,8 +23,21 @@
|
|||
#include <grub/misc.h>
|
||||
#include <grub/time.h>
|
||||
|
||||
#define GRUB_USBHUB_MAX_DEVICES 128
|
||||
|
||||
/* USB Supports 127 devices, with device 0 as special case. */
|
||||
static struct grub_usb_device *grub_usb_devs[128];
|
||||
static struct grub_usb_device *grub_usb_devs[GRUB_USBHUB_MAX_DEVICES];
|
||||
|
||||
struct grub_usb_hub
|
||||
{
|
||||
struct grub_usb_hub *next;
|
||||
grub_usb_controller_t controller;
|
||||
int nports;
|
||||
grub_usb_speed_t *speed;
|
||||
grub_usb_device_t dev;
|
||||
};
|
||||
|
||||
struct grub_usb_hub *hubs;
|
||||
|
||||
/* Add a device that currently has device number 0 and resides on
|
||||
CONTROLLER, the Hub reported that the device speed is SPEED. */
|
||||
|
@ -33,6 +46,7 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller, grub_usb_speed_t speed)
|
|||
{
|
||||
grub_usb_device_t dev;
|
||||
int i;
|
||||
grub_usb_err_t err;
|
||||
|
||||
dev = grub_zalloc (sizeof (struct grub_usb_device));
|
||||
if (! dev)
|
||||
|
@ -41,31 +55,51 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller, grub_usb_speed_t speed)
|
|||
dev->controller = *controller;
|
||||
dev->speed = speed;
|
||||
|
||||
grub_usb_device_initialize (dev);
|
||||
err = grub_usb_device_initialize (dev);
|
||||
if (err)
|
||||
{
|
||||
grub_free (dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Assign a new address to the device. */
|
||||
for (i = 1; i < 128; i++)
|
||||
for (i = 1; i < GRUB_USBHUB_MAX_DEVICES; i++)
|
||||
{
|
||||
if (! grub_usb_devs[i])
|
||||
break;
|
||||
}
|
||||
if (i == 128)
|
||||
if (i == GRUB_USBHUB_MAX_DEVICES)
|
||||
{
|
||||
grub_error (GRUB_ERR_IO, "can't assign address to USB device");
|
||||
for (i = 0; i < 8; i++)
|
||||
grub_free (dev->config[i].descconf);
|
||||
grub_free (dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
grub_usb_control_msg (dev,
|
||||
(GRUB_USB_REQTYPE_OUT
|
||||
| GRUB_USB_REQTYPE_STANDARD
|
||||
| GRUB_USB_REQTYPE_TARGET_DEV),
|
||||
GRUB_USB_REQ_SET_ADDRESS,
|
||||
i, 0, 0, NULL);
|
||||
err = grub_usb_control_msg (dev,
|
||||
(GRUB_USB_REQTYPE_OUT
|
||||
| GRUB_USB_REQTYPE_STANDARD
|
||||
| GRUB_USB_REQTYPE_TARGET_DEV),
|
||||
GRUB_USB_REQ_SET_ADDRESS,
|
||||
i, 0, 0, NULL);
|
||||
if (err)
|
||||
{
|
||||
for (i = 0; i < 8; i++)
|
||||
grub_free (dev->config[i].descconf);
|
||||
grub_free (dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dev->addr = i;
|
||||
dev->initialized = 1;
|
||||
grub_usb_devs[i] = dev;
|
||||
|
||||
/* Wait "recovery interval", spec. says 2ms */
|
||||
grub_millisleep (2);
|
||||
|
||||
grub_usb_device_attach (dev);
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
|
@ -133,7 +167,7 @@ grub_usb_add_hub (grub_usb_device_t dev)
|
|||
if (err)
|
||||
continue;
|
||||
grub_dprintf ("usb", "Hub port %d status: 0x%02x\n", i, status);
|
||||
|
||||
|
||||
/* If connected, reset and enable the port. */
|
||||
if (status & GRUB_USB_HUB_STATUS_CONNECTED)
|
||||
{
|
||||
|
@ -180,7 +214,22 @@ grub_usb_add_hub (grub_usb_device_t dev)
|
|||
(grub_get_time_ms() < timeout) );
|
||||
if (err || !(status & GRUB_USB_HUB_STATUS_C_PORT_RESET) )
|
||||
continue;
|
||||
|
||||
/* Wait a recovery time after reset, spec. says 10ms */
|
||||
grub_millisleep (10);
|
||||
|
||||
/* Do reset of connection change bit */
|
||||
err = grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_OUT
|
||||
| GRUB_USB_REQTYPE_CLASS
|
||||
| GRUB_USB_REQTYPE_TARGET_OTHER),
|
||||
GRUB_USB_REQ_CLEAR_FEATURE,
|
||||
GRUB_USB_HUB_FEATURE_C_CONNECTED,
|
||||
i, 0, 0);
|
||||
/* Just ignore the device if the Hub reports some error */
|
||||
if (err)
|
||||
continue;
|
||||
grub_dprintf ("usb", "Hub port - cleared connection change\n");
|
||||
|
||||
/* Add the device and assign a device address to it. */
|
||||
grub_dprintf ("usb", "Call hub_add_dev - port %d\n", i);
|
||||
next_dev = grub_usb_hub_add_dev (&dev->controller, speed);
|
||||
|
@ -196,49 +245,237 @@ grub_usb_add_hub (grub_usb_device_t dev)
|
|||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
attach_root_port (grub_usb_controller_t controller, int portno,
|
||||
grub_usb_speed_t speed)
|
||||
{
|
||||
grub_usb_device_t dev;
|
||||
grub_err_t err;
|
||||
|
||||
/* Disable the port. XXX: Why? */
|
||||
err = controller->dev->portstatus (controller, portno, 0);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
/* Enable the port. */
|
||||
err = controller->dev->portstatus (controller, portno, 1);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
/* Enable the port and create a device. */
|
||||
dev = grub_usb_hub_add_dev (controller, speed);
|
||||
if (! dev)
|
||||
return;
|
||||
|
||||
/* If the device is a Hub, scan it for more devices. */
|
||||
if (dev->descdev.class == 0x09)
|
||||
grub_usb_add_hub (dev);
|
||||
}
|
||||
|
||||
grub_usb_err_t
|
||||
grub_usb_root_hub (grub_usb_controller_t controller)
|
||||
{
|
||||
grub_err_t err;
|
||||
int ports;
|
||||
int i;
|
||||
struct grub_usb_hub *hub;
|
||||
int changed=0;
|
||||
|
||||
hub = grub_malloc (sizeof (*hub));
|
||||
if (!hub)
|
||||
return GRUB_USB_ERR_INTERNAL;
|
||||
|
||||
hub->next = hubs;
|
||||
hubs = hub;
|
||||
hub->controller = grub_malloc (sizeof (*controller));
|
||||
if (!hub->controller)
|
||||
{
|
||||
grub_free (hub);
|
||||
return GRUB_USB_ERR_INTERNAL;
|
||||
}
|
||||
|
||||
grub_memcpy (hub->controller, controller, sizeof (*controller));
|
||||
hub->dev = 0;
|
||||
|
||||
/* Query the number of ports the root Hub has. */
|
||||
ports = controller->dev->hubports (controller);
|
||||
|
||||
for (i = 0; i < ports; i++)
|
||||
hub->nports = controller->dev->hubports (controller);
|
||||
hub->speed = grub_malloc (sizeof (hub->speed[0]) * hub->nports);
|
||||
if (!hub->speed)
|
||||
{
|
||||
grub_usb_speed_t speed = controller->dev->detect_dev (controller, i);
|
||||
grub_free (hub->controller);
|
||||
grub_free (hub);
|
||||
return GRUB_USB_ERR_INTERNAL;
|
||||
}
|
||||
|
||||
if (speed != GRUB_USB_SPEED_NONE)
|
||||
{
|
||||
grub_usb_device_t dev;
|
||||
for (i = 0; i < hub->nports; i++)
|
||||
{
|
||||
hub->speed[i] = controller->dev->detect_dev (hub->controller, i,
|
||||
&changed);
|
||||
|
||||
/* Enable the port. */
|
||||
err = controller->dev->portstatus (controller, i, 1);
|
||||
if (err)
|
||||
continue;
|
||||
|
||||
/* Enable the port and create a device. */
|
||||
dev = grub_usb_hub_add_dev (controller, speed);
|
||||
if (! dev)
|
||||
continue;
|
||||
|
||||
/* If the device is a Hub, scan it for more devices. */
|
||||
if (dev->descdev.class == 0x09)
|
||||
grub_usb_add_hub (dev);
|
||||
}
|
||||
if (hub->speed[i] != GRUB_USB_SPEED_NONE)
|
||||
attach_root_port (hub->controller, i, hub->speed[i]);
|
||||
}
|
||||
|
||||
return GRUB_USB_ERR_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
poll_nonroot_hub (grub_usb_device_t dev)
|
||||
{
|
||||
struct grub_usb_usb_hubdesc hubdesc;
|
||||
grub_err_t err;
|
||||
int i;
|
||||
grub_uint64_t timeout;
|
||||
grub_usb_device_t next_dev;
|
||||
|
||||
err = grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_IN
|
||||
| GRUB_USB_REQTYPE_CLASS
|
||||
| GRUB_USB_REQTYPE_TARGET_DEV),
|
||||
GRUB_USB_REQ_GET_DESCRIPTOR,
|
||||
(GRUB_USB_DESCRIPTOR_HUB << 8) | 0,
|
||||
0, sizeof (hubdesc), (char *) &hubdesc);
|
||||
if (err)
|
||||
return;
|
||||
|
||||
/* Iterate over the Hub ports. */
|
||||
for (i = 1; i <= hubdesc.portcnt; i++)
|
||||
{
|
||||
grub_uint32_t status;
|
||||
|
||||
/* Get the port status. */
|
||||
err = grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_IN
|
||||
| GRUB_USB_REQTYPE_CLASS
|
||||
| GRUB_USB_REQTYPE_TARGET_OTHER),
|
||||
GRUB_USB_REQ_GET_STATUS,
|
||||
0, i, sizeof (status), (char *) &status);
|
||||
/* Just ignore the device if the Hub does not report the
|
||||
status. */
|
||||
if (err)
|
||||
continue;
|
||||
|
||||
/* Connected and status of connection changed ? */
|
||||
if ((status & GRUB_USB_HUB_STATUS_CONNECTED)
|
||||
&& (status & GRUB_USB_HUB_STATUS_C_CONNECTED))
|
||||
{
|
||||
grub_usb_speed_t speed;
|
||||
|
||||
/* Determine the device speed. */
|
||||
if (status & GRUB_USB_HUB_STATUS_LOWSPEED)
|
||||
speed = GRUB_USB_SPEED_LOW;
|
||||
else
|
||||
{
|
||||
if (status & GRUB_USB_HUB_STATUS_HIGHSPEED)
|
||||
speed = GRUB_USB_SPEED_HIGH;
|
||||
else
|
||||
speed = GRUB_USB_SPEED_FULL;
|
||||
}
|
||||
|
||||
/* A device is actually connected to this port.
|
||||
* Now do reset of port. */
|
||||
err = grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_OUT
|
||||
| GRUB_USB_REQTYPE_CLASS
|
||||
| GRUB_USB_REQTYPE_TARGET_OTHER),
|
||||
GRUB_USB_REQ_SET_FEATURE,
|
||||
GRUB_USB_HUB_FEATURE_PORT_RESET,
|
||||
i, 0, 0);
|
||||
/* If the Hub does not cooperate for this port, just skip
|
||||
the port. */
|
||||
if (err)
|
||||
continue;
|
||||
|
||||
/* Wait for reset procedure done */
|
||||
timeout = grub_get_time_ms () + 1000;
|
||||
do
|
||||
{
|
||||
/* Get the port status. */
|
||||
err = grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_IN
|
||||
| GRUB_USB_REQTYPE_CLASS
|
||||
| GRUB_USB_REQTYPE_TARGET_OTHER),
|
||||
GRUB_USB_REQ_GET_STATUS,
|
||||
0, i, sizeof (status), (char *) &status);
|
||||
}
|
||||
while (!err &&
|
||||
!(status & GRUB_USB_HUB_STATUS_C_PORT_RESET) &&
|
||||
(grub_get_time_ms() < timeout) );
|
||||
if (err || !(status & GRUB_USB_HUB_STATUS_C_PORT_RESET) )
|
||||
continue;
|
||||
|
||||
/* Wait a recovery time after reset, spec. says 10ms */
|
||||
grub_millisleep (10);
|
||||
|
||||
/* Do reset of connection change bit */
|
||||
err = grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_OUT
|
||||
| GRUB_USB_REQTYPE_CLASS
|
||||
| GRUB_USB_REQTYPE_TARGET_OTHER),
|
||||
GRUB_USB_REQ_CLEAR_FEATURE,
|
||||
GRUB_USB_HUB_FEATURE_C_CONNECTED,
|
||||
i, 0, 0);
|
||||
/* Just ignore the device if the Hub reports some error */
|
||||
if (err)
|
||||
continue;
|
||||
|
||||
/* Add the device and assign a device address to it. */
|
||||
next_dev = grub_usb_hub_add_dev (&dev->controller, speed);
|
||||
if (! next_dev)
|
||||
continue;
|
||||
|
||||
/* If the device is a Hub, scan it for more devices. */
|
||||
if (next_dev->descdev.class == 0x09)
|
||||
grub_usb_add_hub (next_dev);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
grub_usb_poll_devices (void)
|
||||
{
|
||||
struct grub_usb_hub *hub;
|
||||
int i;
|
||||
|
||||
for (hub = hubs; hub; hub = hub->next)
|
||||
{
|
||||
int changed=0;
|
||||
/* Do we have to recheck number of ports? */
|
||||
/* No, it should be never changed, it should be constant. */
|
||||
for (i = 0; i < hub->nports; i++)
|
||||
{
|
||||
grub_usb_speed_t speed;
|
||||
|
||||
speed = hub->controller->dev->detect_dev (hub->controller, i,
|
||||
&changed);
|
||||
|
||||
if (speed != GRUB_USB_SPEED_NONE)
|
||||
{
|
||||
if (changed)
|
||||
attach_root_port (hub->controller, i, speed);
|
||||
}
|
||||
|
||||
/* XXX: There should be also handling
|
||||
* of disconnected devices. */
|
||||
|
||||
hub->speed[i] = speed;
|
||||
}
|
||||
}
|
||||
|
||||
/* We should check changes of non-root hubs too. */
|
||||
for (i = 0; i < GRUB_USBHUB_MAX_DEVICES; i++)
|
||||
{
|
||||
grub_usb_device_t dev = grub_usb_devs[i];
|
||||
|
||||
if (dev && dev->descdev.class == 0x09)
|
||||
{
|
||||
poll_nonroot_hub (dev);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
grub_usb_iterate (int (*hook) (grub_usb_device_t dev))
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 128; i++)
|
||||
for (i = 0; i < GRUB_USBHUB_MAX_DEVICES; i++)
|
||||
{
|
||||
if (grub_usb_devs[i])
|
||||
{
|
||||
|
|
|
@ -81,7 +81,7 @@ grub_usb_control_msg (grub_usb_device_t dev,
|
|||
else
|
||||
max = 64;
|
||||
|
||||
grub_dprintf ("usb", "transfer = %p, dev = %p\n", transfer, dev);
|
||||
grub_dprintf ("usb", "control: transfer = %p, dev = %p\n", transfer, dev);
|
||||
|
||||
datablocks = (size + max - 1) / max;
|
||||
|
||||
|
@ -146,6 +146,7 @@ grub_usb_control_msg (grub_usb_device_t dev,
|
|||
transfer->transactions[datablocks + 1].toggle = 1;
|
||||
|
||||
err = dev->controller.dev->transfer (&dev->controller, transfer);
|
||||
grub_dprintf ("usb", "control: err=%d\n", err);
|
||||
|
||||
grub_free (transfer->transactions);
|
||||
|
||||
|
@ -174,6 +175,8 @@ grub_usb_bulk_readwrite (grub_usb_device_t dev,
|
|||
struct grub_pci_dma_chunk *data_chunk;
|
||||
grub_size_t size = size0;
|
||||
|
||||
grub_dprintf ("usb", "bulk: size=0x%02x type=%d\n", size, type);
|
||||
|
||||
/* FIXME: avoid allocation any kind of buffer in a first place. */
|
||||
data_chunk = grub_memalign_dma32 (128, size);
|
||||
if (!data_chunk)
|
||||
|
@ -248,7 +251,7 @@ grub_usb_bulk_readwrite (grub_usb_device_t dev,
|
|||
toggle = transfer->transactions[transfer->last_trans].toggle ? 0 : 1;
|
||||
else
|
||||
toggle = dev->toggle[endpoint]; /* Nothing done, take original */
|
||||
grub_dprintf ("usb", "toggle=%d\n", toggle);
|
||||
grub_dprintf ("usb", "bulk: err=%d, toggle=%d\n", err, toggle);
|
||||
dev->toggle[endpoint] = toggle;
|
||||
|
||||
grub_free (transfer->transactions);
|
||||
|
|
|
@ -325,7 +325,8 @@ setup_common_tables (void)
|
|||
|
||||
/* If it's FADT correct DSDT and FACS addresses. */
|
||||
fadt = (struct grub_acpi_fadt *) cur->addr;
|
||||
if (grub_memcmp (fadt->hdr.signature, "FACP", 4) == 0)
|
||||
if (grub_memcmp (fadt->hdr.signature, "FACP",
|
||||
sizeof (fadt->hdr.signature)) == 0)
|
||||
{
|
||||
fadt->dsdt_addr = PTR_TO_UINT32 (table_dsdt);
|
||||
fadt->facs_addr = facs_addr;
|
||||
|
@ -351,16 +352,16 @@ setup_common_tables (void)
|
|||
rsdt_addr = rsdt = (struct grub_acpi_table_header *) playground_ptr;
|
||||
playground_ptr += sizeof (struct grub_acpi_table_header) + 4 * numoftables;
|
||||
|
||||
rsdt_entry = (grub_uint32_t *)(rsdt + 1);
|
||||
rsdt_entry = (grub_uint32_t *) (rsdt + 1);
|
||||
|
||||
/* Fill RSDT header. */
|
||||
grub_memcpy (&(rsdt->signature), "RSDT", 4);
|
||||
rsdt->length = sizeof (struct grub_acpi_table_header) + 4 * numoftables;
|
||||
rsdt->revision = 1;
|
||||
grub_memcpy (&(rsdt->oemid), root_oemid, 6);
|
||||
grub_memcpy (&(rsdt->oemtable), root_oemtable, 4);
|
||||
grub_memcpy (&(rsdt->oemid), root_oemid, sizeof (rsdt->oemid));
|
||||
grub_memcpy (&(rsdt->oemtable), root_oemtable, sizeof (rsdt->oemtable));
|
||||
rsdt->oemrev = root_oemrev;
|
||||
grub_memcpy (&(rsdt->creator_id), root_creator_id, 6);
|
||||
grub_memcpy (&(rsdt->creator_id), root_creator_id, sizeof (rsdt->creator_id));
|
||||
rsdt->creator_rev = root_creator_rev;
|
||||
|
||||
for (cur = acpi_tables; cur; cur = cur->next)
|
||||
|
@ -378,7 +379,8 @@ setv1table (void)
|
|||
/* Create RSDP. */
|
||||
rsdpv1_new = (struct grub_acpi_rsdp_v10 *) playground_ptr;
|
||||
playground_ptr += sizeof (struct grub_acpi_rsdp_v10);
|
||||
grub_memcpy (&(rsdpv1_new->signature), "RSD PTR ", 8);
|
||||
grub_memcpy (&(rsdpv1_new->signature), "RSD PTR ",
|
||||
sizeof (rsdpv1_new->signature));
|
||||
grub_memcpy (&(rsdpv1_new->oemid), root_oemid, sizeof (rsdpv1_new->oemid));
|
||||
rsdpv1_new->revision = 0;
|
||||
rsdpv1_new->rsdt_addr = PTR_TO_UINT32 (rsdt_addr);
|
||||
|
|
|
@ -194,6 +194,8 @@ grub_cmd_usbtest (grub_command_t cmd __attribute__ ((unused)),
|
|||
int argc __attribute__ ((unused)),
|
||||
char **args __attribute__ ((unused)))
|
||||
{
|
||||
grub_usb_poll_devices ();
|
||||
|
||||
grub_printf ("USB devices:\n\n");
|
||||
grub_usb_iterate (usb_iterate);
|
||||
|
||||
|
|
|
@ -89,7 +89,8 @@ struct grub_nv_super
|
|||
} __attribute__ ((packed));
|
||||
|
||||
static grub_err_t
|
||||
grub_dmraid_nv_detect (grub_disk_t disk, struct grub_raid_array *array)
|
||||
grub_dmraid_nv_detect (grub_disk_t disk, struct grub_raid_array *array,
|
||||
grub_disk_addr_t *start_sector)
|
||||
{
|
||||
grub_disk_addr_t sector;
|
||||
struct grub_nv_super sb;
|
||||
|
@ -132,6 +133,7 @@ grub_dmraid_nv_detect (grub_disk_t disk, struct grub_raid_array *array)
|
|||
"unsupported RAID level: %d", sb.array.raid_level);
|
||||
}
|
||||
|
||||
array->name = NULL;
|
||||
array->number = 0;
|
||||
array->total_devs = sb.array.total_volumes;
|
||||
array->chunk_size = sb.array.stripe_block_size;
|
||||
|
@ -144,6 +146,8 @@ grub_dmraid_nv_detect (grub_disk_t disk, struct grub_raid_array *array)
|
|||
grub_memcpy (array->uuid, (char *) &sb.array.signature,
|
||||
sizeof (sb.array.signature));
|
||||
|
||||
*start_sector = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
struct grub_loopback
|
||||
{
|
||||
char *devname;
|
||||
char *filename;
|
||||
grub_file_t file;
|
||||
int has_partitions;
|
||||
struct grub_loopback *next;
|
||||
};
|
||||
|
@ -63,7 +63,7 @@ delete_loopback (const char *name)
|
|||
*prev = dev->next;
|
||||
|
||||
grub_free (dev->devname);
|
||||
grub_free (dev->filename);
|
||||
grub_file_close (dev->file);
|
||||
grub_free (dev);
|
||||
|
||||
return 0;
|
||||
|
@ -76,6 +76,7 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args)
|
|||
struct grub_arg_list *state = state = cmd->state;
|
||||
grub_file_t file;
|
||||
struct grub_loopback *newdev;
|
||||
grub_err_t ret;
|
||||
|
||||
if (argc < 1)
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name required");
|
||||
|
@ -91,9 +92,6 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args)
|
|||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
/* Close the file, the only reason for opening it is validation. */
|
||||
grub_file_close (file);
|
||||
|
||||
/* First try to replace the old device. */
|
||||
for (newdev = loopback_list; newdev; newdev = newdev->next)
|
||||
if (grub_strcmp (newdev->devname, args[0]) == 0)
|
||||
|
@ -103,10 +101,10 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args)
|
|||
{
|
||||
char *newname = grub_strdup (args[1]);
|
||||
if (! newname)
|
||||
return grub_errno;
|
||||
goto fail;
|
||||
|
||||
grub_free (newdev->filename);
|
||||
newdev->filename = newname;
|
||||
grub_file_close (newdev->file);
|
||||
newdev->file = file;
|
||||
|
||||
/* Set has_partitions when `--partitions' was used. */
|
||||
newdev->has_partitions = state[1].set;
|
||||
|
@ -117,22 +115,16 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args)
|
|||
/* Unable to replace it, make a new entry. */
|
||||
newdev = grub_malloc (sizeof (struct grub_loopback));
|
||||
if (! newdev)
|
||||
return grub_errno;
|
||||
goto fail;
|
||||
|
||||
newdev->devname = grub_strdup (args[0]);
|
||||
if (! newdev->devname)
|
||||
{
|
||||
grub_free (newdev);
|
||||
return grub_errno;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
newdev->filename = grub_strdup (args[1]);
|
||||
if (! newdev->filename)
|
||||
{
|
||||
grub_free (newdev->devname);
|
||||
grub_free (newdev);
|
||||
return grub_errno;
|
||||
}
|
||||
newdev->file = file;
|
||||
|
||||
/* Set has_partitions when `--partitions' was used. */
|
||||
newdev->has_partitions = state[1].set;
|
||||
|
@ -142,6 +134,11 @@ grub_cmd_loopback (grub_extcmd_t cmd, int argc, char **args)
|
|||
loopback_list = newdev;
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
ret = grub_errno;
|
||||
grub_file_close (file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
@ -160,7 +157,6 @@ grub_loopback_iterate (int (*hook) (const char *name))
|
|||
static grub_err_t
|
||||
grub_loopback_open (const char *name, grub_disk_t disk)
|
||||
{
|
||||
grub_file_t file;
|
||||
struct grub_loopback *dev;
|
||||
|
||||
for (dev = loopback_list; dev; dev = dev->next)
|
||||
|
@ -170,29 +166,17 @@ grub_loopback_open (const char *name, grub_disk_t disk)
|
|||
if (! dev)
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
|
||||
|
||||
file = grub_file_open (dev->filename);
|
||||
if (! file)
|
||||
return grub_errno;
|
||||
|
||||
/* Use the filesize for the disk size, round up to a complete sector. */
|
||||
disk->total_sectors = ((file->size + GRUB_DISK_SECTOR_SIZE - 1)
|
||||
disk->total_sectors = ((dev->file->size + GRUB_DISK_SECTOR_SIZE - 1)
|
||||
/ GRUB_DISK_SECTOR_SIZE);
|
||||
disk->id = (unsigned long) dev;
|
||||
|
||||
disk->has_partitions = dev->has_partitions;
|
||||
disk->data = file;
|
||||
disk->data = dev->file;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
grub_loopback_close (grub_disk_t disk)
|
||||
{
|
||||
grub_file_t file = (grub_file_t) disk->data;
|
||||
|
||||
grub_file_close (file);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_loopback_read (grub_disk_t disk, grub_disk_addr_t sector,
|
||||
grub_size_t size, char *buf)
|
||||
|
@ -234,7 +218,6 @@ static struct grub_disk_dev grub_loopback_dev =
|
|||
.id = GRUB_DISK_DEVICE_LOOPBACK_ID,
|
||||
.iterate = grub_loopback_iterate,
|
||||
.open = grub_loopback_open,
|
||||
.close = grub_loopback_close,
|
||||
.read = grub_loopback_read,
|
||||
.write = grub_loopback_write,
|
||||
.next = 0
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* mdraid_linux.c - module to handle linux softraid. */
|
||||
/* mdraid_linux.c - module to handle Linux Software RAID. */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2008 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2008,2009,2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -159,63 +159,254 @@ struct grub_raid_super_09
|
|||
struct grub_raid_disk_09 this_disk;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
static grub_err_t
|
||||
grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array)
|
||||
/*
|
||||
* The version-1 superblock :
|
||||
* All numeric fields are little-endian.
|
||||
*
|
||||
* Total size: 256 bytes plus 2 per device.
|
||||
* 1K allows 384 devices.
|
||||
*/
|
||||
|
||||
struct grub_raid_super_1x
|
||||
{
|
||||
/* Constant array information - 128 bytes. */
|
||||
grub_uint32_t magic; /* MD_SB_MAGIC: 0xa92b4efc - little endian. */
|
||||
grub_uint32_t major_version; /* 1. */
|
||||
grub_uint32_t feature_map; /* Bit 0 set if 'bitmap_offset' is meaningful. */
|
||||
grub_uint32_t pad0; /* Always set to 0 when writing. */
|
||||
|
||||
grub_uint8_t set_uuid[16]; /* User-space generated. */
|
||||
char set_name[32]; /* Set and interpreted by user-space. */
|
||||
|
||||
grub_uint64_t ctime; /* Lo 40 bits are seconds, top 24 are microseconds or 0. */
|
||||
grub_uint32_t level; /* -4 (multipath), -1 (linear), 0,1,4,5. */
|
||||
grub_uint32_t layout; /* only for raid5 and raid10 currently. */
|
||||
grub_uint64_t size; /* Used size of component devices, in 512byte sectors. */
|
||||
|
||||
grub_uint32_t chunksize; /* In 512byte sectors. */
|
||||
grub_uint32_t raid_disks;
|
||||
grub_uint32_t bitmap_offset; /* Sectors after start of superblock that bitmap starts
|
||||
* NOTE: signed, so bitmap can be before superblock
|
||||
* only meaningful of feature_map[0] is set.
|
||||
*/
|
||||
|
||||
/* These are only valid with feature bit '4'. */
|
||||
grub_uint32_t new_level; /* New level we are reshaping to. */
|
||||
grub_uint64_t reshape_position; /* Next address in array-space for reshape. */
|
||||
grub_uint32_t delta_disks; /* Change in number of raid_disks. */
|
||||
grub_uint32_t new_layout; /* New layout. */
|
||||
grub_uint32_t new_chunk; /* New chunk size (512byte sectors). */
|
||||
grub_uint8_t pad1[128 - 124]; /* Set to 0 when written. */
|
||||
|
||||
/* Constant this-device information - 64 bytes. */
|
||||
grub_uint64_t data_offset; /* Sector start of data, often 0. */
|
||||
grub_uint64_t data_size; /* Sectors in this device that can be used for data. */
|
||||
grub_uint64_t super_offset; /* Sector start of this superblock. */
|
||||
grub_uint64_t recovery_offset; /* Sectors before this offset (from data_offset) have been recovered. */
|
||||
grub_uint32_t dev_number; /* Permanent identifier of this device - not role in raid. */
|
||||
grub_uint32_t cnt_corrected_read; /* Number of read errors that were corrected by re-writing. */
|
||||
grub_uint8_t device_uuid[16]; /* User-space setable, ignored by kernel. */
|
||||
grub_uint8_t devflags; /* Per-device flags. Only one defined... */
|
||||
grub_uint8_t pad2[64 - 57]; /* Set to 0 when writing. */
|
||||
|
||||
/* Array state information - 64 bytes. */
|
||||
grub_uint64_t utime; /* 40 bits second, 24 btes microseconds. */
|
||||
grub_uint64_t events; /* Incremented when superblock updated. */
|
||||
grub_uint64_t resync_offset; /* Data before this offset (from data_offset) known to be in sync. */
|
||||
grub_uint32_t sb_csum; /* Checksum upto devs[max_dev]. */
|
||||
grub_uint32_t max_dev; /* Size of devs[] array to consider. */
|
||||
grub_uint8_t pad3[64 - 32]; /* Set to 0 when writing. */
|
||||
|
||||
/* Device state information. Indexed by dev_number.
|
||||
* 2 bytes per device.
|
||||
* Note there are no per-device state flags. State information is rolled
|
||||
* into the 'roles' value. If a device is spare or faulty, then it doesn't
|
||||
* have a meaningful role.
|
||||
*/
|
||||
grub_uint16_t dev_roles[0]; /* Role in array, or 0xffff for a spare, or 0xfffe for faulty. */
|
||||
};
|
||||
/* Could be __attribute__ ((packed)), but since all members in this struct
|
||||
are already appropriately aligned, we can omit this and avoid suboptimal
|
||||
assembly in some cases. */
|
||||
|
||||
#define WriteMostly1 1 /* Mask for writemostly flag in above devflags. */
|
||||
|
||||
static grub_err_t
|
||||
grub_mdraid_detect_09 (grub_disk_addr_t sector,
|
||||
struct grub_raid_super_09 *sb,
|
||||
struct grub_raid_array *array,
|
||||
grub_disk_addr_t *start_sector)
|
||||
{
|
||||
grub_disk_addr_t sector;
|
||||
grub_uint64_t size;
|
||||
struct grub_raid_super_09 sb;
|
||||
grub_uint32_t *uuid;
|
||||
|
||||
/* The sector where the RAID superblock is stored, if available. */
|
||||
size = grub_disk_get_size (disk);
|
||||
sector = NEW_SIZE_SECTORS (size);
|
||||
|
||||
if (grub_disk_read (disk, sector, 0, SB_BYTES, &sb))
|
||||
return grub_errno;
|
||||
|
||||
/* Look whether there is a RAID superblock. */
|
||||
if (sb.md_magic != SB_MAGIC)
|
||||
return grub_error (GRUB_ERR_OUT_OF_RANGE, "not raid");
|
||||
|
||||
/* FIXME: Also support version 1.0. */
|
||||
if (sb.major_version != 0 || sb.minor_version != 90)
|
||||
if (sb->major_version != 0 || sb->minor_version != 90)
|
||||
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"unsupported RAID version: %d.%d",
|
||||
sb.major_version, sb.minor_version);
|
||||
sb->major_version, sb->minor_version);
|
||||
|
||||
/* FIXME: Check the checksum. */
|
||||
/* FIXME: Check the checksum. */
|
||||
|
||||
/* Multipath. */
|
||||
if ((int) sb.level == -4)
|
||||
sb.level = 1;
|
||||
if ((int) sb->level == -4)
|
||||
sb->level = 1;
|
||||
|
||||
if (sb.level != 0 && sb.level != 1 && sb.level != 4 &&
|
||||
sb.level != 5 && sb.level != 6 && sb.level != 10)
|
||||
if (sb->level != 0 && sb->level != 1 && sb->level != 4 &&
|
||||
sb->level != 5 && sb->level != 6 && sb->level != 10)
|
||||
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"unsupported RAID level: %d", sb.level);
|
||||
"unsupported RAID level: %d", sb->level);
|
||||
|
||||
array->number = sb.md_minor;
|
||||
array->level = sb.level;
|
||||
array->layout = sb.layout;
|
||||
array->total_devs = sb.raid_disks;
|
||||
array->disk_size = (sb.size) ? sb.size * 2 : sector;
|
||||
array->chunk_size = sb.chunk_size >> 9;
|
||||
array->index = sb.this_disk.number;
|
||||
array->name = NULL;
|
||||
array->number = sb->md_minor;
|
||||
array->level = sb->level;
|
||||
array->layout = sb->layout;
|
||||
array->total_devs = sb->raid_disks;
|
||||
array->disk_size = (sb->size) ? sb->size * 2 : sector;
|
||||
array->chunk_size = sb->chunk_size >> 9;
|
||||
array->index = sb->this_disk.number;
|
||||
array->uuid_len = 16;
|
||||
array->uuid = grub_malloc (16);
|
||||
if (!array->uuid)
|
||||
return grub_errno;
|
||||
return grub_errno;
|
||||
|
||||
uuid = (grub_uint32_t *) array->uuid;
|
||||
uuid[0] = sb.set_uuid0;
|
||||
uuid[1] = sb.set_uuid1;
|
||||
uuid[2] = sb.set_uuid2;
|
||||
uuid[3] = sb.set_uuid3;
|
||||
uuid[0] = sb->set_uuid0;
|
||||
uuid[1] = sb->set_uuid1;
|
||||
uuid[2] = sb->set_uuid2;
|
||||
uuid[3] = sb->set_uuid3;
|
||||
|
||||
*start_sector = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_mdraid_detect_1x (grub_disk_t disk, grub_disk_addr_t sector,
|
||||
struct grub_raid_super_1x *sb,
|
||||
struct grub_raid_array *array,
|
||||
grub_disk_addr_t *start_sector)
|
||||
{
|
||||
grub_uint64_t sb_size;
|
||||
struct grub_raid_super_1x *real_sb;
|
||||
|
||||
if (sb->major_version != 1)
|
||||
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"Unsupported RAID version: %d",
|
||||
sb->major_version);
|
||||
|
||||
/* Multipath. */
|
||||
if ((int) sb->level == -4)
|
||||
sb->level = 1;
|
||||
|
||||
if (sb->level != 0 && sb->level != 1 && sb->level != 4 &&
|
||||
sb->level != 5 && sb->level != 6 && sb->level != 10)
|
||||
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"Unsupported RAID level: %d", sb->level);
|
||||
|
||||
/* 1.x superblocks don't have a fixed size on disk. So we have to
|
||||
read it again now that we now the max device count. */
|
||||
sb_size = sizeof (struct grub_raid_super_1x) + 2 * grub_le_to_cpu32 (sb->max_dev);
|
||||
real_sb = grub_malloc (sb_size);
|
||||
if (! real_sb)
|
||||
return grub_errno;
|
||||
|
||||
if (grub_disk_read (disk, sector, 0, sb_size, real_sb))
|
||||
{
|
||||
grub_free (real_sb);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
array->name = grub_strdup (real_sb->set_name);
|
||||
if (! array->name)
|
||||
{
|
||||
grub_free (real_sb);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
array->number = 0;
|
||||
array->level = grub_le_to_cpu32 (real_sb->level);
|
||||
array->layout = grub_le_to_cpu32 (real_sb->layout);
|
||||
array->total_devs = grub_le_to_cpu32 (real_sb->raid_disks);
|
||||
array->disk_size = grub_le_to_cpu64 (real_sb->size);
|
||||
array->chunk_size = grub_le_to_cpu32 (real_sb->chunksize);
|
||||
if (grub_le_to_cpu32 (real_sb->dev_number) <
|
||||
grub_le_to_cpu32 (real_sb->max_dev))
|
||||
array->index = grub_le_to_cpu16
|
||||
(real_sb->dev_roles[grub_le_to_cpu32 (real_sb->dev_number)]);
|
||||
else
|
||||
array->index = 0xffff; /* disk will be later not used! */
|
||||
array->uuid_len = 16;
|
||||
array->uuid = grub_malloc (16);
|
||||
if (!array->uuid)
|
||||
{
|
||||
grub_free (real_sb);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
grub_memcpy (array->uuid, real_sb->set_uuid, 16);
|
||||
|
||||
*start_sector = real_sb->data_offset;
|
||||
|
||||
grub_free (real_sb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_mdraid_detect (grub_disk_t disk, struct grub_raid_array *array,
|
||||
grub_disk_addr_t *start_sector)
|
||||
{
|
||||
grub_disk_addr_t sector;
|
||||
grub_uint64_t size;
|
||||
struct grub_raid_super_09 sb_09;
|
||||
struct grub_raid_super_1x sb_1x;
|
||||
grub_uint8_t minor_version;
|
||||
|
||||
/* The sector where the mdraid 0.90 superblock is stored, if available. */
|
||||
size = grub_disk_get_size (disk);
|
||||
sector = NEW_SIZE_SECTORS (size);
|
||||
|
||||
if (grub_disk_read (disk, sector, 0, SB_BYTES, &sb_09))
|
||||
return grub_errno;
|
||||
|
||||
/* Look whether there is a mdraid 0.90 superblock. */
|
||||
if (sb_09.md_magic == SB_MAGIC)
|
||||
return grub_mdraid_detect_09 (sector, &sb_09, array, start_sector);
|
||||
|
||||
/* Check for an 1.x superblock.
|
||||
* It's always aligned to a 4K boundary
|
||||
* and depending on the minor version it can be:
|
||||
* 0: At least 8K, but less than 12K, from end of device
|
||||
* 1: At start of device
|
||||
* 2: 4K from start of device.
|
||||
*/
|
||||
|
||||
for (minor_version = 0; minor_version < 3; ++minor_version)
|
||||
{
|
||||
switch (minor_version)
|
||||
{
|
||||
case 0:
|
||||
sector = (size - 8 * 2) & ~(4 * 2 - 1);
|
||||
break;
|
||||
case 1:
|
||||
sector = 0;
|
||||
break;
|
||||
case 2:
|
||||
sector = 4 * 2;
|
||||
break;
|
||||
}
|
||||
|
||||
if (grub_disk_read (disk, sector, 0, sizeof (struct grub_raid_super_1x),
|
||||
&sb_1x))
|
||||
return grub_errno;
|
||||
|
||||
if (sb_1x.magic == SB_MAGIC)
|
||||
return grub_mdraid_detect_1x (disk, sector, &sb_1x, array,
|
||||
start_sector);
|
||||
}
|
||||
|
||||
/* Neither 0.90 nor 1.x. */
|
||||
return grub_error (GRUB_ERR_OUT_OF_RANGE, "not raid");
|
||||
}
|
||||
|
||||
static struct grub_raid grub_mdraid_dev = {
|
||||
.name = "mdraid",
|
||||
.detect = grub_mdraid_detect,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* raid.c - module to read RAID arrays. */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2006,2007,2008,2009 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -254,7 +254,8 @@ grub_raid_read (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
err = grub_disk_read (array->device[k],
|
||||
read_sector + j * far_ofs + b,
|
||||
array->start_sector[k] +
|
||||
read_sector + j * far_ofs + b,
|
||||
0,
|
||||
read_size << GRUB_DISK_SECTOR_BITS,
|
||||
buf);
|
||||
|
@ -366,7 +367,8 @@ grub_raid_read (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
err = grub_disk_read (array->device[disknr],
|
||||
read_sector + b, 0,
|
||||
array->start_sector[disknr] +
|
||||
read_sector + b, 0,
|
||||
read_size << GRUB_DISK_SECTOR_BITS,
|
||||
buf);
|
||||
|
||||
|
@ -475,12 +477,12 @@ grub_raid_write (grub_disk_t disk __attribute ((unused)),
|
|||
|
||||
static grub_err_t
|
||||
insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
|
||||
const char *scanner_name)
|
||||
grub_disk_addr_t start_sector, const char *scanner_name)
|
||||
{
|
||||
struct grub_raid_array *array = 0, *p;
|
||||
|
||||
/* See whether the device is part of an array we have already seen a
|
||||
device from. */
|
||||
device from. */
|
||||
for (p = array_list; p != NULL; p = p->next)
|
||||
if ((p->uuid_len == new_array->uuid_len) &&
|
||||
(! grub_memcmp (p->uuid, new_array->uuid, p->uuid_len)))
|
||||
|
@ -491,7 +493,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
|
|||
/* Do some checks before adding the device to the array. */
|
||||
|
||||
/* FIXME: Check whether the update time of the superblocks are
|
||||
the same. */
|
||||
the same. */
|
||||
|
||||
if (array->total_devs == array->nr_devs)
|
||||
/* We found more members of the array than the array
|
||||
|
@ -502,7 +504,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
|
|||
|
||||
if (array->device[new_array->index] != NULL)
|
||||
/* We found multiple devices with the same number. Again,
|
||||
this shouldn't happen.*/
|
||||
this shouldn't happen. */
|
||||
grub_dprintf ("raid", "Found two disks with the number %d?!?",
|
||||
new_array->number);
|
||||
|
||||
|
@ -524,46 +526,75 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
|
|||
*array = *new_array;
|
||||
array->nr_devs = 0;
|
||||
grub_memset (&array->device, 0, sizeof (array->device));
|
||||
grub_memset (&array->start_sector, 0, sizeof (array->start_sector));
|
||||
|
||||
/* Check whether we don't have multiple arrays with the same number. */
|
||||
for (p = array_list; p != NULL; p = p->next)
|
||||
{
|
||||
if (p->number == array->number)
|
||||
break;
|
||||
}
|
||||
|
||||
if (p)
|
||||
{
|
||||
/* The number is already in use, so we need to find an new number. */
|
||||
int i = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
for (p = array_list; p != NULL; p = p->next)
|
||||
{
|
||||
if (p->number == i)
|
||||
break;
|
||||
}
|
||||
|
||||
if (!p)
|
||||
{
|
||||
/* We found an unused number. */
|
||||
array->number = i;
|
||||
break;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
array->name = grub_xasprintf ("md%d", array->number);
|
||||
if (! array->name)
|
||||
{
|
||||
grub_free (array->uuid);
|
||||
grub_free (array);
|
||||
{
|
||||
for (p = array_list; p != NULL; p = p->next)
|
||||
{
|
||||
if (! p->name && p->number == array->number)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
if (array->name || p)
|
||||
{
|
||||
/* The number is already in use, so we need to find a new one.
|
||||
(Or, in the case of named arrays, the array doesn't have its
|
||||
own number, but we need one that doesn't clash for use as a key
|
||||
in the disk cache. */
|
||||
int i = array->name ? 0x40000000 : 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
for (p = array_list; p != NULL; p = p->next)
|
||||
{
|
||||
if (p->number == i)
|
||||
break;
|
||||
}
|
||||
|
||||
if (! p)
|
||||
{
|
||||
/* We found an unused number. */
|
||||
array->number = i;
|
||||
break;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
/* mdraid 1.x superblocks have only a name stored not a number.
|
||||
Use it directly as GRUB device. */
|
||||
if (! array->name)
|
||||
{
|
||||
array->name = grub_xasprintf ("md%d", array->number);
|
||||
if (! array->name)
|
||||
{
|
||||
grub_free (array->uuid);
|
||||
grub_free (array);
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Strip off the homehost if present. */
|
||||
char *colon = grub_strchr (array->name, ':');
|
||||
char *new_name = grub_xasprintf ("md/%s",
|
||||
colon ? colon + 1 : array->name);
|
||||
|
||||
if (! new_name)
|
||||
{
|
||||
grub_free (array->uuid);
|
||||
grub_free (array);
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
grub_free (array->name);
|
||||
array->name = new_name;
|
||||
}
|
||||
|
||||
grub_dprintf ("raid", "Found array %s (%s)\n", array->name,
|
||||
scanner_name);
|
||||
|
@ -580,6 +611,7 @@ insert_array (grub_disk_t disk, struct grub_raid_array *new_array,
|
|||
|
||||
/* Add the device to the array. */
|
||||
array->device[new_array->index] = disk;
|
||||
array->start_sector[new_array->index] = start_sector;
|
||||
array->nr_devs++;
|
||||
|
||||
return 0;
|
||||
|
@ -621,6 +653,7 @@ grub_raid_register (grub_raid_t raid)
|
|||
{
|
||||
grub_disk_t disk;
|
||||
struct grub_raid_array array;
|
||||
grub_disk_addr_t start_sector;
|
||||
|
||||
grub_dprintf ("raid", "Scanning for RAID devices on disk %s\n", name);
|
||||
|
||||
|
@ -629,8 +662,8 @@ grub_raid_register (grub_raid_t raid)
|
|||
return 0;
|
||||
|
||||
if ((disk->total_sectors != GRUB_ULONG_MAX) &&
|
||||
(! grub_raid_list->detect (disk, &array)) &&
|
||||
(! insert_array (disk, &array, grub_raid_list->name)))
|
||||
(! grub_raid_list->detect (disk, &array, &start_sector)) &&
|
||||
(! insert_array (disk, &array, start_sector, grub_raid_list->name)))
|
||||
return 0;
|
||||
|
||||
/* This error usually means it's not raid, no need to display
|
||||
|
|
|
@ -402,7 +402,7 @@ grub_scsi_open (const char *name, grub_disk_t disk)
|
|||
if (p->open (bus, scsi))
|
||||
continue;
|
||||
|
||||
disk->id = grub_make_scsi_id (scsi->dev->id, bus, lun);
|
||||
disk->id = grub_make_scsi_id (p->id, bus, lun);
|
||||
disk->data = scsi;
|
||||
scsi->dev = p;
|
||||
scsi->lun = lun;
|
||||
|
|
|
@ -52,20 +52,19 @@ struct grub_usbms_dev
|
|||
|
||||
int luns;
|
||||
|
||||
int config;
|
||||
int interface;
|
||||
struct grub_usb_desc_endp *in;
|
||||
struct grub_usb_desc_endp *out;
|
||||
|
||||
int in_maxsz;
|
||||
int out_maxsz;
|
||||
|
||||
struct grub_usbms_dev *next;
|
||||
};
|
||||
typedef struct grub_usbms_dev *grub_usbms_dev_t;
|
||||
|
||||
static grub_usbms_dev_t grub_usbms_dev_list;
|
||||
|
||||
static int devcnt;
|
||||
/* FIXME: remove limit. */
|
||||
#define MAX_USBMS_DEVICES 128
|
||||
static grub_usbms_dev_t grub_usbms_devices[MAX_USBMS_DEVICES];
|
||||
|
||||
static grub_err_t
|
||||
grub_usbms_reset (grub_usb_device_t dev, int interface)
|
||||
|
@ -74,149 +73,133 @@ grub_usbms_reset (grub_usb_device_t dev, int interface)
|
|||
}
|
||||
|
||||
static void
|
||||
grub_usbms_finddevs (void)
|
||||
grub_usbms_detach (grub_usb_device_t usbdev, int config, int interface)
|
||||
{
|
||||
auto int usb_iterate (grub_usb_device_t dev);
|
||||
unsigned i;
|
||||
for (i = 0; i < ARRAY_SIZE (grub_usbms_devices); i++)
|
||||
if (grub_usbms_devices[i] && grub_usbms_devices[i]->dev == usbdev
|
||||
&& grub_usbms_devices[i]->interface == interface
|
||||
&& grub_usbms_devices[i]->config == config)
|
||||
{
|
||||
grub_free (grub_usbms_devices[i]);
|
||||
grub_usbms_devices[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int usb_iterate (grub_usb_device_t usbdev)
|
||||
static int
|
||||
grub_usbms_attach (grub_usb_device_t usbdev, int configno, int interfno)
|
||||
{
|
||||
struct grub_usb_desc_if *interf
|
||||
= usbdev->config[configno].interf[interfno].descif;
|
||||
int j;
|
||||
grub_uint8_t luns = 0;
|
||||
unsigned curnum;
|
||||
grub_usb_err_t err;
|
||||
|
||||
for (curnum = 0; curnum < ARRAY_SIZE (grub_usbms_devices); curnum++)
|
||||
if (!grub_usbms_devices[curnum])
|
||||
break;
|
||||
|
||||
if (curnum == ARRAY_SIZE (grub_usbms_devices))
|
||||
return 0;
|
||||
|
||||
interf = usbdev->config[configno].interf[interfno].descif;
|
||||
|
||||
if ((interf->subclass != GRUB_USBMS_SUBCLASS_BULK
|
||||
/* Experimental support of RBC, MMC-2, UFI, SFF-8070i devices */
|
||||
&& interf->subclass != GRUB_USBMS_SUBCLASS_RBC
|
||||
&& interf->subclass != GRUB_USBMS_SUBCLASS_MMC2
|
||||
&& interf->subclass != GRUB_USBMS_SUBCLASS_UFI
|
||||
&& interf->subclass != GRUB_USBMS_SUBCLASS_SFF8070 )
|
||||
|| interf->protocol != GRUB_USBMS_PROTOCOL_BULK)
|
||||
return 0;
|
||||
|
||||
grub_usbms_devices[curnum] = grub_zalloc (sizeof (struct grub_usbms_dev));
|
||||
if (! grub_usbms_devices[curnum])
|
||||
return 0;
|
||||
|
||||
grub_usbms_devices[curnum]->dev = usbdev;
|
||||
grub_usbms_devices[curnum]->interface = interfno;
|
||||
|
||||
grub_dprintf ("usbms", "alive\n");
|
||||
|
||||
/* Iterate over all endpoints of this interface, at least a
|
||||
IN and OUT bulk endpoint are required. */
|
||||
for (j = 0; j < interf->endpointcnt; j++)
|
||||
{
|
||||
grub_usb_err_t err;
|
||||
struct grub_usb_desc_device *descdev = &usbdev->descdev;
|
||||
int i;
|
||||
struct grub_usb_desc_endp *endp;
|
||||
endp = &usbdev->config[0].interf[interfno].descendp[j];
|
||||
|
||||
if (descdev->class != 0 || descdev->subclass || descdev->protocol != 0
|
||||
|| descdev->configcnt == 0)
|
||||
return 0;
|
||||
|
||||
/* XXX: Just check configuration 0 for now. */
|
||||
for (i = 0; i < usbdev->config[0].descconf->numif; i++)
|
||||
if ((endp->endp_addr & 128) && (endp->attrib & 3) == 2)
|
||||
{
|
||||
struct grub_usbms_dev *usbms;
|
||||
struct grub_usb_desc_if *interf;
|
||||
int j;
|
||||
grub_uint8_t luns = 0;
|
||||
|
||||
grub_dprintf ("usbms", "alive\n");
|
||||
|
||||
interf = usbdev->config[0].interf[i].descif;
|
||||
|
||||
/* If this is not a USB Mass Storage device with a supported
|
||||
protocol, just skip it. */
|
||||
grub_dprintf ("usbms", "iterate: interf=%d, class=%d, subclass=%d, protocol=%d\n",
|
||||
i, interf->class, interf->subclass, interf->protocol);
|
||||
|
||||
if (interf->class != GRUB_USB_CLASS_MASS_STORAGE
|
||||
|| ( interf->subclass != GRUB_USBMS_SUBCLASS_BULK &&
|
||||
/* Experimental support of RBC, MMC-2, UFI, SFF-8070i devices */
|
||||
interf->subclass != GRUB_USBMS_SUBCLASS_RBC &&
|
||||
interf->subclass != GRUB_USBMS_SUBCLASS_MMC2 &&
|
||||
interf->subclass != GRUB_USBMS_SUBCLASS_UFI &&
|
||||
interf->subclass != GRUB_USBMS_SUBCLASS_SFF8070 )
|
||||
|| interf->protocol != GRUB_USBMS_PROTOCOL_BULK)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
grub_dprintf ("usbms", "alive\n");
|
||||
|
||||
devcnt++;
|
||||
usbms = grub_zalloc (sizeof (struct grub_usbms_dev));
|
||||
if (! usbms)
|
||||
return 1;
|
||||
|
||||
usbms->dev = usbdev;
|
||||
usbms->interface = i;
|
||||
|
||||
grub_dprintf ("usbms", "alive\n");
|
||||
|
||||
/* Iterate over all endpoints of this interface, at least a
|
||||
IN and OUT bulk endpoint are required. */
|
||||
for (j = 0; j < interf->endpointcnt; j++)
|
||||
{
|
||||
struct grub_usb_desc_endp *endp;
|
||||
endp = &usbdev->config[0].interf[i].descendp[j];
|
||||
|
||||
if ((endp->endp_addr & 128) && (endp->attrib & 3) == 2)
|
||||
{
|
||||
/* Bulk IN endpoint. */
|
||||
usbms->in = endp;
|
||||
/* Clear Halt is not possible yet! */
|
||||
/* grub_usb_clear_halt (usbdev, endp->endp_addr); */
|
||||
usbms->in_maxsz = endp->maxpacket;
|
||||
}
|
||||
else if (!(endp->endp_addr & 128) && (endp->attrib & 3) == 2)
|
||||
{
|
||||
/* Bulk OUT endpoint. */
|
||||
usbms->out = endp;
|
||||
/* Clear Halt is not possible yet! */
|
||||
/* grub_usb_clear_halt (usbdev, endp->endp_addr); */
|
||||
usbms->out_maxsz = endp->maxpacket;
|
||||
}
|
||||
}
|
||||
|
||||
if (!usbms->in || !usbms->out)
|
||||
{
|
||||
grub_free (usbms);
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_dprintf ("usbms", "alive\n");
|
||||
|
||||
/* XXX: Activate the first configuration. */
|
||||
grub_usb_set_configuration (usbdev, 1);
|
||||
|
||||
/* Query the amount of LUNs. */
|
||||
err = grub_usb_control_msg (usbdev, 0xA1, 254,
|
||||
0, i, 1, (char *) &luns);
|
||||
|
||||
if (err)
|
||||
{
|
||||
/* In case of a stall, clear the stall. */
|
||||
if (err == GRUB_USB_ERR_STALL)
|
||||
{
|
||||
grub_usb_clear_halt (usbdev, usbms->in->endp_addr);
|
||||
grub_usb_clear_halt (usbdev, usbms->out->endp_addr);
|
||||
}
|
||||
/* Just set the amount of LUNs to one. */
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
usbms->luns = 1;
|
||||
}
|
||||
else
|
||||
/* luns = 0 means one LUN with ID 0 present ! */
|
||||
/* We get from device not number of LUNs but highest
|
||||
* LUN number. LUNs are numbered from 0,
|
||||
* i.e. number of LUNs is luns+1 ! */
|
||||
usbms->luns = luns + 1;
|
||||
|
||||
grub_dprintf ("usbms", "alive\n");
|
||||
|
||||
usbms->next = grub_usbms_dev_list;
|
||||
grub_usbms_dev_list = usbms;
|
||||
|
||||
#if 0 /* All this part should be probably deleted.
|
||||
* This make trouble on some devices if they are not in
|
||||
* Phase Error state - and there they should be not in such state...
|
||||
* Bulk only mass storage reset procedure should be used only
|
||||
* on place and in time when it is really necessary. */
|
||||
/* Reset recovery procedure */
|
||||
/* Bulk-Only Mass Storage Reset, after the reset commands
|
||||
will be accepted. */
|
||||
grub_usbms_reset (usbdev, i);
|
||||
grub_usb_clear_halt (usbdev, usbms->in->endp_addr);
|
||||
grub_usb_clear_halt (usbdev, usbms->out->endp_addr);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
/* Bulk IN endpoint. */
|
||||
grub_usbms_devices[curnum]->in = endp;
|
||||
/* Clear Halt is not possible yet! */
|
||||
/* grub_usb_clear_halt (usbdev, endp->endp_addr); */
|
||||
grub_usbms_devices[curnum]->in_maxsz = endp->maxpacket;
|
||||
}
|
||||
else if (!(endp->endp_addr & 128) && (endp->attrib & 3) == 2)
|
||||
{
|
||||
/* Bulk OUT endpoint. */
|
||||
grub_usbms_devices[curnum]->out = endp;
|
||||
/* Clear Halt is not possible yet! */
|
||||
/* grub_usb_clear_halt (usbdev, endp->endp_addr); */
|
||||
grub_usbms_devices[curnum]->out_maxsz = endp->maxpacket;
|
||||
}
|
||||
}
|
||||
|
||||
grub_dprintf ("usbms", "alive\n");
|
||||
if (!grub_usbms_devices[curnum]->in || !grub_usbms_devices[curnum]->out)
|
||||
{
|
||||
grub_free (grub_usbms_devices[curnum]);
|
||||
grub_usbms_devices[curnum] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_dprintf ("usbms", "alive\n");
|
||||
|
||||
grub_usb_iterate (usb_iterate);
|
||||
/* XXX: Activate the first configuration. */
|
||||
grub_usb_set_configuration (usbdev, 1);
|
||||
|
||||
/* Query the amount of LUNs. */
|
||||
err = grub_usb_control_msg (usbdev, 0xA1, 254, 0, interfno, 1, (char *) &luns);
|
||||
|
||||
if (err)
|
||||
{
|
||||
/* In case of a stall, clear the stall. */
|
||||
if (err == GRUB_USB_ERR_STALL)
|
||||
{
|
||||
grub_usb_clear_halt (usbdev, grub_usbms_devices[curnum]->in->endp_addr);
|
||||
grub_usb_clear_halt (usbdev, grub_usbms_devices[curnum]->out->endp_addr);
|
||||
}
|
||||
/* Just set the amount of LUNs to one. */
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
grub_usbms_devices[curnum]->luns = 1;
|
||||
}
|
||||
else
|
||||
/* luns = 0 means one LUN with ID 0 present ! */
|
||||
/* We get from device not number of LUNs but highest
|
||||
* LUN number. LUNs are numbered from 0,
|
||||
* i.e. number of LUNs is luns+1 ! */
|
||||
grub_usbms_devices[curnum]->luns = luns + 1;
|
||||
|
||||
grub_dprintf ("usbms", "alive\n");
|
||||
|
||||
usbdev->config[configno].interf[interfno].detach_hook = grub_usbms_detach;
|
||||
|
||||
#if 0 /* All this part should be probably deleted.
|
||||
* This make trouble on some devices if they are not in
|
||||
* Phase Error state - and there they should be not in such state...
|
||||
* Bulk only mass storage reset procedure should be used only
|
||||
* on place and in time when it is really necessary. */
|
||||
/* Reset recovery procedure */
|
||||
/* Bulk-Only Mass Storage Reset, after the reset commands
|
||||
will be accepted. */
|
||||
grub_usbms_reset (usbdev, i);
|
||||
grub_usb_clear_halt (usbdev, usbms->in->endp_addr);
|
||||
grub_usb_clear_halt (usbdev, usbms->out->endp_addr);
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -224,15 +207,16 @@ grub_usbms_finddevs (void)
|
|||
static int
|
||||
grub_usbms_iterate (int (*hook) (int bus, int luns))
|
||||
{
|
||||
grub_usbms_dev_t p;
|
||||
int cnt = 0;
|
||||
unsigned i;
|
||||
|
||||
for (p = grub_usbms_dev_list; p; p = p->next)
|
||||
{
|
||||
if (hook (cnt, p->luns))
|
||||
return 1;
|
||||
cnt++;
|
||||
}
|
||||
grub_usb_poll_devices ();
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE (grub_usbms_devices); i++)
|
||||
if (grub_usbms_devices[i])
|
||||
{
|
||||
if (hook (i, grub_usbms_devices[i]->luns))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -248,7 +232,6 @@ grub_usbms_transfer (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
|
|||
grub_usb_err_t err = GRUB_USB_ERR_NONE;
|
||||
grub_usb_err_t errCSW = GRUB_USB_ERR_NONE;
|
||||
int retrycnt = 3 + 1;
|
||||
grub_size_t i;
|
||||
|
||||
retry:
|
||||
retrycnt--;
|
||||
|
@ -304,8 +287,11 @@ grub_usbms_transfer (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
|
|||
/* Debug print of received data. */
|
||||
grub_dprintf ("usb", "buf:\n");
|
||||
if (size <= 64)
|
||||
for (i=0; i<size; i++)
|
||||
grub_dprintf ("usb", "0x%02" PRIxGRUB_SIZE ": 0x%02x\n", i, buf[i]);
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < size; i++)
|
||||
grub_dprintf ("usb", "0x%02x: 0x%02x\n", i, buf[i]);
|
||||
}
|
||||
else
|
||||
grub_dprintf ("usb", "Too much data for debug print...\n");
|
||||
}
|
||||
|
@ -313,7 +299,11 @@ grub_usbms_transfer (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
|
|||
{
|
||||
err = grub_usb_bulk_write (dev->dev, dev->out->endp_addr, size, buf);
|
||||
grub_dprintf ("usb", "write: %d %d\n", err, GRUB_USB_ERR_STALL);
|
||||
grub_dprintf ("usb", "buf:\n");
|
||||
grub_dprintf ("usb", "First 16 bytes of sent data:\n %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
|
||||
buf[ 0], buf[ 1], buf[ 2], buf[ 3],
|
||||
buf[ 4], buf[ 5], buf[ 6], buf[ 7],
|
||||
buf[ 8], buf[ 9], buf[10], buf[11],
|
||||
buf[12], buf[13], buf[14], buf[15]);
|
||||
if (err)
|
||||
{
|
||||
if (err == GRUB_USB_ERR_STALL)
|
||||
|
@ -322,8 +312,11 @@ grub_usbms_transfer (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
|
|||
}
|
||||
/* Debug print of sent data. */
|
||||
if (size <= 256)
|
||||
for (i=0; i<size; i++)
|
||||
grub_dprintf ("usb", "0x%02" PRIxGRUB_SIZE ": 0x%02x\n", i, buf[i]);
|
||||
{
|
||||
unsigned i;
|
||||
for (i=0; i<size; i++)
|
||||
grub_dprintf ("usb", "0x%02x: 0x%02x\n", i, buf[i]);
|
||||
}
|
||||
else
|
||||
grub_dprintf ("usb", "Too much data for debug print...\n");
|
||||
}
|
||||
|
@ -393,24 +386,16 @@ grub_usbms_write (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
|
|||
static grub_err_t
|
||||
grub_usbms_open (int devnum, struct grub_scsi *scsi)
|
||||
{
|
||||
grub_usbms_dev_t p;
|
||||
int i = 0;
|
||||
grub_usb_poll_devices ();
|
||||
|
||||
for (p = grub_usbms_dev_list; p; p = p->next)
|
||||
{
|
||||
/* Check if this is the devnumth device. */
|
||||
if (devnum == i)
|
||||
{
|
||||
scsi->data = p;
|
||||
scsi->luns = p->luns;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
if (!grub_usbms_devices[devnum])
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
|
||||
"unknown USB Mass Storage device");
|
||||
|
||||
i++;
|
||||
}
|
||||
scsi->data = grub_usbms_devices[devnum];
|
||||
scsi->luns = grub_usbms_devices[devnum]->luns;
|
||||
|
||||
return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
|
||||
"not a USB Mass Storage device");
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static struct grub_scsi_dev grub_usbms_dev =
|
||||
|
@ -423,13 +408,28 @@ static struct grub_scsi_dev grub_usbms_dev =
|
|||
.write = grub_usbms_write
|
||||
};
|
||||
|
||||
struct grub_usb_attach_desc attach_hook =
|
||||
{
|
||||
.class = GRUB_USB_CLASS_MASS_STORAGE,
|
||||
.hook = grub_usbms_attach
|
||||
};
|
||||
|
||||
GRUB_MOD_INIT(usbms)
|
||||
{
|
||||
grub_usbms_finddevs ();
|
||||
grub_usb_register_attach_hook_class (&attach_hook);
|
||||
grub_scsi_dev_register (&grub_usbms_dev);
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(usbms)
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < ARRAY_SIZE (grub_usbms_devices); i++)
|
||||
{
|
||||
grub_usbms_devices[i]->dev->config[grub_usbms_devices[i]->config]
|
||||
.interf[grub_usbms_devices[i]->interface].detach_hook = 0;
|
||||
grub_usbms_devices[i]->dev->config[grub_usbms_devices[i]->config]
|
||||
.interf[grub_usbms_devices[i]->interface].attached = 0;
|
||||
}
|
||||
grub_usb_unregister_attach_hook_class (&attach_hook);
|
||||
grub_scsi_dev_unregister (&grub_usbms_dev);
|
||||
}
|
||||
|
|
|
@ -52,9 +52,9 @@
|
|||
/* nilfs 1st super block posission from beginning of the partition
|
||||
in 512 block size */
|
||||
#define NILFS_1ST_SUPER_BLOCK 2
|
||||
/* nilfs 2nd super block posission from end of the partition
|
||||
/* nilfs 2nd super block posission from beginning of the partition
|
||||
in 512 block size */
|
||||
#define NILFS_2ND_SUPER_BLOCK 8
|
||||
#define NILFS_2ND_SUPER_BLOCK(devsize) (((devsize >> 3) - 1) << 3)
|
||||
|
||||
struct grub_nilfs2_inode
|
||||
{
|
||||
|
@ -729,7 +729,7 @@ grub_nilfs2_load_sb (struct grub_nilfs2_data *data)
|
|||
if (partition_size != GRUB_DISK_SIZE_UNKNOWN)
|
||||
{
|
||||
/* Read second super block. */
|
||||
grub_disk_read (disk, partition_size - NILFS_2ND_SUPER_BLOCK, 0,
|
||||
grub_disk_read (disk, NILFS_2ND_SUPER_BLOCK (partition_size), 0,
|
||||
sizeof (struct grub_nilfs2_super_block), &sb2);
|
||||
/* Make sure if 2nd super block is valid. */
|
||||
valid[1] = grub_nilfs2_valid_sb (&sb2);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* getroot.c - Get root device */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2006,2007,2008,2009 Free Software Foundation, Inc.
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -20,14 +20,17 @@
|
|||
#include <config.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <error.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <grub/util/misc.h>
|
||||
|
||||
#ifdef __GNU__
|
||||
#include <hurd.h>
|
||||
|
@ -36,6 +39,16 @@
|
|||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
# include <sys/types.h>
|
||||
# include <sys/wait.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
|
||||
# include <grub/util/libzfs.h>
|
||||
# include <grub/util/libnvpair.h>
|
||||
#endif
|
||||
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/emu/misc.h>
|
||||
|
@ -161,6 +174,58 @@ find_root_device_from_mountinfo (const char *dir)
|
|||
|
||||
#endif /* __linux__ */
|
||||
|
||||
#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
|
||||
static char *
|
||||
find_root_device_from_libzfs (const char *dir)
|
||||
{
|
||||
char *device;
|
||||
char *poolname;
|
||||
char *poolfs;
|
||||
|
||||
grub_find_zpool_from_dir (dir, &poolname, &poolfs);
|
||||
if (! poolname)
|
||||
return NULL;
|
||||
|
||||
{
|
||||
zpool_handle_t *zpool;
|
||||
libzfs_handle_t *libzfs;
|
||||
nvlist_t *nvlist;
|
||||
nvlist_t **nvlist_array;
|
||||
unsigned int nvlist_count;
|
||||
|
||||
libzfs = grub_get_libzfs_handle ();
|
||||
if (! libzfs)
|
||||
return NULL;
|
||||
|
||||
zpool = zpool_open (libzfs, poolname);
|
||||
nvlist = zpool_get_config (zpool, NULL);
|
||||
|
||||
if (nvlist_lookup_nvlist (nvlist, "vdev_tree", &nvlist) != 0)
|
||||
error (1, errno, "nvlist_lookup_nvlist (\"vdev_tree\")");
|
||||
|
||||
if (nvlist_lookup_nvlist_array (nvlist, "children", &nvlist_array, &nvlist_count) != 0)
|
||||
error (1, errno, "nvlist_lookup_nvlist_array (\"children\")");
|
||||
|
||||
do
|
||||
{
|
||||
assert (nvlist_count > 0);
|
||||
} while (nvlist_lookup_nvlist_array (nvlist_array[0], "children",
|
||||
&nvlist_array, &nvlist_count) == 0);
|
||||
|
||||
if (nvlist_lookup_string (nvlist_array[0], "path", &device) != 0)
|
||||
error (1, errno, "nvlist_lookup_string (\"path\")");
|
||||
|
||||
zpool_close (zpool);
|
||||
}
|
||||
|
||||
free (poolname);
|
||||
if (poolfs)
|
||||
free (poolfs);
|
||||
|
||||
return device;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __MINGW32__
|
||||
|
||||
static char *
|
||||
|
@ -453,6 +518,12 @@ grub_guess_root_device (const char *dir)
|
|||
return os_dev;
|
||||
#endif /* __linux__ */
|
||||
|
||||
#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
|
||||
os_dev = find_root_device_from_libzfs (dir);
|
||||
if (os_dev)
|
||||
return os_dev;
|
||||
#endif
|
||||
|
||||
if (stat (dir, &st) < 0)
|
||||
grub_util_error ("cannot stat `%s'", dir);
|
||||
|
||||
|
@ -516,10 +587,89 @@ grub_util_get_dev_abstraction (const char *os_dev __attribute__((unused)))
|
|||
return GRUB_DEV_ABSTRACTION_NONE;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
static char *
|
||||
get_mdadm_name (const char *os_dev)
|
||||
{
|
||||
int mdadm_pipe[2];
|
||||
pid_t mdadm_pid;
|
||||
char *name = NULL;
|
||||
|
||||
if (pipe (mdadm_pipe) < 0)
|
||||
{
|
||||
grub_util_warn ("Unable to create pipe for mdadm: %s", strerror (errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mdadm_pid = fork ();
|
||||
if (mdadm_pid < 0)
|
||||
grub_util_warn ("Unable to fork mdadm: %s", strerror (errno));
|
||||
else if (mdadm_pid == 0)
|
||||
{
|
||||
/* Child. */
|
||||
char *argv[5];
|
||||
|
||||
close (mdadm_pipe[0]);
|
||||
dup2 (mdadm_pipe[1], STDOUT_FILENO);
|
||||
close (mdadm_pipe[1]);
|
||||
|
||||
/* execvp has inconvenient types, hence the casts. None of these
|
||||
strings will actually be modified. */
|
||||
argv[0] = (char *) "mdadm";
|
||||
argv[1] = (char *) "--detail";
|
||||
argv[2] = (char *) "--export";
|
||||
argv[3] = (char *) os_dev;
|
||||
argv[4] = NULL;
|
||||
execvp ("mdadm", argv);
|
||||
exit (127);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Parent. Read mdadm's output. */
|
||||
FILE *mdadm;
|
||||
char *buf = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
close (mdadm_pipe[1]);
|
||||
mdadm = fdopen (mdadm_pipe[0], "r");
|
||||
if (! mdadm)
|
||||
{
|
||||
grub_util_warn ("Unable to open stream from mdadm: %s",
|
||||
strerror (errno));
|
||||
goto out;
|
||||
}
|
||||
|
||||
while (getline (&buf, &len, mdadm) > 0)
|
||||
{
|
||||
if (strncmp (buf, "MD_NAME=", sizeof ("MD_NAME=") - 1) == 0)
|
||||
{
|
||||
char *name_start, *colon;
|
||||
size_t name_len;
|
||||
|
||||
free (name);
|
||||
name_start = buf + sizeof ("MD_NAME=") - 1;
|
||||
/* Strip off the homehost if present. */
|
||||
colon = strchr (name_start, ':');
|
||||
name = strdup (colon ? colon + 1 : name_start);
|
||||
name_len = strlen (name);
|
||||
if (name[name_len - 1] == '\n')
|
||||
name[name_len - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
close (mdadm_pipe[0]);
|
||||
waitpid (mdadm_pid, NULL, 0);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
#endif /* __linux__ */
|
||||
|
||||
char *
|
||||
grub_util_get_grub_dev (const char *os_dev)
|
||||
{
|
||||
char *grub_dev;
|
||||
char *grub_dev = NULL;
|
||||
|
||||
switch (grub_util_get_dev_abstraction (os_dev))
|
||||
{
|
||||
|
@ -600,9 +750,36 @@ grub_util_get_grub_dev (const char *os_dev)
|
|||
grub_dev = xasprintf ("md%s", p);
|
||||
free (p);
|
||||
}
|
||||
else if (os_dev[7] == '/')
|
||||
{
|
||||
/* mdraid 1.x with a free name. */
|
||||
char *p , *q;
|
||||
|
||||
p = strdup (os_dev + sizeof ("/dev/md/") - 1);
|
||||
|
||||
q = strchr (p, 'p');
|
||||
if (q)
|
||||
*q = ',';
|
||||
|
||||
grub_dev = xasprintf ("md/%s", p);
|
||||
free (p);
|
||||
}
|
||||
else
|
||||
grub_util_error ("unknown kind of RAID device `%s'", os_dev);
|
||||
|
||||
#ifdef __linux__
|
||||
{
|
||||
char *mdadm_name = get_mdadm_name (os_dev);
|
||||
|
||||
if (mdadm_name)
|
||||
{
|
||||
free (grub_dev);
|
||||
grub_dev = xasprintf ("md/%s", mdadm_name);
|
||||
free (mdadm_name);
|
||||
}
|
||||
}
|
||||
#endif /* __linux__ */
|
||||
|
||||
break;
|
||||
|
||||
default: /* GRUB_DEV_ABSTRACTION_NONE */
|
||||
|
|
|
@ -1,6 +1,25 @@
|
|||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002,2003,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <error.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
@ -26,6 +45,22 @@
|
|||
# include <libdevmapper.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBZFS
|
||||
# include <grub/util/libzfs.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBNVPAIR
|
||||
# include <grub/util/libnvpair.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_MOUNT_H
|
||||
# include <sys/mount.h>
|
||||
#endif
|
||||
|
||||
int verbosity;
|
||||
|
||||
void
|
||||
|
@ -218,23 +253,87 @@ get_win32_path (const char *path)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBZFS
|
||||
static libzfs_handle_t *__libzfs_handle;
|
||||
|
||||
static void
|
||||
fini_libzfs (void)
|
||||
{
|
||||
libzfs_fini (__libzfs_handle);
|
||||
}
|
||||
|
||||
libzfs_handle_t *
|
||||
grub_get_libzfs_handle (void)
|
||||
{
|
||||
if (! __libzfs_handle)
|
||||
{
|
||||
__libzfs_handle = libzfs_init ();
|
||||
|
||||
if (__libzfs_handle)
|
||||
atexit (fini_libzfs);
|
||||
}
|
||||
|
||||
return __libzfs_handle;
|
||||
}
|
||||
#endif /* HAVE_LIBZFS */
|
||||
|
||||
#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
|
||||
/* ZFS has similar problems to those of btrfs (see above). */
|
||||
void
|
||||
grub_find_zpool_from_dir (const char *dir, char **poolname, char **poolfs)
|
||||
{
|
||||
struct statfs mnt;
|
||||
char *slash;
|
||||
|
||||
*poolname = *poolfs = NULL;
|
||||
|
||||
if (statfs (dir, &mnt) != 0)
|
||||
return;
|
||||
|
||||
if (strcmp (mnt.f_fstypename, "zfs") != 0)
|
||||
return;
|
||||
|
||||
*poolname = xstrdup (mnt.f_mntfromname);
|
||||
|
||||
slash = strchr (*poolname, '/');
|
||||
if (slash)
|
||||
{
|
||||
*slash = '\0';
|
||||
*poolfs = xstrdup (slash + 1);
|
||||
}
|
||||
else
|
||||
*poolfs = xstrdup ("");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This function never prints trailing slashes (so that its output
|
||||
can be appended a slash unconditionally). */
|
||||
char *
|
||||
grub_make_system_path_relative_to_its_root (const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
char *p, *buf, *buf2, *buf3;
|
||||
char *p, *buf, *buf2, *buf3, *ret;
|
||||
uintptr_t offset = 0;
|
||||
dev_t num;
|
||||
size_t len;
|
||||
|
||||
#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
|
||||
char *poolfs = NULL;
|
||||
#endif
|
||||
|
||||
/* canonicalize. */
|
||||
p = canonicalize_file_name (path);
|
||||
|
||||
if (p == NULL)
|
||||
grub_util_error ("failed to get canonical path of %s", path);
|
||||
|
||||
#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
|
||||
/* For ZFS sub-pool filesystems, could be extended to others (btrfs?). */
|
||||
{
|
||||
char *dummy;
|
||||
grub_find_zpool_from_dir (p, &dummy, &poolfs);
|
||||
}
|
||||
#endif
|
||||
|
||||
len = strlen (p) + 1;
|
||||
buf = xstrdup (p);
|
||||
free (p);
|
||||
|
@ -313,7 +412,17 @@ grub_make_system_path_relative_to_its_root (const char *path)
|
|||
len--;
|
||||
}
|
||||
|
||||
return buf3;
|
||||
#if defined(HAVE_LIBZFS) && defined(HAVE_LIBNVPAIR)
|
||||
if (poolfs)
|
||||
{
|
||||
ret = xasprintf ("/%s/@%s", poolfs, buf3);
|
||||
free (buf3);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
ret = buf3;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef HAVE_DEVICE_MAPPER
|
||||
|
|
|
@ -69,10 +69,7 @@ load_palette (void)
|
|||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
grub_outb (i, GRUB_VGA_IO_ARX);
|
||||
grub_outb (i, GRUB_VGA_IO_ARX);
|
||||
}
|
||||
grub_vga_write_arx (i, i);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE (colors); i++)
|
||||
grub_vga_palette_write (i, colors[i].r, colors[i].g, colors[i].b);
|
||||
|
@ -90,7 +87,7 @@ grub_qemu_init_cirrus (void)
|
|||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
|
||||
class = grub_pci_read (addr);
|
||||
|
||||
if (((class >> 16) & 0xffff) != 0x0300)
|
||||
if (((class >> 16) & 0xffff) != GRUB_PCI_CLASS_SUBCLASS_VGA)
|
||||
return 0;
|
||||
|
||||
/* FIXME: chooose addresses dynamically. */
|
||||
|
@ -110,7 +107,7 @@ grub_qemu_init_cirrus (void)
|
|||
|
||||
grub_pci_iterate (find_card);
|
||||
|
||||
grub_outb (1, 0x3c2);
|
||||
grub_outb (GRUB_VGA_IO_MISC_COLOR, GRUB_VGA_IO_MISC_WRITE);
|
||||
|
||||
load_font ();
|
||||
|
||||
|
@ -124,11 +121,11 @@ grub_qemu_init_cirrus (void)
|
|||
GRUB_VGA_SR_MAP_MASK_REGISTER);
|
||||
|
||||
grub_vga_cr_write (15, GRUB_VGA_CR_CELL_HEIGHT);
|
||||
grub_vga_cr_write (79, GRUB_VGA_CR_WIDTH);
|
||||
grub_vga_cr_write (79, GRUB_VGA_CR_HORIZ_END);
|
||||
grub_vga_cr_write (40, GRUB_VGA_CR_PITCH);
|
||||
|
||||
int vert = 25 * 16;
|
||||
grub_vga_cr_write (vert & 0xff, GRUB_VGA_CR_HEIGHT);
|
||||
grub_vga_cr_write (vert & 0xff, GRUB_VGA_CR_VDISPLAY_END);
|
||||
grub_vga_cr_write (((vert >> GRUB_VGA_CR_OVERFLOW_HEIGHT1_SHIFT)
|
||||
& GRUB_VGA_CR_OVERFLOW_HEIGHT1_MASK)
|
||||
| ((vert >> GRUB_VGA_CR_OVERFLOW_HEIGHT2_SHIFT)
|
||||
|
@ -137,10 +134,8 @@ grub_qemu_init_cirrus (void)
|
|||
|
||||
load_palette ();
|
||||
|
||||
grub_outb (0x10, 0x3c0);
|
||||
grub_outb (0, 0x3c1);
|
||||
grub_outb (0x14, 0x3c0);
|
||||
grub_outb (0, 0x3c1);
|
||||
grub_vga_write_arx (GRUB_VGA_ARX_MODE_TEXT, GRUB_VGA_ARX_MODE);
|
||||
grub_vga_write_arx (0, GRUB_VGA_ARX_COLOR_SELECT);
|
||||
|
||||
grub_vga_sr_write (GRUB_VGA_SR_CLOCKING_MODE_8_DOT_CLOCK,
|
||||
GRUB_VGA_SR_CLOCKING_MODE);
|
||||
|
|
|
@ -518,12 +518,39 @@ grub_strndup (const char *s, grub_size_t n)
|
|||
}
|
||||
|
||||
void *
|
||||
grub_memset (void *s, int c, grub_size_t n)
|
||||
grub_memset (void *s, int c, grub_size_t len)
|
||||
{
|
||||
unsigned char *p = (unsigned char *) s;
|
||||
void *p = s;
|
||||
grub_uint8_t pattern8 = c;
|
||||
|
||||
while (n--)
|
||||
*p++ = (unsigned char) c;
|
||||
if (len >= 3 * sizeof (unsigned long))
|
||||
{
|
||||
unsigned long patternl = 0;
|
||||
grub_size_t i;
|
||||
|
||||
for (i = 0; i < sizeof (unsigned long); i++)
|
||||
patternl |= ((unsigned long) pattern8) << (8 * i);
|
||||
|
||||
while (len > 0 && (((grub_addr_t) p) & (sizeof (unsigned long) - 1)))
|
||||
{
|
||||
*(grub_uint8_t *) p = pattern8;
|
||||
p = (grub_uint8_t *) p + 1;
|
||||
len--;
|
||||
}
|
||||
while (len >= sizeof (unsigned long))
|
||||
{
|
||||
*(unsigned long *) p = patternl;
|
||||
p = (unsigned long *) p + 1;
|
||||
len -= sizeof (unsigned long);
|
||||
}
|
||||
}
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
*(grub_uint8_t *) p = pattern8;
|
||||
p = (grub_uint8_t *) p + 1;
|
||||
len--;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
|
@ -21,8 +21,43 @@
|
|||
#include <grub/partition.h>
|
||||
#include <grub/disk.h>
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
#include <grub/util/misc.h>
|
||||
#endif
|
||||
|
||||
grub_partition_map_t grub_partition_map_list;
|
||||
|
||||
/*
|
||||
* Checks that disk->partition contains part. This function assumes that the
|
||||
* start of part is relative to the start of disk->partition. Returns 1 if
|
||||
* disk->partition is null.
|
||||
*/
|
||||
static int
|
||||
grub_partition_check_containment (const grub_disk_t disk,
|
||||
const grub_partition_t part)
|
||||
{
|
||||
if (disk->partition == NULL)
|
||||
return 1;
|
||||
|
||||
if (part->start + part->len > disk->partition->len)
|
||||
{
|
||||
char *partname;
|
||||
|
||||
partname = grub_partition_get_name (disk->partition);
|
||||
grub_dprintf ("partition", "sub-partition %s%d of (%s,%s) ends after parent.\n",
|
||||
part->partmap->name, part->number + 1, disk->name, partname);
|
||||
#ifdef GRUB_UTIL
|
||||
grub_util_warn ("Discarding improperly nested partition (%s,%s,%s%d)",
|
||||
disk->name, partname, part->partmap->name, part->number + 1);
|
||||
#endif
|
||||
grub_free (partname);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static grub_partition_t
|
||||
grub_partition_map_probe (const grub_partition_map_t partmap,
|
||||
grub_disk_t disk, int partnum)
|
||||
|
@ -31,20 +66,21 @@ grub_partition_map_probe (const grub_partition_map_t partmap,
|
|||
|
||||
auto int find_func (grub_disk_t d, const grub_partition_t partition);
|
||||
|
||||
int find_func (grub_disk_t d __attribute__ ((unused)),
|
||||
int find_func (grub_disk_t dsk,
|
||||
const grub_partition_t partition)
|
||||
{
|
||||
if (partnum == partition->number)
|
||||
{
|
||||
p = (grub_partition_t) grub_malloc (sizeof (*p));
|
||||
if (! p)
|
||||
return 1;
|
||||
if (partnum != partition->number)
|
||||
return 0;
|
||||
|
||||
grub_memcpy (p, partition, sizeof (*p));
|
||||
return 1;
|
||||
}
|
||||
if (!(grub_partition_check_containment (dsk, partition)))
|
||||
return 0;
|
||||
|
||||
return 0;
|
||||
p = (grub_partition_t) grub_malloc (sizeof (*p));
|
||||
if (! p)
|
||||
return 1;
|
||||
|
||||
grub_memcpy (p, partition, sizeof (*p));
|
||||
return 1;
|
||||
}
|
||||
|
||||
partmap->iterate (disk, find_func);
|
||||
|
@ -138,6 +174,10 @@ grub_partition_iterate (struct grub_disk *disk,
|
|||
const grub_partition_t partition)
|
||||
{
|
||||
struct grub_partition p = *partition;
|
||||
|
||||
if (!(grub_partition_check_containment (dsk, partition)))
|
||||
return 0;
|
||||
|
||||
p.parent = dsk->partition;
|
||||
dsk->partition = 0;
|
||||
if (hook (dsk, &p))
|
||||
|
|
|
@ -144,8 +144,10 @@ grub_arg_show_help (grub_extcmd_t cmd)
|
|||
}
|
||||
}
|
||||
|
||||
/* FIXME: add spacing back. */
|
||||
grub_xputs (_(opt->doc));
|
||||
while (spacing--)
|
||||
grub_xputs (" ");
|
||||
|
||||
grub_printf ("%s\n", _(opt->doc));
|
||||
|
||||
switch (opt->shortarg)
|
||||
{
|
||||
|
|
|
@ -157,11 +157,13 @@ LOCAL(cont1):
|
|||
andl $(~GRUB_MEMORY_CPU_CR0_PAGING_ON), %eax
|
||||
movl %eax, %cr0
|
||||
|
||||
#ifdef __x86_64__
|
||||
/* Disable amd64. */
|
||||
movl $GRUB_MEMORY_CPU_AMD64_MSR, %ecx
|
||||
rdmsr
|
||||
andl $(~GRUB_MEMORY_CPU_AMD64_MSR_ON), %eax
|
||||
wrmsr
|
||||
#endif
|
||||
|
||||
/* Turn off PAE. */
|
||||
movl %cr4, %eax
|
||||
|
|
|
@ -220,7 +220,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
|
|||
if (! elf)
|
||||
goto out;
|
||||
|
||||
if (elf->ehdr.ehdr32.e_type != ET_EXEC)
|
||||
if (elf->ehdr.ehdr32.e_type != ET_EXEC && elf->ehdr.ehdr32.e_type != ET_DYN)
|
||||
{
|
||||
grub_error (GRUB_ERR_UNKNOWN_OS,
|
||||
"this ELF file is not of the right type");
|
||||
|
|
|
@ -425,6 +425,13 @@ library = {
|
|||
cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB)';
|
||||
};
|
||||
|
||||
module = {
|
||||
name = cmostest;
|
||||
source = commands/i386/cmostest.c;
|
||||
enable = i386_pc;
|
||||
enable = i386_coreboot;
|
||||
};
|
||||
|
||||
module = {
|
||||
name = iorw;
|
||||
source = commands/iorw.c;
|
||||
|
@ -1367,6 +1374,7 @@ module = {
|
|||
source = script/execute.c;
|
||||
source = script/function.c;
|
||||
source = script/lexer.c;
|
||||
source = script/argv.c;
|
||||
|
||||
source = unidata.c;
|
||||
nodist = grub_script.tab.c;
|
||||
|
|
|
@ -56,22 +56,23 @@ parse_color_name (grub_uint8_t *ret, char *name)
|
|||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
grub_parse_color_name_pair (grub_uint8_t *ret, const char *name)
|
||||
int
|
||||
grub_parse_color_name_pair (grub_uint8_t *color, const char *name)
|
||||
{
|
||||
int result = 1;
|
||||
grub_uint8_t fg, bg;
|
||||
char *fg_name, *bg_name;
|
||||
|
||||
/* nothing specified by user */
|
||||
if (name == NULL)
|
||||
return;
|
||||
return result;
|
||||
|
||||
fg_name = grub_strdup (name);
|
||||
if (fg_name == NULL)
|
||||
{
|
||||
/* "out of memory" message was printed by grub_strdup() */
|
||||
grub_wait_after_message ();
|
||||
return;
|
||||
return result;
|
||||
}
|
||||
|
||||
bg_name = grub_strchr (fg_name, '/');
|
||||
|
@ -97,10 +98,12 @@ grub_parse_color_name_pair (grub_uint8_t *ret, const char *name)
|
|||
goto free_and_return;
|
||||
}
|
||||
|
||||
*ret = (bg << 4) | fg;
|
||||
*color = (bg << 4) | fg;
|
||||
result = 0;
|
||||
|
||||
free_and_return:
|
||||
grub_free (fg_name);
|
||||
return result;
|
||||
}
|
||||
|
||||
static grub_uint8_t color_normal, color_highlight;
|
||||
|
@ -122,10 +125,10 @@ set_colors (void)
|
|||
|
||||
/* Replace default `normal' colors with the ones specified by user (if any). */
|
||||
char *
|
||||
grub_env_write_color_normal (struct grub_env_var *var __attribute__ ((unused)),
|
||||
const char *val)
|
||||
grub_env_write_color_normal (struct grub_env_var *var, const char *val)
|
||||
{
|
||||
grub_parse_color_name_pair (&color_normal, val);
|
||||
if (grub_parse_color_name_pair (&color_normal, val))
|
||||
return 0;
|
||||
|
||||
set_colors ();
|
||||
|
||||
|
@ -134,10 +137,10 @@ grub_env_write_color_normal (struct grub_env_var *var __attribute__ ((unused)),
|
|||
|
||||
/* Replace default `highlight' colors with the ones specified by user (if any). */
|
||||
char *
|
||||
grub_env_write_color_highlight (struct grub_env_var *var __attribute__ ((unused)),
|
||||
const char *val)
|
||||
grub_env_write_color_highlight (struct grub_env_var *var, const char *val)
|
||||
{
|
||||
grub_parse_color_name_pair (&color_highlight, val);
|
||||
if (grub_parse_color_name_pair (&color_highlight, val))
|
||||
return 0;
|
||||
|
||||
set_colors ();
|
||||
|
||||
|
|
|
@ -678,6 +678,7 @@ static void (*grub_xputs_saved) (const char *str);
|
|||
GRUB_MOD_INIT(normal)
|
||||
{
|
||||
grub_context_init ();
|
||||
grub_script_init ();
|
||||
|
||||
grub_xputs_saved = grub_xputs;
|
||||
grub_xputs = grub_xputs_normal;
|
||||
|
@ -707,11 +708,16 @@ GRUB_MOD_INIT(normal)
|
|||
/* Preserve hooks after context changes. */
|
||||
grub_env_export ("color_normal");
|
||||
grub_env_export ("color_highlight");
|
||||
|
||||
/* Set default color names. */
|
||||
grub_env_set ("color_normal", "white/black");
|
||||
grub_env_set ("color_highlight", "black/white");
|
||||
}
|
||||
|
||||
GRUB_MOD_FINI(normal)
|
||||
{
|
||||
grub_context_fini ();
|
||||
grub_script_fini ();
|
||||
|
||||
grub_xputs = grub_xputs_saved;
|
||||
|
||||
|
|
|
@ -24,6 +24,10 @@
|
|||
#include <grub/misc.h>
|
||||
#include <grub/dl.h>
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
#include <grub/util/misc.h>
|
||||
#endif
|
||||
|
||||
static struct grub_partition_map grub_bsdlabel_partition_map;
|
||||
|
||||
|
||||
|
@ -37,9 +41,6 @@ bsdlabel_partition_map_iterate (grub_disk_t disk,
|
|||
grub_disk_addr_t delta = 0;
|
||||
unsigned pos;
|
||||
|
||||
/* BSDLabel offsets are absolute even when it's embed inside partition. */
|
||||
delta = grub_partition_get_start (disk->partition);
|
||||
|
||||
/* Read the BSD label. */
|
||||
if (grub_disk_read (disk, GRUB_PC_PARTITION_BSD_LABEL_SECTOR,
|
||||
0, sizeof (label), &label))
|
||||
|
@ -49,30 +50,79 @@ bsdlabel_partition_map_iterate (grub_disk_t disk,
|
|||
if (label.magic != grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC))
|
||||
return grub_error (GRUB_ERR_BAD_PART_TABLE, "no signature");
|
||||
|
||||
/* A kludge to determine a base of be.offset. */
|
||||
if (GRUB_PC_PARTITION_BSD_LABEL_WHOLE_DISK_PARTITION
|
||||
< grub_cpu_to_le16 (label.num_partitions))
|
||||
{
|
||||
struct grub_partition_bsd_entry whole_disk_be;
|
||||
|
||||
pos = sizeof (label) + GRUB_PC_PARTITION_BSD_LABEL_SECTOR
|
||||
* GRUB_DISK_SECTOR_SIZE + sizeof (struct grub_partition_bsd_entry)
|
||||
* GRUB_PC_PARTITION_BSD_LABEL_WHOLE_DISK_PARTITION;
|
||||
|
||||
if (grub_disk_read (disk, pos / GRUB_DISK_SECTOR_SIZE,
|
||||
pos % GRUB_DISK_SECTOR_SIZE, sizeof (whole_disk_be),
|
||||
&whole_disk_be))
|
||||
return grub_errno;
|
||||
|
||||
delta = grub_le_to_cpu32 (whole_disk_be.offset);
|
||||
}
|
||||
|
||||
pos = sizeof (label) + GRUB_PC_PARTITION_BSD_LABEL_SECTOR
|
||||
* GRUB_DISK_SECTOR_SIZE;
|
||||
|
||||
for (p.number = 0;
|
||||
p.number < grub_cpu_to_le16 (label.num_partitions);
|
||||
p.number++)
|
||||
p.number++, pos += sizeof (struct grub_partition_bsd_entry))
|
||||
{
|
||||
struct grub_partition_bsd_entry be;
|
||||
|
||||
if (p.number == GRUB_PC_PARTITION_BSD_LABEL_WHOLE_DISK_PARTITION)
|
||||
continue;
|
||||
|
||||
p.offset = pos / GRUB_DISK_SECTOR_SIZE;
|
||||
p.index = pos % GRUB_DISK_SECTOR_SIZE;
|
||||
|
||||
if (grub_disk_read (disk, p.offset, p.index, sizeof (be), &be))
|
||||
return grub_errno;
|
||||
|
||||
p.start = grub_le_to_cpu32 (be.offset) - delta;
|
||||
p.start = grub_le_to_cpu32 (be.offset);
|
||||
p.len = grub_le_to_cpu32 (be.size);
|
||||
p.partmap = &grub_bsdlabel_partition_map;
|
||||
|
||||
if (be.fs_type != GRUB_PC_PARTITION_BSD_TYPE_UNUSED)
|
||||
if (hook (disk, &p))
|
||||
return grub_errno;
|
||||
grub_dprintf ("partition",
|
||||
"partition %d: type 0x%x, start 0x%llx, len 0x%llx\n",
|
||||
p.number, be.fs_type,
|
||||
(unsigned long long) p.start,
|
||||
(unsigned long long) p.len);
|
||||
|
||||
pos += sizeof (struct grub_partition_bsd_entry);
|
||||
if (p.len == 0)
|
||||
continue;
|
||||
|
||||
if (p.start < delta)
|
||||
{
|
||||
#ifdef GRUB_UTIL
|
||||
char *partname;
|
||||
#endif
|
||||
grub_dprintf ("partition",
|
||||
"partition %d: invalid start (found 0x%llx, wanted >= 0x%llx)\n",
|
||||
p.number,
|
||||
(unsigned long long) p.start,
|
||||
(unsigned long long) delta);
|
||||
#ifdef GRUB_UTIL
|
||||
/* disk->partition != NULL as 0 < delta */
|
||||
partname = grub_partition_get_name (disk->partition);
|
||||
grub_util_warn ("Discarding improperly nested partition (%s,%s,%s%d)",
|
||||
disk->name, partname, p.partmap->name, p.number + 1);
|
||||
grub_free (partname);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
p.start -= delta;
|
||||
|
||||
if (hook (disk, &p))
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
|
|
133
grub-core/script/argv.c
Normal file
133
grub-core/script/argv.c
Normal file
|
@ -0,0 +1,133 @@
|
|||
/* argv.c - methods for constructing argument vector */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/mm.h>
|
||||
#include <grub/script_sh.h>
|
||||
|
||||
/* Return nearest power of two that is >= v. */
|
||||
static unsigned
|
||||
round_up_exp (unsigned v)
|
||||
{
|
||||
v--;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
v |= v >> 4;
|
||||
v |= v >> 8;
|
||||
v |= v >> 16;
|
||||
|
||||
if (sizeof (v) > 4)
|
||||
v |= v >> 32;
|
||||
|
||||
v++;
|
||||
v += (v == 0);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
void
|
||||
grub_script_argv_free (struct grub_script_argv *argv)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
if (argv->args)
|
||||
{
|
||||
for (i = 0; i < argv->argc; i++)
|
||||
grub_free (argv->args[i]);
|
||||
|
||||
grub_free (argv->args);
|
||||
}
|
||||
|
||||
argv->argc = 0;
|
||||
argv->args = 0;
|
||||
}
|
||||
|
||||
/* Prepare for next argc. */
|
||||
int
|
||||
grub_script_argv_next (struct grub_script_argv *argv)
|
||||
{
|
||||
char **p = argv->args;
|
||||
|
||||
if (argv->args && argv->args[argv->argc - 1] == 0)
|
||||
return 0;
|
||||
|
||||
p = grub_realloc (p, round_up_exp ((argv->argc + 2) * sizeof (char *)));
|
||||
if (! p)
|
||||
return 1;
|
||||
|
||||
argv->argc++;
|
||||
argv->args = p;
|
||||
|
||||
if (argv->argc == 1)
|
||||
argv->args[0] = 0;
|
||||
argv->args[argv->argc] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Append `s' to the last argument. */
|
||||
int
|
||||
grub_script_argv_append (struct grub_script_argv *argv, const char *s)
|
||||
{
|
||||
int a, b;
|
||||
char *p = argv->args[argv->argc - 1];
|
||||
|
||||
if (! s)
|
||||
return 0;
|
||||
|
||||
a = p ? grub_strlen (p) : 0;
|
||||
b = grub_strlen (s);
|
||||
|
||||
p = grub_realloc (p, round_up_exp ((a + b + 1) * sizeof (char)));
|
||||
if (! p)
|
||||
return 1;
|
||||
|
||||
grub_strcpy (p + a, s);
|
||||
argv->args[argv->argc - 1] = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Split `s' and append words as multiple arguments. */
|
||||
int
|
||||
grub_script_argv_split_append (struct grub_script_argv *argv, char *s)
|
||||
{
|
||||
char ch;
|
||||
char *p;
|
||||
int errors = 0;
|
||||
|
||||
if (! s)
|
||||
return 0;
|
||||
|
||||
while (! errors && *s)
|
||||
{
|
||||
p = s;
|
||||
while (*s && ! grub_isspace (*s))
|
||||
s++;
|
||||
|
||||
ch = *s;
|
||||
*s = '\0';
|
||||
errors += grub_script_argv_append (argv, p);
|
||||
*s = ch;
|
||||
|
||||
while (*s && grub_isspace (*s))
|
||||
s++;
|
||||
|
||||
if (*s)
|
||||
errors += grub_script_argv_next (argv);
|
||||
}
|
||||
return errors;
|
||||
}
|
|
@ -30,6 +30,252 @@
|
|||
is sizeof (int) * 3, and one extra for a possible -ve sign. */
|
||||
#define ERRNO_DIGITS_MAX (sizeof (int) * 3 + 1)
|
||||
|
||||
static unsigned long is_continue;
|
||||
static unsigned long active_loops;
|
||||
static unsigned long active_breaks;
|
||||
|
||||
/* Scope for grub script functions. */
|
||||
struct grub_script_scope
|
||||
{
|
||||
struct grub_script_argv argv;
|
||||
};
|
||||
static struct grub_script_scope *scope = 0;
|
||||
|
||||
grub_err_t
|
||||
grub_script_break (grub_command_t cmd, int argc, char *argv[])
|
||||
{
|
||||
char *p = 0;
|
||||
unsigned long count;
|
||||
|
||||
if (argc == 0)
|
||||
count = 1;
|
||||
|
||||
else if ((argc > 1) || (count = grub_strtoul (argv[0], &p, 10)) == 0 ||
|
||||
(*p != '\0'))
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad break");
|
||||
|
||||
is_continue = grub_strcmp (cmd->name, "break") ? 1 : 0;
|
||||
active_breaks = grub_min (active_loops, count);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_script_shift (grub_command_t cmd __attribute__((unused)),
|
||||
int argc, char *argv[])
|
||||
{
|
||||
char *p = 0;
|
||||
unsigned long n = 0;
|
||||
|
||||
if (! scope)
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
if (argc == 0)
|
||||
n = 1;
|
||||
|
||||
else if (argc > 1)
|
||||
return GRUB_ERR_BAD_ARGUMENT;
|
||||
|
||||
else
|
||||
{
|
||||
n = grub_strtoul (argv[0], &p, 10);
|
||||
if (*p != '\0')
|
||||
return GRUB_ERR_BAD_ARGUMENT;
|
||||
}
|
||||
|
||||
if (n > scope->argv.argc)
|
||||
return GRUB_ERR_BAD_ARGUMENT;
|
||||
|
||||
scope->argv.argc -= n;
|
||||
scope->argv.args += n;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static int
|
||||
grub_env_special (const char *name)
|
||||
{
|
||||
if (grub_isdigit (name[0]) ||
|
||||
grub_strcmp (name, "#") == 0 ||
|
||||
grub_strcmp (name, "*") == 0 ||
|
||||
grub_strcmp (name, "@") == 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char **
|
||||
grub_script_env_get (const char *name, grub_script_arg_type_t type)
|
||||
{
|
||||
struct grub_script_argv result = { 0, 0 };
|
||||
|
||||
if (grub_script_argv_next (&result))
|
||||
goto fail;
|
||||
|
||||
if (! grub_env_special (name))
|
||||
{
|
||||
char *v = grub_env_get (name);
|
||||
if (v && v[0])
|
||||
{
|
||||
if (type == GRUB_SCRIPT_ARG_TYPE_VAR)
|
||||
{
|
||||
if (grub_script_argv_split_append (&result, v))
|
||||
goto fail;
|
||||
}
|
||||
else
|
||||
if (grub_script_argv_append (&result, v))
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
else if (! scope)
|
||||
{
|
||||
if (grub_script_argv_append (&result, 0))
|
||||
goto fail;
|
||||
}
|
||||
else if (grub_strcmp (name, "#") == 0)
|
||||
{
|
||||
char buffer[ERRNO_DIGITS_MAX + 1];
|
||||
grub_snprintf (buffer, sizeof (buffer), "%u", scope->argv.argc);
|
||||
if (grub_script_argv_append (&result, buffer))
|
||||
goto fail;
|
||||
}
|
||||
else if (grub_strcmp (name, "*") == 0)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < scope->argv.argc; i++)
|
||||
if (type == GRUB_SCRIPT_ARG_TYPE_VAR)
|
||||
{
|
||||
if (i != 0 && grub_script_argv_next (&result))
|
||||
goto fail;
|
||||
|
||||
if (grub_script_argv_split_append (&result, scope->argv.args[i]))
|
||||
goto fail;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i != 0 && grub_script_argv_append (&result, " "))
|
||||
goto fail;
|
||||
|
||||
if (grub_script_argv_append (&result, scope->argv.args[i]))
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
else if (grub_strcmp (name, "@") == 0)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < scope->argv.argc; i++)
|
||||
{
|
||||
if (i != 0 && grub_script_argv_next (&result))
|
||||
goto fail;
|
||||
|
||||
if (type == GRUB_SCRIPT_ARG_TYPE_VAR)
|
||||
{
|
||||
if (grub_script_argv_split_append (&result, scope->argv.args[i]))
|
||||
goto fail;
|
||||
}
|
||||
else
|
||||
if (grub_script_argv_append (&result, scope->argv.args[i]))
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned long num = grub_strtoul (name, 0, 10);
|
||||
if (num == 0)
|
||||
; /* XXX no file name, for now. */
|
||||
|
||||
else if (num <= scope->argv.argc)
|
||||
{
|
||||
if (type == GRUB_SCRIPT_ARG_TYPE_VAR)
|
||||
{
|
||||
if (grub_script_argv_split_append (&result,
|
||||
scope->argv.args[num - 1]))
|
||||
goto fail;
|
||||
}
|
||||
else
|
||||
if (grub_script_argv_append (&result, scope->argv.args[num - 1]))
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
return result.args;
|
||||
|
||||
fail:
|
||||
|
||||
grub_script_argv_free (&result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_script_env_set (const char *name, const char *val)
|
||||
{
|
||||
if (grub_env_special (name))
|
||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad variable name");
|
||||
|
||||
return grub_env_set (name, val);
|
||||
}
|
||||
|
||||
/* Expand arguments in ARGLIST into multiple arguments. */
|
||||
static int
|
||||
grub_script_arglist_to_argv (struct grub_script_arglist *arglist,
|
||||
struct grub_script_argv *argv)
|
||||
{
|
||||
int i;
|
||||
char **values = 0;
|
||||
struct grub_script_arg *arg = 0;
|
||||
struct grub_script_argv result = { 0, 0 };
|
||||
|
||||
for (; arglist && arglist->arg; arglist = arglist->next)
|
||||
{
|
||||
if (grub_script_argv_next (&result))
|
||||
goto fail;
|
||||
|
||||
arg = arglist->arg;
|
||||
while (arg)
|
||||
{
|
||||
switch (arg->type)
|
||||
{
|
||||
case GRUB_SCRIPT_ARG_TYPE_VAR:
|
||||
case GRUB_SCRIPT_ARG_TYPE_DQVAR:
|
||||
values = grub_script_env_get (arg->str, arg->type);
|
||||
for (i = 0; values && values[i]; i++)
|
||||
{
|
||||
if (i != 0 && grub_script_argv_next (&result))
|
||||
goto fail;
|
||||
|
||||
if (grub_script_argv_append (&result, values[i]))
|
||||
goto fail;
|
||||
}
|
||||
grub_free (values);
|
||||
break;
|
||||
|
||||
case GRUB_SCRIPT_ARG_TYPE_TEXT:
|
||||
if (grub_strlen (arg->str) &&
|
||||
grub_script_argv_append (&result, arg->str))
|
||||
goto fail;
|
||||
break;
|
||||
|
||||
case GRUB_SCRIPT_ARG_TYPE_DQSTR:
|
||||
case GRUB_SCRIPT_ARG_TYPE_SQSTR:
|
||||
if (grub_script_argv_append (&result, arg->str))
|
||||
goto fail;
|
||||
break;
|
||||
}
|
||||
arg = arg->next;
|
||||
}
|
||||
}
|
||||
|
||||
if (! result.args[result.argc - 1])
|
||||
result.argc--;
|
||||
|
||||
*argv = result;
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
|
||||
grub_script_argv_free (&result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_script_execute_cmd (struct grub_script_cmd *cmd)
|
||||
{
|
||||
|
@ -46,149 +292,27 @@ grub_script_execute_cmd (struct grub_script_cmd *cmd)
|
|||
return ret;
|
||||
}
|
||||
|
||||
#define ARG_ALLOCATION_UNIT (32 * sizeof (char))
|
||||
#define ARGV_ALLOCATION_UNIT (8 * sizeof (void*))
|
||||
|
||||
/* Expand arguments in ARGLIST into multiple arguments. */
|
||||
char **
|
||||
grub_script_execute_arglist_to_argv (struct grub_script_arglist *arglist, int *count)
|
||||
/* Execute a function call. */
|
||||
grub_err_t
|
||||
grub_script_function_call (grub_script_function_t func, int argc, char **args)
|
||||
{
|
||||
int i;
|
||||
int oom;
|
||||
int argc;
|
||||
int empty;
|
||||
char *ptr;
|
||||
char **argv;
|
||||
char *value;
|
||||
struct grub_script_arg *arg;
|
||||
grub_err_t ret = 0;
|
||||
unsigned long loops = active_loops;
|
||||
struct grub_script_scope *old_scope;
|
||||
struct grub_script_scope new_scope;
|
||||
|
||||
auto void push (char *str);
|
||||
void push (char *str)
|
||||
{
|
||||
char **p;
|
||||
active_loops = 0;
|
||||
new_scope.argv.argc = argc;
|
||||
new_scope.argv.args = args;
|
||||
|
||||
if (oom)
|
||||
return;
|
||||
old_scope = scope;
|
||||
scope = &new_scope;
|
||||
|
||||
p = grub_realloc (argv, ALIGN_UP (sizeof(char*) * (argc + 1), ARGV_ALLOCATION_UNIT));
|
||||
if (!p)
|
||||
oom = 1;
|
||||
else
|
||||
{
|
||||
p[argc++] = str;
|
||||
argv = p;
|
||||
}
|
||||
}
|
||||
ret = grub_script_execute (func->func);
|
||||
|
||||
auto char* append (const char *str, grub_size_t nchar);
|
||||
char* append (const char *str, grub_size_t nchar)
|
||||
{
|
||||
int len;
|
||||
int old;
|
||||
char *p;
|
||||
|
||||
if (oom || !str)
|
||||
return 0;
|
||||
|
||||
len = nchar ?: grub_strlen (str);
|
||||
old = argv[argc - 1] ? grub_strlen (argv[argc - 1]) : 0;
|
||||
p = grub_realloc (argv[argc - 1], ALIGN_UP(old + len + 1, ARG_ALLOCATION_UNIT));
|
||||
|
||||
if (p)
|
||||
{
|
||||
grub_strncpy (p + old, str, len);
|
||||
p[old + len] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
oom = 1;
|
||||
grub_free (argv[argc - 1]);
|
||||
}
|
||||
argv[argc - 1] = p;
|
||||
return argv[argc - 1];
|
||||
}
|
||||
|
||||
/* Move *STR to the begining of next word, but return current word. */
|
||||
auto char* move_to_next (char **str);
|
||||
char* move_to_next (char **str)
|
||||
{
|
||||
char *end;
|
||||
char *start;
|
||||
|
||||
if (oom || !str || !*str)
|
||||
return 0;
|
||||
|
||||
start = *str;
|
||||
while (*start && grub_isspace (*start)) start++;
|
||||
if (*start == '\0')
|
||||
return 0;
|
||||
|
||||
end = start + 1;
|
||||
while (*end && !grub_isspace (*end)) end++;
|
||||
|
||||
*str = end;
|
||||
return start;
|
||||
}
|
||||
|
||||
oom = 0;
|
||||
argv = 0;
|
||||
argc = 0;
|
||||
push (0);
|
||||
for (; arglist; arglist = arglist->next)
|
||||
{
|
||||
empty = 1;
|
||||
arg = arglist->arg;
|
||||
while (arg)
|
||||
{
|
||||
switch (arg->type)
|
||||
{
|
||||
case GRUB_SCRIPT_ARG_TYPE_VAR:
|
||||
value = grub_env_get (arg->str);
|
||||
while (value && *value && (ptr = move_to_next(&value)))
|
||||
{
|
||||
empty = 0;
|
||||
append (ptr, value - ptr);
|
||||
if (*value) push(0);
|
||||
}
|
||||
break;
|
||||
|
||||
case GRUB_SCRIPT_ARG_TYPE_TEXT:
|
||||
if (grub_strlen (arg->str) > 0)
|
||||
{
|
||||
empty = 0;
|
||||
append (arg->str, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case GRUB_SCRIPT_ARG_TYPE_DQSTR:
|
||||
case GRUB_SCRIPT_ARG_TYPE_SQSTR:
|
||||
empty = 0;
|
||||
append (arg->str, 0);
|
||||
break;
|
||||
|
||||
case GRUB_SCRIPT_ARG_TYPE_DQVAR:
|
||||
empty = 0;
|
||||
append (grub_env_get (arg->str), 0);
|
||||
break;
|
||||
}
|
||||
arg = arg->next;
|
||||
}
|
||||
if (!empty)
|
||||
push (0);
|
||||
}
|
||||
|
||||
if (oom)
|
||||
{
|
||||
for (i = 0; i < argc; i++)
|
||||
grub_free (argv[i]);
|
||||
grub_free (argv);
|
||||
argv = 0;
|
||||
}
|
||||
|
||||
if (argv)
|
||||
*count = argc - 1;
|
||||
|
||||
return argv;
|
||||
active_loops = loops;
|
||||
scope = old_scope;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Execute a single command line. */
|
||||
|
@ -196,21 +320,18 @@ grub_err_t
|
|||
grub_script_execute_cmdline (struct grub_script_cmd *cmd)
|
||||
{
|
||||
struct grub_script_cmdline *cmdline = (struct grub_script_cmdline *) cmd;
|
||||
char **args = 0;
|
||||
int i = 0;
|
||||
grub_command_t grubcmd;
|
||||
grub_err_t ret = 0;
|
||||
int argcount = 0;
|
||||
grub_script_function_t func = 0;
|
||||
char errnobuf[18];
|
||||
char *cmdname;
|
||||
struct grub_script_argv argv = { 0, 0 };
|
||||
|
||||
/* Lookup the command. */
|
||||
args = grub_script_execute_arglist_to_argv (cmdline->arglist, &argcount);
|
||||
if (!args)
|
||||
if (grub_script_arglist_to_argv (cmdline->arglist, &argv) || ! argv.args[0])
|
||||
return grub_errno;
|
||||
|
||||
cmdname = args[0];
|
||||
cmdname = argv.args[0];
|
||||
grubcmd = grub_command_find (cmdname);
|
||||
if (! grubcmd)
|
||||
{
|
||||
|
@ -232,13 +353,14 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
|
|||
/* Create two strings and set the variable. */
|
||||
*eq = '\0';
|
||||
eq++;
|
||||
grub_env_set (assign, eq);
|
||||
grub_script_env_set (assign, eq);
|
||||
}
|
||||
grub_free (assign);
|
||||
|
||||
grub_snprintf (errnobuf, sizeof (errnobuf), "%d", grub_errno);
|
||||
grub_env_set ("?", errnobuf);
|
||||
grub_script_env_set ("?", errnobuf);
|
||||
|
||||
grub_script_argv_free (&argv);
|
||||
grub_print_error ();
|
||||
|
||||
return 0;
|
||||
|
@ -247,14 +369,12 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
|
|||
|
||||
/* Execute the GRUB command or function. */
|
||||
if (grubcmd)
|
||||
ret = (grubcmd->func) (grubcmd, argcount - 1, args + 1);
|
||||
ret = (grubcmd->func) (grubcmd, argv.argc - 1, argv.args + 1);
|
||||
else
|
||||
ret = grub_script_function_call (func, argcount - 1, args + 1);
|
||||
ret = grub_script_function_call (func, argv.argc - 1, argv.args + 1);
|
||||
|
||||
/* Free arguments. */
|
||||
for (i = 0; i < argcount; i++)
|
||||
grub_free (args[i]);
|
||||
grub_free (args);
|
||||
grub_script_argv_free (&argv);
|
||||
|
||||
if (grub_errno == GRUB_ERR_TEST_FAILURE)
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
@ -269,13 +389,13 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
|
|||
|
||||
/* Execute a block of one or more commands. */
|
||||
grub_err_t
|
||||
grub_script_execute_cmdblock (struct grub_script_cmd *cmd)
|
||||
grub_script_execute_cmdlist (struct grub_script_cmd *list)
|
||||
{
|
||||
int ret = 0;
|
||||
struct grub_script_cmdblock *cmdblock = (struct grub_script_cmdblock *) cmd;
|
||||
struct grub_script_cmd *cmd;
|
||||
|
||||
/* Loop over every command and execute it. */
|
||||
for (cmd = cmdblock->cmdlist; cmd; cmd = cmd->next)
|
||||
for (cmd = list->next; cmd && ! active_breaks; cmd = cmd->next)
|
||||
ret = grub_script_execute_cmd (cmd);
|
||||
|
||||
return ret;
|
||||
|
@ -307,25 +427,34 @@ grub_script_execute_cmdif (struct grub_script_cmd *cmd)
|
|||
grub_err_t
|
||||
grub_script_execute_cmdfor (struct grub_script_cmd *cmd)
|
||||
{
|
||||
int i;
|
||||
int result;
|
||||
char **args;
|
||||
int argcount;
|
||||
unsigned i;
|
||||
grub_err_t result;
|
||||
struct grub_script_argv argv = { 0, 0 };
|
||||
|
||||
struct grub_script_cmdfor *cmdfor = (struct grub_script_cmdfor *) cmd;
|
||||
|
||||
args = grub_script_execute_arglist_to_argv (cmdfor->words, &argcount);
|
||||
if (!args)
|
||||
if (grub_script_arglist_to_argv (cmdfor->words, &argv))
|
||||
return grub_errno;
|
||||
|
||||
active_loops++;
|
||||
result = 0;
|
||||
for (i = 0; i < argcount; i++)
|
||||
for (i = 0; i < argv.argc; i++)
|
||||
{
|
||||
grub_env_set (cmdfor->name->str, args[i]);
|
||||
result = grub_script_execute_cmd (cmdfor->list);
|
||||
grub_free (args[i]);
|
||||
if (is_continue && active_breaks == 1)
|
||||
active_breaks = 0;
|
||||
|
||||
if (! active_breaks)
|
||||
{
|
||||
grub_script_env_set (cmdfor->name->str, argv.args[i]);
|
||||
result = grub_script_execute_cmd (cmdfor->list);
|
||||
}
|
||||
}
|
||||
|
||||
grub_free (args);
|
||||
if (active_breaks)
|
||||
active_breaks--;
|
||||
|
||||
active_loops--;
|
||||
grub_script_argv_free (&argv);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -337,6 +466,7 @@ grub_script_execute_cmdwhile (struct grub_script_cmd *cmd)
|
|||
int result;
|
||||
struct grub_script_cmdwhile *cmdwhile = (struct grub_script_cmdwhile *) cmd;
|
||||
|
||||
active_loops++;
|
||||
result = 0;
|
||||
do {
|
||||
cond = grub_script_execute_cmd (cmdwhile->cond);
|
||||
|
@ -344,8 +474,19 @@ grub_script_execute_cmdwhile (struct grub_script_cmd *cmd)
|
|||
break;
|
||||
|
||||
result = grub_script_execute_cmd (cmdwhile->list);
|
||||
|
||||
if (active_breaks == 1 && is_continue)
|
||||
active_breaks = 0;
|
||||
|
||||
if (active_breaks)
|
||||
break;
|
||||
|
||||
} while (1); /* XXX Put a check for ^C here */
|
||||
|
||||
if (active_breaks)
|
||||
active_breaks--;
|
||||
|
||||
active_loops--;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -354,26 +495,20 @@ grub_err_t
|
|||
grub_script_execute_menuentry (struct grub_script_cmd *cmd)
|
||||
{
|
||||
struct grub_script_cmd_menuentry *cmd_menuentry;
|
||||
char **args = 0;
|
||||
int argcount = 0;
|
||||
int i = 0;
|
||||
struct grub_script_argv argv = { 0, 0 };
|
||||
|
||||
cmd_menuentry = (struct grub_script_cmd_menuentry *) cmd;
|
||||
|
||||
if (cmd_menuentry->arglist)
|
||||
{
|
||||
args = grub_script_execute_arglist_to_argv (cmd_menuentry->arglist, &argcount);
|
||||
if (!args)
|
||||
if (grub_script_arglist_to_argv (cmd_menuentry->arglist, &argv))
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
grub_normal_add_menu_entry (argcount, (const char **) args,
|
||||
grub_normal_add_menu_entry (argv.argc, (const char **) argv.args,
|
||||
cmd_menuentry->sourcecode);
|
||||
|
||||
/* Free arguments. */
|
||||
for (i = 0; i < argcount; i++)
|
||||
grub_free (args[i]);
|
||||
grub_free (args);
|
||||
grub_script_argv_free (&argv);
|
||||
|
||||
return grub_errno;
|
||||
}
|
||||
|
|
|
@ -103,12 +103,3 @@ grub_script_function_find (char *functionname)
|
|||
|
||||
return func;
|
||||
}
|
||||
|
||||
int
|
||||
grub_script_function_call (grub_script_function_t func,
|
||||
int argc __attribute__((unused)),
|
||||
char **args __attribute__((unused)))
|
||||
{
|
||||
/* XXX: Arguments are not supported yet. */
|
||||
return grub_script_execute (func->func);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
|
||||
#include <grub/dl.h>
|
||||
#include <grub/i18n.h>
|
||||
#include <grub/parser.h>
|
||||
#include <grub/script_sh.h>
|
||||
|
||||
|
@ -39,3 +40,34 @@ grub_normal_parse_line (char *line, grub_reader_getline_t getline)
|
|||
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static grub_command_t cmd_break;
|
||||
static grub_command_t cmd_continue;
|
||||
static grub_command_t cmd_shift;
|
||||
|
||||
void
|
||||
grub_script_init (void)
|
||||
{
|
||||
cmd_break = grub_register_command ("break", grub_script_break,
|
||||
N_("[n]"), N_("Exit from loops"));
|
||||
cmd_continue = grub_register_command ("continue", grub_script_break,
|
||||
N_("[n]"), N_("Continue loops"));
|
||||
cmd_shift = grub_register_command ("shift", grub_script_shift,
|
||||
N_("[n]"), N_("Shift positional parameters."));
|
||||
}
|
||||
|
||||
void
|
||||
grub_script_fini (void)
|
||||
{
|
||||
if (cmd_break)
|
||||
grub_unregister_command (cmd_break);
|
||||
cmd_break = 0;
|
||||
|
||||
if (cmd_continue)
|
||||
grub_unregister_command (cmd_continue);
|
||||
cmd_continue = 0;
|
||||
|
||||
if (cmd_shift)
|
||||
grub_unregister_command (cmd_shift);
|
||||
cmd_shift = 0;
|
||||
}
|
||||
|
|
|
@ -97,9 +97,7 @@ script: newlines0
|
|||
}
|
||||
| script statement delimiter newlines0
|
||||
{
|
||||
struct grub_script_cmdblock *cmdblock;
|
||||
cmdblock = (struct grub_script_cmdblock *) $1;
|
||||
$$ = grub_script_add_cmd (state, cmdblock, $2);
|
||||
$$ = grub_script_append_cmd (state, $1, $2);
|
||||
}
|
||||
| error
|
||||
{
|
||||
|
@ -185,13 +183,11 @@ command: grubcmd { $$ = $1; }
|
|||
/* A list of commands. */
|
||||
commands1: newlines0 command
|
||||
{
|
||||
$$ = grub_script_add_cmd (state, 0, $2);
|
||||
$$ = grub_script_append_cmd (state, 0, $2);
|
||||
}
|
||||
| commands1 delimiters1 command
|
||||
{
|
||||
struct grub_script_cmdblock *cmdblock;
|
||||
cmdblock = (struct grub_script_cmdblock *) $1;
|
||||
$$ = grub_script_add_cmd (state, cmdblock, $3);
|
||||
$$ = grub_script_append_cmd (state, $1, $3);
|
||||
}
|
||||
;
|
||||
|
||||
|
|
|
@ -291,46 +291,40 @@ grub_script_create_cmdmenu (struct grub_parser_param *state,
|
|||
return (struct grub_script_cmd *) cmd;
|
||||
}
|
||||
|
||||
/* Create a block of commands. CMD contains the command that should
|
||||
be added at the end of CMDBLOCK's list. If CMDBLOCK is zero, a new
|
||||
cmdblock will be created. */
|
||||
/* Create a chain of commands. LAST contains the command that should
|
||||
be added at the end of LIST's list. If LIST is zero, a new list
|
||||
will be created. */
|
||||
struct grub_script_cmd *
|
||||
grub_script_add_cmd (struct grub_parser_param *state,
|
||||
struct grub_script_cmdblock *cmdblock,
|
||||
struct grub_script_cmd *cmd)
|
||||
grub_script_append_cmd (struct grub_parser_param *state,
|
||||
struct grub_script_cmd *list,
|
||||
struct grub_script_cmd *last)
|
||||
{
|
||||
struct grub_script_cmd *ptr;
|
||||
|
||||
grub_dprintf ("scripting", "cmdblock\n");
|
||||
grub_dprintf ("scripting", "append command\n");
|
||||
|
||||
if (!cmd)
|
||||
return (struct grub_script_cmd *) cmdblock;
|
||||
if (! last)
|
||||
return list;
|
||||
|
||||
if (!cmdblock)
|
||||
if (! list)
|
||||
{
|
||||
cmdblock = grub_script_malloc (state, sizeof (*cmdblock));
|
||||
if (!cmdblock)
|
||||
list = grub_script_malloc (state, sizeof (*list));
|
||||
if (! list)
|
||||
return 0;
|
||||
|
||||
cmdblock->cmd.exec = grub_script_execute_cmdblock;
|
||||
cmdblock->cmd.next = 0;
|
||||
cmdblock->cmdlist = cmd;
|
||||
cmd->next = 0;
|
||||
list->exec = grub_script_execute_cmdlist;
|
||||
list->next = last;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!cmdblock->cmdlist)
|
||||
cmdblock->cmdlist = cmd;
|
||||
else
|
||||
{
|
||||
ptr = cmdblock->cmdlist;
|
||||
while (ptr->next)
|
||||
ptr = ptr->next;
|
||||
ptr->next = cmd;
|
||||
}
|
||||
ptr = list;
|
||||
while (ptr->next)
|
||||
ptr = ptr->next;
|
||||
|
||||
ptr->next = last;
|
||||
}
|
||||
|
||||
return (struct grub_script_cmd *) cmdblock;
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -116,10 +116,11 @@ COMMENT #.*$
|
|||
|
||||
CHAR [^{}|&$;<> \t\n\'\"\\]
|
||||
DIGITS [[:digit:]]+
|
||||
NAME [[:alpha:]_][[:alnum:][:digit:]_]*
|
||||
NAME [[:alpha:]_][[:alnum:]_]*
|
||||
|
||||
ESC \\.
|
||||
VARIABLE ${NAME}|$\{{NAME}\}|${DIGITS}|$\{{DIGITS}\}|$\?|$\{\?\}
|
||||
SPECIAL \?|\#|\*|\@
|
||||
VARIABLE ${NAME}|$\{{NAME}\}|${DIGITS}|$\{{DIGITS}\}|${SPECIAL}|$\{{SPECIAL}\}
|
||||
DQSTR \"([^\\\"]|{ESC})*\"
|
||||
SQSTR \'[^\']*\'
|
||||
WORD ({CHAR}|{DQSTR}|{SQSTR}|{ESC}|{VARIABLE})+
|
||||
|
@ -221,7 +222,7 @@ WORD ({CHAR}|{DQSTR}|{SQSTR}|{ESC}|{VARIABLE})+
|
|||
}
|
||||
|
||||
<VAR>{
|
||||
\? |
|
||||
{SPECIAL} |
|
||||
{DIGITS} |
|
||||
{NAME} {
|
||||
COPY (yytext, yyleng);
|
||||
|
@ -231,7 +232,7 @@ WORD ({CHAR}|{DQSTR}|{SQSTR}|{ESC}|{VARIABLE})+
|
|||
else
|
||||
ARG (GRUB_SCRIPT_ARG_TYPE_DQVAR);
|
||||
}
|
||||
\{\?\} |
|
||||
\{{SPECIAL}\} |
|
||||
\{{DIGITS}\} |
|
||||
\{{NAME}\} {
|
||||
yytext[yyleng - 1] = '\0';
|
||||
|
|
|
@ -311,6 +311,20 @@ grub_console_setcursor (struct grub_term_output *term __attribute__ ((unused)),
|
|||
efi_call_2 (o->enable_cursor, o, on);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_efi_console_init (struct grub_term_output *term)
|
||||
{
|
||||
grub_console_setcursor (term, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_efi_console_fini (struct grub_term_output *term)
|
||||
{
|
||||
grub_console_setcursor (term, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct grub_term_input grub_console_term_input =
|
||||
{
|
||||
.name = "console",
|
||||
|
@ -321,6 +335,8 @@ static struct grub_term_input grub_console_term_input =
|
|||
static struct grub_term_output grub_console_term_output =
|
||||
{
|
||||
.name = "console",
|
||||
.init = grub_efi_console_init,
|
||||
.fini = grub_efi_console_fini,
|
||||
.putchar = grub_console_putchar,
|
||||
.getwh = grub_console_getwh,
|
||||
.getxy = grub_console_getxy,
|
||||
|
|
|
@ -334,43 +334,26 @@ grub_video_cirrus_setup (unsigned int width, unsigned int height,
|
|||
}
|
||||
|
||||
{
|
||||
int pitch_reg, overflow_reg = 0, line_compare = 0x3ff;
|
||||
struct grub_video_hw_config config = {
|
||||
.pitch = pitch / GRUB_VGA_CR_PITCH_DIVISOR,
|
||||
.line_compare = 0x3ff,
|
||||
.vdisplay_end = height - 1,
|
||||
.horizontal_end = width / GRUB_VGA_CR_WIDTH_DIVISOR
|
||||
};
|
||||
grub_uint8_t sr_ext = 0, hidden_dac = 0;
|
||||
|
||||
pitch_reg = pitch / GRUB_VGA_CR_PITCH_DIVISOR;
|
||||
|
||||
grub_vga_set_geometry (&config, grub_vga_cr_write);
|
||||
|
||||
grub_vga_gr_write (GRUB_VGA_GR_MODE_256_COLOR | GRUB_VGA_GR_MODE_READ_MODE1,
|
||||
GRUB_VGA_GR_MODE);
|
||||
grub_vga_gr_write (GRUB_VGA_GR_GR6_GRAPHICS_MODE, GRUB_VGA_GR_GR6);
|
||||
|
||||
grub_vga_sr_write (GRUB_VGA_SR_MEMORY_MODE_NORMAL, GRUB_VGA_SR_MEMORY_MODE);
|
||||
|
||||
/* Disable CR0-7 write protection. */
|
||||
grub_vga_cr_write (0, GRUB_VGA_CR_VSYNC_END);
|
||||
|
||||
grub_vga_cr_write (width / GRUB_VGA_CR_WIDTH_DIVISOR - 1,
|
||||
GRUB_VGA_CR_WIDTH);
|
||||
grub_vga_cr_write ((height - 1) & 0xff, GRUB_VGA_CR_HEIGHT);
|
||||
overflow_reg |= (((height - 1) >> GRUB_VGA_CR_OVERFLOW_HEIGHT1_SHIFT) &
|
||||
GRUB_VGA_CR_OVERFLOW_HEIGHT1_MASK)
|
||||
| (((height - 1) >> GRUB_VGA_CR_OVERFLOW_HEIGHT2_SHIFT) &
|
||||
GRUB_VGA_CR_OVERFLOW_HEIGHT2_MASK);
|
||||
|
||||
grub_vga_cr_write (pitch_reg & 0xff, GRUB_VGA_CR_PITCH);
|
||||
|
||||
grub_vga_cr_write (line_compare & 0xff, GRUB_VGA_CR_LINE_COMPARE);
|
||||
overflow_reg |= (line_compare >> GRUB_VGA_CR_OVERFLOW_LINE_COMPARE_SHIFT)
|
||||
& GRUB_VGA_CR_OVERFLOW_LINE_COMPARE_MASK;
|
||||
|
||||
grub_vga_cr_write (overflow_reg, GRUB_VGA_CR_OVERFLOW);
|
||||
|
||||
grub_vga_cr_write ((pitch_reg >> CIRRUS_CR_EXTENDED_DISPLAY_PITCH_SHIFT)
|
||||
grub_vga_cr_write ((config.pitch >> CIRRUS_CR_EXTENDED_DISPLAY_PITCH_SHIFT)
|
||||
& CIRRUS_CR_EXTENDED_DISPLAY_PITCH_MASK,
|
||||
CIRRUS_CR_EXTENDED_DISPLAY);
|
||||
|
||||
grub_vga_cr_write ((line_compare >> GRUB_VGA_CR_CELL_HEIGHT_LINE_COMPARE_SHIFT)
|
||||
& GRUB_VGA_CR_CELL_HEIGHT_LINE_COMPARE_MASK, GRUB_VGA_CR_CELL_HEIGHT);
|
||||
|
||||
grub_vga_cr_write (GRUB_VGA_CR_MODE_TIMING_ENABLE
|
||||
| GRUB_VGA_CR_MODE_BYTE_MODE
|
||||
| GRUB_VGA_CR_MODE_NO_HERCULES | GRUB_VGA_CR_MODE_NO_CGA,
|
||||
|
|
|
@ -26,10 +26,168 @@
|
|||
#include <grub/video.h>
|
||||
#include <grub/video_fb.h>
|
||||
#include <grub/pci.h>
|
||||
#include <grub/vga.h>
|
||||
|
||||
#include "sm712_init.c"
|
||||
|
||||
#define GRUB_SM712_TOTAL_MEMORY_SPACE 0x700400
|
||||
#define GRUB_SM712_REG_BASE 0x700000
|
||||
#define GRUB_SM712_PCIID 0x0712126f
|
||||
|
||||
enum
|
||||
{
|
||||
GRUB_SM712_SR_TV_CONTROL = 0x65,
|
||||
GRUB_SM712_SR_RAM_LUT = 0x66,
|
||||
GRUB_SM712_SR_CLOCK_CONTROL1 = 0x68,
|
||||
GRUB_SM712_SR_CLOCK_CONTROL2 = 0x69,
|
||||
GRUB_SM712_SR_VCLK_NUM = 0x6c,
|
||||
GRUB_SM712_SR_VCLK_DENOM = 0x6d,
|
||||
GRUB_SM712_SR_VCLK2_NUM = 0x6e,
|
||||
GRUB_SM712_SR_VCLK2_DENOM = 0x6f,
|
||||
GRUB_SM712_SR_POPUP_ICON_LOW = 0x80,
|
||||
GRUB_SM712_SR_POPUP_ICON_HIGH = 0x81,
|
||||
GRUB_SM712_SR_POPUP_ICON_CTRL = 0x82,
|
||||
GRUB_SM712_SR_POPUP_ICON_COLOR1 = 0x84,
|
||||
GRUB_SM712_SR_POPUP_ICON_COLOR2 = 0x85,
|
||||
GRUB_SM712_SR_POPUP_ICON_COLOR3 = 0x86,
|
||||
|
||||
GRUB_SM712_SR_HW_CURSOR_UPPER_LEFT_X_LOW = 0x88,
|
||||
GRUB_SM712_SR_HW_CURSOR_UPPER_LEFT_X_HIGH = 0x89,
|
||||
GRUB_SM712_SR_HW_CURSOR_UPPER_LEFT_Y_LOW = 0x8a,
|
||||
GRUB_SM712_SR_HW_CURSOR_UPPER_LEFT_Y_HIGH = 0x8b,
|
||||
GRUB_SM712_SR_HW_CURSOR_FG_COLOR = 0x8c,
|
||||
GRUB_SM712_SR_HW_CURSOR_BG_COLOR = 0x8d,
|
||||
|
||||
GRUB_SM712_SR_POPUP_ICON_X_LOW = 0x90,
|
||||
GRUB_SM712_SR_POPUP_ICON_X_HIGH = 0x91,
|
||||
GRUB_SM712_SR_POPUP_ICON_Y_LOW = 0x92,
|
||||
GRUB_SM712_SR_POPUP_ICON_Y_HIGH = 0x93,
|
||||
GRUB_SM712_SR_PANEL_HW_VIDEO_CONTROL = 0xa0,
|
||||
GRUB_SM712_SR_PANEL_HW_VIDEO_COLOR_KEY_LOW = 0xa1,
|
||||
GRUB_SM712_SR_PANEL_HW_VIDEO_COLOR_KEY_HIGH = 0xa2,
|
||||
GRUB_SM712_SR_PANEL_HW_VIDEO_COLOR_KEY_MASK_LOW = 0xa3,
|
||||
GRUB_SM712_SR_PANEL_HW_VIDEO_COLOR_KEY_MASK_HIGH = 0xa4,
|
||||
GRUB_SM712_SR_PANEL_HW_VIDEO_RED_CONSTANT = 0xa5,
|
||||
GRUB_SM712_SR_PANEL_HW_VIDEO_GREEN_CONSTANT = 0xa6,
|
||||
GRUB_SM712_SR_PANEL_HW_VIDEO_BLUE_CONSTANT = 0xa7,
|
||||
GRUB_SM712_SR_PANEL_HW_VIDEO_TOP_BOUNDARY = 0xa8,
|
||||
GRUB_SM712_SR_PANEL_HW_VIDEO_LEFT_BOUNDARY = 0xa9,
|
||||
GRUB_SM712_SR_PANEL_HW_VIDEO_BOTTOM_BOUNDARY = 0xaa,
|
||||
GRUB_SM712_SR_PANEL_HW_VIDEO_RIGHT_BOUNDARY = 0xab,
|
||||
GRUB_SM712_SR_PANEL_HW_VIDEO_TOP_LEFT_OVERFLOW_BOUNDARY = 0xac,
|
||||
GRUB_SM712_SR_PANEL_HW_VIDEO_BOTTOM_RIGHT_OVERFLOW_BOUNDARY = 0xad,
|
||||
GRUB_SM712_SR_PANEL_HW_VIDEO_VERTICAL_STRETCH_FACTOR = 0xae,
|
||||
GRUB_SM712_SR_PANEL_HW_VIDEO_HORIZONTAL_STRETCH_FACTOR = 0xaf,
|
||||
};
|
||||
enum
|
||||
{
|
||||
GRUB_SM712_SR_TV_CRT_SRAM = 0x00,
|
||||
GRUB_SM712_SR_TV_LCD_SRAM = 0x08
|
||||
};
|
||||
enum
|
||||
{
|
||||
GRUB_SM712_SR_TV_ALT_CLOCK = 0x00,
|
||||
GRUB_SM712_SR_TV_FREE_RUN_CLOCK = 0x04
|
||||
};
|
||||
enum
|
||||
{
|
||||
GRUB_SM712_SR_TV_CLOCK_CKIN_NTSC = 0x00,
|
||||
GRUB_SM712_SR_TV_CLOCK_REFCLK_PAL = 0x04
|
||||
};
|
||||
enum
|
||||
{
|
||||
GRUB_SM712_SR_TV_HSYNC = 0x00,
|
||||
GRUB_SM712_SR_TV_COMPOSITE_HSYNC = 0x01
|
||||
};
|
||||
enum
|
||||
{
|
||||
GRUB_SM712_SR_RAM_LUT_NORMAL = 0,
|
||||
GRUB_SM712_SR_RAM_LUT_LCD_RAM_OFF = 0x80,
|
||||
GRUB_SM712_SR_RAM_LUT_CRT_RAM_OFF = 0x40,
|
||||
GRUB_SM712_SR_RAM_LUT_LCD_RAM_NO_WRITE = 0x20,
|
||||
GRUB_SM712_SR_RAM_LUT_CRT_RAM_NO_WRITE = 0x10,
|
||||
GRUB_SM712_SR_RAM_LUT_CRT_8BIT = 0x08,
|
||||
GRUB_SM712_SR_RAM_LUT_CRT_GAMMA = 0x04
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
GRUB_SM712_SR_CLOCK_CONTROL1_VCLK_FROM_CCR = 0x40,
|
||||
GRUB_SM712_SR_CLOCK_CONTROL1_8DOT_CLOCK = 0x10,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
GRUB_SM712_SR_CLOCK_CONTROL2_PROGRAM_VCLOCK = 0x03
|
||||
};
|
||||
|
||||
#define GRUB_SM712_SR_POPUP_ICON_HIGH_MASK 0x7
|
||||
#define GRUB_SM712_SR_POPUP_ICON_HIGH_HW_CURSOR_EN 0x80
|
||||
enum
|
||||
{
|
||||
GRUB_SM712_SR_POPUP_ICON_CTRL_DISABLED = 0,
|
||||
GRUB_SM712_SR_POPUP_ICON_CTRL_ZOOM_ENABLED = 0x40,
|
||||
GRUB_SM712_SR_POPUP_ICON_CTRL_ENABLED = 0x80
|
||||
};
|
||||
#define RGB332_BLACK 0
|
||||
#define RGB332_WHITE 0xff
|
||||
|
||||
enum
|
||||
{
|
||||
GRUB_SM712_CR_OVERFLOW_INTERLACE = 0x30,
|
||||
GRUB_SM712_CR_INTERLACE_RETRACE = 0x31,
|
||||
GRUB_SM712_CR_TV_VDISPLAY_START = 0x32,
|
||||
GRUB_SM712_CR_TV_VDISPLAY_END_HIGH = 0x33,
|
||||
GRUB_SM712_CR_TV_VDISPLAY_END_LOW = 0x34,
|
||||
GRUB_SM712_CR_DDA_CONTROL_LOW = 0x35,
|
||||
GRUB_SM712_CR_DDA_CONTROL_HIGH = 0x36,
|
||||
GRUB_SM712_CR_TV_EQUALIZER = 0x38,
|
||||
GRUB_SM712_CR_TV_SERRATION = 0x39,
|
||||
GRUB_SM712_CR_HSYNC_CTRL = 0x3a,
|
||||
GRUB_SM712_CR_DEBUG = 0x3c,
|
||||
GRUB_SM712_CR_SHADOW_VGA_HTOTAL = 0x40,
|
||||
GRUB_SM712_CR_SHADOW_VGA_HBLANK_START = 0x41,
|
||||
GRUB_SM712_CR_SHADOW_VGA_HBLANK_END = 0x42,
|
||||
GRUB_SM712_CR_SHADOW_VGA_HRETRACE_START = 0x43,
|
||||
GRUB_SM712_CR_SHADOW_VGA_HRETRACE_END = 0x44,
|
||||
GRUB_SM712_CR_SHADOW_VGA_VERTICAL_TOTAL = 0x45,
|
||||
GRUB_SM712_CR_SHADOW_VGA_VBLANK_START = 0x46,
|
||||
GRUB_SM712_CR_SHADOW_VGA_VBLANK_END = 0x47,
|
||||
GRUB_SM712_CR_SHADOW_VGA_VRETRACE_START = 0x48,
|
||||
GRUB_SM712_CR_SHADOW_VGA_VRETRACE_END = 0x49,
|
||||
GRUB_SM712_CR_SHADOW_VGA_OVERFLOW = 0x4a,
|
||||
GRUB_SM712_CR_SHADOW_VGA_CELL_HEIGHT = 0x4b,
|
||||
GRUB_SM712_CR_SHADOW_VGA_HDISPLAY_END = 0x4c,
|
||||
GRUB_SM712_CR_SHADOW_VGA_VDISPLAY_END = 0x4d,
|
||||
GRUB_SM712_CR_DDA_LOOKUP_REG3_START = 0x90,
|
||||
GRUB_SM712_CR_DDA_LOOKUP_REG2_START = 0x91,
|
||||
GRUB_SM712_CR_DDA_LOOKUP_REG1_START = 0xa0,
|
||||
GRUB_SM712_CR_VCENTERING_OFFSET = 0xa6,
|
||||
GRUB_SM712_CR_HCENTERING_OFFSET = 0xa7,
|
||||
};
|
||||
|
||||
#define GRUB_SM712_CR_DEBUG_NONE 0
|
||||
|
||||
#define SM712_DDA_REG3_COMPARE_SHIFT 2
|
||||
#define SM712_DDA_REG3_COMPARE_MASK 0xfc
|
||||
#define SM712_DDA_REG3_DDA_SHIFT 8
|
||||
#define SM712_DDA_REG3_DDA_MASK 0x3
|
||||
#define SM712_DDA_REG2_DDA_MASK 0xff
|
||||
#define SM712_DDA_REG2_VCENTER_MASK 0x3f
|
||||
|
||||
static struct
|
||||
{
|
||||
grub_uint8_t compare;
|
||||
grub_uint16_t dda;
|
||||
grub_uint8_t vcentering;
|
||||
} dda_lookups[] = {
|
||||
{ 21, 469, 2},
|
||||
{ 23, 477, 2},
|
||||
{ 33, 535, 2},
|
||||
{ 35, 682, 21},
|
||||
{ 34, 675, 2},
|
||||
{ 55, 683, 6},
|
||||
};
|
||||
|
||||
static struct
|
||||
{
|
||||
|
@ -42,6 +200,7 @@ static struct
|
|||
grub_pci_device_t dev;
|
||||
} framebuffer;
|
||||
|
||||
#ifndef TEST
|
||||
static grub_err_t
|
||||
grub_video_sm712_video_init (void)
|
||||
{
|
||||
|
@ -60,6 +219,118 @@ grub_video_sm712_video_fini (void)
|
|||
|
||||
return grub_video_fb_fini ();
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void
|
||||
grub_sm712_write_reg (grub_uint8_t val, grub_uint16_t addr)
|
||||
{
|
||||
#ifdef TEST
|
||||
printf (" {1, 0x%x, 0x%x},\n", addr, val);
|
||||
#else
|
||||
*(volatile grub_uint8_t *) (framebuffer.ptr + GRUB_SM712_REG_BASE
|
||||
+ addr) = val;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline grub_uint8_t
|
||||
grub_sm712_read_reg (grub_uint16_t addr)
|
||||
{
|
||||
#ifdef TEST
|
||||
printf (" {-1, 0x%x, 0x5},\n", addr);
|
||||
#else
|
||||
return *(volatile grub_uint8_t *) (framebuffer.ptr + GRUB_SM712_REG_BASE
|
||||
+ addr);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline grub_uint8_t
|
||||
grub_sm712_sr_read (grub_uint8_t addr)
|
||||
{
|
||||
grub_sm712_write_reg (addr, GRUB_VGA_IO_SR_INDEX);
|
||||
return grub_sm712_read_reg (GRUB_VGA_IO_SR_DATA);
|
||||
}
|
||||
|
||||
static inline void
|
||||
grub_sm712_sr_write (grub_uint8_t val, grub_uint8_t addr)
|
||||
{
|
||||
grub_sm712_write_reg (addr, GRUB_VGA_IO_SR_INDEX);
|
||||
grub_sm712_write_reg (val, GRUB_VGA_IO_SR_DATA);
|
||||
}
|
||||
|
||||
static inline void
|
||||
grub_sm712_gr_write (grub_uint8_t val, grub_uint8_t addr)
|
||||
{
|
||||
grub_sm712_write_reg (addr, GRUB_VGA_IO_GR_INDEX);
|
||||
grub_sm712_write_reg (val, GRUB_VGA_IO_GR_DATA);
|
||||
}
|
||||
|
||||
static inline void
|
||||
grub_sm712_cr_write (grub_uint8_t val, grub_uint8_t addr)
|
||||
{
|
||||
grub_sm712_write_reg (addr, GRUB_VGA_IO_CR_INDEX);
|
||||
grub_sm712_write_reg (val, GRUB_VGA_IO_CR_DATA);
|
||||
}
|
||||
|
||||
static inline void
|
||||
grub_sm712_write_arx (grub_uint8_t val, grub_uint8_t addr)
|
||||
{
|
||||
grub_sm712_read_reg (GRUB_VGA_IO_INPUT_STATUS1_REGISTER);
|
||||
grub_sm712_write_reg (addr, GRUB_VGA_IO_ARX);
|
||||
grub_sm712_read_reg (GRUB_VGA_IO_ARX_READ);
|
||||
grub_sm712_write_reg (val, GRUB_VGA_IO_ARX);
|
||||
}
|
||||
|
||||
static inline void
|
||||
grub_sm712_cr_shadow_write (grub_uint8_t val, grub_uint8_t addr)
|
||||
{
|
||||
grub_uint8_t mapping[] =
|
||||
{
|
||||
[GRUB_VGA_CR_HTOTAL] = GRUB_SM712_CR_SHADOW_VGA_HTOTAL,
|
||||
[GRUB_VGA_CR_HORIZ_END] = 0xff,
|
||||
[GRUB_VGA_CR_HBLANK_START] = GRUB_SM712_CR_SHADOW_VGA_HBLANK_START,
|
||||
[GRUB_VGA_CR_HBLANK_END] = GRUB_SM712_CR_SHADOW_VGA_HBLANK_END,
|
||||
[GRUB_VGA_CR_HORIZ_SYNC_PULSE_START] = GRUB_SM712_CR_SHADOW_VGA_HRETRACE_START,
|
||||
[GRUB_VGA_CR_HORIZ_SYNC_PULSE_END] = GRUB_SM712_CR_SHADOW_VGA_HRETRACE_END,
|
||||
[GRUB_VGA_CR_VERT_TOTAL] = GRUB_SM712_CR_SHADOW_VGA_VERTICAL_TOTAL,
|
||||
[GRUB_VGA_CR_OVERFLOW] = GRUB_SM712_CR_SHADOW_VGA_OVERFLOW,
|
||||
[GRUB_VGA_CR_BYTE_PANNING] = 0xff,
|
||||
[GRUB_VGA_CR_CELL_HEIGHT] = GRUB_SM712_CR_SHADOW_VGA_CELL_HEIGHT,
|
||||
[GRUB_VGA_CR_CURSOR_START] = 0xff,
|
||||
[GRUB_VGA_CR_CURSOR_END] = 0xff,
|
||||
[GRUB_VGA_CR_START_ADDR_HIGH_REGISTER] = 0xff,
|
||||
[GRUB_VGA_CR_START_ADDR_LOW_REGISTER] = 0xff,
|
||||
[GRUB_VGA_CR_CURSOR_ADDR_HIGH] = 0xff,
|
||||
[GRUB_VGA_CR_CURSOR_ADDR_LOW] = 0xff,
|
||||
[GRUB_VGA_CR_VSYNC_START] = GRUB_SM712_CR_SHADOW_VGA_VRETRACE_START,
|
||||
[GRUB_VGA_CR_VSYNC_END] = GRUB_SM712_CR_SHADOW_VGA_VRETRACE_END,
|
||||
[GRUB_VGA_CR_VDISPLAY_END] = GRUB_SM712_CR_SHADOW_VGA_VDISPLAY_END,
|
||||
[GRUB_VGA_CR_PITCH] = GRUB_SM712_CR_SHADOW_VGA_HDISPLAY_END,
|
||||
[GRUB_VGA_CR_UNDERLINE_LOCATION] = 0xff,
|
||||
|
||||
[GRUB_VGA_CR_VERTICAL_BLANK_START] = GRUB_SM712_CR_SHADOW_VGA_VBLANK_START,
|
||||
[GRUB_VGA_CR_VERTICAL_BLANK_END] = GRUB_SM712_CR_SHADOW_VGA_VBLANK_END,
|
||||
[GRUB_VGA_CR_MODE] = 0xff,
|
||||
[GRUB_VGA_CR_LINE_COMPARE] = 0xff
|
||||
};
|
||||
if (addr >= ARRAY_SIZE (mapping) || mapping[addr] == 0xff)
|
||||
return;
|
||||
grub_sm712_cr_write (val, mapping[addr]);
|
||||
}
|
||||
|
||||
static inline void
|
||||
grub_sm712_write_dda_lookup (int idx, grub_uint8_t compare, grub_uint16_t dda,
|
||||
grub_uint8_t vcentering)
|
||||
{
|
||||
grub_sm712_cr_write (((compare << SM712_DDA_REG3_COMPARE_SHIFT)
|
||||
& SM712_DDA_REG3_COMPARE_MASK)
|
||||
| ((dda >> SM712_DDA_REG3_DDA_SHIFT)
|
||||
& SM712_DDA_REG3_DDA_MASK),
|
||||
GRUB_SM712_CR_DDA_LOOKUP_REG3_START + 2 * idx);
|
||||
grub_sm712_cr_write (dda & SM712_DDA_REG2_DDA_MASK,
|
||||
GRUB_SM712_CR_DDA_LOOKUP_REG2_START + 2 * idx);
|
||||
grub_sm712_cr_write (vcentering & SM712_DDA_REG2_VCENTER_MASK,
|
||||
GRUB_SM712_CR_DDA_LOOKUP_REG1_START + idx);
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
grub_video_sm712_setup (unsigned int width, unsigned int height,
|
||||
|
@ -70,6 +341,7 @@ grub_video_sm712_setup (unsigned int width, unsigned int height,
|
|||
int found = 0;
|
||||
unsigned i;
|
||||
|
||||
#ifndef TEST
|
||||
auto int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev, grub_pci_id_t pciid __attribute__ ((unused)));
|
||||
int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev, grub_pci_id_t pciid __attribute__ ((unused)))
|
||||
{
|
||||
|
@ -79,7 +351,8 @@ grub_video_sm712_setup (unsigned int width, unsigned int height,
|
|||
addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
|
||||
class = grub_pci_read (addr);
|
||||
|
||||
if (((class >> 16) & 0xffff) != 0x0300 || pciid != 0x0712126f)
|
||||
if (((class >> 16) & 0xffff) != GRUB_PCI_CLASS_SUBCLASS_VGA
|
||||
|| pciid != GRUB_SM712_PCIID)
|
||||
return 0;
|
||||
|
||||
found = 1;
|
||||
|
@ -103,7 +376,7 @@ grub_video_sm712_setup (unsigned int width, unsigned int height,
|
|||
grub_pci_iterate (find_card);
|
||||
if (!found)
|
||||
return grub_error (GRUB_ERR_IO, "Couldn't find graphics card");
|
||||
|
||||
#endif
|
||||
/* Fill mode info details. */
|
||||
framebuffer.mode_info.width = 1024;
|
||||
framebuffer.mode_info.height = 600;
|
||||
|
@ -120,8 +393,12 @@ grub_video_sm712_setup (unsigned int width, unsigned int height,
|
|||
framebuffer.mode_info.blue_field_pos = 0;
|
||||
framebuffer.mode_info.reserved_mask_size = 0;
|
||||
framebuffer.mode_info.reserved_field_pos = 0;
|
||||
framebuffer.mode_info.blit_format = grub_video_get_blit_format (&framebuffer.mode_info);
|
||||
#ifndef TEST
|
||||
framebuffer.mode_info.blit_format
|
||||
= grub_video_get_blit_format (&framebuffer.mode_info);
|
||||
#endif
|
||||
|
||||
#ifndef TEST
|
||||
if (found && framebuffer.base == 0)
|
||||
{
|
||||
grub_pci_address_t addr;
|
||||
|
@ -139,47 +416,280 @@ grub_video_sm712_setup (unsigned int width, unsigned int height,
|
|||
addr = grub_pci_make_address (framebuffer.dev, GRUB_PCI_REG_COMMAND);
|
||||
grub_pci_write (addr, 0x7);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* We can safely discard volatile attribute. */
|
||||
#ifndef TEST
|
||||
framebuffer.ptr
|
||||
= (void *) grub_pci_device_map_range (framebuffer.dev,
|
||||
framebuffer.base,
|
||||
GRUB_SM712_TOTAL_MEMORY_SPACE);
|
||||
#endif
|
||||
framebuffer.mapped = 1;
|
||||
|
||||
/* Initialise SM712. */
|
||||
grub_outb (0x18, GRUB_MACHINE_PCI_IO_BASE + 0x3c4);
|
||||
grub_outb (0x11, GRUB_MACHINE_PCI_IO_BASE + 0x3c5);
|
||||
#ifndef TEST
|
||||
/* FIXME */
|
||||
grub_vga_sr_write (0x11, 0x18);
|
||||
#endif
|
||||
|
||||
#ifndef TEST
|
||||
/* Prevent garbage from appearing on the screen. */
|
||||
grub_memset (framebuffer.ptr, 0,
|
||||
framebuffer.mode_info.height * framebuffer.mode_info.pitch);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE (sm712_init); i++)
|
||||
switch (sm712_init[i].directive)
|
||||
/* FIXME */
|
||||
grub_sm712_sr_write (0, 0x21);
|
||||
grub_sm712_sr_write (0x7a, 0x62);
|
||||
grub_sm712_sr_write (0x16, 0x6a);
|
||||
grub_sm712_sr_write (0x2, 0x6b);
|
||||
grub_sm712_write_reg (0, GRUB_VGA_IO_PIXEL_MASK);
|
||||
grub_sm712_sr_write (GRUB_VGA_SR_RESET_ASYNC, GRUB_VGA_SR_RESET);
|
||||
grub_sm712_write_reg (GRUB_VGA_IO_MISC_NEGATIVE_VERT_POLARITY
|
||||
| GRUB_VGA_IO_MISC_NEGATIVE_HORIZ_POLARITY
|
||||
| GRUB_VGA_IO_MISC_UPPER_64K
|
||||
| GRUB_VGA_IO_MISC_EXTERNAL_CLOCK_0
|
||||
| GRUB_VGA_IO_MISC_ENABLE_VRAM_ACCESS
|
||||
| GRUB_VGA_IO_MISC_COLOR, GRUB_VGA_IO_MISC_WRITE);
|
||||
grub_sm712_sr_write (GRUB_VGA_SR_RESET_ASYNC | GRUB_VGA_SR_RESET_SYNC,
|
||||
GRUB_VGA_SR_RESET);
|
||||
grub_sm712_sr_write (GRUB_VGA_SR_CLOCKING_MODE_8_DOT_CLOCK,
|
||||
GRUB_VGA_SR_CLOCKING_MODE);
|
||||
grub_sm712_sr_write (GRUB_VGA_ALL_PLANES, GRUB_VGA_SR_MAP_MASK_REGISTER);
|
||||
grub_sm712_sr_write (0, GRUB_VGA_SR_CHAR_MAP_SELECT);
|
||||
grub_sm712_sr_write (GRUB_VGA_SR_MEMORY_MODE_CHAIN4
|
||||
| GRUB_VGA_SR_MEMORY_MODE_SEQUENTIAL_ADDRESSING
|
||||
| GRUB_VGA_SR_MEMORY_MODE_EXTERNAL_VIDEO_MEMORY,
|
||||
GRUB_VGA_SR_MEMORY_MODE);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE (sm712_sr_seq1); i++)
|
||||
grub_sm712_sr_write (sm712_sr_seq1[i], 0x10 + i);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE (sm712_sr_seq2); i++)
|
||||
grub_sm712_sr_write (sm712_sr_seq2[i], 0x30 + i);
|
||||
|
||||
/* Undocumented. */
|
||||
grub_sm712_sr_write (0x1a, 0x63);
|
||||
/* Undocumented. */
|
||||
grub_sm712_sr_write (0x1a, 0x64);
|
||||
|
||||
grub_sm712_sr_write (GRUB_SM712_SR_TV_CRT_SRAM | GRUB_SM712_SR_TV_ALT_CLOCK
|
||||
| GRUB_SM712_SR_TV_CLOCK_CKIN_NTSC
|
||||
| GRUB_SM712_SR_TV_HSYNC,
|
||||
GRUB_SM712_SR_TV_CONTROL);
|
||||
|
||||
grub_sm712_sr_write (GRUB_SM712_SR_RAM_LUT_NORMAL, GRUB_SM712_SR_RAM_LUT);
|
||||
|
||||
/* Undocumented. */
|
||||
grub_sm712_sr_write (0x00, 0x67);
|
||||
|
||||
grub_sm712_sr_write (GRUB_SM712_SR_CLOCK_CONTROL1_VCLK_FROM_CCR
|
||||
| GRUB_SM712_SR_CLOCK_CONTROL1_8DOT_CLOCK,
|
||||
GRUB_SM712_SR_CLOCK_CONTROL1);
|
||||
grub_sm712_sr_write (GRUB_SM712_SR_CLOCK_CONTROL2_PROGRAM_VCLOCK,
|
||||
GRUB_SM712_SR_CLOCK_CONTROL2);
|
||||
|
||||
grub_sm712_sr_write (82, GRUB_SM712_SR_VCLK_NUM);
|
||||
grub_sm712_sr_write (137, GRUB_SM712_SR_VCLK_DENOM);
|
||||
|
||||
grub_sm712_sr_write (9, GRUB_SM712_SR_VCLK2_NUM);
|
||||
grub_sm712_sr_write (2, GRUB_SM712_SR_VCLK2_DENOM);
|
||||
/* FIXME */
|
||||
grub_sm712_sr_write (0x04, 0x70);
|
||||
/* FIXME */
|
||||
grub_sm712_sr_write (0x45, 0x71);
|
||||
/* Undocumented */
|
||||
grub_sm712_sr_write (0x30, 0x72);
|
||||
/* Undocumented */
|
||||
grub_sm712_sr_write (0x30, 0x73);
|
||||
/* Undocumented */
|
||||
grub_sm712_sr_write (0x40, 0x74);
|
||||
/* Undocumented */
|
||||
grub_sm712_sr_write (0x20, 0x75);
|
||||
|
||||
grub_sm712_sr_write (0xff, GRUB_SM712_SR_POPUP_ICON_LOW);
|
||||
grub_sm712_sr_write (GRUB_SM712_SR_POPUP_ICON_HIGH_MASK,
|
||||
GRUB_SM712_SR_POPUP_ICON_HIGH);
|
||||
grub_sm712_sr_write (GRUB_SM712_SR_POPUP_ICON_CTRL_DISABLED,
|
||||
GRUB_SM712_SR_POPUP_ICON_CTRL);
|
||||
/* Undocumented */
|
||||
grub_sm712_sr_write (0x0, 0x83);
|
||||
|
||||
grub_sm712_sr_write (8, GRUB_SM712_SR_POPUP_ICON_COLOR1);
|
||||
grub_sm712_sr_write (0, GRUB_SM712_SR_POPUP_ICON_COLOR2);
|
||||
grub_sm712_sr_write (0x42, GRUB_SM712_SR_POPUP_ICON_COLOR3);
|
||||
|
||||
/* Undocumented */
|
||||
grub_sm712_sr_write (0x3a, 0x87);
|
||||
|
||||
/* Why theese coordinates? */
|
||||
grub_sm712_sr_write (0x59, GRUB_SM712_SR_HW_CURSOR_UPPER_LEFT_X_LOW);
|
||||
grub_sm712_sr_write (0x02, GRUB_SM712_SR_HW_CURSOR_UPPER_LEFT_X_HIGH);
|
||||
grub_sm712_sr_write (0x44, GRUB_SM712_SR_HW_CURSOR_UPPER_LEFT_Y_LOW);
|
||||
grub_sm712_sr_write (0x02, GRUB_SM712_SR_HW_CURSOR_UPPER_LEFT_Y_HIGH);
|
||||
|
||||
grub_sm712_sr_write (RGB332_BLACK, GRUB_SM712_SR_HW_CURSOR_FG_COLOR);
|
||||
grub_sm712_sr_write (RGB332_WHITE, GRUB_SM712_SR_HW_CURSOR_BG_COLOR);
|
||||
|
||||
/* Undocumented */
|
||||
grub_sm712_sr_write (0x3a, 0x8e);
|
||||
grub_sm712_sr_write (0x3a, 0x8f);
|
||||
|
||||
grub_sm712_sr_write (0, GRUB_SM712_SR_POPUP_ICON_X_LOW);
|
||||
grub_sm712_sr_write (0, GRUB_SM712_SR_POPUP_ICON_X_HIGH);
|
||||
grub_sm712_sr_write (0, GRUB_SM712_SR_POPUP_ICON_Y_LOW);
|
||||
grub_sm712_sr_write (0, GRUB_SM712_SR_POPUP_ICON_Y_HIGH);
|
||||
|
||||
grub_sm712_sr_write (0, GRUB_SM712_SR_PANEL_HW_VIDEO_CONTROL);
|
||||
grub_sm712_sr_write (0x10, GRUB_SM712_SR_PANEL_HW_VIDEO_COLOR_KEY_LOW);
|
||||
grub_sm712_sr_write (0x08, GRUB_SM712_SR_PANEL_HW_VIDEO_COLOR_KEY_HIGH);
|
||||
grub_sm712_sr_write (0x00, GRUB_SM712_SR_PANEL_HW_VIDEO_COLOR_KEY_MASK_LOW);
|
||||
grub_sm712_sr_write (0x02, GRUB_SM712_SR_PANEL_HW_VIDEO_COLOR_KEY_MASK_HIGH);
|
||||
grub_sm712_sr_write (0xed, GRUB_SM712_SR_PANEL_HW_VIDEO_RED_CONSTANT);
|
||||
grub_sm712_sr_write (0xed, GRUB_SM712_SR_PANEL_HW_VIDEO_GREEN_CONSTANT);
|
||||
grub_sm712_sr_write (0xed, GRUB_SM712_SR_PANEL_HW_VIDEO_BLUE_CONSTANT);
|
||||
|
||||
grub_sm712_sr_write (0x7b, GRUB_SM712_SR_PANEL_HW_VIDEO_TOP_BOUNDARY);
|
||||
grub_sm712_sr_write (0xfb, GRUB_SM712_SR_PANEL_HW_VIDEO_LEFT_BOUNDARY);
|
||||
grub_sm712_sr_write (0xff, GRUB_SM712_SR_PANEL_HW_VIDEO_BOTTOM_BOUNDARY);
|
||||
grub_sm712_sr_write (0xff, GRUB_SM712_SR_PANEL_HW_VIDEO_RIGHT_BOUNDARY);
|
||||
/* Doesn't match documentation? */
|
||||
grub_sm712_sr_write (0x97, GRUB_SM712_SR_PANEL_HW_VIDEO_TOP_LEFT_OVERFLOW_BOUNDARY);
|
||||
grub_sm712_sr_write (0xef, GRUB_SM712_SR_PANEL_HW_VIDEO_BOTTOM_RIGHT_OVERFLOW_BOUNDARY);
|
||||
|
||||
grub_sm712_sr_write (0xbf, GRUB_SM712_SR_PANEL_HW_VIDEO_VERTICAL_STRETCH_FACTOR);
|
||||
grub_sm712_sr_write (0xdf, GRUB_SM712_SR_PANEL_HW_VIDEO_HORIZONTAL_STRETCH_FACTOR);
|
||||
|
||||
grub_sm712_gr_write (GRUB_VGA_NO_PLANES, GRUB_VGA_GR_SET_RESET_PLANE);
|
||||
grub_sm712_gr_write (GRUB_VGA_NO_PLANES, GRUB_VGA_GR_SET_RESET_PLANE_ENABLE);
|
||||
grub_sm712_gr_write (GRUB_VGA_NO_PLANES, GRUB_VGA_GR_COLOR_COMPARE);
|
||||
grub_sm712_gr_write (GRUB_VGA_GR_DATA_ROTATE_NOP, GRUB_VGA_GR_DATA_ROTATE);
|
||||
grub_sm712_gr_write (GRUB_VGA_NO_PLANES, GRUB_VGA_GR_READ_MAP_REGISTER);
|
||||
grub_sm712_gr_write (GRUB_VGA_GR_MODE_256_COLOR, GRUB_VGA_GR_MODE);
|
||||
grub_sm712_gr_write (GRUB_VGA_GR_GR6_MMAP_A0
|
||||
| GRUB_VGA_GR_GR6_GRAPHICS_MODE, GRUB_VGA_GR_GR6);
|
||||
grub_sm712_gr_write (GRUB_VGA_ALL_PLANES, GRUB_VGA_GR_COLOR_COMPARE_DISABLE);
|
||||
grub_sm712_gr_write (0xff, GRUB_VGA_GR_BITMASK);
|
||||
|
||||
/* Write palette mapping. */
|
||||
for (i = 0; i < 16; i++)
|
||||
grub_sm712_write_arx (i, i);
|
||||
|
||||
grub_sm712_write_arx (GRUB_VGA_ARX_MODE_ENABLE_256COLOR
|
||||
| GRUB_VGA_ARX_MODE_GRAPHICS, GRUB_VGA_ARX_MODE);
|
||||
grub_sm712_write_arx (0, GRUB_VGA_ARX_OVERSCAN);
|
||||
grub_sm712_write_arx (GRUB_VGA_ALL_PLANES, GRUB_VGA_ARX_COLOR_PLANE_ENABLE);
|
||||
grub_sm712_write_arx (0, GRUB_VGA_ARX_HORIZONTAL_PANNING);
|
||||
grub_sm712_write_arx (0, GRUB_VGA_ARX_COLOR_SELECT);
|
||||
|
||||
/* FIXME: compute this generically. */
|
||||
{
|
||||
struct grub_video_hw_config config =
|
||||
{
|
||||
case 1:
|
||||
*(volatile grub_uint8_t *) ((char *) framebuffer.ptr
|
||||
+ sm712_init[i].addr) = sm712_init[i].val;
|
||||
break;
|
||||
case -1:
|
||||
{
|
||||
grub_uint8_t val = *(volatile grub_uint8_t *)
|
||||
((char *) framebuffer.ptr + sm712_init[i].addr);
|
||||
(void) val;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
*(volatile grub_uint16_t *) ((char *) framebuffer.ptr
|
||||
+ sm712_init[i].addr) = sm712_init[i].val;
|
||||
break;
|
||||
case 4:
|
||||
*(volatile grub_uint32_t *) ((char *) framebuffer.ptr
|
||||
+ sm712_init[i].addr) = sm712_init[i].val;
|
||||
break;
|
||||
}
|
||||
.vertical_total = 806,
|
||||
.vertical_blank_start = 0x300,
|
||||
.vertical_blank_end = 0,
|
||||
.vertical_sync_start = 0x303,
|
||||
.vertical_sync_end = 0x9,
|
||||
.line_compare = 0x3ff,
|
||||
.vdisplay_end = 0x300,
|
||||
.pitch = 0x80,
|
||||
.horizontal_total = 164,
|
||||
.horizontal_end = 128,
|
||||
.horizontal_blank_start = 128,
|
||||
.horizontal_blank_end = 0,
|
||||
.horizontal_sync_pulse_start = 133,
|
||||
.horizontal_sync_pulse_end = 22
|
||||
};
|
||||
grub_vga_set_geometry (&config, grub_sm712_cr_write);
|
||||
config.horizontal_sync_pulse_start = 134;
|
||||
config.horizontal_sync_pulse_end = 21;
|
||||
config.vertical_sync_start = 0x301;
|
||||
config.vertical_sync_end = 0x0;
|
||||
config.line_compare = 0x0ff;
|
||||
config.vdisplay_end = 0x258;
|
||||
config.pitch = 0x7f;
|
||||
grub_vga_set_geometry (&config, grub_sm712_cr_shadow_write);
|
||||
}
|
||||
|
||||
err = grub_video_fb_create_render_target_from_pointer (&framebuffer.render_target, &framebuffer.mode_info, framebuffer.ptr);
|
||||
grub_sm712_cr_write (GRUB_VGA_CR_BYTE_PANNING_NORMAL,
|
||||
GRUB_VGA_CR_BYTE_PANNING);
|
||||
grub_sm712_cr_write (0, GRUB_VGA_CR_CURSOR_START);
|
||||
grub_sm712_cr_write (0, GRUB_VGA_CR_CURSOR_END);
|
||||
grub_sm712_cr_write (0, GRUB_VGA_CR_START_ADDR_HIGH_REGISTER);
|
||||
grub_sm712_cr_write (0, GRUB_VGA_CR_START_ADDR_LOW_REGISTER);
|
||||
grub_sm712_cr_write (0, GRUB_VGA_CR_CURSOR_ADDR_HIGH);
|
||||
grub_sm712_cr_write (0, GRUB_VGA_CR_CURSOR_ADDR_LOW);
|
||||
grub_sm712_cr_write (GRUB_VGA_CR_UNDERLINE_LOCATION_DWORD_MODE,
|
||||
GRUB_VGA_CR_UNDERLINE_LOCATION);
|
||||
grub_sm712_cr_write (GRUB_VGA_CR_MODE_ADDRESS_WRAP
|
||||
| GRUB_VGA_CR_MODE_BYTE_MODE
|
||||
| GRUB_VGA_CR_MODE_TIMING_ENABLE
|
||||
| GRUB_VGA_CR_MODE_NO_CGA
|
||||
| GRUB_VGA_CR_MODE_NO_HERCULES,
|
||||
GRUB_VGA_CR_MODE);
|
||||
|
||||
grub_sm712_cr_write (0, GRUB_SM712_CR_OVERFLOW_INTERLACE);
|
||||
grub_sm712_cr_write (0, GRUB_SM712_CR_INTERLACE_RETRACE);
|
||||
grub_sm712_cr_write (0, GRUB_SM712_CR_TV_VDISPLAY_START);
|
||||
grub_sm712_cr_write (0, GRUB_SM712_CR_TV_VDISPLAY_END_HIGH);
|
||||
grub_sm712_cr_write (0, GRUB_SM712_CR_TV_VDISPLAY_END_LOW);
|
||||
grub_sm712_cr_write (0x80, GRUB_SM712_CR_DDA_CONTROL_LOW);
|
||||
grub_sm712_cr_write (0x02, GRUB_SM712_CR_DDA_CONTROL_HIGH);
|
||||
|
||||
/* Undocumented */
|
||||
grub_sm712_cr_write (0x20, 0x37);
|
||||
|
||||
grub_sm712_cr_write (0, GRUB_SM712_CR_TV_EQUALIZER);
|
||||
grub_sm712_cr_write (0, GRUB_SM712_CR_TV_SERRATION);
|
||||
grub_sm712_cr_write (0, GRUB_SM712_CR_HSYNC_CTRL);
|
||||
|
||||
/* Undocumented */
|
||||
grub_sm712_cr_write (0x40, 0x3b);
|
||||
|
||||
grub_sm712_cr_write (GRUB_SM712_CR_DEBUG_NONE, GRUB_SM712_CR_DEBUG);
|
||||
|
||||
/* Undocumented */
|
||||
grub_sm712_cr_write (0xff, 0x3d);
|
||||
grub_sm712_cr_write (0x46, 0x3e);
|
||||
grub_sm712_cr_write (0x91, 0x3f);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE (dda_lookups); i++)
|
||||
grub_sm712_write_dda_lookup (i, dda_lookups[i].compare, dda_lookups[i].dda,
|
||||
dda_lookups[i].vcentering);
|
||||
|
||||
/* Undocumented */
|
||||
grub_sm712_cr_write (0, 0x9c);
|
||||
grub_sm712_cr_write (0, 0x9d);
|
||||
grub_sm712_cr_write (0, 0x9e);
|
||||
grub_sm712_cr_write (0, 0x9f);
|
||||
|
||||
grub_sm712_cr_write (0, GRUB_SM712_CR_VCENTERING_OFFSET);
|
||||
grub_sm712_cr_write (0, GRUB_SM712_CR_HCENTERING_OFFSET);
|
||||
|
||||
grub_sm712_write_reg (GRUB_VGA_IO_MISC_NEGATIVE_HORIZ_POLARITY
|
||||
| GRUB_VGA_IO_MISC_UPPER_64K
|
||||
| GRUB_VGA_IO_MISC_28MHZ
|
||||
| GRUB_VGA_IO_MISC_ENABLE_VRAM_ACCESS
|
||||
| GRUB_VGA_IO_MISC_COLOR,
|
||||
GRUB_VGA_IO_MISC_WRITE);
|
||||
|
||||
#ifndef TEST
|
||||
/* Undocumented? */
|
||||
*(volatile grub_uint32_t *) ((char *) framebuffer.ptr + 0x40c00c) = 0;
|
||||
*(volatile grub_uint32_t *) ((char *) framebuffer.ptr + 0x40c040) = 0;
|
||||
*(volatile grub_uint32_t *) ((char *) framebuffer.ptr + 0x40c000) = 0x20000;
|
||||
*(volatile grub_uint32_t *) ((char *) framebuffer.ptr + 0x40c010) = 0x1020100;
|
||||
#endif
|
||||
|
||||
(void) grub_sm712_sr_read (0x16);
|
||||
|
||||
#ifndef TEST
|
||||
err = grub_video_fb_create_render_target_from_pointer (&framebuffer
|
||||
.render_target,
|
||||
&framebuffer.mode_info,
|
||||
framebuffer.ptr);
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
|
@ -192,9 +702,12 @@ grub_video_sm712_setup (unsigned int width, unsigned int height,
|
|||
/* Copy default palette to initialize emulated palette. */
|
||||
err = grub_video_fb_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS,
|
||||
grub_video_fbstd_colors);
|
||||
#endif
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifndef TEST
|
||||
|
||||
static grub_err_t
|
||||
grub_video_sm712_swap_buffers (void)
|
||||
{
|
||||
|
@ -223,7 +736,6 @@ grub_video_sm712_get_info_and_fini (struct grub_video_mode_info *mode_info,
|
|||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
static struct grub_video_adapter grub_video_sm712_adapter =
|
||||
{
|
||||
.name = "SM712 Video Driver",
|
||||
|
@ -266,3 +778,10 @@ GRUB_MOD_FINI(video_sm712)
|
|||
{
|
||||
grub_video_unregister (&grub_video_sm712_adapter);
|
||||
}
|
||||
#else
|
||||
int
|
||||
main ()
|
||||
{
|
||||
grub_video_sm712_setup (1024, 600, 0, 0);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,546 +1,14 @@
|
|||
/* Following sequence is a capture of sm712 initialisation sequence. */
|
||||
static struct
|
||||
{
|
||||
int directive;
|
||||
grub_uint32_t addr;
|
||||
grub_uint32_t val;
|
||||
} sm712_init[] =
|
||||
{
|
||||
{1, 0x7003c4, 0x21},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x62},
|
||||
{1, 0x7003c5, 0x7a},
|
||||
{1, 0x7003c4, 0x6a},
|
||||
{1, 0x7003c5, 0x16},
|
||||
{1, 0x7003c4, 0x6b},
|
||||
{1, 0x7003c5, 0x2},
|
||||
{1, 0x7003c6, 0x0},
|
||||
{1, 0x7003c4, 0x0},
|
||||
{1, 0x7003c5, 0x1},
|
||||
{1, 0x7003c2, 0xeb},
|
||||
{1, 0x7003c4, 0x0},
|
||||
{1, 0x7003c5, 0x3},
|
||||
{1, 0x7003c4, 0x1},
|
||||
{1, 0x7003c5, 0x1},
|
||||
{1, 0x7003c4, 0x2},
|
||||
{1, 0x7003c5, 0xf},
|
||||
{1, 0x7003c4, 0x3},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x4},
|
||||
{1, 0x7003c5, 0xe},
|
||||
{1, 0x7003c4, 0x10},
|
||||
{1, 0x7003c5, 0xc8},
|
||||
{1, 0x7003c4, 0x11},
|
||||
{1, 0x7003c5, 0x40},
|
||||
{1, 0x7003c4, 0x12},
|
||||
{1, 0x7003c5, 0x14},
|
||||
{1, 0x7003c4, 0x13},
|
||||
{1, 0x7003c5, 0x60},
|
||||
{1, 0x7003c4, 0x14},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x15},
|
||||
{1, 0x7003c5, 0xa},
|
||||
{1, 0x7003c4, 0x16},
|
||||
{1, 0x7003c5, 0x92},
|
||||
{1, 0x7003c4, 0x17},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x18},
|
||||
{1, 0x7003c5, 0x51},
|
||||
{1, 0x7003c4, 0x19},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x1a},
|
||||
{1, 0x7003c5, 0x1},
|
||||
{1, 0x7003c4, 0x1b},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x1c},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x1d},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x1e},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x1f},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x20},
|
||||
{1, 0x7003c5, 0xc4},
|
||||
{1, 0x7003c4, 0x21},
|
||||
{1, 0x7003c5, 0x30},
|
||||
{1, 0x7003c4, 0x22},
|
||||
{1, 0x7003c5, 0x2},
|
||||
{1, 0x7003c4, 0x23},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x24},
|
||||
{1, 0x7003c5, 0x1},
|
||||
{1, 0x7003c4, 0x30},
|
||||
{1, 0x7003c5, 0x28},
|
||||
{1, 0x7003c4, 0x31},
|
||||
{1, 0x7003c5, 0x3},
|
||||
{1, 0x7003c4, 0x32},
|
||||
{1, 0x7003c5, 0x24},
|
||||
{1, 0x7003c4, 0x33},
|
||||
{1, 0x7003c5, 0x9},
|
||||
{1, 0x7003c4, 0x34},
|
||||
{1, 0x7003c5, 0xc0},
|
||||
{1, 0x7003c4, 0x35},
|
||||
{1, 0x7003c5, 0x3a},
|
||||
{1, 0x7003c4, 0x36},
|
||||
{1, 0x7003c5, 0x3a},
|
||||
{1, 0x7003c4, 0x37},
|
||||
{1, 0x7003c5, 0x3a},
|
||||
{1, 0x7003c4, 0x38},
|
||||
{1, 0x7003c5, 0x3a},
|
||||
{1, 0x7003c4, 0x39},
|
||||
{1, 0x7003c5, 0x3a},
|
||||
{1, 0x7003c4, 0x3a},
|
||||
{1, 0x7003c5, 0x3a},
|
||||
{1, 0x7003c4, 0x3b},
|
||||
{1, 0x7003c5, 0x3a},
|
||||
{1, 0x7003c4, 0x3c},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x3d},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x3e},
|
||||
{1, 0x7003c5, 0x3},
|
||||
{1, 0x7003c4, 0x3f},
|
||||
{1, 0x7003c5, 0xff},
|
||||
{1, 0x7003c4, 0x40},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x41},
|
||||
{1, 0x7003c5, 0xfc},
|
||||
{1, 0x7003c4, 0x42},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x43},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x44},
|
||||
{1, 0x7003c5, 0x20},
|
||||
{1, 0x7003c4, 0x45},
|
||||
{1, 0x7003c5, 0x18},
|
||||
{1, 0x7003c4, 0x46},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x47},
|
||||
{1, 0x7003c5, 0xfc},
|
||||
{1, 0x7003c4, 0x48},
|
||||
{1, 0x7003c5, 0x20},
|
||||
{1, 0x7003c4, 0x49},
|
||||
{1, 0x7003c5, 0xc},
|
||||
{1, 0x7003c4, 0x4a},
|
||||
{1, 0x7003c5, 0x44},
|
||||
{1, 0x7003c4, 0x4b},
|
||||
{1, 0x7003c5, 0x20},
|
||||
{1, 0x7003c4, 0x4c},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x4d},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x4e},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x4f},
|
||||
{1, 0x7003c5, 0x3a},
|
||||
{1, 0x7003c4, 0x50},
|
||||
{1, 0x7003c5, 0x6},
|
||||
{1, 0x7003c4, 0x51},
|
||||
{1, 0x7003c5, 0x68},
|
||||
{1, 0x7003c4, 0x52},
|
||||
{1, 0x7003c5, 0xa7},
|
||||
{1, 0x7003c4, 0x53},
|
||||
{1, 0x7003c5, 0x7f},
|
||||
{1, 0x7003c4, 0x54},
|
||||
{1, 0x7003c5, 0x83},
|
||||
{1, 0x7003c4, 0x55},
|
||||
{1, 0x7003c5, 0x24},
|
||||
{1, 0x7003c4, 0x56},
|
||||
{1, 0x7003c5, 0xff},
|
||||
{1, 0x7003c4, 0x57},
|
||||
{1, 0x7003c5, 0x3},
|
||||
{1, 0x7003c4, 0x58},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x59},
|
||||
{1, 0x7003c5, 0x60},
|
||||
{1, 0x7003c4, 0x5a},
|
||||
{1, 0x7003c5, 0x59},
|
||||
{1, 0x7003c4, 0x5b},
|
||||
{1, 0x7003c5, 0x3a},
|
||||
{1, 0x7003c4, 0x5c},
|
||||
{1, 0x7003c5, 0x3a},
|
||||
{1, 0x7003c4, 0x5d},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x5e},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x5f},
|
||||
{1, 0x7003c5, 0x3a},
|
||||
{1, 0x7003c4, 0x60},
|
||||
{1, 0x7003c5, 0x1},
|
||||
{1, 0x7003c4, 0x61},
|
||||
{1, 0x7003c5, 0x80},
|
||||
{1, 0x7003c4, 0x63},
|
||||
{1, 0x7003c5, 0x1a},
|
||||
{1, 0x7003c4, 0x64},
|
||||
{1, 0x7003c5, 0x1a},
|
||||
{1, 0x7003c4, 0x65},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x66},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x67},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x68},
|
||||
{1, 0x7003c5, 0x50},
|
||||
{1, 0x7003c4, 0x69},
|
||||
{1, 0x7003c5, 0x3},
|
||||
{1, 0x7003c4, 0x6c},
|
||||
{1, 0x7003c5, 0x52},
|
||||
{1, 0x7003c4, 0x6d},
|
||||
{1, 0x7003c5, 0x89},
|
||||
{1, 0x7003c4, 0x6e},
|
||||
{1, 0x7003c5, 0x9},
|
||||
{1, 0x7003c4, 0x6f},
|
||||
{1, 0x7003c5, 0x2},
|
||||
{1, 0x7003c4, 0x70},
|
||||
{1, 0x7003c5, 0x4},
|
||||
{1, 0x7003c4, 0x71},
|
||||
{1, 0x7003c5, 0x45},
|
||||
{1, 0x7003c4, 0x72},
|
||||
{1, 0x7003c5, 0x30},
|
||||
{1, 0x7003c4, 0x73},
|
||||
{1, 0x7003c5, 0x30},
|
||||
{1, 0x7003c4, 0x74},
|
||||
{1, 0x7003c5, 0x40},
|
||||
{1, 0x7003c4, 0x75},
|
||||
{1, 0x7003c5, 0x20},
|
||||
{1, 0x7003c4, 0x80},
|
||||
{1, 0x7003c5, 0xff},
|
||||
{1, 0x7003c4, 0x81},
|
||||
{1, 0x7003c5, 0x7},
|
||||
{1, 0x7003c4, 0x82},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x83},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x84},
|
||||
{1, 0x7003c5, 0x8},
|
||||
{1, 0x7003c4, 0x85},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x86},
|
||||
{1, 0x7003c5, 0x42},
|
||||
{1, 0x7003c4, 0x87},
|
||||
{1, 0x7003c5, 0x3a},
|
||||
{1, 0x7003c4, 0x88},
|
||||
{1, 0x7003c5, 0x59},
|
||||
{1, 0x7003c4, 0x89},
|
||||
{1, 0x7003c5, 0x2},
|
||||
{1, 0x7003c4, 0x8a},
|
||||
{1, 0x7003c5, 0x44},
|
||||
{1, 0x7003c4, 0x8b},
|
||||
{1, 0x7003c5, 0x2},
|
||||
{1, 0x7003c4, 0x8c},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x8d},
|
||||
{1, 0x7003c5, 0xff},
|
||||
{1, 0x7003c4, 0x8e},
|
||||
{1, 0x7003c5, 0x3a},
|
||||
{1, 0x7003c4, 0x8f},
|
||||
{1, 0x7003c5, 0x3a},
|
||||
{1, 0x7003c4, 0x90},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x91},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x92},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0x93},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0xa0},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0xa1},
|
||||
{1, 0x7003c5, 0x10},
|
||||
{1, 0x7003c4, 0xa2},
|
||||
{1, 0x7003c5, 0x8},
|
||||
{1, 0x7003c4, 0xa3},
|
||||
{1, 0x7003c5, 0x0},
|
||||
{1, 0x7003c4, 0xa4},
|
||||
{1, 0x7003c5, 0x2},
|
||||
{1, 0x7003c4, 0xa5},
|
||||
{1, 0x7003c5, 0xed},
|
||||
{1, 0x7003c4, 0xa6},
|
||||
{1, 0x7003c5, 0xed},
|
||||
{1, 0x7003c4, 0xa7},
|
||||
{1, 0x7003c5, 0xed},
|
||||
{1, 0x7003c4, 0xa8},
|
||||
{1, 0x7003c5, 0x7b},
|
||||
{1, 0x7003c4, 0xa9},
|
||||
{1, 0x7003c5, 0xfb},
|
||||
{1, 0x7003c4, 0xaa},
|
||||
{1, 0x7003c5, 0xff},
|
||||
{1, 0x7003c4, 0xab},
|
||||
{1, 0x7003c5, 0xff},
|
||||
{1, 0x7003c4, 0xac},
|
||||
{1, 0x7003c5, 0x97},
|
||||
{1, 0x7003c4, 0xad},
|
||||
{1, 0x7003c5, 0xef},
|
||||
{1, 0x7003c4, 0xae},
|
||||
{1, 0x7003c5, 0xbf},
|
||||
{1, 0x7003c4, 0xaf},
|
||||
{1, 0x7003c5, 0xdf},
|
||||
{1, 0x7003ce, 0x0},
|
||||
{1, 0x7003cf, 0x0},
|
||||
{1, 0x7003ce, 0x1},
|
||||
{1, 0x7003cf, 0x0},
|
||||
{1, 0x7003ce, 0x2},
|
||||
{1, 0x7003cf, 0x0},
|
||||
{1, 0x7003ce, 0x3},
|
||||
{1, 0x7003cf, 0x0},
|
||||
{1, 0x7003ce, 0x4},
|
||||
{1, 0x7003cf, 0x0},
|
||||
{1, 0x7003ce, 0x5},
|
||||
{1, 0x7003cf, 0x40},
|
||||
{1, 0x7003ce, 0x6},
|
||||
{1, 0x7003cf, 0x5},
|
||||
{1, 0x7003ce, 0x7},
|
||||
{1, 0x7003cf, 0xf},
|
||||
{1, 0x7003ce, 0x8},
|
||||
{1, 0x7003cf, 0xff},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0x0},
|
||||
{-1, 0x7003c1, 0x3e},
|
||||
{1, 0x7003c0, 0x0},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0x1},
|
||||
{-1, 0x7003c1, 0x3b},
|
||||
{1, 0x7003c0, 0x1},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0x2},
|
||||
{-1, 0x7003c1, 0x3f},
|
||||
{1, 0x7003c0, 0x2},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0x3},
|
||||
{-1, 0x7003c1, 0x3f},
|
||||
{1, 0x7003c0, 0x3},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0x4},
|
||||
{-1, 0x7003c1, 0x3b},
|
||||
{1, 0x7003c0, 0x4},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0x5},
|
||||
{-1, 0x7003c1, 0x2f},
|
||||
{1, 0x7003c0, 0x5},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0x6},
|
||||
{-1, 0x7003c1, 0x3f},
|
||||
{1, 0x7003c0, 0x6},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0x7},
|
||||
{-1, 0x7003c1, 0x3f},
|
||||
{1, 0x7003c0, 0x7},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0x8},
|
||||
{-1, 0x7003c1, 0x3f},
|
||||
{1, 0x7003c0, 0x8},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0x9},
|
||||
{-1, 0x7003c1, 0x3d},
|
||||
{1, 0x7003c0, 0x9},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0xa},
|
||||
{-1, 0x7003c1, 0x1f},
|
||||
{1, 0x7003c0, 0xa},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0xb},
|
||||
{-1, 0x7003c1, 0x1f},
|
||||
{1, 0x7003c0, 0xb},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0xc},
|
||||
{-1, 0x7003c1, 0x3f},
|
||||
{1, 0x7003c0, 0xc},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0xd},
|
||||
{-1, 0x7003c1, 0x3f},
|
||||
{1, 0x7003c0, 0xd},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0xe},
|
||||
{-1, 0x7003c1, 0x3f},
|
||||
{1, 0x7003c0, 0xe},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0xf},
|
||||
{-1, 0x7003c1, 0x2e},
|
||||
{1, 0x7003c0, 0xf},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0x10},
|
||||
{-1, 0x7003c1, 0x0},
|
||||
{1, 0x7003c0, 0x41},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0x11},
|
||||
{-1, 0x7003c1, 0x0},
|
||||
{1, 0x7003c0, 0x0},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0x12},
|
||||
{-1, 0x7003c1, 0x0},
|
||||
{1, 0x7003c0, 0xf},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0x13},
|
||||
{-1, 0x7003c1, 0x0},
|
||||
{1, 0x7003c0, 0x0},
|
||||
{-1, 0x7003da, 0x5},
|
||||
{1, 0x7003c0, 0x14},
|
||||
{-1, 0x7003c1, 0x0},
|
||||
{1, 0x7003c0, 0x0},
|
||||
{1, 0x7003d4, 0x0},
|
||||
{1, 0x7003d5, 0xa3},
|
||||
{1, 0x7003d4, 0x1},
|
||||
{1, 0x7003d5, 0x7f},
|
||||
{1, 0x7003d4, 0x2},
|
||||
{1, 0x7003d5, 0x7f},
|
||||
{1, 0x7003d4, 0x3},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0x4},
|
||||
{1, 0x7003d5, 0x85},
|
||||
{1, 0x7003d4, 0x5},
|
||||
{1, 0x7003d5, 0x16},
|
||||
{1, 0x7003d4, 0x6},
|
||||
{1, 0x7003d5, 0x24},
|
||||
{1, 0x7003d4, 0x7},
|
||||
{1, 0x7003d5, 0xf5},
|
||||
{1, 0x7003d4, 0x8},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0x9},
|
||||
{1, 0x7003d5, 0x60},
|
||||
{1, 0x7003d4, 0xa},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0xb},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0xc},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0xd},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0xe},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0xf},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0x10},
|
||||
{1, 0x7003d5, 0x3},
|
||||
{1, 0x7003d4, 0x11},
|
||||
{1, 0x7003d5, 0x9},
|
||||
{1, 0x7003d4, 0x12},
|
||||
{1, 0x7003d5, 0xff},
|
||||
{1, 0x7003d4, 0x13},
|
||||
{1, 0x7003d5, 0x80},
|
||||
{1, 0x7003d4, 0x14},
|
||||
{1, 0x7003d5, 0x40},
|
||||
{1, 0x7003d4, 0x15},
|
||||
{1, 0x7003d5, 0xff},
|
||||
{1, 0x7003d4, 0x16},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0x17},
|
||||
{1, 0x7003d5, 0xe3},
|
||||
{1, 0x7003d4, 0x18},
|
||||
{1, 0x7003d5, 0xff},
|
||||
{1, 0x7003d4, 0x30},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0x31},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0x32},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0x33},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0x34},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0x35},
|
||||
{1, 0x7003d5, 0x80},
|
||||
{1, 0x7003d4, 0x36},
|
||||
{1, 0x7003d5, 0x2},
|
||||
{1, 0x7003d4, 0x37},
|
||||
{1, 0x7003d5, 0x20},
|
||||
{1, 0x7003d4, 0x38},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0x39},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0x3a},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0x3b},
|
||||
{1, 0x7003d5, 0x40},
|
||||
{1, 0x7003d4, 0x3c},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0x3d},
|
||||
{1, 0x7003d5, 0xff},
|
||||
{1, 0x7003d4, 0x3e},
|
||||
{1, 0x7003d5, 0x46},
|
||||
{1, 0x7003d4, 0x3f},
|
||||
{1, 0x7003d5, 0x91},
|
||||
{1, 0x7003d4, 0x40},
|
||||
{1, 0x7003d5, 0xa3},
|
||||
{1, 0x7003d4, 0x41},
|
||||
{1, 0x7003d5, 0x7f},
|
||||
{1, 0x7003d4, 0x42},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0x43},
|
||||
{1, 0x7003d5, 0x86},
|
||||
{1, 0x7003d4, 0x44},
|
||||
{1, 0x7003d5, 0x15},
|
||||
{1, 0x7003d4, 0x45},
|
||||
{1, 0x7003d5, 0x24},
|
||||
{1, 0x7003d4, 0x46},
|
||||
{1, 0x7003d5, 0xff},
|
||||
{1, 0x7003d4, 0x47},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0x48},
|
||||
{1, 0x7003d5, 0x1},
|
||||
{1, 0x7003d4, 0x49},
|
||||
{1, 0x7003d5, 0x7},
|
||||
{1, 0x7003d4, 0x4a},
|
||||
{1, 0x7003d5, 0xe5},
|
||||
{1, 0x7003d4, 0x4b},
|
||||
{1, 0x7003d5, 0x20},
|
||||
{1, 0x7003d4, 0x4c},
|
||||
{1, 0x7003d5, 0x7f},
|
||||
{1, 0x7003d4, 0x4d},
|
||||
{1, 0x7003d5, 0x57},
|
||||
{1, 0x7003d4, 0x90},
|
||||
{1, 0x7003d5, 0x55},
|
||||
{1, 0x7003d4, 0x91},
|
||||
{1, 0x7003d5, 0xd5},
|
||||
{1, 0x7003d4, 0x92},
|
||||
{1, 0x7003d5, 0x5d},
|
||||
{1, 0x7003d4, 0x93},
|
||||
{1, 0x7003d5, 0xdd},
|
||||
{1, 0x7003d4, 0x94},
|
||||
{1, 0x7003d5, 0x86},
|
||||
{1, 0x7003d4, 0x95},
|
||||
{1, 0x7003d5, 0x17},
|
||||
{1, 0x7003d4, 0x96},
|
||||
{1, 0x7003d5, 0x8e},
|
||||
{1, 0x7003d4, 0x97},
|
||||
{1, 0x7003d5, 0xaa},
|
||||
{1, 0x7003d4, 0x98},
|
||||
{1, 0x7003d5, 0x8a},
|
||||
{1, 0x7003d4, 0x99},
|
||||
{1, 0x7003d5, 0xa3},
|
||||
{1, 0x7003d4, 0x9a},
|
||||
{1, 0x7003d5, 0xde},
|
||||
{1, 0x7003d4, 0x9b},
|
||||
{1, 0x7003d5, 0xab},
|
||||
{1, 0x7003d4, 0x9c},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0x9d},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0x9e},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0x9f},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0xa0},
|
||||
{1, 0x7003d5, 0x2},
|
||||
{1, 0x7003d4, 0xa1},
|
||||
{1, 0x7003d5, 0x2},
|
||||
{1, 0x7003d4, 0xa2},
|
||||
{1, 0x7003d5, 0x2},
|
||||
{1, 0x7003d4, 0xa3},
|
||||
{1, 0x7003d5, 0x15},
|
||||
{1, 0x7003d4, 0xa4},
|
||||
{1, 0x7003d5, 0x2},
|
||||
{1, 0x7003d4, 0xa5},
|
||||
{1, 0x7003d5, 0x6},
|
||||
{1, 0x7003d4, 0xa6},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003d4, 0xa7},
|
||||
{1, 0x7003d5, 0x0},
|
||||
{1, 0x7003c2, 0x67},
|
||||
{4, 0x40c00c, 0x0},
|
||||
{4, 0x40c040, 0x0},
|
||||
{4, 0x40c000, 0x20000},
|
||||
{4, 0x40c010, 0x1020100},
|
||||
{1, 0x7003c4, 0x16},
|
||||
{-1, 0x7003c5, 0x17}
|
||||
};
|
||||
static grub_uint8_t sm712_sr_seq1[] =
|
||||
{ 0xc8, 0x40, 0x14, 0x60, 0x0, 0xa, 0x92, 0x0,
|
||||
0x51, 0x00, 0x01, 0x00, 0x0, 0x0, 0x00, 0x0,
|
||||
0xc4, 0x30, 0x02, 0x00, 0x1 };
|
||||
|
||||
static grub_uint8_t sm712_sr_seq2[] =
|
||||
{ 0x28, 0x03, 0x24, 0x09, 0xc0, 0x3a, 0x3a, 0x3a,
|
||||
0x3a, 0x3a, 0x3a, 0x3a, 0x00, 0x00, 0x03, 0xff,
|
||||
0x00, 0xfc, 0x00, 0x00, 0x20, 0x18, 0x00, 0xfc,
|
||||
0x20, 0x0c, 0x44, 0x20, 0x00, 0x00, 0x00, 0x3a,
|
||||
0x06, 0x68, 0xa7, 0x7f, 0x83, 0x24, 0xff, 0x03,
|
||||
0x00, 0x60, 0x59, 0x3a, 0x3a, 0x00, 0x00, 0x3a,
|
||||
0x01, 0x80 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue