Linux system programming minimum Linux system running application

1. Write an application

As shown in the figure below, create a special folder under Ubuntu to store " Linux < /span> System Programming" source code and programs.
Under the directory " /home ", in root Under user rights, use the command "   mkdir linuxsystemcode   " to create a new directory "  linsyscode ".
Afterwards, as shown below, command to use   “  cd linsyscode/  ” 进入目录   “ linsyscode ”   ,Use instruction   mkdir
helloworld    , create a new “ helloworld ” directory, Then use the command cd helloworld/  ” to enter the newly created directory.< /span>
Code editing Use the editor vi editor or vim editor to copy “ helloworld.c ” to the previously created “ helloworld ” directory and use the command “ vi helloworld.c ” or “ vim helloworld.c ” command, as shown in the figure below.
Note: In Linux system programming, if there is no special instructions in the following code, it will be created under the directory "/home/linsyscode"
directory and place the code in it.

2. Cross-compilation hello world

The purpose of cross compilation is how to compile applications that can run on the development board.
First determine the environment variables, as shown in the figure below, use  cd ”  a>   " to open the environment variable file. vim .bashrc " command to return to the root directory, and then use the command  
As shown in the figure below, enter the bottom line. The same compiler used to compile the kernel can be used here.
Use the command   “ cd /home/linsyscode/helloworld/ ”  Return to  “ /home/ linsyscode/helloworld" directory, and then use the following command to use the command to copy the C file "helloworld.c" in the current directory < a i=6>Compile into an executable file that can be run on the development board "helloworld".
arm-none-linux-gnueabi-gcc -o helloworld helloworld.c -static

Explanation:"arm-none-linux-gnueabi-gcc"Indicates the use of arm a>development board;iTop4412 Compiler, corresponding to

“-static” means that the library will also be compiled.

As shown in the figure below, the compilation is successful and the "helloworld" file is generated.

3. Compile helloworld into the file system

After compiling and generating the helloworld file, the program can be compiled directly into the file system. As shown in the figure below, first return to the /home directory, and then use cp The command copies the compiled helloworld program to system bin directory, the command is as follows.
cp -r linsyscode/helloworld/helloworld minilinux/system/bin/

下后编译 system .

4. Recompile the system image

Refer to the blog post: Linux system programming to create the smallest linux file system - CSDN blog https://blog.csdn.net/Eva20192020/article/details/134361209?spm=1001.2014.3001.5502” 
The fourth step in completes the installation of the compilation tools.
After installing the packaging and compilation tool "make_ext4fs". Enter the "/home/minilinux/" directory, and then use the following command to compile the system, as shown in the figure below.
make_ext4fs -s -l 314572800 -a root -L linux system.img system

To generate the system.img file system image, re-program the file system after successful compilation " system.img" file system< a i=3>.

5. The minimum Linux system on the development board to run the application

Start the development board until the minimum system is started and press Enter, as shown in the figure below.
Check whether there is an executable helloworld file in the bin directory, as shown below.
Then use the command "  chmod 777 /bin/helloworld  ” Modify permissions  . As shown below.
Then Use the command “ ./bin/helloworld  ”< a i=5>Run helloworld program, as shown in the figure below. After running, you can see the printed information after the application is run.

6. Run the application on USB flash drive

 This section introduces how to use U disk to copy the executable program to the development board and run it on the development board.

First copy the executable file helloworld to U disk, start the development board until the minimum system is started, as shown in the figure below.

 

As shown in the figure below, the U disk can be recognized and the disk symbol is sda1.

If the file system does not have the /mnt/udisk directory when it is first started, you need to use the command  mkdir  < a i=3>/mnt/udisk ” New. As shown below.

before adding u 盘,插入u 盘的Time, check sda1, use command  “  mount /dev/ sda1 /mnt/udisk  ”  additional u 盘、下图show.

 

At this time, you can run it directly in the U disk, as shown in the figure below, use the command  " chmod 777 /mnt/udisk/helloworld  ”Modify permissions.

Then use the command  ./mnt/udisk/helloworld  ”  Runhelloworld program, as shown in the figure below.  

Guess you like

Origin blog.csdn.net/Eva20192020/article/details/134397249