⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flashdev.c

📁 完整的Bell实验室的嵌入式文件系统TFS
💻 C
字号:
/* This file contains all of the flash support code that does not need   to be relocated to RAM.  Two separate files (flash.c and flashpic.c)   are maintained because under certain compilers, they may need to be   compiled with different options to be made position independent.   NOTE: THESE FUNCTIONS ARE NOT RE-ENTRANT!!!  All of the FLASH routines   assume they can copy themselves into the array FlashFunc[]; hence, only   one operation can be active at any time.*/#include "config.h"#if INCLUDE_FLASH#include "cpu.h"#include "flashdev.h"#include "flash.h"typedef unsigned char uchar;typedef unsigned short ushort;typedef unsigned long ulong;typedef volatile unsigned char vuchar;typedef volatile unsigned short vushort;typedef volatile unsigned long vulong;typedef volatile unsigned int vuint;typedef volatile int vint;extern int FLASHTYPE();extern int ENDFLASHTYPE();extern int FLASHWRITE();extern int ENDFLASHWRITE();extern int FLASHEWRITE();extern int ENDFLASHEWRITE();extern int FLASHERASE();extern int ENDFLASHERASE();/* FlashXXXFbuf[]:   These arrays will contain the flash operation function that is executing.   Recall that to operate on the flash, you cannot be executing out of it.   The flash functions are copied here, then executed through the function   pointer flashfunc which is set to point to FlashFunc.*/ulong    FlashTypeFbuf[FLASHFUNCSIZE];ulong    FlashEraseFbuf[FLASHFUNCSIZE];ulong    FlashWriteFbuf[FLASHFUNCSIZE];ulong    FlashEwriteFbuf[FLASHFUNCSIZE];/* FlashBank[]:   This structure contains all of the information that must be made available   to the various flash operation commands.  It is initialized by flashtype()   and used thereafter by the other operations.*/struct  flashinfo FlashBank[FLASHBANKS];/* FlashNamId[]:   Used to correlate between the ID and a string representing the name   of the flash device.  */struct flashdesc FlashNamId[] = {        { AMD29LV160B_X16, "AMD-29LV160B (2 devices in x16 mode)" },         { SWAPPED_AMD29LV160B_X16, "AMD-29LV160B (2 devices in x16 mode)" },         { AMD29LV160T_X16, "AMD-29LV160T (2 devices in x16 mode)" },        { SWAPPED_AMD29LV160T_X16, "AMD-29LV160T (2 devices in x16 mode)" },        { AMD29LV160B_X8, "AMD-29LV160B (4 devices in x8 mode)" },         { SWAPPED_AMD29LV160B_X8, "AMD-29LV160B (4 devices in x8 mode)" },         { AMD29LV160T_X8, "AMD-29LV160T (4 devices in x8 mode)" },        { SWAPPED_AMD29LV160T_X8, "AMD-29LV160T (4 devices in x8 mode)" },        { AMD29DL323DT_X16, "AMD-29DL323DT (2 devices in x16 mode)" },         { SWAPPED_AMD29DL323DT_X16, "AMD-29DL323DT (2 devices in x16 mode)" },         { AMD29DL323DB_X16, "AMD-29DL323DB (2 devices in x16 mode)" },        { SWAPPED_AMD29DL323DB_X16, "AMD-29DL323DB (2 devices in x16 mode)" },        { AMD29DL323DT_X8, "AMD-29DL323DT (4 devices in x8 mode)" },         { SWAPPED_AMD29DL323DT_X8, "AMD-29DL323DT (4 devices in x8 mode)" },         { AMD29DL323DB_X8, "AMD-29DL323DB (4 devices in x8 mode)" },        { SWAPPED_AMD29DL323DB_X8, "AMD-29DL323DB (4 devices in x8 mode)" },        { AMD29F016D_X8, "AMD-29F016D (4 devices in x8 mode)" },        { SWAPPED_AMD29F016D_X8, "AMD-29F016D (4 devices in x8 mode)" },        { 0,    (char *)0 },};/* Sectors:    These table reflects the sizes of each sector of a flash device.    This this configuration is for a single device, whether it's    in x8 mode or x16 mode.  To get the size of each sector, multiply    each entry by the number of devices.  In an x32 configuration,    there are either 2 devices in x16 mode or 4 devices in x8 mode.*/int Amd29lv160_sects[] = {  /* AMD29LV160 */        0x4000, 0x2000, 0x2000, 0x8000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000};int Amd29dl323dt_sects[] = {    /* AMD29DL323DT */        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000,        0x2000, 0x2000, 0x2000, 0x2000,        0x2000, 0x2000, 0x2000, 0x2000};int Amd29dl323db_sects[] = {    /* AMD29DL323DB */        0x2000, 0x2000, 0x2000, 0x2000,        0x2000, 0x2000, 0x2000, 0x2000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000};int Amd29f016d_sects[] = {  /* AMD29F016D */        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000,        0x10000, 0x10000, 0x10000, 0x10000};struct sectDesc {    int num;    int *size;} Sectors[FLASH_TYPES] = {    { sizeof(Amd29lv160_sects)/sizeof(int), Amd29lv160_sects },    { sizeof(Amd29dl323dt_sects)/sizeof(int), Amd29dl323dt_sects },    { sizeof(Amd29dl323db_sects)/sizeof(int), Amd29dl323db_sects },    { sizeof(Amd29f016d_sects)/sizeof(int), Amd29f016d_sects }};/* Increase the size of sinfo if you ever encounter a device with * more than 100 sectors. */struct sectorinfo sinfo[100];/* FlashInit():   Initialize data structures for each bank of flash...*/intFlashInit(){    int i, snum;    uchar   *begin;    long    size;    struct  flashinfo *fbnk;    long    flash_dev_size;    int flash_type, retval;    snum = 0;    FlashCurrentBank = 0;    fbnk = &FlashBank[0];    fbnk->base = (unsigned char *)FLASH_BANK0_BASE_ADDR;    /* Copy functions to ram space... */    /* Note that this MUST be done when cache is disabled to assure that */    /* the RAM is occupied by the designated block of code. */    /* NOTE: If we are running out of RAM, then no copy is done and     * flashopload returns FLASH_OPS_IN_RAM to indicate this. This     * allows us to avoid a potential cache coherency problem.     */    if (flashopload((ulong *)FLASHTYPE,(ulong *)ENDFLASHTYPE,        FlashTypeFbuf,sizeof(FlashTypeFbuf)) < 0)        return(-1);    if (flashopload((ulong *)FLASHERASE,(ulong *)ENDFLASHERASE,        FlashEraseFbuf,sizeof(FlashEraseFbuf)) < 0)        return(-1);    if (flashopload((ulong *)FLASHWRITE,(ulong *)ENDFLASHWRITE,        FlashWriteFbuf,sizeof(FlashWriteFbuf)) < 0)        return(-1);    if (flashopload((ulong *)FLASHEWRITE,(ulong *)ENDFLASHEWRITE,        FlashEwriteFbuf,sizeof(FlashEwriteFbuf)) < 0)        return(-1);    fbnk->fltype = (int(*)())FlashTypeFbuf;         /* flashtype(). */    fbnk->flerase = (int(*)())FlashEraseFbuf;       /* flasherase(). */    fbnk->flwrite = (int(*)())FlashWriteFbuf;       /* flashwrite(). */    fbnk->flewrite = (int(*)())FlashEwriteFbuf;     /* flashewrite(). */    /* Call this function only after fbnk->base and fbnk->fltype     * have been initialized.     */    fbnk->id = fbnk->fltype(fbnk);    /* Initialize parameters based on the device you have */    switch(fbnk->id) {        case SWAPPED_AMD29LV160T_X16:        case SWAPPED_AMD29LV160B_X16:        case AMD29LV160T_X16:        case AMD29LV160B_X16:        case SWAPPED_AMD29LV160T_X8:        case SWAPPED_AMD29LV160B_X8:        case AMD29LV160T_X8:        case AMD29LV160B_X8:            flash_type = AMD29LV160;            flash_dev_size = 0x200000;  /* In bytes */            break;        case SWAPPED_AMD29DL323DT_X16:        case SWAPPED_AMD29DL323DT_X8:        case AMD29DL323DT_X16:        case AMD29DL323DT_X8:            flash_type = AMD29DL323DT;            flash_dev_size = 0x400000;  /* In bytes */            fbnk->sectorcnt = sizeof(Amd29dl323dt_sects)/sizeof(int);            break;        case SWAPPED_AMD29DL323DB_X16:        case SWAPPED_AMD29DL323DB_X8:        case AMD29DL323DB_X16:        case AMD29DL323DB_X8:            flash_type = AMD29DL323DB;            flash_dev_size = 0x400000;  /* In bytes */            break;        case SWAPPED_AMD29F016D_X8:        case AMD29F016D_X8:            flash_type = AMD29F016D;            flash_dev_size = 0x200000;  /* In bytes */            break;        default:            return -1;    }    fbnk->sectorcnt = Sectors[flash_type].num;    fbnk->end = fbnk->base + (flash_dev_size * FLASH_DEV_COUNT) - 1;    fbnk->width = FLASH_BANK0_WIDTH;    fbnk->sectors = sinfo;    begin = fbnk->base;        for(i=0;i<fbnk->sectorcnt;i++,snum++) {        int ssize;        ssize = Sectors[flash_type].size[i] * FLASH_DEV_COUNT;        fbnk->sectors[i].snum = snum;        fbnk->sectors[i].size = ssize;        fbnk->sectors[i].begin = begin;        fbnk->sectors[i].end =            fbnk->sectors[i].begin + ssize - 1;        fbnk->sectors[i].protected = 0;        begin += ssize;    }#if 0    /* Assume monitor resides in bank0 and that it uses the first 128K */    /* of code space (actually it uses much less, but different options */    /* within the monitor are configurable, so assume worst case). */    /* These "monitor-owned" sectors should be marked as protected. */    size = 0;    for (i=0;((i<FlashBank[0].sectorcnt)&(size<FLASH_PROTECT_SIZE));i++) {        FlashBank[0].sectors[i].protected = 1;        size += FlashBank[0].sectors[i].size;    }    /* Assume that another monitor (eg, the one that came with the     * 3rd party board) resides at the end of flash (at the end     * of the last bank).     */    size = 0;    for (i=FlashBank[FLASHBANKS-1].sectorcnt-1;        size < FLASH_PROTECT_SIZE_OTHER; i--) {            FlashBank[FLASHBANKS-1].sectors[i].protected = 1;        size += FlashBank[FLASHBANKS-1].sectors[i].size;    }#else    sectorProtect(FLASH_PROTECT_RANGE,1);#endif    /* Additional flash memory banks would be initialized here... */    return(0);}#endif INCLUDE_FLASH

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -