FL2440的U-boot-2009.08移植(三)支持Nor FLASH

简介:

如果没有Nor FLASH的同学可以跳过这一章节,直接进行下一张节。如果遇到什么问题,一般都是你没有定义那个宏之类的,这个问题可以很好的额解决。


修改norflash(nor fhash型号:JS28F320)的配置,把include/configs/fl2440.h中关于“Physical Memory Map”和“FLASH and environment organization”的配置都删掉,换成下面的配置:

  • /*-----------------------------------------------------------------------
     * Physical Memory Map
     */
    #define CONFIG_NR_DRAM_BANKS 1   /* we have 1 bank of DRAM */
    #define PHYS_SDRAM_1 0x30000000 /* SDRAM Bank #1 */
    #define PHYS_SDRAM_1_SIZE 0x04000000 /* 64 MB */

    #define PHYS_FLASH_1 0x00000000 /* Flash Bank #1 */
    #define CONFIG_SYS_FLASH_BASE PHYS_FLASH_1
    #define CONFIG_SYS_MONITOR_BASE   TEXT_BASE
    #define FLASH_BASE0_PRELIM        PHYS_FLASH_1

    /*-----------------------------------------------------------------------
     * FLASH and environment organization
     */
    #if 0
    #define CONFIG_AMD_LV400 1/* uncomment this if you have a LV400 flash */
    #define CONFIG_AMD_LV800 1/* uncomment this if you have a LV800 flash */
    #endif

    #define CONFIG_SYS_MAX_FLASH_BANKS 1/* max number of memory banks */
    #define CONFIG_JS2_8F320  1
    #define CONFIG_SYS_FLASH_PROTECTION   1
    #define CONFIG_SYS_FLASH_SIZE    0x00400000    /*4 MB*/
    #define CONFIG_SYS_MAX_FLASH_SECT    32         /*max number of sectors on one chip*/

  • /* timeout values are in ticks */
    #define CONFIG_SYS_FLASH_ERASE_TOUT(2*CONFIG_SYS_HZ) /* Timeout for Flash Erase */
    #define CONFIG_SYS_FLASH_WRITE_TOUT(2*CONFIG_SYS_HZ) /* Timeout for Flash Write */

    #defineCONFIG_ENV_IS_IN_FLASH1
    #define CONFIG_ENV_SIZE0x40000/* Total Size of Environment Sector,这是256K的环境变量储存空间 */
    #define CONFIG_ENV_OFFSET  0x100000  //在以后的内核分区中环境变量分区的OFFSET值要与此一致
    #endif/* __CONFIG_H */

修改board/samsung/fl2440/lowlevel_init.S文件中SDARM刷新参数

  #define REFCNT   1258


修改flash型号相关文件,用board/cmi/flash.c文件替换board/samsung/ofl2440/flash.c文件,使uboot支持Intel的JS28F320型号nor fhash.

打开board/samsung/fl2440/flash.c文件,修改:

  1. 把:
    #define FLASH_BLOCK_SIZE        0x00010000
    改为:
    #define FLASH_BLOCK_SIZE        0x00020000
  2. 把声明:
    static  int    write_short   (flash_info_t *info, ulong dest, ushort data);//并删除这个函数体
    改为:
    static    int      write_word     (flash_info_t *info, ulong dest, ushort data);  
  3. 删除write_buff和write_short两个函数,用下面两个函数代替:
    int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt)
    {
       ulong cp, wp;
       ushort data;
       int l;
       int i, rc;


       wp = (addr & ~1);        /* get lower word aligned address */


       /*
        * handle unaligned start bytes
        */
       if ((l = addr - wp) != 0)
       {
          data = 0;
          for (i=0, cp=wp; i<l; ++i, ++cp) {
           data = (data >> 8) | (*(uchar *)cp << 8);
          }
          for (; i<2 && cnt>0; ++i) {
         data = (data >> 8) | (*src++ << 8);
         --cnt;
         ++cp;
          }
          for (; cnt==0 && i<2; ++i, ++cp) {
         data = (data >> 8) | (*(uchar *)cp << 8);
          }


          if ((rc = write_word(info, wp, data)) != 0) {
         return (rc);
          }
          wp += 2;
       }


       /*
        * handle word aligned part
        */
       while (cnt >= 2) {
          data = *((vu_short*)src);
          if ((rc = write_word(info, wp, data)) != 0) {
          return (rc);
          }
          src += 2;
          wp  += 2;
          cnt -= 2;
       }


       if (cnt == 0) {
          return ERR_OK;
       }


       /*
        * handle unaligned tail bytes
        */
       data = 0;
       for (i=0, cp=wp; i<2 && cnt>0; ++i, ++cp) {
          data = (data >> 8) | (*src++ << 8);
          --cnt;
       }
       for (; i<2; ++i, ++cp) {
          data = (data >> 8) | (*(uchar *)cp << 8);
       }


       return write_word(info, wp, data);
    }

    /*
     * Write 16 bit (short) to flash
     */

    static int write_word (flash_info_t *info, ulong dest, ushort data)
    {
       vu_short *addr = (vu_short *)dest, val;
       int rc = ERR_OK;
       int flag;


       /* Check if Flash is (sufficiently) erased , fix by kavin*/
       if ((*addr & 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.
        */
       flag = disable_interrupts();


       /* clear status register command */
       *addr = 0x50;


       /* program set-up command */
       *addr = 0x40;


       /* latch address/data */
       *addr = data;


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


       /* wait while polling the status register */
       while(((val = *addr) & 0x80) != 0x80)
       {
          if (get_timer_masked() > CONFIG_SYS_FLASH_WRITE_TOUT) {
          rc = ERR_TIMOUT;
          /* suspend program command */
          *addr = 0xB0;
          goto outahere;
          }
       }


       if(val & 0x1A) {        /* check for error */
          printf("\nFlash write error %02x at address %08lx\n",
               (int)val, (unsigned long)dest);
          if(val & (1<<3)) {
         printf("Voltage range error.\n");
         rc = ERR_PROG_ERROR;
         goto outahere;
          }
          if(val & (1<<1)) {
         printf("Device protect error.\n");
         rc = ERR_PROTECTED;
         goto outahere;
          }
          if(val & (1<<4)) {
         printf("Programming error.\n");
         rc = ERR_PROG_ERROR;
         goto outahere;
          }
          rc = ERR_PROG_ERROR;
          goto outahere;
       }


    outahere:
       /* read array command */
       *addr = 0xFF;


       if (flag)
          enable_interrupts();


       return rc;
    }

到目前为止我们还不能用tftp来下载文件,因为我们还没有移植DM9000网卡。

至此,uboot就能完会支持从nor flash启动,编译生成新的u-boot.bin并通过DNW的USB线下载到SDRAM中运行,便可看到u-boot检测到了我们的flash。用flinfo命令可以看 到具体的块信息,还可以用flash的各种命令对flash进行操作,从而实现这块nor flash驱动的完全支持。烧写当然也是没问题的了,把需要烧写的文件下载到SDRAM中后,用cp.b命令就可以了

下面大该分析一下这个驱动文件的函数调用,此flash.c文件中有如下几个函数:


static ulong  flash_get_size         (vu_short *addr, flash_info_t *info);
static void     flash_get_offsets     (ulong base, flash_info_t *info);
static int        write_word (flash_info_t *info, ulong dest, ushort data)

unsigned long flash_init (void)
void flash_print_info  (flash_info_t *info)
int flash_erase (flash_info_t *info, int s_first, int s_last)
int flash_real_protect(flash_info_t *info, long sector, int prot)
int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt)


      1.u-boot启动只会用到flash.c文件中的flash_init函数,正如上面所述;
      2.以static修饰的3个函数只在flash.c文件中被调用;
      3.最后面的4个函数会被/common/cmd_flash.c文件中的函数调用,以实现u-boot下的各种命令操作。


 附:若用JLINK下载u-boot.bin到nor flash 中,需要把/include/configs/fl2440.h 中定义的以下这个宏注释掉:

       /* #define CONFIG_SKIP_RELOCATE_UBOOT    1  */   注释掉u-boo才能初始化CPU


目录
相关文章
|
算法 调度 UED
深入理解操作系统内存管理:原理与实践
【4月更文挑战第23天】 在现代计算机系统中,操作系统的内存管理是保证系统高效、稳定运行的关键组成部分。本文旨在深入探讨操作系统中内存管理的理论基础、关键技术以及实际操作过程,通过对内存分配策略、虚拟内存技术、分页与分段机制等核心概念的详细解析,为读者提供一个清晰、全面的内存管理视角。此外,文章还将通过案例分析,展示内存管理在解决实际问题中的应用,以期加深读者对操作系统内存管理复杂性的认识和理解。
|
Ubuntu Linux Windows
Linux开发环境配置详细过程--正点原子阿尔法开发板
Linux开发环境配置详细过程--正点原子阿尔法开发板
836 0
|
存储 NoSQL 算法
从一个crash问题展开,探索gcc编译优化细节
问题分析的过程也正是技术成长之路,本文以一个gcc编译优化引发的crash为切入点,逐步展开对编译器优化细节的探索之路,在分析过程中打开了新世界的大门……
|
监控 NoSQL
JLink + GDB 调试方法
本节主要介绍嵌入式开发中常用的JLink+GDB调试方法。 调试所需软件 J-link,可以从https://www.segger.com下载对应操作系统的软件包,然后安装(注意:segger是仿真器的名字,相当常用的一款,仿真器的接口也是固定的,一般开发版上都会带有这个调试接口,如图) 运行JLinkGDBServer 按照上图中的配置,配置GDBServer,然后点击OK,进入下一个界面 注意,如果硬件连接没有问题,那么上图中的J-Link和 Device栏中显示绿色,GDB显示为红色,因为我们还没有运行GDB软件。
8454 46
|
Linux 开发者 云计算
linux内核符号表kallsyms简介
在使用perf排查问题时,我们经常会发现[kernel.kallsyms]这个模块。这到底是个什么东西呢?
19871 0
Idea单步调试快速跳过后面的断点-Mute Breakpoints 快速清空所有的断点
https://zhengyz.blog.csdn.net/article/details/128072266?spm=1001.2014.3001.5502
Idea单步调试快速跳过后面的断点-Mute Breakpoints 快速清空所有的断点
|
12月前
|
Shell 开发工具 git
上传文件到gitee(小白都能学会)
上传文件到gitee(小白都能学会)
2720 12
|
物联网 编译器 测试技术
【嵌入式 交叉编译器】如何在 ARM 架构下选择和使用高版本交叉编译器
【嵌入式 交叉编译器】如何在 ARM 架构下选择和使用高版本交叉编译器
1382 7
|
Unix Linux 数据处理
Linux命令stty详解
`stty`是Linux命令,用于设置和查看终端参数,如波特率、字符处理和控制字符。它直接与终端驱动交互,支持多种选项以适应不同的配置需求。例如,`stty -a`显示当前设置,`stty -echo`关闭回显,`stty 115200 cs8`调整波特率和字符大小。注意修改设置可能影响终端行为,建议先备份(`stty -g`)并谨慎操作。查阅手册页以获取详细信息。

热门文章

最新文章