From patchwork Wed Sep 13 22:12:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 813662 X-Patchwork-Delegate: agust@denx.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="bmpnDn32"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xsx541Zk7z9sxR for ; Thu, 14 Sep 2017 08:23:20 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id E90D3C222FE; Wed, 13 Sep 2017 22:20:18 +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 073F7C2275A; Wed, 13 Sep 2017 22:20:16 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 99B7EC22766; Wed, 13 Sep 2017 22:12:42 +0000 (UTC) Received: from mail-qt0-f194.google.com (mail-qt0-f194.google.com [209.85.216.194]) by lists.denx.de (Postfix) with ESMTPS id 0EACBC2222A for ; Wed, 13 Sep 2017 22:12:36 +0000 (UTC) Received: by mail-qt0-f194.google.com with SMTP id t46so949306qtj.3 for ; Wed, 13 Sep 2017 15:12:36 -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; bh=r/bhCAJ8JDz2goG1KgDPPLDzuaAvPHuu7Eu9hHjwt5s=; b=bmpnDn32qPMmBMqguUC/llG/EBg60qlutl69RrZFQnskFw6yEywmgXxDmJU9E6psyF 8u45QPAciC1g5WKDb/6GIbFa6pULDY7i80tLGjEH9NQhpvGFAYmQr7mfVJAI/s0LXAax 7YKOEO3/GdwTiVlomMknI2QzAmZgwQt0j1xDy5U+VM73LBAXhmqcr56WlwiT9Gh/AVr9 WRjBoTFBLxcPgSO3/0G2YUlalcOt4eAbCiVnMlUUpiuoHHplbMB06Jye3E2qRreC3bNa kGwAfQ8Sv0/GjlpN7Gjkjx8Jr7iKhTm6PGggro7XEA+mllY4xtAGCIb2dYXIj8cURIt5 1t0w== 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; bh=r/bhCAJ8JDz2goG1KgDPPLDzuaAvPHuu7Eu9hHjwt5s=; b=ZAeHpOr8tV+huDeqOi36hEU/uwnQ8v3lMQOXAMTFllINJyqmHFlqKkCEqj8UwRwZA0 0enZ4oD62LNFHJQ5RNUDb8lKPtFMbCqJlQC8fcoo0LcG4QrHomq+E7eUbRnz0uhq5mUz y84Qtg7BV5Y0OW/8rXFFoi6PWmWAnmjsJeSJuvQnsv57RXTNyba9gW1zYqoPEwreDW1m HX5lD1PvR/aAPAwYVXvMRMP9LzmImGGF4YGoScNkmw8bCnEoZMagBlVoIQNfDuVL8096 wkvjzPMfoknQcR99Tbta35FfR8yOeNMK1H2XkRIi1Bl39R4OtzZsNEqv49t37ocMcIzk sjqg== X-Gm-Message-State: AHPjjUg32Rqby5QUy+eXydnb+b5RS4V7fN9rz5BP5nc/i1TWvG03iY3s Jfo2KGJrM3uzMCb2a5I= X-Google-Smtp-Source: AOwi7QBTH0JGLtJ6oGbSX70nhFWnEwiyCnqCRYAqSjBcOGzPRWgGFI8Ct/8afsqojALrXXdGaT9Png== X-Received: by 10.237.62.59 with SMTP id l56mr22111194qtf.261.1505340754779; Wed, 13 Sep 2017 15:12:34 -0700 (PDT) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id d22sm10273636qkj.88.2017.09.13.15.12.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Sep 2017 15:12:33 -0700 (PDT) From: Rob Clark To: U-Boot Mailing List Date: Wed, 13 Sep 2017 18:12:20 -0400 Message-Id: <20170913221227.21091-2-robdclark@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170913221227.21091-1-robdclark@gmail.com> References: <20170913221227.21091-1-robdclark@gmail.com> Subject: [U-Boot] [PATCH 1/3] dm: video: Fix cache flushes 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Content can come to screen via putc() and we cannot always rely on updates ending with a puts(). This is the case with efi_console output to vidconsole. Fixes corruption with Shell.efi. Signed-off-by: Rob Clark --- drivers/video/vidconsole-uclass.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index b5afd72227..e081d5a0ee 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -163,6 +163,7 @@ static void vidconsole_putc(struct stdio_dev *sdev, const char ch) struct udevice *dev = sdev->priv; vidconsole_put_char(dev, ch); + video_sync(dev->parent); } static void vidconsole_puts(struct stdio_dev *sdev, const char *s) @@ -260,6 +261,8 @@ static int do_video_puts(cmd_tbl_t *cmdtp, int flag, int argc, for (s = argv[1]; *s; s++) vidconsole_put_char(dev, *s); + video_sync(dev->parent); + return 0; } From patchwork Wed Sep 13 22:12:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 813649 X-Patchwork-Delegate: agust@denx.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="ao1dqhBU"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xswxl4fL4z9s76 for ; Thu, 14 Sep 2017 08:16:59 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 64493C22734; Wed, 13 Sep 2017 22:15:42 +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 4194DC226F1; Wed, 13 Sep 2017 22:15:39 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CF74EC226EC; Wed, 13 Sep 2017 22:12:45 +0000 (UTC) Received: from mail-qt0-f196.google.com (mail-qt0-f196.google.com [209.85.216.196]) by lists.denx.de (Postfix) with ESMTPS id 581AAC225FA for ; Wed, 13 Sep 2017 22:12:39 +0000 (UTC) Received: by mail-qt0-f196.google.com with SMTP id q8so956225qtb.1 for ; Wed, 13 Sep 2017 15:12:39 -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; bh=6aYzn8t2pRojHu/tD/wxkbPdEm4nfbOHbDAbS+PeC9k=; b=ao1dqhBUBznzz3W3//116f6tv+B0+cZ9vRIIYolWS9U8RVQHqNsYpnR+GK5DPbOSHP 2iteKrII0xP/cwqJsi272zNSNn4A7/XCvmrNmXfWdNKrJgZMIiCFARbgyeX+B6F4Abmf 81fHxRKC54v1A64SQHNrvR+0NsR4AFLX67W/WE6VU3eI3Hw+XxGMzZiG8fJM3hyb/753 9jb7ODUX3FmMJWzhbQIG1kxI2X7v/oRkfPj5iChJv2PMb/zHYi1L/0tacaB6P9Xc8/Mi EO1mrv3KOtF4mpGGpLZJyXm4r9sea/rSl7cuqNAmZw36bS0sWoyuMDSvwcxXpwPn/nq3 kAvw== 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; bh=6aYzn8t2pRojHu/tD/wxkbPdEm4nfbOHbDAbS+PeC9k=; b=JkRq2X4ROmgKV99TeZZzUnC1i3SlR5qT5Vd1cY0lMQQ7X3EL58dYTZf4pOMOz4WHrd k+UiNPUE8HjJ8lphlu62g2jfBjJgoT1UTPXIy0IU57dv0CHXxNW3K0D4S04oU4kiYCkN vAU60ZQe1k1DHRGusKjpHUtE4KNg0wbmqf8SJP2NdOffXxQogjvVVPYYPKKgP5lDZDiu G+U7kKVprQhIj3fzUJn+eH5uRd5jL8655nbUQvGxkXoBhkzsyZhIUnOrfiU1YcOr21NO NUTj+oSelNYJ4QdlBUTV0tbg3eMhS/Rs9J1k8ipDZdUCXEe/flqGcWJXr011mD9h9tg1 1row== X-Gm-Message-State: AHPjjUhkcojSuR/Dmjv96524x0+2VPuDOARJrEq311jdowhrayhYMWsL miydbhC7Q6LpRE8+C1g= X-Google-Smtp-Source: AOwi7QB9tX0BKzGhTroyeEPaWvjS0I48tMmNDGdVcsCtPG5HkzY44gQRDuxiOZ3xNxfH8oi0sz9qcg== X-Received: by 10.237.33.188 with SMTP id l57mr14103257qtc.270.1505340757964; Wed, 13 Sep 2017 15:12:37 -0700 (PDT) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id m126sm9872979qkd.52.2017.09.13.15.12.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Sep 2017 15:12:36 -0700 (PDT) From: Rob Clark To: U-Boot Mailing List Date: Wed, 13 Sep 2017 18:12:21 -0400 Message-Id: <20170913221227.21091-3-robdclark@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170913221227.21091-1-robdclark@gmail.com> References: <20170913221227.21091-1-robdclark@gmail.com> Subject: [U-Boot] [PATCH 2/3] dm: video: Add basic ANSI escape sequence support 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Really just the subset that is needed by efi_console. Perhaps more will be added later, for example color support would be useful to implement efi_cout_set_attribute(). Signed-off-by: Rob Clark Reviewed-by: Simon Glass --- drivers/video/Kconfig | 8 +++ drivers/video/vidconsole-uclass.c | 109 ++++++++++++++++++++++++++++++++++++++ drivers/video/video-uclass.c | 4 +- include/video.h | 7 +++ include/video_console.h | 11 ++++ 5 files changed, 136 insertions(+), 3 deletions(-) diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index 082cc4a528..add156cb70 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -44,6 +44,14 @@ config VIDEO_BPP32 this option, such displays will not be supported and console output will be empty. +config VIDEO_ANSI + bool "Support ANSI escape sequences in video console" + depends on DM_VIDEO + default y if DM_VIDEO + help + Enable ANSI escape sequence decoding for a more fully functional + console. + config CONSOLE_NORMAL bool "Support a simple text console" depends on DM_VIDEO diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index e081d5a0ee..0a88cc0a42 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -107,12 +108,120 @@ static void vidconsole_newline(struct udevice *dev) video_sync(dev->parent); } +static char *parsenum(char *s, int *num) +{ + char *end; + *num = simple_strtol(s, &end, 10); + return end; +} + +/* + * Process a character while accumulating an escape string. Chars are + * accumulated into escape_buf until the end of escape sequence is + * found, at which point the sequence is parsed and processed. + */ +static void vidconsole_escape_char(struct udevice *dev, char ch) +{ + struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + + if (!IS_ENABLED(CONFIG_VIDEO_ANSI)) + goto error; + + /* Sanity checking for bogus ESC sequences: */ + if (priv->escape_len >= sizeof(priv->escape_buf)) + goto error; + if (priv->escape_len == 0 && ch != '[') + goto error; + + priv->escape_buf[priv->escape_len++] = ch; + + /* + * Escape sequences are terminated by a letter, so keep + * accumulating until we get one: + */ + if (!isalpha(ch)) + return; + + /* + * clear escape mode first, otherwise things will get highly + * surprising if you hit any debug prints that come back to + * this console. + */ + priv->escape = 0; + + switch (ch) { + case 'H': + case 'f': { + int row, col; + char *s = priv->escape_buf; + + /* + * Set cursor position: [%d;%df or [%d;%dH + */ + s++; /* [ */ + s = parsenum(s, &row); + s++; /* ; */ + s = parsenum(s, &col); + + priv->ycur = row * priv->y_charsize; + priv->xcur_frac = priv->xstart_frac + + VID_TO_POS(col * priv->x_charsize); + + break; + } + case 'J': { + int mode; + + /* + * Clear part/all screen: + * [J or [0J - clear screen from cursor down + * [1J - clear screen from cursor up + * [2J - clear entire screen + * + * TODO we really only handle entire-screen case, others + * probably require some additions to video-uclass (and + * are not really needed yet by efi_console) + */ + parsenum(priv->escape_buf + 1, &mode); + + if (mode == 2) { + video_clear(dev->parent); + video_sync(dev->parent); + priv->ycur = 0; + priv->xcur_frac = priv->xstart_frac; + } else { + debug("unsupported clear mode: %d\n", mode); + } + break; + } + default: + debug("unrecognized escape sequence: %*s\n", + priv->escape_len, priv->escape_buf); + } + + return; + +error: + /* something went wrong, just revert to normal mode: */ + priv->escape = 0; + return; +} + int vidconsole_put_char(struct udevice *dev, char ch) { struct vidconsole_priv *priv = dev_get_uclass_priv(dev); int ret; + if (priv->escape) { + vidconsole_escape_char(dev, ch); + return 0; + } + switch (ch) { + case '\x1b': + priv->escape_len = 0; + priv->escape = 1; + break; case '\a': /* beep */ break; diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c index 3036e3a1f2..0163039821 100644 --- a/drivers/video/video-uclass.c +++ b/drivers/video/video-uclass.c @@ -87,7 +87,7 @@ int video_reserve(ulong *addrp) return 0; } -static int video_clear(struct udevice *dev) +void video_clear(struct udevice *dev) { struct video_priv *priv = dev_get_uclass_priv(dev); @@ -100,8 +100,6 @@ static int video_clear(struct udevice *dev) } else { memset(priv->fb, priv->colour_bg, priv->fb_size); } - - return 0; } /* Flush video activity to the caches */ diff --git a/include/video.h b/include/video.h index 5b4e78b182..61ff653121 100644 --- a/include/video.h +++ b/include/video.h @@ -115,6 +115,13 @@ struct video_ops { int video_reserve(ulong *addrp); /** + * video_clear() - Clear a device's frame buffer to background color. + * + * @dev: Device to clear + */ +void video_clear(struct udevice *dev); + +/** * video_sync() - Sync a device's frame buffer with its hardware * * Some frame buffers are cached or have a secondary frame buffer. This diff --git a/include/video_console.h b/include/video_console.h index 26047934da..9dce234bd9 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -29,6 +29,9 @@ * @xsize_frac: Width of the display in fractional units * @xstart_frac: Left margin for the text console in fractional units * @last_ch: Last character written to the text console on this line + * @escape: TRUE if currently accumulating an ANSI escape sequence + * @escape_len: Length of accumulated escape sequence so far + * @escape_buf: Buffer to accumulate escape sequence */ struct vidconsole_priv { struct stdio_dev sdev; @@ -42,6 +45,14 @@ struct vidconsole_priv { int xsize_frac; int xstart_frac; int last_ch; + /* + * ANSI escape sequences are accumulated character by character, + * starting after the ESC char (0x1b) until the entire sequence + * is consumed at which point it is acted upon. + */ + int escape; + int escape_len; + char escape_buf[32]; }; /** From patchwork Wed Sep 13 22:12:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 813661 X-Patchwork-Delegate: agust@denx.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="KNJLY0Bz"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xsx4h0FRTz9t0F for ; Thu, 14 Sep 2017 08:22:59 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 69C28C21EBC; Wed, 13 Sep 2017 22:18:28 +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 9A603C22732; Wed, 13 Sep 2017 22:18:25 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 04524C22617; Wed, 13 Sep 2017 22:12:48 +0000 (UTC) Received: from mail-qk0-f196.google.com (mail-qk0-f196.google.com [209.85.220.196]) by lists.denx.de (Postfix) with ESMTPS id CE13BC2245A for ; Wed, 13 Sep 2017 22:12:41 +0000 (UTC) Received: by mail-qk0-f196.google.com with SMTP id o77so953535qke.2 for ; Wed, 13 Sep 2017 15:12:41 -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; bh=p7enxtz18WXGN7EXeQYhuvP58LRIwvSyBPEQDaCdY/Q=; b=KNJLY0Bz9IN2/45ShxjPTEXqpilWZFjthqklpPTh/qTenoMmdM6xJf0qiSKpb2Avt8 KBJm0Q7xIPUVyEoA4I6NjbAkmm/h1bJopHouMgADrXbm5uLfmNvv1xvMNUfu4KdLbfdq 8H93dekuZHnuaNN31z7UZSFPkorVTSLKSRywIrnhSOWe8Z2DcLEATmv99hXnxsY1Ro9v Nghuw1dPNsSp1pFJ+T+oAOPBC1VT1b/7OZ4/pAndY3UASzLvPjnmtmn4QyA3DLr/oHuy OnDlyonX4/5lqvWX1ZntdSXEqnuTNdLrYIoqXGZjt+uPkePwSlqYAqbQkMDum5qSQfbw jQgg== 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; bh=p7enxtz18WXGN7EXeQYhuvP58LRIwvSyBPEQDaCdY/Q=; b=Z81a7Dw4lp/Lc7vsEcaEcelyFVfuFeYB5WvaUOVO/DyIhItTE3XeAua9O4yiv3zTeu DDfHsV4uJN0HQJpeKlsqO+xWwFs7PgGbVhtOhYMdLGdWKkR12f53FYlR5rYoQmZkDz5Q DC20ww0QMkd5beIjXqkt4ZUkcTGQ0EEZrKUEWLlt+lxC66ymimDH9Jc5hpSRhdIq6wHL w9DNEWZjqK43XMi9AFsbN05wo4sCOTzkjCFwdFkgE38DYQ3XuQ6SM97PqI9qKqPqY8yK rxcgaBWcF92SbYlQ4X8KCPkyk81UIBrTBQOt7Gdg5maEzb0jYFPIi2VsG5dMGpwQV+ge 0r8A== X-Gm-Message-State: AHPjjUgCYTZgXt8ClaaPb2GLzkajYBqLmGsoUBm+88n89NjRFkPdvwyG W3O4HlK4wOgK2XUljUA= X-Google-Smtp-Source: AOwi7QDk16Fyp+wbONdZiDgxq8obCcfsCIctJgL2rmReWZphwUnvcQieZ+phdqYTUolxVZ7g21YPdQ== X-Received: by 10.233.220.199 with SMTP id q190mr31466qkf.268.1505340760550; Wed, 13 Sep 2017 15:12:40 -0700 (PDT) Received: from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a]) by smtp.gmail.com with ESMTPSA id a22sm7713848qte.32.2017.09.13.15.12.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Sep 2017 15:12:39 -0700 (PDT) From: Rob Clark To: U-Boot Mailing List Date: Wed, 13 Sep 2017 18:12:22 -0400 Message-Id: <20170913221227.21091-4-robdclark@gmail.com> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170913221227.21091-1-robdclark@gmail.com> References: <20170913221227.21091-1-robdclark@gmail.com> Subject: [U-Boot] [PATCH 3/3] dm: video: Add color ANSI escape sequence support 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Note that this doesn't differentiate (due to lack of information in video_priv) between different possible component orders for 32bpp. But the main user at this point is efi_loader, and GOP expects xBGR so any video drivers that this is incorrect for already have problems. (Also, conveniently, this matches what simple-framebuffer bindings expect for kernels that use the simple-framebuffer DT binding to take over the bootloader display.) Signed-off-by: Rob Clark --- drivers/video/vidconsole-uclass.c | 94 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 0a88cc0a42..820540b1bf 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -108,6 +108,41 @@ static void vidconsole_newline(struct udevice *dev) video_sync(dev->parent); } +static const struct { + unsigned r; + unsigned g; + unsigned b; +} colors[] = { + { 0x00, 0x00, 0x00 }, /* black */ + { 0xff, 0x00, 0x00 }, /* red */ + { 0x00, 0xff, 0x00 }, /* green */ + { 0xff, 0xff, 0x00 }, /* yellow */ + { 0x00, 0x00, 0xff }, /* blue */ + { 0xff, 0x00, 0xff }, /* magenta */ + { 0x00, 0xff, 0xff }, /* cyan */ + { 0xff, 0xff, 0xff }, /* white */ +}; + +static void set_color(struct video_priv *priv, unsigned idx, unsigned *c) +{ + switch (priv->bpix) { + case VIDEO_BPP16: + *c = ((colors[idx].r >> 3) << 0) | + ((colors[idx].g >> 2) << 5) | + ((colors[idx].b >> 3) << 11); + break; + case VIDEO_BPP32: + *c = 0xff000000 | + (colors[idx].r << 0) | + (colors[idx].g << 8) | + (colors[idx].b << 16); + break; + default: + /* unsupported, leave current color in place */ + break; + } +} + static char *parsenum(char *s, int *num) { char *end; @@ -194,6 +229,65 @@ static void vidconsole_escape_char(struct udevice *dev, char ch) } break; } + case 'm': { + struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent); + char *s = priv->escape_buf; + char *end = &priv->escape_buf[priv->escape_len]; + + /* + * Set graphics mode: [%d;...;%dm + * + * Currently only supports the color attributes: + * + * Foreground Colors: + * + * 30 Black + * 31 Red + * 32 Green + * 33 Yellow + * 34 Blue + * 35 Magenta + * 36 Cyan + * 37 White + * + * Background Colors: + * + * 40 Black + * 41 Red + * 42 Green + * 43 Yellow + * 44 Blue + * 45 Magenta + * 46 Cyan + * 47 White + */ + + s++; /* [ */ + while (s < end) { + int val; + + s = parsenum(s, &val); + s++; + + switch (val) { + case 30 ... 37: + /* fg color */ + set_color(vid_priv, val - 30, + (unsigned *)&vid_priv->colour_fg); + break; + case 40 ... 47: + /* bg color */ + set_color(vid_priv, val - 40, + (unsigned *)&vid_priv->colour_bg); + break; + default: + /* unknown/unsupported */ + break; + } + } + + break; + } default: debug("unrecognized escape sequence: %*s\n", priv->escape_len, priv->escape_buf);