/* * VAS_EBOOT -- GRand Unified Bootloader * Copyright (C) 2022 Free Software Foundation, Inc. * * VAS_EBOOT 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. * * VAS_EBOOT 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 VAS_EBOOT. If not, see . * * Set/Get UEFI text output mode resolution. */ #include #include #include #include #include #include #include VAS_EBOOT_MOD_LICENSE ("GPLv3+"); static VasEBoot_err_t VasEBoot_efi_set_mode (VasEBoot_efi_simple_text_output_interface_t *o, VasEBoot_efi_int32_t mode) { VasEBoot_efi_status_t status; if (mode != o->mode->mode) { status = o->set_mode (o, mode); if (status == VAS_EBOOT_EFI_SUCCESS) ; else if (status == VAS_EBOOT_EFI_DEVICE_ERROR) return VasEBoot_error (VAS_EBOOT_ERR_BAD_DEVICE, N_("device error: could not set requested mode")); else if (status == VAS_EBOOT_EFI_UNSUPPORTED) return VasEBoot_error (VAS_EBOOT_ERR_OUT_OF_RANGE, N_("invalid mode: number not valid")); else return VasEBoot_error (VAS_EBOOT_ERR_BAD_FIRMWARE, N_("unexpected EFI error number: `%u'"), (unsigned) status); } return VAS_EBOOT_ERR_NONE; } static VasEBoot_err_t VasEBoot_cmd_efitextmode (VasEBoot_command_t cmd __attribute__ ((unused)), int argc, char **args) { VasEBoot_efi_simple_text_output_interface_t *o = VasEBoot_efi_system_table->con_out; unsigned long mode; const char *p = NULL; VasEBoot_err_t err; VasEBoot_efi_uintn_t columns, rows; VasEBoot_efi_int32_t i; if (o == NULL) return VasEBoot_error (VAS_EBOOT_ERR_BAD_DEVICE, N_("no UEFI output console interface")); if (o->mode == NULL) return VasEBoot_error (VAS_EBOOT_ERR_BUG, N_("no mode struct for UEFI output console")); if (argc > 2) return VasEBoot_error (VAS_EBOOT_ERR_BAD_ARGUMENT, N_("at most two arguments expected")); if (argc == 0) { VasEBoot_printf_ (N_("Available modes for console output device.\n")); for (i = 0; i < o->mode->max_mode; i++) if (VAS_EBOOT_EFI_SUCCESS == o->query_mode (o, i, &columns, &rows)) VasEBoot_printf_ (N_(" [%" PRIuVAS_EBOOT_EFI_UINT32_T "] Col %5" PRIuVAS_EBOOT_EFI_UINTN_T " Row %5" PRIuVAS_EBOOT_EFI_UINTN_T " %c\n"), i, columns, rows, (i == o->mode->mode) ? '*' : ' '); } else if (argc == 1) { if (VasEBoot_strcmp (args[0], "min") == 0) mode = 0; else if (VasEBoot_strcmp (args[0], "max") == 0) mode = o->mode->max_mode - 1; else { mode = VasEBoot_strtoul (args[0], &p, 0); if (*args[0] == '\0' || *p != '\0') return VasEBoot_error (VAS_EBOOT_ERR_BAD_ARGUMENT, N_("non-numeric or invalid mode `%s'"), args[0]); } if (mode < (unsigned long) o->mode->max_mode) { err = VasEBoot_efi_set_mode (o, (VasEBoot_efi_int32_t) mode); if (err != VAS_EBOOT_ERR_NONE) return err; } else return VasEBoot_error (VAS_EBOOT_ERR_BAD_ARGUMENT, N_("invalid mode: `%lu' is greater than maximum mode `%lu'"), mode, (unsigned long) o->mode->max_mode); } else if (argc == 2) { VasEBoot_efi_uintn_t u_columns, u_rows; u_columns = (VasEBoot_efi_uintn_t) VasEBoot_strtoul (args[0], &p, 0); if (*args[0] == '\0' || *p != '\0') return VasEBoot_error (VAS_EBOOT_ERR_BAD_ARGUMENT, N_("non-numeric or invalid columns number `%s'"), args[0]); u_rows = (VasEBoot_efi_uintn_t) VasEBoot_strtoul (args[1], &p, 0); if (*args[1] == '\0' || *p != '\0') return VasEBoot_error (VAS_EBOOT_ERR_BAD_ARGUMENT, N_("non-numeric or invalid rows number `%s'"), args[1]); for (i = 0; i < o->mode->max_mode; i++) if (VAS_EBOOT_EFI_SUCCESS == o->query_mode (o, i, &columns, &rows)) if (u_columns == columns && u_rows == rows) return VasEBoot_efi_set_mode (o, (VasEBoot_efi_int32_t) i); return VasEBoot_error (VAS_EBOOT_ERR_BAD_ARGUMENT, N_("no mode found with requested columns and rows")); } return VAS_EBOOT_ERR_NONE; } static VasEBoot_command_t cmd; VAS_EBOOT_MOD_INIT (efitextmode) { cmd = VasEBoot_register_command ("efitextmode", VasEBoot_cmd_efitextmode, N_("[min | max | | ]"), N_("Get or set EFI text mode.")); } VAS_EBOOT_MOD_FINI (efitextmode) { VasEBoot_unregister_command (cmd); }