Uboot environment variable upgrading method and device of linux system

By downloading and comparing the Uboot environment variable upgrade package during device startup, parsing and merging the environment variable content, the problem of environment variable overwriting and loss in existing technologies is solved, ensuring that user environment variables are retained, and improving system stability and user experience.

CN121807348APending Publication Date: 2026-04-07HANGZHOU JIEFENG TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-15
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

In existing technologies, Uboot environment variable upgrades cause user-mode environment variables and other runtime environment variables to be overwritten and lost, affecting the normal operation of system modules and user experience.

Method used

When the device starts up, the upgrade package is downloaded, the environment variable content is parsed and compared, merged and saved to Flash, user environment variables are retained, and new variables are updated or added.

Benefits of technology

This feature ensures that user environment variables are preserved during the upgrade process, preventing them from being erased, thus guaranteeing the normal operation of system modules and improving the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121807348A_ABST
    Figure CN121807348A_ABST
Patent Text Reader

Abstract

The invention provides a uboot environment variable upgrading method and device of a linux system, and the method comprises the steps: downloading an upgrade package when equipment is started and upgrade is detected; judging whether an environment variable partition exists in the upgrade package or not; if yes, analyzing the environment variable partition to obtain environment variable content in the upgrade package, and storing the environment variable content in a memory; reading the existing environment variable content in the Flash of the equipment, and storing the environment variable content in a memory; comparing the environment variable content in the upgrade package with the existing environment variable content to obtain a comparison result; the comparison results are fused to obtain a new environment variable, and the new environment variable is stored in Flash; after upgrading is completed, restarting is conducted, and the system is started through a new environment variable; new environment variables can be written in, values of original system environment variables can be updated, the environment variables stored by a user are reserved, and the environment variables are prevented from being erased to affect use of the environment variables.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of software upgrade technology, and in particular to a method and apparatus for upgrading uboot environment variables in Linux systems. Background Technology

[0002] With the continuous updating of technology, electronic devices are generally upgraded with firmware regularly after leaving the factory to fix old bugs, iterate and add new technologies, improve user experience, increase product competitiveness and retain customers as much as possible.

[0003] Firmware upgrades typically do not include U-Boot environment variables; they only upgrade the application firmware. The Linux system's environment variable partition stores the kernel boot parameters, partition address, boot memory address, system memory, and other environment variables required for system startup, as well as those set by the user in later use. However, if the firmware partition must be modified, the upgrade requires upgrading the U-Boot environment variables to include the modified partition address. Otherwise, the modified partition will fail to run because the Linux kernel mounts it using the old partition address.

[0004] The existing U-Boot environment variable upgrades replace the entire environment variable partition and write it to Flash, completely overwriting the old U-Boot environment variables.

[0005] This type of upgrade will cause the application environment variables set and saved in user mode during previous use, as well as some other runtime environment variables set later, to be overwritten and lost. Although this will not affect the system startup and operation, it will affect the timely operation of modules that use the lost environment variables. They can only be reset and saved again when used again, which will have a negative impact on firmware upgrades and user experience. Summary of the Invention

[0006] In view of this, the purpose of the present invention is to provide a method and apparatus for upgrading uboot environment variables in a Linux system, which can both write new environment variables and update the values ​​of existing system environment variables, while retaining user-saved environment variables and preventing them from being erased and affecting their use.

[0007] In a first aspect, embodiments of the present invention provide a method for upgrading uboot environment variables in a Linux system, the method comprising: When the device starts up and detects an upgrade, download the upgrade package; Determine whether an environment variable partition exists within the upgrade package; If so, the environment variable partition is parsed to obtain the environment variable content within the upgrade package and saved to memory; Read the existing environment variable content in the Flash memory of the device and save it to the memory; The environment variable content in the upgrade package is compared with the existing environment variable content to obtain the comparison result; The comparison results are fused to obtain new environmental variables, which are then saved to the Flash memory. After the upgrade is complete, restart and start the system with the new environment variables.

[0008] Furthermore, the environment variable content within the upgrade package is compared with the existing environment variable content to obtain the comparison results, including: When the environment variables in the upgrade package share common environment variables with the existing environment variables, the common environment variables are updated to the new values ​​in the upgrade package.

[0009] Furthermore, the environment variable content within the upgrade package is compared with the existing environment variable content to obtain the comparison results, including: If an environment variable present in the upgrade package does not exist in the device, the environment variable present in the upgrade package will be added to the device.

[0010] Furthermore, the environment variable content within the upgrade package is compared with the existing environment variable content to obtain the comparison results, including: If the existing environment variables in the device are not present in the upgrade package, the existing environment variables in the device will be retained.

[0011] Secondly, embodiments of the present invention provide a uboot environment variable upgrade device for a Linux system, the device comprising: The download module is used to download the upgrade package when the device starts up and detects an upgrade. The determination module is used to determine whether an environment variable partition exists in the upgrade package; The parsing module is used to parse the environment variable partition when the environment variable partition exists, obtain the environment variable content in the upgrade package, and save it to memory; The reading module is used to read the existing environment variable content in the Flash memory of the device and save it to the memory. The comparison module is used to compare the environment variable content in the upgrade package with the existing environment variable content to obtain the comparison result; The fusion module is used to fuse the comparison results to obtain new environmental variables and save them to the Flash memory. The restart module is used to restart the system after the upgrade is complete and to start the system with the new environment variables.

[0012] Furthermore, the comparison module is specifically used for: When the environment variables in the upgrade package share common environment variables with the existing environment variables, the common environment variables are updated to the new values ​​in the upgrade package.

[0013] Furthermore, the comparison module is specifically used for: If an environment variable present in the upgrade package does not exist in the device, the environment variable present in the upgrade package will be added to the device.

[0014] Furthermore, the comparison module is specifically used for: If the existing environment variables in the device are not present in the upgrade package, the existing environment variables in the device will be retained.

[0015] Thirdly, embodiments of the present invention provide an electronic device, including a memory and a processor, wherein the memory stores a computer program that can run on the processor, and the processor executes the computer program to implement the method described above.

[0016] Fourthly, embodiments of the present invention provide a computer-readable medium having processor-executable non-volatile program code that causes the processor to perform the method described above.

[0017] This invention provides a method and apparatus for upgrading u-boot environment variables in a Linux system, comprising: when the device boots up and detects an upgrade, downloading an upgrade package; determining whether an environment variable partition exists within the upgrade package; if so, parsing the environment variable partition to obtain the environment variable content within the upgrade package and saving it to memory; reading the existing environment variable content in the device's Flash memory and saving it to memory; comparing the environment variable content within the upgrade package with the existing environment variable content to obtain a comparison result; and fusing the comparison result to obtain new environment variables and saving them to Flash memory. After the upgrade is complete, the system will restart and start with the new environment variables. It can write new environment variables and update the values ​​of the original system environment variables, retaining the environment variables saved by the user and preventing them from being erased and affecting their use.

[0018] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention are realized and obtained in accordance with the structures particularly pointed out in the description, claims and drawings.

[0019] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0020] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0021] Figure 1 This is a flowchart of the uboot environment variable upgrade method for a Linux system provided in Embodiment 1 of the present invention; Figure 2 This is a schematic diagram of the uboot environment variable upgrade device for a Linux system provided in Embodiment 2 of the present invention. Detailed Implementation

[0022] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0023] To facilitate understanding of this embodiment, the embodiments of the present invention will be described in detail below.

[0024] Example 1: Figure 1 This is a flowchart of the uboot environment variable upgrade method for a Linux system provided in Embodiment 1 of the present invention.

[0025] Reference Figure 1 The method includes the following steps: Step S101: When the device starts up and detects an upgrade, download the upgrade package; Here, during the upgrade process, if no upgrade is needed, the application services will continue to operate normally.

[0026] Step S102: Determine whether an environment variable partition exists within the upgrade package; Step S103: If yes, then parse the environment variable partition to obtain the environment variable content in the upgrade package and save it to memory; Step S104: Read the existing environment variable content in the device's Flash memory and save it to memory; Step S105: Compare the environment variable content in the upgrade package with the existing environment variable content to obtain the comparison result; Step S106: Merge the comparison results to obtain new environment variables and save them to Flash. Step S107: After the upgrade is complete, restart and start the system with the new environment variables.

[0027] Furthermore, step S105 includes: When the environment variables in the upgrade package share common environment variables with the existing environment variables, the common environment variables will be updated to the new values ​​in the upgrade package.

[0028] Furthermore, step S105 includes: If an environment variable present in the upgrade package does not exist on the device, the environment variable present in the upgrade package will be added to the device.

[0029] Furthermore, step S105 includes: If existing environment variables in the device are not present in the upgrade package, the existing environment variables in the device will be retained.

[0030] Specifically, when the device starts up and detects an upgrade, it downloads the upgrade package; it checks whether there is an environment variable partition in the upgrade package; if so, it parses the environment variable partition to obtain the environment variable content in the upgrade package and saves it to memory; it reads the existing environment variable content in the device's Flash and saves it to memory; it compares the environment variable content in the upgrade package with the existing environment variable content one by one: 1) environment variables that exist in both are updated with the new values ​​in the upgrade package; 2) Add environment variables that were not originally present in the device but are present in the upgrade package; 3) Environment variables that already exist in the device but are not included in the upgrade package will be retained.

[0031] The above three comparison results are merged to obtain new environment variables, which are then saved to Flash. If there are other partition upgrades, the process continues. After the upgrade is complete, the system is restarted and started with the new environment variables. This process can both write new environment variables and update the values ​​of existing system environment variables, while preserving user-saved environment variables to prevent them from being erased and affecting their use.

[0032] Examples of Linux system kernel boot parameters, partition address formats, and contents are as follows:

[0033] Here, env is the environment variable partition, and boot, romfs, usr, web, custom, and mtd are the various partitions in the flash memory; mtdroot= / dev / mtdblock1 is the file system partition number that the kernel will boot from; here, the boot partition is mtdblock0, and mtdblock1 is the romfs partition, i.e., the file system partition.

[0034] This application optimizes the upgrade method for environment variable partitions, solving the drawbacks of losing original user environment variables caused by writing the entire environment variable partition to Flash and completely overwriting the original environment variable partition content in the device with the newly upgraded environment variable partition. The new method can not only write new environment variables, but also update the values ​​of the original system environment variables and retain the environment variables saved by users, preventing them from being erased and affecting their use.

[0035] Example 2: Figure 2 This is a schematic diagram of the uboot environment variable upgrade device for a Linux system provided in Embodiment 2 of the present invention.

[0036] Reference Figure 2 The device includes: The download module is used to download the upgrade package when the device starts up and detects an upgrade. The judgment module is used to determine whether an environment variable partition exists in the upgrade package; The parsing module is used to parse the environment variable partition when an environment variable partition exists, obtain the environment variable content within the upgrade package, and save it to memory; The read module is used to read the existing environment variable contents in the device's Flash memory and save them to memory; The comparison module is used to compare the environment variable content in the upgrade package with the existing environment variable content and obtain the comparison result; The fusion module is used to fuse the comparison results, obtain new environment variables, and save them to Flash. The restart module is used to restart the system after the upgrade is complete and start the system with the new environment variables.

[0037] Furthermore, the comparison module is specifically used for: When the environment variables in the upgrade package share common environment variables with the existing environment variables, the common environment variables will be updated to the new values ​​in the upgrade package.

[0038] Furthermore, the comparison module is specifically used for: If an environment variable present in the upgrade package does not exist on the device, the environment variable present in the upgrade package will be added to the device.

[0039] Furthermore, the comparison module is specifically used for: If existing environment variables in the device are not present in the upgrade package, the existing environment variables in the device will be retained.

[0040] The environment variable upgrade method of this application can effectively avoid the overwriting and loss of application environment variables and other runtime environment variables set and saved by the user during the previous use process due to the upgrade of the entire environment variable partition. The relevant modules of the environment variables set and saved during the original use process can still run as expected by the user. There is no need to re-set them after the upgrade, and there will be no feeling of a significant impact caused by the firmware upgrade, thus avoiding a deterioration in the user experience.

[0041] This invention provides a method and apparatus for upgrading u-boot environment variables in a Linux system, comprising: when the device boots up and detects an upgrade, downloading an upgrade package; determining whether an environment variable partition exists within the upgrade package; if so, parsing the environment variable partition to obtain the environment variable content within the upgrade package and saving it to memory; reading the existing environment variable content in the device's Flash memory and saving it to memory; comparing the environment variable content within the upgrade package with the existing environment variable content to obtain a comparison result; and fusing the comparison result to obtain new environment variables and saving them to Flash memory. After the upgrade is complete, the system will restart and start with the new environment variables. It can write new environment variables and update the values ​​of the original system environment variables, retaining the environment variables saved by the user and preventing them from being erased and affecting their use.

[0042] This invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps of the uboot environment variable upgrade method for the Linux system provided in the above embodiments.

[0043] This invention also provides a computer-readable medium having processor-executable non-volatile program code, on which a computer program is stored, and which, when run by a processor, executes the steps of the uboot environment variable upgrade method of the Linux system described above.

[0044] The computer program product provided in this embodiment of the invention includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the preceding method embodiments. For specific implementation details, please refer to the method embodiments, which will not be repeated here.

[0045] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system and apparatus described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0046] Furthermore, in the description of the embodiments of the present invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in the present invention based on the specific circumstances.

[0047] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0048] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.

[0049] Finally, it should be noted that the above-described embodiments are merely specific implementations of the present invention, used to illustrate the technical solutions of the present invention, and not to limit it. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed in the present invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A method for upgrading u-boot environment variables in a Linux system, characterized in that, The method includes: When the device starts up and detects an upgrade, download the upgrade package; Determine whether an environment variable partition exists within the upgrade package; If so, the environment variable partition is parsed to obtain the environment variable content within the upgrade package and saved to memory; Read the existing environment variable content in the Flash memory of the device and save it to the memory; The environment variable content in the upgrade package is compared with the existing environment variable content to obtain the comparison result; The comparison results are fused to obtain new environmental variables, which are then saved to the Flash memory. After the upgrade is complete, restart and start the system with the new environment variables.

2. The method for upgrading u-boot environment variables in a Linux system according to claim 1, characterized in that, The environment variable content within the upgrade package is compared with the existing environment variable content to obtain the comparison results, including: When the environment variables in the upgrade package share common environment variables with the existing environment variables, the common environment variables are updated to the new values ​​in the upgrade package.

3. The method for upgrading u-boot environment variables in a Linux system according to claim 1, characterized in that, The environment variable content within the upgrade package is compared with the existing environment variable content to obtain the comparison results, including: If an environment variable present in the upgrade package does not exist in the device, the environment variable present in the upgrade package will be added to the device.

4. The method for upgrading u-boot environment variables in a Linux system according to claim 1, characterized in that, The environment variable content within the upgrade package is compared with the existing environment variable content to obtain the comparison results, including: If the existing environment variables in the device are not present in the upgrade package, the existing environment variables in the device will be retained.

5. A U-Boot environment variable upgrade device for a Linux system, characterized in that, The device includes: The download module is used to download the upgrade package when the device starts up and detects an upgrade. The judgment module is used to determine whether an environment variable partition exists in the upgrade package; The parsing module is used to parse the environment variable partition when the environment variable partition exists, obtain the environment variable content in the upgrade package, and save it to memory; The reading module is used to read the existing environment variable content in the Flash memory of the device and save it to the memory. The comparison module is used to compare the environment variable content in the upgrade package with the existing environment variable content to obtain the comparison result; The fusion module is used to fuse the comparison results to obtain new environmental variables and save them to the Flash memory. The restart module is used to restart the system after the upgrade is complete and to start the system with the new environment variables.

6. The u-boot environment variable upgrade device for a Linux system according to claim 5, characterized in that, The comparison module is specifically used for: When the environment variables in the upgrade package share common environment variables with the existing environment variables, the common environment variables are updated to the new values ​​in the upgrade package.

7. The u-boot environment variable upgrade device for a Linux system according to claim 5, characterized in that, The comparison module is specifically used for: If an environment variable present in the upgrade package does not exist in the device, the environment variable present in the upgrade package will be added to the device.

8. The u-boot environment variable upgrade device for a Linux system according to claim 5, characterized in that, The comparison module is specifically used for: If the existing environment variables in the device are not present in the upgrade package, the existing environment variables in the device will be retained.

9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program executable on the processor, characterized in that, When the processor executes the computer program, it implements the method described in any one of claims 1 to 4.

10. A computer-readable medium having processor-executable non-volatile program code, characterized in that, The program code causes the processor to execute the method described in any one of claims 1 to 4.