From: Marek Szyprowski Date: Wed, 4 Sep 2024 11:16:13 +0000 (+0200) Subject: misc: add Tizen reboot notifier for passing reboot parameter X-Git-Tag: accepted/tizen/unified/20240924.153228~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b2df6ecebdd0bbb254672be2370ca9f33fa08411;p=platform%2Fkernel%2Flinux-tizen-modules-source.git misc: add Tizen reboot notifier for passing reboot parameter 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 Signed-off-by: Ɓukasz Stelmach Signed-off-by: Dongwoo Lee Signed-off-by: Hoegeun Kwon Signed-off-by: Jaehoon Chung Signed-off-by: Marek Szyprowski [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 --- diff --git a/kernel/Makefile b/kernel/Makefile index d3d3a64..5e5ae2e 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -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 index 0000000..c330301 --- /dev/null +++ b/kernel/inform-reboot.c @@ -0,0 +1,73 @@ +/* + * Tizen reboot parameter passing notifier + * + * Written by: Junghoon Kim + * + * 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 +#include +#include +#include +#include +#include + +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");