Edward O'Callaghan has uploaded this change for review.

View Change

libflashrom: Provide flashrom_flash_getname() API

The libflashom API exposes a API to get the flash size however
not the flash name.

Change-Id: I3dc32e261e6d54230d93f06b91f723811792112a
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
---
M include/libflashrom.h
M libflashrom.c
2 files changed, 31 insertions(+), 0 deletions(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/86/73286/1
diff --git a/include/libflashrom.h b/include/libflashrom.h
index 490ef03..fc8dd0e 100644
--- a/include/libflashrom.h
+++ b/include/libflashrom.h
@@ -230,6 +230,13 @@
*/
size_t flashrom_flash_getsize(const struct flashrom_flashctx *flashctx);
/**
+ * @brief Returns the name of the specified flash chip.
+ *
+ * @param flashctx The queried flash context.
+ * @param[out] allocated with a copy of the flash name string.
+ */
+void flashrom_flash_getname(const struct flashrom_flashctx *const flashctx, char **name);
+/**
* @brief Erase the specified ROM chip.
*
* If a layout is set in the given flash context, only included regions
diff --git a/libflashrom.c b/libflashrom.c
index 2e89fe5..50a7a0e 100644
--- a/libflashrom.c
+++ b/libflashrom.c
@@ -251,6 +251,17 @@
return flashctx->chip->total_size * 1024;
}

+void flashrom_flash_getname(const struct flashrom_flashctx *const flashctx, char **name)
+{
+ const char *chip_name = flashctx->chip->name;
+ const size_t len = strlen(chip_name) + 1;
+
+ if (!name) return;
+
+ *name = calloc(1, len);
+ strcpy(*name, chip_name);
+}
+
void flashrom_flash_release(struct flashrom_flashctx *const flashctx)
{
if (!flashctx)

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

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I3dc32e261e6d54230d93f06b91f723811792112a
Gerrit-Change-Number: 73286
Gerrit-PatchSet: 1
Gerrit-Owner: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-MessageType: newchange