Skip to content

Commit b2c3c42

Browse files
Duy Vothenguyenyf
authored andcommitted
crc: initial support for CRC subsystem
Migrate support from crc library to new crc subsystem Add hardware acclerator backend for crc subsystem Signed-off-by: Duy Vo <duy.vo.xc@bp.renesas.com>
1 parent d8d3f4a commit b2c3c42

19 files changed

+599
-75
lines changed

MAINTAINERS.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,17 @@ Console:
857857
tests:
858858
- sample.console
859859

860+
CRC:
861+
status: maintained
862+
maintainers:
863+
- thenguyenyf
864+
files:
865+
- include/zephyr/sys/crc.h
866+
- subsys/crc/
867+
- tests/subsys/crc/
868+
labels:
869+
- "area: CRC"
870+
860871
Debug:
861872
status: maintained
862873
maintainers:
@@ -2605,7 +2616,6 @@ Utilities:
26052616
- dcpleung
26062617
- peter-mitsis
26072618
files:
2608-
- lib/crc/
26092619
- lib/utils/
26102620
- tests/unit/timeutil/
26112621
- tests/unit/time_units/

lib/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# FIXME: SHADOW_VARS: Remove this once we have enabled -Wshadow globally.
44
add_compile_options($<TARGET_PROPERTY:compiler,warning_shadow_variables>)
55

6-
add_subdirectory(crc)
76
if(NOT CONFIG_EXTERNAL_LIBC)
87
add_subdirectory(libc)
98
endif()

lib/Kconfig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ source "lib/libc/Kconfig"
77

88
source "lib/cpp/Kconfig"
99

10-
source "lib/crc/Kconfig"
11-
1210
menu "Additional libraries"
1311

1412
source "lib/hash/Kconfig"

lib/crc/CMakeLists.txt

Lines changed: 0 additions & 13 deletions
This file was deleted.

lib/crc/Kconfig

Lines changed: 0 additions & 23 deletions
This file was deleted.

subsys/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ add_subdirectory_ifdef(CONFIG_ARM_SIP_SVC_SUBSYS sip_svc)
3838
add_subdirectory_ifdef(CONFIG_BINDESC bindesc)
3939
add_subdirectory_ifdef(CONFIG_BT bluetooth)
4040
add_subdirectory_ifdef(CONFIG_CONSOLE_SUBSYS console)
41+
add_subdirectory_ifdef(CONFIG_CRC crc)
4142
add_subdirectory_ifdef(CONFIG_DAP dap)
4243
add_subdirectory_ifdef(CONFIG_DEMAND_PAGING demand_paging)
4344
add_subdirectory_ifdef(CONFIG_DISK_ACCESS disk)

subsys/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ source "subsys/bindesc/Kconfig"
1111
source "subsys/bluetooth/Kconfig"
1212
source "subsys/canbus/Kconfig"
1313
source "subsys/console/Kconfig"
14+
source "subsys/crc/Kconfig"
1415
source "subsys/dap/Kconfig"
1516
source "subsys/debug/Kconfig"
1617
source "subsys/demand_paging/Kconfig"

subsys/crc/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
zephyr_library()
4+
5+
zephyr_library_sources(crc4_sw.c)
6+
zephyr_library_sources(crc8_sw.c)
7+
zephyr_library_sources(crc16_sw.c)
8+
zephyr_library_sources(crc7_sw.c)
9+
zephyr_library_sources(crc24_sw.c)
10+
zephyr_library_sources(crc32c_sw.c)
11+
zephyr_library_sources(crc32_sw.c)
12+
zephyr_library_sources(crc32k_4_2_sw.c)
13+
14+
zephyr_library_sources_ifdef(CONFIG_CRC_HW_HANDLER crc_hardware.c)
15+
zephyr_library_sources_ifdef(CONFIG_CRC_SHELL crc_shell.c)

subsys/crc/Kconfig

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# Copyright (c) 2016,2023 Intel Corporation
2+
# Copyright (c) 2025 Renesas Electronics Corporation
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
DT_CHOSEN_Z_CRC := zephyr,crc
6+
7+
menuconfig CRC
8+
bool "Cyclic redundancy check (CRC) Support"
9+
help
10+
Enable use of CRC.
11+
12+
if CRC
13+
14+
module = CRC
15+
module-str = CRC
16+
source "subsys/logging/Kconfig.template.log_config"
17+
18+
config CRC_HW_HANDLER
19+
bool "CRC Hardware Accelerator"
20+
default y if $(dt_chosen_enabled,$(DT_CHOSEN_Z_CRC))
21+
select CRC_DRIVER
22+
help
23+
Enable use of CRC hardware
24+
25+
config CRC4
26+
bool "CRC-4 (Generic)"
27+
depends on CRC_DRIVER_HAS_CRC4
28+
default y
29+
help
30+
Implements a generic CRC-4 algorithm. This is suitable for platforms
31+
without hardware CRC support. Offers flexibility but has lower performance
32+
compared to hardware-based implementations.
33+
34+
config CRC4_TI
35+
bool "CRC-4 (TI Polynomial)"
36+
depends on CRC_DRIVER_HAS_CRC4_TI
37+
default y
38+
help
39+
Implements the TI-specific CRC-4 algorithm. Commonly used in low-level
40+
embedded communication where minimal CRC overhead is needed.
41+
42+
config CRC7_BE
43+
bool "CRC-7 (Big Endian)"
44+
depends on CRC_DRIVER_HAS_CRC7_BE
45+
default y
46+
help
47+
Implements a CRC-7 algorithm with Big Endian bit order. Often used
48+
in SD card protocols and other serial communication standards.
49+
50+
config CRC8
51+
bool "CRC-8 (Generic)"
52+
depends on CRC_DRIVER_HAS_CRC8
53+
default y
54+
help
55+
Implements a generic CRC-8 algorithm. Useful for small data integrity
56+
checks such as checksums and simple communication protocols.
57+
58+
config CRC8_ROHC
59+
bool "CRC-8 (ROHC)"
60+
depends on CRC_DRIVER_HAS_CRC8_ROHC
61+
default y
62+
help
63+
Implements the CRC-8 ROHC (Robust Header Compression) algorithm,
64+
typically used in compressed IP header protocols and networking.
65+
66+
config CRC8_CCITT
67+
bool "CRC-8 (CCITT)"
68+
depends on CRC_DRIVER_HAS_CRC8_CCITT
69+
default y
70+
help
71+
Implements the CRC-8 CCITT polynomial. Commonly used in
72+
telecommunications and low-power sensor protocols.
73+
74+
config CRC16
75+
bool "CRC-16 (Generic)"
76+
depends on CRC_DRIVER_HAS_CRC16
77+
default y
78+
help
79+
Implements the generic CRC-16 algorithm. Frequently used in
80+
storage, file transmission, and basic serial communication protocols.
81+
82+
config CRC16_ANSI
83+
bool "CRC-16 (ANSI)"
84+
depends on CRC_DRIVER_HAS_CRC16_ANSI
85+
default y
86+
help
87+
Implements the ANSI variant of CRC-16, also known as CRC-16-IBM.
88+
Commonly applied in legacy serial and file systems.
89+
90+
config CRC16_CCITT
91+
bool "CRC-16 (CCITT)"
92+
depends on CRC_DRIVER_HAS_CRC16_CCITT
93+
default y
94+
help
95+
Implements the CCITT variant of CRC-16, widely used in
96+
telecommunication systems such as XMODEM and HDLC protocols.
97+
98+
config CRC16_ITU_T
99+
bool "CRC-16 (ITU-T)"
100+
depends on CRC_DRIVER_HAS_CRC16_ITU_T
101+
default y
102+
help
103+
Implements the ITU-T (formerly CCITT) CRC-16 variant.
104+
Popular in modem protocols and wireless communication standards.
105+
106+
config CRC16_REFLECT
107+
bool "CRC-16 (Reflected)"
108+
depends on CRC_DRIVER_HAS_CRC16_REFLECT
109+
default y
110+
help
111+
Implements the reflected (bit-reversed) variant of CRC-16-CCITT.
112+
Useful in systems that process data in LSB-first order.
113+
114+
config CRC24_PGP
115+
bool "CRC-24 (PGP)"
116+
depends on CRC_DRIVER_HAS_CRC24_PGP
117+
default y
118+
help
119+
Implements a CRC24 algorithm, used in applications like Bluetooth
120+
and certain cryptographic protocols.
121+
122+
config CRC32_C
123+
bool "CRC-32C"
124+
depends on CRC_DRIVER_HAS_CRC32_C
125+
default y
126+
help
127+
Implements the CRC32-C (Castagnoli) algorithm, optimized for
128+
high-performance applications such as storage, networking,
129+
and error detection in modern processors.
130+
131+
config CRC32_IEEE
132+
bool "CRC-32 (IEEE)"
133+
depends on CRC_DRIVER_HAS_CRC32_IEEE
134+
default y
135+
help
136+
Implements the CRC32-IEEE (CRC-32) algorithm, commonly used
137+
in Ethernet, ZIP file integrity checks, and other standard
138+
networking and storage applications.
139+
140+
141+
config CRC32_K_4_2
142+
bool "CRC-32K/4.2"
143+
depends on CRC_DRIVER_HAS_CRC32_K_4_2
144+
default y
145+
help
146+
Implement the CRC-32K/4.2 algorithm, a variant of the standard
147+
CRC32-IEEE used in Ethernet, ZIP files, and other data integrity
148+
applications.
149+
150+
config CRC32_K_4_2_TABLE_256
151+
bool "CRC-32K/4.2 Table 256"
152+
help
153+
Enables the software implementation of the CRC-32K/4.2 algorithm
154+
using a 256-entry lookup table for faster computation.
155+
156+
config CRC_SHELL
157+
bool "CRC Shell"
158+
depends on SHELL
159+
select POSIX_C_LIB_EXT
160+
help
161+
Enable CRC checking for memory regions from the shell.
162+
163+
endif # CRC

lib/crc/crc16_sw.c renamed to subsys/crc/crc16_sw.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <zephyr/sys/crc.h>
88

9-
uint16_t crc16(uint16_t poly, uint16_t seed, const uint8_t *src, size_t len)
9+
uint16_t __weak crc16(uint16_t poly, uint16_t seed, const uint8_t *src, size_t len)
1010
{
1111
uint16_t crc = seed;
1212
size_t i, j;
@@ -23,11 +23,10 @@ uint16_t crc16(uint16_t poly, uint16_t seed, const uint8_t *src, size_t len)
2323
}
2424
}
2525

26-
2726
return crc;
2827
}
2928

30-
uint16_t crc16_reflect(uint16_t poly, uint16_t seed, const uint8_t *src, size_t len)
29+
uint16_t __weak crc16_reflect(uint16_t poly, uint16_t seed, const uint8_t *src, size_t len)
3130
{
3231
uint16_t crc = seed;
3332
size_t i, j;
@@ -44,12 +43,10 @@ uint16_t crc16_reflect(uint16_t poly, uint16_t seed, const uint8_t *src, size_t
4443
}
4544
}
4645

47-
4846
return crc;
4947
}
5048

51-
52-
uint16_t crc16_ccitt(uint16_t seed, const uint8_t *src, size_t len)
49+
uint16_t __weak crc16_ccitt(uint16_t seed, const uint8_t *src, size_t len)
5350
{
5451
for (; len > 0; len--) {
5552
uint8_t e, f;
@@ -63,7 +60,7 @@ uint16_t crc16_ccitt(uint16_t seed, const uint8_t *src, size_t len)
6360
return seed;
6461
}
6562

66-
uint16_t crc16_itu_t(uint16_t seed, const uint8_t *src, size_t len)
63+
uint16_t __weak crc16_itu_t(uint16_t seed, const uint8_t *src, size_t len)
6764
{
6865
for (; len > 0; len--) {
6966
seed = (seed >> 8U) | (seed << 8U);

0 commit comments

Comments
 (0)