| elf1980 發表於 2005-10-15 16:08:00 |
原地址:http://blog.21ic.com/user1/1575/archives/2005/4090.html 1、 編譯一個 C、C++ 應用程式 因為各個目標的編譯選項各不相同,參考examples/Makefile檔案或“Global compiler flags” option (CYGBLD_GLOBAL_CFLAGS) 編寫 Makefile檔案; 2、 Debugging Techniques(調試技巧) A、Tracing; B、Kernel Instrumentation; Instrument buffers can be used to find out how many events of a given type happened in the kernel during execution of a program. 3、通過TFTP下載偵錯工具 a、 使用–g選項編譯產生ELF格式的目標檔案main; b、 將main加入到TFTP伺服器根目錄,啟動TFTP伺服器(WinAgents TFTP Service for Windows); c、 開啟超級終端通過串口與目標板串連; d、 目標板上電,目標板上運行帶有TFTP下載功能的Redboot; e、 超級終端中執行:load -h 192.168.1.10 main,將目標檔案main下載到目標板的指定地址; f、 斷開超級中斷串連; g、 啟動insight,調入目標檔案main,通過串口串連目標板:(gdb) target remote /dev/com1; h、 更改PC值為目標檔案下載後的首地址或Entry point值,斷行符號確認; i、 使用cont即可啟動程式運行; j、 若下載的是bin格式的目標檔案,則應使用:load -r -h 主機IP地址 -b 0x0c100000; k、 直接在超級終端中使用:go 0x0c100000運行程式; l、 因為ELF檔案中已經包含了地址資訊,所以下載時不需要指定-b參數,而下載目標檔案則是必須的; m、 超級終端也可以通過TCP/IP:9000連接埠進行上面的操作,調入程式後超級終端需先中斷連線,GDB才能使用串口與目標板串連; 3、 Memory Layout 在 eCos linker script(ldi檔案)中,檔案由兩部分組成; MEMORY { rom : ORIGIN = 0x40000000, LENGTH = 0x80000 ram : ORIGIN = 0x48000000, LENGTH = 0x200000 } MEMORY 塊包含每一個記憶體地區的ORIGIN(起始地址)和LENGTH(長度); SECTIONS { SECTIONS_BEGIN SECTION_rom_vectors (rom, 0x40000000, LMA_EQ_VMA) SECTION_text (rom, ALIGN (0x1), LMA_EQ_VMA) SECTION_fini (rom, ALIGN (0x1), LMA_EQ_VMA) SECTION_rodata (rom, ALIGN (0x1), LMA_EQ_VMA) SECTION_rodata1 (rom, ALIGN (0x1), LMA_EQ_VMA) SECTION_fixup (rom, ALIGN (0x1), LMA_EQ_VMA) SECTION_gcc_except_table (rom, ALIGN (0x1), LMA_EQ_VMA) SECTION_data (ram, 0x48000000, FOLLOWING (.gcc_except_table)) SECTION_bss (ram, ALIGN (0x4), LMA_EQ_VMA) SECTIONS_END } MEMORY塊後面緊跟的是SECTIONS塊,它包含了每一個連接器輸出段的排列描述;每個SECTIONS是通過一個宏調用來描述的; 這些宏的規則: 1、 section塊最後存放在哪個MEMORY地區; 2、 section的最後地址(VMA);利用下列表單之一進行表示: n 位於不帶正負號的整數n指定的絕對位址; ALIGN (n) 在之前section 的最後位置,用 n-byte邊界對其; 3、 section的起始地址(LMA);利用下列表單之一進行表示: LMA_EQ_VMA LMA等於VMA,不變換位置; AT (n) 位於不帶正負號的整數n指定的絕對位址; FOLLOWING (.name) 在section名字初始位置之後; Note that the names of the linker output sections will vary between target architectures. A description of these sections can be found in the specific GCC documentation for your architecture. 4、SECTIONS Command(GNUPro Development Tools / Using ld) 5、In a COFF file, all of the actual instructions reside in .text for setting up the constructor and destructor tables for the GNU C++ compiler. 6、.data section. A COFF file is where all of the initialized data goes. 7、Set up default values for _bss_start and _end variables by setting up the .bss section. The default values for _bss_start and _end are for use by the crt0 file when it zeros the .bss section. 8、The ARM family uses IEEE floating-point numbers. 9、 .code [ 16| 32] This directive selects the instruction set being generated. The value 16 selects Thumb, with the value 32 selecting ARM. .thumb This performs the same action as .code 16. .arm This performs the same action as .code 32. 10、All assembler directives have names that begin with a period (‘.’). The rest of the name is letters, usually in lower case. 11、 第三章 eCos Reference Manual 1、 線程進入點和C++ 當線程函數採用C++編寫時,線程的主函數必須是一個類的靜態成員函數或類外的一個普通函數。它不能是一個普通的類成員函數,因為這樣的成員函數有一個固有的額外的指標this,而核心沒有辦法知道哪個值是使用this指標。 一個解決this問題的方法是使用特別的靜態成員函數,例如: class fred { public: void thread_function(); static void static_thread_aux(cyg_addrword_t); }; void fred::static_thread_aux(cyg_addrword_t objptr) { fred* object = static_cast<fred*>(objptr); object->thread_function(); } static fred instance; extern "C" void cyg_start( void ) { … cyg_thread_create( …, &fred::static_thread_aux, static_cast<cyg_addrword_t>(&instance), …); … } 這裡強制使用entry_data參數給cyg_thread_create儲存this指標。不幸地是這種方法是需要耗費一些C++計算,因此某些安全地類型能夠存在完成當設計在C++ (Effectively this uses the entry_data argument to cyg_thread_create to hold the this pointer. Unfortunately this approach does require the use of some C++ casts, so some of the type safety that can be achieved when programming in C++ is lost.); 2、 Building the Network Stack Using the Build->Packages dialog, add the packages “Networking”, “Freebsd TCP/IP Stack” and “Common Ethernet Support” to your configuration. Their package names are CYGPKG_NET, CYGPKG_NET_FREEBSD_STACK and CYGPKG_NET_ETH_DRIVERS respectively. A short-cut way to do this is by using the “net” template if it is available for your platform. The platform-specific ethernet device driver for your platform will be added as part of the target selection (in the Build->Templates “Hardware” item), along with the PCI I/O subsystem (if relevent) and the appropriate serial device driver. For example, the PowerPC MBX target selection adds the package PKG_NET_QUICC_ETH_DRIVERS, and the Cirrus Logic EDB7xxx target selection adds the package CYGPKG_NET_EDB7XXX_ETH_DRIVERS. After this, eCos and its tests can be built exactly as usual. Note: By default, most of the network tests are not built. This is because some of them require manual intervention, i.e. they are to be run “by hand”, and are not suitable for automated testing. To build the full set of network tests, set the configuration option CYGPKG_NET_BUILD_TESTS “Build networking tests (demo programs)” within “Networking support build options”. 3、 We advise including network.h whether you use these features or not. 4、_KERNEL and __ECOS In general, using the networking code may require definition of two symbols: _KERNEL and __ECOS. _KERNEL is not normally required; __ECOS is normally required. So add this to your compile lines for files which use the network stack: -D__ECOS 5、當使用 OpenBSD包時,程式中不能引用"network.h",否則編譯無法通過; 6、The platform usually also specify an option controlling the ability to co-exist with a ROM monitor: cdl_option CYGSEM_HAL_USE_ROM_MONITOR { display "Work with a ROM monitor" flavor booldata legal_values { "Generic" "CygMon" "GDB_stubs" } default_value { CYG_HAL_STARTUP == "RAM" ? "CygMon" : 0 } parent |