Sorry, I delete some parts of my code. The sectors of S25FL256S flash chip has a combination of 4KB and 64KB. Only the 64KB sectors will be used, for simplicity, and the beginning address of them is 0x00020000.
The "beginning" variable I use here is equal to offset plus 0x00020000 (S25FL256S_BOTTOM_GAP_ADDRESS). The page size of flash is 256B, BTW. /*******************************************************************************************/ static int flash_write( rtems_jffs2_flash_control *super, uint32_t offset, unsigned char *buffer, size_t length) { flash_control *self = get_flash_control(super); XQspiPs *flash_handle = self->flash_instance; uint32_t beginning = offset + S25FL256S_BOTTOM_GAP_ADDRESS; uint32_t num = length / S25FL256S_PAGE_SIZE; uint32_t remaining = length % S25FL256S_PAGE_SIZE; uint32_t written; for (written = 0; written < num; written++) { FlashWrite(flash_handle, beginning + written*S25FL256S_PAGE_SIZE, \ S25FL256S_PAGE_SIZE, WRITE_CMD, \ buffer + written*S25FL256S_PAGE_SIZE); } if (remaining) { FlashWrite(flash_handle, beginning + num*S25FL256S_PAGE_SIZE, \ remaining, WRITE_CMD, buffer + num*S25FL256S_PAGE_SIZE); } return S25FL256S_SUCCESS; } /*************************************************************************************************/ Best wishes, xuelin.t...@qkmtech.com From: Sebastian Huber Date: 2017-10-23 17:44 To: xuelin.t...@qkmtech.com; Chris Johns CC: users@rtems.org Subject: Re: Filesystem in RTEMS On 23/10/17 11:40, Sebastian Huber wrote: > > > On 23/10/17 11:33, xuelin.t...@qkmtech.com wrote: >> static int flash_write( >> rtems_jffs2_flash_control *super, >> uint32_t offset, >> unsigned char *buffer, >> size_t length) { >> >> flash_control *self = get_flash_control(super); >> XQspiPs *flash_handle = self->flash_instance; >> uint32_t num = length / S25FL256S_PAGE_SIZE; >> uint32_t remaining = length % S25FL256S_PAGE_SIZE; >> uint32_t written; >> >> for (written = 0; written < num; written++) { >> FlashWrite(flash_handle, beginning + written*S25FL256S_PAGE_SIZE, \ >> >> S25FL256S_PAGE_SIZE, WRITE_CMD, \ >> buffer + written*S25FL256S_PAGE_SIZE); >> } >> if (remaining) { >> FlashWrite(flash_handle, beginning + num*S25FL256S_PAGE_SIZE, \ >> remaining, WRITE_CMD, buffer + num*S25FL256S_PAGE_SIZE); >> } >> return S25FL256S_SUCCESS; >> } >> >> where, my FlashRead and FlashWrite functions will invoke the >> functions defined in Xilinx BSP to transfer data from/into flash. >> >> I do not know where the problem is... > > You assume length % S25FL256S_PAGE_SIZE == 0. Sorry, I should have read the code more carefully. What is "beginning"? Why don't you use "offset" in this function? -- Sebastian Huber, embedded brains GmbH Address : Dornierstr. 4, D-82178 Puchheim, Germany Phone : +49 89 189 47 41-16 Fax : +49 89 189 47 41-09 E-Mail : sebastian.hu...@embedded-brains.de PGP : Public key available on request. Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
_______________________________________________ users mailing list users@rtems.org http://lists.rtems.org/mailman/listinfo/users