git: a972d2692bb7 - main - bcm2835_fbd: Use the pixel order to choose the 32 bpp palette
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 27 Nov 2026 06:21:16 UTC
The branch main has been updated by manu:
URL: https://cgit.FreeBSD.org/src/commit/?id=a972d2692bb789f9c79da4ee27dd3c32d3e3f349
commit a972d2692bb789f9c79da4ee27dd3c32d3e3f349
Author: Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2026-11-19 17:36:04 +0000
Commit: Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2026-11-27 06:20:40 +0000
bcm2835_fbd: Use the pixel order to choose the 32 bpp palette
Recent Raspberry Pi firmware acts on the pixel order requested through
the mailbox, which older firmware ignored. The order that ends up in
the framebuffer is the requested one combined with framebuffer_swap in
config.txt: when they are the same the red component is in bits 0-7 of
a 32 bpp pixel, when they differ it is in bits 16-23. framebuffer_swap
defaults to on and the firmware reports it as bcm2708_fb.fbswap=1 in
the bootargs.
U-Boot always requests RGB, so with the default config.txt the pixels
have red in bits 0-7. The driver however always configured vt(4) with
red in bits 16-23 for 32 bpp, so red and blue were swapped on the
console.
The firmware does not report the resulting order, only the requested
one, so read the pixel order with GET_PIXEL_ORDER and combine it with
fbswap. If the pixel order cannot be read the previous behavior is
kept. The 24 bpp case is unchanged.
Print the pixel order in the attach message.
Reviewed by: imp
PR: 300542
Tested on: Raspberry Pi 4 Model B Rev 1.4
---
sys/arm/broadcom/bcm2835/bcm2835_fbd.c | 38 ++++++++++++++++++++++------
sys/arm/broadcom/bcm2835/bcm2835_mbox.c | 20 +++++++++++++++
sys/arm/broadcom/bcm2835/bcm2835_mbox_prop.h | 30 ++++++++++++++++++++++
3 files changed, 80 insertions(+), 8 deletions(-)
diff --git a/sys/arm/broadcom/bcm2835/bcm2835_fbd.c b/sys/arm/broadcom/bcm2835/bcm2835_fbd.c
index 50e8689e9d83..18d52e0196d1 100644
--- a/sys/arm/broadcom/bcm2835/bcm2835_fbd.c
+++ b/sys/arm/broadcom/bcm2835/bcm2835_fbd.c
@@ -103,6 +103,10 @@ bcm_fb_init(struct bcmsc_softc *sc, struct bcm2835_fb_config *fb)
return (ENXIO);
}
+ /* Not fatal: without it the colors keep the default layout. */
+ fb->pixel_order = BCM2835_MBOX_PIXEL_ORDER_UNKNOWN;
+ (void)bcm2835_mbox_fb_get_pixel_order(fb);
+
return (0);
}
@@ -132,19 +136,36 @@ bcm_fb_setup_fbd(struct bcmsc_softc *sc)
sc->info.fb_memattr = VM_MEMATTR_WRITE_COMBINING;
#endif
- if (sc->fbswap) {
- switch (sc->info.fb_bpp) {
- case 24:
+ switch (sc->info.fb_bpp) {
+ case 24:
+ if (sc->fbswap) {
vt_config_cons_colors(&sc->info,
COLOR_FORMAT_RGB, 0xff, 0, 0xff, 8, 0xff, 16);
sc->info.fb_cmsize = 16;
+ }
+ break;
+ case 32:
+ /*
+ * The order of the pixels is the pixel order that was
+ * requested through the mailbox (U-Boot asks for RGB)
+ * combined with framebuffer_swap in config.txt, which the
+ * firmware reports as bcm2708_fb.fbswap=1 in the bootargs
+ * (it is the default). The firmware inverts the requested
+ * order relative to framebuffer_swap: when the two differ
+ * the red component is in bits 16-23, which is the default
+ * layout of vt(4), when they are the same it is in bits
+ * 0-7. The firmware does not report the resulting order
+ * itself.
+ */
+ if (fb.pixel_order == BCM2835_MBOX_PIXEL_ORDER_UNKNOWN)
break;
- case 32:
+ if ((fb.pixel_order == BCM2835_MBOX_PIXEL_ORDER_RGB) ==
+ (sc->fbswap != 0)) {
vt_config_cons_colors(&sc->info,
- COLOR_FORMAT_RGB, 0xff, 16, 0xff, 8, 0xff, 0);
+ COLOR_FORMAT_RGB, 0xff, 0, 0xff, 8, 0xff, 16);
sc->info.fb_cmsize = 16;
- break;
}
+ break;
}
fbd = device_add_child(sc->dev, "fbd", device_get_unit(sc->dev));
@@ -162,8 +183,9 @@ bcm_fb_setup_fbd(struct bcmsc_softc *sc)
device_printf(sc->dev, "%dx%d(%dx%d@%d,%d) %dbpp\n", fb.xres, fb.yres,
fb.vxres, fb.vyres, fb.xoffset, fb.yoffset, fb.bpp);
device_printf(sc->dev,
- "fbswap: %d, pitch %d, base 0x%08x, screen_size %d\n",
- sc->fbswap, fb.pitch, fb.base, fb.size);
+ "fbswap: %d, pixel order: %d, pitch %d, base 0x%08x, "
+ "screen_size %d\n", sc->fbswap, (int)fb.pixel_order, fb.pitch,
+ fb.base, fb.size);
return (0);
}
diff --git a/sys/arm/broadcom/bcm2835/bcm2835_mbox.c b/sys/arm/broadcom/bcm2835/bcm2835_mbox.c
index c91647deae44..d1b0b51abd66 100644
--- a/sys/arm/broadcom/bcm2835/bcm2835_mbox.c
+++ b/sys/arm/broadcom/bcm2835/bcm2835_mbox.c
@@ -550,6 +550,26 @@ bcm2835_mbox_fb_get_bpp(struct bcm2835_fb_config *fb)
return (err);
}
+int
+bcm2835_mbox_fb_get_pixel_order(struct bcm2835_fb_config *fb)
+{
+ int err;
+ struct msg_fb_get_pixel_order msg;
+
+ memset(&msg, 0, sizeof(msg));
+ msg.hdr.buf_size = sizeof(msg);
+ msg.hdr.code = BCM2835_MBOX_CODE_REQ;
+ BCM2835_MBOX_INIT_TAG(&msg.pixel_order, GET_PIXEL_ORDER);
+ msg.pixel_order.tag_hdr.val_len = 0;
+ msg.end_tag = 0;
+
+ err = bcm2835_mbox_property(&msg, sizeof(msg));
+ if (err == 0)
+ fb->pixel_order = msg.pixel_order.body.resp.order;
+
+ return (err);
+}
+
int
bcm2835_mbox_fb_init(struct bcm2835_fb_config *fb)
{
diff --git a/sys/arm/broadcom/bcm2835/bcm2835_mbox_prop.h b/sys/arm/broadcom/bcm2835/bcm2835_mbox_prop.h
index 57130258a044..3840f943b96c 100644
--- a/sys/arm/broadcom/bcm2835/bcm2835_mbox_prop.h
+++ b/sys/arm/broadcom/bcm2835/bcm2835_mbox_prop.h
@@ -322,6 +322,24 @@ struct bcm2835_mbox_tag_depth {
} body;
};
+#define BCM2835_MBOX_TAG_GET_PIXEL_ORDER 0x00040006
+#define BCM2835_MBOX_TAG_SET_PIXEL_ORDER 0x00048006
+
+#define BCM2835_MBOX_PIXEL_ORDER_BGR 0
+#define BCM2835_MBOX_PIXEL_ORDER_RGB 1
+
+struct bcm2835_mbox_tag_pixel_order {
+ struct bcm2835_mbox_tag_hdr tag_hdr;
+ union {
+ struct {
+ uint32_t order;
+ } req;
+ struct {
+ uint32_t order;
+ } resp;
+ } body;
+};
+
#define BCM2835_MBOX_TAG_GET_ALPHA_MODE 0x00040007
#define BCM2835_MBOX_TAG_SET_ALPHA_MODE 0x00048007
@@ -424,8 +442,12 @@ struct bcm2835_fb_config {
uint32_t pitch;
uint32_t base;
uint32_t size;
+ uint32_t pixel_order; /* BCM2835_MBOX_PIXEL_ORDER_*, or _UNKNOWN */
};
+/* Not a firmware value: the pixel order could not be read. */
+#define BCM2835_MBOX_PIXEL_ORDER_UNKNOWN 0xffffffff
+
struct msg_fb_get_w_h {
struct bcm2835_mbox_hdr hdr;
struct bcm2835_mbox_tag_fb_w_h physical_w_h;
@@ -442,6 +464,14 @@ struct msg_fb_get_bpp {
int bcm2835_mbox_fb_get_bpp(struct bcm2835_fb_config *);
+struct msg_fb_get_pixel_order {
+ struct bcm2835_mbox_hdr hdr;
+ struct bcm2835_mbox_tag_pixel_order pixel_order;
+ uint32_t end_tag;
+};
+
+int bcm2835_mbox_fb_get_pixel_order(struct bcm2835_fb_config *);
+
struct msg_fb_setup {
struct bcm2835_mbox_hdr hdr;
struct bcm2835_mbox_tag_fb_w_h physical_w_h;