新聞中心

EEPW首頁 > 設(shè)計應(yīng)用 > VxWorks壓縮技術(shù)

VxWorks壓縮技術(shù)

作者:嵌入式版版主 gem2000 時間:2004-07-22 來源: 收藏
本文詳述了縮小VxWorks文件尺寸的方法,當(dāng)開發(fā)進(jìn)入產(chǎn)品階段,很可能會需要這種技術(shù)。更多技術(shù)文章請瀏http://bbs.edw.com.cn

在嵌入式系統(tǒng)中,我們通常會要求VxWorks文件盡量小,比如通過串口、軟盤或tffs加載VxWorks的時候,如果文件太大,可能無法存儲,或加載失敗。下面介紹一種利用Tornado和VxWorks自帶的deflate和inflate,對VxWorks文件進(jìn)行壓縮和解壓縮的技術(shù)。希望對大家有所幫助。
1  使用Tornado創(chuàng)建bootable的project,包括應(yīng)用程序。對VxWorks進(jìn)行適當(dāng)?shù)牟脺p和配置。
2  如果準(zhǔn)備將VxWorks存儲于硬盤,軟盤或tffs上,應(yīng)該在usrAppInit中使用usrNetEndDevStart和usrNetIfConfig啟動網(wǎng)絡(luò)接口。如果存儲于tffs上,還要修改usrNetBoot.c中:
if ( (strncmp (sysBootParams.bootDev, "scsi", 4) == 0)
|| (strncmp (sysBootParams.bootDev, "ide", 3) == 0)
|| (strncmp (sysBootParams.bootDev, "ata", 3) == 0)
|| (strncmp (sysBootParams.bootDev, "fd", 2) == 0))
為:
if ( (strncmp (sysBootParams.bootDev, "scsi", 4) == 0)
|| (strncmp (sysBootParams.bootDev, "ide", 3) == 0)
|| (strncmp (sysBootParams.bootDev, "ata", 3) == 0)
|| (strncmp (sysBootParams.bootDev, "tffs", 4) == 0)
|| (strncmp (sysBootParams.bootDev, "fd", 2) == 0))
3  在dos下運行 tornado/host/x86-win32/bin/torvars。
4  進(jìn)入VxWorks所在的目錄,運行:
deflate VxWorks.z。這里我們默認(rèn).z文件是壓縮文件。
5  如果準(zhǔn)備將VxWorks.z存儲于硬盤,軟盤或tffs上,需要首先創(chuàng)建相應(yīng)的設(shè)備,并用dosFS初始化。如果是通過串口或網(wǎng)絡(luò)加載VxWorks.z,則需要初始化相應(yīng)的接口。
6  修改bootConfig.c文件:
a. 在LOCAL STATUS netLoad 函數(shù)的 tftpXfer和 ftpXfer這一部分代碼結(jié)束的地方添加:
if ( strstr(fileName,".z") || strstr(fileName,".Z") )
{       
printf("
file %s is compressed, now begin uncompressing...
",fileName);
if (bootLoadModuleInflate(fd, pEntry) != OK)
    goto readErr;
}
    else if (bootLoadModule (fd, pEntry) != OK)
goto readErr;
  b. 在 LOCAL STATUS tffsLoad 函數(shù)的 usrTffsConfig和open這一部分代碼結(jié)束的地方添加:
    if ( strstr(fileName,".z") || strstr(fileName,".Z") )
    {       
printf("
file %s is compressed, now begin uncompressing...
",fileName);
if (bootLoadModuleInflate(fd, pEntry) != OK)
    goto readErr;
    }
    else if (bootLoadModule (fd, pEntry) != OK)
goto readErr;
  c. 在 LOCAL STATUS bootLoad 函數(shù)之前定義函數(shù) 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. 如果加載不成功,應(yīng)讀懂上一段代碼,調(diào)整 RAM_HIGH_ADRS 和 RAM_LOW_ADRS的大小。
7  修改 config.h中的啟動參數(shù),比如啟動設(shè)備為tffs=0,0(0,0),文件名為/tffs0/VxWorks.z等等,重新制作bootrom,并寫入flash。
8  啟動時,修改啟動參數(shù),使系統(tǒng)仍然從網(wǎng)絡(luò)加載VxWorks,這個VxWorks中應(yīng)該實現(xiàn)了ftp或tftp功能。通過這些功能,把VxWorks.z文件寫入存儲介質(zhì)如tffs中。
9  重新啟動從tffs或硬盤,軟盤加載VxWorks,即可成功。
10 可以首先通過網(wǎng)絡(luò)啟動,把啟動文件名改為 VxWorks.z來進(jìn)行驗證壓縮和解壓縮。
11 以上只是考慮了從網(wǎng)絡(luò)和tffs來加載VxWorks.z壓縮文件,如果從fd, ata等加載,只需在相應(yīng)地方添加和6.a中相同的代碼即可。
12 本方法在ppc850上,利用tffs和網(wǎng)絡(luò)加載進(jìn)行了驗證,完全適用?!?(gem2000  researcher@263.net)


關(guān)鍵詞:

評論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉