[U-Boot] [PATCH 08/13] fastboot: nand: Add pre erase and write hooks

Maxime Ripard
2015-08-31T14:46:08Z

Some devices might need to do some per-partition initialization
(ECC/Randomizer settings change for example) before actually accessing it.

Add some hooks before the write and erase operations to let the boards
define what they need to do if needed.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
common/fb_nand.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/common/fb_nand.c b/common/fb_nand.c
index 0e1d0603dbcf..1aab1e88f9c0 100644
--- a/common/fb_nand.c
+++ b/common/fb_nand.c
@@ -23,6 +23,16 @@ struct fb_nand_sparse {
struct part_info *part;
};

+__weak int board_fastboot_erase_partition_setup(char *name)
+{
+ return 0;
+}
+
+__weak int board_fastboot_write_partition_setup(char *name)
+{
+ return 0;
+}
+
static int fb_nand_lookup(const char *partname, char *response,
nand_info_t **nand,
struct part_info **part)
@@ -90,10 +100,10 @@ static int _fb_nand_write(nand_info_t *nand, struct part_info *part,
#ifdef CONFIG_FASTBOOT_FLASH_NAND_TRIMFFS
flags |= WITH_DROP_FFS;
#endif
+
ret = nand_write_skip_bad(nand, offset, &length, NULL,
part->size - (offset - part->offset),
buffer, flags);
-
if (ret)
return ret;

@@ -132,6 +142,9 @@ void fb_nand_flash_write(const char *partname, void *download_buffer,
return;
}

+ ret = board_fastboot_erase_partition_setup(part->name);
+ if (ret)
+ return;

ret = _fb_nand_erase(nand, part);
if (ret) {
@@ -140,6 +153,10 @@ void fb_nand_flash_write(const char *partname, void *download_buffer,
return;
}

+ ret = board_fastboot_write_partition_setup(part->name);
+ if (ret)
+ return;
+
if (is_sparse_image(download_buffer)) {
struct fb_nand_sparse sparse_priv;
sparse_storage_t sparse;
@@ -187,6 +204,10 @@ void fb_nand_erase(const char *partname, char *response)
return;
}

+ ret = board_fastboot_erase_partition_setup(part->name);
+ if (ret)
+ return;
+
ret = _fb_nand_erase(nand, part);
if (ret) {
error("failed erasing from device %s", nand->name);
--
2.5.0