eCos学习笔记(转自suncilang.21ic.org)

1、 编译一个 CC++ 应用程序

因为各个目标的编译选项各不相同,参考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/IP9000端口进行上面的操作,调入程序后超级终端需先断开连接,GDB才能使用串口与目标板连接;

 

3、 Memory Layout

eCos linker scriptldi文件)中,文件由两部分组成;

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.

 

4SECTIONS Command(GNUPro Development Tools / Using ld

 

5In 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.

 

7Set 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.

 

8The 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.

10All 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",否则编译无法通过;

 

6The 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           

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值