顯示具有 linux 標籤的文章。 顯示所有文章
顯示具有 linux 標籤的文章。 顯示所有文章

2011年9月8日 星期四

timer using msleep

最近在改之前寫的slic driver,在送DTMF tone的時候會發生crash,如下:

To send DTMF CID sequence [A11111CR]
POL_FORWARD
getOffhook = 0
Freq1 : 13990
Freq2 : 4657
BUG: scheduling while atomic: ash/0x00000100/2020
Call Trace:
[<800074cc>] dump_stack+0x8/0x34
[<80219a04>] schedule+0x778/0x920
[<8021a7c4>] schedule_timeout+0x70/0xdc
[<80030a18>] msleep+0x24/0x34
[] playDtmfTone+0x148/0x6a4 [slic3217x]
[] playDtmfTone+0x598/0x6a4 [slic3217x]


看來root cause是因為在timer中用了msleep

造成它reschedule就crash

解決方式就是透過將timer的call時間拉長
讓Oscillators播放時間p_cid->dtmf_on_ms拉長一點

init_timer(&cid_dtmf_timer);
cid_dtmf_timer.function = cid_dtmf_do_timer;
cid_dtmf_timer.expires = jiffies + ms2jiffies(p_cid->dtmf_on_ms);
add_timer(&cid_dtmf_timer);


才不會造成dtmf signal lost

2010年9月15日 星期三

取得 wifi parameters for linux kernel

想抓取wifi的資訊可利用linux kernel的struct netdev
所提供的struct iw_handler_def wireless_handlers來拿取
這是透過wireless_handlers內有個standard的指標函數,
可提供wireless device driver實作,
因此我們可透過standard指標函數來拿取wireless相關資訊

struct net_device
{
...
const struct iw_handler_def * wireless_handlers;
...
}


struct iw_handler_def
{
...
/* Array of handlers for standard ioctls
* We will call dev->wireless_handlers->standard[ioctl - SIOCSIWCOMMIT]
*/
const iw_handler * standard;
...
}


typedef int (*iw_handler)(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra);


以zd1211rw driver為例:

#define WX(x) [(x)-SIOCIWFIRST]

static const iw_handler zd_standard_iw_handlers[] = {
WX(SIOCGIWNAME) = iw_get_name,
WX(SIOCGIWNICKN) = iw_get_nick,
WX(SIOCSIWFREQ) = iw_set_freq,
WX(SIOCGIWFREQ) = iw_get_freq,
...
};


可以看到這些Wireless Identification的定義:

/* Wireless Identification */
#define SIOCSIWCOMMIT 0x8B00
#define SIOCGIWNAME 0x8B01

#define SIOCSIWNWID 0x8B02 /* set network id (pre-802.11) */
#define SIOCGIWNWID 0x8B03 /* get network id (the cell) */
#define SIOCSIWFREQ 0x8B04 /* set channel/frequency (Hz) */
#define SIOCGIWFREQ 0x8B05 /* get channel/frequency (Hz) */
...
wireless.h:335:#define SIOCIWFIRSTPRIV 0x8BE0
wireless.h:351:#define SIOCIWFIRST 0x8B00


倘若我們想抓取frequency(channel) of current link ,

可直接call function
net_dev -> wireless_handlers ->
standard[SIOCGIWFREQ - SIOCSIWCOMMIT](net_dev, NULL, (void *) & my_freq, NULL);


然後透過my_freq.m就能抓取現在的freq

struct iw_freq my_freq;

struct iw_freq
{
__s32 m; /* Mantissa */
__s16 e; /* Exponent */
__u8 i; /* List index (when in range struct) */
__u8 flags; /* Flags (fixed/auto) */
};


進而推出wifi的rssi

2010年1月28日 星期四

Add new system call

kernel版本:2.6.33-rc2

新增自行定義的system call步驟如下:

1. edit arch/x86/kernel/syscall_table_32.S, add

.long sys_mysystemcall /* 338 */

2. edit include/asm-i386/unistd.h, add

#define __NR_mysystemcall 338

3. create new file, arch/x86/kernel/systemcall.c
(defined filename yourself)

#include <linux/linkage.h>
#include <linux/kernel.h>

asmlinkage int sys_mysystemcall(void)
{
printk("mysystemcall\n");
return 0;
}


4. edit arch/x86/kernel/Makefile, add

obj-y += systemcall.o


5. compiler kernel

root@shulong-desktop:/home/shulong/linux-2.6.33-rc2# make clean && make


6. writing code for user mode, create new file test.c

#include <linux/unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>

#define __NR_mysystemcall 338
#define mysystemcall() syscall(__NR_mysystemcall);

int main ()
{
mysystemcall();
return 0;
}


7. compiler test.c

root@shulong-desktop:~# gcc -Wall test.c -o systemcall

8. execute systemcall

root@shulong-desktop:~# ./systemcall
[ 39.289669] mysystemcall


就可順利加入自行定義的system call。

2009年10月6日 星期二

Meld : Diff and merge tool

比較和合併code的工具,在windows上有[Araxis Merge],但它並非open source software,因此有[WinMerge]可以替代,而在linux上比較常見的是[KDiff3]和[Meld]。

而我最常用的是Meld,它的操作很容易就可上手。

2009年10月2日 星期五

Coding tips, Vim顯示當前行

輸入":set cursorline".
或輸入":set cul".

取消當前行:
輸入":set no cursorline".
或輸入":set no cul"

2009年9月28日 星期一

gcc: warnings being treated as errors

在Ubuntu 9.04,編譯linux kernel for mips時出現了這個問題

gcc: warnings being treated as errors
scripts/kconfig/conf.c:104: error: ignoring return value of 'fgets', declared with attribute warn_unused_result
...

原來是在./src/Makefile的HOSTCFLAGS variables加了-Werror...
把它去掉之後,就能編過了...

2008年11月7日 星期五

Trace code tool

以前在Trace OpenSouce code時,常直接用文字編輯器,感覺很不方便,還要自己找檔案。最近發現一套很好用trace code的工具[GNU Global],它能很神奇的將程式碼變成網頁,而且產生方式超簡單的。

產生網頁的方法:

1. 進入原始碼的目錄下

$ cd ~/speech

2. 執行htags

$ htags -g -F
-g 先執行 gtags
-F 代表要將網頁切成多個Frame

3. 原始碼目錄下就會產生一個叫HTML的目錄

就可以直接用Browser開啟index.html,如下圖所示。



接下來看code就很快了....

2008年8月27日 星期三

Qemu for ARM System emulator

[Qemu]是個相當不錯的模擬器,它不只可以模擬x86,還可模擬arm。最近找了很多相關的資料,發現目前已經有很多人寫了不錯的教學,而且qemu支援的arm平台[ARM System emulator]也相當多。但重點是qemu並非所有arm的平台都支援,所以或許可以找找patch或自己試著修改看看,才能符合自己的平台。

[OPENCSL]這個網站相當不錯,初學者可以很快做出一個"ARM Integrator"(ARMB26EJ-S的架構)的模擬器。另外是OpenMoko[Neo1973],目前已有修改過後的qemu,跑出來就跟真的環境一樣。然後[Linux on Palm 5]也有修改後的模擬器,都可以實際跑起來。

有興趣的朋友,可以玩玩看,我覺得還滿有趣的。

2008年2月20日 星期三

空閒時間看Linux kernel原始碼

看Linux kernel的原始碼是一種很有趣的事情,可以看到很多用C寫奇怪的作法,真很有趣,如jserv所提到的[C 語言的 trigraph/digraph]一文。

只是因為只有空閒時間才能看,所以都只能看片段,沒辦法一層一層的往下找"真相",只有大約知道API怎麼CALL、用什麼樣的結構和演算法等等。

不過令人驚訝的是Linux kernel有超完整的架構,讓我這個初學者超佩服的,這時才知道自己的渺小。

未來,我會找時間來整理一些自己看kernel的想法...

2007年11月27日 星期二

Poring Linux Kernel 2.6 for DIMMPC 520i (Part 1)

最近終於找到時間來Porting板子囉!!

測試完IDE介面,發現可以接硬碟和光碟機...


於是很有趣的將之前收到的ubuntu 7.10放進去跑跑看,結果:

天啊,有畫面也可以跑耶!!但...

kernel還是跑不起來,也只好乖乖porting了...><"

2007年11月18日 星期日

小筆電裝Ubuntu 7.10

今天終於跟裝了兩年多的gentoo說byebye了,
一直都想要換,畢竟我的小筆電速度不夠快,
總不能每裝一套package就一直compiler...吧!!

也剛好昨天回家,
收到數天前到[ShipIt]所申請的光碟片,
超cool的,還有貼紙...

安裝上真的比gentoo方便太多,
在加上用[lazybuntu]來安裝想要的軟體,真的不到一小時就全部裝完囉...

2007年11月11日 星期日

ToolChain for DIMM-PC

由於x86的toolchain建立的文件相當少,
於是使用[crosstool]來建立toolchain可說是相當方便...
[更新]
$ svn co http://crosstool.googlecode.com/svn/trunk/src crosstool
$ cd crosstool
$ cp demo-i686.sh demo-i386.sh
$ vi demo-i386.sh
將eval `cat i686.dat gcc-4.1.0-glibc-2.3.6-tls.dat` sh all.sh --notest
修改成#eval `cat i686.dat gcc-4.1.0-glibc-2.3.6-tls.dat` sh all.sh --notest
將eval `cat i686.dat gcc-4.1.0-glibc-2.3.6.dat` sh all.sh --notest
修改成#eval `cat i386.dat gcc-4.1.0-glibc-2.3.6.dat` sh all.sh --notest

$ vi i386.dat
TARGET=i486-dimmpc-linux-gnu
TARGET_CFLAGS="-O"
$ sudo mkdir /opt/crosstool
$ sudo chown $USER /opt/crosstool
$ sh demo-i386.sh
...
Cross-toolchain build complete. Result in /opt/crosstool/gcc-4.1.0-glibc-2.3.6/i486-dimmpc-linux-gnu.
+ exit 0
+ cd /home/shulong/crosstool
+ sh testhello.sh
+ cd /opt/crosstool/gcc-4.1.0-glibc-2.3.6/i486-dimmpc-linux-gnu
+ test '!' -d tmp
+ mkdir tmp
+ cd tmp
+ test x '!=' x
+ cat
...
+ echo testhello: C compiler can in fact build a trivial program.
testhello: C compiler can in fact build a trivial program.
+ test '' = 1
+ test '' = 1
+ test '' = 1
+ test 1 = ''
+ echo Done.
Done.

看到這個msg就代表成功啦!!

toolchain的路徑在:
/opt/crosstool/gcc-4.1.0-glibc-2.3.6/i486-dimmpc-linux-gnu/

感謝jserv大提供的方向...

2007年8月3日 星期五

Taiwan Linux Forum

一年一度的台灣Linux論壇又來了,
這次我的感覺是辦的比去年差,
雖然請了幾位國外Open Source很厲害的講者,
但講都東西不是太淺...
不然就是沒什麼技術性的東西...
感覺沒學到什麼東西...
只有一個心得,英文聽力要加油...><"
...
這次參與的議程有:

8/1, 早上
Overview of the Linux Market Place and the Technical Development Community, Jim Zemlin, Linux Foundation

心得:
大部份的英文都聽的懂,有一些內容很不錯,只不過是有點介紹性的感覺...

8/1, 下午
Real Time Linux, Linux Kernel Device Drivers and Embedded Linux, Theodore Y. "Ted" Tso, Linux Kernel Developer

心得:
因為下午2:00是我想睡的時候,不過我還是努力的聽(中途不小心...),不過好像只是很簡單的介紹,不夠深入...非常可惜,加上英文講的太快(腔調有點怪怪的)...,聽完只有一個想法,回去開始加強英文聽力><"
...
Open Solaris驅動程式開發, 李宗虞

心得:
講的內容很好,只不過是因為是北京工程師的關係,口語上出現一些大陸用法...><"
什麼源碼、硬盤...
...
印表機在Linux系統中之相容性探討, 林靖翔

8/2, 早上
避免GPL地雷:A Check List, 葉平博士
來自由/開放源碼的警告信, 葛冬梅經理


心得:
講的內容很好,讓人很容易了解GPL,
只不過真的有一些情況,企業要用時真的要小心

8/2, 下午
使用Fedora 7 做OLPC Live-cd, Pake

心得:
很技術性,講的非常好,很想動手玩玩看...
很想弄一台百元電腦...只不過要175元美金><"
...
802.11無線網路封包監測及分析軟體之研製
...
應用感測技術之智慧型環境感知緊急救護系統之設計與實作
...
運用多階層網格技術於2D和3D外形中的呈現
...
自由軟體作業系統核心客製化工具組之研製

心得:
雖然說只是簡略說明做了那些東西,但我可以了解教授所說的...很滿有趣的
...
無線感測網路技術應用於旱災預警與監測通報系統之設計與實作(II)
..
支援跨語言語料收集之維基百科外覆程式
...
小心!間諜就在你身邊! 如何增加LAMP安全-現場Demo, Outian

心得:
超厲害的HACKER DEMO,看的很Shock,
以後自己管SERVER真的要小心...
...
粗體是表示我自己覺得不錯的議程...

另外,大部份的簡報都可以抓的到了,
在[自由軟體入口網站首頁]左邊的部份...

總之,以後可能也不會想去了吧...
不但是太遠了...而且沒有比今年的OSDC精彩~~

2007年7月19日 星期四

Robot need a RTOS,but Linux maybe Realtime?

Reference:
Jserv前輩在OSDC.tw所發表的RT nanokernel for Embedded Linux議題中

Is Linux Realtime?
過去的答案:
No,其原因:
Monolithic Kernel、Non Preemptible、Resource Lock、Priority Scheduling

現在(Kernel 2.6)的答案:Maybe Yes
Old: No Kernel Preemption
Execution in kernel mode interrupted only by explicit、yields, sleeps, and IRQ’s

New: Kernel May Be Preempted
New process may be swapped in after servicing an interrupt

但「May Be」,問題點:
相較於典型RTOS來說,還是太沈重
不具備Hard-Realtime能力


但Robot need a RTOS
所以...
我的目標將先往RTOS的方向走,可能要建立一個Realtime Linux System...
Linux如何Realtime?
這也是我最近要達成的方向...

2007年7月14日 星期六

Porting Kernel 2.6 for DIMM-PC

純粹好玩來Porting Kernel 2.6 for DIMM-PC
大約的步驟...(準備開始)
...
Step1: Collecting about Hardware Information

CPU: AMD™ Elan SC520 133MHz

Memory: 32768k(32 MByte) DRAM, 32 MByte IDE compatible Flash Disk

ide: Assuming 33MHz system bus speed for PIO modes; override with idebus=xx
hda: SanDisk SDC1-32, CFA DISK drive

VGA Board: Topro TP6508IQ video controller
(VGA Graphics for CRT and flat displays)

Ethernet: Crystal LAN™ CS8900 Ethernet Controller(cs8900 rev J found at 0x300 [Cirrus EEPROM])

ttyS00 at 0x03f8 (irq = 4) is a 16550A
ttyS01 at 0x02f8 (irq = 3) is a 16550A
...
Step2: Allocation

Bootloader: lilo or u-Boot
(Reference jserv's blog [探索 Linux bootloader 的佳作])
Linux Kernel: 2.6.20 (or newest)
(Realtime Embedded Linux, RTOS)

Root File System: BusyBox + uClibc(or eglibc) + initscripts...
LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
TERM=vt100
SHELL=/bin/ash
...
Step3: Create Image file
...
Step4: Emulate, Tesing
...
Testing. If not ok, back to Step 2
...
Step5: burn to DIMM-PC Flash ROM

2007年7月10日 星期二

Where Can I get Memory Image context?

明明ml30j53.img的檔案系統就是minix~~~
...
mitelinux:/# cat /proc/mounts
rootfs / rootfs rw 0 0
/dev/root / minix ro 0 0
none /proc proc rw 0 0
none /dev/pts devpts rw 0 0
/dev/ram /mnt/ram minix rw 0 0

mitelinux:/# cat /etc/fstab
/dev/hda1 / minix defaults 1 1
none /proc proc defaults 0 0
none /dev/pts devpts gid=5,mode=620 0 0

mitelinux:/# df -h
Filesystem Size Used Available Use% Mounted on
/dev/hda1 30.2M 10.8M 19.3M 36% //dev/ram 502.0k 40.0k 462.0k 8% /mnt/ram


但我怎麼mount就是沒辦法~~~
Where Can I get Memory Image context?
#mount -t minix ml30j53.img rootfs/ -o loop
功力還不夠啊~~~誰能幫幫我~~思考中~~

[更新]
錯錯不是minix,我還在研究到底是什麼??
csl@csl-desktop:~$ file ml30j53.img
ml30j53.img: x86 boot sector, LInux i386 boot LOader; partition 1: ID=0x83, starthead 1, startsector 63, 62433 sectors, extended partition table (last)\011
看起來像是在Memory Image中的大合體??好像是把所有東西放在一起??
但要放在一起,難道Memory Image沒有filesystem嗎?
...
原來
csl@csl-desktop:~$ qemu-img info ml30j53.img
image: ml30j53.img
file format: raw
virtual size: 31M (32047104 bytes)
disk size: 31M

它是一個raw file format,
/*
raw
Raw disk image format (default). This format has the advantage of being simple and easily exportable to all other emulators. If your file system supports holes (for example in ext2 or ext3 on Linux or NTFS on Windows), then only the written sectors will reserve space. Use qemu-img info to know the real size used by the image or ls -ls on Unix/Linux.
*/
難怪怎麼mount都沒辦法...
還要再努力才行啊~~~
[/更新]

2007年7月6日 星期五

Oh~My God

oh~My God~~I get console in DIMM-PC/520-I
弄了半天~~原來那麼容易取得~~
要不是把VGA接上Screen,
看到DIMM-PC竟然有BIOS的管理介面(跟電腦差不多),
看到DIMM-PC竟然有跟電腦那麼像,
還不用風扇(超強的),
難怪BOSS說這個東東會比ARM強,終於可以體會出來了...
真是說不出來的高興~~

Making directories: [ OK ]
Setting system clock: [ OK ]
MAC address of eth0: 00:e0:4b:04:01:e7
tcpdump: listening on eth0
Configuring eth0: [ OK ]
Configuring lo: [ OK ]
Starting system logger: [ OK ]
Starting kernel logger: [ OK ]
Starting xinetd: [ OK ]
Generating main crontab: [ OK ]
Starting crond: [ OK ]
Starting sshd: [ OK ]

Please press Enter to activate this console.

miteLINUX release 3.0 (Woody)
mitelinux login: root
Password:


BusyBox v1.00-pre7 (2004.02.04-18:02+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

mitelinux:/root#


接下來的工作,就是~~~
改MiteLinux裡面,會有時無法進系統的情況,
還有一些我想玩玩的東西,像kernel變2.6啦...><"
努力吧~~
目標是七月底把這塊板子中的Linux,修改成我要做的東東~

2007年7月4日 星期三

miteLINUX for DIMM-PC



我們的實驗室買了一塊開發板(Kontron DIMM-PC/520-I + JUMPtec),老實說我從來沒聽過這塊板子,不過聽老闆說這塊開發板比arm還強,以後可以拿來用在機器人的核心系統。


規格:
* AMD ELAN SC520 CPU with 133MHz
* 32 Mbyte DRAM and
* 32 MB IDE Flashdisk, IDE Interface
* Floppy, Real Time Clock,
* EEPROM for CMOS-Data backup 5V single voltage,

今天我要將Linux放入,所以要利用JRC+RS232跳線來將img檔寫入flash中,結果很順利就成功。但目前有個問題是拿不到console,今天真的累了~明天在想辦法好了^^"

補充:
http://www.mite.cz/dimmpc/dimmpctable-en.html
http://www.mite.cz/softlinux-en/softlinux-en.html
http://www.amd.com/epd/linux/index.html
目前還沒拿到console,加油中~~