免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1803 | 回复: 0
打印 上一主题 下一主题

U-boot实现NOR FLASH启动 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-08-09 15:59 |只看该作者 |倒序浏览
起始工作就不多说了,本篇主要介绍U-boot的nor flash启动。
修改如下:
(include/configs/.h):
添加:
#define CONFIG_SST_39VF1601   1
#define CFG_MAX_FLASH_BANKS 1
#define PHYS_FLASH_SIZE       0x200000   /* 2MB */
#define CFG_MAX_FLASH_SIZE    (512)       /* max number of sectors on one chip */
#define CFG_ENV_ADDR (CFG_FLASH_BASE + 0x40000)   /* addr of environment */
并将关于AM29LV400和AM29LV800的信息全部注释掉。
NOR FLASH的操作函数在board/fs2410/flash.c中实现。它支持AM29LV400和AM29LV800.为了了解NORFLASH的操作,我们直接修改这个文件。首先我们的板子已经有了一个U-BOOT,但由于烧写的问题,我们这里启动一个调试方法,具体就是在配置文件include/configs/fs2410.h里定义:
#define CONFIG_SKIP_LOWLEVEL_INIT,这个宏用于cpu/arm920t/start.S里,主要是对CPU和存储控制器的初始化,所以调试阶段跳过初始化。然后修改board/fs2410/config.mk:
将TEXT_BASE = 0x33F80000暂时修改为:
TEXT_BASE = 0x33E00000。最后将u-boot.bin下载到这个地址,然后 从这个地址启动u-boot即可。
修改以上步骤以后,接下来我们修改board/fs2410/flash.c:
将:
#define MAIN_SECT_SIZE 0x10000 /* 64 KB */
修改为:
#define MAIN_SECT_SIZE 0x1000 /* 4 KB */(按sector操作)
将:
#define MEM_FLASH_ADDR1     (*(volatile u16 *)(CFG_FLASH_BASE + (0x00000555 flash_id & FLASH_VENDMASK) !=
        (AMD_MANUFACT & FLASH_VENDMASK)) {
        return ERR_UNKNOWN_FLASH_VENDOR;
修改为:if ((info->flash_id & FLASH_VENDMASK) !=
        (SST_MANUFACT & FLASH_VENDMASK)) {
        return ERR_UNKNOWN_FLASH_VENDOR;
阅读弄SST39VF1601使用手册,我们对flash_erase()修改如下:
....
if (info->protect[sect] == 0) {      /* not protected */
                     vu_short *addr = (vu_short *) (info->start[sect]);
                     MEM_FLASH_ADDR1 = CMD_UNLOCK1;
                     MEM_FLASH_ADDR2 = CMD_UNLOCK2;
                     MEM_FLASH_ADDR1 = CMD_ERASE_SETUP;

                     MEM_FLASH_ADDR1 = CMD_UNLOCK1;
                     MEM_FLASH_ADDR2 = CMD_UNLOCK2;
                     *addr = CMD_ERASE_CONFIRM;

                     /* wait until flash is ready */
                     while(1){
                            unsigned short i;
                            i = *((volatile unsigned short *)addr)&0x40;
                            if(i!=*((volatile unsigned short *)addr)&0x40)
                                   continue;
                            if(*((volatile unsigned short *)addr)&0x80)  
                                   break;
                     }
                     printf ("ok.\n");
              } else {   /* it was protected */
                     printf ("protected!\n");
              }
       }
       if (ctrlc ())
........
对flash_hword()修改如下:
volatile static int write_hword (flash_info_t * info, ulong dest, ushort data)
{
       vu_short *addr = (vu_short *) dest;
       ushort result;
       int rc = ERR_OK;
       int cflag, iflag;
       int chip;

       /*
        * Check if Flash is (sufficiently) erased
        */
       result = *addr;
       if ((result & data) != data)
              return ERR_NOT_ERASED;

       /*
        * Disable interrupts which might cause a timeout here. Remember that our exception
* vectors are at address 0 in the flash, and we don't want a (ticker) exception to happen
* while the flash chip is in programming mode.
        */
       cflag = icache_status ();
       icache_disable ();
       iflag = disable_interrupts ();

       MEM_FLASH_ADDR1 = CMD_UNLOCK1;
       MEM_FLASH_ADDR2 = CMD_UNLOCK2;
       MEM_FLASH_ADDR1 = CMD_PROGRAM;
       *addr = data;

       /* arm simple, non interrupt dependent timer */
       reset_timer_masked ();

       /* wait until flash is ready */
       while(1){
              unsigned short i = *(volatile unsigned short *)addr & 0x40;
              if(i != *(volatile unsigned short *)addr & 0x40)   //D6 == D6
                     continue;
              if((*(volatile unsigned short *)addr & 0x80)==(data & 0x80)){
                     rc = ERR_OK;
                     break;     //D7 == D7
              }
       }
       if (iflag)
              enable_interrupts ();
       if (cflag)
              icache_enable ();
       return rc;
}
到此为止,NOR FLASH支持基本修改完毕!
相关连接:
http://blog.chinaunix.net/u2/63379/showart_1330720.html


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/102829/showart_2022584.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP