In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to understand the embedded Linux system online upgrade strategy, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Due to the dispersion, large number and complex deployment location of most embedded devices on the market, the implementation of individual and local upgrades for these devices is very time-consuming and laborious. In view of this situation, this paper provides a strategy for online, remote and batch upgrade of embedded devices based on Linux system, which visually displays the equipment status and upgrade process through the web page, which greatly provides the upgrade efficiency.
Online upgrade Strategy of embedded Linux system
For embedded products running Linux systems, we often want to replace and upgrade the current running devices after we find the current version of the kernel, driver, or application bug and fix it, or when we develop a richer and more outstanding application software. The practice of many people is to update the software version by burning the new version of the software on each device. If the number of products is small and the distribution location is more concentrated, this scheme has a certain effectiveness. However, when the number of devices is large and the locations are scattered, this local burning and writing upgrade method will become very difficult to operate, and the visualization of the upgrade results is difficult, which can only be confirmed through the serial port and other terminals.
For embedded devices that use Linux system and have the ability to access the Internet, no matter whether the access mode is wired network, wifi, 2G or 4G, this paper will provide an efficient, reliable and intuitive upgrade strategy for all or some of the online devices through the server background. The upgrade can be a kernel, driver, file system, application, or some configuration file. Next, we will first show the architecture diagram of the solution, followed by a step-by-step description of the details of each function or logical module.
Overview of the solution
The upgrade scheme consists of three parts: the background server program, the web page and the terminal upgrade program. Figure 1 shows the architecture of the upgrade scheme.
Figure 1. Upgrade scheme architecture diagram
Server program
Server programs are used to monitor the status of terminal devices, manage upgrade packages, control the upgrade process and provide web-side responses and database access. In this strategy, the server is apache-tomcat, the program is java servlet, and the database is MySQL,web page and JSP. You can use any background language (such as php, python, etc.) to implement the server-side functions described in this article.
Server-side functions include:
Terminal message processing
Upgrade package management
Upgrade instruction processing
Terminal message processing
The server program obtains the terminal software version number through getParameter ("version"), queries the * * software version number in the database through queryLatestVersion (), and then compares the two. If it is the same, it proves that the software version of the terminal device is *, and the latest instruction is returned. If it is different and the server does not receive the upgrade instruction from the web end user, the address of the * * upgrade package is queried from the database by queryAddress () and returned to the terminal so that the terminal device can download the upgrade package from the address. In addition, if the user executes the upgrade command in the web interface at this time, the update instruction is returned to the terminal and the terminal device performs the upgrade operation. Take a look at listing 1 for details.
Listing 1. Terminal message processing code snippet
Public void doGet (HttpServletRequest request, HttpServletResponse response)\ throws ServletException, IOException {String msg = null; String version_latest = null; String address_latest = null; String version = request.getParameter ("version"); PrintWriter out = response.getWriter (); version_latest = queryLatestVersion (); if (version.equals (version_latest)) {msg = "| latest | null | null |";} else if (UpdateServlet.update_status) {msg = "| update |" + version_latest+ "| null |" UpdateServlet.update_status = false;} else {address_latest = queryAddress (); msg = "| download | 172.x.x.x" + address_latest+ "|" + MD5+ "|";} out.print (msg); out.flush (); out.close ();}
Upgrade package management
The server program processes the upgrade package uploaded by the web. First, it confirms whether the path where the upgrade package is stored exists. If not, create it. After the upgrade package is received, the version number is intercepted from the upgrade package file name, and then the file name, version number and the storage path information of the upgrade package on the server side are inserted into the database. Similarly, the server program also responds to the changes, deletions and other actions made by the web users to the upgrade package. See listing 2 for detailed upgrade package management.
Listing 2. Upgrade package management code snippet
Protected void doPost (HttpServletRequest request,\ HttpServletResponse response) throws ServletException, IOException {String uploadPath = "/ xx/xx"; File uploadDir = new File (uploadPath); if (! uploadDir.exists ()) {uploadDir.mkdir ();} try {List formItems = upload.parseRequest (request) If (formItems! = null & & formItems.size () > 0) {for (FileItem item: formItems) {if (! item.isFormField ()) {String fileName = new File (item.getName ()). GetName (); Patternp=Pattern.compile ("update_package- (. *?). Tar.gz"); Matcherm=p.matcher (fileName) While (m.find ()) {version = m.group (1);} String filePath = uploadPath + File.separator + fileName; sql = "INSERT INTO package (name,version,address)\ VALUES ('" + fileName+ "','" + version+ "','" + filePath+ "');" DbOperate (sql); File storeFile = new File (filePath); item.write (storeFile); request.setAttribute ("message",\ "Package Has beed uploaded successfully!") } catch (Exception ex) {request.setAttribute ("message", "error info:" + ex.getMessage ());}}
Upgrade instruction processing
If the user selects the upgrade device from the web side and clicks the upgrade button, the server program will record the instruction, and the next time it receives the POST message from the terminal device, it will issue the update upgrade instruction to the designated terminal, and the terminal will execute the upgrade procedure after receiving the update command. After the upgrade is completed, the terminal will periodically report its version number, and you can view the upgrade results of all devices through the list of devices on the web side, so that the upgrade process and results can be visualized.
Terminal upgrade program
The terminal upgrade program consists of two parts: the upgrade management program and the upgrade execution program. The prerequisite for the upgrade strategy described in this article is to build reasonable disk and Flash partitions in order to support the normal operation of various programs in this strategy.
Terminal disk partition exampl
Figure 2. Terminal device disk partition map
Figure 2 is an example of a basic Flash partition for this policy. The total capacity of Flash is 128m. The boot partition is used to store the boot program of the Linux system with a capacity of 2m. The second partition is the Linux kernel partition, which is used to store the Linux kernel image files with a capacity of 8m. The third partition is the root file system partition, which is used to store the root file system image files and as the runtime user operating space, with a capacity of 100m. The fourth is the backup partition, which is used to store the content you want to back up, so that it can be copied to the new file system after the upgrade is completed. The capacity is 16m. * one is the solidified information partition, which is used to store the device software version number, device type, device id and other information, capacity 2m. The partition information is for reference only. The number and size of zones need to be modified according to the specific project. Of course, if the project has no particularity and the hardware resources match the example, this partitioning scheme can also be used directly.
Upgrade management program
The upgrade Manager functions are as follows:
Manage software version information
POST device information to the server
Download the upgrade package from the server
Verification, managing upgrade packs
Start the upgrade execution program
The upgrade manager starts when the system boots and runs as a daemon. * the software version number is read from the macro definition and solidified into the info partition, and the device type, device id, and software version number are read from the info partition at regular intervals. And send this information to the server through HTTP POST. After receiving the device information, the server parses the software version number and compares it with the upgrade package version number in the database. If the upgrade package version number is higher than the device version number, the download instruction, the upgrade package address and the upgrade package MD5 code are returned to the terminal device.
Table 1. Terminal device information message format
Table 2. The server returns the message format
Tables 1 and 2 show the format and content of messages sent by the terminal device and returned by the server, respectively.
The upgrade manager receives a message from the server to parse it, and responds as follows according to different instructions:
If the instruction is download, the corresponding upgrade package is downloaded to the local tmp directory of the terminal device according to the address provided by parameter 1. After the download is completed, the MD5 code of the upgrade package is compared with that in parameter 2 to complete the verification of the upgrade package.
If the directive is update, compare the version number in parameter 1 with the upgrade package version number in the local tmp directory. If the same, the upgrade executor will be started to upgrade.
If the instruction is latest, it proves that the software version of the current terminal device is the same as that of the * upgrade package in the server, which is already * version, and will be ignored.
Upgrade execution program
The functions of the upgrade executor are as follows:
Extract the upgrade package
Backup file
Format kernel, file system partition
Load the files from the upgrade package to the kernel and file system partition
Restart the operating system
Copy backup files to the file system
When the upgrade execution program is started by the upgrade management program, first decompress the upgrade package, and verify and test it. If the test passes, start backing up the user files. It is important to note that the backup partition is mounted on the root backup folder of the file system, so the backup method is to copy the files that need to be backed up to the backup folder and record their original path. The next step is to format the kernel and file system partitions, and then write the new version of the kernel image and file system image in the upgrade package to the kernel and root file system partition to complete the replacement between the old and the new. Then automatically restart the operating system, and after starting successfully, copy the backup files to the corresponding file system path. At this time, the terminal equipment has been upgraded and the new version of the system and software is running. If the upgrade content is only an application or configuration file, you only need to replace the corresponding file.
Interaction between device and server
The terminal device interacts with the server through the HTTP protocol. The terminal program sends device information to the server HTTP POST every 10 seconds, and the server returns three different instructions to the terminal device according to the comparison result of the version number and the upgrade instruction status of the web side. The terminal responds accordingly by parsing the instruction. The download function calls the libcurl library and has the ability to resume transmission at breakpoints. The request frequency of 10 seconds can be adjusted according to the specific project application scenario. If the number of terminals is small and the server can withstand the connection pressure, if you want to respond more quickly and timely, you can consider changing HTTP to socket persistent connection.
Web end
The Web side provides a man-machine interface for users to upgrade, display, receive and track the whole upgrade process. It is written in JSP. Its functions are as follows:
Displays the device status. Displays the device online and offline status, device type, device id, and software version number.
Upgrade package management. Show all upgrade packages, modify and delete existing upgrade packages, etc. Upload a new upgrade package.
Upgrade operation management. Users can select multiple and all devices through the device list and click the upgrade button to generate upgrade instructions.
Summary
This paper provides a strategy for batch upgrade of embedded Linux devices by remote online mode, including kernel, driver, file system, application, configuration file and so on. Can quickly and stably complete the upgrade operation. This paper describes the server program, terminal equipment upgrade program, web function, device and server interaction mode, and fully shows the details of the upgrade process for developers' reference.
It should be noted that during the implementation of this strategy, it is necessary to ensure that the upgrade equipment has sufficient power to ensure the smooth execution of the upgrade process. This strategy only provides a functional description. In order to ensure reliability and adapt to a more complex environment, developers need to add a dual-partition startup backup mechanism. In addition, because the upgrade package is stored in the tmp directory, the size of the upgrade package that can be supported is limited by the physical memory space, and developers can store the upgrade package in the specified disk partition to optimize this feature.
The above is how to understand the embedded Linux system online upgrade strategy, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
Mysql instance shell: docker run-- name mysql-server-t\-e MYSQL_DATABASE= "zabbix"\-e MYSQL_US
© 2024 shulou.com SLNews company. All rights reserved.