嵌入式学习笔记201-Linux kernel动起来

来源:互联网 发布:php 读取json对象 编辑:程序博客网 时间:2024/05/01 13:45
  1. 在前篇博文《嵌入式学习笔记200-Linux kernel初体验》在已经确保环境编译是ok的,接下来让kernel能够最基本的动起来,起码可以看到基本的启动打印!
  2. 修改外部输入时钟频率, 修改 linux-2.6.30.4\arch\arm\mach-s3c2440\mach-smdk2440.c 在大概163行将16934400改成12000000。
static void __init smdk2440_map_io(void){    s3c24xx_init_io(smdk2440_iodesc, ARRAY_SIZE(smdk2440_iodesc));    s3c24xx_init_clocks(16934400);    s3c24xx_init_uarts(smdk2440_uartcfgs, ARRAY_SIZE(smdk2440_uartcfgs));}

3.修改menuconfig配置,由于我的交叉编译是4.3.3version的,需要选择如下红色两行,如果是3.4.5的就不用,其他version的就不清楚了。
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

4.修改机器码,由于之前我们在设置uboot时,u-boot-1.1.6\board\tq2440\tq2440.c –> board_init –>gd->bd->bi_arch_number = MACH_TYPE_TQ2440; , 其中MACH_TYPE_TQ2440在include\asm-arm\mach-types.h 下#define MACH_TYPE_TQ2440 1003, 所以在linux-2.6.30.4\arch\arm\tools\mach-types 的379行改成s3c2440 ARCH_S3C2440 S3C2440 1003即可,至于是什么魔数不重要 ,只要跟uboot的一致即可,当然不能跟原有的冲突。

  1. 接着执行 make,会在 arch/arm/boot下生成 zImage,此时的镜像文件还不能给uboot识别,因为前篇博文提到uboot在调用boot_linux时会解析linux,所以要加个头部信息,在zImage目录下执行: mkimage -n ‘linux-2.6.30.4’ -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008000 -d zImage zImage.bin,会有如下打印:
    Image Name: linux-2.6.30.4
    Created: Sat May 23 16:43:06 2015
    Image Type: ARM Linux Kernel Image (uncompressed)
    Data Size: 1904596 Bytes = 1859.96 kB = 1.82 MB
    Load Address: 0x30008000
    Entry Point: 0x30008000
    各项意思是:
    -A ==> set architecture to ‘arch’
    -O ==> set operating system to ‘os’
    -T ==> set image type to ‘type’
    -C ==> set compression type ‘comp’
    -a ==> set load address to ‘addr’ (hex)
    -e ==> set entry point to ‘ep’ (hex)
    -n ==> set image name to ‘name’
    -d ==> use image data from ‘datafile’
    -x ==> set XIP (execute in place)
    我们的镜像是非加密的所以-C none,至于运行地址0x30008000 随便 只是推荐这个地方而已由于入口函数在kernel的最前面,而最前面在0x30008000 ,所以入口地址也就在0x30008000

6.烧入到nand flash,可以借助烧录器烧入或者uboot的ftp功能,这里我借助天嵌具有烧入功能的bootloader,它已经烧入在nor flash,只要将拨码开关拨到nor选项启动即可,通过选择3即可烧 zImage.bin:
这里写图片描述
首先bootloader会将code download SDRAM内存再调用nand接口写入,不过写入的地址kernel是在0x200000 size=0x300000是固定的(天嵌的bootloader code写固定的),所以到时在修改kernelnand分区时要注意到这点,如果你是用烧录器的话那地址你可以自己定。最后将拨码卡开关拨到nand flash启动即可,当然前提是你有烧入好uboot并且支持启动linux。
前面的博文都是借由这一方式的,相信读者并不陌生。
如果事先有uboot的会有如下打印:

U-Boot 1.1.6 (May 23 2015 - 16:37:20)DRAM:  64 MBFlash:  2 MBNAND:  256 MiB*** Warning - bad CRC or NAND, using default environmentIn:    serialOut:   serialErr:   serialHit any key to stop autoboot:  0 NAND read: device 0 offset 0x200000, size 0x300000 3145728 bytes read: OK## Booting image at 32000000 ...   Image Name:   linux-2.6.30.4   Created:      2015-05-23   8:43:06 UTC   Image Type:   ARM Linux Kernel Image (uncompressed)   Data Size:    1904596 Bytes =  1.8 MB   Load Address: 30008000   Entry Point:  30008000   Verifying Checksum ... OKOKStarting kernel ...Uncompressing Linux........................................................................................................................ done, booting the kernel.Linux version 2.6.30.4 (vedic@vedic-VirtualBox) (gcc version 4.3.3 (Sourcery G++ Lite 2009q1-176) ) #1 Sat May 23 16:09:48 HKT 2015CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177CPU: VIVT data cache, VIVT instruction cacheMachine: SMDK2440Memory policy: ECC disabled, Data cache writebackCPU S3C2440A (id 0x32440001)S3C24XX Clocks, (c) 2004 Simtec ElectronicsS3C244X: core 400.000 MHz, memory 100.000 MHz, peripheral 50.000 MHzCLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL onBuilt 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256Kernel command line: noinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySAC0NR_IRQS:85irq: clearing subpending status 00000002PID hash table entries: 256 (order: 8, 1024 bytes)Console: colour dummy device 80x30console [ttySAC0] enabledDentry cache hash table entries: 8192 (order: 3, 32768 bytes)Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)Memory: 64MB = 64MB totalMemory: 60944KB available (3384K code, 311K data, 120K init, 0K highmem)Calibrating delay loop... 199.47 BogoMIPS (lpj=498688)Mount-cache hash table entries: 512CPU: Testing write buffer coherency: oknet_namespace: 936 bytesNET: Registered protocol family 16S3C Power Management, Copyright 2004 Simtec ElectronicsS3C2440: Initialising architectureS3C2440: IRQ SupportS3C24XX DMA Driver, (c) 2003-2004,2006 Simtec ElectronicsDMA channel 0 at c4808000, irq 33DMA channel 1 at c4808040, irq 34DMA channel 2 at c4808080, irq 35DMA channel 3 at c48080c0, irq 36S3C244X: Clock Support, DVS offbio: create slab <bio-0> at 0SCSI subsystem initializedusbcore: registered new interface driver usbfsusbcore: registered new interface driver hubusbcore: registered new device driver usbs3c2440-i2c s3c2440-i2c: slave address 0x10s3c2440-i2c s3c2440-i2c: bus frequency set to 97 KHzs3c2440-i2c s3c2440-i2c: i2c-0: S3C I2C adapterNET: Registered protocol family 2IP 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 registeredNET: Registered protocol family 1NetWinder Floating Point Emulator V0.97 (extended precision)JFFS2 version 2.2. (NAND) (SUMMARY)  ?? 2001-2006 Red Hat, Inc.ROMFS MTD (C) 2007 Red Hat, Inc.msgmni has been set to 119io scheduler noop registeredio scheduler anticipatory registered (default)io scheduler deadline registeredio scheduler cfq registeredConsole: switching to colour frame buffer device 30x40fb0: s3c2410fb frame buffer devicelp: driver loaded but no devices foundppdev: user-space parallel port driverSerial: 8250/16550 driver, 4 ports, IRQ sharing enableds3c2440-uart.0: s3c2410_serial0 at MMIO 0x50000000 (irq = 70) is a S3C2440s3c2440-uart.1: s3c2410_serial1 at MMIO 0x50004000 (irq = 73) is a S3C2440s3c2440-uart.2: s3c2410_serial2 at MMIO 0x50008000 (irq = 76) is a S3C2440brd: module loadedloop: module loadedUniform Multi-Platform E-IDE driveride-gd driver 1.18ide-cd driver 5.00Driver 'sd' needs updating - please use bus_type methodsdm9000 Ethernet Driver, V1.31S3C24XX NAND Driver, (c) 2004 Simtec Electronicss3c2440-nand s3c2440-nand: Tacls=3, 30ns Twrph0=7 70ns, Twrph1=3 30nsNAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)Scanning device for bad blocksBad eraseblock 1153 at 0x000009020000Creating 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-only0x000000000000-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 availableohci_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 42, io mem 0x49000000usb usb1: configuration #1 chosen from 1 choicehub 1-0:1.0: USB hub foundhub 1-0:1.0: 2 ports detectedusbcore: registered new interface driver libusualusbcore: registered new interface driver usbserialUSB Serial support registered for genericusbcore: registered new interface driver usbserial_genericusbserial: USB Serial Driver coreUSB Serial support registered for FTDI USB Serial Deviceusbcore: registered new interface driver ftdi_sioftdi_sio: v1.4.3:USB FTDI Serial Converters DriverUSB Serial support registered for pl2303usbcore: registered new interface driver pl2303pl2303: Prolific PL2303 USB to serial adaptor drivermice: PS/2 mouse device common for all miceS3C24XX RTC, (c) 2004,2006 Simtec ElectronicsS3C2410 Watchdog Timer, (c) 2004 Simtec Electronicss3c2410-wdt s3c2410-wdt: watchdog inactive, reset disabled, irq enabledAdvanced Linux Sound Architecture Driver Version 1.0.20.ALSA device list:  No soundcards found.TCP cubic registeredNET: Registered protocol family 17RPC: Registered udp transport module.RPC: Registered tcp transport module.drivers/rtc/hctosys.c: unable to open rtc device (rtc0)List of all 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?)No filesystem could mount root, tried:  ext3 ext2 cramfs vfat msdos iso9660 romfsKernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,2)[<c002c700>] (unwind_backtrace+0x0/0xdc) from [<c02a6d24>] (panic+0x40/0x110)[<c02a6d24>] (panic+0x40/0x110) from [<c0008fcc>] (mount_block_root+0x1d0/0x210)[<c0008fcc>] (mount_block_root+0x1d0/0x210) from [<c0009264>] (prepare_namespace+0x164/0x1bc)[<c0009264>] (prepare_namespace+0x164/0x1bc) from [<c0008598>] (kernel_init+0xb4/0xe0)[<c0008598>] (kernel_init+0xb4/0xe0) from [<c004814c>] (do_exit+0x0/0x578)[<c004814c>] (do_exit+0x0/0x578) from [<00000001>] (0x1)

由于还没有烧入文件系统且kernel设置的分区也不正确,所以跑到fs就挂住了,可参考后篇博文关于搭建文件系统 《嵌入式学习笔记300-linux根文件系统搭建》

0 0
原创粉丝点击