oenwrt 中的调试文件系统

1:oenwrt中调试文件系统的创建

在使用之前必须对文件系统进行挂载,Debugfs没有物理设备,其挂载方式:

mount -t debugfs none /sys/kernel/debug
在openwrt的系统启动的文件中有如下代码会挂载debugfs


其创建过程中设计到的API如下:

  1. struct dentry *debugfs_create_u8(const char *name, mode_t mode, struct dentry *parent, u8 *value);  
  2. struct dentry *debugfs_create_u16(const char *name, mode_t mode, structdentry *parent, u16 *value);  
  3. struct dentry *debugfs_create_u32(const char *name, mode_t mode, structdentry *parent, u32 *value);  
  4. 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)

其中直接对特定的变量进行控制就可以直接使用前面的四个函数。其相关的代码可以在内核中找到。

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;
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);





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

家有工程师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值