readd samsung last_kmsg implementation
authorStricted <info@stricted.net>
Sat, 3 Feb 2018 05:55:11 +0000 (06:55 +0100)
committerStricted <info@stricted.net>
Thu, 11 Oct 2018 16:15:47 +0000 (18:15 +0200)
Change-Id: I7ed93a0bceb2b4cf77dc2b56155fedda1ebce6a9

drivers/staging/samsung/Kconfig
drivers/staging/samsung/Makefile
drivers/staging/samsung/sec_debug.c
drivers/staging/samsung/sec_debug_last_kmsg.c [new file with mode: 0644]
drivers/staging/samsung/sec_log.c
drivers/trace/exynos-ss.c
include/linux/sec_debug.h

index 0d5fbda09577fd1a6dcf2ec5a4d53266e77af93a..561b0156580ba1ba863e2c1560edae63c139c687 100644 (file)
@@ -77,21 +77,28 @@ menuconfig SEC_BSP
 
 comment "Samsung TN logging feature"
 config SEC_AVC_LOG
-       default y
+       default n
        bool "Enable avc audit log support" if EMBEDDED
        depends on SEC_EXT
        help
          This option enables additional log buffer for audit log.
 
 config SEC_DEBUG_TSP_LOG
-       default y
+       default n
        bool "Enable tsp log support" if EMBEDDED
        depends on SEC_EXT
        help
          This option enables additional log buffer for tsp log.
 
-config SEC_DEBUG_TIMA_LOG
+config SEC_DEBUG_LAST_KMSG
        default y
+       bool "Enable /proc/last_kmsg support" if EMBEDDED
+       depends on SEC_DEBUG
+       help
+         This option enables /proc/last_kmsg support.
+
+config SEC_DEBUG_TIMA_LOG
+       default n
        bool "Enable tima log support" if EMBEDDED
        depends on SEC_DEBUG
        help
index 83e14ab3238f31621abaafa96b1e422a9f3f3c8b..2cd9332d5f3a5a3e828f3ec49414784628dcc8ae 100644 (file)
@@ -16,6 +16,7 @@ obj-$(CONFIG_BATTERY_SMART)   += sec_batt.o
 
 # Samsung Logging Feature
 obj-$(CONFIG_SEC_EXT)          += sec_log.o
+obj-$(CONFIG_SEC_DEBUG_LAST_KMSG)      += sec_debug_last_kmsg.o
 # Samsung sec sysfs Feature
 obj-$(CONFIG_SEC_SYSFS)                += sec_sysfs.o
 # Samsung Reset Feature
index f105534ef5c3ed87834f41e766628b0b884d502f..65591381799e2dc94a94979456b6cfec6d316c42 100644 (file)
@@ -168,10 +168,12 @@ int __init sec_debug_init(void)
        size_t size = SZ_4K;
        size_t base = SEC_DEBUG_MAGIC_PA;
 
+#if 0  // enable sec_debug regardless debug_level temporarily
        if (!sec_debug_level.en.kernel_fault) {
                pr_info("sec_debug: disabled due to debug level (0x%x)\n", sec_debug_level.uint_val);
                return -1;
        }
+#endif
 
 #ifdef CONFIG_NO_BOOTMEM
        if (!memblock_is_region_reserved(base, size) &&
diff --git a/drivers/staging/samsung/sec_debug_last_kmsg.c b/drivers/staging/samsung/sec_debug_last_kmsg.c
new file mode 100644 (file)
index 0000000..d9b4ba1
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * sec_debug_last_kmsg.c
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd
+ *              http://www.samsung.com
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/uaccess.h>
+#include <linux/slab.h>
+#include <linux/proc_fs.h>
+#include <linux/sec_debug.h>
+
+static char *last_kmsg_buffer;
+static size_t last_kmsg_size;
+
+void sec_debug_save_last_kmsg(unsigned char* head_ptr, unsigned char* curr_ptr,
+       size_t log_size)
+{
+       if (head_ptr == NULL || curr_ptr == NULL || head_ptr == curr_ptr) {
+               pr_err("%s: no data \n", __func__);
+               return;
+       }
+
+       /* provide previous log as last_kmsg */
+       last_kmsg_size = (size_t)SZ_2M;
+       last_kmsg_buffer = (char *)kzalloc(last_kmsg_size, GFP_NOWAIT);
+
+       if (last_kmsg_size && last_kmsg_buffer) {
+               unsigned i;
+               // Relocate the last kmsg log buffer
+               for (i = 0; i < last_kmsg_size; i++)
+                       last_kmsg_buffer[i] = head_ptr[((size_t)(curr_ptr - head_ptr) - last_kmsg_size + i) & (log_size -1)];
+               pr_info("%s: successed\n", __func__);
+       } else
+               pr_err("%s: failed\n", __func__);
+}
+
+static ssize_t sec_last_kmsg_read(struct file *file, char __user *buf,
+                                 size_t len, loff_t *offset)
+{
+       loff_t pos = *offset;
+       ssize_t count;
+
+       if (pos >= last_kmsg_size)
+               return 0;
+
+       count = min(len, (size_t) (last_kmsg_size - pos));
+       if (copy_to_user(buf, last_kmsg_buffer + pos, count))
+               return -EFAULT;
+
+       *offset += count;
+       return count;
+}
+
+static const struct file_operations last_kmsg_file_ops = {
+       .owner = THIS_MODULE,
+       .read = sec_last_kmsg_read,
+};
+
+static int __init sec_last_kmsg_late_init(void)
+{
+       struct proc_dir_entry *entry;
+
+       if (last_kmsg_buffer == NULL)
+               return 0;
+
+       entry = proc_create("last_kmsg", S_IFREG | S_IRUGO,
+                       NULL, &last_kmsg_file_ops);
+       if (!entry) {
+               pr_err("%s: failed to create proc entry\n", __func__);
+               return 0;
+       }
+
+       proc_set_size(entry, last_kmsg_size);
+       return 0;
+}
+
+late_initcall(sec_last_kmsg_late_init);
index 9634abab91471c1c19deabe1c0f8c82ee0674d25..57df37edce1a8ca16eda06ae0db49c448289cbcf 100644 (file)
@@ -399,7 +399,6 @@ static int __init sec_tsp_log_late_init(void)
 late_initcall(sec_tsp_log_late_init);
 #endif /* CONFIG_SEC_DEBUG_TSP_LOG */
 
-
 #ifdef CONFIG_SEC_DEBUG_TIMA_LOG
 #ifdef   CONFIG_TIMA_RKP
 
index 7eeee522d4cfe6e79842866aa53900e1c0cd08b7..de1ed29a15f0f10f830a6be5fce1ea5c45eaaa6b 100644 (file)
@@ -1320,6 +1320,11 @@ static int __init exynos_ss_fixmap(void)
                ess_info.info_log[i - 1].entry.size = size;
        }
        exynos_ss_output();
+#ifdef CONFIG_SEC_DEBUG
+       sec_debug_save_last_kmsg(ess_items[ESS_ITEMS_LOG_KERNEL].head_ptr,
+                       ess_items[ESS_ITEMS_LOG_KERNEL].curr_ptr,
+                       ess_items[ESS_ITEMS_LOG_KERNEL].entry.size);
+#endif
        return 0;
 }
 
index c4a08e0e0d62401f84a00ad25e9843ef3eb8c03b..b75053d5ea438e3eabd7d0ea15b75aaea3421320 100644 (file)
@@ -63,6 +63,12 @@ extern void tsp_dump(void);
 #define sec_debug_tsp_log(a, ...)              do { } while(0)
 #endif
 
+#ifdef CONFIG_SEC_DEBUG_LAST_KMSG
+extern void sec_debug_save_last_kmsg(unsigned char* head_ptr, unsigned char* curr_ptr, size_t log_size);
+#else
+#define sec_debug_save_last_kmsg(a, b, c)              do { } while(0)
+#endif
+
 enum sec_debug_upload_cause_t {
        UPLOAD_CAUSE_INIT               = 0xCAFEBABE,
        UPLOAD_CAUSE_KERNEL_PANIC       = 0x000000C8,