linux-4.18.1_lzip-1.diff 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181
  1. diff -urdN linux-4.18.1/Documentation/00-INDEX linux-4.18.1.new/Documentation/00-INDEX
  2. --- linux-4.18.1/Documentation/00-INDEX 2018-08-15 17:37:34.000000000 +0200
  3. +++ linux-4.18.1.new/Documentation/00-INDEX 2018-08-16 18:56:17.000000000 +0200
  4. @@ -242,6 +242,8 @@
  5. - info on creator of above logo & site to get additional images from.
  6. lsm.txt
  7. - Linux Security Modules: General Security Hooks for Linux
  8. +lzip.txt
  9. + - info on lzip compression for the linux kernel.
  10. lzo.txt
  11. - kernel LZO decompressor input formats
  12. m68k/
  13. diff -urdN linux-4.18.1/Documentation/dontdiff linux-4.18.1.new/Documentation/dontdiff
  14. --- linux-4.18.1/Documentation/dontdiff 2018-08-15 17:37:34.000000000 +0200
  15. +++ linux-4.18.1.new/Documentation/dontdiff 2018-08-16 18:56:17.000000000 +0200
  16. @@ -26,6 +26,7 @@
  17. *.ll
  18. *.log
  19. *.lst
  20. +*.lz
  21. *.lzma
  22. *.lzo
  23. *.mo
  24. diff -urdN linux-4.18.1/Documentation/filesystems/squashfs.txt linux-4.18.1.new/Documentation/filesystems/squashfs.txt
  25. --- linux-4.18.1/Documentation/filesystems/squashfs.txt 2018-08-15 17:37:34.000000000 +0200
  26. +++ linux-4.18.1.new/Documentation/filesystems/squashfs.txt 2018-08-16 18:56:17.000000000 +0200
  27. @@ -2,7 +2,7 @@
  28. =======================
  29. Squashfs is a compressed read-only filesystem for Linux.
  30. -It uses zlib, lz4, lzo, or xz compression to compress files, inodes and
  31. +It uses zlib, lz4, lzip, lzo, or xz compression to compress files, inodes and
  32. directories. Inodes in the system are very small and all blocks are packed to
  33. minimise data overhead. Block sizes greater than 4K are supported up to a
  34. maximum of 1Mbytes (default block size 128K).
  35. diff -urdN linux-4.18.1/Documentation/lzip.txt linux-4.18.1.new/Documentation/lzip.txt
  36. --- linux-4.18.1/Documentation/lzip.txt 1970-01-01 01:00:00.000000000 +0100
  37. +++ linux-4.18.1.new/Documentation/lzip.txt 2018-08-16 18:56:17.000000000 +0200
  38. @@ -0,0 +1,59 @@
  39. +==============================
  40. +Lzip data compression in Linux
  41. +==============================
  42. +
  43. +Introduction
  44. +============
  45. +
  46. +Lzip is a lossless data compressor with a user interface similar to the
  47. +one of gzip or bzip2. Lzip can compress about as fast as gzip (lzip -0),
  48. +or compress most files more than bzip2 (lzip -9). Decompression speed is
  49. +intermediate between gzip and bzip2. Lzip implements the LZMA algorithm.
  50. +
  51. +Lzip has been designed, written and tested with great care to be the
  52. +standard general-purpose compressor for unix-like systems. The lzip
  53. +format is as simple as possible (but not simpler). It provides accurate
  54. +and robust 3 factor integrity checking.
  55. +
  56. +Learn more about lzip at http://www.nongnu.org/lzip/lzip.html
  57. +
  58. +Lzip related components in the kernel
  59. +=====================================
  60. +
  61. +The lzip_decompress module in lib/lzip.c provides a versatile lzip
  62. +decompression function able to do buffer to buffer decompression or
  63. +stream decompression with fill and flush callback functions. The usage
  64. +of the function is documented in include/linux/lzip.h.
  65. +
  66. +For decompressing the kernel image, initramfs, and initrd, there is a
  67. +wrapper function in lib/decompress_lunzip.c providing the same common
  68. +interface as the other decompress_*.c files, which is defined in
  69. +include/linux/decompress/generic.h.
  70. +
  71. +For kernel makefiles, two commands are provided in scripts/Makefile.lib
  72. +for use with $(call if_changed). The kernel image must be compressed
  73. +with $(call if_changed,klzip) which will append a four-byte trailer
  74. +containing the size of the uncompressed data, which is needed by the
  75. +boot code. Other things should be compressed with $(call if_changed,lzip).
  76. +
  77. +Testing
  78. +=======
  79. +
  80. +Lzip-compressed kernel images of multiple linux versions since 2.6.30.10
  81. +have been built and tested, even on machines as modest as an AMD 486-DX2
  82. +at 66 MHz with 64 MiB of RAM. In the worst case (on the slow machine
  83. +above), lzip just increased the boot time a 15% compared with gzip. On
  84. +more modern machines, lzip may boot slightly faster than gzip. It just
  85. +takes 0.2 seconds for lzip to decompress vmlinuz-4.4.16 on my machine.
  86. +
  87. +Decompression time is usually a small fraction of the total boot time.
  88. +For example, using lz4 on a desktop machine in order to save 0.05
  89. +seconds of a total boot time of 20 seconds is probably not worth the
  90. +increased image size.
  91. +
  92. +Xlunzip is a test tool for the lzip_decompress module. It is similar to
  93. +lunzip, but it uses the lzip_decompress module as a backend. The xlunzip
  94. +home page is at http://www.nongnu.org/lzip/xlunzip.html
  95. +
  96. +Author: Antonio Diaz Diaz
  97. +Updated: 2018-07-08
  98. diff -urdN linux-4.18.1/Documentation/x86/boot.txt linux-4.18.1.new/Documentation/x86/boot.txt
  99. --- linux-4.18.1/Documentation/x86/boot.txt 2018-08-15 17:37:34.000000000 +0200
  100. +++ linux-4.18.1.new/Documentation/x86/boot.txt 2018-08-16 18:56:17.000000000 +0200
  101. @@ -665,10 +665,10 @@
  102. The payload may be compressed. The format of both the compressed and
  103. uncompressed data should be determined using the standard magic
  104. numbers. The currently supported compression formats are gzip
  105. - (magic numbers 1F 8B or 1F 9E), bzip2 (magic number 42 5A), LZMA
  106. - (magic number 5D 00), XZ (magic number FD 37), and LZ4 (magic number
  107. - 02 21). The uncompressed payload is currently always ELF (magic
  108. - number 7F 45 4C 46).
  109. + (magic numbers 1F 8B or 1F 9E), bzip2 (magic number 42 5A), lzip
  110. + (magic number 4C 5A), LZMA (magic number 5D 00), XZ (magic number FD
  111. + 37), and LZ4 (magic number 02 21). The uncompressed payload is
  112. + currently always ELF (magic number 7F 45 4C 46).
  113. Field name: payload_length
  114. Type: read
  115. diff -urdN linux-4.18.1/Makefile linux-4.18.1.new/Makefile
  116. --- linux-4.18.1/Makefile 2018-08-15 17:37:34.000000000 +0200
  117. +++ linux-4.18.1.new/Makefile 2018-08-16 18:56:17.000000000 +0200
  118. @@ -890,14 +890,17 @@
  119. export mod_strip_cmd
  120. # CONFIG_MODULE_COMPRESS, if defined, will cause module to be compressed
  121. -# after they are installed in agreement with CONFIG_MODULE_COMPRESS_GZIP
  122. -# or CONFIG_MODULE_COMPRESS_XZ.
  123. +# after they are installed in agreement with CONFIG_MODULE_COMPRESS_GZIP,
  124. +# CONFIG_MODULE_COMPRESS_LZIP or CONFIG_MODULE_COMPRESS_XZ.
  125. mod_compress_cmd = true
  126. ifdef CONFIG_MODULE_COMPRESS
  127. ifdef CONFIG_MODULE_COMPRESS_GZIP
  128. mod_compress_cmd = gzip -n -f
  129. endif # CONFIG_MODULE_COMPRESS_GZIP
  130. + ifdef CONFIG_MODULE_COMPRESS_LZIP
  131. + mod_compress_cmd = lzip -f
  132. + endif # CONFIG_MODULE_COMPRESS_LZIP
  133. ifdef CONFIG_MODULE_COMPRESS_XZ
  134. mod_compress_cmd = xz -f
  135. endif # CONFIG_MODULE_COMPRESS_XZ
  136. @@ -909,6 +912,7 @@
  137. #
  138. INITRD_COMPRESS-y := gzip
  139. INITRD_COMPRESS-$(CONFIG_RD_BZIP2) := bzip2
  140. +INITRD_COMPRESS-$(CONFIG_RD_LZIP) := lzip
  141. INITRD_COMPRESS-$(CONFIG_RD_LZMA) := lzma
  142. INITRD_COMPRESS-$(CONFIG_RD_XZ) := xz
  143. INITRD_COMPRESS-$(CONFIG_RD_LZO) := lzo
  144. diff -urdN linux-4.18.1/arch/arm/Kconfig linux-4.18.1.new/arch/arm/Kconfig
  145. --- linux-4.18.1/arch/arm/Kconfig 2018-08-15 17:37:34.000000000 +0200
  146. +++ linux-4.18.1.new/arch/arm/Kconfig 2018-08-16 18:56:17.000000000 +0200
  147. @@ -76,6 +76,7 @@
  148. select HAVE_IRQ_TIME_ACCOUNTING
  149. select HAVE_KERNEL_GZIP
  150. select HAVE_KERNEL_LZ4
  151. + select HAVE_KERNEL_LZIP
  152. select HAVE_KERNEL_LZMA
  153. select HAVE_KERNEL_LZO
  154. select HAVE_KERNEL_XZ
  155. diff -urdN linux-4.18.1/arch/arm/boot/compressed/Makefile linux-4.18.1.new/arch/arm/boot/compressed/Makefile
  156. --- linux-4.18.1/arch/arm/boot/compressed/Makefile 2018-08-15 17:37:34.000000000 +0200
  157. +++ linux-4.18.1.new/arch/arm/boot/compressed/Makefile 2018-08-16 18:56:17.000000000 +0200
  158. @@ -71,6 +71,7 @@
  159. CPPFLAGS_vmlinux.lds := -DTEXT_START="$(ZTEXTADDR)" -DBSS_START="$(ZBSSADDR)"
  160. compress-$(CONFIG_KERNEL_GZIP) = gzip
  161. +compress-$(CONFIG_KERNEL_LZIP) = klzip
  162. compress-$(CONFIG_KERNEL_LZO) = lzo
  163. compress-$(CONFIG_KERNEL_LZMA) = lzma
  164. compress-$(CONFIG_KERNEL_XZ) = xzkern
  165. diff -urdN linux-4.18.1/arch/arm/boot/compressed/decompress.c linux-4.18.1.new/arch/arm/boot/compressed/decompress.c
  166. --- linux-4.18.1/arch/arm/boot/compressed/decompress.c 2018-08-15 17:37:34.000000000 +0200
  167. +++ linux-4.18.1.new/arch/arm/boot/compressed/decompress.c 2018-08-16 18:56:17.000000000 +0200
  168. @@ -37,6 +37,10 @@
  169. #include "../../../../lib/decompress_inflate.c"
  170. #endif
  171. +#ifdef CONFIG_KERNEL_LZIP
  172. +#include "../../../../lib/decompress_lunzip.c"
  173. +#endif
  174. +
  175. #ifdef CONFIG_KERNEL_LZO
  176. #include "../../../../lib/decompress_unlzo.c"
  177. #endif
  178. diff -urdN linux-4.18.1/arch/mips/Kconfig linux-4.18.1.new/arch/mips/Kconfig
  179. --- linux-4.18.1/arch/mips/Kconfig 2018-08-15 17:37:34.000000000 +0200
  180. +++ linux-4.18.1.new/arch/mips/Kconfig 2018-08-16 18:56:17.000000000 +0200
  181. @@ -1813,6 +1813,7 @@
  182. select HAVE_KERNEL_GZIP
  183. select HAVE_KERNEL_BZIP2
  184. select HAVE_KERNEL_LZ4
  185. + select HAVE_KERNEL_LZIP
  186. select HAVE_KERNEL_LZMA
  187. select HAVE_KERNEL_LZO
  188. select HAVE_KERNEL_XZ
  189. diff -urdN linux-4.18.1/arch/mips/Makefile linux-4.18.1.new/arch/mips/Makefile
  190. --- linux-4.18.1/arch/mips/Makefile 2018-08-15 17:37:34.000000000 +0200
  191. +++ linux-4.18.1.new/arch/mips/Makefile 2018-08-16 18:56:17.000000000 +0200
  192. @@ -336,12 +336,14 @@
  193. boot-y += uImage.bin
  194. boot-y += uImage.bz2
  195. boot-y += uImage.gz
  196. +boot-y += uImage.lz
  197. boot-y += uImage.lzma
  198. boot-y += uImage.lzo
  199. endif
  200. boot-y += vmlinux.itb
  201. boot-y += vmlinux.gz.itb
  202. boot-y += vmlinux.bz2.itb
  203. +boot-y += vmlinux.lz.itb
  204. boot-y += vmlinux.lzma.itb
  205. boot-y += vmlinux.lzo.itb
  206. @@ -452,6 +454,7 @@
  207. echo ' uImage.bin - U-Boot image (uncompressed)'
  208. echo ' uImage.bz2 - U-Boot image (bz2)'
  209. echo ' uImage.gz - U-Boot image (gzip)'
  210. + echo ' uImage.lz - U-Boot image (lzip)'
  211. echo ' uImage.lzma - U-Boot image (lzma)'
  212. echo ' uImage.lzo - U-Boot image (lzo)'
  213. echo ' uzImage.bin - U-Boot image (self-extracting)'
  214. diff -urdN linux-4.18.1/arch/mips/boot/Makefile linux-4.18.1.new/arch/mips/boot/Makefile
  215. --- linux-4.18.1/arch/mips/boot/Makefile 2018-08-15 17:37:34.000000000 +0200
  216. +++ linux-4.18.1.new/arch/mips/boot/Makefile 2018-08-16 18:56:17.000000000 +0200
  217. @@ -26,6 +26,7 @@
  218. suffix-y := bin
  219. suffix-$(CONFIG_KERNEL_BZIP2) := bz2
  220. suffix-$(CONFIG_KERNEL_GZIP) := gz
  221. +suffix-$(CONFIG_KERNEL_LZIP) := lz
  222. suffix-$(CONFIG_KERNEL_LZMA) := lzma
  223. suffix-$(CONFIG_KERNEL_LZO) := lzo
  224. @@ -56,6 +57,7 @@
  225. extra-y += vmlinux.bin.bz2
  226. extra-y += vmlinux.bin.gz
  227. +extra-y += vmlinux.bin.lz
  228. extra-y += vmlinux.bin.lzma
  229. extra-y += vmlinux.bin.lzo
  230. @@ -65,6 +67,9 @@
  231. $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
  232. $(call if_changed,gzip)
  233. +$(obj)/vmlinux.bin.lz: $(obj)/vmlinux.bin FORCE
  234. + $(call if_changed,klzip)
  235. +
  236. $(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE
  237. $(call if_changed,lzma)
  238. @@ -79,6 +84,7 @@
  239. targets += uImage.bin
  240. targets += uImage.bz2
  241. targets += uImage.gz
  242. +targets += uImage.lz
  243. targets += uImage.lzma
  244. targets += uImage.lzo
  245. @@ -91,6 +97,9 @@
  246. $(obj)/uImage.gz: $(obj)/vmlinux.bin.gz FORCE
  247. $(call if_changed,uimage,gzip)
  248. +$(obj)/uImage.lz: $(obj)/vmlinux.bin.lz FORCE
  249. + $(call if_changed,uimage,lzip)
  250. +
  251. $(obj)/uImage.lzma: $(obj)/vmlinux.bin.lzma FORCE
  252. $(call if_changed,uimage,lzma)
  253. @@ -108,6 +117,7 @@
  254. targets += vmlinux.itb
  255. targets += vmlinux.gz.itb
  256. targets += vmlinux.bz2.itb
  257. +targets += vmlinux.lz.itb
  258. targets += vmlinux.lzma.itb
  259. targets += vmlinux.lzo.itb
  260. @@ -144,6 +154,9 @@
  261. $(obj)/vmlinux.bz2.its: $(obj)/vmlinux.its.S $(VMLINUX) FORCE
  262. $(call if_changed_dep,cpp_its_S,bzip2,vmlinux.bin.bz2)
  263. +$(obj)/vmlinux.lz.its: $(obj)/vmlinux.its.S $(VMLINUX) FORCE
  264. + $(call if_changed_dep,cpp_its_S,lzip,vmlinux.bin.lz)
  265. +
  266. $(obj)/vmlinux.lzma.its: $(obj)/vmlinux.its.S $(VMLINUX) FORCE
  267. $(call if_changed_dep,cpp_its_S,lzma,vmlinux.bin.lzma)
  268. @@ -168,6 +181,9 @@
  269. $(obj)/vmlinux.bz2.itb: $(obj)/vmlinux.bz2.its $(obj)/vmlinux.bin.bz2 FORCE
  270. $(call if_changed,itb-image,$<)
  271. +$(obj)/vmlinux.lz.itb: $(obj)/vmlinux.lz.its $(obj)/vmlinux.bin.lz FORCE
  272. + $(call if_changed,itb-image,$<)
  273. +
  274. $(obj)/vmlinux.lzma.itb: $(obj)/vmlinux.lzma.its $(obj)/vmlinux.bin.lzma FORCE
  275. $(call if_changed,itb-image,$<)
  276. diff -urdN linux-4.18.1/arch/mips/boot/compressed/Makefile linux-4.18.1.new/arch/mips/boot/compressed/Makefile
  277. --- linux-4.18.1/arch/mips/boot/compressed/Makefile 2018-08-15 17:37:34.000000000 +0200
  278. +++ linux-4.18.1.new/arch/mips/boot/compressed/Makefile 2018-08-16 18:56:17.000000000 +0200
  279. @@ -64,6 +64,7 @@
  280. tool_$(CONFIG_KERNEL_GZIP) = gzip
  281. tool_$(CONFIG_KERNEL_BZIP2) = bzip2
  282. tool_$(CONFIG_KERNEL_LZ4) = lz4
  283. +tool_$(CONFIG_KERNEL_LZIP) = klzip
  284. tool_$(CONFIG_KERNEL_LZMA) = lzma
  285. tool_$(CONFIG_KERNEL_LZO) = lzo
  286. tool_$(CONFIG_KERNEL_XZ) = xzkern
  287. diff -urdN linux-4.18.1/arch/mips/boot/compressed/decompress.c linux-4.18.1.new/arch/mips/boot/compressed/decompress.c
  288. --- linux-4.18.1/arch/mips/boot/compressed/decompress.c 2018-08-15 17:37:34.000000000 +0200
  289. +++ linux-4.18.1.new/arch/mips/boot/compressed/decompress.c 2018-08-16 18:56:17.000000000 +0200
  290. @@ -64,6 +64,10 @@
  291. #include "../../../../lib/decompress_unlz4.c"
  292. #endif
  293. +#ifdef CONFIG_KERNEL_LZIP
  294. +#include "../../../../lib/decompress_lunzip.c"
  295. +#endif
  296. +
  297. #ifdef CONFIG_KERNEL_LZMA
  298. #include "../../../../lib/decompress_unlzma.c"
  299. #endif
  300. diff -urdN linux-4.18.1/arch/s390/Kconfig linux-4.18.1.new/arch/s390/Kconfig
  301. --- linux-4.18.1/arch/s390/Kconfig 2018-08-15 17:37:34.000000000 +0200
  302. +++ linux-4.18.1.new/arch/s390/Kconfig 2018-08-16 18:56:17.000000000 +0200
  303. @@ -143,6 +143,7 @@
  304. select HAVE_KERNEL_BZIP2
  305. select HAVE_KERNEL_GZIP
  306. select HAVE_KERNEL_LZ4
  307. + select HAVE_KERNEL_LZIP
  308. select HAVE_KERNEL_LZMA
  309. select HAVE_KERNEL_LZO
  310. select HAVE_KERNEL_XZ
  311. diff -urdN linux-4.18.1/arch/s390/boot/compressed/Makefile linux-4.18.1.new/arch/s390/boot/compressed/Makefile
  312. --- linux-4.18.1/arch/s390/boot/compressed/Makefile 2018-08-15 17:37:34.000000000 +0200
  313. +++ linux-4.18.1.new/arch/s390/boot/compressed/Makefile 2018-08-16 18:56:17.000000000 +0200
  314. @@ -7,9 +7,9 @@
  315. KCOV_INSTRUMENT := n
  316. -targets := vmlinux.lds vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2
  317. -targets += vmlinux.bin.xz vmlinux.bin.lzma vmlinux.bin.lzo vmlinux.bin.lz4
  318. -targets += misc.o piggy.o sizes.h head.o
  319. +targets := vmlinux.lds vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2
  320. +targets += vmlinux.bin.lz vmlinux.bin.xz vmlinux.bin.lzma vmlinux.bin.lzo
  321. +targets += vmlinux.bin.lz4 misc.o piggy.o sizes.h head.o
  322. KBUILD_CFLAGS := -m64 -D__KERNEL__ -O2
  323. KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING -D__NO_FORTIFY
  324. @@ -60,6 +60,7 @@
  325. suffix-$(CONFIG_KERNEL_GZIP) := gz
  326. suffix-$(CONFIG_KERNEL_BZIP2) := bz2
  327. suffix-$(CONFIG_KERNEL_LZ4) := lz4
  328. +suffix-$(CONFIG_KERNEL_LZIP) := lz
  329. suffix-$(CONFIG_KERNEL_LZMA) := lzma
  330. suffix-$(CONFIG_KERNEL_LZO) := lzo
  331. suffix-$(CONFIG_KERNEL_XZ) := xz
  332. @@ -70,6 +71,8 @@
  333. $(call if_changed,bzip2)
  334. $(obj)/vmlinux.bin.lz4: $(vmlinux.bin.all-y)
  335. $(call if_changed,lz4)
  336. +$(obj)/vmlinux.bin.lz: $(vmlinux.bin.all-y)
  337. + $(call if_changed,klzip)
  338. $(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y)
  339. $(call if_changed,lzma)
  340. $(obj)/vmlinux.bin.lzo: $(vmlinux.bin.all-y)
  341. diff -urdN linux-4.18.1/arch/s390/boot/compressed/misc.c linux-4.18.1.new/arch/s390/boot/compressed/misc.c
  342. --- linux-4.18.1/arch/s390/boot/compressed/misc.c 2018-08-15 17:37:34.000000000 +0200
  343. +++ linux-4.18.1.new/arch/s390/boot/compressed/misc.c 2018-08-16 18:56:17.000000000 +0200
  344. @@ -53,6 +53,10 @@
  345. #include "../../../../lib/decompress_unlz4.c"
  346. #endif
  347. +#ifdef CONFIG_KERNEL_LZIP
  348. +#include "../../../../lib/decompress_lunzip.c"
  349. +#endif
  350. +
  351. #ifdef CONFIG_KERNEL_LZMA
  352. #include "../../../../lib/decompress_unlzma.c"
  353. #endif
  354. diff -urdN linux-4.18.1/arch/sh/Kconfig linux-4.18.1.new/arch/sh/Kconfig
  355. --- linux-4.18.1/arch/sh/Kconfig 2018-08-15 17:37:34.000000000 +0200
  356. +++ linux-4.18.1.new/arch/sh/Kconfig 2018-08-16 18:56:17.000000000 +0200
  357. @@ -25,6 +25,7 @@
  358. select HAVE_KERNEL_GZIP
  359. select CPU_NO_EFFICIENT_FFS
  360. select HAVE_KERNEL_BZIP2
  361. + select HAVE_KERNEL_LZIP
  362. select HAVE_KERNEL_LZMA
  363. select HAVE_KERNEL_XZ
  364. select HAVE_KERNEL_LZO
  365. diff -urdN linux-4.18.1/arch/sh/Makefile linux-4.18.1.new/arch/sh/Makefile
  366. --- linux-4.18.1/arch/sh/Makefile 2018-08-15 17:37:34.000000000 +0200
  367. +++ linux-4.18.1.new/arch/sh/Makefile 2018-08-16 18:56:17.000000000 +0200
  368. @@ -209,9 +209,9 @@
  369. libs-$(CONFIG_SUPERH32) := arch/sh/lib/ $(libs-y)
  370. libs-$(CONFIG_SUPERH64) := arch/sh/lib64/ $(libs-y)
  371. -BOOT_TARGETS = uImage uImage.bz2 uImage.gz uImage.lzma uImage.xz uImage.lzo \
  372. - uImage.srec uImage.bin zImage vmlinux.bin vmlinux.srec \
  373. - romImage
  374. +BOOT_TARGETS = uImage uImage.bz2 uImage.gz uImage.lz uImage.lzma uImage.xz \
  375. + uImage.lzo uImage.srec uImage.bin zImage vmlinux.bin \
  376. + vmlinux.srec romImage
  377. PHONY += $(BOOT_TARGETS)
  378. all: $(notdir $(KBUILD_IMAGE))
  379. @@ -238,6 +238,7 @@
  380. @echo ' uImage.bin - Kernel-only image for U-Boot (bin)'
  381. @echo '* uImage.gz - Kernel-only image for U-Boot (gzip)'
  382. @echo ' uImage.bz2 - Kernel-only image for U-Boot (bzip2)'
  383. + @echo ' uImage.lz - Kernel-only image for U-Boot (lzip)'
  384. @echo ' uImage.lzma - Kernel-only image for U-Boot (lzma)'
  385. @echo ' uImage.xz - Kernel-only image for U-Boot (xz)'
  386. @echo ' uImage.lzo - Kernel-only image for U-Boot (lzo)'
  387. diff -urdN linux-4.18.1/arch/sh/boot/Makefile linux-4.18.1.new/arch/sh/boot/Makefile
  388. --- linux-4.18.1/arch/sh/boot/Makefile 2018-08-15 17:37:34.000000000 +0200
  389. +++ linux-4.18.1.new/arch/sh/boot/Makefile 2018-08-16 18:56:17.000000000 +0200
  390. @@ -22,14 +22,15 @@
  391. suffix-y := bin
  392. suffix-$(CONFIG_KERNEL_GZIP) := gz
  393. suffix-$(CONFIG_KERNEL_BZIP2) := bz2
  394. +suffix-$(CONFIG_KERNEL_LZIP) := lz
  395. suffix-$(CONFIG_KERNEL_LZMA) := lzma
  396. suffix-$(CONFIG_KERNEL_XZ) := xz
  397. suffix-$(CONFIG_KERNEL_LZO) := lzo
  398. targets := zImage vmlinux.srec romImage uImage uImage.srec uImage.gz \
  399. - uImage.bz2 uImage.lzma uImage.xz uImage.lzo uImage.bin
  400. -extra-y += vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \
  401. - vmlinux.bin.xz vmlinux.bin.lzo
  402. + uImage.bz2 uImage.lz uImage.lzma uImage.xz uImage.lzo uImage.bin
  403. +extra-y += vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lz \
  404. + vmlinux.bin.lzma vmlinux.bin.xz vmlinux.bin.lzo
  405. subdir- := compressed romimage
  406. $(obj)/zImage: $(obj)/compressed/vmlinux FORCE
  407. @@ -71,6 +72,9 @@
  408. $(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin FORCE
  409. $(call if_changed,bzip2)
  410. +$(obj)/vmlinux.bin.lz: $(obj)/vmlinux.bin FORCE
  411. + $(call if_changed,klzip)
  412. +
  413. $(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE
  414. $(call if_changed,lzma)
  415. @@ -86,6 +90,9 @@
  416. $(obj)/uImage.gz: $(obj)/vmlinux.bin.gz
  417. $(call if_changed,uimage,gzip)
  418. +$(obj)/uImage.lz: $(obj)/vmlinux.bin.lz
  419. + $(call if_changed,uimage,lzip)
  420. +
  421. $(obj)/uImage.lzma: $(obj)/vmlinux.bin.lzma
  422. $(call if_changed,uimage,lzma)
  423. diff -urdN linux-4.18.1/arch/sh/boot/compressed/Makefile linux-4.18.1.new/arch/sh/boot/compressed/Makefile
  424. --- linux-4.18.1/arch/sh/boot/compressed/Makefile 2018-08-15 17:37:34.000000000 +0200
  425. +++ linux-4.18.1.new/arch/sh/boot/compressed/Makefile 2018-08-16 18:56:17.000000000 +0200
  426. @@ -5,10 +5,9 @@
  427. # create a compressed vmlinux image from the original vmlinux
  428. #
  429. -targets := vmlinux vmlinux.bin vmlinux.bin.gz \
  430. - vmlinux.bin.bz2 vmlinux.bin.lzma \
  431. - vmlinux.bin.xz vmlinux.bin.lzo \
  432. - head_$(BITS).o misc.o piggy.o
  433. +targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 \
  434. + vmlinux.bin.lz vmlinux.bin.lzma vmlinux.bin.xz vmlinux.bin.lzo \
  435. + head_$(BITS).o misc.o piggy.o
  436. OBJECTS = $(obj)/head_$(BITS).o $(obj)/misc.o $(obj)/cache.o
  437. @@ -66,6 +65,8 @@
  438. $(call if_changed,gzip)
  439. $(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
  440. $(call if_changed,bzip2)
  441. +$(obj)/vmlinux.bin.lz: $(vmlinux.bin.all-y) FORCE
  442. + $(call if_changed,klzip)
  443. $(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
  444. $(call if_changed,lzma)
  445. $(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
  446. diff -urdN linux-4.18.1/arch/sh/boot/compressed/misc.c linux-4.18.1.new/arch/sh/boot/compressed/misc.c
  447. --- linux-4.18.1/arch/sh/boot/compressed/misc.c 2018-08-15 17:37:34.000000000 +0200
  448. +++ linux-4.18.1.new/arch/sh/boot/compressed/misc.c 2018-08-16 18:56:17.000000000 +0200
  449. @@ -58,6 +58,10 @@
  450. #include "../../../../lib/decompress_bunzip2.c"
  451. #endif
  452. +#ifdef CONFIG_KERNEL_LZIP
  453. +#include "../../../../lib/decompress_lunzip.c"
  454. +#endif
  455. +
  456. #ifdef CONFIG_KERNEL_LZMA
  457. #include "../../../../lib/decompress_unlzma.c"
  458. #endif
  459. diff -urdN linux-4.18.1/arch/x86/Kconfig linux-4.18.1.new/arch/x86/Kconfig
  460. --- linux-4.18.1/arch/x86/Kconfig 2018-08-15 17:37:34.000000000 +0200
  461. +++ linux-4.18.1.new/arch/x86/Kconfig 2018-08-16 18:56:17.000000000 +0200
  462. @@ -156,6 +156,7 @@
  463. select HAVE_KERNEL_BZIP2
  464. select HAVE_KERNEL_GZIP
  465. select HAVE_KERNEL_LZ4
  466. + select HAVE_KERNEL_LZIP
  467. select HAVE_KERNEL_LZMA
  468. select HAVE_KERNEL_LZO
  469. select HAVE_KERNEL_XZ
  470. diff -urdN linux-4.18.1/arch/x86/boot/compressed/Makefile linux-4.18.1.new/arch/x86/boot/compressed/Makefile
  471. --- linux-4.18.1/arch/x86/boot/compressed/Makefile 2018-08-15 17:37:34.000000000 +0200
  472. +++ linux-4.18.1.new/arch/x86/boot/compressed/Makefile 2018-08-16 18:56:17.000000000 +0200
  473. @@ -23,8 +23,8 @@
  474. # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
  475. KCOV_INSTRUMENT := n
  476. -targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \
  477. - vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4
  478. +targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lz \
  479. + vmlinux.bin.lzma vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4
  480. KBUILD_CFLAGS := -m$(BITS) -O2
  481. KBUILD_CFLAGS += -fno-strict-aliasing $(call cc-option, -fPIE, -fPIC)
  482. @@ -133,6 +133,8 @@
  483. $(call if_changed,gzip)
  484. $(obj)/vmlinux.bin.bz2: $(vmlinux.bin.all-y) FORCE
  485. $(call if_changed,bzip2)
  486. +$(obj)/vmlinux.bin.lz: $(vmlinux.bin.all-y) FORCE
  487. + $(call if_changed,klzip)
  488. $(obj)/vmlinux.bin.lzma: $(vmlinux.bin.all-y) FORCE
  489. $(call if_changed,lzma)
  490. $(obj)/vmlinux.bin.xz: $(vmlinux.bin.all-y) FORCE
  491. @@ -144,6 +146,7 @@
  492. suffix-$(CONFIG_KERNEL_GZIP) := gz
  493. suffix-$(CONFIG_KERNEL_BZIP2) := bz2
  494. +suffix-$(CONFIG_KERNEL_LZIP) := lz
  495. suffix-$(CONFIG_KERNEL_LZMA) := lzma
  496. suffix-$(CONFIG_KERNEL_XZ) := xz
  497. suffix-$(CONFIG_KERNEL_LZO) := lzo
  498. diff -urdN linux-4.18.1/arch/x86/boot/compressed/misc.c linux-4.18.1.new/arch/x86/boot/compressed/misc.c
  499. --- linux-4.18.1/arch/x86/boot/compressed/misc.c 2018-08-15 17:37:34.000000000 +0200
  500. +++ linux-4.18.1.new/arch/x86/boot/compressed/misc.c 2018-08-16 18:56:17.000000000 +0200
  501. @@ -61,6 +61,10 @@
  502. #include "../../../../lib/decompress_bunzip2.c"
  503. #endif
  504. +#ifdef CONFIG_KERNEL_LZIP
  505. +#include "../../../../lib/decompress_lunzip.c"
  506. +#endif
  507. +
  508. #ifdef CONFIG_KERNEL_LZMA
  509. #include "../../../../lib/decompress_unlzma.c"
  510. #endif
  511. diff -urdN linux-4.18.1/fs/squashfs/Kconfig linux-4.18.1.new/fs/squashfs/Kconfig
  512. --- linux-4.18.1/fs/squashfs/Kconfig 2018-08-15 17:37:34.000000000 +0200
  513. +++ linux-4.18.1.new/fs/squashfs/Kconfig 2018-08-16 18:56:17.000000000 +0200
  514. @@ -4,7 +4,7 @@
  515. help
  516. Saying Y here includes support for SquashFS 4.0 (a Compressed
  517. Read-Only File System). Squashfs is a highly compressed read-only
  518. - filesystem for Linux. It uses zlib, lzo or xz compression to
  519. + filesystem for Linux. It uses zlib, lzip, lzo or xz compression to
  520. compress both files, inodes and directories. Inodes in the system
  521. are very small and all blocks are packed to minimise data overhead.
  522. Block sizes greater than 4K are supported up to a maximum of 1 Mbytes
  523. @@ -134,6 +134,21 @@
  524. file systems will be readable without selecting this option.
  525. If unsure, say N.
  526. +
  527. +config SQUASHFS_LZIP
  528. + bool "Include support for LZIP compressed file systems"
  529. + depends on SQUASHFS
  530. + select LZIP_DECOMPRESS
  531. + help
  532. + Saying Y here includes support for reading Squashfs file systems
  533. + compressed with LZIP compression. LZIP gives better compression
  534. + than the default zlib compression, at the expense of greater CPU
  535. + and memory overhead.
  536. +
  537. + LZIP is not the standard compression used in Squashfs and so most
  538. + file systems will be readable without selecting this option.
  539. +
  540. + If unsure, say N.
  541. config SQUASHFS_LZO
  542. bool "Include support for LZO compressed file systems"
  543. diff -urdN linux-4.18.1/fs/squashfs/Makefile linux-4.18.1.new/fs/squashfs/Makefile
  544. --- linux-4.18.1/fs/squashfs/Makefile 2018-08-15 17:37:34.000000000 +0200
  545. +++ linux-4.18.1.new/fs/squashfs/Makefile 2018-08-16 18:56:17.000000000 +0200
  546. @@ -13,6 +13,7 @@
  547. squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI_PERCPU) += decompressor_multi_percpu.o
  548. squashfs-$(CONFIG_SQUASHFS_XATTR) += xattr.o xattr_id.o
  549. squashfs-$(CONFIG_SQUASHFS_LZ4) += lz4_wrapper.o
  550. +squashfs-$(CONFIG_SQUASHFS_LZIP) += lzip_wrapper.o
  551. squashfs-$(CONFIG_SQUASHFS_LZO) += lzo_wrapper.o
  552. squashfs-$(CONFIG_SQUASHFS_XZ) += xz_wrapper.o
  553. squashfs-$(CONFIG_SQUASHFS_ZLIB) += zlib_wrapper.o
  554. diff -urdN linux-4.18.1/fs/squashfs/decompressor.c linux-4.18.1.new/fs/squashfs/decompressor.c
  555. --- linux-4.18.1/fs/squashfs/decompressor.c 2018-08-15 17:37:34.000000000 +0200
  556. +++ linux-4.18.1.new/fs/squashfs/decompressor.c 2018-08-16 18:56:17.000000000 +0200
  557. @@ -47,6 +47,12 @@
  558. };
  559. #endif
  560. +#ifndef CONFIG_SQUASHFS_LZIP
  561. +static const struct squashfs_decompressor squashfs_lzip_comp_ops = {
  562. + NULL, NULL, NULL, NULL, LZIP_COMPRESSION, "lzip", 0
  563. +};
  564. +#endif
  565. +
  566. #ifndef CONFIG_SQUASHFS_LZO
  567. static const struct squashfs_decompressor squashfs_lzo_comp_ops = {
  568. NULL, NULL, NULL, NULL, LZO_COMPRESSION, "lzo", 0
  569. @@ -78,6 +84,7 @@
  570. static const struct squashfs_decompressor *decompressor[] = {
  571. &squashfs_zlib_comp_ops,
  572. &squashfs_lz4_comp_ops,
  573. + &squashfs_lzip_comp_ops,
  574. &squashfs_lzo_comp_ops,
  575. &squashfs_xz_comp_ops,
  576. &squashfs_lzma_unsupported_comp_ops,
  577. diff -urdN linux-4.18.1/fs/squashfs/decompressor.h linux-4.18.1.new/fs/squashfs/decompressor.h
  578. --- linux-4.18.1/fs/squashfs/decompressor.h 2018-08-15 17:37:34.000000000 +0200
  579. +++ linux-4.18.1.new/fs/squashfs/decompressor.h 2018-08-16 18:56:17.000000000 +0200
  580. @@ -50,6 +50,10 @@
  581. extern const struct squashfs_decompressor squashfs_lz4_comp_ops;
  582. #endif
  583. +#ifdef CONFIG_SQUASHFS_LZIP
  584. +extern const struct squashfs_decompressor squashfs_lzip_comp_ops;
  585. +#endif
  586. +
  587. #ifdef CONFIG_SQUASHFS_LZO
  588. extern const struct squashfs_decompressor squashfs_lzo_comp_ops;
  589. #endif
  590. diff -urdN linux-4.18.1/fs/squashfs/lzip_wrapper.c linux-4.18.1.new/fs/squashfs/lzip_wrapper.c
  591. --- linux-4.18.1/fs/squashfs/lzip_wrapper.c 1970-01-01 01:00:00.000000000 +0100
  592. +++ linux-4.18.1.new/fs/squashfs/lzip_wrapper.c 2018-08-16 18:56:17.000000000 +0200
  593. @@ -0,0 +1,129 @@
  594. +/*
  595. + * Squashfs - a compressed read only filesystem for Linux
  596. + *
  597. + * Copyright (c) 2014
  598. + * Phillip Lougher <phillip@squashfs.org.uk>
  599. + * Copyright (C) 2018 Antonio Diaz Diaz
  600. + *
  601. + * This program is free software; you can redistribute it and/or
  602. + * modify it under the terms of the GNU General Public License
  603. + * as published by the Free Software Foundation; either version 2,
  604. + * or (at your option) any later version.
  605. + *
  606. + * This program is distributed in the hope that it will be useful,
  607. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  608. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  609. + * GNU General Public License for more details.
  610. + *
  611. + * You should have received a copy of the GNU General Public License
  612. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  613. + *
  614. + * lzip_wrapper.c
  615. + */
  616. +
  617. +#include <linux/buffer_head.h>
  618. +#include <linux/mutex.h>
  619. +#include <linux/slab.h>
  620. +#include <linux/vmalloc.h>
  621. +#include <linux/lzip.h>
  622. +
  623. +#include "squashfs_fs.h"
  624. +#include "squashfs_fs_sb.h"
  625. +#include "squashfs.h"
  626. +#include "decompressor.h"
  627. +#include "page_actor.h"
  628. +
  629. +struct squashfs_lzip {
  630. + void *input;
  631. + void *output;
  632. +};
  633. +
  634. +
  635. +static void *lzip_init(struct squashfs_sb_info *msblk, void *buff)
  636. +{
  637. + int block_size = max_t(int, msblk->block_size, SQUASHFS_METADATA_SIZE);
  638. + struct squashfs_lzip *stream = kzalloc(sizeof(*stream), GFP_KERNEL);
  639. + if (stream == NULL)
  640. + goto failed;
  641. + stream->input = vmalloc(block_size);
  642. + if (stream->input == NULL)
  643. + goto failed2;
  644. + stream->output = vmalloc(block_size);
  645. + if (stream->output == NULL)
  646. + goto failed3;
  647. +
  648. + return stream;
  649. +
  650. +failed3:
  651. + vfree(stream->input);
  652. +failed2:
  653. + kfree(stream);
  654. +failed:
  655. + ERROR("Failed to initialise LZIP decompressor\n");
  656. + return ERR_PTR(-ENOMEM);
  657. +}
  658. +
  659. +
  660. +static void lzip_free(void *strm)
  661. +{
  662. + struct squashfs_lzip *stream = strm;
  663. +
  664. + if (stream) {
  665. + vfree(stream->input);
  666. + vfree(stream->output);
  667. + }
  668. + kfree(stream);
  669. +}
  670. +
  671. +
  672. +static int lzip_uncompress(struct squashfs_sb_info *msblk, void *strm,
  673. + struct buffer_head **bh, int b, int offset, int length,
  674. + struct squashfs_page_actor *output)
  675. +{
  676. + struct squashfs_lzip *stream = strm;
  677. + void *buff = stream->input, *data;
  678. + long out_pos;
  679. + int avail, i, bytes = length, res;
  680. +
  681. + for (i = 0; i < b; i++) {
  682. + avail = min(bytes, msblk->devblksize - offset);
  683. + memcpy(buff, bh[i]->b_data + offset, avail);
  684. + buff += avail;
  685. + bytes -= avail;
  686. + offset = 0;
  687. + put_bh(bh[i]);
  688. + }
  689. +
  690. + res = lzip_decompress(stream->input, length, 0, 0, stream->output,
  691. + output->length, 0, &out_pos);
  692. + if (res < 0) {
  693. + ERROR("LZIP error code %d\n", res);
  694. + return -EIO;
  695. + }
  696. + bytes = out_pos;
  697. + data = squashfs_first_page(output);
  698. + buff = stream->output;
  699. + while (data) {
  700. + if (bytes <= PAGE_SIZE) {
  701. + memcpy(data, buff, bytes);
  702. + break;
  703. + }
  704. + memcpy(data, buff, PAGE_SIZE);
  705. + buff += PAGE_SIZE;
  706. + bytes -= PAGE_SIZE;
  707. + data = squashfs_next_page(output);
  708. + }
  709. + squashfs_finish_page(output);
  710. +
  711. + return out_pos;
  712. +}
  713. +
  714. +
  715. +const struct squashfs_decompressor squashfs_lzip_comp_ops = {
  716. + .init = lzip_init,
  717. + .free = lzip_free,
  718. + .decompress = lzip_uncompress,
  719. + .id = LZIP_COMPRESSION,
  720. + .name = "lzip",
  721. + .supported = 1
  722. +};
  723. diff -urdN linux-4.18.1/fs/squashfs/squashfs_fs.h linux-4.18.1.new/fs/squashfs/squashfs_fs.h
  724. --- linux-4.18.1/fs/squashfs/squashfs_fs.h 2018-08-15 17:37:34.000000000 +0200
  725. +++ linux-4.18.1.new/fs/squashfs/squashfs_fs.h 2018-08-16 18:56:17.000000000 +0200
  726. @@ -248,6 +248,7 @@
  727. #define XZ_COMPRESSION 4
  728. #define LZ4_COMPRESSION 5
  729. #define ZSTD_COMPRESSION 6
  730. +#define LZIP_COMPRESSION 7
  731. struct squashfs_super_block {
  732. __le32 s_magic;
  733. diff -urdN linux-4.18.1/include/linux/decompress/lunzip.h linux-4.18.1.new/include/linux/decompress/lunzip.h
  734. --- linux-4.18.1/include/linux/decompress/lunzip.h 1970-01-01 01:00:00.000000000 +0100
  735. +++ linux-4.18.1.new/include/linux/decompress/lunzip.h 2018-08-16 18:56:17.000000000 +0200
  736. @@ -0,0 +1,11 @@
  737. +/* SPDX-License-Identifier: GPL-2.0 */
  738. +#ifndef LINUX_DECOMPRESS_LUNZIP_H
  739. +#define LINUX_DECOMPRESS_LUNZIP_H
  740. +
  741. +int lunzip(unsigned char *inbuf, long in_len,
  742. + long (*fill)(void*, unsigned long),
  743. + long (*flush)(void*, unsigned long),
  744. + unsigned char *outbuf,
  745. + long *in_posp,
  746. + void (*error)(char *x));
  747. +#endif
  748. diff -urdN linux-4.18.1/include/linux/lzip.h linux-4.18.1.new/include/linux/lzip.h
  749. --- linux-4.18.1/include/linux/lzip.h 1970-01-01 01:00:00.000000000 +0100
  750. +++ linux-4.18.1.new/include/linux/lzip.h 2018-08-16 18:56:17.000000000 +0200
  751. @@ -0,0 +1,53 @@
  752. +/* SPDX-License-Identifier: GPL-2.0 */
  753. +#ifndef __LZIP_H__
  754. +#define __LZIP_H__
  755. +/*
  756. + * LZIP decompressor
  757. + *
  758. + * Copyright (C) 2016-2018 Antonio Diaz Diaz.
  759. + */
  760. +
  761. +/* Return values (< 0 = Error) */
  762. +enum {
  763. + LZIP_OOM_INBUF = -1,
  764. + LZIP_HEADER1_EOF = -2,
  765. + LZIP_HEADER2_EOF = -3,
  766. + LZIP_BAD_MAGIC1 = -4,
  767. + LZIP_BAD_MAGIC2 = -5,
  768. + LZIP_BAD_VERSION = -6,
  769. + LZIP_BAD_DICT_SIZE = -7,
  770. + LZIP_OOM_OUTBUF = -8,
  771. + LZIP_WRITE_ERROR = -9,
  772. + LZIP_BAD_DATA = -10,
  773. + LZIP_DATA_EOF = -11,
  774. + LZIP_BAD_CRC = -12
  775. +};
  776. +
  777. +int lzip_decompress(unsigned char *inbuf, long in_len,
  778. + long (*fill)(void*, unsigned long),
  779. + long (*flush)(void*, unsigned long),
  780. + unsigned char *outbuf, long out_size,
  781. + long *in_posp, long *out_posp);
  782. +
  783. +/* inbuf - input buffer. If null or in_len <= 0, fill must be non-null
  784. + * in_len - len of pre-read data in inbuf if inbuf is non-null
  785. + * fill - if non-null, function to fill inbuf when empty
  786. + * flush - if non-null, function to write out outbuf when full
  787. + * outbuf - output buffer. If null or out_size <= 0, flush must be non-null
  788. + * out_size - size of outbuf if outbuf is non-null
  789. + * in_posp - if non-null, the number of bytes consumed will be returned here
  790. + * out_posp - if non-null, the number of bytes produced will be returned here
  791. + *
  792. + * fill will be called (repeatedly) to read data. in_len bytes will be read
  793. + * per call (or 16384 bytes per call if inbuf is null or in_len <= 0).
  794. + *
  795. + * If flush is null, outbuf must be large enough to buffer all the expected
  796. + * output. Else the flush function will be called to flush the output buffer
  797. + * at the appropriate time (stream dependent).
  798. + * If out_size > 0 but is not large enough to buffer all the expected output,
  799. + * it must be at least as large as the dictionary size of the data.
  800. + *
  801. + * inbuf and outbuf may overlap (in-place decompression).
  802. + */
  803. +
  804. +#endif
  805. diff -urdN linux-4.18.1/init/Kconfig linux-4.18.1.new/init/Kconfig
  806. --- linux-4.18.1/init/Kconfig 2018-08-15 17:37:34.000000000 +0200
  807. +++ linux-4.18.1.new/init/Kconfig 2018-08-16 18:56:17.000000000 +0200
  808. @@ -113,6 +113,9 @@
  809. config HAVE_KERNEL_BZIP2
  810. bool
  811. +config HAVE_KERNEL_LZIP
  812. + bool
  813. +
  814. config HAVE_KERNEL_LZMA
  815. bool
  816. @@ -128,7 +131,7 @@
  817. choice
  818. prompt "Kernel compression mode"
  819. default KERNEL_GZIP
  820. - depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || HAVE_KERNEL_XZ || HAVE_KERNEL_LZO || HAVE_KERNEL_LZ4
  821. + depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZIP || HAVE_KERNEL_LZMA || HAVE_KERNEL_XZ || HAVE_KERNEL_LZO || HAVE_KERNEL_LZ4
  822. help
  823. The linux kernel is a kind of self-extracting executable.
  824. Several compression algorithms are available, which differ
  825. @@ -164,6 +167,15 @@
  826. Bzip2 uses a large amount of memory. For modern kernels you
  827. will need at least 8MB RAM or more for booting.
  828. +config KERNEL_LZIP
  829. + bool "Lzip"
  830. + depends on HAVE_KERNEL_LZIP
  831. + help
  832. + Lzip's compression ratio is better than that of gzip and bzip2.
  833. + Decompression speed is between gzip and bzip2. Compression can
  834. + be as fast as gzip or slower than bzip2 depending on compression
  835. + level. Lzip can produce a kernel about a 16% smaller than gzip.
  836. +
  837. config KERNEL_LZMA
  838. bool "LZMA"
  839. depends on HAVE_KERNEL_LZMA
  840. @@ -1882,8 +1894,8 @@
  841. depends on MODULES
  842. help
  843. - Compresses kernel modules when 'make modules_install' is run; gzip or
  844. - xz depending on "Compression algorithm" below.
  845. + Compresses kernel modules when 'make modules_install' is run; gzip,
  846. + lzip or xz are used depending on "Compression algorithm" below.
  847. module-init-tools MAY support gzip, and kmod MAY support gzip and xz.
  848. @@ -1905,11 +1917,14 @@
  849. This determines which sort of compression will be used during
  850. 'make modules_install'.
  851. - GZIP (default) and XZ are supported.
  852. + GZIP (default), LZIP and XZ are supported.
  853. config MODULE_COMPRESS_GZIP
  854. bool "GZIP"
  855. +config MODULE_COMPRESS_LZIP
  856. + bool "LZIP"
  857. +
  858. config MODULE_COMPRESS_XZ
  859. bool "XZ"
  860. diff -urdN linux-4.18.1/init/do_mounts_rd.c linux-4.18.1.new/init/do_mounts_rd.c
  861. --- linux-4.18.1/init/do_mounts_rd.c 2018-08-15 17:37:34.000000000 +0200
  862. +++ linux-4.18.1.new/init/do_mounts_rd.c 2018-08-16 18:56:17.000000000 +0200
  863. @@ -59,6 +59,7 @@
  864. * squashfs
  865. * gzip
  866. * bzip2
  867. + * lzip
  868. * lzma
  869. * xz
  870. * lzo
  871. diff -urdN linux-4.18.1/lib/Kconfig linux-4.18.1.new/lib/Kconfig
  872. --- linux-4.18.1/lib/Kconfig 2018-08-15 17:37:34.000000000 +0200
  873. +++ linux-4.18.1.new/lib/Kconfig 2018-08-16 18:56:17.000000000 +0200
  874. @@ -246,6 +246,12 @@
  875. tristate
  876. select BITREVERSE
  877. +config LZIP_DECOMPRESS
  878. + tristate "LZIP decompression support"
  879. + help
  880. + LZMA compression algorithm is supported using the .lz file format.
  881. + See Documentation/lzip.txt for more information.
  882. +
  883. config LZO_COMPRESS
  884. tristate
  885. @@ -282,6 +288,10 @@
  886. config DECOMPRESS_BZIP2
  887. tristate
  888. +config DECOMPRESS_LZIP
  889. + select LZIP_DECOMPRESS
  890. + tristate
  891. +
  892. config DECOMPRESS_LZMA
  893. tristate
  894. diff -urdN linux-4.18.1/lib/Makefile linux-4.18.1.new/lib/Makefile
  895. --- linux-4.18.1/lib/Makefile 2018-08-15 17:37:34.000000000 +0200
  896. +++ linux-4.18.1.new/lib/Makefile 2018-08-16 18:56:17.000000000 +0200
  897. @@ -116,6 +116,7 @@
  898. obj-$(CONFIG_ZLIB_DEFLATE) += zlib_deflate/
  899. obj-$(CONFIG_REED_SOLOMON) += reed_solomon/
  900. obj-$(CONFIG_BCH) += bch.o
  901. +obj-$(CONFIG_LZIP_DECOMPRESS) += lzip.o
  902. obj-$(CONFIG_LZO_COMPRESS) += lzo/
  903. obj-$(CONFIG_LZO_DECOMPRESS) += lzo/
  904. obj-$(CONFIG_LZ4_COMPRESS) += lz4/
  905. @@ -128,6 +129,7 @@
  906. lib-$(CONFIG_DECOMPRESS_GZIP) += decompress_inflate.o
  907. lib-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o
  908. +lib-$(CONFIG_DECOMPRESS_LZIP) += decompress_lunzip.o
  909. lib-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o
  910. lib-$(CONFIG_DECOMPRESS_XZ) += decompress_unxz.o
  911. lib-$(CONFIG_DECOMPRESS_LZO) += decompress_unlzo.o
  912. diff -urdN linux-4.18.1/lib/decompress.c linux-4.18.1.new/lib/decompress.c
  913. --- linux-4.18.1/lib/decompress.c 2018-08-15 17:37:34.000000000 +0200
  914. +++ linux-4.18.1.new/lib/decompress.c 2018-08-16 18:56:17.000000000 +0200
  915. @@ -8,6 +8,7 @@
  916. #include <linux/decompress/generic.h>
  917. #include <linux/decompress/bunzip2.h>
  918. +#include <linux/decompress/lunzip.h>
  919. #include <linux/decompress/unlzma.h>
  920. #include <linux/decompress/unxz.h>
  921. #include <linux/decompress/inflate.h>
  922. @@ -25,6 +26,9 @@
  923. #ifndef CONFIG_DECOMPRESS_BZIP2
  924. # define bunzip2 NULL
  925. #endif
  926. +#ifndef CONFIG_DECOMPRESS_LZIP
  927. +# define lunzip NULL
  928. +#endif
  929. #ifndef CONFIG_DECOMPRESS_LZMA
  930. # define unlzma NULL
  931. #endif
  932. @@ -48,6 +52,7 @@
  933. { {0x1f, 0x8b}, "gzip", gunzip },
  934. { {0x1f, 0x9e}, "gzip", gunzip },
  935. { {0x42, 0x5a}, "bzip2", bunzip2 },
  936. + { {0x4c, 0x5a}, "lzip", lunzip },
  937. { {0x5d, 0x00}, "lzma", unlzma },
  938. { {0xfd, 0x37}, "xz", unxz },
  939. { {0x89, 0x4c}, "lzo", unlzo },
  940. diff -urdN linux-4.18.1/lib/decompress_lunzip.c linux-4.18.1.new/lib/decompress_lunzip.c
  941. --- linux-4.18.1/lib/decompress_lunzip.c 1970-01-01 01:00:00.000000000 +0100
  942. +++ linux-4.18.1.new/lib/decompress_lunzip.c 2018-08-16 20:45:12.000000000 +0200
  943. @@ -0,0 +1,100 @@
  944. +/*
  945. + * Wrapper for decompressing LZIP-compressed kernel, initramfs, and initrd
  946. + *
  947. + * Copyright (C) 2016-2018 Antonio Diaz Diaz.
  948. + *
  949. + * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  950. + */
  951. +
  952. +#ifdef STATIC
  953. +#define PREBOOT
  954. +#include "lzip.c"
  955. +#else
  956. +#include <linux/lzip.h>
  957. +#include <linux/decompress/lunzip.h>
  958. +#include <linux/decompress/mm.h>
  959. +#endif
  960. +
  961. +STATIC int INIT __lunzip(unsigned char *inbuf, long in_len,
  962. + long (*fill)(void*, unsigned long),
  963. + long (*flush)(void*, unsigned long),
  964. + unsigned char *outbuf, long out_size,
  965. + long *in_posp, long *out_posp,
  966. + void (*error)(char *x))
  967. +{
  968. + const int retval = lzip_decompress(inbuf, in_len, fill, flush,
  969. + outbuf, out_size, in_posp, out_posp);
  970. + switch (retval) {
  971. + case 0: break;
  972. + case LZIP_OOM_INBUF:
  973. + error("Out of memory while allocating input buffer.");
  974. + break;
  975. + case LZIP_HEADER1_EOF:
  976. + error("File ends unexpectedly at member header.");
  977. + break;
  978. + case LZIP_HEADER2_EOF:
  979. + error("Truncated header in multimember file.");
  980. + break;
  981. + case LZIP_BAD_MAGIC1:
  982. + error("Bad magic number (file not in lzip format).");
  983. + break;
  984. + case LZIP_BAD_MAGIC2:
  985. + error("Corrupt header in multimember file.");
  986. + break;
  987. + case LZIP_BAD_VERSION:
  988. + error("Version of lzip member format not supported.");
  989. + break;
  990. + case LZIP_BAD_DICT_SIZE:
  991. + error("Invalid dictionary size in member header.");
  992. + break;
  993. + case LZIP_OOM_OUTBUF:
  994. + error("Out of memory while allocating output buffer.");
  995. + break;
  996. + case LZIP_WRITE_ERROR:
  997. + error("Write error.");
  998. + break;
  999. + case LZIP_BAD_DATA:
  1000. + error("LZIP-compressed data is corrupt.");
  1001. + break;
  1002. + case LZIP_DATA_EOF:
  1003. + error("LZIP-compressed data ends unexpectedly.");
  1004. + break;
  1005. + case LZIP_BAD_CRC:
  1006. + error("CRC mismatch in LZIP-compressed data.");
  1007. + break;
  1008. + default:
  1009. + error("Bug in the LZIP decompressor.");
  1010. + }
  1011. + return retval;
  1012. +}
  1013. +
  1014. +#ifndef PREBOOT
  1015. +/* decompress_fn (see linux/decompress/generic.h) should have an out_size
  1016. + * argument to prevent overflowing outbuf in case of corruption of the
  1017. + * compressed data.
  1018. + */
  1019. +STATIC int INIT lunzip(unsigned char *inbuf, long in_len,
  1020. + long (*fill)(void*, unsigned long),
  1021. + long (*flush)(void*, unsigned long),
  1022. + unsigned char *outbuf,
  1023. + long *in_posp,
  1024. + void (*error)(char *x))
  1025. +{
  1026. + return __lunzip(inbuf, in_len, fill, flush, outbuf, LONG_MAX,
  1027. + in_posp, 0, error);
  1028. +}
  1029. +#else
  1030. +STATIC int INIT __decompress(unsigned char *inbuf, long in_len,
  1031. + long (*fill)(void*, unsigned long),
  1032. + long (*flush)(void*, unsigned long),
  1033. + unsigned char *outbuf, long out_size,
  1034. + long *in_posp,
  1035. + void (*error)(char *x))
  1036. +{
  1037. +/* Some archs pass out_size = 0 (to mean unlimited size), which is unsafe
  1038. + * in case of corruption of the compressed data.
  1039. + */
  1040. + return __lunzip(inbuf, in_len - 4, fill, flush, outbuf,
  1041. + out_size ? out_size : LONG_MAX, in_posp, 0, error);
  1042. +}
  1043. +#endif
  1044. diff -urdN linux-4.18.1/lib/lzip.c linux-4.18.1.new/lib/lzip.c
  1045. --- linux-4.18.1/lib/lzip.c 1970-01-01 01:00:00.000000000 +0100
  1046. +++ linux-4.18.1.new/lib/lzip.c 2018-08-29 13:47:06.000000000 +0200
  1047. @@ -0,0 +1,880 @@
  1048. +/*
  1049. + * LZIP decompressor
  1050. + *
  1051. + * Copyright (C) 2016-2018 Antonio Diaz Diaz.
  1052. + *
  1053. + * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  1054. + */
  1055. +
  1056. +#include <linux/module.h>
  1057. +#include <linux/lzip.h>
  1058. +#include <linux/decompress/mm.h>
  1059. +
  1060. +/*
  1061. + * STATIC_RW_DATA is used in the pre-boot environment on some architectures.
  1062. + * See <linux/decompress/mm.h> for details.
  1063. + */
  1064. +#ifndef STATIC_RW_DATA
  1065. +#define STATIC_RW_DATA static
  1066. +#endif
  1067. +
  1068. +typedef int State;
  1069. +
  1070. +enum { states = 12 };
  1071. +
  1072. +static inline bool St_is_char(const State st) { return st < 7; }
  1073. +
  1074. +static inline State St_set_char(const State st)
  1075. +{
  1076. + STATIC_RW_DATA const State next[states] = { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 };
  1077. + return next[st];
  1078. +}
  1079. +
  1080. +static inline State St_set_match(const State st)
  1081. +{
  1082. + return ((st < 7) ? 7 : 10);
  1083. +}
  1084. +
  1085. +static inline State St_set_rep(const State st)
  1086. +{
  1087. + return ((st < 7) ? 8 : 11);
  1088. +}
  1089. +
  1090. +static inline State St_set_short_rep(const State st)
  1091. +{
  1092. + return ((st < 7) ? 9 : 11);
  1093. +}
  1094. +
  1095. +
  1096. +enum {
  1097. + min_dictionary_bits = 12,
  1098. + min_dictionary_size = 1 << min_dictionary_bits,
  1099. + max_dictionary_bits = 29,
  1100. + max_dictionary_size = 1 << max_dictionary_bits,
  1101. + literal_context_bits = 3,
  1102. + pos_state_bits = 2,
  1103. + pos_states = 1 << pos_state_bits,
  1104. + pos_state_mask = pos_states - 1,
  1105. +
  1106. + len_states = 4,
  1107. + dis_slot_bits = 6,
  1108. + start_dis_model = 4,
  1109. + end_dis_model = 14,
  1110. + modeled_distances = 1 << (end_dis_model / 2), /* 128 */
  1111. + dis_align_bits = 4,
  1112. + dis_align_size = 1 << dis_align_bits,
  1113. +
  1114. + len_low_bits = 3,
  1115. + len_mid_bits = 3,
  1116. + len_high_bits = 8,
  1117. + len_low_symbols = 1 << len_low_bits,
  1118. + len_mid_symbols = 1 << len_mid_bits,
  1119. + len_high_symbols = 1 << len_high_bits,
  1120. + max_len_symbols = len_low_symbols + len_mid_symbols + len_high_symbols,
  1121. +
  1122. + min_match_len = 2, /* must be 2 */
  1123. + max_match_len = min_match_len + max_len_symbols - 1, /* 273 */
  1124. + min_match_len_limit = 5
  1125. +};
  1126. +
  1127. +static inline int get_len_state(const int len)
  1128. +{
  1129. + return min(len - min_match_len, len_states - 1);
  1130. +}
  1131. +
  1132. +static inline int get_lit_state(const uint8_t prev_byte)
  1133. +{
  1134. + return (prev_byte >> (8 - literal_context_bits));
  1135. +}
  1136. +
  1137. +
  1138. +enum { bit_model_move_bits = 5,
  1139. + bit_model_total_bits = 11,
  1140. + bit_model_total = 1 << bit_model_total_bits
  1141. +};
  1142. +
  1143. +typedef int Bit_model;
  1144. +
  1145. +static inline void Bm_init(Bit_model * const probability)
  1146. +{
  1147. + *probability = bit_model_total / 2;
  1148. +}
  1149. +
  1150. +static inline void Bm_array_init(Bit_model bm[], const int size)
  1151. +{
  1152. + int i;
  1153. +
  1154. + for (i = 0; i < size; ++i)
  1155. + Bm_init(&bm[i]);
  1156. +}
  1157. +
  1158. +struct Len_model {
  1159. + Bit_model choice1;
  1160. + Bit_model choice2;
  1161. + Bit_model bm_low[pos_states][len_low_symbols];
  1162. + Bit_model bm_mid[pos_states][len_mid_symbols];
  1163. + Bit_model bm_high[len_high_symbols];
  1164. +};
  1165. +
  1166. +static inline void Lm_init(struct Len_model * const lm)
  1167. +{
  1168. + Bm_init(&lm->choice1);
  1169. + Bm_init(&lm->choice2);
  1170. + Bm_array_init(lm->bm_low[0], pos_states * len_low_symbols);
  1171. + Bm_array_init(lm->bm_mid[0], pos_states * len_mid_symbols);
  1172. + Bm_array_init(lm->bm_high, len_high_symbols);
  1173. +}
  1174. +
  1175. +
  1176. +/* Table of CRCs of all 8-bit messages. */
  1177. +STATIC_RW_DATA const uint32_t crc32[256] =
  1178. + {
  1179. + 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,
  1180. + 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
  1181. + 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2,
  1182. + 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
  1183. + 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9,
  1184. + 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
  1185. + 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C,
  1186. + 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
  1187. + 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423,
  1188. + 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
  1189. + 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x01DB7106,
  1190. + 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
  1191. + 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D,
  1192. + 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
  1193. + 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950,
  1194. + 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
  1195. + 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7,
  1196. + 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
  1197. + 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA,
  1198. + 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
  1199. + 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81,
  1200. + 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
  1201. + 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84,
  1202. + 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
  1203. + 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB,
  1204. + 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
  1205. + 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E,
  1206. + 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
  1207. + 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55,
  1208. + 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
  1209. + 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28,
  1210. + 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
  1211. + 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F,
  1212. + 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
  1213. + 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242,
  1214. + 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
  1215. + 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69,
  1216. + 0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
  1217. + 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC,
  1218. + 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
  1219. + 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693,
  1220. + 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
  1221. + 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D };
  1222. +
  1223. +
  1224. +static inline void CRC32_update_buf(uint32_t * const crc,
  1225. + const uint8_t * const buffer,
  1226. + const long size)
  1227. +{
  1228. + long i;
  1229. + uint32_t c = *crc;
  1230. +
  1231. + for (i = 0; i < size; ++i)
  1232. + c = crc32[(c^buffer[i])&0xFF] ^ (c >> 8);
  1233. + *crc = c;
  1234. +}
  1235. +
  1236. +
  1237. +STATIC_RW_DATA const uint8_t lzip_magic[4] = { 0x4C, 0x5A, 0x49, 0x50 }; /* "LZIP" */
  1238. +
  1239. +typedef uint8_t Lzip_header[6]; /* 0-3 magic bytes */
  1240. + /* 4 version */
  1241. + /* 5 coded_dict_size */
  1242. +enum { Lh_size = 6 };
  1243. +
  1244. +static inline bool Lh_verify_magic(const Lzip_header data)
  1245. +{
  1246. + int i;
  1247. +
  1248. + for (i = 0; i < 4; ++i)
  1249. + if (data[i] != lzip_magic[i])
  1250. + return false;
  1251. + return true;
  1252. +}
  1253. +
  1254. +/* detect (truncated) header */
  1255. +static inline bool Lh_verify_prefix(const Lzip_header data, const int sz)
  1256. +{
  1257. + int i;
  1258. + for (i = 0; i < sz && i < 4; ++i)
  1259. + if (data[i] != lzip_magic[i])
  1260. + return false;
  1261. + return (sz > 0);
  1262. +}
  1263. +
  1264. +/* detect corrupt header */
  1265. +static inline bool Lh_verify_corrupt(const Lzip_header data)
  1266. +{
  1267. + int matches = 0;
  1268. + int i;
  1269. + for (i = 0; i < 4; ++i)
  1270. + if (data[i] == lzip_magic[i])
  1271. + ++matches;
  1272. + return (matches > 1 && matches < 4);
  1273. +}
  1274. +
  1275. +static inline bool Lh_verify_version(const Lzip_header data)
  1276. +{
  1277. + return (data[4] == 1);
  1278. +}
  1279. +
  1280. +static inline unsigned Lh_get_dictionary_size(const Lzip_header data)
  1281. +{
  1282. + unsigned sz = (1 << (data[5] & 0x1F));
  1283. +
  1284. + if (sz > min_dictionary_size)
  1285. + sz -= (sz / 16) * ((data[5] >> 5) & 7);
  1286. + return sz;
  1287. +}
  1288. +
  1289. +
  1290. +typedef uint8_t Lzip_trailer[20];
  1291. + /* 0-3 CRC32 of the uncompressed data */
  1292. + /* 4-11 size of the uncompressed data */
  1293. + /* 12-19 member size including header and trailer */
  1294. +enum { Lt_size = 20 };
  1295. +
  1296. +static inline unsigned Lt_get_data_crc(const Lzip_trailer data)
  1297. +{
  1298. + unsigned tmp = 0;
  1299. + int i;
  1300. +
  1301. + for (i = 3; i >= 0; --i) {
  1302. + tmp <<= 8;
  1303. + tmp += data[i];
  1304. + }
  1305. + return tmp;
  1306. +}
  1307. +
  1308. +static inline unsigned long long Lt_get_data_size(const Lzip_trailer data)
  1309. +{
  1310. + unsigned long long tmp = 0;
  1311. + int i;
  1312. +
  1313. + for (i = 11; i >= 4; --i) {
  1314. + tmp <<= 8;
  1315. + tmp += data[i];
  1316. + }
  1317. + return tmp;
  1318. +}
  1319. +
  1320. +static inline unsigned long long Lt_get_member_size(const Lzip_trailer data)
  1321. +{
  1322. + unsigned long long tmp = 0;
  1323. + int i;
  1324. +
  1325. + for (i = 19; i >= 12; --i) {
  1326. + tmp <<= 8;
  1327. + tmp += data[i];
  1328. + }
  1329. + return tmp;
  1330. +}
  1331. +
  1332. +
  1333. +struct Range_decoder {
  1334. + unsigned long long partial_member_pos;
  1335. + uint8_t *buffer; /* input buffer */
  1336. + long buffer_size;
  1337. + long pos; /* current pos in buffer */
  1338. + long stream_pos; /* when reached, a new block must be read */
  1339. + uint32_t code;
  1340. + uint32_t range;
  1341. + long (*fill)(void*, unsigned long);
  1342. + bool at_stream_end;
  1343. + bool buffer_given;
  1344. +};
  1345. +
  1346. +
  1347. +static bool Rd_read_block(struct Range_decoder * const rdec)
  1348. +{
  1349. + if (!rdec->at_stream_end) {
  1350. + rdec->stream_pos = rdec->fill ?
  1351. + rdec->fill(rdec->buffer, rdec->buffer_size) : 0;
  1352. + rdec->at_stream_end = (rdec->stream_pos < rdec->buffer_size);
  1353. + rdec->partial_member_pos += rdec->pos;
  1354. + rdec->pos = 0;
  1355. + }
  1356. + return rdec->pos < rdec->stream_pos;
  1357. +}
  1358. +
  1359. +
  1360. +static inline bool Rd_init(struct Range_decoder * const rdec,
  1361. + uint8_t * const inbuf, const long in_len,
  1362. + long (*fill)(void*, unsigned long))
  1363. +{
  1364. + rdec->partial_member_pos = 0;
  1365. + rdec->buffer_given = (inbuf && in_len > 0);
  1366. + rdec->buffer_size = rdec->buffer_given ? in_len : 16384;
  1367. + rdec->buffer = rdec->buffer_given ? inbuf : malloc(rdec->buffer_size);
  1368. + if (!rdec->buffer)
  1369. + return false;
  1370. + rdec->pos = 0;
  1371. + rdec->stream_pos = rdec->buffer_given ? in_len : 0;
  1372. + rdec->code = 0;
  1373. + rdec->range = 0xFFFFFFFFU;
  1374. + rdec->fill = fill;
  1375. + rdec->at_stream_end = false;
  1376. + return true;
  1377. +}
  1378. +
  1379. +static inline void Rd_free(struct Range_decoder * const rdec)
  1380. +{
  1381. + if (!rdec->buffer_given)
  1382. + free(rdec->buffer);
  1383. +}
  1384. +
  1385. +static inline bool Rd_finished(struct Range_decoder * const rdec)
  1386. +{
  1387. + return rdec->pos >= rdec->stream_pos && !Rd_read_block(rdec);
  1388. +}
  1389. +
  1390. +static inline unsigned long long
  1391. +Rd_member_position(const struct Range_decoder * const rdec)
  1392. +{
  1393. + return rdec->partial_member_pos + rdec->pos;
  1394. +}
  1395. +
  1396. +static inline void Rd_reset_member_position(struct Range_decoder * const rdec)
  1397. +{
  1398. + rdec->partial_member_pos = 0; rdec->partial_member_pos -= rdec->pos;
  1399. +}
  1400. +
  1401. +static inline uint8_t Rd_get_byte(struct Range_decoder * const rdec)
  1402. +{
  1403. + /* 0xFF avoids decoder error if member is truncated at EOS marker */
  1404. + if (Rd_finished(rdec))
  1405. + return 0xFF;
  1406. + return rdec->buffer[rdec->pos++];
  1407. +}
  1408. +
  1409. +static inline void Rd_load(struct Range_decoder * const rdec)
  1410. +{
  1411. + int i;
  1412. +
  1413. + rdec->code = 0;
  1414. + for (i = 0; i < 5; ++i)
  1415. + rdec->code = (rdec->code << 8) | Rd_get_byte(rdec);
  1416. + rdec->range = 0xFFFFFFFFU;
  1417. +}
  1418. +
  1419. +static inline void Rd_normalize(struct Range_decoder * const rdec)
  1420. +{
  1421. + if (rdec->range <= 0x00FFFFFFU) {
  1422. + rdec->range <<= 8;
  1423. + rdec->code = (rdec->code << 8) | Rd_get_byte(rdec);
  1424. + }
  1425. +}
  1426. +
  1427. +static inline unsigned Rd_decode(struct Range_decoder * const rdec,
  1428. + const int num_bits)
  1429. +{
  1430. + unsigned symbol = 0;
  1431. + int i;
  1432. +
  1433. + for (i = num_bits; i > 0; --i) {
  1434. + bool bit;
  1435. +
  1436. + Rd_normalize(rdec);
  1437. + rdec->range >>= 1;
  1438. + /* symbol <<= 1; */
  1439. + /* if(rdec->code >= rdec->range) { rdec->code -= rdec->range; symbol |= 1; } */
  1440. + bit = (rdec->code >= rdec->range);
  1441. + symbol = (symbol << 1) + bit;
  1442. + rdec->code -= rdec->range & (0U - bit);
  1443. + }
  1444. + return symbol;
  1445. +}
  1446. +
  1447. +static inline unsigned Rd_decode_bit(struct Range_decoder * const rdec,
  1448. + Bit_model * const probability)
  1449. +{
  1450. + uint32_t bound;
  1451. +
  1452. + Rd_normalize(rdec);
  1453. + bound = (rdec->range >> bit_model_total_bits) * *probability;
  1454. + if (rdec->code < bound) {
  1455. + rdec->range = bound;
  1456. + *probability += (bit_model_total - *probability) >> bit_model_move_bits;
  1457. + return 0;
  1458. + } else {
  1459. + rdec->range -= bound;
  1460. + rdec->code -= bound;
  1461. + *probability -= *probability >> bit_model_move_bits;
  1462. + return 1;
  1463. + }
  1464. +}
  1465. +
  1466. +static inline unsigned Rd_decode_tree3(struct Range_decoder * const rdec,
  1467. + Bit_model bm[])
  1468. +{
  1469. + unsigned symbol = 1;
  1470. +
  1471. + symbol = (symbol << 1) | Rd_decode_bit(rdec, &bm[symbol]);
  1472. + symbol = (symbol << 1) | Rd_decode_bit(rdec, &bm[symbol]);
  1473. + symbol = (symbol << 1) | Rd_decode_bit(rdec, &bm[symbol]);
  1474. + return symbol & 7;
  1475. +}
  1476. +
  1477. +static inline unsigned Rd_decode_tree6(struct Range_decoder * const rdec,
  1478. + Bit_model bm[])
  1479. +{
  1480. + unsigned symbol = 1;
  1481. +
  1482. + symbol = (symbol << 1) | Rd_decode_bit(rdec, &bm[symbol]);
  1483. + symbol = (symbol << 1) | Rd_decode_bit(rdec, &bm[symbol]);
  1484. + symbol = (symbol << 1) | Rd_decode_bit(rdec, &bm[symbol]);
  1485. + symbol = (symbol << 1) | Rd_decode_bit(rdec, &bm[symbol]);
  1486. + symbol = (symbol << 1) | Rd_decode_bit(rdec, &bm[symbol]);
  1487. + symbol = (symbol << 1) | Rd_decode_bit(rdec, &bm[symbol]);
  1488. + return symbol & 0x3F;
  1489. +}
  1490. +
  1491. +static inline unsigned Rd_decode_tree8(struct Range_decoder * const rdec,
  1492. + Bit_model bm[])
  1493. +{
  1494. + unsigned symbol = 1;
  1495. + int i;
  1496. +
  1497. + for (i = 0; i < 8; ++i)
  1498. + symbol = (symbol << 1) | Rd_decode_bit(rdec, &bm[symbol]);
  1499. + return symbol & 0xFF;
  1500. +}
  1501. +
  1502. +static inline unsigned
  1503. +Rd_decode_tree_reversed(struct Range_decoder * const rdec,
  1504. + Bit_model bm[], const int num_bits)
  1505. +{
  1506. + unsigned model = 1;
  1507. + unsigned symbol = 0;
  1508. + int i;
  1509. +
  1510. + for (i = 0; i < num_bits; ++i) {
  1511. + const unsigned bit = Rd_decode_bit(rdec, &bm[model]);
  1512. +
  1513. + model = (model << 1) + bit;
  1514. + symbol |= (bit << i);
  1515. + }
  1516. + return symbol;
  1517. +}
  1518. +
  1519. +static inline unsigned
  1520. +Rd_decode_tree_reversed4(struct Range_decoder * const rdec, Bit_model bm[])
  1521. +{
  1522. + unsigned symbol = Rd_decode_bit(rdec, &bm[1]);
  1523. + unsigned model = 2 + symbol;
  1524. + unsigned bit = Rd_decode_bit(rdec, &bm[model]);
  1525. +
  1526. + model = (model << 1) + bit; symbol |= (bit << 1);
  1527. + bit = Rd_decode_bit(rdec, &bm[model]);
  1528. + model = (model << 1) + bit; symbol |= (bit << 2);
  1529. + symbol |= (Rd_decode_bit(rdec, &bm[model]) << 3);
  1530. + return symbol;
  1531. +}
  1532. +
  1533. +static inline unsigned Rd_decode_matched(struct Range_decoder * const rdec,
  1534. + Bit_model bm[], unsigned match_byte)
  1535. +{
  1536. + unsigned symbol = 1;
  1537. + unsigned mask = 0x100;
  1538. +
  1539. + while (true) {
  1540. + const unsigned match_bit = (match_byte <<= 1) & mask;
  1541. + const unsigned bit = Rd_decode_bit(rdec, &bm[symbol+match_bit+mask]);
  1542. +
  1543. + symbol = (symbol << 1) + bit;
  1544. + if (symbol > 0xFF)
  1545. + return symbol & 0xFF;
  1546. + mask &= ~(match_bit ^ (bit << 8)); /* if( match_bit != bit ) mask = 0; */
  1547. + }
  1548. +}
  1549. +
  1550. +static inline unsigned Rd_decode_len(struct Range_decoder * const rdec,
  1551. + struct Len_model * const lm,
  1552. + const int pos_state)
  1553. +{
  1554. + if (Rd_decode_bit(rdec, &lm->choice1) == 0)
  1555. + return Rd_decode_tree3(rdec, lm->bm_low[pos_state]);
  1556. + if (Rd_decode_bit(rdec, &lm->choice2) == 0)
  1557. + return len_low_symbols +
  1558. + Rd_decode_tree3(rdec, lm->bm_mid[pos_state]);
  1559. + return len_low_symbols + len_mid_symbols +
  1560. + Rd_decode_tree8(rdec, lm->bm_high);
  1561. +}
  1562. +
  1563. +
  1564. +struct LZ_decoder {
  1565. + unsigned long long partial_data_pos;
  1566. + struct Range_decoder *rdec;
  1567. + /* Don't move bm_* to LZd_decode_member; makes frame too large. */
  1568. + Bit_model bm_literal[1 << literal_context_bits][0x300];
  1569. + Bit_model bm_match[states][pos_states];
  1570. + Bit_model bm_rep[states];
  1571. + Bit_model bm_rep0[states];
  1572. + Bit_model bm_rep1[states];
  1573. + Bit_model bm_rep2[states];
  1574. + Bit_model bm_len[states][pos_states];
  1575. + Bit_model bm_dis_slot[len_states][1 << dis_slot_bits];
  1576. + Bit_model bm_dis[modeled_distances-end_dis_model+1];
  1577. + Bit_model bm_align[dis_align_size];
  1578. + struct Len_model match_len_model;
  1579. + struct Len_model rep_len_model;
  1580. +
  1581. + unsigned long buffer_size;
  1582. + unsigned dictionary_size;
  1583. + uint8_t *buffer; /* output buffer */
  1584. + unsigned long pos; /* current pos in buffer */
  1585. + unsigned long stream_pos; /* first byte not yet written to file */
  1586. + uint32_t crc;
  1587. + long (*flush)(void*, unsigned long);
  1588. + bool pos_wrapped;
  1589. + bool buffer_given;
  1590. + bool write_error;
  1591. +};
  1592. +
  1593. +static void LZd_flush_data(struct LZ_decoder * const d)
  1594. +{
  1595. + if (d->pos > d->stream_pos) {
  1596. + const long size = d->pos - d->stream_pos;
  1597. +
  1598. + CRC32_update_buf(&d->crc, d->buffer + d->stream_pos, size);
  1599. + if ((d->flush &&
  1600. + d->flush(d->buffer + d->stream_pos, size) != size) ||
  1601. + (!d->flush && d->pos_wrapped))
  1602. + d->write_error = true;
  1603. + if (d->pos >= d->buffer_size) {
  1604. + d->partial_data_pos += d->pos;
  1605. + d->pos = 0;
  1606. + d->pos_wrapped = true;
  1607. + }
  1608. + d->stream_pos = d->pos;
  1609. + }
  1610. +}
  1611. +
  1612. +static inline uint8_t LZd_peek_prev(const struct LZ_decoder * const d)
  1613. +{
  1614. + if (d->pos > 0)
  1615. + return d->buffer[d->pos-1];
  1616. + if (d->pos_wrapped)
  1617. + return d->buffer[d->buffer_size-1];
  1618. + return 0; /* prev_byte of first byte */
  1619. +}
  1620. +
  1621. +static inline uint8_t LZd_peek(const struct LZ_decoder * const d,
  1622. + const unsigned distance)
  1623. +{
  1624. + const unsigned long i = ((d->pos > distance) ? 0 : d->buffer_size) +
  1625. + d->pos - distance - 1;
  1626. + return d->buffer[i];
  1627. +}
  1628. +
  1629. +static inline void LZd_put_byte(struct LZ_decoder * const d, const uint8_t b)
  1630. +{
  1631. + d->buffer[d->pos] = b;
  1632. + if (++d->pos >= d->buffer_size)
  1633. + LZd_flush_data(d);
  1634. +}
  1635. +
  1636. +static inline void LZd_copy_block(struct LZ_decoder * const d,
  1637. + const unsigned distance, unsigned len)
  1638. +{
  1639. + unsigned long lpos = d->pos, i = lpos - distance - 1;
  1640. + bool fast, fast2;
  1641. +
  1642. + if (lpos > distance) {
  1643. + fast = (len < d->buffer_size - lpos);
  1644. + fast2 = (fast && len <= lpos - i);
  1645. + } else {
  1646. + i += d->buffer_size;
  1647. + fast = (len < d->buffer_size - i); /* (i == pos) may happen */
  1648. + fast2 = (fast && len <= i - lpos);
  1649. + }
  1650. + if (fast) { /* no wrap */
  1651. + d->pos += len;
  1652. + if (fast2) /* no wrap, no overlap */
  1653. + memcpy(d->buffer + lpos, d->buffer + i, len);
  1654. + else
  1655. + for (; len > 0; --len)
  1656. + d->buffer[lpos++] = d->buffer[i++];
  1657. + } else
  1658. + for (; len > 0; --len) {
  1659. + d->buffer[d->pos] = d->buffer[i];
  1660. + if (++d->pos >= d->buffer_size)
  1661. + LZd_flush_data(d);
  1662. + if (++i >= d->buffer_size)
  1663. + i = 0;
  1664. + }
  1665. +}
  1666. +
  1667. +static inline bool LZd_init(struct LZ_decoder * const d,
  1668. + struct Range_decoder * const rde,
  1669. + const unsigned dict_size, uint8_t * const outbuf,
  1670. + long out_size, long (*flush)(void*, unsigned long))
  1671. +{
  1672. + d->partial_data_pos = 0;
  1673. + d->rdec = rde;
  1674. + Bm_array_init(d->bm_literal[0], (1 << literal_context_bits) * 0x300);
  1675. + Bm_array_init(d->bm_match[0], states * pos_states);
  1676. + Bm_array_init(d->bm_rep, states);
  1677. + Bm_array_init(d->bm_rep0, states);
  1678. + Bm_array_init(d->bm_rep1, states);
  1679. + Bm_array_init(d->bm_rep2, states);
  1680. + Bm_array_init(d->bm_len[0], states * pos_states);
  1681. + Bm_array_init(d->bm_dis_slot[0], len_states * (1 << dis_slot_bits));
  1682. + Bm_array_init(d->bm_dis, modeled_distances - end_dis_model + 1);
  1683. + Bm_array_init(d->bm_align, dis_align_size);
  1684. + Lm_init(&d->match_len_model);
  1685. + Lm_init(&d->rep_len_model);
  1686. +
  1687. + d->buffer_given = (outbuf && out_size > 0);
  1688. + d->buffer_size = d->buffer_given ? out_size : dict_size;
  1689. + d->dictionary_size = min_t(unsigned long, d->buffer_size, dict_size);
  1690. + d->buffer = d->buffer_given ? outbuf : large_malloc(d->buffer_size);
  1691. + if (!d->buffer)
  1692. + return false;
  1693. + d->pos = 0;
  1694. + d->stream_pos = 0;
  1695. + d->crc = 0xFFFFFFFFU;
  1696. + d->flush = flush;
  1697. + d->pos_wrapped = false;
  1698. + d->write_error = false;
  1699. + /* prev_byte of first byte; also for LZd_peek( 0 ) on corrupt file */
  1700. + if (!d->buffer_given) /* inbuf and outbuf may overlap */
  1701. + d->buffer[d->buffer_size-1] = 0;
  1702. + return true;
  1703. +}
  1704. +
  1705. +static inline void LZd_free(struct LZ_decoder * const d)
  1706. +{
  1707. + if (!d->buffer_given)
  1708. + large_free(d->buffer);
  1709. +}
  1710. +
  1711. +static inline unsigned LZd_crc(const struct LZ_decoder * const d)
  1712. +{
  1713. + return d->crc ^ 0xFFFFFFFFU;
  1714. +}
  1715. +
  1716. +static inline unsigned long long
  1717. +LZd_data_position(const struct LZ_decoder * const d)
  1718. +{
  1719. + return d->partial_data_pos + d->pos;
  1720. +}
  1721. +
  1722. +
  1723. +static bool LZd_verify_trailer(struct LZ_decoder * const d)
  1724. +{
  1725. + Lzip_trailer trailer;
  1726. + int i = 0;
  1727. +
  1728. + while (i < Lt_size)
  1729. + trailer[i++] = Rd_get_byte(d->rdec);
  1730. +
  1731. + return (Lt_get_data_crc(trailer) == LZd_crc(d) &&
  1732. + Lt_get_data_size(trailer) == LZd_data_position(d) &&
  1733. + Lt_get_member_size(trailer) == Rd_member_position(d->rdec));
  1734. +}
  1735. +
  1736. +
  1737. +/* Return value: 0 = OK, < 0 = error (see <linux/lzip.h>). */
  1738. +static int LZd_decode_member(struct LZ_decoder * const d)
  1739. +{
  1740. + struct Range_decoder * const rdec = d->rdec;
  1741. + unsigned rep0 = 0; /* rep[0-3] latest four distances */
  1742. + unsigned rep1 = 0; /* used for efficient coding of */
  1743. + unsigned rep2 = 0; /* repeated distances */
  1744. + unsigned rep3 = 0;
  1745. + State state = 0;
  1746. +
  1747. + Rd_load(rdec);
  1748. + while (!Rd_finished(rdec)) {
  1749. + int len;
  1750. + const int pos_state = LZd_data_position(d) & pos_state_mask;
  1751. +
  1752. + if (Rd_decode_bit(rdec, &d->bm_match[state][pos_state]) == 0) {
  1753. + /* literal byte */
  1754. + Bit_model * const bm = d->bm_literal[get_lit_state(LZd_peek_prev(d))];
  1755. +
  1756. + if (St_is_char(state)) {
  1757. + state -= (state < 4) ? state : 3;
  1758. + LZd_put_byte(d, Rd_decode_tree8(rdec, bm));
  1759. + } else {
  1760. + state -= (state < 10) ? 3 : 6;
  1761. + LZd_put_byte(d, Rd_decode_matched(rdec, bm, LZd_peek(d, rep0)));
  1762. + }
  1763. + continue;
  1764. + }
  1765. + /* match or repeated match */
  1766. + if (Rd_decode_bit(rdec, &d->bm_rep[state]) != 0) {
  1767. + if (Rd_decode_bit(rdec, &d->bm_rep0[state]) == 0) {
  1768. + if (Rd_decode_bit(rdec, &d->bm_len[state][pos_state]) == 0) {
  1769. + state = St_set_short_rep(state);
  1770. + LZd_put_byte(d, LZd_peek(d, rep0));
  1771. + continue;
  1772. + }
  1773. + } else {
  1774. + unsigned distance;
  1775. +
  1776. + if (Rd_decode_bit(rdec, &d->bm_rep1[state]) == 0)
  1777. + distance = rep1;
  1778. + else {
  1779. + if (Rd_decode_bit(rdec, &d->bm_rep2[state]) == 0)
  1780. + distance = rep2;
  1781. + else {
  1782. + distance = rep3;
  1783. + rep3 = rep2;
  1784. + }
  1785. + rep2 = rep1;
  1786. + }
  1787. + rep1 = rep0;
  1788. + rep0 = distance;
  1789. + }
  1790. + state = St_set_rep(state);
  1791. + len = min_match_len + Rd_decode_len(rdec, &d->rep_len_model, pos_state);
  1792. + } else { /* match */
  1793. + unsigned distance;
  1794. +
  1795. + len = min_match_len + Rd_decode_len(rdec, &d->match_len_model, pos_state);
  1796. + distance = Rd_decode_tree6(rdec, d->bm_dis_slot[get_len_state(len)]);
  1797. + if (distance >= start_dis_model) {
  1798. + const unsigned dis_slot = distance;
  1799. + const int direct_bits = (dis_slot >> 1) - 1;
  1800. +
  1801. + distance = (2 | (dis_slot & 1)) << direct_bits;
  1802. + if (dis_slot < end_dis_model)
  1803. + distance += Rd_decode_tree_reversed(rdec,
  1804. + d->bm_dis + (distance - dis_slot), direct_bits);
  1805. + else {
  1806. + distance +=
  1807. + Rd_decode(rdec, direct_bits - dis_align_bits) << dis_align_bits;
  1808. + distance += Rd_decode_tree_reversed4(rdec, d->bm_align);
  1809. + if (distance == 0xFFFFFFFFU) { /* marker found */
  1810. + Rd_normalize(rdec);
  1811. + LZd_flush_data(d);
  1812. + if (d->write_error)
  1813. + return LZIP_WRITE_ERROR;
  1814. + if (len == min_match_len) { /* End Of Stream marker */
  1815. + if (LZd_verify_trailer(d))
  1816. + return 0;
  1817. + else
  1818. + return LZIP_BAD_CRC;
  1819. + }
  1820. + if (len == min_match_len + 1) { /* Sync Flush marker */
  1821. + Rd_load(rdec);
  1822. + continue;
  1823. + }
  1824. + return LZIP_BAD_DATA; /* unknown marker */
  1825. + }
  1826. + }
  1827. + }
  1828. + rep3 = rep2; rep2 = rep1; rep1 = rep0; rep0 = distance;
  1829. + state = St_set_match(state);
  1830. + if (rep0 >= d->dictionary_size ||
  1831. + (rep0 >= d->pos && !d->pos_wrapped)) {
  1832. + LZd_flush_data(d);
  1833. + return LZIP_BAD_DATA;
  1834. + }
  1835. + }
  1836. + LZd_copy_block(d, rep0, len);
  1837. + }
  1838. + LZd_flush_data(d);
  1839. + return LZIP_DATA_EOF;
  1840. +}
  1841. +
  1842. +
  1843. +int lzip_decompress(unsigned char *inbuf, long in_len,
  1844. + long (*fill)(void*, unsigned long),
  1845. + long (*flush)(void*, unsigned long),
  1846. + unsigned char *outbuf, long out_size,
  1847. + long *in_posp, long *out_posp)
  1848. +{
  1849. + unsigned char *outptr = outbuf;
  1850. + struct Range_decoder rdec;
  1851. + struct LZ_decoder *decoder = 0;
  1852. + int retval = 0;
  1853. + bool first_member;
  1854. +
  1855. + if (in_posp)
  1856. + *in_posp = 0;
  1857. + if (out_posp)
  1858. + *out_posp = 0;
  1859. +
  1860. + if (!Rd_init(&rdec, inbuf, in_len, fill))
  1861. + return LZIP_OOM_INBUF;
  1862. +
  1863. + for (first_member = true;; first_member = false) {
  1864. + long data_pos;
  1865. + int size;
  1866. + unsigned dictionary_size;
  1867. + Lzip_header header;
  1868. +
  1869. + Rd_reset_member_position(&rdec);
  1870. + for (size = 0; size < Lh_size && !Rd_finished(&rdec); ++size)
  1871. + header[size] = Rd_get_byte(&rdec);
  1872. + if (Rd_finished(&rdec)) { /* End Of File */
  1873. + if (first_member)
  1874. + retval = LZIP_HEADER1_EOF;
  1875. + else if (Lh_verify_prefix(header, size))
  1876. + retval = LZIP_HEADER2_EOF;
  1877. + break;
  1878. + }
  1879. + if (!Lh_verify_magic(header)) {
  1880. + if (first_member)
  1881. + retval = LZIP_BAD_MAGIC1;
  1882. + else if (Lh_verify_corrupt(header))
  1883. + retval = LZIP_BAD_MAGIC2;
  1884. + break;
  1885. + }
  1886. + if (!Lh_verify_version(header)) {
  1887. + retval = LZIP_BAD_VERSION;
  1888. + break;
  1889. + }
  1890. + dictionary_size = Lh_get_dictionary_size(header);
  1891. + if (dictionary_size < min_dictionary_size ||
  1892. + dictionary_size > max_dictionary_size) {
  1893. + retval = LZIP_BAD_DICT_SIZE;
  1894. + break;
  1895. + }
  1896. +
  1897. + if (!decoder)
  1898. + decoder = malloc(sizeof *decoder);
  1899. + if (!decoder || !LZd_init(decoder, &rdec, dictionary_size,
  1900. + outptr, out_size, flush)) {
  1901. + retval = LZIP_OOM_OUTBUF;
  1902. + break;
  1903. + }
  1904. + retval = LZd_decode_member(decoder);
  1905. + if (in_posp)
  1906. + *in_posp += Rd_member_position(&rdec);
  1907. + data_pos = LZd_data_position(decoder);
  1908. + if (outptr)
  1909. + outptr += data_pos;
  1910. + if (out_posp)
  1911. + *out_posp += data_pos;
  1912. + if (out_size > 0)
  1913. + out_size -= data_pos;
  1914. + LZd_free(decoder);
  1915. + if (retval != 0)
  1916. + break;
  1917. + }
  1918. + if (decoder)
  1919. + free(decoder);
  1920. + Rd_free(&rdec);
  1921. + return retval;
  1922. +}
  1923. +
  1924. +EXPORT_SYMBOL_GPL(lzip_decompress);
  1925. +MODULE_DESCRIPTION("LZIP Decompressor");
  1926. +MODULE_AUTHOR("Antonio Diaz Diaz <antonio@gnu.org>");
  1927. +MODULE_LICENSE("GPL");
  1928. diff -urdN linux-4.18.1/scripts/Makefile.lib linux-4.18.1.new/scripts/Makefile.lib
  1929. --- linux-4.18.1/scripts/Makefile.lib 2018-08-15 17:37:34.000000000 +0200
  1930. +++ linux-4.18.1.new/scripts/Makefile.lib 2018-08-16 18:56:17.000000000 +0200
  1931. @@ -320,6 +320,21 @@
  1932. bzip2 -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
  1933. (rm -f $@ ; false)
  1934. +# Lzip
  1935. +# ---------------------------------------------------------------------------
  1936. +# The .lz format has the uncompressed size available at the end of the
  1937. +# file, but at offset (member_size - 16). So we append a gzip-style size.
  1938. +# Use klzip to compress the kernel image and lzip to compress other things.
  1939. +
  1940. +quiet_cmd_klzip = LZIP $@
  1941. +cmd_klzip = (cat $(filter-out FORCE,$^) | \
  1942. + lzip -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
  1943. + (rm -f $@ ; false)
  1944. +
  1945. +quiet_cmd_lzip = LZIP $@
  1946. +cmd_lzip = (cat $(filter-out FORCE,$^) | lzip -9) > $@ || \
  1947. + (rm -f $@ ; false)
  1948. +
  1949. # Lzma
  1950. # ---------------------------------------------------------------------------
  1951. diff -urdN linux-4.18.1/scripts/extract-ikconfig linux-4.18.1.new/scripts/extract-ikconfig
  1952. --- linux-4.18.1/scripts/extract-ikconfig 2018-08-15 17:37:34.000000000 +0200
  1953. +++ linux-4.18.1.new/scripts/extract-ikconfig 2018-08-16 18:56:17.000000000 +0200
  1954. @@ -59,6 +59,7 @@
  1955. try_decompress '\037\213\010' xy gunzip
  1956. try_decompress '\3757zXZ\000' abcde unxz
  1957. try_decompress 'BZh' xy bunzip2
  1958. +try_decompress 'LZIP' xyz 'lzip -d'
  1959. try_decompress '\135\0\0\0' xxx unlzma
  1960. try_decompress '\211\114\132' xy 'lzop -d'
  1961. try_decompress '\002\041\114\030' xyy 'lz4 -d -l'
  1962. diff -urdN linux-4.18.1/scripts/extract-vmlinux linux-4.18.1.new/scripts/extract-vmlinux
  1963. --- linux-4.18.1/scripts/extract-vmlinux 2018-08-15 17:37:34.000000000 +0200
  1964. +++ linux-4.18.1.new/scripts/extract-vmlinux 2018-08-16 18:56:17.000000000 +0200
  1965. @@ -55,6 +55,7 @@
  1966. try_decompress '\037\213\010' xy gunzip
  1967. try_decompress '\3757zXZ\000' abcde unxz
  1968. try_decompress 'BZh' xy bunzip2
  1969. +try_decompress 'LZIP' xyz 'lzip -d'
  1970. try_decompress '\135\0\0\0' xxx unlzma
  1971. try_decompress '\211\114\132' xy 'lzop -d'
  1972. try_decompress '\002!L\030' xxx 'lz4 -d'
  1973. diff -urdN linux-4.18.1/scripts/gen_initramfs_list.sh linux-4.18.1.new/scripts/gen_initramfs_list.sh
  1974. --- linux-4.18.1/scripts/gen_initramfs_list.sh 2018-08-15 17:37:34.000000000 +0200
  1975. +++ linux-4.18.1.new/scripts/gen_initramfs_list.sh 2018-08-16 18:56:17.000000000 +0200
  1976. @@ -249,6 +249,9 @@
  1977. echo "$output_file" | grep -q "\.bz2$" \
  1978. && [ -x "`which bzip2 2> /dev/null`" ] \
  1979. && compr="bzip2 -9 -f"
  1980. + echo "$output_file" | grep -q "\.lz$" \
  1981. + && [ -x "`which lzip 2> /dev/null`" ] \
  1982. + && compr="lzip -9 -f"
  1983. echo "$output_file" | grep -q "\.lzma$" \
  1984. && [ -x "`which lzma 2> /dev/null`" ] \
  1985. && compr="lzma -9 -f"
  1986. diff -urdN linux-4.18.1/scripts/package/Makefile linux-4.18.1.new/scripts/package/Makefile
  1987. --- linux-4.18.1/scripts/package/Makefile 2018-08-15 17:37:34.000000000 +0200
  1988. +++ linux-4.18.1.new/scripts/package/Makefile 2018-08-16 18:56:17.000000000 +0200
  1989. @@ -129,8 +129,9 @@
  1990. $(if $(findstring tar-src,$@),, \
  1991. $(if $(findstring bz2,$@),bzip2, \
  1992. $(if $(findstring gz,$@),gzip, \
  1993. +$(if $(findstring lz,$@),lzip, \
  1994. $(if $(findstring xz,$@),xz, \
  1995. -$(error unknown target $@)))) \
  1996. +$(error unknown target $@))))) \
  1997. -f -9 $(perf-tar).tar)
  1998. perf-%pkg: FORCE
  1999. @@ -147,8 +148,10 @@
  2000. @echo ' tar-pkg - Build the kernel as an uncompressed tarball'
  2001. @echo ' targz-pkg - Build the kernel as a gzip compressed tarball'
  2002. @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball'
  2003. + @echo ' tarlz-pkg - Build the kernel as a lzip compressed tarball'
  2004. @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball'
  2005. @echo ' perf-tar-src-pkg - Build $(perf-tar).tar source tarball'
  2006. @echo ' perf-targz-src-pkg - Build $(perf-tar).tar.gz source tarball'
  2007. @echo ' perf-tarbz2-src-pkg - Build $(perf-tar).tar.bz2 source tarball'
  2008. + @echo ' perf-tarlz-src-pkg - Build $(perf-tar).tar.lz source tarball'
  2009. @echo ' perf-tarxz-src-pkg - Build $(perf-tar).tar.xz source tarball'
  2010. diff -urdN linux-4.18.1/scripts/package/buildtar linux-4.18.1.new/scripts/package/buildtar
  2011. --- linux-4.18.1/scripts/package/buildtar 2018-08-15 17:37:34.000000000 +0200
  2012. +++ linux-4.18.1.new/scripts/package/buildtar 2018-08-16 18:56:17.000000000 +0200
  2013. @@ -35,6 +35,10 @@
  2014. opts=--bzip2
  2015. tarball=${tarball}.bz2
  2016. ;;
  2017. + tarlz-pkg)
  2018. + opts=--lzip
  2019. + tarball=${tarball}.lz
  2020. + ;;
  2021. tarxz-pkg)
  2022. opts=--xz
  2023. tarball=${tarball}.xz
  2024. diff -urdN linux-4.18.1/scripts/patch-kernel linux-4.18.1.new/scripts/patch-kernel
  2025. --- linux-4.18.1/scripts/patch-kernel 2018-08-15 17:37:34.000000000 +0200
  2026. +++ linux-4.18.1.new/scripts/patch-kernel 2018-08-16 18:56:17.000000000 +0200
  2027. @@ -117,6 +117,10 @@
  2028. ext=".bz2"
  2029. name="bzip2"
  2030. uncomp="bunzip2 -dc"
  2031. + elif [ -r ${filebase}.lz ]; then
  2032. + ext=".lz"
  2033. + name="lzip"
  2034. + uncomp="lzip -dc"
  2035. elif [ -r ${filebase}.xz ]; then
  2036. ext=".xz"
  2037. name="xz"
  2038. diff -urdN linux-4.18.1/tools/testing/selftests/gen_kselftest_tar.sh linux-4.18.1.new/tools/testing/selftests/gen_kselftest_tar.sh
  2039. --- linux-4.18.1/tools/testing/selftests/gen_kselftest_tar.sh 2018-08-15 17:37:34.000000000 +0200
  2040. +++ linux-4.18.1.new/tools/testing/selftests/gen_kselftest_tar.sh 2018-08-16 18:56:17.000000000 +0200
  2041. @@ -27,6 +27,10 @@
  2042. copts="cvjf"
  2043. ext=".tar.bz2"
  2044. ;;
  2045. + tarlz)
  2046. + copts="cv --lzip -f"
  2047. + ext=".tar.lz"
  2048. + ;;
  2049. tarxz)
  2050. copts="cvJf"
  2051. ext=".tar.xz"
  2052. diff -urdN linux-4.18.1/usr/.gitignore linux-4.18.1.new/usr/.gitignore
  2053. --- linux-4.18.1/usr/.gitignore 2018-08-15 17:37:34.000000000 +0200
  2054. +++ linux-4.18.1.new/usr/.gitignore 2018-08-16 18:56:17.000000000 +0200
  2055. @@ -5,6 +5,7 @@
  2056. initramfs_data.cpio
  2057. initramfs_data.cpio.gz
  2058. initramfs_data.cpio.bz2
  2059. +initramfs_data.cpio.lz
  2060. initramfs_data.cpio.lzma
  2061. initramfs_list
  2062. include
  2063. diff -urdN linux-4.18.1/usr/Kconfig linux-4.18.1.new/usr/Kconfig
  2064. --- linux-4.18.1/usr/Kconfig 2018-08-15 17:37:34.000000000 +0200
  2065. +++ linux-4.18.1.new/usr/Kconfig 2018-08-16 18:56:17.000000000 +0200
  2066. @@ -70,6 +70,15 @@
  2067. Support loading of a bzip2 encoded initial ramdisk or cpio buffer
  2068. If unsure, say N.
  2069. +config RD_LZIP
  2070. + bool "Support initial ramdisk/ramfs compressed using lzip"
  2071. + default y
  2072. + depends on BLK_DEV_INITRD
  2073. + select DECOMPRESS_LZIP
  2074. + help
  2075. + Support loading of a lzip encoded initial ramdisk or cpio buffer.
  2076. + If unsure, say N.
  2077. +
  2078. config RD_LZMA
  2079. bool "Support initial ramdisk/ramfs compressed using LZMA"
  2080. default y
  2081. @@ -165,6 +174,18 @@
  2082. If you choose this, keep in mind that you need to have the bzip2 tool
  2083. available to be able to compress the initram.
  2084. +config INITRAMFS_COMPRESSION_LZIP
  2085. + bool "Lzip"
  2086. + depends on RD_LZIP
  2087. + help
  2088. + Lzip's compression ratio is better than that of gzip and bzip2.
  2089. + Decompression speed is between gzip and bzip2. Compression can
  2090. + be as fast as gzip or slower than bzip2 depending on compression
  2091. + level. Lzip can produce a initramfs about a 16% smaller than gzip.
  2092. +
  2093. + If you choose this, keep in mind that you need to have the lzip tool
  2094. + available to be able to compress the initram.
  2095. +
  2096. config INITRAMFS_COMPRESSION_LZMA
  2097. bool "LZMA"
  2098. depends on RD_LZMA
  2099. @@ -222,12 +243,14 @@
  2100. default "" if INITRAMFS_COMPRESSION_NONE
  2101. default ".gz" if INITRAMFS_COMPRESSION_GZIP
  2102. default ".bz2" if INITRAMFS_COMPRESSION_BZIP2
  2103. + default ".lz" if INITRAMFS_COMPRESSION_LZIP
  2104. default ".lzma" if INITRAMFS_COMPRESSION_LZMA
  2105. default ".xz" if INITRAMFS_COMPRESSION_XZ
  2106. default ".lzo" if INITRAMFS_COMPRESSION_LZO
  2107. default ".lz4" if INITRAMFS_COMPRESSION_LZ4
  2108. default ".gz" if RD_GZIP
  2109. default ".lz4" if RD_LZ4
  2110. + default ".lz" if RD_LZIP
  2111. default ".lzo" if RD_LZO
  2112. default ".xz" if RD_XZ
  2113. default ".lzma" if RD_LZMA