Chinaunix首页 | 论坛 | 博客
  • 博客访问: 174611
  • 博文数量: 31
  • 博客积分: 471
  • 博客等级: 下士
  • 技术积分: 240
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-07 12:53
文章分类

全部博文(31)

文章存档

2015年(1)

2013年(1)

2012年(1)

2011年(28)

分类: LINUX

2011-08-17 17:59:53

上接:《5 添加yaffs2文件系统

http://blog.chinaunix.net/space.php?uid=24473044&do=blog&id=2211677

 

6 增加引导内核功能与挂载yaffs2文件系统(待续)

参考说明:

1)本文参考了singleboy

2)参考了Tekkaman Ninjablog文章,http://blog.chinaunix.net/space.php?uid=20543672&do=blog&cuid=2085154

3)参考了黄刚的blog

http://blogold.chinaunix.net:80/u3/101649/showart.php?id=2276917

向上述作者表示感谢!

一、移植环境说明

1,主机环境:VMWareRHEL5

 

2,编译器:arm-linux-gcc v4.4.3

 

3,开发板:mini24402M nor flash256M nand flash(自改,原64M),NEC屏;

 

4u-boot版本:u-boot-2009.08

 

5kernel版本:linux-2.6.32.2

 

二、移植任务描述

验证系列5中为开发板添加的Yaffs2烧写功能,增加引导内核功能与挂载yaffs2文件系统。

 

三、移植步骤

u-boot配置

1】机器码的确定

通常,在u-boot(include/asm-arm/mach-types.h)kernel(arch/arm/tools/mach-type)中都会有一个开发板的机器码(即:MACH_TYPE),只有这两个机器码一致时才能引导内核,否则就会出现错误信息。

gedit board/gy/mini2440/mini2440.c,定位到142行附近,修改如下:

#if defined(CONFIG_S3C2410)

/* arch number of SMDK2410-Board */

gd->bd->bi_arch_number = MACH_TYPE_SMDK2410;

#endif

#if defined(CONFIG_S3C2440)

/* arch number of S3C2440-Board */

 gd->bd->bi_arch_number = MACH_TYPE_MINI2440;

#endif

对于u-boot-2009.08来说MACH_TYPE_MINI2440已经在gedit include/asm-arm/mach-types.h 文件的1985行附件有定义。

#define MACH_TYPE_QQ2440 1998

#define MACH_TYPE_MINI2440 1999  //mini2440的机器码

#define MACH_TYPE_COLIBRI300 2000

       注意核对其与kernelarch/arm/tools/mach-type文件1989行是否一致!

2】修改u-boot中内核引导参数:

gedit include/configs/mini2440.h,定位到127行附近,修改如下:

#define CONFIG_BOOTDELAY    1 

#define CONFIG_SETUP_MEMORY_TAGS     1 //如果没有定义这个参数,则uboot参数必须加入men=内存大小

#define CONFIG_INITRD_TAG            1

#define CONFIG_CMDLINE_TAG           1 //设置bootargs出入内核必须

#define CONFIG_BOOTARGS "noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0"

 

注释1:一定要注意在正确的位置烧写正确的文件系统映象

(a)正确的位置

嵌入式开发中,常通过bootloader烧写文件系统映象,假设我们将文件系统写在flash的地址A处。内核启动时,显然只能从地址A处读取文件系统,内核是怎么知道的呢?通过命令行参数,比如“root=/dev/mtdblock3/dev/mtdblock3又是怎么和地址A对应上的呢?我们在kernelarch/arm/plat-s3c24xx/common-smdk.c(这里以linux2.6.32.2内核为例)flash划分为几个分区。/dev/mtdblock3是第4个分区,它的开始地址必须是A

我的分区情况如下:

Creating 5 MTD partitions on "NAND 256MiB 3,3V 8-bit":

0x000000000000-0x000000040000 : "uboot"

0x000000040000-0x000000060000 : "param"

0x000000060000-0x000000560000 : "Kernel"

0x000000560000-0x000040560000 : "root"

对于上面的分区信息/dev/mtdblock3对应root分区起始地址为0x560000使用bootloader写文件系统映象时烧写的地址必须是0x560000

所以要保证3 bootloader烧到地址A 地址A是内核某个分区的开始地址 命令行参数“root=/dev/mtdblockX ”是这个分区

b正确的文件系统映象

具体制作文件系统的实例,可以参照http://huang-tomey.blog.163.com/blog/static/1247505732009916437175/这一篇博文。

作者的“7、 etc/profile文件: ”有点问题,大家可以这么建立内容:

#Ash profile 
#vim:syntax=sh 
#No core file by defaults 
#ulimit -S -c 0>/dev/null 2>&1 
USER="id -un" 
LOGNAME=$USER 
PS1='[\u@\h \W]#' 
PATH=$PATH:/usr/local/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
HOSTNAME='/bin/hostname' 
export USER LOGNAME PS1 PATH LD_LIBRARY_PATH

 

注释2

    注意,我们在uboot中,include/configs/mini2440.h中定义的下述语句:

define CONFIG_ENV_OFFSET 0X40000 /*一定要与上面的0x000000040000-0x000000060000 : "param"的首地址一致*/

#define CONFIG_ENV_SIZE   0x20000 /* Total Size of Environment Sector 也要与0x000000040000-0x000000060000 : "param"的大小一致*/

 

#define CONFIG_ETHADDR 08:00:3e:26:0a:5b

#define CONFIG_NETMASK     255.255.255.0

#define CONFIG_IPADDR  222.197.173.10

#define CONFIG_SERVERIP  222.197.173.99

#define CONFIG_GATEWAYIP  222.197.173.1

#define CONFIG_OVERWRITE_ETHADDR_ONCE

/*#define CONFIG_BOOTFILE "elinos-lart" */

#define CONFIG_BOOTCOMMAND " nboot 0x31000000 0 0x60000\;bootm 0x31000000"

#define CONFIG_EXTRA_ENV_SETTINGS     \

 "robinfit01=pore"    \

 "stdin=serial\0"     \

 "stdout=serial\0"     \

 "stderr=serial\0"     \

 ""

#if defined(CONFIG_CMD_KGDB)

 

注释3

bootargs参数简析:

initrd, noinitrd: 当你没有使用ramdisk启动系统的时候,你需要使用noinitrd这个参数,但是如果使用了的话,就需要指定initrd=r_addr,size, r_addr表示initrd在内存中的位置,size表示initrd的大小。

 

console: console=tty  使用虚拟串口终端设备 console=ttyS[,options] 使用特定的串口,options可以是这样的形式bbbbpnx,这里bbbb是指串口的波特率,p是奇偶位(从来没有看过使用过),n是指的bitsconsole=ttySAC[,options] 同上面。看你当前的环境,有时用ttyS,有时用ttySAC,网上有人说,这是跟内核的版本有关,2.4ttyS2.6ttySAC,但实际情况是官方文档中也是使用ttyS,所以应该是跟内核版本没有关联的。可以查看Documentation/serial-console.txt找到相关描述。

 

init: 指定的是内核启起来后,进入系统中运行的第一个脚本,一般init=/linuxrc, 或者init=/etc/preinitpreinit的内容一般是创建console,null设备节点,运行init程序,挂载一些文件系统等等操作。请注意,很多初学者以为init=/linuxrc是固定写法,其实不然,/linuxrc指的是/目录下面的linuxrc脚本,一般是一个连接罢了。如果内核找不到linurc文件,将会依搜索/sbin/init, /etc/init,/bin/init,/bin/sh.

mem: 指定内存大小,不是必须的。

 

root: 用来指定rootfs的位置。

 

保存修改。

 

3】制作能被u-boot直接引导的内核uImage

通常,kernel的启动需要u-boot提供一些参数信息,比如yaffs2文件系统在RAM中的位置;ramdiskRAM中的地址,文件系统的大小;nfs起文件系统的挂载位置等等。经过编译后的u-boot在根目录下的tools目录中,会有个叫做mkimage的工具,他可以给zImage添加一个header,也就是说使得通常我们编译的内核zImage添加一个数据头信息部分,我们把添加头后的image通常叫uImageuImage是可以被u-boot直接引导的内核镜像。

mkimage工具的使用介绍如下:

注:中括号括起来的是可选的

mkimage [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image

选项:

-Aset architecture to 'arch'       //用于指定CPU类型,比如ARM

-Oset operating system to 'os'     //用于指定操作系统,比如Linux

-Tset image type to 'type'         //用于指定image类型,比如Kernel

-Cset compression type 'comp'      //指定压缩类型

-aset load address to 'addr' (hex) //指定image的载入地址

-eset entry point to 'ep' (hex)    //内核的入口地址,一般为image的载入地址+0x40(信息头的大小)

-nset image name to 'name'         //image在头结构中的命名

-duse image data from 'datafile'   //无头信息的image文件名

-xset XIP (execute in place)       //设置执行位置

 

注释4

引用网络文章,向作者表示感谢!

————————————我是分割线,引用文章开始——————————————

一、在开始之前先说明一下bootm相关的东西。

1、首先说明一下,S3C2410架构下的bootm只对sdram中的内核镜像文件进行操作(好像AT91架构提供了一段从flash复制内核镜像的代码,不过针对s3c2410架构就没有这段代码,虽然可以在u-boot下添加这段代码,不过好像这个用处不大),所以请确保你的内核镜像下载到sdram中,或者在bootcmd下把flash中的内核镜像复制到sdram中。

2-a参数后是内核的运行地址,-e参数后是入口地址。

3

1
)如果我们
没用mkimage对内核进行处理的话,那直接把内核下载到0x30008000再运行就行,内核会自解压运行(不过内核运行需要一个tag来传递参数,而这个tag建议是由bootloader提供的,在u-boot下默认是由bootm命令建立的)。
 
2
)如果
使用mkimage生成内核镜像文件的话,会在内核的前头加上了64byte的信息,供建立tag之用。bootm命令会首先判断bootm xxxx 这个指定的地址xxxx是否与-a指定的加载地址相同。
(1)
如果
不同的话会从这个地址开始提取出这个64byte的头部,对其进行分析,然后把去掉头部的内核复制到-a指定的load地址中去运行之
(2)
如果
相同的话那就让其原封不同的放在那,但-e指定的入口地址会推后64byte,以跳过这64byte的头部。

二、好,接着介绍使用mkimage生成镜像文件并下载运行的方法。
方法一、
1
、首先,用u-boot/tools/mkimage这个工具为你的内核加上u-boot引导所需要的文件头,具体做法如下:
[root@localhost tftpboot]#mkimage -n 'linux-2.6.14' -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008000 -d zImage zImage.img
Image Name:   linux-2.6.14
Created:      Fri Jan 12 17:14:50 2007
Image Type:   ARM Linux Kernel Image (uncompressed)
Data Size:    1262504 Bytes = 1232.91 kB = 1.20 MB
Load Address: 0x30008000
Entry Point:  0x30008000

这里解释一下参数的意义:
-A ==> set architecture to 'arch'   //用于指定CPU类型,比如ARM
-O ==> set operating system to 'os'  //
用于指定操作系统,比如
Linux
-T ==> set image type to 'type'      //
用于指定image类型,比如
Kernel
-C ==> set compression type 'comp'   //
指定压缩类型

-a ==> set load address to 'addr' (hex)  //
指定image的载入地址
-e ==> set entry point to 'ep' (hex)     //
内核的入口地址,一般是:image的载入地址+0x40(信息头的大小)
-n ==> set image name to 'name'          //image
在头结构中的命名
-d ==> use image data from 'datafile'    //
无头信息的image文件名
-x ==> set XIP (execute in place)        //
设置执行位置

 

2 、下载内核
U-Boot 1.1.3 (Jan 12 2007 - 16:16:36)

U-Boot code: 33F80000 -> 33F9BAC0  BSS: -> 33F9FBAC
RAM Configuration:
Bank #0: 30000000 64 MB
Nor Flash: 512 kB
Nand Flash:  64 MB
In:    serial
Out:   serial
Err:   serial
Hit any key to stop autoboot:  0
sbc2410=>tftp 0x31000000 zImage.img
       
TFTP from server 192.168.1.115; our IP address is 192.168.1.128
Filename 'zImage.img'.
Load address: 0x31000000
Loading: #################################################################
        #################################################################
        #################################################################
        ####################################################
done
Bytes transferred = 1263324 (1346dc hex)


3.
运行 

sbc2410=>bootm 0x31000000
## Booting image at 31000000 ...
  Image Name:   linun-2.6.14 
  Image Type:   ARM Linux Kernel Image (uncompressed)
  Data Size:    1263260 Bytes =  1.2 MB
  Load Address: 30008000
  Entry Point:  30008000
  Verifying Checksum ... OK
OK

Starting kernel ...

Uncompressing Linux.............................................................Linux version 2.6.14 (root@luofuchong) (gcc version 3.4.1) #21 Fri Oct 20 17:206CPU: ARM920Tid(wb) [41129200] revision 0 (ARMv4T)
…………………………………………………………………………………..

Bad eraseblock 1884 at 0x01d70000
Creating 4 MTD partitions on "NAND 64MiB 3,3V 8-bit":
0x00000000-0x00020000 : "vivi"
0x00020000-0x00030000 : "param"
0x00030000-0x00200000 : "kernel"
0x00200000-0x04000000 : "root"

usbmon: debugfs is not available
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

IP-Config: Complete:
     device=eth0, addr=192.168.1.128, mask=255.255.255.0, gw=192.168.1.1,
    host=luofuchong, domain=, nis-domain=(none),
    bootserver=192.168.1.1, rootserver=192.168.1.115, rootpath=
Looking up port of RPC 100003/2 on 192.168.1.115
Looking up port of RPC 100005/1 on 192.168.1.115
VFS: Mounted root (nfs filesystem).
Mounted devfs on /dev
Freeing init memory: 108K
init started:  BusyBox v1.1.3 (2006.09.20-14:52+0000) multi-call binary
Starting pid 696, console /dev/tts/0: '/etc/init.d/rcS'

Please press Enter to activate this console.


方法二、
1
、首先,用u-boot/tools/mkimage这个工具为你的内核加上u-boot引导所需要的文件头,具体做法如下:
[root@localhost tftpboot]#mkimage -n 'linux-2.6.14' -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008040 -d zImage zImage.img
Image Name:   linux-2.6.14
Created:      Fri Jan 12 17:14:50 2007
Image Type:   ARM Linux Kernel Image (uncompressed)
Data Size:    1262504 Bytes = 1232.91 kB = 1.20 MB
Load Address: 0x30008000
Entry Point:  0x30008040

2 、下载内核
U-Boot 1.1.3 (Jan 12 2007 - 16:16:36)

U-Boot code: 33F80000 -> 33F9BAC0  BSS: -> 33F9FBAC
RAM Configuration:
Bank #0: 30000000 64 MB
Nor Flash: 512 kB
Nand Flash:  64 MB
In:    serial
Out:   serial
Err:   serial
Hit any key to stop autoboot:  0
sbc2410=>tftp 0x30008000 zImage.img
       
TFTP from server 192.168.1.115; our IP address is 192.168.1.128
Filename 'zImage.img'.
Load address: 0x30008000
Loading: #################################################################
        #################################################################
        #################################################################
        ####################################################
done
Bytes transferred = 1263324 (1346dc hex)


3.
运行 

sbc2410=>bootm 0x30008000
## Booting image at 30008000 ...
   Image Name:   linux-2.6.14
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    1261056 Bytes =  1.2 MB
   Load Address: 30008000
   Entry Point:  30008040
   Verifying Checksum ... OK
   XIP Kernel Image ... OK


内核启动信息省。。。。

三、固化
       
如果你想把镜像文件写入flash,每次开机后让u-boot帮你复制到sdram中,再使用bootm命令引导的话,可以按照这样操作:
sbc2410=>
tftp 0x30008000 zImage.img
TFTP from server 192.168.1.115; our IP address is 192.168.1.128
Filename 'zImage.img'.
Load address: 0x30008000
Loading: #################################################################
        #################################################################
        #################################################################
        ####################################################
done
Bytes transferred = 1263324 (1346dc hex)
sbc2410=>
nand erase 0x30000 0x1d0000

NAND erase: device 0 offset 196608, size 1900544 ... OK
sbc2410=>
nand write 0x30008000 0x30000 0x1d0000

NAND write: device 0 offset 196608, size 1900544 ...  1900544 bytes written: OK

设置u-boot启动命令:
1
、针对方法一:
sbc2410=>setenv bootcmd nand read
0x31000000 0x30000 0x1d0000\;bootm 0x31000000
sbc2410=>saveenv
Saving Environment to NAND...
Erasing Nand...Writing to Nand... done
2、针对方法二:

sbc2410=>
setenv bootcmd nand read 0x30008000 0x30000 0x1d0000\;bootm 0x30008000
sbc2410=>saveenv

Saving Environment to NAND...
Erasing Nand...Writing to Nand... done

sbc2410=>reset
启动信息略。。。。

————————————我是分割线,引用文章结束——————————————

 

具体制作内核的方法网络上很多资料,有兴趣的可以搜索之!

我的[root@localhost linux-2.6.32.2]#make uImage后的结果如下:

 

Image Name:   Linux-2.6.32.2-FriendlyARM

Created:      Mon Aug 15 06:24:03 2011

Image Type:   ARM Linux Kernel Image (uncompressed)

Data Size:    2288352 Bytes = 2234.72 kB = 2.18 MB

Load Address: 30008000

Entry Point:  30008000

  Image arch/arm/boot/uImage is ready

[root@localhost linux-2.6.32.2]#

 

4将内核与文件系统写入Nand flash

下载内核:

[mini2440] # tftp 0x31000000 uImage  

[mini2440] # nand erase 0x60000 0x500000

[mini2440] # nand write 0x31000000 0x60000 0x500000

 

下载根文件系统:

[mini2440] # tftp 0x30008000 rootfs.img  

[mini2440] # nand erase 0x560000 0xfaa0000

[mini2440] # nand write.yaffs2 0x30008000 0x560000 0x6b9ac0 //将内存0x30008000处的内容写入到nand0x00560000, rootfs.img的大小可以在tftp传送完后看到

 

5】设置u-boot引导参数并保存到nand flash,完成上电后自动加载内核(应该可以不写,uboot已经添加了的)

[mini2440] # setenv bootargs noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0

[mini2440] # setenv bootcmd nboot 0x31000000 0 0x60000\;bootm 0x31000000

[mini2440] # saveenv

6】结果

nand flash引导,开发板上电:

U-Boot 2009.08 (Aug 16 2011 - 06:42:31)

 

modified by gy (robinfit01@163.com)

Love pore and Linux forever!!!

 

DRAM:  64 MB

Flash:  2 MB

NAND:  256 MiB

In:    serial

Out:   serial

Err:   serial

Net:   dm9000

Hit any key to stop autoboot:  0

 

Loading from NAND 256MiB 3,3V 8-bit, offset 0x60000

   Image Name:   Linux-2.6.32.2-FriendlyARM

   Created:      2011-08-15  14:11:24 UTC

   Image Type:   ARM Linux Kernel Image (uncompressed)

   Data Size:    2288352 Bytes =  2.2 MB

   Load Address: 30008000

   Entry Point:  30008000

## Booting kernel from Legacy Image at 31000000 ...

   Image Name:   Linux-2.6.32.2-FriendlyARM

   Created:      2011-08-15  14:11:24 UTC

   Image Type:   ARM Linux Kernel Image (uncompressed)

   Data Size:    2288352 Bytes =  2.2 MB

   Load Address: 30008000

   Entry Point:  30008000     //注意,应该选用注释4的方法一,依此类推,作者添加。

   Verifying Checksum ... OK

   Loading Kernel Image ... OK

OK

 

Starting kernel ...

 

Uncompressing Linux.................................................................................................................................................... done, booting the kernel.

Linux version 2.6.32.2-FriendlyARM (root@localhost.localdomain) (gcc version 4.4.3 (ctng-1.6.1) ) #1 Mon Aug 15 07:11:18 PDT 2011

CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=00007177

CPU: VIVT data cache, VIVT instruction cache

Machine: FriendlyARM Mini2440 development board

Memory policy: ECC disabled, Data cache writeback

CPU S3C2440A (id 0x32440001)

S3C24XX Clocks, (c) 2004 Simtec Electronics

S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz

CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on

Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256

Kernel command line: setenv bootargs noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0

PID hash table entries: 256 (order: -2, 1024 bytes)

Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)

Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)

Memory: 64MB = 64MB total

Memory: 60048KB available (4212K code, 453K data, 156K init, 0K highmem)

SLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1

Hierarchical RCU implementation.

NR_IRQS:85

irq: clearing subpending status 00000002

Console: colour dummy device 80x30

console [ttySAC0] enabled

Calibrating delay loop... 50.27 BogoMIPS (lpj=125696)

Mount-cache hash table entries: 512

CPU: Testing write buffer coherency: ok

NET: Registered protocol family 16

S3C2440: Initialising architecture

S3C2440: IRQ Support

S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics

———————————————————省略——————————————————

s3c2410-rtc s3c2410-rtc: hctosys: invalid date/time

yaffs: dev is 32505859 name is "mtdblock3"

yaffs: passed flags ""

yaffs: Attempting MTD mount on 31.3, "mtdblock3"

yaffs: auto selecting yaffs2

yaffs_read_super: isCheckpointed 0

VFS: Mounted root (yaffs filesystem) on device 31:3.

Freeing init memory: 156K

----------munt all----------------

***********************************************

****************Studying ARM*********************

Kernel version: 2.6.32.2

Student:GY

Date:2011.8.16

***********************************************

 

Please press Enter to activate this console.

[root@hepan-Studio /]#ls

bin         etc         linuxrc     proc        sys         var

boot        home        lost+found  root        tmp

dev         lib         mnt         sbin        usr

 

由于时间原因,uboot中添加SD卡、优盘、开机logousb下载等等的功能就不再一一列举,等有时间了继续添加,有感兴趣的朋友可以看文章开头诸位大神贡献的移植工作。

阅读(3386) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~