2009年2月15日星期日

用SKYEYE来模拟uClinux

2009/02/23
发现之前做的网络提速工作有问题,其实速度主要和skyeye模拟ARM指令有关,skyeye里面有两套模拟ARM指令的方法;一个是ARMul_Emulate32, 另一个是ARMul_Emulate32_dbct, 我有拜读过dbct的算法,打算从dbct入手看看为何我用skyeye模拟网络速度这么慢的问题,不过编译skyeye提示我的gcc不支持inline x86 asm. 查看skyeye README说需要gcc3.3 / gcc3.4,于是我上网下载并编译了gcc3.4, skyeye还是提示我的gcc3.4不支持inline x86 asm,今天写了一段x86 asm的代码在我Office的Fedora6下编译过了, 回家看看ubunut下的gcc能否编译过, 要是过的话, 看来skyeye在检查inline x86 asm这个特性上有问题.
int main(void)
{
int x = 10, y;

__asm ("movl %1, %%eax;"
"movl %%eax, %0;"
:"=r"(y) /* y is output operand */
:"r"(x) /* x is input operand */
:"%eax"); /* %eax is clobbered register */
printf("x=%d, y=%d\n", x, y);
return 0;
}
PS: 晚上发现我的ubuntu gcc果然支持inline x86 asm,是skyeye的check-x86-asm.sh检测代码有问题,直接exit 0绕过检测,顺利编译带有dbct的skyeye,初步感觉效率有一点点提高吧 :-)

2009/02/15
kernel/softirq.c : 367
+// Anders 2009_0215,raise rx & tx riq priority
+if ((nr == NET_RX_SOFTIRQ) || (nr == NET_TX_SOFTIRQ))
+ raise_softirq(nr);
sudo nice -n -20 skyeye -e linux 本来ping可以控制在1s内有echo了,telnet也进去了,可以重新来过又是不行了,昙花一现的成功 :-(

2009年2月2日星期一

一个MODULE引起的血汗

采用让模组直接编译到内核的方式来进行编译,但是文件中却define了MODULE,我掉进了同一条河里.

//Anders 2008_0526, we don't need this macro.
//For this macro I spend 4 hours on tracing why xxx_init_module function doesn't execute. :-(
//Anders 2009_0203, havn't update this for xxx's new driver.
//For this macro, I spend 2 hours again :-(
//#ifndef MODULE
//#define MODULE
//#endif

2009年1月30日星期五

[uClinux-dev mailing list] 摘录之 "如何驾驭uclinux-dist开发包?"

挺不错的一个帖子,告诉大家如何驾驭uClinux-dist这套开发包.用skyeye模拟硬件,无须任何实体硬件资源,适合初学者入门!

Message: 8
Date: Fri, 30 Jan 2009 22:02:42 +1000
From: Greg Ungerer <gerg@snapgear.com>
Subject: Re: [uClinux-dev] why no-mmu cannot support binfmt_aout.c
To: uClinux development list <uclinux-dev@uclinux.org>
Message-ID: <4982EC62.8020408@snapgear.com
>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

loody wrote:
>> What target did you use as your base for this?
>> (What I really want to know is what is set in the
>> config.arch file).
>>
>> Regards
>> Greg
> Dear Greg:
> I use GDB/armulator.
> attach the config and config.arch for your reference.
> Thanks for your help,

Here is what I did:

1. downloaded uClinux-dist-20080808.tar.gz
2. downloaded arm-linux-tools-20061213.tar.gz
3. mkdir user/hello
4. vi user/hello/hello.c and put in it:

int main()
{
printf("hello world\n");
}

5. vi user/hello/Makefile and put in it:

all: hello

romfs:
$(ROMFSINST) /bin/hello

clean:
-rm -f hello *.elf *.gdb *.o

6. vi user/Kconfig, adding in the "Miscellaneous Applications section:

config USER_HELLO_HELLO
bool "hello"

7. vi user/Makefile, adding in a line:

dir_$(CONFIG_USER_HELLO_HELLO) += hello

8. configured uClinux-dist to build "GDB/ARMulator" selecting to
use a linux-2.6.x kernel, and selected the new "hello" program
for inclusion as well

9. make
10. cd images
11. cp .
12. run "skyeye -e linux" and see:

Your elf file is little endian.
arch: arm
cpu info: armv3, arm7tdmi, 41007700, fff8ff00, 0
mach info: name at91, mach_init addr 0x4189a0
uart_mod:0, desc_in:, desc_out:, converter:
SKYEYE: use arm7100 mmu ops
Loaded ROM boot.rom
exec file "linux"'s format is elf32-little.
load section .text.head: addr = 0x01008000 size = 0x00000190.
load section .init: addr = 0x010081a0 size = 0x0000ee60.
load section .text: addr = 0x01017000 size = 0x000ce870.
not load section .rodata: addr = 0x010e6000 size = 0x00000000 .
not load section .pci_fixup: addr = 0x010e6000 size = 0x00000000 .
not load section .rio_route: addr = 0x010e6000 size = 0x00000000 .
not load section __ksymtab: addr = 0x010e6000 size = 0x00000000 .
not load section __ksymtab_gpl: addr = 0x010e6000 size = 0x00000000 .
not load section __ksymtab_unused: addr = 0x010e6000 size = 0x00000000 .
not load section __ksymtab_unused_gpl: addr = 0x010e6000 size =
0x00000000 .
not load section __ksymtab_gpl_future: addr = 0x010e6000 size =
0x00000000 .
not load section __kcrctab: addr = 0x010e6000 size = 0x00000000 .
not load section __kcrctab_gpl: addr = 0x010e6000 size = 0x00000000 .
not load section __kcrctab_unused: addr = 0x010e6000 size = 0x00000000 .
not load section __kcrctab_unused_gpl: addr = 0x010e6000 size =
0x00000000 .
not load section __kcrctab_gpl_future: addr = 0x010e6000 size =
0x00000000 .
load section __param: addr = 0x010e6000 size = 0x00001000.
load section .data: addr = 0x010e8000 size = 0x00009f98.
not load section .bss: addr = 0x010f1fa0 size = 0x00008f20 .
not load section .comment: addr = 0x00000000 size = 0x000013b0 .
call ARMul_InitSymTable,kernel filename is linux.
start addr is set to 0x01008000 by exec file.
Linux version 2.6.25-uc0 (gerg@goober) (gcc version 3.4.4) #2 Fri Jan 30
21:38:07 EST 2009
CPU: Atmel-AT91M40xxx [14000040] revision 0 (ARMvundefined/unknown),
cr=00000000
Machine: Atmel AT91 EB01
Built 1 zonelists in Zone order, mobility grouping off. Total pages: 4064
Kernel command line:
PID hash table entries: 64 (order: 6, 256 bytes)
console [ttyS0] enabled
Dentry cache hash table entries: 2048 (order: 1, 8192 bytes)
Inode-cache hash table entries: 1024 (order: 0, 4096 bytes)
Memory: 16MB = 16MB total
Memory: 15268KB available (832K code, 75K data, 60K init)
Mount-cache hash table entries: 512
io scheduler noop registered (default)
Atmel USART driver version 0.99
ttyS0 at 0xfffd0000 (irq = 2) is a builtin Atmel APB USART
ttyS1 at 0xfffcc000 (irq = 3) is a builtin Atmel APB USART
brd: module loaded
uclinux[mtd]: RAM probe address=0x1400000 size=0x103000
Creating 1 MTD partitions on "ROM":
0x00000000-0x00103000 : "ROMfs"
uclinux[mtd]: set ROMfs to be root filesystem
VFS: Mounted root (romfs filesystem) readonly.
Freeing init memory: 60K
Shell invoked to run file: /etc/rc
Command: hostname GDB-ARMulator
Command: /bin/expand /etc/ramfs.img /dev/ram0
Command: mount -t proc proc /proc
Command: mount -t ext2 /dev/ram0 /var
Command: mkdir /var/tmp
Command: mkdir /var/log
Command: mkdir /var/run
Command: mkdir /var/lock
Command: mkdir /var/empty
Command: cat /etc/motd
Welcome to
____ _ _
/ __| ||_|
_ _| | | | _ ____ _ _ _ _
| | | | | | || | _ \| | | |\ \/ /
| |_| | |__| || | | | | |_| |/ \
| ___\____|_||_|_| |_|\____|\_/\_/
| |
|_|

GDB/ARMulator support by <davidm@snapgear.com>
For further information check:
http://www.uclinux.org/

Execution Finished, Exiting

Sash command shell (version 1.1.1)
/>




13. from the command line I run "hello":

/> hello
hello world
/>


All seems to work...

Regards
Greg

--
Anders Remark:

//-----tools & package-----
http://ftp.snapgear.org/pub/snapgear/tools/arm-linux/
http://www.uclinux.org/uClinux/dist/uClinux-dist-20080808.tar.gz
//-----end of tools & package-----

//-----skyeye.conf-----
cpu: arm7tdmi
mach: at91
mem_bank: map=M, type=RW, addr=0x00000000, size=0x00004000
mem_bank: map=M, type=RW, addr=0x01000000, size=0x00400000
mem_bank: map=M, type=R, addr=0x01400000, size=0x00400000, file=boot.rom
mem_bank: map=M, type=RW, addr=0x02000000, size=0x00400000
mem_bank: map=M, type=RW, addr=0x02400000, size=0x00008000
mem_bank: map=M, type=RW, addr=0x04000000, size=0x00400000
mem_bank: map=I, type=RW, addr=0xf0000000, size=0x10000000
lcd: state=on
//-----end of skyeye.conf-----

2009年1月29日星期四

BASH练习之“目录轮回”

写了一个bash脚本当作练习内容,为bash添加了qu和hui命令.

qu "去"
hui "回"

anders@~#qu .tencent/
/home/anders /home/anders/.tencent/
anders@~/.tencent#qu qq
/home/anders /home/anders/.tencent/ /home/anders/.tencent/qq
anders@~/.tencent/qq#hui
anders@~/.tencent#hui
anders@~#

--------.bashrc-------
# anders bash exercise
declare -a FOLDER_ARRAY
export FOLDER_ARRAY
FOLDER_ARRAY[0]=$(pwd)

qu ()
{
dirname=$1

if [ $# -eq 0 ] || [ ! -d $1 ]; then
echo "usage:qu "
return
else
if [ ${dirname:0:1} != "/" ]; then
dirname=$(pwd)/$dirname
fi
FOLDER_ARRAY[${#FOLDER_ARRAY[@]}]=$dirname
cd $dirname
echo ${FOLDER_ARRAY[@]}
fi
}

hui ()
{
if [ ${#FOLDER_ARRAY[@]} -le 1 ]; then
echo "no back way"
return
else
unset FOLDER_ARRAY[$((${#FOLDER_ARRAY[@]}-1))]
cd ${FOLDER_ARRAY[$((${#FOLDER_ARRAY[@]}-1))]}
fi
}

2009年1月22日星期四

AP Hacking

[引言]

看着家里沉睡已久的AP成品, 突发奇想要玩玩里面的Linux, 可是更新完自己编译的系统后, AP就默默得睡着了,郁闷!只有一条路---把串口接出来!

[串口]

打开壳子发现了4个孔,貌似串口 TX RX GND VCC。产品都为了Cost Down所以串口部分都没做出来,需要自己加232转TTL的芯片才能让串口工作。

1. 华强北买串口公母转接头(方便串口转换)
2. taobao网购RS232转TTL转换器(本想去华强搞定此东西,不过走进赛格,商铺让我眼花缭乱,找了半天未果)
3. 从其他废旧板子中找到5pin排针,剪掉一pin,找美女帮我焊接到板之上, 都怪自己不会烙铁 :-(

哈哈, 串口有信息了, 提示内存不足, 只怪我的Image太大了!晕!看来非要把FLASH启下来重新来过.

[FLASH]

我没有系统的Loader, 找朋友把FLASH焊接下来,去烧录器上把2M的FLASH内容读了出来。我知道Loader是64K,所以我只需要前面的64K内容,用UltraEdit进入Hex编译模式选中COPY,然后到我的Fedora下用Cat把原是的Image(mini版本) cat到Loader后面,形成Loader+Image的文件,烧录到Flash中!好激动啊!系统马上可以动了!

[调试]

晕, 放上去什么反应都没有, 又劳驾朋友帮我重新焊接一次!但是系统继续没反应!时间也不早了, 不想继续麻烦朋友了, 下班回家!半夜我睡不踏实总在研究问题出在哪里!

翌日再战!对比一下发现用UltraEdit复制出来的64K文件竟然和从FLASH里面读出来的文件有出入!这UltraEdit复制粘贴怎么这么逊啊!还是Linux好,用dd很方便就把2M文件的前64K搞了出来。后悔自己为何用Ultraedit干这傻事,以后坚决用Linux思维方式解决问题!再次麻烦朋友帮忙焊接FLASH, 我烧录好自己重新整合的Loader+Image文件. 哈哈!系统OK了!可以轻松进去Shell Hack, 不错不错!终于有一块开发板可以Hacking了!

[后记]

烙铁要学习, 总麻烦朋友过意不去啊 =.=

2009年1月18日星期日

Unix shell 家谱

Thompson shell
The Thompson shell was the first Unix shell, introduced in the first version of Unix in 1971, and was written by Ken Thompson.

Bourne shell
The Bourne shell, or sh, was the default Unix shell of Unix Version 7, and replaced the Thompson shell, whose executable file had the same name, sh.

Korn shell
The Korn shell (ksh) is a Unix shell which was developed by David Korn (AT&T Bell Laboratories) in the early 1980s. It is backwards-compatible with the Bourne shell and includes many features of the C shell as well, such as a command history, which was inspired by the requests of Bell Labs users.

Bash(derive for Bourne shell)
Bash is a free software Unix shell written for the GNU Project. Its name is an acronym which stands for Bourne-again shell.[1] The name is a pun on the name of the Bourne shell (sh), an early and important Unix shell written by Stephen Bourne and distributed with Version 7 Unix circa 1978,[2] and the concept of being "born again". Bash was created in 1987 by Brian Fox. In 1990 Chet Ramey became the primary maintainer.[3]

Almquist shell(derive for Bourne shell)
The Almquist shell (also known as A Shell, ash and sh) was originally Kenneth Almquist's clone of the SVR4-variant of the Bourne shell; it is a fast, small, POSIX-compatible Unix shell designed to replace the Bourne shell in later BSD distributions. By intention it did not feature line editing or command history mechanisms originally, because Almquist felt that such should be moved into the terminal driver. Current variants have emacs and vi modes.

Debian Almquist shell(derive for Almquist shell)
Debian Almquist shell (dash) is a Unix shell, much smaller than bash but still aiming at POSIX-compliancy. It requires less disk space but is also less feature-rich. Some missing features, such as the $LINENO variable, are required by POSIX.

/bin/sh != /bin/bash

继续研究bash,惊奇发现自己是个白痴.原来以为/bin/sh和/bin/bash是一个东西,可是发现绝对不是那么回事.我还没搞懂这个dash是什么东西.晕!