From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1npZUr-00072U-0B for mharc-grub-devel@gnu.org; Fri, 13 May 2022 13:54:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npZUp-0006x6-6A for grub-devel@gnu.org; Fri, 13 May 2022 13:54:35 -0400 Received: from mail-vk1-xa2a.google.com ([2607:f8b0:4864:20::a2a]:44833) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1npZUn-0004hb-3z for grub-devel@gnu.org; Fri, 13 May 2022 13:54:34 -0400 Received: by mail-vk1-xa2a.google.com with SMTP id o132so4546403vko.11 for ; Fri, 13 May 2022 10:54:32 -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=WW2ijWO6dY0qBfQciXfAsYpGUWjNJcE9LvlW5CMgdc0=; b=unLT0eIpOZwWBrYaP6BV3PIRu/ij7fnjtwBAseNOQkz8/ZL0U5V9xsDAq0DhvJWS7U hBjkJX6oB7ja0gsbT9/6IiXTCzqiM0pI+rVqbMizZwRZ9fHJvR3cMb+MKxocqcTWhffq POShADUH2EWu1xLiL4kg0YnzSbSn6jUdcMztXUtr8DZ8xCFYAbrdhIahdebHNK7cPnal CRhm//RlhcR7CqeNjTHZ17OloHZ1QI1jvmRX/OEPFONYxivwjxvHJoW4f2yVuTbMPHzs 04bTfyoG2vpCoSjYqEnrkVuqlP8kKp2uiqSYIt1axR1R+U2tIDC8H26FWKozoI95F1Vl cRkA== 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=WW2ijWO6dY0qBfQciXfAsYpGUWjNJcE9LvlW5CMgdc0=; b=XRHxblwGOpOcUy64YCGJhrIUEICoamqFhnSYIO8CzXFbvhY2nmAQExSRhlewvLjUcS IPOCri/YqEiRY4+FKyuxCQRORfw4ebYl6++N+OFz3hLregL3NFnIq0VTABSiSN7KpC+y 1UvoxzjHAecNsM7tyo6RO4O40ZSoLJHIp7XMaI8NsKnrX/7uqONGHsNbFQBnpC0qfuhv fd5Bot73pMxTW+SyFdI2mXRXmytBqkkwakh5dghqXgjoXJBiWlQeY3DczVEXXBEhNBCQ H1X0wL/rMd6SpyIhV6ev8eA19MDl5xp+hnO6JDbbBLvvMHkAeN+1rlKdDnE5PZ9f4gkZ cRVA== X-Gm-Message-State: AOAM532MVPQGfgpB9bvKCXIV9g1O+raWLk2hP7OQ0cYZRwZ2jkyRtrgH 0AEGOW79cTZLhB8Bw8/LWmjoM6BgEnVwiQ8e X-Google-Smtp-Source: ABdhPJzNorQPkBAEbu2iAUrzbsQ1a4Wb7TJruEduaxju5nBi6pemwm1zoZGcgkuPJcFt95YbPxkCIA== X-Received: by 2002:a1f:286:0:b0:352:69d4:4823 with SMTP id 128-20020a1f0286000000b0035269d44823mr2770668vkc.8.1652464471775; Fri, 13 May 2022 10:54:31 -0700 (PDT) Received: from localhost.localdomain ([37.218.244.249]) by smtp.gmail.com with ESMTPSA id l14-20020ab0164e000000b003626f894decsm421717uae.26.2022.05.13.10.54.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 10:54:31 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Paul Menzel , Glenn Washburn , Gerd Hoffmann Subject: [PATCH v2 1/2] efi: Add efitextmode command for getting/setting the text mode resolution Date: Fri, 13 May 2022 12:54:11 -0500 Message-Id: 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::a2a; envelope-from=development@efficientek.com; helo=mail-vk1-xa2a.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: Fri, 13 May 2022 17:54:35 -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 Reviewed-by: Gerd Hoffmann Tested-by: Gerd Hoffmann --- 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