u-boot2009,norflash移植

  1. 开发板的配置文件fl2440.h/include/configs/fl2440.h)修改配置

    /*-------------------------------------------------------------------

    * FLASH and environment organization

    */

    #define CONFIG_SYS_MONITOR_BASE TEXT_BASE

    #define FLASH_BASE0_PRELIM PHYS_FLASH_1

    #define CONFIG_SYS_FLASH_PROTECTION 1

    #define CFG_MAX_FLASH_BANKS 1

    #define CONFIG_SYS_FLASH_SIZE 0x00400000

    #define CONFIG_SYS_MAX_FLASH_SECT 32

     

    #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_ENV_IS_IN_FLASH 1

    #define CONFIG_ENV_SIZE 0x20000

    #define CONFIG_ENV_OFFSET 0x40000

    /*----------------------------------------------------------------*/

     

  2. 把开发板目录下flash.c文件替换成下面的/board/cmi/下面的flash.c文件,然后删除这个write_short函数的申明和定义、删除write_buff函数。替换成下面的两个函数

     

    /*

    * Copy memory to flash, returns:

    * 0 - OK

    * 1 - write timeout

    * 2 - Flash not erased

    * 4 - Flash not identified

    */

    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);

     

    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;

    }

     

    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;

    }

     

    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;

     

     

    if ((*addr & data) != data)

    return ERR_NOT_ERASED;

     

    flag = disable_interrupts();

    *addr = 0x50;

    *addr = 0x40;

    *addr = data;

    reset_timer_masked();

    while(((val = *addr) & 0x80) != 0x80)

    {

    if (get_timer_masked() > CONFIG_SYS_FLASH_WRITE_TOUT) {

    rc = ERR_TIMOUT;

     

    *addr = 0xB0;

    goto outahere;

    }

    }

    if(val & 0x1A) {

    printf("nFlash write error x at address lxn",

    (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:

     

    *addr = 0xFF;

    if (flag)

    enable_interrupts();

    return rc;

    }

     

    1. 修改board/fl2440/flash.c中函数申明:

      static ulong flash_get_size (vu_short *addr, flash_info_t *info);

      //static int write_short (flash_info_t *info, ulong dest, ushort data);

      static int write_word (flash_info_t *info, ulong dest, ushort data);

      static void flash_get_offsets (ulong base, flash_info_t *info);
      1. 开发板的配置文件flash.h/include/flash.h)修改配置

     

    #define FLASH_28F320J3D 0x00C0        /* INTEL 28F320J3A ( 32M = 128K x 32)    */

    #define FLASH_28F640J3D 0x00C2        /* INTEL 28F640J3A ( 64M = 128K x 64)    */

    #define FLASH_28F128J3D 0x00C4        /* INTEL 28F128J3A (128M = 128K x 128)    */

    #define FLASH_28F256J3D 0x00C6        /* INTEL 28F256J3A (256M = 128K x 256)    */

    (原来是a)

     

    #define INTEL_ID_28F320J3D 0x00160016    /* 32M = 128K x 32    */

    #define INTEL_ID_28F640J3D 0x00170017    /* 64M = 128K x 64    */

    #define INTEL_ID_28F128J3D 0x00180018    /* 128M = 128K x 128    */

     

    以及将/board/fl2440/flash.c 中涉及的这两项修改。

        

  3. 修改flash.c文件中的一个宏定义:
    把:
    #define FLASH_BLOCK_SIZE        0x00010000
    改为:
    #define FLASH_BLOCK_SIZE        0x00020000
posted on 2012-11-23 13:48  WithYouTh  阅读(291)  评论(0编辑  收藏  举报