summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/buflib.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/firmware/buflib.c b/firmware/buflib.c
index 6ddd96e7df..2ed13b49b1 100644
--- a/firmware/buflib.c
+++ b/firmware/buflib.c
@@ -105,6 +105,10 @@
105/* Bitmask of enabled paranoia checks */ 105/* Bitmask of enabled paranoia checks */
106#define BUFLIB_PARANOIA 0 106#define BUFLIB_PARANOIA 0
107 107
108#if BUFLIB_PARANOIA & PARANOIA_CHECK_CRC
109# define BUFLIB_HAS_CRC
110#endif
111
108/* Forward indices, used to index a block start pointer as block[fidx_XXX] */ 112/* Forward indices, used to index a block start pointer as block[fidx_XXX] */
109enum { 113enum {
110 fidx_LEN, /* length of the block, must come first */ 114 fidx_LEN, /* length of the block, must come first */
@@ -116,14 +120,20 @@ enum {
116/* Backward indices, used to index a block end pointer as block[-bidx_XXX] */ 120/* Backward indices, used to index a block end pointer as block[-bidx_XXX] */
117enum { 121enum {
118 bidx_USER, /* dummy to get below fields to be 1-based */ 122 bidx_USER, /* dummy to get below fields to be 1-based */
123#ifdef BUFLIB_HAS_CRC
119 bidx_CRC, /* CRC, protects all metadata behind it */ 124 bidx_CRC, /* CRC, protects all metadata behind it */
125#endif
120 bidx_BSIZE, /* total size of the block header */ 126 bidx_BSIZE, /* total size of the block header */
121}; 127};
122 128
123/* Number of fields in the block header, excluding the name, which is 129/* Number of fields in the block header, excluding the name, which is
124 * accounted for using the BSIZE field. Note that bidx_USER is not an 130 * accounted for using the BSIZE field. Note that bidx_USER is not an
125 * actual field so it is not included in the count. */ 131 * actual field so it is not included in the count. */
126#define BUFLIB_NUM_FIELDS 5 132#ifdef BUFLIB_HAS_CRC
133# define BUFLIB_NUM_FIELDS 5
134#else
135# define BUFLIB_NUM_FIELDS 4
136#endif
127 137
128struct buflib_callbacks buflib_ops_locked = { 138struct buflib_callbacks buflib_ops_locked = {
129 .move_callback = NULL, 139 .move_callback = NULL,
@@ -1211,6 +1221,7 @@ static void check_block_handle(struct buflib_context *ctx,
1211 } 1221 }
1212} 1222}
1213 1223
1224#ifdef BUFLIB_HAS_CRC
1214static uint32_t calc_block_crc(union buflib_data *block, 1225static uint32_t calc_block_crc(union buflib_data *block,
1215 union buflib_data *block_end) 1226 union buflib_data *block_end)
1216{ 1227{
@@ -1247,3 +1258,22 @@ static void check_block_crc(struct buflib_context *ctx,
1247 } 1258 }
1248 } 1259 }
1249} 1260}
1261#else
1262static void update_block_crc(struct buflib_context *ctx,
1263 union buflib_data *block,
1264 union buflib_data *block_end)
1265{
1266 (void)ctx;
1267 (void)block;
1268 (void)block_end;
1269}
1270
1271static void check_block_crc(struct buflib_context *ctx,
1272 union buflib_data *block,
1273 union buflib_data *block_end)
1274{
1275 (void)ctx;
1276 (void)block;
1277 (void)block_end;
1278}
1279#endif