VxWorks壓縮技術(shù)
在嵌入式系統(tǒng)中,我們通常會(huì)要求VxWorks文件盡量小,比如通過(guò)串口、軟盤或tffs加載VxWorks的時(shí)候,如果文件太大,可能無(wú)法存儲(chǔ),或加載失敗。下面介紹一種利用Tornado和VxWorks自帶的deflate和inflate,對(duì)VxWorks文件進(jìn)行壓縮和解壓縮的技術(shù)。希望對(duì)大家有所幫助。
1 使用Tornado創(chuàng)建bootable的project,包括應(yīng)用程序。對(duì)VxWorks進(jìn)行適當(dāng)?shù)牟脺p和配置。
2 如果準(zhǔn)備將VxWorks存儲(chǔ)于硬盤,軟盤或tffs上,應(yīng)該在usrAppInit中使用usrNetEndDevStart和usrNetIfConfig啟動(dòng)網(wǎng)絡(luò)接口。如果存儲(chǔ)于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下運(yùn)行 tornado/host/x86-win32/bin/torvars。
4 進(jìn)入VxWorks所在的目錄,運(yùn)行:
deflate
5 如果準(zhǔn)備將VxWorks.z存儲(chǔ)于硬盤,軟盤或tffs上,需要首先創(chuàng)建相應(yīng)的設(shè)備,并用dosFS初始化。如果是通過(guò)串口或網(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中的啟動(dòng)參數(shù),比如啟動(dòng)設(shè)備為tffs=0,0(0,0),文件名為/tffs0/VxWorks.z等等,重新制作bootrom,并寫入flash。
8 啟動(dòng)時(shí),修改啟動(dòng)參數(shù),使系統(tǒng)仍然從網(wǎng)絡(luò)加載VxWorks,這個(gè)VxWorks中應(yīng)該實(shí)現(xiàn)了ftp或tftp功能。通過(guò)這些功能,把VxWorks.z文件寫入存儲(chǔ)介質(zhì)如tffs中。
9 重新啟動(dòng)從tffs或硬盤,軟盤加載VxWorks,即可成功。
10 可以首先通過(guò)網(wǎng)絡(luò)啟動(dòng),把啟動(dòng)文件名改為 VxWorks.z來(lái)進(jìn)行驗(yàn)證壓縮和解壓縮。
11 以上只是考慮了從網(wǎng)絡(luò)和tffs來(lái)加載VxWorks.z壓縮文件,如果從fd, ata等加載,只需在相應(yīng)地方添加和6.a中相同的代碼即可。
12 本方法在ppc850上,利用tffs和網(wǎng)絡(luò)加載進(jìn)行了驗(yàn)證,完全適用?!?(gem2000 researcher@263.net)
評(píng)論