From patchwork Tue Oct 10 12:23:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 823813 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jMVPJFNc"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yBGdj69YVz9tY3 for ; Tue, 10 Oct 2017 23:29:45 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 7E65DC21DE6; Tue, 10 Oct 2017 12:26:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 6E036C21DED; Tue, 10 Oct 2017 12:24:45 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D3748C21C93; Tue, 10 Oct 2017 12:23:42 +0000 (UTC) Received: from mail-qt0-f193.google.com (mail-qt0-f193.google.com [209.85.216.193]) by lists.denx.de (Postfix) with ESMTPS id 1D0EFC21D88 for ; Tue, 10 Oct 2017 12:23:37 +0000 (UTC) Received: by mail-qt0-f193.google.com with SMTP id 32so15985392qtp.4 for ; Tue, 10 Oct 2017 05:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BqAiLC4yuJTewoCTYbyAbFqinZ5Q0ONhHg/sQT6k/qQ=; b=jMVPJFNcru+abYOUGA0Vq7hIuDTNcNVUsLuwdkUEAAFBYrlXhA+yQiLmeuqgTopthi HGAOv/vHiwd+j5KRjG3inX3nD/Tv50WVCCAMzolHn4cV4KAgtnicfmLeqqXHBI5te0rt 36p9jTYZ2e2yYDnDeRU26fYVsxL/xFkh0jAbqUCcRtaLLE442DognVOeLLjZXpoZm+mO DHxCAJS2mTCDXOFNu85Yn1VakPqpmQLOHnFX+vUOMeIO6evKEfQeGgTaASElvSKNKoTC WK03K+4OPNWlsX+LjUb1Ilzte0NDYk8bmTtXVg/kp8HRJDWDI5TPX41GufNrA6M/aV6x iHQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BqAiLC4yuJTewoCTYbyAbFqinZ5Q0ONhHg/sQT6k/qQ=; b=iie4/4AvZugHVblueBilnu6KmNNgZJP4C7RBbhXaYI5KWmgoinHSXH9sWnFpeMPn5V e9lWdtjzVoPNTurseswxGvp+tGt6APA9ZX3UDqIAkFqzk4UmdzKnIQjvYPetoqpO2Hju kdgTbz158mwnJSTBnrRsHg7p8zRR/ZD4mKbbPRixOq/Npm/rqbA+xzfd3boaS/W+qY85 jarvYoT/zVGSzTsqHO5eB2o3Z1VeEZMbM/MjCZmWHq8x5YrD2wJa+yq6Emascubu9sXP qysY2oObBttflKj6Aoduxkz0I7bkRaWxvrP+ljMdosb7Q9MNRzgg0s7bOfLoa554n346 QryA== X-Gm-Message-State: AMCzsaUEJLaxG+qPaQ1WJgivN7ZfBiXCcvEzjBbKTXHE9m/g7JGu3ICN tLc7RvUE38ud10xDQcz3/oNnssVL X-Google-Smtp-Source: AOwi7QB947AzyPRKa13IiIMti40DdFLG/4MRU5EAj153q/m8OsqsaYaUqN+2mnQLYWFNrWxK/nMOGQ== X-Received: by 10.55.143.197 with SMTP id r188mr1922299qkd.211.1507638215798; Tue, 10 Oct 2017 05:23:35 -0700 (PDT) Received: from localhost ([144.121.20.162]) by smtp.gmail.com with ESMTPSA id s27sm6398296qtj.81.2017.10.10.05.23.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Oct 2017 05:23:34 -0700 (PDT) From: Rob Clark To: U-Boot Mailing List Date: Tue, 10 Oct 2017 08:23:01 -0400 Message-Id: <20171010122309.25313-6-robdclark@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171010122309.25313-1-robdclark@gmail.com> References: <20171010122309.25313-1-robdclark@gmail.com> MIME-Version: 1.0 Cc: Heinrich Schuchardt , Leif Lindholm Subject: [U-Boot] [PATCH 05/11] efi_loader: console support for color attributes X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Shell.efi uses this, and supporting color attributes makes things look nicer. Map the EFI fg/bg color attributes to ANSI escape sequences. Not all colors have a perfect match, but spec just says "Devices supporting a different number of text colors are required to emulate the above colors to the best of the device’s capabilities". Signed-off-by: Rob Clark Tested-by: Heinrich Schuchardt Reviewed-by: Alexander Graf --- include/efi_api.h | 33 +++++++++++++++++++++++++++++++++ lib/efi_loader/efi_console.c | 27 +++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/include/efi_api.h b/include/efi_api.h index 58bf15b8e6..9610d03d47 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -427,6 +427,39 @@ struct simple_text_output_mode { EFI_GUID(0x387477c2, 0x69c7, 0x11d2, \ 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b) +#define EFI_BLACK 0x00 +#define EFI_BLUE 0x01 +#define EFI_GREEN 0x02 +#define EFI_CYAN 0x03 +#define EFI_RED 0x04 +#define EFI_MAGENTA 0x05 +#define EFI_BROWN 0x06 +#define EFI_LIGHTGRAY 0x07 +#define EFI_BRIGHT 0x08 +#define EFI_DARKGRAY 0x08 +#define EFI_LIGHTBLUE 0x09 +#define EFI_LIGHTGREEN 0x0a +#define EFI_LIGHTCYAN 0x0b +#define EFI_LIGHTRED 0x0c +#define EFI_LIGHTMAGENTA 0x0d +#define EFI_YELLOW 0x0e +#define EFI_WHITE 0x0f +#define EFI_BACKGROUND_BLACK 0x00 +#define EFI_BACKGROUND_BLUE 0x10 +#define EFI_BACKGROUND_GREEN 0x20 +#define EFI_BACKGROUND_CYAN 0x30 +#define EFI_BACKGROUND_RED 0x40 +#define EFI_BACKGROUND_MAGENTA 0x50 +#define EFI_BACKGROUND_BROWN 0x60 +#define EFI_BACKGROUND_LIGHTGRAY 0x70 + +/* extract foreground color from EFI attribute */ +#define EFI_ATTR_FG(attr) ((attr) & 0x07) +/* treat high bit of FG as bright/bold (similar to edk2) */ +#define EFI_ATTR_BOLD(attr) (((attr) >> 3) & 0x01) +/* extract background color from EFI attribute */ +#define EFI_ATTR_BG(attr) (((attr) >> 4) & 0x7) + struct efi_simple_text_output_protocol { void *reset; efi_status_t (EFIAPI *output_string)( diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c index f508b79ab8..c25d6b16f2 100644 --- a/lib/efi_loader/efi_console.c +++ b/lib/efi_loader/efi_console.c @@ -316,14 +316,37 @@ static efi_status_t EFIAPI efi_cout_set_mode( return EFI_EXIT(EFI_SUCCESS); } +static const struct { + unsigned fg; + unsigned bg; +} color[] = { + { 30, 40 }, /* 0: black */ + { 34, 44 }, /* 1: blue */ + { 32, 42 }, /* 2: green */ + { 36, 46 }, /* 3: cyan */ + { 31, 41 }, /* 4: red */ + { 35, 45 }, /* 5: magenta */ + { 33, 43 }, /* 6: brown, map to yellow as edk2 does*/ + { 37, 47 }, /* 7: light grey, map to white */ +}; + +/* See EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute(). */ static efi_status_t EFIAPI efi_cout_set_attribute( struct efi_simple_text_output_protocol *this, unsigned long attribute) { + unsigned int bold = EFI_ATTR_BOLD(attribute); + unsigned int fg = EFI_ATTR_FG(attribute); + unsigned int bg = EFI_ATTR_BG(attribute); + EFI_ENTRY("%p, %lx", this, attribute); - /* Just ignore attributes (colors) for now */ - return EFI_EXIT(EFI_UNSUPPORTED); + if (attribute) + printf(ESC"[%u;%u;%um", bold, color[fg].fg, color[bg].bg); + else + printf(ESC"[0;37;40m"); + + return EFI_EXIT(EFI_SUCCESS); } static efi_status_t EFIAPI efi_cout_clear_screen(