天天看點

u-boot2012.04.01移植到mini2440

需要把mini2440的核心換成3.11的,在網上找到了這2篇文章,自己測試過可以使用,為了以後産看友善,轉載一下,感謝作者的無私分享,對我幫助很大,謝謝。

作者:angrad

原作網址:http://blog.chinaunix.net/uid-22609852-id-3515982.html

軟體平台: Windows XP, Ubuntu

硬體平台: mini2440

軟體: Source Insight、u-boot.2012.04.01 (官方下載下傳源碼)

一、uboot 啟動分析

 1.set the cpu to SVC32 mode(start.S)

 2.turn off the watchdog

 3.mask all IRQs by setting all bits in the INTMR

 4.設定分頻系數

 5.cpu_init_crit

        flush v4 I/D caches

        disable MMU stuff and caches

        lowlevel_init //setup RAM timing(lowlevel_init.S)

                設定BWSCON

        board_init_f //set sp, call board_init_f

                init_sequence (各種初始化)

                        ...

                        board_early_init_f

                        ...

                        serial_init

                        ...

二、嘗試

make smdk2410_config

make

成功生成的u-boot.bin并不能讓mini2440啟動

三、修改

  1.修改根目錄下boards.cfg在

  smdk2410                     arm         arm920t     -                   samsung        s3c24x0

  下添加一行

  mini2440                     arm         arm920t     -                   samsung        s3c24x0

 2.make mini2440_config

 3.複制include\configs\smdk2410.h為include\configs\mini2440.h

 4.cp board\samsung\smdk2410到board\samsung\mini2440

 5.從start.S裡可以看出,預設認為60Mhz的HCLK來設定記憶體控制器,才設定系統時鐘MPLL是有問題的。

     因為沒設定時鐘時,是以晶振的頻率運作的

     注釋掉(mini2440\smdk2410.c)int board_early_init_f(void)中的

                #if 0

                writel((M_MDIV << 12) + (M_PDIV << 4) + M_SDIV,

                 &clk_power->mpllcon);

                #endif

     start.S修改分頻設定

     ldr r0, =0x4C000014

     mov r1, #5

     str r1, [r0]

     将MPLL的設定放到start.S

     在分頻後加上

     mrc p15, 0, r1, c1, c0, 0  

     orr r1, r1, #0xc0000000

     mcr p15, 0, r1, c1, c0, 0

     #define S3C2440_MPLL_400MHZ     ((0x5c<<12)|(0x01<<4)|(0x01))

     ldr r0, =0x4c000004

     ldr r1, =S3C2440_MPLL_400MHZ

     str r1, [r0]

     mrc p15, 0, r0, c1, c0, 0 @ read control reg

     orr r0, r0, #(1<<12)

     mcr p15, 0, r0, c1, c0, 0   @ write it back

    6.修改設定BWSCON的SMRDATA(lowlevel_init.S)

     .long 0x22050000 //BWSCON

     .long 0x00000700 //BANKCON0

     .long 0x00000700 //BANKCON1

     .long 0x00000700 //BANKCON2

     .long 0x00000700 //BANKCON3

     .long 0x00000700 //BANKCON4

     .long 0x00000700 //BANKCON5

     .long 0x00018005 //BANKCON6

     .long 0x00018005 //BANKCON7

     .long 0x009803dc //REFRESH

     .long 0x000000B1 //BANKSIZE

     .long 0x00000030 //MRSRB6

     .long 0x00000030 //MRSRB7

     再次make,并燒寫u-boot.bin到nor flash,啟動後發現是亂碼,應該是序列槽波特率問題,看看序列槽初始化

u-boot2012.04.01移植到mini2440

     7.board.c (z:\u-boot-2012.04.01\arch\arm\lib\Board.c)

               serial_init(z:\u-boot-2012.04.01\drivers\serial\Serial_s3c24x0.c)

                   serial_init_dev

                          _serial_setbrg

                                 get_PCLK(z:\u-boot-2012.04.01\arch\arm\cpu\arm920t\s3c24x0\Speed.c)

                                        get_HCLK

                                        發現沒有定義CONFIG_S3C2440,它用2410的那套

     那麼在config中的mini2440.h中去掉#define CONFIG_S3C2410改成#define CONFIG_S3C2440

    make發現多個錯誤

     s3c2410_nand.c: In function 's3c2410_hwcontrol':

     s3c2410_nand.c:57: warning: implicit declaration of function 's3c2410_get_base_nand'

     s3c2410_nand.c:57: warning: initialization makes pointer from integer without a cast

     s3c2410_nand.c:72: error: dereferencing pointer to incomplete type

     s3c2410_nand.c:72: error: dereferencing pointer to incomplete type

     s3c2410_nand.c:75: error: dereferencing pointer to incomplete type

     s3c2410_nand.c:75: error: dereferencing pointer to incomplete type

     s3c2410_nand.c: In function 's3c2410_dev_ready':

     s3c2410_nand.c:85: warning: initialization makes pointer from integer without a cast

     s3c2410_nand.c:87: error: dereferencing pointer to incomplete type

     s3c2410_nand.c: In function 'board_nand_init':

     s3c2410_nand.c:129: warning: initialization makes pointer from integer without a cast

     s3c2410_nand.c:150: error: dereferencing pointer to incomplete type

     s3c2410_nand.c:153: error: dereferencing pointer to incomplete type

     s3c2410_nand.c:154: error: dereferencing pointer to incomplete type、

     s3c2410_nand.c找錯誤,發現是因為更改了#define CONFIG_S3C2440後,s3c2410_nand未定義

   暫且先讓序列槽輸出正常看看,去掉nand支援。

     [root: u-boot-2012.04.01]# grep "s3c2410_nand.o" * -nR 

    drivers/mtd/nand/Makefile:61:COBJS-$(CONFIG_NAND_S3C2410) += s3c2410_nand.o

     drivers/mtd/nand/.depend.s3c2410_nand:1:s3c2410_nand.o: s3c2410_nand.c \

     drivers/mtd/nand/.depend:341:s3c2410_nand.o: s3c2410_nand.c \

   [root: u-boot-2012.04.01]# vi drivers/mtd/nand/Makefile 

     找到

    COBJS-$(CONFIG_NAND_S3C2410) += s3c2410_nand.o

   現取消CONFIG_NAND_S3C2410的定義,在mini2440.h中發現

   #ifdef CONFIG_CMD_NAND

   #define CONFIG_NAND_S3C2410

   #define CONFIG_SYS_S3C2410_NAND_HWECC

   #define CONFIG_SYS_MAX_NAND_DEVICE 1

   #define CONFIG_SYS_NAND_BASE 0x4E000000

   #endif

   則注釋掉//#define CONFIG_CMD_NAND

   再編譯提示

   fs/yaffs2/libyaffs2.o: In function `yaffs_StartUp':

   /home/profiles/u-boot-2012.04.01/fs/yaffs2/yaffscfg.c:210: undefined reference to `nand_info'

   還是在mini2440.h中先注釋掉

   //#define CONFIG_YAFFS2

  再次make,并燒寫u-boot.bin到nor flash,啟動後發現Flash: *** failed ***,序列槽正常了,隻是flash還有問題

    8.為了去掉原u-boot複雜的重定位代碼,現自己寫重定位代碼,将init.c添加到board/samsung/mini2440下。修改

    board/samsung/mini2440/Makefile

    改COBJS   := smdk2410.o init.o

    init.c内容如下

點選(此處)折疊或打開

  1. #define NFCONF (*((volatile unsigned long *)0x4E000000))
  2. #define NFCONT (*((volatile unsigned long *)0x4E000004))
  3. #define NFCMMD (*((volatile unsigned char *)0x4E000008))    //注意是char* 不是long*,與下面保持一緻
  4. #define NFADDR (*((volatile unsigned char *)0x4E00000C))
  5. #define NFDATA (*((volatile unsigned char *)0x4E000010))
  6. #define NFSTAT (*((volatile unsigned char *)0x4E000020))
  7. void nand_read_ll(unsigned int addr, unsigned char *buf, unsigned int len);
  8. static int isNor()
  9. {
  10.     volatile int *p = (volatile int *)0;
  11.     int val;
  12.     val = *p;
  13.     *p = 0xfdfdfdfd;
  14.     if(0xfdfdfdfd == *p)    //可寫,證明是在SRAM中運作,即是從NAND啟動
  15.     {
  16.         *p = val;
  17.         return 0;
  18.      }
  19.      else     //寫NOR需要特定的指令時序
  20.     {
  21.         return 1;
  22.     }
  23. }
  24. void copy_to_sdram(unsigned char *src, unsigned char *dest, unsigned int len)
  25. {
  26.     int i = 0;
  27.     /* 判斷啟動方式 */
  28.     if (isNor())
  29.     {
  30.         while(i < len)
  31.         {
  32.             dest[i] = src[i];    //直接讀 NOR(view Figure 5-1. S3C2440A Memory Map after Reset)
  33.             i++;
  34.         }
  35.     }
  36.     else
  37.     {
  38.         nand_read_ll((unsigned int)src, dest, len);
  39.     }
  40. }
  41. void clear_bss(void)
  42. {
  43.     extern int __bss_start, __bss_end__;
  44.     int *p = &__bss_start;
  45.     for(; p<=&__bss_end__; p++)
  46.     {
  47.         *p = 0;
  48.     }
  49. }
  50. void nand_init_ll(void)
  51. {
  52. /* NFCONF
  53. TACLS [13:12] CLE & ALE duration setting value (0~3)
  54. = 0 Duration = HCLK x TACLSHCLK x TACLS (view K9F1208.pdf)
  55. TWRPH0 [10:8] TWRPH0 duration setting value (0~7)
  56.           Duration = HCLK x ( TWRPH0 + 1 ) = 25ns (view K9F1208.pdf) 1/135.75 = 7ns
  57. = 3 TWRPH0 >= 25 / 7 - 1 = 2.57
  58. TWRPH1 [6:4] TWRPH1 duration setting value (0~7)
  59.   Duration = HCLK x ( TWRPH1 + 1 ) = 10ns (view K9F1208.pdf)
  60. = 1     TWRPH1 >= 10 / 7 - 1 = 0.42
  61. */
  62.     #define TACLS 0
  63.     #define TWRPH0 3
  64.     #define TWRPH1 1
  65.     NFCONF = (TACLS<<12) | (TWRPH0<<8) | (TWRPH1<<4);
  66. /* NFCONT
  67. InitECC [4] Initialize ECC decoder/encoder(Write-only)
  68. = 1 Initialize ECC decoder/encoder
  69. Reg_nCE [1] NAND Flash Memory nFCE signal control
  70. = 1 Force nFCE to high (Disable chip select)
  71. MODE [0] NAND flash controller operating mode
  72. = 1 NAND flash controller enable
  73.  */
  74.     NFCONT = (1<<4) | (0<<1) | (1<<0);
  75. }
  76. static void nand_select(void)
  77. {
  78.     NFCONT &= ~(1<<1);
  79. }
  80. static void nand_deselect(void)
  81. {
  82.     NFCONT |= (1<<1);
  83. }
  84. static void nand_cmd(unsigned char cmd)
  85. {
  86.     volatile int i;
  87.     NFCMMD = cmd;
  88.     for (i = 0; i < 10; i++);
  89. }
  90. static void nand_addr(unsigned int addr)
  91. {
  92. /* Address(5Cycle)
  93. Col Add.1,2 & Row Add.1,2,3
  94. */
  95.     int col = addr % 2048;
  96.     int row = addr / 2048;
  97.     volatile int i;
  98.     NFADDR = col & 0xff;
  99.     for(i=0; i<10; i++);
  100.     NFADDR = (col>>8) & 0xff;
  101.     for(i=0; i<10; i++);
  102.     NFADDR = row & 0xff;
  103.     for(i=0; i<10; i++);
  104.     NFADDR = (row>>8) & 0xff;
  105.     for(i=0; i<10; i++);
  106.     NFADDR = (row>>16) & 0xff;
  107.     for(i=0; i<10; i++);
  108. }
  109. static void nand_wait(void)
  110. {
  111.     while(!(NFSTAT&1));
  112. }
  113. void nand_read_ll(unsigned int addr, unsigned char *dest, unsigned int len)
  114. {
  115.     int col = addr % 2048, i = 0;
  116.     nand_select();
  117.     while(i < len)
  118.     {
  119.         /* view K9K8G08U0A.pdf */
  120.         nand_cmd(0x00);
  121.         nand_addr(addr);
  122.         nand_cmd(0x30);
  123.         nand_wait();
  124.         for(; col<2048 && i<len; col++)
  125.         {
  126.             dest[i] = NFDATA;
  127.             i++;
  128.             addr++;
  129.         }
  130.         col = 0;
  131.      }
  132.     nand_deselect();
  133. }

    修改start.S

      #ifndef CONFIG_SKIP_LOWLEVEL_INIT

     bl cpu_init_crit

     #endif

     ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)

     bic sp, sp, #7

      bl nand_init_ll

     mov r0, #0

     //ldr r1, =_start

     ldr r1, _TEXT_BASE //CONFIG_SYS_TEXT_BASE = 0x33f00000

     ldr r2, _bss_start_ofs

      bl copy_to_sdram //copy_to_sdram(r0, r1, r2)

     bl clear_bss

      ldr pc, =call_board_init_f //遠跳轉

     call_board_init_f:

      ldr r0,=0x00000000

     bl board_init_f

    修改mini2440.h中 #define CONFIG_SYS_TEXT_BASE 0x33f80000

   自己寫了重定位,就去掉它寫的重定位函數

    注釋掉掉board.c中board_init_f中 //relocate_code(addr_sp, id, addr);

    删掉start.S中下面不需要的代碼

點選(此處)折疊或打開

  1. /*------------------------------------------------------------------                                                                                                                                        ------------*/
  2. /*                                                                                                                                        
  3.  * void relocate_code (addr_sp, gd, addr_moni)                                                                                                                                        
  4.  *                                                                                                                                        
  5.  * This "function" does not return, instead it continues in RAM                                                                                                                                        
  6.  * after relocating the monitor code.                                                                                                                                        
  7.  *                                                                                                                                        
  8.  */                                                                                                                                        
  9. .globl    relocate_code                                                                                                                                        
  10. relocate_code:                                                                                                                                        
  11. mov    r4, r0    /* save addr_sp */                                                                                                                                        
  12. mov    r5, r1    /* save addr of gd */                                                                                                                                        
  13. mov    r6, r2    /* save addr of destination */                                                                                                                                        
  14. /* Set up the stack     */                                                                                                                                        
  15. stack_setup:                                                                                                                                        
  16. mov    sp, r4                                                                                                                                        
  17. adr    r0, _start                                                                                                                                        
  18. cmp    r0, r6                                                                                                                                        
  19. beq    clear_bss     /* skip relocation */                                                                                                                                        
  20. mov    r1, r6     /* r1 <- scratch for copy_loop */                                                                                                                                        
  21. ldr    r3, _bss_start_ofs                                                                                                                                        
  22. add    r2, r0, r3     /* r2 <- source end address     */                                                                                                                                        
  23. copy_loop:                                                                                                                                        
  24. ldmia     {r9-r10}     /* copy from source address [r0] */                                                                                                                                        
  25. stmia     {r9-r10}     /* copy to target address [r1] */                                                                                                                                        
  26. cmp    r0, r2     /* until source end address [r2] */                                                                                                                                        
  27. blo    copy_loop                                                                                                                                        
  28. #ifndef CONFIG_SPL_BUILD                                                                                                                                        
  29. /*                                                                                                                                        
  30. * fix .rel.dyn relocations                                                                                                                                        
  31. */                                                                                                                                        
  32. ldr    r0, _TEXT_BASE     /* r0 <- Text base */                                                                                                                                        
  33. sub    r9, r6, r0     /* r9 <- relocation offset */                                                                                                                                        
  34. ldr    r10, _dynsym_start_ofs    /* r10 <- sym table ofs */                                                                                                                                        
  35. add    r10, r10, r0     /* r10 <- sym table in FLASH */                                                                                                                                        
  36. ldr    r2, _rel_dyn_start_ofs    /* r2 <- rel dyn start ofs */                                                                                                                                        
  37. add    r2, r2, r0     /* r2 <- rel dyn start in FLASH */                                                                                                                                        
  38. ldr    r3, _rel_dyn_end_ofs    /* r3 <- rel dyn end ofs */                                                                                                                                        
  39. add    r3, r3, r0     /* r3 <- rel dyn end in FLASH */                                                                                                                                        
  40. fixloop:                                                                                                                                        
  41. ldr    r0, [r2]     /* r0 <- location to fix up, IN */                                                                                                                                        
  42. add    r0, r0, r9     /* r0 <- location to fix up in RAM */                                                                                                                                        
  43. ldr    r1, [r2, #4]                                                                                                                                        
  44. and    r7, r1, #0xff                                                                                                                                        
  45. cmp    r7, #23     /* relative fixup? */                                                                                                                                        
  46. beq    fixrel                                                                                                                                        
  47. cmp    r7, #2     /* absolute fixup? */                                                                                                                                        
  48. beq    fixabs                                                                                                                                        
  49. /* ignore unknown type of fixup */                                                                                                                                        
  50. b    fixnext                                                                                                                                        
  51. fixabs:                                                                                                                                        
  52. /* absolute fix: set location to (offset) symbol value */                                                                                                                                        
  53. mov    r1, r1, LSR #4     /* r1 <- symbol index in .dynsym */                                                                                                                                        
  54. add    r1, r10, r1     /* r1 <- address of symbol in table */                                                                                                                                        
  55. ldr    r1, [r1, #4]     /* r1 <- symbol value */                                                                                                                                        
  56. add    r1, r1, r9     /* r1 <- relocated sym addr */                                                                                                                                        
  57. b    fixnext                                                                                                                                        
  58. fixrel:                                                                                                                                        
  59. /* relative fix: increase location by offset */                                                                                                                                        
  60. ldr    r1, [r0]                                                                                                                                        
  61. add    r1, r1, r9                                                                                                                                        
  62. fixnext:                                                                                                                                        
  63. str    r1, [r0]                                                                                                                                        
  64. add    r2, r2, #8     /* each rel.dyn entry is 8 bytes */                                                                                                                                        
  65. cmp    r2, r3                                                                                                                                        
  66. blo    fixloop                                                                                                                                        
  67. #endif                                                                                                                                        
  68. clear_bss:
  69. #ifndef CONFIG_SPL_BUILD
  70. ldr    r0, _bss_start_ofs
  71. ldr    r1, _bss_end_ofs
  72. mov    r4, r6     /* reloc addr */
  73. add    r0, r0, r4
  74. add    r1, r1, r4
  75. mov    r2, #0x00000000     /* clear     */
  76. clbss_l:str    r2, [r0]     /* clear loop...     */
  77. add    r0, r0, #4
  78. cmp    r0, r1
  79. bne    clbss_l
  80. bl coloured_LED_init
  81. bl red_led_on
  82. #endif

    因為第二階段函數board_init_f需要

    修改函數定義

    unsigned int board_init_f  (ulong);(common.h)

    unsigned int board_init_f(ulong bootflag) (arch/arm/lib/board.c)

    函數體最後加上

     return (unsigned int)id;

    傳回後給start.S的第二階段代碼用

    在start.S

    ldr r0,=0x00000000

    bl board_init_f

    後加上

    //board_init_f的傳回值在r0裡面,剛好把id傳給board_init_r

     ldr r1, _TEXT_BASE

     bl board_init_r

     vi arch/arm/config.mk 

    注釋掉

      #LDFLAGS_u-boot += -pie

    修改

    arch/arm/cpu/u-boot.lds添加 board/samsung/mini2440/libmini2440.o (.text)

        .text :

        {

             __image_copy_start = .;

             CPUDIR/start.o (.text)

              board/samsung/mini2440/libmini2440.o (.text)

             *(.text)

        }

    修改board.c

     //addr -= gd->mon_len;

     //addr &= ~(4096 - 1); 

      addr = CONFIG_SYS_TEXT_BASE;

      make後燒寫發現

u-boot2012.04.01移植到mini2440

    9.在SI中搜尋" Flash:“

    (z:\u-boot-2012.04.01\arch\arm\lib\Board.c)

    #if !defined(CONFIG_SYS_NO_FLASH)

    puts("Flash: ");

    繼續看

    if (flash_size > 0) {

        ...

    }else {

         puts(failed); //輸出*** failed ***

         hang(); //挂起

    }

    void hang(void)

    {

         puts("### ERROR ### Please RESET the board ###\n");

         for (;;); //死循環    

   }

    注釋掉 //hang();

    再次 make,并燒寫u-boot.bin到nor flash,發現uboot是啟動起來了不過flash和nand都不識别

u-boot2012.04.01移植到mini2440

    10.定義#define DEBUG (z:\u-boot-2012.04.01\include\configs\Mini2440.h)

    友善調試

u-boot2012.04.01移植到mini2440

    11.找nor的識别問題

    從圖中 JEDEC PROBE: ID 1 2249 0和代碼(z:\u-boot-2012.04.01\drivers\mtd\Cfi_flash.c)

     debug("JEDEC PROBE: ID %x %x %x\n",

     info->manufacturer_id,

     info->device_id,

     info->device_id2);

  可以看出 manufacturer_id是 1, device_id是 2249, device_id2是 0

    flash_init (z:\u-boot-2012.04.01\drivers\mtd\Cfi_flash.c)

        flash_detect_legacy

            // match jedec ids against table. If a match is found, fill flash_info entry

            jedec_flash_match (z:\u-boot-2012.04.01\drivers\mtd\Jedec_flash.c)

                if (( jedec_table[i].mfr_id & mask) == (info->manufacturer_id & mask) &&

                    ( jedec_table[i].dev_id & mask) == (info->device_id & mask)) {

                        fill_info(info, &jedec_table[i], base);

                        ret = 1;

                        break;

                }

                可以看到manufacturer_id、device_id都要和 jedec_table中的資訊比對。

                添加mini2440用的nor flash資訊(需要檢視晶片手冊Am29LV160DB.pdf)

                 {

                     .mfr_id = 1,

                     .dev_id = 0x2249,

                     .name = "Am29LV160DB",

                     .uaddr = {

                         [1] = MTD_UADDR_0x0555_0x02AA

                     },

                     .DevSize = SIZE_2MiB,

                     .CmdSet = CFI_CMDSET_AMD_LEGACY,

                     .NumEraseRegions = 4,

                     .regions = {

                         ERASEINFO(0x04000, 1),

                         ERASEINFO(0x02000, 2),

                         ERASEINFO(0x08000, 1),

                         ERASEINFO(0x10000, 31),

                     }

             },

u-boot2012.04.01移植到mini2440

    取消DEBUG定義(看之前的DEBUG資訊足以),再次編譯燒寫

    12.提示Flash: ERROR: too many flash sectors

    搜尋發現#define CONFIG_SYS_MAX_FLASH_SECT (19)  //(z:\u-boot-2012.04.01\include\configs\Mini2440.h)

    修改大一點#define CONFIG_SYS_MAX_FLASH_SECT (128)

    make燒寫,Flash:2 MiB.

u-boot2012.04.01移植到mini2440

    13.修改棧指針

    start.S中加上

     .globl base_sp

     base_sp:

     .long 0 

    start_code: 

    .....

     ldr r1, _TEXT_BASE

     ldr sp, base_sp

     bl board_init_r

    在board.c的board_init_f加上

     extern ulong base_sp;

    ...

    memcpy(id, (void *)gd, sizeof(gd_t));

     base_sp = addr_sp;

     //relocate_code(addr_sp, id, addr);

    14.加上nand的支援

    在mini2440.h中取消注釋

     #define CONFIG_CMD_NAND

    make出錯,拷貝drivers/mtd/nand/s3c2410_nand.c複制為 s3c2440_nand.c

    修改mini2440.h

    #ifdef CONFIG_CMD_NAND

     #ifdef CONFIG_S3C2410

     #define CONFIG_NAND_S3C2410

     #define CONFIG_SYS_S3C2410_NAND_HWECC

     #else

     #define CONFIG_NAND_S3C2440

     #define CONFIG_SYS_S3C2440_NAND_HWECC

     #endif

    #define CONFIG_SYS_MAX_NAND_DEVICE 1

    #define CONFIG_SYS_NAND_BASE 0x4E000000

    #endif

    修改 drivers/mtd/nand/Makefile

    加上

    COBJS-$(CONFIG_NAND_S3C2410) += s3c2410_nand.o

     COBJS-$(CONFIG_NAND_S3C2440) += s3c2440_nand.o

    修改s3c2440_nand.c中的s3c2410_nand為s3c2440_nand(除了宏)

    包括 s3c2440_dev_ready、 s3c2440_hwcontrol、 s3c2440_get_base_nand

    從nand_init開始看

     nand_init_chip

             board_nand_init

                 ...

                tacls = 4;

                twrph0 = 8;

                twrph1 = 8;

                   #endif

                   cfg = S3C2410_NFCONF_EN;

                   cfg |= S3C2410_NFCONF_TACLS(tacls - 1);

                   cfg |= S3C2410_NFCONF_TWRPH0(twrph0 - 1);

                   cfg |= S3C2410_NFCONF_TWRPH1(twrph1 - 1);

                   writel(cfg, &nand_reg->nfconf);

                   cfg = ((tacls-1)<<12) | ((tacls-1)<<8) | ((tacls-1)<<4);

                   writel(cfg, &nand_reg->nfconf);

                    writel((1<<4) | (0<<1) | (1<<0), &nand_reg->nfcont);

                    ...

                      nand->select_chip = NULL;

                     //修改為 nand->select_chip = s3c2440_select_nand;

                     自己寫

                                    static void s3c2440_select_nand(struct mtd_info *mtd, int chipnr)

                                    {

                                         struct s3c2440_nand *nand = s3c2440_get_base_nand();

                                         switch (chipnr) {

                                               case -1: //-1 for deselect

                                                     nand->nfcont |= 1<<1;

                                                     break;

                                               case 0: //0 for select

                                                     nand->nfcont &= ~(1<<1);

                                                     break;

                                               default:

                                                     BUG();

                                        }

                                     }

                         nand->cmd_ctrl = s3c2440_hwcontrol;

                                   //修改s3c2410_hwcontrol,根據ctrl判斷是發指令還是位址

                                   static void s3c2410_hwcontrol(struct mtd_info *mtd, int dat, unsigned int ctrl)

                                   {

                                         struct s3c2440_nand *nand = s3c2440_get_base_nand();

                                         debug("hwcontrol(): 0x%02x 0x%02x\n", dat, ctrl);

                                         if (ctrl & NAND_CLE)

                                         {

                                               writeb(dat, &nand->nfcmd);

                                         }

                                         else if (ctrl & NAND_ALE)

                                         {

                                               writeb(dat, &nand->nfaddr);

                                         }

                                   }

                                   ...

                             nand_scan

                                       nand_scan_ident

                                             nand_set_defaults

                                                 if (chip->cmdfunc == NULL)

                                                     chip->cmdfunc = nand_command; //static void nand_command(struct mtd_info *mtd, unsigned int command, int column, int page_addr)

                                                 if (!chip->select_chip)

                                                      chip->select_chip = nand_select_chip;

                                             nand_get_flash_type

                                                 chip->select_chip(mtd, 0);

                                                 chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1);

                                                 <=> nand_command

                                                        chip->cmd_ctrl(mtd, readcmd, ctrl);

                                                        <=> s3c2410_hwcontrol;

                           nand_register

                                   add_mtd_device

      make後nand可以正常使用了

    15.mini2440用dm9000網卡,搜尋drivers/net/Makefile 可以發現

     COBJS-$(CONFIG_DRIVER_DM9000) += dm9000x.o

    由mini2440.h中的宏CONFIG_DRIVER_DM9000控制,并且從上面結果可以看到,需要去掉cs8900的宏.

     #if 0

     #define CONFIG_CS8900

     #define CONFIG_CS8900_BASE 0x19000300

     #define CONFIG_CS8900_BUS16

     #else

     #define CONFIG_DRIVER_DM9000

     #endif

     make看看結果

     dm9000x.c: In function 'dm9000_outblk_8bit':

     dm9000x.c:156: error: 'DM9000_DATA' undeclared (first use in this function)

     dm9000x.c:156: error: (Each undeclared identifier is reported only once

     dm9000x.c:156: error: for each function it appears in.)

     dm9000x.c: In function 'dm9000_outblk_16bit':

     dm9000x.c:165: error: 'DM9000_DATA' undeclared (first use in this function)

     dm9000x.c: In function 'dm9000_outblk_32bit':

     dm9000x.c:173: error: 'DM9000_DATA' undeclared (first use in this function)

     dm9000x.c: In function 'dm9000_inblk_8bit':

     dm9000x.c:180: error: 'DM9000_DATA' undeclared (first use in this function)

     dm9000x.c: In function 'dm9000_inblk_16bit':

     dm9000x.c:189: error: 'DM9000_DATA' undeclared (first use in this function)

     dm9000x.c: In function 'dm9000_inblk_32bit':

     dm9000x.c:197: error: 'DM9000_DATA' undeclared (first use in this function)

     dm9000x.c: In function 'dm9000_rx_status_32bit':

     dm9000x.c:204: error: 'DM9000_IO' undeclared (first use in this function)

     dm9000x.c:206: error: 'DM9000_DATA' undeclared (first use in this function)

     dm9000x.c: In function 'dm9000_rx_status_16bit':

     dm9000x.c:213: error: 'DM9000_IO' undeclared (first use in this function)

     dm9000x.c:215: error: 'DM9000_DATA' undeclared (first use in this function)

     dm9000x.c: In function 'dm9000_rx_status_8bit':

     dm9000x.c:221: error: 'DM9000_IO' undeclared (first use in this function)

     dm9000x.c:224: error: 'DM9000_DATA' undeclared (first use in this function)

     dm9000x.c: In function 'dm9000_probe':

     dm9000x.c:243: error: 'CONFIG_DM9000_BASE' undeclared (first use in this function)

     dm9000x.c: In function 'dm9000_send':

     dm9000x.c:420: error: 'DM9000_IO' undeclared (first use in this function)

     dm9000x.c: In function 'dm9000_rx':

     dm9000x.c:484: error: 'DM9000_DATA' undeclared (first use in this function)

     dm9000x.c: In function 'DM9000_ior':

     dm9000x.c:574: error: 'DM9000_IO' undeclared (first use in this function)

     dm9000x.c:575: error: 'DM9000_DATA' undeclared (first use in this function)

     dm9000x.c: In function 'DM9000_iow':

     dm9000x.c:584: error: 'DM9000_IO' undeclared (first use in this function)

     dm9000x.c:585: error: 'DM9000_DATA' undeclared (first use in this function)

     make[1]: *** [dm9000x.o] Error 1

     make[1]: Leaving directory `/home/profiles/u-boot-2012.04.01/drivers/net'

     make: *** [drivers/net/libnet.o] Error 2

    報錯

     grep "DM9000_DATA" * -nR參考其他開發闆

     include/configs/M5253DEMO.h:95:# define DM9000_DATA (CONFIG_DM9000_BASE + 4)

    定義了

      #   define CONFIG_DM9000_BASE   (CONFIG_SYS_CS1_BASE | 0x300)

      #   define DM9000_IO        CONFIG_DM9000_BASE

      #   define DM9000_DATA      (CONFIG_DM9000_BASE + 4)

    則在mini2440.h上加上這些宏,并把值參照原理圖晶片手冊,DM9000接片選4即bank4,由2440手冊知0x20000000是bank4的基址修改過來為:

     #define CONFIG_DM9000_BASE   0x20000000

     #define DM9000_IO        CONFIG_DM9000_BASE

     #define DM9000_DATA      (CONFIG_DM9000_BASE + 4) //LADDR2開始接到DM9000上

    記憶體控制器初始化已經在lowlevel.S中設定過為

     SMRDATA:

     .long 0x22050000 //BWSCON

     make燒寫從nor啟動,發現 Net:   No ethernet found.

u-boot2012.04.01移植到mini2440

    16.在source insight中搜尋“ No ethernet found.”找出原因

     eth_initialize (board.c)

         board_eth_init (mini2440/smdk2410.c)

             cs8900_initialize此處不合适,添加DM9000的函數

             #ifdef CONFIG_CS8900

             rc = cs8900_initialize(0, CONFIG_CS8900_BASE);

             #endif

             #ifdef CONFIG_DRIVER_DM9000

             rc = dm9000_initialize(bis);

             #endif

    再次 make燒寫來試驗網絡功能

     set ipaddr 169.254.252.201 (連上網線同自己要ping的機器在一個網段)

     set serverip 169.254.252.200

     set gatewayip 255.255.0.0  (同自己要ping的機器一緻)

     set ethaddr 08:00:27:71:89:bb

     ping 169.254.252.200 通了

u-boot2012.04.01移植到mini2440

    自行測試下tftp的下載下傳功能。

     tftp 30000000 uImage

    發面 bootm 30000000後不能啟動linux,在解壓後停住了。應該是開發闆型号沒修改

    修改board_init(board.c)中

     gd->bd->bi_arch_number = MACH_TYPE_SMDK2410;為

     gd->bd->bi_arch_number = MACH_TYPE_MINI2440;

    再次tftp下載下傳後bootm就啟動了

    17.環境變量

    開發闆燒寫u-boot後,發現 *** Warning - bad CRC, using default environment

    SI搜尋一下。

     set_default_env

         default_environment

            #ifdef CONFIG_BOOTARGS

                "bootargs=" CONFIG_BOOTARGS "\0"

            #ifdef CONFIG_BOOTCOMMAND

                "bootcmd=" CONFIG_BOOTCOMMAND "\0"

    在mini2440.h中加上

     #define CONFIG_BOOTARGS "console=ttySAC0 root=/dev/mtdblock3"

     #define CONFIG_BOOTCOMMAND "nand read 30000000 0x60000 0x500000;bootm 30000000"

    修改

     #define CONFIG_NETMASK 255.255.0.0

     #define CONFIG_IPADDR 169.254.252.201

     #define CONFIG_SERVERIP 169.254.252.200

    加上

     #define CONFIG_ETHADDR 08:00:27:71:89:bb

    18.裁剪

    在mini2440.h找不需要的宏

     #if 0

     #define CONFIG_USB_OHCI

     #define CONFIG_USB_KEYBOARD

     #define CONFIG_USB_STORAGE

     #define CONFIG_DOS_PARTITION

     #endif

     //#define CONFIG_RTC_S3C24X0

     #if 0

     #define CONFIG_BOOTP_BOOTFILESIZE

     #define CONFIG_BOOTP_BOOTPATH

     #define CONFIG_BOOTP_GATEWAY

     #define CONFIG_BOOTP_HOSTNAME

     #endif

     //#define CONFIG_CMD_USB

     //#define CONFIG_CMD_DATE

     //#define CONFIG_CMD_DHCP

     #if 0

     #define CONFIG_CMD_FAT

     #define CONFIG_CMD_EXT2

     #define CONFIG_CMD_UBI

     #define CONFIG_CMD_UBIFS

     #define CONFIG_CMD_MTDPARTS

     #define CONFIG_MTD_DEVICE

     #define CONFIG_MTD_PARTITIONS

     #define CONFIG_YAFFS2

     #define CONFIG_RBTREE

     #endif

    裁剪後 make發現

    u-boot.bin的大小為 204344B小了很多

    19.環境變量預設存在nor,為了讓u-boot裡面的saveenv指令将環境變量儲存到nand,且不能破壞核心,需要修改儲存的位置。

    在SI中搜尋 "saveen v",找到env_nand.c檔案,到Makefile中找尋它所依賴的宏.

     vi common/Makefile,發現它依賴于CONFIG_ENV_IS_IN_NAND

    (mini2440.h)修改

     #if 0

     #define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x070000)

     #define CONFIG_ENV_IS_IN_FLASH

     #define CONFIG_ENV_SIZE 0x10000

     #define CONFIG_ENV_OVERWRITE

     #endif

    添加

     #define CONFIG_ENV_IS_IN_NAND

    在env_nand.c中找到宏CONFIG_ENV_OFFSET,這個制定存在nand的哪個位址

    需要看看原核心的分區。

    在我使用的2.6.32.2源代碼中發現

    static struct mtd_partition friendly_arm_default_nand_part[] = {

        [0] = {

            .name = "supervivi",

            .size = 0x00040000,

            .offset = 0,

        },

        [1] = {

            .name = "param",

            .offset = 0x00040000,

            .size = 0x00020000,

        },

        [2] = {

            .name = "Kernel",

            .offset = 0x00060000,

            .size = 0x00500000,

        },

        [3] = {

            .name = "root",

            .offset = 0x00560000,

            .size = 1024 * 1024 * 1024, //

        },

        [4] = {

            .name = "nand",

            .offset = 0x00000000,

            .size = 1024 * 1024 * 1024, //

        }

    };

    (或者啟動核心後發現)

u-boot2012.04.01移植到mini2440

    參數存在0x40000開始的0x20000大小處

    則加定義(mini2440.h)

     #define CONFIG_ENV_OFFSET 0x40000

     #define CONFIG_ENV_SIZE 0x20000

     #define CONFIG_ENV_RANGE CONFIG_ENV_SIZE //擦除機關

     make後燒寫nor

    此時還有 *** Warning - bad CRC, using default environment

    在u-boot裡執行 save指令重新開機就行了

    u-boot倒計時5秒如果沒有執行的話,就會執行我們設定的

    #define CONFIG_BOOTCOMMAND " nand read 30000000 0x60000 0x500000;bootm 30000000"

    即從nand flash 0x60000的地方讀0x500000的資料(整個核心)到記憶體0x30000000的地方,然後從0x30000000啟動核心。

     于是我們必須先将uImage燒寫到0x60000的地方: 

    先下載下傳 tftp 30000000 uImage

     nand erase 60000 500000

     nand write 30000000 60000 500000 //這樣60000的地方就有了可啟動的核心

    下次重新開機開發闆,5秒延時之後将自動讀核心并加載運作

    20.代替繁瑣的數字

    在board.c的board_init_r中加上

     run_command("mtdparts default", 0); //必須讓uboot執行這條指令

     for (;;) {

     main_loop();

     }

    在mini2440中定義宏

     #define CONFIG_CMD_MTDPARTS

    參照其它開發闆再添加上

      #define CONFIG_MTD_DEVICE

    #define MTDIDS_DEFAULT "nand0=mini2440-0"

     #define MTDPARTS_DEFAULT "mtdparts=mini2440-0:256k(u-boot)," \

                                                        "128k(params)," \

                                                        "5m(kernel)," \

                                                        "-(rootfs)" \ //-餘下的所有給rootfs

     make後提示發現drivers\mtd\mtdcore.c中的 get_mtd_device_nm未定義。

    則可以直接去drivers\mtd\Makefile中檢視哪個宏決定是否編譯成mtdcore.o

    或者 grep "mtdcore.o" * -nR發現是CONFIG_MTD_DEVICE控制的

    将宏添加到mini2440.h

     #define CONFIG_MTD_DEVICE

    再次 make并燒寫

    在uboot執行指令 mtdparts

u-boot2012.04.01移植到mini2440

    現在可以嘗試用名字代替數字的分區表示,如

     tftp 30000000 uImage

     nand erase.part kernel

     nand write 30000000 kernel

    此版對于yaffs的一個小bug

    drivers/mtd/nand/nand_util.c (nand_write_skip_bad)中

    改為

    ops.len = pagesize;

    ops.ooblen = nand->oobsize;

    ops.mode = MTD_OOB_RAW ;

   ops.ooboffs = 0;

    pages = write_size / pagesize_oob;

    for (page = 0; page < pages; page++) {

    WATCHDOG_RESET();

    ops.datbuf = p_buffer;

    ops.oobbuf = ops.datbuf + pagesize;

    rval = nand->write_oob(nand, offset, &ops);

    if ( rva l)

   break;

    offset += pagesize;

    p_buffer += pagesize_oob;

    }

    if (!need_skip && !(flags & WITH_DROP_FFS)) {

    改為

     if (!need_skip && !(flags & WITH_DROP_FFS) && !(flags & WITH_YAFFS_OOB)) {

之前的核心都是用 nfs檔案系統。

如果想用jffs2或者yaffs應該執行下列指令

燒寫JFFS2

tftp 30000000 fs.jffs2

nand erase.part rootfs

nand write.jffs2 30000000 0x00260000 5b89a8

set bootargs console=ttySAC0 root=/dev/mtdblock3 rootfstype=jffs2

燒寫YAFFS(需要先在mini2440中重新 #define CONFIG_CMD_NAND_YAFFS再編譯)

tftp 30000000 fs.yaffs2

nand erase.part rootfs

nand write.yaffs 30000000 260000  889bc0 //檔案大小

用uboot更新自身

tftp 30000000 u-boot_new.bin; protect off all; erase 0 3ffff; cp.b 30000000 0 40000

移植完後制作更新檔

mv u-boot-2012.04.01 u-boot-2012.04.01_ok

tar xjf u-boot-2012.04.01.tar.bz2

diff -urN u-boot-2012.04.01 u-boot-2012.04.01_ok > u-boot-2012.04.01.patch

打更新檔

cd u-boot-2012.04.01

patch -p1 < ../u-boot-2012.04.01.patch  //因為現在所在u-boot-2012.04.01目錄,-p1 數字表示忽略第一個斜杠

u-boot2012.04.01移植到mini2440

[email protected]

編譯新uboot

make mini2440_config

make