以前一直都是只移过u-boot没有移过linux,这次尝试下。
现在能够启动的是barebox,我现在准备先做的事情是在天嵌科技提供的u-boot的基础上,启动linux内核。
一、关于机器码
u-boot在启动linux内核的时候,会传过去3个参数,r0,r1,r2.分别是
r0=0
r1=平台编号
r2=参数地址
内核在启动时,是通过bootloader传入的机器码(MACH_TYPE)确定应启动哪种目标平台的,
在u-boot的(board/embedsky/XXXX.c)会对机器码进行设置:
gd->bd->bi_arch_number = MACH_TYPE_S3C2440;
还有启动参数:
gd->bd->bi_boot_params = 0x30000100;
Linux中arch/arm/tools/mach_types中有机器码定义,linux内核启动的时候,在haed.s中会去查找机器码,看是否支持。
Linux中的机器码是用下面两个宏定义的:
MACHINE_START()
MACHINE_END
EmbedSky中u-boot中机器码使用的是MACH_TYPE_S3C2440=168
存放参数的地址是0x30000100
Linux中定义的
MACHINE_START(S3C2440, "TQ2440")
.phys_io = S3C2410_PA_UART,
.io_pg_offst = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
.boot_params = S3C2410_SDRAM_PA + 0x100, 这个得和u-boot传进来的参数匹配
.init_irq = s3c24xx_init_irq,
.map_io = tq2440_map_io,
.init_machine = tq2440_machine_init,
.timer = &s3c24xx_timer,
MACHINE_END
在make menuconfig时,有菜单可以选择,其中的System Type中可以选择开发板,
可以看到有添加的EmbedSky选项了,当我们需要添加自己的开发板时,修改arch/arm/ mach-s3c2440/Kconfig文件
在arch/arm/plat-s3c24xx/Kconfig中有配置选项,
arch/arm/plat-s3c24xx/Makefile:48:
obj-$(CONFIG_MACH_EMBEDSKY) += common-EmbedSky.o
如何添加自己的开发板
当我们需要添加自己的开发板时,我们首先在arch/arm/mach-s3c2440/Kconfig中添加配置选项
查看Kconfig看看SMDK2440的菜单配置情况(arch/arm/mach-s3c2440)
1. 修改时钟
arch/arm/mach-s3c2440/mach-smdk2440.c”文件的大概162行或163行,把16.9344MHz改为12MHz,
2. 修改机器码
机器码保存在内核源码的“arch/arm/tools/mach-types”文件中,在大概379行,把原来的362改为168保存即可
3. 编译内核
Make zImage
4. 下载内核
到此处讲下分布,将zImage下载到nand的0x00200000处了,u-boot在启动的时候,从nand中读取内核到0x30008000处
setup_linux_param(boot_mem_base + LINUX_PARAM_OFFSET); 0x30000100
这是设置内核参数地址
5. 把镜像存放到指定位置
添加自己的的设备
1. 在arch/arm/mach-s3c2440/Kconfig文件中仿照ARCH_S3C2440添加如下语句:
2. 搜索关键字ARCH_S3C2440
所以添加了Kconfig选项后,得在Makefile中添加选项,在目录下添加文件
修改Makefile文件天剑语句:
cp mach-s3c2440.c mach-my2440.c
3. 搜索关键字MACH_SMDK
在arch/arm/plat-s3c24xx/目录下的Kconfig和Makefile文件中用到,修改
“arch/arm/plat-s3c24xx/common-smdk.c”为“common-zhuanxu.c”,复制“arch/arm/plat-s3c24xx/include/plat/common-smdk.h”为“common- zhuanxu.h”。
修改文件common-zhuanxu.c和mach-my2440.c包含的头文件
此时再次编译的选择新的平台就可以编译成功了。
在arch/arm/Kconfig文件中
以上修改的情况下内核无法启动,什么原因呢??
后来发现问题了,是没有修改arch/arm/tools/mach-types文件,修改里面的文件,将里面修改如下:
现在分析下为什么?
因为很多部分通过ARCH_S3C2440会产生mach-types.h文件,所以当们修改了Kconfig文件,此时就会选中ARCH_MY2440,而不是ARCH_S3C2440,就不会产生mach-types.h中的语句了。
#ifdef CONFIG_ARCH_S3C2440
# ifdef machine_arch_type
# undef machine_arch_type
# define machine_arch_type __machine_arch_type
# else
# define machine_arch_type MACH_TYPE_S3C2440
# endif
# define machine_is_s3c2440() (machine_arch_type == MACH_TYPE_S3C2440)
#else
# define machine_is_s3c2440() (0)
#endif
现在第二中修改方法:
修改arch/arm/mach-s3c2440/Kconfig
晶振的配置问题:
当配置为12M的时候,会选择PLL_12M这个选项
然后会去编译对应的PLL文件。
下面是第一次下载内核后出现的打印信息
Booting Linux ...
Copy linux kernel from 0x00200000 to 0x30008000, size = 0x00300000 ... Copy Kernel to SDRAM done,NOW, Booting Linux......
Uncompressing Linux.............................................................................................................. done, booting the kernel.
Linux version 2.6.32.2-zhuanxu (zhuanxu@zhuanxu-desktop) (gcc version 4.3.3 (Sourcery G++ Lite 2009q1-176) ) #2 PREEMPT Sun Jun 10 12:23:15 CST 2012
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: SMDK2440
ATAG_INITRD is deprecated; please update your bootloader.
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XX Clocks, (c) 2004 Simtec Electronics
S3C244X: core 400.000 MHz, memory 100.000 MHz, peripheral 50.000 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=ttySAC0 root=/dev/nfs nfsroot=10.42.0.21:/work/nfs_root/fs_mini ip=10.42.0.11:10.42.0.21:10.42.0.11:255.255.255.0:SKY2440.embedsky.net:eth0:off
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: 61236KB available (3088K code, 353K data, 100K init, 0K highmem)
SLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
Hierarchical RCU implementation.
NR_IRQS:85
irq: clearing pending ext status 00080000
irq: clearing subpending status 00000002
Console: colour dummy device 80x30
console [ttySAC0] enabled
Calibrating delay loop... 199.47 BogoMIPS (lpj=498688)
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
devtmpfs: initialized
NET: Registered protocol family 16
S3C2440: Initialising architecture
S3C2440: IRQ Support
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics
DMA channel 0 at c4808000, irq 33
DMA channel 1 at c4808040, irq 34
DMA channel 2 at c4808080, irq 35
DMA channel 3 at c48080c0, irq 36
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
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
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
JFFS2 version 2.2. (NAND) (SUMMARY) © 2001-2006 Red Hat, Inc.
JFFS2: default compression mode: priority
msgmni has been set to 119
alg: No test for stdrng (krng)
io scheduler noop registered (default)
Console: switching to colour frame buffer device 30x40
fb0: s3c2410fb frame buffer device
Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
s3c2440-uart.0: s3c2410_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440-uart.1: s3c2410_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440-uart.2: s3c2410_serial2 at MMIO 0x50008000 (irq = 76) is a S3C2440
loop: module loaded
S3C24XX NAND Driver, (c) 2004 Simtec Electronics
s3c24xx-nand s3c2440-nand: Tacls=2, 20ns Twrph0=6 60ns, Twrph1=2 20ns
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 217 at 0x000001b20000
Bad eraseblock 282 at 0x000002340000
Bad eraseblock 1089 at 0x000008820000
Bad eraseblock 1232 at 0x000009a00000
Bad eraseblock 1335 at 0x00000a6e0000
Bad eraseblock 1602 at 0x00000c840000
Creating 8 MTD partitions on "NAND 256MiB 3,3V 8-bit":
0x000000000000-0x000000004000 : "Boot Agent"
mtd: partition "Boot Agent" doesn't end on an erase block -- force read-only
0x000000000000-0x000000200000 : "S3C2410 flash partition 1"
0x000000400000-0x000000800000 : "S3C2410 flash partition 2"
0x000000800000-0x000000a00000 : "S3C2410 flash partition 3"
0x000000a00000-0x000000e00000 : "S3C2410 flash partition 4"
0x000000e00000-0x000001800000 : "S3C2410 flash partition 5"
0x000001800000-0x000003000000 : "S3C2410 flash partition 6"
0x000003000000-0x000004000000 : "S3C2410 flash partition 7"
usbmon: debugfs is not available
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
usb usb1: configuration #1 chosen from 1 choice
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
usbcore: registered new interface driver libusual
usbcore: registered new interface driver usbserial
USB Serial support registered for generic
usbcore: registered new interface driver usbserial_generic
usbserial: USB Serial Driver core
USB Serial support registered for FTDI USB Serial Device
usbcore: registered new interface driver ftdi_sio
ftdi_sio: v1.5.0:USB FTDI Serial Converters Driver
USB Serial support registered for pl2303
usbcore: registered new interface driver pl2303
pl2303: Prolific PL2303 USB to serial adaptor driver
mice: PS/2 mouse device common for all mice
S3C24XX RTC, (c) 2004,2006 Simtec Electronics
S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics
s3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabled
TCP cubic registered
drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
IP-Config: Device `eth0' not found.
Looking up port of RPC 100003/2 on 10.42.0.21
rpcbind: server 10.42.0.21 not responding, timed out
Root-NFS: Unable to get nfsd port number from server, using default
Looking up port of RPC 100005/1 on 10.42.0.21
rpcbind: server 10.42.0.21 not responding, timed out
Root-NFS: Unable to get mountd port number from server, using default
Root-NFS: Server returned error -5 while mounting /work/nfs_root/fs_mini
VFS: Unable to mount root fs via NFS, trying floppy.
VFS: Cannot open root device "nfs" 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 16384 mtdblock7 (driver?)
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)
[<c0027b3c>] (unwind_backtrace+0x0/0xe8) from [<c02522b0>] (panic+0x4c/0x134)
[<c02522b0>] (panic+0x4c/0x134) from [<c0008f20>] (mount_block_root+0x16c/0x224)
[<c0008f20>] (mount_block_root+0x16c/0x224) from [<c00091bc>] (prepare_namespace+0xf8/0x190)
[<c00091bc>] (prepare_namespace+0xf8/0x190) from [<c00085d8>] (kernel_init+0xec/0x120)
[<c00085d8>] (kernel_init+0xec/0x120) from [<c0022a90>] (kernel_thread_exit+0x0/0x8)