2007年10月10日

好久没有和老同学在一起聊天了,不知道是不是因为不再有那种在一起海吹的激情了,但是肯定不是因为忙的缘故。

从大学开始,和大鸟关系就不错,他一直以来就很照顾我,帮了我不少忙,加上前些天在同学录上看到了关于同学之间联系的种种言论,突然觉得,我既然过来上海了,总是应该和大鸟打个招呼的。

不熟悉上海的路,徐家汇出地铁站颇费了一番周折才找到公交站,等了半天没有车来,鸟兄的电话在催,他已经在我住处那边等了一会了,就打车过去了,其实不贵,也能报销,但是,这些年来就是没有打车的习惯。

胖了不少,看起来还挺年轻,也挺精神,不过,成家立业了,看起来就是和以前不一样,尽管不确切这不一样究竟在哪里。我想,我给他的印象也差不了多少。

鸟兄还是那么热情,载我到红鱼盆,点的菜在我看来比较奢侈,我的感觉还是老样子,够吃就行。天南海北的吹,想到哪说到哪,和念书时唯一不同的是少了女人的内容,多了对各自周边环境的看法。饭店的空调有点冷,于是,他说出去转转,我说好。特殊的场合或者服务我没兴趣,其实也不不知道自己有没有兴趣,就是从来没想过该去,于是我说就到上岛要杯茶聊聊天吧。说这句话的时候突然想了一下,作为男人,我是不是有点迂腐和放不开,然后他竟然也提起了,苦笑。

我喜欢龙井,就要了一壶,看着根根倒立的茶叶,抽烟的欲望少了很多。他来了一壶碧螺春。他却是酷爱茶,说家里从龙井,碧螺春到白茶全都齐了。说到这我倒是从他那里知道了百茶不是安吉的专利,溧阳也有的。

还是继续吃饭时的天南海北,当然,烟也越少越多。他说,上海人,尤其是年轻的,很势利,所以不上档次的衣着和香烟在有些场合和行业会显得格格不入,甚至招人看不起。别的我没有具体的概念,关于香烟,很明显能拿得出手的档次就是中华。我看了看手中燃烧着的新版红梅,我竟然从来没想过这个问题,还好,我不常在上海,呵呵。

咖啡吧的环境和饭店就是不一样,多一些思考就很容易让人的谈话扯到一些比较现实的问题。谈男人的三十而立,谈现实的困境,谈将来的想法。他说自己很满足目前的生活状态了,虽然谈不上富裕,但是比上不足比下有余。不过,我倒是从他的言行举止感觉到这些更多是家庭那种温馨所带来的今生上的满足感。有房有车有老婆有小孩,其实,我也会觉得满足的。不过,我却还在想着该奋斗多少年。

2006年11月27日

A cool blog for gtk and embedded system development.

http://blog.csdn.net/absurd

 

http://dev.csdn.net/author/absurd/index.html

http://www.nutshellsoft.com/english/broadcast/

 

copied from mic’s blog, thx.

2006年06月15日

1. nets.org.sg 新加坡
2. clock.tl.fukuoka-u.ac.jp 日本
3. clock.cuhk.edu.hk  香港
4. clock.nc.fukuoka-u.ac.jp 日本
5. jamtepat.singnet.com.sg 新加坡

vivi boot loader的实现

参考资料:
1.嵌入式系统 Boot Loader 技术内幕, 詹荣开 (zhanrk@sohu.com)
2.Getting started with VIVI,  Janhoon Lyu, nandy@mizi.com
3.嵌入式设备上的Linux 系统开发,A. Santhanam etc.
4.Linux system development on an embedded device, A. Santhanam
5.vivi 有关资料http://www.mizi.com/developer/s3c2410x/index.html
6.smdk2410的硬件和软件/linux相关资料 http://www.samsung.com search  2410

说明:本文文字结构照抄” 嵌入式系统 Boot Loader 技术内幕, 詹荣开 (zhanrk@sohu.com)” 一文,以vivi中head.S作为stage1, main()作为stage2,解释了VIVI for SMDK2410 (based on S3C2410) 开发系统的bootloader的实现。将原文放在这里是为了方便读者。注意,VIVI的实现并非完全跟原文一致。多谢原文作者詹大侠的详细解释。
附录有一节__SETUP在kernel的作用来自jeppeter (member) from http:// linuxforum.net

文中对MTD subsystem linux没作解释。Google “MTD linux subsystem 文件系统 JFSS2 ”可以获得足够的解释。

如有错误,烦请email jonesxu@gmail.com告知。多些

Ver.0.95
Jones S Z Xu
jonesxu@gmail.com
2004-09-29
Chapter 1 Boot loader基本结构
由于 Boot Loader 的实现依赖于 CPU 的体系结构,因此大多数 Boot Loader 都分为 stage1 和 stage2 两大部分。依赖于 CPU 体系结构的代码,比如设备初始化代码等,通常都放在 stage1 中,而且通常都用汇编语言来实现,以达到短小精悍的目的。而 stage2 则通常用C语言来实现,这样可以实现给复杂的功能,而且代码会具有更好的可读性和可移植性。

Boot Loader 的 stage1 通常包括以下步骤(以执行的先后顺序):

硬件设备初始化。
为加载 Boot Loader 的 stage2 准备 RAM 空间。
拷贝 Boot Loader 的 stage2 到 RAM 空间中。
设置好堆栈。
跳转到 stage2 的 C 入口点。

Boot Loader 的 stage2 通常包括以下步骤(以执行的先后顺序):

初始化本阶段要使用到的硬件设备。
检测系统内存映射(memory map)。
将 kernel 映像和根文件系统映像从 flash 上读到 RAM 空间中。
为内核设置启动参数。
调用内核。

1.1 Boot Loader 的 stage1

1.1.1 基本的硬件初始化

这是 Boot Loader 一开始就执行的操作,其目的是为 stage2 的执行以及随后的 kernel 的执行准备好一些基本的硬件环境。它通常包括以下步骤(以执行的先后顺序):

1. 屏蔽所有的中断。为中断提供服务通常是 OS 设备驱动程序的责任,因此在 Boot Loader 的执行全过程中可以不必响应任何中断。中断屏蔽可以通过写 CPU 的中断屏蔽寄存器或状态寄存器(比如 ARM 的 CPSR 寄存器)来完成。

2. 设置 CPU 的速度和时钟频率。

3. RAM 初始化。包括正确地设置系统的内存控制器的功能寄存器以及各内存库控制寄存器等。

4. 初始化 LED。典型地,通过 GPIO 来驱动 LED,其目的是表明系统的状态是 OK 还是 Error。如果板子上没有 LED,那么也可以通过初始化 UART 向串口打印 Boot Loader 的 Logo 字符信息来完成这一点。

5. 关闭 CPU 内部指令/数据 cache。


VIVI在第一阶段完成以下任务


Disable watch dog timer ;   disable all interrupts  ;  

initialise system clocks; initialise the static memory  All LED on

set GPIO for UART  Initialize UART 0  ;  

copy_myself to ram; jump to ram
get read to call C functions    setup stack pointer
call main
1.1.2 为加载 stage2 准备 RAM 空间

为了获得更快的执行速度,通常把 stage2 加载到 RAM 空间中来执行,因此必须为加载 Boot Loader 的 stage2 准备好一段可用的 RAM 空间范围。

由于 stage2 通常是 C 语言执行代码,因此在考虑空间大小时,除了 stage2 可执行映象的大小外,还必须把堆栈空间也考虑进来。此外,空间大小最好是 memory page 大小(通常是 4KB)的倍数。一般而言,1M 的 RAM 空间已经足够了。具体的地址范围可以任意安排,比如 blob 就将它的 stage2 可执行映像安排到从系统 RAM 起始地址 0xc0200000 开始的 1M 空间内执行。但是,将 stage2 安排到整个 RAM 空间的最顶 1MB(也即(RamEnd-1MB) – RamEnd)是一种值得推荐的方法。

为了后面的叙述方便,这里把所安排的 RAM 空间范围的大小记为:stage2_size(字节),把起始地址和终止地址分别记为:stage2_start 和 stage2_end(这两个地址均以 4 字节边界对齐)。因此:

stage2_end=stage2_start+stage2_size


另外,还必须确保所安排的地址范围的的确确是可读写的 RAM 空间,因此,必须对你所安排的地址范围进行测试。具体的测试方法可以采用类似于 blob 的方法,也即:以 memory page 为被测试单位,测试每个 memory page 开始的两个字是否是可读写的。为了后面叙述的方便,我们记这个检测算法为:test_mempage,其具体步骤如下:

1. 先保存 memory page 一开始两个字的内容。

2. 向这两个字中写入任意的数字。比如:向第一个字写入 0×55,第 2 个字写入 0xaa。

3. 然后,立即将这两个字的内容读回。显然,我们读到的内容应该分别是 0×55 和 0xaa。如果不是,则说明这个 memory page 所占据的地址范围不是一段有效的 RAM 空间。

4. 再向这两个字中写入任意的数字。比如:向第一个字写入 0xaa,第 2 个字中写入 0×55。

5. 然后,立即将这两个字的内容立即读回。显然,我们读到的内容应该分别是 0xaa 和 0×55。如果不是,则说明这个 memory page 所占据的地址范围不是一段有效的 RAM 空间。

6. 恢复这两个字的原始内容。测试完毕。

为了得到一段干净的 RAM 空间范围,我们也可以将所安排的 RAM 空间范围进行清零操作。

1.1.3 拷贝 stage2 到 RAM 中

拷贝时要确定两点:(1) stage2 的可执行映象在固态存储设备的存放起始地址和终止地址;(2) RAM 空间的起始地址。

1.1.4 设置堆栈指针 sp

堆栈指针的设置是为了执行 C 语言代码作好准备。通常我们可以把 sp 的值设置为(stage2_end-4),也即在 1.1.2 节所安排的那个 1MB 的 RAM 空间的最顶端(堆栈向下生长)。

此外,在设置堆栈指针 sp 之前,也可以关闭 led 灯,以提示用户我们准备跳转到 stage2。

经过上述这些执行步骤后,系统的物理内存布局应该如下图2所示。

1.1.5 跳转到 stage2 的 C 入口点

在上述一切都就绪后,就可以跳转到 Boot Loader 的 stage2 去执行了。比如,在 ARM 系统中,这可以通过修改 PC 寄存器为合适的地址来实现。

head.S 负责完成硬件初始化操作,具体分析见源码注释 ,汇编差不多忘光了,下面注释中有关汇编的东西多些。
其中"linkage.h"
#define SYMBOL_NAME_STR(X) #X
#define SYMBOL_NAME(X) X
#ifdef __STDC__
#define SYMBOL_NAME_LABEL(X) X##:
#else
#define SYMBOL_NAME_LABEL(X) X/**/:
#endif

#define __ALIGN .align 0
#define __ALIGN_STR ".align 0"

#ifdef __ASSEMBLY__

#define ALIGN __ALIGN
#define ALIGN_STR __ALIGN_STR

#define ENTRY(name) \
 .globl SYMBOL_NAME(name); \
 ALIGN; \
 SYMBOL_NAME_LABEL(name)

#endif

其中"machine.h" 包括了
smdk2410.h (有关开发板的配置) ,
包括memory map, Porocessor memory map ,FLASH, ROM, DRAM的物理地址和在VIVI中用的虚拟地址(?),Architecture magic and machine type, UART,CPU,DRAM的初始化参数等

smdk2410.h进一步包括s3c2410.h, 有关CPU的设置,Definition of constants related to the S3C2410 microprocessor(based on ARM 920T).

/*
* vivi/arch/s3c2410/head.S:
*   Initialise hardware
*
* Copyright (C) 2001 MIZI Research, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
*
* Author: Janghoon Lyu <nandy@mizi.com>
* Date  : $Date: 2003/02/26 10:38:11 $
*
* $Revision: 1.18 $
*
*
* History:
*
* 2002-05-14: Janghoon Lyu <nandy@mizi.com>
*   – Initial code
*
*/

#include "config.h"//àautoconf.h 空的
#include "linkage.h"//定义
#include "machine.h"

@ Start of executable code

ENTRY(_start)//入口点
ENTRY(ResetEntryPoint)

@
@ Exception vector table (physical address = 0×00000000)
@//异常向量 表 物理地址0×0000000

@ 0×00: Reset//最 基本操作 :复位  B 是最简单的分支。一旦遇到一个 B 指令,ARM 处理器将立即跳转到给定的地址,从那里继续执行。注意存储在分支指令中的实际的值是相对当前的 R15 的
bReset

@ 0×04: Undefined instruction exception//处理未定义的指令
UndefEntryPoint:
bHandleUndef

@ 0×08: Software interrupt exception//软中断
SWIEntryPoint:
bHandleSWI

@ 0×0c: Prefetch Abort (Instruction Fetch Memory Abort) //中文名不知道
PrefetchAbortEnteryPoint:
bHandlePrefetchAbort

@ 0×10: Data Access Memory Abort//
DataAbortEntryPoint:
bHandleDataAbort

@ 0×14: Not used//空
NotUsedEntryPoint:
bHandleNotUsed

@ 0×18: IRQ(Interrupt Request) exception//中断(普通)
IRQEntryPoint:
bHandleIRQ

@ 0×1c: FIQ(Fast Interrupt Request) exception// fast 中断处理
FIQEntryPoint:
bHandleFIQ

@
@ VIVI magics
@

@ 0×20: magic number so we can verify that we only put
.long   0
@ 0×24:
.long   0
@ 0×28: where this vivi was linked, so we can put it in memory in the right place
.long   _start
@ 0×2C: this contains the platform, cpu and machine id
.long   ARCHITECTURE_MAGIC
@ 0×30: vivi capabilities
.long   0
#ifdef CONFIG_PM// power management //vivi未用
@ 0×34:
bSleepRamProc
#endif
#ifdef CONFIG_TEST//test modevivi未用
@ 0×38:
bhmi
#endif


@
@ Start VIVI head
@
Reset://第一步 RESET
@ disable watch dog timer//disable watch dog定时器
movr1, #0×53000000
movr2, #0×0
strr2, [r1]//add 0×5300_0000 清 0,bit 5=0 disable this timer

#ifdef CONFIG_S3C2410_MPORT3//另一种Platform 非SMDK
movr1, #0×56000000
movr2, #0×00000005
strr2, [r1, #0x70]
mov r2, #0×00000001
strr2, [r1, #0x78]
movr2, #0×00000001
str r2, [r1, #0x74]
#endif

@ disable all interrupts//禁止 所有中断
movr1, #INT_CTL_BASE//0×4A00_0000 source pending register
movr2, #0xffffffff
strr2, [r1, #oINTMSK] //0×4A00_0008
//0×4A00_0008  INTERRUPT MASK register=0xFFFFFFFF, disable all int
ldrr2, =0×7ff
strr2, [r1, #oINTSUBMSK]//0×4A00_001C
//Interrupt sub mask register ,  bit[10:0] = 1 ->0×7FF ->disable all

@ initialise system clocks//初始化系统时钟
movr1, #CLK_CTL_BASE// LOCK TIME COUNT REGISTER(LOCKTIME)
//0×4c000000
mvnr2, #0xff000000
strr2, [r1, #oLOCKTIME]//0×4C000000 ->0xFF00_0000;

@ldrr2, mpll_50mhz//CPU定成50Mhz
@strr2, [r1, #oMPLLCON]//
#ifndef CONFIG_S3C2410_MPORT1//如果未定义成MPORT1 (一种plat form)
@ 1:2:4
movr1, #CLK_CTL_BASE
movr2, #0×3
strr2, [r1, #oCLKDIVN]//
// vCLKDIVN0×3/* FCLK:HCLK:PCLK = 1:2:4 */
mrcp15, 0, r1, c1, c0, 0@ read ctrl register
orrr1, r1, #0xc0000000@ Asynchronous  
mcrp15, 0, r1, c1, c0, 0@ write ctrl register

@ now, CPU clock is 200 Mhz//CPU定成200Mhz
movr1, #CLK_CTL_BASE
ldrr2, mpll_200mhz
strr2, [r1, #oMPLLCON]
#else//platform= MPORT1 ,以下不理
@ 1:2:2
   mov r1, #CLK_CTL_BASE
   ldr r2, clock_clkdivn
   str r2, [r1, #oCLKDIVN]

   mrc p15, 0, r1, c1, c0, 0       @ read ctrl register
   orr r1, r1, #0xc0000000     @ Asynchronous
   mcr p15, 0, r1, c1, c0, 0       @ write ctrl register

   @ now, CPU clock is 100 Mhz
   mov r1, #CLK_CTL_BASE
   ldr r2, mpll_100mhz
   str r2, [r1, #oMPLLCON]
#endif
blmemsetup//第2步memsetup

#ifdef CONFIG_PM//如果有 Power management:不用
@ Check if this is a wake-up from sleep
ldrr1, PMST_ADDR
ldrr0, [r1]
tstr0, #(PMST_SMR)
bneWakeupStart
#endif


#ifdef CONFIG_S3C2410_SMDK//SMDK platform
@ All LED on//点灯,好歹通知一下外面的同志3
movr1, #GPIO_CTL_BASE
addr1, r1, #oGPIO_F
ldrr2,=0×55aa
strr2, [r1, #oGPIO_CON]
movr2, #0xff
strr2, [r1, #oGPIO_UP]
movr2, #0×00
strr2, [r1, #oGPIO_DAT]
#endif

#if 0
@ SVC
mrsr0, cpsr
bicr0, r0, #0xdf
orrr1, r0, #0xd3
msrcpsr_all, r1
#endif
//设置串口 ,内外联络的通道
@ set GPIO for UART
movr1, #GPIO_CTL_BASE// 0×5600_0000
addr1, r1, #oGPIO_H
// oGPIO_H 0×70 PORT H CONTROL REGISTERS

ldrr2, gpio_con_uart// vGPHCON= 0×0016faaa
strr2, [r1, #oGPIO_CON]// 01 01 10 11 11 10 10 10 10 10 10 B
//oGPIO_CON = 0×0  
// GPH0 bit[1:0] = 10  nCTS0
// GPH1 bit[3:2] = 10  nRTS0
// GPH2 bit[5:4] = 10  TXD0
// GPH3 bit[7:6] = 10  RXD0
// GPH4 bit[9:8] = 10 TXD1
// GPH5 bit[11:10] = 10 RXD1
// GPH6 bit[13:12] = 11  nRTS1
// GPH7 bit[15:14] = 11 nCTS1
// GPH8 bit[17:16] = 10 UEXTCLK
// GPH9 bit[19:18] = 01 Output
// GPH10 bit[21:20] = 01 Output

ldrr2, gpio_up_uart// vGPHUP 0×000007ff = 0111 1111 1111  B
strr2, [r1, #oGPIO_UP]
// oGPIO_UP 0×8 /* R/W, Pull-up disable register */
//  0×7FF ->  1: The pull-up function is disabled. For all GPHx
// reg GPHUP 0×56000078

blInitUART//initialize UART

#ifdef CONFIG_DEBUG_LL//low level debugging info
@ Print current Program Counter//vivi def没用
ldrr1, SerBase//往串口上输出 info
movr0, #’\r’
blPrintChar
movr0, #’\n’
blPrintChar
movr0, #’@’
blPrintChar
movr0, pc
blPrintHexWord
#endif


#ifdef CONFIG_BOOTUP_MEMTEST//  comment ‘Low Level Hardware Debugging’
 bool ‘ Enable simple memory test’ CONFIG_BOOTUP_MEMTEST  //vivi def没用
@ simple memory test to find some DRAM flaults.
blmemtest//check the first 1MB  in increments of 4k//改大点3
#endif

#ifdef CONFIG_S3C2410_NAND_BOOT
blcopy_myself

@ jump to ram
ldrr1, =on_the_ram//将on_the_ram的地址装入r1
addpc, r1, #0//pc = r1+0
nop
nop
1:b1b@ infinite loop//硬是看不懂这个 B

on_the_ram:
#endif

#ifdef CONFIG_DEBUG_LL
ldrr1, SerBase
ldrr0, STR_STACK
blPrintWord
ldrr0, DW_STACK_START
blPrintHexWord
#endif

@ get read to call C functions
ldrsp, DW_STACK_START@ setup stack pointer
// STACK_BASE+STACK_SIZE-4
// STACK_BASE = (VIVI_PRIV_RAM_BASE – STACK_SIZE)
//STACK从上往下用。  所以 STACK_START = STACK_BASE+STACK_SIZE-4
movfp, #0@ no previous frame, so fp=0
mova2, #0@ set argv to NULL

blmain@ call main //如果正常,一去不复返的了

movpc, #FLASH_BASE@ otherwise, reboot, //FLASH_BASE=ROM_BASE0 = 0×0

@
@ End VIVI head
@

/*
* subroutines
*/

@
@ Wake-up codes
@
#ifdef CONFIG_PM
WakeupStart:// power management 用
@ Clear sleep reset bit
ldrr0, PMST_ADDR
movr1, #PMST_SMR
strr1, [r0]

@ Release the SDRAM signal protections
ldrr0, PMCTL1_ADDR
ldrr1, [r0]
bicr1, r1, #(SCLKE | SCLK1 | SCLK0)
strr1, [r0]

@ Go…
ldrr0, PMSR0_ADDR@ read a return address
ldrr1, [r0]
movpc, r1
nop
nop
1:b1b@ infinite loop

SleepRamProc://power management用
@ SDRAM is in the self-refresh mode */
ldrr0, REFR_ADDR
ldrr1, [r0]
orrr1, r1, #SELF_REFRESH
strr1, [r0]

@ wait until SDRAM into self-refresh
movr1, #16
1:subsr1, r1, #1
bne1b

@ Set the SDRAM singal protections
ldrr0, PMCTL1_ADDR
ldrr1, [r0]
orrr1, r1, #(SCLKE | SCLK1 | SCLK0)
strr1, [r0]

/* Sleep… Now */
ldrr0, PMCTL0_ADDR
ldrr1, [r0]
orrr1, r1, #SLEEP_ON
strr1, [r0]
1:b1b

#ifdef CONFIG_TEST
hmi:
ldrr0, PMCTL0_ADDR // PMCTL0_ADDR: .long 0×4c00000c, Clock Gen Ctrl
ldrr1, =0×7fff0// reset clock gen ctrl
strr1, [r0]

@ All LED on//点灯?
movr1, #GPIO_CTL_BASE
addr1, r1, #oGPIO_F
ldrr2,=0×55aa
strr2, [r1, #oGPIO_CON]
movr2, #0xff
strr2, [r1, #oGPIO_UP]
movr2, #0xe0
strr2, [r1, #oGPIO_DAT]
1:b1b
#endif

#endif

ENTRY(memsetup)//memsetup子程序
@ initialise the static memory

@ set memory control registers
movr1, #MEM_CTL_BASE//memory controller
adrlr2, mem_cfg_val
addr3, r1, #52
1:ldrr4, [r2], #4
strr4, [r1], #4
cmpr1, r3
bne1b

movpc, lr//这里返回了么?
注意注意:这里memsetup已经返回了,下面是独立的子程序了呢

#ifdef CONFIG_S3C2410_NAND_BOOT  // NAND如此,NOR应该如何处理呢?
@//不需要copy vivi to ram?????
@ copy_myself: copy vivi to ram
@
copy_myself:
movr10, lr

@ reset NAND
movr1, #NAND_CTL_BASE
ldrr2, =0xf830@ initial value
strr2, [r1, #oNFCONF]
ldrr2, [r1, #oNFCONF]
bicr2, r2, #0×800@ enable chip
strr2, [r1, #oNFCONF]
movr2, #0xff@ RESET command
strbr2, [r1, #oNFCMD]
movr3, #0@ wait
1:addr3, r3, #0×1
cmpr3, #0xa
blt1b
2:ldrr2, [r1, #oNFSTAT]@ wait ready
tstr2, #0×1
beq2b
ldrr2, [r1, #oNFCONF]
orrr2, r2, #0×800@ disable chip
strr2, [r1, #oNFCONF]

@ get read to call C functions (for nand_read())
ldrsp, DW_STACK_START@ setup stack pointer
movfp, #0@ no previous frame, so fp=0

@ copy vivi to RAM
ldrr0, =VIVI_RAM_BASE  //(DRAM_BASE + DRAM_SIZE – VIVI_RAM_SIZE)
//0×33f00000
mov     r1, #0×0//start address, now vivi is in steppingstone
movr2, #0×20000//128k ?
blnand_read_ll
// nand_read_ll(unsigned char *buf, unsigned long start_addr, int size)
// ro = buf , r1 =start , size = r2=128k ??yeah ? 要这么多干吗?
tstr0, #0×0//返回值在r0中
beqok_nand_read//nand_read_ll()顺利返回
#ifdef CONFIG_DEBUG_LL
bad_nand_read:
ldrr0, STR_FAIL
ldrr1, SerBase
blPrintWord
1:b1b@ infinite loop
#endif

ok_nand_read:
#ifdef CONFIG_DEBUG_LL
ldrr0, STR_OK
ldrr1, SerBase
blPrintWord
#endif

@ verify
movr0, #0//flash start add? no. 是用NAND启动时,从NAND copy到phy add=0的4Kbytes SRAM(stepping stone)中的vivi
ldrr1, =0×33f00000//VIVI_RAM_BASE
// VIVI_RAM_BASE = (DRAM_BASE + DRAM_SIZE(64M) – VIVI_RAM_SIZE)
//= 0×3000_0000+0×0400_0000-0×0010_0000 = 0×33f0_0000
movr2, #0×400@ 4 bytes * 1024 = 4K-bytes //移4K去VIVI_RAM_BASE ?NO   比较4Kbytes? YES
go_next:
ldrr3, [r0], #4//将[r0]指向的数据(32bit?)放进r3 ,然后r0+4->r0
ldrr4, [r1], #4//将[r1]指向的数据(32bit?)放进r4 ,然后r1+4->r1
teqr3, r4//比较r3/r4的大小
bnenotmatch//出现不匹配的情况
subsr2, r2, #4//r2-4 ->r2, if subs 结果为0,flagZ==1
beqdone_nand_read//若r2==0条件(flagZ==1)成立,跳到done_nand_read
bnego_next//flagZ==0; 说明r2!=0
notmatch:
#ifdef CONFIG_DEBUG_LL
subr0, r0, #4
ldrr1, SerBase
blPrintHexWord
ldrr0, STR_FAIL
ldrr1, SerBase
blPrintWord
#endif
1:b1b//匹配与否,不匹配时去哪里了?
done_nand_read:

#ifdef CONFIG_DEBUG_LL
ldrr0, STR_OK
ldrr1, SerBase
blPrintWord
#endif

movpc, r10//返回罗,在函数入口处movr10, lr


@ clear memory
@ r0: start address
@ r1: length
mem_clear:
movr2, #0
movr3, r2
movr4, r2
movr5, r2
movr6, r2
movr7, r2
movr8, r2
movr9, r2

clear_loop:
stmiar0!, {r2-r9}
subsr1, r1, #(8 * 4)
bneclear_loop

movpc, lr

#endif @ CONFIG_S3C2410_NAND_BOOT


#ifdef CONFIG_BOOTUP_MEMTEST // Low Level Hardware Debuggingà Enable simple memory test  //vivi未用
@
@ Simple memory test function
@
memtest:
movr10, lr

#ifdef CONFIG_DEBUG_LL//low level debugging,往serport上面捣腾信息
movr0, #’M’
ldrr1, SerBase
blPrintChar
movr0, #’T’
ldrr1, SerBase
blPrintChar
movr0, #’S’
ldrr1, SerBase
blPrintChar
movr0, #’T’
ldrr1, SerBase
blPrintChar
movr0, #’ ‘
ldrr1, SerBase
blPrintChar
#endif

       /* check the first 1MB  in increments of 4k *///循环测试1M得SDRAM//我们应该改大点
       mov     r7, #0×1000
       mov     r6, r7, lsl #8  /* 4k << 2^8 = 1MB */
       mov     r5, #DRAM_BASE
//DRAM_BASE =DRAM_BASE0= 0×30000000      /* base address of dram bank 0 */

mem_test_loop:
       mov     r0, r5  
       bl      testram_nostack
       teq     r0, #1  
       beq     badram  

       add     r5, r5, r7
       subs    r6, r6, r7
       bne     mem_test_loop


@ the first megabyte is OK. so let us clear it.
       mov     r0, #((1024 * 1024) / (8 * 4))@ 1MB in steps of 32 bytes
       mov     r1, #DRAM_BASE
       mov     r2, #0  
       mov     r3, #0  
       mov     r4, #0  
       mov     r5, #0  
       mov     r6, #0  
       mov     r7, #0  
       mov     r8, #0  
       mov     r9, #0  

clear_loop_memtest:
       stmia   r1!, {r2-r9}
       subs    r0, r0, #(8 * 4)
       bne     clear_loop_memtest

#ifdef CONFIG_DEBUG_LL
ldrr0, STR_OK
ldrr1, SerBase
blPrintWord
#endif

movpc, r10@ return  memtest return

badram:
#ifdef CONFIG_DEBUG_LL
ldrr0, STR_FAIL
ldrr1, SerBase
blPrintWord
#endif
1:b1b@ loop 有坏// 死循环?


@ testmem.S: memory tester, test if there is RAM available at given location
@//called by memtest
@ Copyright (C) 2001 Russell King (rmk@arm.linux.org.uk)
@
@ This version clobbers registers r1-r4, so be sure to store their contents
@ in a safe position. This function is not APCS compliant, so only use it
@ from assembly code.
@
@ r0 = address to test
@ returns r0 = 0 – ram present, r0 = 1 – no ram
@ clobbers r1 – r4
ENTRY(testram_nostack)
       ldmia   r0, {r1, r2}    @ store current value in r1 and r2
       mov     r3, #0×55       @ write 0×55 to first word
       mov     r4, #0xaa       @ 0xaa to second
       stmia   r0, {r3, r4}
       ldmia   r0, {r3, r4}    @ read it back
       teq     r3, #0×55       @ do the values match
       teqeq   r4, #0xaa
       bne     bad             @ oops, no
       mov     r3, #0xaa       @ write 0xaa to first word
       mov     r4, #0×55       @ 0×55 to second
       stmia   r0, {r3, r4}
       ldmia   r0, {r3, r4}    @ read it back
       teq     r3, #0xaa       @ do the values match
       teqeq   r4, #0×55
bad:    stmia   r0, {r1, r2}    @ in any case, restore old data
       moveq   r0, #0          @ ok – all values matched
       movne   r0, #1          @ no ram at this location
       mov     pc, lr

#endif @ CONFIG_BOOTUP_MEMTEST

@ Initialize UART
@
@ r0 = number of UART port

//SerBase  = UART0_CTL_BASE = UART_CTL_BASE =0×50000000
// 0×5000_0000 UART channel 0 line control register


InitUART:
ldrr1, SerBase//0×5000_0000
movr2, #0×0
strr2, [r1, #oUFCON]//清零 oUFCON
//#define oUFCON0×08/* R/W, UART FIFO control register */
// UFCON0 0×50000008 R/W UART channel 0 FIFO control register
Tx FIFO Trigger Level [7:6] : 00 : Empty
Rx FIFO Trigger Level [5:4]: 00 : 00 = 4-byte
Tx FIFO Reset [2] : 0 = Normal
Rx FIFO Reset [1] : 0 = Normal
FIFO Enable [0] 0 = Disable
strr2, [r1, #oUMCON]//  * (0×5000_0000 + oUMCON(0×0C) ) = 0;
// UART modem control register
//  Auto Flow Control (AFC) [4] 0 = Disable
// Request to Send [0] = 0; // If AFC bit is enabled, this value will be ignored. In this case
the S3C2410A will control nRTS automatically. If AFC bit is disabled, nRTS must be controlled by software.  0 = ‘H’ level (Inactivate nRTS)   1 = ‘L’ level (Activate nRTS)

movr2, #0×3//
strr2, [r1, #oULCON]//* (0×5000_0000 + oULCON(0×00) ) = 0×3 =0011B
// UART line control register      8N1
// Infra-Red Mode [6] : 0 : 0 = Normal mode operation
// Parity Mode [5:3] : 000 = 0xx = No parity
// Number of Stop Bit [2] : 0 : 0 = One stop bit per frame
// Word Length [1:0] : 11 = 8-bit

ldrr2, =0×245//
strr2, [r1, #oUCON]
/// * (0×5000_0000 + oUCON(0×04) ) = 0×245 = 10 0100 0101 B
// UART control register
// Receive Mode [1:0] : 01 = Interrupt requ est or polling mode
//  Transmit Mode [3:2] 01 = Interrupt request or polling mode
// [4] reserved
// Loopback Mode [5]  0 = normal
// Rx Error Status Interrupt Enable [6]  1  = Generate receive error status interrupt.
// Rx Time Out Enable Interrupt  [ 7] 0 =  Disable
// Rx Interrupt Type [8] = 0 Pulse
// Tx Interrupt Type [9]  = 1 Level
// Clock Selection [10] = 0 =PCLK:  UBRDIVn = (int)(PCLK / (bps x 16) ) -1
// PCLK = ¼ FCLK =50 000 000 Hz
#define UART_BRD ((50000000 / (UART_BAUD_RATE * 16)) – 1)
// 115200  
movr2, #UART_BRD
strr2, [r1, #oUBRDIV] ////* (0×5000_0000 + oUBRDIV(0×28)) = UART_BRD
// /* R/W, Baud rate divisor register */

movr3, #100
movr2, #0×0
1:subr3, r3, #0×1//r3 = r3 –1 //目的想延迟,结果延迟不料
tstr2, r3// r2 r3  “bit AND”, if result =0 ,flagZ=1, else flagZ=0
bne1b// if flagZ = 0 ,goto 1 // if r2 r3 ‘bit AND’结果 为1 才会goto1

#if 0
movr2, #’U’
strr2, [r1, #oUTXHL]

1:ldrr3, [r1, #oUTRSTAT]
andr3, r3, #UTRSTAT_TX_EMPTY
tstr3, #UTRSTAT_TX_EMPTY
bne1b

movr2, #’0′
strr2, [r1, #oUTXHL]

1:ldrr3, [r1, #oUTRSTAT]
andr3, r3, #UTRSTAT_TX_EMPTY
tstr3, #UTRSTAT_TX_EMPTY
bne1b
#endif

movpc, lr//return


@
@ Exception handling functions
@//基本都是 infinite loop
HandleUndef://handle undefined instructions
#ifdef CONFIG_DEBUG_LL
movr12, r14
ldrr0, STR_UNDEF
ldrr1, SerBase
blPrintWord
blPrintFaultAddr
#endif
1:b1b@ infinite loop

HandleSWI://handle software interrupt exception
#ifdef CONFIG_DEBUG_LL
movr12, r14
ldrr0, STR_SWI
ldrr1, SerBase
blPrintWord
blPrintFaultAddr
#endif
1:b1b@ infinite loop

HandlePrefetchAbort://handle prefetch abort exception
#ifdef CONFIG_DEBUG_LL
movr12, r14
ldrr0, STR_PREFETCH_ABORT
ldrr1, SerBase
blPrintWord
blPrintFaultAddr
#endif
1:b1b@ infinite loop

HandleDataAbort://handle data access memory abort
#ifdef CONFIG_DEBUG_LL
movr12, r14
ldrr0, STR_DATA_ABORT
ldrr1, SerBase
blPrintWord
blPrintFaultAddr
#endif
1:b1b@ infinite loop

HandleIRQ://handle IRQ exception
#ifdef CONFIG_DEBUG_LL
movr12, r14
ldrr0, STR_IRQ
ldrr1, SerBase
blPrintWord
blPrintFaultAddr
#endif
1:b1b@ infinite loop

HandleFIQ://handle FIRQ exception
#ifdef CONFIG_DEBUG_LL
movr12, r14
ldrr0, STR_FIQ
ldrr1, SerBase
blPrintWord
blPrintFaultAddr
#endif
1:b1b@ infinite loop

HandleNotUsed:
#ifdef CONFIG_DEBUG_LL
movr12, r14
ldrr0, STR_NOT_USED
ldrr1, SerBase
blPrintWord
blPrintFaultAddr
#endif
1:b1b@ infinite loop


@
@ Low Level Debug
@
#ifdef CONFIG_DEBUG_LL

@
@ PrintFaultAddr: Print falut address
@
@ r12: contains address of instruction + 4
@
PrintFaultAddr:
movr0, r12@ Print address of instruction + 4
ldrr1, SerBase
blPrintHexWord
mrcp15, 0, r0, c6, c0, 0@ Read fault virtual address
ldrr1, SerBase
blPrintHexWord
movpc, lr

@ PrintHexNibble : prints the least-significant nibble in R0 as a
@ hex digit
@   r0 contains nibble to write as Hex
@   r1 contains base of serial port
@   writes ro with XXX, modifies r0,r1,r2
@   TODO : write ro with XXX reg to error handling
@   Falls through to PrintChar
PrintHexNibble:
adrr2, HEX_TO_ASCII_TABLE
andr0, r0, #0xF
ldrr0, [r2, r0]@ convert to ascii
bPrintChar

@ PrintChar : prints the character in R0
@   r0 contains the character
@   r1 contains base of serial port
@   writes ro with XXX, modifies r0,r1,r2
@   TODO : write ro with XXX reg to error handling
PrintChar:
TXBusy:
ldrr2, [r1, #oUTRSTAT]
andr2, r2, #UTRSTAT_TX_EMPTY
tstr2, #UTRSTAT_TX_EMPTY
beqTXBusy
strr0, [r1, #oUTXHL]
movpc, lr

@ PrintWord : prints the 4 characters in R0
@   r0 contains the binary word
@   r1 contains the base of the serial port
@   writes ro with XXX, modifies r0,r1,r2
@   TODO : write ro with XXX reg to error handling
PrintWord:
movr3, r0
movr4, lr
blPrintChar

movr0, r3, LSR #8/* shift word right 8 bits */
blPrintChar

movr0, r3, LSR #16/* shift word right 16 bits */
blPrintChar

movr0, r3, LSR #24/* shift word right 24 bits */
blPrintChar

movr0, #’\r’
blPrintChar

movr0, #’\n’
blPrintChar

movpc, r4

@ PrintHexWord : prints the 4 bytes in R0 as 8 hex ascii characters
@   followed by a newline
@   r0 contains the binary word
@   r1 contains the base of the serial port
@   writes ro with XXX, modifies r0,r1,r2
@   TODO : write ro with XXX reg to error handling
PrintHexWord:
movr4, lr
movr3, r0
movr0, r3, LSR #28
blPrintHexNibble
movr0, r3, LSR #24
blPrintHexNibble
movr0, r3, LSR #20
blPrintHexNibble
movr0, r3, LSR #16
blPrintHexNibble
movr0, r3, LSR #12
blPrintHexNibble
movr0, r3, LSR #8
blPrintHexNibble
movr0, r3, LSR #4
blPrintHexNibble
movr0, r3
blPrintHexNibble

movr0, #’\r’
blPrintChar

movr0, #’\n’
blPrintChar

movpc, r4
#endif

@
@ Data Area
@
@ Memory configuration values
.align 4
mem_cfg_val:
.longvBWSCON
.longvBANKCON0
.longvBANKCON1
.longvBANKCON2
.longvBANKCON3
.longvBANKCON4
.longvBANKCON5
.longvBANKCON6
.longvBANKCON7
.longvREFRESH
.longvBANKSIZE
.longvMRSRB6
.longvMRSRB7

@ Processor clock values
.align 4
clock_locktime:
.longvLOCKTIME
mpll_50mhz:
.longvMPLLCON_50
#ifdef CONFIG_S3C2410_MPORT1
mpll_100mhz:
.long   vMPLLCON_100
#endif
mpll_200mhz:
.longvMPLLCON_200
clock_clkcon:
.longvCLKCON
clock_clkdivn:
.longvCLKDIVN
@ initial values for serial
uart_ulcon:
.longvULCON
uart_ucon:
.longvUCON
uart_ufcon:
.longvUFCON
uart_umcon:
.longvUMCON
@ inital values for GPIO
gpio_con_uart:
.longvGPHCON
gpio_up_uart:
.longvGPHUP

.align2
DW_STACK_START:
.wordSTACK_BASE+STACK_SIZE-4

#ifdef CONFIG_DEBUG_LL
.align2
HEX_TO_ASCII_TABLE:
.ascii"0123456789ABCDEF"
STR_STACK:
.ascii"STKP"
STR_UNDEF:
.ascii"UNDF"
STR_SWI:
.ascii"SWI "
STR_PREFETCH_ABORT:
.ascii"PABT"
STR_DATA_ABORT:
.ascii"DABT"
STR_IRQ:
.ascii"IRQ "
STR_FIQ:
.ascii"FIQ"
STR_NOT_USED:
.ascii"NUSD"
.align 2
STR_OK:
.ascii"OK  "
STR_FAIL:
.ascii"FAIL"
STR_CR:
.ascii  "\r\n"
#endif

.align 4
SerBase:
#if defined(CONFIG_SERIAL_UART0)
.long UART0_CTL_BASE
#elif defined(CONFIG_SERIAL_UART1)
.long UART1_CTL_BASE
#elif defined(CONFIG_SERIAL_UART2)
.long UART2_CTL_BASE
#else
#error not defined base address of serial
#endif

#ifdef CONFIG_PM
.align 4
PMCTL0_ADDR:
.long 0×4c00000c
PMCTL1_ADDR:
.long 0×56000080
PMST_ADDR:
.long 0×560000B4
PMSR0_ADDR:
.long 0×560000B8
REFR_ADDR:
.long 0×48000024
#endif


1.2 Boot Loader 的 stage2

正如前面所说,stage2 的代码通常用 C 语言来实现,以便于实现更复杂的功能和取得更好的代码可读性和可移植性。但是与普通 C 语言应用程序不同的是,在编译和链接 boot loader 这样的程序时,我们不能使用 glibc 库中的任何支持函数。其原因是显而易见的。这就给我们带来一个问题,那就是从那里跳转进 main() 函数呢?直接把 main() 函数的起始地址作为整个 stage2 执行映像的入口点或许是最直接的想法。但是这样做有两个缺点:1)无法通过main() 函数传递函数参数;2)无法处理 main() 函数返回的情况。一种更为巧妙的方法是利用 trampoline(弹簧床)的概念。也即,用汇编语言写一段trampoline 小程序,并将这段 trampoline 小程序来作为 stage2 可执行映象的执行入口点。然后我们可以在 trampoline 汇编小程序中用 CPU 跳转指令跳入 main() 函数中去执行;而当 main() 函数返回时,CPU 执行路径显然再次回到我们的 trampoline 程序。简而言之,这种方法的思想就是:用这段 trampoline 小程序来作为 main() 函数的外部包裹(external wrapper)。

下面给出一个简单的 trampoline 程序示例(来自blob):


.text

.globl _trampoline
_trampoline:
blmain
/* if main ever returns we just call it again */
b_trampoline


可以看出,当 main() 函数返回后,我们又用一条跳转指令重新执行 trampoline 程序――当然也就重新执行 main() 函数,这也就是 trampoline(弹簧床)一词的意思所在。

在vivi中采用如下的代码 实现 循环调用: main返回之后 就reset
@ get read to call C functions
ldrsp, DW_STACK_START@ setup stack pointer
// STACK_BASE+STACK_SIZE-4
// STACK_BASE = (VIVI_PRIV_RAM_BASE – STACK_SIZE)
//STACK从上往下用。  所以 STACK_START = STACK_BASE+STACK_SIZE-4
movfp, #0@ no previous frame, so fp=0
mova2, #0@ set argv to NULL

blmain@ call main //如果正常,一去不复返的了

movpc, #FLASH_BASE@ otherwise, reboot, //FLASH_BASE=ROM_BASE0 = 0×0

1.2.1初始化本阶段要使用到的硬件设备

这通常包括:(1)初始化至少一个串口,以便和终端用户进行 I/O 输出信息;(2)初始化计时器等。  在初始化这些设备之前,也可以重新把 LED 灯点亮,以表明我们已经进入 main() 函数执行。  设备初始化完成后,可以输出一些打印信息,程序名字字符串、版本号等。

对VIVI而言,这些已经在stage 1中完成了。

1.2.2 检测系统的内存映射(memory map)

所谓内存映射就是指在整个 4GB 物理地址空间中有哪些地址范围被分配用来寻址系统的 RAM 单元。比如,在 SA-1100 CPU 中,从 0xC000,0000 开始的 512M 地址空间被用作系统的 RAM 地址空间,而在 Samsung S3C44B0X CPU 中,从 0×0c00,0000 到 0×1000,0000 之间的 64M 地址空间被用作系统的 RAM 地址空间。虽然 CPU 通常预留出一大段足够的地址空间给系统 RAM,但是在搭建具体的嵌入式系统时却不一定会实现 CPU 预留的全部 RAM 地址空间。也就是说,具体的嵌入式系统往往只把 CPU 预留的全部 RAM 地址空间中的一部分映射到 RAM 单元上,而让剩下的那部分预留 RAM 地址空间处于未使用状态。由于上述这个事实,因此 Boot Loader 的 stage2 必须在它想干点什么 (比如,将存储在 flash 上的内核映像读到 RAM 空间中) 之前检测整个系统的内存映射情况,也即它必须知道 CPU 预留的全部 RAM 地址空间中的哪些被真正映射到 RAM 地址单元,哪些是处于 "unused" 状态的。

VIVI中 用CONFIG_BOOTUP_MEMTEST 中的memtest完成基本的RAM检测

1.2.3 加载内核映像和根文件系统映像

(1) 规划内存占用的布局

这里包括两个方面:(1)内核映像所占用的内存范围;(2)根文件系统所占用的内存范围。在规划内存占用的布局时,主要考虑基地址和映像的大小两个方面。

对于内核映像,一般将其拷贝到从(MEM_START+0×8000) 这个基地址开始的大约1MB大小的内存范围内(嵌入式 Linux 的内核一般都不操过 1MB)。为什么要把从 MEM_START 到 MEM_START+0×8000 这段 32KB 大小的内存空出来呢?这是因为 Linux 内核要在这段内存中放置一些全局数据结构,如:启动参数和内核页表等信息。

而对于根文件系统映像,则一般将其拷贝到 MEM_START+0×0010,0000 开始的地方。如果用 Ramdisk 作为根文件系统映像,则其解压后的大小一般是1MB。

(2)从 Flash 上拷贝

由于像 ARM 这样的嵌入式 CPU 通常都是在统一的内存地址空间中寻址 Flash 等固态存储设备的,因此从 Flash 上读取数据与从 RAM 单元中读取数据并没有什么不同。用一个简单的循环就可以完成从 Flash 设备上拷贝映像的工作:


while(count) {
*dest++ = *src++; /* they are all aligned with word boundary */
count -= 4; /* byte number */
};


1.2.4 设置内核的启动参数

应该说,在将内核映像和根文件系统映像拷贝到 RAM 空间中后,就可以准备启动 Linux 内核了。但是在调用内核之前,应该作一步准备工作,即:设置 Linux 内核的启动参数。

Linux 2.4.x 以后的内核都期望以标记列表(tagged list)的形式来传递启动参数。启动参数标记列表以标记 ATAG_CORE 开始,以标记 ATAG_NONE 结束。每个标记由标识被传递参数的 tag_header 结构以及随后的参数值数据结构来组成。数据结构 tag 和 tag_header 定义在 Linux 内核源码的include/asm/setup.h 头文件中:


/* The list ends with an ATAG_NONE node. */
#define ATAG_NONE0×00000000

struct tag_header {
u32 size; /* 注意,这里size是字数为单位的 */
u32 tag;
};
……
struct tag {
struct tag_header hdr;
union {
struct tag_corecore;
struct tag_mem32mem;
struct tag_videotextvideotext;
struct tag_ramdiskramdisk;
struct tag_initrdinitrd;
struct tag_serialnrserialnr;
struct tag_revisionrevision;
struct tag_videolfbvideolfb;
struct tag_cmdlinecmdline;

/*
* Acorn specific
*/
struct tag_acornacorn;

/*
* DC21285 specific
*/
struct tag_memclkmemclk;
} u;
};


在嵌入式 Linux 系统中,通常需要由 Boot Loader 设置的常见启动参数有:ATAG_CORE、ATAG_MEM、ATAG_CMDLINE、ATAG_RAMDISK、ATAG_INITRD等。

比如,设置 ATAG_CORE 的代码如下:


params = (struct tag *)BOOT_PARAMS;

params->hdr.tag = ATAG_CORE;
params->hdr.size = tag_size(tag_core);

params->u.core.flags = 0;
params->u.core.pagesize = 0;
params->u.core.rootdev = 0;

params = tag_next(params);


其中,BOOT_PARAMS 表示内核启动参数在内存中的起始基地址,指针 params 是一个 struct tag 类型的指针。宏 tag_next() 将以指向当前标记的指针为参数,计算紧临当前标记的下一个标记的起始地址。注意,内核的根文件系统所在的设备ID就是在这里设置的。

下面是设置内存映射情况的示例代码:


for(i = 0; i < NUM_MEM_AREAS; i++) {
if(memory_map[i].used) {
params->hdr.tag = ATAG_MEM;
params->hdr.size = tag_size(tag_mem32);

params->u.mem.start = memory_map[i].start;
params->u.mem.size = memory_map[i].size;

params = tag_next(params);
}
}


可以看出,在 memory_map[]数组中,每一个有效的内存段都对应一个 ATAG_MEM 参数标记。

Linux 内核在启动时可以以命令行参数的形式来接收信息,利用这一点我们可以向内核提供那些内核不能自己检测的硬件参数信息,或者重载(override)内核自己检测到的信息。比如,我们用这样一个命令行参数字符串"console=ttyS0,115200n8"来通知内核以 ttyS0 作为控制台,且串口采用 "115200bps、无奇偶校验、8位数据位"这样的设置。下面是一段设置调用内核命令行参数字符串的示例代码:


char *p;

/* eat leading white space */
for(p = commandline; *p == ‘ ‘; p++)
;

/* skip non-existent command lines so the kernel will still
   * use its default command line.
*/
if(*p == ‘\0′)
return;

params->hdr.tag = ATAG_CMDLINE;
params->hdr.size = (sizeof(struct tag_header) + strlen(p) + 1 + 4) >> 2;

strcpy(params->u.cmdline.cmdline, p);

params = tag_next(params);


请注意在上述代码中,设置 tag_header 的大小时,必须包括字符串的终止符’\0′,此外还要将字节数向上圆整4个字节,因为 tag_header 结构中的size 成员表示的是字数。

下面是设置 ATAG_INITRD 的示例代码,它告诉内核在 RAM 中的什么地方可以找到 initrd 映象(压缩格式)以及它的大小:


params->hdr.tag = ATAG_INITRD2;
params->hdr.size = tag_size(tag_initrd);

params->u.initrd.start = RAMDISK_RAM_BASE;
params->u.initrd.size = INITRD_LEN;

params = tag_next(params);


下面是设置 ATAG_RAMDISK 的示例代码,它告诉内核解压后的 Ramdisk 有多大(单位是KB):


params->hdr.tag = ATAG_RAMDISK;
params->hdr.size = tag_size(tag_ramdisk);

params->u.ramdisk.start = 0;
params->u.ramdisk.size = RAMDISK_SIZE; /* 请注意,单位是KB */
params->u.ramdisk.flags = 1; /* automatically load ramdisk */

params = tag_next(params);


最后,设置 ATAG_NONE 标记,结束整个启动参数列表:


static void setup_end_tag(void)
{
params->hdr.tag = ATAG_NONE;
params->hdr.size = 0;
}


1.2.5 调用内核

Boot Loader 调用 Linux 内核的方法是直接跳转到内核的第一条指令处,也即直接跳转到 MEM_START+0×8000 地址处。在跳转时,下列条件要满足:

1. CPU 寄存器的设置:

R0=0;


R1=机器类型 ID;关于 Machine Type Number,可以参见 linux/arch/arm/tools/mach-types。


R2=启动参数标记列表在 RAM 中起始基地址;


2. CPU 模式:

必须禁止中断(IRQs和FIQs);


CPU 必须 SVC 模式;


3. Cache 和 MMU 的设置:

MMU 必须关闭;


指令 Cache 可以打开也可以关闭;


数据 Cache 必须关闭;
如果用 C 语言,可以像下列示例代码这样来调用内核:


void (*theKernel)(int zero, int arch, u32 params_addr) = (void (*)(int, int, u32))KERNEL_RAM_BASE;
……
theKernel(0, ARCH_NUMBER, (u32) kernel_params_start);


注意,theKernel()函数调用应该永远不返回的。如果这个调用返回,则说明出错。


Stage2在VIVI中的具体体现
Vivi\init\main.c

int main(int argc, char *argv[])
{
/* * Step 1:   NB:  MMU. */
/* 硬件上按下某个key之后,clear_mem(USER_RAM_BASE(),USER_RAM_SIZE);
// clear_mem()空的呢 */
reset_handler();

/*  Step 2:  Board甫 檬扁拳 钦聪促. */
// init_time(), set_gpios(setting GPIO  registers)
ret = board_init();

/* Step 3:*   4G甫 府聪绢(linear)窍霸 *   MMU甫 难技夸. */
//
mem_map_init();

void mem_map_init(void)
{
#ifdef CONFIG_S3C2410_NAND_BOOT
mem_map_nand_boot();
//mem_mapping_linear-> 将4G空间线性映射成4K个1M空间,并将其中的有效的DRAM做成cacheable
#else
mem_map_nor();
// copy_vivi_to_ram();//àmemcpy(VIVI_RAM_BASE, VIVI_ROM_BASE, VIVI_RAM_SIZE); NOR在这里将vivi从nor flash copy到ram中 VIVI_RAM_BASE= (DRAM_BASE + DRAM_SIZE – VIVI_RAM_SIZE), VIVI_ROM_BASE=0×0, VIVI_RAM_SIZE=SZ_1M  //oho,比NAND在stage 1中copy 128K还多呢 ,1M可是把kernel也给copy到DRAM中了,可惜位置太高,在VIVI_RAM中,不在boot_mem_base+KERNEL_OFFSET,所以后面还会再copy一次的
//mem_mapping_linear();-> 将4G空间线性映射成4K个1M空间,并将其中的DRAM做成cacheable
//nor_flash_mapping();à将FLASH_BASE和FLASH_UNCACHED_BASE 都映射到FLASH_BASE
//0×0 à0×0 ,cacheable ,  0×1000_0000 -> 0×0 , uncacheable   SIZE为FLASH_SIZE
//nor_flash_remapping();->"Map flash virtual section to DRAM at  VIVI_RAM_BASE;
//*(mmu_tlb_base + (VIVI_ROM_BASE >> 20)) = (VIVI_RAM_BASE | MMU_SECDESC | MMU_CACHEABLE);
//0×0 à vivi_ram_base , cacheable  SIZE为1M = MMU_SECTION_SIZE = VIVI RAM的大小
#endif
cache_clean_invalidate();
//clean and invalidate all cache lines
tlb_invalidate();
//Invalidate all TLB entries
}

mmu_init();

// /* Invalidate caches *//* Load page table pointer *//* Write domain id (cp15_r3) */
/* Set control register v4 *//* Clear out ‘unwanted’ bits (then put them in if we need them) */
/* Turn on what we want *//* Fault checking enabled */
#ifdef CONFIG_CPU_D_CACHE_ON enable Data cache
#ifdef CONFIG_CPU_I_CACHE_ON  enable Instruction cache
/* MMU enabled */

/ * Now, vivi is running on the ram. MMU is enabled.
*/

/*  Step 4: initialize the heap area*/
ret = heap_init();

//malloc_init(): initialize heap area at (VIVI_RAM_BASE – HEAP_SIZE), size =HEAP_SIZE (SZ_1M) 这一段为virtual-phy是linear的 //除了NOR中的0×0->VIVI_RAM_BASE, FLASH_UNCACED_BASE(0×1000_0000) à 0×0

/* Step 5:   MTD狼 颇萍记partition 沥焊啊  *. */
ret = mtd_dev_init();

// mtd_init(); 初始化不同的MTD根据 CONFIG_MTD_xxx, and CONFIG_S3C2410_AMD_BOOT, INTEL_BOOT
//注意,这里的初始化 跟MTD partition上面的文件系统没有上面关系
//intel_init()其实就是jedec_init
#ifdef CONFIG_MTD_CFI
add_command(&flash_cmd);
#endif

/* Step 6:. */
init_priv_data();

#ifdef CONFIG_PARSE_PRIV_DATA:
 vivi will be able to get MTD partition information from MTD.
#else, vivi will use default parameters in the vivi’s code.
init_priv_data(void)
{
ret_def = get_default_priv_data();
//get_default_param_tlb()
->cp smdk.c中default_vivi_parameter to VIVI_PRIV_RAM_BASE+PARAMETER_TLB_OFFSET (virt=phy in this area)
//such as mach_type, media_type,boot_mem_base,baudrate, Xmodem, boot_delay
//get_default_linux_cmd())
->cp smdk.c中char linux_cmd[] = "noinitrd root=/dev/bon/2 init=/linuxrc console=ttyS0";
to (VIVI_PRIV_RAM_BASE + LINUX_CMD_OFFSET)
//get_default_mtd_partition()
->smdk中的default_mtd_partitions to VIVI_PRIV_RAM_BASE + MTD_PART_OFFSET
ret_saved = load_saved_priv_data();
//将以前saved param partition 从DRAM_BASE+xxx_OFFSET复制到VIVI_PRIV_RAM_BASE+xxx_OFFSET
//缺省用saved,  上此saved参数
}


/* Step 7: */

misc();
//add_command(&cpu_cmd);
/* add user command ; cpu_cmd可以 Display cpu information and Change cpu clock and bus clock\n");
init_builtin_cmds();
/* Register basic user commands */

/* Step 8: */
boot_or_vivi();
//等timeout(可以在default_parameter boot_delay中设定,可以用boot_delay命令设定,可以。。无关紧要)
//有key按下就vivi,否则就run_autoboot()
//à”boot” àcommand_boot()à
//media_type = get_param_value("media_type", &ret);//default = MT_S3C2410->NAND or NOR
//从*vivi_params = (VIVI_PRIV_RAM_BASE + PARAMETER_TLB_OFFSET + 16);取参数(def or saved)
kernel_part = get_mtd_partition("kernel"); //default=
// mtd_parts = (mtd_partition_t *)(VIVI_PRIV_RAM_BASE + MTD_PART_OFFSET + 16);取参数(def or saved)
from = kernel_part->offset; // default smdk.c中default_mtd_partitions中offset=0×30000
size = kernel_part->size; // default smdk.c中default_mtd_partitions中size=0xC0000

boot_kernel(from, size, media_type);//def: boot_kernel(0×30000,0xC0000,NAND/NOR);

return 0;
}
main()到此结束

int boot_kernel(ulong from, size_t size, int media_type)
{
int ret;
ulong boot_mem_base;/* base address of bootable memory ,vitual = phy add */
ulong to;
ulong mach_type;

boot_mem_base = get_param_value("boot_mem_base", &ret);
//default: 0×3000_0000; vir = linear
if (ret) {
printk("Can’t get base address of bootable memory\n");
printk("Get default DRAM address. (0x%08lx\n", DRAM_BASE);
boot_mem_base = DRAM_BASE;
}

/* copy kerne image */
to = boot_mem_base + LINUX_KERNEL_OFFSET; //0×3000_8000 的说
//copy_vivi_to_ram中已经把kernel copy到了VIVI_RAM,浪费的说

ret = copy_kernel_img(to, (char *)from, size, media_type);
// case MT_NOR_FLASH:
//memcpy((char *)to, (from + FLASH_UNCACHED_BASE), size);
// virtual add FLASH_UNCACHED_BASE 对应phy add 0×0,又从flash里面copy一次kernel 到to
//case MT_SMC_S3C2410: //按NAND的规矩copy
//ret = nand_read_ll((unsigned char *)dst,  (unsigned long)src, (int)size);

/* 检查是否是compressed linux kernel image */
if (*(ulong *)(to + 9*4) != LINUX_ZIMAGE_MAGIC) {
printk("Warning: this binary is not compressed linux kernel image\n");
printk("zImage magic = 0x%08lx\n", *(ulong *)(to + 9*4));
} else {
printk("zImage magic = 0x%08lx\n", *(ulong *)(to + 9*4));
}

/* Setup linux parameters and linux command line */
setup_linux_param(boot_mem_base + LINUX_PARAM_OFFSET); 0×3000_0100
// LINUX_PARAM_OFFSET0×100
// params->u1.s.page_size = LINUX_PAGE_SIZE  ;  = SZ_4K
//params->u1.s.nr_pages = (DRAM_SIZE >> LINUX_PAGE_SHIFT); //SZ_4K =12bit =LINUX_PAGE_SHIFT
//加点什么for NOR?
///* set linux command line */
//linux_cmd = get_linux_cmd_line();-> char *linux_cmd_line = (char *)(VIVI_PRIV_RAM_BASE + LINUX_CMD_OFFSET + 8);
//if (linux_cmd == NULL) {//default = smdk.c中char linux_cmd[] = "noinitrd root=/dev/bon/2 init=/linuxrc console=ttyS0";
//printk("Wrong magic: could not found linux command line\n");
//} else {
//memcpy(params->commandline, linux_cmd, strlen(linux_cmd) + 1);
//printk("linux command line is: \"%s\"\n", linux_cmd);
//}

/* Get machine type */
mach_type = get_param_value("mach_type", &ret);//default :smdk2410.h  MACH_TYPE 193
printk("MACH_TYPE = %d\n", mach_type);

/* Go Go Go */
printk("NOW, Booting Linux……\n");
call_linux(0, mach_type, to);
// void  call_linux(long a0, long a1, long a2)
/* r0 = must contain a zero or else the kernel loops
* r1 = architecture type
* r2 = address to be executed */
//{
//cache_clean_invalidate();
//tlb_invalidate();

__asm__(
"movr0, %0\n"// a0
"movr1, %1\n"// a1
"movr2, %2\n"// a2
"movip, #0\n"
"mcrp15, 0, ip, c13, c0, 0\n"/* zero PID */
"mcrp15, 0, ip, c7, c7, 0\n"/* invalidate I,D caches */
"mcrp15, 0, ip, c7, c10, 4\n"/* drain write buffer */
"mcrp15, 0, ip, c8, c7, 0\n"/* invalidate I,D TLBs */
"mrcp15, 0, ip, c1, c0, 0\n"/* get control register */
"bicip, ip, #0×0001\n"/* disable MMU */
"mcrp15, 0, ip, c1, c0, 0\n"/* write control register */
"movpc, r2\n"
"nop\n"
"nop\n"
: /* no outpus */
: "r" (a0), "r" (a1), "r" (a2)
);
}
return 0;
}

实现自己的s3c2410系统需要对bootloader修改的部分:
1.INTEL_CMD for MTD device  DONE
2.常量FLASH_SIZE, ROM_SIZE, RAM_SIZE
3.linux_cmd[] != "noinitrd root=/dev/bon/2 init=/linuxrc console=ttyS0"; 改
mem=16M root=/dev/mtdblock2 init=/bin/init
来自89712 kernel的CONFIG_CMDLINE="mem=16M root=/dev/mtdblock2 init=/bin/init"。Arch/arm/setup.c

root =  MAJOR  MINOR MTD参数等等有关
4.Linux parameter的问题,如何传入,现有vivi用struct param_struct传入,我们应该改点什么才对;在CS89712的hermit-P2中,用的是struct tag传入,可是没打算boot;在EP7211的hermit中,打算boot,但是用的是param_struct;
Hermit-P1中用的也是tag
我们的系统在param或者tag里面传出自己flash/ram的特性 ft
params->u1.s.rootdev = MKDEV(MTD_MAJOR, MTD_MINOR); //(31,3)

附录 一 CDB89712 linux中的有关参数
其中rootdev = (MTD_MAJOR,MTD_MINOR) = (31,3) /* i boot on /dev/mtd3 */
//    /dev/mtdblock3?  (31,3)
The default location for rootfs image is mtd3, put your image at the mtd3 start address (or modify the ‘MTD_MINOR’ variable in tags.h).
mtd3: 00400000 00020000 "cdb89712 flash free partition" ( starting at 0×400000, put your rootfs image here)

但是,干吗CONFIG_CMDLINE="mem=16M root=/dev/mtdblock2 init=/bin/init"
?? /dev/mtdblock2 (31,2)

呵呵,没法,只好自己试。
Struct mtd_partition {
{bootloader// /dev/mtdblock031 0
},{kernel// /dev/mtdblock131 1
},{jffs2// /dev/mtdblock231 2
}
}

/dev/mtdblock 1 2 都试试
在2410的arch\arm\mach-s3c2410\smdk.c中

附录二  需要对kernel(zImage)和jffs2解压么?
vivi中boot_kernel可没有uncompress/decompress kernel的说

附录三 关于mtd partition在bootloader和kernel中的差别

在bootloader/ vivi中,为了方便 用户从命令行输入parameter参数,所以增加了一个param partition,;在bootloader后期,会将有关参数cp 到bootmem + LINUX_PARAM_OFFSET处。
而在kernel中,通常就用3个标准的partition:bootloader/kernel/ rootfs(e.g.jffs2)

linux kernel启动的入口处

MACHINE_START(SMDK2410, "Samsung-SMDK2410")
//大清早刚进来,MMU还没启动呢
BOOT_MEM(0×30000000, 0×48000000, 0xe8000000)
//pram:0×30000000: physical start address of RAM
//pio: 0×4800_0000 phy adrr of 8MB region containing IO for use with the debugging macros in arch/arm/kernel/debug-armv.S
//vio: 0xe8000_0000 virtual address of the 8MB debugging region

BOOT_PARAMS(0×30000100)
//Physical address of struct param_struct or tag list, giving the kernel various parameters about its execution enviroment
FIXUP(fixup_smdk)
MAPIO(smdk_map_io)
INITIRQ(s3c2410_init_irq)
MACHINE_END

附录 关于do_map_probe

在vivi中,没有支持jedec_probe //command_set001,所以我们自己增加了intel_flash.c etc

在kernel中,对jedec_probe的支持没有问题,command_set0001也存在,所以我们可以完全不理会下层的实现,专心将drivers/mtd/maps/cdb89712.c改造成smdk2410.c就可以了.
cdb89712.c中有关将片内SRAM和BOOT_ROM映射为MTD的部分不理会。

注意在config.in中增加相应的:CONFIG_MTD_SMDK2410


附录 param_struct 与tag_list的对比

以下代码来自testasecca的boot-patch for  89712
http://ttestasecca.free.fr/cdb89712/patch/boot_patch
cdb89712/kernel/arch/boot/compressed/misc.c

int hermit_linux_cmdfunc(int argc, char *argv[])
{
       struct tag *tag = (struct tag *) LINUX_PARAM_ADDRESS;

       /* zero param block */
       memzero (tag, LINUX_PARAM_SIZE);

       /* set up core tag */
       tag->hdr.tag = ATAG_CORE;
       tag->hdr.size = tag_size(tag_core);
       tag->u.core.flags = 0;
       tag->u.core.pagesize = 0×1000;
       tag->u.core.rootdev = MKDEV(MTD_MAJOR, MTD_MINOR);

       /* 16 MB of SDRAM at 0xc0000000 */
       tag = tag_next(tag);
       tag->hdr.tag = ATAG_MEM;
       tag->hdr.size = tag_size(tag_mem32);
       tag->u.mem.size = DRAM1_SIZE >> 12;
       tag->u.mem.start = DRAM1_START;

       /* an initial ramdisk image in flash at 0×00700000 */
/*      tag = tag_next(tag);
       tag->hdr.tag = ATAG_INITRD;
       tag->hdr.size = tag_size(tag_initrd);
       tag->u.initrd.start = INITRD_LOAD_ADDRESS;
       tag->u.initrd.size  = INITRD_SIZE; */
       /* the command line arguments */

/*      if (argc > 1) {
               tag = tag_next(tag);
               tag->hdr.tag = ATAG_CMDLINE;
               tag->hdr.size = (COMMAND_LINE_SIZE + 3 +
                        sizeof(struct tag_header)) >> 2;

               {
                       const unsigned char *src;
                       unsigned char *dst;
                       dst = tag->u.cmdline.cmdline;
                       memzero (dst, COMMAND_LINE_SIZE);
                       while (–argc > 0) {
                               src = *++argv;
                               hprintf ("Doing %s\n", src);
                               while (*src)
                                       *dst++ = *src++;
                               *dst++ = ‘ ‘;
                       }
                       *–dst = ‘\0′;
               }
       }
*/


       tag = tag_next(tag);
       tag->hdr.tag = 0;
       tag->hdr.size = 0;

       /* branch to kernel image */
       __asm__ volatile (
       "       mov     r4, #0×00000000\n"      /* start of flash */
       "       add     r4, r4, #0×00020000\n"  /* kernel offset in flash*/
       "       mov     r0, #0\n"               /* kernel sanity check */
       "       mov     r1, #107\n"             /* CDB89712 arch. number */
       "       mov     r2, #0\n"
       "       mov     r3, #0\n"
//        "       mov     pc, r4"                 /* go there! */
       );

       /* never get here */
       return 0;
}

以下来自VIVI/lib/boot_kernel.c
static void setup_linux_param(ulong param_base)
{
struct param_struct *params = (struct param_struct *)param_base;
char *linux_cmd;

printk("Setup linux parameters at 0x%08lx\n", param_base);
memset(params, 0, sizeof(struct param_struct));

/* ²¿¿À¿Á ÇØÁà¾ß µÉ °Íµé.. ³­µð°¡ °æÇèÀûÀ¸·Î ´ëÃæ ÂïÀº °Í.. */
params->u1.s.page_size = LINUX_PAGE_SIZE;
params->u1.s.nr_pages = (DRAM_SIZE >> LINUX_PAGE_SHIFT);
#if 0
params->u1.s.page_size = LINUX_PAGE_SIZE;
params->u1.s.nr_pages = (dram_size >> LINUX_PAGE_SHIFT);
params->u1.s.ramdisk_size = 0;
params->u1.s.rootdev = rootdev;
params->u1.s.flags = 0;

/* TODO */
/* If use ramdisk */
/*
params->u1.s.initrd_start = ?;
params->u1.s.initrd_size = ?;
params->u1.s.rd_start = ?;
*/

#endif

/* set linux command line */
linux_cmd = get_linux_cmd_line();
if (linux_cmd == NULL) {
printk("Wrong magic: could not found linux command line\n");
} else {
memcpy(params->commandline, linux_cmd, strlen(linux_cmd) + 1);
printk("linux command line is: \"%s\"\n", linux_cmd);
}
}

附录 struct param_struct解释
asm-arm/setup.h

/* This is the old deprecated way to pass parameters to the kernel */
struct param_struct {
   union {
       struct {
           unsigned long page_size;            /*  0 */
           unsigned long nr_pages;             /*  4 */
           unsigned long ramdisk_size;         /*  8 */
           unsigned long flags;                /* 12 */
#define FLAG_READONLY   1
#define FLAG_RDLOAD     4
#define FLAG_RDPROMPT   8
           unsigned long rootdev;              /* 16 */
           unsigned long video_num_cols;       /* 20 */
           unsigned long video_num_rows;       /* 24 */
           unsigned long video_x;              /* 28 */
           unsigned long video_y;              /* 32 */
           unsigned long memc_control_reg;     /* 36 */
           unsigned char sounddefault;         /* 40 */
           unsigned char adfsdrives;           /* 41 */
           unsigned char bytes_per_char_h;     /* 42 */
           unsigned char bytes_per_char_v;     /* 43 */
           unsigned long pages_in_bank[4];     /* 44 */
           unsigned long pages_in_vram;        /* 60 */
           unsigned long initrd_start;         /* 64 */
           unsigned long initrd_size;          /* 68 */
           unsigned long rd_start;             /* 72 */
           unsigned long system_rev;           /* 76 */
           unsigned long system_serial_low;    /* 80 */
           unsigned long system_serial_high;   /* 84 */
           unsigned long mem_fclk_21285;       /* 88 */
       } s;
       char unused[256];
   } u1;
   union {
       char paths[8][128];
       struct {
           unsigned long magic;
           char n[1024 - sizeof(unsigned long)];
       } s;
   } u2;
   char commandline[COMMAND_LINE_SIZE];
};

Kernel initialisation parameters on ARM Linux
———————————————

The following document describes the kernel initialisation parameter
structure, otherwise known as ’struct param_struct’ which is used
for most ARM Linux architectures.

This structure is used to pass initialisation parameters from the
kernel loader to the Linux kernel proper, and may be short lived
through the kernel initialisation process.  As a general rule, it
should not be referenced outside of arch/arm/kernel/setup.c:setup_arch().

There are a lot of parameters listed in there, and they are described
below:

page_size

  This parameter must be set to the page size of the machine, and
  will be checked by the kernel.

nr_pages

  This is the total number of pages of memory in the system.  If
  the memory is banked, then this should contain the total number
  of pages in the system.

  If the system contains separate VRAM, this value should not
  include this information.

ramdisk_size

  This is now obsolete, and should not be used.

flags

  Various kernel flags, including:
   bit 0 – 1 = mount root read only
   bit 1 – unused
   bit 2 – 0 = load ramdisk
   bit 3 – 0 = prompt for ramdisk

rootdev

  major/minor number pair of device to mount as the root filesystem.

video_num_cols
video_num_rows

  These two together describe the character size of the dummy console,
  or VGA console character size.  They should not be used for any other
  purpose.

  It’s generally a good idea to set these to be either standard VGA, or
  the equivalent character size of your fbcon display.  This then allows
  all the bootup messages to be displayed correctly.

video_x
video_y

  This describes the character position of cursor on VGA console, and
  is otherwise unused. (should not used for other console types, and
  should not be used for other purposes).

memc_control_reg

  MEMC chip control register for Acorn Archimedes and Acorn A5000
  based machines.  May be used differently by different architectures.

sounddefault

  Default sound setting on Acorn machines.  May be used differently by
  different architectures.

adfsdrives

  Number of ADFS/MFM disks.  May be used differently by different
  architectures.

bytes_per_char_h
bytes_per_char_v

  These are now obsolete, and should not be used.

pages_in_bank[4]

  Number of pages in each bank of the systems memory (used for RiscPC).
  This is intended to be used on systems where the physical memory
  is non-contiguous from the processors point of view.

pages_in_vram

  Number of pages in VRAM (used on Acorn RiscPC).  This value may also
  be used by loaders if the size of the video RAM can’t be obtained
  from the hardware.

initrd_start
initrd_size

  This describes the kernel virtual start address and size of the
  initial ramdisk.

rd_start

  Start address in sectors of the ramdisk image on a floppy disk.

system_rev

  system revision number.

system_serial_low
system_serial_high

  system 64-bit serial number

mem_fclk_21285

  The speed of the external oscillator to the 21285 (footbridge),
  which control’s the speed of the memory bus, timer & serial port.
  Depending upon the speed of the cpu its value can be between
  0-66 MHz. If no params are passed or a value of zero is passed,
  then a value of 50 Mhz is the default on 21285 architectures.

paths[8][128]

  These are now obsolete, and should not be used.

commandline

  Kernel command line parameters.  Details can be found elsewhere.


附录四  MTD_PARTITION 从vivi bootloader和kernel两个角度
vivi bootlader 看NAND下的partition ,
vivi/arch/smdk.c

以下为缺省
#ifdef CONFIG_S3C2410_NAND_BOOT
mtd_partition_t default_mtd_partitions[] = {
{
name:"vivi",
offset:0,
size:0×00020000,// 128k
flag:0
}, {
name:"param",
offset:0×00020000,//128k
size:0×00010000,//64k
flag:0
}, {
name:"kernel",
offset:0×00030000,//192k
size:0×000C0000,//768k
flag:0
}, {
name:"root",
offset:0×00100000,
size:0×00140000,
flag:MF_BONFS//simple block filesystem over NAND
// #define MF_BONFS0×00000004, priv_data.h
}
};

s3c2410\kernel\drivers\mtd\nand\smc_smdk2410.c

#undef CONFIG_MTD_SMC_S3C2410_SMDK_PARTITION

/*
* MTD structure for S3C2410 Development Board
*/
static struct mtd_info *s3c2410_mtd = NULL;

#ifdef CONFIG_MTD_SMC_S3C2410_SMDK_PARTITION
#include <linux/mtd/partitions.h>

static struct mtd_partition smc_partitions[] = {
{
name:"kernel",
size:0×000c0000,
//size:0×00200000,
offset:0×0,
mask_flags:MTD_WRITEABLE,/*force read-only */
}, {
name:"root",
size:0×00a00000,
offset:MTDPART_OFS_APPEND,
mask_flags:MTD_WRITEABLE,  /* force read-only */
}
};
#endif

所以,在vivi bootlader中需要对SMC进行划分区.

问题:
除了通过linux-parameter把kernel所在区域传入boot-kernel了之外,root.cramfs的partition分区信息怎么传入的呢?
答案
smdk.c cmd line? linux_cmd[] = "noinitrd root=/dev/bon/2 init=/linuxrc console=ttyS0"; //呵呵,考,躲这里的说
这里用的虽然是root=/dev/bon/2,但是
悖论“linux的设备都是在/dev/下,访问这些设备文件需要设备驱动程序支持,而访问设备文件才能取得设备号,才能加载驱动程序,那么第一设备驱动程序是怎么加载呢”
答案ROOT_DEV,不需要访问设备文件,直接制定设备号。
就是是直接用设备号(bon,2),它的partition信息在哪里?在bootloader中虽然用vivi> bon part 0 192k 2M做了分区,part2就是 for root的,但这些信息并不会传入kernel,除非。。??

cramfsck打开root.cramfs,看看里面的bon/2的定义,是否有init script完成分区
“Let’s write root filesystem in SMC. The steps of this work are the same as those of above. But there is one caution.
vivi can’t write the root image, which size is bigger than 1.2MB, on SMC. Because vivi is coded to use decided partition size of bon filesystem that is a kinds of layer for nand flash, although it controls all area of SMC. The decided size is approximately 1.2~1.3MB.
So, please use small size of root image when writing root filesystem on SMC. If you have finished this work well and rebooted target system, you can use the console of target system.”
这就是为啥 vivi首先用自己做SMC partition, writing (1) vivi (2) kernel (3)root.cramfs<1.3M
然后用Ztelent/minicom 下载root_qtopia.cramfs, 用imagewrite把image写入NAND,大约有40M
drivers/mtd/nand/bon.c
int __init part_setup(char *options)
{
   if (!options || !*options) return 0;
   PARTITION_OFFSET = simple_strtoul(options, &options, 0);
   if (*options == ‘k’ || *options == ‘K’) {
PARTITION_OFFSET *= 1024;
   } else if (*options == ‘m’ || *options == ‘M’) {
PARTITION_OFFSET *= 1024;
   }
   return 0;
}
__setup("nand_part_offset=", part_setup);

虽然vivi/drivers/mtd/nand/bon.c中有comand_part命令能够将在vivi命令行中输入的bon命令划分bon,但是这些partition参数可没看见被传入kernel such as param_struct/a_tag

终于搞清楚了,
在VIVI中,在bon划分partition时,在offset = mtd->size – mtd->erasesize 最后一块eraseblock中,写入了BON_MAGIC (8BYTE), PARTITION INFO
vivi/drivers/mtd/bon.c
write_partition()
memcpy(buf, bon_part_magic, 8);
s = (unsigned int *)(buf+8);
*s++ = num_part;
for (i = 0; i < num_part; i++) {
*s++ = parts[i].offset;
*s++ = parts[i].size;
*s++ = parts[i].flag;
}
在kernel中linux/drivers/mtd/nand/bon.c
read_partition_info()
if (MTD_READ(mtd, offset, 512, &retlen, buf) < 0) {
   goto next_block;
}
if (strncmp(buf, BON_MAGIC, 8) == 0) break;
然后是:   s = (unsigned int *)(buf + 8);
  for(i=0;i < bon.num_part; i++) {
char name[8];
//int num_block;
bon.parts[i].offset = *s++;
bon.parts[i].size = *s++;
bon.parts[i].flag = *s++;
}
附录五 关于__setup 在内核中的作用 ,参考linux\init\main.c
以下内容来自
jeppeter (member) from http:// linuxforum.net


你的这个问题,我从google上查找到了一些资料,再结合内核源代码,就在这里把这个问题说的清楚一点.
首先,这里有一个简短的回答,
http://mail.nl.linux.org/kernelnewbies/2003-03/msg00043.html

从这上面的意思是这里会从main.c 中的checksetup函数中运行,这个函数是这样的

static int __init checksetup(char *line)
{
struct kernel_param *p;

p = &__setup_start;
do {
int n = strlen(p->str);
if (!strncmp(line,p->str,n)) {
if (p->setup_func(line+n))
return 1;
}
p++;
} while (p < &__setup_end);
return 0;
}

这里的意思是从__setup_start开始处到__setup_end处中查找一个数据结构,这个数据结构中有str与setup_func这两个数据成员变量.
只要与这里面的str与输入的参数字符串相匹配,就会调用个这个字符串后面所指的内容,
对于你这里所说的 __setup("console=",console_setup); 就是你在启动linux内核的时候如果有这么一个参数输入console=ttyS1,那内核就会
把默认的tty定位为ttyS1,这个在consol_setup函数的字符串处理中完成,因为它最后是确定prefered_console的参数.


那把这在这里实现这个的内容是这样的,

__setup() 是一个宏定义,在include/linux/init.h这个文件中.
struct kernel_param {
const char *str;
int (*setup_func)(char *);
};

extern struct kernel_param __setup_start, __setup_end;

#define __setup(str, fn) \
static char __setup_str_##fn[] __initdata = str; \
static struct kernel_param __setup_##fn __attribute__((unused)) __initsetup = { __setup_str_##fn, fn }

在这个情景中作了替换是这样的

static char __setup_str_console_setup[] = "console=";
static struct kernel_param __setup_console_setup = { __setup_str_console_setup, console_setup}

这样你还可能不是很清楚,那你就要参考arch/i386/vmlinuz.lds这个关于ld 链接器的脚本文件有这样的一段

__setup_start = .;
.setup.init : { *(.setup.init) }
__setup_end = .;


这里的意思就是__setup_start是一个节的开始,而__setup_end是一个节的结束,这个节的名称是.setup,init,
这个你可以用readelf -a这个来看一下你的vmlinux-2.4.20-8(后面的数字与你的内核版本有关)这个文件,
可以看到有一个叫.setup.init的节,__setup_start就是指这个节的开始,那这个节中有什么内容呢,其实就是一个
数据结构,一个就是str,一个就是setup_func,与我前面的说法相一致,那具体是什么呢,就是一个在.init.data节中存储的
字符串—–__initdata是一个宏,就是(__attribute__ ((__section__ (".data.init")))), 所以你可以.data.init在vmlinux-2.4.20-8中的
在文件中的偏移量与加载的的虚拟地址偏移量相减就可以得到,
举个例子,所有的这些都是用readelf 与od 命令得到的
我现在用的内核版本,它的.setup.init的节在0×26dd60的文件偏移处.
[10] .data.init PROGBITS c0368040 268040 005d18 00 WA 0 0 32
[11] .setup.init PROGBITS c036dd60 26dd60 0001b0 00 WA 0 0 4

再查找console_setup在vmlinux-2.4.20-8所被映射为内存地址,
840: c0355d40 343 FUNC LOCAL DEFAULT 9 console_setup

这就可以知道了它所在的位置,就是0xc0355d40,这就是它的虚拟映射地址

再用下面一条命令
od –address-radix=x -t x4 vmlinux-2.4.20-8 |grep -A 20 26dd60 |head -20 | grep c0355d40
可以得到
26de40 c036943b c0355d10 c0369447 c0355d40

很明显,这个函数的处理字符串在内存中的地址是0xc0369447,与前面得到的.data.init节在内存映射中的位置
0xc0368040相减就是 0×1407,与.data.init在文件中的偏移量0×268040相加就得到0×269447
这样用
od –address-radix=x -a vmlinux-2.4.20-8 |grep -A 2 269440

就可以得到下面的内容,
269440 b l i n k = nul c o n s o l e = nul
269450 r e s e r v e = nul nul nul nul nul nul nul nul
269460 ` dc4 6 @ ` dc4 6 @ c p u f r e q =

"console="这个值果真就在这里.

(注:前面od 的选项 –address-radix= 表示的是显示文件偏移量的格式,默认下是o就是八进制, -t 表示显示文件二进制的形式
默认是o6 就是八进制的6位长,而-a表示显示的是字符串格式.)
这是一点感受,与大家分享,希望大家提出宝贵意见.

1. Introduction

In ADS and SDT environment, arm asm is usually used, it can be compiled by arm compiler, armcc.

While for linux programming environment, we use GNU GCC compiler that supports GNU asm (GAS).

These two kinds of asm compiler has different syntax, so it’s important to replant one kind of code to another.

In this document, the most important things that should be kept in mind during the replanting stage is put.

2.    replanting

2.1    Replanting of .s file

2.1.1    Comment

In arm asm, “;” is used to comment off a line.

In GAS, we use “@”, “#” or “//” can be used to comment off a line, and “/*  */” can be used to comment off more than one line.

The example below show the difference,

For ADS environment

;

; —————————————————————————

;Static Global Data section variables

;—————————————————————————

;

; ————————– NONE ——————————————-

 

For GAS environment

@

/* —————————————————————————

@Static Global Data section variables

@—————————————————————————

*/

// ————————– NONE ——————————————-

 

 

2.1.2    Operator

(1). Define a constant:

ADS:  @TIMER1_CTRL              EQU     0×0A800008

GAS:  .equ              TIMER1_CTRL,  0×0A800008

(2). Define a label or symbal:

ADS:  LABEL_ONE

GAS:  LABEL_ONE:

(3).

ADS:  DCD

GAS:  .long

(4). Define a function:

ADS:  myfunc FUNCTION

XXXX  

XXXX

ENDFUNC

Or

myfunc PROC

XXXX  

XXXX

ENDP

GAS:  myfunc:

XXXX  

XXXX

(5). Define a global function or variable

ADS:  @EXPORT SspSipStopTimer1

GAS:  .global     SspSipStopTimer1

(6).

ADS:  DCD

GAS:  .long

(7). Code section

ADS:  AREA WORD, CODE, READONLY

          XXXX

          XXXX

          END

GAS:  .text

          XXXX

          XXXX

          .end

(8). Data section

ADS:  AREA BLOCK, DATA, READWRITE

          XXXX

          XXXX

          END

GAS:  .data

          XXXX

          XXXX

          .end

(9).

ADS:  :OR:

GAS:  |

(10).

ADS:  :SHL:

GAS:  <<

(11).

ADS:  :SHR:

GAS:  >>

(12).

ADS:  CODE32:

GAS:  .arm

(13).

ADS:  CODE16:

GAS:  .thumb

(14).

ADS:  %:

GAS:  .fill

(15).

ADS:  LTORG:

GAS:  .ltorg

(16).

ADS:  INCLUDE:

GAS:  .include

(17).

ADS:  IF:DEF:

GAS:  .IFDEF

(18).

ADS:  ELSE

GAS:  .ELSE

(19).

ADS: ENDIF

GAS: .ENDIF

(20).

ADS: &

GAS: +0x

2.2    Replanting of .h/.c file with inline assemble

(1). For GAS, the normal inline asm syntax is like,

__asm__("asm statements" : outputs : inputs : registers-modified);

 

(2). It can be explained by,

__asm__ __volatile__(

"movl %1, %%eax;\n\r"  /*1st line code, add */

"movl %%eax, %0;" /*2nd line code*/

:"=r"(b)      /* output */    

:"r"(a)       /* input */

:"%eax");     /*if have, show the registers that should not be effected */

 

(3). The example below shows how to do the replanting.

 

For ADS environment

    __asm{

            rsbs    dumy, var2, 0

            movmi   L_var_out, L_var1, lsl var2

            movpl   L_var_out, L_var1, asr dumy

         }

 

 

For GAS environment

       __asm__ __volatile__(

            " rsbs    %0, %3, #0;\n\r"

            " movmi   %1, %2, lsl %3;\n\r"

            " movpl   %1, %2, asr %0"

            :"=r" (dumy), "=r" (L_var_out)

            :"r" (L_var1), "r" (var2)

);

 

or

    asm volatile(

               " rsbs    %0, %3, #0;\n\r"

            " movmi   %1, %2, lsl %3;\n\r"

            " movpl   %1, %2, asr %0"

            :"=r" (dumy), "=r" (L_var_out)

            :"r" (L_var1), "r" (var2)

       );

 

2006年06月09日

1、configuration file:  $QPEDIR/demohome/Settings/qpe.conf

[StorageMonitor]

2、Source file: src/server/serverapp.cpp

the constructor ServerApplication() defines whether install the storage monitor by read the configure file qpe.conf,  

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    Config cfg("qpe");
    cfg.setGroup("StorageMonitor");
    if (cfg.readBoolEntry("Enabled", TRUE)) {
        //qDebug("Storage Monitor enabled");
        sm = new StorageMonitor( this );
        QTimer *storageTimer = new QTimer( this );
        connect( storageTimer, SIGNAL(timeout()), sm, SLOT(checkAvailStorage()));
        storageTimer->start(cfg.readNumEntry("UpdatePeriod", 15)*1000);
    }

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Compare Free version2.1.0 and commercial version, we find that in commercial version it add something to avoid messagebox to tip there’s no memory avail for in-writible filesystem, e.g. cramfs. refer to below lines, those add ///joy line is only in commercial version,

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void StorageMonitor::checkAvailStorage()
{
    printf("checkAvailStorage, suppressNotification: %d\n", (int)suppressNotification);
    if (suppressNotification)
        return;

    sinfo->update();
    const FileSystem *fs;
    bool haveWritableFS = FALSE;
    fs = sinfo->fileSystemOf(QPEApplication::documentDir());
    if (fs == 0) {
        qDebug( "No file systems found for %s",QPEApplication::documentDir().local8Bit().data());
        return;
    }
    if( fs->isWritable() )
 haveWritableFS = TRUE;

    long availStorage = fileSystemMetrics(fs);
  
    //check all additional filesystems
    const QList<FileSystem>& filesystems(sinfo->fileSystems());
    QListIterator<FileSystem> iter(filesystems);
   
    for ( ; iter.current(); ++iter )
    {
        if ((*iter)->isRemovable()) {
            availStorage += fileSystemMetrics(*iter);
     if( (*iter)->isWritable() )
  haveWritableFS = TRUE;
        }
    }

    if( !haveWritableFS )
 return; // no writable filesystems, lack of free space is irrelevant
   
    //qDebug(QString("Free storage: %1 kB").arg(availStorage));
   
    //for now read config file each time until we have notification in place
    Config cfg("qpe");
    cfg.setGroup("StorageMonitor");
    int notificationLimit = cfg.readNumEntry("MinimalStorageLimit", 20);
    printf("notflmt: %d, availStorage: %d\n", notificationLimit, availStorage);
    if (notificationLimit >= 0 && availStorage <= notificationLimit ) { 
        QString msg = tr("<qt>The device has no free storage space. "
               "Please delete unwanted documents.</qt>");
        outOfSpace(msg);
    }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Before, there is a tip from busybox which prevent qpe from running automatically by "qpe -qws&", this tip shows twice. The tip string is,

"Please press Enter to activate this console".

I did a little change to the nusybox source to fix this problem.

file:    init/init.c      fucntion: run()

remove the following lines,

#if 0// joy, remove askfirst
#if !defined(__UCLIBC__) || defined(__ARCH_HAS_MMU__)
  if (a->action & ASKFIRST) {
   char c;
   /*
    * Save memory by not exec-ing anything large (like a shell)
    * before the user wants it. This is critical if swap is not
    * enabled and the system has low memory. Generally this will
    * be run on the second virtual console, and the first will
    * be allowed to start a shell or whatever an init script
    * specifies.
    */
   messageD(LOG, "Waiting for enter to start ‘%s’"
      "(pid %d, terminal %s)\n",
       cmdpath, getpid(), a->terminal);
   bb_full_write(1, press_enter, sizeof(press_enter) – 1);
   while(read(0, &c, 1) == 1 && c != ‘\n’)
    ;
  }
#endif
#endif

2006年06月08日

Today, I read the qte source code and write something about the display part of qte system.

[reference: Qt/Embedded在体系上为C/S结构,任何一个Qt/Embedded程序都可以作为系统中唯一的一个GUI Server存在。当应用程序首次以系统GUI Server的方式加载时,将建立QWSServer实体。此时调用QWSServer::openDisplay()函数创建窗体。]

As a QApplication, there’s 3 types can be slected,

enum Type { Tty, GuiClient, GuiServer };

  • QApplication::Tty – 控制台应用程序
  • QApplication::GuiClient – 图形用户界面客户端应用程序
  • QApplication::GuiServer – 图形用户界面服务器应用程序
  • In Qtopia system, src/server/main.cpp main() creates the GuiServer, for other QApplication implementation, the default type is GuiClient, Type=GuiClient. refer to qpeapplication.h, the constructor function,

    class QTOPIA_EXPORT QPEApplication : public QApplication
    {
        Q_OBJECT
    public:
        QPEApplication( int& argc, char **argv, Type=GuiClient );

    }

    Here is the flow chart in simple for display part,

    0、(qwindowssystem_qws.cpp)

    In the constructure function of QWSServer, we call openDisplay()

    1、(qwindowssystem_qws.cpp)

    qt_init_display();

    2、(qapplication_qws.cpp)

    init_display();

    3、:(qapplication_qws.cpp)

    qt_fbdpy = new QWSDisplay(); 

    /* reference*/

    QWSDisplay* qt_fbdpy = 0;

    class Q_EXPORT QWSDisplay

    {

    QWSDisplayData *d;

    }

    /******/

    4、:(qapplication_qws.cpp)

    QWSDisplay::QWSDisplay()
    {
        d = new QWSDisplayData( 0, qws_single_process );
    }


    5、:(qapplication_qws.cpp)

    QWSDisplayData( QObject* parent, bool singleProcess = FALSE )
    {
    #ifndef QT_NO_QWS_MULTIPROCESS
     if ( singleProcess )
         csocket = 0;
     else {
         csocket = new QWSSocket(parent);
         QObject::connect( csocket, SIGNAL(connectionClosed()),
             qApp, SLOT(quit()) );
     }
    #endif
     init();
    }

    6、init()-〉call:(qapplication_qws.cpp)

    QScreen *s = qt_get_screen( qws_display_id, qws_display_spec );

    //(qgfxraster_qws.cpp) qt_get_screen return global var qt_screen, and call:

    qt_screen->connect( spec ) ;//here spec is char*, ":0"


    s->initDevice();

    7、QScreen is herited from QLinuxFbScreen, since connect() is a virtual function, it open the framebuffer device, "/dev/fb0" (qgfxLinuxfb_qws.cpp)

    bool QLinuxFbScreen::connect( const QString &displaySpec )
    {
        // Check for explicitly specified device
        QRegExp r( "/dev/fb[0-9]+" );
        int len;
        int m = r.match( displaySpec, 0, &len );

        QString dev = (m>=0) ? displaySpec.mid( m, len ) : QString("/dev/fb0");

        fd=open( dev.latin1(), O_RDWR );
        if (fd<0) {
     qWarning("Can’t open framebuffer device %s",dev.latin1());
     return FALSE;
        }

        fb_fix_screeninfo finfo;
        fb_var_screeninfo vinfo;

        memset( &finfo, 0, sizeof(fb_fix_screeninfo) ); // keep valgrind happy
        memset( &vinfo, 0, sizeof(fb_var_screeninfo) ); // keep valgrind happy

        /* Get fixed screen information */
        if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo)) {
     perror("reading /dev/fb0");
     qWarning("Error reading fixed information");
     return FALSE;
        }

        /* Get variable screen information */
        if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo)) {
     perror("reading /dev/fb0");
     qWarning("Error reading variable information");
     return FALSE;
        }

        d=vinfo.bits_per_pixel;
        lstep=finfo.line_length;
        int xoff = vinfo.xoffset;
        int yoff = vinfo.yoffset;
        const char* qwssize;
        if( (qwssize=getenv("QWS_SIZE")) && sscanf(qwssize,"%dx%d",&w,&h)==2 ) {
     if ( (uint)w > vinfo.xres ) w = vinfo.xres;
     if ( (uint)h > vinfo.yres ) h = vinfo.yres;
     dw=w;
     dh=h;
     xoff += (vinfo.xres – w)/2;
     yoff += (vinfo.yres – h)/2;
        } else {
     dw=w=vinfo.xres;
     dh=h=vinfo.yres;
        }
        dataoffset = yoff * lstep + xoff * d / 8;
        //qDebug("Using %dx%dx%d screen",w,h,d);

        /* Figure out the size of the screen in bytes */
        size = h * lstep;

        //    qDebug("Framebuffer base at %lx",finfo.smem_start);
        //    qDebug("Registers base %lx",finfo.mmio_start);

        mapsize=finfo.smem_len;

        data = (unsigned char *)mmap(0, mapsize, PROT_READ | PROT_WRITE,
         MAP_SHARED, fd, 0);
        data += dataoffset;

        if ((int)data == -1) {
     perror("mapping /dev/fb0");
     qWarning("Error: failed to map framebuffer device to memory.");
     return FALSE;
        }

        canaccel=useOffscreen();

        if(mapsize-size<16384) {
     canaccel=false;
        }

        if(canaccel) {
     setupOffScreen();
        } else {
     optype = &dummy_optype;
     lastop = &dummy_lastop;
        }

        // Now read in palette
        if((vinfo.bits_per_pixel==8) || (vinfo.bits_per_pixel==4)) {
     screencols= (vinfo.bits_per_pixel==8) ? 256 : 16;
     int loopc;
     startcmap = new fb_cmap;
     startcmap->start=0;
     startcmap->len=screencols;
     startcmap->red=(unsigned short int *)
       malloc(sizeof(unsigned short int)*screencols);
     startcmap->green=(unsigned short int *)
         malloc(sizeof(unsigned short int)*screencols);
     startcmap->blue=(unsigned short int *)
        malloc(sizeof(unsigned short int)*screencols);
     startcmap->transp=(unsigned short int *)
          malloc(sizeof(unsigned short int)*screencols);
     ioctl(fd,FBIOGETCMAP,startcmap);
     for(loopc=0;loopc<screencols;loopc++) {
         screenclut[loopc]=qRgb(startcmap->red[loopc] >> 8,
           startcmap->green[loopc] >> 8,
           startcmap->blue[loopc] >> 8);
     }
        } else {
     screencols=0;
        }

        initted=true;

        return TRUE;
    }

    8、

    The mmaped char* is char* data, important ioctl system call to framebuffer device is FBIOGET_FSCREENINFO, FBIOGET_VSCREENINFO and FBIOGETCMAP

    > hi all,
    >         does any one knows how the  Qtopia media player uses
    > the frame buffer to display the video data.
    >         i am writing a plugin for the mpeg4 short header
    > file.after loading the decoder,my plugin takes the encoded
    > data from the mpeg4 file,passes it to the proprity hardware
    > to decode it and then i am reading the decoded data.
    > i am calling the read ioctl to read the decoded data in the
    > function "ReadVideoScaledFrame()–>MediaPlayer Decoder Class"
    > but it is not putting that data in the frame buffer..

    Hi Abhijit,

    The videoReadScaledFrame function takes a number of arguments, let me explain
    the first one which is important here.

    http://doc.trolltech.com/qtopia2.0/html/mediaplayerdecoder.html#videoReadScaledFrame

    bool MediaPlayerDecoder::videoReadScaledFrame( unsigned char **output_rows,
    int, int, int in_w, int in_h, int out_w, int out_h, ColorFormat fmt, int );

    The output_rows argument is passed to the decoder. It is an array of pointers.
    Each pointer is for each line. Those pointers might be to framebuffer memory,
    or it might be to an offscreen buffer used by the mediaplayer which gets
    translated and/or clipped before being displayed.

    Where possible, the pointers in output_rows will point directly to framebuffer
    memory, but this is not always possible on all devices at all times. Other
    windows can partially obsure the output, or the screen may require rotation
    first before being written to the framebuffer. The fastest path is selected
    by the mediaplayer and it passes output_rows pointing to what is approriate.

    In most cases the data is going directly to the framebuffer. Just fill
    ouput_rows with the decoded data. The mediaplayer passes this as appropriate
    and then does what is appropriate with the data afterwards, sometimes nothing
    since it went directly to the framebuffer.

    Perhaps you may find reading the code where this fucntion is called will help
    understand it:
    $QPEDIR/src/libraries/mediaplayer/videooutput.cpp

    Or an example implementation might also help:
    $QPEDIR/src/3rdparty/plugins/codecs/libffmpeg/libffmpegplugin.cpp

    [joy NOTE:]

    refer to libffmpeg/libavcodecs/allcodecs.c, avcodec_register_all( ) for the method of how to add/change a a/v codec. Combine this to the display mechanism of Qtopia mediaplayer, we can add our software and/or hardware codecs.

    The display mechanism of Qte also can be got from another document from internet, here i marked it as "qtopia_qte study".

    There are some example in libffmpeg about how to register and use a brand new codec, pls refer to libffmpeg/libavcodecs/apiexample.c.