LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 7275|回复: 16

入门的教程:Getting Familiar with uClinux/ARM 2.6(已翻译)

[复制链接]
发表于 2004-5-17 11:27:31 | 显示全部楼层 |阅读模式
from: http://adam.kaist.ac.kr/~hschoe/ ... _uClinuxARM2_6.html

Getting Familiar with uClinux/ARM 2.6

by Hyok S. Choi <hyok.choi@samsung.com>
the authur and maintainer of uClinux/ARM2.6



Why uClinux/ARM 2.6?
Why do you going to use uClinux? Maybe there would be many reasons to consider the uClinux for your embedded OS. Some of them could be as follows :

Lightweight
You can make a complete linux 2.6 preemptible kernel image include console and some basic device driver and ROMFS under 300KB! (zImage) and the applications in flat-binary format are approximately 30~50% lighter than typical conventional linux ELF binaries, thanks to lighter standard C and C++ libraries.

XIP
With much smaller RAM, you can execute your kernel and even the applications by XIP(eXecution In Place). It could help you to boot up faster, although the access time of the flash or rom for boot image should be fast enough and/or enough cache size. (There could be trade-off between these values if we want to find the optimal balance.)

Cheaper
It is known that the MMU core size in typical ARM SoC wafer is about 30%. In typical network or embedded systems above a half of applications does not need the MMU. Many of RTOS is not use MMU in default, even if target CPU has one.

Full Linux API
You can use the full Linux APIs on your uClinux platform with few exceptions. You can use the pThread in uClibc and the standard system calls. There are plenty of applications which are ported to uClinux in the userland in uclinux distribution package.

Easiar to adapt
One of the interesting feature in nature of uClinux is the possibility of user application to access the whole system, include registers in devices. With a bit of wrapper, we can make the firmware code run on uClinux as a plain application! Of course, you can add some device driver and call the linux system calls and use many open Ips in mixed with the old firmware code. If you're planing of migration of your firmware codes to linux, but you're not familiar with linux system programming, uClinux could be a good starting point. ;-)

Full Linux 2.6 kernel features
Although, it is lighter, it supports almost full features of conventional linux 2.6 kernel, include preemptible kernel feature and so many file-systems, device drivers. Porting of device drivers for conventional linux is handy. Almost all codes are should be compiled without change, except memory mapping from virtual address to physical.

The First Compile Guide
If you decided to make up an uClinux development environment, this is the list that you have to grab on your linux pc :

uClinux distribution
The easiest way to getting started with uClinux is to play with a copy of uClinux-dist from the uClinux.org site at:
http://www.uclinux.org/pub/uClinux/dist/
Note that the kernel version in the distribution may not be the latest. You'll be able to gather the latest patch set and the vanila linux kernel from the kernel.org to make a latest copy of uClinux kernel.
At this time (20040427), the latest distribution is “http://www.uclinux.org/pub/uClin ... 20040408.tar.gz”. If you have some strange trouble with compilation, even if you followed this guide, simply use this distribution for your testing, and update later. :-)

the Kernel and patch
You could find the latest uClinux/ARM kernel patch at:
http://adam.kaist.ac.kr/~hschoe/
At the download section, you'll find the link of latest “linux-2.6.x-hscx.patch.gz” and the original kernel package like:
http://adam.kaist.ac.kr/~hschoe/ ... 2.6.5-hsc2.patch.gz
and
http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.5.tar.bz2

ARM-ELF toolchain
Since the linux 2.6 kernel code uses some new features of newer binutils, you need a newer ARM-ELF toolchain for kernel compilation than the one of uclinux.org. You could find the latest toolchain at the same place with the kernel and patch download section above, and the direct url at current time is :
http://adam.kaist.ac.kr/~hschoe/ ... f-tools-20040427.sh

Hardware Platform or an ARMulator
Of course, you need a platform to run the kernel on. Please refer the notice section which platform is supported. Even if you can not find the one that you have, or if you don't have any hardware platform, you can run a complete kernel on your linux PC! : the ARMulator.
The ARMulator is an GDB based emulator which emulates full Atmel AT91x, arm7tdmi EB01. The url of ARMulator home is :
http://www.uclinux.org/pub/uClinux/utilities/armulator/
You can download directly at this urls:
http://www.uclinux.org/pub/uClin ... tor/gdb-5.0.tar.bz2 (the original gdb-5.0 archive)
http://www.uclinux.org/pub/uClin ... r-20021127.patch.gz (Patches against gdb-5.0)

And another patch if you want to run the kernel with ramdisk on the ARMulator :
http://adam.kaist.ac.kr/~hschoe/ ... k-20040412.patch.gz

That's all for your first compilation.

Okay, Here we go step by step.
(On this guide, the downloaded files are gathered on ~/incoming and the ARMulator is used for platform to run on.)

Install the toolchain

be the root and execute the arm-elf-tools-20040427.sh like:

[root@hyoklinux /]# /bin/sh ~/incoming/arm-elf-tools-20040427.sh

You should see the list of files that is installed. The toolchain binaries for execution are installed to /usr/local/bin. So you need the directory to be included in your search path, usually it is default for common linux distribution like redhat.

Untar the uClinux distribution

On a directory which has enough free available space(about 2GB?), untar the uclinux distribution :
[root@hyoklinux /]# tar -zxvf ~/incoming/uClinux-dist-20040408.tar.gz

Let's look around what we have on the uClinux-dist directory:

[root@hyoklinux /]# cd uClinux-dist/
[root@hyoklinux uClinux-dist]# ls -al
total 104
drwxr-xr-x 15 1000 users 4096 Apr 8 09:27 .
drwxr-xr-x 28 root root 4096 Apr 27 20:32 ..
-rw-r--r-- 1 1000 users 18007 Apr 8 09:13 COPYING
drwxr-xr-x 3 1000 users 4096 Apr 8 09:13 Documentation
-rw-r--r-- 1 1000 users 9305 Apr 8 09:13 Makefile
-rw-r--r-- 1 1000 users 4934 Apr 8 09:13 README
-rw-r--r-- 1 1000 users 1743 Apr 8 09:13 SOURCE
drwxr-xr-x 2 1000 users 4096 Apr 15 15:19 bin
drwxr-xr-x 3 1000 users 4096 Apr 8 09:27 config <-- the configuration files for userland and etc.
drwxr-xr-x 11 1000 users 4096 Apr 8 09:27 freeswan <-- IPsec implementation
drwxr-xr-x 68 1000 users 4096 Apr 8 09:23 glibc <-- Yes, the GNU C library.
drwxr-xr-x 18 1000 users 4096 Apr 8 09:28 lib <-- many libraries ported to uClinux include uC-libc.
drwxr-xr-x 15 1000 users 4096 Apr 8 09:27 linux-2.0.x <-- uClinux 2.0.x kernel
drwxr-xr-x 16 1000 users 4096 Apr 8 09:27 linux-2.4.x <-- uClinux 2.4.x kernel
drwxr-xr-x 18 1000 users 4096 Apr 8 09:27 linux-2.6.x <-- uClinux 2.6.x kernel
drwxr-xr-x 3 1000 users 4096 Apr 8 09:26 tools <-- utilities for romfs install and etc.
drwxr-xr-x 17 1000 users 4096 Apr 8 09:27 uClibc <-- the uClibc, from uclibc.org. Differ to uC-libc.
drwxr-xr-x 174 1000 users 4096 Apr 8 09:27 user <-- the “userland”. The applications that is ported.
drwxr-xr-x 44 1000 users 4096 Apr 8 09:27 vendors <-- the configuration files for each vendor/models.
Make a new linux-2.6.x kernel from the scratch

The kernel version of linux-2.6.x directory in the 20040408 distribution is “linux-2.6.2-uc0”. We need another kernel with newer kernel version for uClinux/ARM 2.6, here.

[root@hyoklinux uClinux-dist]# tar -jxvf ~/incoming/linux-2.6.5.tar.bz2

Now we got the whole linux-2.6.5 codes, and need to patch the kernel.

[root@hyoklinux uClinux-dist]# gzip -dc ~/incoming/linux-2.6.5-hsc2.patch.gz | patch -p0

You should see the codes that patched in some directories that contains “armnommu” string. You can use the directory name “linux-2.6.5” for your uClinux 2.6 kernel directory without further operation. However, I recommend to use the kernel directory name to “linux-2.6.x” because it is more convenient.
So you don't need the linux-2.6.x directory which is included in the uClinux-dist. :

[root@hyoklinux uClinux-dist]# rm -rf linux-2.6.x/

And we rename the newer patched kernel directory to “linux-2.6.x”.

[root@hyoklinux uClinux-dist]# mv linux-2.6.5 linux-2.6.x

Confirm the configuration files

The current uClinux distribution does not contain the proper configuration files for uClinux/ARM 2.6. We need a simple fix-up. The default configuration for ARMulator is at vendors/GDB/ARMulator. We can fix-up the configuration files like this :

[root@hyoklinux uClinux-dist]# cp linux-2.6.x/arch/armnommu/configs/GDB_ARMulator_defconfig vendors/GDB/ARMulator/config.linux-2.6.x

Since we'll use a ramdisk for the rootfs, we need to fix the “rc” in the configuration directory to use ramdisk device number 1.

edit the vendors/GDB/ARMulator/rc to just like :

[root@hyoklinux uClinux-dist]# vim vendors/GDB/ARMulator/rc

hostname GDB-ARMulator
/bin/expand /etc/ramfs.img /dev/ram1
mount -t proc proc /proc
mount -t ext2 /dev/ram1 /var
mkdir /var/tmp
mkdir /var/log
mkdir /var/run
mkdir /var/lock
mkdir /var/empty
cat /etc/motd
Distribution Configuration

We need setup the configuration for kernel and user applications.

[root@hyoklinux uClinux-dist]# make menuconfig

At the first Main Menu, Select the “Vendor/Product Selection”.
And Select “GDB” for the “Vendor”, and “ARMulator” for the “GDB Products” like :

--- Select the Vendor you wish to target
(GDB) Vendor
--- Select the Product you wish to target
(ARMulator) GDB Products
You can go back to main menu with 'esc' key or “Exit” button.

At the Main Menu, Select the “Kernel/Library/Defaults Selection”.
And Select “linux-2.6.x” for the “Kernel Version”, and “uClibc” for the “Libc version”.
And toggle the whole below menus :

(linux-2.6.x) Kernel Version
(uClibc) Libc Version
  • Default all settings (lose changes) (NEW)
  • Customize Kernel Settings (NEW)
  • Customize Vendor/User Settings (NEW)
  • Update Default Vendor Settings (NEW)

    You can go back to main menu with 'esc' key or “Exit” button.

    With the first “default all settings”, the configration files in the vendors directory is loaded. And with the second “Customize kernel settings”, we can edit the kernel configration. The thrid “Customize Vendor/User settings” is for configuration of applications and libraries configuration for making the romfs.img which will be the rootfs of the kernel. With the final “Update Default Vendor settings”, your changes on the kernel and user application configuration will be saved on the vendors/product directory.

    You can go back to main menu with 'esc' key or “Exit” button, and do again for save dialog. And save it!

    Kernel Configuration

    If you followed the steps in “confirm the configuration files” above, your kernel should get configured.

    However, we need to change the initial ramdisk size. Because the romfs.img size with the default applications are about 771KB. In “General setup” menu, there is “Default kernel command string”. Change this to:

    root=/dev/ram0 initrd=0x01300000,800K keepinitrd
    You can go back to main menu with 'esc' key or “Exit” button, and do again for save dialog. And save it!

    Application/library Configuration

    On this menu, we don't need fix anything for now.

    Look around the configurations and simply “exit” and save.

    Make

    We are ready to make the whole bunch. Simply type:

    [root@hyoklinux uClinux-dist]# make

    For linux-2.4.x, you should do “make dep” before “make”. But linux-2.6.x don't need to.

    It will compile the whole kernel and uclibc, user applications, and make the romfs.img.

    The results

    You should get the files in the image directory like:

    [root@hyoklinux uClinux-dist]# ls -al images

    total 3036
    drwxr-xr-x 2 root root 4096 Apr 27 22:13 .
    drwxr-xr-x 17 1000 users 4096 Apr 27 22:13 ..
    -rw-r--r-- 1 root root 1540272 Apr 27 22:13 image.bin
    -rwxr-xr-x 1 root root 45912 Apr 27 22:13 linux.data
    -rwxr-xr-x 1 root root 704856 Apr 27 22:13 linux.text
    -rw-r--r-- 1 root root 789504 Apr 27 22:13 romfs.img




    [root@hyoklinux uClinux-dist]# ls -al linux-2.6.x/linux

    -rwxr-xr-x 2 root root 15499433 Apr 27 22:11 linux-2.6.x/linux
    If you got the same files, you've the whole kernel and rootfs image.

    Let's play with it with ARMulator!

    ARMulator installation

    We need another directory to compile the GDB/ARMulator. However, this time, I'll install it in the uClinux-dist directory for temporary usage.

    [root@hyoklinux uClinux-dist]# tar -jxvf ~/incoming/gdb-5.0.tar.bz2

    and patch it!

    [root@hyoklinux uClinux-dist]# gzip -dc ~/incoming/gdb-5.0-uclinux-armulator-20021127.patch.gz | patch -p0

    and another one.

    [root@hyoklinux uClinux-dist]# gzip -dc ~/incoming/gdb-5.0-uclinux-armulator-ramdisk-20040412.patch.gz | patch -p0

    okay, the codes are ready for compilation. Let's make it.

    [root@hyoklinux uClinux-dist]# cd gdb-5.0/
    [root@hyoklinux gdb-5.0]# ./configure ?target=arm-elf
    [root@hyoklinux gdb-5.0]# make
    [root@hyoklinux gdb-5.0]# make install (be the root before this)


    Running the ARMulator

    Before run the ARMulator, we need a symbolic link to the rootfs image, “romfs.img”.

    [root@hyoklinux gdb-5.0]# cd ..
    [root@hyoklinux uClinux-dist]# ln -s images/romfs.img boot.rom

    and if we make this initial script for GDB, it's convenient.

    [root@hyoklinux uClinux-dist]# cat > .gdbinit
    target sim
    load
    ^D

    That's all for our first kernel running. Let's do it!

    [root@hyoklinux uClinux-dist]# arm-elf-gdb linux-2.6.x/linux

    GNU gdb 5.0
    Copyright 2000 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB. Type "show warranty" for details.
    This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-elf"...
    Loaded ROM boot.rom to 0x01300000
    Loaded ROM boot.rom to 0x01400000
    Loaded ROM boot.rom to 0x04000000
    Loaded ROM boot.rom to 0x01300000
    Loaded ROM boot.rom to 0x01400000
    Loaded ROM boot.rom to 0x04000000
    Connected to the simulator.
    Loading section .init, size 0xb000 vma 0x1000000
    Loading section .text, size 0xa0b98 vma 0x100b000
    Loading section __ex_table, size 0x5b8 vma 0x10abba0
    Loading section .data, size 0x8ef8 vma 0x10ae000
    Start address 0x1000000
    Transfer rate: 5931584 bits in <1 sec.
    (gdb) run
    Starting program: /uClinux-dist/linux-2.6.x/linux
    Linux version 2.6.5-hsc1 (root@hyoklinux) (gcc version 2.95.3 20010315 (release)(ColdFire patches - 20010318 from http://fiddes.net/coldfire/)(uClinux XIP and shared lib patches from http://www.snapgear.com/)) #9 Mon May 3 11:00:29 KST 2004
    CPU: Atmel-AT91M40xxx [14000040] revision 0 (ARMvundefined/unknown)
    Machine: ATMEL EB01
    On node 0 totalpages: 1024
    DMA zone: 0 pages, LIFO batch:1
    Normal zone: 1024 pages, LIFO batch:1
    HighMem zone: 0 pages, LIFO batch:1
    Built 1 zonelists
    Kernel command line: root=/dev/ram0 initrd=0x01300000,800K keepinitrd
    PID hash table entries: 32 (order 5: 256 bytes)
    Memory: 4MB = 4MB total
    Memory: 2448KB available (642K code, 92K data, 44K init)
    Calibrating delay loop... 15.87 BogoMIPS
    Dentry cache hash table entries: 1024 (order: 0, 4096 bytes)
    Inode-cache hash table entries: 1024 (order: 0, 4096 bytes)
    Mount-cache hash table entries: 512 (order: 0, 4096 bytes)
    checking if image is initramfs...it isn't (ungzip failed); looks like an initrd
    POSIX conformance testing by UNIFIX
    Linux NoNET1.0 for Linux 2.6
    Atmel USART driver version 0.99
    ttyS0 at 0xfffd0000 (irq = 2) is a builtin Atmel APB USART
    ttyS1 at 0xfffcc000 (irq = 3) is a builtin Atmel APB USART
    RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize
    loop: loaded (max 8 devices)
    RAMDISK: romfs filesystem found at block 0
    RAMDISK: Loading 771 blocks [1 disk] into ram disk... done.
    VFS: Mounted root (romfs filesystem) readonly.
    Freeing init memory: 44K
    Shell invoked to run file: /etc/rc
    Command: hostname GDB-ARMulator
    Command: /bin/expand /etc/ramfs.img /dev/ram1
    Command: mount -t proc proc /proc
    Command: mount -t ext2 /dev/ram1 /var
    Command: mkdir /var/tmp
    Command: mkdir /var/log
    Command: mkdir /var/run
    Command: mkdir /var/lock
    Command: mkdir /var/empty
    Command: cat /etc/motd
    Welcome to
    ____ _ _
    / __| ||_|
    _ _| | | | _ ____ _ _ _ _
    | | | | | | || | _ \| | | |\ \/ /
    | |_| | |__| || | | | | |_| |/ \
    | ___\____|_||_|_| |_|\____|\_/\_/
    | |
    |_|


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


    Execution Finished, Exiting


    Sash command shell (version 1.1.1)
    /> ps
    PID PORT STAT SIZE SHARED %CPU COMMAND
    1 S 163K 0K 48.0 /sbin/init
    2 S 0K 0K 0.0 ksoftirqd/0
    3 S 0K 0K 1.0 events/0
    4 S 0K 0K 0.0 kblockd/0
    5 S 0K 0K 0.0 pdflush
    6 S 0K 0K 0.0 pdflush
    7 S 0K 0K 0.0 kswapd0
    8 S 0K 0K 0.0 aio/0
    11 S0 R 165K 0K 0.0 /bin/sh
    /> cd bin
    /bin> ls -al
    drwxr-xr-x 1 0 0 32 Jan 1 00:00 .
    drwxr-xr-x 1 0 0 32 Jan 1 00:00 ..
    -rwxr-xr-x 1 0 0 105980 Jan 1 00:00 boa
    -rwxr-xr-x 1 0 0 91104 Jan 1 00:00 dhcpcd
    -rwxr-xr-x 1 0 0 29624 Jan 1 00:00 expand
    -rwxr-xr-x 1 0 0 40504 Jan 1 00:00 gdbserver
    -rwxr-xr-x 1 0 0 73748 Jan 1 00:00 ifconfig
    -rwxr-xr-x 1 0 0 41144 Jan 1 00:00 inetd
    -rwxr-xr-x 1 0 0 31176 Jan 1 00:00 init
    -rwxr-xr-x 1 0 0 56380 Jan 1 00:00 login
    -rwxr-xr-x 1 0 0 64656 Jan 1 00:00 ping
    -rwxr-xr-x 1 0 0 34280 Jan 1 00:00 reboot
    -rwxr-xr-x 1 0 0 73860 Jan 1 00:00 route
    -rwxr-xr-x 1 0 0 79852 Jan 1 00:00 sh
    -rwxr-xr-x 1 0 0 51216 Jan 1 00:00 telnetd
    /bin> cat /proc/meminfo
    MemTotal: 2516 kB
    MemFree: 560 kB
    Buffers: 900 kB
    Cached: 188 kB
    SwapCached: 0 kB
    Active: 984 kB
    Inactive: 44 kB
    HighTotal: 0 kB
    HighFree: 0 kB
    LowTotal: 2516 kB
    LowFree: 560 kB
    SwapTotal: 0 kB
    SwapFree: 0 kB
    Dirty: 0 kB
    Writeback: 0 kB
    Mapped: 0 kB
    Slab: 752 kB
    Committed_AS: 0 kB
    PageTables: 0 kB
    VmallocTotal: 4194303 kB
    VmallocUsed: 0 kB
    VmallocChunk: 4194303 kB
    /bin>
    1. Getting Familiar with uClinux/ARM 2.6
    复制代码
  • 发表于 2004-5-24 13:26:10 | 显示全部楼层
    觉得蓝底色读起比较舒服一些!
    发表于 2004-5-25 21:18:04 | 显示全部楼层

    获取常见的uClinux/ARM 2.6

    原文出自:http://adam.kaist.ac.kr/~hschoe/ ... _uClinuxARM2_6.html

    作者:Hyok S.Choi <hyok.choi@samsung.com>

    翻译:renbagshoes <renbagshes12@yahoo.com.cn>
    转载请注明www.linuxsir.cn,谢谢!

    一、使用uClinux/ARM 2.6的原因?
    为什么你要使用uClinux?有很多的理由使uClinux做为你的嵌入式操作系统。其中大部分认为uClinux有以下好处:

    轻便
    你可以编译linux2.6的内核得到一个300k以下的内核镜像,它包括终端和一些基本的设备驱动以及只读文件系统。并且flat格式的二进制zImage和应用程序要比linux传统使用的ELF二进制小30%--50%,由于使用了较少的标准的C和C++库。

    XIP(execution in place)
    你能通过XIP来在一个较小的RAM时执行你的内核镜像,甚至是应用程序。它能帮助你快速的启动,尽管flash的存取时间或是rom启动镜像足够快以及有足够的缓存大小。(如果我们想找到它们最优化的平衡点,可以交换两者之间这些变量。)

    便宜
    MMU(内存管理单元)核心大小大约占典型的ARM SoC(System-on-Chip单片机)wafer(晶体)的30%。在典型的网络和嵌入式系统里有一半以上的应用程序不需要MMU。甚至如果只有一个CPU的许多RTOS(实时操作系统)在默认情况下也不使用MMU。

    完全的Linux应用程序接口
    除少数情况外,你可以在uClinux平台上完全使用Linux应用程序接口。你能在uClibc里使用多线程以及使用标准的系统调用。在用户盘里的uClinux发布包里有大量的应用程序
    被移植到了uClinux系统上。

    Easiar to adapt
    在uClinux性能里有一个有趣的特性,是应用程序可以访问整个系统,包括设备里的寄存器,with a bit of wrapper ,我们能 制作固件代码做为无格式的 应用程序运 行在 uClinux上!当然,你能加一些设备驱动和系统调用来调用以及使用许多打开的Ips在混和的旧的固件代码里。如果你计划移动你的固件代码到linux,但你没有熟悉的linux系统程序,uClinux是一个很好的出发点;-)

    完全的linux2.6内核的特性
    尽管uClinux很小,但它支持linux2.6内核约定的全部的特性,包括内核优先级特性以及许多的文件系统,设备驱动。为linux约定设备驱动端口是容易实现的。几乎所有的代码不需要改变就可以编译,除了从虚拟地址到物理的内存镜像外。

    注:上面的部分由于涉及的概念太多,翻译的不大好,请大家指正,谢谢。

    二、初次编译uClinux/ARM2.6指南
    如果你决定使用uClinux做为开发环境,那么下面的部分将会让uClinux运行在你的linux PC机上:

    1、获得uClinux发布包
    一个最容易得到uClinux的发布包的方法是直接访问uClinux.org站点:
    http://www.uclinux.org/pub/uClinux/dist/

    注意这里发布的内核版本可能不是最新的,但你能找到一个最新的补丁以及从kernel.org站点上找一个对应的linux内核版本来制作一个最新的uClinux内核。此时(2004年05月25日)可从“http://www.uclinux.org/pub/uClinux/dist”获得最新的发布包的版本是uClinux-dist.20040408.tar.gz。如果你对编译软件不是很熟悉,那么根据这个指南你将会很容易的使用这个分布包来制作你的uClinux内核或是升级它到最新的版本。

    2、获得最新的内核及补丁
    你能到这里找到最新的uClinux/ARM内核补丁:

    http://adam.kaist.ac.kr/~hschoe/

    在下载的部分,你将会找到“linux-2.6.x-hscx.patch.gz”最新的链接,以及原始的内核包:

    http://adam.kaist.ac.kr/~hschoe/ ... 2.6.5-hsc2.patch.gz

    http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.5.tar.bz2

    3、ARM-ELF工具链
    从linux2.6内核代码使用了一些更新的binutils新特性以来,你需要一个比uclinux.org站点上更新的ARM-ELF工具链来编译内核。你能够从上面的与下载内核和补丁相同的download部分找到最新的工具链,就在当前的链接下:

    http://adam.kaist.ac.kr/~hschoe/ ... f-tools-20040427.sh

    4、硬件平台或是一个ARMulator(ARM仿真)
    当然你需要一个平台来运行uClinux内核,请首先看一下注意事项里有那些平台被支持。即使你不能找到适用于你的平台,或是你没有任何的硬件平台,那你也能在你的linux PC机上运行这个内核:使用ARMulator(ARM仿真)。ARMulator是一个以GDB调试器为基础的仿 真,这个仿真完全支持Atmel AT91x和arm7tdmi EB01。ARMulator的主页在这:

    http://www.uclinux.org/pub/uClinux/utilities/armulator/

    你也能直接从这里下载:

    http://www.uclinux.org/pub/uClin ... tor/gdb-5.0.tar.bz2(原始gdb-5.0包)
    http://www.uclinux.org/pub/uClin ... r-20021127.patch.gz(gdb-5.0所依赖的补丁)

    如果你想在ARMulator上运行内核的ramdisk(虚拟磁盘),那么你就需要从这下载另外一个软件包:

    http://adam.kaist.ac.kr/~hschoe/ ... k-20040412.patch.gz


    5、如果你是初次编译这些发布包的话,OK!从这我们将会一步一步的进行
    (现在把上面所下载的软件包都发在/root/incoming目录里)
    (On this guide, the downloaded files are gathered on ~/incoming and the ARMulator is used for platform to run on.)

    6、安装工具链
    以root用户来执行arm-elf-tools-20040427.sh,像这样:

    [root@hyoklinux /]#/bin/sh ~/incoming/arm-elf-tools-20040427.sh

    注:~是你的root用户目录,当然也可以选择别的目录,但这取决于你的第5步所设置的目录。

    你将看到被安装文件的列表,这个工具链的可执行的二进制文件被安装到了/usr/local/bin目录里,所以你的环境变量的搜索路径应包括这个目录,通常使用的发行版像redhat等已经将这个路径包括在$PATH变量里,可以用下面的命令查看一下:

    [root@hyoklinux /]#echo $PATH

    7、释放uClinux发布包
    在一个有2GB空间的目录里来释放uclinux发布包

    [root@hyoklinux /]# tar -zxvf ~/incoming/uClinux-dist-20040408.tar.gz

    让我们看看uClinux-dist目录里有什么文件

    [root@hyoklinux /]# cd uClinux-dist/
    [root@hyoklinux uClinux-dist]# ls -al
    total 104
    drwxr-xr-x 15 1000 users 4096 Apr 8 09:27 .
    drwxr-xr-x 28 root root 4096 Apr 27 20:32 ..
    -rw-r--r-- 1 1000 users 18007 Apr 8 09:13 COPYING
    drwxr-xr-x 3 1000 users 4096 Apr 8 09:13 Documentation
    -rw-r--r-- 1 1000 users 9305 Apr 8 09:13 Makefile
    -rw-r--r-- 1 1000 users 4934 Apr 8 09:13 README
    -rw-r--r-- 1 1000 users 1743 Apr 8 09:13 SOURCE
    drwxr-xr-x 2 1000 users 4096 Apr 15 15:19 bin
    drwxr-xr-x 3 1000 users 4096 Apr 8 09:27 config <-- 为本地用户提供的配置文件以及其它的
    drwxr-xr-x 11 1000 users 4096 Apr 8 09:27 freeswan <-- IPsec的实现
    drwxr-xr-x 68 1000 users 4096 Apr 8 09:23 glibc <-- GNU C库
    drwxr-xr-x 18 1000 users 4096 Apr 8 09:28 lib <-- 许多移植到uClinux的库,包括uC-libc.
    drwxr-xr-x 15 1000 users 4096 Apr 8 09:27 linux-2.0.x <-- uClinux 2.0.x kernel
    drwxr-xr-x 16 1000 users 4096 Apr 8 09:27 linux-2.4.x <-- uClinux 2.4.x kernel
    drwxr-xr-x 18 1000 users 4096 Apr 8 09:27 linux-2.6.x <-- uClinux 2.6.x kernel
    drwxr-xr-x 3 1000 users 4096 Apr 8 09:26 tools <-- 安装romfs提供的程序以及其它的
    drwxr-xr-x 17 1000 users 4096 Apr 8 09:27 uClibc <-- uClibc可从uclibc.org找到,与uC-libc不同.
    drwxr-xr-x 174 1000 users 4096 Apr 8 09:27 user <-- the“userland”被移植的应用程序
    drwxr-xr-x 44 1000 users 4096 Apr 8 09:27 vendors <-- 每一个vendor/models的配置文件

    注:vendor(计算机销售商)
        models(模型)

    8、用这些文件制作出一个新的linux-2.6.x内核

    在20040408发布包目录里的linux-2.6.x是由内核“linux-2.6.2”和补丁“linux-2.6.2-uc0”生成的。而uClinux/ARM2.6需要更新的内核版本(如linux-2.6.5 + linux-2.6.5-hsc2.patch)。

    [root@hyoklinux uClinux-dist]# tar -jxvf ~/incoming/linux-2.6.5.tar.bz2

    现在我们得到了整个的linux-2.6.5源代码,以及所需的内核补丁。

    [root@hyoklinux uClinux-dist]# gzip -dc ~/incoming/linux-2.6.5-hsc2.patch.gz | patch -p0

    运行上面的命令后,你将会看到一些补丁目录里包含有“armnommu”的字符串的代码。你可以在你的uClinux 2.6内核里使用“linux-2.6.5”的目录名,这不是必需的。然而,我觉得使用“linux-2.6.x”这个名字会更方便些。

    因此你现在不需要原来uClinux目录里的linux-2.6.x(即那个linux-2.6.2-uc0),执行:

    [root@hyoklinux uClinux-dist]# rm -rf linux-2.6.x/

    然后我们将重命名更新补丁的内核目录名为“linux-2.6.x”,执行:

    [root@hyoklinux uClinux-dist]# mv linux-2.6.5 linux-2.6.x

    9、确定配置文件

    当前的uClinux发布包不包含有关于uClinux/ARM2.6完整的配置文件。我们需要简单的修改一下,ARMulator默认的配置文件在vendors/GDB/ARMulator目录下面。我们能像下面这样来修改它:

    [root@hyoklinux uClinux-dist]# cp linux-2.6.x/arch/armnommu/configs/GDB_ARMulator_defconfig \ vendors/GDB/ARMulator/config.linux-2.6.x

    为了rootfs能使用ramdisk,我们需要修改一下配置目录里的“rc”这个文件,这样就可以使用1号的ramdisk设备了。
    (原文:Since we'll use a ramdisk for the rootfs, we need to fix the “rc” in the configuration directory to use ramdisk device number 1)

    像下面这样编辑vendors/GDB/ARMulator/rc这个文件:
    [root@hyoklinux uClinux-dist]# vim vendors/GDB/ARMulator/rc

    hostname GDB-ARMulator
    /bin/expand /etc/ramfs.img /dev/ram1
    mount -t proc proc /proc
    mount -t ext2 /dev/ram1 /var
    mkdir /var/tmp
    mkdir /var/log
    mkdir /var/run
    mkdir /var/lock
    mkdir /var/empty
    cat /etc/motd


    10、配置内核和安装用户应用程序

    [root@hyoklinux uClinux-dist]# make menuconfig

    首先在“Main Menu”找到“Vendor/Product”所在行,选择“GDB/ARMulator”,像这样:

    --- Select the Vendor you wish to target
    (GDB) Vendor
    --- Select the Product you wish to target
    (ARMulator) GDB Products

    你可以按'esc'键或是“Exit”按钮返回主菜单。

    在主菜单选择“Kernel/Library/Defaults选项”。
    选择内核版本为“linux-2.6.x”,以及选择使用的库为“uClibc”。
    切换到下面的菜单:

    (linux-2.6.x) Kernel Version
    (uClibc) Libc Version
  • Default all settings (lose changes) (NEW)
  • Customize Kernel Settings (NEW)
  • Customize Vendor/User Settings (NEW)
  • Update Default Vendor Settings (NEW)

    你可以按'esc'键或是“Exit”按钮返回主菜单。


    第一个“default all settings”选项是vendors目录里默认的配置文件。第二个“Customize kernel settings”选项能让我们编辑内核配置。第三个“Customize Vendor/User settings”选项是为了生成romfs.img所需要配置应用程序和库。最后一“Update Default Vendor settings”项,你对内核的改变以及你所配置的应用程序将保存在vendors/product的目录里。

    你可以按'esc'键或是“Exit”按钮返回主菜单,然后保存并退出!

    11、配置内核
    如果你确认了上面的配置过程,那么你可以得到一个配置文件。然而我们需要改变初始的ramdis的大小。因为romfs.img文件的大小在默认情况下大约是771KB。在“一般设置(General setup)”菜单里,有“Default kernel command string”这一项,这样改变它:

    root=/dev/ram0 initrd=0x01300000,800K keepinitrd

    你可以按'esc'键或是“Exit”按钮返回主菜单,然后保存并退出!

    程序/库的配置

    在这个菜单上,我们不需要修改任何的设置,看一下配置按“exit”保存并退出!


    现在我们运行下面的这步来进行整个的编译过程:

    [root@hyoklinux uClinux-dist]# make

    注:如果是编译linux-2.4.x或是以下的版本的内核,你在“make”之前还需要“make dep”这一步,但是在编译linux-2.6.x的内核时就不需要了。

    这一步将编译整个内核和uclibc(uClinux的系统库),用户程序,以及制作romfs.img文件。


    下面是结果,你可以像下面这样查看image目录里的文件:

    [root@hyoklinux uClinux-dist]# ls -al images
    total 3036
    drwxr-xr-x 2 root root 4096 Apr 27 22:13 .
    drwxr-xr-x 17 1000 users 4096 Apr 27 22:13 ..
    -rw-r--r-- 1 root root 1540272 Apr 27 22:13 image.bin
    -rwxr-xr-x 1 root root 45912 Apr 27 22:13 linux.data
    -rwxr-xr-x 1 root root 704856 Apr 27 22:13 linux.text
    -rw-r--r-- 1 root root 789504 Apr 27 22:13 romfs.img

    [root@hyoklinux uClinux-dist]# ls -al linux-2.6.x/linux
    -rwxr-xr-x 2 root root 15499433 Apr 27 22:11 linux-2.6.x/linux

    如果你得到了相同的文件,那么你就有了整个内核和rootfs镜像。


    12、让我们来使用ARMulator!

    安装ARMulator,我们需要另外一个目录来编译GDB/ARMulator。然而这时我们将在uClinux-dist的临时使用的目录里安装它。

    [root@hyoklinux uClinux-dist]# tar -jxvf ~/incoming/gdb-5.0.tar.bz2

    打上补丁:

    [root@hyoklinux uClinux-dist]# gzip -dc ~/incoming/gdb-5.0-uclinux-armulator-20021127.patch.gz | patch -p0

    执行另外的一步:

    [root@hyoklinux uClinux-dist]# gzip -dc ~/incoming/gdb-5.0-uclinux-armulator-ramdisk-20040412.patch.gz | patch -p0

    好,现在所要编译的代码已经准备好了,让我们执行它:

    [root@hyoklinux uClinux-dist]# cd gdb-5.0/
    [root@hyoklinux gdb-5.0]# ./configure --target=arm-elf
    [root@hyoklinux gdb-5.0]# make
    [root@hyoklinux gdb-5.0]# make install

    现在可以运行ARMulator了!

    在运行ARMulator之前,我们需要一个能链接到镜像文件“romfs.img”的标志。

    [root@hyoklinux gdb-5.0]# cd ..
    [root@hyoklinux uClinux-dist]# ln -s images/romfs.img boot.rom

    以及制作一个初始化GDB的脚本:

    [root@hyoklinux uClinux-dist]# cat > .gdbinit
    target sim
    load
    ^D


    通过下面的命令,就可以运行我们的内核了。

    [root@hyoklinux uClinux-dist]# arm-elf-gdb linux-2.6.x/linux

    GNU gdb 5.0
    Copyright 2000 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB. Type "show warranty" for details.
    This GDB was configured as "--host=i686-pc-linux-gnu --target=arm-elf"...
    Loaded ROM boot.rom to 0x01300000
    Loaded ROM boot.rom to 0x01400000
    Loaded ROM boot.rom to 0x04000000
    Loaded ROM boot.rom to 0x01300000
    Loaded ROM boot.rom to 0x01400000
    Loaded ROM boot.rom to 0x04000000
    Connected to the simulator.
    Loading section .init, size 0xb000 vma 0x1000000
    Loading section .text, size 0xa0b98 vma 0x100b000
    Loading section __ex_table, size 0x5b8 vma 0x10abba0
    Loading section .data, size 0x8ef8 vma 0x10ae000
    Start address 0x1000000
    Transfer rate: 5931584 bits in <1 sec.

    (gdb) run

    Starting program: /uClinux-dist/linux-2.6.x/linux
    Linux version 2.6.5-hsc1 (root@hyoklinux) (gcc version 2.95.3 20010315 (release)(ColdFire patches - 20010318 from http://fiddes.net/coldfire/)(uClinux XIP and shared lib patches from http://www.snapgear.com/)) #9 Mon May 3 11:00:29 KST 2004
    CPU: Atmel-AT91M40xxx [14000040] revision 0 (ARMvundefined/unknown)
    Machine: ATMEL EB01
    On node 0 totalpages: 1024
    DMA zone: 0 pages, LIFO batch:1
    Normal zone: 1024 pages, LIFO batch:1
    HighMem zone: 0 pages, LIFO batch:1
    Built 1 zonelists
    Kernel command line: root=/dev/ram0 initrd=0x01300000,800K keepinitrd
    PID hash table entries: 32 (order 5: 256 bytes)
    Memory: 4MB = 4MB total
    Memory: 2448KB available (642K code, 92K data, 44K init)
    Calibrating delay loop... 15.87 BogoMIPS
    Dentry cache hash table entries: 1024 (order: 0, 4096 bytes)
    Inode-cache hash table entries: 1024 (order: 0, 4096 bytes)
    Mount-cache hash table entries: 512 (order: 0, 4096 bytes)
    checking if image is initramfs...it isn't (ungzip failed); looks like an initrd
    POSIX conformance testing by UNIFIX
    Linux NoNET1.0 for Linux 2.6
    Atmel USART driver version 0.99
    ttyS0 at 0xfffd0000 (irq = 2) is a builtin Atmel APB USART
    ttyS1 at 0xfffcc000 (irq = 3) is a builtin Atmel APB USART
    RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize
    loop: loaded (max 8 devices)
    RAMDISK: romfs filesystem found at block 0
    RAMDISK: Loading 771 blocks [1 disk] into ram disk... done.
    VFS: Mounted root (romfs filesystem) readonly.
    Freeing init memory: 44K
    Shell invoked to run file: /etc/rc
    Command: hostname GDB-ARMulator
    Command: /bin/expand /etc/ramfs.img /dev/ram1
    Command: mount -t proc proc /proc
    Command: mount -t ext2 /dev/ram1 /var
    Command: mkdir /var/tmp
    Command: mkdir /var/log
    Command: mkdir /var/run
    Command: mkdir /var/lock
    Command: mkdir /var/empty
    Command: cat /etc/motd
    Welcome to
    ____ _ _
    / __| ||_|
    _ _| | | | _ ____ _ _ _ _
    | | | | | | || | _ \| | | |\ \/ /
    | |_| | |__| || | | | | |_| |/ \
    | ___\____|_||_|_| |_|\____|\_/\_/
    | |
    |_|


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


    Execution Finished, Exiting


    Sash command shell (version 1.1.1)
    /> ps
    PID PORT STAT SIZE SHARED %CPU COMMAND
    1 S 163K 0K 48.0 /sbin/init
    2 S 0K 0K 0.0 ksoftirqd/0
    3 S 0K 0K 1.0 events/0
    4 S 0K 0K 0.0 kblockd/0
    5 S 0K 0K 0.0 pdflush
    6 S 0K 0K 0.0 pdflush
    7 S 0K 0K 0.0 kswapd0
    8 S 0K 0K 0.0 aio/0
    11 S0 R 165K 0K 0.0 /bin/sh
    /> cd bin
    /bin> ls -al
    drwxr-xr-x 1 0 0 32 Jan 1 00:00 .
    drwxr-xr-x 1 0 0 32 Jan 1 00:00 ..
    -rwxr-xr-x 1 0 0 105980 Jan 1 00:00 boa
    -rwxr-xr-x 1 0 0 91104 Jan 1 00:00 dhcpcd
    -rwxr-xr-x 1 0 0 29624 Jan 1 00:00 expand
    -rwxr-xr-x 1 0 0 40504 Jan 1 00:00 gdbserver
    -rwxr-xr-x 1 0 0 73748 Jan 1 00:00 ifconfig
    -rwxr-xr-x 1 0 0 41144 Jan 1 00:00 inetd
    -rwxr-xr-x 1 0 0 31176 Jan 1 00:00 init
    -rwxr-xr-x 1 0 0 56380 Jan 1 00:00 login
    -rwxr-xr-x 1 0 0 64656 Jan 1 00:00 ping
    -rwxr-xr-x 1 0 0 34280 Jan 1 00:00 reboot
    -rwxr-xr-x 1 0 0 73860 Jan 1 00:00 route
    -rwxr-xr-x 1 0 0 79852 Jan 1 00:00 sh
    -rwxr-xr-x 1 0 0 51216 Jan 1 00:00 telnetd
    /bin> cat /proc/meminfo
    MemTotal: 2516 kB
    MemFree: 560 kB
    Buffers: 900 kB
    Cached: 188 kB
    SwapCached: 0 kB
    Active: 984 kB
    Inactive: 44 kB
    HighTotal: 0 kB
    HighFree: 0 kB
    LowTotal: 2516 kB
    LowFree: 560 kB
    SwapTotal: 0 kB
    SwapFree: 0 kB
    Dirty: 0 kB
    Writeback: 0 kB
    Mapped: 0 kB
    Slab: 752 kB
    Committed_AS: 0 kB
    PageTables: 0 kB
    VmallocTotal: 4194303 kB
    VmallocUsed: 0 kB
    VmallocChunk: 4194303 kB
    /bin>


    不错的文章,值得读一下,翻译时来来回回读了好几遍,每次都有不同的收获,感觉不错;-)
    由于时间仓促,未能测试,请大家和我关注这个贴子,使它能更准确、更完善!
  •  楼主| 发表于 2004-5-27 00:01:23 | 显示全部楼层
    好棒~ 可惜都没时间看啊
    发表于 2004-8-1 21:18:33 | 显示全部楼层
    多谢carol1980,
    多谢renbagshoes!!
    发表于 2004-8-10 15:47:11 | 显示全部楼层

    error in compiling GDB 5.0

    make[1]: Entering directory `/usr/src/gdb-5.0/gdb'
    gcc -c -g -O2    -I. -I. -I./config -DHAVE_CONFIG_H -I./../include/opcode -I./../readline/.. -I../bfd -I./../bfd  -I./../include -I../intl -I./../intl -I./tui -DUSE_INCLUDED_REGEX   arm-tdep.c
    arm-tdep.c:1382:12: missing terminating " character
    arm-tdep.c:1384:25: missing terminating " character
    arm-tdep.c:1392:12: missing terminating " character
    arm-tdep.c:1394:25: missing terminating " character
    make[1]: *** [arm-tdep.o] Error 1
    make[1]: Leaving directory `/usr/src/gdb-5.0/gdb'
    make: *** [all-gdb] Error 2

    What is the problem?
    发表于 2004-8-10 22:12:39 | 显示全部楼层
    谢谢
    发表于 2004-8-30 21:54:29 | 显示全部楼层

    两个补丁都打上了?

    error in compiling GDB 5.0
    make[1]: Entering directory `/usr/src/gdb-5.0/gdb'
    gcc -c -g -O2 -I. -I. -I./config -DHAVE_CONFIG_H -I./../include/opcode -I./../readline/.. -I../bfd -I./../bfd -I./../include -I../intl -I./../intl -I./tui -DUSE_INCLUDED_REGEX arm-tdep.c
    arm-tdep.c:1382:12: missing terminating " character
    arm-tdep.c:1384:25: missing terminating " character
    arm-tdep.c:1392:12: missing terminating " character
    arm-tdep.c:1394:25: missing terminating " character
    make[1]: *** [arm-tdep.o] Error 1
    make[1]: Leaving directory `/usr/src/gdb-5.0/gdb'
    make: *** [all-gdb] Error 2

    What is the problem?



    # gzip -dc ~/incoming/gdb-5.0-uclinux-armulator-20021127.patch.gz | patch -p0
    # gzip -dc ~/incoming/gdb-5.0-uclinux-armulator-ramdisk-20040412.patch.gz | patch -p0
    发表于 2004-8-31 13:09:38 | 显示全部楼层

    2个补丁早就打上了。我用的是debian系统。

    我仔细重做了一遍,打上了这2个补丁,还是此问题出现。请高手援手。
    发表于 2005-1-19 05:40:39 | 显示全部楼层
    nirvaam:/home/embeded/uClinux-dist# make menuconfig
    config/mkconfig > config.in
    make -C /home/embeded/uClinux-dist/config/scripts/lxdialog all
    make[1]: Entering directory `/home/embeded/uClinux-dist/config/scripts/lxdialog'
    /bin/sh: line 1: cc: command not found

    >> Unable to find the Ncurses libraries.
    >>
    >> You must have Ncurses installed in order
    >> to use 'make menuconfig'

    make[1]: *** [ncurses] Error 1
    make[1]: Leaving directory `/home/embeded/uClinux-dist/config/scripts/lxdialog'
    make: *** [menuconfig] Error 2

                                           
    我把ncurses的相关包都安装了还是不行,不明白cc是什么。
    刚刚开始接触uclinx,debian平台,请高手指点一下,thx!
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    快速回复 返回顶部 返回列表