/** * * Initializes a specific XFlash instance. * The initialization entails: * - Check the Device family type. * - Issuing the CFI query command. * - Get and translate relevant CFI query information. * - Set default options for the instance. * - Setup the VTable. * - Call the family initialize function of the instance. * - Initialize the Xilinx Platform Flash XL to Async mode if the user * selects to use the Platform Flash XL in the MLD. The Platform Flash XL * is an Intel CFI complaint device. * * @param InstancePtr is a pointer to the XFlash instance. * @param BaseAddress is the base address of the flash memory. * @param BusWidth is the total width of the flash memory, in bytes. * @param IsPlatformFlash is used to specify if the flash is a platform * flash. * * @return * - XST_SUCCESS if successful. * - XFLASH_PART_NOT_SUPPORTED if the command set algorithm or * Layout is not supported by any flash family compiled into * the system. * - XFLASH_CFI_QUERY_ERROR if the device would not enter CFI * query mode. Either the device(s) do not support CFI, the wrong * BaseAddress param was used, an unsupported part layout exists, * or a hardware problem exists with the part. * * @note BusWidth is not the width of an individual part. Its the total * operating width. For example, if there are two 16-bit parts, * with one tied to data lines D0-D15 and other tied to D15-D31, * BusWidth would be (32 / 8) = 4. If a single 16-bit flash is in * 8-bit mode, then BusWidth should be (8 / 8) = 1. * ******************************************************************************/ int XFlash_Initialize(XFlash * InstancePtr, u32 BaseAddress, u8 BusWidth, int IsPlatformFlash) { int Status = XST_FAILURE; /* * Validate parameters. */ if(InstancePtr == NULL) { return XST_FAILURE; } if (BusWidth > 8) { return XFLASH_PART_NOT_SUPPORTED; } InstancePtr->IsReady = 0; InstancePtr->Geometry.BaseAddress = BaseAddress; InstancePtr->IsPlatformFlash = IsPlatformFlash; #ifdef XPAR_XFL_DEVICE_FAMILY_INTEL if (IsPlatformFlash == 1) { /* * Set Async mode for platform flash */ WRITE_FLASH_16(InstancePtr->Geometry.BaseAddress + XFL_INTEL_CMD_CONFIG_REG_ASYNC_ADDR, XFL_INTEL_CMD_CONFIG_REG_SETUP); WRITE_FLASH_16(InstancePtr->Geometry.BaseAddress + XFL_INTEL_CMD_CONFIG_REG_ASYNC_ADDR, XFL_INTEL_CMD_CONFIG_REG_CONFIRM); } #endif /* XPAR_XFL_DEVICE_FAMILY_INTEL */ /* * Get CFI data. */ Status = XFlashCFI_ReadCommon(InstancePtr, BusWidth); if (Status != XST_SUCCESS) { return (XFLASH_CFI_QUERY_ERROR); } /* * Set the VTable function pointer based on the command set algorithm * discovered in the CFI query. */ Status = SetVTable(InstancePtr); if (Status != XST_SUCCESS) { return Status; } /* * Initialize the specific flash family device. * If it initializes successfully set the IsReady flag to indicate the * device is ready. */ Status = InstancePtr->VTable.Initialize(InstancePtr); if (Status == XST_SUCCESS) { InstancePtr->IsReady = XIL_COMPONENT_IS_READY; } return Status; }
/** * * This function verifies the locking and unlocking features of the Flash device. * * @param None * * @return XST_SUCCESS if successful else XST_FAILURE. * * @note None. * ******************************************************************************/ int FlashProtectionExample(void) { int Status; u32 Index; #ifdef XPAR_XFL_DEVICE_FAMILY_INTEL #if XFL_TO_ASYNCMODE /* * Set Flash to Async mode. */ if (FLASH_MEM_WIDTH == 1) { WRITE_FLASH_8(FLASH_BASE_ADDRESS + ASYNC_ADDR, 0x60); WRITE_FLASH_8(FLASH_BASE_ADDRESS + ASYNC_ADDR, 0x03); } else if (FLASH_MEM_WIDTH == 2) { WRITE_FLASH_16(FLASH_BASE_ADDRESS + ASYNC_ADDR, INTEL_CMD_CONFIG_REG_SETUP); WRITE_FLASH_16(FLASH_BASE_ADDRESS + ASYNC_ADDR, INTEL_CMD_CONFIG_REG_CONFIRM); } #endif #endif /* * Initialize the Flash Library. */ Status = XFlash_Initialize(&FlashInstance, FLASH_BASE_ADDRESS, FLASH_MEM_WIDTH, 0); if(Status != XST_SUCCESS) { return XST_FAILURE; } /* * Reset the Flash Device. This clears the Status registers and puts * the device in Read mode. */ Status = XFlash_Reset(&FlashInstance); if(Status != XST_SUCCESS) { return XST_FAILURE; } /* * Lock the Block. */ Status = XFlash_Lock(&FlashInstance, BLOCK_OFFSET_ADDR, 0); if(Status != XST_SUCCESS) { return XST_FAILURE; } /* * Perform the Erase operation. This should fail as the block is locked. */ Status = XFlash_Erase(&FlashInstance, START_ADDRESS, FLASH_TEST_SIZE); if(Status == XST_SUCCESS) { return XST_FAILURE; } /* * Unlock the Block. */ Status = XFlash_Unlock(&FlashInstance, BLOCK_OFFSET_ADDR, 0); if(Status != XST_SUCCESS) { return XST_FAILURE; } /* * Perform the Erase operation. This should succeed as the block is * unlocked. */ Status = XFlash_Erase(&FlashInstance, START_ADDRESS, FLASH_TEST_SIZE); if(Status != XST_SUCCESS) { return XST_FAILURE; } /* * Prepare the write buffer. Fill in the data need to be written into * Flash Device. */ for(Index = 0; Index < FLASH_TEST_SIZE; Index++) { WriteBuffer[Index] = (u8)Index; } /* * Perform the Write operation. */ Status = XFlash_Write(&FlashInstance, START_ADDRESS, FLASH_TEST_SIZE, WriteBuffer); if(Status != XST_SUCCESS) { return XST_FAILURE; } /* * Perform the read operation. */ Status = XFlash_Read(&FlashInstance, START_ADDRESS, FLASH_TEST_SIZE, ReadBuffer); if(Status != XST_SUCCESS) { return XST_FAILURE; } /* * Compare the data read against the data Written. */ for(Index = 0; Index < FLASH_TEST_SIZE; Index++) { if(ReadBuffer[Index] != (u8)Index) { return XST_FAILURE; } } return XST_SUCCESS; }