Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nozBG-0005Ge-H4 for mharc-grub-devel@gnu.org; Wed, 11 May 2022 23:07:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nozBE-0005DE-Ge for grub-devel@gnu.org; Wed, 11 May 2022 23:07:56 -0400 Received: from mail-vs1-xe34.google.com ([2607:f8b0:4864:20::e34]:38696) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nozBC-0001No-L2 for grub-devel@gnu.org; Wed, 11 May 2022 23:07:56 -0400 Received: by mail-vs1-xe34.google.com with SMTP id q2so3880611vsr.5 for ; Wed, 11 May 2022 20:07:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lnvEmc8MwEj48doCv6fVzeYNEXI2smaV1iRQLf8lssw=; b=C6lhGg7AfX6ptuqc4GdtWiRrQNzA5rgDvr40hp4ro0vONAbR3+p5hb0Lm1yZ6i41Ya QzenSF97F1eWtw3EFJUMyfMDvjTm7O8ul6uHmqxd3Z9KxEbn2ygVf1G7eMEFjCH1let6 zVGhmDCAiwVCj7YQnLRXwC/yrwflvGRMXTIHj1I4lFGYLhEnfdgTB+n3kOO/FgQui3Ul J2vsCOS/stSOXgoy6hWxk06Hcc92dTzwC5he/+2QmAuYYxoRMYGXMJeDNF1jn0OEz2ke YeMR1cqr/lJLkAJXWuI23D0EiaCb+alpFX8hfj9Mfy2NP9fxQq7cYYbtZPODCEuRSh1I AXow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lnvEmc8MwEj48doCv6fVzeYNEXI2smaV1iRQLf8lssw=; b=24UHX9lXwTJ/iF33fyRqpQ4bJW09ozIxUyI3q687SMDKUP5N3CQScOzva76hv0jq9/ 3cLOFdC23KDJ8iwahYlA1gj6ggHsxP7SFuqP1Vr8ejQctWmnFwl/Kdfm3g/wMhCZHiY7 G2/mXjClyBE+rBtmsasY0UDsYcCavdSG91L4UWXQu6Lnea4k2U2LgQd9AsTCyxwvoP1H MgoaTpSKBtinG88VIhEK+SeRk9dos4EqASwUvtSBCqiII6zwhkKHS3WBJR9qTNCImD3d xeahNr5Wp9EwLlIG0KN6o1aWABF981/A/EPikGQTLEip0t4Z2g8W0cD3IiURex01lOFW oqoA== X-Gm-Message-State: AOAM533XppimYMPnr1IDeoBDJdYR3dYu+IPafGbFrhW2ZFMujqXA8XA0 ZFqpv3pjM7VhlILuJVta8Y5OvyK7CZg80dBu X-Google-Smtp-Source: ABdhPJyygNaB3ylUrbgwb0+vluqgAgqrjwInz2iZ4xysaTMJ5eiE9NvaHqiaZrLbEsvRFxN/kr9ZQw== X-Received: by 2002:a67:67c6:0:b0:32c:bf27:8f68 with SMTP id b189-20020a6767c6000000b0032cbf278f68mr14904070vsc.86.1652324873341; Wed, 11 May 2022 20:07:53 -0700 (PDT) Received: from localhost.localdomain ([37.218.244.249]) by smtp.gmail.com with ESMTPSA id u22-20020ac5c936000000b00351d39fb576sm483395vkl.53.2022.05.11.20.07.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 20:07:52 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Gerd Hoffmann , Glenn Washburn Subject: [PATCH 1/2] efi: Add efitextmode command for getting/setting the text mode resolution Date: Wed, 11 May 2022 22:07:34 -0500 Message-Id: <5a8f63684863512d4604cf70fd8e846eae2b1e9b.1652324591.git.development@efficientek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::e34; envelope-from=development@efficientek.com; helo=mail-vs1-xe34.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 May 2022 03:07:56 -0000 This command is meant to behave similarly to the 'mode' command of the EFI Shell application. One difference is that to set the mode the mode number is given, not the rows and columns of the desired mode. Also supported are the arguments "min" and "max", which set the mode to the minimum and maximum mode respectively as calculated by the columns * rows of that mode. Signed-off-by: Glenn Washburn --- grub-core/Makefile.core.def | 6 ++ grub-core/commands/efi/efitextmode.c | 118 +++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 grub-core/commands/efi/efitextmode.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 726f51be7..b22e48f0f 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -813,6 +813,12 @@ module = { enable = efi; }; +module = { + name = efitextmode; + efi = commands/efi/efitextmode.c; + enable = efi; +}; + module = { name = blocklist; common = commands/blocklist.c; diff --git a/grub-core/commands/efi/efitextmode.c b/grub-core/commands/efi/efitextmode.c new file mode 100644 index 000000000..fb72aa6f3 --- /dev/null +++ b/grub-core/commands/efi/efitextmode.c @@ -0,0 +1,118 @@ +/* efitextmode.c - command to get/set text mode resolution */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2003,2005,2006,2007,2009 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 . + */ + +#include +#include +#include +#include +#include +#include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); + +static grub_err_t +grub_cmd_efitextmode (grub_command_t cmd __attribute__ ((unused)), + int argc, char **args) +{ + grub_efi_simple_text_output_interface_t *o; + unsigned long mode; + const char *p = NULL; + grub_efi_status_t status; + grub_efi_uintn_t columns, rows; + grub_efi_int32_t i; + + if (argc > 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("at most one argument expected")); + + o = grub_efi_system_table->con_out; + + if (argc == 1) + { + if (grub_strcmp (args[0], "min") == 0) + mode = 0; + else if (grub_strcmp (args[0], "max") == 0) + mode = o->mode->max_mode - 1; + else + { + mode = grub_strtoul (args[0], &p, 0); + + if (grub_errno != GRUB_ERR_NONE) + return grub_errno; + + if (*args[0] == '\0' || *p != '\0') + return grub_error (GRUB_ERR_BAD_ARGUMENT, + N_("non-numeric or invalid mode `%s'"), + args[0]); + } + + if (mode < (unsigned long) o->mode->max_mode) + { + if (mode != (unsigned long) o->mode->mode) + { + status = efi_call_2 (o->set_mode, o, (grub_efi_int32_t) mode); + if (status == GRUB_EFI_SUCCESS) + ; + else if (status == GRUB_EFI_DEVICE_ERROR) + return grub_error (GRUB_ERR_BAD_DEVICE, + N_("device error: could not set requested" + " mode")); + else if (status == GRUB_EFI_UNSUPPORTED) + return grub_error (GRUB_ERR_OUT_OF_RANGE, + N_("invalid mode: number not valid")); + else + return grub_error (GRUB_ERR_BAD_OS, + N_("unexpected EFI error number: `%u'"), + (unsigned) status); + } + } + else + return grub_error (GRUB_ERR_BAD_ARGUMENT, + N_("invalid mode: `%lu' is greater than maximum" + " mode `%lu'"), + mode, (unsigned long) o->mode->max_mode); + } + + if (argc == 0) + { + grub_printf_ (N_("Available modes for console output device.\n")); + + for (i=0; i < o->mode->max_mode; i++) + if (GRUB_EFI_SUCCESS == efi_call_4 (o->query_mode, o, i, + &columns, &rows)) + grub_printf_ (N_(" [%lu] Col %5u Row %5u %c\n"), + (unsigned long) i, (unsigned) columns, (unsigned) rows, + (i == o->mode->mode) ? '*' : ' '); + } + + return GRUB_ERR_NONE; +} + +static grub_command_t cmd; + +GRUB_MOD_INIT(cmp) +{ + cmd = grub_register_command ("efitextmode", grub_cmd_efitextmode, + N_("[min|max|mode_num]"), N_("Get or set EFI text mode.")); +} + +GRUB_MOD_FINI(cmp) +{ + grub_unregister_command (cmd); +} -- 2.34.1