arm64 glass console

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

arm64 glass console

Mark Kettenis
The diff below makes it possible to switch over to the framebuffer
console in the bootloader.  Currently, we'll use whatever device is
designated in the device tree (or the ACPI SPCR table) as the console.
With this diff you can use:

  boot> set tty fb0

to override that default.

ok?


Index: arch/arm64/stand/efiboot/Makefile
===================================================================
RCS file: /cvs/src/sys/arch/arm64/stand/efiboot/Makefile,v
retrieving revision 1.8
diff -u -p -r1.8 Makefile
--- arch/arm64/stand/efiboot/Makefile 3 Aug 2019 15:22:20 -0000 1.8
+++ arch/arm64/stand/efiboot/Makefile 9 Aug 2019 22:04:51 -0000
@@ -36,7 +36,7 @@ SRCS+= aes_xts.c bcrypt_pbkdf.c blowfish
  pkcs5_pbkdf2.c rijndael.c sha1.c sha2.c softraid.c
 
 .PATH: ${S}/lib/libkern/arch/arm64 ${S}/lib/libkern
-SRCS+= divdi3.c moddi3.c qdivrem.c strlcpy.c strlen.c
+SRCS+= divdi3.c moddi3.c qdivrem.c strlcat.c strlcpy.c strlen.c
 
 .PATH: ${S}/lib/libz
 SRCS+= adler32.c crc32.c inflate.c inftrees.c
Index: arch/arm64/stand/efiboot/conf.c
===================================================================
RCS file: /cvs/src/sys/arch/arm64/stand/efiboot/conf.c,v
retrieving revision 1.21
diff -u -p -r1.21 conf.c
--- arch/arm64/stand/efiboot/conf.c 4 Aug 2019 13:45:14 -0000 1.21
+++ arch/arm64/stand/efiboot/conf.c 9 Aug 2019 22:04:51 -0000
@@ -45,7 +45,7 @@
 #include "efipxe.h"
 #include "softraid_arm64.h"
 
-const char version[] = "0.17";
+const char version[] = "0.18";
 int debug = 0;
 
 struct fs_ops file_system[] = {
@@ -67,6 +67,7 @@ int ndevs = nitems(devsw);
 
 struct consdev constab[] = {
  { efi_cons_probe, efi_cons_init, efi_cons_getc, efi_cons_putc },
+ { efi_fb_probe, efi_fb_init, efi_cons_getc, efi_cons_putc },
  { NULL }
 };
 struct consdev *cn_tab;
Index: arch/arm64/stand/efiboot/efiboot.c
===================================================================
RCS file: /cvs/src/sys/arch/arm64/stand/efiboot/efiboot.c,v
retrieving revision 1.23
diff -u -p -r1.23 efiboot.c
--- arch/arm64/stand/efiboot/efiboot.c 25 Apr 2019 20:19:30 -0000 1.23
+++ arch/arm64/stand/efiboot/efiboot.c 9 Aug 2019 22:04:51 -0000
@@ -103,12 +103,14 @@ efi_main(EFI_HANDLE image, EFI_SYSTEM_TA
 
 static SIMPLE_TEXT_OUTPUT_INTERFACE *conout;
 static SIMPLE_INPUT_INTERFACE *conin;
+static dev_t serial = makedev(0, 0);
+static dev_t framebuffer = makedev(1, 0);
 
 void
 efi_cons_probe(struct consdev *cn)
 {
  cn->cn_pri = CN_MIDPRI;
- cn->cn_dev = makedev(12, 0);
+ cn->cn_dev = serial;
 }
 
 void
@@ -169,6 +171,32 @@ efi_cons_putc(dev_t dev, int c)
  conout->OutputString(conout, buf);
 }
 
+void
+efi_fb_probe(struct consdev *cn)
+{
+ cn->cn_pri = CN_LOWPRI;
+ cn->cn_dev = framebuffer;
+}
+
+void
+efi_fb_init(struct consdev *cn)
+{
+ conin = ST->ConIn;
+ conout = ST->ConOut;
+}
+
+int
+efi_fb_getc(dev_t dev)
+{
+ return efi_cons_getc(dev);
+}
+
+void
+efi_fb_putc(dev_t dev, int c)
+{
+ efi_cons_putc(dev, c);
+}
+
 static void
 efi_heap_init(void)
 {
@@ -310,6 +338,7 @@ efi_framebuffer(void)
  uint32_t reg[4];
  uint32_t width, height, stride;
  char *format;
+ char *prop;
 
  /*
  * Don't create a "simple-framebuffer" node if we already have
@@ -319,13 +348,19 @@ efi_framebuffer(void)
  node = fdt_find_node("/chosen");
  for (child = fdt_child_node(node); child;
      child = fdt_next_node(child)) {
- if (fdt_node_is_compatible(child, "simple-framebuffer"))
+ if (!fdt_node_is_compatible(child, "simple-framebuffer"))
+ continue;
+ if (fdt_node_property(child, "status", &prop) &&
+    strcmp(prop, "okay") == 0)
  return;
  }
  node = fdt_find_node("/");
  for (child = fdt_child_node(node); child;
      child = fdt_next_node(child)) {
- if (fdt_node_is_compatible(child, "simple-framebuffer"))
+ if (!fdt_node_is_compatible(child, "simple-framebuffer"))
+ continue;
+ if (fdt_node_property(child, "status", &prop) &&
+    strcmp(prop, "okay") == 0)
  return;
  }
 
@@ -387,6 +422,36 @@ efi_framebuffer(void)
     "simple-framebuffer", strlen("simple-framebuffer") + 1);
 }
 
+
+void
+efi_console(void)
+{
+ char path[128];
+ void *node, *child;
+ char *prop;
+
+ if (cn_tab->cn_dev != framebuffer)
+ return;
+
+ /* Find the desired framebuffer node. */
+ node = fdt_find_node("/chosen");
+ for (child = fdt_child_node(node); child;
+     child = fdt_next_node(child)) {
+ if (!fdt_node_is_compatible(child, "simple-framebuffer"))
+ continue;
+ if (fdt_node_property(child, "status", &prop) &&
+    strcmp(prop, "okay") == 0)
+ break;
+ }
+ if (child == NULL)
+ return;
+
+ /* Point stdout-path at the framebuffer node. */
+ strlcpy(path, "/chosen/", sizeof(path));
+ strlcat(path, fdt_node_name(child), sizeof(path));
+ fdt_node_add_property(node, "stdout-path", path, strlen(path) + 1);
+}
+
 int acpi = 0;
 void *fdt = NULL;
 char *bootmac = NULL;
@@ -463,6 +528,7 @@ efi_makebootargs(char *bootargs)
  fdt_node_add_property(node, "openbsd,uefi-mmap-desc-ver", zero, 4);
 
  efi_framebuffer();
+ efi_console();
 
  fdt_finalize();
 
@@ -648,21 +714,39 @@ devboot(dev_t dev, char *p)
  p[2] = '0' + sd_boot_vol;
 }
 
+const char cdevs[][4] = { "com", "fb" };
+const int ncdevs = nitems(cdevs);
+
 int
 cnspeed(dev_t dev, int sp)
 {
  return 115200;
 }
 
+char ttyname_buf[8];
+
 char *
 ttyname(int fd)
 {
- return "com0";
+ snprintf(ttyname_buf, sizeof ttyname_buf, "%s%d",
+    cdevs[major(cn_tab->cn_dev)], minor(cn_tab->cn_dev));
+
+ return ttyname_buf;
 }
 
 dev_t
 ttydev(char *name)
 {
+ int i, unit = -1;
+ char *no = name + strlen(name) - 1;
+
+ while (no >= name && *no >= '0' && *no <= '9')
+ unit = (unit < 0 ? 0 : (unit * 10)) + *no-- - '0';
+ if (no < name || unit < 0)
+ return NODEV;
+ for (i = 0; i < ncdevs; i++)
+ if (strncmp(name, cdevs[i], no - name + 1) == 0)
+ return makedev(i, unit);
  return NODEV;
 }
 
Index: arch/arm64/stand/efiboot/efiboot.h
===================================================================
RCS file: /cvs/src/sys/arch/arm64/stand/efiboot/efiboot.h,v
retrieving revision 1.3
diff -u -p -r1.3 efiboot.h
--- arch/arm64/stand/efiboot/efiboot.h 25 Jun 2018 22:39:14 -0000 1.3
+++ arch/arm64/stand/efiboot/efiboot.h 9 Aug 2019 22:04:51 -0000
@@ -25,3 +25,7 @@ void efi_cons_probe(struct consdev *);
 void efi_cons_init(struct consdev *);
 int efi_cons_getc(dev_t);
 void efi_cons_putc(dev_t, int);
+void efi_fb_probe(struct consdev *);
+void efi_fb_init(struct consdev *);
+int efi_fb_getc(dev_t);
+void efi_fb_putc(dev_t, int);

Reply | Threaded
Open this post in threaded view
|

Re: arm64 glass console

Matthieu Herrb-3
On Sat, Aug 10, 2019 at 12:16:14AM +0200, Mark Kettenis wrote:

> The diff below makes it possible to switch over to the framebuffer
> console in the bootloader.  Currently, we'll use whatever device is
> designated in the device tree (or the ACPI SPCR table) as the console.
> With this diff you can use:
>
>   boot> set tty fb0
>
> to override that default.
>
> ok?

Hi,

This works great on my PineBook 11" HD
--
Matthieu Herrb

Reply | Threaded
Open this post in threaded view
|

Re: arm64 glass console

Krystian Lewandowski-2
Hi,
had a chance to build efiboot with the patch eventually.

Works fine on:
- Pinebook 11" (1080p)
- A64+ with 1080p display via HDMI

--
Krystian

Reply | Threaded
Open this post in threaded view
|

Re: arm64 glass console

Mark Kettenis
> Date: Mon, 12 Aug 2019 14:17:55 +0200
> From: Krystian Lewandowski <[hidden email]>
>
> Hi,
> had a chance to build efiboot with the patch eventually.
>
> Works fine on:
> - Pinebook 11" (1080p)
> - A64+ with 1080p display via HDMI

Thanks!

I have committed a axppmic(4) diff based on your code for the battery
sensors.  However, it will only enable the additional sensors if you
have a very recent Linux device tree (not packaged yet).  If you know
how to build device trees from the Linux source tree, you could try
that out.  But please be aware that you need the kernel changes I made
over the weekend for that to work.

If you want to test my changes (I might have broken something) it is
probably easier quickly add the driver and add something like:

         sc->sc_sensdata = axp803_battery_sensdata;

in axppmic_attach_common().

Cheers,

Mark