An embedded starting method for realizing dynamic configuration of screen direction

By storing screen orientation parameters in the NV partition and combining them with U-Boot and kernel mechanisms, the screen orientation can be dynamically configured, solving the problem of inflexible screen orientation configuration in existing technologies and achieving flexible configuration and stability without changing the kernel image.

CN122173173APending Publication Date: 2026-06-09INGENIC SEMICON CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
INGENIC SEMICON CO LTD
Filing Date
2024-12-06
Publication Date
2026-06-09

Smart Images

  • Figure CN122173173A_ABST
    Figure CN122173173A_ABST
Patent Text Reader

Abstract

This invention provides an embedded boot method for dynamically configuring screen orientation. The method includes: S1, setting a screen orientation parameter storage area in a non-volatile NV partition; S2, during the U-Boot boot phase, reading the screen orientation parameters from the NV partition; S3, determining whether the parameters in the NV partition are valid user configurations; S4, U-Boot appending the selected screen orientation parameters to the bootcmd command; S5, during kernel boot, parsing the screen orientation parameters in the bootcmd command using the early_param mechanism; S6, initializing the corresponding screen orientation based on the parsed parameters; and S7, the user configuration interface. This invention achieves dynamic screen orientation configuration, improving system flexibility; it allows changing the screen orientation without modifying the kernel or recompiling the firmware, simplifying system maintenance; it is compatible with existing default configuration mechanisms, ensuring system stability and reliability; and by storing user configurations in the NV partition, it ensures that the configuration remains valid after a device reboot.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of embedded system startup processing technology, and specifically relates to an embedded startup method for dynamically configuring screen orientation. Background Technology

[0002] In the existing embedded device boot process, U-Boot is responsible for reading the kernel image from the storage device and loading it into memory. Once the kernel is loaded and decompressed, it takes over system control, begins initializing hardware devices, loads drivers, and finally runs the initialization process to complete the system boot. The kernel image contains initialization information for the hardware devices, which is determined after the kernel image is compiled.

[0003] Currently, different screen orientations are typically configured using different kernel images and device trees (DTS). For example, to achieve both landscape and portrait screen displays on the same device, two kernel images with corresponding DTS configurations are usually required: one set for landscape and the other for portrait. Each time the screen orientation is switched, the kernel image needs to be changed, which not only increases maintenance complexity but also reduces system flexibility.

[0004] The problems with existing technology are:

[0005] In real-world applications, although hardware resources are generally the same, usage scenarios may require screens to be displayed in landscape or portrait orientations. Existing technologies require different kernel images for each display orientation, which is not only inconvenient but also prone to errors.

[0006] Managing multiple kernel images increases the maintenance cost and complexity of the system.

[0007] Switching the screen orientation requires changing the kernel image, which may require restarting the device, impacting user experience and system flexibility.

[0008] In addition, the relevant technical terms are as follows:

[0009] Device Tree Source (DTS): A file used to describe the board-level hardware topology and configuration parameters, enabling the kernel to recognize and initialize hardware devices.

[0010] U-Boot: A bootloader widely used in the embedded field, primarily for booting embedded systems.

[0011] SPL (Secondary Program Loader): The first stage of execution code in U-Boot, mainly responsible for initializing the chip.

[0012] Kernel: The kernel image file contains initialization information for hardware devices and the core functions of the operating system.

[0013] NV partition (Non-Volatile Memory partition): A portion of non-volatile memory designed to store data that will not be lost even after power is turned off. Widely used in various devices, it is typically used to store critical information such as device IDs, MAC addresses, and other parameters. early_param: A mechanism in the Linux kernel used to handle boot parameters, allowing certain important parameters to be parsed and applied before the kernel is fully initialized. Summary of the Invention

[0014] The purpose of this invention is to provide an embedded startup method that enables dynamic screen orientation configuration, thereby solving the technical problem of lack of flexibility in screen orientation configuration in the prior art.

[0015] To achieve the above objectives, the present invention employs an embedded startup method for dynamically configuring screen orientation, comprising the following steps:

[0016] S1, Set the screen orientation parameter storage area in the non-volatile NV partition;

[0017] Before the device boots up, the user writes screen orientation parameters to the NV partition using upper-layer application tools; or the NV partition is written with default values ​​during program flashing. These configuration parameters are in the format of simple key-value pairs; further including:

[0018] S1.1, A fixed offset address is reserved in the device's storage medium as an NV partition for storing screen orientation parameters;

[0019] S1.2, Implement a device utility application in user space, which has the following functions:

[0020] - Directly map and access the device node corresponding to the NV partition;

[0021] - Read / write screen direction parameters at a specified offset address;

[0022] - Provides parameter validation and error handling mechanisms;

[0023] S1.3, users can configure the screen orientation in the following ways:

[0024] - Use this tool to write parameters directly to the NV partition;

[0025] - Set default values ​​during production programming;

[0026] S2, during the U-Boot startup phase, reads the screen orientation parameters from the NV partition:

[0027] When the device starts up, U-Boot reads the screen orientation parameters from the NV partition and then appends them to the bootcmd boot command;

[0028] S3, determine whether the parameters in the NV partition are valid user configurations: further including parameter validity checks:

[0029] S3.1 In order to determine whether the data in the NV partition is a valid user configuration, a function is implemented to first check whether the magic number matches, and then verify whether the angle value is a valid value.

[0030] S3.2 If it is a valid user configuration, use the screen orientation parameter in the NV partition; otherwise, use the default angle configuration in the Device Tree DTS.

[0031] S4, U-Boot appends the selected screen orientation parameters to the bootcmd command;

[0032] During the U-Boot startup phase, a function is implemented to handle screen orientation parameters. The function's purpose is to read the user-set angle from the NV partition using the nv_read method.

[0033] - Check the validity of the read angle. If it is a valid angle value, append it to the bootcmd of the kernel.

[0034] S5, during kernel startup, parses the screen orientation parameters in bootcmd using the early_param mechanism; further includes kernel processing logic:

[0035] During the kernel startup phase, a function is implemented that uses the early_param mechanism to parse screen orientation parameters. The function's purpose is as follows:

[0036] - This function parses the passed-in parameters, specifically the bootcmd passed from uboot;

[0037] - Set the global rotation_angle variable if the parameter is valid;

[0038] S6. Based on the parsed parameters, the kernel initializes the corresponding screen orientation;

[0039] In this step, the kernel needs to determine whether the NV partition's angle matches the angle configured in DTS. If so, it rotates according to the original configured angle. If the NV partition's angle does not match the angle configured in DTS, it calculates the angle difference and rotates accordingly. This process is implemented through a function whose function is:

[0040] - Read the rot_angle configuration from the DTS file node and store it in the variable fbdev->angle;

[0041] - Compare with the global variable dy_rot_angle. If dy_rot_angle is valid and not equal to fbdev->angle, then calculate the angle difference angle_diff.

[0042] - Based on the angle difference, set a variable to determine whether to rotate the screen;

[0043] S7, User Configuration Interface: To allow users to dynamically configure the screen orientation, a function is provided. This function writes the user-specified angle value to the NV partition and sets the corresponding magic number to identify it as a valid user configuration. The function's purpose is:

[0044] - Read the rotation angle configured by the user, which is represented as argv[2] in the code;

[0045] - Add the magic number to the angle value and store it in the value variable, i.e., value = 0xeeee0000|degree; - Write the value variable to the nv partition using the nv_write method; represented as nv_write(sysinfo_flag_nv).

[0046] Step S1 further includes the setting and data structure of the NV partition, as follows:

[0047] The following data structure is defined in the NV partition to store screen orientation parameters:

[0048] The high 16 bits represent the magic number, and the low 16 bits represent the angle value.

[0049]

[0050] The high 16 bits of rot_angle are used as a magic number to determine whether the data is a valid user configuration; the low 16 bits are used to store the actual rotation angle value.

[0051] The simple key-value pairs in step S1 include: "nv.rot_angle=90" or "nv.rot_angle=180".

[0052] The function mentioned in step S3.1 is as follows:

[0053]

[0054] The verification angle value is whether it is a valid value, i.e., 0°, 90°, 180° or 270°.

[0055] The code for the U-Boot stage in steps S2-S4 is as follows:

[0056]

[0057]

[0058] In the code, the cmdargs variable represents the bootcmd that starts the kernel, and "rot_angle=%d" represents the appended content.

[0059] In step S5, the code for the function is as follows:

[0060]

[0061] }

[0062] early_param("rot_angle",early_rot_angle).

[0063] In step S6, the code for the function is as follows:

[0064] if(of_property_read_u32(fbdev->dev->of_node,"ingenic,rot_angle",

[0065] &fbdev->rot_angle)){

[0066] dev_err(fbdev->dev,"read rot_angle failed!please check dts.");

[0067] }

[0068] dev_info(fbdev->dev,"dts rot_angle=%d,nv.rot_angle=%d\n",fbdev->rot_angle,dy_rot_angle);

[0069] if(dy_rot_angle!=-1&&fbdev->rot_angle!=dy_rot_angle){

[0070] int angle_diff=(dy_rot_angle-fbdev->rot_angle+360)%360;

[0071] if(angle_diff==90||angle_diff==270){

[0072] fbdev->swap_dims = 1;

[0073] }else{

[0074] fbdev->swap_dims = 0;

[0075] }

[0076] fbdev->rot_angle=dy_rot_angle;

[0077] }

[0078] In step S7, the code for the function is as follows:

[0079] unsigned short degree=atoi(argv[2]);

[0080] unsigned int value=0xeeee0000|degree;

[0081] sysinfo_flag_nv->rot_angle=value;

[0082] if(nv_write(sysinfo_flag_nv)<0){

[0083] printf("Failed to set sysinfo flag nv\n");

[0084] }

[0085] The method described above is screen orientation configuration during the startup process. It achieves dynamic screen orientation configuration by combining NV partitioning and U-Boot.

[0086] An embedded startup method for dynamically configuring screen orientation according to claim 1, characterized in that the method is applicable to embedded systems or devices, and can be applied to various embedded systems or devices that require flexible configuration of screen orientation, including tablet computers, smartwatches, and vehicle displays.

[0087] The beneficial effects of this invention include:

[0088] 1. Dynamic configuration of screen orientation has been implemented, improving the system's flexibility;

[0089] 2. The screen orientation can be changed without modifying the kernel or recompiling the firmware, simplifying system maintenance;

[0090] 3. It is compatible with existing default configuration mechanisms, ensuring the stability and reliability of the system;

[0091] 4. Store user configurations via NV partitions to ensure that the configurations remain effective after the device restarts. Attached Figure Description

[0092] The accompanying drawings, which are provided to further illustrate the invention and form part of this application, are not intended to limit the scope of the invention.

[0093] Figure 1 This is a flowchart illustrating the method used in this application. Detailed Implementation

[0094] To better understand the technical content and advantages of the present invention, the present invention will now be described in further detail with reference to the accompanying drawings.

[0095] This invention relates to screen orientation configuration during the boot process of an embedded system, and more particularly to a technical solution for dynamically configuring screen orientation through a combination of NV partitioning and U-Boot. A technical solution combining NV partitioning and U-Boot is proposed to achieve dynamic screen orientation configuration in an embedded system. Figure 1 As shown, the following is a detailed description of the scheme:

[0096] S1, Set the screen orientation parameter storage area in the non-volatile NV partition;

[0097] Before device startup, the user writes screen orientation parameters to the NV partition using upper-layer application tools; or the NV partition is written with default values ​​during program flashing. These configuration parameters are in the form of simple key-value pairs, such as "nv.rot_angle=90" or "nv.rot_angle=180"; further including:

[0098] S1.1, A fixed offset address is reserved in the device's storage medium as an NV partition for storing screen orientation parameters;

[0099] S1.2, Implement a device utility application in user space, which has the following functions:

[0100] - Directly map and access the device node corresponding to the NV partition;

[0101] - Read / write screen direction parameters at a specified offset address;

[0102] - Provides parameter validation and error handling mechanisms;

[0103] S1.3, users can configure the screen orientation in the following ways:

[0104] - Use this tool to write parameters directly to the NV partition;

[0105] - Set default values ​​during production programming;

[0106] Furthermore, within the NV partition, the following data structure is defined to store screen orientation parameters:

[0107] The high 16 bits represent the magic number, and the low 16 bits represent the angle value.

[0108]

[0109] Where: the high 16 bits of rot_angle are used as the magic number to determine whether the data is a valid user configuration; the low 16 bits are used to store the actual rotation angle value;

[0110] S2, during the U-Boot startup phase, reads the screen orientation parameters from the NV partition;

[0111] When the device starts up, U-Boot reads the screen orientation parameters from the NV partition and then appends them to the bootcmd boot command;

[0112] S3, determine whether the parameters in the NV partition are valid user configurations;

[0113] This further includes parameter validity assessment:

[0114] S3.1, To determine whether the data in the NV partition is a valid user configuration, a function is implemented to first check if the magic number matches, and then verify whether the angle value is valid; the code implementation of the function is as follows:

[0115]

[0116] The verification angle value is whether it is a valid value, i.e., 0°, 90°, 180° or 270°;

[0117] S3.2 If it is a valid user configuration, use the screen orientation parameter in the NV partition; otherwise, use the default angle configuration in the Device Tree DTS.

[0118] S4, U-Boot appends the selected screen orientation parameters to the bootcmd command;

[0119] During the U-Boot startup phase, a function is implemented to handle screen orientation parameters. The function's purpose is to read the user-set angle from the NV partition using the nv_read method.

[0120] - Check the validity of the read angle. If it is a valid angle value, append it to the bootcmd of the kernel.

[0121] The code for the U-Boot stage in steps S2-S4 is as follows:

[0122]

[0123]

[0124] In the code, the cmdargs variable represents the bootcmd that starts the kernel, and "rot_angle=%d" represents the appended content.

[0125] S5, during kernel startup, parses the screen orientation parameters in bootcmd using the early_param mechanism; further includes kernel processing logic:

[0126] During the kernel startup phase, a function is implemented that uses the early_param mechanism to parse screen orientation parameters; the code for this function is as follows:

[0127]

[0128] return 0;

[0129] }

[0130] early_param("rot_angle",early_rot_angle);

[0131] The function's purpose is:

[0132] - This function parses the passed-in parameters, specifically the bootcmd passed from uboot;

[0133] - Set the global rotation_angle variable if the parameter is valid;

[0134] This function parses the passed parameters and sets the global rotation_angle variable if the parameters are valid;

[0135] S6. Based on the parsed parameters, the kernel initializes the corresponding screen orientation;

[0136] In this step, the kernel needs to determine whether the angle of the NV partition matches the angle configured in DTS, and if so, rotate according to the original configured angle; otherwise, calculate the angle difference and rotate accordingly. This process is implemented through a function, the code of which is as follows:

[0137] if(of_property_read_u32(fbdev->dev->of_node,"ingenic,rot_angle",

[0138] &fbdev->rot_angle)){

[0139] dev_err(fbdev->dev,"read rot_angle failed!please check dts.");

[0140] }

[0141] dev_info(fbdev->dev,"dts rot_angle=%d,nv.rot_angle=%d\n",fbdev->rot_angle,dy_rot_angle);

[0142] if(dy_rot_angle!=-1&&fbdev->rot_angle!=dy_rot_angle){

[0143] int angle_diff=(dy_rot_angle-fbdev->rot_angle+360)%360;

[0144] if(angle_diff==90||angle_diff==270){

[0145] fbdev->swap_dims = 1;

[0146] }else{

[0147] fbdev->swap_dims = 0;

[0148] }

[0149] fbdev->rot_angle=dy_rot_angle;

[0150] };

[0151] The function's purpose is:

[0152] - Read the rot_angle configuration from the DTS file node and store it in the variable fbdev->angle;

[0153] - Compare with the global variable dy_rot_angle. If dy_rot_angle is valid and not equal to fbdev->angle, then calculate the angle difference angle_diff.

[0154] - Based on the angle difference, set a variable to determine whether to rotate the screen;

[0155] S7, User Configuration Interface: To allow users to dynamically configure the screen orientation, a function is provided. This function writes the user-specified angle value to the NV partition and sets the corresponding magic number to identify a valid user configuration. The code implementation of the function is as follows:

[0156] unsigned short degree=atoi(argv[2]);

[0157] unsigned int value=0xeeee0000|degree;

[0158] sysinfo_flag_nv->rot_angle=value;

[0159] if(nv_write(sysinfo_flag_nv)<0){

[0160] printf("Failed to set sysinfo flag nv\n");

[0161] }

[0162] The function's purpose is:

[0163] - Read the rotation angle configured by the user, which is represented as argv[2] in the code;

[0164] - Add the magic number to the angle value and store it in the value variable, i.e., value = 0xeeee0000|degree; - Write the value variable to the nv partition using the nv_write method; represented as nv_write(sysinfo_flag_nv).

[0165] The method described is for screen orientation configuration during the boot process. It achieves dynamic screen orientation configuration through a combination of NV partitioning and U-Boot. It is suitable for embedded systems or devices requiring flexible screen orientation configuration, including tablets, smartwatches, and automotive displays.

[0166] Through the above implementation methods, the present invention achieves dynamic configuration of screen orientation without modifying the kernel or recompiling the firmware. This solution has the following advantages:

[0167] 1. Flexibility: Supports seamless switching between user-defined configurations and default DTS configurations.

[0168] 2. Robustness: Through magic number and validity checks, it is ensured that only valid user configurations will be used.

[0169] 3. Compatibility: The system can still function normally without user configuration, using the default values ​​in DTS.

[0170] 4. Maintainability: Clear decision-making logic makes the system behavior more predictable, facilitating debugging and maintenance.

[0171] 5. User-friendly: Provides a simple interface that allows users to change the screen orientation as needed.

[0172] The application of this invention is not limited to specific embedded systems or devices, but can be widely used in various embedded devices that require flexible screen orientation configuration.

[0173] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, various modifications and variations can be made to the embodiments of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. An embedded startup method for dynamically configuring screen orientation, characterized in that, The method includes the following steps: S1, Set the screen orientation parameter storage area in the non-volatile NV partition; Before the device boots up, the user writes screen orientation parameters to the NV partition using upper-layer application tools; or the NV partition is written with default values ​​during program flashing. These configuration parameters are in the format of simple key-value pairs; further including: S1.1, A fixed offset address is reserved in the device's storage medium as an NV partition for storing screen orientation parameters; S1.2, Implement a device utility application in user space, which has the following functions: - Directly map and access the device node corresponding to the NV partition; - Read / write screen direction parameters at a specified offset address; - Provides parameter validation and error handling mechanisms; S1.3, users can configure the screen orientation in the following ways: - Use this tool to write parameters directly to the NV partition; - Set default values ​​during production programming; S2, during the U-Boot startup phase, reads the screen orientation parameters from the NV partition: When the device starts up, U-Boot reads the screen orientation parameters from the NV partition and then appends them to the bootcmd boot command; S3, determine whether the parameters in the NV partition are valid user configurations: this further includes parameter validity checks: S3.1 In order to determine whether the data in the NV partition is a valid user configuration, a function is implemented to first check whether the magic number matches, and then verify whether the angle value is a valid value. S3.2 If it is a valid user configuration, use the screen orientation parameter in the NV partition; otherwise, use the default angle configuration in the Device Tree DTS. S4, U-Boot appends the selected screen orientation parameters to the bootcmd command; During the U-Boot startup phase, a function is implemented to handle screen orientation parameters. The function's purpose is as follows: - Read the user-set angle from the NV partition using the nv_read method; - Check the validity of the read angle. If it is a valid angle value, append it to the bootcmd of the kernel. S5, during kernel startup, parses the screen orientation parameters in bootcmd using the early_param mechanism; further includes kernel processing logic: During the kernel startup phase, a function is implemented that uses the early_param mechanism to parse screen orientation parameters. The function's purpose is as follows: - This function parses the passed-in parameters, specifically the bootcmd passed from uboot; - Set the global rotation_angle variable if the parameter is valid; S6. Based on the parsed parameters, the kernel initializes the corresponding screen orientation; In this step, the kernel needs to determine whether the NV partition's angle matches the angle configured in DTS. If so, it rotates according to the original configured angle. If the NV partition's angle does not match the angle configured in DTS, it calculates the angle difference and rotates accordingly. This process is implemented through a function whose function is: - Read the rot_angle configuration from the DTS file node and store it in the variable fbdev->angle; - Compare with the global variable dy_rot_angle. If dy_rot_angle is valid and not equal to fbdev->angle, then calculate the angle difference angle_diff. - Based on the angle difference, set a variable to determine whether to rotate the screen; S7, User Configuration Interface: To allow users to dynamically configure the screen orientation, a function is provided. This function writes the user-specified angle value to the NV partition and sets the corresponding magic number to identify it as a valid user configuration. The function's purpose is: - Read the rotation angle configured by the user, which is represented as argv[2] in the code; - Add the magic number to the angle value and store it in the value variable, i.e., value = 0xeeee0000|degree; - Write the variable value to the nv partition using the nv_write method; it is represented as nv_write(sysinfo_flag_nv).

2. The embedded startup method for dynamically configuring screen orientation according to claim 1, characterized in that, Step S1 further includes the setting and data structure of the NV partition, as follows: The following data structure is defined in the NV partition to store screen orientation parameters: The high 16 bits represent the magic number, and the low 16 bits represent the angle value. #define NV_MAGIC_NUMBER 0xEEEE0000 #define NV_ANGLE_MASK 0x0000FFFF struct nv_flags{ unsigned int rot_angle; Other NV partition data, ...; }; The high 16 bits of rot_angle are used as a magic number to determine whether the data is a valid user configuration; the low 16 bits are used to store the actual rotation angle value.

3. The embedded startup method for dynamically configuring screen orientation according to claim 1, characterized in that, The simple key-value pairs in step S1 include: "nv.rot_angle=90" or "nv.rot_angle=180".

4. The embedded startup method for dynamically configuring screen orientation according to claim 1, characterized in that, The code implementation of the function described in step S3.1 is as follows: int is_nv_data_valid(unsigned int rot_angle){ unsigned int magic=rot_angle&0xFFFF0000; unsigned int angle=rot_angle&NV_ANGLE_MASK; return(magic==NV_MAGIC_NUMBER)&& (angle==0||angle==90||angle==180||angle==270); } The verification angle value is whether it is a valid value, i.e., 0°, 90°, 180° or 270°.

5. An embedded startup method for dynamically configuring screen orientation according to claim 1, characterized in that, The U-Boot phase in steps S2-S4 is implemented as follows: In the code, the cmdargs variable represents the bootcmd command for starting the kernel, and "rot_angle=%d" represents the appended content.

6. An embedded startup method for dynamically configuring screen orientation according to claim 1, characterized in that, In step S5, the code implementation of the function is as follows:

7. An embedded startup method for dynamically configuring screen orientation according to claim 1, characterized in that, In step S6, the code implementation of the function is as follows: if(of_property_read_u32(fbdev->dev->of_node,"ingenic,rot_angle", &fbdev->rot_angle)){ dev_err(fbdev->dev,"read rot_angle failed!please check dts."); 8. An embedded startup method for dynamically configuring screen orientation according to claim 1, characterized in that, In step S7, the code implementation of the function is as follows: unsigned short degree = atoi(argv[2]); unsigned int value = 0xeeee0000 | degree; sysinfo_flag_nv->rot_angle = value; if(nv_write(sysinfo_flag_nv) < 0) { printf("Failed to set sysinfo flag nv\n"); }。 9. An embedded startup method for dynamically configuring screen orientation according to claim 1, characterized in that, The method described above configures the screen orientation during the startup process by combining NV partitioning and U-Boot to achieve dynamic screen orientation configuration.

10. An embedded startup method for dynamically configuring screen orientation according to claim 1, characterized in that, The method is applicable to embedded systems or devices, and can be used in various embedded systems or devices that require flexible screen orientation configuration, including tablets, smartwatches, and automotive displays.