(Formerly known as "Hello World") How to develop the first hello World Program in μClinux? (IC design) (de2) (nio ii) (OS) (Linux) (μClinux) (C/C ++) (GCC)

Source: Internet
Author: User

Abstract
The attacker of μClinux does not need to upload the program on de2. The important thing is how to place our program on μClinux to upload the program.

Introduction
On de2, how does one install the μClinux operating system? In (IC design) (de2) (nioii) (OS) (Linux) (μClinux), we have run μClinux on de2, is this the end? Developers are concerned about how to run their own programs on μClinux.

There are two problems to solve:
1. How to Use the nios2-linux-uclibc-gcc cross compiler?
2. How can I upload my own rows to the image?

Let's take a look at how to make the best of Hello world on μClinux.

How to Use the nios2-linux-uclibc-gcc cross compiler?
Step 1:
First, use VI to upload a hello_world.c under/usr/local/src.

1 # Include < Stdio. h >
2
3 Int Main (){
4 Printf ( " Hello world \ n " );
5 }

Step 2:
Use hello_world.c of GCC strongswan for Linux

[ Root @ localhost SRC ] # GCC hello_world.c-O hello_world_linux

Step 3:
Hello_world_linux

[ Root @ localhost SRC ] #./Hello_world_linux

Results

Hello World

This confirms that our hello_world.c program is completely correct and can be used in Linux.

Step 4:
Use the nios2-linux-uclibc-gcc cross compiler extends unzip μClinux hello_world.c

[ Root @ localhost SRC ] # Nios2-linux-uclibc-gcc-W1-elf2flt hello_world.c-O hello_world_uclinux

Nios2-linux-uclibc-gcc is a cross compiler of the niosii platform. How can I install the μClinux operating system on de2? (IC design) (de2) (nio ii) (OS) (Linux) (μClinux ).

-Wl indicates the number of linker records.-elf2flt is used to compile logs because the nioii platform is in the ELF format, but μClinux Is In The FLT format.

Step 5:
Hello_world_uclinux

[ Root @ localhost SRC ] #./Hello_world_uclinux
-Bash:./hello_world_uclinux: cannot execute binary file

As we could not normally perform the operation during the specified period, this indicates that cross compile is successful.

How can I put my own rows on the image?
All images to be packaged will be stored in/usr/local/src/uClinux-Dist/romfs, that is, we only need to write, write, and film .... in this project, it will be packaged into the sdram of the zimage to de2.

Step 1:
Put hello_world_uclinux under/usr/local/src/uClinux-Dist/romfs/usr // bin.

[ Root @ localhost SRC ] # Cp hello_world_uclinux/usr/local/src/uClinux-Dist/romfs/usr/bin

Step 2:
Package as image

[ Root @ localhost SRC ] # Cd uClinux-Dist; make Linux Image

Zimage will be found at/usr/local/src/uClinux-Dist/linux-2.6.x/ARCH/nios2nommu/boot/

Step 3:
Upload zimage to Windows c: \ Altera \ 72 \ nios2eds \ examples \

Import the hardware into de2
Step 1:
Upload de2_nios2.sof to c: \ Altera \ 72 \ nios2eds \ examples \.

Step 2:
Dynamic niosii command shell
Start-> program set-> Altera-> niosii eds 7.2-> niosii 7.2 command shell

Step 3:
Import hardware into de2

[ Systems Builder ] $ Nios2-configure-sof de2_nios.sof

Results

Searching for sof file:
In.
De2_nios.sof

Info: **************************************** ***************************
Info: Running Quartus II programmer
Info: Command: quartus_pgm -- no_banner -- Mode = JTAG-o p ; De2_nios.sof
Info: Using programming cable " USB-blaster [USB-0] "
Info: started programmer operation at Mon Jun 09   03 : 01 : 45   2008
Info: Refreshing device Index 1
Info: Device 1 Contains jtag id code 0x020b40dd
Info: configuration succeeded -- 1 Device (s) configured
Info: successfully saved med operation (s)
Info: ended programmer operation at Mon Jun 09   03 : 01 : 46   2008
Info: Quartus II programmer was successful. 0 Errors ,   0 Warnings
Info: allocated 54 Megabytes of memory during processing
Info: Processing ended: Mon Jun 09   03 : 01 : 46   2008
Info: elapsed time: 00 : 00 : 02

Step 4:
Upload zimage of μClinux to SDRAM

[ Systems Builder ] $ Nios2-download-G zimage

Results

Using Cable " USB-blaster [USB-0] " , Device 1 , Instance 0x00
Pausing target processor: OK
Initializing CPU cache (if present)
OK
Downloaded 1197kb in 14 . 4 S ( 83 . 1kb/s)
Verified OK
Starting processor at address 0x00d00000

Step 5:
μ Clinux

[ Systems Builder ] $ Nios2-terminal

Results

Uncompressing Linux OK , Booting the kernel.
Linux version 2.6.19 -Uc1 (root@localhost.localdomain) (GCC version 3.4.6 )# 2 PR
Empt sun Jun 8   23 : 28 : 30 CST 2008

UClinux/niosii
Altera niosii support (c) 2004 Microtronix Datacom Ltd.
Built 1 Zonelists. Total pages: 2032
Kernel command line:
PID hash table entries: 32 (Order: 5 ,   128 Bytes)
Dentry cache hash table entries: 1024 (Order: 0 ,   4096 Bytes)
Inode-Cache hash table entries: 1024 (Order: 0 ,   4096 Bytes)
Memory available: 5956 K/8192 K RAM , 0 k/0 k rom (1465 K kernel code , 680 k Data)
Mount-Cache hash table entries: 512
Net: Registered protocol family 16
Net: Registered protocol family 2
IP Route cache hash table entries: 1024 (Order: 0 ,   4096 Bytes)
TCP established hash table entries: 1024 (Order: 0 ,   4096 Bytes)
TCP bind hash table entries: 1024 (Order: 0 ,   4096 Bytes)
TCP: Hash Tables configured (established 1024 Bind 1024 )
TCP Reno registered
Io scheduler Noop registered
Io scheduler deadline registered (default)
Serial: jtag uart driver $ Revision: 1.3 $
Ttyj0 at mmio 0x806810f0 (IRQ =   1 ) Is a jtag_uart
TCP cubic registered
Net: Registered protocol family 1
Net: Registered protocol family 17
Freeing unused kernel memory: 572 K freed (0x97a000-0xa08000)
Shell invoked to run file:/etc/rc
Command: Hostname uClinux
Command: Mount-T proc/proc
Command: Mount-T sysfs/sys
Command: Mount-T usbfs NONE/proc/bus/USB
Mount: mounting none on/proc/bus/USB failed: no such file or directory
Command: mkdir/var/tmp
Command: mkdir/var/log
Command: mkdir/var/run
Command: mkdir/var/lock
Command: mkdir/var/empty
Command: ifconfig Lo 127.0.0.1
Command: Route add-Net 127.0.0.0 Netmask 255.0.0.0 Lo
Command: CAT/etc/motd
Welcome
______
/__ | _ |
_ | _________
| _ \ | | \\//
| _ | |__ | _ | /\
| ___ \____ | _ | \____ | \_/\_/
|
| _ |

For further information check:

Http://www.uclinux.org/

Execution finished,Exiting

Sash command shell (Version1.1.1)
/>

If you see this line, it means that the Clinux has been successfully deployed on de2.

Step 6:
Hello_world_uclinux

/> Cd usr/bin
/Usr/bin> hello_world_uclinux
Hello World
/Usr/bin>

Conclusion
So far, we have used GCC for cross compiler and image packaging. In fact, whatever release version, the embedded system is almost like this method, which is quite different from Windows Programming and web programming.

See also
(Original) how to install μClinux operating system on de2? (IC design) (de2) (nio ii) (OS) (Linux) (μClinux)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.