1:oenwrt中调试文件系统的创建
在使用之前必须对文件系统进行挂载,Debugfs没有物理设备,其挂载方式:
mount -t debugfs none /sys/kernel/debug
在openwrt的系统启动的文件中有如下代码会挂载debugfs
其创建过程中设计到的API如下:
- struct dentry *debugfs_create_u8(const char *name, mode_t mode, struct dentry *parent, u8 *value);
- struct dentry *debugfs_create_u16(const char *name, mode_t mode, structdentry *parent, u16 *value);
- struct dentry *debugfs_create_u32(const char *name, mode_t mode, structdentry *parent, u32 *value);
- struct dentry *debugfs_create_bool(const char *name, mode_t mode, structdentry *parent, u32 *value);
-
struct dentry *debugfs_create_dir(constchar*name,struct dentry*parent);
struct dentry *debugfs_create_file(constchar*name, mode_t mode, struct dentry *parent,void*data,struct file_operations *fops)
struct dentry *debugfs_create_file(constchar*name, mode_t mode, struct dentry *parent,void*data,struct file_operations *fops)
其中直接对特定的变量进行控制就可以直接使用前面的四个函数。其相关的代码可以在内核中找到。
static u32dbg_txdesc_index;
struct dentry *dbg= wil->debug = debugfs_create_dir(WIL_NAME,wil_to_wiphy(wil)->debugfsdir);
if (IS_ERR_OR_NULL(dbg))
return -ENODEV;
if (IS_ERR_OR_NULL(dbg))
return -ENODEV;
debugfs_create_u32("desc_index", S_IRUGO | S_IWUSR, dbg,&dbg_txdesc_index);
#define WLAN_GPIO_OUT 0x00000000
#define WLAN_GPIO_ENABLE 0x0000000C
#define WLAN_GPIO_IN 0x00000018
#define WLAN_GPIO_PIN1 0x0000002c
static int filter_write_addr (struct file *file, const char *buf,unsigned long count, void *data)
{
char *end;
u32 val=0;
struct ath10k *ar = file->private_data;
val = (int)simple_strtoul(buf,&end,10);
ath10k_pci_write32(ar, WLAN_GPIO_BASE_ADDRESS +WLAN_GPIO_OUT,val);
return count;
}
static int filter_read_addr (struct file *file, char __user *user_buf, size_t size, loff_t *ppos)
{
int i=0,count=0,ret=0;
u32 val=0;
struct ath10k *ar = file->private_data;
char *buf = kzalloc(100*50, GFP_KERNEL);
if (!buf)
return -ENOMEM;
val = ath10k_pci_read32(ar, WLAN_GPIO_BASE_ADDRESS +WLAN_GPIO_OUT);
count += sprintf(buf+count, "0x%08x\n",val);
ret=simple_read_from_buffer(user_buf, size, ppos, buf, count);
kfree(buf);
return ret;
}
static const struct file_operations led_proc_fops = {
.read = filter_read_addr,
.write = filter_write_addr,
.open = simple_open,
.owner = THIS_MODULE,
.llseek = default_llseek,
};
#if 1
// printk(KERN_INFO "%s Enabled\n", opt->name);
u32 val=0;
ath10k_pci_write32(ar, WLAN_GPIO_BASE_ADDRESS +WLAN_GPIO_ENABLE,0x1082);
val = ath10k_pci_read32(ar, WLAN_GPIO_BASE_ADDRESS +WLAN_GPIO_ENABLE);
printk(KERN_INFO "WLAN_GPIO_ENABLE: 0x%08x\n",val);
ath10k_pci_write32(ar, WLAN_GPIO_BASE_ADDRESS +WLAN_GPIO_PIN1,0x828);
val = ath10k_pci_read32(ar, WLAN_GPIO_BASE_ADDRESS +WLAN_GPIO_PIN1);
printk(KERN_INFO "WLAN_GPIO_PIN1: 0x%08x\n",val);
#endif
debugfs_create_file("led", S_IRUSR, ar->debug.debugfs_phy, ar,&led_proc_fops);