Linux+ramdisk移植到S3C2440A开发板

Linux+ramdisk移植到S3C2440A开发板

一.环境

PC:                      虚拟机的redhat9

开发板            S3C2440A64M sdram64M nand flash

Bootloader       已移植好的可以执行tftpgo命令的u-boot

 

二.Linux的移植

交叉编译器:    arm-linux-gcc-3.4.1.tar.tar

源码:                linux-2.6.26.3.tar.bz2

1.      移植步骤

            1.1安装交叉编译工具(如果环境中有其他交叉编译器,建议先卸载掉)

(1)    arm-linux-gcc-3.4.1.tar.tar复制到redhat9的根目录”/”下,然后

#cd /

[root@localhost /]# tar –xvf arm-linux-gcc-3.4.1.tar.tar

[root@localhost /]# vim /etc/bashrc bashrc末尾添加:

                     PATH=$PATH:/usr/local/arm/3.4.1/bin 保存退出

            1.2修改源码

1)解压linux-2.6.26.3.tar.bz2并进入解压后的主目录

2[root@localhost linux-2.6.26.3]# vim Makefile 修改

                     ARCH ?=arm

CROSS_COMPILE ?=arm-linux-

3修改平台输入时钟

                            找到内核源码arch/arm/mach-s3c2440/mach-smdk2440.c 文件,在函数 static

void __init smdk2440_map_io(void)中,修改成s3c24xx_init_clocks(12000000)

4修改machine 名称(可以不改)

修改文件arch/arm/mach-s3c2440/mach-smdk2440.c , 在文件中找到MACHINE_START( ),修改为MACHINE_START(S3C2440, “QLJT2440)。这样在启动的打印信息中会有QLJT2440出现的。

5修改Nand flash 分区信息

修改文件arch/arm/plat-s3c24xx/common-smdk.c

 static struct mtd_partition smdk_default_nand_part[] = {

     [0] = {

         .name   = "u-boot-1.3.4",

         .size   = SZ_256K,

         .offset = 0,

     },

     [1] = {

         .name   = "linux-2.6.26.3",

         .offset = SZ_256K,

         .size   = SZ_4M-SZ_256K,

     },

     [2] = {

         .name   = "reserve for file system",

         .offset = SZ_4M,

         .size   = SZ_16M,

     },

     [3] = {

         .name   = "others",

         .offset = SZ_4M+SZ_16M,

         .size   = SZ_64M-SZ_4M-SZ_16M,

     }

}

6)修改 arch/arm/kernel/head.S 

Line 80  ENTRY(stext)

         /********* add here *********/

mov    r0, #0

ldr    r1, =0x16a

      ldr    r2, =0x30000100

   /********* end add *********/

 

            1.3修改编译选项

1 [root@localhost linux-2.6.26.3]# cp arch/arm/configs/s3c2410_defconfig .config

[root@localhost linux-2.6.26.3]# make menuconfig

2 [*]Enable loadable module support--->

[*]Forced module loading

[*]Module unloading

3System Type--->

S3C2410 Machines--->

[*]SMDK2410/A9M2410 选上 其余不选

S3C2440 Machines--->

[*]SMDK2440

[*]SMDK2440 with S3C2440 CPU module,其余不选

其余的Machines 下选项全部不选(如2400241224422443

4mem=64M console=ttySAC0 root=/dev/ram initrd=0x30800000,0x00800000

5Device Drivers --->

Block devices  --->

(4096) Default RAM disk size (kbytes) 改成 8192;

1.4 编译

       [root@localhost linux-2.6.26.3]# make dep

*** Warning: make dep is unnecessary now.     (正常,这里显示什么可不必理会)

[root@localhost linux-2.6.26.3]# make zImage

2.     运行

1[ ~ljh@GDLC ]# tftp 30008000 zImage   注意:[ ~ljh@GDLC ]# 是我的u-boot控制台

TFTP from server 192.168.0.238; our IP address is 192.168.0.69

Filename 'zImage'.

Load address: 0x30008000

Loading: #################################################################

         ###########################################

done

Bytes transferred = 1575148 (1808ec hex)

2[ ~ljh@GDLC ]# go 30008000

## Starting application at 0x30008000 ...

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

Linux version 2.6.26.3 (root@localhost.localdomain) (gcc version 3.4.1) #3 Tue Oct 20 23:18:02 CST 2009

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

Machine: QLJT2440

.

.

.

1f03      45056 mtdblock3 (driver?)

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)

到此说明linux移植成功了,但是系统启动的时候找不到文件系统,下面移植ramdisk文件系统。

 

ramdisk文件系统移植(基于busybox)

交叉编译器:           arm-linux-gcc-3.3.2.tar.bz2

Busybox源码:         busybox-1.3.2.tar.bz2

1.        编译busybox

(1)        安装编译环境,方法参见前面arm-linux-gcc-3.4.1的安装

(2)        解压busybox-1.3.2.tar.bz2进入解压后的主目录。

(3)        修改Makefile

ARCH        ?= arm

                  CROSS_COMPILE   ?= arm-linux-

(4)        [root@localhost busybox-1.3.2]# make defconfig

(5)        [root@localhost busybox-1.3.2]# make menuconfig

Busybox Settings  --->

            Build Options  --->

                     [*] Build BusyBox as a static binary (no shared libs)

               Installation Options  --->

                        [*] Don't use /usr

Choose your default shell (msh)  --->

                                       ( ) ash                                

                   ( ) hush                              

                   ( ) lash                              

                   (X) msh                               

                   ( ) none

                       Miscellaneous Utilities  --->      (注意:下面这两个选项原来是选上的,把他们去掉)

                                     [ ] readahead

                                     [ ] taskset

(6)        修改applets/applets.c

#if ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__)改为

#if 0 //ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__)

(7)        编译

[root@localhost busybox-1.3.2]# make

[root@localhost busybox-1.3.2]# make install

成功后就会在busybox-1.3.2目录下生成一个_install目录,存放我们所需要的文件

2.        制作ramdisk文件系统

1[root@localhost busybox-1.3.2]#mkdir filesystem

[root@localhost busybox-1.3.2]#cd filesystem

2[root@localhost filesystem]# dd if=/dev/zero of=./ramdisk bs=1k count=8000   

8000+0 records in

8000+0 records out

3[root@localhost filesystem]#losetup /dev/loop0 ./ramdisk

[root@localhost filesystem]#mke2fs -m 0 /dev/loop0

[root@localhost filesystem]#mount -t ext2 /dev/loop0 /mnt/

[root@localhost filesystem]#cd /mnt/

[root@localhost mnt]# mkdir dev lib  sys  proc  etc  home  usr  tmp  var

(4)把刚才编译busybox生成的在_install下的文件复制过来,并创建两个节点

[root@localhost mnt]# cp -arf /linux_transplant/busybox-1.3.2/_install/* ./

[root@localhost mnt]# mknod -m 600 dev/console c 5 1

[root@localhost mnt]# mknod -m 666 dev/null c 1 3

(4) etc中建立相关的配置文件 /etc/init.d/rcS  /etc/fstab  /etc/inittab /etc/passwd  /etc/group  /etc/shadow

linuxrcboot运行完成执行的第一个用户程序,将控制交给用户;

inittab:linuxrc将会去执行这个文件中的配置;

console::sysinit:-/etc/init.d/rcS

rcSinittab调用的用户程序借口

#!/bin/sh

mount  -a(可以在此直接挂载设备mount -t proc proc /proc

 mount -t sysfs sys /sys

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin

# Start a new shell in the console

/bin/sh

(注:#chmod  777 rcS  )

fstab: mount的相关配置

proc /proc proc defaults 0  0

Group passwd shadow为用户信息,可以从linux系统中的etc中拷贝使用,本文给出一个简单的,也可以不创建,这里我只创建了group

group :用户信息

root::0:root(第一二两个:号中间为空的时候不需要密码,就可以登陆,当不为空时读取shadow中相关信息,并得到登陆密码)

5[root@localhost /]# umount /mnt/

[root@localhost /]# losetup -d /dev/loop0

[root@localhost /]# cd /linux_transplant/filesystem/

[root@localhost filesystem]# gzip -9 ramdisk

 

这时一个已制作好的文件系统ramdisk.gz就在filesystem目录下了。

6)下载运行

[root@localhost filesystem]# cp ramdisk.gz /tftpboot/

[ ~ljh@GDLC ]# tftp 30008000 zImage

[ ~ljh@GDLC ]# tftp 30800000 ramdisk.gz

[ ~ljh@GDLC ]# go 30008000

7)启动信息

         .

         .

         .

drivers/rtc/hctosys.c: unable to open rtc device (rtc0)

RAMDISK: Compressed image found at block 0

VFS: Mounted root (ext2 filesystem).

 

 

BusyBox v1.3.2 (2009-10-20 23:42:37 CST) Built-in shell (msh)

Enter 'help' for a list of built-in commands.

 

# ls

bin         home        lost+found  sys         var

dev         lib         proc        tmp

etc         linuxrc     sbin        usr

# pwd

/

#

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值