<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.freebsd.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.freebsd.org/bugzilla/"
          
          maintainer="bugmeister@FreeBSD.org"
>

    <bug>
          <bug_id>299090</bug_id>
          
          <creation_ts>2026-10-03 11:57:30 +0000</creation_ts>
          <short_desc>loader.efi: hw.uart.console in loader.conf is replaced by the SPCR value</short_desc>
          <delta_ts>2026-10-08 19:46:06 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>Base System</product>
          <component>kern</component>
          <version>15.1-RELEASE</version>
          <rep_platform>Any</rep_platform>
          <op_sys>Any</op_sys>
          <bug_status>New</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=292206</see_also>
    
    <see_also>https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=299089</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>---</priority>
          <bug_severity>Affects Some People</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Rick Richard">rick</reporter>
          <assigned_to name="Warner Losh">imp</assigned_to>
          <cc>imp</cc>
    
    <cc>olivier</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1447688</commentid>
    <comment_count>0</comment_count>
      <attachid>275337</attachid>
    <who name="Rick Richard">rick</who>
    <bug_when>2026-10-03 11:57:30 +0000</bug_when>
    <thetext>Created attachment 275337
[PATCH] loader.efi: Don&apos;t replace a hw.uart.console set by the user

DESCRIPTION

When the firmware provides an ACPI SPCR table, a hw.uart.console line in
loader.conf has no effect.  At the OK prompt, &quot;show hw.uart.console&quot; prints
the value derived from the SPCR, not the one from loader.conf.

check_acpi_spcr() sets hw.uart.console unconditionally.  It is called from
parse_uefi_con_out(), which runs once in main() and again from
efi_console.c whenever the console mode is updated.  loader.lua runs
efi-autoresizecons right after config.load(), so the order is:

  1. main(): hw.uart.console = SPCR value
  2. loader.conf: hw.uart.console = the user&apos;s value (setenv succeeds)
  3. efi-autoresizecons -&gt; parse_uefi_con_out() -&gt; check_acpi_spcr():
     hw.uart.console = SPCR value again

I confirmed step 2 by printing from config.lua&apos;s setEnv(): the user&apos;s value
is set and reads back, and it is gone by the time local.lua runs.  Setting
the variable at the OK prompt works, because nothing runs the SPCR code
after that.

This leaves no persistent way to correct or override what the SPCR says,
for example when the table describes the UART wrongly or the user wants a
different port or speed.

Related: PR 292206, fixed by d82698ac68 (&quot;loader.efi: Only use SPCR if
enabled&quot;), was a case of the SPCR producing a bad hw.uart.console.  Its
commit message notes &quot;While one could unset this value to boot, you
couldn&apos;t do that automatically very easily.&quot;  This is the same problem in
general: with this patch, loader.conf can correct whatever the SPCR says.

The attached patch skips the SPCR translation when hw.uart.console is
already set, as the x86 code in bootinfo.c already does (&quot;if someone
specifically setup hw.uart.console, don&apos;t override that&quot;).  At the first
call nothing has set it yet, so the default behaviour doesn&apos;t change.


AFFECTED VERSIONS

main, stable/15 and releng/15.1.  check_acpi_spcr() came in with
70253b538f68 (&quot;loader.efi: Parse SPCR table entry in ACPI tables&quot;), so 14.x
is not affected.


HOW TO REPEAT

On an EFI system whose firmware provides SPCR, put a hw.uart.console line
in /boot/loader.conf, stop at the OK prompt and run
&quot;show hw.uart.console&quot;.

I used QEMU&apos;s riscv virt machine with its bundled EDK2 firmware, which
provides SPCR, and hw.uart.console=&quot;mm:0x10000000,rs:0,br:115200&quot;.  That
table gives a 32-bit register stride for a byte-spaced UART (being reported
to QEMU), so the SPCR value can&apos;t boot the kernel and the loader.conf value
is needed.


TESTED

riscv64 15.1-RELEASE-p3 world, kernel with the uart_cpu_fdt.c NULL-tag fix
from PR 299089, hw.uart.console in loader.conf:

  loader             result
  15.1-RELEASE-p3    loader.conf value replaced; kernel faults (rs:2)
  with patch         loader.conf value kept; boots to multi-user

Without a loader.conf setting the patched loader passes the SPCR value as
before.  Not tested on arm64 or amd64.


ATTACHMENTS

0001-loader.efi-Don-t-replace-a-hw.uart.console-set-by-th.patch
  against main ff2efe65a89a</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>275337</attachid>
            <date>2026-10-03 11:57:30 +0000</date>
            <delta_ts>2026-10-03 11:57:53 +0000</delta_ts>
            <desc>[PATCH] loader.efi: Don&apos;t replace a hw.uart.console set by the user</desc>
            <filename>0001-loader.efi-Don-t-replace-a-hw.uart.console-set-by-th.patch</filename>
            <type>text/plain</type>
            <size>1516</size>
            <attacher name="Rick Richard">rick</attacher>
            
              <data encoding="base64">RnJvbSA2ZTQxZTUwNGIyYjY2YWIzNDQ2ZjNmZjBjN2ZlMDI5YWExYjBiYzMyIE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiBSaWNrIFJpY2hhcmQgPHJpY2tAc2xvc2VydmVycy5jb20+CkRh
dGU6IFNhdCwgMyBPY3QgMjAyNiAwOTowMDowMCAtMDcwMApTdWJqZWN0OiBbUEFUQ0hdIGxvYWRl
ci5lZmk6IERvbid0IHJlcGxhY2UgYSBody51YXJ0LmNvbnNvbGUgc2V0IGJ5IHRoZSB1c2VyCgpj
aGVja19hY3BpX3NwY3IoKSBzZXRzIGh3LnVhcnQuY29uc29sZSBmcm9tIHRoZSBTUENSIHRhYmxl
IGV2ZXJ5IHRpbWUKaXQgcnVucywgYW5kIHBhcnNlX3VlZmlfY29uX291dCgpIHJ1bnMgYWdhaW4g
d2hlbmV2ZXIgdGhlIGNvbnNvbGUgbW9kZQppcyB1cGRhdGVkLiAgbG9hZGVyLmx1YSBydW5zIGVm
aS1hdXRvcmVzaXplY29ucyByaWdodCBhZnRlciByZWFkaW5nCmxvYWRlci5j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