Bug 253253 - stable/13: efi boot always defaults to cons: serial
Summary: stable/13: efi boot always defaults to cons: serial
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: conf (show other bugs)
Version: 13.0-STABLE
Hardware: amd64 Any
: --- Affects Many People
Assignee: Toomas Soome
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-04 16:35 UTC by Remko Catersels
Modified: 2021-02-04 21:36 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Remko Catersels 2021-02-04 16:35:23 UTC
Recent stable/13:
FreeBSD molly.dicelan.home 13.0-ALPHA3 FreeBSD 13.0-ALPHA3 #14 stable/13-n244437-ca9e7ac2fbb: Thu Feb  4 12:26:03 CET 2021     root@molly.dicelan.home:/usr/obj/usr/src/amd64.amd64/sys/MOLLY  amd64

Custom kernel but the same happens with GENERIC. 

System is set up for CSM and efi boot:
# gpart show
=>       40  312581728  ada0  GPT  (149G)
         40     409600     1  efi  (200M)
     409640       1024     2  freebsd-boot  (512K)
     410664        984        - free -  (492K)
     411648   33554432     3  freebsd-swap  (16G)
   33966080  278614016     4  freebsd-zfs  (133G)
  312580096       1672        - free -  (836K)


If the system CSM boots everything is fine. If I UEFI boot, the loader menu setting Cons is always set to serial. Which then disables the video and refuses to boot, it just hangs (even after waiting 10 minutes I still can't access the machine remotely, no pings, nothing). There's no serial console attached. Even if I disable all serial ports in the BIOS/UEFI it still defaults to Cons: Serial, display shuts off and booting appears to stop. Switching Cons manually to video works, system boots with efifb enabled.

Tried adding various console= settings in loader.conf. console="vidconsole", console="efi", none of it matters, Cons: always defaults to serial and the system doesn't boot. 

This means I can't reboot without being present at console to manually switch Cons to Video.
Comment 1 Toomas Soome freebsd_committer freebsd_triage 2021-02-04 19:56:17 UTC
(In reply to sirdice from comment #0)

vidconsole is not legal value with efi.

what does (from loader OK prompt) efi-show -g global -v ConOut tell? or from running system: efivar -d 8be4df61-93ca-11d2-aa0d-00e098032b8c-ConOut

Same for ConOutDev?
Comment 2 Remko Catersels 2021-02-04 20:19:40 UTC
Yeah, was grasping at straws with vidconsole. IIRC that was valid with the old sc(4) console. 

I don't seem to have ConOut?

root@molly:~ # efivar -d 8be4df61-93ca-11d2-aa0d-00e098032b8c-ConOut
efivar: fetching 8be4df61-93ca-11d2-aa0d-00e098032b8c-ConOut: No such file or directory

root@molly:~ # efivar | grep ConOut
8be4df61-93ca-11d2-aa0d-00e098032b8c-ConOutDev
root@molly:~ # efivar -d 8be4df61-93ca-11d2-aa0d-00e098032b8c-ConOutDev
8be4df61-93ca-11d2-aa0d-00e098032b8c-ConOutDev
: PciRoot(0x0)/Pci(0x2,0x0)/AcpiAdr(0x80010100)

I do have a ConInDev:
root@molly:~ # efivar | grep ConIn
8be4df61-93ca-11d2-aa0d-00e098032b8c-ConInDev
root@molly:~ # efivar -d 8be4df61-93ca-11d2-aa0d-00e098032b8c-ConInDev
8be4df61-93ca-11d2-aa0d-00e098032b8c-ConInDev
: PciRoot(0x0)/Pci(0x1f,0x0)/Acpi(PNP0303,0x0)

Note that this system has now been booted by manually setting Cons: to video. Not sure if that matters for the contents of those variables. I can't get it to boot at all if Cons: is set to serial. 

I've also added a specific FreeBSD boot entry with efibootmgr to see if that made any difference. It didn't. 

root@molly:~ # efibootmgr
BootCurrent: 0000
Timeout    : 1 seconds
BootOrder  : 0000, 0001
+Boot0000* FreeBSD-13
 Boot0001* Hard Drive
Comment 3 Toomas Soome freebsd_committer freebsd_triage 2021-02-04 20:47:12 UTC
(In reply to sirdice from comment #2)

vidvonsole is only valid with bios loade, not with uefi (loader.efi).

There is this block of code:

        rv = efi_global_getenv("ConOut", buf, &sz);
        if (rv != EFI_SUCCESS) {
                /* If we don't have any ConOut default to serial */
                how = RB_SERIAL;
                goto out;
        }

That does explain it... This patch should fix it

tsoome@freebsd-2:/usr/src % git diff
diff --git a/stand/efi/loader/main.c b/stand/efi/loader/main.c
index ca41cd4a2610..a21e8b0d96ba 100644
--- a/stand/efi/loader/main.c
+++ b/stand/efi/loader/main.c
@@ -735,6 +735,8 @@ parse_uefi_con_out(void)
        how = 0;
        sz = sizeof(buf);
        rv = efi_global_getenv("ConOut", buf, &sz);
+       if (rv != EFI_SUCCESS) {
+               rv = efi_global_getenv("ConOutDev", buf, &sz);
        if (rv != EFI_SUCCESS) {
                /* If we don't have any ConOut default to serial */
                how = RB_SERIAL;
tsoome@freebsd-2:/usr/src %
Comment 4 Toomas Soome freebsd_committer freebsd_triage 2021-02-04 20:48:30 UTC
(In reply to Toomas Soome from comment #3)

Oh, please note, there is extra { on that aded if statement.
Comment 5 Remko Catersels 2021-02-04 21:28:00 UTC
Did this:

root@molly:/usr/src/stand/efi/loader # git diff
diff --git a/stand/efi/loader/main.c b/stand/efi/loader/main.c
index ca41cd4a261..9d81003acc4 100644
--- a/stand/efi/loader/main.c
+++ b/stand/efi/loader/main.c
@@ -735,6 +735,9 @@ parse_uefi_con_out(void)
        how = 0;
        sz = sizeof(buf);
        rv = efi_global_getenv("ConOut", buf, &sz);
+       if (rv != EFI_SUCCESS) {
+               rv = efi_global_getenv("ConOutDev", buf, &sz);
+       }
        if (rv != EFI_SUCCESS) {
                /* If we don't have any ConOut default to serial */
                how = RB_SERIAL;


Build is good. 

root@molly:/usr/src/stand/efi/loader # cp /usr/obj/usr/src/amd64.amd64/stand/efi/loader/loader_lua.efi /boot/efi/EFI/BOOT/bootx64.efi

Then rebooted. Yes! That works. Cons: is now video by default. I even got the cool graphics loader :)
Comment 6 commit-hook freebsd_committer freebsd_triage 2021-02-04 21:30:56 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=2bd4ff2d8911009283e4e615ca4aad35a845f48b

commit 2bd4ff2d8911009283e4e615ca4aad35a845f48b
Author:     Toomas Soome <tsoome@FreeBSD.org>
AuthorDate: 2021-02-04 20:49:02 +0000
Commit:     Toomas Soome <tsoome@FreeBSD.org>
CommitDate: 2021-02-04 21:29:38 +0000

    loader.efi: There are systems without ConOut, also use ConOutDev

    Conout does contian the default output device name.
    ConOutDev does contain all possible output device names, so we can
    use it as fallback, when there is no ConOut.

    PR: 253253

 stand/efi/loader/main.c | 2 ++
 1 file changed, 2 insertions(+)
Comment 7 commit-hook freebsd_committer freebsd_triage 2021-02-04 21:34:57 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=0c839497c174e961fc71f7d3329d05b10ec5525b

commit 0c839497c174e961fc71f7d3329d05b10ec5525b
Author:     Toomas Soome <tsoome@FreeBSD.org>
AuthorDate: 2021-02-04 20:49:02 +0000
Commit:     Toomas Soome <tsoome@FreeBSD.org>
CommitDate: 2021-02-04 21:33:15 +0000

    loader.efi: There are systems without ConOut, also use ConOutDev

    Conout does contian the default output device name.
    ConOutDev does contain all possible output device names, so we can
    use it as fallback, when there is no ConOut.

    PR: 253253

    (cherry picked from commit 2bd4ff2d8911009283e4e615ca4aad35a845f48b)

 stand/efi/loader/main.c | 2 ++
 1 file changed, 2 insertions(+)