以文本方式查看主題 - 曙海教育集團論壇 (http://www.hufushizhe.com/bbs/index.asp) -- VxWorks技術討論區 (http://www.hufushizhe.com/bbs/list.asp?boardid=11) ---- VxWorks壓縮技術 (http://www.hufushizhe.com/bbs/dispbbs.asp?boardid=11&id=1406) |
-- 作者:wangxinxin -- 發布時間:2010-11-17 9:53:10 -- VxWorks壓縮技術 在嵌入式系統中,我們通常會要求VxWorks文件盡量小,比如通過串口、軟盤或tffs加載VxWorks的時候,如果文件太大,可能無法存儲,或加載失敗。下面介紹一種利用Tornado和VxWorks自帶的deflate和inflate,對VxWorks文件進行壓縮和解壓縮的技術。希望對大家有所幫助。 1 使用Tornado創建bootable的project,包括應用程序。對VxWorks進行適當的裁減和配置。 2 如果準備將VxWorks存儲于硬盤,軟盤或tffs上,應該在usrAppInit中使用usrNetEndDevStart和usrNetIfConfig啟動網絡接口。如果存儲于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 進入VxWorks所在的目錄,運行: deflate 5 如果準備將VxWorks.z存儲于硬盤,軟盤或tffs上,需要首先創建相應的設備,并用dosFS初始化。如果是通過串口或網絡加載VxWorks.z,則需要初始化相應的接口。 6 修改bootConfig.c文件: a. 在LOCAL STATUS netLoad 函數的 tftpXfer和 ftpXfer這一部分代碼結束的地方添加: 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 函數的 usrTffsConfig和open這一部分代碼結束的地方添加: 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 函數之前定義函數 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。 8 啟動時,修改啟動參數,使系統仍然從網絡加載VxWorks,這個VxWorks中應該實現了ftp或tftp功能。通過這些功能,把VxWorks.z文件寫入存儲介質如tffs中。 9 重新啟動從tffs或硬盤,軟盤加載VxWorks,即可成功。 10 可以首先通過網絡啟動,把啟動文件名改為 VxWorks.z來進行驗證壓縮和解壓縮。 11 以上只是考慮了從網絡和tffs來加載VxWorks.z壓縮文件,如果從fd, ata等加載,只需在相應地方添加和6.a中相同的代碼即可。 12 本方法在ppc850上,利用tffs和網絡加載進行了驗證,完全適用 |