U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: George Chan via B4 Relay <devnull+gchan9527.gmail.com@kernel.org>
To: Tom Rini <trini@konsulko.com>,
	 Mattijs Korpershoek <mkorpershoek@kernel.org>,
	 Simon Glass <sjg@chromium.org>,
	Casey Connolly <casey.connolly@linaro.org>,
	 Neil Armstrong <neil.armstrong@linaro.org>,
	 Sumit Garg <sumit.garg@kernel.org>
Cc: u-boot@lists.denx.de, u-boot-qcom@groups.io,
	 George Chan <gchan9527@gmail.com>
Subject: [PATCH 3/3] mach-snapdragon: Add support to append string to kernel cmdline
Date: Sun, 27 Apr 2025 19:25:22 +0800	[thread overview]
Message-ID: <20250427-android-boot-v1-3-bb6b37c9c9f1@gmail.com> (raw)
In-Reply-To: <20250427-android-boot-v1-0-bb6b37c9c9f1@gmail.com>

From: George Chan <gchan9527@gmail.com>

Add support for blindly appending string to bootargs env_param and let
boot process take care of it.

Signed-off-by: George Chan <gchan9527@gmail.com>
---
 arch/arm/mach-snapdragon/Kconfig | 11 +++++
 arch/arm/mach-snapdragon/board.c | 97 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 108 insertions(+)

diff --git a/arch/arm/mach-snapdragon/Kconfig b/arch/arm/mach-snapdragon/Kconfig
index 976c0e35fce..ee65bbd1313 100644
--- a/arch/arm/mach-snapdragon/Kconfig
+++ b/arch/arm/mach-snapdragon/Kconfig
@@ -45,4 +45,15 @@ config SYS_CONFIG_NAME
 	  Based on this option include/configs/<CONFIG_SYS_CONFIG_NAME>.h header
 	  will be used for board configuration.
 
+config SYS_BOARD_CMDLINE_APPEND
+        bool "Snapdragon SoCs based board cmdline append string"
+        help
+          Allows to specify the Snapdragon SoCs based board kernel cmdline override.
+          will be used as the custom board bootloader cmdline booting OS like Android.
+
+config SYS_BOARD_CMDLINE_APPEND_STRING
+	string "String to append"
+	default ""
+	depends on SYS_BOARD_CMDLINE_APPEND
+
 endif
diff --git a/arch/arm/mach-snapdragon/board.c b/arch/arm/mach-snapdragon/board.c
index deae4d32378..9b1dad8752d 100644
--- a/arch/arm/mach-snapdragon/board.c
+++ b/arch/arm/mach-snapdragon/board.c
@@ -46,6 +46,103 @@ static struct {
 	phys_size_t size;
 } prevbl_ddr_banks[CONFIG_NR_DRAM_BANKS] __section(".data") = { 0 };
 
+#ifdef CONFIG_SYS_BOARD_CMDLINE_APPEND
+/* (1) kernel cmdline support length is limited, which is (256..4096)
+ * (2) detain ref to COMMAND_LINE_SIZE of kernel header.
+ * (3) assumed null terminated.
+ * (4) Test shows that 1024 is working...
+ */
+#define COMMAND_LINE_SIZE_4_14		1024 /* ok make it default */
+static char bootargs[COMMAND_LINE_SIZE_4_14] = { 0 };
+const static char *soc_bootargs = CONFIG_SYS_BOARD_CMDLINE_APPEND_STRING;
+
+/* sort by importance to avoid some important value got wiped out */
+const static char *soc_bootargs_default = \
+" msm_drm.dsi_display0=dsi_nt36675_tianma_vid_display:" \
+" androidboot.lcmtype=dsi_nt36672c_tianma_fhd_video_display" \
+" androidboot.hwname=joyeuse" \
+" androidboot.secureboot=1" \
+" androidboot.keymaster=1"  \
+" androidboot.bootdevice=1d84000.ufshc" \
+" androidboot.boot_devices=soc/1d84000.ufshc" \
+" androidboot.verifiedbootstate=orange" \
+" androidboot.multisim_config=dsds" \
+" androidboot.cpuid=0xdc1467b8 " \
+" androidboot.dp=0x0 androidboot.baseband=msm" \
+" androidboot.fpsensor=fpc" \
+" androidboot.hwc=VDF_TWO" \
+" androidboot.hwlevel=MP" \
+" androidboot.AdcVol1=463 androidboot.AdcVol2=1306" \
+" androidboot.hwversion=4.90.0";
+
+/* fixups are put here:
+ * (1) androidboot.android_dt_dir this is to abuse the param to get rid of
+ * old fstab in device tree, and let search fail.
+ * (2) in case of fstab.qcom is in use but default boot.img have cmdline but
+ * do not specify the value, it will result expecting "fstab" instead of
+ * "fstab.qcom" and boot fail. so add a default value at last of cmd here.
+ */
+const static char *fix_bootargs = \
+" androidboot.android_dt_dir=/tmp/" \
+" androidboot.fstab_suffix=default" \
+" console=ramoops ";
+
+const char *get_board_support_bootargs(void)
+{
+        return soc_bootargs;
+}
+
+const char *get_board_support_bootargs_fixup(void)
+{
+        return fix_bootargs;
+}
+
+const char *board_fdt_chosen_bootargs(const struct fdt_property *fdt)
+{
+	int j;
+	char *env_prop = env_get("bootargs");
+	const char *soc_prop;
+	const char *fix_prop = fix_bootargs;
+	const char *fdt_prop;
+
+	soc_prop = (strlen(soc_bootargs) == 0) ? soc_bootargs_default : soc_bootargs;
+
+	fdt_prop = (fdt == NULL) ? "" : fdt->data;
+
+	if (env_prop == NULL)
+		env_prop = "";
+
+	debug("\n");
+	debug("fdt bootargs: %s\n", fdt_prop);
+	debug("env bootargs: %s\n", env_prop);
+	debug("soc bootargs: %s\n", soc_prop);
+	debug("fix bootargs: %s\n", fix_prop);
+
+	/* since android init parse androidboot property on a
+	 * first-come-first-serve manner so dtb valus come first and
+	 * then u-boot defaults and board specific fixups
+	 */
+	snprintf(bootargs, COMMAND_LINE_SIZE_4_14 - 2, "%s %s %s %s",
+		env_prop , fdt_prop, fix_prop, soc_prop);
+
+	/* remove all carriage return */
+	for (j = 0; j < COMMAND_LINE_SIZE_4_14; j++) {
+		if (bootargs[j] == '\0')
+			break;
+
+		if ((bootargs[j] == '\n') || (bootargs[j] == '\r'))
+			bootargs[j] = ' ';
+	}
+
+	/* trim to max length */
+	bootargs[COMMAND_LINE_SIZE_4_14 - 1] = '\0';
+
+	debug("out bootargs: %s\n", bootargs);
+	debug("total length: %d\n", j);
+	return bootargs;
+}
+#endif
+
 int dram_init(void)
 {
 	/*

-- 
2.43.0



  parent reply	other threads:[~2025-04-27 12:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-27 11:25 [PATCH 0/3] u-boot chain-loading LineageOS bootimg George Chan via B4 Relay
2025-04-27 11:25 ` [PATCH 1/3] boot/image-android.c: Workaround androidboot kernel/ramdisk addr George Chan via B4 Relay
2025-04-27 11:25 ` [PATCH 2/3] boot/bootmeth-android.c: Reuse fastboot memory block for unzip kernel George Chan via B4 Relay
2025-04-27 11:25 ` George Chan via B4 Relay [this message]
2025-04-28 13:53 ` [PATCH 0/3] u-boot chain-loading LineageOS bootimg Casey Connolly
2025-04-29  4:04   ` george chan
2025-04-29  8:30   ` Mattijs Korpershoek
2025-04-30  3:58     ` george chan
2025-04-30 12:03       ` Mattijs Korpershoek
2025-04-30 15:13         ` george chan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250427-android-boot-v1-3-bb6b37c9c9f1@gmail.com \
    --to=devnull+gchan9527.gmail.com@kernel.org \
    --cc=casey.connolly@linaro.org \
    --cc=gchan9527@gmail.com \
    --cc=mkorpershoek@kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=sjg@chromium.org \
    --cc=sumit.garg@kernel.org \
    --cc=trini@konsulko.com \
    --cc=u-boot-qcom@groups.io \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox