]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
cmd: fru: Separate checksum routine
authorMichal Simek <michal.simek@xilinx.com>
Mon, 15 Apr 2019 09:04:42 +0000 (11:04 +0200)
committerMichal Simek <michal.simek@xilinx.com>
Thu, 6 Jun 2019 11:46:52 +0000 (13:46 +0200)
There is a need to call this function from different places too.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
common/fru_ops.c

index e3be6da969935ed5699e8016c3435c1e521e9e6c..4bab1a725c92c8a635710f9be3e87a07641c941d 100644 (file)
@@ -10,7 +10,6 @@
 #include <malloc.h>
 #include <asm/io.h>
 #include <asm/arch/hardware.h>
-#include "linux/crc8.h"
 
 struct fru_table fru_data  __attribute__((section(".data")));
 
@@ -34,6 +33,18 @@ static int fru_check_language(u8 code)
        return code;
 }
 
+static u8 fru_checksum(u8 *addr, u8 len)
+{
+       u8 checksum = 0;
+
+       while (len--) {
+               checksum += *addr;
+               addr++;
+       }
+
+       return checksum;
+}
+
 static int fru_check_type_len(u8 type_len, u8 language, u8 *type)
 {
        int len;
@@ -88,23 +99,16 @@ static int fru_parse_board(unsigned long addr)
 int fru_capture(unsigned long addr)
 {
        struct fru_common_hdr *hdr;
-       u8 crc = 0;
-       u8 len;
-       u8 *temp = (u8 *)addr;
+       u8 checksum = 0;
 
-       hdr = (struct fru_common_hdr *)addr;
-       len = sizeof(struct fru_common_hdr);
-
-       while(len--) {
-               crc += *temp;
-               temp++;
-       }
-
-       if (crc) {
+       checksum = fru_checksum((u8 *)addr, sizeof(struct fru_common_hdr));
+       if (checksum) {
                printf("%s Common header CRC error\n", __func__);
                return -EINVAL;
        }
 
+       hdr = (struct fru_common_hdr *)addr;
+
        memcpy((void *)&fru_data.hdr, (void *)hdr,
               sizeof(struct fru_common_hdr));