Openwrt from a rookie perspective (1) First acquaintance with openwrt

   As a rookie, in order to get familiar with the openwrt system, I have read a lot of senior articles. Because the writing angle or target group is different, the focus is also different, and the knowledge learned is fragmented. When I have accumulated more knowledge, I will look back and find that "it is so", the author has already summarized it for us.
 
   For old birds, this article can be ignored directly. Now the Internet of Things is very popular, and there are many openwrt-based developments. This article hopes to help rookies who are new to openwrt like me, get to know openwrt as soon as possible, and avoid detours, so as not to give up halfway.
   
   I used to brush the openwrt system with a 703N router. When I was doing 3g network card dialing, I had contact with openwrt, and even wrote a program and uploaded it to the router to run. These are purely from the programmer's point of view, treating the router as a "computer". It is no different from programming on a computer except that the compilation environment uses a cross compiler environment.

  Thanks to the Enshan Forum, my 703N flashing firmware is downloaded from the jar, and the 3g dial-up script is also provided on the jar. The flashing process is all done according to the tutorial on the forum.

  Openwrt, a branch of the Linux system, is widely known. Thanks to the rise of various home routers, ordinary people can access this system at a very small price (a cheap router is only tens of dollars). Now MTK (MediaTek) is targeting IoT applications with router chips, and you can get a development board from Taobao for tens of dollars, and some have technical support.

   This is nonsense, the purpose is to reflect a "dish", I hope that friends who have the same feeling as me, work together to enter the world of openwrt. Enter the topic:

   openwrt in my eyes:

      1) It is a linux operating system, and its origin is specially born for routers. Of course, you can also use it as a normal linux operating system, depending on your application. Just like the goal of XP is a desktop office system, but some people prefer to use it as a database server.

      2) Booting is required to start the operating system kernel. Just like dos, windows need the code on the boot partition of the disk to boot in order to start. Anyone who has used ghost to install the Windows system knows that sometimes the system cannot be started after the installation is completed. It is OK to use the partition tool to repair the boot partition of the following disk. The so-called "repair" is to rewrite a small piece of boot code into the boot partition of the disk. When the computer starts, the operating system will be loaded through this code.

    3) openwrt is an embedded linux operating system. As I understand embedded, its hardware resources and memory resources are much less than that of PC. Usually, embedded systems use a chip called FLASH to act as a PC hard disk. If you know the microcontroller, it will be better understood.

    4) The booting of openwrt is done by something called bootloader. Since you are a rookie, you don't need to care about its specific implementation, you only need to know that there is and must have this thing, and its function is the same as the boot code on the boot partition on the disk introduced in 2). And just like the boot partition on the disk is in a specific location on the disk, the bootloader is also stored in the specific area of ​​the FLASH chip mentioned in 3). As for which one is specific, it is related to the processor chip used. Since it is a "rookie", I will not dwell on this issue. The commonly used bootloader is called uboot, uboot is a name, it is a kind of bootloader. Just like if you want to buy something, you can use Alipay or UnionPay.

     5) Usually, for the convenience of management, from the perspective of the bootloader, the FLASH is divided into logical blocks for management. For example, block0, block1, block2,..., each block stores different things. Just like the disk is divided into four logical disks, CDEF, the C drive is usually used to install the operating system, and the D drive is used to install the data files.

     6) Generally speaking, from the perspective of openwrt, FLASH is divided into logical blocks that are the same as bootload, which is convenient for unifying ideas. Everything is for the convenience of management, there is no need to be unconventional.

     7) For the rookie who is new to openwrt, the general bootloader and openwrt system are ready-made by others, so there is no need to worry about how the blocks are divided and why they are divided in this way.

     8) It is worth mentioning that bootloader and openwrt are two independent programs (but bootloader is born to start openwrt). The bootloader sets a certain logical block such as block0 to be able to write data. In the openwrt system, this logical block cannot be written. At this point, the two systems of bootloader and openwrt are independent systems, they are "God" in the world they build, and they do not interfere with each other.

     9) In addition to booting openwrt, the bootloader has an important role to upgrade or replace the openwrt system. It is to use what I call "brushing", in fact, the brushing of mobile phones is a truth. At this time, in the eyes of the bootloader, the openwrt program (usually we call it "firmware") is a piece of data. The role of the bootloader is to write these data to the specified location of the specified logical block of FLASH. Of course, these data can also be "backed up". Of course, the bootloader can also write a small piece of data required by openwrt to the specified data area. As mentioned earlier, the bootloader is the "God" in the world it builds. What it does depends entirely on what the designer of the bootloader gives it. function.
     
     10) How does the bootloader obtain the "firmware" from our computer? Usually, the bootloader supports the network. Users can communicate with the bootloader through the network on the PC, or through the serial port. The putty tool can communicate with the bootloader at the same time. Both methods are supported. The current bootloader has a built-in web server, which is connected to the webserver on the bootloader through the browser on the PC, and the interaction between the user and the bootloader can also be realized through the cgi program on the webserver.

      11) Friends often hear the concept of "undead bootloader" when flashing the router. In fact, it means that as long as you do not destroy the bootloader program when flashing the computer, the openwrt firmware can be flashed back at any time, and the router will not become a useless "brick". ". Of course, if you flash the bootloader program, if it fails or the new bootloader fails, your system will never start. The only way is to solder the FLASH chip off the board. Write a normal program to the new chip with a programmer commonly used in the development of single-chip microcomputer, and then solder it back. In addition to needing the necessary tools, you also need to be backed up by normal procedures.


     To sum up:         
      openwrt is a linux system, you need to use bootloader to boot
      openwrt and bootloader are located in different areas on the same FLASH chip.
      Bootloader will provide some convenient means to enable us to use the new openwrt firmware during the development process

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325815393&siteId=291194637