summaryrefslogtreecommitdiffstats
path: root/libflashrom.h
diff options
context:
space:
mode:
authorNico Huber <nico.huber@secunet.com>2012-12-10 13:34:10 +0000
committerDavid Hendricks <david.hendricks@gmail.com>2017-06-03 20:13:06 +0200
commit454f61338213f73ca74fda54c0bf86afb01947de (patch)
tree5c981a1a181c130467d3c37b99cdeaf686ff49c8 /libflashrom.h
parent7af0e79b44bdc86497a992a90855f284e74d73f1 (diff)
downloadflashrom-454f61338213f73ca74fda54c0bf86afb01947de.tar.gz
flashrom-454f61338213f73ca74fda54c0bf86afb01947de.tar.bz2
flashrom-454f61338213f73ca74fda54c0bf86afb01947de.zip
Add a convenient libflashrom interface
This adds a minimal libflashrom interface based on the draft in the wiki. While the glue code in libflashrom.c is build on top of the existing code instead on overhauling it, the interface in libflashrom.h is supposed to be stable. So we can keep the interface and adapt internals later if favoured, without breaking clients. A new make target, libinstall, is also added. It installs libflashrom.a and libflashrom.h in lib/ and include/ dirs respectively. Hooking this into the build would break linking of the CLI and is post- poned until that got fixed. v2: Rebase and fixes by Anton Kochkov. v3: o fl_image_*() rewritten with layout support (touch only included regions). o Moved read/erase/write/verify operations to flashrom.c. o Added layout pointer and flags to the flash context. v4: Removed libflashrom.o from LIB_OBJS until CLI is adapted. v5: o Incorporated David's comments. o Added `fl_flashprog_t` as dummy parameter to hide the fact that we have global state all around, and for future-proofness ofc. v6: o Change namespace prefix to flashrom_. o Remove typedefs. Change-Id: I00f169990830aa17b7dfae5eb74010d40c476181 Signed-off-by: Nico Huber <nico.huber@secunet.com> Reviewed-on: https://review.coreboot.org/17946 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: David Hendricks <david.hendricks@gmail.com>
Diffstat (limited to 'libflashrom.h')
-rw-r--r--libflashrom.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/libflashrom.h b/libflashrom.h
new file mode 100644
index 000000000..42b02f9fa
--- /dev/null
+++ b/libflashrom.h
@@ -0,0 +1,70 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright (C) 2012 secunet Security Networks AG
+ * (Written by Nico Huber <nico.huber@secunet.com> for secunet)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __LIBFLASHROM_H__
+#define __LIBFLASHROM_H__ 1
+
+#include <stdarg.h>
+
+int flashrom_init(int perform_selfcheck);
+int flashrom_shutdown(void);
+/** @ingroup flashrom-general */
+enum flashrom_log_level { /* This has to match enum msglevel. */
+ FLASHROM_MSG_ERROR = 0,
+ FLASHROM_MSG_INFO = 1,
+ FLASHROM_MSG_DEBUG = 2,
+ FLASHROM_MSG_DEBUG2 = 3,
+ FLASHROM_MSG_SPEW = 4,
+};
+/** @ingroup flashrom-general */
+typedef int(flashrom_log_callback)(enum flashrom_log_level, const char *format, va_list);
+void flashrom_set_log_callback(flashrom_log_callback *);
+
+struct flashrom_programmer;
+int flashrom_programmer_init(struct flashrom_programmer **, const char *prog_name, const char *prog_params);
+int flashrom_programmer_shutdown(struct flashrom_programmer *);
+
+struct flashrom_flashctx;
+int flashrom_flash_probe(struct flashrom_flashctx **, const struct flashrom_programmer *, const char *chip_name);
+size_t flashrom_flash_getsize(const struct flashrom_flashctx *);
+int flashrom_flash_erase(struct flashrom_flashctx *);
+void flashrom_flash_release(struct flashrom_flashctx *);
+
+/** @ingroup flashrom-flash */
+enum flashrom_flag {
+ FLASHROM_FLAG_FORCE,
+ FLASHROM_FLAG_FORCE_BOARDMISMATCH,
+ FLASHROM_FLAG_VERIFY_AFTER_WRITE,
+ FLASHROM_FLAG_VERIFY_WHOLE_CHIP,
+};
+void flashrom_flag_set(struct flashrom_flashctx *, enum flashrom_flag, bool value);
+bool flashrom_flag_get(const struct flashrom_flashctx *, enum flashrom_flag);
+
+int flashrom_image_read(struct flashrom_flashctx *, void *buffer, size_t buffer_len);
+int flashrom_image_write(struct flashrom_flashctx *, const void *buffer, size_t buffer_len);
+int flashrom_image_verify(struct flashrom_flashctx *, const void *buffer, size_t buffer_len);
+
+struct flashrom_layout;
+int flashrom_layout_include_region(struct flashrom_layout *, const char *name);
+void flashrom_layout_release(struct flashrom_layout *);
+void flashrom_layout_set(struct flashrom_flashctx *, const struct flashrom_layout *);
+
+#endif /* !__LIBFLASHROM_H__ */