From c48950e07b4a222c0313ba54a2a652509e865484 Mon Sep 17 00:00:00 2001 From: Pavel Zakopaylo Date: Fri, 1 Dec 2023 14:52:07 +1100 Subject: [PATCH] Removed unnecessary CRC function I missed the existing one in include/blisp_util.h --- CMakeLists.txt | 2 +- include/crc.h | 6 ---- lib/chip/blisp_chip_bl808.c | 8 ++--- lib/crc.c | 69 ------------------------------------- 4 files changed, 5 insertions(+), 80 deletions(-) delete mode 100644 include/crc.h delete mode 100644 lib/crc.c diff --git a/CMakeLists.txt b/CMakeLists.txt index f89dd82..5756a55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ option(BLISP_USE_SYSTEM_LIBRARIES "Use system-installed libraries" "${CMAKE_USE_ option(COMPILE_TESTS "Compile the tests" OFF) add_library(libblisp_obj OBJECT - lib/blisp.c lib/blisp_easy.c lib/crc.c + lib/blisp.c lib/blisp_easy.c lib/chip/blisp_chip_bl60x.c lib/chip/blisp_chip_bl70x.c lib/chip/blisp_chip_bl808.c) diff --git a/include/crc.h b/include/crc.h deleted file mode 100644 index c6f6c1f..0000000 --- a/include/crc.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _BLISP_CRC_H -#define _BLISP_CRC_H - -unsigned long crc(unsigned char *buf, int len); - -#endif // _BLISP_CRC_H diff --git a/lib/chip/blisp_chip_bl808.c b/lib/chip/blisp_chip_bl808.c index fd65c86..808aabf 100644 --- a/lib/chip/blisp_chip_bl808.c +++ b/lib/chip/blisp_chip_bl808.c @@ -5,7 +5,7 @@ #include "blisp.h" #include "blisp_struct.h" -#include "crc.h" +#include "blisp_util.h" #include struct blisp_chip blisp_chip_bl808 = { @@ -225,7 +225,7 @@ struct bl808_bootheader_t bl808_header = { }; void fill_crcs(struct bl808_bootheader_t *bh) { - bh->flash_cfg.crc32 = crc((unsigned char *) &bh->flash_cfg.cfg, sizeof(struct bl808_spi_flash_cfg_t)); - bh->clk_cfg.crc32 = crc((unsigned char *) &bh->clk_cfg.cfg, sizeof(struct bl808_sys_clk_cfg_t)); - bh->crc32 = crc((unsigned char *) bh, sizeof(struct bl808_bootheader_t) - 4); + bh->flash_cfg.crc32 = crc32_calculate((unsigned char *) &bh->flash_cfg.cfg, sizeof(struct bl808_spi_flash_cfg_t)); + bh->clk_cfg.crc32 = crc32_calculate((unsigned char *) &bh->clk_cfg.cfg, sizeof(struct bl808_sys_clk_cfg_t)); + bh->crc32 = crc32_calculate((unsigned char *) bh, sizeof(struct bl808_bootheader_t) - 4); } diff --git a/lib/crc.c b/lib/crc.c deleted file mode 100644 index 1169920..0000000 --- a/lib/crc.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * CRC code taken from https://www.rfc-editor.org/rfc/rfc1952#section-8 - * - * Copyright (c) 1996 L. Peter Deutsch - * - * Permission is granted to copy and distribute this document for any - * purpose and without charge, including translations into other - * languages and incorporation into compilations, provided that the - * copyright notice and this notice are preserved, and that any - * substantive changes or deletions from the original are clearly - * marked. - */ - -#include -#include - -/* Table of CRCs of all 8-bit messages. */ -unsigned long crc_table[256]; - -/* Flag: has the table been computed? Initially false. */ -int crc_table_computed = 0; - -/* Make the table for a fast CRC. */ -void make_crc_table(void) { - unsigned long c; - int n, k; - for (n = 0; n < 256; n++) { - c = (unsigned long) n; - for (k = 0; k < 8; k++) { - if (c & 1) { - c = 0xedb88320L ^ (c >> 1); - } else { - c = c >> 1; - } - } - crc_table[n] = c; - } - crc_table_computed = 1; -} - -/* - Update a running crc with the bytes buf[0..len-1] and return -the updated crc. The crc should be initialized to zero. Pre- and -post-conditioning (one's complement) is performed within this -function so it shouldn't be done by the caller. Usage example: - - unsigned long crc = 0L; - - while (read_buffer(buffer, length) != EOF) { - crc = update_crc(crc, buffer, length); - } - if (crc != original_crc) error(); -*/ -unsigned long update_crc(unsigned long crc, unsigned char *buf, int len) { - unsigned long c = crc ^ 0xffffffffL; - int n; - - if (!crc_table_computed) - make_crc_table(); - for (n = 0; n < len; n++) { - c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8); - } - return c ^ 0xffffffffL; -} - -/* Return the CRC of the bytes buf[0..len-1]. */ -unsigned long crc(unsigned char *buf, int len) { - return update_crc(0L, buf, len); -}