Run your own hello program on uclinux

Source: Internet
Author: User
Run your own hello program-general Linux technology-Linux programming and kernel information on uclinux. The following is a detailed description. Then, create a directory named test under the user directory of uClinux:

Cd uClinux/user/

Mkdir test

Create a c program named hello. C under the test directory. The source code is as follows:

# Include
Int main (void)
{
Printf ("Hello, uClinux! ");
Return (0 );
}

Then, use the cross compiler to compile the hello. c source program and generate an executable file named hello:

Arm-elf-gcc-Wall-elf2flt-o hello. c

Copy the executable file to the uClinux image file directory (/home/user/uClinux/romfs/bin:

Cp./hello.../romfs/bin/

Then create a Makefile file under the test directory. The content is as follows (in fact, it is copied from other directories under the user and slightly modified ):

EXEC = hello
OBJS = hello. o

All: $ (EXEC)

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

$ (OBJS): hello. c

Romfs:
$ (ROMFSINST)/bin/$ (EXEC)

Clean:
-Rm-f $ (EXEC) *. elf *. gdb *. o

In the future, you can follow this template to modify the associations. The rest can be left unchanged.

Next we need to modify some configuration files of uClinux and tell uClinux to add a User Application.

Edit the file user/Makefile in the uClinux directory and add the following line of text:

Dir _ $ (CONFIG_USER_TEST_HELLO) + = test

Pay attention to two problems here: first, the added location. When opening the file, you will find many similar statements in this Makefile. You only need to put the above line in the appropriate location in alphabetical order; second, pay attention to the color changes of the above line of text. The black part is actually the same as other lines, and the red part is the user program directory we added to the user, note that the preceding statements are in uppercase, and the subsequent statements must be consistent with the user directory. The blue part is the name of the executable file generated after the user program is compiled.

Edit the file config/Configure. help In the uClinux directory and append the following text at the end of the file:

CONFIG_USER_TEST_HELLO
This is an example C program in uClinux OS, and it will print "Hello, uClinux! "On screen.

Note: The first line must be written at the top, and the second line must start with two spaces with a total length of less than 70 characters.

Edit the file config/config. in under the uClinux directory and append the following text at the end of the file:

######################### Mainmenu_option next_comment
Comment 'test'

Bool 'hello' CONFIG_USER_TEST_HELLO
Endmenu
#########################

Then, return to the root directory of uClinux and re-compile the kernel. However, this process does not have to be as complicated as compiling the kernel for the first time. You can compile only the image file to be generated after the connection:

Genromfs-v-V "ROMdisk"-f./images/romfs. img-d./romfs

Make image

Make

The previous two steps will show a memory image table, in which you can find an application named hello. If there is no error, it will be completed soon.
Related Article

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.