[U-Boot] [PATCH] dm: video: Add basic ANSI escape sequence support

Rob Clark robdclark at gmail.com
Mon Sep 11 20:42:22 UTC 2017


On Mon, Sep 11, 2017 at 8:31 AM, Rob Clark <robdclark at gmail.com> wrote:
> On Mon, Sep 11, 2017 at 7:50 AM, Lothar Waßmann <LW at karo-electronics.de> wrote:
>> Hi,
>>
>> On Mon, 11 Sep 2017 05:42:01 -0400 Rob Clark wrote:
>>> On Mon, Sep 11, 2017 at 2:18 AM, Simon Glass <sjg at chromium.org> wrote:
>>> > On 7 September 2017 at 14:28, Rob Clark <robdclark at gmail.com> wrote:
>>> >> 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 <robdclark at gmail.com>
>>> >> ---
>>> >>  drivers/video/vidconsole-uclass.c | 112 ++++++++++++++++++++++++++++++++++++++
>>> >>  drivers/video/video-uclass.c      |   4 +-
>>> >>  include/video.h                   |   7 +++
>>> >>  include/video_console.h           |  11 ++++
>>> >>  4 files changed, 131 insertions(+), 3 deletions(-)
>>> >>
>>> >> diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
>>> >> index e081d5a0ee..7998b4cf5f 100644
>>> >> --- a/drivers/video/vidconsole-uclass.c
>>> >> +++ b/drivers/video/vidconsole-uclass.c
>>> >> @@ -9,6 +9,7 @@
>>> >>   */
>>> >>
>>> >>  #include <common.h>
>>> >> +#include <linux/ctype.h>
>>> >>  #include <dm.h>
>>> >>  #include <video.h>
>>> >>  #include <video_console.h>
>>> >> @@ -107,12 +108,123 @@ static void vidconsole_newline(struct udevice *dev)
>>> >>         video_sync(dev->parent);
>>> >>  }
>>> >>
>>> >> +/*
>>> >> + * Parse a number from string that ends in a non-numeric character..
>>> >> + * sscanf() would be nice.  This is just enough for parsing ANSI escape
>>> >> + * sequences.
>>> >> + */
>>> >> +static char *parsenum(char *s, int *num)
>>> >
>>> > Can you use simple_strtoul() or similar?
>>>
>>> Possibly, but I'm not sure it is a good idea.. I don't think escape
>>> sequences are meant to be encoded with hex or octal number strings.
>>> From a quick look, I don't see any escape code terminated with 'x', so
>>> maybe it would end up working ok.. but something like ESC[0x1234m
>>> should be an escape sequence terminated with x followed by normal
>>> chars 1234m and strtoul would get that wrong..
>>>
>> stroul(s, NULL, 10) will only parse decimal numbers and stop at
>> non-decimal digits.
>>
>
> And you'd expect simple_strtoul() would too.. but that does not appear
> to be the case.  Not sure if that is intentional.
>

So I double checked simple_strtoul() in upstream kernel, and (apart
from being re-written) it seems to have fixed this bug.  So I'm
guessing the u-boot copied a buggy version from the linux kernel src
and never got a fix.  I'll send a patch for that.  It will be easy
enough to drop parsenum() once the fix is merged.

BR,
-R


More information about the U-Boot mailing list