다음과 같은 경로에 read/write 가능한 debug fs를 생성한다
cat /sys/kernel/debug/rpi_debug/val
아래의 코드를 module로 생성하여 빌드한다.
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/platform_device.h>
#include <linux/io.h>
#include <linux/init.h>
#include <linux/memblock.h>
#include <linux/slab.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/cpu.h>
#include <linux/delay.h>
#include <asm/setup.h>
#include <linux/input.h>
#include <linux/debugfs.h>
#include <linux/timer.h>
#include <linux/workqueue.h>
#include <linux/mutex.h>
#include <linux/slub_def.h>
#include <linux/uaccess.h>
#include <asm/memory.h>
uint32_t my_debug_state = 0x1000;
static struct dentry *my_debugfs_root;
static int my_stat_get(void *data, u64 *val)
{
*val = my_debug_state;
return 0;
}
static int my_stat_set(void *data, u64 val)
{
my_debug_state = (uint32_t)val;
return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(my_stat_fops, my_stat_get, my_stat_set, "%llu\n");
static int my_debugfs_driver_probe(struct platform_device *pdev)
{
return 0;
}
static struct platform_driver my_debugfs_driver = {
.probe = my_debugfs_driver_probe,
.driver = {
.owner = THIS_MODULE,
.name = "my_debug",
},
};
static int __init my_debugfs_init(void)
{
my_debugfs_root = debugfs_create_dir("my_debug", NULL);
debugfs_create_file("val", S_IRUGO, my_debugfs_root, NULL, &my_stat_fops);
return platform_driver_register(&my_debugfs_driver);
}
late_initcall(my_debugfs_init);
MODULE_LICENSE("GPL");
.
'Kernel > Practice' 카테고리의 다른 글
| misc device 例 (0) | 2024.09.21 |
|---|---|
| kwork 사용 例 (0) | 2024.02.02 |
| hrtimer 사용 例 (0) | 2024.02.02 |
| process 생성/종료 ftrace 얻기 (0) | 2024.02.02 |
| 함수 ftrace 얻기 (0) | 2024.02.02 |