Linux 2.6添加lzma压缩支持

所需文件:8892172881e7b3940b07843209dcc7d974768cfed
说明:
a. squashfs3.4.tar.gz,squashfs文件包;
b. lzma457.tar.bz2,LZMA压缩解压算法库;
c. sqlzma3.4-457.tar.bz2,squashfs工具、kernel相关补丁(patch)和Makefile.

解压上面下载的3个文件包:
1) tar xvf squashfs3.4.tar.gz
2) tar xvf lzma457.tar.bz2 –C lzma457
3) tar xvf sqlzma3.4-457.tar.bz2

patch:
1)为lzma457库打patch
patch -p0 < sqlzma1-457.patch
2)为squashfs3.4工具打patch
patch -p0 < sqlzma2u-3.4.patch
3)为kernel打patch, 这里先patch linux 2.6.16
a.patch -p0 < squashfs3.4/kernel-patches/linux-2.6.16
b.cp sqlzma2k-3.4.patch sqlzma2k-3.4.patch-16
c.vi sqlzma2k-3.4.patch-16 ,然后:% s/ linux-2.6.27.4/ linux-2.6.16/g
(这是为了修改为linux-2.6.16版本)
d.patch –p0 < sqlzma2k-3.4.patch-16

4)改变squashfs3.4目录里的linux-2.6.16目录为链接文件
a.cd squashfs3.4/kernel-patches/
b.mv linux-2.6.16 linux-2.6.16-b
c.ln –sf /home/longjindong/squashfs/linux-2.6.16;cd –

5)改/home/longjindong/squashfs里的Makefile
vi Makefile #把第16行改成KVer = linux-2.6.16

6)把lzma相关文件copy到linux-2.6.16/fs/squashfs/下
cp -a sqlzma.h sqmagic.h ./lzma457/C/Compress/Lzma/{LzmaDecode.h,LzmaDecode.c,LzmaTypes.h,uncomp.c} linux-2.6.16/fs/squashfs/

如果不copy这此文件编译时会出现如下警告,并不能正常使用.
7)vi linux-2.6.16/fs/squashfs/Makefile #加上如下二行:
squashfs-y += uncomp.o
squashfs-y += LzmaDecode.o

8)把linux-2.6.16/fs/squashfs/inode.c中的static int __init init_squashfs_fs(void)函数里的kmalloc改成vmalloc, static void free_sqlzma(void) 函数里的kfree改成vfree.不然后会出如下警告并不能正常使用.

编译

1. ko及tools
make
完后,ko是: squashfs3.4/kernel-patches/linux-2.6.16/fs/squashfs/squashfs.ko
./lzma457/C/Compress/Lzma/kmod/sqlzma.ko
./lzma457/C/Compress/Lzma/kmod/unlzma.ko
Tools 是:
./squashfs3.4/squashfs-tools/unsquashfs
./squashfs3.4/squashfs-tools/mksquashfs
2. 让kernel从sqlzma分区起动系统
1) cd linux-2.6.16
2) make menuconfig
3) File systems —> Miscellaneous filesystems —> <*> SquashFS 3.4 – Squashed file system support
4) make
正常的话kenrel image就是arch/arm/boot/zImage

用mksquashfs 做文件系统
mksquashfs source1 source2 … dest -all-root –lzmadic 1024K