예제 #1
0
파일: init.c 프로젝트: flihp/grub2
void
grub_machine_get_bootlocation (char **device, char **path)
{
  grub_efi_loaded_image_t *image = NULL;
  char *p;

  image = grub_efi_get_loaded_image (grub_efi_image_handle);
  if (!image)
    return;
  *device = grub_efidisk_get_device_name (image->device_handle);
  if (!*device && grub_efi_net_config)
    {
      grub_efi_net_config (image->device_handle, device, path);
      return;
    }

  *path = grub_efi_get_filename (image->file_path);
  if (*path)
    {
      /* Get the directory.  */
      p = grub_strrchr (*path, '/');
      if (p)
        *p = '\0';
    }
}
예제 #2
0
void
grub_efi_set_prefix (void)
{
  grub_efi_loaded_image_t *image = NULL;
  char *device = NULL;
  char *path = NULL;

  {
    char *pptr = NULL;
    if (grub_prefix[0] == '(')
      {
	pptr = grub_strrchr (grub_prefix, ')');
	if (pptr)
	  {
	    device = grub_strndup (grub_prefix + 1, pptr - grub_prefix - 1);
	    pptr++;
	  }
      }
    if (!pptr)
      pptr = grub_prefix;
    if (pptr[0])
      path = grub_strdup (pptr);
  }

  if (!device || !path)
    image = grub_efi_get_loaded_image (grub_efi_image_handle);
  if (image && !device)
    device = grub_efidisk_get_device_name (image->device_handle);

  if (image && !path)
    {
      char *p;

      path = grub_efi_get_filename (image->file_path);

      /* Get the directory.  */
      p = grub_strrchr (path, '/');
      if (p)
	*p = '\0';
    }

  if (device && path)
    {
      char *prefix;

      prefix = grub_xasprintf ("(%s)%s", device, path);
      if (prefix)
	{
	  grub_env_set ("prefix", prefix);
	  grub_free (prefix);
	}
    }

  grub_free (device);
  grub_free (path);
}
예제 #3
0
파일: efi.c 프로젝트: Arvian/GRUB2
/* Search the mods section from the PE32/PE32+ image. This code uses
   a PE32 header, but should work with PE32+ as well.  */
grub_addr_t
grub_efi_modules_addr (void)
{
  grub_efi_loaded_image_t *image;
  struct grub_pe32_header *header;
  struct grub_pe32_coff_header *coff_header;
  struct grub_pe32_section_table *sections;
  struct grub_pe32_section_table *section;
  struct grub_module_info *info;
  grub_uint16_t i;

  image = grub_efi_get_loaded_image (grub_efi_image_handle);
  if (! image)
    return 0;

  header = image->image_base;
  coff_header = &(header->coff_header);
  sections
    = (struct grub_pe32_section_table *) ((char *) coff_header
					  + sizeof (*coff_header)
					  + coff_header->optional_header_size);

  for (i = 0, section = sections;
       i < coff_header->num_sections;
       i++, section++)
    {
      if (grub_strcmp (section->name, "mods") == 0)
	break;
    }

  if (i == coff_header->num_sections)
    return 0;

  info = (struct grub_module_info *) ((char *) image->image_base
				      + section->virtual_address);
  if (info->magic != GRUB_MODULE_MAGIC)
    return 0;

  return (grub_addr_t) info;
}
예제 #4
0
파일: init.c 프로젝트: Firef0x/burg-new
void
grub_efi_set_prefix (void)
{
  grub_efi_loaded_image_t *image;

  image = grub_efi_get_loaded_image (grub_efi_image_handle);
  if (image)
    {
      char *device;
      char *file;
      char *prefix;

      device = grub_efidisk_get_device_name (image->device_handle);
      file = grub_efi_get_filename (image->file_path);

      if (file)
        {
          char *p;

          /* Get the directory.  */
          p = grub_strrchr (file, '/');
          if (p)
            *p = '\0';
        }

      prefix = grub_xasprintf ("(%s)%s", (device) ? device : "net0",
			       (file) ? file : "");

      if (prefix)
        {
          grub_env_set ("prefix", prefix);
          grub_free (prefix);
        }
      grub_free (device);
      grub_free (file);
    }
}
예제 #5
0
static grub_err_t
grub_cmd_appleloader (grub_command_t cmd __attribute__ ((unused)),
                      int argc, char *argv[])
{
  grub_efi_boot_services_t *b;
  grub_efi_loaded_image_t *loaded_image;
  struct devdata *pdev;

  grub_dl_ref (my_mod);

  /* Initialize some global variables.  */
  image_handle = 0;

  b = grub_efi_system_table->boot_services;

  for (pdev = devs ; pdev->devpath ; pdev++)
    if (efi_call_6 (b->load_image, 0, grub_efi_image_handle, pdev->devpath,
                    NULL, 0, &image_handle) == GRUB_EFI_SUCCESS)
      break;

  if (! pdev->devpath)
    {
      grub_error (GRUB_ERR_BAD_OS, "can't find model");
      goto fail;
    }

  grub_dprintf ("appleload", "Model: %s\n", pdev->model);

  loaded_image = grub_efi_get_loaded_image (image_handle);
  if (! loaded_image)
    {
      grub_error (GRUB_ERR_BAD_OS, "no loaded image available");
      goto fail;
    }

  if (argc > 0)
    {
      int i, len;
      grub_efi_char16_t *p16;

      for (i = 0, len = 0; i < argc; i++)
        len += grub_strlen (argv[i]) + 1;

      len *= sizeof (grub_efi_char16_t);
      cmdline = p16 = grub_malloc (len);
      if (! cmdline)
        goto fail;

      for (i = 0; i < argc; i++)
        {
          char *p8;

          p8 = argv[i];
          while (*p8)
            *(p16++) = *(p8++);

          *(p16++) = ' ';
        }
      *(--p16) = 0;

      loaded_image->load_options = cmdline;
      loaded_image->load_options_size = len;
    }

  grub_loader_set (grub_appleloader_boot, grub_appleloader_unload, 0);

  return 0;

 fail:

  grub_dl_unref (my_mod);
  return grub_errno;
}