2010年4月11日星期日

设计多线程安全库

1. 为什么要多线程?
    多线程可以提高系统的性能。更方便实现某些程序模型。

2. posix中的一些线程安全函数如下
        asctime_r, ctime_r, getgrgid_r,getgrnam_r, getpwnam_r,
getpwuid_r, gmtime_r, localtime_r, rand_r, readdir_r, strtok_r

3. 线程安全和可重入例程的特点
线程安全例程是指这个例程即使被多个线程同时调用也不会产生错误的结果。
通常,可以通过一下三种方法来保证线程安全:

3.1 设计成可重入例程
只使用参数和堆栈的例程。   
void test(int *buf) {
           int in_buf[20];
           buf[0] = in_buf[0];
          ....
}
3.2 使用线程局部的数据
使用thread specific data或者Thread local Storage技术的函数
3.3 利用锁技术
spinlock, mutex_lock , ...

4. 非线程安全函数的例子
4.1  libc 中的ctime
返回了全局的静态分配的_tmbuf
struct tm _tmbuf;

/* Return the `struct tm' representation of *T in local time.  */
struct tm *
localtime (t)
     const time_t *t;
{
  return __tz_convert (t, 1, &_tmbuf);
}


2010年4月10日星期六

使用qemu建立简单的ceph分布式文件系统测试环境

1. 下载代码并编译
git clone git://ceph.newdream.net/git/ceph.git
git clone git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client.git

2. 配置服务端环境并启动服务
2.1 添加use_xattr
在/etc/fstab中,找到服务端所在文件系统的位置,添加use_xattr选项。比如
UUID=c0fb46f4-6b8d-41a3-b026-5850b9f51865 / ext3
relatime,user_xattr,errors=remount-ro 0 1
重启系统

2.2 建立文件夹
mkdir -p dev/osd0
mkdir out
mkdir log

2.3 启动ceph服务, ip地址可以根据自己的环境选择
./vstart.sh -n -d -m 192.168.0.100

3. 测试服务端配置
./csyn --syn makedirs 2 2 2
./csyn --syn walk
执行后,应该可以看到很多文件夹和文件

4. 编译linux客户端
4.1 配置
make menuconfig , 在文件系统中选择ceph

5. 启动qemu 加载ceph文件系统
mount -t ceph 192.168.0.100:/ /mnt/ceph
touch abc

6. 验证
./csyn --syn walk
应该可以看到刚刚建立的文件abc

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可以方便监视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编程简介

linux下,framebuffer设备文件名通常是/dev/fb0,1,2等。
控制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的字体处理功能用起来不是很方便,而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主要使用内存的地方是yaffs_object和yaffs_tnode,下面的方法大体上可以估计出使用的
内存数量,但由于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的按条件执行指令的功能

arm的条件执行功能可以避免执行jmp指令,但每条指令都判断一次条件。

和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显示中文

 1. 编译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  编译:
tar jxvf ../src/libpng-1.2.38.tar.bz2
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*
     (3) libjpeg 编译:
                  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 编译:
tar zxvf ../src/directfb_1.2.8.orig.tar.gz
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交叉编译过程

#!/usr/bin/bash

#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 CPPFLAGS="-I/opt/usr/include"
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

用glibc写文件操作的程序时候,如果访问的文件超过一定大小(可能是2GB?),函数可能报
"Value too large for defined data type"错误。

这时候,可以通过调用open64, lseek64函数,可以解决这个问题。

编译时候需要添加下面两个选项:

-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64

2009年7月29日星期三

fedora11 flash插件安装

1.下载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有两种用法,间接调用和直接调用。

间接调用时,连接器会把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 接口时序计算

一般的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

from[http://wiki.netbsd.se/How_to_reduce_libc_size]
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

假设交叉编译器是arm-linux-gcc (4.2.2)
目标机器是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

1.下载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