Linux内核移植(3)

来源:互联网 发布:母婴店软件 编辑:程序博客网 时间:2024/05/20 14:43

Linux3.8.3内核移植-uImage启动

linux kernel编译之后,生成uImage和zImage。而uImage正是u-boot可以直接启动的内核镜像。
启动流程:u-boot从nandflash中启动,加载SD卡中的uImage至DRAM中运行!
(前期先从SD卡加载uImage,方便调试,后面会放到nand加载)

1、修改u-boot,让其能够识别SD卡中的uImage,进入u-boot命令

SMDK6410 # printenv baudrate=115200 bootargs=console=ttySAC,115200 bootcmd=nand read 0x50018000 0x60000 0x1c0000;bootm 0x50018000 bootdelay=3 ethact=dm9000 ethaddr=00:40:5c:26:0a:5b gatewayip=192.168.1.1 ipaddr=192.168.1.2 serverip=192.168.1.136 stderr=serial stdin=serial

将bootcmd修改为”fatload mmc 0 50008000 uImage;bootm 50008000”,并保存

SMDK6410 # setenv bootcmd "fatload mmc 0 50008000 uImage;bootm 50008000"SMDK6410 # saveenvSaving Environment to NAND...saveenv:env_new->crc=0x67aa16f2Erasing Nand...Erasing at 0x80000 -- 100% complete.Writing to Nand... doneSMDK6410 #

这段代码就是,u-boot将SD卡中的uImage加载到DRAM 0x50008000,并从0x50008000运行!

2、尝试启动内核,将uImage复制到SD卡中,启动

U-Boot 2013.04-rc1 (Nov 26 2017 - 10:13:37) for SMDK6410CPU:     S3C6410@533MHz         Fclk = 533MHz, Hclk = 133MHz, Pclk = 66MHz (ASYNC Mode)Board:   SMDK6410DRAM:  128 MiBWARNING: Caches not enabledFlash: *** failed ***NAND:  256 MiBMMC:   Samsung  Host Controller: 0,3.6 GiBIn:    serialOut:   serialErr:   serialNet:   dm9000Hit any key to stop autoboot:  0reading uImage1510736 bytes read in 57 ms (25.3 MiB/s)## Booting kernel from Legacy Image at 50008000 ...   Image Name:   Linux-3.8.3   Image Type:   ARM Linux Kernel Image (uncompressed)   Data Size:    1510672 Bytes = 1.4 MiB   Load Address: 50008000   Entry Point:  50008000   Verifying Checksum ... OK   XIP Kernel Image ... OKOKStarting kernel ...

以上,可以看出,uboot已经成功读取并解压了内核,读出内核name&type,但是无法成功启动,一直停留在Starting kernel …

分析:
Load Address: 50008000 内核加载地址
Entry Point: 50008000 内核启动地址
由于制作uImage的时候,是将zImage前面添加0x40Bytes的头,所以真正的内核应该在50008040

3、修改内核入口地址

eric@eric-PC:~/Documents/linux-3.8.3/scripts$ gedit Makefile.lib 

322行:

#UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR)    #eric++2017-12-03UIMAGE_ENTRYADDR ?= $(shell echo $(UIMAGE_LOADADDR) | sed -e"s/..$$/40/")

再次make uImage

Image Name:   Linux-3.8.3Created:      Sun Dec  3 09:47:22 2017Image Type:   ARM Linux Kernel Image (uncompressed)Data Size:    1510672 Bytes = 1475.27 kB = 1.44 MBLoad Address: 50008000Entry Point:  50008040  Image arch/arm/boot/uImage is readyeric@eric-PC:~/Documents/linux-3.8.3$

Entry Point: 50008040,已经变为50008040

4、再次启动

U-Boot 2013.04-rc1 (Nov 26 2017 - 10:13:37) for SMDK6410CPU:     S3C6410@533MHz         Fclk = 533MHz, Hclk = 133MHz, Pclk = 66MHz (ASYNC Mode)Board:   SMDK6410DRAM:  128 MiBWARNING: Caches not enabledFlash: *** failed ***NAND:  256 MiBMMC:   Samsung  Host Controller: 0,3.6 GiBIn:    serialOut:   serialErr:   serialNet:   dm9000Hit any key to stop autoboot:  0SMDK6410 #SMDK6410 # printenvbaudrate=115200bootargs=noinitrd root=/dev/mtdblock2 rootfstpye=yaffs2 init=/linuxrc console=ttySAC0,115200bootcmd=fatload mmc 0 50008000 uImage;bootm 50008000bootdelay=3ethact=dm9000ethaddr=00:40:5c:26:0a:5bgatewayip=192.168.1.1ipaddr=192.168.1.2serverip=192.168.1.136stderr=serialstdin=serialstdout=serialEnvironment size: 345/16380 bytesSMDK6410 # setenv bootargs ""SMDK6410 # saventUnknown command 'savent' - try 'help'SMDK6410 # savenvUnknown command 'savenv' - try 'help'SMDK6410 # saveenvSaving Environment to NAND...saveenv:env_new->crc=0x73d947d5Erasing Nand...Erasing at 0x80000 -- 100% complete.Writing to Nand... doneSMDK6410 # printenvbaudrate=115200bootargs=bootcmd=fatload mmc 0 50008000 uImage;bootm 50008000bootdelay=3ethact=dm9000ethaddr=00:40:5c:26:0a:5bgatewayip=192.168.1.1ipaddr=192.168.1.2serverip=192.168.1.136stderr=serialstdin=serialstdout=serialEnvironment size: 261/16380 bytesSMDK6410 #U-Boot 2013.04-rc1 (Nov 26 2017 - 10:13:37) for SMDK6410CPU:     S3C6410@533MHz         Fclk = 533MHz, Hclk = 133MHz, Pclk = 66MHz (ASYNC Mode)Board:   SMDK6410DRAM:  128 MiBWARNING: Caches not enabledFlash: *** failed ***NAND:  256 MiBMMC:   Samsung  Host Controller: 0,3.6 GiBIn:    serialOut:   serialErr:   serialNet:   dm9000Hit any key to stop autoboot:  0reading uImage1510736 bytes read in 63 ms (22.9 MiB/s)## Booting kernel from Legacy Image at 50008000 ...   Image Name:   Linux-3.8.3   Image Type:   ARM Linux Kernel Image (uncompressed)   Data Size:    1510672 Bytes = 1.4 MiB   Load Address: 50008000   Entry Point:  50008040   Verifying Checksum ... OK   XIP Kernel Image ... OKOKStarting kernel ...Uncompressing Linux... done, booting the kernel.Booting Linux on physical CPU 0x0Linux version 3.8.3 (eric@eric-PC) (gcc version 4.4.3 (ctng-1.6.1) ) #3 Sat Dec 2 18:06:08 CST 2017CPU: ARMv6-compatible processor [410fb766] revision 6 (ARMv7), cr=00c5387dCPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cacheMachine: X6410Memory policy: ECC disabled, Data cache writebackCPU S3C6410 (id 0x36410101)S3C24XX Clocks, Copyright 2004 Simtec ElectronicsS3C64XX: PLL settings, A=533000000, M=533000000, E=24000000S3C64XX: HCLK2=266500000, HCLK=133250000, PCLK=66625000mout_apll: source is fout_apll (1), rate is 533000000mout_epll: source is epll (1), rate is 24000000mout_mpll: source is mpll (1), rate is 533000000usb-bus-host: source is clk_48m (0), rate is 48000000irda-bus: source is mout_epll (0), rate is 24000000CPU: found DTCM0 8k @ 00000000, not enabledCPU: moved DTCM0 8k to fffe8000, enabledCPU: found DTCM1 8k @ 00000000, not enabledCPU: moved DTCM1 8k to fffea000, enabledCPU: found ITCM0 8k @ 00000000, not enabledCPU: moved ITCM0 8k to fffe0000, enabledCPU: found ITCM1 8k @ 00000000, not enabledCPU: moved ITCM1 8k to fffe2000, enabledBuilt 1 zonelists in Zone order, mobility grouping on.  Total pages: 32512Kernel command line: console=ttySAC0,115200 root=/dev/ram init=/linuxrc initrd=0x51000000,6M ramdisk_size=6144PID hash table entries: 512 (order: -1, 2048 bytes)Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)__ex_table already sorted, skipping sortMemory: 128MB = 128MB totalMemory: 120616k/120616k available, 10456k reserved, 0K highmemVirtual kernel memory layout:    vector  : 0xffff0000 - 0xffff1000   (   4 kB)    DTCM    : 0xfffe8000 - 0xfffec000   (  16 kB)    ITCM    : 0xfffe0000 - 0xfffe4000   (  16 kB)    fixmap  : 0xfff00000 - 0xfffe0000   ( 896 kB)    vmalloc : 0xc8800000 - 0xff000000   ( 872 MB)    lowmem  : 0xc0000000 - 0xc8000000   ( 128 MB)    modules : 0xbf000000 - 0xc0000000   (  16 MB)      .text : 0xc0008000 - 0xc02930d4   (2605 kB)      .init : 0xc0294000 - 0xc02af6e4   ( 110 kB)      .data : 0xc02b0000 - 0xc02db6a0   ( 174 kB)       .bss : 0xc02dc000 - 0xc030d2f8   ( 197 kB)SLUB: Genslabs=13, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1NR_IRQS:246VIC @f6000000: id 0x00041192, vendor 0x41VIC @f6010000: id 0x00041192, vendor 0x41sched_clock: 32 bits at 100 Hz, resolution 10000000ns, wraps every 4294967286msConsole: colour dummy device 80x30Calibrating delay loop... 353.89 BogoMIPS (lpj=1769472)pid_max: default: 32768 minimum: 301Mount-cache hash table entries: 512CPU: Testing write buffer coherency: okSetting up static identity map for 0x501ebf48 - 0x501ebfa4DMA: preallocated 256 KiB pool for atomic coherent allocationsX6410: Option string x6410=0X6410: selected LCD display is 480x272s3c64xx_dma_init: Registering DMA channelsPL080: IRQ 73, at c8846000, channels 0..8PL080: IRQ 74, at c8848000, channels 8..16S3C6410: Initialising architecturebio: create slab <bio-0> at 0usbcore: registered new interface driver usbfsusbcore: registered new interface driver hubusbcore: registered new device driver usbTrying to unpack rootfs image as initramfs...rootfs image is not initramfs (junk in compressed archive); looks like an initrdFreeing initrd memory: 6144KROMFS MTD (C) 2007 Red Hat, Inc.io scheduler noop registeredio scheduler deadline registeredio scheduler cfq registered (default)s3c-fb s3c-fb: window 0: fbSerial: 8250/16550 driver, 4 ports, IRQ sharing disableds3c6400-uart.0: ttySAC0 at MMIO 0x7f005000 (irq = 69) is a S3C6400/10console [ttySAC0] enableds3c6400-uart.1: ttySAC1 at MMIO 0x7f005400 (irq = 70) is a S3C6400/10s3c6400-uart.2: ttySAC2 at MMIO 0x7f005800 (irq = 71) is a S3C6400/10s3c6400-uart.3: ttySAC3 at MMIO 0x7f005c00 (irq = 72) is a S3C6400/10brd: module loadedloop: module loadeds3c24xx-nand s3c6400-nand: Tacls=4, 30ns Twrph0=8 60ns, Twrph1=6 45nss3c24xx-nand s3c6400-nand: System booted from NANDs3c24xx-nand s3c6400-nand: NAND soft ECCNAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit), 256MiB, page size: 2048, OOB size: 64Scanning device for bad blocksBad eraseblock 331 at 0x000002960000Bad eraseblock 835 at 0x000006860000Bad eraseblock 913 at 0x000007220000Bad eraseblock 1128 at 0x000008d00000Bad eraseblock 1787 at 0x00000df60000Bad eraseblock 2018 at 0x00000fc40000Creating 3 MTD partitions on "nand":0x000000000000-0x000000100000 : "uboot"0x000000100000-0x000000300000 : "kernel"0x000000300000-0x000010000000 : "rootfs"ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Drivers3c2410-ohci s3c2410-ohci: S3C24XX OHCIs3c2410-ohci s3c2410-ohci: new USB bus registered, assigned bus number 1s3c2410-ohci s3c2410-ohci: irq 79, io mem 0x74300000s3c2410-ohci s3c2410-ohci: init err (00000000 0000)s3c2410-ohci s3c2410-ohci: can't start s3c24xxs3c2410-ohci s3c2410-ohci: startup error -75s3c2410-ohci s3c2410-ohci: USB bus 1 deregistereds3c2410-ohci: probe of s3c2410-ohci failed with error -75mousedev: PS/2 mouse device common for all micei2c /dev entries driversdhci: Secure Digital Host Controller Interface driversdhci: Copyright(c) Pierre Ossmans3c-sdhci s3c-sdhci.0: clock source 0: mmc_busclk.0 (133250000 Hz)s3c-sdhci s3c-sdhci.0: clock source 2: mmc_busclk.2 (24000000 Hz)mmc0: SDHCI controller on samsung-hsmmc [s3c-sdhci.0] using ADMAs3c-sdhci s3c-sdhci.1: clock source 0: mmc_busclk.0 (133250000 Hz)s3c-sdhci s3c-sdhci.1: clock source 2: mmc_busclk.2 (24000000 Hz)mmc0: mmc_rescan_try_freq: trying to init card at 400000 Hzmmc0: mmc_rescan_try_freq: trying to init card at 300000 Hzmmc1: SDHCI controller on samsung-hsmmc [s3c-sdhci.1] using ADMAmmc0: mmc_rescan_try_freq: trying to init card at 200000 Hzusbcore: registered new interface driver usbhidusbhid: USB HID core driverVFP support v0.3: implementor 41 architecture 1 part 20 variant b rev 5drivers/rtc/hctosys.c: unable to open rtc device (rtc0)RAMDISK: Couldn't find valid RAM disk image starting at 0.mmc0: mmc_rescan_try_freq: trying to init card at 100000 HzList of all partitions:No filesystem could mount root, tried:  ext3 ext2 cramfs romfsKernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(1,0)[<c0013fc4>] (unwind_backtrace+0x0/0xf4) from [<c01e9664>] (panic+0x8c/0x1dc)[<c01e9664>] (panic+0x8c/0x1dc) from [<c0294da0>] (mount_block_root+0x28c/0x2e0)[<c0294da0>] (mount_block_root+0x28c/0x2e0) from [<c0294fb8>] (prepare_namespace+0x160/0x1b8)[<c0294fb8>] (prepare_namespace+0x160/0x1b8) from [<c01e9090>] (kernel_init+0x8/0xe4)[<c01e9090>] (kernel_init+0x8/0xe4) from [<c000e558>] (ret_from_fork+0x14/0x3c)

OK!至此,u-boot已经成功启动了linux kernel!
启动依旧停止,,后续陆续完善。。。

成功启动kernel的关键:
1、成功生成uImage
2、uboot成功加载uImage
3、成功进入入口地址50008040
4、MACH_TYPE ID u-boot和kernel必须一致