コード例 #1
0
ファイル: ieee1275.c プロジェクト: remfalc/vyt-vyatta-grub
static grub_err_t
grub_video_ieee1275_fill_mode_info (grub_ieee1275_phandle_t dev,
				    struct grub_video_mode_info *out)
{
  grub_uint32_t tmp;

  grub_memset (out, 0, sizeof (*out));

  if (grub_ieee1275_get_integer_property (dev, "width", &tmp,
					  sizeof (tmp), 0))
    return grub_error (GRUB_ERR_IO, "Couldn't retrieve display width.");
  out->width = tmp;

  if (grub_ieee1275_get_integer_property (dev, "height", &tmp,
					  sizeof (tmp), 0))
    return grub_error (GRUB_ERR_IO, "Couldn't retrieve display height.");
  out->height = tmp;

  if (grub_ieee1275_get_integer_property (dev, "linebytes", &tmp,
					  sizeof (tmp), 0))
    return grub_error (GRUB_ERR_IO, "Couldn't retrieve display pitch.");
  out->pitch = tmp;

  out->mode_type = GRUB_VIDEO_MODE_TYPE_INDEX_COLOR;
  out->bpp = 8;
  out->bytes_per_pixel = 1;
  out->number_of_colors = 256;

  out->blit_format = grub_video_get_blit_format (out);
  return GRUB_ERR_NONE;
}
コード例 #2
0
ファイル: cmain.c プロジェクト: kphillisjr/burg
void
grub_ieee1275_init (void)
{
    grub_ieee1275_finddevice ("/chosen", &grub_ieee1275_chosen);

    if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen, "mmu", &grub_ieee1275_mmu,
                                            sizeof grub_ieee1275_mmu, 0) < 0)
        grub_ieee1275_mmu = 0;

    grub_ieee1275_find_options ();
}
コード例 #3
0
ファイル: ofnet.c プロジェクト: pendor/grub-zfs
static void
grub_ofnet_findcards (void)
{
  auto int search_net_devices (struct grub_ieee1275_devalias *alias);

  int search_net_devices (struct grub_ieee1275_devalias *alias)
  {
    if (!grub_strcmp (alias->type, "network"))
      {
	struct grub_ofnetcard_data *ofdata;
	struct grub_net_card *card;
	grub_ieee1275_phandle_t devhandle;
	grub_net_link_level_address_t lla;
	char *shortname;

	ofdata = grub_malloc (sizeof (struct grub_ofnetcard_data));
	if (!ofdata)
	  {
	    grub_print_error ();
	    return 1;
	  }
	card = grub_zalloc (sizeof (struct grub_net_card));
	if (!card)
	  {
	    grub_free (ofdata);
	    grub_print_error ();
	    return 1;
	  }

	ofdata->path = grub_strdup (alias->path);

	grub_ieee1275_finddevice (ofdata->path, &devhandle);

	if (grub_ieee1275_get_integer_property
	    (devhandle, "max-frame-size", &(ofdata->mtu),
	     sizeof (ofdata->mtu), 0))
	  {
	    ofdata->mtu = 1500;
	  }

	if (grub_ieee1275_get_property (devhandle, "mac-address",
					&(lla.mac), 6, 0)
	    && grub_ieee1275_get_property (devhandle, "local-mac-address",
					   &(lla.mac), 6, 0))
	  {
	    grub_error (GRUB_ERR_IO, "Couldn't retrieve mac address.");
	    grub_print_error ();
	    return 0;
	  }

	lla.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
	card->default_address = lla;

	card->driver = NULL;
	card->data = ofdata;
	card->flags = 0;
	shortname = find_alias (alias->path);
	card->name = grub_xasprintf ("ofnet_%s", shortname ? : alias->path);
	card->idle_poll_delay_ms = 1;
	grub_free (shortname);

	card->driver = &ofdriver;
	grub_net_card_register (card);
	return 0;
      }
    return 0;
  }

  /* Look at all nodes for devices of the type network.  */
  grub_ieee1275_devices_iterate (search_net_devices);
}
コード例 #4
0
ファイル: cmain.c プロジェクト: kphillisjr/burg
static void
grub_ieee1275_find_options (void)
{
    grub_ieee1275_phandle_t root;
    grub_ieee1275_phandle_t options;
    grub_ieee1275_phandle_t openprom;
    grub_ieee1275_phandle_t bootrom;
    int rc;
    grub_uint32_t realmode = 0;
    char tmp[32];
    int is_smartfirmware = 0;
    int is_olpc = 0;
    int is_qemu = 0;

#ifdef __sparc__
    grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0);
#endif

    grub_ieee1275_finddevice ("/", &root);
    grub_ieee1275_finddevice ("/options", &options);
    grub_ieee1275_finddevice ("/openprom", &openprom);

    rc = grub_ieee1275_get_integer_property (options, "real-mode?", &realmode,
            sizeof realmode, 0);
    if (((rc >= 0) && realmode) || (grub_ieee1275_mmu == 0))
        grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_REAL_MODE);

    rc = grub_ieee1275_get_property (openprom, "CodeGen-copyright",
                                     tmp,	sizeof (tmp), 0);
    if (rc >= 0 && !grub_strncmp (tmp, SF, sizeof (SF) - 1))
        is_smartfirmware = 1;

    rc = grub_ieee1275_get_property (root, "architecture",
                                     tmp,	sizeof (tmp), 0);
    if (rc >= 0 && !grub_strcmp (tmp, "OLPC"))
        is_olpc = 1;

    rc = grub_ieee1275_get_property (root, "model",
                                     tmp,	sizeof (tmp), 0);
    if (rc >= 0 && !grub_strcmp (tmp, "Emulated PC"))
        is_qemu = 1;

    if (rc >= 0 && grub_strncmp (tmp, "IBM", 3) == 0)
        grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS);

    if (grub_strncmp (tmp, "PowerMac", sizeof ("PowerMac") - 1) == 0)
        grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS);

    if (is_smartfirmware)
    {
        /* Broken in all versions */
        grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_OUTPUT);

        /* There are two incompatible ways of checking the version number.  Try
           both. */
        rc = grub_ieee1275_get_property (openprom, "SmartFirmware-version",
                                         tmp, sizeof (tmp), 0);
        if (rc < 0)
            rc = grub_ieee1275_get_property (openprom, "firmware-version",
                                             tmp, sizeof (tmp), 0);
        if (rc >= 0)
        {
            /* It is tempting to implement a version parser to set the flags for
               e.g. 1.3 and below.  However, there's a special situation here.
               3rd party updates which fix the partition bugs are common, and for
               some reason their fixes aren't being merged into trunk.  So for
               example we know that 1.2 and 1.3 are broken, but there's 1.2.99
               and 1.3.99 which are known good (and applying this workaround
               would cause breakage). */
            if (!grub_strcmp (tmp, "1.0")
                    || !grub_strcmp (tmp, "1.1")
                    || !grub_strcmp (tmp, "1.2")
                    || !grub_strcmp (tmp, "1.3"))
            {
                grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0);
                grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS);
            }
        }
    }

    if (is_olpc)
    {
        /* OLPC / XO laptops have three kinds of storage devices:

        - NAND flash.  These are accessible via OFW callbacks, but:
           - Follow strange semantics, imposed by hardware constraints.
           - Its ABI is undocumented, and not stable.
           They lack "device_type" property, which conveniently makes GRUB
           skip them.

         - USB drives.  Not accessible, because OFW shuts down the controller
           in order to prevent collisions with applications accessing it
           directly.  Even worse, attempts to access it will NOT return
           control to the caller, so we have to avoid probing them.

         - SD cards.  These work fine.

         To avoid breakage, we only need to skip USB probing.  However,
         since detecting SD cards is more reliable, we do that instead.
            */

        grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_OFDISK_SDCARD_ONLY);
        grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_HAS_CURSORONOFF);
    }

    if (is_qemu)
    {
        /* OpenFirmware hangs on qemu if one requests any memory below 1.5 MiB.  */
        grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM);

        grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_HAS_CURSORONOFF);
    }

    if (! grub_ieee1275_finddevice ("/rom/boot-rom", &bootrom))
    {
        rc = grub_ieee1275_get_property (bootrom, "model", tmp, sizeof (tmp), 0);
        if (rc >= 0 && !grub_strncmp (tmp, OHW, sizeof (OHW) - 1))
        {
            grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_OUTPUT);
            grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CANNOT_SET_COLORS);
            grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CANNOT_INTERPRET);
            grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_FORCE_CLAIM);
            grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_ANSI);
        }
    }
}
コード例 #5
0
ファイル: mmap.c プロジェクト: Firef0x/burg-new
grub_err_t
grub_machine_mmap_iterate (int (*hook) (grub_uint64_t, grub_uint64_t,
					grub_uint32_t, void *closure),
			   void *closure)
{
  grub_ieee1275_phandle_t root;
  grub_ieee1275_phandle_t memory;
  grub_uint32_t available[32];
  grub_ssize_t available_size;
  grub_uint32_t address_cells = 1;
  grub_uint32_t size_cells = 1;
  char copyright[128];
  int i;

  /* Determine the format of each entry in `available'.  */
  grub_ieee1275_finddevice ("/", &root);
  grub_ieee1275_get_integer_property (root, "#address-cells", &address_cells,
				      sizeof address_cells, 0);
  grub_ieee1275_get_integer_property (root, "#size-cells", &size_cells,
				      sizeof size_cells, 0);

  grub_ieee1275_get_property (root, "copyright", copyright,
			      sizeof copyright, 0);

  if (size_cells > address_cells)
    address_cells = size_cells;

  /* Apple ppc g4, g5 /memory/available[] uses 32bit offset and size,
     including for >4GB fitted RAM,
     and does not use root cell sizes. Maybe some other ieee1275 Apple
     uses 64bit offset and size? */
  if (grub_strstr (copyright, "Apple"))
    address_cells = size_cells;

  /* Load `/memory/available'.  */
  if (grub_ieee1275_finddevice ("/memory", &memory))
    return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
		       "couldn't find /memory node");
  if (grub_ieee1275_get_integer_property (memory, "available", available,
					  sizeof available, &available_size))
    return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
		       "couldn't examine /memory/available property");

  /* Decode each entry and call `hook'.  */
  i = 0;
  available_size /= sizeof (grub_uint32_t);
  while (i < available_size)
    {
      grub_uint64_t address;
      grub_uint64_t size;

      address = available[i++];
      if (address_cells == 2)
	address = (address << 32) | available[i++];

      size = available[i++];
      if (size_cells == 2)
	size = (size << 32) | available[i++];

      if (hook (address, size, GRUB_MACHINE_MEMORY_AVAILABLE, closure))
	break;
    }

  return grub_errno;
}
コード例 #6
0
ファイル: ieee1275.c プロジェクト: remfalc/vyt-vyatta-grub
static grub_err_t
grub_video_ieee1275_setup (unsigned int width, unsigned int height,
			   unsigned int mode_type __attribute__ ((unused)),
			   unsigned int mode_mask __attribute__ ((unused)))
{
  grub_uint32_t current_width, current_height, address;
  grub_err_t err;
  grub_ieee1275_phandle_t dev;

  if (!display)
    return grub_error (GRUB_ERR_IO, "Couldn't find display device.");

  if (grub_ieee1275_finddevice (display, &dev))
    return grub_error (GRUB_ERR_IO, "Couldn't open display device.");

  if (grub_ieee1275_get_integer_property (dev, "width", &current_width,
					  sizeof (current_width), 0))
    return grub_error (GRUB_ERR_IO, "Couldn't retrieve display width.");

  if (grub_ieee1275_get_integer_property (dev, "height", &current_height,
					  sizeof (current_width), 0))
    return grub_error (GRUB_ERR_IO, "Couldn't retrieve display height.");

  if ((width == current_width && height == current_height)
      || (width == 0 && height == 0))
    {
      grub_dprintf ("video", "IEEE1275: keeping current mode %dx%d\n",
		    current_width, current_height);
    }
  else
    {
      grub_dprintf ("video", "IEEE1275: Setting mode %dx%d\n", width, height);
      /* TODO. */
      return grub_error (GRUB_ERR_IO, "can't set mode %dx%d", width, height);
    }
  
  err = grub_video_ieee1275_fill_mode_info (dev, &framebuffer.mode_info);
  if (err)
    {
      grub_dprintf ("video", "IEEE1275: couldn't fill mode info\n");
      return err;
    }

  if (grub_ieee1275_get_integer_property (dev, "address", (void *) &address,
					  sizeof (address), 0))
    return grub_error (GRUB_ERR_IO, "Couldn't retrieve display address.");

  /* For some reason sparc64 uses 32-bit pointer too.  */
  framebuffer.ptr = (void *) (grub_addr_t) address;

  grub_video_ieee1275_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS,
				   grub_video_fbstd_colors);

  grub_dprintf ("video", "IEEE1275: initialising FB @ %p %dx%dx%d\n",
		framebuffer.ptr, framebuffer.mode_info.width,
		framebuffer.mode_info.height, framebuffer.mode_info.bpp);
  
  err = grub_video_fb_create_render_target_from_pointer 
    (&framebuffer.render_target, &framebuffer.mode_info, framebuffer.ptr);

  if (err)
    {
      grub_dprintf ("video", "IEEE1275: Couldn't create FB target\n");
      return err;
    }
  
  err = grub_video_fb_set_active_render_target (framebuffer.render_target);
  
  if (err)
    {
      grub_dprintf ("video", "IEEE1275: Couldn't set FB target\n");
      return err;
    }
  
  err = grub_video_fb_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS,
				   grub_video_fbstd_colors);

  if (err)
    grub_dprintf ("video", "IEEE1275: Couldn't set palette\n");
  else
    grub_dprintf ("video", "IEEE1275: Success\n");
  
  return err;
}