vimNote

vim 用久了總要試著客製化,這篇就來紀錄一下吧!
我覺得一個好的文字編輯器要:

  1. 配色要看的順眼
  2. 有方便的快捷鍵(搜尋 取代 註解等等)
  3. 自動完成
  4. Trace code 的功能(搜尋函式或變數宣告等等)

現在有很多很方便的文字編輯器,選一個自己用的最順手的就好囉!
我的話因為大部分都在寫C,也滿習慣終端機的介面,歷久彌新的Vim就是最好選擇!

使用 vundle 來管理套件,依照指示來修改.vimrc就可以開使用了。

我目前使用的套件有

  • 狀態列:airline
    還可以額外加入顯示git資訊以及選擇字型等等,在這邊就先不介紹拉。

    • ‘vim-airline/vim-airline’
    • ‘vim-airline/vim-airline-themes’
  • 文件瀏覽:NERDTree

    • ‘scrooloose/nerdtree’
  • 搜尋定義:taglist

    • ‘vim-scripts/taglist.vim’
  • 自動完成:YouComleteMe

    • ‘Valloric/YouCompleteMe’
    • 安裝這個套件的話,vim在編譯時要加入 python support^[2]^,其他照著說明來安裝就好囉

外觀主題:

  • ‘sonph/onehalf’

Vim Hot keys

Vim 可以自定義一些快捷鍵,操作起來可以更方便,不過有時候定義太多反而會造成困擾,我想先熟悉內建的熱鍵就好,有需要的話再加。

以下列出幾個我目前覺得會比較常用到的

vim window:

ctrl+w :arrow_up: :arrow_down: :arrow_left: :arrow_right:
ctrl+w +v vertical split
ctrl+w +s horizontal split
ctrl+w +c close window
ctrl+w +T expand current window to new tab

vim tab

:tabnew 創立新的tab
:tabNext 移至下一個tab

NERD Tree

nerd Tree Hotkeys這篇寫了幾個滿基本的按鍵。

修改紀錄

  • 2017/2/5
    心血來潮來重新設定vim,順便將用到的套件稍微整理一下,之後如果有用新的套件的話會陸陸續續更新在此文件。

Reference

  1. YCM installation guide
  2. Vim with python support

linux_kernel_trace_event

最近要從 linux kernel 撈一些資料出來看,用 printk() 很沒效率,結果也不一定符合預期。

找了一下 linux 內建的 trace events

用法滿直接的,把 debugfs mount 好之後就可以開始用了!

先切換到底下路徑: /sys/kernel/debug/tracing

裡面會有幾個資料夾和檔案,底下介紹我有用到的部分:

  • available_events : 紀錄了一些可使用的events,像是 ext4、jbd2 等等
  • set_event:將 available_events 中要 trace 的函式名稱複製到這個檔案就可以啟用了
    也可以透過echo “ext4:*” > set_event 來啟用某個特定的subsystem
  • trace:event trace 的輸出會寫到這個檔案,可以透過 cat 輸出這個檔案到其他資料夾
  • trace_pipe:如果要不中斷地輸出 event trace 的資料,可以 cat 這個檔案

Android-Kernel-Compilation

Using Nexus 4 as example

Environment:

  • Ubuntu 16.04 LTS
  • kernel version 4.4.0-47-generic
  • CPU

Step

  1. download andorid kernel source of a particular version.
    $ git clone https://android.googlesource.com/kernel/msm.git
    • the master branch is empty^[1]^, using $ git branch -r to see the list of remote branch.
    • $ git checkout -b <local branch name> <remote branch name>
    • Here I use origin/android-msm-mako-3.4-lollipop-release
  2. download cross compiler for example : arm-linux-androideabi-4.6
    $ git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6
  3. setup environment variables
    export ARCH=arm
    export PATH=$PATH:${path to cross compiler}/arm-linux-androideabi-4.6/bin
    export CROSS_COMPILE=arm-linux-androideabi-
  4. choose a config file
    $ make mako_defconfig
    In directoty /arch/arm/configs/, choose a default config
    • make menuconfig to view available options
      • append addtional build version number …etc
  5. build the kernel

    $ make -j4
    If succeeds, there will be a zImage file in /arch/arm/boot

    • kernel/timeconf.pl line 373 may have error, comments the
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      @@ -370,9 +370,9 @@ if ($hz eq '--can') {
      }
      @val = @{$canned_values{$hz}};
      - if (!defined(@val)) {
      - @val = compute_values($hz);
      - }
      + #if (!defined(@val)) {
      + # @val = compute_values($hz);
      + #}
      output($hz, @val);
      }
  6. install the kernel to you phone ^[5]^
    I use factory imgaes from here and wrap new zImage into boot.img

    • $ sudo apt-get install abootimg
    • extract boot.img by $ abootimg -x boot.img
    • update bootsize in bootimg.cfg with Hex format
      If the bootsize is unknown, directly run the commands below. abootimg will promt out a message saying that the bootsize is incorrect and the correct bootsize is displayed

    • pack new boot.img
      $ abootimg --create <your_boot.img> -f bootimg.cfg -k zImage -r initrd.img

    • use fastboot to flash new boot.img,
      $ fastboot boot <your_boot.img>
  7. See if you compile success
    Check the phone status

Comments

  • Before building the kernel, you can use $ make menuconfig to change the kernel name

    or modify the Makefile in the root to add custom kernel version

Reference:

[1] https://groups.google.com/forum/?fromgroups=#!topic/android-kernel/Rq5993NokVs%5B1-25%5D
[2]Tutorial: Android Kernel Configure, Compile & Install (Part 1)
[3]Tutorial: Android Kernel Configure, Compile & Install (Part 2)
[4] http://forum.xda-developers.com/nexus-4/general/howto-build-nexus-4-kernel-t2021202
[5] http://forum.xda-developers.com/showpost.php?p=37379748&postcount=40