libflashrom,writeprotect: add functions for reading/writing WP configs
New functions are exposed through the libflashrom API for
reading/writing chip's WP settins: `flashrom_wp_{read,write}_cfg()`.
They read/write an opaque `struct flashrom_wp_cfg` instance, which
includes the flash protection range and status register protection mode.
This commit also adds `{read,write}_wp_bits()` helper functions that
read/write chip-specific WP configuration bits.
Tested: flashrom --wp-{enable,disable,range,list,status} at end of patch series
Change-Id: I3ad25708c3321b8fb0216c3eaf6ffc07616537ad
Signed-off-by: Nikolai Artemiev <nartemiev@google.com>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/58479
Original-Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Original-Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Original-Reviewed-by: Nico Huber <nico.h@gmx.de>
diff --git a/libflashrom.h b/libflashrom.h
index d0d5826..2890d0b 100644
--- a/libflashrom.h
+++ b/libflashrom.h
@@ -1,6 +1,7 @@
/*
* This file is part of the flashrom project.
*
+ * Copyright (C) 2010 Google Inc.
* Copyright (C) 2012 secunet Security Networks AG
* (Written by Nico Huber <nico.huber@secunet.com> for secunet)
*
@@ -117,4 +118,32 @@
void flashrom_layout_release(struct flashrom_layout *);
void flashrom_layout_set(struct flashrom_flashctx *, const struct flashrom_layout *);
+/** @ingroup flashrom-wp */
+enum flashrom_wp_result {
+ FLASHROM_WP_OK = 0,
+ FLASHROM_WP_ERR_CHIP_UNSUPPORTED = 1,
+ FLASHROM_WP_ERR_OTHER = 2,
+ FLASHROM_WP_ERR_READ_FAILED = 3,
+ FLASHROM_WP_ERR_WRITE_FAILED = 4,
+ FLASHROM_WP_ERR_VERIFY_FAILED = 5
+};
+
+enum flashrom_wp_mode {
+ FLASHROM_WP_MODE_DISABLED,
+ FLASHROM_WP_MODE_HARDWARE,
+ FLASHROM_WP_MODE_POWER_CYCLE,
+ FLASHROM_WP_MODE_PERMANENT
+};
+struct flashrom_wp_cfg;
+
+enum flashrom_wp_result flashrom_wp_cfg_new(struct flashrom_wp_cfg **);
+void flashrom_wp_cfg_release(struct flashrom_wp_cfg *);
+void flashrom_wp_set_mode(struct flashrom_wp_cfg *, enum flashrom_wp_mode);
+enum flashrom_wp_mode flashrom_wp_get_mode(const struct flashrom_wp_cfg *);
+void flashrom_wp_set_range(struct flashrom_wp_cfg *, size_t start, size_t len);
+void flashrom_wp_get_range(size_t *start, size_t *len, const struct flashrom_wp_cfg *);
+
+enum flashrom_wp_result flashrom_wp_read_cfg(struct flashrom_wp_cfg *, struct flashrom_flashctx *);
+enum flashrom_wp_result flashrom_wp_write_cfg(struct flashrom_flashctx *, const struct flashrom_wp_cfg *);
+
#endif /* !__LIBFLASHROM_H__ */