Esempio n. 1
0
static int
iterate_device (const char *name, void *data)
{
  struct search_ctx *ctx = data;
  char *cur_uuid;

  if (get_uuid (name, &cur_uuid, 1))
    {
      if (grub_errno == GRUB_ERR_UNKNOWN_FS)
	grub_errno = 0;
      grub_print_error ();
      return 0;
    }

  grub_dprintf ("nativedisk", "checking %s: %s\n", name,
		cur_uuid);
  if (ctx->prefix_uuid && grub_strcasecmp (cur_uuid, ctx->prefix_uuid) == 0)
    {
      char *prefix;
      prefix = grub_xasprintf ("(%s)/%s", name, ctx->prefix_path);
      grub_env_set ("prefix", prefix);
      grub_free (prefix);
      ctx->prefix_found = 1;
    }
  if (ctx->root_uuid && grub_strcasecmp (cur_uuid, ctx->root_uuid) == 0)
    {
      grub_env_set ("root", name);
      ctx->root_found = 1;
    }
  return ctx->prefix_found && ctx->root_found;
}
Esempio n. 2
0
void
grub_machine_set_prefix (void)
{
#ifndef __i386__
  char bootpath[64]; /* XXX check length */
  char *filename;
  char *prefix;
#endif

  if (grub_prefix[0])
    {
      grub_env_set ("prefix", grub_prefix);
      /* Prefix is hardcoded in the core image.  */
      return;
    }

#ifdef __i386__
  grub_env_set ("prefix", "(sd,1)/");
#else
  if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath", &bootpath,
				  sizeof (bootpath), 0))
    {
      /* Should never happen.  */
      grub_printf ("/chosen/bootpath property missing!\n");
      grub_env_set ("prefix", "");
      return;
    }

  /* Transform an OF device path to a GRUB path.  */

  prefix = grub_ieee1275_encode_devname (bootpath);

  filename = grub_ieee1275_get_filename (bootpath);
  if (filename)
    {
      char *newprefix;
      char *lastslash = grub_strrchr (filename, '\\');

      /* Truncate at last directory.  */
      if (lastslash)
        {
	  *lastslash = '\0';
	  grub_translate_ieee1275_path (filename);

	  newprefix = grub_xasprintf ("%s%s", prefix, filename);
	  if (newprefix)
	    {
	      grub_free (prefix);
	      prefix = newprefix;
	    }
	}
    }

  grub_env_set ("prefix", prefix);

  grub_free (filename);
  grub_free (prefix);
#endif
}
Esempio n. 3
0
static grub_err_t
grub_cmd_next (grub_extcmd_context_t ctxt, int argc, char **args)
{
  struct grub_arg_list *state = ctxt->state;
  char *p, *root = NULL, *part_name = NULL, *part_guid = NULL;

  /* TODO: Add a uuid parser and a command line flag for providing type.  */
  grub_gpt_part_type_t part_type = GRUB_GPT_PARTITION_TYPE_USR_X86_64;

  if (!state[NEXT_SET_DEVICE].set || !state[NEXT_SET_UUID].set)
    {
      grub_error (GRUB_ERR_INVALID_COMMAND, N_("-d and -u are required"));
      goto done;
    }

  if (argc == 0)
    root = grub_strdup (grub_env_get ("root"));
  else if (argc == 1)
    root = grub_strdup (args[0]);
  else
    {
      grub_error (GRUB_ERR_BAD_ARGUMENT, N_("unexpected arguments"));
      goto done;
    }

  if (!root)
    goto done;

  /* To make using $root practical strip off the partition name.  */
  p = grub_strchr (root, ',');
  if (p)
    *p = '\0';

  if (grub_find_next (root, &part_type, &part_name, &part_guid))
    goto done;

  if (grub_env_set (state[NEXT_SET_DEVICE].arg, part_name))
    goto done;

  if (grub_env_set (state[NEXT_SET_UUID].arg, part_guid))
    goto done;

  grub_errno = GRUB_ERR_NONE;

done:
  grub_free (root);
  grub_free (part_name);
  grub_free (part_guid);

  return grub_errno;
}
Esempio n. 4
0
grub_err_t
grub_multiboot_set_console (int console_type, int accepted_consoles,
			    int width, int height, int depth,
			    int console_req)
{
  console_required = console_req;
  if (!(accepted_consoles 
	& (GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER
	   | (GRUB_MACHINE_HAS_VGA_TEXT ? GRUB_MULTIBOOT_CONSOLE_EGA_TEXT : 0))))
    {
      if (console_required)
	return grub_error (GRUB_ERR_BAD_OS,
			   "OS requires a console but none is available");
      grub_puts_ (N_("WARNING: no console will be available to OS"));
      accepts_video = 0;
      accepts_ega_text = 0;
      return GRUB_ERR_NONE;
    }

  if (console_type == GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER)
    {
      char *buf;
      if (depth && width && height)
	buf = grub_xasprintf ("%dx%dx%d,%dx%d,auto", width,
			      height, depth, width, height);
      else if (width && height)
	buf = grub_xasprintf ("%dx%d,auto", width, height);
      else
	buf = grub_strdup ("auto");

      if (!buf)
	return grub_errno;
      grub_env_set ("gfxpayload", buf);
      grub_free (buf);
    }
  else
    {
#if GRUB_MACHINE_HAS_VGA_TEXT
      grub_env_set ("gfxpayload", "text");
#else
      /* Always use video if no VGA text is available.  */
      grub_env_set ("gfxpayload", "auto");
#endif
    }

  accepts_video = !!(accepted_consoles & GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER);
  accepts_ega_text = !!(accepted_consoles & GRUB_MULTIBOOT_CONSOLE_EGA_TEXT);
  return GRUB_ERR_NONE;
}
Esempio n. 5
0
/* Helper for grub_cmd_load_env.  */
static int
set_var (const char *name, const char *value, void *whitelist)
{
  if (! whitelist)
    {
      grub_env_set (name, value);
      return 0;
    }

  if (test_whitelist_membership (name,
				 (const grub_env_whitelist_t *) whitelist))
    grub_env_set (name, value);

  return 0;
}
Esempio n. 6
0
void
grub_machine_set_prefix (void)
{
  grub_env_set ("prefix", prefix);
  free (prefix);
  prefix = 0;
}
Esempio n. 7
0
/* Set slot status values */
static gboolean grub_set_state(RaucSlot *slot, gboolean good) {
	GPtrArray *pairs = g_ptr_array_new_full(10, g_free);
	gboolean res = FALSE;

	g_assert_nonnull(slot);

	if (good) {
		g_ptr_array_add(pairs, g_strdup_printf("%s_OK=1", slot->bootname));
		g_ptr_array_add(pairs, g_strdup_printf("%s_TRY=0", slot->bootname));
	} else {
		g_ptr_array_add(pairs, g_strdup_printf("%s_OK=0", slot->bootname));
		g_ptr_array_add(pairs, g_strdup_printf("%s_TRY=0", slot->bootname));
	}

	res = grub_env_set(pairs);
	if (!res) {
		g_warning("failed marking as %s", good ? "good" : "bad");
		goto out;
	}

	res = TRUE;
out:
	g_ptr_array_unref(pairs);
	return res;
}
Esempio n. 8
0
static grub_err_t
grub_cmd_read (grub_command_t cmd __attribute__ ((unused)),
	       int argc, char **args)
{
  grub_uitree_t node;

  if (argc < 2)
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "not enough parameter");

  if (! grub_widget_current_node)
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "no current node");

  node = grub_widget_current_node;
  while (node)
    {
      char *parm;

      parm = grub_uitree_get_prop (node, "parameters");
      if (parm)
	{
	  char *result;

	  result = grub_dialog_get_parm (node, parm, args[0]);
	  if (result)
	    grub_env_set (args[1], result);
	  break;
	}
      node = node->parent;
    }

  return 0;
}
Esempio n. 9
0
/* Get the first entry number from the value of the environment variable NAME,
   which is a space-separated list of non-negative integers.  The entry number
   which is returned is stripped from the value of NAME.  If no entry number
   can be found, -1 is returned.  */
static int
get_and_remove_first_entry_number (const char *name)
{
  const char *val;
  char *tail;
  int entry;

  val = grub_env_get (name);
  if (! val)
    return -1;

  grub_error_push ();

  entry = (int) grub_strtoul (val, &tail, 0);

  if (grub_errno == GRUB_ERR_NONE)
    {
      /* Skip whitespace to find the next digit.  */
      while (*tail && grub_isspace (*tail))
	tail++;
      grub_env_set (name, tail);
    }
  else
    {
      grub_env_unset (name);
      grub_errno = GRUB_ERR_NONE;
      entry = -1;
    }

  grub_error_pop ();

  return entry;
}
Esempio n. 10
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);
}
Esempio n. 11
0
static PyObject *bits__putenv(PyObject *self, PyObject *args)
{
    const char *key, *value;
    if (!PyArg_ParseTuple(args, "ss:putenv", &key, &value))
        return NULL;
    if (grub_env_set(key, value) != GRUB_ERR_NONE || grub_env_export(key) != GRUB_ERR_NONE)
        return PyErr_SetFromErrno(PyExc_OSError);
    return Py_BuildValue("");
}
Esempio n. 12
0
grub_err_t
grub_rescue_parse_line (char *line,
			grub_reader_getline_t getline, void *getline_data)
{
  char *name;
  int n;
  grub_command_t cmd;
  char **args;

  if (grub_parser_split_cmdline (line, getline, getline_data, &n, &args)
      || n < 0)
    return grub_errno;

  if (n == 0)
    return GRUB_ERR_NONE;

  /* In case of an assignment set the environment accordingly
     instead of calling a function.  */
  if (n == 1)
    {
      char *val = grub_strchr (args[0], '=');

      if (val)
	{
	  val[0] = 0;
	  grub_env_set (args[0], val + 1);
	  val[0] = '=';
	  goto quit;
	}
    }

  /* Get the command name.  */
  name = args[0];

  /* If nothing is specified, restart.  */
  if (*name == '\0')
    goto quit;

  cmd = grub_command_find (name);
  if (cmd)
    {
      (cmd->func) (cmd, n - 1, &args[1]);
    }
  else
    {
      grub_printf_ (N_("Unknown command `%s'.\n"), name);
      if (grub_command_find ("help"))
	grub_printf ("Try `help' for usage\n");
    }

 quit:
  /* Arguments are returned in single memory chunk separated by zeroes */
  grub_free (args[0]);
  grub_free (args);

  return grub_errno;
}
Esempio n. 13
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);
}
Esempio n. 14
0
void
grub_machine_set_prefix (void)
{
  if (grub_prefix[0] != '(')
    {
      char bootpath[IEEE1275_MAX_PATH_LEN];
      char *prefix, *path, *colon;
      grub_ssize_t actual;

      if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootpath",
				      &bootpath, sizeof (bootpath), &actual))
	{
	  /* Should never happen.  */
	  grub_printf ("/chosen/bootpath property missing!\n");
	  grub_env_set ("prefix", "");
	  return;
	}

      /* Transform an OF device path to a GRUB path.  */
      colon = grub_strchr (bootpath, ':');
      if (colon)
	{
	  char *part = colon + 1;

	  /* Consistently provide numbered partitions to GRUB.
	     OpenBOOT traditionally uses alphabetical partition
	     specifiers.  */
	  if (part[0] >= 'a' && part[0] <= 'z')
	    part[0] = '1' + (part[0] - 'a');
	}
      prefix = grub_ieee1275_encode_devname (bootpath);

      path = grub_xasprintf("%s%s", prefix, grub_prefix);

      grub_strcpy (grub_prefix, path);

      grub_free (path);
      grub_free (prefix);
    }

  grub_env_set ("prefix", grub_prefix);
}
Esempio n. 15
0
static grub_err_t
grub_cmd_read (grub_command_t cmd __attribute__ ((unused)), int argc, char **args)
{
  char *line = grub_getline ();
  if (! line)
    return grub_errno;
  if (argc > 0)
    grub_env_set (args[0], line);

  grub_free (line);
  return 0;
}
Esempio n. 16
0
/* Set current timeout in the variable "timeout".  */
void
grub_menu_set_timeout (int timeout)
{
  /* Ignore TIMEOUT if it is zero, because it will be unset really soon.  */
  if (timeout > 0)
    {
      char buf[16];

      grub_snprintf (buf, sizeof (buf), "%d", timeout);
      grub_env_set ("timeout", buf);
    }
}
Esempio n. 17
0
void
grub_machine_init (void)
{
  char args[256];
  grub_ssize_t actual;

  grub_ieee1275_init ();

  grub_console_init_early ();
#ifdef __i386__
  grub_get_extended_memory ();
#endif
  grub_claim_heap ();
  grub_console_init_lately ();
  grub_ofdisk_init ();

  /* Process commandline.  */
  if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootargs", &args,
				  sizeof args, &actual) == 0
      && actual > 1)
    {
      int i = 0;

      while (i < actual)
	{
	  char *command = &args[i];
	  char *end;
	  char *val;

	  end = grub_strchr (command, ';');
	  if (end == 0)
	    i = actual; /* No more commands after this one.  */
	  else
	    {
	      *end = '\0';
	      i += end - command + 1;
	      while (grub_isspace(args[i]))
		i++;
	    }

	  /* Process command.  */
	  val = grub_strchr (command, '=');
	  if (val)
	    {
	      *val = '\0';
	      grub_env_set (command, val + 1);
	    }
	}
    }

  grub_install_get_time_ms (ieee1275_get_time_ms);
}
Esempio n. 18
0
static grub_err_t
grub_rescue_parse_line (char *line, grub_reader_getline_t getline,
			void *closure)
{
  char *name;
  int n;
  grub_command_t cmd;
  char **args;

  if (grub_parser_split_cmdline (line, getline, closure, &n, &args) || n < 0)
    return grub_errno;

  if (n == 0)
    return GRUB_ERR_NONE;

  /* In case of an assignment set the environment accordingly
     instead of calling a function.  */
  if (n == 1 && grub_strchr (line, '='))
    {
      char *val = grub_strchr (args[0], '=');
      val[0] = 0;
      grub_env_set (args[0], val + 1);
      val[0] = '=';
      goto quit;
    }

  /* Get the command name.  */
  name = args[0];

  /* If nothing is specified, restart.  */
  if (*name == '\0')
    goto quit;

  cmd = grub_command_find (name);
  if (cmd)
    {
      (cmd->func) (cmd, n - 1, &args[1]);
    }
  else
    {
      grub_printf ("Unknown command `%s'\n", name);
      if (grub_command_find ("help"))
	grub_printf ("Try `help' for usage\n");
    }

 quit:
  grub_free (args[0]);
  grub_free (args);

  return grub_errno;
}
Esempio n. 19
0
static grub_err_t
grub_env_new_context (int export_all)
{
  struct grub_env_context *context;
  int i;
  struct menu_pointer *menu;

  context = grub_zalloc (sizeof (*context));
  if (! context)
    return grub_errno;
  menu = grub_zalloc (sizeof (*menu));
  if (! menu)
    {
      grub_free (context);
      return grub_errno;
    }

  context->prev = grub_current_context;
  grub_current_context = context;

  menu->prev = current_menu;
  current_menu = menu;

  /* Copy exported variables.  */
  for (i = 0; i < HASHSZ; i++)
    {
      struct grub_env_var *var;

      for (var = context->prev->vars[i]; var; var = var->next)
	if (var->global || export_all)
	  {
	    if (grub_env_set (var->name, var->value) != GRUB_ERR_NONE)
	      {
		grub_env_context_close ();
		return grub_errno;
	      }
	    grub_env_export (var->name);
	    grub_register_variable_hook (var->name, var->read_hook, var->write_hook);
	  }
    }

  return GRUB_ERR_NONE;
}
Esempio n. 20
0
File: env.c Progetto: Arvian/GRUB2
/**
* @attention 本注释得到了"核高基"科技重大专项2012年课题“开源操作系统内核分析和安全性评估
*(课题编号:2012ZX01039-004)”的资助。
*
* @copyright 注释添加单位:清华大学——03任务(Linux内核相关通用基础软件包分析)承担单位
*
* @author 注释添加人员:谢文学
*
* @date 注释添加日期:2013年6月8日
*
* @brief 导出一个环境变量。
*
* @note 注释详细内容:
*
* 本函数实现导出一个环境变量的功能。首先使用grub_env_find()找到该环境变量;如果没找到,则
* 使用grub_env_set()将其设置为“”,并重新使用grub_env_find()找到该环境变量;最后设置改环境
* 变量的global标志位1。
**/
grub_err_t
grub_env_export (const char *name)
{
  struct grub_env_var *var;

  var = grub_env_find (name);
  if (! var)
    {
      grub_err_t err;

      err = grub_env_set (name, "");
      if (err)
	return err;
      var = grub_env_find (name);
    }
  var->global = 1;

  return GRUB_ERR_NONE;
}
Esempio n. 21
0
File: env.c Progetto: 0xroot/radare2
grub_err_t
grub_register_variable_hook (const char *name,
			     grub_env_read_hook_t read_hook,
			     grub_env_write_hook_t write_hook)
{
  struct grub_env_var *var = grub_env_find (name);

  if (! var)
    {
      if (grub_env_set (name, "") != GRUB_ERR_NONE)
	return grub_errno;

      var = grub_env_find (name);
      /* XXX Insert an assertion?  */
    }

  var->read_hook = read_hook;
  var->write_hook = write_hook;

  return GRUB_ERR_NONE;
}
Esempio n. 22
0
File: env.c Progetto: 0xroot/radare2
void
grub_env_unset (const char *name)
{
  struct grub_env_var *var;

  var = grub_env_find (name);
  if (! var)
    return;

  if (var->read_hook || var->write_hook)
    {
      grub_env_set (name, "");
      return;
    }

  grub_env_remove (var);

  grub_free (var->name);
  grub_free (var->value);
  grub_free (var);
}
Esempio n. 23
0
static void
grub_parse_cmdline (void)
{
  grub_ssize_t actual;
  char args[256];

  if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootargs", &args,
				  sizeof args, &actual) == 0
      && actual > 1)
    {
      int i = 0;

      while (i < actual)
	{
	  char *command = &args[i];
	  char *end;
	  char *val;

	  end = grub_strchr (command, ';');
	  if (end == 0)
	    i = actual; /* No more commands after this one.  */
	  else
	    {
	      *end = '\0';
	      i += end - command + 1;
	      while (grub_isspace(args[i]))
		i++;
	    }

	  /* Process command.  */
	  val = grub_strchr (command, '=');
	  if (val)
	    {
	      *val = '\0';
	      grub_env_set (command, val + 1);
	    }
	}
    }
}
Esempio n. 24
0
/* Set slot as primary boot slot */
static gboolean grub_set_primary(RaucSlot *slot) {
	GPtrArray *pairs = g_ptr_array_new_full(10, g_free);
	GString *order = g_string_sized_new(10);
	gboolean res = FALSE;
	GList *slots;

	g_assert_nonnull(slot);

	g_string_append(order, slot->bootname);

	/* Iterate over class members */
	slots = g_hash_table_get_values(r_context()->config->slots);
	for (GList *l = slots; l != NULL; l = l->next) {
		RaucSlot *s = l->data;
		if (s == slot)
			continue;
		if (s->sclass != slot->sclass)
			continue;

		g_string_append_c(order, ' ');
		g_string_append(order, s->bootname);
	}

	g_ptr_array_add(pairs, g_strdup_printf("%s_OK=%i", slot->bootname, 1));
	g_ptr_array_add(pairs, g_strdup_printf("%s_TRY=%i", slot->bootname, 0));
	g_ptr_array_add(pairs, g_strdup_printf("ORDER=%s", order->str));

	res = grub_env_set(pairs);
	if (!res) {
		g_warning("failed marking as primary");
		goto out;
	}

	res = TRUE;
out:
	g_string_free(order, TRUE);
	g_ptr_array_unref(pairs);
	return res;
}
Esempio n. 25
0
/* Run a menu entry.  */
void
grub_menu_execute_entry(grub_menu_entry_t entry)
{
  grub_err_t err = GRUB_ERR_NONE;

  if (entry->restricted)
    err = grub_normal_check_authentication (entry->users);

  if (err)
    {
      grub_print_error ();
      grub_errno = GRUB_ERR_NONE;
      return;
    }

  grub_env_set ("chosen", entry->title);

  grub_parser_execute ((char *) entry->sourcecode);

  if (grub_errno == GRUB_ERR_NONE && grub_loader_is_loaded ())
    /* Implicit execution of boot, only if something is loaded.  */
    grub_command_execute ("boot", 0, 0);
}
Esempio n. 26
0
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);
    }
}
Esempio n. 27
0
static grub_err_t
grub_cmd_read (grub_extcmd_t cmd, int argc, char **argv)
{
  grub_target_addr_t addr;
  grub_uint32_t value = 0;
  char buf[sizeof ("XXXXXXXX")];

  if (argc != 1)
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "Invalid number of arguments");

  addr = grub_strtoul (argv[0], 0, 0);
  switch (cmd->cmd->name[sizeof ("in") - 1])
    {
    case 'l':
      value = grub_inl (addr);
      break;

    case 'w':
      value = grub_inw (addr);
      break;

    case 'b':
      value = grub_inb (addr);
      break;
    }

  if (cmd->state[0].set)
    {
      grub_snprintf (buf, sizeof (buf), "%x", value);
      grub_env_set (cmd->state[0].arg, buf);
    }
  else
    grub_printf ("0x%x\n", value);

  return 0;
}
Esempio n. 28
0
static grub_err_t
grub_cmd_read (grub_extcmd_context_t ctxt, int argc, char **argv)
{
    grub_addr_t addr;
    grub_uint32_t value = 0;
    char buf[sizeof ("XXXXXXXX")];

    if (argc != 1)
        return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));

    addr = grub_strtoul (argv[0], 0, 0);
    switch (ctxt->extcmd->cmd->name[sizeof ("read_") - 1])
    {
    case 'd':
        value = *((volatile grub_uint32_t *) addr);
        break;

    case 'w':
        value = *((volatile grub_uint16_t *) addr);
        break;

    case 'b':
        value = *((volatile grub_uint8_t *) addr);
        break;
    }

    if (ctxt->state[0].set)
    {
        grub_snprintf (buf, sizeof (buf), "%x", value);
        grub_env_set (ctxt->state[0].arg, buf);
    }
    else
        grub_printf ("0x%x\n", value);

    return 0;
}
Esempio n. 29
0
void
grub_machine_set_prefix (void)
{
  /* Initialize the prefix.  */
  grub_env_set ("prefix", grub_prefix);
}
Esempio n. 30
0
/* Run a menu entry.  */
static void
grub_menu_execute_entry(grub_menu_entry_t entry, int auto_boot)
{
  grub_err_t err = GRUB_ERR_NONE;
  int errs_before;
  grub_menu_t menu = NULL;
  char *optr, *buf, *oldchosen = NULL, *olddefault = NULL;
  const char *ptr, *chosen, *def;
  grub_size_t sz = 0;

  if (entry->restricted)
    err = grub_auth_check_authentication (entry->users);

  if (err)
    {
      grub_print_error ();
      grub_errno = GRUB_ERR_NONE;
      return;
    }

  errs_before = grub_err_printed_errors;

  chosen = grub_env_get ("chosen");
  def = grub_env_get ("default");

  if (entry->submenu)
    {
      grub_env_context_open ();
      menu = grub_zalloc (sizeof (*menu));
      if (! menu)
	return;
      grub_env_set_menu (menu);
      if (auto_boot)
	grub_env_set ("timeout", "0");
    }

  for (ptr = entry->id; *ptr; ptr++)
    sz += (*ptr == '>') ? 2 : 1;
  if (chosen)
    {
      oldchosen = grub_strdup (chosen);
      if (!oldchosen)
	grub_print_error ();
    }
  if (def)
    {
      olddefault = grub_strdup (def);
      if (!olddefault)
	grub_print_error ();
    }
  sz++;
  if (chosen)
    sz += grub_strlen (chosen);
  sz++;
  buf = grub_malloc (sz);
  if (!buf)
    grub_print_error ();
  else
    {
      optr = buf;
      if (chosen)
	{
	  optr = grub_stpcpy (optr, chosen);
	  *optr++ = '>';
	}
      for (ptr = entry->id; *ptr; ptr++)
	{
	  if (*ptr == '>')
	    *optr++ = '>';
	  *optr++ = *ptr;
	}
      *optr = 0;
      grub_env_set ("chosen", buf);
      grub_env_export ("chosen");
      grub_free (buf);
    }

  for (ptr = def; ptr && *ptr; ptr++)
    {
      if (ptr[0] == '>' && ptr[1] == '>')
	{
	  ptr++;
	  continue;
	}
      if (ptr[0] == '>')
	break;
    }

  if (ptr && ptr[0] && ptr[1])
    grub_env_set ("default", ptr + 1);
  else
    grub_env_unset ("default");

  grub_script_execute_sourcecode (entry->sourcecode, entry->argc, entry->args);

  if (errs_before != grub_err_printed_errors)
    grub_wait_after_message ();

  if (grub_errno == GRUB_ERR_NONE && grub_loader_is_loaded ())
    /* Implicit execution of boot, only if something is loaded.  */
    grub_command_execute ("boot", 0, 0);

  if (entry->submenu)
    {
      if (menu && menu->size)
	{
	  grub_show_menu (menu, 1, auto_boot);
	  grub_normal_free_menu (menu);
	}
      grub_env_context_close ();
    }
  if (oldchosen)
    grub_env_set ("chosen", oldchosen);
  else
    grub_env_unset ("chosen");
  if (olddefault)
    grub_env_set ("default", olddefault);
  else
    grub_env_unset ("default");
  grub_env_unset ("timeout");
}