Configuration information management method and electronic equipment

By using environment variable partitioning to store configuration information in embedded systems and automatically converting it into UCI configuration files, the problem of configuration loss when devices are restored to factory settings is solved, achieving high system reliability and business continuity, simplifying the configuration process, and improving security.

CN121764541APending Publication Date: 2026-03-31SHENZHEN MINEW 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-11-20
Publication Date
2026-03-31

AI Technical Summary

Technical Problem

In embedded systems, when a device is restored to factory settings, user-defined configuration information is lost, leading to service interruption, low system reliability, and the traditional method requires manual reconfiguration, which affects production line efficiency and safety.

Method used

The configuration information that needs to be persisted is stored in the environment variable partition of the storage device, saved in the form of structured environment variables, and automatically converted into file system configuration information when the system starts. By parsing the environment variables, a UCI configuration file is generated to achieve the persistence and automatic reconstruction of configuration information.

Benefits of technology

It improved system reliability and business continuity, simplified the configuration process, reduced maintenance costs, increased production line efficiency, and enhanced the security of configuration information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121764541A_ABST
    Figure CN121764541A_ABST
Patent Text Reader

Abstract

The invention provides a configuration information management method and electronic equipment, and relates to the technical field of embedded systems. In view of the problems of long-time interruption of business service and low system reliability caused by complete loss of traditional configuration information, the configuration information management method provided by the invention comprises the following steps: in a system starting process, obtaining a structured environment variable stored in an environment variable partition of a memory; analyzing the structured environment variable to obtain configuration attribute information corresponding to each field of the structured environment variable; and based on the configuration attribute information, generating configuration information corresponding to the structured environment variable in a target configuration file under a target directory of the file system. According to the embodiment of the invention, the system reliability and service continuity can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of embedded systems technology, and in particular to a configuration information management method and electronic device. Background Technology

[0002] In embedded systems, such as OpenWrt, all configuration files are stored in a file system under a dedicated system configuration directory ( / etc / config / directory). When a device performs a factory reset, the entire file system is reset to the initial state in the firmware, and all user-defined configurations are completely erased. For some application scenarios that require the retention of specific configurations (such as device authentication information, server addresses, etc.), the complete loss of the corresponding configuration information necessitates manual reset, leading to prolonged service interruptions and low system reliability. Summary of the Invention

[0003] According to various embodiments of this application, a configuration information management method and electronic device are provided; which can improve system reliability and business continuity.

[0004] Firstly, this application provides a configuration information management method, which includes: During system startup, the system retrieves the structured environment variables stored in the environment variable partition of the storage device; parses the structured environment variables to obtain the configuration attribute information corresponding to each field of the structured environment variables; and generates the configuration information corresponding to the structured environment variables in the target configuration file under the target directory of the file system based on the configuration attribute information.

[0005] By using the above method, the configuration information that needs to be persistently saved is stored in the environment variable partition of the storage device. It will not be cleared when the system is restored to factory settings or restarted. During the system startup process, the corresponding structured environment variables can be read from the environment variable partition. Then, by parsing the structured environment variables, the configuration information in the file system is automatically generated. While ensuring that the configuration information is not completely cleared, the system can automatically complete the reconfiguration at startup, thereby improving business continuity and system reliability. It has strong ease of use and practicality.

[0006] In one possible implementation of the first aspect, the structured environment variables are stored in a key-value pair format; parsing the structured environment variables to obtain the configuration attribute information corresponding to each field of the structured environment variables includes: Parse the keys of the structured environment variables to obtain the directory identifier, type identifier, encryption identifier, configuration file name, and configuration section identifier; The configuration attribute information includes the directory identifier, the type identifier, the encryption identifier, the configuration file name, and the configuration segment identifier.

[0007] In one possible implementation of the first aspect, generating the configuration information corresponding to the structured environment variable in the configuration file under the target directory of the file system based on the configuration attribute information includes: The target directory is determined based on the directory identifier; Based on the type identifier, determine the configuration type to be executed; The target configuration file is determined based on the configuration file name; Based on the configuration segment identifier, the target configuration segment is determined; Based on the values ​​of the structured environment variables, configuration information corresponding to the target configuration section in the target configuration file under the target directory is generated according to the configuration type.

[0008] In one possible implementation of the first aspect, the type identifier includes a configuration segment creation type; the step of generating configuration information corresponding to the structured environment variable in the target configuration file under the target directory of the file system based on the configuration attribute information includes: When the type identifier is the creation configuration segment type, the target directory is determined based on the directory identifier; The target configuration file is determined based on the configuration file name; Based on the configuration segment identifier, the target configuration segment to be configured is determined; Based on the values ​​of the structured environment variables, generate the configuration segment type corresponding to the target configuration segment; The configuration information includes the target directory, the target configuration file, the target configuration section, and the configuration section type.

[0009] In one possible implementation of the first aspect, the type identifier includes a single-value configuration type; the step of generating configuration information corresponding to the structured environment variable in the target configuration file under the target directory of the file system based on the configuration attribute information includes: When the type identifier is the single-value configuration type, the target configuration file under the target directory is determined based on the directory identifier and the configuration file name; Based on the configuration segment identifier, the target configuration segment to be configured is determined; Based on the option keys and values ​​of the structured environment variables, generate option values ​​corresponding to the target options in the target configuration segment; The configuration information includes the option values.

[0010] In one possible implementation of the first aspect, the type identifier includes an array configuration type; generating the configuration information corresponding to the structured environment variable in the target configuration file under the target directory of the file system based on the configuration attribute information includes: When the type identifier is the array configuration type, the target configuration file under the target directory is determined based on the directory identifier and the configuration file name; Based on the configuration segment identifier, the target configuration segment to be configured is determined; Based on the list keys and values ​​of the structured environment variables, generate list elements corresponding to the target list in the target configuration segment; The configuration information includes the list elements.

[0011] In one possible implementation of the first aspect, the type identifier includes a file configuration type; generating configuration information corresponding to the structured environment variable in the target configuration file under the target directory of the file system based on the configuration attribute information includes: When the type identifier is the file configuration type, the target configuration file under the target directory is determined based on the directory identifier and the configuration file name; Based on the configuration segment identifier, the target configuration segment to be configured is determined; Based on the values ​​of the structured environment variables, the file path and file content in the file system are determined; Based on the file path, a corresponding data file is created in the file system, and the file content is written into the data file; Based on the file key of the structured environment variable and the file path, generate the file path option corresponding to the target configuration section in the target configuration file; The configuration information includes the data file and the file path options.

[0012] In one possible implementation of the first aspect, generating the configuration information corresponding to the structured environment variable in the target configuration file under the target directory of the file system based on the configuration attribute information further includes: Based on the encryption identifier, determine whether the value of the structured environment variable is in an encrypted state; When the value of the structured environment variable is in the encrypted state, the configuration information is obtained by decrypting the value of the structured environment variable.

[0013] In one possible implementation of the first aspect, the method further includes: For the configuration information to be saved, the structured environment variables are generated according to a preset format and persistently stored in the environment variable partition.

[0014] Secondly, this application provides a configuration information management device, comprising: The acquisition unit is used to acquire structured environment variables stored in the environment variable partition of the memory during system startup. The parsing unit is used to parse the structured environment variable to obtain the configuration attribute information corresponding to each field of the structured environment variable; The configuration unit is used to generate configuration information corresponding to the structured environment variables in the target configuration file under the target directory of the file system based on the configuration attribute information.

[0015] Thirdly, this application provides an electronic device including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the method described in any one of the first aspects.

[0016] Fourthly, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in any one of the first aspects.

[0017] Fifthly, this application provides a computer program product that, when run on a device, causes the device to perform the method described in any one of the first aspects above.

[0018] It is understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here. Attached Figure Description

[0019] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0020] Figure 1 This is a schematic diagram of the memory partition layout provided in an embodiment of this application; Figure 2 A schematic diagram illustrating the implementation flow of the configuration information management method provided in this application embodiment; Figure 3 This is a schematic diagram of the configuration information management device provided in the embodiments of this application; Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0021] The embodiments of the technical solution of this application will now be described in detail with reference to the accompanying drawings. These embodiments are only used to more clearly illustrate the technical solution of this application and are therefore merely examples, and should not be used to limit the scope of protection of this application.

[0022] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains; the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the application; the terms “comprising” and “having”, and any variations thereof, in the specification, claims, and foregoing description of the drawings are intended to cover non-exclusive inclusion.

[0023] In the description of the embodiments of this application, technical terms such as "first" and "second" are used only to distinguish different objects and should not be construed as indicating or implying relative importance or implicitly specifying the number, specific order, or primary and secondary relationship of the indicated technical features. In the description of the embodiments of this application, "multiple" means two or more, unless otherwise explicitly defined.

[0024] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0025] In the description of the embodiments in this application, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " in this document generally indicates that the preceding and following related objects have an "or" relationship.

[0026] In embedded systems, such as OpenWrt, all configuration files are stored in the file system under the system configuration directory ( / etc / config / directory). When the device performs a factory reset, the entire file system is reset to the initial state in the firmware, resulting in the loss of all user-defined configurations. This causes serious problems for scenarios that require the retention of specific configurations, such as the need for manual reconfiguration, which leads to long-term interruptions in business services and poor system reliability.

[0027] Furthermore, different configuration information needs to be set for different users. For example, user A needs to connect to server A and use a specific message queue telemetry transport (MQTT) configuration; while user B requires different network parameters and security certificates. Traditionally, this requires compiling a separate firmware version for each user, leading to an explosive increase in the number of firmware versions and extremely high maintenance costs. Moreover, during mass production, each device needs to be configured independently, which is time-consuming and affects production line efficiency; manual operation is prone to errors, making it difficult to guarantee yield rates; at the same time, there is a lack of standardized configuration interfaces, resulting in inconsistent operations across different production lines. Currently, configuration information is stored in plaintext. Once the storage chip is physically read, all configuration information (such as passwords, keys, and other sensitive information) will be exposed, posing a serious security risk.

[0028] To address the above technical issues, this application provides a configuration information management method. For embedded Linux systems such as OpenWrt, based on the characteristic that the environment variable partition in the memory is not cleared during factory reset, specific configuration information that needs to be saved is stored in the environment variable partition in the form of structured environment variables, achieving persistent storage of configuration information. Furthermore, the structured environment variables stored in the environment variable partition are automatically converted into configuration information in a Unified Configuration Interface (UCI) configuration file.

[0029] First, we will introduce the partitioning of the memory and its corresponding storage performance.

[0030] Please see Figure 1 , Figure 1 This is a schematic diagram of the memory partition layout provided in an embodiment of this application; the memory can be a flash memory; such as Figure 1 As shown, the storage can include multiple independent partitions, such as a bootloader partition, an environment variable partition, a kernel partition, a root file system partition, and an overwrite partition. The environment variable partition stores content in plaintext key-value pair format; the root file system partition stores configuration information in UCI configuration files under the file system directory ( / etc / config / ).

[0031] In traditional solutions, configuration information is stored in the root file system partition, such as the UCI configuration file under the file system directory ( / etc / config / ). This partition is reset when the factory settings are restored. The overwrite partition is used to store all user modifications to the root file system. When the factory settings are restored, the overwrite partition will be formatted and cleared, resulting in all user-defined configuration information being deleted.

[0032] The contents of the environment variable partition will not be cleared when the system is restored to factory settings. In this embodiment, the environment variable partition is selected, and the configuration information that needs to be persistently stored is stored in the environment variable partition in the form of structured environment variables. When the system starts, the structured environment variables of the environment variable partition are converted into configuration information in the configuration file to support the reading of system services and business applications (such as network, firewall, client, etc.).

[0033] Based on the above storage partitioning architecture, the specific implementation process of this configuration information management method will be described below through an example.

[0034] Please see Figure 2 , Figure 2 This is a schematic diagram illustrating the implementation flow of the configuration information management method provided in this application embodiment; the executing entity of this method can be an embedded device, such as a router, gateway, or other embedded device. Figure 2 As shown, the method may include the following steps: S201, during system startup, retrieves the structured environment variables stored in the environment variable partition of the memory.

[0035] In some embodiments, the memory can be a Flash memory chip on an embedded device; the environment variable partition is an independent, non-volatile storage area on the Flash memory chip, which is usually managed by the bootloader; the system boot process can be the first boot after a factory reset.

[0036] After triggering a factory reset, the system clears the modified content in the Overlay partition and RootFS partition, restoring them to the initial state in the firmware. All UCI configuration files ( / etc / config / ) stored in them are also reset. However, the environment variable partition of the storage chip is not touched during the factory reset operation, and all configuration data is preserved intact, achieving persistent storage of configuration data.

[0037] Accordingly, the above system startup process is the initialization phase in which the system kernel is loaded and started running by the bootloader, but system services (such as network and firewall) have not yet officially started. This ensures that configuration information is set before business services run. The engine reads all pre-stored, structured environment variables that conform to naming conventions from the environment variable partition.

[0038] The basic storage format of this environment variable partition is key-value pairs (key=value); however, this structured environment variable is different from the simple Bootloader environment variable in this environment variable partition. This structured environment variable is encoded through a preset naming convention.

[0039] Accordingly, the system executes the initialization script, reads the environment variable partition, obtains the original environment variable list, filters out the structured environment variables with specific prefixes, and passes the filtered structured environment variables to the subsequent transformation engine.

[0040] In some embodiments, for the configuration information to be saved, structured environment variables are generated in a preset format and persistently stored in the environment variable partition.

[0041] For example, structured environment variables generated according to a preset format are environment variables encoded using a preset naming convention. For instance, the naming convention can be represented as follows: <dir> . <ktype> <stype> . <cfgfile> . <section> . <key> = <value> in, <dir>This represents a directory identifier, which can occupy 1 to 3 characters. This directory identifier can include system configuration 'sys', corresponding to the ' / etc / config / ' directory; it can also include Bluetooth configuration 'ble', corresponding to the ' / etc / config / thingoo / ' directory; it can also include application configuration 'aoa', corresponding to the ' / etc / config / aoa / ' directory; it can also include other extensible directory identifiers, which can be expanded and set according to the needs of actual application scenarios.

[0042] <ktype>This represents the type identifier, which can occupy 1 character. The type identifier can include the creation configuration section type, i.e., the section type, represented by 's'; it can also include the single-value configuration type, i.e., the option type, represented by 'o'; it can also include the array configuration type, i.e., the list type, represented by 'l'; and it can also include the file configuration type, i.e., the file type, represented by 'f', used for configuring file content.

[0043] <stype>'y' indicates an encryption identifier and can occupy 0-1 characters; 'y' indicates that the value part is encrypted and can use the Anti-Misuse Authentication Encryption (AES-GCM-SIV) algorithm; 'n' or empty indicates that the value part is plaintext.

[0044] <cfgfile>This indicates the configuration file name, corresponding to the name of the UCI configuration file, such as system, network, wireless, etc.

[0045] <section>This represents a configuration section identifier, which can include named sections and anonymous sections; named sections can directly use the section name, such as ntp; anonymous sections can use '@'. <sectype>The format is [n], such as '@system[0]'.

[0046] <key>As key, <value>For value; when the type identifier <ktype>When it is 's', <key>When the field is empty, other type identifiers (such as 'o', 'l', 'f') <key>Fields represent names corresponding to type identifiers, such as option names for single-value configuration types (type identifier 'o'), list names for array configuration types (type identifier 'l'), and file paths for file configuration types (type identifier 'f').

[0047] S202, parse the structured environment variables to obtain the configuration attribute information corresponding to each field of the structured environment variables.

[0048] In some embodiments, the structured environment variables read are parsed by a parser to extract the configuration attribute information corresponding to each field; the configuration attribute information can be a series of explicit configuration meta-information that can be directly used by subsequent programs.

[0049] For example, based on the uci-defaults mechanism, during system startup, system initialization and configuration management operations are performed based on the structured environment variables in the environment variable partition. This converts the structured environment variables into configuration information in the standard configuration file, and then generates the corresponding configuration information in the configuration file based on each configuration attribute.

[0050] The configuration attribute information corresponding to each field in the structured environment variable is used to indicate the target location variable in the configuration file to generate the corresponding configuration information, so as to obtain the expected configuration file for subsequent service or business calls.

[0051] In some embodiments, structured environment variables are parsed to obtain configuration attribute information corresponding to each field of the structured environment variables, including: Parse the keys of the structured environment variables to obtain the directory identifier, type identifier, encryption identifier, configuration file name, and configuration section identifier; among which, the configuration attribute information includes the directory identifier, type identifier, encryption identifier, configuration file name, and configuration section identifier.

[0052] For example, structured environment variables are stored in a key-value pair format, such as the part before the equals sign in the naming convention described above. <dir> . <ktype> <stype> . <cfgfile> . <section> . <key>It can be used as the key for the entire structured environment variable; the part after the equals sign. <value>As the value, the configuration attribute information corresponding to each field is determined by parsing and identifying the keys of the structured environment variables: directory identifier, type identifier, encryption identifier, configuration file name, and configuration section identifier.

[0053] S203, based on configuration attribute information, generates configuration information corresponding to structured environment variables in the target configuration file under the target directory of the file system.

[0054] In some embodiments, the target directory and target configuration file are determined based on the directory identifier and configuration file name in the configuration attribute information, and the configuration operation corresponding to the configuration type in the configuration attribute information is executed to generate configuration content that conforms to UCI syntax in the target configuration file, thereby obtaining the configuration information corresponding to the structured environment variable.

[0055] In some embodiments, based on configuration attribute information, configuration information corresponding to structured environment variables is generated in a configuration file in the target directory of the file system, including: Based on the directory identifier, determine the target directory; based on the type identifier, determine the configuration type to be executed; based on the configuration file name, determine the target configuration file; based on the configuration segment identifier, determine the target configuration segment; based on the value of the structured environment variable, generate the configuration information corresponding to the target configuration segment in the target configuration file under the target directory, according to the configuration type.

[0056] For example, directory identifiers in structured environment variables <dir>Used to distinguish different configuration directories; for example, for the parsed directory identifier field, if <dir>If ='sys', then the target directory for the corresponding configuration is determined to be the system configuration directory / etc / config / ; if <dir>If ='ble', then the target directory for the corresponding configuration is determined to be the Bluetooth configuration directory / etc / config / thingoo / ; if <dir>If the value is 'aoa', then the target directory for the corresponding configuration is determined to be the application configuration directory / etc / config / aoa / .

[0057] For example, type identifiers in structured environment variables <ktype>Used to distinguish different configuration types; for example, for the parsed type identifier field, if <ktype>='s', then it is determined to be of type section, used to create configuration sections; if <ktype>If ='o', then it is determined to be of type option, used to configure a single value for the option; if <ktype>='l', then it is determined to be of type list, used to configure the array; if <ktype>If the value is 'f', it is determined to be of type 'file' and used for configuration file content; this enables unified processing of different configuration types.

[0058] For example, encrypted identifiers in structured environment variables <stype>Used to determine whether the value is encrypted; for example, for a parsed encryption identifier field, if <stype>='y', then the value part is determined to be encrypted. <stype>If 'n' is empty, then the value part is confirmed to be plaintext.

[0059] For example, the configuration file name in a structured environment variable. <cfgfile>Used to determine the target configuration file; for example, for the parsed configuration file name field, if <cfgfile>If `='system'`, then the target configuration file is determined to be 'system', meaning the final configuration will be written to the file ` / etc / config / system`; if... <cfgfile>If `='network'`, then the target configuration file is determined to be 'network', meaning the final configuration will be written to the file ` / etc / config / network`; if... <cfgfile>If the value is 'wireless', then the target configuration file is set to 'wireless', meaning the final configuration will be written to the file / etc / config / wireless.

[0060] For example, configuration section identifiers in structured environment variables <section>Used to determine the target configuration segment; for example, for the parsed configuration segment identifier field, if <section>If the value is 'ntp', then the target configuration segment is determined to be the segment named 'ntp', and configuration operations will be performed on this segment. Regarding the parsed key, if... <key>If the key is 'enable', then the configuration item's key is 'enable', which means that the target option is set in the target configuration section.

[0061] Accordingly, the form of configuration information differs for different configuration types. For example, for configuration segment creation, single-value configuration, array configuration, and file configuration types, after determining the target directory and target configuration file, the corresponding standardized configuration lines such as config, option, and list are written into the target configuration file, and the corresponding data files, i.e., the physical files of the entities, are created in the specified path through file configuration operations.

[0062] In some embodiments, the type identifier includes the creation of a configuration segment type; based on the configuration attribute information, generating configuration information corresponding to structured environment variables in the target configuration file under the target directory of the file system includes: When the type identifier is set to create a configuration segment, the target directory is determined based on the directory identifier; the target configuration file is determined based on the configuration file name; the target configuration segment to be configured is determined based on the configuration segment identifier; and the configuration segment type corresponding to the target configuration segment is generated based on the value of the structured environment variable. The configuration information includes the target directory, target configuration file, target configuration segment, and configuration segment type.

[0063] For example, by parsing structured environment variables, the type identifier is identified as the type of configuration segment being created ( <ktype>='s', section type), create the corresponding target directory based on the directory identifier dir, such as 'mkdir -p / etc / config / '; check if the target configuration file exists, and create the configuration file if it does not exist, such as 'touch / etc / config / system'; execute UCI commands to create the target configuration section and generate the corresponding configuration information for the named section or the anonymous section.

[0064] For example, for a named section, its corresponding structured environment variable is set to fw_setenvsys.s.system.ntp timeserver; the target configuration section is created using the UCI command: uci setsystem.ntp=timeserve; and the converted UCI configuration information is generated: config timeserver'ntp'.

[0065] For example, for an anonymous section, its corresponding structured environment variable is set to fw_setenvsys.s.system.@system[0] system. The target configuration section is created by using the UCI command: uci addsystem system; and the converted UCI configuration information is generated: config system.

[0066] In some embodiments, the type identifier includes a single-value configuration type; based on configuration attribute information, configuration information corresponding to structured environment variables is generated in the target configuration file under the target directory of the file system, including: When the type identifier is a single-value configuration type, the target configuration file in the target directory is determined based on the directory identifier and the configuration file name; the target configuration segment to be configured is determined based on the configuration segment identifier; and the option values ​​corresponding to the target options in the target configuration segment are generated based on the option keys and values ​​of the structured environment variables; wherein, the configuration information includes option values.

[0067] For example, by parsing structured environment variables, the type identifier is identified as a single-value configuration type ( <ktype>='o', option type), determines the corresponding target directory in the file system based on the directory identifier dir, such as the ' / etc / config / ' directory; based on the configuration file name <cfgfile>Determine the target configuration file, such as 'etc / config / system'; based on the configuration section identifier. <section>Determine the target configuration segment, and based on the option key and value, determine the target options under the target configuration segment, and generate the option values ​​corresponding to the target options under the target configuration segment.

[0068] For example, for single-value configuration types, the corresponding structured environment variables can be set as follows: fw_setenv sys.o.system.@system[0].hostname 'MyRoute'; fw_setenv sys.o.system.@system[0].timezone 'UTC-8'; After parsing, the location of the target configuration file was determined to be / etc / config / system. The anonymous section @system[0] under the target configuration file was used to determine the corresponding option keys hostname and timezone. The option keys were assigned the values ​​MyRouter and UTC-8 respectively, and the corresponding configuration information was generated. config system option hostname'MyRouter' Option timezone 'UTC-8'.

[0069] For the `option` type, the value set in its structured environment variable must be enclosed in single quotes to maintain consistency with the `uci show` output format. It also supports values ​​containing spaces. During conversion, it automatically handles escape characters. For example, if the value corresponding to the option is `'o'Reilly'`, the conversion engine will escape it, converting it to `'o'\'Reilly'`. The escaped backslashes ensure that the command interpreter shell treats this as a literal single quote, not a delimiter. This ensures that both simple names and complex strings containing special characters are accurately written to the configuration file. `fw_setenv` and `fw_printenv` are environment variable read / write tools provided by U-Boot.

[0070] In some embodiments, the type identifier includes an array configuration type; based on configuration attribute information, configuration information corresponding to structured environment variables is generated in the target configuration file under the target directory of the file system, including: When the type identifier is an array configuration type, the target configuration file in the target directory is determined based on the directory identifier and the configuration file name; the target configuration segment to be configured is determined based on the configuration segment identifier; and list elements corresponding to the target list in the target configuration segment are generated based on the list keys and values ​​of the structured environment variables; wherein, the configuration information includes the list elements.

[0071] For example, by parsing structured environment variables, the type identifier is identified as an array configuration type ( <ktype>='l', list type), determines the corresponding target directory in the file system based on the directory identifier dir, such as the ' / etc / config / ' directory; based on the configuration file name <cfgfile>Determine the target configuration file, such as 'etc / config / system'; based on the configuration section identifier. <section>Determine the target configuration segment, and based on the list key and value, determine the target list under the target configuration segment, and generate the list elements corresponding to the target list under the target configuration segment.

[0072] For example, for the list type, its corresponding structured environment variable can be set as: fw_setenv sys.l.system.ntp.server"'ntp1.aliyun.com''ntp2.aliyun.com''ntp3.aliyun.com'"; After parsing, the location of the target configuration file was determined to be / etc / config / system. Within this target configuration file, the named section ntp was identified, and the corresponding list key was determined to be server. The transformation engine processed the values ​​of the structured environment variables 'ntp1.aliyun.com', 'ntp2.aliyun.com', and 'ntp3.aliyun.com', generating the corresponding configuration information (i.e., list elements): Configure timeserver 'ntp' List servers 'ntp1.aliyun.com' List servers 'ntp2.aliyun.com' list server 'ntp3.aliyun.com'.

[0073] In the structured environment variable representation, each list element must be enclosed in single quotes. An intelligent segmentation algorithm handles spaces within elements, scanning the string character by character to identify single quote pairs and determine that all content between two single quotes (including spaces) constitutes a complete list element. For example, for the structured environment variable values ​​'ntp1.aliyun.com'''ntp2.aliyun.com'''ntp3.aliyun.com', the intelligent segmentation algorithm identifies three pairs of single quotes and outputs a list containing three elements. Correspondingly, the uci add_list command is called multiple times to append elements one by one. The conversion engine iterates through the element list, calling the uci add_list command repeatedly. Each command adds a line of list server 'list element' configuration information to the ntp section of the / etc / config / system file.

[0074] By intelligently identifying element boundaries and splitting long strings packaged in a single structured environment variable into multiple independent elements, and then adding these elements one by one to the specified list in the UCI configuration through a loop, it ensures that both simple lists of server addresses and complex lists of strings containing spaces can be accurately parsed and generate standard multi-line UCI list configurations.

[0075] In some embodiments, the type identifier includes the file configuration type; based on configuration attribute information, configuration information corresponding to structured environment variables is generated in the target configuration file under the target directory of the file system, including: When the type identifier is file configuration, the target configuration file in the target directory is determined based on the directory identifier and configuration file name; the target configuration segment to be configured is determined based on the configuration segment identifier; the file path and file content in the file system are determined based on the value of the structured environment variable; a corresponding data file is created in the file system based on the file path, and the file content is written into the data file; and the file path options corresponding to the target configuration segment in the target configuration file are generated based on the file key and file path of the structured environment variable. The configuration information includes the data file and the file path options.

[0076] For example, by parsing structured environment variables, the type identifier is identified as a file configuration type ( <ktype>='f', file type), determines the corresponding target directory in the file system based on the directory identifier dir, such as the ' / etc / config / ' directory; based on the configuration file name <cfgfile>Determine the target configuration file, such as 'etc / config / wireless'; based on the configuration section identifier. <section>The system determines the target configuration segment and the option key to be created or set in that segment. By parsing the value, it determines the file path and content in the file system, creates the data file according to the file path, and writes the file content. By executing a UCI command, it generates an option in the target configuration file ('etc / config / wireless'), which is the string representing the file path of the corresponding data file.

[0077] For example, for the file type, its corresponding structured environment variable can be set as: fw_setenv sys.fy.wireless.wifi0.key ' / etc / wifi / cert.pem+LS0tLS1CRUdJTi...'; After parsing, the target directory was determined to be the system configuration directory / etc / config / , the configuration type f was determined to be a file configuration type, the encryption identifier y was determined to be the encryption status, the target configuration file was determined to be / etc / config / wireless / , the target configuration section was determined to be wifi0, and the option key to be created or set in this target configuration section was determined; by parsing the value part, the file path / etc / wifi / cert.pem and the file content LS0tLS1CRUdJTi... were determined; a data file was created based on the file path, and the decrypted file content was written into the data file: echo "decoded content"> / etc / wifi / cert.pem; then, the UCI command was executed: uci set wireless.wifi0.key=' / etc / wifi / cert.pem'; In the / etc / config / wireless configuration file, a string representing the file path corresponding to the option key is generated.

[0078] By decoding and decrypting encoded variables stored in the environment variable partition, a new data file is created on the device's file system. Finally, by configuring the registered file path in the UCI configuration, a reference relationship between the configuration and the data file is established. This solves the problem that UCI configuration files are not suitable for directly storing binary or long text data such as certificates and keys. Furthermore, by storing the data in the environment variable partition, the files can be automatically reconstructed after a factory reset, achieving persistent file storage. Sensitive files are stored in encrypted form in the environment variable partition and separated from the configuration, which facilitates setting different file access permissions and enhances file security.

[0079] In some embodiments, generating configuration information corresponding to structured environment variables in a target configuration file under the target directory of the file system based on configuration attribute information further includes: Based on the encrypted identifier, it is determined whether the value of the structured environment variable is in an encrypted state; if the value of the structured environment variable is in an encrypted state, the configuration information is obtained by decrypting the value of the structured environment variable.

[0080] For example, when the encryption flag is 'y', the value of the structured environment variable is determined to be in an encrypted state; for instance, for the 'file' type, the file path and encrypted file content are determined by parsing the value. The encrypted file content is decrypted using the AES-GCM-SIV algorithm to obtain base64_content, and then Base64 decoded to obtain the original, binary file content 'file_data'.

[0081] In some embodiments, for normal application scenarios that start up each time, the device may also restart multiple times (such as power failure, manual restart). During this restart phase, the device's conversion engine can also run, by checking the environment variable partition, reading and parsing the structured environment variables.

[0082] In this application scenario, the system has not been reset, and the UCI configuration files in the ` / etc / config / ` directory already exist. These files may contain the same configurations as the structured environment variables stored in the environment variable partition, or they may contain temporary modifications entered by the user later through the web interface that have not yet been synchronized to the environment variable partition. In this case, the operations performed by the conversion engine can be set to the following two strategies: First, the forced overwrite strategy: the conversion engine can ignore the contents of the current UCI configuration file and strictly regenerate the configuration based on the contents of the environment variable partition. This ensures that the device configuration is always consistent with the contents of the environment variable partition or the initial configuration.

[0083] Second, the intelligent merging and skipping strategy: The conversion engine checks whether a configuration item already exists; if it does, it skips it to avoid overwriting the user's latest modifications. The specific execution command implementation principle is the same as in the above embodiment.

[0084] In this embodiment, configuration parameters are permanently saved by storing the configuration in the environment variable partition, ensuring that the default factory configuration is not lost even after a factory reset. A unified configuration conversion mechanism and a type identifier indicating the configuration type support all UCI configuration types. The production line configuration process is simplified from flashing different firmware for each device to flashing a generic firmware and injecting configuration data. For example, the production line can first flash a unified image firmware, and then use an automated script to quickly write specific configurations to the environment variable partition. This achieves batch, parallel, and automated production line configuration, ensuring configuration is completed as soon as production is finished, eliminating the need for individual configurations after production, thus greatly improving configuration efficiency. By using encrypted identifiers and encrypting sensitive information, the security of sensitive information is protected, effectively preventing physical extraction attacks. Even if the flash is removed, plaintext cannot be read directly. The conversion mechanism of the conversion engine is fully compatible with the existing UCI mechanism. When the system starts, the structured environment variables are automatically converted into standard UCI configuration files and stored in the standard / etc / config / directory. All existing system services, applications and UCI command-line tools do not need to be modified, and the normal operation of the system is not affected.

[0085] In the traditional model, different customers' customized needs (such as default server addresses) must be met by compiling different firmware. This application can separate firmware from configuration, requiring only the maintenance of a single general firmware. The differences between different customers are only reflected in the configuration data package written to the environment variable partition. It supports firmware generalization and configuration differentiation. For new customer needs, there is no need to recompile, test, and release firmware; only a new configuration file needs to be set. This greatly reduces the number of firmware versions, lowers maintenance costs, and reduces supply chain complexity.

[0086] Furthermore, the structured environment variables stored in the environment variable partition, through structured naming conventions, achieve self-description of configuration attributes. They can complete type identification and path location without additional metadata, enabling precise task execution and making the system simple and robust. The configurations stored in the environment variable partition can be flexibly set according to user needs and support flexible expansion to new configuration types and storage locations.

[0087] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0088] Corresponding to the configuration information management method provided in the above embodiments, such as Figure 3 The diagram shown is a schematic representation of the configuration information management device provided in this application embodiment. For ease of explanation, only the parts related to this application embodiment are shown.

[0089] The configuration information management device includes: The acquisition unit 31 is used to acquire the structured environment variables stored in the environment variable partition of the memory during the system startup process; Parsing unit 32 is used to parse the structured environment variable to obtain the configuration attribute information corresponding to each field of the structured environment variable; Configuration unit 33 is used to generate configuration information corresponding to the structured environment variable in the target configuration file under the target directory of the file system based on the configuration attribute information.

[0090] In one possible implementation, the above-mentioned units and modules are used to implement the steps in the above-described method embodiments.

[0091] Figure 4 A schematic diagram of the hardware structure of electronic device 4 is shown.

[0092] like Figure 4 As shown, the electronic device 4 of this embodiment includes: at least one processor 41 ( Figure 4 (Only one is shown in the image) A memory 42 stores a computer program 43 that can run on the processor 41. When the processor 41 executes the computer program 43, it implements the steps in the above method embodiments, for example... Figure 2 S201 to S203 are shown. Alternatively, when the processor 41 executes the computer program 43, it implements the functions of each module / unit in the above-described device embodiments.

[0093] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 4. In other embodiments of this application, the electronic device 4 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0094] The electronic device 4 may include, but is not limited to, a processor 41 and a memory 42. Those skilled in the art will understand that... Figure 4 This is merely an example of electronic device 4 and does not constitute a limitation on electronic device 4. It may include more or fewer components than shown, or combine certain components, or different components. For example, the server may also include input sending devices, network access devices, buses, etc.

[0095] The processor 41 mentioned above can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.

[0096] The processor 41 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 41 is a cache memory. This memory can store instructions or data that the processor 41 has just used or that are used repeatedly. If the processor 41 needs to use the instruction or data again, it can directly retrieve it from the memory. This avoids repeated accesses, reduces the waiting time of the processor 41, and thus improves the efficiency of the system.

[0097] In some embodiments, the aforementioned memory 42 may be an internal storage unit of the electronic device 4, such as a hard disk or memory of the electronic device 4. The memory 42 may also be an external storage device of the electronic device 4, such as a plug-in hard disk, smart media card (SMC), secure digital card (SD), flash card, etc., equipped on the electronic device 4. Furthermore, the memory 42 may include both internal and external storage units of the electronic device 4. The memory 42 is used to store operating systems, applications, bootloaders, data, and other programs, such as program code for computer programs. The memory 42 can also be used to temporarily store data that has been sent or will be sent.

[0098] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0099] It should be noted that the structure of the above-mentioned electronic device is only illustrative. Depending on the application scenario, other physical structures may also be included. The physical structure of the electronic device is not limited here.

[0100] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0101] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps described in the various method embodiments above.

[0102] This application provides a computer program product that, when run on a server, enables the server to execute the steps described in the above-described method embodiments.

[0103] If the integrated modules / units 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, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc.

[0104] The electronic devices, computer storage media, and computer program products provided in the embodiments of this application are all used to execute the methods provided above. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects corresponding to the methods provided above, and will not be repeated here.

[0105] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification. It should be understood that the above description is merely to help those skilled in the art better understand the embodiments of this application, and is not intended to limit the scope of the embodiments of this application. Based on the examples given above, those skilled in the art can obviously make various equivalent modifications or changes. For example, some steps in the various embodiments of the above detection method may be unnecessary, or new steps may be added. Alternatively, any combination of two or more of the above embodiments may be used. Such modifications, changes, or combinations also fall within the scope of the embodiments of this application.

[0106] It should also be understood that the methods, situations, categories, and classifications of embodiments in this application are for the convenience of description only and should not constitute a special limitation. Various methods, categories, situations, and features in embodiments can be combined without contradiction.

[0107] It should also be understood that, in the various embodiments of this application, unless otherwise specified or in case of logical conflict, the terms and / or descriptions between different embodiments are consistent and can be referenced by each other, and the technical features in different embodiments can be combined to form new embodiments according to their inherent logical relationships.

[0108] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0109] In the embodiments provided in this application, it should be understood that the disclosed apparatus / network devices and methods can be implemented in other ways. For example, the apparatus / network device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0110] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0111] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications 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 this application, and should all be included within the protection scope of this application.

[0112] Finally, it should be noted that the above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.< / section> < / cfgfile> < / ktype> < / section> < / cfgfile> < / ktype> < / section> < / cfgfile> < / ktype> < / ktype> < / key> < / section> < / section> < / cfgfile> < / cfgfile> < / cfgfile> < / cfgfile> < / stype> < / stype> < / stype> < / ktype> < / ktype> < / ktype> < / ktype> < / ktype> < / dir> < / dir> < / dir> < / dir> < / value> < / key> < / section> < / cfgfile> < / stype> < / ktype> < / dir> < / key> < / key> < / ktype> < / value> < / key> < / sectype> < / section> < / cfgfile> < / stype> < / ktype> < / dir> < / value> < / key> < / section> < / cfgfile> < / stype> < / ktype> < / dir>

Claims

1. A configuration information management method characterized by comprising: The application relates to a method for generating configuration information based on a structured environment variable. During system startup, a structured environment variable stored in an environment variable partition of a memory is acquired; The structured environment variable is parsed to obtain configuration attribute information corresponding to each field of the structured environment variable; Based on the configuration attribute information, configuration information corresponding to the structured environment variable is generated in a target configuration file under a target directory of a file system.

2. The method of claim 1, wherein, The structured environment variable is stored based on a key-value pair format; The structured environment variable is parsed to obtain configuration attribute information corresponding to each field of the structured environment variable, including: The keys of the structured environment variable are parsed to obtain a directory identifier, a type identifier, an encryption identifier, a configuration file name and a configuration segment identifier; The configuration attribute information includes the directory identifier, the type identifier, the encryption identifier, the configuration file name and the configuration segment identifier.

3. The method of claim 2, wherein, Based on the configuration attribute information, configuration information corresponding to the structured environment variable is generated in a configuration file under a target directory of a file system, including: Based on the directory identifier, the target directory is determined; Based on the type identifier, a configuration type to be executed is determined; Based on the configuration file name, the target configuration file is determined; Based on the configuration segment identifier, a target configuration segment is determined; Based on the value of the structured environment variable, configuration information corresponding to the target configuration segment in the target configuration file under the target directory is generated according to the configuration type.

4. The method of claim 2, wherein, The type identifier includes a creation configuration segment type; based on the configuration attribute information, configuration information corresponding to the structured environment variable is generated in a target configuration file under a target directory of a file system, including: When the type identifier is the creation configuration segment type, based on the directory identifier, the target directory is determined; Based on the configuration file name, the target configuration file is determined; Based on the configuration segment identifier, a target configuration segment to be configured is determined; Based on the value of the structured environment variable, a configuration segment type corresponding to the target configuration segment is generated; The configuration information includes the target directory, the target configuration file, the target configuration segment and the configuration segment type.

5. The method of claim 2, wherein, The type identifier includes a single-value configuration type; based on the configuration attribute information, configuration information corresponding to the structured environment variable is generated in a target configuration file under a target directory of a file system, including: When the type identifier is the single-value configuration type, based on the directory identifier and the configuration file name, a target configuration file under the target directory is determined; Based on the configuration segment identifier, a target configuration segment to be configured is determined; Based on the option key and the value of the structured environment variable, an option value corresponding to a target option in the target configuration segment is generated; The configuration information includes the option value.

6. The method of claim 2, wherein, The type identifier includes an array configuration type; based on the configuration attribute information, configuration information corresponding to the structured environment variable is generated in a target configuration file under a target directory of a file system, including: When the type identifier is the array configuration type, a target configuration file under the target directory is determined based on the directory identifier and the configuration file name; A target configuration section to be configured is determined based on the configuration section identifier; A list element corresponding to a target list in the target configuration section is generated based on the list key and value of the structured environment variable; The configuration information includes the list element.

7. The method of claim 2, wherein, The type identifier includes a file configuration type; and the generating, based on the configuration attribute information, of the configuration information corresponding to the structured environment variable in a target configuration file under a target directory of a file system includes: When the type identifier is the file configuration type, a target configuration file under the target directory is determined based on the directory identifier and the configuration file name; A target configuration section to be configured is determined based on the configuration section identifier; A file path and file content in the file system are determined based on the value of the structured environment variable; A corresponding data file is created in the file system based on the file path, and the file content is written in the data file; A file path option corresponding to the target configuration section in the target configuration file is generated based on the file key of the structured environment variable and the file path; The configuration information includes the data file and the file path option.

8. The method according to any one of claims 2 to 7, characterized in that, The generating, based on the configuration attribute information, of the configuration information corresponding to the structured environment variable in a target configuration file under a target directory of a file system further includes: It is determined whether the value of the structured environment variable is in an encrypted state based on the encryption identifier; In a case where the value of the structured environment variable is in the encrypted state, the configuration information is obtained by decrypting the value of the structured environment variable.

9. The method according to any one of claims 1 to 7, characterized in that, The method further includes: For configuration information to be saved, the structured environment variable is generated in a preset format, and is stored persistently in the environment variable partition.

10. An electronic device, comprising: The device includes a memory and a processor, the memory stores a computer program, and the processor implements the method in any one of claims 1 to 9 when executing the computer program.