linux内核压缩方式调研

kernel镜像格式

(1)vmlinux
vmlinuz是可引导的、可压缩的内核镜像,vm代表Virtual Memory。是由用户对内核源码编译得到,实质是elf格式的文件,内含符号表,可用于调试。
(2)Image
Image是经过objcopy处理的只包含二进制数据的内核代码,未经过压缩。
(3)zImage
zImage是ARM linux常用的一种压缩镜像文件,它是由vmlinux加上解压代码经gzip压缩而成,命令格式是#make zImage.这种格式的Linux镜像文件多存放在NAND上.
(4)bzImage
bz表示big zImage,其格式与zImage类似,但采用了不同的压缩算法,都是使用了gzip压缩成,bzImage的压缩率更高,适用于大内核。
(5)uImage
uImage是uboot专用的镜像文件,它是在zImage之前加上一个长度为0x40的头信息(tag),在头信息内说明了该镜像文件的类型、加载 位置、生成时间、大小等信息.换句话说,若直接从uImage的0x40位置开始执行,则zImage和uImage没有任何区别.命令格式是#make uImage.这种格式的Linux镜像文件多存放在NAND上。
u-boot 的tools 目录下有mkimage 工具,可以用来制作uImage,参照这里
(6)xipImage
这种格式的Linux镜像文件多存放在NorFlash上,且运行时不需要拷贝到内存SDRAM中,可以直接在NorFlash中运行.

linux 压缩模式 配置选项

在init/Kconfig中可以看到有如下关于压缩方式的选择,根据以下描述可以简略的知晓各种压缩算法的特点。对于这几种算法的详细测试可以参考这里

choice
        prompt "Kernel compression mode"
        default KERNEL_GZIP
        depends on HAVE_KERNEL_GZIP || HAVE_KERNEL_BZIP2 || HAVE_KERNEL_LZMA || HAVE_KERNEL_XZ || HAVE_KERNEL_LZO || HAVE_KERNEL_LZ4
        help

          The linux kernel is a kind of self-extracting executable.
          Several compression algorithms are available, which differ
          in efficiency, compression and decompression speed.
          Compression speed is only relevant when building a kernel.
          Decompression speed is relevant at each boot.

          If you have any problems with bzip2 or lzma compressed
          kernels, mail me (Alain Knaff) <alain@knaff.lu>. (An older
          version of this functionality (bzip2 only), for 2.4, was
          supplied by Christian Ludwig)

          High compression options are mostly useful for users, who
          are low on disk space (embedded systems), but for whom ram
          size matters less.

          If in doubt, select 'gzip'

config KERNEL_GZIP
        bool "Gzip"
        depends on HAVE_KERNEL_GZIP
        help
          The old and tried gzip compression. It provides a good balance
          between compression ratio and decompression speed.

config KERNEL_BZIP2
        bool "Bzip2"
        depends on HAVE_KERNEL_BZIP2
        help
          Its compression ratio and speed is intermediate.
          Decompression speed is slowest among the choices.  The kernel
                    size is about 10% smaller with bzip2, in comparison to gzip.
          Bzip2 uses a large amount of memory. For modern kernels you
          will need at least 8MB RAM or more for booting.

config KERNEL_LZMA
        bool "LZMA"
        depends on HAVE_KERNEL_LZMA
        help
          This compression algorithm's ratio is best.  Decompression speed
          is between gzip and bzip2.  Compression is slowest.
          The kernel size is about 33% smaller with LZMA in comparison to gzip.

config KERNEL_XZ
        bool "XZ"
        depends on HAVE_KERNEL_XZ
        help
          XZ uses the LZMA2 algorithm and instruction set specific
          BCJ filters which can improve compression ratio of executable
          code. The size of the kernel is about 30% smaller with XZ in
          comparison to gzip. On architectures for which there is a BCJ
          filter (i386, x86_64, ARM, IA-64, PowerPC, and SPARC), XZ
          will create a few percent smaller kernel than plain LZMA.

          The speed is about the same as with LZMA: The decompression
          speed of XZ is better than that of bzip2 but worse than gzip
          and LZO. Compression is slow.

config KERNEL_LZO
        bool "LZO"
        depends on HAVE_KERNEL_LZO
        help
          Its compression ratio is the poorest among the choices. The kernel
          size is about 10% bigger than gzip; however its speed
          (both compression and decompression) is the fastest.

config KERNEL_LZ4
        bool "LZ4"
        depends on HAVE_KERNEL_LZ4
        help
          LZ4 is an LZ77-type compressor with a fixed, byte-oriented encoding.
          A preliminary version of LZ4 de/compression tool is available at
          <https://code.google.com/p/lz4/>.

          Its compression ratio is worse than LZO. The size of the kernel
          is about 8% bigger than LZO. But the decompression speed is
          faster than LZO.

endchoice

内核压缩和解压缩代码在目录kernel/arch/arm/boot/compressed。该文档中貌似没有具体压缩算法的实现。
更多资料:
linux内核镜像格式

Quick Benchmark: Gzip vs Bzip2 vs LZMA vs XZ vs LZ4 vs LZO

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值