A few days ago, I developed a network monitoring system based on ARM UClinux, and I was going to do it immediately. I finally made a breath, so I got some notes and experience to conduct some discussions for this development model. I hope to help everyone. .
According to my development process, I will think of the following sections one by one.
1. Development platform selection and argumentation
2. Establishment of development environment
3. Development of general procedures
4. Linux program transplants to the ARM UCLinux platform
5. Remainder
I hope to add a lot of ideas to facilitate everyone to improve.
1. Development platform selection and argumentation
A project gets hands, how to choose development platforms (mainly referring to CPU and operating systems and development environment and tools) should be said, sometimes this is not only in progress, product quality, maintainability, etc., even involves programs Enableable. I am in conjunction with my network monitoring system, I will simply summarize some considerations of the platform, please also add it.
Rejuvenate from the system function:
(1) Whether there is a piece of peripherals, dedicated instructions or supporting software modules directly implement system functional requirements. I feel that this is very affected by many people's decisions.
(2) Price
This should be comprehensive consideration through the resource provided by the CPU. It provides how much useful resources, how many resources are useless (that is a silver!), Or the three words, cost performance, on the other hand, it is necessary to catch main Contradiction, is it necessary, what characteristics are highlights in user needs (just raised by these highlights), then the flower will take it.
(3) Power consumption
The system is not high in CPU power consumption, but for mobile devices, this is fatal, and this is not only for CPUs, and all almost devices must take the leather belt to run.
(4) Processing speed
This item doesn't have to say, everyone understands the importance, but it is a matter of learning, on the one hand, how fast it needs, if it is not good to control, the margin is still bigger Sustain, on the other hand, the CPU instruction cycle is, there is no water, there is no parallel, what architecture, there is no dedicated directive (seeing people DSP more cattle, doing this one), access to external memory and peripherals Speed, etc., which is slowly called bottleneck.
(5) Hardware support (such as external memory, dual power supply, etc.)
This is a miscellaneous, but it will increase additional price, system volume, etc., can not be ignored.
From the perspective of developers:
(1) Is there sufficient technical support including Demo version and schematic, DEMO program, operating system, and BSP, test development tools, etc.
(2) Self-conditions; including the requirements of the project development cycle, the developer's familiarity of the device and development model and the degree of hardness.
(3) Whether the available resources are rich (books, networks, etc.)
The above three points mainly consider the rapid development of a stable system.
(4) Inheritability, portability and scalability of the system.
(5) Is there a spot.
(6) The quality of the program provider. (Including technical level and service awareness).
According to the above consideration, S3C4510B (ARM7TDMI) UCLinux development mode is selected.
(1) The following is the satisfaction of the platform to my system: (corresponding to the above)
The hardware part of this monitoring system mainly requires the following parts:
a. Ethernet interface (S3C4510B self-contained network controller) b. Serial port (self)
C. The interface with the data acquisition chip (8-bit data cable, less than 8-bit address bus). (Own)
The system software part requires the following sections:
a. Hardware interface driver (UCLinux provides serial port and network controller driver)
b. Network Agreement Stack Support (UCLinux provides protocol stacks such as TCPIP, UDP)
C. Application layer program (if you count, you can see from Linux transplant, then too much, I used a ready-made)
(2) This application system is not the batch of things, which is not harsh for price requirements, and this CPU can be about 55 or so, acceptable.
(3) This application system has a fixed power supply, and the power consumption is not high. Of course, it is said that ARM is very characterized by saving power.
(4) The application system speed should be satisfied: 1. Serial port: 115200bps 2. Network speed can be 10Mbps, so it is not high for system speed requirements. This ARM can be within 50m.
(5) The system is not high in volume requirements, adding Flash and RAM still no problem (it feels that my system is really no desire!)
From the perspective of developers:
(1) Because time is tight (one and a half months), the more you support it. Currently, I will have the development board, the schematic, uclinux from the developer, the corresponding drive, bootloader, can be used. Software hardware is parallel. (BootLoader and network controller driver did not provide the original code, more pity :-(
(2) At the time, my development model and ARM of the embedded system were only awkward, and Linux came around for about a month. I am afraid now.
(3) There are very many resources on the Internet.
Provide some of us commonly used.
Http://www.uclinux.org/ uclinux's big camp.
Http://www.ucdot.org/ Some technical articles are very good.
http://www.linuxdevices.com/
Http://www.linuxeden.com/ This is a domestic Linux site.
Uclinux-dev@uclinux.org This is a list of UCLinux, the answer is big, very helpful, remember to set your email into a plain text format. Application is:
Http://mailman.uclinux.org/mailman/listinfo/uclinux-dev web way.
(4) The above development model is used, and the maintenanceability, portability and scalability of the software are good.
(5) The current CPU is still more common, and there is no problem in the spot.
(6) Does the quality of the program provider ....
This set of plans is still more satisfactory based on the above considerations and current development conditions.
Today, go home first, let go back to the specific development step.
2. The establishment of the development environment.
First, two nonsense is a brother who is confused with the operating system (especially embedded operating system) as before. Because someone always is asking if it is necessary to use an operating system, my CPU can be ported to the operating system, which can be transplanted what operating system, and the operating system can run certain programs.
From my personal experience, this is actually a mysterious feeling of many hardware bodies, and I have a mysterious sense of the operating system (as I a year ago). To put it bluntly, the operating system is a very clever process, and your own procedure has no difference from essential, so, I have to use this program, I can use this program, my CPU can run this program How can I run. This program can run, another program that calls this program interface can not run! The answer will become simple, and the operating system is not a must (even if the embedded system is even more such), you can run some programs to run on the PC bare metal without operating system (BIOS is like this), like this Like C51, (although the extravagant is a bit of heartache), or transplanted UCOS to the top. On the other hand, there are many of the modern operating systems that require some hardware support, (like the implementation of the protection mode), in turn, high-end CPU specializes in the architecture of the support operating system, so that many operating systems are realized by picky hardware platforms of. In fact, other procedures are the same, the other CPU on the on-chip peripheral of your program is not allowed to be transplanted. This is the roughness is not thick. Book is biography, or talk about the establishment of the development environment in ARM UClinux development mode (in fact, the following is not limited to this hardware platform and operating system)
I have seen the words "Cross-Compiling Environment" in the book, I have seen it very much in the book, and I only know that I used it in the future. In fact, who is solved who is using who is using the code problem? .
The most important task of compilation is to convert your program into machine code that can be identified by the CPU running the program, and the different CPU has a corresponding compiler and on the other hand. The compiler itself is also a program, of course, it is also necessary to run on a CPU platform. So the cross-compiled intersection is in that compiler itself a program on the CPU1, but is compiled for the CPU2 (outside a whole!). As soon as I thought, I used to develop programs with 51 and DSP development software (mostly Ide-integrated development environments). Of course, if you are running normally on your ARM system, and your resources are enough, you can transplant the ARM compilation tool running on the PC to the ARM, and all the system's application is directly in the ARM system. Compile, this is not a cross-compilation, but if there is conditional, the development or transplantation of the program is more convenient, because the entire development process returns to the model in which the application is compiled on the PC, that is Use your own compiler with your own compiler with your own compiler.
Different from the development model of the operating system (the operating system here, especially referring to the operating system of the special interface function library, the current UCOS is not counted), in the target board (that is, the board of the system) uses the operating system In the development mode, the library that should be operating the system should be required in the cross-compilation environment. For example, Uclibc provided by Uclinux. At this time, the developed host is not only necessary to have the compilation tool required for the target board CPU. There is also a library of the corresponding operating system, but also because the general library file also recompiles the compiler with the target CPU on the development machine, so Also put the original code of the operating system on the developer. (Hey, there is nothing to do with the target board, but it is really going to carry so much thing, it is really worthy of it !!).
Although the interface library of the operating system is critical, everyone seems to have forgotten its existence. These are more because everyone has stayed away from the era of the knife fire (need to tell the compiler, the library, and the name of the library of the lib), the integrated compiler is made to compile all the cumbersome works of the link to the build button. . And whether it is a Windows environment, or a Linux environment, there are environment variables to record these parameters. . But try to change the / usr / lib directory, you will know that you can't ignore their existence, because the functionality of the operating system is used to hand over these libraries to use. Of course, if your system does not rely on any operating system, you only need a compilation tool, less of these probes. The above things are generally not necessary to study carefully, but when developing or transplanting procedures in crossings, you may need to understand almost all important parameters of the compiler, linker and other development tools.
When I was developing, the host used Linux, if there is condition, I suggest that everyone is doing this, the use of Linux does not imagine complex (although I have to put a book about Linux now), and the development program can first Turn on the host, then use the cross-compilation tool to re-compile it to the target system, you can do this because the host is Linux, the target system runs uclinux, the application interface provided by the two operating systems is almost the same, so the program is almost no modification. .
In my system, establish a basic development environment process is as follows.
(1) Install the GNU development tool chain (which is a set of compiled development programs developed for the ARM CPU development. Including ARM-ELF-GCC, ARM-ELF-LD, etc.
(2) Unzip the UCLinux source code to the corresponding path, compile it according to the compiled kernel, and the compilation tool used at this time is already the ARM compilation tool mentioned above, because it is going to run on the ARM CPU. In addition, the same as compiling the Linux kernel, at this time, the function provided by the kernel can be cut off.
(3) Unzip the library (UCLIBC) to the corresponding path and compile it with the above tool.
Even the most basic environment is built.
The above work is relatively simple for people who have done, here is introduced to help without use or just start using this development model, and make a clear thinking.
3. Application development
Because the target board is used with uclinux, it provides the basic consistent part of the program interface and Linux, inconsistent part is mainly UCLinux does not support MMU (it should be UCLinux is customized by CPU without MMU), the most obvious is the fork function To replace the vFork function, this is also programming, it feels the most uncomfortable (no way, who makes our CPU have physiological defects). Another unpredictable difference is that the library Uclibc provided by Uclinux is cut. It is more suitable for the resource tight embedded system (the last decomposition has been said, the application is part of the application to deal with the library function, and everyone is finally the chain together, so the library function is big, your program is small) .
Therefore, based on this development model, the application development has become a program development under Linux. Moreover, in practice, the program first compiles the compiler to take the host platform on the host and commissioned (the compiler under Linux is GCC), of course, the premise is the hardware condition host required in the debugging program. For example, there is a paragraph in my program that is for the serial port, so I first edited a serial program in the host, and transfer the compiler with the target board after transfer (if I saw the "Cross-Compiling Environment", this is not I will be dizzy), download it to the target board, generally can be used directly. The above is also why I think that developing an embedded Linux program host should use a Linux environment. For people who have never used Linux (for example, I), I should spend 3 or 4 days before 3 or 4 days, especially its editor, people who are used to compile the compilation environment sometimes even compiler and editor. The concept is blurred, so it is generally directly entering the integrated compilation environment, and even the writing is a flat, and I don't know the editor of some editors provided by the integrated compiler. If you use Emacs under Linux, you will find them. The gap between the rooms is probably ... If you are so big like me, it is so big. So the programming sequence should be selected as an excellent editor, under Linux, of course, Emacs, although I just saw it is ugly, complicated. But as long as you practice more, it is helpful for improving efficiency. (Complete your program with two editors, half is Emacs, half is not emacs, look at the effect :-)
For the specific Linux program, I will not have the door ax, you need to make a wake up is that the people who are born by the hardware should develop good programming habits, don't let the jokes of the software. Because made some network applications, the websites and books to be used when some network programming are introduced;
<< UNIX Network Programming Volume 1 >> W.Richard.stevens. This is a Bible of the Bible of Linux Network Programming
http://www.fanqiang.com/a4/b7/ Suitable for network programming.
There are also IBM China's tutorials and articles about Linux, are translated, and there are many writings very good.
In fact, similar resources do not count, you should go to Google on Google when you encounter problems.
Key to say something about the compiler, don't understand it, compiler in the cross-compilation environment, which is difficult, which is not because the tragic environment under the target board compiler in the cross-compilation environment. Think about compiling the MYPROGRAM.C to make the MyProgram.c, the simplest gcc -o myprogram myprogram.c is OK. (In fact, you can also find similar commands in VC, integrated development environments just call it for you). Everything seems to be justified.
But try to change the / usr / include path (such as changing to stupid_include), then compile it, it will find that the header file (such as #include
gcc -i / usr / stupid_include -o myprogram myprogram.c will find that the error message is gone, everything is restored to the quiet, suddenly understand, no environment variables, pass the parameters, can also tell the compiler. Back to talk about your target compiler, although it takes up a lot of the land, compiler, header files, library files, one a lot, but you have to make a program compiler to dizziness, because there is no environment variable tells itself Where is the header file and a library file? It seems that there are only two ways, one is to grab the environment variable of the host to change into their own (a bandit), or add the necessary parameters (or the gentleman), tell the compiler. (In addition, there are other parameters). From the source program to the executable, depending on the situation, it may be divided into a few steps. Generally, each step may have an application implementation, and the ARM development tool chain provided by the GNU is actually such a program. Provide a full set of services from compiling to links to format transformation. You can use the ARM-ELF-GCC command to directly generate executable files (in fact, call the next program after the completion of your own task), or you can add your own parameters, just make your own things.
The use of the main parameters of the compiler will be explained next time. Here, I want to talk about the main steps of the compiler to generate applications. The reason for this problem is that many people can't distinguish between such as compilation and links. Don't ask, this is still a disaster that Ide integrates the development environment. Some people will say that Ide strokes you, you are old. Actually, first, things that are mentioned above generally found in the Option or Build Option under the Ide's Project menu, just generally do not need to be tied. In another aspect, IDE is like a fool camera, and many work he helps you complete it. It is easy to use. But if you want to be a photographer, you can't understand every detail. In fact, the compiler is the same. (You can make your own choices for many options such as optimization, warning level, macro definition). The following is a few main steps: (Some of the following don't confirm, if you find problems, please correct it in time.
(1) Prefoliation. The main job is to process all # beginning, including header files. There is no connection between the previous unclear file and the executable (because you have always seen the two file names), now you know, there is no contact between them. After the end of the precompilation, the mission of the header file is over. It can be seen when the next introduction of different platform programs is transformed, and the pre-compilation is sometimes useful.
(2) Compilation. Compiling should be the main step, that is to generate the source file to generate the language of the CPU, which is generally the suffix to .o target file, it should be said that the file at this time is already executed. Of course, the external symbols such as external functions are not introduced. For compilation programs, these external symbols are just a shadow, I don't know if it is not there. You can call a function that does not exist in your program, or not, you don't have to declare, in the compilation phase, many compilers just give a warning. The error is only wrong when the link is linked. (Oh, enough weight!)
(3) Link: When the link is a clearing, the external symbol used in the program has to be handed out. You can specify the target file that needs to be connected, or tell the compiler library file name and path (specified method next time). The compiler will go, you need to pay attention to the designation of the library needs to pay attention to the order. First, if there is a function of the same name in different libraries, and the function is called, then the link is connected in front, this is also applicable for the designation of the header file path, if your own header file is the same, And your header path is in front of the system header file, your header file will replace the header file. The library file is organized by the corresponding program (Linux is an am command) will need to be added to the target file (this file is generated by the compile stage) to generate a file file, and can establish a search and retrieval content is included. The symbol defined in the target file. That is, the library file is not necessary, but it provides a fast retrieval mechanism for functions in the target files that are often used. The above is the main step. Of course, there are some tools for format conversion. Not introduced. I know the details of the compiler are very beneficial for the development and transplantation of the program.
Debugging during program development is also critical, because you can debug on the host, so you can use the GDB under Linux, (a bit like DOS under DOS). But just use the fur, there is a debugging tool for the host mode, has no time to study, and the heroes who have hoped to use more articles.
In addition, how to make Ramdisk, how to launch your own procedure, these are too linux, people who have never been touched, for everyone's health, I don't talk about it, I can give me email, I can give me email. Everyone discusses.
4. Transplantation of different platform programs - Migration of simple programs
The two weeks of the research program transplant is the most painful two weeks, there is not much to learn from things, and can only touch the front, so even more firm determined to organize some things to give later. But then, I'm intimidated by my brothers, as long as you want to do what you want, the program transplant is actually relatively simple.
First list some questions:
(1) The program running on x86 can not run on the 51 single-chip, why is it possible, if you can, what you should do can be implemented.
(2) The same CPU platform, why the DOS program can run under Windows, can you run under Linux, why, what work may be implemented.
Why can transplant procedures, why do you want to transplant procedures?
The program can first be grateful to the development of the big bulls in the high-level language, remember, no matter how beautiful the code is compiled, it will become a CPU to identify the machine language, and almost a thousand CPUs say a thousand languages. To ensure that everyone has a common language, it provides a high-level language-advanced language. Every CPU sent its own translation - compiler. This translation is proficient in both languages, advanced languages and their own languages. (From this you can see the importance of the compilation tool in program transplant). As long as the program does not have a constraint on the hardware, it can be said that this communication is unlimited, even different operating system platforms. (Operating system is also a program, can also be ported) Example: Use VC (or TC, BC) with VC (or TC, BC) in Windows to implement i = i 1, and do not change it to recompile with 51 C compiler. And run on the 51 single-chip. A small transplant is over.
It is also grateful to the brothers of the open source, without these C files and h files, let you recompile, how to run on your CPU? In fact, more than this, will also see the open source organization's specialized work for the programs of portability. So why do you want to transplant the program?
Ask this question, just like a wallet on the ground, why do you want to pick up, the answer is self-evident. Why do you want to have a ready-made thing. Of course, the transplant procedure can be so simple, especially for the first time, followed by some problems that should be considered before transplantation. (Just as there is a wallet on the ground, you will be in your own pocket, say that it is a set). On the other hand, you give me a good program, let me take it, I have to consider it, maybe there is more problems to write one. The portable procedures I said here should be more maintained, more mature source code (like the UCD-SNMP behind me), the current open source code is not only open to their own procedures. Instead, there is a set of mature and complete version controls, bug reports, and PATCH submission processes.
This code has a greater value of use.
When can I consider the transplant procedure? When the embedded operating system is developed, the program with a certain size can be used to check the source code that is not mature. As mentioned earlier, the transplantation of the program is ultimately only for the CPU, in fact, there is nothing to do with the operating system, but on the other hand, because the code may use some library functions, these libraries include the API provided by the C language standard library and operating system ( Application interface) library. Assume that only the source code includes only the C standard library, then the program can transplant cross-operative system. PRINTF is used in the Hello World program, because the function is a C standard function, so use TC (BC or VC) on x86 can be directly compiled, just in the ARM UClinux platform, but if the program is called, then the VFORK function is called, then Only the operating system of Linux has supported this special service, and the program cannot be compiled directly under the Window or DOS operating system. Similar functions that can only be supported by this operating system. Further, the physiological defects on the hardware will also bother to be brought, and the S3C4510B does not support MMU, which does not provide the UCLinux that is running, and the UCLinux itself can support MMUs, so it is related before transplantation Both functions (such as forks) are replaced (using vfork). Fortunately, most of the application interfaces provided by Uclinux and Linux are still the same. So this work can be affected.
As can be known, if it is developed on various embedded Linux (except UCLinux, there are several) platforms, it can be used for the platform and the source code on the Linux platform, but to keep in mind the differences between them. . In my system, network monitoring is required, so I want to use the SNMP protocol, the protocol and HTTP, FTP belong to the maturity protocol of the application layer, dedicated to network management. There are already some code for this protocol, the most famous is UCD-SNMP, not in the software itself, the portability is also better, and it can be transplanted on platforms such as Linux, UNIX, so it is decided to transplant it to ARM UClinux. On the platform (don't look at it so easy now, I am a little bit of this time).
Simply summarize, the premise of transplanted applications is that the key tools of transplantation are compilers, the source code and hardware platforms, the better (here mainly referring to the use of compilation, or doing the platform Things, for example, point the pointer to a specific address and then operate), on the other hand, if the program is based on an operating system (using the special service provided by the operating system, the API), whether to see if your operating system provides related services . The following is a simple list of questions that I think when I think is transplanted:
(1) Features of our operating system and features supported under current versions.
For example: Uclinux does not support MMU, which is also unable to support the corresponding features.
(2) Hardware resources.
Because the embedded system resources are more tense, hardware resources must be considered:
(1) Software storage space
This may only know if you use the target compiler to recompile, so you can only estimate, but don't look at this program only dozens of k under Linux, think that the program is small, this is because Linux under the procedure Multiple use dynamic libraries, and in the embedded system, it is possible to link the useful libraries together, so the size of the program will increase.
(2) The program is running space. .
(3) Hardware and corresponding drivers are complete
The above work should be as good as possible, but sometimes I can't grasp in advance, I can only listen to the life (have you made a mistake !!)
Some people may have to have a dizzy, excite you, if you find a good source code (good portability), then the rest is to work, you can play your compiler, as long as you can smoothly use the source code smoothly Your compiler recompores it. 90% of the work is complete (isn't it?)
Back and forth has introduced some compiler, the following is aimed at the specific parameters of my ARM compiler, and the settings of the main parameters of the compiler are described.
Joining I already have Hello.c, compile the link under the X86 Linux platform.
GCC-C Hello.c generated .o
GCC -O Hello Hello.o produces an executable file, and the host compiler parameters are saved, so it looks simple. Here I deliberately divided into two steps.
Let's take a look at the program with my compiler (the heart is not good first).
ARM-ELF-GCC -IROOT / UCLIBC / INCLUDE -MSOFT-FLOAT -MCPU = ARM7TDMI -MIT-FRAME-POINTER -FSIGNED-CHAR -MCPU = ARM7TDMI -OS -WALL -DEMBED -D_UCLINUX_ -C Hello.c
This is just compiling and explains the parameters one by one.
ARM-ELF-GCC is a GNU ARM Compilation Tool
1) Include Address: Parameters: -i: root / uclibc / incrude (this is the header file path of my UCLinux on the host) Usage: -i root / uclibc / incrude
-I parameter guarantee that the back header file is searched before the search system header file is searched so as to replace the header file of the system. If there are multiple such parameters, the order in which the search is from left to right, then the head of the system file.
2) -m is an option for the CPU.
-mcpu = arm7tdmi Description CPU type
-Msoft-float produces an output containing floating point libraries
-fsigned-char allows char types with symbols
-FOTIMIT-FRAME-POINTER does not save it in the register without a function that does not require a frame pointer.
3) -OS -wall
-Wall: All warnings display OS: Optimize size, this option enables all O2 optimizations that do not increase size, and further optimize according to size
4) = -dembed -d_uclinux_
-D: Define the MACRO after -dmacro as a string 1.
The following is a link:
ARM-ELF-LD -L / Root / Uclibc / LiB -L / USR / Local / GNU / ARM-ELF / LIB / USR / LOCAL / GNU / LIB / GCC-LIB / ARM-ELF / 3.0.1 - Elf2flt -o hello /root/uclibc/lib/crt0.o /usr/local/gnu/lib/gcc-lib/Arm-elf/3.0.1/ Crtbegin.o Hello.o
/us/local/gnu/lib/gcc-lib/Arm-elf/3.0.1/crtend.o -lc -lgcc -lc
among them
1) Link Tool: ARM-ELF-LD
2) -l Indicates the path of the library that needs to be linked, like the use, and the path to your library can also be added here. -L / root / uclibc / lib -l / usr / local / GNU / ARM-ELF / LIB
-L / USR / Local / GNU / LIB / GCC-LIB / ARM-ELF / 3.0.1
3) -o followed by the final file name of the generated
4) /Root/uclibc/lib/crt0.o /usr/local/gnu/lib/gcc-lib/Arm-elf/3.0.1/ Crtbegin.o Objects.o
/us/local/gnu/lib/gcc-lib/arm-elf/3.0.1/crtend.o
This is the .o file that needs to be linked together
5) -lc -lgcc -lc -l followed by the name of the library that needs to be linked, the name of the general library is libXXX.A, and it is -lxxx when used, does not add Lib and .a. Also pay attention to the location, your own library file should be added in front of his library.
After the compilation passed, the transplant is completed, and it is possible to analyze his compile option (for those header files, library files, etc.), and then use their own compiler to recompile the corresponding parameters. Ok.
Of course, this is just a simple program, complex case is next to talk.
________________ c2.4g / 128m / Intel 845G / AC97 / Reltek 8139 Windows2000 Magiclinux 1.2beta2 Just for Fun!