平台:jz2440
作者:庄泽彬(欢迎转载,请注明作者)
说明:韦东山二期视频学习笔记
交叉编译工具:arm-linux-gcc (GCC)4.3.2
PC环境:ubuntu18.04
一、uboot的编译和烧录
下载uboot-2012-04版本的uboot进行移植,下载链接:ftp://ftp.denx.de/pub/u-boot/
编译:
1 make smdk2410_config 2 make -j4
使用oflash进行烧录,注意要烧录到norflash进行启动,不能烧录到nandflash启动:
1 sudo oflash u-boot.bin
使用没有修改的uboo2012-04版本烧录启动肯定不能启动,要进行修改,支持jz2440
二、uboot的启动流程
在进行移植之前,我们要先了解uboot的启动流程,才能快速的移植。根据编译过程,看看是那些文件先编译,在uboot启动阶段最先执行.
根据下图编译的log,和链接器脚本可知,arch/arm/cpu/arm920t/start.c 是最先执行的,并且链接地址为0。
根据start.c分析uboot主要内容如下:
2.1 set the cpu to SVC32 mode 设置为管理模式
2.2 turn off the watchdog 关闭看门狗
2.3 mask all IRQs by setting all bits in the INTMR
2.4 设置时钟比例: FCLK:HCLK:PCLK = 1:2:4
2.5 设置内存控制器
2.6 设置栈,调用board_init_f进行初始化
2.6.1 设置栈指针地址sp = 0x30000f80
2.6.2 设置gd变量
DECLARE_GLOBAL_DATA_PTR
#define DECLARE_GLOBAL_DATA_PTR register volatile gd_t *gd asm ("r8")
ffixed-r8
指定r8寄存器来存放gd变量的地址
2.7 重定位代码:
为什么要重定位代码呢?norflash的全局变量能像内存一样读,但是不能像内存一样写,从这一点出发也需要把代码进行重定位,重定位之后,还要修改代码,修改里面的变量,函数使用新的地址.
在链接的时候添加pie选项,会把地址信息存放在.rel和dynsym段中。arm-linux-ld -pie
查看链接脚本中也有这两个段:
最终的sdram内存分布如下图:
三、uboot重定位分析
3.1 从NOR Flash 把代码复制到sdram(源码:u-boot-2012.04.01archarmcpuarm920tstart.S)
1 /* Set up the stack */ 2 stack_setup: 3 mov sp, r4 4 5 adr r0, _start 6 cmp r0, r6 7 beq clear_bss /* skip relocation */ 8 mov r1, r6 /* r1 <- scratch for copy_loop */ 9 ldr r3, _bss_start_ofs 10 add r2, r0, r3 /* r2 <- source end address */ 11 12 copy_loop: 13 ldmia r0!, {r9-r10} /* copy from source address [r0] */ 14 stmia r1!, {r9-r10} /* copy to target address [r1] */ 15 cmp r0, r2 /* until source end address [r2] */ 16 blo copy_loop
3.2 程序的链接地址是0,访问全局变量、静态变量、调用函数时是基于0地址编译得到的地址,现在把程序复制到了sdram,需要修改代码,把基于0地址编译得到的地址改为新地址
1 分析"重定位之修改代码为新地址": 2 #ifndef CONFIG_SPL_BUILD 3 /* 4 * fix .rel.dyn relocations 5 */ 6 ldr r0, _TEXT_BASE /* r0 <- Text base */ 7 // r0=0, 代码基地址 8 9 sub r9, r6, r0 /* r9 <- relocation offset */ 10 // r9 = r6-r0 = 0x33f41000 - 0 = 0x33f41000 11 12 ldr r10, _dynsym_start_ofs /* r10 <- sym table ofs */ 13 // r10 = 00073608 14 15 add r10, r10, r0 /* r10 <- sym table in FLASH */ 16 // r10 = 00073608 + 0 = 00073608 17 18 ldr r2, _rel_dyn_start_ofs /* r2 <- rel dyn start ofs */ 19 // r2=0006b568 20 21 add r2, r2, r0 /* r2 <- rel dyn start in FLASH */ 22 // r2=r2+r0=0006b568 23 24 ldr r3, _rel_dyn_end_ofs /* r3 <- rel dyn end ofs */ 25 // r3=00073608 26 27 add r3, r3, r0 /* r3 <- rel dyn end in FLASH */ 28 // r3=r3+r0=00073608 29 30 fixloop: 31 ldr r0, [r2] /* r0 <- location to fix up, IN FLASH! */ 32 1. r0=[0006b568]=00000020 33 34 add r0, r0, r9 /* r0 <- location to fix up in RAM */ 35 1. r0=r0+r9=00000020 + 0x33f41000 = 0x33f41020 36 37 ldr r1, [r2, #4] 38 1. r1=[0006b568+4]=00000017 39 40 and r7, r1, #0xff 41 1. r7=r1&0xff=00000017 42 43 cmp r7, #23 /* relative fixup? */ 44 1. r7 == 23(0x17) 45 46 beq fixrel 47 cmp r7, #2 /* absolute fixup? */ 48 49 beq fixabs 50 /* ignore unknown type of fixup */ 51 b fixnext 52 fixabs: 53 /* absolute fix: set location to (offset) symbol value */ 54 mov r1, r1, LSR #4 /* r1 <- symbol index in .dynsym */ 55 56 add r1, r10, r1 /* r1 <- address of symbol in table */ 57 58 ldr r1, [r1, #4] /* r1 <- symbol value */ 59 60 add r1, r1, r9 /* r1 <- relocated sym addr */ 61 62 b fixnext 63 fixrel: 64 /* relative fix: increase location by offset */ 65 ldr r1, [r0] 66 1. r1=[00000020]=000001e0 67 68 add r1, r1, r9 69 1. r1=r1+r9=000001e0 + 0x33f41000 = 33F411E0 70 71 fixnext: 72 str r1, [r0] 73 1. [0x33f41020] = 33F411E0 74 75 add r2, r2, #8 /* each rel.dyn entry is 8 bytes */ 76 1. r2=r2+8=0006b568+8=6B570 77 78 cmp r2, r3 79 1. 80 81 blo fixloop 82 #endif
3.3 调用clear_bss
3.4 调用C函数board_init_r:第2阶段的代码
四、修改uboot代码--新建单板、修改系统时钟、串口
4.1 新建新的单板
4.2修改系统时钟、支持串口显示:
uboot代码里先以60Mhz时钟计算参数来设置内存控制器,但是还没有设置MPLL
cpu_init_crit
| |
| lowlevel_init 对内存的初始化,要求HCLK=60Mhz,但是时钟的设置在初始化内存之后,这部分代码有问题需要调整
|
board_init_f
|
init_sequence
|
board_early_init_f
/* to reduce PLL lock time, adjust the LOCKTIME register */
writel(0xFFFFFF, &clk_power->locktime);
/* configure MPLL */
writel((M_MDIV << 12) + (M_PDIV << 4) + M_SDIV,&clk_power->mpllcon);
使用openjtag调试,根据下面调试的内容可知,无法往sdram写入数据,这部分的初始化需要调整
代码修改如下:
1 zhuang@zhuang:~/project/3-jz2440/systems/u-boot-2012.04.01$ git diff . 2 diff --git a/arch/arm/cpu/arm920t/start.S b/arch/arm/cpu/arm920t/start.S 3 index 8c5612c..8655eca 100644 4 --- a/arch/arm/cpu/arm920t/start.S 5 +++ b/arch/arm/cpu/arm920t/start.S 6 @@ -169,9 +169,30 @@ copyex: 7 8 /* FCLK:HCLK:PCLK = 1:2:4 */ 9 /* default FCLK is 120 MHz ! */ 10 - ldr r0, =CLKDIVN 11 - mov r1, #3 12 - str r1, [r0] 13 + /* 2. 设置时钟 */ 14 + ldr r0, =0x4c000014 15 + // mov r1, #0x03; // FCLK:HCLK:PCLK=1:2:4, HDIVN=1,PDIVN=1 16 + mov r1, #0x05; // FCLK:HCLK:PCLK=1:4:8 17 + str r1, [r0] 18 + 19 + /* 如果HDIVN非0,CPU的总线模式应该从“fast bus mode”变为“asynchronous bus mode” */ 20 + mrc p15, 0, r1, c1, c0, 0 /* 读出控制寄存器 */ 21 + orr r1, r1, #0xc0000000 /* 设置为“asynchronous bus mode” */ 22 + mcr p15, 0, r1, c1, c0, 0 /* 写入控制寄存器 */ 23 + 24 + #define S3C2440_MPLL_400MHZ ((0x5c<<12)|(0x01<<4)|(0x01)) 25 + 26 + /* MPLLCON = S3C2440_MPLL_200MHZ */ 27 + ldr r0, =0x4c000004 28 + ldr r1, =S3C2440_MPLL_400MHZ 29 + str r1, [r0] 30 + 31 + /* 启动ICACHE */ 32 + mrc p15, 0, r0, c1, c0, 0 @ read control reg 33 + orr r0, r0, #(1<<12) 34 + mcr p15, 0, r0, c1, c0, 0 @ write it back 35 + 36 + 37 #endif /* CONFIG_S3C24X0 */ 38 39 /* 40 diff --git a/board/samsung/smdk2440/lowlevel_init.S b/board/samsung/smdk2440/lowlevel_init.S 41 index a2bf570..c14cab3 100644 42 --- a/board/samsung/smdk2440/lowlevel_init.S 43 +++ b/board/samsung/smdk2440/lowlevel_init.S 44 @@ -152,16 +152,16 @@ lowlevel_init: 45 /* the literal pools origin */ 46 47 SMRDATA: 48 - .word (0+(B1_BWSCON<<4)+(B2_BWSCON<<8)+(B3_BWSCON<<12)+(B4_BWSCON<<16)+(B5_BWSCON<<20)+(B6_BWSCON<<24)+(B7_BWSCON<<28)) 49 - .word ((B0_Tacs<<13)+(B0_Tcos<<11)+(B0_Tacc<<8)+(B0_Tcoh<<6)+(B0_Tah<<4)+(B0_Tacp<<2)+(B0_PMC)) 50 - .word ((B1_Tacs<<13)+(B1_Tcos<<11)+(B1_Tacc<<8)+(B1_Tcoh<<6)+(B1_Tah<<4)+(B1_Tacp<<2)+(B1_PMC)) 51 - .word ((B2_Tacs<<13)+(B2_Tcos<<11)+(B2_Tacc<<8)+(B2_Tcoh<<6)+(B2_Tah<<4)+(B2_Tacp<<2)+(B2_PMC)) 52 - .word ((B3_Tacs<<13)+(B3_Tcos<<11)+(B3_Tacc<<8)+(B3_Tcoh<<6)+(B3_Tah<<4)+(B3_Tacp<<2)+(B3_PMC)) 53 - .word ((B4_Tacs<<13)+(B4_Tcos<<11)+(B4_Tacc<<8)+(B4_Tcoh<<6)+(B4_Tah<<4)+(B4_Tacp<<2)+(B4_PMC)) 54 - .word ((B5_Tacs<<13)+(B5_Tcos<<11)+(B5_Tacc<<8)+(B5_Tcoh<<6)+(B5_Tah<<4)+(B5_Tacp<<2)+(B5_PMC)) 55 - .word ((B6_MT<<15)+(B6_Trcd<<2)+(B6_SCAN)) 56 - .word ((B7_MT<<15)+(B7_Trcd<<2)+(B7_SCAN)) 57 - .word ((REFEN<<23)+(TREFMD<<22)+(Trp<<20)+(Trc<<18)+(Tchr<<16)+REFCNT) 58 - .word 0x32 59 - .word 0x30 60 - .word 0x30 61 +.long 0x22011110 //BWSCON 62 +.long 0x00000700 //BANKCON0 63 +.long 0x00000700 //BANKCON1 64 +.long 0x00000700 //BANKCON2 65 +.long 0x00000700 //BANKCON3 66 +.long 0x00000700 //BANKCON4 67 +.long 0x00000700 //BANKCON5 68 +.long 0x00018005 //BANKCON6 69 +.long 0x00018005 //BANKCON7 70 +.long 0x008C04F4 // REFRESH 71 +.long 0x000000B1 //BANKSIZE 72 +.long 0x00000030 //MRSRB6 73 +.long 0x00000030 //MRSRB7 74 diff --git a/board/samsung/smdk2440/smdk2410.c b/board/samsung/smdk2440/smdk2410.c 75 index e9ba922..44f38d1 100644 76 --- a/board/samsung/smdk2440/smdk2410.c 77 +++ b/board/samsung/smdk2440/smdk2410.c 78 @@ -74,11 +74,11 @@ int board_early_init_f(void) 79 struct s3c24x0_gpio * const gpio = s3c24x0_get_base_gpio(); 80 81 /* to reduce PLL lock time, adjust the LOCKTIME register */ 82 - writel(0xFFFFFF, &clk_power->locktime); 83 + //writel(0xFFFFFF, &clk_power->locktime); 84 85 /* configure MPLL */ 86 - writel((M_MDIV << 12) + (M_PDIV << 4) + M_SDIV, 87 - &clk_power->mpllcon); 88 + //writel((M_MDIV << 12) + (M_PDIV << 4) + M_SDIV, 89 + // &clk_power->mpllcon); 90 91 /* some delay between MPLL and UPLL */ 92 pll_delay(4000); 93 diff --git a/include/configs/smdk2440.h b/include/configs/smdk2440.h 94 index 7d16320..71336c7 100644 95 --- a/include/configs/smdk2440.h 96 +++ b/include/configs/smdk2440.h 97 @@ -35,7 +35,8 @@ 98 */ 99 #define CONFIG_ARM920T /* This is an ARM920T Core */ 100 #define CONFIG_S3C24X0 /* in a SAMSUNG S3C24x0-type SoC */ 101 -#define CONFIG_S3C2410 /* specifically a SAMSUNG S3C2410 SoC */ 102 +//#define CONFIG_S3C2410 /* specifically a SAMSUNG S3C2410 SoC */ 103 +#define CONFIG_S3C2440 /* specifically a SAMSUNG S3C2410 SoC */ 104 #define CONFIG_SMDK2410 /* on a SAMSUNG SMDK2410 Board */ 105 106 #define CONFIG_SYS_TEXT_BASE 0x0 107 @@ -98,7 +99,7 @@ 108 #define CONFIG_CMD_DATE 109 #define CONFIG_CMD_DHCP 110 #define CONFIG_CMD_ELF 111 -#define CONFIG_CMD_NAND 112 +//#define CONFIG_CMD_NAND 113 #define CONFIG_CMD_PING 114 #define CONFIG_CMD_REGINFO 115 #define CONFIG_CMD_USB 116 @@ -223,7 +224,7 @@ 117 #define CONFIG_CMD_MTDPARTS 118 #define CONFIG_MTD_DEVICE 119 #define CONFIG_MTD_PARTITIONS 120 -#define CONFIG_YAFFS2 121 +//#define CONFIG_YAFFS2 122 #define CONFIG_RBTREE 123 124 /* additions for new relocation code, must be added to all boards */
编译和烧录查看现在结果,现在串口起码可以输出了啊:
五、支持nandflash启动
原来的代码在链接时加了“-pie选项”,使得u-boot.bin里多了rel、dynsym段,这两个段主要是重定位之后修改成新的地址使用的,使用这种方式代码相对会比较大。
5.1 去掉-pie选项,修改如下:
代码修改支持nandflash主要如下:
1 zhuang@zhuang:~/project/3-jz2440/systems/u-boot-2012.04.01$ git diff . 2 diff --git a/arch/arm/config.mk b/arch/arm/config.mk 3 index 3c5f987..cca02b3 100644 4 --- a/arch/arm/config.mk 5 +++ b/arch/arm/config.mk 6 @@ -72,5 +72,5 @@ endif 7 8 # needed for relocation 9 ifndef CONFIG_NAND_SPL 10 -LDFLAGS_u-boot += -pie 11 +#LDFLAGS_u-boot += -pie 12 endif 13 diff --git a/arch/arm/cpu/arm920t/start.S b/arch/arm/cpu/arm920t/start.S 14 index 8655eca..34f7da8 100644 15 --- a/arch/arm/cpu/arm920t/start.S 16 +++ b/arch/arm/cpu/arm920t/start.S 17 @@ -203,103 +203,30 @@ copyex: 18 bl cpu_init_crit 19 #endif 20 21 -/* Set stackpointer in internal RAM to call board_init_f */ 22 -call_board_init_f: 23 ldr sp, =(CONFIG_SYS_INIT_SP_ADDR) 24 bic sp, sp, #7 /* 8-byte alignment for ABI compliance */ 25 + 26 + bl nand_init_ll 27 + mov r0,#0 28 + ldr r1,_TEXT_BASE 29 + 30 + ldr r2,_bss_start_ofs 31 + 32 + bl copy_code_to_sdram 33 + bl clear_bss 34 + 35 + ldr pc,=call_board_init_f 36 + 37 +/* Set stackpointer in internal RAM to call board_init_f */ 38 +call_board_init_f: 39 + 40 ldr r0,=0x00000000 41 bl board_init_f 42 43 -/*------------------------------------------------------------------------------*/ 44 - 45 -/* 46 - * void relocate_code (addr_sp, gd, addr_moni) 47 - * 48 - * This "function" does not return, instead it continues in RAM 49 - * after relocating the monitor code. 50 - * 51 - */ 52 - .globl relocate_code 53 -relocate_code: 54 - mov r4, r0 /* save addr_sp */ 55 - mov r5, r1 /* save addr of gd */ 56 - mov r6, r2 /* save addr of destination */ 57 - 58 - /* Set up the stack */ 59 -stack_setup: 60 - mov sp, r4 61 - 62 - adr r0, _start 63 - cmp r0, r6 64 - beq clear_bss /* skip relocation */ 65 - mov r1, r6 /* r1 <- scratch for copy_loop */ 66 - ldr r3, _bss_start_ofs 67 - add r2, r0, r3 /* r2 <- source end address */ 68 - 69 -copy_loop: 70 - ldmia r0!, {r9-r10} /* copy from source address [r0] */ 71 - stmia r1!, {r9-r10} /* copy to target address [r1] */ 72 - cmp r0, r2 /* until source end address [r2] */ 73 - blo copy_loop 74 - 75 -#ifndef CONFIG_SPL_BUILD 76 - /* 77 - * fix .rel.dyn relocations 78 - */ 79 - ldr r0, _TEXT_BASE /* r0 <- Text base */ 80 - sub r9, r6, r0 /* r9 <- relocation offset */ 81 - ldr r10, _dynsym_start_ofs /* r10 <- sym table ofs */ 82 - add r10, r10, r0 /* r10 <- sym table in FLASH */ 83 - ldr r2, _rel_dyn_start_ofs /* r2 <- rel dyn start ofs */ 84 - add r2, r2, r0 /* r2 <- rel dyn start in FLASH */ 85 - ldr r3, _rel_dyn_end_ofs /* r3 <- rel dyn end ofs */ 86 - add r3, r3, r0 /* r3 <- rel dyn end in FLASH */ 87 -fixloop: 88 - ldr r0, [r2] /* r0 <- location to fix up, IN FLASH! */ 89 - add r0, r0, r9 /* r0 <- location to fix up in RAM */ 90 - ldr r1, [r2, #4] 91 - and r7, r1, #0xff 92 - cmp r7, #23 /* relative fixup? */ 93 - beq fixrel 94 - cmp r7, #2 /* absolute fixup? */ 95 - beq fixabs 96 - /* ignore unknown type of fixup */ 97 - b fixnext 98 -fixabs: 99 - /* absolute fix: set location to (offset) symbol value */ 100 - mov r1, r1, LSR #4 /* r1 <- symbol index in .dynsym */ 101 - add r1, r10, r1 /* r1 <- address of symbol in table */ 102 - ldr r1, [r1, #4] /* r1 <- symbol value */ 103 - add r1, r1, r9 /* r1 <- relocated sym addr */ 104 - b fixnext 105 -fixrel: 106 - /* relative fix: increase location by offset */ 107 - ldr r1, [r0] 108 - add r1, r1, r9 109 -fixnext: 110 - str r1, [r0] 111 - add r2, r2, #8 /* each rel.dyn entry is 8 bytes */ 112 - cmp r2, r3 113 - blo fixloop 114 -#endif 115 + ldr r1,_TEXT_BASE 116 117 -clear_bss: 118 -#ifndef CONFIG_SPL_BUILD 119 - ldr r0, _bss_start_ofs 120 - ldr r1, _bss_end_ofs 121 - mov r4, r6 /* reloc addr */ 122 - add r0, r0, r4 123 - add r1, r1, r4 124 - mov r2, #0x00000000 /* clear */ 125 - 126 -clbss_l:str r2, [r0] /* clear loop... */ 127 - add r0, r0, #4 128 - cmp r0, r1 129 - bne clbss_l 130 - 131 - bl coloured_LED_init 132 - bl red_led_on 133 -#endif 134 + //second action 135 + bl board_init_r 136 137 /* 138 * We are done. Do not return, instead branch to second part of board 139 diff --git a/arch/arm/cpu/u-boot.lds b/arch/arm/cpu/u-boot.lds 140 index e49ca0c..ba20982 100644 141 --- a/arch/arm/cpu/u-boot.lds 142 +++ b/arch/arm/cpu/u-boot.lds 143 @@ -35,6 +35,7 @@ SECTIONS 144 { 145 __image_copy_start = .; 146 CPUDIR/start.o (.text) 147 + board/samsung/smdk2440/libsmdk2440.o (.text) 148 *(.text) 149 } 150 151 diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c 152 index 5270c11..afafe7b 100644 153 --- a/arch/arm/lib/board.c 154 +++ b/arch/arm/lib/board.c 155 @@ -256,7 +256,7 @@ init_fnc_t *init_sequence[] = { 156 NULL, 157 }; 158 159 -void board_init_f(ulong bootflag) 160 +unsigned int board_init_f(ulong bootflag) 161 { 162 bd_t *bd; 163 init_fnc_t **init_fnc_ptr; 164 @@ -369,8 +369,9 @@ void board_init_f(ulong bootflag) 165 * reserve memory for U-Boot code, data & bss 166 * round down to next 4 kB limit 167 */ 168 - addr -= gd->mon_len; 169 - addr &= ~(4096 - 1); 170 + //addr -= gd->mon_len; 171 + //addr &= ~(4096 - 1); 172 + addr = CONFIG_SYS_TEXT_BASE; 173 174 debug("Reserving %ldk for U-Boot at: %08lx ", gd->mon_len >> 10, addr); 175 176 @@ -435,8 +436,10 @@ void board_init_f(ulong bootflag) 177 debug("relocation Offset is: %08lx ", gd->reloc_off); 178 memcpy(id, (void *)gd, sizeof(gd_t)); 179 180 - relocate_code(addr_sp, id, addr); 181 + //relocate_code(addr_sp, id, addr); 182 183 + return (unsigned int )id; 184 + 185 /* NOTREACHED - relocate_code() does not return */ 186 } 187 188 diff --git a/board/samsung/smdk2440/Makefile b/board/samsung/smdk2440/Makefile 189 index b8657b4..04d36b3 100644 190 --- a/board/samsung/smdk2440/Makefile 191 +++ b/board/samsung/smdk2440/Makefile 192 @@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk 193 194 LIB = $(obj)lib$(BOARD).o 195 196 -COBJS := smdk2410.o 197 +COBJS := smdk2410.o init.o 198 SOBJS := lowlevel_init.o 199 200 SRCS := $(SOBJS:.o=.S) $(COBJS:.o=.c) 201 diff --git a/include/common.h b/include/common.h 202 index 4b5841e..390ab72 100644 203 --- a/include/common.h 204 +++ b/include/common.h 205 @@ -273,7 +273,7 @@ int abortboot(int bootdelay); 206 extern char console_buffer[]; 207 208 /* arch/$(ARCH)/lib/board.c */ 209 -void board_init_f (ulong) __attribute__ ((noreturn)); 210 +unsigned int board_init_f(ulong) ; 211 void board_init_r (gd_t *, ulong) __attribute__ ((noreturn)); 212 int checkboard (void); 213 int checkflash (void); 214 diff --git a/include/configs/smdk2440.h b/include/configs/smdk2440.h 215 index 71336c7..b638eb4 100644 216 --- a/include/configs/smdk2440.h 217 +++ b/include/configs/smdk2440.h 218 @@ -39,7 +39,7 @@ 219 #define CONFIG_S3C2440 /* specifically a SAMSUNG S3C2410 SoC */ 220 #define CONFIG_SMDK2410 /* on a SAMSUNG SMDK2410 Board */ 221 222 -#define CONFIG_SYS_TEXT_BASE 0x0 223 +#define CONFIG_SYS_TEXT_BASE 0x33f00000 224 225 #define CONFIG_SYS_ARM_CACHE_WRITETHROUGH 226 227 zhuang@zhuang:~/project/3-jz2440/systems/u-boot-2012.04.01$
添加了一个文件:board/samsung/smdk2440/init.c这里封装了nandflash初始化等操作,nand_init_ll、copy_code_to_sdram,由于我们在start.S文件中重定位了代码,因此不需要在arch/arm/lib/board.c中要去掉重定位的操作relocate_code。
这个值CONFIG_SYS_TEXT_BASE为什么要设置为0x33f00000,这个值是程序链接的大小,bin文件的大小只有300多k,但是没有包含bss等段,
反汇编查看文件的大小:0x00094b40的十进制是600多k,因此设置的CONFIG_SYS_TEXT_BASE我们设置为1M(设置大一点比较安全),我们的sdram的末端地址为0x34000000,0x3400000-0x33f00000=1M
1 arm-linux-objdump -D u-boot > u-boot.dis
编译烧录,开发板设置为nandflash启动,根据下图nandflash启动还是可以输出之前的log,设置成nandflash启动的代码修改暂时没有问题,其余的bug后续修复.
六、支持norflash:
首先我们来看看代码为什么会打印 Flash:*** failed ***,norflash会调用这个进行初始化flash_init,如果初始化失败,则会卡在hang中无法执行,我们打开了调试信息之后,其实是识别出来norflash的,但是为什么会初始化失败是由于jedec_table这个数组没有添加我们norflash的型号导致的。
Board.c (archarmlib)
flash_init
flash_detect_legacy
jedec_flash_match
jedec_table //根据这个数组匹配有没有相应的norflash型号
|
|success |------ |
|failed
|-----puts(failed);
|
|-----hang();norflash初始化失败则会卡在这里
代码修改如下:
1 zhuang@zhuang:~/project/3-jz2440/systems/u-boot-2012.04.01$ git diff . 2 diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c 3 index afafe7b..b8c17ae 100644 4 --- a/arch/arm/lib/board.c 5 +++ b/arch/arm/lib/board.c 6 @@ -527,8 +527,9 @@ void board_init_r(gd_t *id, ulong dest_addr) 7 print_size(flash_size, " "); 8 # endif /* CONFIG_SYS_FLASH_CHECKSUM */ 9 } else { 10 - puts(failed); 11 - hang(); 12 + puts("0 KB "); 13 + //puts(failed); 14 + //hang(); 15 } 16 #endif 17 18 diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c 19 index 35294bc..295003e 100644 20 --- a/drivers/mtd/cfi_flash.c 21 +++ b/drivers/mtd/cfi_flash.c 22 @@ -42,6 +42,9 @@ 23 #include <mtd/cfi_flash.h> 24 #include <watchdog.h> 25 26 +//#define DEBUG 1 27 +//#define _DEBUG 1 28 + 29 /* 30 * This file implements a Common Flash Interface (CFI) driver for 31 * U-Boot. 32 diff --git a/drivers/mtd/jedec_flash.c b/drivers/mtd/jedec_flash.c 33 index 2350f36..4037ec2 100644 34 --- a/drivers/mtd/jedec_flash.c 35 +++ b/drivers/mtd/jedec_flash.c 36 @@ -367,6 +367,24 @@ static const struct amd_flash_info jedec_table[] = { 37 } 38 }, 39 #endif 40 + { 41 + .mfr_id = (u16)MX_MANUFACT, 42 + .dev_id = 0x2249, 43 + .name = "MXIC MT29LV160DB", 44 + .uaddr = { 45 + [1] = MTD_UADDR_0x0555_0x02AA /* x16 */ 46 + }, 47 + .DevSize = SIZE_2MiB, 48 + .CmdSet = P_ID_AMD_STD, 49 + .NumEraseRegions= 4, 50 + .regions = { 51 + ERASEINFO(16*1024, 1), 52 + ERASEINFO(8*1024, 2), 53 + ERASEINFO(32*1024, 1), 54 + ERASEINFO(16*1024, 31), 55 + } 56 + }, 57 + 58 }; 59 60 static inline void fill_info(flash_info_t *info, const struct amd_flash_info *jedec_entry, ulong base) 61 diff --git a/include/configs/smdk2440.h b/include/configs/smdk2440.h 62 index b638eb4..9342042 100644 63 --- a/include/configs/smdk2440.h 64 +++ b/include/configs/smdk2440.h 65 @@ -187,7 +187,7 @@ 66 67 #define CONFIG_SYS_MAX_FLASH_BANKS 1 68 #define CONFIG_SYS_FLASH_BANKS_LIST { CONFIG_SYS_FLASH_BASE } 69 -#define CONFIG_SYS_MAX_FLASH_SECT (19) 70 +#define CONFIG_SYS_MAX_FLASH_SECT (128) 71 72 #define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x070000) 73 #define CONFIG_ENV_IS_IN_FLASH 74 zhuang@zhuang:~/project/3-jz2440/systems/u-boot-2012.04.01$
按照上述方式进行修改,编译烧录现象如下,起码norflash初始化不会报错:
在uboot中进行norflash的读写实验,从下图可以看出norflash进行读写的实验基本没有问题,但是在0x3000000会有点问题:
由于之前在第一阶段的时候讲sp设置到了0x30000000,因此在调用函数的时候30000000的数据会变化,我们在第一阶段的时候sp已经重新定义了位置,在第二阶段的时候没有修改sp的指向,因此这里需要重新设置sp的地址:
修改代码如下:
1 diff --git a/arch/arm/cpu/arm920t/start.S b/arch/arm/cpu/arm920t/start.S 2 index 34f7da8..a1876a5 100644 3 --- a/arch/arm/cpu/arm920t/start.S 4 +++ b/arch/arm/cpu/arm920t/start.S 5 @@ -110,6 +110,11 @@ FIQ_STACK_START: 6 IRQ_STACK_START_IN: 7 .word 0x0badc0de 8 9 +.globl base_sp 10 +base_sp: 11 + .long 0 12 + 13 + 14 /* 15 * the actual start code 16 */ 17 @@ -224,7 +229,9 @@ call_board_init_f: 18 bl board_init_f 19 20 ldr r1,_TEXT_BASE 21 - 22 + 23 + ldr sp,=base_sp 24 + 25 //second action 26 bl board_init_r 27 28 diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c 29 index afafe7b..6cd7352 100644 30 --- a/arch/arm/lib/board.c 31 +++ b/arch/arm/lib/board.c 32 @@ -262,6 +262,7 @@ unsigned int board_init_f(ulong bootflag) 33 init_fnc_t **init_fnc_ptr; 34 gd_t *id; 35 ulong addr, addr_sp; 36 + extern ulong base_sp; 37 #ifdef CONFIG_PRAM 38 ulong reg; 39 #endif 40 @@ -436,6 +437,8 @@ unsigned int board_init_f(ulong bootflag) 41 debug("relocation Offset is: %08lx ", gd->reloc_off); 42 memcpy(id, (void *)gd, sizeof(gd_t)); 43 44 + base_sp = addr_sp; 45 + 46 //relocate_code(addr_sp, id, addr); 47
重新进行norflash的读写实验,在0x3000000读写没有问题.
七、支持nandflash操作:
修改代码如下:
1 diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile 2 index 1d1b628..1554712 100644 3 --- a/drivers/mtd/nand/Makefile 4 +++ b/drivers/mtd/nand/Makefile 5 @@ -59,6 +59,7 @@ COBJS-$(CONFIG_NAND_MXS) += mxs_nand.o 6 COBJS-$(CONFIG_NAND_NDFC) += ndfc.o 7 COBJS-$(CONFIG_NAND_NOMADIK) += nomadik.o 8 COBJS-$(CONFIG_NAND_S3C2410) += s3c2410_nand.o 9 +COBJS-$(CONFIG_NAND_S3C2440) += s3c2440_nand.o 10 COBJS-$(CONFIG_NAND_S3C64XX) += s3c64xx.o 11 COBJS-$(CONFIG_NAND_SPEAR) += spr_nand.o 12 COBJS-$(CONFIG_NAND_OMAP_GPMC) += omap_gpmc.o 13 diff --git a/drivers/mtd/nand/s3c2440_nand.c b/drivers/mtd/nand/s3c2440_nand.c 14 index e1a459b..a0c8876 100644 15 --- a/drivers/mtd/nand/s3c2440_nand.c 16 +++ b/drivers/mtd/nand/s3c2440_nand.c 17 @@ -51,46 +51,47 @@ static void nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) 18 } 19 #endif 20 21 -static void s3c2410_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) 22 +static void s3c2440_hwcontrol(struct mtd_info *mtd, int dat, unsigned int ctrl) 23 { 24 struct nand_chip *chip = mtd->priv; 25 - struct s3c2410_nand *nand = s3c2410_get_base_nand(); 26 - 27 - debug("hwcontrol(): 0x%02x 0x%02x ", cmd, ctrl); 28 - 29 - if (ctrl & NAND_CTRL_CHANGE) { 30 - ulong IO_ADDR_W = (ulong)nand; 31 - 32 - if (!(ctrl & NAND_CLE)) 33 - IO_ADDR_W |= S3C2410_ADDR_NCLE; 34 - if (!(ctrl & NAND_ALE)) 35 - IO_ADDR_W |= S3C2410_ADDR_NALE; 36 + struct s3c2440_nand *nand = s3c2440_get_base_nand(); 37 38 - chip->IO_ADDR_W = (void *)IO_ADDR_W; 39 - 40 - if (ctrl & NAND_NCE) 41 - writel(readl(&nand->nfconf) & ~S3C2410_NFCONF_nFCE, 42 - &nand->nfconf); 43 - else 44 - writel(readl(&nand->nfconf) | S3C2410_NFCONF_nFCE, 45 - &nand->nfconf); 46 + if (ctrl &NAND_CLE){ 47 + writeb(dat,&nand->nfcmd); 48 + }else if (ctrl &NAND_ALE){ 49 + writeb(dat,&nand->nfaddr); 50 } 51 - 52 - if (cmd != NAND_CMD_NONE) 53 - writeb(cmd, chip->IO_ADDR_W); 54 } 55 56 -static int s3c2410_dev_ready(struct mtd_info *mtd) 57 +static int s3c2440_dev_ready(struct mtd_info *mtd) 58 { 59 - struct s3c2410_nand *nand = s3c2410_get_base_nand(); 60 + struct s3c2440_nand *nand = s3c2440_get_base_nand(); 61 debug("dev_ready "); 62 return readl(&nand->nfstat) & 0x01; 63 } 64 65 +static void s3c2440_nand_select(struct mtd_info *mtd, int chipnr) 66 +{ 67 + struct s3c2440_nand *nand = s3c2440_get_base_nand(); 68 + 69 + switch (chipnr) { 70 + case -1: 71 + nand->nfcont |= (1<<1); 72 + break; 73 + case 0: 74 + nand->nfcont &= ~(1<<1); 75 + break; 76 + 77 + default: 78 + BUG(); 79 + } 80 +} 81 + 82 + 83 #ifdef CONFIG_S3C2410_NAND_HWECC 84 void s3c2410_nand_enable_hwecc(struct mtd_info *mtd, int mode) 85 { 86 - struct s3c2410_nand *nand = s3c2410_get_base_nand(); 87 + struct s3c2440_nand *nand = s3c2440_get_base_nand(); 88 debug("s3c2410_nand_enable_hwecc(%p, %d) ", mtd, mode); 89 writel(readl(&nand->nfconf) | S3C2410_NFCONF_INITECC, &nand->nfconf); 90 } 91 @@ -126,7 +127,7 @@ int board_nand_init(struct nand_chip *nand) 92 u_int32_t cfg; 93 u_int8_t tacls, twrph0, twrph1; 94 struct s3c24x0_clock_power *clk_power = s3c24x0_get_base_clock_power(); 95 - struct s3c2410_nand *nand_reg = s3c2410_get_base_nand(); 96 + struct s3c2440_nand *nand_reg = s3c2440_get_base_nand(); 97 98 debug("board_nand_init() "); 99 100 @@ -143,17 +144,20 @@ int board_nand_init(struct nand_chip *nand) 101 twrph1 = 8; 102 #endif 103 104 - cfg = S3C2410_NFCONF_EN; 105 - cfg |= S3C2410_NFCONF_TACLS(tacls - 1); 106 - cfg |= S3C2410_NFCONF_TWRPH0(twrph0 - 1); 107 - cfg |= S3C2410_NFCONF_TWRPH1(twrph1 - 1); 108 + //cfg = S3C2410_NFCONF_EN; 109 + //cfg |= S3C2410_NFCONF_TACLS(tacls - 1); 110 + //cfg |= S3C2410_NFCONF_TWRPH0(twrph0 - 1); 111 + //cfg |= S3C2410_NFCONF_TWRPH1(twrph1 - 1); 112 + cfg = ((tacls-1)<<12)|((twrph0-1)<<8)|((twrph1-1)<<4); 113 writel(cfg, &nand_reg->nfconf); 114 115 + writel((1<<4)|(1<<1)|(1<<0), &nand_reg->nfcont); 116 + 117 /* initialize nand_chip data structure */ 118 nand->IO_ADDR_R = (void *)&nand_reg->nfdata; 119 nand->IO_ADDR_W = (void *)&nand_reg->nfdata; 120 121 - nand->select_chip = NULL; 122 + nand->select_chip = s3c2440_nand_select; 123 124 /* read_buf and write_buf are default */ 125 /* read_byte and write_byte are default */ 126 @@ -162,9 +166,9 @@ int board_nand_init(struct nand_chip *nand) 127 #endif 128 129 /* hwcontrol always must be implemented */ 130 - nand->cmd_ctrl = s3c2410_hwcontrol; 131 + nand->cmd_ctrl = s3c2440_hwcontrol; 132 133 - nand->dev_ready = s3c2410_dev_ready; 134 + nand->dev_ready = s3c2440_dev_ready; 135 136 #ifdef CONFIG_S3C2410_NAND_HWECC 137 nand->ecc.hwctl = s3c2410_nand_enable_hwecc; 138 diff --git a/include/configs/smdk2440.h b/include/configs/smdk2440.h 139 index 9342042..6f5710d 100644 140 --- a/include/configs/smdk2440.h 141 +++ b/include/configs/smdk2440.h 142 @@ -99,7 +99,7 @@ 143 #define CONFIG_CMD_DATE 144 #define CONFIG_CMD_DHCP 145 #define CONFIG_CMD_ELF 146 -//#define CONFIG_CMD_NAND 147 +#define CONFIG_CMD_NAND 148 #define CONFIG_CMD_PING 149 #define CONFIG_CMD_REGINFO 150 #define CONFIG_CMD_USB 151 @@ -208,8 +208,14 @@ 152 * NAND configuration 153 */ 154 #ifdef CONFIG_CMD_NAND 155 + 156 +#ifdef CONFIG_S3C2410 157 #define CONFIG_NAND_S3C2410 158 #define CONFIG_SYS_S3C2410_NAND_HWECC 159 +#else 160 +#define CONFIG_NAND_S3C2440 161 +#define CONFIG_SYS_S3C2440_NAND_HWECC 162 +#endif 163 #define CONFIG_SYS_MAX_NAND_DEVICE 1 164 #define CONFIG_SYS_NAND_BASE 0x4E000000 165 #endif
使用loady进行烧录,现在串口输入loady 30000000,之后按ctrl+A,之后按s,选择ymodel,选择文件即可使用loady进行烧录
烧录到Norflash
烧录到nandflash:
启动,识别到nandflash:
八、支持DM9000:
根据下图可知uboot支持的是cs8900网卡,我们使用的是DM9000网卡,因此需要把dm9000编译进uboot而不是cs8900,在配置文件添加这个宏CONFIG_DRIVER_DM9000
根据下面的原理图可知DM9000是使用nGCS4作为片选引脚,内存的基地址要设置为0x2000_0000 ,
代码修改如下,BANKCON4用于修改DM9000的时序:
zhuang@zhuang:~/project/3-jz2440/systems/u-boot-2012.04.01$ git diff . diff --git a/board/samsung/smdk2440/lowlevel_init.S b/board/samsung/smdk2440/lowlevel_init.S index c14cab3..0adf662 100644 --- a/board/samsung/smdk2440/lowlevel_init.S +++ b/board/samsung/smdk2440/lowlevel_init.S @@ -157,7 +157,7 @@ SMRDATA: .long 0x00000700 //BANKCON1 .long 0x00000700 //BANKCON2 .long 0x00000700 //BANKCON3 -.long 0x00000700 //BANKCON4 +.long 0x00000740 //BANKCON4 .long 0x00000700 //BANKCON5 .long 0x00018005 //BANKCON6 .long 0x00018005 //BANKCON7 diff --git a/include/configs/smdk2440.h b/include/configs/smdk2440.h index 6f5710d..780adb7 100644 --- a/include/configs/smdk2440.h +++ b/include/configs/smdk2440.h @@ -55,10 +55,17 @@ /* * Hardware drivers */ + # if 0 #define CONFIG_CS8900 /* we have a CS8900 on-board */ #define CONFIG_CS8900_BASE 0x19000300 #define CONFIG_CS8900_BUS16 /* the Linux driver does accesses as shorts */ +#else +#define CONFIG_DRIVER_DM9000 +#define CONFIG_DM9000_BASE 0x20000000 +#define DM9000_IO CONFIG_DM9000_BASE +#define DM9000_DATA (CONFIG_DM9000_BASE + 4) +#endif /* * select serial console configuration */
编译烧录:现象如下,显示没有找到网卡:
在uboot里网卡初始化流程如下,由于没有修改成DM9000的初始化导致的:
puts("Net: ");
eth_initialize(gd->bd);
|
int board_eth_init(bd_t *bis)
{
int rc = 0;
#ifdef CONFIG_CS8900
rc = cs8900_initialize(0, CONFIG_CS8900_BASE);
#endif
return rc;
}
#endif
代码修改如下:
1 diff --git a/board/samsung/smdk2440/smdk2410.c b/board/samsung/smdk2440/smdk2410.c 2 index 44f38d1..b56f8aa 100644 3 --- a/board/samsung/smdk2440/smdk2410.c 4 +++ b/board/samsung/smdk2440/smdk2410.c 5 @@ -138,6 +138,11 @@ int board_eth_init(bd_t *bis) 6 #ifdef CONFIG_CS8900 7 rc = cs8900_initialize(0, CONFIG_CS8900_BASE); 8 #endif 9 + 10 +#ifdef CONFIG_DRIVER_DM9000 11 + rc = dm9000_initialize(bis); 12 +#endif 13 + 14 return rc; 15 } 16 #endif
编译烧录现象如下,识别到DM9000,并且ping成功:
使用tftp下载:
安装相关的软件
1 apt-get install tftp-hpa tftpd-hpa xinetd
修改配置文件:
sudo vim /etc/default/tftpd-hpa
# /etc/default/tftpd-hpa TFTP_USERNAME="tftp" TFTP_DIRECTORY="/tftpboot" TFTP_ADDRESS=":69" TFTP_OPTIONS="--secure"
创建tftp的目录
1 sudo mkdir /tftpboot 2 sudo chmod 777 /tftpboot
使用tftp下载内核实验如下,成功下载内核,因此uboot对应dm9000的修改暂时没有问题:
九、修改默认参数以及裁剪uboot
代码修改如下:
1 zhuang@zhuang:~/project/3-jz2440/systems/u-boot-2012.04.01$ git diff . 2 diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c 3 index 6cd7352..634f4c8 100644 4 --- a/arch/arm/lib/board.c 5 +++ b/arch/arm/lib/board.c 6 @@ -654,6 +654,9 @@ void board_init_r(gd_t *id, ulong dest_addr) 7 } 8 #endif 9 10 + //mtdparts_init(); 11 + run_command("mtdparts default",0); //在执行mtdpart之前需要运行mtdparts default 进行初始化设置 12 + 13 /* main_loop() can return to retry autoboot, if so just run it again. */ 14 for (;;) { 15 main_loop(); 16 diff --git a/include/configs/smdk2440.h b/include/configs/smdk2440.h 17 index bb3f227..709071d 100644 18 --- a/include/configs/smdk2440.h 19 +++ b/include/configs/smdk2440.h 20 @@ -75,15 +75,15 @@ 21 /************************************************************ 22 * USB support (currently only works with D-cache off) 23 ************************************************************/ 24 -#define CONFIG_USB_OHCI 25 -#define CONFIG_USB_KEYBOARD 26 -#define CONFIG_USB_STORAGE 27 -#define CONFIG_DOS_PARTITION 28 +//#define CONFIG_USB_OHCI //裁剪没有用到的模块 29 +//#define CONFIG_USB_KEYBOARD 30 +//#define CONFIG_USB_STORAGE 31 +//#define CONFIG_DOS_PARTITION 32 33 /************************************************************ 34 * RTC 35 ************************************************************/ 36 -#define CONFIG_RTC_S3C24X0 37 +//#define CONFIG_RTC_S3C24X0 38 39 40 #define CONFIG_BAUDRATE 115200 41 @@ -91,10 +91,10 @@ 42 /* 43 * BOOTP options 44 */ 45 -#define CONFIG_BOOTP_BOOTFILESIZE 46 -#define CONFIG_BOOTP_BOOTPATH 47 -#define CONFIG_BOOTP_GATEWAY 48 -#define CONFIG_BOOTP_HOSTNAME 49 +//#define CONFIG_BOOTP_BOOTFILESIZE 50 +//#define CONFIG_BOOTP_BOOTPATH 51 +//#define CONFIG_BOOTP_GATEWAY 52 +//#define CONFIG_BOOTP_HOSTNAME 53 54 /* 55 * Command line configuration. 56 @@ -103,13 +103,13 @@ 57 58 #define CONFIG_CMD_BSP 59 #define CONFIG_CMD_CACHE 60 -#define CONFIG_CMD_DATE 61 -#define CONFIG_CMD_DHCP 62 +//#define CONFIG_CMD_DATE 63 +//#define CONFIG_CMD_DHCP 64 #define CONFIG_CMD_ELF 65 #define CONFIG_CMD_NAND 66 #define CONFIG_CMD_PING 67 #define CONFIG_CMD_REGINFO 68 -#define CONFIG_CMD_USB 69 +//#define CONFIG_CMD_USB 70 71 #define CONFIG_SYS_HUSH_PARSER 72 #define CONFIG_SYS_PROMPT_HUSH_PS2 "> " 73 @@ -162,7 +162,7 @@ 74 75 76 #define CONFIG_BOOTARGS "console=ttySAC0 root=/dev/mtdblock3" 77 -#define CONFIG_BOOTCOMMAND "nand read 30000000 0xabc 0x200000;bootm 30000000" 78 +#define CONFIG_BOOTCOMMAND "nand read 30000000 kernel 0x200000;bootm 30000000" 79 #define CONFIG_ETHADDR "00:06:3b:01:41:55" 80 /*----------------------------------------------------------------------- 81 * Stack sizes 82 @@ -200,11 +200,28 @@ 83 #define CONFIG_SYS_FLASH_BANKS_LIST { CONFIG_SYS_FLASH_BASE } 84 #define CONFIG_SYS_MAX_FLASH_SECT (128) 85 86 +#if 0 87 #define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x070000) 88 #define CONFIG_ENV_IS_IN_FLASH 89 #define CONFIG_ENV_SIZE 0x10000 90 /* allow to overwrite serial and ethaddr */ 91 #define CONFIG_ENV_OVERWRITE 92 +#endif 93 + 94 +#define CONFIG_ENV_IS_IN_NAND 95 +#define CONFIG_ENV_OFFSET 0x00040000 //设置params分区存放的大小和便宜 96 +#define CONFIG_ENV_SIZE 0x20000 /* nand blcok size */ 97 +#define CONFIG_ENV_RANGE CONFIG_ENV_SIZE 98 + 99 +#define CONFIG_CMD_MTDPARTS 100 +#define CONFIG_MTD_DEVICE 101 +#define MTDIDS_DEFAULT "nand0=jz2440-0" // which device 102 + //mtdparts 命令对nandflash的划分 103 +#define MTDPARTS_DEFAULT "mtdparts=jz2440-0:256k(u-boot)," 104 + "128k(params)," 105 + "2m(kernel)," 106 + "-(rootfs)" 107 + 108 109 /* 110 * Size of malloc() pool 111 @@ -234,6 +251,7 @@ 112 /* 113 * File system 114 */ 115 + #if 0 116 #define CONFIG_CMD_FAT 117 #define CONFIG_CMD_EXT2 118 #define CONFIG_CMD_UBI 119 @@ -241,9 +259,9 @@ 120 #define CONFIG_CMD_MTDPARTS 121 #define CONFIG_MTD_DEVICE 122 #define CONFIG_MTD_PARTITIONS 123 -//#define CONFIG_YAFFS2 124 +#define CONFIG_YAFFS2 125 #define CONFIG_RBTREE 126 - 127 +#endif 128 /* additions for new relocation code, must be added to all boards */ 129 #define CONFIG_SYS_SDRAM_BASE PHYS_SDRAM_1 130 #define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + 0x1000 -
设置默认的环境变量修改文件include/configs/smdk2440.h
1 /* 2 * select serial console configuration 3 */ 4 @@ -115,8 +122,8 @@ 5 #define CONFIG_ZERO_BOOTDELAY_CHECK 6 7 #define CONFIG_NETMASK 255.255.255.0 8 -#define CONFIG_IPADDR 10.0.0.110 9 -#define CONFIG_SERVERIP 10.0.0.1 10 +#define CONFIG_IPADDR 192.168.1.17 11 +#define CONFIG_SERVERIP 192.168.1.100 12 13 #if defined(CONFIG_CMD_KGDB) 14 #define CONFIG_KGDB_BAUDRATE 115200 /* speed to run kgdb serial port */ 15 @@ -153,6 +160,10 @@ 16 #define CONFIG_LZO 17 #define CONFIG_LZMA 18 19 + 20 +#define CONFIG_BOOTARGS "console=ttySAC0 root=/dev/mtdblock3" 21 +#define CONFIG_BOOTCOMMAND "nand read 30000000 0xabc 0x200000;bootm 30000000" 22 +#define CONFIG_ETHADDR "00:06:3b:01:41:55" 23 /*-----------------------------------------------------------------------
编译烧录,设置默认的环境变量生效:
tftp下载uboot到sdram,解除写保护,擦除分区,从内存拷贝到norflash。
下载内核到nandflash
从nandflash读到sdram并启动
支持mtdpart命令:
利用分区名进行烧录,擦除等操作
十、uboot支持jffs2文件系统烧录,默认支持jffs2文件系统烧录
支持yaffs2文件系统,代码修改如下:
1 diff --git a/drivers/mtd/nand/nand_util.c b/drivers/mtd/nand/nand_util.c 2 old mode 100644 3 new mode 100755 4 index 60c778e..f9c4a88 5 --- a/drivers/mtd/nand/nand_util.c 6 +++ b/drivers/mtd/nand/nand_util.c 7 @@ -515,7 +515,7 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, 8 return -EINVAL; 9 } 10 11 - if (!need_skip && !(flags & WITH_DROP_FFS)) { 12 + if (!need_skip && !(flags & WITH_DROP_FFS) && !(flags & WITH_YAFFS_OOB)) { 13 rval = nand_write (nand, offset, length, buffer); 14 if (rval == 0) 15 return 0; 16 @@ -553,7 +553,7 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, 17 18 ops.len = pagesize; 19 ops.ooblen = nand->oobsize; 20 - ops.mode = MTD_OOB_AUTO; 21 + ops.mode = MTD_OOB_RAW; 22 ops.ooboffs = 0; 23 24 pages = write_size / pagesize_oob; 25 @@ -564,7 +564,7 @@ int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, 26 ops.oobbuf = ops.datbuf + pagesize; 27 28 rval = nand->write_oob(nand, offset, &ops); 29 - if (!rval) 30 + if (rval) 31 break; 32 33 offset += pagesize; 34 diff --git a/include/configs/smdk2440.h b/include/configs/smdk2440.h 35 index 709071d..dc25330 100644 36 --- a/include/configs/smdk2440.h 37 +++ b/include/configs/smdk2440.h 38 @@ -160,7 +160,7 @@ 39 #define CONFIG_LZO 40 #define CONFIG_LZMA 41 42 - 43 +#define CONFIG_CMD_NAND_YAFFS 44 #define CONFIG_BOOTARGS "console=ttySAC0 root=/dev/mtdblock3" 45 #define CONFIG_BOOTCOMMAND "nand read 30000000 kernel 0x200000;bootm 30000000" 46 #define CONFIG_ETHADDR "00:06:3b:01:41:55"
更新uboot
烧录yaffs文件系统
使用yaffs文件系统启动Ok