【转载】关于Embedded Linux启动的经典问题
转载自:http://linux.chinaunix.net/techdoc/install/2009/04/13/1107608.shtml
发信人: armlinux (armlinux), 信区: Embedded
标 题: 关于Embedded Linux启动的经典问题
发信站: 哈工大紫丁香 (Sun Aug 31 20:14:46 2003)
On Sat 06 Apr, Arts Thibaut wrote:
> due to compiling problem, i try to understand the boot sequence. I know
> the main points for i386 architecture.
> > i assume that the entry point of Linux is the
> ~/arch/armnommu/boot/compressed/head.S file written by Russel King.
> This function call (after uncompressing the kernel) the "start_kernel"
> function.
> > i wish to know:
> > * what is the real boot sequence? (if i am wrong)
> * what exactly do the head.S file? (or where is documentation about it?)
I've been collecting info with intent to write this up properly. I haven't
done it yet, but I might soon.
Here is the collected info, totally unedited, and largely from posts to this
list. It should help you get the general idea:
Startup
-------
bootloader:
Linux needs almost nothing. Basically Linux just needs a boot loader to
get the kernel from some storage medium into RAM by some method, set up
a couple of registers and call it at its entry point. No MMU setup is
required.
After the bootloader finishes, it calls bootLinux(), which jumps to
the kernel. However, since the kernel is compressed, the first
entry point is in arch/arm/boot/compressed/head.s. This calls
decompress_kernel(), which is located in /arch/arm/boot/compressed/misc.c.
This calls setup_sa1100(), which initializes the UART and GPIO, and then
calls gunzip() after printing "Uncompressing Linux".
Boot code:
> ./boot/compressed/head.S
> ./boot/compressed/head-sa1100.S
> ./boot/compressed/setup-sa1100.S
This is startup code for decompressing and locating the kernel image. The
kernel is stored in compressed form to save space and make bootstrapping
simpler and easier. This code is discarded once the kernel begins
executing. This code is called by the bootloader program or whatever is
used to initialize the machine following a hard reset, after the bootloader
has loaded the compressed kernel image to a specified location in system
memory.
> ./kernel/head-armo.S
> ./kernel/head-armv.S
This is the entry point for the kernel itself, which is entered following
the decompression and relocation of the kernel image to its final
destination area in system memory.It uses the machine number in R1 to find a
table built by the linker containing vital info like where the RAM is, how
much of it there is etc.
----from RMK:--
On Tue, Jul 17, 2001 at 08:45:15PM -0700, Yang, Neil L wrote:
> I'm interested in finding out more about the arm boot sequence. One of the
> questions I had was where decompress_kernel() is called from.
arch/arm/boot/compressed/head.S
> Also, when is the MACHINE_START macro called?
Not every macro is a piece of executable code. This particular one builds
a data structure.
On Wed, Jul 18, 2001 at 09:49:57AM -0700, Chivukula, Sandeep wrote:
> >> Also, when is the MACHINE_START macro called?
> >Not every macro is a piece of executable code. This particular one builds
> >a data structure.
> > So when in the boot process does this data structure get created and by
> whom ? i.e. which function makes it initially
No function makes it. I'll explain more clearly.
The MACHINE_START macro expands to a statically built data structure, ie one
that is there when the compiler builds the file. It expands to:
const struct machine_desc __mach_desc_(type)
__attribute__((__section__(".arch.info"))) = {
nr: MACH_TYPE_(type),
name: (name)
The various other definitions set various machine_desc structure members
using named initialisers, and finally MACHINE_END provides the closing
brace for the structure initialiser. (see include/asm-arm/mach/arch.h)
Note that above, (type) is the first argument passed to the MACHINE_START
macro, and (name) is the second.
All of these machine_desc structures are collected up by the linker into
the .arch.info ELF section on final link, which is bounded by two symbols,
__arch_info_begin, __arch_info_end. These symbols do not contain pointers
into the .arch.info section, but their address are within that section.
I hope this is enough information.
-----------
This code calls start_kernel
-------From: Ray L -----on linux-arm-kernel list
> Is there a way
> to figure out where everything is placed in the kernel zImage, by looking
> at the setup of the makefiles and ld?
yes, look at the ldscripts (*.lds.* under linux/arch/arm/)
> Where are the variables _text,
> _etext, _edata, and _end defined.
in one of the ldscript files, eg: linux/arch/arm/vmlinux.lds
this script also defines a few tables, including:
proc.info is an array of structs collected from places like the end of
linux/arch/arm/mm/proc-arm720.S. these structs hold processor-specific info.
arch.info is an array of 'struct machine_desc' collected from the
MACHINE_START() macros, in places like linux/arch/arm/mach-clps711x/p720t.c.
these structs hold machine-specific info.
> Specifically, I would like to know the actual trace of the boot
> sequence of the kernel on an arm processor, not an x86.
ok, assume you're on a P720T.
- assume the uncompressor has done its thing, and we have, in RAM, a vmlinux
image ready to go
- according to linux/arch/arm/vmlinux.lds, the ENTRY() is at 'stext', so go
to linux/arch/arm/head-armv.S and find the stext symbol
- you're not on a netwinder or L7200 so skip down to __entry
- disable interrupts and make sure we're in supervisor mode
- call lookup_processor_type, which will query the cpu for it's id, then
lookup that id in .proc.info table. if it finds the struct, r10 will point
to it. this struct comes from the end of linux/arch/arm/mm/proc-arm720.S.
- if we didn;t find the struct, print out 'Error: p' on uart2 and die.
- the bootloader has arranged for r1 to hold a special integer, selected from
the list in linux/arch/arm/tools/mach-types. this will be 24 for the P720T
- call lookup_architecture_type, which will lookup r1 in the arch.info
table. this is a 'struct machine_desc' created in MACHINE_START() in
linux/arch/arm/mach-clps711x/p720t.c.
- if we didn;t find the struct, print out 'Error: a' on uart2 and die.
- call __create_page_tables to map in ram, uarts, etc
- set up lr with __ret. next time we return from a subroutine, we'll return
to __ret, which is a few lines down.
- set pc = [r10 + 12]. in other words, jump to the address in the fourth
slot of the P720T proc.info struct, which is __arm720_setup in
linux/arch/arm/mm/proc-arm720.S.
- __arm720_setup sets up MMU and returns to __ret in head-armv.S
- at __ret, set up lr with __mmap_switched (via __switch_data)
- turn on the MMU, wait for the pipeline to clear, and return to
__mmap_switched a few lines down
- __mmap_switched loads up the info from __switch_data. this, among other
things, set up stack pointer to inittask + 8192.
- clear out BSS
- jump to start_kernel
hopefully i got all that correct :-) it's not the easiest thing to follow,
but pretty straightforward once you know where the tricky jumps and linker
tables are.
--------endsnip
Wookey
【转载】关于Embedded Linux启动的经典问题的更多相关文章
- [转载] Linux启动过程详解-《别怕Linux编程》之八
本原创文章属于<Linux大棚>博客,博客地址为http://roclinux.cn.文章作者为rocrocket.为了防止某些网站的恶性转载,特在每篇文章前加入此信息,还望读者体谅. = ...
- 【转载】在Linux系统下用dd命令制作ISO镜像U盘启动盘
#### 将U盘插入USB接口 #umount /dev/sdb* #dd if=/iso存放路径/XXX.iso of=/dev/sdb bs=1M ##### [转载]在Linux系统下用dd命令 ...
- Linux启动流程详解【转载】
在BIOS阶段,计算机的行为基本上被写死了,可以做的事情并不多:一般就是通电.BIOS.主引导记录.操作系统这四步.所以我们一般认为加载内核是linux启动流程的第一步. 第一步.加载内核 操作系统接 ...
- 【转载】Linux启动初始化配置文件浅析(解决source /etc/profile重启后就失效?)
1)/etc/profile 登录时,会执行. 全局(公有)配置,不管是哪个用户,登录时都会读取该文件. (2)/ect/bashrc Ubuntu没有此文件,与之对应的是/ect/bash. ...
- [转载]嵌入式linux启动时运行的inittab文件
源地址:https://www.cnblogs.com/yfz0/p/5853826.html 嵌入式系统下的linux启动配置文件,不同与普通的PC linux启动配置,启动相关文件与文件的内容也要 ...
- 构建自己的embedded linux系统
[教程]使用buildroot完全自定义自己的embedded linux系统(nand)http://www.eeboard.com/bbs/thread-38377-1-1.html [教程] [ ...
- Linux 启动过程分析
本文仅简单介绍Linux的启动过程,在此基础上做简要的分析.对于Linux启动过程中内部详细的函数调用不做介绍,只是希望本文能给新手起到一个抛砖引玉的作用,以便深入研究Linux的启动过程.下图基本展 ...
- Linux启动流程详解
在BIOS阶段,计算机的行为基本上被写死了,可以做的事情并不多:一般就是通电.BIOS.主引导记录.操作系统这四步.所以我们一般认为加载内核是linux启动流程的第一步. 第一步.加载内核 操作系统接 ...
- Linux 启动参数介绍
Linux 启动参数介绍 取自2.6.18 kernel Documentation/i386/boot.txt 文件中介绍 vga= 这里的不是一个整数(在C语言表示法中,应是十进制,八进制或者十六 ...
随机推荐
- 转:最简单的基于 DirectShow 的视频播放器
50行代码实现的一个最简单的基于 DirectShow 的视频播放器 本文介绍一个最简单的基于 DirectShow 的视频播放器.该播放器对于初学者来说是十分有用的,它包含了使用 DirectSho ...
- ZZmsvcprt.lib(MSVCP90.dll) : error LNK2005:已经在libcpmtd.lib(xmutex.obj) 中定义 .的分析解决办法 (转)
很久没有写程式设计入门知识的相关文章了,这篇文章要来谈谈程式库 (Library) 连结,以及关于 MSVC 与 CRT 之间的种种恩怨情仇. 如果你使用的作业系统是 Linux.Mac 或其他非 W ...
- 最近面试遇到的Windows相关的题目
上周准备在公司内部转岗,面了3个部门windows客户端相关的工作,最终拿到3个Offer,主要涉及C++和Windows两大块内容,C++的题目基本都答上了,Windows一直都是我的弱项,在这里记 ...
- ubuntu 16.04 U盘多媒体不自动弹出
如下图: 设置 --> 详细信息 --> 可移动媒体 来自为知笔记(Wiz)
- U盘安装ubuntu,一直提示start booting from usb device…[转]
找到U盘中syslinux文件夹下的syslinux.cfg文件,在default vesamenu.c32前面加一个#号就可以了. 我的syslinux.cfg文件修改后如下,够简单吧!!!!建议用 ...
- web开发必备-网络基础知识---记录一下
1.osi 7层网络模型 2.socket 套接字编程 PS:一个从事web开发的人来说,我们是使用http协议来和服务器来进行交互.后面会详细的分析这个过程.
- python数据结构之二叉树的实现
树的定义 树是一种重要的非线性数据结构,直观地看,它是数据元素(在树中称为结点)按分支关系组织起来的结构,很象自然界中的树那样.树结构在客观世界中广泛存在,如人类社会的族谱和各种社会组织机构都可用树形 ...
- Android开发:第四日——SQLite初接触
一.SQLite 介绍 SQLite一个非常流行的轻量级嵌入式数据库,SQLite支持多数的SQL92标准,在一些场合下其性能优于MySql等数据库引擎,并且只利用很少的内存就有很好的性能.此外它还是 ...
- 正则指引-量词demo
class Program { static void Main(string[] args) { string str = "1\"3"; var re1 = Rege ...
- Linux查看端口、进程情况及kill进程
看端口: ps -aux | grep tomcat 发现并没有8080端口的Tomcat进程. 使用命令:netstat –apn 查看所有的进程和端口使用情况.发现下面的进程列表,其中最后一栏是P ...