mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/5] fbconsole: use symbolic names for ANSI colors
@ 2025-06-01 20:59 Ahmad Fatoum
  2025-06-01 20:59 ` [PATCH 2/5] fbconsole: darken shade of non-bright white Ahmad Fatoum
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Ahmad Fatoum @ 2025-06-01 20:59 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Instead of hardcoding color indices, let's define symbolic names and use
them throughout. This makes it clear that we are using different default
colors, which will be fixed in the follow-up commit.

No functional change.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 drivers/video/fbconsole.c | 51 +++++++++++++++++++++------------------
 1 file changed, 28 insertions(+), 23 deletions(-)

diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 401b36c4de73..55df524a96a3 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -32,6 +32,11 @@ static const char * const rotation_names[] = {
 	[FBCONSOLE_ROTATE_270] = "270",
 };
 
+enum ansi_color {
+	BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE,
+	BRIGHT
+};
+
 struct fbc_priv {
 	struct console_device cdev;
 	struct fb_info *fb;
@@ -111,22 +116,22 @@ struct rgb {
 };
 
 static struct rgb colors[] = {
-	{ 0, 0, 0 },
-	{ 205, 0, 0 },
-	{ 0, 205, 0 },
-	{ 205, 205, 0 },
-	{ 0, 0, 238 },
-	{ 205, 0, 205 },
-	{ 0, 205, 205 },
-	{ 229, 229, 229 },
-	{ 127, 127, 127 },
-	{ 255, 0, 0 },
-	{ 0, 255, 0 },
-	{ 255, 255, 0 },
-	{ 92, 92, 255 },
-	{ 255, 0, 255 },
-	{ 0, 255, 255 },
-	{ 255, 255, 255 },
+	[BLACK]			= { 0, 0, 0 },
+	[RED]			= { 205, 0, 0 },
+	[GREEN]			= { 0, 205, 0 },
+	[YELLOW]		= { 205, 205, 0 },
+	[BLUE]			= { 0, 0, 238 },
+	[MAGENTA]		= { 205, 0, 205 },
+	[CYAN]			= { 0, 205, 205 },
+	[WHITE]			= { 229, 229, 229 },
+	[BRIGHT + BLACK]	= { 127, 127, 127 },
+	[BRIGHT + RED]		= { 255, 0, 0 },
+	[BRIGHT + GREEN]	= { 0, 255, 0 },
+	[BRIGHT + YELLOW]	= { 255, 255, 0 },
+	[BRIGHT + BLUE]		= { 92, 92, 255 },
+	[BRIGHT + MAGENTA]	= { 255, 0, 255 },
+	[BRIGHT + CYAN]		= { 0, 255, 255 },
+	[BRIGHT + WHITE]	= { 255, 255, 255 },
 };
 
 static void drawchar(struct fbc_priv *priv, int x, int y, int c)
@@ -155,7 +160,7 @@ static void drawchar(struct fbc_priv *priv, int x, int y, int c)
 	bgcolor = priv->flags & ANSI_FLAG_INVERT ? priv->color : priv->bgcolor;
 
 	if (priv->flags & ANSI_FLAG_BRIGHT)
-		color += 8;
+		color += BRIGHT;
 
 	rgb = &colors[color];
 	color = gu_rgb_to_pixel(priv->fb, rgb->r, rgb->g, rgb->b, 0xff);
@@ -490,8 +495,8 @@ static void fbc_parse_colors(struct fbc_priv *priv)
 		switch (code) {
 		case 0:
 			priv->flags = 0;
-			priv->color = 8;
-			priv->bgcolor = 0;
+			priv->color = BRIGHT + BLACK;
+			priv->bgcolor = BLACK;
 			break;
 		case 1:
 			priv->flags |= ANSI_FLAG_BRIGHT;
@@ -503,13 +508,13 @@ static void fbc_parse_colors(struct fbc_priv *priv)
 			priv->color = code - 30;
 			break;
 		case 39:
-			priv->color = 7;
+			priv->color = WHITE;
 			break;
 		case 40 ... 47:
 			priv->bgcolor = code - 40;
 			break;
 		case 49:
-			priv->bgcolor = 0;
+			priv->bgcolor = BLACK;
 			break;
 		}
 
@@ -814,8 +819,8 @@ int register_fbconsole(struct fb_info *fb)
 	priv->fb = fb;
 	priv->x = 0;
 	priv->y = 0;
-	priv->color = 7;
-	priv->bgcolor = 0;
+	priv->color = WHITE;
+	priv->bgcolor = BLACK;
 
 	cdev = &priv->cdev;
 	cdev->dev = &fb->dev;
-- 
2.39.5




^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/5] fbconsole: darken shade of non-bright white
  2025-06-01 20:59 [PATCH 1/5] fbconsole: use symbolic names for ANSI colors Ahmad Fatoum
@ 2025-06-01 20:59 ` Ahmad Fatoum
  2025-06-01 21:00 ` [PATCH 3/5] fbconsole: add support for aixterm bright colors Ahmad Fatoum
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Ahmad Fatoum @ 2025-06-01 20:59 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Bold/bright white at 255 is too close to 229 for the shades to be
clearly discernible. Bump down the white to 205 instead, which is
still white-ish enough.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 drivers/video/fbconsole.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 55df524a96a3..cd1950a644cc 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -123,7 +123,7 @@ static struct rgb colors[] = {
 	[BLUE]			= { 0, 0, 238 },
 	[MAGENTA]		= { 205, 0, 205 },
 	[CYAN]			= { 0, 205, 205 },
-	[WHITE]			= { 229, 229, 229 },
+	[WHITE]			= { 205, 205, 205 },
 	[BRIGHT + BLACK]	= { 127, 127, 127 },
 	[BRIGHT + RED]		= { 255, 0, 0 },
 	[BRIGHT + GREEN]	= { 0, 255, 0 },
-- 
2.39.5




^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/5] fbconsole: add support for aixterm bright colors
  2025-06-01 20:59 [PATCH 1/5] fbconsole: use symbolic names for ANSI colors Ahmad Fatoum
  2025-06-01 20:59 ` [PATCH 2/5] fbconsole: darken shade of non-bright white Ahmad Fatoum
@ 2025-06-01 21:00 ` Ahmad Fatoum
  2025-06-01 21:00 ` [PATCH 4/5] fbconsole: use only one default color Ahmad Fatoum
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Ahmad Fatoum @ 2025-06-01 21:00 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We already support the global bold/bright modifier, but there are also
inherently bright color codes, apparently first added for AIX.

Teach barebox about them.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 drivers/video/fbconsole.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index cd1950a644cc..b399c044be94 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -516,6 +516,10 @@ static void fbc_parse_colors(struct fbc_priv *priv)
 		case 49:
 			priv->bgcolor = BLACK;
 			break;
+		case 90 ... 97:
+			priv->flags |= ANSI_FLAG_BRIGHT;
+			priv->color = code - 90;
+			break;
 		}
 
 		if (*str != ';')
-- 
2.39.5




^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 4/5] fbconsole: use only one default color
  2025-06-01 20:59 [PATCH 1/5] fbconsole: use symbolic names for ANSI colors Ahmad Fatoum
  2025-06-01 20:59 ` [PATCH 2/5] fbconsole: darken shade of non-bright white Ahmad Fatoum
  2025-06-01 21:00 ` [PATCH 3/5] fbconsole: add support for aixterm bright colors Ahmad Fatoum
@ 2025-06-01 21:00 ` Ahmad Fatoum
  2025-06-01 21:00 ` [PATCH 5/5] fbconsole: reset cursor to origin when changing fonts Ahmad Fatoum
  2025-06-02  7:42 ` (subset) [PATCH 1/5] fbconsole: use symbolic names for ANSI colors Sascha Hauer
  4 siblings, 0 replies; 8+ messages in thread
From: Ahmad Fatoum @ 2025-06-01 21:00 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The default framebuffer color is (dark) white, which we also revert to
when resetting the default color and keeping style intact.

We also support the ANSI "reset all colors/styles" sequence and include
it in the default barebox prompt, but that one doesn't currently default
to white, but bright black (gray) instead.

Given that we have a pitch black background by default, dark white is
easier on the eyes than gray, so let's make that the singular default.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 drivers/video/fbconsole.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index b399c044be94..167569abd5c1 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -37,6 +37,8 @@ enum ansi_color {
 	BRIGHT
 };
 
+#define DEFAULT_COLOR	WHITE
+
 struct fbc_priv {
 	struct console_device cdev;
 	struct fb_info *fb;
@@ -495,7 +497,7 @@ static void fbc_parse_colors(struct fbc_priv *priv)
 		switch (code) {
 		case 0:
 			priv->flags = 0;
-			priv->color = BRIGHT + BLACK;
+			priv->color = DEFAULT_COLOR;
 			priv->bgcolor = BLACK;
 			break;
 		case 1:
@@ -508,7 +510,7 @@ static void fbc_parse_colors(struct fbc_priv *priv)
 			priv->color = code - 30;
 			break;
 		case 39:
-			priv->color = WHITE;
+			priv->color = DEFAULT_COLOR;
 			break;
 		case 40 ... 47:
 			priv->bgcolor = code - 40;
-- 
2.39.5




^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 5/5] fbconsole: reset cursor to origin when changing fonts
  2025-06-01 20:59 [PATCH 1/5] fbconsole: use symbolic names for ANSI colors Ahmad Fatoum
                   ` (2 preceding siblings ...)
  2025-06-01 21:00 ` [PATCH 4/5] fbconsole: use only one default color Ahmad Fatoum
@ 2025-06-01 21:00 ` Ahmad Fatoum
  2025-06-01 21:02   ` Ahmad Fatoum
  2025-06-02  7:42   ` (subset) " Sascha Hauer
  2025-06-02  7:42 ` (subset) [PATCH 1/5] fbconsole: use symbolic names for ANSI colors Sascha Hauer
  4 siblings, 2 replies; 8+ messages in thread
From: Ahmad Fatoum @ 2025-06-01 21:00 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

If we switch from one font to another, we update priv->rows and
priv->cols, but priv->x and priv->y remain at their old values.

This becomes problematic, when a bigger font is chosen, because the
coordinates may now exceed the maximum number of rows and lines,
triggering an out-of-bounds memory access, when they are scaled
according to the new font.

Fix this by resetting to (0, 0) whenever the number of columns and rows
changes. The end result looks neater anyway.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 drivers/video/fbconsole.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
index 167569abd5c1..fd220a6c1e05 100644
--- a/drivers/video/fbconsole.c
+++ b/drivers/video/fbconsole.c
@@ -679,6 +679,7 @@ static int setup_font(struct fbc_priv *priv)
 	const struct font_desc *font;
 	unsigned int height = priv->fb->yres - priv->margin.top - priv->margin.bottom;
 	unsigned int width = priv->fb->xres - priv->margin.left - priv->margin.right;
+	unsigned int newrows, newcols;
 
 	font = find_font_enum(priv->par_font_val);
 	if (!font) {
@@ -690,14 +691,22 @@ static int setup_font(struct fbc_priv *priv)
 	switch (priv->rotation) {
 	case FBCONSOLE_ROTATE_0:
 	case FBCONSOLE_ROTATE_180:
-		priv->rows = height / priv->font->height;
-		priv->cols = width / priv->font->width;
+		newrows = height / priv->font->height;
+		newcols = width / priv->font->width;
 		break;
 	case FBCONSOLE_ROTATE_90:
 	case FBCONSOLE_ROTATE_270:
-		priv->rows = width / priv->font->height;
-		priv->cols = height / priv->font->width;
+		newrows = width / priv->font->height;
+		newcols = height / priv->font->width;
 		break;
+	default:
+		return -EINVAL;
+	}
+
+	if (priv->rows != newrows || priv->cols != newcols) {
+		priv->rows = newrows;
+		priv->cols = newcols;
+		priv->x = priv->y = 0;
 	}
 
 	return 0;
-- 
2.39.5




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 5/5] fbconsole: reset cursor to origin when changing fonts
  2025-06-01 21:00 ` [PATCH 5/5] fbconsole: reset cursor to origin when changing fonts Ahmad Fatoum
@ 2025-06-01 21:02   ` Ahmad Fatoum
  2025-06-02  7:42   ` (subset) " Sascha Hauer
  1 sibling, 0 replies; 8+ messages in thread
From: Ahmad Fatoum @ 2025-06-01 21:02 UTC (permalink / raw)
  To: Ahmad Fatoum, barebox

On 01.06.25 23:00, Ahmad Fatoum wrote:
> If we switch from one font to another, we update priv->rows and
> priv->cols, but priv->x and priv->y remain at their old values.
> 
> This becomes problematic, when a bigger font is chosen, because the
> coordinates may now exceed the maximum number of rows and lines,
> triggering an out-of-bounds memory access, when they are scaled
> according to the new font.
> 
> Fix this by resetting to (0, 0) whenever the number of columns and rows
> changes. The end result looks neater anyway.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>

Should've made this the first commit. Can this one be applied to master as well?

> ---
>  drivers/video/fbconsole.c | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/video/fbconsole.c b/drivers/video/fbconsole.c
> index 167569abd5c1..fd220a6c1e05 100644
> --- a/drivers/video/fbconsole.c
> +++ b/drivers/video/fbconsole.c
> @@ -679,6 +679,7 @@ static int setup_font(struct fbc_priv *priv)
>  	const struct font_desc *font;
>  	unsigned int height = priv->fb->yres - priv->margin.top - priv->margin.bottom;
>  	unsigned int width = priv->fb->xres - priv->margin.left - priv->margin.right;
> +	unsigned int newrows, newcols;
>  
>  	font = find_font_enum(priv->par_font_val);
>  	if (!font) {
> @@ -690,14 +691,22 @@ static int setup_font(struct fbc_priv *priv)
>  	switch (priv->rotation) {
>  	case FBCONSOLE_ROTATE_0:
>  	case FBCONSOLE_ROTATE_180:
> -		priv->rows = height / priv->font->height;
> -		priv->cols = width / priv->font->width;
> +		newrows = height / priv->font->height;
> +		newcols = width / priv->font->width;
>  		break;
>  	case FBCONSOLE_ROTATE_90:
>  	case FBCONSOLE_ROTATE_270:
> -		priv->rows = width / priv->font->height;
> -		priv->cols = height / priv->font->width;
> +		newrows = width / priv->font->height;
> +		newcols = height / priv->font->width;
>  		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	if (priv->rows != newrows || priv->cols != newcols) {
> +		priv->rows = newrows;
> +		priv->cols = newcols;
> +		priv->x = priv->y = 0;
>  	}
>  
>  	return 0;


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: (subset) [PATCH 1/5] fbconsole: use symbolic names for ANSI colors
  2025-06-01 20:59 [PATCH 1/5] fbconsole: use symbolic names for ANSI colors Ahmad Fatoum
                   ` (3 preceding siblings ...)
  2025-06-01 21:00 ` [PATCH 5/5] fbconsole: reset cursor to origin when changing fonts Ahmad Fatoum
@ 2025-06-02  7:42 ` Sascha Hauer
  4 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2025-06-02  7:42 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Sun, 01 Jun 2025 22:59:58 +0200, Ahmad Fatoum wrote:
> Instead of hardcoding color indices, let's define symbolic names and use
> them throughout. This makes it clear that we are using different default
> colors, which will be fixed in the follow-up commit.
> 
> No functional change.
> 
> 
> [...]

Applied, thanks!

[1/5] fbconsole: use symbolic names for ANSI colors
      https://git.pengutronix.de/cgit/barebox/commit/?id=57d83a39bba3 (link may not be stable)
[2/5] fbconsole: darken shade of non-bright white
      https://git.pengutronix.de/cgit/barebox/commit/?id=33c13215a36e (link may not be stable)
[3/5] fbconsole: add support for aixterm bright colors
      https://git.pengutronix.de/cgit/barebox/commit/?id=c286f7e0efa0 (link may not be stable)
[4/5] fbconsole: use only one default color
      https://git.pengutronix.de/cgit/barebox/commit/?id=b4c59c0c9753 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: (subset) [PATCH 5/5] fbconsole: reset cursor to origin when changing fonts
  2025-06-01 21:00 ` [PATCH 5/5] fbconsole: reset cursor to origin when changing fonts Ahmad Fatoum
  2025-06-01 21:02   ` Ahmad Fatoum
@ 2025-06-02  7:42   ` Sascha Hauer
  1 sibling, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2025-06-02  7:42 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Sun, 01 Jun 2025 23:00:02 +0200, Ahmad Fatoum wrote:
> If we switch from one font to another, we update priv->rows and
> priv->cols, but priv->x and priv->y remain at their old values.
> 
> This becomes problematic, when a bigger font is chosen, because the
> coordinates may now exceed the maximum number of rows and lines,
> triggering an out-of-bounds memory access, when they are scaled
> according to the new font.
> 
> [...]

Applied, thanks!

[5/5] fbconsole: reset cursor to origin when changing fonts
      https://git.pengutronix.de/cgit/barebox/commit/?id=812b498be405 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-06-02  7:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-01 20:59 [PATCH 1/5] fbconsole: use symbolic names for ANSI colors Ahmad Fatoum
2025-06-01 20:59 ` [PATCH 2/5] fbconsole: darken shade of non-bright white Ahmad Fatoum
2025-06-01 21:00 ` [PATCH 3/5] fbconsole: add support for aixterm bright colors Ahmad Fatoum
2025-06-01 21:00 ` [PATCH 4/5] fbconsole: use only one default color Ahmad Fatoum
2025-06-01 21:00 ` [PATCH 5/5] fbconsole: reset cursor to origin when changing fonts Ahmad Fatoum
2025-06-01 21:02   ` Ahmad Fatoum
2025-06-02  7:42   ` (subset) " Sascha Hauer
2025-06-02  7:42 ` (subset) [PATCH 1/5] fbconsole: use symbolic names for ANSI colors Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox