1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-10-27 11:22:10 +01:00

serial.h: Extract serial declarations to a separate header

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 <antoniovazquezblanco@gmail.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/89650
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Antonio Vázquez
2025-10-20 23:10:19 +02:00
committed by Anastasia Klimchuk
parent db43ab2989
commit 78ef763042
7 changed files with 61 additions and 48 deletions

View File

@@ -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

View File

@@ -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)
{

55
include/serial.h Normal file
View File

@@ -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__ */

View File

@@ -36,6 +36,7 @@
#include "flash.h"
#include "programmer.h"
#include "platform/udelay.h"
#include "serial.h"
enum pony_type {
TYPE_SI_PROG,

View File

@@ -15,6 +15,8 @@
* GNU General Public License for more details.
*/
#include "serial.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

View File

@@ -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

View File

@@ -23,6 +23,7 @@
#include "programmer.h"
#include "spi.h"
#include "platform/udelay.h"
#include "serial.h"
static int spidriver_serialport_setup(char *dev)
{