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

[Raspberry] Pi 4 Enable serial0

[install_raspi-config]

https://github.com/EmilGus/install_raspi-config/blob/master/README.md

 

  • Start raspi-config: sudo raspi-config
  • Select option - Update
  • Reboot
  • Select option 3 - Interface Options
  • Select option P6 - Serial Port
  • At the prompt Would you like a login shell to be accessible over serial?, answer 'No'
  • At the prompt Would you like the serial port hardware to be enabled?, answer 'Yes'

  • 注意:如果您在樹莓派上安裝了 Ubuntu 作業系統,請進行如下組態:

    • /boot/config.txt 加入 enable_uart=1

    • 在 Ubuntu系統的文件 /boot/firmware/cmdline.txt中刪除

    console=serial0,115200(類似於在樹莓派系統中文件/boot/cmdline.txt)

    • 運行以下命令關閉序列控制台:

    sudo systemctl stop serial-getty@ttyS0.service && sudo systemctl disable serial-getty@ttyS0.service

    • 請確保您已安裝python 序列庫 pyserial,而不是來自 apt 的 python-serial。

    • 建立 udev file (/etc/udev/rules.d/50-tty.rules),並加入以下內容:

    • KERNEL=="ttyS0", SYMLINK+="serial0" GROUP="tty" MODE="0660"
      KERNEL=="ttyAMA0", SYMLINK+="serial1" GROUP="tty" MODE="0660"
    • 運行以下命令多載 udev 規則:

    sudo udevadm control --reload-rules && sudo udevadm trigger

    2025/04/03

    Raspberry 4B pin definition



    Linux nano cmd

     

    • Ctrl+K 剪下整列或選取範圍
    • Alt+6 複製整列或選取範圍
    • Ctrl+6 開始選取
    • Ctrl+U 貼上剪貼簿內容
    • Alt+U Undo
    • Alt+E Redo
    • Alt+Del 刪除整行
    • Alt+3 Comment/Uncomment
    • Alt+/ || Alt+G 跳到指定行數
    • Ctrl+G Help
    • Alt+W || F6 尋找
    • Alt+Q 尋找下一個
    • Alt+W 尋找上一個
    • Alt+R 尋找並置換
    • Alt+X 關閉下方 Help 提示
    • Ctrl+S 存檔
    • Ctrl+O 另存新檔
    • Ctrl+X 退出