misc: add Tizen reboot notifier for passing reboot parameter 12/317212/1
authorMarek Szyprowski <m.szyprowski@samsung.com>
Wed, 4 Sep 2024 11:16:13 +0000 (13:16 +0200)
committerMarek Szyprowski <m.szyprowski@samsung.com>
Thu, 5 Sep 2024 13:23:47 +0000 (15:23 +0200)
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.

Signed-off-by: Junghoon Kim <jhoon20.kim@samsung.com>
Signed-off-by: Ɓukasz Stelmach <l.stelmach@samsung.com>
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Signed-off-by: Hoegeun Kwon <hoegeun.kwon@samsung.com>
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
[mszyprow: this is a squashed set of the following patches
 from platform/kernel/linux-rpi 'tizen' (c4f85fdcd893) branch:
 misc: add Tizen reboot notifier for passing reboot parameter
 misc: make sure Tizen notifier is executed before reset
 misc: tizen-inform-reboot: resolve sync failure about reboot parameter
 misc: tizen-inform-reboot: Add support for download mode
 misc: tizen-inform-reboot: Use ksys_open() and ksys_close() wrappers
 misc: tizen-inform-reboot: Fix to use filp_open.
 misc: tizen-inform-reboot: Fix build error
 misc: tizen-inform-reboot: fix a potential NULL pointer dereference
 misc: tizen-inform-reboot: Remove force_uaccess begin and end func
 misc: tizen-inform_reboot: Fix to use kernel_write function
 ported to v6.6 linux-rpi kernel and adapted for
 linux-tizen-modules-source repository]

Change-Id: I0b29ad06958e08ffbb48e1b145e0dafb3388faf8
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
kernel/Makefile
kernel/inform-reboot.c [new file with mode: 0644]

index d3d3a647598c7594df98cf66d3bd4bdbe7f21ede..5e5ae2ef3642b7c69720d4e0def228aae427c795 100644 (file)
@@ -6,6 +6,8 @@ LOGGER_EVENTS_BUFFER_SIZE ?= 256
 LOGGER_RADIO_BUFFER_SIZE ?= 256
 LOGGER_SYSTEM_BUFFER_SIZE ?= 256
 
+TIZEN_INFORM_PATH ?= "/mnt/inform/reboot-param.bin"
+
 # See commit 0b999ae3614d0 ("Merge tag 'compiler-attributes-for-linus-v5.0-rc7'"[..]) for rationale
 CFLAGS_logger.o   += -Wno-error=missing-attributes \
        -DLOGGER_MAIN_BUFFER_SIZE=$(LOGGER_MAIN_BUFFER_SIZE) \
@@ -13,15 +15,18 @@ CFLAGS_logger.o   += -Wno-error=missing-attributes \
        -DLOGGER_RADIO_BUFFER_SIZE=$(LOGGER_RADIO_BUFFER_SIZE) \
        -DLOGGER_SYSTEM_BUFFER_SIZE=$(LOGGER_SYSTEM_BUFFER_SIZE)
 CFLAGS_proc-tsm.o += -Wno-error=missing-attributes
+CFLAGS_inform-reboot.o += -DTIZEN_INFORM_PATH="\"$(TIZEN_INFORM_PATH)\""
 
 # Build is disabled by default so that when new module is added to this repository (and -source package),
 # it won't get automatically build in packages using it (that would break these automatically as file list
 # would no longer match).
+BUILD_inform_reboot ?= n
 BUILD_logger ?= n
 BUILD_proc_tsm ?= n
 BUILD_kdbus ?= n
 BUILD_zlogger ?= n
 
+obj-$(BUILD_inform_reboot) += inform-reboot.o
 obj-$(BUILD_logger) += logger.o
 obj-$(BUILD_proc_tsm) += proc-tsm.o
 obj-$(BUILD_kdbus) += kdbus/
diff --git a/kernel/inform-reboot.c b/kernel/inform-reboot.c
new file mode 100644 (file)
index 0000000..c330301
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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 = 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);
+
+MODULE_LICENSE("GPL");