日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/1/21 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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文件,修改:

  • 把:
    #define FLASH_BLOCK_SIZE??? ??? 0x00010000
    改為:
    #define FLASH_BLOCK_SIZE??? ????0x00020000
  • 把聲明:
    static ?int ? ?write_short? ?(flash_info_t *info, ulong dest, ushort data);//并刪除這個函數體
    改為:
    static ? ?int ? ? ?write_word ? ? (flash_info_t *info, ulong dest, ushort data);??
  • 刪除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


    總結

    以上是生活随笔為你收集整理的FL2440的U-boot-2009.08移植(三)支持Nor FLASH的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。