实验一 移植U-Boot 1.3.1
【实验内容】
移植U-Boot 1.3.1到FS2410开发平台上。 【实验目的】
掌握FS2410的硬件资源。
掌握U-BOOT的目录树和移植方法。 掌握U-BOOT的调试方法。 【实验平台】
优龙FS2410(ARM920T) U-Boot版本:1.3.1 【实验步骤】
1. 了解U-boot的目录结构。参看图1.1 目录 board common cpu driver doc
examples include lib_xxx net post rtc tools
内容
目标板相关文件,主要包含SDRAM、FLASH驱动
于处理器体系结构的通用代码,如内存大小探测与故障检测 与处理器相关的文件
通用设备驱动,如CFI FLASH驱动 U-Boot的说明文档
可在U-Boot下运行的示例程序;如hello_world.c,timer.c 头文件;configs目录下存放与目标板相关的配置头文件 处理器体系相关的文件
与网络功能相关的文件目录 上电自检文件目录 RTC驱动程序
用于创建U-Boot S-RECORD和BIN镜像文件的工具
图1.1 U-BOOT目录树
2. 建立自己的开发板类型
首先在/home/linux目录下建立自己的工作目录。
#mkdir /home/linux
2.2进入U-Boot源码目录。
#cd u-boot-1.3.1
2.3创建自己的开发板.
#cd board
#cp smdk2410 fs2410 –a #cd fs2410
#mv smdk2410.c fs2410/fs2410.c
#vi Makefile (将smdk2410修改为fs2410) #cd ../../include/configs #cp smdk2410.h fs2410.h
华清远见—嵌入式培训专家 移植实验
退回U-Boot根目录:#cd ../../
3.建立编译选项 #vi Makefile
3.1具体的修改代码如下:
把 smdk2410_config : unconfig
@$(MKCONFIG) $(@:_config=) arm arm920t smdk2410 NULL s3c24x0 修改为
fs2410_config : unconfig
@$(MKCONFIG) $(@:_config=) arm arm920t fs2410 NULL s3c24x0
3.2 具体的详解注释
arm: CPU的架构(ARCH)
arm920t: CPU的类型(CPU),其对应于cpu/arm920t子目录。 fs2410: 开发板的型号(BOARD),对应于board/fs2410目录。 NULL: 开发者/或经销商(vender),本例为空 s3c24x0: 片上系统(SOC)
4. 编译
#make fs2410_config #make
5.实验结果
本步骤将编译u-boot.bin文件,但是无法运行在fs2410开发板上。
6. 修改cpu/arm920t/start.S文件,完成U-Boot的重定向
修改中断禁止部分
# if defined(CONFIG_S3C2410)
ldr r1, =0x7ff /*根据2410芯片手册,INTSUBMSK有11位可用 */
ldr r0, =INTSUBMSK str r1, [r0]
# endif
修改时钟设置(本开发板不用修改) 将从Flash启动改成从NAND Flash启动
在文件中找到用//括起来的代码,并在这些代码下添加如下用*括起来的
代码:
////////////////////////////////////////////////////////////////////
copy_loop:
ldmia {r3-r10} /* copy from source address [r0] */ stmia {r3-r10} /* copy to target address [r1] */ cmp r0, r2 /* until source end addreee [r2] */
ble copy_loop
华清远见—嵌入式培训专家 移植实验
#endif /* CONFIG_SKIP_RELOCATE_UBOOT */
///////////////////////////////////////////////////////////////////// **************************************************
#ifdef CONFIG_S3C2410_NAND_BOOT
@ reset NAND
mov r1, #NAND_CTL_BASE
ldr r2, =0xf830 @ initial value
str r2, [r1, #oNFCONF] ldr r2, [r1, #oNFCONF]
bic r2, r2, #0x800 @ enable chip
str r2, [r1, #oNFCONF] mov r2, #0xff @ RESET command
strb r2, [r1, #oNFCMD] mov r3, #0 @ wait
nand1:
add r3, r3, #0x1 cmp r3, #0xa blt nand1 nand2:
ldr r2, [r1, #oNFSTAT] @ wait ready
tst r2, #0x1 beq nand2
ldr r2, [r1, #oNFCONF]
orr r2, r2, #0x800 @ disable chip
str r2, [r1, #oNFCONF]
@ get read to call C functions (for nand_read())
ldr sp, DW_STACK_START @ setup stack pointer mov fp, #0 @ no previous frame, so fp=0
@ copy U-Boot to RAM ldr r0, =TEXT_BASE mov r1, #0x0 mov r2, #0x30000 bl nand_read_ll tst r0, #0x0 beq ok_nand_read bad_nand_read: loop2:
b loop2 @ infinite loop
ok_nand_read: @ verify mov r0, #0 ldr r1, =TEXT_BASE
华清远见—嵌入式培训专家 移植实验
mov r2, #0x400 @ 4 bytes * 1024 = 4K-bytes
go_next:
ldr r3, [r0], #4 ldr r4, [r1], #4 teq r3, r4 bne notmatch subs r2, r2, #4 beq stack_setup bne go_next notmatch:
loop3: b loop3 @ infinite loop #endif @ CONFIG_S3C2410_NAND_BOOT
********************************************************* 在 “ _start_armboot: .word start_armboot ”后加入:
.align 2
DW_STACK_START: .word STACK_BASE+STACK_SIZE-4
7.修改board/fs2410/lowlevel_init.S文件,设置内存控制器
在移植过程中,往往需要依照开发板的内存区的配置情况,对内存进行设置。参考S3C2410手册可理解该文件内容。参考代码如下: #define BWSCON 0x48000000 #define PLD_BASE 0x2C000000 #define SDRAM_REG 0x2C000106
/* BWSCON */ #define DW8 #define DW16 #define DW32 #define WAIT #define UBLB
/* BANKSIZE */ #define BURST_EN
#define B1_BWSCON #define B2_BWSCON #define B3_BWSCON #define B4_BWSCON #define B5_BWSCON #define B6_BWSCON #define B7_BWSCON
/* BANK0CON */
(DW16 + WAIT) (DW32) (DW32)
(DW16 + WAIT + UBLB) (DW8 + UBLB) (DW32) (DW32)
(0x1<<7)
(0x0) (0x1) (0x2) (0x1<<2) (0x1<<3)
华清远见—嵌入式培训专家 移植实验
#define B0_Tacs #define B0_Tcos /*#define B0_Tcos #define B0_Tacc /*#define B0_Tacc #define B0_Tcoh #define B0_Tah #define B0_Tacp #define B0_PMC
/* BANK1CON */ #define B1_Tacs #define B1_Tcos /*#define B1_Tcos #define B1_Tacc /*#define B1_Tacc #define B1_Tcoh #define B1_Tah #define B1_Tacp #define B1_PMC
#define B2_Tacs #define B2_Tcos #define B2_Tacc #define B2_Tcoh #define B2_Tah #define B2_Tacp #define B2_PMC
#define B3_Tacs #define B3_Tcos #define B3_Tacc #define B3_Tcoh #define B3_Tah #define B3_Tacp #define B3_PMC
#define B4_Tacs #define B4_Tcos #define B4_Tacc #define B4_Tcoh #define B4_Tah #define B4_Tacp #define B4_PMC
0x0 /* 0clk */ 0x1 /* 1clk */ 0x0 0clk */ 0x7 /* 14clk */ 0x5 8clk */ 0x0 /* 0clk */ 0x0 /* 0clk */
0x0 /* page mode is not used */ 0x0 /* page mode disabled */
0x0 /* 0clk */ 0x1 /* 1clk */ 0x0 0clk */ 0x7 /* 14clk */ 0x5 8clk */ 0x0 /* 0clk */ 0x0 /* 0clk */
0x0 /* page mode is not used */ 0x0 /* page mode disabled */ 0x3 /* 4clk */ 0x3 /* 4clk */ 0x7 /* 14clk */ 0x3 /* 4clk */ 0x3 /* 4clk */
0x0 /* page mode is not used */ 0x0 /* page mode disabled */ 0x3 /* 4clk */ 0x3 /* 4clk */ 0x7 /* 14clk */ 0x3 /* 4clk */ 0x3 /* 4clk */
0x0 /* page mode is not used */ 0x0 /* page mode disabled */ 0x3 /* 4clk */ 0x1 /* 1clk */ 0x7 /* 14clk */ 0x1 /* 1clk */ 0x0 /* 0clk */
0x0 /* page mode is not used */ 0x0 /* page mode disabled */ 华清远见—嵌入式培训专家 移植实验
#define B5_Tacs #define B5_Tcos #define B5_Tacc #define B5_Tcoh #define B5_Tah #define B5_Tacp #define B5_PMC
#define B6_MT 0x3 /* SDRAM */ #define B6_Trcd 0x1 /* 3clk */ #define B6_SCAN 0x2 /* 10bit */
#define B7_MT #define B7_Trcd #define B7_SCAN
/* REFRESH parameter */
#define REFEN 0x1 /* Refresh enable */
#define TREFMD 0x0 /* CBR(CAS before RAS)/Auto refresh */ #define Trp 0x0 /* 2clk */ #define Trc 0x3 /* 7clk */ #define Tchr 0x2 /* 3clk */ #define REFCNT 1113 /* period=15.6us, HCLK=60Mhz, (2048+1-15.6*60) */ ......
.word ((B6_MT<<15)+(B6_Trcd<<2)+(B6_SCAN)) .word ((B7_MT<<15)+(B7_Trcd<<2)+(B7_SCAN))
.word ((REFEN<<23)+(TREFMD<<22)+(Trp<<20)+(Trc<<18)+(Tchr<<16)+REFCNT) .word 0x32 .word 0x30
.word 0x30
8.修改board/fs2410/里的文件,加入NAND Flash操作 1) 从vivi代码中提取nand_read.c文件,在board/fs/目录下面建立nand_read.c文件,
代码如下: #include #define __REGb(x) (*(volatile unsigned char *)(x)) #define __REGi(x) (*(volatile unsigned int *)(x)) #define NF_BASE 0x4e000000 # if defined(CONFIG_S3C2410) 0x3 /* SDRAM */ 0x1 /* 3clk */ 0x2 /* 10bit */ 0x0 /* 0clk */ 0x3 /* 4clk */ 0x5 /* 8clk */ 0x2 /* 2clk */ 0x1 /* 1clk */ 0x0 /* page mode is not used */ 0x0 /* page mode disabled */ 华清远见—嵌入式培训专家 移植实验 #define NFCONF __REGi(NF_BASE + 0x0) #define NFCMD __REGb(NF_BASE + 0x4) #define NFADDR __REGb(NF_BASE + 0x8) #define NFDATA __REGb(NF_BASE + 0xc) #define NFSTAT __REGb(NF_BASE + 0x10) #define BUSY 1 inline void wait_idle(void) { int i; while(!(NFSTAT & BUSY)) for(i=0; i<10; i++); } /* low level nand read function */ int nand_read_ll(unsigned char *buf, unsigned long start_addr, int size) { int i, j; if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)) { return -1; /* invalid alignment */ } /* chip Enable */ NFCONF &= ~0x800; for(i=0; i<10; i++); for(i=start_addr; i < (start_addr + size);) { /* READ0 */ NFCMD = 0; /* Write Address */ NFADDR = i & 0xff; NFADDR = (i >> 9) & 0xff; NFADDR = (i >> 17) & 0xff; NFADDR = (i >> 25) & 0xff; wait_idle(); for(j=0; j < NAND_SECTOR_SIZE; j++, i++) { *buf = (NFDATA & 0xff); buf++; } } /* chip Disable */ NFCONF |= 0x800; /* chip disable */ return 0; } # endif 2)并修改board/fs2410/目录下面的Makefile文件。添加对nand_read.c文件的编译,具体如下: 把OBJS := smdk2410.o flash.o 改为OBJS := smdk2410.o flash.o nand_read.o 华清远见—嵌入式培训专家 移植实验 3)在board/fs2410/fs2410.c里加入Nand Flash的初始化函数 在文件的最后加入Nand Flash的初始化函数,该函数在后面Nand Flash的操作都要用到。u-boot运行到第2阶段会进入start_armboot()函数。其中nand_init()函数是对nand flash的最初初始化函数。Nand_init()函数在两个文件中实现。其调用与CFG_NAND_LEGACY宏有关,如果没有定义这个宏,系统调用 drivers/nand/nand.c中的nand_init();否则调用自己在本文件中的nand_init()函数,本例使用后者。代码如下: #if defined(CONFIG_CMD_NAND) typedef enum { NFCE_LOW, NFCE_HIGH } NFCE_STATE; static inline void NF_Conf(u16 conf) { S3C2410_NAND * const nand = S3C2410_GetBase_NAND(); nand->NFCONF = conf; } static inline void NF_Cmd(u8 cmd) { S3C2410_NAND * const nand = S3C2410_GetBase_NAND(); nand->NFCMD = cmd; } static inline void NF_CmdW(u8 cmd) { NF_Cmd(cmd); udelay(1); } static inline void NF_Addr(u8 addr) { S3C2410_NAND * const nand = S3C2410_GetBase_NAND(); nand->NFADDR = addr; } static inline void NF_WaitRB(void) { S3C2410_NAND * const nand = S3C2410_GetBase_NAND(); while (!(nand->NFSTAT & (1<<0))); } static inline void NF_Write(u8 data) { S3C2410_NAND * const nand = S3C2410_GetBase_NAND(); nand->NFDATA = data; } 华清远见—嵌入式培训专家 移植实验 static inline u8 NF_Read(void) { S3C2410_NAND * const nand = S3C2410_GetBase_NAND(); return(nand->NFDATA); } static inline u32 NF_Read_ECC(void) { S3C2410_NAND * const nand = S3C2410_GetBase_NAND(); return(nand->NFECC); } static inline void NF_Cont(u16 cont) { S3C2410_NAND * const nand = S3C2410_GetBase_NAND(); nand->NFCONT = cont; } static inline void NF_SetCE(NFCE_STATE s) { S3C2410_NAND * const nand = S3C2410_GetBase_NAND(); switch (s) { case NFCE_LOW: nand->NFCONF &= ~(1<<11); break; case NFCE_HIGH: nand->NFCONF |= (1<<11); break; } } static inline void NF_Init_ECC(void) { S3C2410_NAND * const nand = S3C2410_GetBase_NAND(); nand->NFCONF |= (1<<12); } extern ulong nand_probe(ulong physadr); static inline void NF_Reset(void) { int i; NF_SetCE(NFCE_LOW); NF_Cmd(0xFF); /* reset command */ for(i = 0; i < 10; i++); /* tWB = 100ns. */ NF_WaitRB(); /* wait 200~500us; */ NF_SetCE(NFCE_HIGH); } static inline void NF_Init(void) { 华清远见—嵌入式培训专家 移植实验 #if 0 #define TACLS 0 #define TWRPH0 3 #define TWRPH1 0 #else #define TACLS 0 #define TWRPH0 4 #define TWRPH1 2 #endif #if defined(CONFIG_S3C2440) NF_Conf((TACLS<<12)|(TWRPH0<<8)|(TWRPH1<<4)); NF_Cont((1<<6)|(1<<4)|(1<<1)|(1<<0)); #else NF_Conf((1<<15)|(0<<14)|(0<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0)); /*nand->NFCONF = (1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0); */ /* 1 1 1 1, 1 xxx, r xxx, r xxx */ /* En 512B 4step ECCR nFCE=H tACLS tWRPH0 tWRPH1 */ #endif NF_Reset(); } void nand_init(void) { S3C2410_NAND * const nand = S3C2410_GetBase_NAND(); NF_Init(); #ifdef DEBUG printf(\"NAND flash probing at 0x%.8lX\\n\#endif printf (\"%4lu MB\\n\} 4)配置GPIO和PLL 根据开发板的硬件说明和芯片手册,修改GPIO和PLL的配置。参考代码如下: gpio->GPACON = 0x007FFFFF; -> gpio->GPACON = 0x007FFFFF; gpio->GPBCON = 0x00044555; -> gpio->GPBCON = 0x002AAAAA; gpio->GPBUP = 0x000007FF; -> gpio->GPBUP = 0x000002BF; gpio->GPCCON = 0xAAAAAAAA; -> gpio->GPCCON = 0xAAAAAAAA; gpio->GPCUP = 0x0000FFFF; -> gpio->GPCUP = 0x0000FFFF; gpio->GPDCON = 0xAAAAAAAA; -> gpio->GPDCON = 0xAAAAAAAA; gpio->GPDUP = 0x0000FFFF; -> gpio->GPDUP = 0x0000FFFF; 华清远见—嵌入式培训专家 移植实验 gpio->GPECON = 0xAAAAAAAA; -> gpio->GPECON = 0xAAAAAAAA; gpio->GPEUP = 0x0000FFFF; -> gpio->GPEUP = 0x000037F7; gpio->GPFCON = 0x000055AA; -> gpio->GPFCON = 0x00000000; gpio->GPFUP = 0x000000FF; -> gpio->GPFUP = 0x00000000; gpio->GPGCON = 0xFF95FFBA; -> gpio->GPGCON = 0xFFEAFF5A; gpio->GPGUP = 0x0000FFFF; -> gpio->GPGUP = 0x0000F0DC; gpio->GPHCON = 0x002AFAAA; -> gpio->GPHCON = 0x0018AAAA; gpio->GPHUP = 0x000007FF; -> gpio->GPHUP = 0x00000656; gpio->GPHDAT = 0x000001FF; 9.修改include/configs/fs2410.h头文件 1)加入命令定义(Line 39) /* Command line configuration. */ #include 把#define CFG_PROMPT \"SMDK2410 # \" 修改为#define CFG_PROMPT \"FS2410\" 3) 修改默认载入地址(Line 125) 把#define CFG_LOAD_ADDR 0x33000000 修改为#define CFG_LOAD_ADDR 0x30008000 4) 加入Flash环境信息(在Line 181前) #define CFG_ENV_IS_IN_NAND 1 #define CFG_ENV_OFFSET 0X30000 #define CFG_NAND_LEGACY //#define CFG_ENV_IS_IN_FLASH 1 #define CFG_ENV_SIZE 0x10000 /* Total Size of Environment Sector */ 5)加入Nand Flash设置(在文件结尾处) /* NAND flash settings */ #if defined(CONFIG_CMD_NAND) #define CFG_NAND_BASE 0x4E000000 /* NandFlash控制器在SFR区起始寄存器地址 */ #define CFG_MAX_NAND_DEVICE 1 /* 支持的最在Nand Flash数据 */ #define SECTORSIZE 512 /* 1页的大小 */ #define NAND_SECTOR_SIZE SECTORSIZE 华清远见—嵌入式培训专家 移植实验 #define NAND_BLOCK_MASK 511 /* 页掩码 */ #define ADDR_COLUMN 1 /* 一个字节的Column地址 */ #define ADDR_PAGE 3 /* 3字节的页块地址!!!!!*/ #define ADDR_COLUMN_PAGE 4 /* 总共4字节的页块地址!!!!! */ #define NAND_ChipID_UNKNOWN 0x00 /* 未知芯片的ID号 */ #define NAND_MAX_FLOORS 1 #define NAND_MAX_CHIPS 1 /* Nand Flash命令层底层接口函数 */ #define WRITE_NAND_ADDRESS(d, adr) {rNFADDR = d;} #define WRITE_NAND(d, adr) {rNFDATA = d;} #define READ_NAND(adr) (rNFDATA) #define NAND_WAIT_READY(nand) {while(!(rNFSTAT&(1<<0)));} #define WRITE_NAND_COMMAND(d, adr) {rNFCMD = d;} #define WRITE_NAND_COMMANDW(d, adr) NF_CmdW(d) #define NAND_DISABLE_CE(nand) {rNFCONF |= (1<<11);} #define NAND_ENABLE_CE(nand) {rNFCONF &= ~(1<<11);} /* the following functions are NOP's because S3C24X0 handles this in hardware */ #define NAND_CTL_CLRALE(nandptr) #define NAND_CTL_SETALE(nandptr) #define NAND_CTL_CLRCLE(nandptr) #define NAND_CTL_SETCLE(nandptr) /* 允许Nand Flash写校验 */ #define CONFIG_MTD_NAND_VERIFY_WRITE 1 6) 加入Nand Flash启动支持(在文件结尾处) /* Nandflash Boot*/ #define STACK_BASE 0x33f00000 #define STACK_SIZE 0x8000 /* NAND Flash Controller */ #define NAND_CTL_BASE 0x4E000000 #define bINT_CTL(Nb) __REG(INT_CTL_BASE + (Nb)) /* Offset */ #define oNFCONF 0x00 #define CONFIG_S3C2410_NAND_BOOT 1 /* Offset */ #define oNFCONF 0x00 #define oNFCMD 0x04 #define oNFADDR 0x08 #define oNFDATA 0x0c #define oNFSTAT 0x10 #define oNFECC 0x14 华清远见—嵌入式培训专家 移植实验 #define rNFCONF (*(volatile unsigned int *)0x4e000000) #define rNFCMD (*(volatile unsigned char *)0x4e000004) #define rNFADDR (*(volatile unsigned char *)0x4e000008) #define rNFDATA (*(volatile unsigned char *)0x4e00000c) #define rNFSTAT (*(volatile unsigned int *)0x4e000010) #define rNFECC (*(volatile unsigned int *)0x4e000014) #define rNFECC0 (*(volatile unsigned char *)0x4e000014) #define rNFECC1 (*(volatile unsigned char *)0x4e000015) #define rNFECC2 (*(volatile unsigned char *)0x4e000016) 8) 加入jffs2的支持 /*JFFS2 Support */ #undef CONFIG_JFFS2_CMDLINE #define CONFIG_JFFS2_NAND 1 #define CONFIG_JFFS2_DEV \"nand0\" #define CONFIG_JFFS2_PART_SIZE 0x4c0000 #define CONFIG_JFFS2_PART_OFFSET 0x40000 /*JFFS2 Support */ 9) 加入usb的支持 /* USB Support*/ #define CONFIG_USB_OHCI #define CONFIG_USB_STORAGE #define CONFIG_USB_KEYBOARD #define CONFIG_DOS_PARTITION #define CFG_DEVICE_DEREGISTER #define CONFIG_SUPPORT_VFAT #define LITTLEENDIAN /* USB Support*/ 10. 修改include/linux/mtd/nand.h头文件 屏蔽如下定义: #if 0 /* Select the chip by setting nCE to low */ #define NAND_CTL_SETNCE 1 /* Deselect the chip by setting nCE to high */ #define NAND_CTL_CLRNCE 2 /* Select the command latch by setting CLE to high */ #define NAND_CTL_SETCLE 3 /* Deselect the command latch by setting CLE to low */ #define NAND_CTL_CLRCLE 4 /* Select the address latch by setting ALE to high */ #define NAND_CTL_SETALE 5 /* Deselect the address latch by setting ALE to low */ #define NAND_CTL_CLRALE 6 /* Set write protection by setting WP to high. Not used! */ 华清远见—嵌入式培训专家 移植实验 #define NAND_CTL_SETWP 7 /* Clear write protection by setting WP to low. Not used! */ #define NAND_CTL_CLRWP 8 #endif 11. 修改include/linux/mtd/nand_ids.h头文件 在该文件中加入开发板的NAND Flash型号 {\"Samsung K9F1208U0B\, 0x76, 26, 0, 3, 0x4000, 0}, 12.修改common/env_nand.c文件 我们使用了早期的Nand读写方式,因此做出下列移植: 1. 加入函数原型定义 extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE]; extern int nand_legacy_erase(struct nand_chip *nand, size_t ofs, size_t len, int clean); /* info for NAND chips, defined in drivers/nand/nand.c */ Line 61: extern nand_info_t nand_info[CFG_MAX_NAND_DEVICE]; 2. 修改saveenv函数 注释Line 195 //if (nand_erase(&nand_info[0], CFG_ENV_OFFSET, CFG_ENV_SIZE)) 加入:if (nand_legacy_erase(nand_dev_desc + 0, CFG_ENV_OFFSET, CFG_ENV_SIZE, 0)) 注释Line 200 //ret = nand_write(&nand_info[0], CFG_ENV_OFFSET, &total, (u_char*)env_ptr); 加入:ret = nand_legacy_rw(nand_dev_desc + 0,0x00 | 0x02, CFG_ENV_OFFSET, CFG_ENV_SIZE, &total, (u_char*)env_ptr); 3. 修改env_relocate_spec函数 注释Line 275 //ret = nand_read(&nand_info[0], CFG_ENV_OFFSET, &total, (u_char*)env_ptr); 加入:ret = nand_legacy_rw(nand_dev_desc + 0, 0x01 | 0x02, CFG_ENV_OFFSET, CFG_ENV_SIZE, &total, (u_char*)env_ptr); 14.添加启动的设置。具体修改在common/cmd_boot.c。 14.1 首先添加头文件#include int do_go (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { #if defined(CONFIG_I386) DECLARE_GLOBAL_DATA_PTR; #endif ulong addr, rc; int rcode = 0; 华清远见—嵌入式培训专家 移植实验 ///////////////////////////////////////////////////////////////////////// char *commandline = getenv(\"bootargs\"); struct param_struct *lht_params=(struct param_struct *)0x30000100; printf(\"setup linux parameters at 0x30000100\\n\"); memset(lht_params,0,sizeof(struct param_struct)); lht_params->u1.s.page_size=4096; lht_params->u1.s.nr_pages=0x4000000>>12; memcpy(lht_params->commandline,commandline,strlen(commandline)+1); printf(\"linux command line is: \\\"%s\\\"\\n\ /////////////////////////////////////////////////////////////////////// if (argc < 2) { printf (\"Usage:\\n%s\\n\ return 1; } addr = simple_strtoul(argv[1], NULL, 16); printf (\"## Starting application at 0x%08lX ...\\n\ /* * pass address parameter as argv[0] (aka command name), * and all remaining args */ #if defined(CONFIG_I386) /* * x86 does not use a dedicated register to pass the pointer * to the global_data */ argv[0] = (char *)gd; #endif #if !defined(CONFIG_NIOS) //////////////////////////////////////////////////////////////////// __asm__( \"mov r1, #193\\n\" \"mov ip, #0\\n\" \"mcr p15, 0, ip, c13, c0, 0\\n\" /* zero PID */ \"mcr p15, 0, ip, c7, c7, 0\\n\" /* invalidate I,D caches */ \"mcr p15, 0, ip, c7, c10, 4\\n\" /* drain write buffer */ \"mcr p15, 0, ip, c8, c7, 0\\n\" /* invalidate I,D TLBs */ \"mrc p15, 0, ip, c1, c0, 0\\n\" /* get control register */ \"bic ip, ip, #0x0001\\n\" /* disable MMU */ 华清远见—嵌入式培训专家 移植实验 \"mov pc, %0\\n\" \"nop\\n\" : :\"r\"(addr) ); ////////////////////////////////////////////////////////// rc = ((ulong (*)(int, char *[]))addr) (--argc, &argv[1]); #else /* * Nios function pointers are address >> 1 */ rc = ((ulong (*)(int, char *[]))(addr>>1)) (--argc, &argv[1]); #endif if (rc != 0) rcode = 1; printf (\"## Application terminated, rc = 0x%lX\\n\ return rcode; } 其中用//括起来的代码是要添加的代码。否则在引导LINUX内核的时候会出现一个Error:a的典型错误。平台号没有正确传入内核。 14.交叉编译U-BOOT #make distclean #make fs2410_config #make CROSS_COMPILE=arm-linux- 注意交叉编译器用3.4.4的编译器进行编译。 15.下载 最后在U-BOOT-1.3.1的根目录下生成了u-boot.bin的镜像。然后下载这个镜像到flash里面去就OK!启动开发板,查看输出的结果是否正确。 16.U-BOOT-1.1.3的全部命令 ? - alias for 'help' askenv - get environment variables from stdin autoscr - run script from memory base - print or set address offset bdinfo - print Board Info structure boot - boot default, i.e., run 'bootcmd' bootd - boot default, i.e., run 'bootcmd' bootelf - Boot from an ELF image in memory bootm - boot application image from memory bootp - boot image via network using BootP/TFTP protocol bootvx - Boot vxWorks from an ELF image cmp - memory compare 华清远见—嵌入式培训专家 移植实验 coninfo - print console devices and information cp - memory copy crc32 - checksum calculation date - get/set/reset date & time dcache - enable or disable data cache dhcp - invoke DHCP client to obtain IP/boot params echo - echo args to console erase - erase FLASH memory fatinfo - print information about filesystem fatload - load binary file from a dos filesystem fatls - list files in a directory (default /) flinfo - print FLASH memory information fsinfo - print information about filesystems fsload - load binary file from a filesystem image go - start application at address 'addr' help - print online help icache - enable or disable instruction cache iminfo - print header information for application image imls - list all images found in flash itest - return true/false on integer compare loadb - load binary file over serial line (kermit mode) loads - load S-Record file over serial line loady - load binary file over serial line (ymodem mode) loop - infinite loop on address range ls - list files in a directory (default /) md - memory display mm - memory modify (auto-incrementing) mtest - simple RAM test mw - memory write (fill) nand - legacy NAND sub-system nboot - boot from NAND device nfs - boot image via network using NFS protocol nm - memory modify (constant address) ping - send ICMP ECHO_REQUEST to network host printenv - print environment variables protect - enable or disable FLASH write protection rarpboot - boot image via network using RARP/TFTP protocol reset - Perform RESET of the CPU run - run commands in an environment variable saveenv - save environment variables to persistent storage setenv - set environment variables sleep - delay execution for some time tftpboot - boot image via network using TFTP protocol usb - USB sub-system 华清远见—嵌入式培训专家 移植实验 usbboot - boot from USB device version - print monitor version 17.挂载U盘的实验 由于U-BOOT已经支持了U盘的支持,所以可以进行相应的实验。具体如下: 启动开发板,进入U-BOOT的终端。出现FS2410#提示符 FS2410#usb start --启动U盘 FS2410#fatls usb 0 --扫描U盘 FS2410# fatload usb 0 0x30008000 zImage –-从U盘下载内核镜像到 内存 FS2410#go 30008000 --启动内核 18.调试方法。U-BOOT的调试很多,一般比较常用的就是通过点灯和打印的方式。 1)点灯的方式,具体实例为:(lib_arm/board.c) 1.1.在函数start_armboot里可以添加 *(volatile u32 *)0x56000054=0xa0,有两个灯亮。 0x56000054是GPIO的一个数据寄存器地址,参看S3C2410手册。 1.3.在汇编代码里也可以进行相应的调试。例如在cpu/arm920t/start.S里添加: 在#if defined(COINFIG_S3C2410) ldr r1,=0x7ff ldr r0,=INTSUBMSK str r1,[r0] 后面添加如下调试信息,然后重新编译U-BOOT并下载到FLASH里看看调试信息是否正确。 ldr r1, =0x50 ldr r0, =0x56000054 str r1, [r0]. 这个时候2个灯全亮,2个全灭。 2) printf().同过这种方式也是很方便调试,打印调试信息。 总结:认真完成以上步骤。并理解相应的代码。
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- 7swz.com 版权所有 赣ICP备2024042798号-8
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务