
在項目中需要適配vxWorks,自己總結的遇到的問(wèn)題與解決方法,歡迎大家交流vxWorks使用心得。
Q:
如何在vxWorks bootrom添加devs命令?

A:
在usrconfig.c中的包含 bootFsLoadInit()
configAll.h 添加 兩個(gè)宏定義
/* Define for FS */#define BOOTAPP /* add by maketure at 20180509 */#define INCLUDE_DOSFS /* add by maketure at 20180509 */

Q:
在workbench中如何生成vxWorks的bootrom.bin文件?
A:
(方案1)在workbench中-->open development shell 進(jìn)入bsp目錄,輸入make bootrom.bin
(方案2)在workbench中,在工程右鍵選擇Builds Options-->set Active build Spec...-->選擇需要生成二進(jìn)制文件格式
Q:
ZYNQ芯片系列中SDK工具用來(lái)生成BOOT.bin的bootrom.elf 文件怎么通過(guò)workbench獲得?
A:
workbench生成的bootrom本身的格式就是elf,故只要重命名
Q:
在workbench中如何更新vxWorks library?
A:
(1)P2020相關(guān)系列
在workbench中-->open development shell 進(jìn)入對應的庫目錄,然后 make TOOL=e500v2diab CPU=PPC32
(2)ZYNQ系列
make CPU=ARMARCH7 TOOL=diab
make CPU=ARMARCH7 TOOL=diab VXBUILD=SMP
make CPU=ARMARCH7 TOOL=gnu
make CPU=ARMARCH7 TOOL=gnu VXBUILD=SMP
Q:
如何對vxwork的輸入輸出重定向,即printf輸出的對象?
A:
(1)ioTaskStdSet 任務(wù)級別重定向 ioGlobalStdSet全局的
void spyComTask(int freq,FUNCPTR printRtn){int delay = freq * sysClkRateGet ();int consoleFd = open ("/tffs1/output.txt", 2, 0); //把spy任務(wù)輸出重定向到 tffs里的output.txt文件ioTaskStdSet (0, STD_IN, consoleFd);ioTaskStdSet (0 ,STD_OUT, consoleFd);ioTaskStdSet (0, STD_ERR, consoleFd);void spyComTask ( int freq, FUNCPTR printRtn ) { int delay = freq * sysClkRateGet ();int consoleFd = open ("/tffs1/output.txt", 2, 0); //把spy任務(wù)輸出重定向到 tffs里的output.txt文件ioTaskStdSet (0, STD_IN, consoleFd);ioTaskStdSet (0 ,STD_OUT, consoleFd);ioTaskStdSet (0, STD_ERR, consoleFd);while (TRUE){spyReportCommon (printRtn);taskDelay (delay);}
consoleFd = NONE;
此consoleFd變量即標準輸入輸出句柄,此時(shí)為空。
同樣,可以找到如下的三行代碼:
ioGlobalStdSet (STD_IN, consoleFd);ioGlobalStdSet (STD_OUT, consoleFd);ioGlobalStdSet (STD_ERR, consoleFd);
/*打開(kāi)串口,輸入輸出重定向到超級終端*/
if((consoleFd=open("/tyCo/0",O_RDWR,0))==ERROR)logMsg("open /tyCo/0 error! \n",0,0,0,0,0,0);(void)ioctl(consoleFd,FIOBAUDRATE,9600);(void)ioctl(consoleFd,FIOSETOPTIONS,OPT_TERMINAL&~OPT_ECHO);(void)ioctl(consoleFd,FIOWFLUSH,0);(void)ioctl(consoleFd,FIORFLUSH,0);
(2)VxWorks中的重定向
(3) VxWorks5.5中的輸入輸出定向
在target\config\bspName\config.h文件中,可以找到如下定義:
#undef INCLUDE_PC_CONSOLE /* PC keyboard and VGA console */#ifdef INCLUDE_PC_CONSOLE# define PC_CONSOLE (0) /* console number */# define N_VIRTUAL_CONSOLES (2) /* shell / application */#endif /* INCLUDE_PC_CONSOLE *//* PS/2 101-key default keyboard type (use PC_XT_83_KBD for 83-key) */#define PC_KBD_TYPE (PC_PS2_101_KBD)
實(shí)際開(kāi)發(fā)中的應用
假如某Telnet打開(kāi)的socket為sock:
ioGlobalStdSet(STD_OUT,sock);ioGlobalStdSet(STD_IN,sock);ioGlobalStdSet(STD_ERR,sock);ipstatShow();ioGlobalStdSet(STD_OUT,consoleFd);ioGlobalStdSet(STD_IN,consoleFd);ioGlobalStdSet(STD_ERR,consoleFd);
Q:
vxBusShow 沒(méi)有命令時(shí),如何解決?
A:
添加組件 vxBus subsystem show routines
如果找到,二者結合成一個(gè)instance,否則在vxBusShow里可以看到一個(gè)orphan。使用vxBusShow可以比較清晰的看到driver列表和device列表以及orphan列表

Q:
如何通過(guò)命令行顯示驅動(dòng) 以及設備 (devs)、文件描述的情況?

Q:
vxWorks如何查看任務(wù)負載?
A:
getcpuusage命令
Q:
vxWorks查看與修改系統時(shí)間?
A:

Q:
VxWorks ifconfig 修改IP , MAC地址等?
A:
ifAddSet "motetsec0 192.168.5.100 up"ifMaskSet "motetsec0 255.255.255.0 up"ifConfig "motetsec0 192.168.5.100 up"ifConfig "motetsec0 lladdr 192.168.5.100 up"

Q:
vxWorks命令行 查看can收發(fā)狀況
A:

Q:
vxWorks查看串口收發(fā)情況
A:
uartShow
Q:
vxWorks FUNCPTR 與VOIDFUNCPTR 定義的位置?
A:
vxTypesOld.h e_vxTypesOld.hQ:
為啥將40wrsample.cdf copy to ${WIND_BASE}/target/config/comps/vxWorks directory然后workbench未出現可配置的界面?
A:
需要重啟下workbench
Q:
vxWorks怎么查看二進(jìn)制文件是否有某個(gè)符號表?
A:
nmpentium default/vxWorks | grep wrsampleRegisterQ:
VxWorks怎么在命令行中測試函數的執行時(shí)間?
A:
timexN delay,100Q:
vxWorks怎么獲取主機的IP地址?
A:
int bb(){char name[32];int ip = 0;char ipadd[15];char *p;struct in_addr iaddr;if (gethostname(name, 30) == ERROR) //This routine gets the target machine's symbolic name, which can be used for identification{fprintf(stderr, "Call gethostname failed!\n");return 0;}if ((ip = hostGetByName(name)) == ERROR)//這個(gè)數怎么變x.x.x.x 例如192.168.0.50{fprintf(stderr, "Call hostGetByName failed!\n");return 0;}iaddr.s_addr = ip;sprintf(ipadd,"%s",inet_ntoa(iaddr));p = inet_ntoa(iaddr);printf("%s\n%d\n %s\n",name,ip,ipadd);printf("%s\n",p);}
添加組件 vxBus subsystem show routines

gethostName 得到名稱(chēng)為target nameThis routine gets the target machine's symbolic name, which can be used for identification最后處理得到的ip為 inet on ethernet
Q:
windRiver workbench 如何編譯靜態(tài)庫?
1. 新建一個(gè)“Downloadable Kernel Module Project”工程;

2. 選擇對應的硬件環(huán)境,此處選擇“MIPSI64gnule_SMP”;

3. 選擇需要編譯生成的庫形式,Linker對應生成動(dòng)態(tài)庫.out,Librarian對應生成靜態(tài)庫.a;


4. 編譯成成對應庫文件(此處以靜態(tài)庫為例);

5. 新建一個(gè)image工程,點(diǎn)擊右鍵的properties,選擇build properties;

6. 點(diǎn)擊build properties,選擇build macros選項卡,該選項下有兩欄需特別注意,一個(gè)是EXTRA_MODULES,一個(gè)是LIBS,在image工程中我們要鏈接MODULE工程編譯生成的庫文件,需要添加在EXTRA_MODULES欄中,可以在其中鏈接諸如.o、 .a等文件。但是在LIBS中鏈接這類(lèi)a文件,會(huì )編譯報錯,至于為何報錯,以及這兩者有啥區別,有待日后研究……

A:
New Wind River Workbench Project --->類(lèi)型為static Kernel Library ,不能選擇vxwork6.x project 否則看不到static Kernel Library 類(lèi)型引用為 編譯類(lèi)型需要在工程創(chuàng )建后更改


image:

Q:
如何在vxwork使用腳本(鏡像和腳本同一級目錄,且需要定制shell startup script組件)?
A:
啟動(dòng)參數中的腳本優(yōu)先于usrAppinit執行.若需要在usrAppInit里面執行,則需要收到調用
usrStartupScript("/tffs0/start_opensca")函數使用?
啟動(dòng)目標機,在bootrom引導vxworks時(shí),指定startup script參數,如:
boot device : cpmunit number : 0processor number : 0host name : chenqifile name : vxWorksinet on ethernet (e) : 192.168.0.200host inet (h) : 192.168.0.118user (u) : targetftp password (pw) : targetflags (f) : 0x0target name (tn) : 850pcstartup script (s) : myscript.txt如果一切正常,vxworks啟動(dòng)完畢之后,會(huì )有:Executing startup script myscript.txt ...printf("hello ")hello出現下面情況ipAttach(0, "motetsec")C interp: unknown symbol name 'ipAttach'需要添加Attach END to IPv4
Q:
如何通過(guò)網(wǎng)絡(luò )設備名獲取mac地址?
A:
STATUS get_mac(char* ifName,int ifUnit){END_OBJ *pEnd;UINT8 *pData = NULL;int i =0;STATUS rval =0;pData = (UINT8 *)malloc(MAC_ADRS_LEN);pEnd = endFindByName(ifName,ifUnit);if(pEnd == NULL){perror("pEnd is null \n");return ERROR;}rval = muxIoctl(pEnd,EIOCGADDR,pData);for(i=0;i < MAC_ADRS_LEN;i++){printf("%02x:",*(pData+i));}return rval;}
Q:
vxWork如何命令行中創(chuàng )建nor flash文件設備?
A:
step one: tffsDevFormat(0,0)---normal step two: usrTffsConfig(0,0,"/tffs0")usrTffsConfig (1, 0, "/tffs1");-> cd "/tffs0"cd: error = 0x16.·value = -1 = 0xffffffffset three:dosfsDiskFormat("/tffs0")
Q:
ipAttach 接口作用以及如何加入組件?
A:
主要是建立ip協(xié)議棧與mux接口之間的關(guān)系?

Q:
怎么修改vxWorks編譯固定庫文件?
A:
The makefile provides a mechanism that allows you to use the local copy insteadof the common version. The following macros designate a private copy of therelated files:For example, to use a private version of usrConfig.c, set the macro USRCONFIG tousrConfig.c in Makefile as follows:USRCONFIG = usrConfig.c
Q:
vxWorks target.reg使用什么標記語(yǔ)言?
A:
target.ref uses the apigen markup language

Q:
VxWorks outConsole 可以用于早期打印調試
A:

Q:
vxworks 預處理分析
A:
When building a VxWorks image, many compile-time macros are expanded, andit is sometimes difficult to know what the actual numeric values of these macrosare and which branch of conditionally compiled code is being used. The bootromcode, in particular, contains many conditional compilations. One way to find thisinformation is to retrieve the post-processed compiler output.To retrieve the post-processor output for a given object module, use the followingcommand:make ADDED_CFLAGS=-E file.o > file.iNext, remove all of the lines starting with # and all blank lines
Q:
vxWorks 怎么判斷一個(gè)任務(wù)是否存在,以及怎么根據任務(wù)名稱(chēng)過(guò)去ID,以及A任務(wù)如何等待任務(wù)B的結束?
A:
示例為根據等待任務(wù)名為"taskIde"結束
if(taskIdVerify(taskNameToId("taskIde")) != ERROR){taskWait(taskNameToId("taskIde"),sysClkRateGet()*2);}
Q:
workbench怎么在工程文本中加入路徑等
A:
*.mk_USER_CFLAGS = -I $(BSP_DIR)/net/mii -I $(BSP_DIR)/appDrivers -I $(BSP_DIR)/lib_utils -I $(BSP_DIR)/SRIO -I $(BSP_DIR)/net -I $(BSP_DIR)/mv88e6xxx -I $(BSP_DIR)/net -I $(BSP_DIR)/net/linux_mv88e6xxx -I $(BSP_DIR)/net/gtLib.wpj<BEGIN> BUILD_default_MACRO__USER_CFLAGS-I \$(BSP_DIR)/net/mii \-I \$(BSP_DIR)/appDrivers \-I \$(BSP_DIR)/lib_utils \-I \$(BSP_DIR)/SRIO \-I \$(BSP_DIR)/net \-I \$(BSP_DIR)/mv88e6xxx \-I \$(BSP_DIR)/net \-I \$(BSP_DIR)/net/linux_mv88e6xxx \-I \$(BSP_DIR)/net/gtLib<END>
Q:
vxWorks 如何格式化EMMC設備?
A:

Q:
workbench 中如何更換 image project bsp?
A:


Q:
nfsmaxPath undefined sybmol
A:
關(guān)于出現找不到 nfsmaxPath符號表示因為,未定制nfs 客戶(hù)端與核心組件
IMPORT int nfsMaxPath; /* max. length of file path */Q:
vxWorks如何將RTC時(shí)間轉化成時(shí)間戳,然后寫(xiě)入系統時(shí)鐘?
A:
參考P2020將時(shí)鐘寫(xiě)進(jìn)系統時(shí)間中,注意vxWorks 中mktime函數存在問(wèn)題
Q:
vxWorks底層接收MAC數據?
A:


Q:
如何指定讓ping的數據包從哪個(gè)網(wǎng)口發(fā)送出去?
A:
windows: ping -s 192.168.5.84 192.168.5.81vxworks : ping "-S 192.168.5.82 192.168.5.84" (-I 可指定網(wǎng)口名)

Q:
vxWorks如何 去掉 讀秒
A:
修改啟動(dòng)參數
flags =0x8
Q:
內存分析需要添加的組建 Target 0x02b1cad0 for vector 714 out of range
A:
解決方案:
- In operating system components / kernel components / : you must include the component "Allow 32-bits branches to handlers"- In operating system components / real time process components / : you must include the component "shared data region support in RTPs or kernel"
Q:
vxWorks 常見(jiàn)的內存分配疑問(wèn)?
A:






Q:
vxWorks 怎么建立RAM/MEM文件系統
A:
ramDrv 需要添加組件ram disk driver 和xbd ram disk driver
在代碼自己添加內存文件系統
BLK_DEV * pBlkDev1;pBlkDev1 = ramDevCreate((char *) sysMemTop(), 512, 32768, 32768, 0);xbdBlkDevCreateSync(pBlkDev1, "/ram");dosFsVolFormat ("/ram:0", DOS_OPT_BLANK, NULL);BLK_DEV * pBlkDev2;pBlkDev2 = ramDevCreate((char *) (sysMemTop()+0x1000000), 512, 32768, 32768, 0);xbdBlkDevCreateSync(pBlkDev1, "/ram1");dosFsVolFormat ("/ram1:0", DOS_OPT_BLANK, NULL);
MEM文件系統:添加memLib 需要添加組件MEM disk driver
memDrv 即可flash也可內存,ramDrv只能用途內存

DOS_OPT_BLANK = 2
總結:


Q:
怎么獲取vxWorks系統的版本信息?
A:

如何在vxWorks bootrom添加devs命令?
Q:
Nandflash page / block相關(guān)的信息?
A:
NandFlash頁(yè)的概念 page: 一個(gè)page大小為2K + 64bytes, 如上圖所示,其中的64bytes是所在頁(yè)的infomation, 記錄著(zhù)此頁(yè)的使用情況,比如剩余存空間等.
block: 一個(gè)block由64個(gè)頁(yè)組成, 一個(gè)nandflash芯片由2k個(gè)block組成,算算就知道,一個(gè)nandflash芯片一共能存儲256M的數據.
Q:
驅動(dòng)關(guān)于調試打印控制的問(wèn)題?
A:



#ifdef MHAL_ETH_DEBUG_ON#define LOG_LVL 7#define WARN_LVL 3#define ERROR_LVL 1#define NONE_LVL 0LOCAL int mhalEthernetDgbLvl = NONE_LVL;#define MHAL_ETH_DBG_MSG(level, fmt, a1, a2, a3, a4, a5, a6) \do{ \if(mhalEthernetDgbLvl >= level) \logMsg(fmt,(int)(a1),(int)(a2),(int)(a3),\(int)(a4),(int)(a5),(int)(a6)); \}while ((0))#else#define MHAL_ETH_DBG_MSG(level,fmt,a1,a2,a3,a4,a5,a6)#endif /* MHAL_ETH_DEBUG_ON */vel,fmt,a1,a2,a3,a4,a5,a6)#endif /* MHAL_ETH_DEBUG_ON */
Q:
workbench中usrConfig.c 與 prjConfig.c之間的關(guān)系?
A:


Q:
有的vxWorks 鏡像為啥 通過(guò)FTP啟動(dòng)后,ls會(huì )出現 "cannot open (null)"?
A:

Q:
關(guān)于workbench編譯時(shí)為啥會(huì )出現找不到sysAmpCpuPrep的符號表?
當前原因是因為配置文件中包含了WRLoad組件,去掉即可。
A:


Q:
vxWork 若需要將用戶(hù)空間的地址與內核空間的地址分開(kāi),該怎么做?
A:
這部分和 RTP 組件以及虛擬化內存組件相關(guān)

Q:
vxWorks flag 參數配置
A:
flags (f)
一些標志位的集合,每個(gè)標志代表一個(gè)特殊的選項。這些標志定義如下:
0x01 = 即使processor number為0,也不要激活系統控制器。(這個(gè)其實(shí)是由使用的板子解釋的,所以應參考目標板子的資料)
0x02 = 載入所有VxWorks符號表,而不只是全局部分。
0x04 = 不要自動(dòng)引導
0x08 = 快速自動(dòng)引導,也就是自動(dòng)引導前等的時(shí)間短一些。
0x20 = 禁用安全登錄。
0x80 = 用TFTP(而不是FTP)來(lái)引導。
0x400 = 調試模式。
Q:
如何查看vxWorsk tffs文件系統的映射地址
A:

Q:
VxWorks 如何產(chǎn)生map文件?
A:

workbench怎么生成帶debug調試信息的bootrom
ADDED_CFLAGS += -g -O
如何判斷elf文件是否包含調試信息

Q:
vxWork 怎么鏈接靜態(tài)庫全部符號表到kernel image?
測試發(fā)現static kernel library 鏈接到kernel image 時(shí)只會(huì )鏈接使用到的函數文件
所以采用Relinkable kernel Module,其實(shí)就是DKM工程
A:

Q:
WRS_ASM("isync")的作用?
A:

關(guān)注本公眾號
掌握更多行業(yè)動(dòng)態(tài)
打開(kāi)公眾號名片點(diǎn)擊關(guān)注
聯(lián)系客服