• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1diff -Nur u-boot-v2019.07/lib/crc32.c u-boot-v2019.07_ok/lib/crc32.c
2--- u-boot-v2019.07/lib/crc32.c	2020-05-30 23:14:30.908000000 +0800
3+++ u-boot-v2019.07_ok/lib/crc32.c	2020-05-30 12:06:17.000000000 +0800
4@@ -8,259 +8,139 @@
5  * For conditions of distribution and use, see copyright notice in zlib.h
6  */
7
8-#ifdef USE_HOSTCC
9-#include <arpa/inet.h>
10-#else
11-#include <common.h>
12-#include <efi_loader.h>
13-#endif
14-#include <compiler.h>
15-#include <u-boot/crc.h>
16+#define ZEXPORT /* empty */
17+#define cpu_to_le32(x)      (x)
18+#define le32_to_cpu(x)      (x)
19+#define tole(x)  cpu_to_le32(x)
20+typedef unsigned char   uint8_t;
21+typedef unsigned short  uint16_t;
22+typedef unsigned int    uint32_t;
23+typedef unsigned int    uint;
24+typedef unsigned char   bytef;
25+typedef unsigned int    size_t;
26+typedef unsigned int    uintptr_t;
27
28-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
29-#include <watchdog.h>
30-#endif
31-#include "u-boot/zlib.h"
32-
33-#ifdef USE_HOSTCC
34-#define __efi_runtime
35-#define __efi_runtime_data
36-#endif
37-
38-#define tole(x) cpu_to_le32(x)
39-
40-#ifdef CONFIG_DYNAMIC_CRC_TABLE
41-
42-static int __efi_runtime_data crc_table_empty = 1;
43-static uint32_t __efi_runtime_data crc_table[256];
44-static void __efi_runtime make_crc_table OF((void));
45-
46-/*
47-  Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
48-  x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
49-
50-  Polynomials over GF(2) are represented in binary, one bit per coefficient,
51-  with the lowest powers in the most significant bit.  Then adding polynomials
52-  is just exclusive-or, and multiplying a polynomial by x is a right shift by
53-  one.  If we call the above polynomial p, and represent a byte as the
54-  polynomial q, also with the lowest power in the most significant bit (so the
55-  byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
56-  where a mod b means the remainder after dividing a by b.
57-
58-  This calculation is done using the shift-register method of multiplying and
59-  taking the remainder.  The register is initialized to zero, and for each
60-  incoming bit, x^32 is added mod p to the register if the bit is a one (where
61-  x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
62-  x (which is shifting right by one and adding x^32 mod p if the bit shifted
63-  out is a one).  We start with the highest power (least significant bit) of
64-  q and repeat for all eight bits of q.
65-
66-  The table is simply the CRC of all possible eight bit values.  This is all
67-  the information needed to generate CRC's on data a byte at a time for all
68-  combinations of CRC register values and incoming bytes.
69-*/
70-static void __efi_runtime make_crc_table(void)
71-{
72-  uint32_t c;
73-  int n, k;
74-  uLong poly;		/* polynomial exclusive-or pattern */
75-  /* terms of polynomial defining this crc (except x^32): */
76-  static Byte __efi_runtime_data p[] = {
77-		0, 1, 2, 4, 5, 7, 8, 10, 11, 12, 16, 22, 23, 26};
78-
79-  /* make exclusive-or pattern from polynomial (0xedb88320L) */
80-  poly = 0L;
81-  for (n = 0; n < sizeof(p)/sizeof(Byte); n++)
82-    poly |= 1L << (31 - p[n]);
83-
84-  for (n = 0; n < 256; n++)
85-  {
86-    c = (uLong)n;
87-    for (k = 0; k < 8; k++)
88-      c = c & 1 ? poly ^ (c >> 1) : c >> 1;
89-    crc_table[n] = tole(c);
90-  }
91-  crc_table_empty = 0;
92-}
93-#else
94 /* ========================================================================
95  * Table of CRC-32's of all single-byte values (made by make_crc_table)
96  */
97-
98-static const uint32_t __efi_runtime_data crc_table[256] = {
99-tole(0x00000000L), tole(0x77073096L), tole(0xee0e612cL), tole(0x990951baL),
100-tole(0x076dc419L), tole(0x706af48fL), tole(0xe963a535L), tole(0x9e6495a3L),
101-tole(0x0edb8832L), tole(0x79dcb8a4L), tole(0xe0d5e91eL), tole(0x97d2d988L),
102-tole(0x09b64c2bL), tole(0x7eb17cbdL), tole(0xe7b82d07L), tole(0x90bf1d91L),
103-tole(0x1db71064L), tole(0x6ab020f2L), tole(0xf3b97148L), tole(0x84be41deL),
104-tole(0x1adad47dL), tole(0x6ddde4ebL), tole(0xf4d4b551L), tole(0x83d385c7L),
105-tole(0x136c9856L), tole(0x646ba8c0L), tole(0xfd62f97aL), tole(0x8a65c9ecL),
106-tole(0x14015c4fL), tole(0x63066cd9L), tole(0xfa0f3d63L), tole(0x8d080df5L),
107-tole(0x3b6e20c8L), tole(0x4c69105eL), tole(0xd56041e4L), tole(0xa2677172L),
108-tole(0x3c03e4d1L), tole(0x4b04d447L), tole(0xd20d85fdL), tole(0xa50ab56bL),
109-tole(0x35b5a8faL), tole(0x42b2986cL), tole(0xdbbbc9d6L), tole(0xacbcf940L),
110-tole(0x32d86ce3L), tole(0x45df5c75L), tole(0xdcd60dcfL), tole(0xabd13d59L),
111-tole(0x26d930acL), tole(0x51de003aL), tole(0xc8d75180L), tole(0xbfd06116L),
112-tole(0x21b4f4b5L), tole(0x56b3c423L), tole(0xcfba9599L), tole(0xb8bda50fL),
113-tole(0x2802b89eL), tole(0x5f058808L), tole(0xc60cd9b2L), tole(0xb10be924L),
114-tole(0x2f6f7c87L), tole(0x58684c11L), tole(0xc1611dabL), tole(0xb6662d3dL),
115-tole(0x76dc4190L), tole(0x01db7106L), tole(0x98d220bcL), tole(0xefd5102aL),
116-tole(0x71b18589L), tole(0x06b6b51fL), tole(0x9fbfe4a5L), tole(0xe8b8d433L),
117-tole(0x7807c9a2L), tole(0x0f00f934L), tole(0x9609a88eL), tole(0xe10e9818L),
118-tole(0x7f6a0dbbL), tole(0x086d3d2dL), tole(0x91646c97L), tole(0xe6635c01L),
119-tole(0x6b6b51f4L), tole(0x1c6c6162L), tole(0x856530d8L), tole(0xf262004eL),
120-tole(0x6c0695edL), tole(0x1b01a57bL), tole(0x8208f4c1L), tole(0xf50fc457L),
121-tole(0x65b0d9c6L), tole(0x12b7e950L), tole(0x8bbeb8eaL), tole(0xfcb9887cL),
122-tole(0x62dd1ddfL), tole(0x15da2d49L), tole(0x8cd37cf3L), tole(0xfbd44c65L),
123-tole(0x4db26158L), tole(0x3ab551ceL), tole(0xa3bc0074L), tole(0xd4bb30e2L),
124-tole(0x4adfa541L), tole(0x3dd895d7L), tole(0xa4d1c46dL), tole(0xd3d6f4fbL),
125-tole(0x4369e96aL), tole(0x346ed9fcL), tole(0xad678846L), tole(0xda60b8d0L),
126-tole(0x44042d73L), tole(0x33031de5L), tole(0xaa0a4c5fL), tole(0xdd0d7cc9L),
127-tole(0x5005713cL), tole(0x270241aaL), tole(0xbe0b1010L), tole(0xc90c2086L),
128-tole(0x5768b525L), tole(0x206f85b3L), tole(0xb966d409L), tole(0xce61e49fL),
129-tole(0x5edef90eL), tole(0x29d9c998L), tole(0xb0d09822L), tole(0xc7d7a8b4L),
130-tole(0x59b33d17L), tole(0x2eb40d81L), tole(0xb7bd5c3bL), tole(0xc0ba6cadL),
131-tole(0xedb88320L), tole(0x9abfb3b6L), tole(0x03b6e20cL), tole(0x74b1d29aL),
132-tole(0xead54739L), tole(0x9dd277afL), tole(0x04db2615L), tole(0x73dc1683L),
133-tole(0xe3630b12L), tole(0x94643b84L), tole(0x0d6d6a3eL), tole(0x7a6a5aa8L),
134-tole(0xe40ecf0bL), tole(0x9309ff9dL), tole(0x0a00ae27L), tole(0x7d079eb1L),
135-tole(0xf00f9344L), tole(0x8708a3d2L), tole(0x1e01f268L), tole(0x6906c2feL),
136-tole(0xf762575dL), tole(0x806567cbL), tole(0x196c3671L), tole(0x6e6b06e7L),
137-tole(0xfed41b76L), tole(0x89d32be0L), tole(0x10da7a5aL), tole(0x67dd4accL),
138-tole(0xf9b9df6fL), tole(0x8ebeeff9L), tole(0x17b7be43L), tole(0x60b08ed5L),
139-tole(0xd6d6a3e8L), tole(0xa1d1937eL), tole(0x38d8c2c4L), tole(0x4fdff252L),
140-tole(0xd1bb67f1L), tole(0xa6bc5767L), tole(0x3fb506ddL), tole(0x48b2364bL),
141-tole(0xd80d2bdaL), tole(0xaf0a1b4cL), tole(0x36034af6L), tole(0x41047a60L),
142-tole(0xdf60efc3L), tole(0xa867df55L), tole(0x316e8eefL), tole(0x4669be79L),
143-tole(0xcb61b38cL), tole(0xbc66831aL), tole(0x256fd2a0L), tole(0x5268e236L),
144-tole(0xcc0c7795L), tole(0xbb0b4703L), tole(0x220216b9L), tole(0x5505262fL),
145-tole(0xc5ba3bbeL), tole(0xb2bd0b28L), tole(0x2bb45a92L), tole(0x5cb36a04L),
146-tole(0xc2d7ffa7L), tole(0xb5d0cf31L), tole(0x2cd99e8bL), tole(0x5bdeae1dL),
147-tole(0x9b64c2b0L), tole(0xec63f226L), tole(0x756aa39cL), tole(0x026d930aL),
148-tole(0x9c0906a9L), tole(0xeb0e363fL), tole(0x72076785L), tole(0x05005713L),
149-tole(0x95bf4a82L), tole(0xe2b87a14L), tole(0x7bb12baeL), tole(0x0cb61b38L),
150-tole(0x92d28e9bL), tole(0xe5d5be0dL), tole(0x7cdcefb7L), tole(0x0bdbdf21L),
151-tole(0x86d3d2d4L), tole(0xf1d4e242L), tole(0x68ddb3f8L), tole(0x1fda836eL),
152-tole(0x81be16cdL), tole(0xf6b9265bL), tole(0x6fb077e1L), tole(0x18b74777L),
153-tole(0x88085ae6L), tole(0xff0f6a70L), tole(0x66063bcaL), tole(0x11010b5cL),
154-tole(0x8f659effL), tole(0xf862ae69L), tole(0x616bffd3L), tole(0x166ccf45L),
155-tole(0xa00ae278L), tole(0xd70dd2eeL), tole(0x4e048354L), tole(0x3903b3c2L),
156-tole(0xa7672661L), tole(0xd06016f7L), tole(0x4969474dL), tole(0x3e6e77dbL),
157-tole(0xaed16a4aL), tole(0xd9d65adcL), tole(0x40df0b66L), tole(0x37d83bf0L),
158-tole(0xa9bcae53L), tole(0xdebb9ec5L), tole(0x47b2cf7fL), tole(0x30b5ffe9L),
159-tole(0xbdbdf21cL), tole(0xcabac28aL), tole(0x53b39330L), tole(0x24b4a3a6L),
160-tole(0xbad03605L), tole(0xcdd70693L), tole(0x54de5729L), tole(0x23d967bfL),
161-tole(0xb3667a2eL), tole(0xc4614ab8L), tole(0x5d681b02L), tole(0x2a6f2b94L),
162-tole(0xb40bbe37L), tole(0xc30c8ea1L), tole(0x5a05df1bL), tole(0x2d02ef8dL)
163+const unsigned int g_crc_table[256] = { /* 256:�����С */
164+    tole(0x00000000L), tole(0x77073096L), tole(0xee0e612cL), tole(0x990951baL),
165+    tole(0x076dc419L), tole(0x706af48fL), tole(0xe963a535L), tole(0x9e6495a3L),
166+    tole(0x0edb8832L), tole(0x79dcb8a4L), tole(0xe0d5e91eL), tole(0x97d2d988L),
167+    tole(0x09b64c2bL), tole(0x7eb17cbdL), tole(0xe7b82d07L), tole(0x90bf1d91L),
168+    tole(0x1db71064L), tole(0x6ab020f2L), tole(0xf3b97148L), tole(0x84be41deL),
169+    tole(0x1adad47dL), tole(0x6ddde4ebL), tole(0xf4d4b551L), tole(0x83d385c7L),
170+    tole(0x136c9856L), tole(0x646ba8c0L), tole(0xfd62f97aL), tole(0x8a65c9ecL),
171+    tole(0x14015c4fL), tole(0x63066cd9L), tole(0xfa0f3d63L), tole(0x8d080df5L),
172+    tole(0x3b6e20c8L), tole(0x4c69105eL), tole(0xd56041e4L), tole(0xa2677172L),
173+    tole(0x3c03e4d1L), tole(0x4b04d447L), tole(0xd20d85fdL), tole(0xa50ab56bL),
174+    tole(0x35b5a8faL), tole(0x42b2986cL), tole(0xdbbbc9d6L), tole(0xacbcf940L),
175+    tole(0x32d86ce3L), tole(0x45df5c75L), tole(0xdcd60dcfL), tole(0xabd13d59L),
176+    tole(0x26d930acL), tole(0x51de003aL), tole(0xc8d75180L), tole(0xbfd06116L),
177+    tole(0x21b4f4b5L), tole(0x56b3c423L), tole(0xcfba9599L), tole(0xb8bda50fL),
178+    tole(0x2802b89eL), tole(0x5f058808L), tole(0xc60cd9b2L), tole(0xb10be924L),
179+    tole(0x2f6f7c87L), tole(0x58684c11L), tole(0xc1611dabL), tole(0xb6662d3dL),
180+    tole(0x76dc4190L), tole(0x01db7106L), tole(0x98d220bcL), tole(0xefd5102aL),
181+    tole(0x71b18589L), tole(0x06b6b51fL), tole(0x9fbfe4a5L), tole(0xe8b8d433L),
182+    tole(0x7807c9a2L), tole(0x0f00f934L), tole(0x9609a88eL), tole(0xe10e9818L),
183+    tole(0x7f6a0dbbL), tole(0x086d3d2dL), tole(0x91646c97L), tole(0xe6635c01L),
184+    tole(0x6b6b51f4L), tole(0x1c6c6162L), tole(0x856530d8L), tole(0xf262004eL),
185+    tole(0x6c0695edL), tole(0x1b01a57bL), tole(0x8208f4c1L), tole(0xf50fc457L),
186+    tole(0x65b0d9c6L), tole(0x12b7e950L), tole(0x8bbeb8eaL), tole(0xfcb9887cL),
187+    tole(0x62dd1ddfL), tole(0x15da2d49L), tole(0x8cd37cf3L), tole(0xfbd44c65L),
188+    tole(0x4db26158L), tole(0x3ab551ceL), tole(0xa3bc0074L), tole(0xd4bb30e2L),
189+    tole(0x4adfa541L), tole(0x3dd895d7L), tole(0xa4d1c46dL), tole(0xd3d6f4fbL),
190+    tole(0x4369e96aL), tole(0x346ed9fcL), tole(0xad678846L), tole(0xda60b8d0L),
191+    tole(0x44042d73L), tole(0x33031de5L), tole(0xaa0a4c5fL), tole(0xdd0d7cc9L),
192+    tole(0x5005713cL), tole(0x270241aaL), tole(0xbe0b1010L), tole(0xc90c2086L),
193+    tole(0x5768b525L), tole(0x206f85b3L), tole(0xb966d409L), tole(0xce61e49fL),
194+    tole(0x5edef90eL), tole(0x29d9c998L), tole(0xb0d09822L), tole(0xc7d7a8b4L),
195+    tole(0x59b33d17L), tole(0x2eb40d81L), tole(0xb7bd5c3bL), tole(0xc0ba6cadL),
196+    tole(0xedb88320L), tole(0x9abfb3b6L), tole(0x03b6e20cL), tole(0x74b1d29aL),
197+    tole(0xead54739L), tole(0x9dd277afL), tole(0x04db2615L), tole(0x73dc1683L),
198+    tole(0xe3630b12L), tole(0x94643b84L), tole(0x0d6d6a3eL), tole(0x7a6a5aa8L),
199+    tole(0xe40ecf0bL), tole(0x9309ff9dL), tole(0x0a00ae27L), tole(0x7d079eb1L),
200+    tole(0xf00f9344L), tole(0x8708a3d2L), tole(0x1e01f268L), tole(0x6906c2feL),
201+    tole(0xf762575dL), tole(0x806567cbL), tole(0x196c3671L), tole(0x6e6b06e7L),
202+    tole(0xfed41b76L), tole(0x89d32be0L), tole(0x10da7a5aL), tole(0x67dd4accL),
203+    tole(0xf9b9df6fL), tole(0x8ebeeff9L), tole(0x17b7be43L), tole(0x60b08ed5L),
204+    tole(0xd6d6a3e8L), tole(0xa1d1937eL), tole(0x38d8c2c4L), tole(0x4fdff252L),
205+    tole(0xd1bb67f1L), tole(0xa6bc5767L), tole(0x3fb506ddL), tole(0x48b2364bL),
206+    tole(0xd80d2bdaL), tole(0xaf0a1b4cL), tole(0x36034af6L), tole(0x41047a60L),
207+    tole(0xdf60efc3L), tole(0xa867df55L), tole(0x316e8eefL), tole(0x4669be79L),
208+    tole(0xcb61b38cL), tole(0xbc66831aL), tole(0x256fd2a0L), tole(0x5268e236L),
209+    tole(0xcc0c7795L), tole(0xbb0b4703L), tole(0x220216b9L), tole(0x5505262fL),
210+    tole(0xc5ba3bbeL), tole(0xb2bd0b28L), tole(0x2bb45a92L), tole(0x5cb36a04L),
211+    tole(0xc2d7ffa7L), tole(0xb5d0cf31L), tole(0x2cd99e8bL), tole(0x5bdeae1dL),
212+    tole(0x9b64c2b0L), tole(0xec63f226L), tole(0x756aa39cL), tole(0x026d930aL),
213+    tole(0x9c0906a9L), tole(0xeb0e363fL), tole(0x72076785L), tole(0x05005713L),
214+    tole(0x95bf4a82L), tole(0xe2b87a14L), tole(0x7bb12baeL), tole(0x0cb61b38L),
215+    tole(0x92d28e9bL), tole(0xe5d5be0dL), tole(0x7cdcefb7L), tole(0x0bdbdf21L),
216+    tole(0x86d3d2d4L), tole(0xf1d4e242L), tole(0x68ddb3f8L), tole(0x1fda836eL),
217+    tole(0x81be16cdL), tole(0xf6b9265bL), tole(0x6fb077e1L), tole(0x18b74777L),
218+    tole(0x88085ae6L), tole(0xff0f6a70L), tole(0x66063bcaL), tole(0x11010b5cL),
219+    tole(0x8f659effL), tole(0xf862ae69L), tole(0x616bffd3L), tole(0x166ccf45L),
220+    tole(0xa00ae278L), tole(0xd70dd2eeL), tole(0x4e048354L), tole(0x3903b3c2L),
221+    tole(0xa7672661L), tole(0xd06016f7L), tole(0x4969474dL), tole(0x3e6e77dbL),
222+    tole(0xaed16a4aL), tole(0xd9d65adcL), tole(0x40df0b66L), tole(0x37d83bf0L),
223+    tole(0xa9bcae53L), tole(0xdebb9ec5L), tole(0x47b2cf7fL), tole(0x30b5ffe9L),
224+    tole(0xbdbdf21cL), tole(0xcabac28aL), tole(0x53b39330L), tole(0x24b4a3a6L),
225+    tole(0xbad03605L), tole(0xcdd70693L), tole(0x54de5729L), tole(0x23d967bfL),
226+    tole(0xb3667a2eL), tole(0xc4614ab8L), tole(0x5d681b02L), tole(0x2a6f2b94L),
227+    tole(0xb40bbe37L), tole(0xc30c8ea1L), tole(0x5a05df1bL), tole(0x2d02ef8dL)
228 };
229-#endif
230-
231-#if 0
232-/* =========================================================================
233- * This function can be used by asm versions of crc32()
234- */
235-const uint32_t * ZEXPORT get_crc_table()
236-{
237-#ifdef CONFIG_DYNAMIC_CRC_TABLE
238-  if (crc_table_empty) make_crc_table();
239-#endif
240-  return (const uint32_t *)crc_table;
241-}
242-#endif
243
244 /* ========================================================================= */
245-# if __BYTE_ORDER == __LITTLE_ENDIAN
246-#  define DO_CRC(x) crc = tab[(crc ^ (x)) & 255] ^ (crc >> 8)
247-# else
248-#  define DO_CRC(x) crc = tab[((crc >> 24) ^ (x)) & 255] ^ (crc << 8)
249-# endif
250-
251+#define do_crc(x) (crc = tab[(crc ^ (x)) & 255] ^ (crc >> 8))   /* 255 8 */
252 /* ========================================================================= */
253-
254 /* No ones complement version. JFFS2 (and other things ?)
255  * don't use ones compliment in their CRC calculations.
256  */
257-uint32_t __efi_runtime crc32_no_comp(uint32_t crc, const Bytef *buf, uInt len)
258+unsigned int  crc32_no_comp(unsigned int crc, const bytef *buf, uint len)
259 {
260-    const uint32_t *tab = crc_table;
261-    const uint32_t *b =(const uint32_t *)buf;
262+    const unsigned int *tab = g_crc_table;
263+    const unsigned int *b = (const unsigned int *)buf;
264     size_t rem_len;
265-#ifdef CONFIG_DYNAMIC_CRC_TABLE
266-    if (crc_table_empty)
267-      make_crc_table();
268-#endif
269-    crc = cpu_to_le32(crc);
270+
271     /* Align it */
272-    if (((long)b) & 3 && len) {
273-	 uint8_t *p = (uint8_t *)b;
274-	 do {
275-	      DO_CRC(*p++);
276-	 } while ((--len) && ((long)p)&3);
277-	 b = (uint32_t *)p;
278+    if ((((uintptr_t)b) & 3) && len) { /* 3 */
279+        uint8_t *p = (uint8_t *)b;
280+        do {
281+            do_crc(*p++);
282+        } while ((--len) && (((uintptr_t)p) & 3)); /* 3 */
283+        b = (unsigned int *)p;
284     }
285
286-    rem_len = len & 3;
287-    len = len >> 2;
288+    rem_len = len & 3;   /* 3 */
289+    len = len >> 2;      /* 2 */
290     for (--b; len; --len) {
291-	 /* load data 32 bits wide, xor data 32 bits wide. */
292-	 crc ^= *++b; /* use pre increment for speed */
293-	 DO_CRC(0);
294-	 DO_CRC(0);
295-	 DO_CRC(0);
296-	 DO_CRC(0);
297+        /* load data 32 bits wide, xor data 32 bits wide. */
298+        crc ^= *++b; /* use pre increment for speed */
299+        do_crc(0);
300+        do_crc(0);
301+        do_crc(0);
302+        do_crc(0);
303     }
304     len = rem_len;
305     /* And the last few bytes */
306     if (len) {
307-	 uint8_t *p = (uint8_t *)(b + 1) - 1;
308-	 do {
309-	      DO_CRC(*++p); /* use pre increment for speed */
310-	 } while (--len);
311+        uint8_t *p = (uint8_t *)(b + 1) - 1;
312+        do {
313+            do_crc(*++p); /* use pre increment for speed */
314+        } while (--len);
315     }
316
317     return le32_to_cpu(crc);
318 }
319-#undef DO_CRC
320-
321-uint32_t __efi_runtime crc32(uint32_t crc, const Bytef *p, uInt len)
322-{
323-     return crc32_no_comp(crc ^ 0xffffffffL, p, len) ^ 0xffffffffL;
324-}
325+#undef do_crc
326
327-/*
328- * Calculate the crc32 checksum triggering the watchdog every 'chunk_sz' bytes
329- * of input.
330- */
331-uint32_t crc32_wd(uint32_t crc, const unsigned char *buf, uInt len,
332-		  uInt chunk_sz)
333+unsigned int hi_crc32 (unsigned int crc, const bytef *p, uint len)
334 {
335-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
336-	const unsigned char *end, *curr;
337-	int chunk;
338-
339-	curr = buf;
340-	end = buf + len;
341-	while (curr < end) {
342-		chunk = end - curr;
343-		if (chunk > chunk_sz)
344-			chunk = chunk_sz;
345-		crc = crc32 (crc, curr, chunk);
346-		curr += chunk;
347-		WATCHDOG_RESET ();
348-	}
349-#else
350-	crc = crc32 (crc, buf, len);
351-#endif
352+    if (!p || !len) {
353+        return 0;
354+    }
355
356-	return crc;
357+    return crc32_no_comp(crc ^ 0xffffffffL, p, len) ^ 0xffffffffL;
358 }
359
360-void crc32_wd_buf(const unsigned char *input, unsigned int ilen,
361-		unsigned char *output, unsigned int chunk_sz)
362-{
363-	uint32_t crc;
364
365-	crc = crc32_wd(0, input, ilen, chunk_sz);
366-	crc = htonl(crc);
367-	memcpy(output, &crc, sizeof(crc));
368-}
369Binary files u-boot-v2019.07/lib/crc32.o and u-boot-v2019.07_ok/lib/crc32.o differ
370diff -Nur u-boot-v2019.07/lib/lzma/LzmaDec.c u-boot-v2019.07_ok/lib/lzma/LzmaDec.c
371--- u-boot-v2019.07/lib/lzma/LzmaDec.c	2020-05-30 23:14:30.920000000 +0800
372+++ u-boot-v2019.07_ok/lib/lzma/LzmaDec.c	2020-05-30 12:06:17.000000000 +0800
373@@ -1,13 +1,9 @@
374 /* LzmaDec.c -- LZMA Decoder
375 2009-09-20 : Igor Pavlov : Public domain */
376+#include <hi_boot_rom.h>
377
378-#include <config.h>
379-#include <common.h>
380-#include <watchdog.h>
381 #include "LzmaDec.h"
382
383-#include <linux/string.h>
384-
385 #define kNumTopBits 24
386 #define kTopValue ((UInt32)1 << kNumTopBits)
387
388@@ -47,9 +43,10 @@
389   i -= 0x40; }
390 #endif
391
392-#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }
393+#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR;}
394+#define NORMALIZE_CHECK_MODIFY if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }
395
396-#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
397+#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK_MODIFY; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
398 #define UPDATE_0_CHECK range = bound;
399 #define UPDATE_1_CHECK range -= bound; code -= bound;
400 #define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \
401@@ -131,7 +128,7 @@
402     = kMatchSpecLenStart + 2 : State Init Marker
403 */
404
405-static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
406+unsigned int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec* p, SizeT limit, const Byte* bufLimit)
407 {
408   CLzmaProb *probs = p->probs;
409
410@@ -153,7 +150,7 @@
411   UInt32 range = p->range;
412   UInt32 code = p->code;
413
414-  WATCHDOG_RESET();
415+    hi_watchdog_feed();
416
417   do
418   {
419@@ -177,9 +174,10 @@
420         state -= (state < 4) ? state : 3;
421         symbol = 1;
422
423-        WATCHDOG_RESET();
424+                hi_watchdog_feed();
425
426-        do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100);
427+                do { GET_BIT(prob + symbol, symbol) }
428+                while (symbol < 0x100);
429       }
430       else
431       {
432@@ -188,7 +186,7 @@
433         state -= (state < 10) ? 3 : 6;
434         symbol = 1;
435
436-        WATCHDOG_RESET();
437+                hi_watchdog_feed();
438
439         do
440         {
441@@ -270,14 +268,14 @@
442         prob = probs + RepLenCoder;
443       }
444       {
445-        unsigned limit, offset;
446+                unsigned int inner_limit, offset;
447         CLzmaProb *probLen = prob + LenChoice;
448         IF_BIT_0(probLen)
449         {
450           UPDATE_0(probLen);
451           probLen = prob + LenLow + (posState << kLenNumLowBits);
452           offset = 0;
453-          limit = (1 << kLenNumLowBits);
454+                    inner_limit = (1 << kLenNumLowBits);
455         }
456         else
457         {
458@@ -288,17 +286,17 @@
459             UPDATE_0(probLen);
460             probLen = prob + LenMid + (posState << kLenNumMidBits);
461             offset = kLenNumLowSymbols;
462-            limit = (1 << kLenNumMidBits);
463+                        inner_limit = (1 << kLenNumMidBits);
464           }
465           else
466           {
467             UPDATE_1(probLen);
468             probLen = prob + LenHigh;
469             offset = kLenNumLowSymbols + kLenNumMidSymbols;
470-            limit = (1 << kLenNumHighBits);
471+                        inner_limit = (1 << kLenNumHighBits);
472           }
473         }
474-        TREE_DECODE(probLen, limit, len);
475+                TREE_DECODE(probLen, inner_limit, len);
476         len += offset;
477       }
478
479@@ -312,16 +310,17 @@
480         {
481           unsigned posSlot = (unsigned)distance;
482           int numDirectBits = (int)(((distance >> 1) - 1));
483+                    unsigned int numDirectBitsTemp = (unsigned int)numDirectBits;
484           distance = (2 | (distance & 1));
485           if (posSlot < kEndPosModelIndex)
486           {
487-            distance <<= numDirectBits;
488+                        distance <<= numDirectBitsTemp;
489             prob = probs + SpecPos + distance - posSlot - 1;
490             {
491               UInt32 mask = 1;
492               unsigned i = 1;
493
494-              WATCHDOG_RESET();
495+                            hi_watchdog_feed();
496
497               do
498               {
499@@ -335,7 +334,7 @@
500           {
501             numDirectBits -= kNumAlignBits;
502
503-            WATCHDOG_RESET();
504+                        hi_watchdog_feed();
505
506             do
507             {
508@@ -409,7 +408,7 @@
509           const Byte *lim = dest + curLen;
510           dicPos += curLen;
511
512-          WATCHDOG_RESET();
513+                    hi_watchdog_feed();
514
515           do
516             *(dest) = (Byte)*(dest + src);
517@@ -418,7 +417,7 @@
518         else
519         {
520
521-          WATCHDOG_RESET();
522+                    hi_watchdog_feed();
523
524           do
525           {
526@@ -433,7 +432,7 @@
527   }
528   while (dicPos < limit && buf < bufLimit);
529
530-  WATCHDOG_RESET();
531+    hi_watchdog_feed();
532
533   NORMALIZE;
534   p->buf = buf;
535@@ -451,7 +450,7 @@
536   return SZ_OK;
537 }
538
539-static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
540+void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec* p, SizeT limit)
541 {
542   if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)
543   {
544@@ -477,7 +476,7 @@
545   }
546 }
547
548-static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
549+unsigned  int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec* p, SizeT limit, const Byte* bufLimit)
550 {
551   do
552   {
553@@ -510,7 +509,7 @@
554   DUMMY_REP
555 } ELzmaDummy;
556
557-static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)
558+ ELzmaDummy LzmaDec_TryDummy(const CLzmaDec* p, const Byte* buf, SizeT inSize)
559 {
560   UInt32 range = p->range;
561   UInt32 code = p->code;
562@@ -541,7 +540,8 @@
563       if (state < kNumLitStates)
564       {
565         unsigned symbol = 1;
566-        do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);
567+                do { GET_BIT_CHECK(prob + symbol, symbol) }
568+                while (symbol < 0x100);
569       }
570       else
571       {
572@@ -668,14 +668,14 @@
573
574           if (posSlot < kEndPosModelIndex)
575           {
576-            prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;
577+                        prob = probs + SpecPos + ((2 | (posSlot & 1)) << (unsigned int)numDirectBits) - posSlot - 1;
578           }
579           else
580           {
581             numDirectBits -= kNumAlignBits;
582             do
583             {
584-              NORMALIZE_CHECK
585+                            NORMALIZE_CHECK_MODIFY
586               range >>= 1;
587               code -= range & (((code - range) >> 31) - 1);
588               /* if (code >= range) code -= range; */
589@@ -701,7 +701,7 @@
590 }
591
592
593-static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)
594+ void LzmaDec_InitRc(CLzmaDec* p, const Byte* data)
595 {
596   p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);
597   p->range = 0xFFFFFFFF;
598@@ -730,7 +730,7 @@
599   LzmaDec_InitDicAndState(p, True, True);
600 }
601
602-static void LzmaDec_InitStateReal(CLzmaDec *p)
603+ void LzmaDec_InitStateReal(CLzmaDec* p)
604 {
605   UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));
606   UInt32 i;
607@@ -804,63 +804,79 @@
608           int dummyRes = LzmaDec_TryDummy(p, src, inSize);
609           if (dummyRes == DUMMY_ERROR)
610           {
611-            memcpy(p->tempBuf, src, inSize);
612-            p->tempBufSize = (unsigned)inSize;
613-            (*srcLen) += inSize;
614-            *status = LZMA_STATUS_NEEDS_MORE_INPUT;
615-            return SZ_OK;
616-          }
617-          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
618-          {
619-            *status = LZMA_STATUS_NOT_FINISHED;
620-            return SZ_ERROR_DATA;
621-          }
622-          bufLimit = src;
623+                    unsigned int cs = (uintptr_t)p->tempBuf ^ inSize ^ (uintptr_t)src ^ inSize;
624+                    (hi_void)memcpy_s(p->tempBuf,inSize ,src, inSize, cs);
625+                    p->tempBufSize = (unsigned)inSize;
626+                    (*srcLen) += inSize;
627+                    *status = LZMA_STATUS_NEEDS_MORE_INPUT;
628+                    return SZ_OK;
629+                }
630+
631+                if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
632+                {
633+                    *status = LZMA_STATUS_NOT_FINISHED;
634+                    return SZ_ERROR_DATA;
635+                }
636+
637+                bufLimit = src;
638+            }
639+            else
640+            { bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX; }
641+
642+            p->buf = src;
643+
644+            if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
645+            { return SZ_ERROR_DATA; }
646+
647+            processed = (SizeT)(p->buf - src);
648+            (*srcLen) += processed;
649+            src += processed;
650+            inSize -= processed;
651         }
652         else
653-          bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;
654-        p->buf = src;
655-        if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
656-          return SZ_ERROR_DATA;
657-        processed = (SizeT)(p->buf - src);
658-        (*srcLen) += processed;
659-        src += processed;
660-        inSize -= processed;
661-      }
662-      else
663-      {
664-        unsigned rem = p->tempBufSize, lookAhead = 0;
665-        while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)
666-          p->tempBuf[rem++] = src[lookAhead++];
667-        p->tempBufSize = rem;
668-        if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
669         {
670-          int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);
671-          if (dummyRes == DUMMY_ERROR)
672-          {
673+            unsigned rem = p->tempBufSize, lookAhead = 0;
674+
675+            while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)
676+            { p->tempBuf[rem++] = src[lookAhead++]; }
677+
678+            p->tempBufSize = rem;
679+
680+            if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
681+            {
682+                int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);
683+
684+                if (dummyRes == DUMMY_ERROR)
685+                {
686+                    (*srcLen) += lookAhead;
687+                    *status = LZMA_STATUS_NEEDS_MORE_INPUT;
688+                    return SZ_OK;
689+                }
690+
691+                if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
692+                {
693+                    *status = LZMA_STATUS_NOT_FINISHED;
694+                    return SZ_ERROR_DATA;
695+                }
696+            }
697+
698+            p->buf = p->tempBuf;
699+
700+            if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)
701+            { return SZ_ERROR_DATA; }
702+
703+            lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));
704             (*srcLen) += lookAhead;
705-            *status = LZMA_STATUS_NEEDS_MORE_INPUT;
706-            return SZ_OK;
707-          }
708-          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
709-          {
710-            *status = LZMA_STATUS_NOT_FINISHED;
711-            return SZ_ERROR_DATA;
712-          }
713+            src += lookAhead;
714+            inSize -= lookAhead;
715+            p->tempBufSize = 0;
716         }
717-        p->buf = p->tempBuf;
718-        if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)
719-          return SZ_ERROR_DATA;
720-        lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));
721-        (*srcLen) += lookAhead;
722-        src += lookAhead;
723-        inSize -= lookAhead;
724-        p->tempBufSize = 0;
725-      }
726-  }
727-  if (p->code == 0)
728-    *status = LZMA_STATUS_FINISHED_WITH_MARK;
729-  return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;
730+    }
731+
732+    if (p->code == 0)
733+    { *status = LZMA_STATUS_FINISHED_WITH_MARK; }
734+
735+    return (p->code == 0) ? (SRes)SZ_OK : (SRes)SZ_ERROR_DATA;
736 }
737
738 SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
739@@ -887,20 +903,23 @@
740       curFinishMode = finishMode;
741     }
742
743-    res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
744-    src += inSizeCur;
745-    inSize -= inSizeCur;
746-    *srcLen += inSizeCur;
747-    outSizeCur = p->dicPos - dicPos;
748-    memcpy(dest, p->dic + dicPos, outSizeCur);
749-    dest += outSizeCur;
750-    outSize -= outSizeCur;
751-    *destLen += outSizeCur;
752-    if (res != 0)
753-      return res;
754-    if (outSizeCur == 0 || outSize == 0)
755-      return SZ_OK;
756-  }
757+        res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
758+        src += inSizeCur;
759+        inSize -= inSizeCur;
760+        *srcLen += inSizeCur;
761+        outSizeCur = p->dicPos - dicPos;
762+        unsigned int cs = (uintptr_t)dest ^ outSizeCur ^ (uintptr_t)(p->dic + dicPos) ^ outSizeCur;
763+        (hi_void)memcpy_s(dest,outSizeCur,p->dic + dicPos, outSizeCur, cs);
764+        dest += outSizeCur;
765+        outSize -= outSizeCur;
766+        *destLen += outSizeCur;
767+
768+        if (res != 0)
769+        { return res; }
770+
771+        if (outSizeCur == 0 || outSize == 0)
772+        { return SZ_OK; }
773+    }
774 }
775
776 void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
777@@ -909,7 +928,7 @@
778   p->probs = 0;
779 }
780
781-static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)
782+ void LzmaDec_FreeDict(CLzmaDec* p, ISzAlloc* alloc)
783 {
784   alloc->Free(alloc, p->dic);
785   p->dic = 0;
786@@ -947,7 +966,7 @@
787   return SZ_OK;
788 }
789
790-static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)
791+ SRes LzmaDec_AllocateProbs2(CLzmaDec* p, const CLzmaProps* propNew, ISzAlloc* alloc)
792 {
793   UInt32 numProbs = LzmaProps_GetNumProbs(propNew);
794   if (p->probs == 0 || numProbs != p->numProbs)
795Binary files u-boot-v2019.07/lib/lzma/LzmaDec.o and u-boot-v2019.07_ok/lib/lzma/LzmaDec.o differ
796diff -Nur u-boot-v2019.07/lib/lzma/LzmaTools.c u-boot-v2019.07_ok/lib/lzma/LzmaTools.c
797--- u-boot-v2019.07/lib/lzma/LzmaTools.c	2020-05-30 23:14:30.920000000 +0800
798+++ u-boot-v2019.07_ok/lib/lzma/LzmaTools.c	2020-05-30 12:06:17.000000000 +0800
799@@ -17,31 +17,29 @@
800  *
801  */
802
803-#include <config.h>
804-#include <common.h>
805-#include <watchdog.h>
806+#include <hi_boot_rom.h>
807
808-#ifdef CONFIG_LZMA
809
810 #define LZMA_PROPERTIES_OFFSET 0
811 #define LZMA_SIZE_OFFSET       LZMA_PROPS_SIZE
812 #define LZMA_DATA_OFFSET       LZMA_SIZE_OFFSET+sizeof(uint64_t)
813
814-#include "LzmaTools.h"
815 #include "LzmaDec.h"
816+#include "LzmaTools.h"
817+
818+#define IN_BUF_SIZE     (0x1000)
819+#define OUT_BUF_SIZE    (0x1000)
820+
821
822-#include <linux/string.h>
823-#include <malloc.h>
824+SRes Decode2(CLzmaDec* state, Byte* in_buf, LZMA_STREAM_S* in_stream, Byte* out_buf, LZMA_STREAM_S* out_stream,
825+             unsigned int uncompress_len, unsigned int compress_len, ELzmaStatus* status);
826
827-static void *SzAlloc(void *p, size_t size) { return malloc(size); }
828-static void SzFree(void *p, void *address) { free(address); }
829
830-int lzmaBuffToBuffDecompress (unsigned char *outStream, SizeT *uncompressedSize,
831-                  unsigned char *inStream,  SizeT  length)
832+int lzmaBuffToBuffDecompress (unsigned char* outStream, SizeT* uncompressedSize,
833+                              unsigned char* inStream,  SizeT length, ISzAlloc* alloc)
834 {
835     int res = SZ_ERROR_DATA;
836     int i;
837-    ISzAlloc g_Alloc;
838
839     SizeT outSizeFull = 0xFFFFFFFF; /* 4GBytes limit */
840     SizeT outProcessed;
841@@ -50,34 +48,37 @@
842     ELzmaStatus state;
843     SizeT compressedSize = (SizeT)(length - LZMA_PROPS_SIZE);
844
845-    debug ("LZMA: Image address............... 0x%p\n", inStream);
846-    debug ("LZMA: Properties address.......... 0x%p\n", inStream + LZMA_PROPERTIES_OFFSET);
847-    debug ("LZMA: Uncompressed size address... 0x%p\n", inStream + LZMA_SIZE_OFFSET);
848-    debug ("LZMA: Compressed data address..... 0x%p\n", inStream + LZMA_DATA_OFFSET);
849-    debug ("LZMA: Destination address......... 0x%p\n", outStream);
850-
851-    memset(&state, 0, sizeof(state));
852+    (hi_void)memset_s(&state,sizeof(state), 0, sizeof(state), (uintptr_t)(&state) ^ sizeof(state) ^ 0 ^ sizeof(state));
853
854     outSize = 0;
855     outSizeHigh = 0;
856     /* Read the uncompressed size */
857-    for (i = 0; i < 8; i++) {
858+    for (i = 0; i < 8; i++)
859+    {
860         unsigned char b = inStream[LZMA_SIZE_OFFSET + i];
861-            if (i < 4) {
862-                outSize     += (UInt32)(b) << (i * 8);
863-        } else {
864-                outSizeHigh += (UInt32)(b) << ((i - 4) * 8);
865+
866+        if (i < 4)
867+        {
868+            outSize     += (UInt32)(b) << ((unsigned int)i * 8);
869+        }
870+        else
871+        {
872+            outSizeHigh += (UInt32)(b) << (((unsigned int)i - 4) * 8);
873         }
874     }
875
876     outSizeFull = (SizeT)outSize;
877-    if (sizeof(SizeT) >= 8) {
878+
879+    if (sizeof(SizeT) >= 8)
880+    {
881         /*
882          * SizeT is a 64 bit uint => We can manage files larger than 4GB!
883          *
884          */
885-            outSizeFull |= (((SizeT)outSizeHigh << 16) << 16);
886-    } else if (outSizeHigh != 0 || (UInt32)(SizeT)outSize != outSize) {
887+        outSizeFull |= (((SizeT)outSizeHigh << 16) << 16);
888+    }
889+    else if (outSizeHigh != 0 || (UInt32)(SizeT)outSize != outSize)
890+    {
891         /*
892          * SizeT is a 32 bit uint => We cannot manage files larger than
893          * 4GB!  Assume however that all 0xf values is "unknown size" and
894@@ -85,39 +86,185 @@
895          *
896          */
897         if (outSizeHigh != (SizeT)-1 || outSize != (SizeT)-1) {
898-            debug ("LZMA: 64bit support not enabled.\n");
899+            boot_msg0 ("LZMA: 64bit support not enabled.\n");
900             return SZ_ERROR_DATA;
901         }
902     }
903
904-    debug("LZMA: Uncompresed size............ 0x%zx\n", outSizeFull);
905-    debug("LZMA: Compresed size.............. 0x%zx\n", compressedSize);
906-
907-    g_Alloc.Alloc = SzAlloc;
908-    g_Alloc.Free = SzFree;
909+    boot_msg1("Uncompresed size: ", outSizeFull);
910+    boot_msg1("Compresed size: ", compressedSize);
911
912     /* Short-circuit early if we know the buffer can't hold the results. */
913-    if (outSizeFull != (SizeT)-1 && *uncompressedSize < outSizeFull)
914-        return SZ_ERROR_OUTPUT_EOF;
915+    if (outSizeFull != (SizeT) - 1 && *uncompressedSize < outSizeFull)
916+    { return SZ_ERROR_OUTPUT_EOF; }
917
918     /* Decompress */
919-    outProcessed = min(outSizeFull, *uncompressedSize);
920-
921-    WATCHDOG_RESET();
922+    outProcessed = (outSizeFull > *uncompressedSize) ? (*uncompressedSize) : outSizeFull;
923
924+    hi_watchdog_feed();
925     res = LzmaDecode(
926-        outStream, &outProcessed,
927-        inStream + LZMA_DATA_OFFSET, &compressedSize,
928-        inStream, LZMA_PROPS_SIZE, LZMA_FINISH_END, &state, &g_Alloc);
929+              outStream, &outProcessed,
930+              inStream + LZMA_DATA_OFFSET, &compressedSize,
931+              inStream, LZMA_PROPS_SIZE, LZMA_FINISH_END, &state, alloc);
932     *uncompressedSize = outProcessed;
933
934-    debug("LZMA: Uncompressed ............... 0x%zx\n", outProcessed);
935-
936-    if (res != SZ_OK)  {
937+    if (res != SZ_OK)
938+    {
939         return res;
940     }
941
942     return res;
943 }
944
945-#endif
946+
947+unsigned int LzmaDecode2(const Byte* prop_data, unsigned int prop_size, ELzmaStatus* status, ISzAlloc* alloc,
948+                LZMA_STREAM_S* in_stream, LZMA_STREAM_S* out_stream, unsigned int uncompress_len, unsigned int compress_len)
949+{
950+    CLzmaDec p;
951+    SRes res;
952+    Byte* in_buf = HI_NULL;
953+    Byte* out_buf = HI_NULL;
954+    unsigned int dic_size = compress_len;
955+
956+    LzmaDec_Construct(&p);
957+
958+    res = LzmaDec_AllocateProbs(&p, prop_data, prop_size, alloc);
959+
960+    if (0 != res)
961+    {
962+        return SZ_ERROR_MEM;
963+    }
964+
965+    LzmaDec_Init(&p);
966+
967+    in_buf = IAlloc_Alloc(alloc, IN_BUF_SIZE);
968+
969+    if (HI_NULL == in_buf)
970+    {
971+        return SZ_ERROR_MEM;
972+    }
973+
974+    out_buf = IAlloc_Alloc(alloc, OUT_BUF_SIZE);
975+
976+    if (HI_NULL == out_buf)
977+    {
978+        IAlloc_Free(alloc, in_buf);
979+        in_buf = HI_NULL;
980+        return SZ_ERROR_MEM;
981+    }
982+
983+    (hi_void)memset_s(in_buf, IN_BUF_SIZE, 0, IN_BUF_SIZE, (uintptr_t)in_buf ^ IN_BUF_SIZE ^ 0 ^ IN_BUF_SIZE);
984+    (hi_void)memset_s(out_buf, OUT_BUF_SIZE, 0, OUT_BUF_SIZE, (uintptr_t)out_buf ^ OUT_BUF_SIZE ^ 0 ^ OUT_BUF_SIZE);
985+
986+    if (p.prop.dicSize <= compress_len)
987+    {
988+        dic_size = p.prop.dicSize;
989+    }
990+
991+    p.dic = IAlloc_Alloc(alloc, dic_size);
992+
993+    if (HI_NULL == p.dic)
994+    {
995+        IAlloc_Free(alloc, in_buf);
996+        in_buf = HI_NULL;
997+
998+        IAlloc_Free(alloc, out_buf);
999+        out_buf = HI_NULL;
1000+
1001+        return SZ_ERROR_MEM;
1002+    }
1003+
1004+    p.dicBufSize = dic_size;
1005+
1006+    res = Decode2(&p, in_buf, in_stream, out_buf, out_stream, uncompress_len, compress_len, status);
1007+
1008+    if ((res == SZ_OK) && (*status == LZMA_STATUS_NEEDS_MORE_INPUT))
1009+    {
1010+        res = SZ_ERROR_INPUT_EOF;
1011+    }
1012+
1013+    IAlloc_Free(alloc, in_buf);
1014+    in_buf = HI_NULL;
1015+
1016+    IAlloc_Free(alloc, out_buf);
1017+    out_buf = HI_NULL;
1018+
1019+    IAlloc_Free(alloc, p.dic);
1020+    p.dic = HI_NULL;
1021+
1022+    LzmaDec_FreeProbs(&p, alloc);
1023+
1024+    return res;
1025+}
1026+
1027+
1028+SRes Decode2(CLzmaDec* state, Byte* in_buf, LZMA_STREAM_S* in_stream, Byte* out_buf, LZMA_STREAM_S* out_stream,
1029+             unsigned int uncompress_len, unsigned int compress_len, ELzmaStatus* status)
1030+{
1031+    int there_is_size = (compress_len != (unsigned int) - 1);
1032+    size_t in_pos = 0, in_size = 0, out_pos = 0;
1033+    unsigned int in_offset = in_stream->offset;
1034+    unsigned int out_offset = out_stream->offset;
1035+
1036+    LzmaDec_Init(state);
1037+
1038+    for (;;)
1039+    {
1040+        if (in_pos == in_size)
1041+        {
1042+            in_size = (uncompress_len > IN_BUF_SIZE) ? IN_BUF_SIZE : uncompress_len;
1043+            RINOK(in_stream->func(in_offset, in_buf, in_size));
1044+            RINOK(in_stream->func(in_offset, in_buf, 1));       /* Make sure the readings are correct. */
1045+            uncompress_len -= in_size;
1046+            in_pos = 0;
1047+        }
1048+
1049+        {
1050+            SRes res;
1051+            size_t in_processed = in_size - in_pos;
1052+            size_t out_processed = OUT_BUF_SIZE - out_pos;
1053+
1054+            ELzmaFinishMode finish_mode = LZMA_FINISH_ANY;
1055+
1056+            if (there_is_size && out_processed > compress_len)
1057+            {
1058+                out_processed = (size_t)compress_len;
1059+                finish_mode = LZMA_FINISH_END;
1060+            }
1061+
1062+            res = LzmaDec_DecodeToBuf(state, out_buf + out_pos, &out_processed,
1063+                                      in_buf + in_pos, &in_processed, finish_mode, status);
1064+
1065+            in_pos += in_processed;
1066+            out_pos += out_processed;
1067+            compress_len -= out_processed;
1068+
1069+            /* Misjudgment is required. */
1070+            if (out_stream->func(out_offset, out_buf, out_processed) != out_processed)
1071+            {
1072+                return SZ_ERROR_WRITE;
1073+            }
1074+
1075+            in_offset += in_processed;
1076+            out_offset += out_processed;
1077+
1078+            out_pos = 0;
1079+
1080+            if (res != SZ_OK || (there_is_size && compress_len == 0))
1081+            {
1082+                return res;
1083+            }
1084+
1085+            if (in_processed == 0 && out_processed == 0)
1086+            {
1087+                if (there_is_size || *status != LZMA_STATUS_FINISHED_WITH_MARK)
1088+                {
1089+                    return SZ_ERROR_DATA;
1090+                }
1091+
1092+                return res;
1093+            }
1094+        }
1095+    }
1096+}
1097+
1098diff -Nur u-boot-v2019.07/lib/lzma/LzmaTools.h u-boot-v2019.07_ok/lib/lzma/LzmaTools.h
1099--- u-boot-v2019.07/lib/lzma/LzmaTools.h	2020-05-30 23:14:30.920000000 +0800
1100+++ u-boot-v2019.07_ok/lib/lzma/LzmaTools.h	2020-05-30 12:06:17.000000000 +0800
1101@@ -11,8 +11,22 @@
1102 #ifndef __LZMA_TOOL_H__
1103 #define __LZMA_TOOL_H__
1104
1105-#include <lzma/LzmaTypes.h>
1106
1107-extern int lzmaBuffToBuffDecompress (unsigned char *outStream, SizeT *uncompressedSize,
1108-			      unsigned char *inStream,  SizeT  length);
1109+/* The return value of the function is the actual read/write length. Note that the return value is not success/fail */
1110+typedef unsigned int (*LZMA_STREAM_FCT)(unsigned int offset, unsigned char* buffer, unsigned int size);
1111+
1112+typedef struct
1113+{
1114+    unsigned int offset;
1115+    LZMA_STREAM_FCT func;
1116+} LZMA_STREAM_S;
1117+
1118+extern int lzmaBuffToBuffDecompress (unsigned char* outStream, unsigned int* uncompressedSize,
1119+                                     unsigned char* inStream, unsigned int length, ISzAlloc* alloc);
1120+
1121+extern unsigned int LzmaDecode2(const Byte* prop_data, unsigned int prop_size, ELzmaStatus* status,
1122+	                                   ISzAlloc* alloc, LZMA_STREAM_S* in_stream, LZMA_STREAM_S* out_stream,
1123+	                                   unsigned int uncompress_len, unsigned int compress_len);
1124+
1125 #endif
1126+
1127Binary files u-boot-v2019.07/lib/lzma/LzmaTools.o and u-boot-v2019.07_ok/lib/lzma/LzmaTools.o differ
1128diff -Nur u-boot-v2019.07/lib/lzma/Types.h u-boot-v2019.07_ok/lib/lzma/Types.h
1129--- u-boot-v2019.07/lib/lzma/Types.h	2020-05-30 23:14:30.920000000 +0800
1130+++ u-boot-v2019.07_ok/lib/lzma/Types.h	2020-05-30 12:06:17.000000000 +0800
1131@@ -4,12 +4,6 @@
1132 #ifndef __7Z_TYPES_H
1133 #define __7Z_TYPES_H
1134
1135-#include <stddef.h>
1136-
1137-#ifdef _WIN32
1138-#include <windows.h>
1139-#endif
1140-
1141 #define SZ_OK 0
1142
1143 #define SZ_ERROR_DATA 1
1144@@ -28,16 +22,13 @@
1145 #define SZ_ERROR_ARCHIVE 16
1146 #define SZ_ERROR_NO_ARCHIVE 17
1147
1148-typedef int SRes;
1149+typedef unsigned int SRes;
1150+typedef int          ptrdiff_t;
1151
1152-#ifdef _WIN32
1153-typedef DWORD WRes;
1154-#else
1155 typedef int WRes;
1156-#endif
1157
1158 #ifndef RINOK
1159-#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
1160+#define RINOK(x) {unsigned int __result__ = (x); if (__result__ != 0) return __result__; }
1161 #endif
1162
1163 typedef unsigned char Byte;
1164@@ -74,6 +65,10 @@
1165
1166 #endif
1167
1168+#ifdef USE_FOTA
1169+typedef unsigned int size_t;
1170+#endif
1171+
1172 #ifdef _LZMA_NO_SYSTEM_SIZE_T
1173 typedef UInt32 SizeT;
1174 #else
1175@@ -118,19 +113,19 @@
1176
1177 typedef struct
1178 {
1179-  SRes (*Read)(void *p, void *buf, size_t *size);
1180+    SRes (*Read)(void* p, void* buf, size_t* size);
1181     /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
1182        (output(*size) < input(*size)) is allowed */
1183 } ISeqInStream;
1184
1185 /* it can return SZ_ERROR_INPUT_EOF */
1186-SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
1187-SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
1188+SRes SeqInStream_Read(ISeqInStream* stream, void* buf, size_t size);
1189+SRes SeqInStream_Read2(ISeqInStream* stream, void* buf, size_t size, SRes errorType);
1190 SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
1191
1192 typedef struct
1193 {
1194-  size_t (*Write)(void *p, const void *buf, size_t size);
1195+    size_t (*Write)(void* p, const void* buf, size_t size);
1196     /* Returns: result - the number of actually written bytes.
1197        (result < size) means error */
1198 } ISeqOutStream;
1199@@ -144,30 +139,30 @@
1200
1201 typedef struct
1202 {
1203-  SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */
1204+    SRes (*Read)(void* p, void* buf, size_t* size);  /* same as ISeqInStream::Read */
1205   SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
1206 } ISeekInStream;
1207
1208 typedef struct
1209 {
1210-  SRes (*Look)(void *p, const void **buf, size_t *size);
1211+    SRes (*Look)(void* p, const void** buf, size_t* size);
1212     /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
1213        (output(*size) > input(*size)) is not allowed
1214        (output(*size) < input(*size)) is allowed */
1215-  SRes (*Skip)(void *p, size_t offset);
1216+    SRes (*Skip)(void* p, size_t offset);
1217     /* offset must be <= output(*size) of Look */
1218
1219-  SRes (*Read)(void *p, void *buf, size_t *size);
1220+    SRes (*Read)(void* p, void* buf, size_t* size);
1221     /* reads directly (without buffer). It's same as ISeqInStream::Read */
1222   SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
1223 } ILookInStream;
1224
1225-SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
1226+SRes LookInStream_LookRead(ILookInStream* stream, void* buf, size_t* size);
1227 SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
1228
1229 /* reads via ILookInStream::Read */
1230-SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
1231-SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
1232+SRes LookInStream_Read2(ILookInStream* stream, void* buf, size_t size, SRes errorType);
1233+SRes LookInStream_Read(ILookInStream* stream, void* buf, size_t size);
1234
1235 #define LookToRead_BUF_SIZE (1 << 14)
1236
1237@@ -175,8 +170,8 @@
1238 {
1239   ILookInStream s;
1240   ISeekInStream *realStream;
1241-  size_t pos;
1242-  size_t size;
1243+    size_t pos;
1244+    size_t size;
1245   Byte buf[LookToRead_BUF_SIZE];
1246 } CLookToRead;
1247
1248@@ -208,27 +203,16 @@
1249
1250 typedef struct
1251 {
1252-  void *(*Alloc)(void *p, size_t size);
1253+    void* (*Alloc)(void* p, size_t size);
1254   void (*Free)(void *p, void *address); /* address can be 0 */
1255 } ISzAlloc;
1256
1257 #define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
1258 #define IAlloc_Free(p, a) (p)->Free((p), a)
1259
1260-#ifdef _WIN32
1261-
1262-#define CHAR_PATH_SEPARATOR '\\'
1263-#define WCHAR_PATH_SEPARATOR L'\\'
1264-#define STRING_PATH_SEPARATOR "\\"
1265-#define WSTRING_PATH_SEPARATOR L"\\"
1266-
1267-#else
1268-
1269 #define CHAR_PATH_SEPARATOR '/'
1270 #define WCHAR_PATH_SEPARATOR L'/'
1271 #define STRING_PATH_SEPARATOR "/"
1272 #define WSTRING_PATH_SEPARATOR L"/"
1273
1274 #endif
1275-
1276-#endif
1277diff -Nur u-boot-v2019.07/lib/SConscript u-boot-v2019.07_ok/lib/SConscript
1278--- u-boot-v2019.07/lib/SConscript	1970-01-01 08:00:00.000000000 +0800
1279+++ u-boot-v2019.07_ok/lib/SConscript	2020-05-30 23:05:15.608442200 +0800
1280@@ -0,0 +1,9 @@
1281+import os
1282+Import('env')
1283+
1284+env = env.Clone()
1285+
1286+src = [os.path.join('crc32.c'), os.path.join('lzma', 'LzmaDec.c'), os.path.join('lzma', 'LzmaTools.c')]
1287+objs = env.Object(src)
1288+objs.sort()
1289+Return('objs')
1290\ No newline at end of file
1291diff -Nur u-boot-v2019.07/SConscript u-boot-v2019.07_ok/SConscript
1292--- u-boot-v2019.07/SConscript	1970-01-01 08:00:00.000000000 +0800
1293+++ u-boot-v2019.07_ok/SConscript	2020-05-29 16:04:52.676000000 +0800
1294@@ -0,0 +1,34 @@
1295+#!/usr/bin/env python3
1296+# coding=utf-8
1297+
1298+import os
1299+from scripts import common_env
1300+from scripts.mk_prim_xml_step1 import create_file_id_dic
1301+Import('env')
1302+Import('env_cfg')
1303+Import('module')
1304+
1305+module_path = env_cfg.get_module_dir(module)
1306+obj_path = env_cfg.obj_path
1307+module_libs = env_cfg.get_module_libs(module)
1308+libs = []
1309+
1310+env = env.Clone()
1311+env_cfg.append_environs(env, module)
1312+common_env.print_log_env(env, env_cfg.get_module_dir(module))
1313+
1314+file_id_dict = None
1315+file = os.path.join(env_cfg.root, module_path, 'file_id.cfg')
1316+if not os.path.exists(file):
1317+    file_id_dict = None
1318+else:
1319+    file_id_dict = create_file_id_dic(file)
1320+
1321+for lib in module_libs:
1322+    print('lib_name:',lib)
1323+    src_path = module_libs[lib]
1324+    objs = []
1325+    for src in src_path:
1326+        objs += env.SConscript(os.path.join(src, 'SConscript'), {'env':env, 'id_dict':file_id_dict}, variant_dir = os.path.join('#', obj_path, module_path, src), duplicate = 0)
1327+    libs += env.Library(lib,sorted(objs))
1328+Return('libs')
1329