1. 編譯及反編譯dtb檔
先安裝 device-tree-compiler 。
$ sudo apt-get install device-tree-compiler
反組譯 dtb 檔。
$ dtc -I dtb -O dts /where/your/source.dtb -o output.dtsi
反組譯後,即可用文字編輯器編輯 output.dtsi 。編輯好後,可以利用下面命令編成 dtb 檔。
$ dtc -I dts -O dtb output.dtsi -o output.dtb
2. 關閉Ubuntu休眠
安裝 xset 。
$ sudo apt-get install x11-xserver-utils
關閉休眠。
$ xset -dpms s off
$ xset s noblank
查看 xset 的設定。
$ xset -q
3. container_of用法
container_of 可以從 memeber 的指標來反推回去主結構的指標。
container_of 的定義在 kernel source code 裡的 include/linux/kernel.h 。
/**
* container_of - cast a member of a structure out to the containing structure
* @ptr: the pointer to the member.
* @type: the type of the container struct this is embedded in.
* @member: the name of the member within the struct.
*
*/
#define container_of(ptr, type, member) ({ \
void *__mptr = (void *)(ptr); \
BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
!__same_type(*(ptr), void), \
"pointer type mismatch in container_of()"); \
((type *)(__mptr - offsetof(type, member))); })
* container_of - cast a member of a structure out to the containing structure
* @ptr: the pointer to the member.
* @type: the type of the container struct this is embedded in.
* @member: the name of the member within the struct.
*
*/
#define container_of(ptr, type, member) ({ \
void *__mptr = (void *)(ptr); \
BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \
!__same_type(*(ptr), void), \
"pointer type mismatch in container_of()"); \
((type *)(__mptr - offsetof(type, member))); })
使用方法。假設我們定義了一個結構名為 my_struct 。如下所示。
struct my_struct {
int member1;
char member2;
int member3;
unsigned int member4;
...
};
如果我們有 member3 的指標,那就可以透過 container_of 來獲得 my_struct 的指標。
...
//p_member3 為member3的指標
struct my_struct* p_my_struct = container_of(p_member3,struct my_struct, member3);
...
4. v4l2 列出裝置支援的所有格式
安裝v4l-utils。
$ sudo apt install v4l-utils
列出裝置支援的格式。
$ v4l2-ctl -d /dev/video0 --list-formats-ext
5. git Diff From the First Commit
$ git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 HEAD
4b825dc642cb6eb9a060e54bf8d69288fbee4904 是 git 對所有空白的 tree 建立的第一個ID。所有的repository都會有此 id 。
6. 解壓縮zst檔
安裝zstd。
$ sudo apt-get install zstd
解壓縮檔案。
$ tar --use-compress-program=unzstd -xvf file.tar.zst
7. Mount the FileSystem of a Disk Image
假設有一個 disk.img ,這個 image 是整個 disk 的備份,並含有 partition table 。那必須先下以下指令列出 image 上所有的 partition 。
$ fdisk -lu disk.img
Disk disk.img: 6.1 GiB, 6581911552 bytes, 12855296 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 34D6B1B7-D6AF-438D-9B09-640A3E0DCB25
Device Start End Sectors Size Type
disk.img1 1019904 12840959 11821056 5.7G Linux filesystem
disk.img2 2048 133119 131072 64M Linux filesystem
disk.img3 133120 264191 131072 64M Linux filesystem
disk.img4 264192 265087 896 448K Linux filesystem
disk.img5 266240 267135 896 448K Linux filesystem
disk.img6 268288 397311 129024 63M Linux filesystem
disk.img7 397312 398335 1024 512K Linux filesystem
disk.img8 399360 399871 512 256K Linux filesystem
disk.img9 401408 401919 512 256K Linux filesystem
disk.img10 403456 1017855 614400 300M Linux filesystem
disk.img11 1017856 1017891 36 18K Linux filesystem
Partition table entries are not in disk order.
如果要 mount disk.img1 ,那就必須下以下指令。
$ sudo mount -o loop,offset=522190848 /path/disk.img /mount_point
其中offset 為 1019904 * 512。因為一個 Sector 為512 bytes 。
文章標籤
全站熱搜