网站公告列表

  没有公告

加入收藏
设为首页
联系站长
您现在的位置: 61EDA中国电子网 >> 技术文库 >> NIOSII >> 正文
  Nios中uclinux的CompileHello           ★★★ 【字体:
Nios中uclinux的CompileHello
作者:61EDA    文章来源:本站原创    点击数:    更新时间:2008-2-5    

CompileHello

 

Version 7, changed by hippo5329@yahoo.com.tw. 01/15/2007.   Show version history

 

11. To compile a simple program, just add -elf2flt to link flag

 

Create a file, hello.c

 

i nclude <stdio.h>

int main(void)

{

printf("hello world\n");

}

 

nios2-linux-uclibc-gcc hello.c -o hello -elf2flt

 

The compiled object format is FLAT.

You may check it with,

 

nios2-linux-uclibc-flthdr hello

 

hello

Magic: bFLT

Rev: 4

Build Date: Mon Jun 5 21:49:44 2006

Entry: 0x40

Data Start: 0x4a8c

Data End: 0x5c48

BSS End: 0x7ca8

Stack Size: 0x1000

Reloc Start: 0x5c48

Reloc Count: 0x11e

Flags: 0x1 ( Load-to-Ram )

 

Then copy hello to the rootfs's bin dir. Rebuild the kernel image for initramfs.

cp hello ~/uClinux-dist-test/romfs/bin

cd ~/uClinux-dist-test

make linux image

 

Boot nios2 uClinux, and run

hello

 

The default stack size of application is 4KB, you can change it with -elf2flt="-s <new stack size>" option, eg ,

nios2-linux-uclibc-gcc hello.c -o hello -elf2flt="-s 16000"

will have stack size as 16KiB.

 

The default include dir search path is /opt/nios2/include or staging_dir/include .

The default library search path is /opt/nios2/lib or staging_dir/lib .

The default apps library is uClibc's libc, so you don't need -lc .

If you use math, you need -lm .

If you use pthread, you need -lpthread .

If you use crypt, you need -lcrypt .

 

You will need those include headers, too.

The order of librarys is important, the linker will search only one pass by default.

 

example apps to use button pio.

 

Add hello as an user apps to uClinux-dist

 

Follow uClinux-dist/Documentation/Adding-User-Apps-HOWTO .

 

add a line to user/Makefile , dir_$(CONFIG_USER_HELLO_HELLO) += hello

add a line to misc section of config/config.in, bool 'hello' CONFIG_USER_HELLO_HELLO

mkdir ~/uClinux-dist/user/hello

put hello.c in user/hello dir,

create Makefile in user/hello dir,

EXEC = hello

 

OBJS = hello.o

 

all: $(EXEC)

 

$(EXEC): $(OBJS)

$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)

 

romfs:

$(ROMFSINST) /bin/$(EXEC)

 

clean:

-rm -f $(EXEC) *.elf *.gdb *.o

文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
    基于FPGA 的多用途提升小波变…
    FPGA构建高性能DSP
    可编程器件在以太网集线器中…
    嵌入式大屏幕LED显示屏的设计…
    mcu,DSP,PLD/EDA的介绍/比较…
    FPGA 与ASIC对比…
    JPEG2000中嵌入式块编码的FP…
    基于FPGA的多路声呐信号采集…
    基于FPGA的智能控制器设计及…
    选择最佳的高速FPGA收发器解…
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    湘ICP备08001332号 站长:61EDA