- System
- Multi-threads
2018年1月5日 星期五
2017年12月9日 星期六
2017年11月29日 星期三
[Development] using GNU development tools
- SOP
Configure
Build
- universal binary:
- build flag: e.g.
--arch ppc --arch i386
Install
2017年11月25日 星期六
[Kernel] Linux kernel debug
- 技巧
- 用 printk dump messages to console
- 簡單好用, 行為類似 printf, 不過這會改變 kernel行為 (例如: 執行速度變慢, 使得 race condition 行為不一致)
- 可同時更改 ring buffer size (更改 kernel boot parameter: log_buf_len), 避免 log的訊息被裁斷
- 更改 log level, 預設為 KERN_WARNING, e.g. 開啟所有 log: , 並刪除 boot parameters: quiet, splash (runtime 查看 boot parameters:
- 用 gdb
- disassemble function codes
-
gdb vmlinux
(gdb) dissemble functionName - locate core dump:
gdb crashed_function_obj, e.g. gdb sd.o(gdb) list *(backtrace_func_shown+offset), e.g. list *(sd_remove+0x20- 用 objdump
objdump -SdCg sample.o- ToDo: add2line 指令介紹, ELF 格式介紹, study Kernel Debugging
- Reference
cat /proc/cmdline)echo 7 > /proc/sys/kernel/printk2017年8月2日 星期三
[Notes] Linux Devices Drivers 3Ed.
- Books: Linux Device Drivers
- Ch1. Introduction
- 說明驅動程式的角色
- 設計原則: 提供機制 (mechanism)-要提供什麼能力, 而非法則 (policy)-如何使用這些能力
- Kernel 概論
- Module
- Device分類: character device, block device, network interface
- Ch2. Module
- Kernel preparation
- Download Linux Kernel source codes
apt-get source linux-image-unsigned-$(uname -r)
sudo apt-get install libncurses-dev flex bison openssl libssl-dev dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf
cp /boot/config-4.15.0-91-generic .
make menuconfig
make -j 16 clean
make -j 16
- build -
- include kernel headers (/usr/src/linux-headers)
- make file - obj-m
- sample module file
#include#include MODULE_DESCRIPTION("Hello_world"); MODULE_LICENSE("GPL"); static int hello_init(void) { printk(KERN_INFO "Hello world !\n"); return 0; } static void hello_exit(void) { printk(KERN_INFO "Bye !\n"); } module_init(hello_init); module_exit(hello_exit);
PWD := $(shell pwd) KVERSION := $(shell uname -r) KERNEL_DIR = /usr/src/linux-headers-$(KVERSION)/ MODULE_NAME = hello obj-m := $(MODULE_NAME).o all: make -C $(KERNEL_DIR) M=$(PWD) modules clean: make -C $(KERNEL_DIR) M=$(PWD) clean
insmod hello.ko dmseg
- header: 重要 headers: linux/init.h, linux/module.h 含有後面要用到的 marcos
- license
- module_init()
- module_exit
- module_param(parameterName, type, permission)
2017年7月15日 星期六
[Kernel] Portal
- Tool:
- trace kernel: LXR
- Steps
- Environment setup
- source code
- architecture
- fetch: apt-get source linux-image-$(uname -r)
- sources.list -> 可能需要 uncomment /etc/apt/sources.list 中 deb-src 的 #, 並且做 apt-get update
- build
- 推薦書目:
- Linux Kernel in a nutshell
- Understanding the Linux Kernel
- Professional Kernel Architecture - 中譯本: 深入探索 Linux 核心架構
- Linux Kernel Development - 中譯本: 精通Linux核心開發 : 設計與實作Linux核心的權威指南
- Understanding Linux Network Internals - 中譯本: Linux 網路原理
- Linux Device Driver - 中譯本: Linux驅動程式
- Essential Linux Device Driver - 中譯本: Linux 驅動程式開發實戰
- Debugging Linux Systems
- Linux 鳥哥的私房菜
- Reference:
2017年6月16日 星期五
[License] GPL v.s. LGPL & GPL in Linux
- 簡單比較
- GPL:
- 保護 application
- 較嚴苛
- release binary時, 需要 release source code
- 僅為執行(非修改)此 binary使用, 不用 release source code
- LGPL:
- 保護 library
- 較寬鬆
- dynamically or statically link則無限制
- 在 kernel 上所執行的使用者應用程式都不受 GPL制約
2013年6月5日 星期三
[Vim] Mac中 Vim 設定
- 預設路徑
binary: /usr/bin
support file: /usr/share/vim/vim73
rc: ~/.vim/vimrc (若沒有, 請自己建)
- 單一檔案的 plugin 應放在 ~/.vim/plugin下, e.g. a.vim
- 其他 plugin一句底下的資料夾放置(例如: ctrlp)
- ~/.vim/autoload/ctrlp/
- ~/.vim/autoload/ctrlp/ctrlp.vim
- ~/.vim/doc/ctrlp.txt
- ~/.vim/plugin/ctrlp.vim
- plugins/colorschemes/scripts 放在 ~/.vim下, not /usr/share/vim/vim73
- a.vim: 在 header與 source file間切換
- :A =>切換
- :AT =>切換至新開的 tag page
- :AS => split? 垂直分割
- :AV => horizontal 分割
- 不知為啥, 我覺得 :AS與 :AV 沒作用
[Vim] vim 快攻
- 重要參數
- 可單獨操作
- b before
- e end
- w word
- $ 行末
- 0 行頭
- g global
- c confirm
- ! 強制
- 移動
- hjkl 分別是左下上右, 應該主要是右手食指上中指下
- gg 檔案起始處
- #shift-G #代表行號, 沒輸入則是到檔案最後一行
- 檔案操作
- :q quit
- :wq write & quit
- 文件編輯
- i insert
- x ...這不知道是啥
- a append, A 可在行末 append
- d delete, 可搭配參數, e.g: dw, d$, d0
- p paste
- u undo, U: 還原整行, ctrl-R為還原先前操作
- o open new line
- % 找到配對的括號
- dd 刪除行
- 搜尋與取代類
- / 向下搜尋, 找到後用 n跳至下一個, shift-N至上一個
- ? 向上搜尋
- 環境可設定 :set hls highlight search, 便會有如 source Insight中 F8的功能啦, 要讓它消失則下 :noh noHightLight
- r replace 單一字元
- R 是同進入取代模式
- c change, 搭配參數用, e.g. cw: change word, 會取代掉 cursor所在的 word
- :s strike, 應該會是最常用的功能
- s/old/new/g 將 old用 new取代, 若後面加 /g則為 global
- s/old/new/gc c是 confirm用
- #,#s/old/new/gc #是行號, 代表在這兩行之間的取代動作
- 執行外部指令
- :!script, script為 shell script, e.g. :!ls, 但有些動作還是不能操作, 剛試驗了一下, :!cd ~/Desktop, 再執行 :!pwd, 似乎並沒改變
- :r fileName, 可將檔案 fileName的內容貼到目前 cursor處
- 外掛類
- a.vim
- :a switch between header/source code
- ctag
- auto complete
- Ctrl-N
2013年6月1日 星期六
[Linux] GRUB2 開機順序
- cd /etc/grub.d/ (開機順序存放在此資料夾, 以 prefix數字小到大的順序開機, 預設 linux為 10_linux, 優於 30_os-proper的 windows作業系統, 因此, 執行以下兩步驟, done!)
- 30_os-proper 更名為 08_os-proper (mv ./30_os-proper ./08_os-proper)
- sudo update-grub
2012年12月17日 星期一
訂閱:
文章 (Atom)