Nikolai Artemiev has uploaded this change for review.

View Change

WIP: flashrom: import chip restore handler from cros flashrom

Change-Id: I2a522dc1fd3952793fbcad70afc6dd43850fbbc5
Signed-off-by: Nikolai Artemiev <nartemiev@google.com>
---
M flash.h
M flashrom.c
2 files changed, 41 insertions(+), 0 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/76/47276/1
diff --git a/flash.h b/flash.h
index 203d32d..a58f1a1 100644
--- a/flash.h
+++ b/flash.h
@@ -349,6 +349,8 @@
int do_erase(struct flashctx *);
int do_write(struct flashctx *, const char *const filename, const char *const referencefile);
int do_verify(struct flashctx *, const char *const filename);
+#define CHIP_RESTORE_CALLBACK int (*func) (struct flashctx *flash, uint8_t status)
+int register_chip_restore(CHIP_RESTORE_CALLBACK, struct flashctx *flash, uint8_t status);

/* Something happened that shouldn't happen, but we can go on. */
#define ERROR_NONFATAL 0x100
diff --git a/flashrom.c b/flashrom.c
index 26e2df8..c4b17bb 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -536,6 +536,15 @@
{0}, /* This entry corresponds to PROGRAMMER_INVALID. */
};

+#define CHIP_RESTORE_MAXFN 4
+static int chip_restore_fn_count = 0;
+static struct chip_restore_func_data {
+ CHIP_RESTORE_CALLBACK;
+ struct flashctx *flash;
+ uint8_t status;
+} chip_restore_fn[CHIP_RESTORE_MAXFN];
+
+
#define SHUTDOWN_MAXFN 32
static int shutdown_fn_count = 0;
/** @private */
@@ -580,6 +589,22 @@
return 0;
}

+int register_chip_restore(CHIP_RESTORE_CALLBACK,
+ struct flashctx *flash, uint8_t status)
+{
+ if (chip_restore_fn_count >= CHIP_RESTORE_MAXFN) {
+ msg_perr("Tried to register more than %i chip restore"
+ " functions.\n", CHIP_RESTORE_MAXFN);
+ return 1;
+ }
+ chip_restore_fn[chip_restore_fn_count].func = func; /* from macro */
+ chip_restore_fn[chip_restore_fn_count].flash = flash;
+ chip_restore_fn[chip_restore_fn_count].status = status;
+ chip_restore_fn_count++;
+
+ return 0;
+}
+
int programmer_init(enum programmer prog, const char *param)
{
int ret;
@@ -626,6 +651,19 @@
return ret;
}

+static int chip_restore()
+{
+ int rc = 0;
+
+ while (chip_restore_fn_count > 0) {
+ int i = --chip_restore_fn_count;
+ rc |= chip_restore_fn[i].func(chip_restore_fn[i].flash,
+ chip_restore_fn[i].status);
+ }
+
+ return rc;
+}
+
/** Calls registered shutdown functions and resets internal programmer-related variables.
* Calling it is safe even without previous initialization, but further interactions with programmer support
* require a call to programmer_init() (afterwards).
@@ -2286,6 +2324,7 @@
void finalize_flash_access(struct flashctx *const flash)
{
unmap_flash(flash);
+ chip_restore();
}

/**

To view, visit change 47276. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I2a522dc1fd3952793fbcad70afc6dd43850fbbc5
Gerrit-Change-Number: 47276
Gerrit-PatchSet: 1
Gerrit-Owner: Nikolai Artemiev <nartemiev@google.com>
Gerrit-MessageType: newchange