This is an automated email from the ASF dual-hosted git repository.
GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new b6c64e5af6a !drivers/rpmsg: check the rpmsg_port frame checksum
unconditionally
b6c64e5af6a is described below
commit b6c64e5af6a3bc067ad03e7e1e9c75e8ff56cde3
Author: wangshaoxin <[email protected]>
AuthorDate: Thu Oct 22 10:05:23 2026 +0800
!drivers/rpmsg: check the rpmsg_port frame checksum unconditionally
The frame checksum is gated by CONFIG_RPMSG_PORT_UART_CRC and
CONFIG_RPMSG_PORT_SPI_CRC, both off by default (SPI turns it on only
through RETX), so a corrupted frame goes undetected. On top of that, the
receivers skip the check when the crc field is zero, so a frame whose crc
field was zeroed in transit is accepted as valid.
Remove both options, always compute the checksum on transmit and always
verify it on receive, including frames carrying crc == 0. SPI keeps
folding a zero checksum to 1, so a valid SPI frame never carries 0.
BREAKING CHANGE: CONFIG_RPMSG_PORT_UART_CRC and CONFIG_RPMSG_PORT_SPI_CRC
are removed. A peer built without them sends crc == 0, which this side now
rejects, so both ends of an rpmsg_port link must be updated together.
Signed-off-by: wangshaoxin <[email protected]>
Signed-off-by: Bowen Wang <[email protected]>
---
.../os/drivers/special/rpmsg/rpmsg_port_uart.rst | 4 ++--
drivers/rpmsg/Kconfig | 17 -----------------
drivers/rpmsg/rpmsg_port_spi.c | 14 ++++----------
drivers/rpmsg/rpmsg_port_spi_slave.c | 14 ++++----------
drivers/rpmsg/rpmsg_port_uart.c | 9 ++-------
5 files changed, 12 insertions(+), 46 deletions(-)
diff --git a/Documentation/os/drivers/special/rpmsg/rpmsg_port_uart.rst
b/Documentation/os/drivers/special/rpmsg/rpmsg_port_uart.rst
index 1fc9b5d473d..fb54d8050a5 100644
--- a/Documentation/os/drivers/special/rpmsg/rpmsg_port_uart.rst
+++ b/Documentation/os/drivers/special/rpmsg/rpmsg_port_uart.rst
@@ -127,8 +127,8 @@ Data Frame Format
│ 2 byte │ 2 byte │ 2 byte │ 2 byte │ N bytes │
└────────┴────────┴────────┴────────┴──────────────┘
-- crc: 16-bit XOR checksum of the rest of the frame, see ``xorsum16()``
- (optional, enabled via CONFIG_RPMSG_PORT_UART_CRC)
+- crc: 16-bit XOR checksum of the rest of the frame, see ``xorsum16()``,
+ always checked by the receiver
- cmd: Command field (unused for data frames, set to 0)
- avail: Available space (unused for data frames, set to 0)
- len: Total length including header
diff --git a/drivers/rpmsg/Kconfig b/drivers/rpmsg/Kconfig
index 340ccfbcb2e..3280e82f266 100644
--- a/drivers/rpmsg/Kconfig
+++ b/drivers/rpmsg/Kconfig
@@ -188,7 +188,6 @@ config RPMSG_PORT_RETX
bool "Rpmsg Port Retransmission Support"
default y
depends on RPMSG_PORT
- select RPMSG_PORT_SPI_CRC if RPMSG_PORT_SPI || RPMSG_PORT_SPI_SLAVE
---help---
Enable retransmission mechanism for rpmsg port transport.
When enabled, unacknowledged DATA frames will be retransmitted
@@ -219,14 +218,6 @@ config RPMSG_PORT_SPI_THREAD_STACKSIZE
int "Rpmsg SPI Port Stack Size"
default 4096
-config RPMSG_PORT_SPI_CRC
- bool "Rpmsg SPI Port Use Checksum"
- default n
- ---help---
- Check every frame with a 16-bit XOR checksum (xorsum16()). It
- catches corrupted framing at little cost, but it is not a CRC:
it
- misses errors that flip the same bit in two 16-bit words.
-
config RPMSG_PORT_SPI_RX_THRESHOLD
int "Rpmsg SPI Port Rx Buffer Threshold"
default 50
@@ -265,14 +256,6 @@ config RPMSG_PORT_UART_TX_THREAD_STACKSIZE
int "Rpmsg UART Port TX Stack Size"
default DEFAULT_TASK_STACKSIZE
-config RPMSG_PORT_UART_CRC
- bool "Rpmsg UART Port Checksum Enable"
- default n
- ---help---
- Check every frame with a 16-bit XOR checksum (xorsum16()). It
- catches corrupted framing at little cost, but it is not a CRC:
it
- misses errors that flip the same bit in two 16-bit words.
-
config RPMSG_PORT_UART_COMPRESSION
bool "Rpmsg UART Port LZF Compression"
default n
diff --git a/drivers/rpmsg/rpmsg_port_spi.c b/drivers/rpmsg/rpmsg_port_spi.c
index fef73ba9521..512135376d6 100644
--- a/drivers/rpmsg/rpmsg_port_spi.c
+++ b/drivers/rpmsg/rpmsg_port_spi.c
@@ -162,15 +162,11 @@ static const struct rpmsg_port_ops_s g_rpmsg_port_spi_ops
=
static uint16_t rpmsg_port_spi_crc16(FAR struct rpmsg_port_header_s *hdr)
{
-#ifdef CONFIG_RPMSG_PORT_SPI_CRC
uint16_t crc = xorsum16(&hdr->cmd, hdr->len - sizeof(hdr->crc));
- /* The receiver skips the check of a zero crc, so never send one */
+ /* A peer built with the check optional skips a zero crc, never send one */
return crc != 0 ? crc : 1;
-#else
- return 0;
-#endif
}
#ifdef CONFIG_PM
@@ -473,14 +469,12 @@ static void rpmsg_port_spi_complete_handler(FAR void *arg)
goto out;
}
- /* When RETX is enabled the CRC is compiled in and a valid frame's CRC is
- * never zero (the crc16 macro folds a zero result to 1), so validate
- * unconditionally: a torn frame carrying crc==0 would otherwise bypass
- * the check and poison the retx state machine.
+ /* A valid frame's crc is never zero, so a torn frame carrying crc==0 is
+ * rejected here instead of poisoning the retx state machine.
*/
crc = rpmsg_port_spi_crc16(rpspi->rxhdr);
- if (crc != 0 && rpspi->rxhdr->crc != crc)
+ if (rpspi->rxhdr->crc != crc)
{
rpmsgerr("crc check fail received: %u calculated: %u "
"len=%u cmd=%u\n",
diff --git a/drivers/rpmsg/rpmsg_port_spi_slave.c
b/drivers/rpmsg/rpmsg_port_spi_slave.c
index 9fbb4c94c14..cbf1d912cec 100644
--- a/drivers/rpmsg/rpmsg_port_spi_slave.c
+++ b/drivers/rpmsg/rpmsg_port_spi_slave.c
@@ -191,15 +191,11 @@ static const struct spi_slave_devops_s
g_rpmsg_port_spi_slave_ops =
static uint16_t rpmsg_port_spi_crc16(FAR struct rpmsg_port_header_s *hdr)
{
-#ifdef CONFIG_RPMSG_PORT_SPI_CRC
uint16_t crc = xorsum16(&hdr->cmd, hdr->len - sizeof(hdr->crc));
- /* The receiver skips the check of a zero crc, so never send one */
+ /* A peer built with the check optional skips a zero crc, never send one */
return crc != 0 ? crc : 1;
-#else
- return 0;
-#endif
}
#ifdef CONFIG_PM
@@ -555,14 +551,12 @@ static void rpmsg_port_spi_slave_notify(FAR struct
spi_slave_dev_s *dev,
goto out;
}
- /* When RETX is enabled the CRC is compiled in and a valid frame's CRC is
- * never zero (the crc16 macro folds a zero result to 1), so validate
- * unconditionally: a torn frame carrying crc==0 would otherwise bypass
- * the check and poison the retx state machine.
+ /* A valid frame's crc is never zero, so a torn frame carrying crc==0 is
+ * rejected here instead of poisoning the retx state machine.
*/
crc = rpmsg_port_spi_crc16(rpspi->rxhdr);
- if (crc != 0 && rpspi->rxhdr->crc != crc)
+ if (rpspi->rxhdr->crc != crc)
{
rpmsgerr("crc check fail received: %u calculated: %u "
"len=%u cmd=%u\n",
diff --git a/drivers/rpmsg/rpmsg_port_uart.c b/drivers/rpmsg/rpmsg_port_uart.c
index 14b3efcd8e7..1939ebcb6b8 100644
--- a/drivers/rpmsg/rpmsg_port_uart.c
+++ b/drivers/rpmsg/rpmsg_port_uart.c
@@ -83,12 +83,8 @@
#define RPMSG_PORT_UART_EVT_CONNED (1 << 2) /* Connected with peer or
not */
#define RPMSG_PORT_UART_EVT_TX (1 << 3) /* TX is ready or not */
-#ifdef CONFIG_RPMSG_PORT_UART_CRC
-# define rpmsg_port_uart_crc16(hdr) xorsum16(&(hdr)->cmd, \
+#define rpmsg_port_uart_crc16(hdr) xorsum16(&(hdr)->cmd, \
(hdr)->len -
sizeof((hdr)->crc))
-#else
-# define rpmsg_port_uart_crc16(hdr) 0
-#endif
#ifdef CONFIG_RPMSG_PORT_UART_DEBUG
# define rpmsgdump(m,b,s) lib_dumpbuffer(m, (FAR const
uint8_t *)b, s)
@@ -834,8 +830,7 @@ static void rpmsg_port_uart_rx_worker(FAR struct
rpmsg_port_uart_s *rpuart,
else if (buf[i] == RPMSG_PORT_UART_END)
{
if (hdr->len < sizeof(*hdr) || hdr->len != next ||
- (hdr->crc != 0 &&
- hdr->crc != rpmsg_port_uart_crc16(hdr)))
+ hdr->crc != rpmsg_port_uart_crc16(hdr))
{
rpmsgerr("Recv error crc=%u len=%u next=%u i=%zd "
"dbg_i=%d\n", hdr->crc, hdr->len, next, i,