您的位置:首页 > 运维架构 > Linux

linux内核移植笔记

2016-09-20 14:41 239 查看
我的开发相关数据


———————————————————————————————————————

机操作系统:Centos
6.7
交叉编译器环境:arm-linux-gcc-4.5.4 
交叉编译器:buildroot-2012.08
开发板平台: FL2440 
Linux内核版本: linux-3.0 
调试终端:SECURE-CRT
Bootloader:U-boot-2010.09
邮箱:hongfuhaocomon@163.com


———————————————————————————————————————

下面直接进行


1. Linux内核移植与启动


2.1 

交叉编译器:buildroot-2012.08

Bootloader:U-boot-2010.09

Target borad:FL2440


首先到 Linux Kernel官方网站www.kernel.org下载得到linux-3.0-rc4.tar.bz2文件,把它放到一个你有权限读写的文件夹,运行下面命令解压缩并进入解压后的文件夹:

[hongfuhao@vboxcentos6 kernel]$ tar -xjf linux-3.0.tar.bz2  

[hongfuhao@vboxcentos6 kernel]$ ls

linux-3.0  linux-3.0.tar.bz2

2.2配置内核编译参数

1. 首先修改顶层目录的Makefile文件

首要便是交叉编译器环境变量和选择开发平台类型

然后要将生成的zimage拷贝到当前目录,再手动增加mkimage工具来自动把Zimage生成可执行的.bin文。

[hongfuhao@vboxcentos6 linux-3.0]$ vim Makefile  

注:内核编译之后会生成两个文件。一个Image,一个Zimage。image为内核映像文件,而Zimage为内核映像压缩文件。Image大约为4M,而Zimage不到2M。

修改内容如下:
@@ -192,8 +192,8 @@

 # Default value for CROSS_COMPILE is not to prefix executables

 # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile

 export KBUILD_BUILDHOST := $(SUBARCH)

- ARCH       ?= $(SUBARCH)

- CROSS_COMPILE  ?= $(CONFIG_CROSS_COMPILE:"%"=%)

+ARCH       ?= arm

+CROSS_COMPILE?= /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-

# Architecture as present in compile.h

 UTS_MACHINE    := $(ARCH)

@@ -557,6 +557,9 @@

 # This allow a user to issue only 'make' to build a kernel including modules

 # Defaults to vmlinux, but the arch makefile usually adds further targets

 all: vmlinux

+  cp arch/arm/boot/zImage . -f

+ mkimage -A arm -O linux -T kernel -C none -a 30008040 -n "Linux Kernel" -d zImage\ linuxrom-s3c2440.bin

+   rm -f zImage

 ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE

KBUILD_CFLAGS  += -Os

@@ -1201,6 +1204,7 @@

  -o -name '.*.rej' -o -size 0 \

-o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \

-type f -print | xargs rm -f

+       @rm -f linuxrom-s3c2440.bin

2.修改晶振频率

使用的是fl2440开发板,根据datesheet可知晶振频率为12M。所以下一步修改晶振频率。

[hongfuhao@vboxcentos6 linux-3.0]$ vim arch/arm/mach-s3c2440/mach-smdk2440.c 


@@ -160,7 +160,7 @@

 static void __init smdk2440_map_io(void)

 {

    s3c24xx_init_io(smdk2440_iodesc, ARRAY_SIZE(smdk2440_iodesc));

--   s3c24xx_init_clocks(16934400);

+   s3c24xx_init_clocks(12000000);

    s3c24xx_init_uarts(smdk2440_uartcfgs, ARRAY_SIZE(smdk2440_uartcfgs));

 }

3.修改驱动串口

[hongfuhao@vboxcentos6 linux-3.0]$ vim drivers/tty/serial/samsung.c

 

@@ -54,7 +54,7 @@

 

 /* UART name and device definitions */

 

--
#define S3C24XX_SERIAL_NAME    "ttySAC":

+ #define S3C24XX_SERIAL_NAME    "ttyS"

  #define S3C24XX_SERIAL_MAJOR   204

  #define S3C24XX_SERIAL_MINOR   64

参考mini2440的.config文件作为我们的默认.config文件。改好之后再

[hongfuhao@vboxcentos6 linux-3.0]$ Make menuconfig

打开文本窗口来选定即将要编译的模块,保存后会将里面的信息保存到同时生成的.config配置文件中。

另外:make menuconfig时出来的文本窗口中的信息是通过读取在内核源代码目录下的Kconfig文件来配置的。根据Makefile文件来编译,而Makefile文件中的变量则通过.config来进行赋值操作。仅仅在Kconfig中添加选项。

4.修改MACHINE ID设备编号

OK,同样因为是做FL2440的内核,所以我们选择三星SMDK2440这个开发板。

因为我U-boot中使用的machine id为1999,而且我使用的是s3c2440这个板子。

将mini2440和和s3c2440的machineID对调。

[hongfuhao@vboxcentos6 linux-3.0]$ vim arch/arm/tools/mach-types

配置就绪之后

Make

显示成功

此时已经会生成一个linux-s3c2440.bin的可执行二进制文件。

[hongfuhao@vboxcentos6 linux-3.0]$ ls

arch     crypto         fs       Kbuild    linuxrom-s3c2440.bin  modules.builtin  README          security    usr

block    Documentation  include  Kconfig  MAINTAINERS            modules.order    REPORTING-BUGS  sound       virt

COPYING  drivers        init     kernel   Makefile               Module.symvers   samples         System.map  vmlinux

CREDITS  firmware       ipc      lib      mm                     net              scripts         tools       vmlinux.o

5.对nandflash进行分区

[hongfuhao@vboxcentos6 linux-3.0]$ vim arch/arm/plat-s3c24xx/common-smdk.c




@@ -106,49 +106,39 @@

    },

 };

 

-/* NAND parititon from 2.4.18-swl5 */

+/* NAND parititon from 2.4.18-swl5,modify by Handy 2014.11.30 */

 

 static struct mtd_partition smdk_default_nand_part[] = {

    [0] = {

-       .name   = "Boot Agent",

-       .size   = SZ_16K,

+       .name   = "bootloader",

+       .size   = SZ_1M,

        .offset = 0,

    },

    [1] = {

-       .name   = "S3C2410 flash partition 1",

-       .offset = 0,

-       .size   = SZ_2M,

+       .name   = "linux",

+       .offset = MTDPART_OFS_NXTBLK,

+       .size   = SZ_1M*15,

    },

    [2] = {

-       .name   = "S3C2410 flash partition 2",

-       .offset = SZ_4M,

-       .size   = SZ_4M,

+       .name   = "rootfs",

+       .offset = MTDPART_OFS_NXTBLK,

+       .size   = SZ_1M*40,

    },

    [3] = {

-       .name   = "S3C2410 flash partition 3",

-       .offset = SZ_8M,

-       .size   = SZ_2M,

+       .name   = "apps",

+       .offset = MTDPART_OFS_NXTBLK,

+       .size   = SZ_1M*50,

    },

    [4] = {

-       .name   = "S3C2410 flash partition 4",

-       .offset = SZ_1M * 10,

-       .size   = SZ_4M,

+       .name   = "data",

+       .offset = MTDPART_OFS_NXTBLK,

+       .size   = SZ_1M*50,

    },

    [5] = {

-       .name   = "S3C2410 flash partition 5",

-       .offset = SZ_1M * 14,

-       .size   = SZ_1M * 10,

-   },

-   [6] = {

-       .name   = "S3C2410 flash partition 6",

-       .offset = SZ_1M * 24,

-       .size   = SZ_1M * 24,

-   },

-   [7] = {

-       .name   = "S3C2410 flash partition 7",

-       .offset = SZ_1M * 48,

+       .name   = "backup",

+       .offset = SZ_1M * 100,

        .size   = MTDPART_SIZ_FULL,

-   }

+   },

 };

板子上nandflash是256M,给bootloader1M用来启动,内核15M以及40M的根文件系统。其他自由分配。

注意:此时若要再进行分区就要选择相应的文件系统。Nandflash比较常用的有yaffs2,ubifs,cramfs以及initramfs等等。

[hongfuhao@vboxcentos6 linux-3.0]$ make


此时能编译成功,但是生成的linux-s3c2440.bin文件依旧不能在板子上跑起来。

因为内核启动时首先挂载的是根文件系统,我们还没有做根文件系统给予内核支持,系统会出错而退出启动。

  CHK     include/linux/version.h

  CHK     include/generated/utsrelease.h

make[1]: “include/generated/mach-types.h”是最新的。

  CALL    scripts/checksyscalls.sh

  CHK     include/generated/compile.h

  CC      arch/arm/plat-s3c24xx/common-smdk.o

  LD      arch/arm/plat-s3c24xx/built-in.o

  LD      vmlinux.o

  MODPOST vmlinux.o

  GEN     .version

  CHK     include/generated/compile.h

  UPD     include/generated/compile.h

  CC      init/version.o

  LD      init/built-in.o

  LD      .tmp_vmlinux1

  KSYM    .tmp_kallsyms1.S

  AS      .tmp_kallsyms1.o

  LD      .tmp_vmlinux2

  KSYM    .tmp_kallsyms2.S

  AS      .tmp_kallsyms2.o

  LD      vmlinux

  SYSMAP  System.map

  SYSMAP  .tmp_System.map

  OBJCOPY arch/arm/boot/Image

  Kernel: arch/arm/boot/Image is ready

  GZIP    arch/arm/boot/compressed/piggy.gzip

  AS      arch/arm/boot/compressed/piggy.gzip.o

  SHIPPED arch/arm/boot/compressed/lib1funcs.S

  AS      arch/arm/boot/compressed/lib1funcs.o

  LD      arch/arm/boot/compressed/vmlinux

  OBJCOPY arch/arm/boot/zImage

  Kernel: arch/arm/boot/zImage is ready

  Building modules, stage 2.

  MODPOST 178 modules

cp arch/arm/boot/zImage . -f

mkimage -A arm -O linux -T kernel -C none -a 30008040 -n "Linux Kernel" -d zImage \ linuxrom-s3c2440.bin

Image Name:   Linux Kernel

Created:      Wed Sep 21 02:46:09 2016

Image Type:   ARM Linux Kernel Image (uncompressed)

Data Size:    2337936 Bytes = 2283.14 kB = 2.23 MB

Load Address: 30008040

Entry Point:  30008040

rm -f zImage

[hongfuhao@vboxcentos6 linux-3.0]$ ls

arch     crypto         fs       Kbuild    linuxrom-s3c2440.bin  modules.builtin  README          security    usr

block    Documentation  include  Kconfig  MAINTAINERS            modules.order    REPORTING-BUGS  sound       virt

COPYING  drivers        init     kernel   Makefile               Module.symvers   samples         System.map  vmlinux

CREDITS  firmware       ipc      lib      mm                     net              scripts         tools       vmlinux.o


3.添加根文件系统内核支持

此步先进行省略,至此内核数据修改完成看看移植到开发板厚的情况。
没有根文件系统的支持,开机运行出错如下
U-Boot 2010.09 (Jul 15 2016 - 21:57:32)

DRAM:  64 MiB

NAND:  256 MiB

*** Warning - bad CRC or NAND, using default environment

In:    serial

Out:   serial

Err:   serial

Net:   dm9000

Hit any key to stop autoboot:  0 

NAND read: device 0 offset 0x100000, size 0x900000

Skipping bad block 0x00700000

 9437184 bytes read: OK

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

   Image Name:   Linux Kernel

   Created:      2016-09-20  22:24:48 UTC

   Image Type:   ARM Linux Kernel Image (uncompressed)

   Data Size:    2332608 Bytes = 2.2 MiB

   Load Address: 30008040

   Entry Point:  30008040

   Verifying Checksum ... OK

   Loading Kernel Image ... OK

OK

Starting kernel ...

Uncompressing Linux... done, booting the kernel.

Linux version 3.0.0 (hongfuhao@vboxcentos6.localdomain) (gcc version 4.5.4 (Buildroot 2012.08) ) #1 Wed Sep 21 06:15:35 CST 2016

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

CPU: VIVT data cache, VIVT instruction cache

Machine: SMDK2440

Memory policy: ECC disabled, Data cache writeback

CPU S3C2440A (id 0x32440001)

S3C24XX Clocks, Copyright 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: console=ttyS0,115200 mem=64M rw loglevel=7

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: 60204k/60204k available, 5332k reserved, 0K highmem

Virtual kernel memory layout:

    vector  : 0xffff0000 - 0xffff1000   (   4 kB)

    fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)

    DMA     : 0xffc00000 - 0xffe00000   (   2 MB)

    vmalloc : 0xc4800000 - 0xf6000000   ( 792 MB)

    lowmem  : 0xc0000000 - 0xc4000000   (  64 MB)

    modules : 0xbf000000 - 0xc0000000   (  16 MB)

      .init : 0xc0008000 - 0xc002a000   ( 136 kB)

      .text : 0xc002a000 - 0xc0439ee4   (4160 kB)

      .data : 0xc043a000 - 0xc045e300   ( 145 kB)

       .bss : 0xc045e324 - 0xc0498f4c   ( 236 kB)

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

NR_IRQS:85

irq: clearing subpending status 00000002

Console: colour dummy device 80x30

console [ttyS0] enabled

Calibrating delay loop... 201.52 BogoMIPS (lpj=503808)

pid_max: default: 32768 minimum: 301

Mount-cache hash table entries: 512

CPU: Testing write buffer coherency: ok

gpiochip_add: gpios 288..303 (GPIOK) failed to register

gpiochip_add: gpios 320..334 (GPIOL) failed to register

gpiochip_add: gpios 352..353 (GPIOM) failed to register

NET: Registered protocol family 16

S3C Power Management, Copyright 2004 Simtec Electronics

S3C2440: Initialising architecture

S3C2440: IRQ Support

S3C244X: Clock Support, DVS off

bio: create slab <bio-0> at 0

usbcore: registered new interface driver usbfs

usbcore: registered new interface driver hub

usbcore: registered new device driver usb

s3c-i2c s3c2440-i2c: slave address 0x10

s3c-i2c s3c2440-i2c: bus frequency set to 98 KHz

s3c-i2c s3c2440-i2c: i2c-0: S3C I2C adapter

Advanced Linux Sound Architecture Driver Version 1.0.24.

NET: Registered protocol family 2

IP route cache hash table entries: 1024 (order: 0, 4096 bytes)

TCP established hash table entries: 2048 (order: 2, 16384 bytes)

TCP bind hash table entries: 2048 (order: 1, 8192 bytes)

TCP: Hash tables configured (established 2048 bind 2048)

TCP reno registered

UDP hash table entries: 256 (order: 0, 4096 bytes)

UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)

NET: Registered protocol family 1

RPC: Registered named UNIX socket transport module.

RPC: Registered udp transport module.

RPC: Registered tcp transport module.

RPC: Registered tcp NFSv4.1 backchannel transport module.

JFFS2 version 2.2. (NAND) 漏 2001-2006 Red Hat, Inc.

ROMFS MTD (C) 2007 Red Hat, Inc.

msgmni has been set to 117

io scheduler noop registered

io scheduler deadline registered

io scheduler cfq registered (default)

Console: switching to colour frame buffer device 60x53

fb0: s3c2410fb frame buffer device

s3c2440-uart.0: ttyS0 at MMIO 0x50000000 (irq = 70) is a S3C2440

s3c2440-uart.1: ttyS1 at MMIO 0x50004000 (irq = 73) is a S3C2440

s3c2440-uart.2: ttyS2 at MMIO 0x50008000 (irq = 76) is a S3C2440

brd: module loaded

S3C24XX NAND Driver, (c) 2004 Simtec Electronics

s3c24xx-nand s3c2440-nand: Tacls=3, 29ns Twrph0=7 69ns, Twrph1=3 29ns

s3c24xx-nand s3c2440-nand: NAND soft ECC

NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)

Scanning device for bad blocks

Bad eraseblock 56 at 0x000000700000

Bad eraseblock 669 at 0x0000053a0000

Bad eraseblock 1800 at 0x00000e100000

Creating 8 MTD partitions on "NAND":

0x000000000000-0x000000004000 : "Boot Agent"

mtd: partition "Boot Agent" doesn't end on an erase block -- force read-only

ftl_cs: FTL header corrupt!

0x000000000000-0x000000200000 : "S3C2410 flash partition 1"

ftl_cs: FTL header not found.

0x000000400000-0x000000800000 : "S3C2410 flash partition 2"

ftl_cs: FTL header not found.

0x000000800000-0x000000a00000 : "S3C2410 flash partition 3"

ftl_cs: FTL header not found.

0x000000a00000-0x000000e00000 : "S3C2410 flash partition 4"

ftl_cs: FTL header not found.

0x000000e00000-0x000001800000 : "S3C2410 flash partition 5"

ftl_cs: FTL header not found.

0x000001800000-0x000003000000 : "S3C2410 flash partition 6"

ftl_cs: FTL header not found.

0x000003000000-0x000010000000 : "S3C2410 flash partition 7"

ftl_cs: FTL header not found.

dm9000 Ethernet Driver, V1.31

ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver

s3c2410-ohci s3c2410-ohci: S3C24XX OHCI

s3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1

s3c2410-ohci s3c2410-ohci: irq 42, io mem 0x49000000

hub 1-0:1.0: USB hub found

hub 1-0:1.0: 2 ports detected

usbcore: registered new interface driver libusual

mousedev: PS/2 mouse device common for all mice

S3C24XX RTC, (c) 2004,2006 Simtec Electronics

i2c /dev entries driver

S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics

s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled

cpuidle: using governor ladder

sdhci: Secure Digital Host Controller Interface driver

sdhci: Copyright(c) Pierre Ossman

usbcore: registered new interface driver usbhid

usbhid: USB HID core driver

ALSA device list:

  No soundcards found.

TCP cubic registered

NET: Registered protocol family 17

Registering the dns_resolver key type

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

Root-NFS: no NFS server address

VFS: Unable to mount root fs via NFS, trying floppy.

VFS: Cannot open root device "(null)" or unknown-block(2,0)

Please append a correct "root=" boot option; here are the available partitions:

1f00              16 mtdblock0  (driver?)

1f01            2048 mtdblock1  (driver?)

1f02            4096 mtdblock2  (driver?)

1f03            2048 mtdblock3  (driver?)

1f04            4096 mtdblock4  (driver?)

1f05           10240 mtdblock5  (driver?)

1f06           24576 mtdblock6  (driver?)

1f07          212992 mtdblock7  (driver?)

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

[<c002f508>] (unwind_backtrace+0x0/0xf0) from [<c033c4c0>] (panic+0x58/0x18c)

[<c033c4c0>] (panic+0x58/0x18c) from [<c0008ce4>] (mount_block_root+0x15c/0x210)

[<c0008ce4>] (mount_block_root+0x15c/0x210) from [<c0008f3c>] (mount_root+0xa4/0xc8)

[<c0008f3c>] (mount_root+0xa4/0xc8) from [<c00090c4>] (prepare_namespace+0x164/0x1bc)

[<c00090c4>] (prepare_namespace+0x164/0x1bc) from [<c00089a0>] (kernel_init+0xdc/0x110)

[<c00089a0>] (kernel_init+0xdc/0x110) from [<c002b840>] (kernel_thread_exit+0x0/0x8)

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: