linux-4.19.8_lzip-0.diff 65 KB

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