uboot 解压缩

在uboot中进行解压缩是非常实用的

uboot中完毕delay 用户进行交互的段

if(BootType == '3') {

      char *argv[3];

      printf("   3: System Boot system code via Flash. ");

。。。

下面就是要进入kernel拷贝内容了

由于kernel的尺寸比較大   通常会达到3M以上   这样用串口或者网络都会比較耗费时间  也会浪费宝贵的内存

解决方法就是传输和保存都用压缩过的 应用的时候在进行解压

uboot中已经集成了集中经常使用的解压缩程序,一般常见的gzip  、 bzip 、  lzma  都已经存在。

我们仅仅须要调用就能够了,这里给出一个建立解压缩命令的方法。

建立新的命令在签名的博客已经写了 ,这里就直接引用结果了

#include <common.h>
#include <command.h>
    u32 ret_decomps;
#ifdef CONFIG_CMD_DECOMPRESS
do_compress(cmd_tbl_t *cmdtp,int flag,int argc,char *argv[])
{
    u32 destLen = 0,len;
    len = simple_strtoul(argv[1], NULL, 16);
    printf("decompress start");
    //lzmaBuffToBuffDecompress (unsigned char *outStream, SizeT *uncompressedSize, unsigned char *inStream,  SizeT  length)
    ret_decomps = lzmaBuffToBuffDecompress ((char *)0xa2000000, &destLen, (char *)0xa1000000,  len);
    printf("decompress finish");
    return 0;
}
U_BOOT_CMD(

decomps,5,1,do_compress,"decompress test ","decompress:addr "

);
#endif

这里明有一些调试的信息没除去,反正不影响结果。

插一点,开启debug打印的方法

在uboot中能够看到有非常多的debug信息打印      

debug ("LZMA: Image address............... 0x%lx ", inStream);
    debug ("LZMA: Properties address.......... 0x%lx ", inStream + LZMA_PROPERTIES_OFFSET);
    debug ("LZMA: Uncompressed size address... 0x%lx ", inStream + LZMA_SIZE_OFFSET);
    debug ("LZMA: Compressed data address..... 0x%lx ", inStream + LZMA_DATA_OFFSET);
    debug ("LZMA: Destination address......... 0x%lx ", outStream);

尽管自己也能够用print函数实现 , 可是不如直接打开省事的  。

能够在相应的.h文件里添加一个

#define DEBUG

这样上面那些打印就能够打印出来了

以下继续我们命令的部分

这俩要開始添加lzma编译连接在make中的设置,由于默认lzma是不编译链接的。方法就是主文件夹下的makefile中加

LIBS += lib/lzma/liblzma.a

这样就能够编译连接进去了

然后我们就能够调用解压缩的接口函数进行解压缩操作了


原文地址:https://www.cnblogs.com/jzssuanfa/p/6883878.html