misc: add Tizen reboot notifier for passing reboot parameter 04/145004/7
authorJunghoon Kim <jhoon20.kim@samsung.com>
Mon, 21 Aug 2017 02:04:32 +0000 (11:04 +0900)
committerJaehoon Chung <jh80.chung@samsung.com>
Mon, 18 Sep 2017 07:07:43 +0000 (07:07 +0000)
To determine booting mode (e.g, fota or recovery) in u-boot side, reboot
parameter should be passed through inform partition.

Add Tizen reboot notifier for passing reboot parameter.

Change-Id: I5830dcf58ec6905b0bc382599aa9ff1251f817d8
Signed-off-by: Junghoon Kim <jhoon20.kim@samsung.com>
drivers/misc/Kconfig
drivers/misc/Makefile
drivers/misc/tizen-inform-reboot.c [new file with mode: 0644]

index 779f7d6..765fcc0 100644 (file)
@@ -774,6 +774,22 @@ config PANEL_BOOT_MESSAGE
          An empty message will only clear the display at driver init time. Any other
          printf()-formatted message is valid with newline and escape codes.
 
+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 6c400f0..0e99344 100644 (file)
@@ -54,6 +54,7 @@ obj-$(CONFIG_ECHO)            += echo/
 obj-$(CONFIG_VEXPRESS_SYSCFG)  += vexpress-syscfg.o
 obj-$(CONFIG_CXL_BASE)         += cxl/
 obj-$(CONFIG_PANEL)             += panel.o
+obj-$(CONFIG_TIZEN_INFORM_REBOOT)      += tizen-inform-reboot.o
 
 lkdtm-$(CONFIG_LKDTM)          += lkdtm_core.o
 lkdtm-$(CONFIG_LKDTM)          += lkdtm_bugs.o
diff --git a/drivers/misc/tizen-inform-reboot.c b/drivers/misc/tizen-inform-reboot.c
new file mode 100644 (file)
index 0000000..7a1f16f
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * 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;
+       int fd;
+       loff_t pos = 0;
+       mm_segment_t old_fs = get_fs();
+
+       set_fs(KERNEL_DS);
+
+       fd = sys_open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644);
+       if (fd >= 0) {
+               file = fget(fd);
+               if (file) {
+                       if (cmd) {
+                               if (!strncmp(cmd, "fota", 4))
+                                       cmd = "upgr";
+                               else if (!strncmp(cmd, "recovery", 8))
+                                       cmd = "rcvr";
+                               else
+                                       cmd = "ndef";
+                       } else
+                               cmd = "norm";
+
+                       vfs_write(file, cmd, strlen(cmd), &pos);
+                       vfs_fsync(file, 0);
+                       fput(file);
+               }
+               sys_close(fd);
+               /* to guarantee all file data and metadata sync */
+               emergency_sync();
+       } else {
+               pr_err("Reboot parameter passing is failed.\n"
+                               "Inform file path should be described correctly in config.\n");
+       }
+
+       set_fs(old_fs);
+
+       return NOTIFY_DONE;
+}
+
+static struct notifier_block nb_inform_reboot_block = {
+       .notifier_call = inform_reboot_notifier
+};
+
+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);