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 # saveenv
Saving Environment to NAND...
saveenv:env_new->crc=0x67aa16f2
Erasing Nand...
Erasing at 0x80000 -- 100% complete.
Writing to Nand... done
SMDK6410 #
这段代码就是,u-boot将SD卡中的uImage加载到DRAM 0x50008000,并从0x50008000运行!
2、尝试启动内核,将uImage复制到SD卡中,启动
U-Boot 2013.04-rc1 (Nov 26 2017 - 10:13:37) for SMDK6410
CPU: S3C6410@533MHz
Fclk = 533MHz, Hclk = 133MHz, Pclk = 66MHz (ASYNC Mode)
Board: SMDK6410
DRAM: 128 MiB
WARNING: Caches not enabled
Flash: *** failed ***
NAND: 256 MiB
MMC: Samsung Host Controller: 0,3.6 GiB
In: serial
Out: serial
Err: serial
Net: dm9000
Hit any key to stop autoboot: 0
reading uImage
1510736 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 ... OK
OK
Starting 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-03
UIMAGE_ENTRYADDR ?= $(shell echo $(UIMAGE_LOADADDR) | sed -e"s/..$$/40/")
再次make uImage
Image Name: Linux-3.8.3
Created: Sun Dec 3 09:47:22 2017
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 1510672 Bytes = 1475.27 kB = 1.44 MB
Load Address: 50008000
Entry Point: 50008040
Image arch/arm/boot/uImage is ready
eric@eric-PC:~/Documents/linux-3.8.3$
Entry Point: 50008040,已经变为50008040
4、再次启动
U-Boot 2013.04-rc1 (Nov 26 2017 - 10:13:37) for SMDK6410
CPU: S3C6410@533MHz
Fclk = 533MHz, Hclk = 133MHz, Pclk = 66MHz (ASYNC Mode)
Board: SMDK6410
DRAM: 128 MiB
WARNING: Caches not enabled
Flash: *** failed ***
NAND: 256 MiB
MMC: Samsung Host Controller: 0,3.6 GiB
In: serial
Out: serial
Err: serial
Net: dm9000
Hit any key to stop autoboot: 0
SMDK6410 #
SMDK6410 # printenv
baudrate=115200
bootargs=noinitrd root=/dev/mtdblock2 rootfstpye=yaffs2 init=/linuxrc console=ttySAC0,115200
bootcmd=fatload mmc 0 50008000 uImage;bootm 50008000
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
stdout=serial
Environment size: 345/16380 bytes
SMDK6410 # setenv bootargs ""
SMDK6410 # savent
Unknown command 'savent' - try 'help'
SMDK6410 # savenv
Unknown command 'savenv' - try 'help'
SMDK6410 # saveenv
Saving Environment to NAND...
saveenv:env_new->crc=0x73d947d5
Erasing Nand...
Erasing at 0x80000 -- 100% complete.
Writing to Nand... done
SMDK6410 # printenv
baudrate=115200
bootargs=
bootcmd=fatload mmc 0 50008000 uImage;bootm 50008000
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
stdout=serial
Environment size: 261/16380 bytes
SMDK6410 #
U-Boot 2013.04-rc1 (Nov 26 2017 - 10:13:37) for SMDK6410
CPU: S3C6410@533MHz
Fclk = 533MHz, Hclk = 133MHz, Pclk = 66MHz (ASYNC Mode)
Board: SMDK6410
DRAM: 128 MiB
WARNING: Caches not enabled
Flash: *** failed ***
NAND: 256 MiB
MMC: Samsung Host Controller: 0,3.6 GiB
In: serial
Out: serial
Err: serial
Net: dm9000
Hit any key to stop autoboot: 0
reading uImage
1510736 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 ... OK
OK
Starting kernel ...
Uncompressing Linux... done, booting the kernel.
Booting Linux on physical CPU 0x0
Linux version 3.8.3 (eric@eric-PC) (gcc version 4.4.3 (ctng-1.6.1) ) #3 Sat Dec 2 18:06:08 CST 2017
CPU: ARMv6-compatible processor [410fb766] revision 6 (ARMv7), cr=00c5387d
CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
Machine: X6410
Memory policy: ECC disabled, Data cache writeback
CPU S3C6410 (id 0x36410101)
S3C24XX Clocks, Copyright 2004 Simtec Electronics
S3C64XX: PLL settings, A=533000000, M=533000000, E=24000000
S3C64XX: HCLK2=266500000, HCLK=133250000, PCLK=66625000
mout_apll: source is fout_apll (1), rate is 533000000
mout_epll: source is epll (1), rate is 24000000
mout_mpll: source is mpll (1), rate is 533000000
usb-bus-host: source is clk_48m (0), rate is 48000000
irda-bus: source is mout_epll (0), rate is 24000000
CPU: found DTCM0 8k @ 00000000, not enabled
CPU: moved DTCM0 8k to fffe8000, enabled
CPU: found DTCM1 8k @ 00000000, not enabled
CPU: moved DTCM1 8k to fffea000, enabled
CPU: found ITCM0 8k @ 00000000, not enabled
CPU: moved ITCM0 8k to fffe0000, enabled
CPU: found ITCM1 8k @ 00000000, not enabled
CPU: moved ITCM1 8k to fffe2000, enabled
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 32512
Kernel command line: console=ttySAC0,115200 root=/dev/ram init=/linuxrc initrd=0x51000000,6M ramdisk_size=6144
PID 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 sort
Memory: 128MB = 128MB total
Memory: 120616k/120616k available, 10456k reserved, 0K highmem
Virtual 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=1
NR_IRQS:246
VIC @f6000000: id 0x00041192, vendor 0x41
VIC @f6010000: id 0x00041192, vendor 0x41
sched_clock: 32 bits at 100 Hz, resolution 10000000ns, wraps every 4294967286ms
Console: colour dummy device 80x30
Calibrating delay loop... 353.89 BogoMIPS (lpj=1769472)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
Setting up static identity map for 0x501ebf48 - 0x501ebfa4
DMA: preallocated 256 KiB pool for atomic coherent allocations
X6410: Option string x6410=0
X6410: selected LCD display is 480x272
s3c64xx_dma_init: Registering DMA channels
PL080: IRQ 73, at c8846000, channels 0..8
PL080: IRQ 74, at c8848000, channels 8..16
S3C6410: Initialising architecture
bio: create slab 0> at 0
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
Trying to unpack rootfs image as initramfs...
rootfs image is not initramfs (junk in compressed archive); looks like an initrd
Freeing initrd memory: 6144K
ROMFS MTD (C) 2007 Red Hat, Inc.
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
s3c-fb s3c-fb: window 0: fb
Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
s3c6400-uart.0: ttySAC0 at MMIO 0x7f005000 (irq = 69) is a S3C6400/10
console [ttySAC0] enabled
s3c6400-uart.1: ttySAC1 at MMIO 0x7f005400 (irq = 70) is a S3C6400/10
s3c6400-uart.2: ttySAC2 at MMIO 0x7f005800 (irq = 71) is a S3C6400/10
s3c6400-uart.3: ttySAC3 at MMIO 0x7f005c00 (irq = 72) is a S3C6400/10
brd: module loaded
loop: module loaded
s3c24xx-nand s3c6400-nand: Tacls=4, 30ns Twrph0=8 60ns, Twrph1=6 45ns
s3c24xx-nand s3c6400-nand: System booted from NAND
s3c24xx-nand s3c6400-nand: NAND soft ECC
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit), 256MiB, page size: 2048, OOB size: 64
Scanning device for bad blocks
Bad eraseblock 331 at 0x000002960000
Bad eraseblock 835 at 0x000006860000
Bad eraseblock 913 at 0x000007220000
Bad eraseblock 1128 at 0x000008d00000
Bad eraseblock 1787 at 0x00000df60000
Bad eraseblock 2018 at 0x00000fc40000
Creating 3 MTD partitions on "nand":
0x000000000000-0x000000100000 : "uboot"
0x000000100000-0x000000300000 : "kernel"
0x000000300000-0x000010000000 : "rootfs"
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 79, io mem 0x74300000
s3c2410-ohci s3c2410-ohci: init err (00000000 0000)
s3c2410-ohci s3c2410-ohci: can't start s3c24xx
s3c2410-ohci s3c2410-ohci: startup error -75
s3c2410-ohci s3c2410-ohci: USB bus 1 deregistered
s3c2410-ohci: probe of s3c2410-ohci failed with error -75
mousedev: PS/2 mouse device common for all mice
i2c /dev entries driver
sdhci: Secure Digital Host Controller Interface driver
sdhci: Copyright(c) Pierre Ossman
s3c-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 ADMA
s3c-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 Hz
mmc0: mmc_rescan_try_freq: trying to init card at 300000 Hz
mmc1: SDHCI controller on samsung-hsmmc [s3c-sdhci.1] using ADMA
mmc0: mmc_rescan_try_freq: trying to init card at 200000 Hz
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
VFP support v0.3: implementor 41 architecture 1 part 20 variant b rev 5
drivers/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 Hz
List of all partitions:
No filesystem could mount root, tried: ext3 ext2 cramfs romfs
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(1,0)
[] (unwind_backtrace+0x0/0xf4) from [] (panic+0x8c/0x1dc)
[] (panic+0x8c/0x1dc) from [] (mount_block_root+0x28c/0x2e0)
[] (mount_block_root+0x28c/0x2e0) from [] (prepare_namespace+0x160/0x1b8)
[] (prepare_namespace+0x160/0x1b8) from [] (kernel_init+0x8/0xe4)
[] (kernel_init+0x8/0xe4) from [] (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必须一致