misc: add Tizen reboot notifier for passing reboot parameter 39/303539/1
authorJaehoon Chung <jh80.chung@samsung.com>
Tue, 2 Jan 2024 00:31:18 +0000 (09:31 +0900)
committerJaehoon Chung <jh80.chung@samsung.com>
Tue, 2 Jan 2024 04:22:08 +0000 (13:22 +0900)
To provide a reboot command with argument, add tien-inform-reboot.c file.
Its argument will be passed to U-boot, and u-boot will be parsing its argument.
Then it will be entering to a proper mode.

This patch is based on Tizen RPI4 kernel tree.

Change-Id: Icfcec0a26b1cf7a53c5c4352991463df9c67aed6
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
drivers/misc/Kconfig
drivers/misc/Makefile
drivers/misc/tizen-inform-reboot.c [new file with mode: 0644]

index 358ad56..2c1925a 100644 (file)
@@ -496,6 +496,23 @@ config VCPU_STALL_DETECTOR
 
          If you do not intend to run this kernel as a guest, say N.
 
+config TIZEN_INFORM_REBOOT
+       bool "Tizen reboot parameter passing support"
+       default "n"
+       help
+         This enables support for passing reboot parameter through inform
+         partition. It is required to determine booting mode (e.g., fota or
+         normal). After passing reboot parameter, u-boot checks the contents
+         of inform file and then determines proper booting mode.
+
+config TIZEN_INFORM_PATH
+       depends on TIZEN_INFORM_REBOOT
+       string "Absolute path of inform file for passing reboot parameter"
+       help
+         This option determines the absolute path of inform file for passing
+         reboot parameter.
+
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
index ac9b3e7..19c4dd4 100644 (file)
@@ -62,3 +62,4 @@ obj-$(CONFIG_HI6421V600_IRQ)  += hi6421v600-irq.o
 obj-$(CONFIG_OPEN_DICE)                += open-dice.o
 obj-$(CONFIG_GP_PCI1XXXX)      += mchp_pci1xxxx/
 obj-$(CONFIG_VCPU_STALL_DETECTOR)      += vcpu_stall_detector.o
+obj-$(CONFIG_TIZEN_INFORM_REBOOT)      += tizen-inform-reboot.o
diff --git a/drivers/misc/tizen-inform-reboot.c b/drivers/misc/tizen-inform-reboot.c
new file mode 100644 (file)
index 0000000..f85386e
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Tizen reboot parameter passing notifier
+ *
+ * Written by: Junghoon Kim <jhoon20.kim@samsung.com>
+ *
+ * Copyright (C) 2017 Samsung Electronics Co., Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/notifier.h>
+#include <linux/reboot.h>
+#include <linux/syscalls.h>
+#include <linux/file.h>
+#include <linux/fcntl.h>
+#include <linux/uaccess.h>
+
+static int inform_reboot_notifier(struct notifier_block *nb,
+                                               unsigned long val, void *buf)
+{
+       char *cmd = buf;
+       char *filename = CONFIG_TIZEN_INFORM_PATH;
+       struct file *file;
+       loff_t pos = 0;
+
+       file = filp_open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644);
+       if (!IS_ERR(file)) {
+               struct super_block *sb = file->f_path.dentry->d_sb;
+
+               if (cmd) {
+                       if (!strncmp(cmd, "fota", 4))
+                               cmd = "upgr";
+                       else if (!strncmp(cmd, "recovery", 8))
+                               cmd = "rcvr";
+                       else if (!strncmp(cmd, "download", 8))
+                               cmd = "dwnl";
+                       else
+                               cmd = "ndef";
+               } else
+                       cmd = "norm";
+
+               kernel_write(file, cmd, strlen(cmd), &pos);
+
+               down_read(&sb->s_umount);
+               sync_filesystem(sb);
+               up_read(&sb->s_umount);
+
+               fput(file);
+       } else {
+               pr_err("Reboot parameter passing is failed.\n"
+                               "Inform file path should be described correctly in config.\n");
+       }
+
+       return NOTIFY_DONE;
+}
+
+static struct notifier_block nb_inform_reboot_block = {
+       .notifier_call = inform_reboot_notifier,
+       .priority = 256,
+};
+
+static int __init inform_reboot_init(void)
+{
+       /* to support reboot parameter passing */
+       register_reboot_notifier(&nb_inform_reboot_block);
+       return 0;
+}
+
+subsys_initcall(inform_reboot_init);