eric_jia的个人空间 https://blog.eetop.cn/208662 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

nios中uclinux的CompileHello

已有 866 次阅读| 2008-7-10 20:17 |个人分类:精品

nios中uclinux的CompileHello
[ 2007-4-11 16:41:00 | By: caopengly ]
 

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 .

  1. add a line to user/Makefile , dir_$(CONFIG_USER_HELLO_HELLO) += hello
  2. add a line to misc section of config/config.in, bool 'hello' CONFIG_USER_HELLO_HELLO
  3. mkdir ~/uClinux-dist/user/hello
  4. put hello.c in user/hello dir,
  5. 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

 

http://blog.eccn.com/u/20/cmd.htm?do=blogs&id=29&uid=20


点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 1

    粉丝
  • 0

    好友
  • 0

    获赞
  • 5

    评论
  • 访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-4-28 09:01 , Processed in 0.019803 second(s), 11 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部