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
Attention is currently required from: Nikolai Artemiev.
Edward O'Callaghan has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/70514 )
Change subject: flashrom: Check for flash access restricitons in read_flash()
......................................................................
Patch Set 3: Code-Review+2
--
To view, visit https://review.coreboot.org/c/flashrom/+/70514
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I22c795d7d08ef8bf773733d9952967b2fa2ef299
Gerrit-Change-Number: 70514
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:48:31 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: Felix Singer.
Edward O'Callaghan has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/68151 )
Change subject: flashchips.c: Indent definition of W25Q512NW-IM properly
......................................................................
Patch Set 1: Code-Review+2
--
To view, visit https://review.coreboot.org/c/flashrom/+/68151
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Icfd2a49383da0f8f0a4e3295aba81ce1d200652c
Gerrit-Change-Number: 68151
Gerrit-PatchSet: 1
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: Sat, 10 Dec 2022 23:46:40 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment