Attention is currently required from: Thomas Heijligen, Nicholas Chin.
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/70573 )
Change subject: ch347_spi.c: Initial support for the WCH CH347
......................................................................
Patch Set 2: Code-Review+1
(6 comments)
File ch347_spi.c:
https://review.coreboot.org/c/flashrom/+/70573/comment/d4d56a34_ec6727d6
PS2, Line 24: #define CH347_CMD_SPI_CFG 0xC0
: #define CH347_CMD_SPI_CS_CTRL 0xC1
: #define CH347_CMD_SPI_OUT_IN 0xC2
: #define CH347_CMD_SPI_IN 0xC3
: #define CH347_CMD_SPI_OUT 0xC4
Suggestion: use tabs to align the hex values?
```
#define CH347_CMD_SPI_CFG 0xC0
#define CH347_CMD_SPI_CS_CTRL 0xC1
#define CH347_CMD_SPI_OUT_IN 0xC2
#define CH347_CMD_SPI_IN 0xC3
#define CH347_CMD_SPI_OUT 0xC4
```
https://review.coreboot.org/c/flashrom/+/70573/comment/63330009_bb1e3c85
PS2, Line 48: static struct libusb_device_handle *handle = NULL;
There have been changes to other programmers to pass this kind of data around through the flashctx. It'd be nice to do so here as well.
https://review.coreboot.org/c/flashrom/+/70573/comment/70c9c377_3f928e2e
PS2, Line 51: 1
Do you need to specify the array size? Or is this hardcoded because the code below only tries opening a device with this ID?
https://review.coreboot.org/c/flashrom/+/70573/comment/668a20d3_272d8b52
PS2, Line 71: uint8_t cmd[13] = {0};
: cmd[0] = CH347_CMD_SPI_CS_CTRL;
: /* payload length, uint16 LSB: 10 */
: cmd[1] = 10;
:
: cmd[3] = cs1;
: cmd[8] = cs2;
How about:
```
uint8_t cmd[13] = {
[0] = CH347_CMD_SPI_CS_CTRL,
/* payload length, uint16 LSB: 10 */
[1] = 10,
[3] = cs1,
[8] = cs2,
};
```
https://review.coreboot.org/c/flashrom/+/70573/comment/d3e14433_b2a08e5d
PS2, Line 221:
nit: trailing space
https://review.coreboot.org/c/flashrom/+/70573/comment/455c3f1a_f0b22586
PS2, Line 287: uint16_t vid = devs_ch347_spi[0].vendor_id;
: uint16_t pid = devs_ch347_spi[0].device_id;
: handle = libusb_open_device_with_vid_pid(NULL, vid, pid);
: if (handle == NULL) {
: msg_perr("Couldn't open device %04x:%04x.\n", vid, pid);
: return -1;
: }
Does the CH341A code do the same? It should be fine as long as there's only one VID/DID in the list.
--
To view, visit https://review.coreboot.org/c/flashrom/+/70573
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I31b86c41076cc45d4a416a73fa1131350fb745ba
Gerrit-Change-Number: 70573
Gerrit-PatchSet: 2
Gerrit-Owner: Nicholas Chin <nic.c3.14(a)gmail.com>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Thomas Heijligen <src(a)posteo.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-Attention: Thomas Heijligen <src(a)posteo.de>
Gerrit-Attention: Nicholas Chin <nic.c3.14(a)gmail.com>
Gerrit-Comment-Date: Sun, 11 Dec 2022 11:01:54 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: Thomas Heijligen.
Hello build bot (Jenkins), Thomas Heijligen,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/flashrom/+/70573
to look at the new patch set (#2).
Change subject: ch347_spi.c: Initial support for the WCH CH347
......................................................................
ch347_spi.c: Initial support for the WCH CH347
Add support for the WCH CH347, a high-speed USB to bus converter
supporting multiple protocols interfaces including SPI. Currently only
mode 1 (vendor defined communication interface) is supported, mode 2
(USB HID communication interface) support will be added later. The code
is currently hard coded to use a CS1 and a SPI clock of 60 MHz, though
there are 2 CS lines and 6 other GPIO lines available, as well as a
configurable clock divisor. Support for these will be exposed through
programmer parameters in later commits.
This currently uses the synchronous libusb API. Performance seems to be
alright so far, if it becomes an issue I may switch to the asynchronous
API.
Tested with a MX25L1606E flash chip and a hard coded divisor of 2 for a
SPI clock speed of 15 MHz, as I was having signal integrity issues at
higher clock speeds.
Signed-off-by: Nicholas Chin <nic.c3.14(a)gmail.com>
Change-Id: I31b86c41076cc45d4a416a73fa1131350fb745ba
---
M Makefile
A ch347_spi.c
M include/programmer.h
M programmer_table.c
4 files changed, 388 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/73/70573/2
--
To view, visit https://review.coreboot.org/c/flashrom/+/70573
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I31b86c41076cc45d4a416a73fa1131350fb745ba
Gerrit-Change-Number: 70573
Gerrit-PatchSet: 2
Gerrit-Owner: Nicholas Chin <nic.c3.14(a)gmail.com>
Gerrit-Reviewer: Thomas Heijligen <src(a)posteo.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-Attention: Thomas Heijligen <src(a)posteo.de>
Gerrit-MessageType: newpatchset
Attention is currently required from: Felix Singer.
Edward O'Callaghan has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/68153 )
Change subject: libflashrom.c: Invert if conditions to improve the readability
......................................................................
Patch Set 6: Code-Review+2
--
To view, visit https://review.coreboot.org/c/flashrom/+/68153
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I4021d8802cd041dcca29a226af0798ebd9c5a81b
Gerrit-Change-Number: 68153
Gerrit-PatchSet: 6
Gerrit-Owner: Felix Singer <felixsinger(a)posteo.net>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-Attention: Felix Singer <felixsinger(a)posteo.net>
Gerrit-Comment-Date: Sun, 11 Dec 2022 07:21:01 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: Thomas Heijligen.
Peter Stuge has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/70571 )
Change subject: serial: Add Darwin/macOS support for custom and >230400 baudrates
......................................................................
serial: Add Darwin/macOS support for custom and >230400 baudrates
This change is based on the patch proposed by Denis Ahrens in
https://review.coreboot.org/c/flashrom/+/67822
Change-Id: I3e6b88d2b4c2a130b16456752681fd9f807bf6f0
Signed-off-by: Peter Stuge <peter(a)stuge.se>
---
M Makefile
A custom_baud_darwin.c
M meson.build
M serial.c
4 files changed, 87 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/71/70571/1
diff --git a/Makefile b/Makefile
index 729ff7a..3ae6c8a 100644
--- a/Makefile
+++ b/Makefile
@@ -803,9 +803,13 @@
ifeq ($(TARGET_OS), Linux)
LIB_OBJS += custom_baud_linux.o
else
+ifeq ($(TARGET_OS), Darwin)
+LIB_OBJS += custom_baud_darwin.o
+else
LIB_OBJS += custom_baud.o
endif
endif
+endif
USE_SOCKETS := $(if $(call filter_deps,$(DEPENDS_ON_SOCKETS)),yes,no)
ifeq ($(USE_SOCKETS), yes)
diff --git a/custom_baud_darwin.c b/custom_baud_darwin.c
new file mode 100644
index 0000000..7525ac2
--- /dev/null
+++ b/custom_baud_darwin.c
@@ -0,0 +1,62 @@
+/*
+ * This file is part of the flashrom project.
+ *
+ * Copyright (C) 2022 Peter Stuge <peter(a)stuge.se>
+ *
+ * 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 <termios.h>
+#include <sys/ioctl.h>
+#include <IOKit/serial/ioss.h>
+#include <errno.h>
+
+#include "custom_baud.h"
+
+int set_custom_baudrate(int fd, unsigned int baud, const enum custom_baud_stage stage, void *tio_wanted) {
+ speed_t speed;
+ struct termios *wanted = tio_wanted;
+
+ switch (stage) {
+ case BEFORE_FLAGS:
+ break;
+
+ case WITH_FLAGS:
+ if (cfsetspeed(wanted, B19200) == -1)
+ return -1;
+ break;
+
+ case AFTER_FLAGS:
+ speed = baud;
+
+ if (ioctl(fd, IOSSIOSPEED, &speed) == -1)
+ return -1;
+
+ cfsetispeed(wanted, speed);
+ cfsetospeed(wanted, speed);
+ break;
+ }
+
+ return 0;
+}
+
+int use_custom_baud(unsigned int baud, const struct baudentry *baudtable)
+{
+ int i;
+ for (i = 0; baudtable[i].baud; i++) {
+ if (baudtable[i].baud == baud)
+ return 0;
+
+ if (baudtable[i].baud > baud)
+ return 1;
+ }
+ return 1;
+}
diff --git a/meson.build b/meson.build
index a93b1f9..8c11e77 100644
--- a/meson.build
+++ b/meson.build
@@ -108,6 +108,8 @@
if host_machine.system() == 'linux'
custom_baud_c = 'custom_baud_linux.c'
+elif host_machine.system() == 'darwin'
+ custom_baud_c = 'custom_baud_darwin.c'
else
custom_baud_c = 'custom_baud.c'
endif
diff --git a/serial.c b/serial.c
index cfc9b1e..4b4ca39 100644
--- a/serial.c
+++ b/serial.c
@@ -47,6 +47,10 @@
* On Linux there is a non-standard way to use arbitrary baud rates that we use if there is no
* matching standard rate, see custom_baud.c
*
+ * On Darwin there is also a non-standard ioctl() to set arbitrary baud rates
+ * and any above 230400, see custom_baud_darwin.c and
+ * https://opensource.apple.com/source/IOSerialFamily/IOSerialFamily-91/tests/…
+ *
* On Windows there exist similar macros (starting with CBR_ instead of B) but they are only defined for
* backwards compatibility and the API supports arbitrary baud rates in the same manner as the macros, see
* http://msdn.microsoft.com/en-us/library/windows/desktop/aa363214(v=vs.85).a…
@@ -71,6 +75,7 @@
#ifdef B230400
BAUDENTRY(230400)
#endif
+#if !IS_DARWIN
#ifdef B460800
BAUDENTRY(460800)
#endif
@@ -107,6 +112,7 @@
#ifdef B4000000
BAUDENTRY(4000000)
#endif
+#endif /* !IS_DARWIN */
{0, 0} /* Terminator */
};
--
To view, visit https://review.coreboot.org/c/flashrom/+/70571
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I3e6b88d2b4c2a130b16456752681fd9f807bf6f0
Gerrit-Change-Number: 70571
Gerrit-PatchSet: 1
Gerrit-Owner: Peter Stuge <peter(a)stuge.se>
Gerrit-Reviewer: Thomas Heijligen <src(a)posteo.de>
Gerrit-Attention: Thomas Heijligen <src(a)posteo.de>
Gerrit-MessageType: newchange
Peter Stuge has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/70569 )
Change subject: serial: Call set_custom_baudrate() thrice
......................................................................
serial: Call set_custom_baudrate() thrice
Call the function before tcsetattr() settings are known, then again
with settings prepared but not yet applied and finally a third time
after tcsetattr().
Darwin support needs this change; there custom_baud code must be
called to modify the settings passed to tcsetattr() and then again
after tcsetattr() returns.
The change should be non-functional on all currently supported systems;
current code calls set_custom_baudrate() before any tcsetattr()
settings are prepared, so we have three stages in total.
This change originates from discussion of the macOS patch proposed by
Denis Ahrens in https://review.coreboot.org/c/flashrom/+/67822
Change-Id: I40cc443cfb7bf6b212b31826d437b898cc13c427
Signed-off-by: Peter Stuge <peter(a)stuge.se>
---
M custom_baud.c
M custom_baud_linux.c
M include/custom_baud.h
M serial.c
4 files changed, 52 insertions(+), 6 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/69/70569/1
diff --git a/custom_baud.c b/custom_baud.c
index 28f182c..8bbe6cc 100644
--- a/custom_baud.c
+++ b/custom_baud.c
@@ -19,7 +19,7 @@
#include "custom_baud.h"
/* Stub, should not get called. */
-int set_custom_baudrate(int fd, unsigned int baud)
+int set_custom_baudrate(int fd, unsigned int baud, const enum custom_baud_stage stage, void *tio_wanted)
{
errno = ENOSYS; /* Hoping "Function not supported" will make you look here. */
return -1;
diff --git a/custom_baud_linux.c b/custom_baud_linux.c
index 2d5f261..761d496 100644
--- a/custom_baud_linux.c
+++ b/custom_baud_linux.c
@@ -29,9 +29,13 @@
* for more info.
*/
-int set_custom_baudrate(int fd, unsigned int baud)
+int set_custom_baudrate(int fd, unsigned int baud, const enum custom_baud_stage stage, void *tio_wanted)
{
struct termios2 tio;
+
+ if (stage != BEFORE_FLAGS)
+ return 0;
+
if (ioctl(fd, TCGETS2, &tio)) {
return -1;
}
diff --git a/include/custom_baud.h b/include/custom_baud.h
index c8b8fc2..38e6cfc 100644
--- a/include/custom_baud.h
+++ b/include/custom_baud.h
@@ -22,7 +22,13 @@
unsigned int baud;
};
-int set_custom_baudrate(int fd, unsigned int baud);
+enum custom_baud_stage {
+ BEFORE_FLAGS = 0,
+ WITH_FLAGS,
+ AFTER_FLAGS
+};
+
+int set_custom_baudrate(int fd, unsigned int baud, const enum custom_baud_stage stage, void *tio_wanted);
/* Returns 1 if non-exact rate would be used, and setting a custom rate is supported.
The baudtable must be in ascending order and terminated with a 0-baud entry. */
diff --git a/serial.c b/serial.c
index 72f9ef6..cfc9b1e 100644
--- a/serial.c
+++ b/serial.c
@@ -179,6 +179,7 @@
}
msg_pdbg("Baud rate is %ld.\n", dcb.BaudRate);
#else
+ int custom_baud = (baud >= 0 && use_custom_baud(baud, sp_baudtable));
struct termios wanted, observed;
if (tcgetattr(fd, &observed) != 0) {
msg_perr_strerror("Could not fetch original serial port configuration: ");
@@ -186,8 +187,8 @@
}
wanted = observed;
if (baud >= 0) {
- if (use_custom_baud(baud, sp_baudtable)) {
- if (set_custom_baudrate(fd, baud)) {
+ if (custom_baud) {
+ if (set_custom_baudrate(fd, baud, BEFORE_FLAGS, NULL)) {
msg_perr_strerror("Could not set custom baudrate: ");
return 1;
}
@@ -198,7 +199,6 @@
msg_perr_strerror("Could not fetch serial port configuration: ");
return 1;
}
- msg_pdbg("Using custom baud rate.\n");
} else {
const struct baudentry *entry = round_baud(baud);
if (cfsetispeed(&wanted, entry->flag) != 0 || cfsetospeed(&wanted, entry->flag) != 0) {
@@ -212,6 +212,10 @@
wanted.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG | IEXTEN);
wanted.c_iflag &= ~(IXON | IXOFF | IXANY | ICRNL | IGNCR | INLCR);
wanted.c_oflag &= ~OPOST;
+ if (custom_baud && set_custom_baudrate(fd, baud, WITH_FLAGS, &wanted)) {
+ msg_perr_strerror("Could not set custom baudrate: ");
+ return 1;
+ }
if (tcsetattr(fd, TCSANOW, &wanted) != 0) {
msg_perr_strerror("Could not change serial port configuration: ");
return 1;
@@ -236,6 +240,13 @@
(long)observed.c_oflag, (long)wanted.c_oflag
);
}
+ if (custom_baud) {
+ if (set_custom_baudrate(fd, baud, AFTER_FLAGS, &wanted)) {
+ msg_perr_strerror("Could not set custom baudrate: ");
+ return 1;
+ }
+ msg_pdbg("Using custom baud rate.\n");
+ }
if (cfgetispeed(&observed) != cfgetispeed(&wanted) ||
cfgetospeed(&observed) != cfgetospeed(&wanted)) {
msg_pwarn("Could not set baud rates exactly.\n");
--
To view, visit https://review.coreboot.org/c/flashrom/+/70569
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I40cc443cfb7bf6b212b31826d437b898cc13c427
Gerrit-Change-Number: 70569
Gerrit-PatchSet: 1
Gerrit-Owner: Peter Stuge <peter(a)stuge.se>
Gerrit-MessageType: newchange
Attention is currently required from: Nikolai Artemiev.
Edward O'Callaghan has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/70515 )
Change subject: flashrom: Check for flash access restricitons in verify_range()
......................................................................
Patch Set 3: Code-Review+2
--
To view, visit https://review.coreboot.org/c/flashrom/+/70515
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I61dfadd3c75365f2e55abeea75f673ab791ca5cc
Gerrit-Change-Number: 70515
Gerrit-PatchSet: 3
Gerrit-Owner: Nikolai Artemiev <nartemiev(a)google.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec(a)chromium.org>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-Attention: Nikolai Artemiev <nartemiev(a)google.com>
Gerrit-Comment-Date: Sat, 10 Dec 2022 23:49:08 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment