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

📄 cfiscs.c

📁 MPC8560 for vxwork BSP
💻 C
📖 第 1 页 / 共 5 页
字号:
    if (flashPtr[0x20] == 0x51 && /* 'Q' */        flashPtr[0x21] == 0x51 && /* 'Q' */        flashPtr[0x22] == 0x52 && /* 'R' */        flashPtr[0x23] == 0x52 && /* 'R' */        flashPtr[0x24] == 0x59 && /* 'Y' */        flashPtr[0x25] == 0x59)   /* 'Y' */        {        /* Let's try turning one off */        CFI_WORD_WRITE((FlashWPTR)(&flashPtr[0x55]), READ_ARRAY);        if (flashPtr[0x20] != 0x51) /* Turned off successfully */            {            thisCFI->multiplier = 2;            thisCFI->interleaveFactor = 1;            vol.interleaving =2;            vol.type = (FlashType) ((flashWPtr[0] << 8) | flashWPtr[1]);            vol.write = cfiscsByteWrite;            vol.erase = cfiscsErase;#ifdef DEBUG_PRINT            DEBUG_PRINT ("Debug: detected two 8 bit devices\n");#endif            goto getCFI;            }        }#endif  /* 0 */    /* a 16 bit device in 16 bit mode */    if (flashPtr[0x20] == 0x51 && /* 'Q' */        flashPtr[0x21] == 0x00 && /* NUL */        flashPtr[0x22] == 0x52 && /* 'R' */        flashPtr[0x23] == 0x00 && /* NUL */        flashPtr[0x24] == 0x59 && /* 'Y' */        flashPtr[0x25] == 0x00)   /* NUL */        {        thisCFI->multiplier = 2;        thisCFI->interleaveFactor = 1;        vol.interleaving = 1;        vol.type = (FlashType) ((flashWPtr[0] << 8) | (flashWPtr[1]));        vol.write = cfiscsWordWrite;        vol.erase = cfiscsErase;#ifdef DEBUG_PRINT        DEBUG_PRINT ("Debug: detected one 16 bit device\n");#endif        goto getCFI;        }    /* If we have a 16 bit device in 8 bit mode it should ID correctly */    if (flashPtr[0x20] == 0x51 && /* 'Q' */        flashPtr[0x21] == 0x51 && /* 'Q' */        flashPtr[0x22] == 0x52 && /* 'R' */        flashPtr[0x23] == 0x52 && /* 'R' */        flashPtr[0x24] == 0x59 && /* 'Y' */        flashPtr[0x25] == 0x59)   /* 'Y' */        {        thisCFI->multiplier = 2;#ifdef DEBUG_PRINT        DEBUG_PRINT ("Debug: detected a 16 bit device in 8 bit mode\n");#endif        vol.interleaving =1;        thisCFI->interleaveFactor = 1;        vol.type = (FlashType) ((flashWPtr[0] << 8) | flashWPtr[1]);        vol.write = cfiscsByteWrite;        vol.erase = cfiscsErase;        goto getCFI;        }    /* Reset to READ_ARRAY and retry. Maybe 32 bit addressing      */    flashWPtr[0x55] = (USHORT) ((READ_ARRAY << 8) | READ_ARRAY);     flashDPtr[0x55] = (ULONG) (QUERY << 24| QUERY <<16 | QUERY << 8 | QUERY);     /* A 32 bit device in 8 bit mode and two 16 bit device in 8 bit mode will     * appear the same to the query process. The only way to make the     * distinction is to try and set one device back to read array mode while     * the other remains in query mode      */    if (flashPtr[0x40] == 0x51 && /* 'Q' */        flashPtr[0x41] == 0x51 && /* 'Q' */        flashPtr[0x42] == 0x51 && /* 'Q' */        flashPtr[0x43] == 0x51 && /* 'Q' */        flashPtr[0x44] == 0x52 && /* 'R' */        flashPtr[0x45] == 0x52 && /* 'R' */        flashPtr[0x46] == 0x52 && /* 'R' */        flashPtr[0x47] == 0x52 && /* 'R' */        flashPtr[0x48] == 0x59 && /* 'Y' */        flashPtr[0x49] == 0x59 && /* 'Y' */        flashPtr[0x4a] == 0x59 && /* 'Y' */        flashPtr[0x4b] == 0x59)   /* 'Y' */        {        /* See if we can turn one off */        flashPtr[0x154] = READ_ARRAY;        if ((flashPtr[0x40] != 0x51) && (flashPtr[0x41] == 0x51))            {   /* Turned one device off successfully */            flashPtr[0x154] = QUERY;    /* turn it back on to query mode */            vol.interleaving = 2;            vol.type = (FlashType) ((flashWPtr[0] << 8) | (flashWPtr[4]));#ifdef DEBUG_PRINT            DEBUG_PRINT ("Debug: detected two 16 bit device, 8 bit interleaved(2)\n");#endif            }        else            {            vol.interleaving =1;#ifdef DEBUG_PRINT            DEBUG_PRINT ("Debug: detected a 32 bit device in 8 bit mode\n");#endif            vol.type = (FlashType) ((flashDPtr[0] << 8) | flashDPtr[1]);            }        thisCFI->multiplier = 4;        thisCFI->interleaveFactor = 1;        vol.write = cfiscsByteWrite;        vol.erase = cfiscsErase;        goto getCFI;        }    /* Is it a single 32 bit device */    if (flashPtr[0x40] == 0x51 && /* 'Q' */        flashPtr[0x41] == 0x00 && /* NUL */        flashPtr[0x42] == 0x00 && /* NUL */        flashPtr[0x43] == 0x00 && /* NUL */        flashPtr[0x44] == 0x52 && /* 'R' */        flashPtr[0x45] == 0x00 && /* NUL */        flashPtr[0x46] == 0x00 && /* NUL */        flashPtr[0x47] == 0x00 && /* NUL */        flashPtr[0x48] == 0x59 && /* 'Y' */        flashPtr[0x49] == 0x00 && /* NUL */        flashPtr[0x4a] == 0x00 && /* NUL */        flashPtr[0x4b] == 0x00)   /* NUL */        {#ifdef DEBUG_PRINT        DEBUG_PRINT ("Debug: detected a 32 bit device in 32 bit mode\n");#endif        thisCFI->multiplier = 4;        thisCFI->interleaveFactor = 1;        vol.interleaving = 1;        vol.type = (FlashType) ((flashDPtr[0] << 8) | flashDPtr[1]);        vol.write = cfiscsDWordWrite;        vol.erase = cfiscsErase;        goto getCFI;        }    /* Two 16 bit devices in 16 bit mode */    if (flashPtr[0x40] == 0x51 && /* 'Q' */        flashPtr[0x41] == 0x00 && /* NUL */        flashPtr[0x42] == 0x51 && /* 'Q' */        flashPtr[0x43] == 0x00 && /* NUL */        flashPtr[0x44] == 0x52 && /* 'R' */        flashPtr[0x45] == 0x00 && /* NUL */        flashPtr[0x46] == 0x52 && /* 'R' */        flashPtr[0x47] == 0x00 && /* NUL */        flashPtr[0x48] == 0x59 && /* 'Y' */        flashPtr[0x49] == 0x00 && /* NUL */        flashPtr[0x4a] == 0x59 && /* 'Y' */        flashPtr[0x4b] == 0x00)   /* NUL */        {#ifdef DEBUG_PRINT        DEBUG_PRINT ("Debug: Detected two 16 bit devices in 16 bit mode(3)\n");#endif        thisCFI->multiplier = 4;        thisCFI->interleaveFactor = 2;        vol.interleaving = 2;        vol.type = (FlashType) (flashPtr[0] << 8 |                                 flashPtr[thisCFI->multiplier]);        vol.write = cfiscsInterleavedWordWrite;        vol.erase = cfiscsErase;        goto getCFI;        }    /* Reset to READ_ARRAY and retry. Maybe 64 bit addressing */    flashDPtr[0x55] = (ULONG) ((READ_ARRAY << 24) | (READ_ARRAY << 16) |                               (READ_ARRAY << 8) | READ_ARRAY);    flashDPtr[0xaa] = (ULONG) (QUERY << 24| QUERY <<16 | QUERY << 8 | QUERY);    /* Four 16 bit device in 8 bit mode or two 16 bit device in 16 bit mode     * among others, will appear the same. Let's not tell them apart     * for the moment, just because we know what is there.      */    taskDelay (10);    /* Is it four interleaved 8 bit devices */    if (flashPtr[0x80] == 0x51 && /* 'Q' */        flashPtr[0x81] == 0x51 && /* 'Q' */        flashPtr[0x82] == 0x51 && /* 'Q' */        flashPtr[0x83] == 0x51 && /* 'Q' */        flashPtr[0x84] == 0x51 && /* 'Q' */        flashPtr[0x85] == 0x51 && /* 'Q' */        flashPtr[0x86] == 0x51 && /* 'Q' */        flashPtr[0x87] == 0x51 && /* 'Q' */        flashPtr[0x88] == 0x52 && /* 'R' */        flashPtr[0x89] == 0x52 && /* 'R' */        flashPtr[0x8a] == 0x52 && /* 'R' */        flashPtr[0x8b] == 0x52 && /* 'R' */        flashPtr[0x8c] == 0x52 && /* 'R' */        flashPtr[0x8d] == 0x52 && /* 'R' */        flashPtr[0x8e] == 0x52 && /* 'R' */        flashPtr[0x8f] == 0x52 && /* 'R' */        flashPtr[0x90] == 0x59 && /* 'Y' */        flashPtr[0x91] == 0x59 && /* 'Y' */        flashPtr[0x92] == 0x59 && /* 'Y' */        flashPtr[0x93] == 0x59 && /* 'Y' */        flashPtr[0x94] == 0x59 && /* 'Y' */        flashPtr[0x95] == 0x59 && /* 'Y' */        flashPtr[0x96] == 0x59 && /* 'Y' */        flashPtr[0x97] == 0x59)   /* 'Y' */        {        /* workaround for wrSbc85xx */#ifdef DEBUG_PRINT        DEBUG_PRINT ("Debug: detected four 8 bit devices in 32 bit mode\n");#endif        thisCFI->multiplier = 8;        thisCFI->interleaveFactor = 4;        vol.interleaving = 4;        vol.type = (FlashType) ((flashDPtr[0] << 8) | flashDPtr[1]);        vol.write = cfiscsDWordWrite;        vol.erase = cfiscsDWordErase;        goto getCFI;        }    /* If we get here the device is probably not CFI */#ifdef DEBUG_PRINT    DEBUG_PRINT ("Debug: Failed to identify CFI... \n Exiting \n");#endif    flashDPtr[0xaa] = (ULONG) (READ_ARRAY << 24| READ_ARRAY <<16                                | READ_ARRAY << 8 | READ_ARRAY);     return flUnknownMedia;    getCFI:    /* check the command set ID */    thisCFI->commandSetId = flashPtr[0x13 * thisCFI->multiplier] |                             ((unsigned)flashPtr[0x14 * thisCFI->multiplier] << 8);    if (thisCFI->commandSetId != INTEL_COMMAND_SET &&        thisCFI->commandSetId != AMDFUJ_COMMAND_SET)        {#ifdef DEBUG_PRINT        DEBUG_PRINT("Debug: did not recognize command set.\n");#endif        return flUnknownMedia;        }    /* get address for primary algorithm extended table. */    primaryTable = flashPtr[0x15 * thisCFI->multiplier] |                   ((unsigned)flashPtr[0x16 * thisCFI->multiplier] << 8);    /* check alternate command set ID. */    thisCFI->altCommandSetId = flashPtr[0x17 * thisCFI->multiplier] |                                ((unsigned)flashPtr[0x18 * thisCFI->multiplier] << 8);    if (thisCFI->altCommandSetId != INTEL_ALT_COMMAND_SET &&        thisCFI->altCommandSetId != AMDFUJ_ALT_COMMAND_SET &&        thisCFI->altCommandSetId != ALT_NOT_SUPPORTED)        return flUnknownMedia;    /* get address for secondary algorithm extended table. */    secondaryTable = flashPtr[0x19 * thisCFI->multiplier] |                     ((unsigned)flashPtr[0x1a * thisCFI->multiplier] << 8);    thisCFI->vpp = flashPtr[0x1d * thisCFI->multiplier];    vol.erasableBlockSize = (flashPtr[0x2f * thisCFI->multiplier] |                             ((unsigned)flashPtr[0x30 * thisCFI->multiplier]) << 8) *                            0x100L;    /* we reserve one erase block for NVRAM usage */#ifdef SAVE_NVRAM_REGION    if (vol.interleaving == 1)  /* wrSbc85xx boot flash only */        {        /* save 1MB rounded to next blk */        vol.chipSize = (1L << flashPtr[0x27 * thisCFI->multiplier]) -                        vol.erasableBlockSize * (1+(0xfffff/vol.erasableBlockSize));        }    else        {        vol.chipSize = (1L << flashPtr[0x27 * thisCFI->multiplier]);        }#else    vol.chipSize = (1L << flashPtr[0x27 * thisCFI->multiplier]);#endif    vol.erasableBlockSize *= vol.interleaving;#ifdef BUFFERED_WRITE_BROKEN    thisCFI->maxBytesWrite = 1;#else    thisCFI->maxBytesWrite = 1L << (flashPtr[0x2a * thisCFI->multiplier] |                                    ((unsigned)flashPtr[0x2b * thisCFI->multiplier] << 8));#endif /* BUFFERED_WRITE_BROKEN */    /* In this part we access the primary extended table implemented by Intel.     * If the device uses a different extended table, it should be accessed     * according to the vendor specifications.      */    if ((primaryTable) && (thisCFI->commandSetId == INTEL_COMMAND_SET))        {        /* look for the primary table identification string "PRI" */        if (priIdStr[0] != flashPtr[primaryTable * thisCFI->multiplier] ||            priIdStr[1] != flashPtr[(primaryTable + 1) * thisCFI->multiplier] ||            priIdStr[2] != flashPtr[(primaryTable + 2) * thisCFI->multiplier])            {#ifdef DEBUG_PRINT            DEBUG_PRINT ("Debug: No primary ID @ offset 0x%x\n", primaryTable);#endif            return flUnknownMedia;            }        thisCFI->optionalCommands = flashPtr[(primaryTable + 5) * thisCFI->multiplier] |                                    ((long)flashPtr[(primaryTable + 6) *                                                    thisCFI->multiplier] << 8) |                                    ((long)flashPtr[(primaryTable + 7) *                                                    thisCFI->multiplier] << 16) |                                    ((long)flashPtr[(primaryTable + 8) *                                                    thisCFI->multiplier] << 24);        thisCFI->afterSuspend = flashPtr[(primaryTable + 9) * thisCFI->multiplier];        }    else        {        thisCFI->optionalCommands = 0;        thisCFI->afterSuspend = 0;        }    /* Make sure this comes at the end since the device is set to READ_ARRAY     * mode prior to the return     */    if (cfiscsGetChipCount(&vol) != flOK)        return flUnknownMedia;#ifdef DEBUG_PRINT    DEBUG_PRINT ("Debug: No of chips detected is %d\n", vol.noOfChips);#endif#ifdef INTERLEAVED_MODE_REQUIRES_32BIT_WRITES    vol.erase = cfiscsInterleavedWordErase;/*#else  / * !INTERLEAVED_MODE_REQUIRES_32BIT_WRITES * /    vol.erase = cfiscsErase;*/#endif /* INTERLEAVED_MODE_REQUIRES_32BIT_WRITES */#ifdef DEBUG_PRINT    DEBUG_PRINT ("Debug: flash cmd set = %s\n",                 ((thisCFI->commandSetId) == INTEL_COMMAND_SET)?                 "Intel" : "AMD");    DEBUG_PRINT ("Debug: primaryTable = %d\n", primaryTable);    DEBUG_PRINT ("Debug: alt cmd set = %s\n",                 ((thisCFI->altCommandSetId) == 0)?                 "Not supported" :  "Supported");    DEBUG_PRINT ("Debug: secondaryTable = %d\n", secondaryTable);    DEBUG_PRINT ("Debug: vpp = %d\n", thisCFI->vpp);    DEBUG_PRINT ("Debug: erase size = %d\n", vol.erasableBlockSize);    DEBUG_PRINT ("Debug: opt cmd = %d\n", thisCFI->optionalCommands);    DEBUG_PRINT ("Debug: after suspend = %d\n", thisCFI->afterSuspend);    DEBUG_PRINT ("Debug: end\n");#endif    /* Might have to do this on a bus width basis but for now it seems to     * work with Intel devices.     */    if (vol.interleaving == 4)        {        flashDPtr[0xaa] = (ULONG) (READ_AR

⌨️ 快捷键说明

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