Shiyu Sun has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/39686 )
Change subject: i2c_helper: Add support for the Linux I2C subsystem
......................................................................
i2c_helper: Add support for the Linux I2C subsystem
See https://www.kernel.org/doc/Documentation/i2c/ for details.
This creates common interface for I2C access functions, and adds
implementation for linux I2C functions.
Signed-off-by: Shiyu Sun <sshiyu(a)chromium.org>
Change-Id: Ie0487824dfb71970bede17f617dbbb30ddf78c12
---
M Makefile
A i2c_helper.h
A i2c_helper_linux.c
M meson.build
M meson_options.txt
5 files changed, 241 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/86/39686/1
diff --git a/Makefile b/Makefile
index 28ceab6..aa77a64 100644
--- a/Makefile
+++ b/Makefile
@@ -418,6 +418,10 @@
endif
endif
+ifeq ($(TARGET_OS), Linux)
+CONFIG_LINUX_I2C_HELPER = yes
+endif
+
###############################################################################
# General architecture-specific settings.
# Like above for the OS, below we verify user-supplied options depending on the target architecture.
@@ -1047,6 +1051,11 @@
PROGRAMMER_OBJS += ni845x_spi.o
endif
+ifeq ($(CONFIG_LINUX_I2C_HELPER), yes)
+LIB_OBJS += i2c_helper_linux.o
+FEATURE_CFLAGS += -D'CONFIG_LINUX_I2C_HELPER=1'
+endif
+
ifneq ($(NEED_SERIAL), )
LIB_OBJS += serial.o custom_baud.o
endif
diff --git a/i2c_helper.h b/i2c_helper.h
new file mode 100644
index 0000000..80dc836
--- /dev/null
+++ b/i2c_helper.h
@@ -0,0 +1,112 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright (C) 2020 The Chromium OS Authors
+ *
+ * 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.
+ */
+
+#ifndef I2C_HELPER_H
+#define I2C_HELPER_H
+
+#include <inttypes.h>
+
+/**
+ * An convinent structure that contains the buffer size and the buffer
+ * pointer. Used to wrap buffer details while doing the I2C data
+ * transfer on both input and output. It is the client's responsibility
+ * to use i2c_buffer_t_fill to initialize this struct instead of
+ * trying to construct it directly.
+ */
+typedef struct {
+ void *buf;
+ uint16_t len;
+} i2c_buffer_t;
+
+/**
+ * i2c_buffer_t_fill - fills in the i2c_buffer_t
+ *
+ * @i2c_buf: pointer to the be constructed.
+ * @buf: buffer contains data to be included in i2c_buffer_t.
+ * @len: length of buffer to be included in i2c_buffer_t.
+ *
+ * This function takes in a pointer to an initialized i2c_buffer_t
+ * object with related information, and fill in the i2c_buffer_t with
+ * some validation applied. The function does allow initialization with
+ * NULL buffer but will make sure len == 0 in such case.
+ *
+ * returns 0 on success, <0 to indicate failure
+ */
+static inline int i2c_buffer_t_fill(i2c_buffer_t *i2c_buf, void *buf, uint16_t len)
+{
+ if (!i2c_buf || (!buf && len))
+ return -1;
+
+ i2c_buf -> buf = buf;
+ i2c_buf -> len = len;
+
+ return 0;
+}
+
+/**
+ * i2c_open - opens the target I2C device and set the I2C slave address
+ *
+ * @bus: I2C bus number of the target device.
+ * @addr: I2C slave address.
+ * @force: whether to force set the I2C slave address.
+ *
+ * This function returns a file descriptor for the target device. It is
+ * the client's responsibility to pass the return value to i2c_close to
+ * clean up.
+ *
+ * returns fd of target device on success, <0 to indicate failure
+ */
+int i2c_open(int bus, uint16_t addr, int force);
+
+/**
+ * i2c_close - closes the file descriptor returned by i2c_open
+ *
+ * @fd: file descriptor to be closed.
+ *
+ * It is the client's responsibility to set fd = -1 when it is
+ * done with it.
+ *
+ * returns 0 on success, <0 to indicate failure
+ */
+int i2c_close(int fd);
+
+/**
+ * i2c_read - reads data from the I2C device
+ *
+ * @fd: file descriptor of the target device.
+ * @addr: I2C slave address of the target device.
+ * @buf_read: data struct includes reading buffer and size.
+ *
+ * This function does accept empty read and do nothing on such case.
+ *
+ * returns read length on success, <0 to indicate failure
+ */
+int i2c_read(int fd, uint16_t addr, i2c_buffer_t *buf_read);
+
+/**
+ * i2c_write - writes command/data into the I2C device
+ *
+ * @fd: file descriptor of the target device.
+ * @addr: I2C slave address of the target device.
+ * @buf_write: data struct includes writting buffer and size.
+ *
+ * This function does accept empty write and do nothing on such case.
+ *
+ * returns wrote length on success, <0 to indicate failure.
+ */
+int i2c_write(int fd, uint16_t addr, const i2c_buffer_t *buf_write);
+
+#endif /* !I2C_HELPER_H */
diff --git a/i2c_helper_linux.c b/i2c_helper_linux.c
new file mode 100644
index 0000000..0703518
--- /dev/null
+++ b/i2c_helper_linux.c
@@ -0,0 +1,113 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright (C) 2020 The Chromium OS Authors
+ *
+ * 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.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/fcntl.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+#include <stdlib.h>
+#include <linux/i2c.h>
+#include <linux/i2c-dev.h>
+
+#include "flash.h"
+#include "i2c_helper.h"
+
+#define I2C_DEV_PREFIX "/dev/i2c-"
+#define I2C_MAX_BUS 255
+
+int i2c_close(int fd)
+{
+ return fd == -1 ? 0 : close(fd);
+}
+
+int i2c_open(int bus, uint16_t addr, int force)
+{
+ int ret = -1;
+ int fd = -1;
+
+ /* Maximum i2c bus number is 255(3 char), +1 for null terminated string. */
+ int path_len = strlen(I2C_DEV_PREFIX) + 4;
+ int request = force ? I2C_SLAVE_FORCE : I2C_SLAVE;
+
+ if (bus < 0 || bus > I2C_MAX_BUS) {
+ msg_perr("Invalid I2C bus %d.\n", bus);
+ return ret;
+ }
+
+ char *dev = calloc(1, path_len);
+ if (!dev) {
+ msg_perr("Unable to allocate space for device name of len %d: %s.\n",
+ path_len, strerror(errno));
+ goto linux_i2c_open_err;
+ }
+
+ ret = snprintf(dev, path_len, "%s%d", I2C_DEV_PREFIX, bus);
+ if (ret < 0) {
+ msg_perr("Unable to join bus number to device name: %s.\n", strerror(errno));
+ goto linux_i2c_open_err;
+ }
+
+ fd = open(dev, O_RDWR);
+ if (fd < 0) {
+ msg_perr("Unable to open I2C device %s: %s.\n", dev, strerror(errno));
+ ret = fd;
+ goto linux_i2c_open_err;
+ }
+
+ ret = ioctl(fd, request, addr);
+ if (ret < 0) {
+ msg_perr("Unable to set I2C slave address to 0x%02x: %s.\n", addr, strerror(errno));
+ i2c_close(fd);
+ goto linux_i2c_open_err;
+ }
+
+linux_i2c_open_err:
+ if (dev)
+ free(dev);
+
+ return ret ? ret : fd;
+}
+
+int i2c_read(int fd, uint16_t addr, i2c_buffer_t *buf)
+{
+ if (buf->len == 0)
+ return 0;
+
+ int ret = ioctl(fd, I2C_SLAVE, addr);
+ if (ret < 0) {
+ msg_perr("Unable to set I2C slave address to 0x%02x: %s.\n", addr, strerror(errno));
+ return ret;
+ }
+
+ return read(fd, buf->buf, buf->len);
+}
+
+int i2c_write(int fd, uint16_t addr, const i2c_buffer_t *buf)
+{
+ if (buf->len == 0)
+ return 0;
+
+ int ret = ioctl(fd, I2C_SLAVE, addr);
+ if (ret < 0) {
+ msg_perr("Unable to set I2C slave address to 0x%02x: %s.\n", addr, strerror(errno));
+ return ret;
+ }
+
+ return write(fd, buf->buf, buf->len);
+}
diff --git a/meson.build b/meson.build
index 8bb3e65..b586d9a 100644
--- a/meson.build
+++ b/meson.build
@@ -63,6 +63,7 @@
config_serprog = get_option('config_serprog')
config_usbblaster_spi = get_option('config_usbblaster_spi')
config_stlinkv3_spi = get_option('config_stlinkv3_spi')
+config_linux_i2c_helper = get_option('config_linux_i2c_helper')
cargs = []
deps = []
@@ -290,6 +291,11 @@
cargs += '-DCONFIG_BITBANG_SPI=1'
endif
+if config_linux_i2c_helper
+ srcs += 'i2c_helper_linux.c'
+ cargs += '-DCONFIG_LINUX_I2C_HELPER=1'
+endif
+
# raw memory, MSR or PCI port I/O access
if need_raw_access
srcs += 'hwaccess.c'
diff --git a/meson_options.txt b/meson_options.txt
index 2831271..ff4a786 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -35,3 +35,4 @@
option('config_serprog', type : 'boolean', value : true, description : 'serprog')
option('config_usbblaster_spi', type : 'boolean', value : true, description : 'Altera USB-Blaster dongles')
option('config_stlinkv3_spi', type : 'boolean', value : true, description : 'STMicroelectronics STLINK-V3')
+option('config_linux_i2c_helper', type: 'boolean', value : true, description : 'Linux I2C control')
--
To view, visit https://review.coreboot.org/c/flashrom/+/39686
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ie0487824dfb71970bede17f617dbbb30ddf78c12
Gerrit-Change-Number: 39686
Gerrit-PatchSet: 1
Gerrit-Owner: Shiyu Sun <sshiyu(a)google.com>
Gerrit-MessageType: newchange
Edward O'Callaghan has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/39896 )
Change subject: Makefile: Fix 'CONFIG_ENABLE_LIBUSB1_PROGRAMMERS=no'
......................................................................
Makefile: Fix 'CONFIG_ENABLE_LIBUSB1_PROGRAMMERS=no'
Turns out CONFIG_RAIDEN was missing in the LIBUSB1
as no overrides. Credit to HAOUAS Elyes for spotting this.
Change-Id: I7dd26665a0133175949c11717837e9de68a1bf71
Signed-off-by: Edward O'Callaghan <quasisec(a)google.com>
---
M Makefile
1 file changed, 1 insertion(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/96/39896/1
diff --git a/Makefile b/Makefile
index 28ceab6..4c6c4cc 100644
--- a/Makefile
+++ b/Makefile
@@ -730,6 +730,7 @@
override CONFIG_DIGILENT_SPI = no
override CONFIG_DEVELOPERBOX_SPI = no
override CONFIG_PICKIT2_SPI = no
+override CONFIG_RAIDEN = no
override CONFIG_STLINKV3_SPI = no
endif
ifeq ($(CONFIG_ENABLE_LIBPCI_PROGRAMMERS), no)
--
To view, visit https://review.coreboot.org/c/flashrom/+/39896
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I7dd26665a0133175949c11717837e9de68a1bf71
Gerrit-Change-Number: 39896
Gerrit-PatchSet: 1
Gerrit-Owner: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-MessageType: newchange
David Hendricks has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/37407 )
Change subject: print.c: Fix alignment in print_supported_boards_helper()
......................................................................
print.c: Fix alignment in print_supported_boards_helper()
Commit 61e16e5 eliminated some duplicate logic for printing test status,
but in doing so introduced a regression where some entries in `flashrom
-L` output became unaligned.
Up until then, it was assumed that the status field will always be
8-wide, including space for padding. This patch fixes alignment when
using test_state_to_text() by making the padding consistent with other
fields where a for-loop is used to pad the field up to a maximum width.
Change-Id: Ie0a0b45c6466d14447aca443c2697e2048c6ef14
Signed-off-by: David Hendricks <david.hendricks(a)gmail.com>
---
M flash.h
M print.c
2 files changed, 29 insertions(+), 14 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/07/37407/1
diff --git a/flash.h b/flash.h
index 1a9bd9f..e7b1c89 100644
--- a/flash.h
+++ b/flash.h
@@ -145,10 +145,11 @@
enum test_state {
OK = 0,
- NT = 1, /* Not tested */
- BAD, /* Known to not work */
- DEP, /* Support depends on configuration (e.g. Intel flash descriptor) */
- NA, /* Not applicable (e.g. write support on ROM chips) */
+ NT = 1, /* Not tested */
+ BAD, /* Known to not work */
+ DEP, /* Support depends on configuration (e.g. Intel flash descriptor) */
+ NA, /* Not applicable (e.g. write support on ROM chips) */
+ TEST_STATE_END, /* Not a test state, just an indicator of how many are defined. */
};
#define TEST_UNTESTED (struct tested){ .probe = NT, .read = NT, .erase = NT, .write = NT }
diff --git a/print.c b/print.c
index 6a7ff5d..e5be6b6 100644
--- a/print.c
+++ b/print.c
@@ -35,6 +35,20 @@
}
}
+static size_t max_test_state_len(void)
+{
+ int i;
+ size_t max_len;
+
+ for (i = max_len = 0; i < TEST_STATE_END; i++) {
+ size_t len = strlen(test_state_to_text(i));
+ if (len > max_len)
+ max_len = len;
+ }
+
+ return max_len;
+}
+
static int print_supported_chips(void)
{
const char *delim = "/";
@@ -388,8 +402,12 @@
for (i = strlen("Board"); i < maxboardlen; i++)
msg_ginfo(" ");
- msg_ginfo("Status Required value for\n");
- for (i = 0; i < maxvendorlen + maxboardlen + strlen("Status "); i++)
+ msg_ginfo("Status");
+ for (i = strlen("Status"); i < max_test_state_len(); i++)
+ msg_ginfo(" ");
+
+ msg_ginfo("Required value for\n");
+ for (i = 0; i < maxvendorlen + maxboardlen + max_test_state_len(); i++)
msg_ginfo(" ");
msg_ginfo("-p internal:mainboard=\n");
@@ -401,14 +419,10 @@
for (i = 0; i < maxboardlen - strlen(b->name); i++)
msg_ginfo(" ");
- switch (b->working) {
- case OK: msg_ginfo("OK "); break;
- case NT: msg_ginfo("NT "); break;
- case DEP: msg_ginfo("DEP "); break;
- case NA: msg_ginfo("N/A "); break;
- case BAD:
- default: msg_ginfo("BAD "); break;
- }
+ const char *test_state = test_state_to_text(b->working);
+ msg_ginfo("%s", test_state);
+ for (i = 0; i < max_test_state_len() - strlen(test_state); i++)
+ msg_ginfo(" ");
for (e = board_matches; e->vendor_name != NULL; e++) {
if (strcmp(e->vendor_name, b->vendor)
--
To view, visit https://review.coreboot.org/c/flashrom/+/37407
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ie0a0b45c6466d14447aca443c2697e2048c6ef14
Gerrit-Change-Number: 37407
Gerrit-PatchSet: 1
Gerrit-Owner: David Hendricks <david.hendricks(a)gmail.com>
Gerrit-MessageType: newchange
David Hendricks has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/39640 )
Change subject: Copy Verified label from coreboot
......................................................................
Patch Set 3: Code-Review+2
--
To view, visit https://review.coreboot.org/c/flashrom/+/39640
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: refs/meta/config
Gerrit-Change-Id: Ie77d5b461992c166c54d01ecda6fb509ad0a4407
Gerrit-Change-Number: 39640
Gerrit-PatchSet: 3
Gerrit-Owner: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: David Hendricks <david.hendricks(a)gmail.com>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Patrick Georgi <pgeorgi(a)google.com>
Gerrit-Comment-Date: Thu, 26 Mar 2020 04:29:33 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Angel Pons has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/39826 )
Change subject: Fix segfault when running `flashrom -L`
......................................................................
Fix segfault when running `flashrom -L`
The raiden_debug programmer is of type USB. However, it does not set the
field `devs.dev`, which will result in a segfault when trying to print
the devices of the non-existing table.
FIx that by replacing `devs.note` with `devs.dev` and adding an empty
device table. Since Device IDs are not used to match programmers,
nothing could be added to the table.
TEST=Running `flashrom -L` no longer segfaults and returns normally.
Change-Id: Ie4171a11384c34abb102d1aadf86aa1b8829fc04
Signed-off-by: Angel Pons <th3fanbus(a)gmail.com>
---
M flashrom.c
M programmer.h
M raiden_debug_spi.c
3 files changed, 7 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/26/39826/1
diff --git a/flashrom.c b/flashrom.c
index e541b68..081b705 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -137,7 +137,7 @@
{
.name = "raiden_debug",
.type = USB,
- .devs.note = "All programmer devices speaking the raiden protocol\n",
+ .devs.dev = devs_raiden,
.init = raiden_debug_spi_init,
.map_flash_region = fallback_map,
.unmap_flash_region = fallback_unmap,
diff --git a/programmer.h b/programmer.h
index 08500c6..9a41be1 100644
--- a/programmer.h
+++ b/programmer.h
@@ -407,6 +407,7 @@
/* raiden_debug_spi.c */
#if CONFIG_RAIDEN == 1
int raiden_debug_spi_init(void);
+extern const struct dev_entry devs_raiden[];
#endif
/* drkaiser.c */
diff --git a/raiden_debug_spi.c b/raiden_debug_spi.c
index 6914455..173e355 100644
--- a/raiden_debug_spi.c
+++ b/raiden_debug_spi.c
@@ -116,6 +116,11 @@
#include <string.h>
#include <unistd.h>
+/* FIXME: Add some programmer IDs here */
+const struct dev_entry devs_raiden[] = {
+ {0},
+};
+
#define GOOGLE_VID (0x18D1)
#define GOOGLE_RAIDEN_SPI_SUBCLASS (0x51)
#define GOOGLE_RAIDEN_SPI_PROTOCOL (0x01)
--
To view, visit https://review.coreboot.org/c/flashrom/+/39826
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Ie4171a11384c34abb102d1aadf86aa1b8829fc04
Gerrit-Change-Number: 39826
Gerrit-PatchSet: 1
Gerrit-Owner: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-MessageType: newchange
Nico Huber has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/39640 )
Change subject: Copy Verified label from coreboot
......................................................................
Patch Set 3: Code-Review+1
Seems safe as Jenkins is re-triggered on rebase.
--
To view, visit https://review.coreboot.org/c/flashrom/+/39640
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: refs/meta/config
Gerrit-Change-Id: Ie77d5b461992c166c54d01ecda6fb509ad0a4407
Gerrit-Change-Number: 39640
Gerrit-PatchSet: 3
Gerrit-Owner: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Patrick Georgi <pgeorgi(a)google.com>
Gerrit-Comment-Date: Wed, 25 Mar 2020 23:30:37 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment