7d6723bb8e9774d49869890deb9a309aea0a4efd
[openwrt/staging/dangole.git] /
1 From 0e71cac033bb7689c4dfa2e6814191337ef770f5 Mon Sep 17 00:00:00 2001
2 From: INAGAKI Hiroshi <musashino.open@gmail.com>
3 Date: Thu, 13 Oct 2022 00:51:33 +0900
4 Subject: [PATCH] nvmem: u-boot-env: align endianness of crc32 values
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 This patch fixes crc32 error on Big-Endianness system by conversion of
10 calculated crc32 value.
11
12 Little-Endianness system:
13
14 obtained crc32: Little
15 calculated crc32: Little
16
17 Big-Endianness system:
18
19 obtained crc32: Little
20 calculated crc32: Big
21
22 log (APRESIA ApresiaLightGS120GT-SS, RTL8382M, Big-Endianness):
23
24 [ 8.570000] u_boot_env 18001200.spi:flash@0:partitions:partition@c0000: Invalid calculated CRC32: 0x88cd6f09 (expected: 0x096fcd88)
25 [ 8.580000] u_boot_env: probe of 18001200.spi:flash@0:partitions:partition@c0000 failed with error -22
26
27 Fixes: f955dc1445069 ("nvmem: add driver handling U-Boot environment variables")
28
29 Signed-off-by: INAGAKI Hiroshi <musashino.open@gmail.com>
30 Acked-by: Rafał Miłecki <rafal@milecki.pl>
31 Tested-by: Christian Lamparter <chunkeey@gmail.com>
32 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
33 ---
34 drivers/nvmem/u-boot-env.c | 2 +-
35 1 file changed, 1 insertion(+), 1 deletion(-)
36
37 --- a/drivers/nvmem/u-boot-env.c
38 +++ b/drivers/nvmem/u-boot-env.c
39 @@ -143,7 +143,7 @@ static int u_boot_env_parse(struct u_boo
40 crc32_data_len = priv->mtd->size - crc32_data_offset;
41 data_len = priv->mtd->size - data_offset;
42
43 - calc = crc32(~0, buf + crc32_data_offset, crc32_data_len) ^ ~0L;
44 + calc = le32_to_cpu((__le32)crc32(~0, buf + crc32_data_offset, crc32_data_len) ^ ~0L);
45 if (calc != crc32) {
46 dev_err(dev, "Invalid calculated CRC32: 0x%08x (expected: 0x%08x)\n", calc, crc32);
47 err = -EINVAL;