mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 23:22:37 +02:00
Enable continuous SPI reads
Previous unnecessary page-by-page reading is repurposed to read by big naturally aligned areas (now chip size limited to 16MB for future-proofing of 4 byte addressed multi-die chips) and serprog hack for continuous reads is removed. Change-Id: Iadf909c9216578b1c5dacd4c4991bb436e32edc9 Signed-off-by: Urja Rannikko <urjaman@gmail.com> Reviewed-on: https://review.coreboot.org/20223 Reviewed-by: Nico Huber <nico.h@gmx.de> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
026c741651
commit
731316a912
23
serprog.c
23
serprog.c
@ -303,15 +303,13 @@ static int serprog_spi_send_command(struct flashctx *flash,
|
|||||||
unsigned int writecnt, unsigned int readcnt,
|
unsigned int writecnt, unsigned int readcnt,
|
||||||
const unsigned char *writearr,
|
const unsigned char *writearr,
|
||||||
unsigned char *readarr);
|
unsigned char *readarr);
|
||||||
static int serprog_spi_read(struct flashctx *flash, uint8_t *buf,
|
|
||||||
unsigned int start, unsigned int len);
|
|
||||||
static struct spi_master spi_master_serprog = {
|
static struct spi_master spi_master_serprog = {
|
||||||
.type = SPI_CONTROLLER_SERPROG,
|
.type = SPI_CONTROLLER_SERPROG,
|
||||||
.max_data_read = MAX_DATA_READ_UNLIMITED,
|
.max_data_read = MAX_DATA_READ_UNLIMITED,
|
||||||
.max_data_write = MAX_DATA_WRITE_UNLIMITED,
|
.max_data_write = MAX_DATA_WRITE_UNLIMITED,
|
||||||
.command = serprog_spi_send_command,
|
.command = serprog_spi_send_command,
|
||||||
.multicommand = default_spi_send_multicommand,
|
.multicommand = default_spi_send_multicommand,
|
||||||
.read = serprog_spi_read,
|
.read = default_spi_read,
|
||||||
.write_256 = default_spi_write_256,
|
.write_256 = default_spi_write_256,
|
||||||
.write_aai = default_spi_write_aai,
|
.write_aai = default_spi_write_aai,
|
||||||
};
|
};
|
||||||
@ -933,25 +931,6 @@ static int serprog_spi_send_command(struct flashctx *flash,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: This function is optimized so that it does not split each transaction
|
|
||||||
* into chip page_size long blocks unnecessarily like spi_read_chunked. This has
|
|
||||||
* the advantage that it is much faster for most chips, but breaks those with
|
|
||||||
* non-continuous reads. When spi_read_chunked is fixed this method can be removed. */
|
|
||||||
static int serprog_spi_read(struct flashctx *flash, uint8_t *buf,
|
|
||||||
unsigned int start, unsigned int len)
|
|
||||||
{
|
|
||||||
unsigned int i, cur_len;
|
|
||||||
const unsigned int max_read = spi_master_serprog.max_data_read;
|
|
||||||
for (i = 0; i < len; i += cur_len) {
|
|
||||||
int ret;
|
|
||||||
cur_len = min(max_read, (len - i));
|
|
||||||
ret = spi_nbyte_read(flash, start + i, buf + i, cur_len);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *serprog_map(const char *descr, uintptr_t phys_addr, size_t len)
|
void *serprog_map(const char *descr, uintptr_t phys_addr, size_t len)
|
||||||
{
|
{
|
||||||
/* Serprog transmits 24 bits only and assumes the underlying implementation handles any remaining bits
|
/* Serprog transmits 24 bits only and assumes the underlying implementation handles any remaining bits
|
||||||
|
27
spi25.c
27
spi25.c
@ -940,30 +940,31 @@ int spi_nbyte_read(struct flashctx *flash, unsigned int address, uint8_t *bytes,
|
|||||||
/*
|
/*
|
||||||
* Read a part of the flash chip.
|
* Read a part of the flash chip.
|
||||||
* FIXME: Use the chunk code from Michael Karcher instead.
|
* FIXME: Use the chunk code from Michael Karcher instead.
|
||||||
* Each page is read separately in chunks with a maximum size of chunksize.
|
* Each naturally aligned area is read separately in chunks with a maximum size of chunksize.
|
||||||
*/
|
*/
|
||||||
int spi_read_chunked(struct flashctx *flash, uint8_t *buf, unsigned int start,
|
int spi_read_chunked(struct flashctx *flash, uint8_t *buf, unsigned int start,
|
||||||
unsigned int len, unsigned int chunksize)
|
unsigned int len, unsigned int chunksize)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
unsigned int i, j, starthere, lenhere, toread;
|
unsigned int i, j, starthere, lenhere, toread;
|
||||||
unsigned int page_size = flash->chip->page_size;
|
/* Limit for multi-die 4-byte-addressing chips. */
|
||||||
|
unsigned int area_size = min(flash->chip->total_size * 1024, 16 * 1024 * 1024);
|
||||||
|
|
||||||
/* Warning: This loop has a very unusual condition and body.
|
/* Warning: This loop has a very unusual condition and body.
|
||||||
* The loop needs to go through each page with at least one affected
|
* The loop needs to go through each area with at least one affected
|
||||||
* byte. The lowest page number is (start / page_size) since that
|
* byte. The lowest area number is (start / area_size) since that
|
||||||
* division rounds down. The highest page number we want is the page
|
* division rounds down. The highest area number we want is the area
|
||||||
* where the last byte of the range lives. That last byte has the
|
* where the last byte of the range lives. That last byte has the
|
||||||
* address (start + len - 1), thus the highest page number is
|
* address (start + len - 1), thus the highest area number is
|
||||||
* (start + len - 1) / page_size. Since we want to include that last
|
* (start + len - 1) / area_size. Since we want to include that last
|
||||||
* page as well, the loop condition uses <=.
|
* area as well, the loop condition uses <=.
|
||||||
*/
|
*/
|
||||||
for (i = start / page_size; i <= (start + len - 1) / page_size; i++) {
|
for (i = start / area_size; i <= (start + len - 1) / area_size; i++) {
|
||||||
/* Byte position of the first byte in the range in this page. */
|
/* Byte position of the first byte in the range in this area. */
|
||||||
/* starthere is an offset to the base address of the chip. */
|
/* starthere is an offset to the base address of the chip. */
|
||||||
starthere = max(start, i * page_size);
|
starthere = max(start, i * area_size);
|
||||||
/* Length of bytes in the range in this page. */
|
/* Length of bytes in the range in this area. */
|
||||||
lenhere = min(start + len, (i + 1) * page_size) - starthere;
|
lenhere = min(start + len, (i + 1) * area_size) - starthere;
|
||||||
for (j = 0; j < lenhere; j += chunksize) {
|
for (j = 0; j < lenhere; j += chunksize) {
|
||||||
toread = min(chunksize, lenhere - j);
|
toread = min(chunksize, lenhere - j);
|
||||||
rc = spi_nbyte_read(flash, starthere + j, buf + starthere - start + j, toread);
|
rc = spi_nbyte_read(flash, starthere + j, buf + starthere - start + j, toread);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user