2009年12月31日星期四
使用iwconfig 配置无线网卡
1. 启动无线网卡
ifconfig wlan0 on
2. 扫描无线接入点
iwlist wlan0 scanning
3. 连接接入点
iwconfig wlan0 essid YOUR-SERVICE-NAME
4. 配置网络
例如
ifconfig wlan0 192.168.xxx.xxx netmask 255.255.255.0 up
5. 测试
例如
ping 192.168.1.1
2009年12月14日星期一
使用bootchart-lite监视linux启动和运行状态
但鉴于bootchart的特殊实现方式,它不太适合嵌入式系统。
在嵌入式系统中,可以使用精简化的bootchart--bootchart-lite,替代bootchart。
1. bootchart-lite 源码下载
http://code.google.com/p/bootchart-lite/
2. 编译
CC=arm-linux-gcc ./configure
make
在src目录下面会生成bootchart-lite可执行文件
bootchart-lite 默认配置是把log文件存放在/etc/bootchart-lite/目录下,
使用之前要先建立这个目录。
3. 配置启动参数,让linux启动后,先启动bootchart-lite
init=bootchart-lite
4. 启动linux
5. 收集log文件,渲染图像
bootchart-lite会生成如下3个log文件:
proc_diskstats.log
proc_ps.log
proc_stat.log
把这3个文件取出后,在pc上运行如下命令:
tar czf bootchart.tgz *.log
bootchart -f png bootchart.tgz
在log所在目录下,会生成一个bootchart.png文件,打开看看你的系统状态吧。。。。
当然,pc上别忘记装bootchart工具。
2009年12月8日星期二
Linux Framebuffer编程简介
控制framebuffer设备的一般步骤如下:
1) 打开设备,映射framebuffer
2)依照硬件要求,准备好数据
3)把数据复制到framebuffer
例子程序如下:
1)打开设备,映射framebuffer
static void *fbbuf;
int openfb(char *devname)
{
int fd;
fd = open(devname, O_RDWR);
if (ioctl(fd, FBIOGET_VSCREENINFO, &fbvar) < 0)
return -1;
bpp = fbvar.bits_per_pixel;
screen_size = fbvar.xres * fbvar.yres * bpp / 8;
fbbuf = mmap(0, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
return fd;
}
2)数据准备,假设lcd控制器被初始化为565,16bit格式的
static inline int make_pixel(unsigned int a, unsigned int r, unsigned int g, unsigned int b)
{
return (unsigned int)(((r>>3)<<11)|((g>>2)<<5|(b>>3)));
}
3) 把想要显示的数据复制到framebuffer,假设把framebuffer填充成一种颜色
static void fill_pixel(unsigned int pixel, int x0, int y0, int w, int h)
{
int i, j;
unsigned short *pbuf = (unsigned short *)fbbuf;
for (i = y0; i < h; i ++) {
for (j = x0; j < w; j ++) {
pbuf[i * screen_width + j] = pixel;
}
}
}
2009年11月25日星期三
在nanox中使用cairo来渲染字体
将两者结合时,唯一需要注意的问题是像素的格式区别:
nanox的各颜色通道顺序是: RGBA R是低地址
cairo的顺序是:BGRA B是低地址
示例代码如下:
使用时,先调用prepare函数,创建cairo的surface,然后调用render函数,获取渲染后的图像,图像的地址
通过buf指针传回.这个buf可以通过nanox的GrArea直接显示,比如:
GrArea (win_id, gc_id, 0, 0, width, height, buf_from_cairo, MWPF_RGB);
static cairo_surface_t *prepare_text(int width, int height)
{
cairo_surface_t * surface;
surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height);
fprintf(stderr, "prepare text finished\n");
return surface;
}
static void render_text(cairo_surface_t *surface, unsigned char **buf,
unsigned int *width, unsigned int *height)
{
unsigned char *databuf;
unsigned int dw, dh , ds;
unsigned char *pixbuf;
unsigned int i, j;
cairo_t *cr = cairo_create(surface);
cairo_select_font_face(cr, "Sazanami Gothic",
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size(cr, 30.0);
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
cairo_move_to(cr, 0.0, 35.0);
cairo_show_text(cr, "R u 学生.");
cairo_move_to(cr, 0.0, 0.0);
cairo_set_source_rgb(cr, 1.0, 0.0, 0.0);
cairo_line_to(cr, 100.0, 15.0);
cairo_arc(cr, 200, 30, 15, 0.0, 2 * 3.1415926);
cairo_stroke(cr);
cairo_destroy(cr);
databuf = cairo_image_surface_get_data(surface);
if (!databuf) {
fprintf(stderr, "get cairo image data failed\n");
return;
}
dw = cairo_image_surface_get_width(surface);
dh = cairo_image_surface_get_height(surface);
ds = cairo_image_surface_get_stride(surface);
fprintf(stderr, " w: %d, h: %d, s: %d\n", dw, dh ,ds);
pixbuf = (unsigned char *)malloc(dh * ds);
/* Name : Low High */
/* Cairo: B G R A */ /* src */
/* Nanox: R G B A */ /* dst */
/* only for little endian ? */
for (i = 0; i < dh; i++) {
unsigned char *row = databuf + i * ds;
unsigned char *dst = pixbuf + i * ds;
for (j = 0; j < ds; j += 4) {
unsigned char *data = &row[j];
unsigned char *b = &dst[j];
unsigned int pixel;
/* wait for optimization */
memcpy(&pixel, data, sizeof(unsigned int));
b[0] = (pixel & 0xff0000) >> 16;
b[1] = (pixel & 0x00ff00) >> 8;
b[2] = (pixel & 0x0000ff) >> 0;
b[3] = 0;
}
}
fprintf(stderr, " render text finished\n");
#if 0
cairo_surface_write_to_png(surface, "hello.png");
2009年10月13日星期二
估计yaffs2内存使用情况
内存数量,但由于yaffs2的内存是根据系统运行情况,动态变化的,实际情况会有些出路。
计算方法如下:
1. yaffs_Objectszh占用 内存情况
每个文件,目录,符号连接都是一个object,每个object大概用了120个字节。
所以假设有1000个文件,那么object占用ram的大小是1000 * 120 => 120Kbytes
2. yaffs_Tnode 占用内存情况
首先计算 需要用多少bit数来表示整个nand:
bitnum = log2(nand 有的page数目)
然后在此基础上加1,yaffs内部表示时候需要多一个bit。
如果如上的bitnum不是偶数,加1。
最后内存使用情况是bitnum * pagenum / 8 字节
例如:nand有65536个页面
bitnum = log2(65536) + 1 = 16 + 1 = 17
向上去偶数,得到bitnum = 18
最后,表示整个nand的tnode用的内存是:
18 * 65536 / 8 = 147456 字节
2009年9月16日星期三
arm的按条件执行指令的功能
和x86对比的汇编代码如下。
C语言代码如下:
int b;
int test(int a) {
if (a>0)
return a+b;
return b;
}
分别用arm gcc 4.3.3 和x86 gcc 4.3.3 加-O2 -S选项 生成汇编代码。
arm的汇编代码如下:
test:
.fnstart
.LFB2:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
cmp r0, #0
ldrgt r3, .L5
ldrle r3, .L5
ldrgt r2, [r3, #0]
ldrle r0, [r3, #0]
addgt r0, r0, r2
bx lr
.L6:
.align 2
.L5:
.word b
x86的汇编代码如下:
test:
pushl %ebp
movl %esp, %ebp
movl 8(%ebp), %eax
testl %eax, %eax
jle .L2
addl b, %eax
popl %ebp
ret
.p2align 4,,7
.p2align 3
.L2:
movl b, %eax
popl %ebp
ret
.size test, .-test
.comm b,4,4
2009年9月15日星期二
directfb显示中文
需要的软件包:
zlib_1.2.3.3.dfsg.orig.tar.gz, libpng-1.2.38.tar.bz2 , jpegsrc.v7.tar.gz, freetype_2.3.7.orig.tar.gz, directfb_1.2.8.orig.tar.gz
(1) zlib 编译:
tar zxvf ../src/zlib_1.2.3.3.dfsg.orig.tar.gz
cd zlib-1.2.3.3.dfsg
CC=arm-none-linux-gnueabi-gcc ./configure --prefix=/opt
make && make install
cd .. && rm -rf zlib*
(2) libpng 编译:
cd libpng-1.2.38/
PKG_CONFIG_PATH=/opt/lib/pkgconfig CC=arm-none-linux-gnueabi-gcc CFLAGS=-I/opt/include \
LDFLAGS=-L/opt/lib ./configure --host=arm-none-linux-gnueabi --prefix=/opt --with-gnu-ld
make && make install
cd .. && rm -rf libpng*
tar zxvf ../src/jpegsrc.v7.tar.gz
cd jpeg-7/
CC=arm-none-linux-gnueabi-gcc ./configure --host=arm-none-linux-gnueabi \
--prefix=/opt --with-gnu-ld
make && make install
cd .. && rm -rf jpeg*
(4) freetype 编译:
tar zxvf ../src/freetype_2.3.7.orig.tar.gz
cd freetype-2.3.7/
PKG_CONFIG_PATH=/opt/lib/pkgconfig CC=arm-none-linux-gnueabi-gcc \
CFLAGS=-I/opt/include LDFLAGS=-L/opt/lib ./configure --host=arm-none-linux-gnueabi \
--prefix=/opt --with-gnu-ld
make && make install
cd .. && rm -rf freetype*
(5) directfb 编译:
cd directfb-1.2.8
CPPFLAGS="-I/opt/include" CFLAGS="-I/opt/include" LDFLAGS="-L/opt/lib" \
PKG_CONFIG_PATH="/opt/lib/pkgconfig" CC=arm-none-linux-gnueabi-gcc \
./configure --host=arm-none-linux-gnueabi --prefix=/opt --exec-prefix=/opt --enable-zlib --disable-x11 \
--enable-fbdev --disable-sdl --disable-vnc --enable-jpeg --disable-gif \
--enable-text --enable-freetype --enable-text --disable-network --disable-debug-support \
--disable-video4linux --with-gnu-ld
make && make install
cd .. && rm -rf directfb*
2. 配置根文件系统
(1) 复制库文件(可根据需要选择,比如帮助文件之类的可以不要, 还可以strip,减少库的占用空间)
cp -avrf /opt/* /mnt/armfs/opt/
(2) 复制字体文件
cp -avf /usr/share/fonts/truetype/wqy/wqy-zenhei.ttc /mnt/armfs/opt/share/directfb-1.2.8/
3. 编译可应用程序 (参考directfb的文本显示例子)
程序代码(我用的是linux系统,所以源代码中输入的中文应该是utf8的):
/**
* text.c
*
* Drawing text
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <directfb.h>
/*
* (Globals)
*/
static IDirectFB *dfb = NULL;
static IDirectFBSurface *primary = NULL;
static int screen_width = 0;
static int screen_height = 0;
#define DFBCHECK(x...) \
{ \
DFBResult err = x; \
\
if (err != DFB_OK) \
{ \
fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
DirectFBErrorFatal( #x, err ); \
} \
}
/*
* The font we will use to draw the text.
*/
static IDirectFBFont *font = NULL;
/*
* The string we will draw. Strings in DirectFB have to UTF-8 encoded.
* For ASCII characters this does not make any difference.
*/
static char *text = "DirectFB rulez!我是中国人";
#define DATADIR "/opt/share/directfb-1.2.8"
int main (int argc, char **argv)
{
int i, width;
/*
* A structure describing font properties.
*/
DFBFontDescription font_dsc;
/*
* (Locals)
*/
DFBSurfaceDescription dsc;
/*
* (Initialize)
*/
DFBCHECK (DirectFBInit (&argc, &argv));
DFBCHECK (DirectFBCreate (&dfb));
DFBCHECK (dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN));
dsc.flags = DSDESC_CAPS;
dsc.caps = DSCAPS_PRIMARY | DSCAPS_FLIPPING;
DFBCHECK (dfb->CreateSurface( dfb, &dsc, &primary ));
DFBCHECK (primary->GetSize (primary, &screen_width, &screen_height));
/*
* First we need to create a font interface by passing a filename
* and a font description to specify the desired font size. DirectFB will
* find (or not) a suitable font loader.
*/
font_dsc.flags = DFDESC_HEIGHT;
font_dsc.height = 48;
DFBCHECK (dfb->CreateFont (dfb, DATADIR"/wqy-zenhei.ttc", &font_dsc, &font));
/*
* Set the font to the surface we want to draw to.
*/
DFBCHECK (primary->SetFont (primary, font));
/*
* Determine the size of our string when drawn using the loaded font.
* Since we are interested in the full string, we pass -1 as string length.
*/
DFBCHECK (font->GetStringWidth (font, text, -1, &width));
/*
* We want to let the text slide in on the right and slide out on the left.
*/
for (i = screen_width; i > -width; i--)
{
/*
* Clear the screen.
*/
DFBCHECK (primary->SetColor (primary, 0x0, 0x0, 0x0, 0xFF));
DFBCHECK (primary->FillRectangle (primary, 0, 0, screen_width, screen_height));
/*
* Set the color that will be used to draw the text.
*/
DFBCHECK (primary->SetColor (primary, 0x80, 0x0, 0x20, 0xFF));
/*
* Draw the text left aligned with "i" as the X coordinate.
*/
DFBCHECK (primary->DrawString (primary, text, -1, i, screen_height / 2, DSTF_LEFT));
/*
* Flip the front and back buffer, but wait for the vertical retrace to avoid tearing.
*/
DFBCHECK (primary->Flip (primary, NULL, DSFLIP_WAITFORSYNC));
}
/*
* Release the font.
*/
font->Release (font);
/*
* (Release)
*/
primary->Release (primary);
dfb->Release (dfb);
return 23;
}
2009年9月6日星期日
gtk directfb arm linux交叉编译过程
#Packages list
#atk-1.26.0.tar.bz2 expat_2.0.1.orig.tar.gz glib-2.21.5.tar.bz2 gtk-doc-1.11.tar.bz2 librsvg-2.22.3.tar.bz2 poppler-0.10.7.tar.gz
#cairo-1.8.2.tar.gz fontconfig-2.5.91.tar.gz gst-plugins-base-0.10.23.tar.bz2 hicolor-icon-theme-0.10.tar.gz libxml2-sources-2.6.31.tar.gz SHA256SUMS-for-bz2
#dbus_1.2.16.orig.tar.gz freetype-2.3.6.tar.bz2 gstreamer-0.10.23.tar.bz2 jpegsrc.v7.tar.gz pango-1.24.5.tar.bz2 tslib_1.0.orig.tar.gz
#DirectFB-1.3.0.tar.gz gettext-0.16.tar.gz gtk+-2.16.6.tar.bz2 libpng-1.2.38.tar.bz2 pixman-0.12.0.tar.gz
# Step 1: Build Glib
#************Important**********************************************#
# you need to check your cross compiling toolchain to find whether
# there is an underscore before symbols, for example:
# cat >test.c <<"EOF"
# int test(){}
# EOF
# arm-linux-gcc -c test.c
# nm test.o
# rm test.c test.o
# then set glib_cv_uscore to "no" or "yes" according to the result of "nm test.o"
#************Important**********************************************#
tar jxvf ../src/glib-2.21.5.tar.bz2
cd glib-2.21.5
cat > config.cache << "EOF"
glib_cv_stack_grows=no
glib_cv_has__inline=yes
glib_cv_working_bcopy=no
glib_cv_uscore=no
ac_cv_func_posix_getpwuid_r=yes
ac_cv_func_posix_getgrgid_r=yes
EOF
CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/opt --cache-file=config.cache
make
sudo PATH=$PATH:/usr/local/arm/4.2.2-eabi/usr/bin make install
cd .. && rm -rf glib*
# Step 2: Build atk
tar jxvf ../src/atk-1.26.0.tar.bz2
cd atk-1.26.0/
PKG_CONFIG_PATH=/opt/lib/pkgconfig CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/opt
make && make install
cd .. && rm -rf atk*
# Step 3: png
tar jxvf ../src/libpng-1.2.38.tar.bz2
cd libpng-1.2.38/
PKG_CONFIG_PATH=/opt/lib/pkgconfig CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/opt
make && make install
cd .. && rm -rf libpng*
# Step 4: jpeg
tar zxvf ../src/jpegsrc.v7.tar.gz
cd jpeg-7/
CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/opt
make && make install
cd .. && rm -rf jpeg*
# Step 5: libxml
tar zxvf ../src/libxml2-sources-2.6.31.tar.gz
cd libxml2-2.6.31/
PKG_CONFIG_PATH=/opt/lib/pkgconfig CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/opt
make && make install
cd .. && rm -rf libxml*
# Step 6: pixman
tar zxvf ../src/pixman-0.12.0.tar.gz
cd pixman-0.12.0/
PKG_CONFIG_PATH=/opt/lib/pkgconfig CC=arm-linux-gcc ./configure --host=arm-linux \
--prefix=/opt --disable-gtk
make && make install
cd .. && rm -rf pixman*
# Step 7: freetype
tar jxvf ../src/freetype-2.3.6.tar.bz2
cd freetype-2.3.6/
PKG_CONFIG_PATH=/opt/lib/pkgconfig CC=arm-linux-gcc ./configure --host=arm-linux --prefix=/opt
make && make install
cd .. && rm -rf freetype*
# Step 8: fontconfig
tar zxvf ../src/fontconfig-2.5.91.tar.gz
cd fontconfig-2.5.91
PKG_CONFIG_PATH=/opt/lib/pkgconfig CC=arm-linux-gcc ./configure --host=arm-linux \
--with-arch=arm --prefix=/opt --with-freetype-config=/opt/bin/freetype-config
make && make install
cd .. && rm -rf fontconfig*
# Step 9: directfb
tar zxvf ../src/DirectFB-1.3.0.tar.gz
cd DirectFB-1.3.0/
CPPFLAGS="-I/opt/include" CFLAGS="-I/opt/include" LDFLAGS="-L/opt/lib" \
PKG_CONFIG_PATH="/opt/lib/pkgconfig" \
./configure --host=arm-linux --prefix=/opt --exec-prefix=/opt --enable-zlib --disable-x11 \
--enable-fbdev --disable-sdl --disable-vnc --enable-jpeg --disable-gif --with-gfxdrivers=none
make && make install
cd .. && rm -rf DirectFB*
# Step 10: poppler
tar zxvf ../src/poppler-0.10.7.tar.gz
cd poppler-0.10.7/
PKG_CONFIG_PATH=/opt/lib/pkgconfig CC=arm-linux-gcc CPPFLAGS="-I/opt/include" \
CFLAGS="-I/opt/include" LDFLAGS="-L/opt/lib" \
./configure --host=arm-linux --enable-libjpeg --without-x --disable-gtk-test \
--disable-utils --disable-splash-output --disable-gdk --prefix=/opt
make && make install
cd .. && rm -rf poppler*
# Step 11: cairo
tar zxvf ../src/cairo-1.8.2.tar.gz
cd cairo-1.8.2/
PKG_CONFIG_PATH=/opt/lib/pkgconfig CPPFLAGS="-I/opt/include" CFLAGS="-I/opt/include" LDFLAGS="-L/opt/lib" \
./configure --without-x --prefix=/opt --enable-directfb --enable-xlib=no --host=arm-linux --enable-ps=yes \
--enable-svg=yes --enable-pdf=yes
make && make install
cd .. && rm -rf cairo*
# Step 12: pango
tar jxvf ../src/pango-1.24.5.tar.bz2
cd pango-1.24.5/
PKG_CONFIG_PATH=/opt/lib/pkgconfig CC=arm-linux-gcc ./configure --host=arm-linux \
--without-x --prefix=/opt
make && make install
cd .. && rm -rf pango*
# Step 13: gtk+
# There is a "Can't link to Pango " problem, not find a better solution but the following:
# change [ if $PKG_CONFIG uninstalled $PANGO_PACKAGES; then ] to
# ---> [ if $PKG_CONFIG $PANGO_PACKAGES; then ]
#
tar jxvf ../src/gtk+-2.16.6.tar.bz2
cd gtk+-2.16.6/
cat>config.cache<<"EOF"
gio_can_sniff=yes
EOF
CPPFLAGS="-I/opt/include" CFLAGS="-I/opt/include" LDFLAGS="-L/opt/lib" \
PKG_CONFIG_LIBDIR=/opt/lib/pkgconfig CC=arm-linux-gcc ./configure --host=arm-linux \
--without-x --prefix=/opt --without-libtiff --without-libjasper --with-gdktarget=directfb \
--cache-file=config.cache --disable-glibtest --disable-gdiplus --disable-cups
make && make install
cd .. && rm -rf gtk
# Test
# Hello World
# download from:
# http://library.gnome.org/devel/gtk-tutorial/stable/c39.html#SEC-HELLOWORLD
# Makefile
DEBUG=-g
CFLAGS=-Wall -c ${DEBUG}
GTK_CFLAGS=`pkg-config --cflags gtk+-2.0 cairo cairo-ft cairo-directfb directfb freetype2 pangoft2 pangocairo pango pixman-1`
GTK_LIBS=`pkg-config --libs libpng12 libxml-2.0 gtk+-2.0 atk cairo cairo-ft cairo-directfb directfb freetype2 pangoft2 pangocairo pango pixman-1`
GMODULE_LIBS= `pkg-config --libs gmodule-2.0`
CC=arm-linux-gcc
gtkdemo:
${CC} ${GTK_CFLAGS} ${OBJS} -v -o gtkdemo gtkdemo.c ${GTK_LIBS} ${GMODULE_LIBS}
clean:
rm gtkdemo
# Build method
PKG_CONFIG_PATH=/opt/lib/pkgconfig make
# Strip Libs
# decrease libs size
cd /opt/lib
arm-linux-strip -s ./*
cd /opt/bin
arm-linux-strip -s ./*
# rootfile system config
pango-querymodules > '/opt/etc/pango/pango.modules'
# At last you should copy fonts and config them.
2009年8月11日星期二
编译directfb
export CFLAGS="-I/opt/usr/include"
export LDFLAGS="-L/opt/usr/lib"
export PKG_CONFIG_PATH="/opt/usr/lib/pkgconfig"
./configure --host=arm-linux --build=i686-pc-linux-gnu --prefix=/opt/usr --exec-prefix=/opt/usr --enable-zlib --disable-x11 --enable-fbdev --disable-sdl --disable-vnc --disable-jpeg --disable-gif
2009年8月2日星期日
Value too large for defined data type
"Value too large for defined data type"错误。
这时候,可以通过调用open64, lseek64函数,可以解决这个问题。
编译时候需要添加下面两个选项:
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
2009年7月29日星期三
fedora11 flash插件安装
http://get.adobe.com/flashplayer/ 网站上下载install_flash_player_10_linux.tar.gz文件.
2.复制到mozilla插件文件夹
将下载的文件解压 后,将libflashplayer.so文件复制到/usr/lib/mozilla/plugins/文件夹下.
2009年7月27日星期一
2009年7月20日星期一
mount kvm disk image
1. kpartx -av disk.img
add map loop0p1 (253:0): 0 1863477 linear /dev/loop0 63
add map loop0p2 (253:1): 0 224910 linear /dev/loop0 1863540
add map loop0p5 : 0 224847 linear 253:1 63
2. mount /dev/mapper/loop0p1 /mnt/
通常image的根文件系统都被映射到loop0p1
卸载
1. unmount /mnt
2. kpartx -dv diks.img
del devmap : loop0p5
del devmap : loop0p2
del devmap : loop0p1
2009年7月13日星期一
linux 动态连接加载器 ld-linux用法
间接调用时,连接器会把ld-linux的执行路径嵌入到可执行文件中,如elf文件时,ld-linux被放在.interp段中。
直接调用时,在命令行下输入/lib/ld-linux-so.* [选项] [可执行程序] [程序参数]
ld-linux按照如下顺序搜索可执行程序需要的共享库:
1. (只针对elf文件) 可执行程序中如果有DT_RPATH或DT_RUNPATH段,则使用这两个段中指定的搜索目录。
2.使用环境变量LD_LIBRARY_PATH指定的搜索目录
3.使用/etc/ld.so.cache中的搜索目录,但如果可执行程序在连接时候添加了-z nodeflib选项,则不使用。
4.使用默认的库目录,/lib /usr/lib,如果添加了-z nodeflib,则不使用。
编译可执行程序时,可以安如下方法指定共享库的目录
gcc -Xlinker -rpath=DIR -o exe exe.c
编译完后,运行readelf -d exe可以看到如下段
0x0000000f (RPATH) Library rpath: [DIR]
2009年7月8日星期三
TFT LCD 接口时序计算
1.VSYNC: 帧频率 一秒钟处理的帧的数目 (Frame Frequency)
2.HSYNC: 行频率 一秒钟处理的行的数目
3.DOTCLK: 像素频率 一秒钟处理的像素数目
同时,还有如下接口参数:
VBP: vertical back porch 垂直方向后端没使用的行数
VFP: vertical front porch 垂直方向前端没使用的行数
HBP: horizonal back porch 水平方向后端没使用的像素数目
HFP: horizonal front porch 水平方向前端没使用的像素数目
DOTCLK = FrameRate(VSYNC) * 行总数 *行中的像素总数
行总数 = LCD 高 + VBP + VFP
行中的像素总数= LCD宽 + HBP + HFP
(注:有些LCD,还需要在行总数中加上VSYNC宽度,在行中像素总数中加上HSYNC宽度)
以LMS430HF02这款LCD为例
帧频率是60帧/秒
LCD高度是272行
LCD宽度是480个像素
VBP= 12.0 # line
VFP= 4.0 # line
HBP= 45.0 # pixel
HFP= 8.0 # pixel
DOTCLK = VSYNC* (lcd_width + hbp + hfp) * (lcd_height+ vbp + vfp)
/1000000 = 9.21024Mhz
和LCD datasheet中提供的接口时序说明基本一致。
2009年7月1日星期三
裁剪libc
How to reduce libc size
From NetBSD Wiki
Jump to: navigation, search
Contents
[hide]
* 1 Introduction
* 2 Build options
o 2.1 Default -O2, file size 1164025
o 2.2 -O1, file size 1159845
+ 2.2.1 Linker strip, file size 1065624
o 2.3 -Os, file size 1094281
+ 2.3.1 Manual strip, file size 1004180
+ 2.3.2 Linker strip, file size 1000060
* 3 Feature removal
o 3.1 SCCS version strings, file size 953136
o 3.2 Hesiod name service, file size 942468
o 3.3 Yellow Pages (YP), file size 917368
o 3.4 IPv6 support, file size 909272
o 3.5 Stack smashing protection (SSP), file size 894764
o 3.6 Remote procedure call (RPC), file size 806036
o 3.7 Execution profiling control, file size 801720
o 3.8 Citrus I18N, file size 767560
o 3.9 MD2, RMD160, SHA1, SHA2, MD4 and MD5 cryptographic
hash functions, file size 723780
o 3.10 Misc, Native Language Support (NLS), Regular
Expression and Stack Smashing Protection, file size 691884
* 4 Ideas
o 4.1 Compiler options
+ 4.1.1 Thumb instruction set, file size 585440
o 4.2 Feature removals
+ 4.2.1 Database support from lib/libc/db
+ 4.2.2 Regular memory allocator instead of JEMALLOC
+ 4.2.3 Reduce resolver size in lib/libc/resolver
+ 4.2.4 Use libhack
* 5 Alternatives
o 5.1 Crunchgen
* 6 References
Introduction
The NetBSD installation is not big, but it can be made smaller. Here
are a few tricks to make the base of user space, the C standard
library libc, a bit smaller for dynamically linked systems. These
trials were done on a cross compiled NetBSD current ARMv6 branch.
First the user space is built with default options. Then the cross
compiler script $TOOLDIR/bin/nbmake-evbarm was used to clean and
rebuild the libc with special options. The new libc binary was then
copied to the target file system and a smoke test of booting the ARM
development board was done. If /sbin/init and /bin/sh managed with the
new libc, the test was a success while everything else was a failure.
The result is a crippled libc and /lib/libc.so.12.159 file size
reduction from 1164 to 692 kilobytes. Run time memory usage is harder
to predict since it depends on what parts of in memory libc are
actually used by the processes, but at least text and data sections
reported by the size utility give some idea.
Build options
Default -O2, file size 1164025
-O2 optimization is used by default and the libc file size after a
./build.sh -U -m evbarm build is:
-r--r--r-- 1 test test 1164025 2008-04-18 08:23
obj/destdir.evbarm/lib/libc.so.12.159
Sections reported by size utility:
text data bss dec hex filename
931608 25728 64332 1021668 f96e4 obj/libc.so.12.159
-O1, file size 1159845
If the libc is build with CFLAGS=-O1, the ELF shared object file size is:
-rw-r--r-- 1 test test 1159845 Apr 19 09:20 lib/libc.so.12.159
Sections reported by size utility:
text data bss dec hex filename
927436 25728 64332 1017496 f8698 obj/libc.so.12.159
Linker strip, file size 1065624
If the -O1 build is stripped and size optimized by the linker with
LDFLAGS=-Wl,-O1\ -Wl,-s, the file size reduces to:
-rwxr-xr-x 1 test test 1065624 2008-04-19 13:28 obj/libc.so.12.159
Sections reported by size utility:
text data bss dec hex filename
923316 25728 64332 1013376 f7680 obj/libc.so.12.159
-Os, file size 1094281
The gcc compiler can optimize binaries for size with CFLAGS=-Os:
-rwxr-xr-x 1 test test 1094281 2008-04-19 10:56 obj/libc.so.12.159
Sections reported by size utility:
text data bss dec hex filename
861864 25736 64332 951932 e867c obj/libc.so.12.159
Manual strip, file size 1004180
The binary can then be stripped manually:
$ $TOOLDIR/bin/arm--netbsdelf-strip -s obj/libc.so.12.159
$ ls -l obj/libc.so.12.159
-rwxr-xr-x 1 test test 1004180 2008-04-19 11:02 obj/libc.so.12.159
Sections reported by size utility:
text data bss dec hex filename
861864 25736 64332 951932 e867c obj/libc.so.12.159
Linker strip, file size 1000060
The -Os compiled binary is smaller with linker based strip and
optimization where LDFLAGS=-Wl,-O1\ -Wl,-s than with a manual strip:
-rwxr-xr-x 1 test test 1000060 2008-04-19 12:07 obj/libc.so.12.159
Sections reported by size utility:
text data bss dec hex filename
857744 25736 64332 947812 e7664 obj/libc.so.12.159
Feature removal
In addition to compiler flags CFLAGS=-Os LDFLAGS=-Wl,-O1\ -Wl,-s,
special feature flags can be used to strip features out of libc and
reduce its size. Some feature flags, as documented by BUILDING and
share/mk/bsd.README, are supported for the whole user space.
SCCS version strings, file size 953136
SCCS version strings are normally embedded into object file, but they
be removed by following changes in lib/libc/Makefile:
--- lib/libc/Makefile.inc 3 Jun 2007 17:36:08 -0000 1.3
+++ lib/libc/Makefile.inc 19 Apr 2008 11:01:23 -0000
@@ -24,7 +24,8 @@
.include <bsd.own.mk>
WARNS=4
-CPPFLAGS+= -D_LIBC -DLIBC_SCCS -DSYSLIBC_SCCS -D_REENTRANT
+#CPPFLAGS+= -D_LIBC -DLIBC_SCCS -DSYSLIBC_SCCS -D_REENTRANT
+CPPFLAGS+= -D_LIBC -D_REENTRANT
.if (${USE_HESIOD} != "no")
CPPFLAGS+= -DHESIOD
The resulting libc binary finally goes below the one megabyte mark:
-rwxr-xr-x 1 test test 953136 2008-04-19 13:54 obj/libc.so.12.159
Sections reported by size utility:
text data bss dec hex filename
857744 25736 64332 947812 e7664 obj/libc.so.12.159
Hesiod name service, file size 942468
Hesiod, a DNS based database service, support can be removed from libc
with USE_HESIOD=no MKHESIOD=no build variables and result is:
-rwxr-xr-x 1 test test 942468 2008-04-19 14:16 obj/libc.so.12.159
Sections reported by size utility:
text data bss dec hex filename
847625 25252 62180 935057 e4491 obj/libc.so.12.159
Yellow Pages (YP), file size 917368
Yellow Pages (YP) or Network Information Service (NIS) directory
service support can be removed with USE_YP=no MKYP=no variables:
-rwxr-xr-x 1 test test 917368 2008-04-19 14:29 obj/libc.so.12.159
Sections reported by size utility:
text data bss dec hex filename
824328 24488 58944 907760 dd9f0 obj/libc.so.12.159
IPv6 support, file size 909272
IPv6 support can be removed with USE_INET6=no:
-rwxr-xr-x 1 test test 909272 2008-04-19 14:48 obj/libc.so.12.159
Sections reported by size utility:
text data bss dec hex filename
816537 24368 58944 899849 dbb09 obj/libc.so.12.159
Stack smashing protection (SSP), file size 894764
SSP buffer overflow protection from the GCC compiler can be disabled
with USE_SSP=no and the libc binary size goes below 900k:
-rwxr-xr-x 1 test test 894764 2008-04-19 15:02 obj/libc.so.12.159
Sections reported by size utility:
text data bss dec hex filename
802029 24368 58944 885341 d825d obj/libc.so.12.159
Remote procedure call (RPC), file size 806036
RPC support can be disabled with MKRPC=no variable and a patch like this:
--- lib/libc/Makefile 9 Jan 2008 01:33:52 -0000 1.131.4.1
+++ lib/libc/Makefile 23 Apr 2008 13:04:42 -0000
@@ -74,7 +80,10 @@
.endif
.include "${.CURDIR}/regex/Makefile.inc"
.include "${.CURDIR}/resolv/Makefile.inc"
+MKRPC?= yes
+.if (${MKRPC} != "no")
.include "${.CURDIR}/rpc/Makefile.inc"
+.endif
.include "${.CURDIR}/ssp/Makefile.inc"
.include "${.CURDIR}/stdio/Makefile.inc"
.include "${.CURDIR}/stdlib/Makefile.inc"
As a result the libc size goes down to 806 kilobytes:
-rw-r--r-- 1 test test 806036 2008-04-23 16:00 lib/libc.so.12.159
Sections reported by size utility:
text data bss dec hex filename
717964 22624 58500 799088 c3170 obj/libc.so.12.159
Execution profiling control, file size 801720
Profiling control can be removed from libc with MKGMON=no and a patch like:
--- lib/libc/Makefile 9 Jan 2008 01:33:52 -0000 1.131.4.1
+++ lib/libc/Makefile 24 Apr 2008 08:07:08 -0000
@@ -58,7 +58,10 @@
.include "${.CURDIR}/dlfcn/Makefile.inc"
.include "${.CURDIR}/gdtoa/Makefile.inc"
.include "${.CURDIR}/gen/Makefile.inc"
+MKGMON?= yes
+.if (${MKGMON} != "no")
.include "${.CURDIR}/gmon/Makefile.inc"
+.endif
.include "${.CURDIR}/hash/Makefile.inc"
.include "${.CURDIR}/iconv/Makefile.inc"
.include "${.CURDIR}/inet/Makefile.inc"
And libc size goes down around 4 kilobytes:
-rwxr-xr-x 1 test test 801720 2008-04-24 10:57 obj/libc.so.12.159
Sections reported by size utility:
text data bss dec hex filename
713959 22500 58436 794895 c210f obj/libc.so.12.159
Citrus I18N, file size 767560
Citrus I18N support can be removed with MKCITRUS=no,
lib/libc/locale/setlocale.c patch and a makefile patch:
--- Makefile 9 Jan 2008 01:33:52 -0000 1.131.4.1
+++ Makefile 25 Apr 2008 07:51:20 -0000
@@ -53,12 +53,18 @@
.include "${.CURDIR}/../../common/lib/libc/Makefile.inc"
.include "${.CURDIR}/db/Makefile.inc"
+MKCITRUS?= yes
+.if (${MKCITRUS} != "no")
.include "${.CURDIR}/citrus/Makefile.inc"
+.endif
.include "${.CURDIR}/compat-43/Makefile.inc"
.include "${.CURDIR}/dlfcn/Makefile.inc"
.include "${.CURDIR}/gdtoa/Makefile.inc"
The libc binary is now below 800 kilobytes:
-rwxr-xr-x 1 test test 767560 2008-04-25 10:01 obj/libc.so.12.159
Sections reported by size utility:
text data bss dec hex filename
685150 18696 56968 760814 b9bee obj/libc.so.12.159
MD2, RMD160, SHA1, SHA2, MD4 and MD5 cryptographic hash functions,
file size 723780
All cryptographic hash functions can be removed from the libc with
MKMD2=no MKRMD160=no MKSHA1=no MKSHA2=no MKMD=no and
lib/libc/hash/Makefile.inf and lib/libc/Makefile patches:
--- lib/libc/hash/Makefile.inc 27 Oct 2006 18:29:21 -0000 1.11
+++ lib/libc/hash/Makefile.inc 30 Apr 2008 09:10:21 -0000
@@ -4,8 +4,20 @@
# hash functions
.PATH: ${ARCHDIR}/hash ${.CURDIR}/hash
+MKMD2?= yes
+.if (${MKMD2} != "no")
.include "${.CURDIR}/hash/md2/Makefile.inc"
+.endif
+MKRMD160?= yes
+.if (${MKRMD160} != "no")
.include "${.CURDIR}/hash/rmd160/Makefile.inc"
+.endif
+MKSHA1?= yes
+.if (${MKSHA1} != "no")
.include "${.CURDIR}/hash/sha1/Makefile.inc"
+.endif
+MKSHA2?= yes
+.if (${MKSHA2} != "no")
.include "${.CURDIR}/hash/sha2/Makefile.inc"
+.endif
--- lib/libc/Makefile 9 Jan 2008 01:33:52 -0000 1.131.4.1
+++ lib/libc/Makefile 30 Apr 2008 09:11:25 -0000
.include "${.CURDIR}/inet/Makefile.inc"
.include "${.CURDIR}/isc/Makefile.inc"
.include "${.CURDIR}/locale/Makefile.inc"
+MKMD?= yes
+.if (${MKMD} != "no")
.include "${.CURDIR}/md/Makefile.inc"
+.endif
.include "${.CURDIR}/misc/Makefile.inc"
.include "${.CURDIR}/net/Makefile.inc"
.include "${.CURDIR}/nameser/Makefile.inc"
libc size reduces to:
-rwxr-xr-x 1 test test 723780 2008-04-30 12:03 obj/libc.so.12.159
Sections reported by size utility:
text data bss dec hex filename
642476 18456 56968 717900 af44c obj/libc.so.12.159
Misc, Native Language Support (NLS), Regular Expression and Stack
Smashing Protection, file size 691884
Indeed, misc object, NLS, regular expression (IEEE Std 1003.2-1992
("POSIX.2") regular expressions) and Stack Smashing Protection (SSP)
support library are easily removed from the build process with
MKMISC=no MKNLS=no MKREGEX=no MKSSP=no and an obvious patch to
lib/libc/Makefile:
.include "${.CURDIR}/md/Makefile.inc"
+.endif
+MKMISC?= yes
+.if (${MKMISC} != "no")
.include "${.CURDIR}/misc/Makefile.inc"
+.endif
.include "${.CURDIR}/net/Makefile.inc"
.include "${.CURDIR}/nameser/Makefile.inc"
+MKNLS?= yes
+.if (${MKNLS} != "no")
.include "${.CURDIR}/nls/Makefile.inc"
+.endif
.if (${MACHINE_ARCH} != "alpha") && (${MACHINE_ARCH} != "sparc64")
.include "${.CURDIR}/quad/Makefile.inc"
.endif
+MKREGEX?= yes
+.if (${MKREGEX} != "no")
.include "${.CURDIR}/regex/Makefile.inc"
+.endif
.include "${.CURDIR}/resolv/Makefile.inc"
...
.include "${.CURDIR}/rpc/Makefile.inc"
+.endif
+MKSSP?= yes
+.if (${MKSSP} != "no")
.include "${.CURDIR}/ssp/Makefile.inc"
+.endif
.include "${.CURDIR}/stdio/Makefile.inc"
.include "${.CURDIR}/stdlib/Makefile.inc"
.include "${.CURDIR}/string/Makefile.inc"
Boot with sbin/init still works as does bin/sh, but user friendly
programs like bin/ps and bin/ls now fail due to missing symbols:
# ls -l lib/libc.so.12.159
/lib/libc.so.12: Undefined PLT symbol "__fgets_chk" (symnum = 156)
# ls lib/libc.so.12.159
lib/libc.so.12.159
# ps aux
/lib/libc.so.12: Undefined PLT symbol "__strcat_chk" (symnum = 207)
# ps
ps: warning: /var/run/dev.db: /lib/libc.so.12: Undefined PLT symbol "_catopen" )
File size now:
-rwxr-xr-x 1 test test 691884 2008-04-30 14:18 obj/libc.so.12.159
Segment sizes reported by size utility:
text data bss dec hex filename
614238 17284 56928 688450 a8142 obj/libc.so.12.159
Ideas
While a few compiler and feature options were a tried out, a number of
new ideas were found. Some of these were quickly tried out, but they
resulted in the build or smoke/boot test failures.
Compiler options
Thumb instruction set, file size 585440
Compile to 16 bit THUMB instruction set instead of normal 32 bit
* Whole user space needs to be build with -mthumb-interwork
* CPUFLAGS build variable should contain -mthumb and -mthumb-interwork
* If some files (like atomic_init_testset.c) need arm32 code due
to embedded ARM assembly or other tool chain issues, the CPUFLAGS
build variable can be overridden: Per file build options override
* libc from matt-armv6 branch builds with -mthumb but fails to run
with SIGILL: Thumb compilation discussion on port-arm
After a successfull compile with atomic_init_testset.o compiled with
-mthumb-interwork only, the file size is:
-rwxr-xr-x 1 mira mira 585440 2008-05-12 11:20 obj/libc.so.12.159
size utility reports:
text data bss dec hex filename
507462 17616 56928 582006 8e176 obj/libc.so.12.159
Feature removals
Database support from lib/libc/db
* sbin/init and possibly others depend on Berkeley DB support
* a custom init and bin/sh propably work without it
Regular memory allocator instead of JEMALLOC
* USE_JEMALLOC: (share/mk/bsd.README) If "no", disables building
the "jemalloc" allocator designed for improved performance with
threaded applications.
o seems to require rebuild of user space, but even after
that init dies with:
warning: no /dev/console
panic: init died (signal 0, exit 12)
Stopped in pid 1.1 (init) at netbsd:cpu_Debugger+0x4: bx r14
Reduce resolver size in lib/libc/resolver
* remove IPv6 support
* remove debug features
Use libhack
* Use size optimized distrib/utils/libhack with/instead of libc
Alternatives
Crunchgen
crunchgen can be used to create statically (at compile time) linked
executables, which include only those object files, which are really
used by the executable.
* Use crunchgen or related build infra to build a dynamic library
from only those object files that are actually required by the
applications
References
* The BUILDING and share/mk/bsd.README files in addition to libc
specific makefiles and sources contain information on the different
build and feature options.
* gcc and ld manual pages
* Shrinking NetBSD - deep final distribution re-linker, discussion
on tech-userlevel
* Reducing libc size, discussion on tech-userlevel
arm交叉编译bash和python
目标机器是EABI,armv4t
一.bash
下载代码
http://core.ring.gr.jp/pub/GNU/bash/bash-3.2.48.tar.gz
配置
CC=arm-linux-gcc CFLAGS=-mabi=aapcs-linux ./configure --host=arm-unknown-linux --target=arm-unknow-linux --build=i686-unknown-linux
编译
make
确认库和二进制程序
readelf -h bash 确认abi版本和目标机器
readelf -d bash 确认使用的共享库
如果是静态编译,就不用确认共享库了。
二.python
下载代码
python-2.6.2
配置和bash一样。但,如果出现交叉编译无法执行程序的错误时,把configure文件中对应部分注释掉。
通过后,make编译。
2009年6月29日星期一
编译arm平台的ethtool
git clone git://git.kernel.org/pub/scm/network/ethtool/ethtool.git
2.准备交叉编译工具
可以从codesoucery下载
3.编译
假设目标机器的规格如下:
ABI: EABI version 4
little endian
armv5te
按如下顺序运行:
./autogen.sh
./configure CC=CROSS-COMPILER PATH CFLAGS=-march=armv5te --host=arm-xx-linux
如果需要静态编译则
打开vim Makefile 在CC= CROSS-COMPILER后面加上--static
保存
make
就在当前文件夹内生成一个可执行文件ethtool
确认编译后的文件
readelf -h ethtool
确认以下信息(具体内容要看自己的配置了)
OS/ABI UNIX - System V
Machine :ARM
Flags Version4 EABI
2009年6月27日星期六
编译2.6.31内核和busybox1.14.2
目标板versatile。
CPU核: ARM926T,arm9tdmi
ARM指令集:armv5te
交叉编译工具:
http://www.codesourcery.com/sgpp/lite/arm/portal/package4571/public/arm-none-linux-gnueabi/arm-2009q1-203-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
内核配置:
先使用源码自带的
make versatile_defconfig
另外将CONFIG_AEABI选项也选择了。
配置好后,make 编译就行了。
busybox的配置。
配置时候,添加如下的附加编译器条件:
-mlittle-endian -marm -fno-omit-frame-pointer -mapcs -mno-sched-prolog
-mabi=aapcs-linux -mno-thumb-interwork -march=armv5te -mtune=arm9tdmi
-msoft-float -fno-stack-protector -fno-optimize-sibling-calls -fwrapv
编译
最后,确认下编译好的内核和busybox
查看ELF Header内核和busybox要保持一致
readelf -h vmlinux
readelf -h busybox
Version: 1 (current)
OS/ABI: UNIX -System V
ABI Version: 0
Machine: ARM
Version: 0x1
Flags: 0x5000002, has entry point, Version5 EABI
2009年6月24日星期三
My PGP Public Key ID and Fingerprint
My PGP Public Key
Version: GnuPG v2.0.10 (GNU/Linux)
mQGiBEpBhvQRBADP95PG0teyveIfFJbxl8DootgI41mOENgJ394wvB77yPLvq/lf
KUN+eq3V5IwkaX+P8u2Hf/1ZQI49Up/fSmchw4ITsgXmLsXyoZcMw373mL9o9BZp
kf8PXXKojMpUINJ976JCdJETYJUfh5EvP2cKLivw5ENdx/cdAzSoExt/LwCgiQiy
xv/jxN1HUtXm/Tjw99ig2iUD/3sXc2/ljUyw9DSwf1KTQR17eiYlLQj1OnnvnKWv
r11bzwZ6xyDNxvRnY4/QovbuBaswcVTV5piEsy0p4boKf6dEnaTF6LOeFV02ZrAu
TB1kFiWBzRnvcqcHY53XzCDo6OCM78ULI8dEt4kCW+mCCfuPqLkEUk3TO4p8U79E
0p7vA/9Kk4qBne1uKbB/GzPnMBtRF7TeDY58mNtpt/UUV40UvevpoyZ/Cn/zcrl/
Hz0sPlUAQzMQ0lnBDEHlso20DmhnbyUofW9RzV2UaF4t5++kurBAoGqxpMrXH4eE
yKm/vCy46o29NQ+n647yQbg8TZQsfO7KqgdUeTrwD9MW+dJxL7QkSGFpeWFuZyBL
YW5nIDxrYW5naGFpeWFuZ0BnbWFpbC5jb20+iGAEExECACAFAkpBhvQCGwMGCwkI
BwMCBBUCCAMEFgIDAQIeAQIXgAAKCRDYH0FaMAPo2LViAJ9Zc9d5fUzvM7ToKFBU
GUzjn/lDiQCbBJl4Z2y6+WkliEsdl5bXzPhJF8i5Ag0ESkGG9BAIAJuPwo8X+bZ9
hY5WkiIfS4BqlN+O1SpEwBoljxikcmo9t2rajiJkkEp+X6mg+cZq3q+bEt7SLGdz
Q7UIQLjcdakUy+NOobd3sodWOM+gwI5bWAP/ZHUu6ETc1EUDV7bsabsl29pwHDvF
jdZrgmg9Bc7Rg03giizvjbFiddLzQfSE23sSbxWoePq0HbwPc+rsPopmVCVw7dbZ
mMVrHqTATmTs3butlmxn529O6WCN8ob/TW//fQNZBbh5kqpTjzUO9ZeS3kD3vW9K
n71mNeUs7LwYjhczTjMclpyShbfc54IqShsTw9qBGtd27uB4ZjF0xEEc32PVSVE8
Ie2D8AYW0LcAAwcH+wdNqisKEmcAdlJ7N5BxqhjP0CXRymtPogYUbtBurSwat49q
SqDESqW8A65vo2DIDvdDz6YUaaji1EXNqNzHBSgyy4u5ekhSXe+Hhx+URw4oEDHs
0sIQpsKYuwYTFMNZHjgflsGFfYB2SDUNMgw9u+1B8k9dn8dP3jKDtgNctjJOG4ip
dR2vqVvE2bJumh94pf+1XyqQs2FfbmYB7DbURBnt0dGEGZOxPM3FRhHG1QSQHaB+
HfWhiz6Kd/mqaeOOAW3u30Wu/ZPiESgVTxGGJ8d3+VMSdWfPzAp2FmqBoRbcBueL
ljqzY08i8C2nLSodrwmpyVJWV9+f3LcXK+q+gQmISQQYEQIACQUCSkGG9AIbDAAK
CRDYH0FaMAPo2O/kAJ9DEhg9Kg4eqKDQ9yY0cBhbmM7kagCfSW0Er/De6HfYuMgq
tmrDyF5Frrw=
=lYW3
-----END PGP PUBLIC KEY BLOCK-----
2009年6月22日星期一
How To: Running Fedora-ARM under QEMU
2009年5月30日星期六
powerpc 汇编语言注释
.globl array
.section ".data" /*把array变量放到数据段*/
.align 2
.type array, @object
.size array, 24
array:
.long 21
.long 2
.long 3
.long 90
.long 10
.long 11
.section .rodata
.align 3
.LC0:
.string "%d\n"
.section ".text"
.align 2
.globl main
.type main, @function
main:
stwu 1,-32(1)
mflr 0
stw 31,28(1)
stw 0,36(1)
mr 31,1
/* r9 is the address of array*/
lis 9,array@ha /*读array地址的高16位并左移16位*/
la 9,array@l(9) /*读array地址的低16位,并将其与r9 (上条指令的执行结果)相加,得到array的地址,存放到r9中*/
li 0,0
stw 0,0(9)
li 0,1
stw 0,4(9)
li 10,2
stw 10,8(31)
1:
lwz 10,8(31)
addi 0,10,-2 /*将r10减去2,结果放到r0中*/
slwi 0,0,2
add 11,9,0
lwz 4,0(11) /*从内存加载数据到r0*/
addi 0,10,-1
slwi 0,0,2 /*将r0左移两位*/
add 11,9,0
lwz 0,0(11)
add 11,4,0
slwi 0,10,2
add 4,9,0
stw 11,0(4)
addi 0,10,1
stw 0,8(31)
cmpwi 7,0,5
ble 7,1b
li 0,0
stw 0,8(31)
b .L2
.L3:
lwz 0,8(31)
lis 9,array@ha
la 9,array@l(9)
slwi 0,0,2
add 9,0,9
lwz 0,0(9)
lis 9,.LC0@ha
la 3,.LC0@l(9)
mr 4,0
crxor 6,6,6
bl printf
lwz 9,8(31)
addi 0,9,1
stw 0,8(31)
.L2:
lwz 0,8(31)
cmpwi 7,0,5
ble 7,.L3
li 0,0
mr 3,0
lwz 11,0(1)
lwz 0,4(11)
mtlr 0
lwz 31,-4(11)
mr 1,11
blr
.size main,.-main
.ident "GCC: (GNU) 4.1.2 20071124 (Red Hat 4.1.2-42)"
.section .note.GNU-stack,"",@progbits
2009年4月28日星期二
使用gdbserver调试arm应用程序
gdbserver的源代码在gdb的源代码包中
ftp://sourceware.org/pub/gdb/releases/gdb-6.8.tar.bz2
2.准备toolchain
使用codesoucery的toolchain
http://www.codesourcery.com/sgpp/lite/arm/portal/package3696/public/arm-none-linux-gnueabi/arm-2008q3-72-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
3.配置gdbserver
在gdb文件下下,能找到gdbserver文件夹
首先声明一个环境变量CC
export CC=YOUR-PATH-OF-GCC/arm-none-linux-gnueabi-gcc
配置
./configure --host=arm-none-linux --target=arm-none-linux
意思是说编译在arm-none-linux上运行的,能执行arm-none-linux目标文件的gdbserver
4.make 编译
就会生成一个gdbserver可执行文件
5.使用gdbserver远程调试应用程序
以串口为例
假设应用程序为hello
在arm板子上的命令行下运行
gdbserver /dev/ttyS0 hello
在开发机上运行
gdb hello
在gdb的提示符下运行
target remote YOUR SERIAL
2009年4月26日星期日
编译busybox1.14.0
http://www.codesourcery.com/sgpp/lite/arm/portal/package3698/public/arm-none-linux-gnueabi/arm-2008q3-72-arm-none-linux-gnueabi.bin
2.在busybox目录下
配置busybox
make menuconfig
配置成静态链接,并指定toolchain路径和前缀
3.make 编译
如果提示dnsd.c lvalue error相关的错误,打下面的补丁给busybox
http://www.busybox.net/downloads/fixes-1.14.0/busybox-1.14.0-unaligned.patch
编译成功后,会生成一个busybox可执行文件
使用qemu和kgdb调试内核
CONFIG_KGDB=y
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_BUGVERBOSE=y
CONFIG_FRAME_POINTER=y
CONFIG_KGDB_SERIAL_CONSOLE=y
2.运行qemu (以versatilepb机器为例)
qemu-system-arm -M versatilepb -kernel arch/arm/boot/zImage -append "kgdboc=ttyAMA0 kgdbwait root=/dev/nfs \
nfsroot=192.168.1.24:/mnt/arm-fs rw ip=dhcp" -net nic,vlan=0 -net tap,vlan=0,script=./qemu-ifup -serial tcp::4444,server
kgdboc选项指定了通过串口用kgdb来调试内核,kgdbwait,等待gdb链接
-serial 选项指定了串口和tcp端口的映射
3.运行gdb
arm-eabi-gdb vmlinux
target remote 主机ip:4444
可以开始调试了。
用qemu通过nfs启动linux
1.设置网络-使qemu能使用开发机的网络
首先确认下开发机的内核时候配置了TUN
grep CONFIG_TUN= /boot/config-`uname -r`
正常的情况下是CONFIG_TUN=m或者=y
2.安装网络配置工具
yum install bridge-utils
3.配置网络
/usr/sbin/brctl addbr br0
/sbin/ifconfig eth0 0.0.0.0 promisc up
/usr/sbin/brctl addif br0 eth0
/sbin/dhclient br0
/sbin/iptables -F FORWARD
4. Fedora 9 配置网络文件系统
假设网络文件系统的目录是/mnt/arm-nfs
在/etc/export内添加如下一条:
/mnt/arm-nfs/ *(rw,sync,no_root_squash)
启动网络文件系统服务
/sbin/service nfs restart
5.准备qemu启动用的脚本,将下面代码保存为qemu-ifup,设置执行模式chmod +x qemu-ifup
#!/bin/sh
/sbin/ifconfig $1 0.0.0.0 promisc up
/usr/sbin/brctl addif br0 $1
6.内核配置
CONFIG_IP_PNP_DHCP=y
CONFIG_TUN=y
CONFIG_AEABI=y
CONFIG_TMPFS=y
7.启动qemu
qemu-system-arm -M YourMachine -kernel zImage root="/dev/nfs nfsroot=<host-ip>:/mnt/YourNFS rw ip=dhcp" \
-net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=./qemu-ifup
2009年4月5日星期日
2009年3月30日星期一
2009年3月18日星期三
ARM Linux 时钟驱动流程
2009年3月14日星期六
使用qemu调试arm linux内核
安装qemu
下载内核文件 这里用2.6.27
建立交叉编译环境。
2.获取编译内核用的config文件
从qemu网站下载测试qemu用的文件http://www.nongnu.org/qemu/linux-user-test-0.3.tar.gz
tar zxvf linux-user-test-0.3.tar.gz
解压后,可以看到3个文件:arm_root.img zImage.integrator README
假设解压后的文件放在 /qemu-test目录下
在内核源代码的根目录下执行
./scripts/extract-ikconfig /qemu-test/zImage.integrator > qemu-linux_defconfig
结束后,将生成一个qemu-linux_defconfig配置文件
3.编译内核
cp qemu-linux_defconfig .config
make zImage
4.用qemu启动内核
qemu-system-arm -kernel zImage -initrd /qemu-test/arm_root.img / -redir tcp:9999::9999 -s -S
5.用gdb调试内核
假设运行qemu的机器的ip地址是192.168.1.5
arm-eabi-gdb vmlinux
在gdb的提示符下运行下面的命令:
target remote 192.168.1.5:1234
这时候就可以调试内核了。
比如设置断点
break start_kernel
查看寄存器
info registers
等等。。。
2009年3月1日星期日
用android build system 编译自己的init
建立一个myinit文件夹
编辑一个init.c文件
代码如下
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int i = 0;
while (1)
{
printf("hello world (%d)",i++);
sleep(2);
}
return 0;
}
另外建立一个Android.mk 文件,内容如下
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
init.c
LOCAL_MODULE:= init
LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED)
LOCAL_STATIC_LIBRARIES := libcutils libc
#LOCAL_STATIC_LIBRARIES := libcutils libc libminui libpixelflinger_static
#LOCAL_STATIC_LIBRARIES += libminzip libunz libamend libmtdutils libmincrypt
#LOCAL_STATIC_LIBRARIES += libstdc++_static
include $(BUILD_EXECUTABLE)
在myinit文件夹下输入mm,
编译系统就会自动输出一个编译好的init程序
输出的路径也会提示出来。
用android build system 编译一个最小的android平台
http://source.android.com/download
这个网站的方法配置系统
然后下载android平台文件
repo init -u git://android.git.kernel.org/platform/manifest.git
repo sync
在平台所在文件夹下运行
. build/envsetup.sh
然后运行
在build/core/main.mk文件中的
ifeq ($SDK_ONLY),true)行前面
添加SDK_ONLY := false
BUILD_TINY_ANDROID := true
保存。
在平台所在文件夹下,运行mm,系统将自动编译整个平台。
所生成的文件的存放路径也会提示出来。
如果提示和libpixelflinger 与hardware_legacy依赖相关的错误,
则修改
Android.mk中的LOCAL_SHARED_LIBRARIES
将hardware_legacy行去掉。
2009年2月26日星期四
在fedora 9上装Cell SDK 3.1
让vim显示行尾的空格
match WhitespaceEOL /\s\+$/
2009年2月25日星期三
2009年2月24日星期二
make xxx Is a directory. Stop. 的原因
2009年2月19日星期四
为linux建立最小的根文件系统
在编译内核时候,可以指定一个文件夹作为内核启动时候的根文件系统,linux中管这个文件系统叫做initramfs。
具体做法如下(以i386为例)
1.下载内核文件
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.26.tar.bz2
2.解压内核
bzip2 -d linux-2.6.26.tar.bz2 生成一个linux-2.6.26.tar文件,然后
tar xvf linux-2.6.26.tar
解压后,将有个linux-2.6.26文件夹存在
3.准备一个iniramfs文件系统的文件夹
在linux-2.6.26文件夹下建立一个文件夹 myinitramfs
写一个测试用的hello world,起名为hello.c,如下:
#include
#include
int main(int argc,char *argv[])
{
int i = 0;
while (1) {
printf("hello world (%d)\n",i);
}
return 0;
}
编译 gcc -static -o init hello.c
把init拷贝到myinitramfs文件夹下。
cp init myinitramfs/
由于需要显示文字,还需要在文件夹下准备console设备文件。
mkdir myinitramfs/dev
cp -a /dev/console myinitramfs/
4.编译内核
在linux-2.6.26文件下下,执行make help。
将看到很多帮助信息,其中有一项是 i386_defconfig
执行 make i386_defconfig,将生成一个.config文件。
为了把之前准备好的文件夹添加到内核配置文件中,还需要重新配置下config文件
make config
在 General Setup --->
Initial RAM filesystem and RAM disk (initramfs/initrd) support (BLK_DEV_INITRD) [Y/n/?]
Initramfs source file(s) (INITRAMFS_SOURCE) [myinitramfs]
处,输入准备好的文件夹.
配置好后,在.config文件中会有如下一条定义
CONFIG_INITRAMFS_SOURCE="myinitramfs"
保存.config
make 编译内核
5.用qemu测试内核和initramfs
qemu -kernel linux-2.6.26/arch/i386/boot/bzImage -initrd linux-2.6.26/usr/initramfs_data.cpio.gz /dev/zero
initramfs_data.cpio.gz 这个文件是内核自动生成的,具体名字可能不同的系统或者内核有差异,但是后缀应该是.cpio.gz