From patchwork Sun Sep 10 13:22:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 812145 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="atausQi1"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xqsMJ3cpWz9s7g for ; Sun, 10 Sep 2017 23:28:28 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 3CCA3C21E8C; Sun, 10 Sep 2017 13:26:15 +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_DNSWL_NONE, 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 4E6E7C21F56; Sun, 10 Sep 2017 13:24:04 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E12C6C21F6C; Sun, 10 Sep 2017 13:23:19 +0000 (UTC) Received: from mail-qk0-f193.google.com (mail-qk0-f193.google.com [209.85.220.193]) by lists.denx.de (Postfix) with ESMTPS id D0885C21F3C for ; Sun, 10 Sep 2017 13:23:10 +0000 (UTC) Received: by mail-qk0-f193.google.com with SMTP id d70so4071027qkc.1 for ; Sun, 10 Sep 2017 06:23:10 -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=2xAWRAf/a5Nbxul9xbdSVE572q0Z9uMMhO3kG8dCpaQ=; b=atausQi1Lvynv6jduAI3c4iixa1xo0FH63k+tsLwIE/S5nHonxQgL/8oC+brfsez2Y DIYPcWjBFIU2QRKGOv9JgQYqAwq7wJICYWfHRq2jiSkOvzwzPSF3ct1UjfsC5liddC/h ROTas5meLdeM/CHRf4suFrr1XYCnOazuoAH+hNM7dxA9Yt1/B6lDhjbnOQGyzNBGrBpg 4L8EfO9lT6S4jQ70y9mFwt5PJPosu+itkQ0XFEYIWJNeV5m3GgU3v6fhtNt8DKXGacXd ezK/zAoASjRf4urMNUC2VQ6pDll7bQ6MbGqPw4HFN0mvDtoTV+5Sq4T0T4qGQCgz2vXh fkXQ== 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=2xAWRAf/a5Nbxul9xbdSVE572q0Z9uMMhO3kG8dCpaQ=; b=WI84A00J2Id8JL1A+wftxkJCJBR9BkGXXrMNR8YofHbccy/fS5sBnf6swMm070wj60 GXQH+M2rJDkc8fNjIbHpPeTIYSPL4OmZ6HeY/dkRjCqvJbIUwy6zaNVsG2utehklX1ld H9ylXXBLzfHX05btKZA6oFTiA84/F5Si+xFqPN5zXrMBvlcjSQFz7spzu+sBCl2D7H1j 2ciehyEFusjsF/vyybQSEbpgymf9G6zGqhHE8w26mT9D6g9gXQ2K+k/91L4WjwG68Yla K2V785XNZlGfk8Mo+obgin2Xa+PrZj8gE6mTsCkqOZX1jAlYkO7UvFqCY8w/Wrp7dLMj 9qtg== X-Gm-Message-State: AHPjjUgtEi4yqNS9Wd8J3mjodG302E17BvoWVpVMhKpndiVb6OaESaww Pjbr3gyNZN6M27AxWvI= X-Google-Smtp-Source: AOwi7QCaVHxsRAIof83mQSH9B/LZ2kW4tq6U1CeB25IEcMTHLkpoW/OjHIfsCA445m+VwxBsTfP+Yw== X-Received: by 10.55.76.196 with SMTP id z187mr11956889qka.100.1505049789483; Sun, 10 Sep 2017 06:23:09 -0700 (PDT) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id g132sm4200279qke.11.2017.09.10.06.23.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 10 Sep 2017 06:23:08 -0700 (PDT) From: Rob Clark To: U-Boot Mailing List Date: Sun, 10 Sep 2017 09:22:29 -0400 Message-Id: <20170910132236.14318-9-robdclark@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170910132236.14318-1-robdclark@gmail.com> References: <20170910132236.14318-1-robdclark@gmail.com> MIME-Version: 1.0 Cc: Heinrich Schuchardt , Peter Jones , Leif Lindholm Subject: [U-Boot] [PATCH v1 08/12] 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 --- include/efi_api.h | 29 +++++++++++++++++++++++++++++ lib/efi_loader/efi_console.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/include/efi_api.h b/include/efi_api.h index 87c8ffe68e..3cc1dbac2e 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -426,6 +426,35 @@ 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 + +#define EFI_ATTR_FG(attr) ((attr) & 0x0f) +#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 2e13fdc096..fcd65ca488 100644 --- a/lib/efi_loader/efi_console.c +++ b/lib/efi_loader/efi_console.c @@ -316,12 +316,42 @@ 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 */ + { 30, 40 }, /* 6: brown, map to black */ + { 37, 47 }, /* 7: light grey, map to white */ + { 37, 47 }, /* 8: bright, map to white */ + { 34, 44 }, /* 9: light blue, map to blue */ + { 32, 42 }, /* A: light green, map to green */ + { 36, 46 }, /* B: light cyan, map to cyan */ + { 31, 41 }, /* C: light red, map to red */ + { 35, 45 }, /* D: light magenta, map to magenta */ + { 33, 43 }, /* E: yellow */ + { 37, 47 }, /* F: white */ +}; + static efi_status_t EFIAPI efi_cout_set_attribute( struct efi_simple_text_output_protocol *this, unsigned long attribute) { + unsigned fg = EFI_ATTR_FG(attribute); + unsigned bg = EFI_ATTR_BG(attribute); + EFI_ENTRY("%p, %lx", this, attribute); + if (attribute) + printf(ESC"[%u;%um", color[fg].fg, color[bg].bg); + else + printf(ESC"[37;40m"); + /* Just ignore attributes (colors) for now */ return EFI_EXIT(EFI_UNSUPPORTED); }