aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mediatek_i2c_spi.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/mediatek_i2c_spi.c b/mediatek_i2c_spi.c
index 5757f31e..4929fbf9 100644
--- a/mediatek_i2c_spi.c
+++ b/mediatek_i2c_spi.c
@@ -464,9 +464,46 @@ static const struct spi_master spi_master_i2c_mediatek = {
.probe_opcode = default_spi_probe_opcode,
};
+static int get_params(bool *allow_brick)
+{
+ char *brick_str = NULL;
+ int ret = 0;
+
+ *allow_brick = false; /* Default behaviour is to bail. */
+ brick_str = extract_programmer_param_str("allow_brick");
+ if (brick_str) {
+ if (!strcmp(brick_str, "yes")) {
+ *allow_brick = true;
+ } else {
+ msg_perr("%s: Incorrect param format, allow_brick=yes.\n", __func__);
+ ret = SPI_GENERIC_ERROR;
+ }
+ }
+ free(brick_str);
+
+ return ret;
+}
+
static int mediatek_init(void)
{
int ret;
+ bool allow_brick;
+
+ if (get_params(&allow_brick))
+ return SPI_GENERIC_ERROR;
+
+ /*
+ * TODO: Once board_enable can facilitate safe i2c allow listing
+ * then this can be removed.
+ */
+ if (!allow_brick) {
+ msg_perr("%s: For i2c drivers you must explicitly 'allow_brick=yes'. ", __func__);
+ msg_perr("There is currently no way to determine if the programmer works on a board "
+ "as i2c device address space can be overloaded. Set 'allow_brick=yes' if "
+ "you are sure you know what you are doing.\n");
+ return SPI_GENERIC_ERROR;
+ }
+
int fd = i2c_open_from_programmer_params(ISP_PORT, 0);
if (fd < 0) {
msg_perr("Failed to open i2c\n");