📄 199.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>CTerm非常精华下载</title>
</head>
<body bgcolor="#FFFFFF">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="577">
<tr><td width="32%" rowspan="3" height="123"><img src="DDl_back.jpg" width="300" height="129" alt="DDl_back.jpg"></td><td width="30%" background="DDl_back2.jpg" height="35"><p align="center"><a href="http://202.112.58.200"><font face="黑体"><big><big>Tsinghua</big></big></font></a></td></tr>
<tr>
<td width="68%" background="DDl_back2.jpg" height="44"><big><big><font face="黑体"><p align="center"> 嵌入式系统 (BM: turbolinux jacobw) </font></big></big></td></tr>
<tr>
<td width="68%" height="44" bgcolor="#000000"><font face="黑体"><big><big><p align="center"></big></big><a href="http://cterm.163.net"><img src="banner.gif" width="400" height="60" alt="banner.gif"border="0"></a></font></td>
</tr>
<tr><td width="100%" colspan="2" height="100" align="center" valign="top"><br><p align="center">[<a href="嵌入式系统.htm">回到开始</a>][<a href="196.htm">上一层</a>][<a href="200.htm">下一篇</a>]
<hr><p align="left"><small>发信人: BBF (棒棒头~~冷酷到底), 信区: Embedded <br>
标 题: Re: 移植一个Linux要修改那些部分涉及到哪些文件? <br>
发信站: BBS 水木清华站 (Mon Apr 16 20:35:51 2001) <br>
<br>
贴一篇权当灌水,写的精彩,可惜是说MIPS porting的 <br>
Linux Porting Guide <br>
By Rajesh Palani <br>
Embedded Systems Programming <br>
(02/26/01, 07:50:40 PM EDT) <br>
Why pay someone to port Linux for you? Here's oneLinux how-to no embedded pr <br>
ogrammer should miss. <br>
Linux is gaining in popularity in embedded systems. Many commercial vendors <br>
specialize in porting Linux to embedded systems. This article explains the w <br>
ork involved in porting Linux to a specific embedded system and how it was d <br>
one for one embedded system in particular. <br>
Until now, most embedded operating systems have been proprietary. If a new p <br>
rocessor was designed and developed by a semiconductor company, they had to <br>
depend on an operating system company to port their operating system to the <br>
new processor. The other issue was with the development tools (compiler, deb <br>
ugger, simulator, and so on) for the given processor. Usually the operating <br>
system company also provided these tools. In addition, the peripherals aroun <br>
d the processor required drivers that had to be developed for the specific o <br>
perating system. With the introduction of Linux into the embedded sphere, it <br>
has become possible for the semiconductor company itself to port an operati <br>
ng system to a new processor, since the source code for the Linux kernel is <br>
available as open source. The GNU [1] project provides a wealth of developme <br>
nt tools that support Linux and are also open source. In addition, many devi <br>
ce drivers are available for Linux, which could be used directly or as a sta <br>
rting point for your target devices. <br>
Project specifics <br>
In our example, the target platform (development board) to which we ported L <br>
inux consisted of an ASIC (application-specific integrated circuit) for Wind <br>
ows-based terminals (thin client) and Internet access terminals, a MIPS CPU, <br>
and a CPU interface (North Bridge). In addition, the development board also <br>
supported EDO DRAM, flash ROM, I2C RTC, I2C EEPROM, and I2C serial bus. The <br>
high-level system block diagram is shown in Figure 1. An architectural bloc <br>
k diagram of the ASIC is shown in Figure 2. A ramdisk (explained later in th <br>
e article) served as the root file system. A ramdisk was used initially in o <br>
rder to speed up the porting process. Though this article is based on Linux <br>
on MIPS, the overall approach is not very different for other processors (AR <br>
M, 386, and so on). In addition, the article deals only with minimum kernel <br>
functionality. <br>
Figure 1 <br>
Figure 2 <br>
Cross-development tools were used for this project. The current development <br>
was done on a PC running Red Hat Linux. The Linux VR Web site (see Reference <br>
s) is a good starting point for cross-development tools and sources for Linu <br>
x on MIPS. The following cross-development tools need to be downloaded and i <br>
nstalled on the PC running Linux: cross-binutils-as, ld, and so on; C cross <br>
compiler; and cross-development C libraries. The detailed steps for installa <br>
tion are available along with the tools. <br>
The kernel sources <br>
The Linux kernel sources for MIPS can be downloaded from the Linux-VR site. <br>
One of the most important steps in porting Linux to a new target platform is <br>
to have a very clear understanding of how the kernel sources are organized. <br>
The following directory structure is not complete and includes only parts t <br>
hat are of interest to this article. The $(TOPDIR) [2] has the following sub <br>
-directories: <br>
arch-This subdirectory contains all of the architecture-specific code. For e <br>
ach supported architecture (MIPS, ARM, 386, and so on), there is a subdirect <br>
ory under "arch". Each supported architecture subdirectory has four major su <br>
bdirectories: <br>
kernel, which contains the architecture-specific kernel code <br>
mm, which contains the architecture-specific memory management code <br>
lib, which contains architecture specific library code (vsprintf and so on) <br>
MY_PLATFORM (target platform directory), which contains platform-specific co <br>
de. <br>
de. <br>
Note that Linux ports to processors without memory management units (MMU) ar <br>
e also available <br>
documentation-This subdirectory contains the documentation for the kernel <br>
drivers-This subdirectory contains code for the device drivers. Each type of <br>
device has further subdirectories, such as char, block, net, and so on <br>
fs-This directory contains the file system code. This has further sub-direct <br>
ories for each supported file system (ext2, proc, and so on) <br>
include-The include subdirectory contains the include files for the kernel. <br>
It has further subdirectories for common include files (for all architecture <br>
s), one for every architecture supported, and a couple of other subdirectori <br>
es <br>
init-This directory contains the initialization code for the kernel <br>
kernel-This directory contains the main kernel code <br>
lib-This directory contains the library code of the kernel <br>
mm-This directory contains the memory management code <br>
Building the kernel image <br>
The Makefile in the $(TOPDIR) has to have ARCH (architecture) properly defin <br>
ed (MIPS in this case). The Makefile in $(TOPDIR)/arch/MY_ ARCH/boot has to <br>
have CROSS_COMPILE (mipsel-linux, MIPS little-endian cross-compiler tool-set <br>
in this case) and LOADADDR (address at which the kernel image would be load <br>
ed) defined as per the configuration. If additional configuration options ha <br>
ve to be added, the $(TOPDIR)/arch/MY_ARCH/config.in file has to be modified <br>
. You would need to have a config option for your platform (CONFIG_MYPLATFOR <br>
M) to include code that is specific to your platform. The kernel has to be c <br>
onfigured ("make config") to the barest minimum needs (serial driver, ramdis <br>
k driver, ext2 file system). Then do a "make dep" to set up the dependencies <br>
and finally a "make vmlinux" to produce the kernel image. <br>
Ramdisk <br>
To begin with, a ramdisk can be mounted as the root file system. Ramdisk ima <br>
ges and objects are also available readily for MIPS (Linux-VR site). A ramdi <br>
sk image is a file that contains an image of an ext2 filesystem, while a ram <br>
disk object is an elf object that encapsulates a ramdisk image and can be li <br>
nked into the kernel. The ramdisk image is usually stored in compressed form <br>
. CONFIG_BLK_DEV_RAM and CONFIG_BLK_DEV_INITRD need to be defined as Y in "m <br>
ake config." The ramdisk image can be modified to include your applications, <br>
if required. Tools (scripts) are available at the Linux VR site for creatin <br>
g a ramdisk object. The ramdisk.o file needs to be copied to $(TOPDIR)/ arch <br>
/MY_ARCH/boot and linked into the kernel. There is a detailed document, $(TO <br>
PDIR)/Documenta-tion/ramdisk.txt, on how to use the RAM disk block device wi <br>
th Linux. <br>
Processor-specific changes to the kernel code <br>
If your processor is a standard (or popular) one, in most cases a Linux port <br>
to that processor would be available. If you are one of the unlucky few who <br>
has to deal with a specific implementation of a given processor core to whi <br>
ch Linux has not yet been ported, you'll want to figure out which processor <br>
in the list of ported ones is closest to yours and use that port as a starti <br>
ng point for your specific processor implementation. For example, the MIPS c <br>
ore is licensed to many silicon vendors who have their own implementations. <br>
The number of TLB [3] (translation lookaside buffers) entries may be differe <br>
nt for different implementations. Add a config option (CONFIG_MYCPU) to incl <br>
ude code that is specific to your processor. Directories $(TOPDIR)/arch/MY_A <br>
RCH/kernel and $(TOPDIR)/arch/MY_ARCH/mm contain the processor-specific code <br>
that require modifications if you are dealing with a new implementation. <br>
Assembly file $(TOPDIR)/arch/MY_ARCH/kernel/head.S contains kernel_entry, th <br>
e entry point for the kernel. This file also contains the exception handling <br>
code. Listing 1 shows the implementation of the kernel_entry routine in pse <br>
udocode. <br>
Listing 1: Kernel entry pseudocode <br>
1. Set desired endian mode <br>
2. Clear the BEV bit <br>
3. Set the TLB bit <br>
4. GOTO cpu_probe and return <br>
5. Set up stack for kernel <br>
6. Clear bss <br>
7. GOTO prom_init and return <br>
8. GOTO loadmmu and return <br>
9. Disable coprocessors <br>
10. GOTO start_kernel <br>
11. GOTO 10 <br>
The configuration register has to be set up correctly. The first thing to be <br>
done is to make sure that we are running in the desired endian mode. In our <br>
case, we run the system in little-endian mode. The bootstrap exception vect <br>
or bit needs to be cleared to make sure that the normal exception vectors ar <br>
e used henceforth. In addition, the TLB bit is set to make sure that TLB-bas <br>
ed translation is used. <br>
The next step is to probe for the cputype. Listing 2 is a very simple implem <br>
entation of this function. $(TOPDIR)/include/asm/bootinfo.h contains entries <br>
for the cputype (MYCPU) and machine group (MY_MACH_GROUP). The mips_ cputyp <br>
e variable has to be updated in the cpu_probe function. This value is used l <br>
ater to determine the exception handling and MMU routines that need to be lo <br>
aded for the given CPU, as well as to get the CPU information in the /proc f <br>
ile system. <br>
Listing 2: Code to probe cputype <br>
LEAF(cpu_probe) <br>
la t3, mips_cputype <br>
li t2, MYCPU /* include/asm-mips/bootinfo.h */ <br>
b probe_done <br>
sw t2, (t3) <br>
sw t2, (t3) <br>
END(cpu_probe) <br>
The initial stack for the kernel is set up next. Then the bss section of the <br>
kernel image is cleared. Control then transfers to the prom_init() function <br>
. Then the TLB and caches are flushed and the cache manipulation functions a <br>
re set up inside loadmmu(). Disabling of the coprocessors other than coproce <br>
ssor 0 is done next, followed by a jump to start_kernel(). <br>
$(TOPDIR)/arch/MY_ARCH/mm contains the TLB routines and cache handling routi <br>
nes. <br>
Platform specific changes to the kernel code <br>
$(TOPDIR)/arch/MY_ARCH has a sub-directory for each target development platf <br>
orm that is supported. Create a MY_PLATFORM directory by copying a platform <br>
closest to your configuration. This directory should contain the interrupt h <br>
andling, timer, initialization, and setup routines for your specific platfor <br>
m. Create a MY_PLATFORM directory under $(TOPDIR)/include/asm. This director <br>
y is used to hold include files specific to your platform. <br>
The prom_init() function, which is part of $(TOPDIR)/arch/MY_ARCH/MY_PLATFOR <br>
M/prom.c (Listing 3), modifies the command line string to add parameters tha <br>
t need to be passed to the kernel from the bootloader. The machine group and <br>
upper bound of usable memory are set up here. <br>
Listing 3: PROM initialization <br>
int __init prom_init (int argc, char **argv, char **envp) <br>
{ <br>
{ <br>
unsigned int mem_limit; <br>
// set upper limit to maximum physical RAM (32MB) <br>
mem_limit = 32 * 1024 * 1024; <br>
// the bootloader usually passes us argc/argv[ ]. <br>
//In the present case, these arguments are not <br>
//passed from the bootloader. The kernel wants <br>
// one big string. put it in arcs_cmdline, which <br>
later gets copied to command_line <br>
//(see arch/mips/kernel/setup.c) <br>
strcpy (arcs_cmdline, *root=/dev/ram*); <br>
mips_machgroup = MY_MACH_GROUP; <br>
// set the upper bound of usable memory <br>
mips_memory_upper = KSEG0 + mem_limit; <br>
printk(*Detected %dMB of memory\n*, mem_limit >> 20); <br>
return 0; <br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -