linux-4.14.40_lzip-3.diff 84 KB

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