static int alt_epcs_flash_memcmp( alt_flash_dev* flash_info, const void* src_buffer, int offset, size_t n ) { /* * Compare chunks of memory at a time, for better serial-flash * read efficiency. */ alt_u8 chunk_buffer[32]; const int chunk_size = sizeof(chunk_buffer) / sizeof(*chunk_buffer); int current_offset = 0; while (n > 0) { int this_chunk_size = n > chunk_size ? chunk_size : n; int this_chunk_cmp; if ( alt_epcs_flash_read( flash_info, offset + current_offset, chunk_buffer, this_chunk_size ) < 0 ) { /* * If the read fails, I'm not sure what the appropriate action is. * Compare success seems wrong, so make it compare fail. */ return -1; } /* Compare this chunk against the source memory buffer. */ this_chunk_cmp = memcmp(&((unsigned char*)(src_buffer))[current_offset], chunk_buffer, this_chunk_size); if (this_chunk_cmp) { return this_chunk_cmp; } n -= this_chunk_size; current_offset += this_chunk_size; } /* * If execution made it to this point, compare is successful. */ return 0; }
static Cyg_ErrNo epcs_bread( cyg_io_handle_t handle, void *buf, cyg_uint32 *len, cyg_uint32 pos) { struct alt_flash_dev *flash_info = (alt_flash_dev *)p_epcs_fd; return alt_epcs_flash_read(flash_info, pos, buf, *len); } // epcs_bread()