Skip to contentSkip to conversation

Grub-devel Digest, Vol 185, Issue 13

DISCUSSION Artyom Pozharov 1 participant 1 message Jul 17, 2019 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Sorry, do you know about my bug (Grub-installation to UEFI with HP 250 G6)? I am worrying, because I have been waiting for answer a long time.

ср, 17 июл. 2019 г., 19:01 <[email protected]>:

Quoted 237 lines

Send Grub-devel mailing list submissions to
[email protected]

To subscribe or unsubscribe via the World Wide Web, visit
https://lists.gnu.org/mailman/listinfo/grub-devel
or, via email, send a message with subject or body 'help' to
[email protected]

You can reach the person managing the list at
[email protected]

When replying, please edit your Subject line so it is more specific than "Re: Contents of Grub-devel digest..."

Today's Topics:

1. Re: [PATCH] grub-core/commands/basic_math.c: New commands to perform basic math operations on variables (Vladimir 'phcoder' Serbinenko)

----------------------------------------------------------------------

Message: 1
Date: Tue, 16 Jul 2019 21:48:51 +0200
From: "Vladimir 'phcoder' Serbinenko" <[email protected]>
To: The development of GRUB 2 <[email protected]>
Subject: Re: [PATCH] grub-core/commands/basic_math.c: New commands to
perform basic math operations on variables
Message-ID:

        <

CAEaD8JOTj9yDJMFSJKiWaHH4kJt1fgGoH+BqM-00626NkLsYyA@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Quoted 71 lines · On Tue, 16 Jul 2019, 19:15 glenn tanner, <[email protected]> wrote:

Added new commands to add and subtract values from grub variables, was desirable for automated testing. Compiled and tested under x86_64-efi.

grub-core/Makefile.core.def +5 -0
index 474a63e68..c383f0157 100644
@@ -2503,3 +2503,8 @@ module = {
  common = commands/i386/wrmsr.c;
  enable = x86;
 };
+
+module = {
+  name = basic_math;
+  common = commands/basic_math.c;
+};
grub-core/commands/basic_math.c new file +32 -0
new file mode 100644
index 000000000..9337cd5b1
@@ -0,0 +1,134 @@
+/* basic_math.c - basic math functions.  */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  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
+ *  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/>.
+ */
+
+/* what any module needs */
+#include <grub/dl.h>
+#include <grub/misc.h>
+#include <grub/extcmd.h>
+#include <grub/i18n.h>
+#include <grub/mm.h>
+/* what my module needs */
+#include <grub/env.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+static grub_err_t
+grub_cmd_add (grub_extcmd_context_t ctxt __attribute__ ((unused)), int

argc, char **args)

grub-core/commands/basic_math.c new file +8 -0
+{
+  unsigned int i;
+  int ret, value_int=0, arg_int=0, digit;
+  const char *value;
+  char buf[512];
+
+  if (argc != 2)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Variable and value

required"));

grub-core/commands/basic_math.c new file +4 -0
+
+  value = grub_env_get (args[0]);
+  if (!value)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Variable must be

defined"));

grub-core/commands/basic_math.c

Quoted 5 lines
grub-core/commands/basic_math.c new file +5 -0
+
+  for (i=0;i<grub_strlen(value);i++) {
+    if (grub_isdigit((int)value[i])) {
+      digit = value[i] - '0';
+      value_int = (10*value_int) + digit;

This should be grub_strtol and not custom loop

Quoted 94 lines
grub-core/commands/basic_math.c new file +9 -0
+    }
+  }
+
+  for (i=0;i<grub_strlen(args[1]);i++) {
+    if (grub_isdigit((int)args[1][i])) {
+      digit = args[1][i] - '0';
+      arg_int = (10*arg_int) + digit;
+    } else {
+      return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Value must be a

positive interger"));

grub-core/commands/basic_math.c new file +14 -0
+    }
+  }
+
+  ret=value_int+arg_int;
+  /* grub_printf ("%d\n", ret); */
+
+  grub_snprintf (buf, sizeof (buf), "%d", ret);
+  /* grub_printf ("%s\n", buf); */
+  grub_env_set (args[0], buf);
+  return 0;
+}
+
+static grub_err_t
+grub_cmd_sub (grub_extcmd_context_t ctxt __attribute__ ((unused)), int

argc, char **args)

grub-core/commands/basic_math.c new file +8 -0
+{
+  unsigned int i;
+  int ret, value_int=0, arg_int=0, digit;
+  const char *value;
+  char buf[512];
+
+  if (argc != 2)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Variable and value

required"));

grub-core/commands/basic_math.c new file +4 -0
+
+  value = grub_env_get (args[0]);
+  if (!value)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Variable must be

defined"));

grub-core/commands/basic_math.c new file +14 -0
+
+  for (i=0;i<grub_strlen(value);i++) {
+    if (grub_isdigit((int)value[i])) {
+      digit = value[i] - '0';
+      value_int = (10*value_int) + digit;
+    }
+  }
+
+  for (i=0;i<grub_strlen(args[1]);i++) {
+    if (grub_isdigit((int)args[1][i])) {
+      digit = args[1][i] - '0';
+      arg_int = (10*arg_int) + digit;
+    } else {
+      return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Value must be a

positive interger"));

grub-core/commands/basic_math.c new file +5 -0
+    }
+  }
+
+  if (arg_int > value_int)
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("Result may not be

negitive"));

grub-core/commands/basic_math.c new file +31 -1
+
+  ret=value_int-arg_int;
+  /* grub_printf ("%d\n", ret); */
+
+  grub_snprintf (buf, sizeof (buf), "%d", ret);
+  /* grub_printf ("%s\n", buf); */
+  grub_env_set (args[0], buf);
+  return 0;
+}
+
+static grub_extcmd_t cmd_add, cmd_sub;
+
 
+GRUB_MOD_INIT(basic_math)
+{
+  cmd_add =
+    grub_register_extcmd ("add", grub_cmd_add, 0,
+                         N_("<variable_name> <value>"),
+                         N_("Add value to variable."),
+                         0);
+  cmd_sub =
+    grub_register_extcmd ("sub", grub_cmd_sub, 0,
+                         N_("<variable_name> <value>"),
+                         N_("Subtract value from variable."),
+                         0);
+}
+
+GRUB_MOD_FINI(basic_math)
+{
+  grub_unregister_extcmd (cmd_add);
+  grub_unregister_extcmd (cmd_sub);
+}
 
--
Quoted 7 lines

Regards,
Glenn Tanner
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <
https://lists.gnu.org/archive/html/grub-devel/attachments/20190716/c23d5329/attachment.html

Quoted 1 line

------------------------------

Subject: Digest Footer

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

------------------------------

End of Grub-devel Digest, Vol 185, Issue 13
*******************************************