[Skiboot] [PATCH v3 1/7] libflash: Return a pointer to internal structure.
Cyril Bur
cyril.bur at au1.ibm.com
Wed Aug 26 16:02:32 AEST 2015
There are some functions (notably: erase_chip and set_4b_mode) which cannot
be abstracted away by the blocklevel interface, this means that if they are
really needed (by pflash for example) then at the moment a program like
pflash would need to pass a blocklevel_device struct to libflash.
This forces libflash to trust that it was given a blocklevel that it did
init. If it didn't init it the container_of call will return junk and
libflash has no way to protect its self. This method (while very useful)
has destroyed type safety. As such, this commit reintroduces some
typesafety back into this stack.
Signed-off-by: Cyril Bur <cyril.bur at au1.ibm.com>
---
external/pflash/pflash.c | 4 ++--
libflash/libflash.c | 6 +++++-
libflash/libflash.h | 3 ++-
libflash/test/test-flash.c | 2 +-
platforms/astbmc/pnor.c | 2 +-
platforms/rhesus/rhesus.c | 2 +-
6 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c
index 0d2d669..5c10037 100644
--- a/external/pflash/pflash.c
+++ b/external/pflash/pflash.c
@@ -434,7 +434,7 @@ static void flash_access_setup_bmc(bool use_lpc, bool need_write)
}
/* Open flash chip */
- rc = flash_init(fl_ctrl, &bl);
+ rc = flash_init(fl_ctrl, &bl, NULL);
if (rc) {
fprintf(stderr, "Failed to open flash chip\n");
exit(1);
@@ -493,7 +493,7 @@ static void flash_access_setup_pnor(bool use_lpc, bool use_sfc, bool need_write)
#endif
/* Open flash chip */
- rc = flash_init(fl_ctrl, &bl);
+ rc = flash_init(fl_ctrl, &bl, NULL);
if (rc) {
fprintf(stderr, "Failed to open flash chip\n");
exit(1);
diff --git a/libflash/libflash.c b/libflash/libflash.c
index 90ae653..831bdd4 100644
--- a/libflash/libflash.c
+++ b/libflash/libflash.c
@@ -798,7 +798,8 @@ static int flash_get_info(struct blocklevel_device *bl, const char **name,
return 0;
}
-int flash_init(struct spi_flash_ctrl *ctrl, struct blocklevel_device **bl)
+int flash_init(struct spi_flash_ctrl *ctrl, struct blocklevel_device **bl,
+ struct flash_chip **flash_chip)
{
struct flash_chip *c;
int rc;
@@ -842,6 +843,9 @@ bail:
c->bl.flags = WRITE_NEED_ERASE;
*bl = &(c->bl);
+ if (flash_chip)
+ *flash_chip = c;
+
return 0;
}
diff --git a/libflash/libflash.h b/libflash/libflash.h
index f3973ab..fa5143a 100644
--- a/libflash/libflash.h
+++ b/libflash/libflash.h
@@ -45,7 +45,8 @@ extern bool libflash_debug;
struct flash_chip;
struct spi_flash_ctrl;
-int flash_init(struct spi_flash_ctrl *ctrl, struct blocklevel_device **bl);
+int flash_init(struct spi_flash_ctrl *ctrl, struct blocklevel_device **bl,
+ struct flash_chip **flash_chip);
void flash_exit(struct blocklevel_device *bl);
/* libflash sets the 4b mode automatically based on the flash
diff --git a/libflash/test/test-flash.c b/libflash/test/test-flash.c
index cf2b3a5..c93aef5 100644
--- a/libflash/test/test-flash.c
+++ b/libflash/test/test-flash.c
@@ -378,7 +378,7 @@ int main(void)
memset(sim_image, 0xff, sim_image_sz);
test = malloc(0x10000 * 2);
- rc = flash_init(&sim_ctrl, &bl);
+ rc = flash_init(&sim_ctrl, &bl, NULL);
if (rc) {
ERR("flash_init failed with err %d\n", rc);
exit(1);
diff --git a/platforms/astbmc/pnor.c b/platforms/astbmc/pnor.c
index 2cd57c6..74353ea 100644
--- a/platforms/astbmc/pnor.c
+++ b/platforms/astbmc/pnor.c
@@ -46,7 +46,7 @@ int pnor_init(void)
goto fail;
}
- rc = flash_init(pnor_ctrl, &bl);
+ rc = flash_init(pnor_ctrl, &bl, NULL);
if (rc) {
prerror("PLAT: Failed to open init PNOR driver\n");
goto fail;
diff --git a/platforms/rhesus/rhesus.c b/platforms/rhesus/rhesus.c
index b597ba0..2131ec0 100644
--- a/platforms/rhesus/rhesus.c
+++ b/platforms/rhesus/rhesus.c
@@ -129,7 +129,7 @@ static int rhesus_pnor_init(void)
prerror("PLAT: Failed to open PNOR flash controller\n");
goto fail;
}
- rc = flash_init(pnor_ctrl, &bl);
+ rc = flash_init(pnor_ctrl, &bl, NULL);
if (rc) {
prerror("PLAT: Failed to open init PNOR driver\n");
goto fail;
--
2.5.0
More information about the Skiboot
mailing list