首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

[求助]高手救命!!如何修改如下makefile?

[求助]高手救命!!如何修改如下makefile?

请教高手!

在nios2上加载uclinux,现在想要应用一个hello_world的简单程序,如下:

#include <stdio.h>
main()
{
printf("hello world!\n");
}

请问该如何修改下面nios2自带的makefile啊?非常感谢!!!!!

#
# configurable options
#  - set DEBUG = 1 to turn on debugging support
#
DEBUG = 1
PROJ_NAME = hello
INSTALL_DIR =
PROGS := $(PROJ_NAME).exe
CFLAGS +=
#
# You should not need to modify anything beyond this point
#
TOPDIR = ..
include $(TOPDIR)/Rules.mak
ifeq '$(DEBUG)' '1'
PROGS += $(PROGS:.exe=.gdb)
endif
all: $(PROGS)
.PHONY: clean
clean:
-rm -f *.[oad] *.elf *.gdb *.bin *.exe
.PHONY: install
install: all
ifeq "$(INSTALL_DIR)" ""
$(error No installation directory specified)
endif
mkdir -p $(INSTALL_DIR)/bin
install -v $(filter %.exe, $(PROGS)) $(INSTALL_DIR)/bin

如果是使用nioside中的makefile的话,只要改自带的名字就可以了。

 

 

 

如果在linux中通过交叉编译的话,makefile如下。

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

步骤如下:

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

#include <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

[此贴子已经被作者于2007-4-11 16:48:05编辑过]

这个版主不太冷 =========================== 我的中电网博客:http://blog.chinaecnet.com/u/20/index.htm

版主,看不到图片~~

我用的是niosIDE里面自带的makefile

我已上传了uclinux的简单教程。就在本版。

NiosII下UCOS和移植Linux教程.rar

不过,

Why develope on Linux when you have the IDE on Windows?

The IDE on Windows is not good for uClinux kernel/apps development,

  • The IDE's compiler defaults to newlib, while we prefer to use uClibc in uClinux. Software building and porting will be much easier with the compiler created from buildroot.
  • The tools run much faster, and with less trouble on Linux. After using Linux, you will feel the IDE on Windows moves like turtles.
  • If you want to develop Nios II uClinux, you should work on Linux and learn Linux. You can learn a lot when working on Linux, and the "Linux know how" is the key to success on Nios II uClinux.
这个版主不太冷 =========================== 我的中电网博客:http://blog.chinaecnet.com/u/20/index.htm

好的,下载学习~~

谢谢版主的建议,由于毕业设计需要用到这方面知识,没有足够时间学习linux,

所以想着在NIOS IDE环境下可能会简单一点吧……

不过还是很多都不懂

返回列表