Development of embedded system based on ARM + UCLinux

xiaoxiao2021-03-18  228

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. The selection and argumentation of the development platform 2. The establishment of the development environment 3. Development of general procedures 4. The Linux program is transplanted to the ARM UCLinux platform. The rest of the problem hopes to add a lot of ideas to facilitate everyone to improve. 1. The selection of development platforms and demonstrates a project to get hands, how to choose development platform (mainly refer to CPU and operating system and development environment and tools) should be said, sometimes this is not light affecting progress, product quality, maintainability, etc. And even the implementability of the scheme. I am in conjunction with my network monitoring system, I will simply summarize some considerations of the platform, please also add it. Consideration from the system function: (1) Whether there is a piece of peripheral, dedicated instruction or supporting software module directly implements system functional requirements. I feel that this is a big impact on many people's decision-making (2) This price should be comprehensively considered through the resources provided by the CPU. It provides a useful resource, how many resources are useless (that is the silver!), Or The three words, cost performance, and on the other hand, it is necessary to grasp the main contradiction, is it necessary to be a must, what characteristics are the highlights in the user's demand (just raised the price of these highlights), then the flower is Flower. (3) Power consumption This 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 belt to run. (4) Treatment speed This item doesn't have to say, everyone understands importance, but specifically calculates, it is a matter of learning. On the one hand, how fast it needs, if you add non-real-time operating system, it is not good to control. The margin is still a bit stable. On the other hand, the CPU directive cycle is much, there is no water, there is no parallel, what architecture, there is no dedicated directive (see people DSP multi-cattle, do this one), external memory and Access speed of peripherals, etc., which is slow, called bottlenecks. (5) Hardware support (such as external memory, dual power supply, etc.) is a miscellaneous item, but increase additional price, system volume, etc., can not be ignored. From the perspective of developers: (1) Is there enough technical support including Demo 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.), and the above three points are mainly considering rapidly developing 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 (1) The following is the satisfaction of the platform to my system: (and the above point corresponds to the above) The hardware part of this monitoring system mainly requires: 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). (From) This system software part requires the following sections: a. The 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 from Linux transplant procedures, there is too much, I used a ready-made) (2) This application is not a batch of things, not demanding the price requirements, and This CPU can be about 55, 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 (so I feel that my system is really no desire!) From the developer's perspective: (1) Because time is very tight (one Half a month, so the more support, the better. 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, but a pity :-( (2) I was only ear to the development model and ARM of the embedded system, Linux came out for about a month. I thought it was a little scared. 3) Online resources, there are very many. Provide some of you often use. :: URL :: http://www.uclinux.org/ uclinux Big Camp. :: URL :: http://www.ucdot.org/ Some technical articles are very good. :: URL :: http://www.linuxdevices.com/ :: url :: http://www.linuxeden.com/ This is a domestic Linux site. UClinux-dev@uclinux.org This is the list of UCLinux, the answer is big, very helpful, remember to set your email into a plain text format. Apply is: :: URL :: http://mailman.uclinux.org/ Mailman / ListINFO / UCLINUX-DEV Web Way. (4) The above development model, the maintenanceability, portability and scalability of the software are good. (5) The current CPU is still more common, the spot is no problem. 6) Is the program provider's quality? .. It's still possible :-) According to the above considerations and the current development situation, this set of plans is still more satisfactory. Today, go home first, and next introduction to the specific development step Bar. 2. 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, what is said, is not limited to this hardware platform and operating system), I have seen "cross-compilation" The environment "The word, I felt very Xuan, I used it later, it is actually solving who is using who the tools who use who the tool to edit 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 for the ARM CPU. Including ARM-ELF-GCC, ARM-ELF-LD, etc. (2) will code from UCLinux source code Under the corresponding path, compile it according to the compiled kernel's steps (this time the compilation tool used is already the ARM compilation tool mentioned above, because it is running on the ARM CPU, in addition, and compiling the Linux kernel The functionality of the kernel can be cut (3) to decompression to the corresponding path by menuconfig, and use the above tools. This is the most basic environment. The above work has been It is relatively simple, here is introduced here to help not use or just start using this kind of development model, and the application is developed because the target board is used with uclinux on the target board, which provides the basic consistent under Linux. The inconsistent part is mainly UCLinux does not support MMU (should be said to be customized for CPU without MMU), the most obvious is that the fork function is replaced with a vfork function, this is also programming, it feels the most unhappy point (no The way, who makes our CPUs have physiological defects). Another difference between UCLinux is cut by the library Uclibc, which is more suitable for the resource tight embedded system (the application is very large. Part is derived from the library function, and everyone is finally the chain together, so the library function is large, your program is small). The application development based on this development mode 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 :-) Programming for specific Linux, I will not board the door, I need to take a wake up. The people who have been born in hardware should develop good program habits, don't let the software joke. Because of some network applications, the websites and books to be used when some network programming; <> w.richard.stevens. This is the Book of Bibliographic books for Linux network :: URL :: 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 the header file (such as #include) in the program (such as #include) in the program. Because the compiler seeing such a header will find the path to the system specified, this path is saved by environment variables (LINUX and Windows are like this). For the above situation, the path name is not changed, but add a parameter to the compiler as follows: gcc -i / usr / stupid_include -o myprogram myprogram.c will find that the error message is gone, everything is restored to the peace of the past, suddenly understand No environment variables, pass 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: (I don't confirm the following, if you find problems, please correct it. (1) Precatch. Main job is to process all # beginning, including header files. There is no connection in executable (because two file names are always seen), now I know, there is no connection between them. After the precompilation end, the mission of the header file is over. Different platform programs are introduced next time. As can be seen when transplantation, pre-compilation is sometimes useful. (2) Compile. Compile should be the main step, that is to generate the source file to generate the language of the CPU, generally the suffix is ​​the target file, which should be said, this The file is already available. Of course, the external symbols such as external functions are not introduced. For the compiled program, these external symbols are just a shadow, I don't know if it is not there. You can be your program Instrumentation, there is no existence, even don't declare, in the compilation phase, many compilers just give a warning. Only when the link will be reported. (Oh, enough mentions!) (3) Link: Link is a list of money At the time, the external symbols used in the program have to be handed out. You can specify the target file you need to connect together, or tell the compiler library file name and path (specified method Next) The compiler will go, it is necessary to note that the specification of the library requires a payment.

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 platforms - Simple program transplant research procedures for the two weeks of the most painful two weeks, there is not much to learn from things, can only touch the front, so even more firm determination should be sorted out Things give later brothers. 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 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 the program? Program can first be grateful to develop a high-end language, remember, no matter how beautiful code is compiled, it will become a CPU to identify machine language, and almost one Thousands of 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 . Some questions that I need to consider when I think that I think is transplant: (1) The characteristics of their operating system and the 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 is generally like to use the target compiler to recompilation, so it can only be estimated, but don't Look at this program is only tens of K under Linux, it is considered that the program is small, because Linux has multiple dynamic libraries more than the program, and in the embedded system, it is very likely to link the use of the library, so The size of the program will greatly increase. (2) The program is running space. (3) Hardware and the corresponding drive should be as good as possible, but sometimes you can't grasp, you can only listen to life (no mistake !!) may have a harah, excitement, if you find it Good source code (good portability), then the rest is to work is to play your compiler, as long as you can successfully use your compiler to recompile.

90% of the work has been completed (not.) The last thing I have introduced some compiler, and the specific parameters of my ARM compiler will explain the settings of the main parameters of the compiler. Joining I already have Hello.c, compile the link under the X86 Linux platform. GCC-C Hello.c generates .o gcc -o hello hello.o generates an executable file, the last time, 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 -ftmit-frame-pointer -fsigned-char -mcpu = arm7tdmi -os -wall -dembed -d_uclinux_ -c hello.c This is just compilation, Separate the parameters one by one. ARM-ELF-GCC is a GNU ARM Compilation Tool 1) Include Address: Parameters: -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 generates output -fsigned-char to allow char Types to be symbol-Fomit-frame-Pointer does not save it in the registers for all functions that do not require a frame pointer. 3) -OS -WALL -WALL: All warnings are displayed in OS: Optimize size, this option enables all O2 optimizations that do not increase the size, and further optimize 4) = -DEMBED -D_UCLINUX_ -D: After -dmacro MacRo is defined as a string 1. The following is a link: ARM-ELF-LD -L / Root / Uclibc / Lib -L / USR / LOCAL / GNU / ARM-ELF / LIB -L / 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 / usr / local / GNU / LIB / GCC-LIB / ARM-ELF / 3.0.1 / CRTEND.O -LC -LGCC -LC where 1) Link Tools: ARM-ELF-LD 2) -l Indicates the path, usage, and -I, the path to its own library can also be added here.

转载请注明原文地址:https://www.9cbs.com/read-129864.html

New Post(0)