2025/04/20

[Linux] Dts

 

如何從執行中的檔案系統截取出 DTS

在已執行的系統中,其檔案系統格式的 DTS 位於:
/sys/firmware/devicetree/base/
而 /proc/device-tree 只是一個 soft link 連結到上述的位置。

另一個為 DTB 格式的 DTS 則是位於:
/sys/firmware/fdt

$ dtc -I dts -O dtb -o device-tree.dtb device_tree.dts

在 /sys/kernel/config/device-tree/overlays/ 目录下创建目录,创建完成后目录内自动会有三个文件 dtbo path status
直接复制 已经编译好的 *.dtbo 文件覆盖 dtbo 文件.

root@npi:/sys/kernel/config/device-tree/overlays# mkdir test
root@npi:/sys/kernel/config/device-tree/overlays# cd test
root@npi:/sys/kernel/config/device-tree/overlays/test# ls
root@npi:/sys/kernel/config/device-tree/overlays/test# dtbo path status
root@npi:/sys/kernel/config/device-tree/overlays/test# cat status
root@npi:/sys/kernel/config/device-tree/overlays/test# unapplied
root@npi:/sys/kernel/config/device-tree/overlays/test# cp /lib/firmware/test.dtbo dtbo
root@npi:/sys/kernel/config/device-tree/overlays/test# cat status
root@npi:/sys/kernel/config/device-tree/overlays/test# applied


 

2025/04/15

[Linux] Macro

#define DEVICE_ATTR_RW(_name) \
	struct device_attribute dev_attr_##_name = __ATTR_RW(_name)
#define __ATTR_RW(_name) __ATTR(_name, 0644, _name##_show, _name##_store) 
#define __ATTR(_name, _mode, _show, _store) {				\
	.attr = {.name = __stringify(_name),				\
		 .mode = VERIFY_OCTAL_PERMISSIONS(_mode) },		\
	.show	= _show,						\
	.store	= _store,						\
}
  
#define ATTRIBUTE_GROUPS(_name)					\
static const struct attribute_group _name##_group = {		\
	.attrs = _name##_attrs,					\
}; 
struct attribute_group {
	const char		*name;
	umode_t			(*is_visible)(struct kobject *,
					      struct attribute *, int);
	umode_t			(*is_bin_visible)(struct kobject *,
						  const struct bin_attribute *, int);
	size_t			(*bin_size)(struct kobject *,
					    const struct bin_attribute *,
					    int);
	struct attribute	**attrs;
	union {
		struct bin_attribute		**bin_attrs;
		const struct bin_attribute	*const *bin_attrs_new;
	};
};
struct attribute {
	const char		*name;
	umode_t			mode;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
	bool			ignore_lockdep:1;
	struct lock_class_key	*key;
	struct lock_class_key	skey;
#endif
};
    
CLASS_ATTR_RW(xxx);  <<-- xxx代表你想要的节点名字,可以任意字符内容
||
||
\/
struct class_attribute class_attr_xxx = <<--xxx是宏定义的括号里的内容
{
.attr = {
.name = "xxx", <<--这里就是宏定义的括号里的内容,你想要的节点名字
.mode = VERIFY_OCTAL_PERMISSIONS((S_IWUSR | S_IRUGO))
},
.show = xxx_show, <<--xxx也是宏定义括号里的内容,根据你括号里的内容而变
.store = xxx_store <<--xxx也是宏定义括号里的内容,根据你括号里的内容而变
}; 

2025/04/12

[Linux] Commands

 [GPIO]

gpioinfo // 板子定義gpio

gpioget gpiochip* [pin]

gpioset gpiochip* [pin]=[1/0]

cat /sys/kernel/debug/gpio // 真實ic定義gpio 給 gpio_request()

 

[Network] 

nmcli r wifi [on/off]

2025/04/05

[Linux] Simple Makefile

obj-m += "file_name".o


PWD := $(CURDIR)

all:
        $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
        $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

2025/04/04

[Raspberry] Pi 4 share folder

sudo apt install samba

編輯 /etc/samba/smb.conf

首先找到 workgroup
把 workgroup 設成和 Windows 一樣的 (可以在設定/系統/關於/進階系統設定/電腦名稱找到)

預設是 WORKGROUP
workgroup = WORKGROUP

加入要分享的資料夾

直接將以下這段放在smb.conf最下面即可:
[要分享的資料夾的名稱]
comment = "描述"
path = /home/"user"/share
browsable = yes
read only = no
create mask = 777
directory mask = 777

加入使用者
sudo smbpasswd -a <UserName> <password>


Linux ethernet 網路設定
192.168.xx.xx/24
255.255.255.0
192.168.1.1

WIndow加入
連線網路磁碟機->192.168.xx.xx