Disclosure of Invention
In order to solve the above problems, the present disclosure provides a device booting method, an apparatus, a storage medium, and an electronic device.
In a first aspect, the present disclosure provides a device booting method, including:
acquiring the size of a target file corresponding to a target starting file in target equipment;
loading the target starting file with the size of the target file from a preset storage area of the target equipment according to a first preset storage address;
and running the target starting file to start the target equipment.
Optionally, the obtaining a size of a target file corresponding to a target startup file in the target device includes:
determining whether the target file size is stored in a preset environment variable of the target device;
and under the condition that the size of the target file is stored in the preset environment variable, acquiring the size of the target file from the preset environment variable.
Optionally, the method further comprises:
under the condition that the size of the target file is not stored in the preset environment variable, a second preset storage address is obtained;
acquiring the size of the stored target file from a preset storage area of the target equipment according to the second preset storage address;
and storing the size of the target file in the preset environment variable.
Optionally, the preset storage area comprises a raw partition.
In a second aspect, the present disclosure provides an apparatus for starting a device, the apparatus comprising:
the first file size obtaining module is used for obtaining the size of a target file corresponding to a target starting file in target equipment;
the file acquisition module is used for loading the target starting file with the size of the target file from a preset storage area of the target equipment according to a first preset storage address;
and the operation module is used for operating the target starting file so as to start the target equipment.
Optionally, the first file size obtaining module is further configured to:
determining whether the target file size is stored in a preset environment variable of the target device;
and under the condition that the size of the target file is stored in the preset environment variable, acquiring the size of the target file from the preset environment variable.
Optionally, the apparatus further comprises:
the address acquisition module is used for acquiring a second preset storage address under the condition that the size of the target file is not stored in the preset environment variable;
a second file size obtaining module, configured to obtain, according to the second preset storage address, the size of the stored target file from a preset storage area of the target device;
and the storage module is used for storing the size of the target file in the preset environment variable.
Optionally, the preset storage area comprises a raw partition.
In a third aspect, the present disclosure provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of the method of the first aspect of the present disclosure.
In a fourth aspect, the present disclosure provides an electronic device comprising: a memory having a computer program stored thereon; a processor for executing the computer program in the memory to implement the steps of the method of the first aspect of the disclosure.
According to the technical scheme, the size of the target file corresponding to the target starting file in the target equipment is obtained; loading the target starting file with the size of the target file from a preset storage area of the target equipment according to a first preset storage address; and running the target starting file to start the target equipment. That is to say, when the target boot file is loaded, the target boot file may be directly loaded through the storage address corresponding to the target boot file, so that the target boot file of the target device may also be normally loaded under the condition that the file system is abnormal, so that the target device may be normally started.
Additional features and advantages of the disclosure will be set forth in the detailed description which follows.
Detailed Description
The following detailed description of specific embodiments of the present disclosure is provided in connection with the accompanying drawings. It should be understood that the detailed description and specific examples, while indicating the present disclosure, are given by way of illustration and explanation only, not limitation.
First, an application scenario of the present disclosure will be explained. Currently, system start-up of a vehicle product includes three steps: in the related technology, after bootloader startup is completed, the size of a kernel file is obtained through a file name, and the kernel file is loaded through a file system according to the size of the kernel file. In addition, when the kernel file is loaded through the file system, a series of authority checks are performed, so that the vehicle-mounted product is slow to start.
In order to solve the above technical problems, the present disclosure provides a device boot method, an apparatus, a storage medium, and an electronic device, where when a target boot file is loaded, the target boot file may be directly loaded through a storage address corresponding to the target boot file, so that when a file system is abnormal, the target boot file of the target device may also be normally loaded, so that the target device may be normally booted.
The present disclosure is described below with reference to specific examples.
Fig. 1 is a flow chart illustrating a method of device booting according to an example embodiment, which may include, as shown in fig. 1:
s101, obtaining the size of a target file corresponding to a target starting file in target equipment.
The target boot file may be a kernel file, a firmware file, or a dtb (device tree blob) file, and the type of the target boot file is not limited in this disclosure.
In this step, when the target startup file is generated by compiling, the size of the target file corresponding to the target startup file may be obtained, and the size of the target file is stored in a preset storage location in a preset storage area, where preset storage locations corresponding to different target startup files are different.
S102, loading the target start file with the size of the target file from the preset storage area of the target device according to the first preset storage address.
The preset storage area may be a raw partition of the target device, and the raw partition may be an unformatted area in the target device. In the preset storage area, the target file may be stored after the storage location of the target file size.
It should be noted that, in the related art, when the target device performs a flush operation, the storage area of the target device may be formatted into a target format in which a file system can operate, for example, for a linux system, the target format may be ext 4. The present disclosure may obtain a size of a target file corresponding to the target boot file in advance, determine a size of a storage space occupied by the preset storage area according to the size of the target file, for example, if the size of the target file is 90M, the storage space occupied by the preset storage area may be 100M, and control the target device not to perform formatting operation on the preset storage area when performing a booting operation.
In this step, after obtaining the size of the target file corresponding to the target boot file, a preset first preset storage address may be obtained, and the target boot file is loaded after obtaining the target boot file from the preset storage area according to the first preset storage address and the size of the target file.
And S103, operating the target starting file to start the target equipment.
By adopting the method, when the target starting file is loaded, the target starting file can be loaded through the first preset storage address corresponding to the target starting file, so that the target starting file of the target equipment can be normally loaded under the condition that a file system is abnormal, and the target equipment can be normally started.
Fig. 2 is a flow diagram illustrating another method of device booting according to an example embodiment, which may include, as shown in fig. 2:
s201, determining whether a target file size is stored in a preset environment variable of a target device, executing step S202 if the target file size is stored in the preset environment variable, and executing steps S203 to S205 if the target file size is not stored in the preset environment variable.
The preset environment variable may be a predefined environment variable for storing the size of the target file, and may be defined in the makefile, for example.
In one possible implementation manner, whether the target file size is stored in the preset environment variable may be determined according to the value of the preset environment variable. Exemplarily, in the case that the value of the preset environment variable is a default value, it is determined that the target file size is not stored in the preset environment variable; and under the condition that the value of the preset environment variable is a non-default value, determining that the size of the target file is stored in the preset environment variable.
In another possible implementation manner, whether the target file size is stored in the preset environment variable may be determined according to the number of times of starting the target device. Exemplarily, when the number of times of starting the target device is 0, that is, the target device is started for the first time after the shutdown is performed, it is determined that the size of the target file is not stored in the preset environment variable; and determining that the target file size is stored in the preset environment variable under the condition that the starting times of the target equipment is more than 0, namely the target equipment is not started for the first time after the flash.
S202, acquiring the size of the target file from the preset environment variable.
In this step, in a case where it is determined that the target file size is stored in the preset environment variable, the value of the preset environment variable may be used as the target file size.
S203, acquiring a second preset storage address.
The second preset storage address may be a start address of a second preset storage area in the preset storage area, where the second preset storage address is used for storing the target boot file.
In this step, the second preset storage address may be obtained when it is determined that the size of the target file is not stored in the preset environment variable.
S204, according to the second preset storage address, the size of the stored target file is obtained from the preset storage area of the target device.
The preset storage area may be a raw partition of the target device, and the raw partition may be an unformatted area in the target device.
In a possible implementation manner, the preset storage area may be divided into a first preset storage area and a second preset storage area, where the first preset storage area may be used to store the target boot file, and the second preset storage area may be used to store the size of the target file. The first preset storage area and the second preset storage area may be adjacent storage areas in the preset storage areas, and the first preset storage area may be adjacent to and located after the second preset storage area.
It should be noted that, in the prior art, when the target device performs a flush operation, the storage area of the target device may be formatted into a target format in which a file system can operate, for example, for a linux system, the target format may be ext 4. The method and the device can acquire the size of the target file corresponding to the target starting file in advance, determine the preset storage area according to the size of the target file, and control the target device not to perform formatting operation on the preset storage area when performing the flashing operation.
In this step, after the second preset storage address is obtained, the size of the target file may be obtained from the second preset storage area according to the second preset storage address.
S205, storing the size of the target file in the preset environment variable.
In this step, after the size of the target file stored in the preset storage area is obtained, the size of the target file may be stored in the preset environment variable, so that the target device may read the size of the target file from the preset environment variable when the target device is started next time. Illustratively, the value of the preset environment variable may be updated to the target file size.
S206, loading the target start file with the size of the target file from the preset storage area of the target device according to the first preset storage address.
The first predetermined storage address may be a start address of the first predetermined storage area.
In this step, after obtaining the size of the target file corresponding to the target boot file, the preset first preset storage address may be obtained, and the target boot file is loaded after obtaining the target boot file from the preset storage area according to the first preset storage address and the size of the target file.
And S207, running the target starting file to start the target equipment.
By adopting the method, when the target starting file is loaded, the target starting file can be loaded through the first preset storage address corresponding to the target starting file, so that the target starting file of the target equipment can be normally loaded under the condition that a file system is abnormal, and the target equipment can be normally started. In addition, the size of the target file can be stored in the preset environment variable, the acquisition efficiency of the size of the target file is improved, and therefore the starting speed of the target device can be improved.
Fig. 3 is a block diagram illustrating an apparatus for activating a device according to an exemplary embodiment, which may include, as shown in fig. 3:
a first file size obtaining module 301, configured to obtain a size of a target file corresponding to a target startup file in a target device;
a file obtaining module 302, configured to load the target startup file with the size of the target file from a preset storage area of the target device according to a first preset storage address;
an operation module 303, configured to operate the target start-up file to start the target device.
Optionally, the first file size obtaining module 301 is further configured to:
determining whether the target file size is stored in a preset environment variable of the target device;
and under the condition that the size of the target file is stored in the preset environment variable, acquiring the size of the target file from the preset environment variable.
Optionally, fig. 4 is a block diagram illustrating another device activation apparatus according to an exemplary embodiment, and as shown in fig. 4, the apparatus further includes:
an address obtaining module 304, configured to obtain a second preset storage address when the size of the target file is not stored in the preset environment variable;
a second file size obtaining module 305, configured to obtain the size of the target file stored in the preset storage area of the target device according to the second preset storage address;
the storage module 306 is configured to store the size of the target file in the preset environment variable.
Optionally, the preset storage area comprises a raw partition.
By the device, when the target starting file is loaded, the target starting file can be loaded through the first preset storage address corresponding to the target starting file, so that the target starting file of the target equipment can be normally loaded under the condition that a file system is abnormal, and the target equipment can be normally started.
With regard to the apparatus in the above-described embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.
Fig. 5 is a block diagram illustrating an electronic device 500 in accordance with an example embodiment. As shown in fig. 5, the electronic device 500 may include: a processor 501 and a memory 502. The electronic device 500 may also include one or more of a multimedia component 503, an input/output (I/O) interface 504, and a communication component 505.
The processor 501 is configured to control the overall operation of the electronic device 500, so as to complete all or part of the steps in the device booting method. The memory 502 is used to store various types of data to support operation at the electronic device 500, such as instructions for any application or method operating on the electronic device 500 and application-related data, such as contact data, messaging, pictures, audio, video, and so forth. The Memory 502 may be implemented by any type of volatile or non-volatile Memory device or combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read-Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic Memory, flash Memory, magnetic disk or optical disk. The multimedia component 503 may include a screen and an audio component. Wherein the screen may be, for example, a touch screen and the audio component is used for outputting and/or inputting audio signals. For example, the audio component may include a microphone for receiving external audio signals. The received audio signal may further be stored in the memory 502 or transmitted through the communication component 505. The audio assembly also includes at least one speaker for outputting audio signals. The I/O interface 504 provides an interface between the processor 501 and other interface modules, such as a keyboard, mouse, buttons, etc. These buttons may be virtual buttons or physical buttons. The communication component 505 is used for wired or wireless communication between the electronic device 500 and other devices. Wireless Communication, such as Wi-Fi, bluetooth, Near Field Communication (NFC), 2G, 3G, 4G, NB-IOT, eMTC, or other 5G, etc., or a combination of one or more of them, which is not limited herein. The corresponding communication component 505 may thus comprise: Wi-Fi module, Bluetooth module, NFC module, etc.
In an exemplary embodiment, the electronic Device 500 may be implemented by one or more Application Specific Integrated Circuits (ASICs), Digital Signal Processors (DSPs), Digital Signal Processing Devices (DSPDs), Programmable Logic Devices (PLDs), Field Programmable Gate Arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components for performing the above-mentioned Device start-up method.
In another exemplary embodiment, a computer readable storage medium comprising program instructions which, when executed by a processor, implement the steps of the above-described device booting method is also provided. For example, the computer readable storage medium may be the memory 502 described above comprising program instructions executable by the processor 501 of the electronic device 500 to perform the device booting method described above.
In another exemplary embodiment, a computer program product is also provided, which comprises a computer program executable by a programmable apparatus, the computer program having code portions for performing the above-mentioned device start-up method when executed by the programmable apparatus.
The preferred embodiments of the present disclosure are described in detail with reference to the accompanying drawings, however, the present disclosure is not limited to the specific details of the above embodiments, and various simple modifications may be made to the technical solution of the present disclosure within the technical idea of the present disclosure, and these simple modifications all belong to the protection scope of the present disclosure. It should be noted that, in the foregoing embodiments, various features described in the above embodiments may be combined in any suitable manner, and in order to avoid unnecessary repetition, various combinations that are possible in the present disclosure are not described again.
In addition, any combination of various embodiments of the present disclosure may be made, and the same should be considered as the disclosure of the present disclosure, as long as it does not depart from the spirit of the present disclosure.