注意的問題總結: 1.內核參數傳遞 內核中的參數是內核提供的,在配置內核時指定,而u-boot提供的則在u-boot啟動時傳遞到內核取代內核提供的。u-boot的參數傳遞利用了三個通用寄存器R0,R1,R2。u-boot在啟動的過程中把參數放到3個寄存器中,到內核啟動時再把寄存器中的參數取出。一般我們需要通過u-boot/tools/目錄下的mkimage制作uImage,使用bootm命令進行加載,注意go命令是不傳遞內核參數的。 mkimage[-x]-A arch-O os-T type-C comp-a addr-e ep-n name-d data_file[:data_file...]image 選項: -A:set architecture to'arch'//用于指定CPU類型,比如ARM -O:set operatingsystemto'os'//用于指定操作系統,比如Linux -T:set image type to'type'//用于指定image類型,比如Kernel -C:set compression type'comp'//指定壓縮類型 -a:set load address to'addr'(hex)//指定image的載入地址 -e:set entry point to'ep'(hex)//內核的入口地址,一般為image的載入地址+0x40(信息頭的大小) -n:set image name to'name'//image在頭結構中的命名 -d:use image data from'datafile'//無頭信息的image文件名 -x:set XIP(execute in place)//設置執行位置 例如: mkimage-n'linux-2.6.30.4'-A arm-O linux-T kernel-C none-a 0x30008000-e 0x30008040-d zImage uImage.img 注意內核的加載地址是內存的起始地址+0x8000,0x40是64k的頭部,是mkimage加上去的,0x30008040是內核第一條指令所在的地址。u-boot參數鏈表在內存中的地址是0x30000100。r0的值是0,r1是u-boot傳遞過來的機器碼,r2是參數鏈表在內存中的物理地址。 修改u-boot中我們的開發板的配置文件/include/configs/TE2440II.h,增加如下宏定義,使其能向內核傳遞參數(在這里主要是console參數,否則無法在控制臺看到啟動信息): #define CONFIG_SETUP_MEMORY_TAGS #define CONFIG_INITRD_TAG #define CONFIG_CMDLINE_TAG #define CONFIG_BOOTARGS " noinitrd root=/dev/mtdblock3 init=/linuxrc mem=64M devfs=mount console=tty0 console=ttySAC0,115200" 上面的操作完成后,重新編譯u-boot,下載到nand中,重新啟動u-boot后,把我們編譯生成的uImage文件下載到內存的0x30008000地址處,就可以用bootm命令來手動引導內核了(執行bootm 0x30008000)。 2.機器碼 內核會在編譯鏈接過程中,將各種處理器內核描述符組合成表,接著從機器描述符表中查詢有無r1寄存器指定的機器碼,如果沒有就將退出,所以這也說明了為什么在u-boot中機器碼一定要和內核中的機器碼一致,否則內核就無法啟動。 先看看u-boot的機器碼和linux的機器碼是由什么地方決定的,u-boot中的機器碼在u-boot的board/samsung/TE2440II/TE2440II.c中決定。 /* arch number of SMDK2410-Board */ gd->bd->bi_arch_number = MACH_TYPE_SMDK2410; 查看u-boot/include/asm-arm/mach-type.h文件有: #define MACH_TYPE_SMDK2410 193 #define MACH_TYPE_S3C2440 362 Linux中決定機器碼的就是下面那個機器描述符。 MACHINE_START(SMDK2440,"SMDK2440") /* Maintainer: Ben Dooks <ben@fluff.org> */ .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=smdk2440_map_io, .init_machine=smdk2440_machine_init, .timer=&s3c24xx_timer, MACHINE_END 查看內核目錄下的arch/arm/tools/mach-types.h文件,有: smdk2410 ARCH_SMDK2410 SMDK2410 193 s3c2440 ARCH_S3C2440 S3C2440 362 smdk2440 MACH_SMDK2440 SMDK2440 1008 關鍵字是s3c2440,所以我們上面看到的是0x000000a8(362)。 所以,我們這里不去修改內核,而是直接修改u-boot 的 board/samsung/ok2440v3/ok2440v3.c文件,如下: /* arch number of SMDK2410-Board */ gd->bd->bi_arch_number = MACH_TYPE_S3C2440; 3. [\u@\h \W]# 進入控制臺,\u會顯示成root,\h會顯示成hostname,\w會顯示成當前路徑。 4. “Hit any key to stop autoboot:” doc/README.autoboot里說得很清楚,自動引導只有需要最基本的兩個配置:CONFIG_BOOTDELAY和CONFIG_BOOTCOMMAND: The basic autoboot configuration options are documented in the main U-Boot README. See it for details. They are: bootdelay bootcmd CONFIG_BOOTDELAY CONFIG_BOOTCOMMAND 根目錄下的Readme文件里對這幾個參數有說明: Boot Delay: CONFIG_BOOTDELAY - in seconds Delay before automatically booting the default image; set to -1 to disable autoboot. bootcmd see CONFIG_BOOTCOMMAND Autoboot Command: CONFIG_BOOTCOMMAND Only needed when CONFIG_BOOTDELAY is enabled; define a command string that is automatically executed when no character is read on the console interface within "Boot Delay" after reset. 由此,我們只需要在自已的開發板的配置文件里/include/configs/TE2440II.h #define CONFIG_BOOTDELAY 5 #define CONFIG_BOOTCOMMAND "nand read 0x30008000 0x00500000 0x00300000; bootm 0x30008000" 重新編譯u-boot,OK了,嘿嘿。 6.如果tftp出現T和#,那是tftp不斷重啟,據說是網卡還沒準備好的,所以將tftp超時的時間加大。 在net/tftp.c中,修改這句: #define TIMEOUT 200000UL /* Millisecs to timeout for lost pkt */ 7.我使用的命令 1)print或printenv可以打印出環境變量 2)setenv bootargs 'noinitrd root=/dev/mtdblock3 init=/linuxrc mem=64M devfs=mount console=tty0,ttySAC0,115200' 這樣使用setenv 可以設置環境變量 3)setenv bootargs 這樣使用setenv 直接加環境變量的名字可以刪除環境變量 4)saveenv 保存環境變量,否則復位后,上次用setenv設置的環境變量就不在了。 5)tftp 0x30008000 192.168.1.101:u-boot.bin 從IP地址為192.168.1.101的tftp服務器處下載 u-boo.bin文件到0x30008000處。 6)nand erase 0x0 0x30000 擦除0x0到0x30000范圍的nandflash 7)nand write 0x30008000 0x0 0x30000 從0x30008000將數據傳到0x0,長度為0x30000 8)nand scrub 擦除整個nandflash,先按y,再按回車 9)nand write.yaffs2 0x30008000 0x00800000 0x03c00000 寫yaffs2文件系統用的 李萬鵬 |