2011年3月31日 星期四

如何知道一個 .lib 是 debug 或是 release version

答案就在 



IMAGE_FILE_HEADER




You can check the Characteristics field of the IMAGE_FILE_HEADER structure of the file. If the library is a release build, then bit 0x0200 (DEBUG_STRIPPED) will be set; on a debug build, it will be clear.



IMAGE_FILE_DEBUG_STRIPPED




0x0200









所以使用 dumpbin /headers xxxx.lib




看最前面 IMAGE_FILE_HEADER




的  characteristics




假如 0x0200 這個bit 被設定的話 那就是 release




沒設的話是 debug 





dumpbin /headers xxxx.lib | more

看第一頁

Build lame mp3 encoder MIPS

Using lame 3.98-4

in compiling bitstream.c
Visual Studio 9.0\VC\INCLUDE\sys/stat.inl(55)
error C2466: cannot allocate an array of constant size 0

_STATIC_ASSERT( sizeof(struct stat) == sizeof(struct _stat64i32) );


_STATIC_ASSERT Macro

Evaluate an expression at compile time and generate an error when the result is FALSE.




define _USE_32BIT_TIME_T




再來會出現 link error
修改 makefile.msvc
MACHINE = /machine:WIN32 --> MIPS
LIB_OPTS = /nologo $(MACHINE)




再來build 到 frontend/parse.c (175)  
IDLE_PRIORITY_CLASS undefined 


WINCE 沒有 SetPriorityClass()
改寫一下就行了 (SetThreadPriority)

2011年3月30日 星期三

OpenCV

在找有關 cmake  ffmpeg 的時候 搜尋到 OpenCV
這個project 可能以後會用得到 (人臉辨識...)

OpenCV可用於解決如下領域的問題:

Build libavcodec ( for H.264 decoding )

為了想要 decoding h.264
找到了最合適的開源lib  libavcodec
libavcodec is used by famous ffmpeg


第一部  build WIN32 version

1. 先安裝 MinGW
2. 下載最新的 snapshot version ( recommended by ffmpeg website ) 並解開
下  ./configure
出現錯誤,應該是沒有 yasm
可以下 --disable-yasm

又出現錯誤 意思是沒有 aligned memory allocator 但是又要用 SSE
所以 請用
 ./configure --enable-memalign-hack

後來又出現 pkg-config error 是因為minGW 沒有pkg-config 嗎?

要安裝 pkg-config 好像又要花一番工夫
http://www.mingw.org/wiki/FAQ
How do I get pkg-config installed?
把pkg-config copy 到mingw \bin 下執行
會出現沒有libglib-2.0-0.dll 的訊息 
再下載 libglib-2.0-0.dll 執行之後 會出現沒有intl.dll 的訊息
intl.dll 在 gnu gettext 中,得到 gettext runtime 之後 copy intl.dll 到 mingw \bin下就行了

2011年3月17日 星期四

WINCE 7: Build BSP Problem mipsasm error D8016

Build Image 到一半出現錯誤並停止
是build 到 BSP Caches 和 stall 的部份
看 build.log
mipsasm : Command line error D8016 : '/QMmips32' and '/QMmips2' command-line options are incompatible

原因是由於 mipsasm try to build *.s
但是 nmake 給它的 option 中  /QMmips32 和 /QMmips2 衝突

從 build.log 中 可以看到 makefile.def including 很多的檔案
/QMmips32 是來自於 \WINCE700\platform\DB1200\sources.cmn
找到 在\WINCE700\public\COMMON\oak\misc 下的 makefile.def

看到以下code


!ELSEIF "$(_TGTCPUFAMILY)" == "MIPS"

ASSEMBLER=mipsasm -nologo
!  IF "$(_TGTCPUISA)" == "II"
C_ARCH_CMD_LINE=-QMmips2 -D_M_MRX000=4000
!  ELSEIF "$(_TGTCPUISA)" == "IV"
C_ARCH_CMD_LINE=-QMmips4
CDEFINES=-D_MIPS64 $(CDEFINES)
!  ELSEIF "$(_TGTCPUISA)" == "16"
CDEFINES=-DMIPS16SUPPORT $(CDEFINES)
!    IF "$(NOMIPS16CODE)" == "1"
C_ARCH_CMD_LINE=-QMmips2 -D_M_MRX000=4000
CDEFINES=-DNOMIPS16CODE $(CDEFINES)
!    ELSE
C_ARCH_CMD_LINE=-QMmips16 -D_M_MRX000=4000
!    ENDIF
LDEFINES=-merge:.text16=.text $(LDEFINES)
!  ENDIF
!  IF "$(WINCECOD)" != ""
AFLAGS=-Fa$(_OBJDIR)\ -FAsc $(AFLAGS)
!  ENDIF
!  IF "$(_TGTCPUOPTIONS)" == "_FP"
C_ARCH_CMD_LINE=$(C_ARCH_CMD_LINE) -QMFPE-
!  ELSE
C_ARCH_CMD_LINE=$(C_ARCH_CMD_LINE) -QMFPE
!  ENDIF
ASM_ARCH_CMD_LINE=$(C_ARCH_CMD_LINE)
AFLAGS=-c $(CINCLUDES) $(CDEFINES) $(AFLAGS) $(ADEFINES)

!ELSEIF "$(_TGTCPUFAMILY)" == "ARM"


上面就是根據你的 Platform 然後定義 C_ARCH_CMD_LINE 及 ASM_ARCH_CMD_LINE
也就是如果你的 _TGTCPUFAMILY為 MIPSII_FP
就會在 mipsasm 後面加上 -QMmips2 -D_M_MRX000=4000 -QMFPE-

所以是 sources.cmn 中的 /QMmips32 及 makefile.def 中的 MIPSII ( -QMmips2 )
衝到
但是兩個都沒有錯,那麼要如何解決才完美呢
在 makefile.def 中後面又找到了一段


# Use C_ARCH_FLAGS and A_ARCH_FLAGS to override the default architecture
# flags passed to the compiler and assembler, respectively.
!IF "$(C_ARCH_FLAGS)" != ""
C_ARCH_CMD_LINE=$(C_ARCH_FLAGS)
!ENDIF
!IF "$(A_ARCH_FLAGS)" != ""
ASM_ARCH_CMD_LINE=$(A_ARCH_FLAGS)
!ENDIF


也就是說 使用 C_ARCH_FLAGS 和 A_ARCH_FLAGS  override the default architecture
所以完美的解決方法就是在 sources.cmn 中指定
C_ARCH_FLAGS =/QMmips32 /QMFPE
A_ARCH_FLAGS = /QMmips32 /QMFPE 即可

再來繼續編譯後, 在 AES.c 發生錯誤
問題是在於 AES.c 中  有個函式宣告為 inline
而在 c 中,不能用 inline 而要改成 __inline
此問題就可解決了。

2011年3月11日 星期五

Windows 7 network connect to USB200 (XP or old network )

Windows Vista or Windows 7 預設的 LAN Manager authentication level 和XP不同
所以會有無法連線的情況

解決方法如下
In Windows 7

Control Panel\System and Security\Administrative Tools
執行 Local Security Policy
在 Local Policies --> Security Options 下

 Network Security: LAN Manager authentication level






Windows 7 default 值是 not defined
改成 Send LM & NTLM - use NTLMv2 session security if negotiated

WINCE 7

在安裝WinCE 7 ( Windows Embedded Compact 7 )時,我用了最小的安裝
只安裝MIPSII 而且也沒安裝 CTK (Compact Test Kit)

WINCE 7 的MIPS 有SMP865X BSP
讓我很感興趣,查了一下,此為 Sigma Designs 的配件
主要作為 NMD ( Network Media Device ) 用途

也找到下面一些資訊
http://social.technet.microsoft.com/wiki/contents/articles/ctk-testing-sigma-designs-smp865x.aspx

CTK是很重要的,要開始學習怎麼去用。

2011年3月10日 星期四

Standard SDK

 在用Plarform Builder创建Win CE工程时,在用New Platform Wizard向导为平台添加/删除组件的时,有一个“Standard SDK for Windows CE”。找个有什么用呢?以及Standard SDK for Windows CE和从pb导出的sdk软件包有什么不同?
         Standard SDK是微软用PB帮我们导出的一个SDK,里面包含了微软觉得可以作为“standard”的一些组件。以前的PB里面有一个组件叫standard sdk,选了这个组件之后,就会自动把standard sdk里面所包含的组件都关联进去了。
       一般来说,如果开发你自己的程序的时候standard sdk够用,那就直接用standard sdk就可以了。省的装pb了。但是standard sdk有很多缺陷,例如不支持中文,不支持DX等等。如果遇到standard sdk不支持的功能,那就只能自己从pb里面导出了。



When included in a display-based platform, the standard SDK automatically incorporates all associated features into that platform. The following list shows the features that compose the standard SDK:

2011年3月9日 星期三

RegOpenKeyEx failed with 5 (ACCESS_DENIED )

在Windows 下的RegOpenKeyEx 要指定 KEY_READ or KEY_WRITE flag, 不能指定為 0
否則會回傳 5 (ACCESS_DENIED)
在WINCE下此flag 為 0

2011年3月8日 星期二

2011年3月4日 星期五

USB Deep Trace Down

在做有關 burning 的問題的時候,發現速度並不夠快。
於是深入追蹤 在usbdrv.cpp 中發現在 GetInterface() 的上面有一段詳細說明


 *        The USB (OHCI) hardware assumes a host page size of 4K bytes.  Under Windows CE, many
 *        supported processors do not necessarily follow this assumption (1K page size is common).
 *        The issue here is that the underlying hardware can use scatter/gather DMA, but
 *        can handle at most 1 page transition per transfer.  However, client buffers on systems
 *        with smaller page sizes may be scattered across several physically disjoint pages.
 *
 *        In order to make this restriction transparent to client drivers, OHCD.DLL allocates
 *        a buffer from the system which is known to be contiguous within 4K sections.
 *        Then, DMA is done to the private buffers, and copied to the client buffer
 *        once the transfer is complete.  For some client drivers, this extra copy may
 *        impose an unacceptable performance hit, however.  So, the Windows CE transfer functions
 *        allow the client to pass in an optional physical memory address which is used directly
 *        for the DMA to/from the HC hardware.  Because the HC accesses this buffer directly,
 *        the following two restrictions must be rigidly adhered to:
 *
 *        1) Physical buffer must be contiguous within 4K segments.   How the client allocates
 *           this memory is beyond the scope of this document (e.g. may be through a platform
 *           specific call). The LockPages() call can be used to get physical page information.
 *
 *        2) Client must not access or free the buffer before the transfer has completed.

意思就是說 USB Transfer 的時候,OHCD (or EHCD) 會 allocate 一個private的 4K buffer.
給 DMA 用,然後DMA完成時,再用memcpy 到 client buffer。
但是這會帶來 performance 的衝擊。


也就是 LPISSUE_BULK_TRANSFER (7個參數)  的最後一個參數 Physical Address 假如不為
NULL, Host Controller 會直接 DMA到這個 Physical Address.


以bot transfer 為例
BOT_DataTransfer (usbmsc.c)   ....BulkTransfer::SendAnotherTransfer  --> lpIssueBulkTransfer
http://support.microsoft.com/kb/937755/en-us
上面文章有用
三種加速的方法,Disable Cache, PacketsPerTransfer 0x80, IntThresCtrl = 1

[HKEY_LOCAL_MACHINE\Drivers\USB\ClientDrivers\Mass_Storage_Class] 
"DisableBuffering"=0 時會用 DMA   =1 時 不用DMA(也就是不指定Physical address)


但是 = 0 時用DMA 也是另外 AllocPhysMem (in BulkTransfer::BulkTransfer() ) 然後再 memcpy ( 2個 in BulkTrans.cpp )


所以要真正加速而減少 memcpy 的話,必須要rewrite usbmsc bot部份


FILE_FLAG_WRITE_THROUGH & FILE_FLAG_NO_BUFFERING 沒用
http://support.microsoft.com/kb/99794/en-us

最後結果
能提昇USB速度有用的是 IntThresCtrl = 1
在Au1200 BSP中 修改registry 並沒有用
it is hard wired in Platform\DB1200\Drivers\USB20\EHCI\CHW.CPP
in CHW::EnterOperationalState()
set usbcmd.bit.IntThreshCtrl = 1 // original 8 microframe

EnableCache=0 + PacketsPerTransfer=80 in common.reg also improve