Subject: [PATCH V1] scsi: ufs: Get boot device storage type from command line

Get the boot device storage type by reading it from
kernel command line arguments and export the same
information to ufs modules.

Signed-off-by: Chetan C R <[email protected]>
---
drivers/ufs/Kconfig | 1 +
drivers/ufs/host/Kconfig | 9 +++++++
drivers/ufs/host/Makefile | 1 +
drivers/ufs/host/ufs-cmdline.c | 54 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 65 insertions(+)
create mode 100644 drivers/ufs/host/ufs-cmdline.c

diff --git a/drivers/ufs/Kconfig b/drivers/ufs/Kconfig
index 90226f7..9d2f84e 100644
--- a/drivers/ufs/Kconfig
+++ b/drivers/ufs/Kconfig
@@ -9,6 +9,7 @@ menuconfig SCSI_UFSHCD
select PM_DEVFREQ
select DEVFREQ_GOV_SIMPLE_ONDEMAND
select NLS
+ select UFS_QCOM_CMDLINE if ARCH_QCOM
help
Enables support for UFS (Universal Flash Storage) host controllers.
A UFS host controller is an electronic component that is able to
diff --git a/drivers/ufs/host/Kconfig b/drivers/ufs/host/Kconfig
index 8259022..6197070 100644
--- a/drivers/ufs/host/Kconfig
+++ b/drivers/ufs/host/Kconfig
@@ -68,6 +68,15 @@ config SCSI_UFS_QCOM
Select this if you have UFS controller on QCOM chipset.
If unsure, say N.

+config UFS_QCOM_CMDLINE
+ bool "Get the boot device type from kernel command line for Qcom devices"
+ help
+ This selects the support of getting the boot device storage type
+ from kernel command line arguments and export this information
+ to the Qcom UFS controller platform driver.
+
+ If unsure, say N.
+
config SCSI_UFS_MEDIATEK
tristate "Mediatek specific hooks to UFS controller platform driver"
depends on SCSI_UFSHCD_PLATFORM && ARCH_MEDIATEK
diff --git a/drivers/ufs/host/Makefile b/drivers/ufs/host/Makefile
index e4be542..a9463f1 100644
--- a/drivers/ufs/host/Makefile
+++ b/drivers/ufs/host/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_SCSI_UFS_CDNS_PLATFORM) += cdns-pltfrm.o
obj-$(CONFIG_SCSI_UFS_QCOM) += ufs_qcom.o
ufs_qcom-y += ufs-qcom.o
ufs_qcom-$(CONFIG_SCSI_UFS_CRYPTO) += ufs-qcom-ice.o
+obj-$(CONFIG_UFS_QCOM_CMDLINE) += ufs-cmdline.o
obj-$(CONFIG_SCSI_UFS_EXYNOS) += ufs-exynos.o
obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o
obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o
diff --git a/drivers/ufs/host/ufs-cmdline.c b/drivers/ufs/host/ufs-cmdline.c
new file mode 100644
index 0000000..408755c
--- /dev/null
+++ b/drivers/ufs/host/ufs-cmdline.c
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2022, The Linux Foundation. All rights reserved.
+ */
+
+#include <linux/init.h>
+#include <linux/printk.h>
+#include <linux/string.h>
+
+#ifdef CONFIG_BOOT_CONFIG
+#include <linux/bootconfig.h>
+#endif
+
+#define ANDROID_BOOT_DEV_MAX_V3 30
+
+static char android_boot_dev_v3[ANDROID_BOOT_DEV_MAX_V3];
+static const char *android_boot_dev_v4;
+
+const char *get_storage_boot_device(void)
+{
+ if (android_boot_dev_v4 && strlen(android_boot_dev_v4))
+ return android_boot_dev_v4;
+
+ else if (strlen(android_boot_dev_v3))
+ return android_boot_dev_v3;
+
+ pr_err("Not able to get Bootconfig or Kernel command line param\n");
+ return NULL;
+};
+EXPORT_SYMBOL_GPL(get_storage_boot_device);
+
+/* boot image header version 3 android boot device type */
+static int __init get_android_boot_dev_v3(char *str)
+{
+ strscpy(android_boot_dev_v3, str, ANDROID_BOOT_DEV_MAX_V3);
+ return 1;
+}
+__setup("androidboot.bootdevice=", get_android_boot_dev_v3);
+
+#ifdef CONFIG_BOOT_CONFIG
+/* boot image header version 4 android boot device type */
+static int __init get_android_boot_dev_v4(void)
+{
+ struct xbc_node *vnode = NULL;
+
+ android_boot_dev_v4 = xbc_find_value("androidboot.bootdevice", &vnode);
+
+ if (vnode && xbc_node_is_array(vnode))
+ xbc_array_for_each_value(vnode, android_boot_dev_v4);
+
+ return 0;
+}
+fs_initcall(get_android_boot_dev_v4);
+#endif
--
2.7.4


2022-07-27 13:17:27

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH V1] scsi: ufs: Get boot device storage type from command line

Hi Chetan,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on jejb-scsi/for-next]
[also build test WARNING on mkp-scsi/for-next linus/master v5.19-rc8 next-20220726]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Chetan-C-R/scsi-ufs-Get-boot-device-storage-type-from-command-line/20220727-163016
base: https://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi.git for-next
config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20220727/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-3) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/42a08523b91855ba31b0974a32f02c43b163c571
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Chetan-C-R/scsi-ufs-Get-boot-device-storage-type-from-command-line/20220727-163016
git checkout 42a08523b91855ba31b0974a32f02c43b163c571
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/ufs/host/

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

>> drivers/ufs/host/ufs-cmdline.c:19:13: warning: no previous prototype for 'get_storage_boot_device' [-Wmissing-prototypes]
19 | const char *get_storage_boot_device(void)
| ^~~~~~~~~~~~~~~~~~~~~~~


vim +/get_storage_boot_device +19 drivers/ufs/host/ufs-cmdline.c

18
> 19 const char *get_storage_boot_device(void)
20 {
21 if (android_boot_dev_v4 && strlen(android_boot_dev_v4))
22 return android_boot_dev_v4;
23
24 else if (strlen(android_boot_dev_v3))
25 return android_boot_dev_v3;
26
27 pr_err("Not able to get Bootconfig or Kernel command line param\n");
28 return NULL;
29 };
30 EXPORT_SYMBOL_GPL(get_storage_boot_device);
31

--
0-DAY CI Kernel Test Service
https://01.org/lkp

2022-07-27 19:04:37

by Bart Van Assche

[permalink] [raw]
Subject: Re: [PATCH V1] scsi: ufs: Get boot device storage type from command line

On 7/27/22 01:28, Chetan C R wrote:
> diff --git a/drivers/ufs/Kconfig b/drivers/ufs/Kconfig
> index 90226f7..9d2f84e 100644
> --- a/drivers/ufs/Kconfig
> +++ b/drivers/ufs/Kconfig
> @@ -9,6 +9,7 @@ menuconfig SCSI_UFSHCD
> select PM_DEVFREQ
> select DEVFREQ_GOV_SIMPLE_ONDEMAND
> select NLS
> + select UFS_QCOM_CMDLINE if ARCH_QCOM
> help
> Enables support for UFS (Universal Flash Storage) host controllers.
> A UFS host controller is an electronic component that is able to

[ ... ]

> +__setup("androidboot.bootdevice=", get_android_boot_dev_v3);

How can this work since __setup() declarations should occur in the core
kernel and since the ufshcd driver can be built as a kernel module?

Thanks,

Bart.

Subject: Re: [PATCH V1] scsi: ufs: Get boot device storage type from command line

Hi Brat,

Thanks for you response!

Yes, since SCSI_UFSHCD=y am selecting UFS_QCOM_CMDLINE=y so that it gets
__setup() declarations. I am able to read the command line arguments and
get this "androidboot.bootdevice=" info. I had cross checked again.

Thanks,
Chetan C R

On 7/27/2022 11:16 PM, Bart Van Assche wrote:
> On 7/27/22 01:28, Chetan C R wrote:
>> diff --git a/drivers/ufs/Kconfig b/drivers/ufs/Kconfig
>> index 90226f7..9d2f84e 100644
>> --- a/drivers/ufs/Kconfig
>> +++ b/drivers/ufs/Kconfig
>> @@ -9,6 +9,7 @@ menuconfig SCSI_UFSHCD
>>       select PM_DEVFREQ
>>       select DEVFREQ_GOV_SIMPLE_ONDEMAND
>>       select NLS
>> +    select UFS_QCOM_CMDLINE if ARCH_QCOM
>>       help
>>         Enables support for UFS (Universal Flash Storage) host
>> controllers.
>>         A UFS host controller is an electronic component that is able to
>
> [ ... ]
>
>> +__setup("androidboot.bootdevice=", get_android_boot_dev_v3);
>
> How can this work since __setup() declarations should occur in the
> core kernel and since the ufshcd driver can be built as a kernel module?
>
> Thanks,
>
> Bart.

2022-07-28 14:23:51

by Bart Van Assche

[permalink] [raw]
Subject: Re: [PATCH V1] scsi: ufs: Get boot device storage type from command line

On 7/28/22 01:35, Chetan Chinnadagudihundi Ravindranath (Consultant)
(QUIC) wrote:
> Hi Brat,

Please spell my name correctly.

> Yes, since SCSI_UFSHCD=y am selecting UFS_QCOM_CMDLINE=y so that it gets
> __setup() declarations. I am able to read the command line arguments and
> get this "androidboot.bootdevice=" info. I had cross checked again.

I was asking about SCSI_UFSHCD=m instead of SCSI_UFSHCD=y.

Thanks,

Bart.