⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 在armulator中移植uclinux.txt

📁 在ARMulator中移植uClinuxGetting Familiar with uClinux/ARM 2.6 by Hyok S. Choi <hyok.choi@samsung.com
💻 TXT
📖 第 1 页 / 共 2 页
字号:
在ARMulator中移植uClinux
Getting Familiar with uClinux/ARM 2.6
by Hyok S. Choi <hyok.choi@samsung.com>
the author and maintainer of uClinux/ARM2.6
 
Why uClinux/ARM 2.6?
Why would you want to use uClinux? There could be many reasons to consider the uClinux for your embedded OS. Some of them could be as following:

Lightweight
You can make a complete linux 2.6 preemptible kernel image including console and some basic device drivers 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 for the flash or rom for boot image should be fast enough and/or enough cache size. (There could be a trade-off between those 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 more than a half of applications do not need the MMU. Many of RTOS do 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.

Easier to adapt
One of the interesting natures of uClinux is the possibility of user application accessing the whole system, including 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 planning to migrate 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, including preemptible kernel feature and so many file-systems, device drivers. Porting of device drivers for conventional Linux is handy. Almost all codes should be compiled without change, except memory mapping from virtual address to physical.

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

uClinux distribution
The easiest way to get 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 vanilla 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/uClinux/dist/uClinux-dist-20040408.tar.gz”. If you have some strange trouble with compilation, even after following 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://opensrc.sec.samsung.com/
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://opensrc.sec.samsung.com/download/linux-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 of the new features from 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://opensrc.sec.samsung.com/download/arm-elf-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 a 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/uClinux/utilities/armulator/gdb-5.0.tar.bz2 (the original gdb-5.0 archive)
http://www.uclinux.org/pub/uClinux/utilities/armulator/gdb-5.0-uclinux-armulator-20021127.patch.gz (Patches against gdb-5.0)

And another patch if you want to run the kernel with ramdisk on the ARMulator :
http://opensrc.sec.samsung.com/download/gdb-5.0-uclinux-armulator-ramdisk-20040412.patch.gz

That's all for your first compilation.

Okay, here we go step by step.
(This guide is assuming that the downloaded files are located at ~/incoming and the ARMulator is used for platform to run on.)

Install the toolchain

su to log in as the root then 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 patched in directories that contain “armnommu” string. You can use the directory >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 re> 

[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

host>/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 to configure compilation options 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 configuration files in the vendors directory is loaded. And with the second “Customize kernel settings”, we can edit the kernel configuration. The third “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 it again for save dialog. And save it!

Kernel Configuration

If you followed the steps in “confirm the configuration files” above, your kernel should have been 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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -