From 8834db0ffb6d4e14e7995d277af4e7aafb499d4e Mon Sep 17 00:00:00 2001
From: Richard Acayan <mailingradian@gmail.com>
Date: Tue, 26 Nov 2024 21:38:47 -0500
Subject: [PATCH] linux-postmarketos-qcom-sdm670: enable null tty (MR 5856)

The Google Pixel 3a automatically appends console=null to the command
line. In the kernel, the preferred console is set to ttynull. Since
ttynull is not automatically enabled, a warning is currently emitted:

	[    0.909853] Warning: unable to open an initial console.

This also causes stdin, stdout, and stderr to be missing from the init
process.

In the busybox implementation, syslogd creates the /dev/log socket and
opens /dev/kmsg. This happens just before daemonizing, which opens
/dev/null and aliases stdin, stdout, and stderr to it. After daemonizing
and potentially closing the socket, stdin is aliased to the socket to
save stack memory. If the program starts without stdin under Linux, the
socket gains the constant STDIN_FILENO file descriptor, which is cleared
when daemonizing.

Syscalls when the 0, 1, 2 file descriptors aren't open:

	socket(AF_UNIX, SOCK_DGRAM, 0)    = 0
	openat(AT_FDCWD, "/dev/kmsg", O_WRONLY|O_LARGEFILE) = 1
	openat(AT_FDCWD, "/dev/null", O_RDWR|O_LARGEFILE) = 2

Enable the CONFIG_NULL_TTY option and update the configuration to allow
the kernel to open stdin, stdout, and stderr for the init and (by
inheritance) syslogd processes. It's technically an expert option but
isn't enabled by default (and can be enabled in config fragments).

Closes #3269
[ci:skip-build]: already built successfully in CI
---
 .../linux-postmarketos-qcom-sdm670/APKBUILD          |  4 ++--
 .../config-postmarketos-qcom-sdm670.aarch64          | 12 +++++++-----
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/device/community/linux-postmarketos-qcom-sdm670/APKBUILD b/device/community/linux-postmarketos-qcom-sdm670/APKBUILD
index c1bf1d54195..040bd5d4db2 100644
--- a/device/community/linux-postmarketos-qcom-sdm670/APKBUILD
+++ b/device/community/linux-postmarketos-qcom-sdm670/APKBUILD
@@ -5,7 +5,7 @@
 _flavor="postmarketos-qcom-sdm670"
 pkgname=linux-$_flavor
 pkgver=6.11.3
-pkgrel=0
+pkgrel=1
 pkgdesc="Mainline Kernel fork for SDM670 devices"
 arch="aarch64"
 _carch="arm64"
@@ -67,5 +67,5 @@ package() {
 
 sha512sums="
 c0503c5de978df3925143d2d27f973c9ce41612020fc5d7d21bf8137c9b6c7f8f0fab6dff7fd8f59606d0b80d51ccc8cb41f8617a4a39befc7cfd4aec5d2fa97  linux-sdm670-v6.11.3.tar.gz
-7f7885a8e5360d451fb2efb934034bbec4c79a12fac62c75d02a7cbb3e24aa22b829e94eb3827dd64e48535c4f38c160ff7c31171a92045232c7c21efe9e1f46  config-postmarketos-qcom-sdm670.aarch64
+0aa0a1daa7a898dd6bc5bbdd79599ca6385c13424e0b5fc38f68b4b2d9ee05fcda27337704a21f0af2eba4469eea6381e2c2aad5fbc424d943838093c3181a4e  config-postmarketos-qcom-sdm670.aarch64
 "
diff --git a/device/community/linux-postmarketos-qcom-sdm670/config-postmarketos-qcom-sdm670.aarch64 b/device/community/linux-postmarketos-qcom-sdm670/config-postmarketos-qcom-sdm670.aarch64
index 7d0b1467fc9..ebb44e95796 100644
--- a/device/community/linux-postmarketos-qcom-sdm670/config-postmarketos-qcom-sdm670.aarch64
+++ b/device/community/linux-postmarketos-qcom-sdm670/config-postmarketos-qcom-sdm670.aarch64
@@ -2,19 +2,20 @@
 # Automatically generated file; DO NOT EDIT.
 # Linux/arm64 6.11.3 Kernel Configuration
 #
-CONFIG_CC_VERSION_TEXT="aarch64-linux-gnu-gcc (GCC) 14.1.0"
+CONFIG_CC_VERSION_TEXT="aarch64-linux-gnu-gcc (GCC) 14.2.0"
 CONFIG_CC_IS_GCC=y
-CONFIG_GCC_VERSION=140100
+CONFIG_GCC_VERSION=140200
 CONFIG_CLANG_VERSION=0
 CONFIG_AS_IS_GNU=y
-CONFIG_AS_VERSION=24200
+CONFIG_AS_VERSION=24300
 CONFIG_LD_IS_BFD=y
-CONFIG_LD_VERSION=24200
+CONFIG_LD_VERSION=24300
 CONFIG_LLD_VERSION=0
 CONFIG_CC_CAN_LINK=y
 CONFIG_CC_CAN_LINK_STATIC=y
 CONFIG_CC_HAS_ASM_GOTO_OUTPUT=y
 CONFIG_CC_HAS_ASM_GOTO_TIED_OUTPUT=y
+CONFIG_TOOLS_SUPPORT_RELR=y
 CONFIG_CC_HAS_ASM_INLINE=y
 CONFIG_CC_HAS_NO_PROFILE_FN_ATTR=y
 CONFIG_PAHOLE_VERSION=127
@@ -750,6 +751,7 @@ CONFIG_HAVE_ARCH_COMPILER_H=y
 CONFIG_HAVE_ARCH_PREL32_RELOCATIONS=y
 # CONFIG_LOCK_EVENT_COUNTS is not set
 CONFIG_ARCH_HAS_RELR=y
+CONFIG_RELR=y
 CONFIG_HAVE_PREEMPT_DYNAMIC=y
 CONFIG_HAVE_PREEMPT_DYNAMIC_KEY=y
 CONFIG_ARCH_WANT_LD_ORPHAN_WARN=y
@@ -2623,7 +2625,7 @@ CONFIG_SERIAL_QCOM_GENI_CONSOLE=y
 CONFIG_SERIAL_MCTRL_GPIO=y
 # CONFIG_SERIAL_NONSTANDARD is not set
 # CONFIG_N_GSM is not set
-# CONFIG_NULL_TTY is not set
+CONFIG_NULL_TTY=y
 CONFIG_HVC_DRIVER=y
 CONFIG_HVC_IRQ=y
 CONFIG_HVC_XEN=y
-- 
GitLab