linux内核移植 I

时间:2021-02-02 12:26:40

根据tx2440的文档, 目标也比较简单, 先编译成功, 再烧录, 根文件系统, busybox 这些.

A. 准备

1. 解压tar, 修改根Makefile

ARCH ?= arm

CROSS_COMPILE ?= arm-linux-

 

2. 修改时钟

arch/arm/mach-s3c2440/mach-smdk2440.c

s3c24xx_init_clocks(12000000);

 

3. 修改机器码

arch/arm/tools/mach-types

s3c2440      ....   xxx, 要对应uboot里面的机器码.

book@book-desktop:/tmp/linux-2.6.22.6/arch/arm/tools$ cat /tmp/u-boot/include/asm-arm/mach-types.h |grep S3C2440
#define MACH_TYPE_S3C2440              362
#define MACH_TYPE_SMDKS3C2440          782
#ifdef CONFIG_ARCH_S3C2440
#  define machine_arch_type     MACH_TYPE_S3C2440
# define machine_is_s3c2440()   (machine_arch_type == MACH_TYPE_S3C2440)
book@book-desktop:/tmp/linux-2.6.22.6/arch/arm/tools$ cat mach-types |grep s3c2440
s3c2440                 ARCH_S3C2440            S3C2440                 362

似乎是对的, 暂时不管它.

 

4. 配置

make menuconfig

首先load一下2410的配置文件, 即arch/arm/configs/s3c2410_defconfig

进System Type, 选择S3C24xx Machine

linux内核移植 I

仅选择以上几项, 其他不选.

然后save成.config文件.

 

5. make uImage, 是不是很简单...

烧进去看看吧.

 

6. 修改分区

arch/arm/plat-s3c24xx/common-smdk.c

 [0] = {
                .name   = "BootLoader",
                .size   = 0x00040000,
                .offset = 0,
        },
        [1] = {
                .name   = "params",
                .offset = MTDPART_OFS_APPEND,
                .size   = 0x00020000,
        },
        [2] = {
                .name   = "kernel",
                .offset = MTDPART_OFS_APPEND,
                .size   = 0x00200000,
        },
        [3] = {
                .name   = "root",
                .offset = MTDPART_OFS_APPEND,
                .size   = MTDPART_SIZ_FULL,
        }

内核启动的时候:

Creating 4 MTD partitions on "NAND 256MiB 3,3V 8-bit":
0x00000000-0x00040000 : "BootLoader"     0-0x40000是bootload分区, 大小是256K
0x00040000-0x00060000 : "params"      0x40000-0x60000是params分区, 128K
0x00060000-0x00260000 : "kernel"        kernel分区有2M
0x00260000-0x10000000 : "root"           剩下的,到256M都是root分区.


bootargs=noinitrd console=ttySAC0 root=/dev/mtdblock3 rootfstype=yaffs

yaffs tragedy:attempt to put data chunk into a non-file
==>> yaffs bug: fs/yaffs2/yaffs_guts.c 3404
page 8826 in gc has no object: -65536 123600896 104202240
yaffs tragedy:attempt to put data chunk into a non-file
==>> yaffs bug: fs/yaffs2/yaffs_guts.c 3404
List of all partitions:
1f00        256 mtdblock0 (driver?)
1f01        128 mtdblock1 (driver?)
1f02       2048 mtdblock2 (driver?)
1f03     259712 mtdblock3 (driver?)
No filesystem could mount root, tried:  yaffs
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,3)

 

搞了半天flash有问题..

能起来的情况下, uboot配置如下:

bootargs=noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0
bootcmd=nand read.jffs2 0x30007FC0 kernel; bootm 0x30007FC0
bootdelay=2
baudrate=115200
ethaddr=08:00:3e:26:0a:5b
ipaddr=192.168.7.17
serverip=192.168.7.11
netmask=255.255.255.0
stdin=serial
stdout=serial
stderr=serial
mtdids=nand0=nandflash0
mtdparts=mtdparts=nandflash0:256k@0(bootloader),128k(params),2m(kernel),-(root)
partition=nand0,0
mtddevnum=0
mtddevname=bootloader

根目录设备挂载mnode

# ls -l
crw-r--r--    1 0        0          5,   1 Jan  1 00:00 console
brw-r--r--    1 0        0         31,   0 Jan 22  2008 mtdblock0
brw-r--r--    1 0        0         31,   1 Jan 22  2008 mtdblock1
brw-r--r--    1 0        0         31,   2 Jan 22  2008 mtdblock2
crw-r--r--    1 0        0          1,   3 Jan 22  2008 null
crw-r--r--    1 0        0        204,  64 Jan  1 00:04 ttySAC0

查看busybox依赖的库

book@book-desktop:/tmp/mini_fs/bin$ arm-linux-readelf -a "busybox"|grep Shared
 0x00000001 (NEEDED)                     Shared library: [libcrypt.so.1]
 0x00000001 (NEEDED)                     Shared library: [libm.so.6]
 0x00000001 (NEEDED)                     Shared library: [libc.so.6]

最后烧录成jffs2文件格式,

 启动参数改成:

bootargs=noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0 rootfstype=jffs2

制作镜像文件的命令是:

 mkfs.jffs2 -n -s 512 -e 16KiB -d mini_fs -o mini.jffs2