From 78ef7630428a1c4f61880e803bcbf6f8b0d77b62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20V=C3=A1zquez?= Date: Mon, 20 Oct 2025 23:10:19 +0200 Subject: [PATCH] serial.h: Extract serial declarations to a separate header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch moves all the declarations relevant to serial into their own header in include/serial.h. The corresponding functions implementations are already in serial.c, so the declarations naturally can be in serial.h Currently, most of the declarations reside in flash.h making it difficult to really understand file dependency. Change-Id: Id0b4d188e2a94dbc4d90747c05eabca39c6b3f26 Signed-off-by: Antonio Vázquez Reviewed-on: https://review.coreboot.org/c/flashrom/+/89650 Reviewed-by: Anastasia Klimchuk Tested-by: build bot (Jenkins) --- buspirate_spi.c | 1 + include/programmer.h | 48 -------------------------------------- include/serial.h | 55 ++++++++++++++++++++++++++++++++++++++++++++ pony_spi.c | 1 + serial.c | 2 ++ serprog.c | 1 + spidriver.c | 1 + 7 files changed, 61 insertions(+), 48 deletions(-) create mode 100644 include/serial.h diff --git a/buspirate_spi.c b/buspirate_spi.c index c2f8f4fea..56315ca08 100644 --- a/buspirate_spi.c +++ b/buspirate_spi.c @@ -15,6 +15,7 @@ #include "programmer.h" #include "spi.h" #include "platform/udelay.h" +#include "serial.h" /* Change this to #define if you want to test without a serial implementation */ #undef FAKE_COMMUNICATION diff --git a/include/programmer.h b/include/programmer.h index acf23bd64..116e81c0a 100644 --- a/include/programmer.h +++ b/include/programmer.h @@ -432,54 +432,6 @@ extern struct registered_master registered_masters[]; extern int registered_master_count; int register_master(const struct registered_master *mst); - - -/* serial.c */ -#if IS_WINDOWS -typedef HANDLE fdtype; -#define SER_INV_FD INVALID_HANDLE_VALUE -#else -typedef int fdtype; -#define SER_INV_FD -1 -#endif - -void sp_flush_incoming(void); -fdtype sp_openserport(char *dev, int baud); -extern fdtype sp_fd; -int serialport_config(fdtype fd, int baud); -int serialport_shutdown(void *data); -int serialport_write(const unsigned char *buf, unsigned int writecnt); -int serialport_write_nonblock(const unsigned char *buf, unsigned int writecnt, unsigned int timeout, unsigned int *really_wrote); -int serialport_read(unsigned char *buf, unsigned int readcnt); -int serialport_read_nonblock(unsigned char *c, unsigned int readcnt, unsigned int timeout, unsigned int *really_read); - -/* Serial port/pin mapping: - - 1 CD <- - 2 RXD <- - 3 TXD -> - 4 DTR -> - 5 GND -- - 6 DSR <- - 7 RTS -> - 8 CTS <- - 9 RI <- -*/ -enum SP_PIN { - PIN_CD = 1, - PIN_RXD, - PIN_TXD, - PIN_DTR, - PIN_GND, - PIN_DSR, - PIN_RTS, - PIN_CTS, - PIN_RI, -}; - -void sp_set_pin(enum SP_PIN pin, int val); -int sp_get_pin(enum SP_PIN pin); - /* spi_master feature checks */ static inline bool spi_master_4ba(const struct flashctx *const flash) { diff --git a/include/serial.h b/include/serial.h new file mode 100644 index 000000000..392db464f --- /dev/null +++ b/include/serial.h @@ -0,0 +1,55 @@ +/* + * This file is part of the flashrom project. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef __SERIAL_H__ +#define __SERIAL_H__ 1 + +#if IS_WINDOWS +typedef HANDLE fdtype; +#define SER_INV_FD INVALID_HANDLE_VALUE +#else +typedef int fdtype; +#define SER_INV_FD -1 +#endif + +void sp_flush_incoming(void); +fdtype sp_openserport(char *dev, int baud); +extern fdtype sp_fd; +int serialport_config(fdtype fd, int baud); +int serialport_shutdown(void *data); +int serialport_write(const unsigned char *buf, unsigned int writecnt); +int serialport_write_nonblock(const unsigned char *buf, unsigned int writecnt, unsigned int timeout, unsigned int *really_wrote); +int serialport_read(unsigned char *buf, unsigned int readcnt); +int serialport_read_nonblock(unsigned char *c, unsigned int readcnt, unsigned int timeout, unsigned int *really_read); + +/* Serial port/pin mapping: + + 1 CD <- + 2 RXD <- + 3 TXD -> + 4 DTR -> + 5 GND -- + 6 DSR <- + 7 RTS -> + 8 CTS <- + 9 RI <- +*/ +enum SP_PIN { + PIN_CD = 1, + PIN_RXD, + PIN_TXD, + PIN_DTR, + PIN_GND, + PIN_DSR, + PIN_RTS, + PIN_CTS, + PIN_RI, +}; + +void sp_set_pin(enum SP_PIN pin, int val); +int sp_get_pin(enum SP_PIN pin); + +#endif /* !__SERIAL_H__ */ diff --git a/pony_spi.c b/pony_spi.c index 39dacb936..4d0397f8f 100644 --- a/pony_spi.c +++ b/pony_spi.c @@ -36,6 +36,7 @@ #include "flash.h" #include "programmer.h" #include "platform/udelay.h" +#include "serial.h" enum pony_type { TYPE_SI_PROG, diff --git a/serial.c b/serial.c index 0a2ea305e..06f8b5119 100644 --- a/serial.c +++ b/serial.c @@ -15,6 +15,8 @@ * GNU General Public License for more details. */ +#include "serial.h" + #include #include #include diff --git a/serprog.c b/serprog.c index 29fe88a43..82b538f23 100644 --- a/serprog.c +++ b/serprog.c @@ -30,6 +30,7 @@ #include "programmer.h" #include "chipdrivers.h" #include "platform/udelay.h" +#include "serial.h" /* According to Serial Flasher Protocol Specification - version 1 */ #define S_ACK 0x06 diff --git a/spidriver.c b/spidriver.c index 494077061..7b097f2be 100644 --- a/spidriver.c +++ b/spidriver.c @@ -23,6 +23,7 @@ #include "programmer.h" #include "spi.h" #include "platform/udelay.h" +#include "serial.h" static int spidriver_serialport_setup(char *dev) {