Showing posts with label embedded system. Show all posts
Showing posts with label embedded system. Show all posts

Wednesday, June 30, 2010

S3C2440 - Kernel - Build Code

最近再用skyeye, 這是一套可以 simulate S3C2440 的 simulator. 之前是用 skyeye-1.26, 後來才發現沒有支援 S3C2440, 雖然可以成功在上面跑, 但是沒有辦法掛上flash. 只好 upgrade 到 skyeye-1.30.

可是我始終build 不起來這個版本, 也困擾了好幾個晚上在這邊. 索性找找找, 找到要在 aclocal.m4 做一些修正, 其實是增加幾個定義, e.g. PKG_PROG_PKG_CONFIG ... etc.

於是本篇就來介紹另外一種更方面於 makefile 的 build code 方法.

傳統 build code 都要寫上一堆複雜的 makefile, 而且要 follow rule. 但是這種方法碰到大 project 會很麻煩. 於是在 linux 上有了一些工具可以輔助開發. e.g. Autoscan, aclocal, autoconf, automake

至於使用方法以下是轉錄下面的網站:
Automake 所產生的 Makefile 除了可以做到程式的編譯和連結,也已經把如何產生程式檔(如 manual page, info 檔及 dvi 檔) 的動作,還有把原始程式包裝起來以供散 的動作都考慮進去了,所以原始程式所存放的目錄架構最好符合 GNU 的標準慣例,接下來我拿hello.c 來做為例子。

在工作目錄下建立一個新的子目錄 ``devel'',再在 devel 下建立一個``hello'' 的子目錄,這個目錄將作為我們存放 hello 這個程式及其相關檔案的地方:

% mkdir devel
% cd devel
% mkdir hello
% cd hello

用編輯器寫個 hello.c 檔,
#include stdio.h
int main(int argc, char** argv)
{
printf(``Hello, GNU! '');
return 0;
}

接下來就要用 Autoconf 及 Automake 來幫我們產生 Makefile 檔了,

1. 用 autoscan 產生一個 configure.in 的雛型,執行 autoscan 後會產生一個configure.scan 的檔案,我們可以用它做為configure.in檔的藍本。

% autoscan
% ls
configure.scan hello.c

2. 編輯 configure.scan 檔,如下所示,並且把它的檔名改成configure.in
dnl Process this file with autoconf to produce a con figure script.
AC_INIT(hello.c)
AM_INIT_AUTOMAKE(hello, 1.0)
dnl Checks for programs.
AC_PROG_CC
dnl Checks for libraries.
dnl Checks for header files.
dnl Checks for typedefs, structures, and compiler ch aracteristics.
dnl Checks for library functions.
AC_OUTPUT(Makefile)

3. 執行 aclocal 和 autoconf ,分別會產生 aclocal.m4 及 configure 兩個檔案
% aclocal
% autoconf
% ls
aclocal.m4 configure configure.in hello.c

4. 編輯 Makefile.am 檔,內容如下
AUTOMAKE_OPTIONS= foreign
bin_PROGRAMS= hello
hello_SOURCES= hello.c

5. 執行 automake --add-missing ,Automake 會根據 Makefile.am 檔產生一些檔案,包含最重要的 Makefile.in
% automake --add-missing
automake: configure.in: installing `./install-sh'
automake: configure.in: installing `./mkinstalldirs'
automake: configure.in: installing `./missing'

6. 最後執行 ./configure ,
% ./configure
creating cache ./config.cache
checking for a BSD compatible install... /usr/bin/in stall -c
checking whether build environment is sane... yes
checking whether make sets ${MAKE}... yes
checking for working aclocal... found
checking for working autoconf... found
checking for working automake... found
checking for working autoheader... found
checking for working makeinfo... found
checking for gcc... gcc
checking whether the C compiler (gcc ) works... yes
checking whether the C compiler (gcc ) is a cross-co mpiler... no
checking whether we are using GNU C... yes
checking whether gcc accepts -g... yes
updating cache ./config.cache
creating ./config.status
creating Makefile

現在你的目錄下已經產生了一個 Makefile 檔,下個 ``make'' 指令就可以開始編譯 hello.c 成執行檔,執行 ./hello 和 GNU 打聲招呼吧!

% make
gcc -DPACKAGE="hello" -DVERSION="1.0" -I. -I. -g -O2 -c he llo.c
gcc -g -O2 -o hello hello.o
% ./hello
Hello! GNU!


轉自以下這篇文章

Wednesday, June 16, 2010

S3C2440 - Kernel - Start Kernel -1

上一篇介紹了在 Start Kernel 的幾個步驟, 這邊會詳細介紹每個步驟的目的.

(1) lock_kernel();
第一件要做的事情就是先 lock kernel.
static inline void lock_kernel(void)
{
if (!++current->lock_depth) // task_struct /include/linux/sched.h, initialized by fork.c
spin_lock(&kernel_flag);
}
current = get_current( ) , 也就是取得目前 process 的 task_struct*

kernel_flag 是一個 kernel local spin lock. 所有的 process 獲得這個 kernel local spin lock 才可以存取 kernel resource.

process 的 lock_depth 初始值是 -1. 在 fork.c 中設置. 當 lock_depth >= 0 時候, process 才可以得到 kernel local spin lock.

在 kernel 有很多種方法可以作為 kernel control path 的 synchronous. Kernel control path 可以當成是一連串的執行命令. Spin lock 是最常使用到的, 而且也適用於 all cpu.

(2) Print linux version
printk(linux_banner); // Linux version 2.4.18-rmk7-pxa1 (harlan@harlan) (gcc version 2.95.3 20010315 (release)) #13 日 6月 3 08:02:23 CST 2007

這其實是列印 linux version. 至於 printk 內容就請自己去看了.


Saturday, May 8, 2010

S3C2440 - Kernel - Booting from zImage

最近開始陸陸續續 trace Linux Kernel. 從最早的 boot loader 開始, 到現在的 kernel. 也正因為如此開始找了 simulator, 因為我本來的一台 pc 掛點了, 所幸 cygwin 強大的幫忙之下, 終於可以在 windows 上面 build 出可以相容的 linux kernel 了. 可是目前 debug 和 simulator 還是有點問題. 所以就一邊作一邊 trace code 了.

kernel 的起始點有分兩種, 一種是沒有壓縮過的 vmlinux, 另外一種就是 zImage 了. 兩者差別在於是否有經過 gunzip 壓縮了. 以下會介紹 zImage 的 booting 方式.

起始點在 linux/arch/arm/boot/compressed/head.S ( 結尾是大寫的 S, 差異性這裡就不多說了 ). 因為是 assembly code, 所以有些指令常常需要翻來翻去才能理解.

這隻 head.S 大致上要作的事情就是檢查傳進來的參數, 檢查是否要作 reloactor 動作 ( 因為要為了跨平台 ), 把 cache 打開作解壓縮動作. 最後關掉 Cache / MMU 跳到 kernel 進入點也就是第一種做法的進入點.

說的倒是很簡單, 可是暫存器精簡到不行, 建議還是拿simulator 實際跑跑看才會比較知道為何要設定這些 register. 或是拿張紙筆紀錄一下也是一種方法.

Tuesday, April 15, 2008

89C51硬體線路

本篇會介紹89C51的記憶體控制信號,包含了ALE, PSEN, RD和WR
  1. 30 pin 是ALE ( Address Latch Enable ), 位址閂鎖致能, 一般會搭配74LS373使用以取出位址線A0-A7, 此信號頻率也是石英晶體的1/6
  2. 29 pin 是PSEN ( Program Store Enable ), 當使用外部 ROM 時, 這隻腳會輸出低電位.
  3. 16 pin 是RD ( Read Enable ), 讀取外部 RAM 時用到的
  4. 17 pin 是WR ( Write Enable ), 寫入外部 RAM 時會用到.

Thursday, March 20, 2008

S3C2440A Memory Map

S3C2440A的記憶體還真複雜,光是Bank的概念和NAND Flash或NOR Flash開機,我就搞了好幾天才理解為何會這樣。和X86不太一樣,ARM這顆RISC做的還真複雜,前天才將Clock搞懂要怎麼設和裡面原理,最近都要看記憶體了。