<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><style>body { line-height: 1.5; }blockquote { margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em; }body { font-size: 10.5pt; font-family: 微软雅黑; color: rgb(0, 0, 0); line-height: 1.5; }</style></head><body>
<div><span></span>Sorry, I delete some parts of my code. </div><div>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.</div><div><br></div><div>The "beginning" variable I use here is equal to offset plus <span style="font-size: 10.5pt; line-height: 1.5; background-color: window;">0x00020000 (</span><span style="font-size: 10.5pt; line-height: 1.5; background-color: window;">S25FL256S_BOTTOM_GAP_ADDRESS</span><span style="background-color: window; font-size: 10.5pt; line-height: 1.5;">).</span></div><div><span style="background-color: window; font-size: 10.5pt; line-height: 1.5;">The page size of flash is 256B, BTW.</span></div><div><span style="font-size: 10.5pt; line-height: 1.5; background-color: window;"><br></span></div><div><span style="font-size: 10.5pt; line-height: 1.5; background-color: window;">/*******************************************************************************************/</span></div><div>static int flash_write(<br> rtems_jffs2_flash_control *super,<br> uint32_t offset,<br> unsigned char *buffer,<br> size_t length) {<br> flash_control *self = get_flash_control(super);<br> XQspiPs *flash_handle = self->flash_instance;<br> uint32_t beginning = offset + S25FL256S_BOTTOM_GAP_ADDRESS;<br> uint32_t num = length / S25FL256S_PAGE_SIZE;<br> uint32_t remaining = length % S25FL256S_PAGE_SIZE;<br> uint32_t written;<br><br> for (written = 0; written < num; written++) {<br> FlashWrite(flash_handle, beginning + written*S25FL256S_PAGE_SIZE, \<br> S25FL256S_PAGE_SIZE, WRITE_CMD, \<br> buffer + written*S25FL256S_PAGE_SIZE);<br> }<br> if (remaining) {<br> FlashWrite(flash_handle, beginning + num*S25FL256S_PAGE_SIZE, \<br> remaining, WRITE_CMD, buffer + num*S25FL256S_PAGE_SIZE);<br> }<br> return S25FL256S_SUCCESS;<br>}</div><div>/*************************************************************************************************/</div><div><br></div>
<div><br></div><hr style="width: 210px; height: 1px;" color="#b5c4df" size="1" align="left">
<div><span><div style="MARGIN: 10px; FONT-FAMILY: verdana; FONT-SIZE: 10pt"><div>Best wishes,</div><div>xuelin.tian@qkmtech.com</div></div></span></div>
<blockquote style="margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em;"><div> </div><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm"><div style="PADDING-RIGHT: 8px; PADDING-LEFT: 8px; FONT-SIZE: 12px;FONT-FAMILY:tahoma;COLOR:#000000; BACKGROUND: #efefef; PADDING-BOTTOM: 8px; PADDING-TOP: 8px"><div><b>From:</b> <a href="mailto:sebastian.huber@embedded-brains.de">Sebastian Huber</a></div><div><b>Date:</b> 2017-10-23 17:44</div><div><b>To:</b> <a href="mailto:xuelin.tian@qkmtech.com">xuelin.tian@qkmtech.com</a>; <a href="mailto:chrisj@rtems.org">Chris Johns</a></div><div><b>CC:</b> <a href="mailto:users@rtems.org">users@rtems.org</a></div><div><b>Subject:</b> Re: Filesystem in RTEMS</div></div></div><div><div>On 23/10/17 11:40, Sebastian Huber wrote:</div>
<div>></div>
<div>></div>
<div>> On 23/10/17 11:33, xuelin.tian@qkmtech.com wrote:</div>
<div>>> static int flash_write(</div>
<div>>> rtems_jffs2_flash_control *super,</div>
<div>>> uint32_t offset,</div>
<div>>> unsigned char *buffer,</div>
<div>>> size_t length) {</div>
<div>>></div>
<div>>> flash_control *self = get_flash_control(super);</div>
<div>>> XQspiPs *flash_handle = self->flash_instance;</div>
<div>>> uint32_t num = length / S25FL256S_PAGE_SIZE;</div>
<div>>> uint32_t remaining = length % S25FL256S_PAGE_SIZE;</div>
<div>>> uint32_t written;</div>
<div>>></div>
<div>>> for (written = 0; written < num; written++) {</div>
<div>>> FlashWrite(flash_handle, beginning + written*S25FL256S_PAGE_SIZE, \ </div>
<div>>></div>
<div>>> S25FL256S_PAGE_SIZE, WRITE_CMD, \</div>
<div>>> buffer + written*S25FL256S_PAGE_SIZE);</div>
<div>>> }</div>
<div>>> if (remaining) {</div>
<div>>> FlashWrite(flash_handle, beginning + num*S25FL256S_PAGE_SIZE, \</div>
<div>>> remaining, WRITE_CMD, buffer + num*S25FL256S_PAGE_SIZE);</div>
<div>>> }</div>
<div>>> return S25FL256S_SUCCESS;</div>
<div>>> }</div>
<div>>></div>
<div>>> where, my FlashRead and FlashWrite functions will invoke the </div>
<div>>> functions defined in Xilinx BSP to transfer data from/into flash.</div>
<div>>></div>
<div>>> I do not know where the problem is...</div>
<div>></div>
<div>> You assume length % S25FL256S_PAGE_SIZE == 0. </div>
<div> </div>
<div>Sorry, I should have read the code more carefully.</div>
<div> </div>
<div>What is "beginning"? Why don't you use "offset" in this function?</div>
<div> </div>
<div>-- </div>
<div>Sebastian Huber, embedded brains GmbH</div>
<div> </div>
<div>Address : Dornierstr. 4, D-82178 Puchheim, Germany</div>
<div>Phone : +49 89 189 47 41-16</div>
<div>Fax : +49 89 189 47 41-09</div>
<div>E-Mail : sebastian.huber@embedded-brains.de</div>
<div>PGP : Public key available on request.</div>
<div> </div>
<div>Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.</div>
</div></blockquote>
</body></html>