移植u-boot12.04到jz2440 -->支持nandflash启动

u-boot2012.04支持nandflash

1. 重新添加#define CONFIG_CONFIG_CMD

    \drivers\mtd\nand
    下s3c2410_nand.c 拷贝为s3c2440_nand.c
    
     怎么决定编译s3c2440_nand.c 而不编译 s3c2410-nand.c
    
     看文件下的Makefile 找到相应的配置文件

      配置文件添加
      #define CONFIG_NAND_S3C2440
        #define CONFIG_SYS_S3C2440_NAND_HWECC
        
         Makefile中添加 以下代码
        
          COBJS-$(CONFIG_NAND_S3C2440) += s3c2440_nand.o   
          
          
     board_init_r
     #if defined(CONFIG_CMD_NAND)
        puts("NAND:  ");
        nand_init();        /* go init the NAND */
        #endif



                
    void nand_init(void)   Nand.c (drivers\mtd\nand
                nand_init_chip(i);
                            board_nand_init //设置nand_chip 结构体。提供底层函数
                                    nand->select_chip = NULL;
                                    nand->cmd_ctrl = s3c2440_hwcontrol;
                                    nand->dev_ready = s3c2440_dev_ready;
                                nand_scan
                                     nand_scan_ident
                                             nand_set_defaults(chip, busw);
                                                     chip->select_chip = nand_select_chip;
                                                     chip->cmdfunc = nand_command;
                                           nand_get_flash_type
                                                          chip->select_chip(mtd, 0);
                                                          chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
                                                                      nand_command (struct mtd_info *mtd, unsigned int command, int column, int page_addr)// 发地址,发命令
                                                                              chip->cmd_ctrl(mtd, command, ctrl);
                                                                                          s3c2440_hwcontrol  
                                                                                                      static void s3c2440_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
                                                                                                              
                                                                                      
                                                           chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1);
                                                          *maf_id = chip->read_byte(mtd);
                                                          *dev_id = chip->read_byte(mtd);


                                                        
                                                        
                                                    int board_nand_init(struct nand_chip *nand)
                                                                //初始化
                                                                cfg = ((tacls-1) <<12) |( (twrph0-1) << 8) | ((twrph1 - 1) << 4 );
                                                                writel(cfg, &nand_reg->nfconf);
                                                                /* 使能NAND Flash控制器, 初始化ECC, 禁止片选 */
                                                                //writel ((1<<4)|(1<<1)|(1<<0),nand_reg->nfcont);
                                                                writel ((1<<4)|(1<<1)|(1<<0),&nand_reg->nfcont);
                                                        
                                              
          s3c2440_hwcontrol 自己重写
                                                        
                                                            struct nand_chip *chip = mtd->priv;
                                                            struct s3c2440_nand *nand = s3c2440_get_base_nand();

                                                            if(ctrl & NAND_CLE)
                                                            {
                                                                /*发命令*/

                                                                writeb(dat,&nand->nfcmd);
                                                            }
                                                            else if(ctrl & NAND_ALE)
                                                            {
                                                                /*发地址*/
                                                                writeb(dat,&nand->nfaddr);// 地址
                                                            }
                                                                                                    
                                                            自己编写 s3c2440_nand_select 函数
                                                            
                                                            struct s3c2440_nand *nand = s3c2440_get_base_nand();

                                                            switch (chipnr) {
                                                            case -1: /*不选*/
                                                                nand->nfcont |= (1 <<1);
                                                                break;
                                                            case 0:  /*选中,没有进行操作*/
                                                                nand->nfcont &= ~(1 <<1);
                                                                break;

                                                            default:
                                                                BUG();
                                                            }
                                                            


                                                            
                                nor 启动
                         
           U-Boot 2012.04.01 (Jul 23 2016 - 13:18:18)

                                    CPUID: 32440001
                                    FCLK:      400 MHz
                                    HCLK:      100 MHz
                                    PCLK:       50 MHz
                                    DRAM:  64 MiB
                                    WARNING: Caches not enabled
                                    Flash: 2 MiB
                                    NAND:  256 MiB  //能够识别出 nand
                                    *** Warning - bad CRC, using default environment

                                    In:    serial
                                    Out:   serial
                                    Err:   serial
                                    Net:   CS8900-0
                                    
                                    
                                    nand erease 0 80000
                                    nand write 0 0 80000  0:nor 0 nand  80000 长度
                                    nand read 30000000 0 80000//3000000 读到哪里 0 从nand 0 开始读 80000 读的长度
                                    cmp.b 0 30000000
                                    
                                    
                                    U-Boot 2012.04.01 (Jul 23 2016 - 13:18:18)
                                nand 启动
                                CPUID: 32440001
                                FCLK:      400 MHz
                                HCLK:      100 MHz
                                PCLK:       50 MHz
                                DRAM:  64 MiB
                                WARNING: Caches not enabled
                                Flash: 0 KB  // nand 启动0 地址对应片内内存,无法读取 nor flash的值
                                NAND:  256 MiB
                                *** Warning - bad CRC, using default environment

                                In:    serial
                                Out:   serial
                                Err:   serial
                                Net:   CS8900-0
                                SMDK2410 #


你可能感兴趣的:(u-boot,分析,嵌入式,u-boot,移植)