diff mbox series

[v2] default-distrovars: Have KERNEL_CONSOLE reference SERIAL_CONSOLES

Message ID 20240829214144.2947418-1-jdmason@kudzu.us
State New
Headers show
Series [v2] default-distrovars: Have KERNEL_CONSOLE reference SERIAL_CONSOLES | expand

Commit Message

Jon Mason Aug. 29, 2024, 9:41 p.m. UTC
Currently, KERNEL_CONSOLE has a default value of "ttyS0".  However, Arm
machines and those using virtio serial prefer to use "ttyAMA0" or "hvc0"
(or something else).  These are usually defined by the machine config
file as SERIAL_CONSOLES, which has one or more entries.  Take the first
one of those instead of ttyS0, but default back to ttyS0 if nothing is
set.

Also, use this variable in the efi wic file instead of "ttyS0".

Signed-off-by: Jon Mason <jdmason@kudzu.us>
---
 meta/conf/distro/include/default-distrovars.inc | 3 ++-
 scripts/lib/wic/canned-wks/mkefidisk.wks        | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

Comments

Mikko Rapeli Aug. 30, 2024, 10:24 a.m. UTC | #1
Hi,

On Thu, Aug 29, 2024 at 05:41:44PM -0400, Jon Mason via lists.openembedded.org wrote:
> Currently, KERNEL_CONSOLE has a default value of "ttyS0".  However, Arm
> machines and those using virtio serial prefer to use "ttyAMA0" or "hvc0"
> (or something else).  These are usually defined by the machine config
> file as SERIAL_CONSOLES, which has one or more entries.  Take the first
> one of those instead of ttyS0, but default back to ttyS0 if nothing is
> set.
> 
> Also, use this variable in the efi wic file instead of "ttyS0".

What kind of issues prompted this patch?

I ran into possibly similar issues recently where a machine config
and image is meant for multiple arm64 machines and serial console
login stopped working on some of them. The kernel console messages
were on the correct serial port on all machines but systemd-serialgetty recipe
setup was not. I switched from the yocto specific systemd-serialgetty
to upstream systemd which fixed all issues and serial getty is
now on all needed serial ports (based on our test setup):

systemd_%.bbappend:

PACKAGECONFIG:append = " serial-getty-generator"

In our setup we also can't set the default console via kernel command line
since that changes between machines.

Cheers,

-Mikko

> Signed-off-by: Jon Mason <jdmason@kudzu.us>
> ---
>  meta/conf/distro/include/default-distrovars.inc | 3 ++-
>  scripts/lib/wic/canned-wks/mkefidisk.wks        | 2 +-
>  2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/meta/conf/distro/include/default-distrovars.inc b/meta/conf/distro/include/default-distrovars.inc
> index 7554081e8b1a..976ff4adc526 100644
> --- a/meta/conf/distro/include/default-distrovars.inc
> +++ b/meta/conf/distro/include/default-distrovars.inc
> @@ -1,7 +1,8 @@
>  QA_LOGFILE = "${TMPDIR}/qa.log"
>  
>  OEINCLUDELOGS ?= "yes"
> -KERNEL_CONSOLE ?= "ttyS0"
> +# if SERIAL_CONSOLES is set, take the first device entry.  Otherwise use ttyS0 as the default
> +KERNEL_CONSOLE ?= "${@d.getVar('SERIAL_CONSOLES').split(' ')[0].split(';')[1]},${@d.getVar('SERIAL_CONSOLES').split(' ')[0].split(';')[0] or 'ttyS0'}"
>  KEEPUIMAGE ??= "yes"
>  
>  DEFAULT_IMAGE_LINGUAS = "en-us en-gb"
> diff --git a/scripts/lib/wic/canned-wks/mkefidisk.wks b/scripts/lib/wic/canned-wks/mkefidisk.wks
> index 9f534fe18471..5fa6682a9e10 100644
> --- a/scripts/lib/wic/canned-wks/mkefidisk.wks
> +++ b/scripts/lib/wic/canned-wks/mkefidisk.wks
> @@ -8,4 +8,4 @@ part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024
>  
>  part swap --ondisk sda --size 44 --label swap1 --fstype=swap
>  
> -bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
> +bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=${KERNEL_CONSOLE} console=tty0"
> -- 
> 2.39.2
> 

> 
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#203948): https://lists.openembedded.org/g/openembedded-core/message/203948
> Mute This Topic: https://lists.openembedded.org/mt/108169885/7159507
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [mikko.rapeli@linaro.org]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Jon Mason Aug. 30, 2024, 1:39 p.m. UTC | #2
On Fri, Aug 30, 2024 at 01:24:29PM +0300, Mikko Rapeli wrote:
> Hi,
> 
> On Thu, Aug 29, 2024 at 05:41:44PM -0400, Jon Mason via lists.openembedded.org wrote:
> > Currently, KERNEL_CONSOLE has a default value of "ttyS0".  However, Arm
> > machines and those using virtio serial prefer to use "ttyAMA0" or "hvc0"
> > (or something else).  These are usually defined by the machine config
> > file as SERIAL_CONSOLES, which has one or more entries.  Take the first
> > one of those instead of ttyS0, but default back to ttyS0 if nothing is
> > set.
> > 
> > Also, use this variable in the efi wic file instead of "ttyS0".
> 
> What kind of issues prompted this patch?
> 
> I ran into possibly similar issues recently where a machine config
> and image is meant for multiple arm64 machines and serial console
> login stopped working on some of them. The kernel console messages
> were on the correct serial port on all machines but systemd-serialgetty recipe
> setup was not. I switched from the yocto specific systemd-serialgetty
> to upstream systemd which fixed all issues and serial getty is
> now on all needed serial ports (based on our test setup):
> 
> systemd_%.bbappend:
> 
> PACKAGECONFIG:append = " serial-getty-generator"
> 
> In our setup we also can't set the default console via kernel command line
> since that changes between machines.

The origin of this is getting poky-altcfg working on fvp-base.
systemd wasn't printing to term because console wasn't specified in
the meta-arm efi-disk.wks.in file, which is based on 
scripts/lib/wic/canned-wks/mkefidisk.wks

For portability, this needed to be a variable, and KERNEL_CONSOLE
seems like the right choice.  There are a lot of arm based machines
out there with ttyAMA0 and a few that are ttyS0.  So it cannot be a
arch based choice, and the machine conf file probably already has
SERIAL_CONSOLES set.  So, we can be dynamic here and get the proper
value for most things.

Now, we could be super smart and add all of the consoles in
SERIAL_CONSOLES, but I think that might be a bit too much.

Anyway, probably a few more wks changes coming to allow me to remove
them from meta-arm.

Thanks,
Jon

> 
> Cheers,
> 
> -Mikko
> 
> > Signed-off-by: Jon Mason <jdmason@kudzu.us>
> > ---
> >  meta/conf/distro/include/default-distrovars.inc | 3 ++-
> >  scripts/lib/wic/canned-wks/mkefidisk.wks        | 2 +-
> >  2 files changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/meta/conf/distro/include/default-distrovars.inc b/meta/conf/distro/include/default-distrovars.inc
> > index 7554081e8b1a..976ff4adc526 100644
> > --- a/meta/conf/distro/include/default-distrovars.inc
> > +++ b/meta/conf/distro/include/default-distrovars.inc
> > @@ -1,7 +1,8 @@
> >  QA_LOGFILE = "${TMPDIR}/qa.log"
> >  
> >  OEINCLUDELOGS ?= "yes"
> > -KERNEL_CONSOLE ?= "ttyS0"
> > +# if SERIAL_CONSOLES is set, take the first device entry.  Otherwise use ttyS0 as the default
> > +KERNEL_CONSOLE ?= "${@d.getVar('SERIAL_CONSOLES').split(' ')[0].split(';')[1]},${@d.getVar('SERIAL_CONSOLES').split(' ')[0].split(';')[0] or 'ttyS0'}"
> >  KEEPUIMAGE ??= "yes"
> >  
> >  DEFAULT_IMAGE_LINGUAS = "en-us en-gb"
> > diff --git a/scripts/lib/wic/canned-wks/mkefidisk.wks b/scripts/lib/wic/canned-wks/mkefidisk.wks
> > index 9f534fe18471..5fa6682a9e10 100644
> > --- a/scripts/lib/wic/canned-wks/mkefidisk.wks
> > +++ b/scripts/lib/wic/canned-wks/mkefidisk.wks
> > @@ -8,4 +8,4 @@ part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024
> >  
> >  part swap --ondisk sda --size 44 --label swap1 --fstype=swap
> >  
> > -bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
> > +bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=${KERNEL_CONSOLE} console=tty0"
> > -- 
> > 2.39.2
> > 
> 
> > 
> > -=-=-=-=-=-=-=-=-=-=-=-
> > Links: You receive all messages sent to this group.
> > View/Reply Online (#203948): https://lists.openembedded.org/g/openembedded-core/message/203948
> > Mute This Topic: https://lists.openembedded.org/mt/108169885/7159507
> > Group Owner: openembedded-core+owner@lists.openembedded.org
> > Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [mikko.rapeli@linaro.org]
> > -=-=-=-=-=-=-=-=-=-=-=-
> > 
> 
>
Quentin Schulz Aug. 30, 2024, 2:07 p.m. UTC | #3
Hi Jon,

On 8/29/24 11:41 PM, Jon Mason via lists.openembedded.org wrote:
> Currently, KERNEL_CONSOLE has a default value of "ttyS0".  However, Arm
> machines and those using virtio serial prefer to use "ttyAMA0" or "hvc0"
> (or something else).  These are usually defined by the machine config
> file as SERIAL_CONSOLES, which has one or more entries.  Take the first
> one of those instead of ttyS0, but default back to ttyS0 if nothing is
> set.
> 
> Also, use this variable in the efi wic file instead of "ttyS0".
> 
> Signed-off-by: Jon Mason <jdmason@kudzu.us>
> ---
>   meta/conf/distro/include/default-distrovars.inc | 3 ++-
>   scripts/lib/wic/canned-wks/mkefidisk.wks        | 2 +-
>   2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/meta/conf/distro/include/default-distrovars.inc b/meta/conf/distro/include/default-distrovars.inc
> index 7554081e8b1a..976ff4adc526 100644
> --- a/meta/conf/distro/include/default-distrovars.inc
> +++ b/meta/conf/distro/include/default-distrovars.inc
> @@ -1,7 +1,8 @@
>   QA_LOGFILE = "${TMPDIR}/qa.log"
>   
>   OEINCLUDELOGS ?= "yes"
> -KERNEL_CONSOLE ?= "ttyS0"
> +# if SERIAL_CONSOLES is set, take the first device entry.  Otherwise use ttyS0 as the default
> +KERNEL_CONSOLE ?= "${@d.getVar('SERIAL_CONSOLES').split(' ')[0].split(';')[1]},${@d.getVar('SERIAL_CONSOLES').split(' ')[0].split(';')[0] or 'ttyS0'}"

I believe this won't work if SERIAL_CONSOLES is the empty string (which 
is the default value in bitbake.conf). I believe we need to check if 
SERIAL_CONSOLES is not empty. I assume we don't need to check if a ';' 
character is present and can be assumed present if non-empty?

Also, because I was curious, the following may work too:

",".join(d.getVar('SERIAL_CONSOLES').split(' ')[0].split(';')[::-1])

would construct the same string with only one d.getVar call, and added 
bonus it works if SERIAL_CONSOLES is empty.

>   KEEPUIMAGE ??= "yes"
>   
>   DEFAULT_IMAGE_LINGUAS = "en-us en-gb"
> diff --git a/scripts/lib/wic/canned-wks/mkefidisk.wks b/scripts/lib/wic/canned-wks/mkefidisk.wks
> index 9f534fe18471..5fa6682a9e10 100644
> --- a/scripts/lib/wic/canned-wks/mkefidisk.wks
> +++ b/scripts/lib/wic/canned-wks/mkefidisk.wks
> @@ -8,4 +8,4 @@ part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024
>   
>   part swap --ondisk sda --size 44 --label swap1 --fstype=swap
>   
> -bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
> +bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=${KERNEL_CONSOLE} console=tty0"
> 

I think we need to add this variable to WICVARS?

c.f. 
https://git.openembedded.org/openembedded-core/tree/meta/classes-recipe/image_types_wic.bbclass#n7
https://git.openembedded.org/openembedded-core/tree/meta/classes-recipe/image_types_wic.bbclass#n99
https://git.openembedded.org/openembedded-core/tree/meta/classes-recipe/image_types_wic.bbclass#n207

Cheers,
Quentin
diff mbox series

Patch

diff --git a/meta/conf/distro/include/default-distrovars.inc b/meta/conf/distro/include/default-distrovars.inc
index 7554081e8b1a..976ff4adc526 100644
--- a/meta/conf/distro/include/default-distrovars.inc
+++ b/meta/conf/distro/include/default-distrovars.inc
@@ -1,7 +1,8 @@ 
 QA_LOGFILE = "${TMPDIR}/qa.log"
 
 OEINCLUDELOGS ?= "yes"
-KERNEL_CONSOLE ?= "ttyS0"
+# if SERIAL_CONSOLES is set, take the first device entry.  Otherwise use ttyS0 as the default
+KERNEL_CONSOLE ?= "${@d.getVar('SERIAL_CONSOLES').split(' ')[0].split(';')[1]},${@d.getVar('SERIAL_CONSOLES').split(' ')[0].split(';')[0] or 'ttyS0'}"
 KEEPUIMAGE ??= "yes"
 
 DEFAULT_IMAGE_LINGUAS = "en-us en-gb"
diff --git a/scripts/lib/wic/canned-wks/mkefidisk.wks b/scripts/lib/wic/canned-wks/mkefidisk.wks
index 9f534fe18471..5fa6682a9e10 100644
--- a/scripts/lib/wic/canned-wks/mkefidisk.wks
+++ b/scripts/lib/wic/canned-wks/mkefidisk.wks
@@ -8,4 +8,4 @@  part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024
 
 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
 
-bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
+bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=${KERNEL_CONSOLE} console=tty0"