Chinaunix首页 | 论坛 | 博客
  • 博客访问: 717280
  • 博文数量: 182
  • 博客积分: 2088
  • 博客等级: 大尉
  • 技术积分: 1698
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-16 15:09
个人简介

.

文章分类

全部博文(182)

文章存档

2016年(1)

2015年(18)

2014年(14)

2013年(20)

2012年(129)

分类: 嵌入式

2012-06-15 17:07:40

交叉编译环境:mipseltools-gcc-4.1.2
1. 简单配置如下,(其它默认)
BusyBox Setting --->
    Build Option --->
        [ ] Build BusyBox as a static binary (no shared libs)//动态链接,节省空间
        [*] Build shared libbusybox
              [*] Produce a binary for each applet, linked against libbusybox
             [*] Produce addtional busybox binary linked against libbusybox
        [*] Build with Large File Support (for accessing files > 2 GB)
        (mipsel-linux-) Cross Compiler prefix
    Installation Options --->
        [*] Don't use /usr
               Applets links (as soft-links) --->
        (../rootfs) BusyBox installation prefix
2. make
编译过程中出现了一些错误,如下:
错误1:
coreutils/fsync.c: In function ‘fsync_main’:
coreutils/fsync.c:27: error: ‘O_NOATIME’ undeclared (first use in this function)
coreutils/fsync.c:27: error: (Each undeclared identifier is reported only once
coreutils/fsync.c:27: error: for each function it appears in.)
make[1]: *** [coreutils/fsync.o] Error 1
make: *** [coreutils] Error 2
解决:由于在busybox-1.15.2/coreutils/fsyn.c中包含后#include "libbb.h",busybox-1.15.2/include/libbb.h中有包含#include ,在mipseltools-gcc-4.1.2/mipsel-linux/include/fcntl.h中有包含#include ,所以,在交叉编译器mipseltools-gcc-4.1.2/mipsel-linux/include/bits/fcntl.h中添加O_NOATIME宏定义:
           # define O_NOATIME 0x40000 /* Do not set atime. */
错误2:
miscutils/ionice.c: In function ‘ioprio_set’:
miscutils/ionice.c:16: error: ‘SYS_ioprio_set’ undeclared (first use in this function)
miscutils/ionice.c:16: error: (Each undeclared identifier is reported only once
miscutils/ionice.c:16: error: for each function it appears in.)
miscutils/ionice.c: In function ‘ioprio_get’:
miscutils/ionice.c:21: error: ‘SYS_ioprio_get’ undeclared (first use in this function)
make[1]: *** [miscutils/ionice.o] Error 1
make: *** [miscutils] Error 2
解决:在busybox-1.15.2/miscutils/ionice.c内包含有#include 和#include ,在mipseltools-gcc-4.1.2/mipsel-linux/include/sys/syscall.h内包含#include ,所以在mipseltools-gcc-4.1.2/mipsel-linux/include/bits/Syscall.h中添加宏:SYS_ioprio_get和SYS_ioprio_set
#define SYS_ioprio_get __NR_ioprio_get
#define SYS_ioprio_set __NR_ioprio_set
在mipseltools-gcc-4.1.2/mipsel-linux/include/asm/Unistd.h中添加宏:__NR_ioprio_get和__NR_ioprio_set
#define __NR_ioprio_set    (__NR_Linux + 314)
#define __NR_ioprio_get    (__NR_Linux + 315)
错误3:
CC      networking/ifenslave.o
In file included from networking/ifenslave.c:105:
/opt/project/ToolChain/mipseltools-gcc-4.1.2/bin/../lib/gcc/mipsel-linux/4.1.2/../../../../mipsel-linux/include/linux/if_bonding.h:65: error: ‘IFNAMSIZ’ undeclared here (not in a function)networking/ifenslave.c:120: error: field `mtu'' has incomplete type
networking/ifenslave.c:120: error: field `flags'' has incomplete type
networking/ifenslave.c:120: error: field `hwaddr'' has incomplete type
networking/ifenslave.c: In function `set_ifrname_and_do_ioctl'':
networking/ifenslave.c:155: error: dereferencing pointer to incomplete type
networking/ifenslave.c: In function `set_hwaddr'':
networking/ifenslave.c:177: error: storage size of `ifr'' isn''t known
networking/ifenslave.c:177: warning: unused variable `ifr''
networking/ifenslave.c: In function `set_mtu'':
networking/ifenslave.c:185: error: storage size of `ifr'' isn''t known
networking/ifenslave.c:185: warning: unused variable `ifr''
networking/ifenslave.c: In function `set_if_flags'':
networking/ifenslave.c:193: error: storage size of `ifr'' isn''t known
networking/ifenslave.c:193: warning: unused variable `ifr''
networking/ifenslave.c: In function `set_if_up'':
networking/ifenslave.c:201: error: `IFF_UP'' undeclared (first use in this function
)
networking/ifenslave.c:201: error: (Each undeclared identifier is reported only on
ce
networking/ifenslave.c:201: error: for each function it appears in.)
networking/ifenslave.c: In function `set_if_down'':
networking/ifenslave.c:209: error: `IFF_UP'' undeclared (first use in this function
)
networking/ifenslave.c: In function `clear_if_addr'':
networking/ifenslave.c:217: error: storage size of `ifr'' isn''t known
networking/ifenslave.c:217: warning: unused variable `ifr''
networking/ifenslave.c: In function `set_if_addr'':
networking/ifenslave.c:244: error: storage size of `ifr'' isn''t known
networking/ifenslave.c:244: warning: unused variable `ifr''
networking/ifenslave.c: In function `change_active'':
networking/ifenslave.c:266: error: storage size of `ifr'' isn''t known
networking/ifenslave.c:268: error: `IFF_SLAVE'' undeclared (first use in this funct
ion)
networking/ifenslave.c:266: warning: unused variable `ifr''
networking/ifenslave.c: In function `enslave'':
networking/ifenslave.c:285: error: storage size of `ifr'' isn''t known
networking/ifenslave.c:288: error: `IFF_SLAVE'' undeclared (first use in this funct
ion)
networking/ifenslave.c:285: warning: unused variable `ifr''
networking/ifenslave.c: In function `release'':
networking/ifenslave.c:404: error: storage size of `ifr'' isn''t known
networking/ifenslave.c:407: error: `IFF_SLAVE'' undeclared (first use in this funct
ion)
networking/ifenslave.c:404: warning: unused variable `ifr''
networking/ifenslave.c: In function `get_drv_info'':
networking/ifenslave.c:433: error: storage size of `ifr'' isn''t known
networking/ifenslave.c:441: error: `BOND_ABI_VERSION'' undeclared (first use in thi
s function)
networking/ifenslave.c:433: warning: unused variable `ifr''
networking/ifenslave.c: In function `ifenslave_main'':
networking/ifenslave.c:519: error: `IFF_MASTER'' undeclared (first use in this func
tion)
networking/ifenslave.c:523: error: `IFF_UP'' undeclared (first use in this function
)
make[1]: *** [networking/ifenslave.o] Error 1
make: *** [networking] Error 2
解决:在busybox-1.15.2/networking/ifenslave.c内加入#include
在mipseltools-gcc-4.1.2/mipsel-linux/include/linux/if_bonding.h内加入
/* userland - kernel ABI version (2003/05/08) */
#define BOND_ABI_VERSION 2

#ifndef IFNAMSIZ
#define IFNAMSIZ 16
#endif
错误4:
networking/interface.c:818: error: ‘ARPHRD_INFINIBAND’ undeclared here (not in a function)
make[1]: *** [networking/interface.o] Error 1
make: *** [networking] Error 2
解决:在mipseltools-gcc-4.1.2/mipsel-linux/include/linux/net/if_arp.h中添加
#define ARPHRD_INFINIBAND 32   /* InfiniBand. */
3. make install
这样,在rootfs目录下便生成了bin和sbin目录及里面的命令工具和linuxrc文件

4. 在rootfs下新建其他几个目录
4.1 mkdir etc dev lib proc mnt sys tmp usr var(bin and sbin会在make install busybox时会自动生成)
4.2 在dev下执行:
mknod -m 600 dev/console c 5 1
mknod -m 666 dev/null c 1 3

4.3 etc文件夹是许多系统配置文件保存的地方。这些文件非常重要,如果配置错误,就可能影响系统的启动。busybox源代码example/bootfloopy/etc目录中的文件算是一个简单的例子,可以把其中的文件拷贝过来作为基础
在rcS中添加内容(根据项目的实际需要):
# mount filesystems
/bin/mount -t proc /proc /proc
/bin/mount -t sysfs sysfs /sys
/bin/mount -t tmpfs tmpfs /dev
# create necessary devices
/bin/mknod /dev/null c 1 3
/bin/mknod /dev/audio c 14 4
#/bin/mknod /dev/ts c 10 16
#/bin/mknod /dev/mem c 1 1
#/bin/mknod /dev/ram0 b 1 0
#/bin/mknod /dev/fb0 c 29 0
/bin/mknod /dev/console c 5 1
/bin/mknod /dev/tty c 5 0
/bin/mknod /dev/mtdblock2 b 31 2
/bin/mknod /dev/mtdblock3 b 31 3
/bin/mkdir /dev/misc
/bin/mknod /dev/misc/rtc c 10 135
/bin/mknod /dev/misc/cc2500 c 10 158
/bin/mknod /dev/misc/keypad c 10 159
/bin/mknod /dev/tty0 c 4 0
/bin/mknod /dev/dsp c 14 3
/bin/mknod /dev/mixer c 14 0
/bin/mknod /dev/sadc c 238 12
/bin/mknod /dev/misc/pwm c 10 160
/sbin/insmod /lib/modules/jz4740_udc.ko
/sbin/insmod /lib/modules/g_file_storage.ko file=/dev/mtdblock3
/bin/mount -t vfat /dev/mtdblock3 /mnt

4.4 因为是编译的时候使用的是动态链接。所以先看看/busybox/rootfs/bin/busybox使用了哪些lib,然后从mipseltools-gcc-4.1.2复制相应的lib到/rootfs/lib中
$ mipsel-linux-readelf -d busybox
Dynamic section at offset 0x104 contains 26 entries:
Tag        Type                         Name/Value
0x00000001 (NEEDED)                     Shared library: [libm.so.6]
0x00000001 (NEEDED)                     Shared library: [libc.so.6]
0x0000000c (INIT)                       0x40a7c8
0x0000000d (FINI)                       0x50477c
0x00000004 (HASH)                       0x4001fc
0x00000005 (STRTAB)                     0x406b08
0x00000006 (SYMTAB)                     0x4023e8
0x0000000a (STRSZ)                      13147 (bytes)
0x0000000b (SYMENT)                     16 (bytes)
0x70000016 (MIPS_RLD_MAP)               0x566530
0x00000015 (DEBUG)                      0x0
0x00000003 (PLTGOT)                     0x566540
0x00000011 (REL)                        0x0
0x00000012 (RELSZ)                      0 (bytes)
0x00000013 (RELENT)                     8 (bytes)
0x70000001 (MIPS_RLD_VERSION)           1
0x70000005 (MIPS_FLAGS)                 NOTPOT
0x70000006 (MIPS_BASE_ADDRESS)          0x400000
0x7000000a (MIPS_LOCAL_GOTNO)           236
0x70000011 (MIPS_SYMTABNO)              1138
0x70000012 (MIPS_UNREFEXTNO)            35
0x70000013 (MIPS_GOTSYM)                0x7
0x6ffffffe (VERNEED)                    0x40a748
0x6fffffff (VERNEEDNUM)                 2
0x6ffffff0 (VERSYM)                     0x409e64
0x00000000 (NULL)                       0x0
$ cp /opt/project/ToolChain/mipseltools-gcc-4.1.2/mipsel-linux/lib/lib/ld* ./
$ cp /opt/project/ToolChain/mipseltools-gcc-4.1.2/mipsel-linux/lib/libc-2.3.2.so ./
$ cp /opt/project/ToolChain/mipseltools-gcc-4.1.2/mipsel-linux/lib//lib/libc.so.6 ./
$ cp /opt/project/ToolChain/mipseltools-gcc-4.1.2/mipsel-linux/lib//lib/libm * ./
删除所有的静态库文件rm -rf rootfs/lib/*.a
移除所有的符号信息, 压缩库空间mipsel-linux-strip rootfs/lib/*
并在lib目录下新建modules文件夹,在其内添加所需的模块
$ mkdir modules
$ cp Linux2.6.43/.../jz4740_udc.ko ./
$ cp Linux2.6.43/../g_file_storage.ko ./
这样制作好rootfs后,使用工具mkyaffs2image生成yaffs2文件,然后烧录到机器内运行(u-boot,kernel之前已OK)
$ mkyaffs2image 1 rootfs rootfs.yaffs2

4.5 启动运行后,从串口打印can't open /dev/tty2: No such file or directory
原因在于/etc/inittab内的tty2::askfirst:-/bin/sh
顺便修改inittab内容为:
::sysinit:/etc/init.d/rcS
::once:-/bin/sh
::ctrlaltdel:/bin/reboot
::shutdown:/bin/umount -a -r
::shutdown:/bin/swapoff -a
************************************************************************

PS:
错误1:
CC      miscutils/flash_eraseall.o
miscutils/flash_eraseall.c:14:26: error: mtd/mtd-user.h: No such file or directory
miscutils/flash_eraseall.c:15:28: error: mtd/jffs2-user.h: No such file or directory
miscutils/flash_eraseall.c:41: error: expected ‘)’ before ‘*’ token
miscutils/flash_eraseall.c: In function ‘flash_eraseall_main’:
miscutils/flash_eraseall.c:52: error: storage size of ‘cleanmarker’ isn’t known
miscutils/flash_eraseall.c:53: error: ‘mtd_info_t’ undeclared (first use in this function)
miscutils/flash_eraseall.c:53: error: (Each undeclared identifier is reported only once
miscutils/flash_eraseall.c:53: error: for each function it appears in.)
miscutils/flash_eraseall.c:53: error: expected ‘;’ before ‘meminfo’
miscutils/flash_eraseall.c:54: warning: ISO C90 forbids mixed declarations and code
miscutils/flash_eraseall.c:55: error: ‘erase_info_t’ undeclared (first use in this function)
miscutils/flash_eraseall.c:55: error: expected ‘;’ before ‘erase’
miscutils/flash_eraseall.c:56: warning: ISO C90 forbids mixed declarations and code
miscutils/flash_eraseall.c:71: error: ‘MEMGETINFO’ undeclared (first use in this function)
miscutils/flash_eraseall.c:71: error: ‘meminfo’ undeclared (first use in this function)
miscutils/flash_eraseall.c:72: error: ‘erase’ undeclared (first use in this function)
miscutils/flash_eraseall.c:73: error: ‘MTD_NANDFLASH’ undeclared (first use in this function)
miscutils/flash_eraseall.c:83: warning: implicit declaration of function ‘cpu_to_je16’
miscutils/flash_eraseall.c:83: error: ‘JFFS2_MAGIC_BITMASK’ undeclared (first use in this function)
miscutils/flash_eraseall.c:84: error: ‘JFFS2_NODETYPE_CLEANMARKER’ undeclared (first use in this function)
miscutils/flash_eraseall.c:86: warning: implicit declaration of function ‘cpu_to_je32’
miscutils/flash_eraseall.c:86: error: invalid application of ‘sizeof’ to incomplete type ‘struct jffs2_unknown_node’
miscutils/flash_eraseall.c:88: error: storage size of ‘oobinfo’ isn’t known
miscutils/flash_eraseall.c:90: error: ‘MEMGETOOBSEL’ undeclared (first use in this function)
miscutils/flash_eraseall.c:93: error: ‘MTD_NANDECC_AUTOPLACE’ undeclared (first use in this function)
miscutils/flash_eraseall.c:88: warning: unused variable ‘oobinfo’
miscutils/flash_eraseall.c:121: error: invalid application of ‘sizeof’ to incomplete type ‘struct jffs2_unknown_node’
miscutils/flash_eraseall.c:134: error: ‘MEMGETBADBLOCK’ undeclared (first use in this function)
miscutils/flash_eraseall.c:155: warning: implicit declaration of function ‘show_progress’
miscutils/flash_eraseall.c:157: error: ‘MEMERASE’ undeclared (first use in this function)
miscutils/flash_eraseall.c:165: error: storage size of ‘oob’ isn’t known
miscutils/flash_eraseall.c:170: error: ‘MEMWRITEOOB’ undeclared (first use in this function)
miscutils/flash_eraseall.c:165: warning: unused variable ‘oob’
miscutils/flash_eraseall.c:52: warning: unused variable ‘cleanmarker’
make[1]: *** [miscutils/flash_eraseall.o] Error 1
make: *** [miscutils] Error 2
解决:
拷贝内核linux-2.6.24.3\drivers\mtd\mtd-utils\include\mtd文件夹到交叉编译器的include目录
不过还会出现warning:
CC      miscutils/inotifyd.o
miscutils/inotifyd.c: In function ‘inotifyd_main’:
miscutils/inotifyd.c:79: warning: implicit declaration of function ‘inotify_init’
miscutils/inotifyd.c:102: warning: implicit declaration of function ‘inotify_add_watch’
miscutils/inotifyd.c:163: warning: implicit declaration of function ‘inotify_rm_watch’
错误2:
CC      miscutils/inotifyd.o
miscutils/inotifyd.c:31:25: error: sys/inotify.h: No such file or directory
miscutils/inotifyd.c: In function ‘inotifyd_main’:
miscutils/inotifyd.c:79: warning: implicit declaration of function ‘inotify_init’
miscutils/inotifyd.c:102: warning: implicit declaration of function ‘inotify_add_watch’
miscutils/inotifyd.c:144: error: dereferencing pointer to incomplete type
miscutils/inotifyd.c:156: error: dereferencing pointer to incomplete type
miscutils/inotifyd.c:157: error: dereferencing pointer to incomplete type
miscutils/inotifyd.c:157: error: dereferencing pointer to incomplete type
miscutils/inotifyd.c:160: error: dereferencing pointer to incomplete type
miscutils/inotifyd.c:163: warning: implicit declaration of function ‘inotify_rm_watch’
miscutils/inotifyd.c:163: error: dereferencing pointer to incomplete type
miscutils/inotifyd.c:167: error: invalid application of ‘sizeof’ to incomplete type ‘struct inotify_event’
miscutils/inotifyd.c:167: error: dereferencing pointer to incomplete type
make[1]: *** [miscutils/inotifyd.o] Error 1
make: *** [miscutils] Error 2
解决:
拷贝linux-2.6.24.3\include\linux\inotify.h到交叉编译器xxx/include/sys下
最后make ,出现错误如下:
LINK    busybox_unstripped
Trying libraries: crypt m
^Cmake: *** Deleting file `busybox_unstripped'
make: *** [busybox_unstripped] Interrupt
make
LINK    busybox_unstripped
Trying libraries: crypt m
Failed: -Wl,--start-group -lcrypt -lm -Wl,--end-group
Output of:
mipsel-linux-gcc -Wall -Wshadow -Wwrite-strings -Wundef -Wstrict-prototypes -Wunused -Wunused-parameter -Wunused-function -Wunused-value -Wmissing-prototypes -Wmissing-declarations -Wdeclaration-after-statement -Wold-style-definition -fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer -ffunction-sections -fdata-sections -fno-guess-branch-probability -funsigned-char -static-libgcc -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 -Os -fpic -fvisibility=hidden -o busybox_unstripped -Wl,--sort-common -Wl,--sort-section,alignment -Wl,--gc-sections -Wl,--start-group applets/built-in.o archival/lib.a archival/libunarchive/lib.a console-tools/lib.a coreutils/lib.a coreutils/libcoreutils/lib.a debianutils/lib.a e2fsprogs/lib.a editors/lib.a findutils/lib.a init/lib.a libbb/lib.a libpwdgrp/lib.a loginutils/lib.a mailutils/lib.a miscutils/lib.a modutils/lib.a networking/lib.a networking/libiproute/lib.a networking/udhcp/lib.a printutils/lib.a procps/lib.a runit/lib.a selinux/lib.a shell/lib.a sysklogd/lib.a util-linux/lib.a util-linux/volume_id/lib.a archival/built-in.o archival/libunarchive/built-in.o console-tools/built-in.o coreutils/built-in.o coreutils/libcoreutils/built-in.o debianutils/built-in.o e2fsprogs/built-in.o editors/built-in.o findutils/built-in.o init/built-in.o libbb/built-in.o libpwdgrp/built-in.o loginutils/built-in.o mailutils/built-in.o miscutils/built-in.o modutils/built-in.o networking/built-in.o networking/libiproute/built-in.o networking/udhcp/built-in.o printutils/built-in.o procps/built-in.o runit/built-in.o selinux/built-in.o shell/built-in.o sysklogd/built-in.o util-linux/built-in.o util-linux/volume_id/built-in.o -Wl,--end-group -Wl,--start-group -lcrypt -lm -Wl,--end-group
==========
miscutils/lib.a(inotifyd.o): In function `inotifyd_main':
inotifyd.c:(.text.inotifyd_main+0x64): undefined reference to `inotify_init'
inotifyd.c:(.text.inotifyd_main+0x10c): undefined reference to `inotify_add_watch'
inotifyd.c:(.text.inotifyd_main+0x320): undefined reference to `inotify_rm_watch'
collect2: ld returned 1 exit status
make: *** [busybox_unstripped] Error 1
只好将inotifyd项去掉[ ]
阅读(4456) | 评论(0) | 转发(0) |
0

上一篇:ubuntu使用的source.list

下一篇:编译jpeg

给主人留下些什么吧!~~