diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2015-02-26 11:46:09 +0800 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2015-02-26 16:34:27 +1100 |
commit | 6c26bc72093a317a7018bafbece55393d9e222f5 (patch) | |
tree | 1264c7dd0f123d48e2387dffbb1f9d332f7d41eb /libflash | |
parent | 4ddba54145f2c6056cc0236774429825f5ba84d9 (diff) | |
download | skiboot-6c26bc72093a317a7018bafbece55393d9e222f5.zip skiboot-6c26bc72093a317a7018bafbece55393d9e222f5.tar.gz skiboot-6c26bc72093a317a7018bafbece55393d9e222f5.tar.bz2 |
libflash: move ffs_flash_read into libflash
We have ffs_flash_read to do optionally-ecc-ed reads of flash data.
However, this isn't really related to the ffs partitioning.
This change moves ffs_flash_read into libflash.c, named
flash_read_corrected. The function itself isn't changed.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'libflash')
-rw-r--r-- | libflash/libffs.c | 55 | ||||
-rw-r--r-- | libflash/libffs.h | 4 | ||||
-rw-r--r-- | libflash/libflash.c | 55 | ||||
-rw-r--r-- | libflash/libflash.h | 2 | ||||
-rw-r--r-- | libflash/test/Makefile.check | 2 | ||||
-rw-r--r-- | libflash/test/test-flash.c | 1 |
6 files changed, 59 insertions, 60 deletions
diff --git a/libflash/libffs.c b/libflash/libffs.c index bce4ac4..109ac40 100644 --- a/libflash/libffs.c +++ b/libflash/libffs.c @@ -22,11 +22,6 @@ #include <ccan/endian/endian.h> #include "libffs.h" -#include "ecc.h" - -#ifndef MIN -#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#endif enum ffs_type { ffs_type_flash, @@ -292,53 +287,3 @@ int ffs_update_act_size(struct ffs_handle *ffs, uint32_t part_idx, return flash_smart_write(ffs->chip, offset, ent, FFS_ENTRY_SIZE); } -#define COPY_BUFFER_LENGTH 4096 - -/* - * This provides a wrapper around flash_read on ECCed data - * len is length of data without ECC attached - */ -int ffs_flash_read(struct flash_chip *c, uint32_t pos, void *buf, uint32_t len, - bool ecc) -{ - uint64_t *bufecc; - uint32_t copylen; - int rc; - uint8_t ret; - - if (!ecc) - return flash_read(c, pos, buf, len); - - /* Copy the buffer in chunks */ - bufecc = malloc(ECC_BUFFER_SIZE(COPY_BUFFER_LENGTH)); - if (!bufecc) - return FLASH_ERR_MALLOC_FAILED; - - while (len > 0) { - /* What's left to copy? */ - copylen = MIN(len, COPY_BUFFER_LENGTH); - - /* Read ECCed data from flash */ - rc = flash_read(c, pos, bufecc, ECC_BUFFER_SIZE(copylen)); - if (rc) - goto err; - - /* Extract data from ECCed data */ - ret = eccmemcpy(buf, bufecc, copylen); - if (ret == UE) { - rc = FLASH_ERR_ECC_INVALID; - goto err; - } - - /* Update for next copy */ - len -= copylen; - buf = (uint8_t *)buf + copylen; - pos += ECC_BUFFER_SIZE(copylen); - } - - return 0; - -err: - free(bufecc); - return rc; -} diff --git a/libflash/libffs.h b/libflash/libffs.h index 15ed3c5..b597118 100644 --- a/libflash/libffs.h +++ b/libflash/libffs.h @@ -53,8 +53,4 @@ int ffs_part_info(struct ffs_handle *ffs, uint32_t part_idx, int ffs_update_act_size(struct ffs_handle *ffs, uint32_t part_idx, uint32_t act_size); -int ffs_flash_read(struct flash_chip *c, uint32_t pos, void *buf, uint32_t len, - bool ecc); - - #endif /* __LIBFFS_H */ diff --git a/libflash/libflash.c b/libflash/libflash.c index 5badbff..31a347b 100644 --- a/libflash/libflash.c +++ b/libflash/libflash.c @@ -19,6 +19,11 @@ #include "libflash.h" #include "libflash-priv.h" +#include "ecc.h" + +#ifndef MIN +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#endif static const struct flash_info flash_info[] = { { 0xc22019, 0x02000000, FL_ERASE_ALL | FL_CAN_4B, "Macronix MXxxL25635F"}, @@ -123,6 +128,56 @@ int flash_read(struct flash_chip *c, uint32_t pos, void *buf, uint32_t len) return ct->cmd_rd(ct, CMD_READ, true, pos, buf, len); } +#define COPY_BUFFER_LENGTH 4096 + +/* + * This provides a wrapper around flash_read on ECCed data + * len is length of data without ECC attached + */ +int flash_read_corrected(struct flash_chip *c, uint32_t pos, void *buf, + uint32_t len, bool ecc) +{ + uint64_t *bufecc; + uint32_t copylen; + int rc; + uint8_t ret; + + if (!ecc) + return flash_read(c, pos, buf, len); + + /* Copy the buffer in chunks */ + bufecc = malloc(ECC_BUFFER_SIZE(COPY_BUFFER_LENGTH)); + if (!bufecc) + return FLASH_ERR_MALLOC_FAILED; + + while (len > 0) { + /* What's left to copy? */ + copylen = MIN(len, COPY_BUFFER_LENGTH); + + /* Read ECCed data from flash */ + rc = flash_read(c, pos, bufecc, ECC_BUFFER_SIZE(copylen)); + if (rc) + goto err; + + /* Extract data from ECCed data */ + ret = eccmemcpy(buf, bufecc, copylen); + if (ret == UE) { + rc = FLASH_ERR_ECC_INVALID; + goto err; + } + + /* Update for next copy */ + len -= copylen; + buf = (uint8_t *)buf + copylen; + pos += ECC_BUFFER_SIZE(copylen); + } + + return 0; + +err: + free(bufecc); + return rc; +} static void fl_get_best_erase(struct flash_chip *c, uint32_t dst, uint32_t size, uint32_t *chunk, uint8_t *cmd) { diff --git a/libflash/libflash.h b/libflash/libflash.h index f9ec977..01806d5 100644 --- a/libflash/libflash.h +++ b/libflash/libflash.h @@ -70,6 +70,8 @@ int flash_get_info(struct flash_chip *chip, const char **name, int flash_force_4b_mode(struct flash_chip *chip, bool enable_4b); int flash_read(struct flash_chip *c, uint32_t pos, void *buf, uint32_t len); +int flash_read_corrected(struct flash_chip *c, uint32_t pos, void *buf, + uint32_t len, bool ecc); int flash_erase(struct flash_chip *c, uint32_t dst, uint32_t size); int flash_write(struct flash_chip *c, uint32_t dst, const void *src, uint32_t size, bool verify); diff --git a/libflash/test/Makefile.check b/libflash/test/Makefile.check index 5d32a41..4000395 100644 --- a/libflash/test/Makefile.check +++ b/libflash/test/Makefile.check @@ -16,7 +16,7 @@ $(LIBFLASH_TEST:%=%-check) : %-check: % libflash/test/stubs.o: libflash/test/stubs.c $(call Q, HOSTCC ,$(HOSTCC) $(HOSTCFLAGS) -g -c -o $@ $<, $<) -$(LIBFLASH_TEST) : libflash/test/stubs.o libflash/libflash.c +$(LIBFLASH_TEST) : libflash/test/stubs.o libflash/libflash.c libflash/ecc.c $(LIBFLASH_TEST) : % : %.c $(call Q, HOSTCC ,$(HOSTCC) $(HOSTCFLAGS) -O0 -g -I include -I . -o $@ $< libflash/test/stubs.o, $<) diff --git a/libflash/test/test-flash.c b/libflash/test/test-flash.c index 5f48797..375b338 100644 --- a/libflash/test/test-flash.c +++ b/libflash/test/test-flash.c @@ -22,6 +22,7 @@ #include <libflash/libflash-priv.h> #include "../libflash.c" +#include "../ecc.c" #define __unused __attribute__((unused)) |