Skip to content

Instantly share code, notes, and snippets.

@allenyllee
Last active February 26, 2024 04:39
Show Gist options
  • Save allenyllee/d7431053780f469b30bfd4a073ebf711 to your computer and use it in GitHub Desktop.
Save allenyllee/d7431053780f469b30bfd4a073ebf711 to your computer and use it in GitHub Desktop.

Linux Driver Coding Notes

##I/O Device Driver

  • Character Driver
  • Block Driver

##Interrupt Service Routine

  • Bottom Half

    • Tasklet
      • can not be preempt
    • Workqueue
      • can be preempt
  • Wait Queue

  • Complations

  • Timer List

  • Notification

    • 非同步通知
      • SIGIO
    • 執行user space 應用
      • call_usermodehelper()

##Platform Device & Platform Driver

##通訊方式

  • SPI
    • MTD
  • I2C
  • UART

Engr.Cat 的debug 清單

應用軟體

Chrome

FVD Speed Dial 同步問題

有時會發現用Ever Sync 同步很久還是無法完成的問題,如何debug?

  1. 首先到__擴充功能__頁面,勾選右上角__開發人員模式__
  2. 找到Ever Sync (ID: iohcojnlgnfbmjfjfkbhahhmppcggdog) 找到 查看檢視模式 點擊 background.html
  3. 會開啟一個視窗,頁面上方選 Console,可以看到log
  4. 同2. 3.步驟找到FVD Speed Dial (ID: llaficoajjainaijghjlofdfmbjpebpa) 點擊 background.html 可以看見log
  5. 發現同步時出現一個error could not execute statement (778 disk I/O error)
  6. Disk I/O 失敗,懷疑是防毒軟體造成
  7. 在防毒軟體的real-time scan 在例外 process 加入 chrome.exe
  8. 問題解決

BitTorrent Sync

有時會一直無法完成同步,顯示上傳中...

  1. 先看是哪個資料夾出現問題
  2. 關閉Sync 程式
  3. C:\Users\PEGA-Allen\AppData\Roaming\BitTorrent Sync
  4. 刪除該資料夾對應的 .db.availability 檔案 (可以用_.db_檔案的大小來猜測,如果資料夾裡檔案數量越多_.db_越大)
  5. 重新開啟Sync ,讓程式重建資料庫

Docker

執行 docker run hello-world 後等很久,出現以下訊息

Network timed out while trying to connect to https://index.docker.io/v1/repositories/library/hello-world/images. You may want to check your internet connection or if you are behind a proxy..

解決辦法: 進到 Settings > Network 裡,將 DNS server 設成 8.8.8.8 即可

AllenYL 的How To清單

Octopress

Windows環境設置(使用chocolatey)

Chocolatey Packages

  • 安裝chocolatey
  rem cmd
  @powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
  • 安裝git
  choco install git
  • 安裝ruby 1.9.3
  choco install ruby -version 1.9.3.55100

有時因安全性問題無法舊版無法執行,更新版本請用

  choco upgrade ruby
  • 安裝ruby dev kit
 rem for ruby 2.0+
 choco install ruby2.devkit
 
 rem for ruby 1.8 & 1.9
 choco install ruby.devkit

x64 版本有些bug,造成安裝失敗,解決辦法參考 Can't get Ruby DevKit configuration file autogenerated properly

直接下載DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe 解壓縮到chocolatey 預設解壓的資料夾C:\tools\DevKit2,開啟檔案dk.rb,找到REG_KEYS修改如下

   REG_KEYS = [
       'Software\RubyInstaller\MRI',
       'Software\RubyInstaller\Rubinius',
       'Software\Wow6432Node\RubyInstaller\MRI'
   ]

改完後執行

    ruby dk.rb init

產生新的config.yml後再執行

    ruby dk.rb install
  • 安裝完後必須更新環境變數才會生效
  refreshenv
  • 確認ruby 版本
  ruby --version

設置octopress

  • 移到octopress目錄下,安裝dependancies 記得將git 切到octopress 的 source branch
  gem install bundler
  bundle install
  1. 若出現以下錯誤訊息:
Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=SSLv3 read
server certificate B: certificate verify failed
(https://rubygems.org/gems/rake-10.5.0.gem)
An error occurred while installing rake (10.5.0), and Bundler
cannot continue.
Make sure that `gem install rake -v '10.5.0'` succeeds before bundling.

參考 ruby on rails - bundle install fails with SSL certificate verification error - Stack Overflow 執行gem update --system

  1. 若出現:
Errno::EINVAL: Invalid argument -
C:/tools/ruby193/lib/ruby/gems/1.9.1/gems/jekyll-sitemap-0.11.0/spec/fixtures/_posts/2016-04-01-i¶↓h
An error occurred while installing jekyll-sitemap (0.11.0), and
Bundler cannot continue.
Make sure that `gem install jekyll-sitemap -v '0.11.0'` succeeds before
bundling.

Goto your devKit location and run the following command in terminal ruby dk.rb init ruby dk.rb install

  1. 若出現:
ERROR:  Could not find a valid gem 'bundler' (>= 0), here is why:
          Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://api.rubygems.org/specs.4.8.gz)

參考 rubygems SSL Issue Copying https://raw.githubusercontent.com/rubygems/rubygems/master/lib/rubygems/ssl_certs/index.rubygems.org/GlobalSignRootCA.pem into C:\Ruby23-x64\lib\ruby\2.3.0\rubygems\ssl_certs

發布blog

rake setup_github_pages

Note: 如果你不是全新安裝,而是從github Clone 之前的資料,還是必須要執行這個指令,才會產生 _deploy 資料夾。但是rake deploy 會出現無法 push fail 的錯誤訊息,所以請參考下方,將本地 master 刪除,改成遠端master。

  • 之後就可以執行以下命令
rake generate   # Generates posts and pages into the public directory
rake watch      # Watches source/ and sass/ for changes and regenerates
rake preview    # Watches, and mounts a webserver at http://localhost:4000
$ git add .
$ git commit -m "article:Github page + Octopress"
$ git push
$ rake deploy
  • 若出現以下錯誤訊息:
   ## Pushing generated _deploy website
   To https://github.com/allencatlee/allencatlee.github.io
    ! [rejected]        master -> master (non-fast-forward)
   error: failed to push some refs to 'https://github.com/allencatlee/allencatlee.github.io'
   hint: Updates were rejected because the tip of your current branch is behind
   hint: its remote counterpart. Integrate the remote changes (e.g.
   hint: 'git pull ...') before pushing again.
   hint: See the 'Note about fast-forwards' in 'git push --help' for details.

   ## Github Pages deploy complete
   cd -
原因可能是目前本地端的__master__ 跟遠端的__master__ 不相同,所以請先切換到`_deploy`資料夾下,將本地端的__master__改名成__master2__,再從遠端__checkout origin/master__,確認無誤後,再剛剛的__master2__刪除。

octopress/docs#54 (comment)

   cd _deploy 				## 切換到_deploy 資料夾, 底下應該有.git的資料夾
   
   git checkout master 	## 切換到master分枝
   
   git branch -m master2 	## 重新命名成master2
   
   git branch -r 			## 列出所有遠端分枝
   
   git checkout origin/master -b master 
   						## 建立一個本地端的master 分枝,並與遠端origin/master連結
   
   git pull 				## 抓取遠端master內容,最後應該要顯示 Already up-to-date.
   
   git branch -d master2 	## 刪除master2分枝
   

更改blog 標題...等設定

所有設定皆包含在以下檔案了 http://octopress.org/docs/configuring/

    _config.yml       # Main config (Jekyll's settings)
    Rakefile          # Configs for deployment
    config.rb         # Compass config
    config.ru         # Rack config
  • _config.yml
  • Main Configs
   url:                # For rewriting urls for RSS, etc
   title:              # Used in the header and title tags
   subtitle:           # A description used in the header
   author:             # Your name, for RSS, Copyright, Metadata
   simple_search:      # Search engine for simple site search
   description:        # A default meta description for your site
   date_format:        # Format dates using Ruby's date strftime syntax
   subscribe_rss:      # Url for your blog's feed, defauts to /atom.xml
   subscribe_email:    # Url to subscribe by email (service required)
   category_feeds:     # Enable per category RSS feeds (defaults to false in 2.1)
   email:              # Email address for the RSS feed if you want it.
  • Jekyll & Plugins
   root:               # Mapping for relative urls (default: /)
   permalink:          # Permalink structure for blog posts
   source:             # Directory for site source files
   destination:        # Directory for generated site files
   plugins:            # Directory for Jekyll plugins
   code_dir:           # Directory for code snippets (for include_code plugin)
   category_dir:       # Directory for generated blog category pages

   pygments:           # Toggle python pygments syntax highlighting
   paginate:           # Posts per page on the blog index
   pagination_dir:     # Directory base for pagination URLs eg. /blog/page/2/
   recent_posts:       # Number of recent posts to appear in the sidebar

   default_asides:     # Configure what shows up in the sidebar and in what order
   blog_index_asides:  # Optional sidebar config for blog index page
   post_asides:        # Optional sidebar config for post layout
   page_asides:        # Optional sidebar config for page layout
  • 3rd Party Settings
   Github - List your github repositories in the sidebar
   Twitter - Add a button for sharing of posts and pages on Twitter
   Google Plus One - Setup sharing for posts and pages on Google's plus one network.
   Pinboard - Share your recent Pinboard bookmarks in the sidebar.
   Delicious - Share your recent Delicious bookmarks in the sidebar.
   Disqus Comments - Add your disqus short name to enable disqus comments on your site.
   Google Analytics - Add your tracking id to enable Google Analytics tracking for your site.
   Facebook - Add a Facebook like button

Docker for windows

Getting Started

Docker Command

Docker commands

docker ps  							#List containers
docker stop [container_name] 		#Stop a running container

Engr.Cat的學習清單

書名 / 進度:

待讀清單

###BIOS

###Embedded

###OS

###Assembly

###C Library

  • The Red Hat newlib C Library
  • 有OS System Call 的C 語言實作,在標準C lib 中會呼叫的OS System call,如果沒有OS 就要自己實作

###Data Structure & Algorithm

###Design Pattern

###Hack

###Agile Develop

###Software Engineer

##課程

##練習題庫

##討論區

##英文學習

##工具

  • codepad is an online compiler/interpreter, and a simple collaboration tool.
    • 線上編譯執行工具,可以將執行結果分享給別人
  • QEMU ON WINDOWS
    • qemu 虛擬機器,可模擬 x86,x86-64,ARM,SPARC 32 and 64,PowerPC,MIPS 等平台
  • CMake
    • CMake is used to control the software compilation process using simple platform and compiler independent configuration files, and generate native makefiles and workspaces that can be used in the compiler environment of your choice.
  • MinGW-w64 or MinGW-builds
    • The mingw-w64 project is a complete runtime environment for gcc to support binaries native to Windows 64-bit and 32-bit operating systems.
  • http://www.compileonline.com/
    • Compile and Execute your favorite programming languages online

##文件

已讀清單

  • test1
  • test2

Engr.Cat的工具清單

文字編輯器

Notepad++

檔案比較工具

Open Source

  • Meld
  • KDiff3
  • diff-ext
    • 這是在檔案總管新增compare右鍵選單的套件,類似Beyond Compare 可以記憶選擇的檔案,再跟別的視窗的檔案進行比較,也可以3-way compare

Close Source

樂譜編輯

  • VexFlow
  • HTML5 瀏覽器即時Render 樂譜

截圖軟體

  • Snipaste
  • 一個截圖、貼圖在螢幕上的工具

OS image

Coding Tools

OS 重灌

Chocolatey

  • 安裝Chocolatey
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
choco install conemu
choco install ethanbrown.conemuconfig
choco install sourcetree
choco install notepadplusplus.install

#linux shell基本操作 Unix, Linux Commands

##安裝套件

sudo apt-get install tree 			#安裝tree (列出目錄的樹狀圖)
sudo apt-get install mtd-tools		#安裝mtd-tools ( 操作character device 的flash )

##系統操作

  • 重新啟動
reboot								#重新啟動(/sbin/reboot)

##訊息

  • display kernel message (in kernel buffer)
dmesg               			# 印出所有kernel message
dmesg -c            			# 印出所有kernel message, 並清空message buffer
cat /var/log/messages			# 印出所有kernel message, dmesg 其實是show這個檔案
tail -f /var/log/messages		# 印出kernel message 的尾端,並同步更新內容
  • 顯示Kernel版本
uname -a						# -a: 印出所有系統資訊
  • 顯示Driver Module 訊息
modinfo hello.ko				# 顯示hello.ko 的info

##裝置

  • 列出所有裝置 bus dev
cd /sys
ls
  • 列出所有裝置之 major/minor number
cd /sys/dev/char/   # 到character裝置資料夾下
ls                  # 列出所有裝置之major/minor
ls -lt              # -l: 列出所有檔案詳細資訊, -t:按修改時間排序
ls -l /dev/myLED*   # 列出名稱包含/dev/myLED 的裝置
ls -l 200:0         # 列出major:minor為200:0 的裝置
  • 載入及移除Driver
insmod xxx.ko       # 載入xxx driver module
rmmod xxx           # 卸載 xxx driver module
lsmod               # 列出所有載入的driver module
  • 建立device node
mknod /dev/myLED0 c 200 0
# mknod __file_name__ __deivce_type__ __major_mun__ __minor_num__
# __file_name__  : /dev/xxx
# __deivce_type__: c=caracter, b=block
# __major_mun__  : 
# __minor_num__  :
  • 移除device node
rm -f /dev/myLED*   #移除包含/dev/myLED 的裝置節點
  • 控制device
echo 1 > /dev/myLED0    #output 1 到 myLED0
  • 使用sysfs控制device
cd /sys/class/gpio      #到sys 下的gpio目錄
echo 22 > export        #產生gpio22 目錄
cd gpio22               #到 gpio22目錄
echo out > direction    #設定direction 為out
echo 1 > value          #設定value 為 1
cd /sys/class/gpio
echo 24 > export
cd gpio24
echo in > direction					#設定input
while true; do cat value; done;		#迴圈用cat 讀取value的值
  • 列出platform device
ls -l /sys/devices/platform			# 列出所有已註冊的platform device

Interrupt

  • 列出所有Interrupt
cat /proc/interrupts

##程序(Process)

  • 列出現在所有程序
ps aux
  • trace system call 的流程
stace ./test 						#對test 執行檔 做trace

搜尋

  • 搜尋檔案中符合的樣式
grep [options] [pattern] [filepath]
ex:
grep -rn completion ./
		# -r: 遞迴搜尋, -n: 顯示行號
		# 在目前資料夾(./)底下遞迴搜尋所有檔案中包含 "completion" 字串的內容,並顯示行號

檔案系統

mount						#列出所有掛載的檔案系統
tree 						#列出目錄樹狀結構
cat /proc/filesystems		#列出系統支援的檔案系統

##檔案操作

  • 修改檔案權限
chmod +x ./build.sh			#將build.sh 加上執行(execute, X)權限
  • 讀寫檔案RAW值
dd if=/dev/zero of=eeprom count=256		#在eeprom寫入256 bytes 個零(特殊檔案/dev/zero 會回傳0)
								     		#if: input file, of: output file
  • 二進位操作
hexdump /dev/mtd0				#列出/dev/mtd0 的二進位內容
hexdump /dev/mtd0 | head		#列出/dev/mtd0 的二進位內容(前10行)
hexedit eeprom					#編輯eeprom 的二進位值
  • flash 操作(character device)
flash_eraseall	/dev/mtd0		# 清除/dev/mtd0 整顆flash 
flashcp -v /bin/ls /dev/mtd0   	# 複製 /bin/ls (二進位檔)到 /dev/mtd0 (flash)

##開機載入

vi /etc/init.d/rcS				# 在/etc/init.d/rcS 新增需要開機執行的指令
  								# 可以mknod 新增一個device node 或
  								# mount 一個檔案系統...等
vi /etc/fstab					# 在/etc/fstab 新增需要開機掛載的filesystem

#vi 基本操作 vi指令說明(完整版) vi指令說明(簡易版)

##開檔

vi xxx

##編輯

  • 進入編輯模式
  a   (append)在游標之後加入資料
  i   (insert)在游標之前加入資料
  o   (open)在游標下方新增一行加入資料
  • 離開編輯模式
  <ESC>   結束輸入模式
  • 存檔
1. 按 <ESC>
2. 輸入 :w
3. 按 <enter>

##關閉檔案

  • 保存修改
1. 按 <ESC>
2. 輸入 :wq
3. 按 <enter>
  • 捨棄修改
1. 按 <ESC>
2. 輸入 :q!
3. 按 <Enter>

##視窗的移動

<Ctrl><f>       視窗往下捲一頁。
<Ctrl><b>       視窗往上捲一頁。

<Ctrl><e>       視窗往下捲一行。
<Ctrl><y>       視窗往上捲一行。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment