Board logo

标题: VxWorks压缩技术 02 [打印本页]

作者: samwalton    时间: 2014-3-26 15:20     标题: VxWorks压缩技术 02

c. 在 LOCAL STATUS bootLoad 函数之前定义函
数 bootLoadModuleInflate的原型:
#define DECOMP_BUF_SIZE  (RAM_HIGH_ADRS - RAM_LOW_ADRS)
#define COMP_BUF_SIZE  (DECOMP_BUF_SIZE / 3)
STATUS bootLoadModuleInflate(int zfd, FUNCPTR *pEntry)
{
    char *imageBuf = NULL;
    char *compBuf = NULL;
    int  fd = -1;
    int  rv = ERROR;
    int  compSize, r;
    extern STATUS inflate(char *src, char *dst, int src_size);
    if ((compBuf = malloc(COMP_BUF_SIZE)) == NULL)
    {
  printErr("No enough memory for image buffer
");
  goto done;
    }
    compSize = 0;
    while ((r = read(zfd, compBuf + compSize, COMP_BUF_SIZE - compSize)) > 0)
  compSize += r;
    if (r < 0)
    {
  printErr("Read failed: errno = %d
", errnoGet());
  goto done;
    }
    if (compSize == COMP_BUF_SIZE)
    {
  printErr("Compressed image too large
");
  goto done;
    }
    printErr("Uncompressing %d bytes... ", compSize);
    if ((imageBuf = malloc(DECOMP_BUF_SIZE)) == NULL)
    {
  printErr("Not enough memory for decompression buffer
");
  goto done;
    }
    if ((r = inflate(compBuf, imageBuf, compSize)) < 0)
    {
  printErr("
Uncompress failed
");
  goto done;
    }
    printErr("
Loading image... ");
    memDrv();
    memDevCreate("mem:", imageBuf, DECOMP_BUF_SIZE);
    if ((fd = open("mem:0", O_RDONLY, 0)) < 0)
    {
  printErr("
Cannot open memory device.
");
  goto done;
    }
    if (bootLoadModule(fd, pEntry) != OK)
    {
  printErr("
Error loading: errno = %d
", errnoGet());
  goto done;
    }
    printErr("
");
    rv = OK;
  done:
    if (fd >= 0)
  close(fd);
    if (imageBuf)
  free(imageBuf);
    if (compBuf)
  free(compBuf);
    return rv;
}
d. 如果加载不成功,应读懂上一段代码,调整 RAM_HIGH_ADRS 和 RAM_LOW_ADRS的大小。
7  修改 config.h中的启动参数,比如启动设备为tffs=0,0(0,0),文件名为/tffs0/VxWorks.z等等,重新制作bootrom,并写入flash。




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0