----------------------------------------------------------
使用環境
PC: Centos5.4
kernel: 3.0.1
corss: arm-linux-gcc 4.4.1
arm: s3c6410
uboot: uboot-2010-03
----------------------------------------------------------
第一處修改:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #ifndef CONFIG_NAND_SPL /* * flush v4 I/D caches */ mov r0, #0 mcr p15, 0, r0, c7, c7, 0/* flush v3/v4 cache */ mcr p15, 0, r0, c8, c7, 0/* flush v4 TLB */ /* * disable MMU stuff and caches//////////////////////////////////////////////// */ mrc p15, 0, r0, c1, c0, 0 bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS) bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM) orr r0, r0, #0x00000002 @ set bit 2 (A) Align orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache mcr p15, 0, r0, c1, c0, 0//從后面拷貝過來的 ///////////////////////////////以下的注釋掉 /* Prepare to disable the MMU */ //adr r1, mmu_disable_phys /* We presume we're within the first 1024 bytes */ //and r1, r1, #0x3fc //ldr r2, _TEXT_PHY_BASE //ldr r3, =0xfff00000 //and r2, r2, r3 //orr r2, r2, r1 //b mmu_disable //.align 5 /* Run in a single cache-line */ //mmu_disable: // mcr p15, 0, r0, c1, c0, 0 // nop // nop // mov pc, r2 //////////////////////////////////////////////////////////////////// |
第二處修改:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | bl lowlevel_init /* go setup pll,mux,memory */ 之后 /* when we already run in ram, we don't need to relocate U-Boot.//////////////////////////////////////////////////////////////////// * and actually, memory controller must be configured before U-Boot * is running in ram. */ ldr r0, =0xff000fff bic r1, pc, r0 /* r0 <- current base addr of code */ ldr r2, _TEXT_BASE /* r1 <- original base addr in ram */ bic r2, r2, r0 /* r0 <- current base addr of code */ cmp r1, r2 /* compare r0, r1 */ beq after_copy /* r0 == r1 then skip flash copy */ #ifdef CONFIG_BOOT_NAND mov r0, #0x1000 bl copy_from_nand #endif after_copy://////////////////////////////////////////////////////// #ifdef CONFIG_ENABLE_MMU |
上面的修改是判斷到底是從Nand Flash啟動還是RAM啟動;
1.如果是從nandflash中啟動,那么PC的值一定在4K之內。那么執行完bicr1,pc,r0 之后,r1為0。_TEXT_BASE要么等于0x57e00000,要么等于0xC7e00000.那么執行完bicr2,r2,r0 之后,r2為0x00e00000,那么不相等,則不跳轉,下面應該就是copy_from_nand。
2.如果是從ram中啟動,那么PC的值為0xx7e00000。那么執行完bicr1,pc,r0 之后,r1為0x00e00000。_TEXT_BASE要么等于0x57e00000,要么等于0xC7e00000.那么執行完bicr2,r2,r0 之后,r2為0x00e00000,那么相等,跳轉到after_copy,也就是不需要copy。承接上面分析,如果沒有完成copy,則接下來就是copy_from_nand。
第三處修改:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #ifndef CONFIG_NAND_SPL /* * we assume that cache operation is done before. (eg. cleanup_before_linux()) * actually, we don't need to do anything about cache if not use d-cache in * U-Boot. So, in this function we clean only MMU. by scsuh * * void theLastJump(void *kernel, int arch_num, uint boot_params); */ #ifdef CONFIG_ENABLE_MMU .globl theLastJump theLastJump: 之前加上以下語句 /* * copy U-Boot to SDRAM and jump to ram (from NAND or OneNAND) * r0: size to be compared * Load 1'st 2blocks to RAM because U-boot's size is larger than 1block(128k) size *//////////////////////////////////////////////////////////////////////////////// .globl copy_from_nand copy_from_nand: mov r10, lr /* save return address */ mov r9, r0 /* get ready to call C functions */ ldr sp, _TEXT_PHY_BASE/* setup temp stack pointer */ sub sp, sp, #12 mov fp, #0 /* no previous frame, so fp=0 */ mov r9, #0x1000 bl copy_uboot_to_ram //此函數需要添加,稍后說明。 3: tst r0, #0x0 bne copy_failed ldr r0, =0x0c000000 ldr r1, _TEXT_PHY_BASE 1: ldr r3, [r0], #4 ldr r4, [r1], #4 teq r3, r4 bne compare_failed/* not matched */ subs r9, r9, #4 bne 1b 4: mov lr, r10 /* all is OK */ mov pc, lr copy_failed: nop /* copy from nand failed */ b copy_failed compare_failed: nop /* compare failed */ b compare_failed |
接著進入u-boot-2010.03/include/configs編輯smdk6410.h,添加下面的宏定義;
1.
1 | #definevirt_to_phys(x) virt_to_phy_smdk6410(x) |
2.
1 | #defineCONFIG_SYS_PROMPT 'SMDK6410#' /*MonitorCommandPrompt */ |
1 | 這里的”SMDK6410”可以自己修改,這就是你進入uboot的命令模式的#前面的文字。 |
1 |
1 2 | //#definePHYS_SDRAM_1_SIZE 0x08000000 /*128MBinBank#1 */ #definePHYS_SDRAM_1_SIZE 0x10000000 /*256MBinBank#1 */ |
1 | 修改SDRAM內存為256M的。 |
1 |
1 2 3 4 | /*NANDconfiguration*/ #defineNAND_DISABLE_CE()(NFCONT_REG|= (1<<1)) #defineNAND_ENABLE_CE()(NFCONT_REG&=~(1<<1)) #defineNF_TRANSRnB() do{while(!(NFSTAT_REG&(1<<0)));}while(0) |
1 | 這里的定義是后面寫nand_cp.c要用到的宏定義 |
1 |
1 2 3 4 5 | /* *Architecturemagicandmachinetype */ //#define MACH_TYPE 1270/*smdk6400ID*/ #defineMACH_TYPE 1626/*smdk6410ID*/ |
1 | 6410的ID號; |
1 |
1 2 3 4 5 6 | /* *Sizeofmalloc()pool */ //#define CONFIG_SYS_MALLOC_LEN (CONFIG_ENV_SIZE+1024*1024) #defineCONFIG_SYS_MALLOC_LEN (CONFIG_ENV_SIZE+512*1024) #defineCONFIG_SYS_GBL_DATA_SIZE 128 /*sizeinbytesforinitialdata*/ |
1 | 修改內存大小; |
1 |
1 | #defineCONFIG_BOOTDELAY 3 |
1 | 修改bootdelay延遲時間 |
1 |
1 2 3 4 | //#define CONFIG_SYS_MEMTEST_END (CONFIG_SYS_SDRAM_BASE +0x7e00000) /*126MBinDRAM*/ #defineCONFIG_SYS_MEMTEST_END (CONFIG_SYS_SDRAM_BASE +0x9e00000) /*256MBinDRAM*/ |
1 | 修改SDROM大小; |
1 |
1 2 3 4 | /*the PWMTImer4usesacounterof15625for10ms,soweneed*/ /*ittowrap100times (total1562500)toget1sec.*/ //#define CONFIG_SYS_HZ 1000 //atPCLK50MHz #defineCONFIG_SYS_HZ 1562500 |
1 | 時鐘修改; |
1 | 10. |
1 2 | //#define CONFIG_STACKSIZE 0x40000 /*regularstack256KB*/ #defineCONFIG_STACKSIZE 0x80000 /*regularstack512KB*/ |
1 | 堆棧大小修改; |
1 | 11. |
1 2 | //#define PHYS_SDRAM_1_SIZE 0x08000000 /*128MBinBank#1 */ #definePHYS_SDRAM_1_SIZE0x10000000 /*256MBinBank#1 */ |
1 | Nand Flash每塊大小修改; |
1 | 12. |
1 2 | //#define CONFIG_ENV_SIZE 0x4000 /*TotalSizeofEnvironmentSector*/ #defineCONFIG_ENV_SIZE 0x80000 /*TotalSizeofEnvironmentSector*/ |
1 | Total Size of Environment Sector修改; |
1 | 13. |
1 2 3 4 | //#define CONFIG_BOOTCOMMAND 'nand read 0x50018000 0x60000 0x1c0000;' //'bootm0x50018000' #define CONFIG_BOOTCOMMAND 'nand read 0x50018000 0x100000 0x500000;' 'bootm0x50018000' |
1 | CONFIG_BOOTCOMMAND修改 |
1 | 14. |
1 | #defineCONFIG_ENV_OFFSET 0x0080000 |
1 | CONFIG_ENV_OFFSET修改 |
1 | 15. |
1 2 | //#define CONFIG_SYS_NAND_PAGE_SIZE 2048 #defineCONFIG_SYS_NAND_PAGE_SIZE 4096 |
1 | Nand Flash每一頁大小的修改 |
1 | 16. |
1 2 3 | /*NANDchipblocksize */ //#define CONFIG_SYS_NAND_BLOCK_SIZE (128*1024) #defineCONFIG_SYS_NAND_BLOCK_SIZE (512*1024) |
1 | Nand Flash每一塊大小的修改 |
1 | 17. |
1 2 3 | /*NANDchippageperblockcount */ //#define CONFIG_SYS_NAND_PAGE_COUNT 64 #defineCONFIG_SYS_NAND_PAGE_COUNT 128 |
1 | 校驗位修改 |
1 | 并將里面的所有6400除了(#define CONFIG_S3C6400 1)替換為6410 |
1 |
1 | 接下來在u-boot-2010.03/cpu/arm1176/下面新建一個nand_cp.c文件,代碼如下: |
1 2 3 4 | #include #ifdefCONFIG_S3C64XX #include #include |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include staticintnandll_read_page(uchar*buf,ulongaddr,intlarge_block) { inti; intpage_size=512; /* 2K */ if(large_block==1) page_size=2048; /* 4K */ if(large_block==2) page_size=4096; NAND_ENABLE_CE(); NFCMD_REG=NAND_CMD_READ0; /*WriteAddress*/ NFADDR_REG=0; if(large_block) NFADDR_REG=0; |
1 2 3 4 5 6 7 8 9 10 | NFADDR_REG=(addr)&0xff; NFADDR_REG=(addr>>8)&0xff; NFADDR_REG=(addr>>16)&0xff; /* #defineNFCMD_REG __REG(ELFIN_NAND_BASE+NFCMMD_OFFSET) #defineELFIN_NAND_BASE 0x70200000 #defineNFCMMD_OFFSET 0x08 NFCMD_REG=(*( (volatileu32*) (0x70200008) )) NFCMMD 0x70200008 NANDFlash命令設置寄存器0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 | #define NAND_CMD_READSTART 0x30 */ if(large_block) NFCMD_REG=NAND_CMD_READSTART; /* define NF_TRANSRnB() do{ while( !( NFSTAT_REG&(1<<0) ) ); }while(0) #define NFSTAT_REG __REG(ELFIN_NAND_BASE+NFSTAT_OFFSET) NFSTAT_REG=(*( (volatileu32*) (0x70200028) )) NFSTAT 0x70200028 NANDFlash操作狀態寄存器 */ NF_TRANSRnB(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | /*forcompatibility(2460).u32cannotbeused.byscsuh*/ for(i=0;i { *buf++=NFDATA8_REG; } /* #defineNAND_DISABLE_CE()(NFCONT_REG|= (1<<1)) #defineNFCONT_REG __REG(ELFIN_NAND_BASE+NFCONT_OFFSET) #define__REG(x) (*((volatileu32*)(x))) #defineELFIN_NAND_BASE 0x70200000 #defineNFCONT_OFFSET 0x04 */ NAND_DISABLE_CE(); return0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | staticintnandll_read_blocks(ulongdst_addr,ulongsize,int large_block) { uchar*buf=(uchar*)dst_addr; inti; uintpage_shift=9; if(large_block==1) page_shift=11; /*Readpages*/ if(large_block==2) page_shift=12; if(large_block==2) { /*Readpages*/ for(i=0;i<4;i++,buf+=(1<<(page_shift-1))) { nandll_read_page(buf,i,large_block); } /*Readpages*/ /* 0x3c000 = 111100000000000000 */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 | for(i=4;i<(0x3c000>>page_shift);i++,buf+=(1< { nandll_read_page(buf,i,large_block); } } else { for(i=0;i<(0x3c000>>page_shift);i++,buf+=(1< { nandll_read_page(buf,i,large_block); } } return0; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | } intcopy_uboot_to_ram(void) { intlarge_block =0; inti; vu_charid; /* #defineNAND_ENABLE_CE() (NFCONT_REG&=~(1<<1)) #defineNFCONT_REG __REG(ELFIN_NAND_BASE+NFCONT_OFFSET) #define__REG(x) (*((volatileu32*)(x))) #defineELFIN_NAND_BASE 0x70200000 #defineNFCONT_OFFSET 0x04 NFCONT_REG=(*( (volatileu32*) (0x70200004) )) NFCONT0x70200004 讀/寫NANDFlash控制寄存器 [0]1:NANDFlash控制器使能 */ NAND_ENABLE_CE(); |
1 2 3 4 5 6 7 8 | /* #defineNFCMD_REG __REG(ELFIN_NAND_BASE+NFCMMD_OFFSET) #defineELFIN_NAND_BASE 0x70200000 #defineNFCMMD_OFFSET 0x08 NFCMD_REG=(*( (volatileu32*) (0x70200008) )) NFCMMD 0x70200008 NANDFlash命令設置寄存器0 #defineNAND_CMD_READID 0x90 |
1 2 3 4 5 6 7 8 9 10 11 | */ NFCMD_REG=NAND_CMD_READID; * #defineNFADDR_REG __REG(ELFIN_NAND_BASE+NFADDR_OFFSET) #defineELFIN_NAND_BASE 0x70200000 #defineNFADDR_OFFSET 0x0C NFADDR_REG =(*( (volatileu32*) (0x7020000C) )) NFADDR0x7020000C NANDFlash地址設置寄存器 */ NFADDR_REG= 0x00; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | /* #define NFDATA8_REG __REGb(ELFIN_NAND_BASE+NFDATA_OFFSET) #define__REGb(x) (*(vu_char*)(x)) NFDATA8_REG = (*( (vu_char*) (0x70200010) )) NFDATA0x70200010 讀/寫NANDFlash數據寄存器 NANDFlash 讀/燒寫數據值用于I/O */ /*waitforawhile*/ for(i=0;i<200;i++); id=NFDATA8_REG; id=NFDATA8_REG; if(id>0x80) large_block=1; if(id ==0xd5) large_block=2; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | /*readNANDBlock. *128KB->240KBbecauseofU-Bootsizeincrease.byscsuh *So,read0x3c000bytesnot0x20000(128KB). */ /* #define CONFIG_SYS_PHY_UBOOT_BASE (CONFIG_SYS_SDRAM_BASE+0x07e00000) #define CONFIG_SYS_SDRAM_BASE 0x50000000 CONFIG_SYS_PHY_UBOOT_BASE= 0x57e00000 0x3c000 = 1M */ returnnandll_read_blocks(CONFIG_SYS_PHY_UBOOT_BASE,0x3c000,large_block); } #endif |
1 |
1 | 修改u-boot-2010.03/cpu/arm1176/Makefile,在COBJS = cpu.o后面加nand_cp.o |
1 | COBJS = cpu.o nand_cp.o |
1 | 修改u-boot-2010.03/board/samsung/smdk6410/u-boot-nand.lds,添加nand_cp.o 如下: |
1 2 3 4 5 6 7 8 | { cpu/arm1176/start.o (.text) cpu/arm1176/s3c64xx/cpu_init.o (.text) board/samsung/smdk6410/lowlevel_init.o (.text) cpu/arm1176/nand_cp.o(.text) lib_arm/board.o (.text) *(.text) } |
上一篇:u-boot2010.03 移植篇(二)-----修改start.S,支持nand啟動
下一篇:u-boot2010.03 配置編譯目標分析
推薦閱讀最新更新時間:2025-04-23 17:58



設計資源 培訓 開發板 精華推薦
- 具有串行接口的 LTC2382-16、16 位、500ksps、低功耗 SAR ADC 的典型應用
- GAN switch test board
- Arduino Mini植物澆水出差寶
- NCV8871LVBGEVB,可調輸出非同步升壓控制器評估板
- 使用 Analog Devices 的 LT1584CT-3.45 的參考設計
- LT3970IDDB-5 5V 降壓轉換器的典型應用
- VIN = 2.5V 至 4.2V、VOUT = 5V、I 負載 = 100mA 時 ZXSC420 DC-DC 升壓開關控制器的典型應用
- LTC3623IUDD 12V 至 -1V、1MHz 降壓穩壓器的典型應用電路
- AM2F-2409SZ 9V 2 瓦 DC-DC 轉換器的典型應用
- LTC2945HUD-1 具有高達 200V 浪涌保護的堅固型 4V 至 70V 高壓側功率監視器的典型應用