A method and device for generating a partition based on mirror burning
By using a method of generating partitions through image burning, the partition table is automatically generated and the image data is merged, which solves the problems of inconvenient operation and large memory consumption of surface-mount SD interface storage devices, and achieves flexible partitioning and memory saving.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GUANGZHOU ANYKA MICROELECTRONICS CO LTD
- Filing Date
- 2024-12-17
- Publication Date
- 2026-06-19
AI Technical Summary
Traditional methods are inconvenient for partitioning surface-mount SD interface storage devices, and their reliance on Linux systems leads to high memory consumption, while manual partitioning is prone to errors.
The partition generation method, which uses image burning, automatically generates a partition table and merges image data using the Master Boot Record and Extended Boot Record, and writes it directly to the storage device, reducing memory dependency.
It enables flexible partitioning of SD interface storage devices, reduces memory usage, lowers operational complexity and error rate, and is suitable for different types of storage devices.
Smart Images

Figure CN122240134A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method and apparatus for generating partitions based on image burning. Background Technology
[0002] There are two traditional methods for partitioning SD interface storage devices: one is based on PC-based partitioning software such as WinPM, which partitions the portable SD interface storage device; the other is based on the Linux kernel's system call fdisk command for partitioning. This method relies on the Linux system, requiring the entire Linux system to be running beforehand. However, the Linux file system (rootfs) needs to be mounted on a physical partition in order for the entire Linux system to boot.
[0003] However, the first method requires connecting a mobile SD interface storage device to the PC for operation. For surface-mount SD interface storage devices, since they are usually fixed on the device, it is not easy to connect them directly to the PC for operation, so the applicability is poor. The second method does not have a physical partition, so the rootfs is usually directly mounted in memory, which occupies memory space. If the physical partition is created manually, it is easy to cause the creation error due to manually entering the creation command. Summary of the Invention
[0004] This application provides a method and apparatus for generating partitions based on image burning, which can avoid dependence on external software, improve the flexibility of partitioning SD interface storage devices, and save memory space.
[0005] In a first aspect, embodiments of this application provide a method for generating partitions based on image burning, characterized in that it includes:
[0006] Obtain the configuration information of the image to be burned, including the starting address, file size and type information;
[0007] The filling number of each image to be burned is determined based on the preset system information and type information;
[0008] Determine whether the number of images to be burned is less than or equal to a preset threshold;
[0009] If so, the configuration information of the image to be burned will be written into the partition table of the master boot record in sequence according to the filling number;
[0010] If not, determine the extended information based on the image to be burned whose fill number is equal to the preset threshold minus 1; write the configuration information and extended information of the image to be burned whose fill number is less than the preset threshold into the partition table of the master boot record in sequence;
[0011] Write the configuration information of the images to be burned with a fill number greater than or equal to the preset threshold into the extended boot record;
[0012] The partition table of the master boot record and the image to be burned with the filling number 1 are merged into the first firmware;
[0013] Write the first firmware to the SD interface storage device.
[0014] Furthermore, the preset threshold is 4;
[0015] The partition table in the Master Boot Record includes the first primary partition, the second primary partition, the third primary partition, and the fourth primary partition;
[0016] The above-mentioned configuration information of the image to be burned is sequentially written into the partition table of the Master Boot Record according to the filling number, including:
[0017] If the fill number is 1, the configuration information of the image to be burned will be written to the first primary partition;
[0018] If the fill number is 2, then the configuration information of the image to be burned will be written to the second primary partition;
[0019] If the fill number is 3, the configuration information of the image to be burned will be written to the third primary partition;
[0020] If the fill number is 4, the configuration information of the image to be burned will be written to the fourth primary partition.
[0021] Furthermore, the configuration information and extended information of the images to be burned, whose filler numbers are less than a preset threshold, are sequentially written into the partition table of the Master Boot Record, including:
[0022] Write the configuration information of the image to be burned, which has the number 1, into the first primary partition;
[0023] Write the configuration information of the image to be burned, which has the number 2, into the second main partition;
[0024] Write the configuration information of the image to be burned, which has the number 3, into the third main partition;
[0025] Write extended information to the fourth primary partition.
[0026] Furthermore, the method also includes:
[0027] After writing the configuration information of the images to be burned with a fill number greater than or equal to a preset threshold into the extended boot record, the extended boot records and the corresponding images to be burned are merged to obtain multiple second firmware;
[0028] Write each second firmware to the SD interface storage device.
[0029] Furthermore, the method also includes:
[0030] Construct an array of length 512 bytes to serve as the master boot record;
[0031] Use bytes 447 to 510 of the Master Boot Record as the partition table;
[0032] Bytes 447 to 462 of the partition table are designated as the first primary partition; bytes 463 to 478 are designated as the second primary partition; bytes 479 to 494 are designated as the third primary partition; bytes 495 to 510 are designated as the fourth primary partition; after writing the configuration information of all images to be burned into the partition table, bytes 511 and 512 of the master boot record are set as the end marker.
[0033] Furthermore, the above-mentioned process of writing the configuration information of the image to be burned into the first primary partition includes:
[0034] The starting address of the image to be burned is resolved into the starting address of the logical block;
[0035] The file size of the image to be burned is parsed into logical block sizes;
[0036] Write the logical block start address, logical block size, and type information into the first primary partition; the logical block start address and logical block size are located in the 9th to 16th bytes of the first primary partition.
[0037] Furthermore, the extended information determined based on the image to be programmed with a fill number equal to a preset threshold minus 1 includes:
[0038] Obtain the starting address and file size of the image to be burned whose fill number is equal to the preset threshold minus 1;
[0039] Add the starting address and the file size to get the extended starting offset;
[0040] Subtract the expansion start offset from the preset disk capacity to obtain the expansion record size;
[0041] Use the extended starting offset and extended record size as extended information.
[0042] Furthermore, the above-mentioned writing of configuration information for images to be burned with a filler number greater than or equal to a preset threshold into the extended boot record includes:
[0043] Construct an array of length 512 bytes as an extended boot record;
[0044] Use bytes 447 to 462 of the extended boot record as the first extended partition;
[0045] Use bytes 463 to 478 of the extended boot record as the second extended partition;
[0046] Write the configuration information of the image to be burned to the first extended partition;
[0047] Write the configuration information of the next image to be burned to the second extended partition;
[0048] Set the 511th and 512th bytes of the extended boot record as the end marker.
[0049] Furthermore, the starting address of the logical block in the first extended partition is 0x2000;
[0050] The type information in the second extended partition is 0x05.
[0051] Secondly, embodiments of this application provide an apparatus for generating partitions based on image burning, comprising:
[0052] The acquisition module is used to obtain the configuration information of the image to be burned, including the starting address, file size and type information;
[0053] The sequence determination module is used to determine the filling number of each image to be burned based on preset system information and type information;
[0054] The judgment module determines whether the number of images to be burned is less than or equal to a preset threshold.
[0055] The first partition module is used to write the configuration information of the image to be burned into the partition table of the master boot record according to the filling number when the judgment result of the judgment module is yes.
[0056] The second partition module is used to determine the extended information based on the image to be burned with the fill number equal to the preset threshold minus 1 when the judgment result is negative; to write the configuration information and extended information of the image to be burned with the fill number less than the preset threshold into the partition table of the master boot record in sequence; and to write the configuration information of the image to be burned with the fill number greater than or equal to the preset threshold into the extended boot record.
[0057] The first merging module is used to merge the partition table of the master boot record and the image to be burned with the fill number 1 into the first firmware; and write the first firmware to the storage device with the SD interface.
[0058] Furthermore, the first partition module is specifically used to perform the following steps:
[0059] If the fill number is 1, the configuration information of the image to be burned will be written to the first primary partition;
[0060] If the fill number is 2, then the configuration information of the image to be burned will be written to the second primary partition;
[0061] If the fill number is 3, the configuration information of the image to be burned will be written to the third primary partition;
[0062] If the fill number is 4, the configuration information of the image to be burned will be written to the fourth primary partition.
[0063] Furthermore, the second partition module is specifically used to perform the following steps:
[0064] Write the configuration information of the image to be burned, which has the number 1, into the first primary partition;
[0065] Write the configuration information of the image to be burned, which has the number 2, into the second main partition;
[0066] Write the configuration information of the image to be burned, which has the number 3, into the third main partition;
[0067] Write extended information to the fourth primary partition.
[0068] Furthermore, the device also includes a second merging module, used to: after writing the configuration information of the images to be burned with a fill number greater than or equal to a preset threshold into the extended boot record, merge each extended boot record and the corresponding image to be burned to obtain multiple second firmware; and write each second firmware into the storage device of the SD interface.
[0069] Furthermore, the device also includes:
[0070] The first building module is used to construct an array of 512 bytes as the master boot record;
[0071] The partition table determination module is used to determine the 447th to 510th bytes of the Master Boot Record as the partition table.
[0072] The partitioning module is used to designate bytes 447 to 462 of the partition table as the first primary partition; bytes 463 to 478 of the partition table as the second primary partition; bytes 479 to 494 of the partition table as the third primary partition; and bytes 495 to 510 of the partition table as the fourth primary partition.
[0073] The first termination module is used to set the 511th and 512th bytes of the master boot record as the termination flag after writing the configuration information of all images to be burned into the partition table.
[0074] Furthermore, the aforementioned first partition module is specifically used for:
[0075] The starting address of the image to be burned is resolved into the starting address of the logical block;
[0076] The file size of the image to be burned is parsed into logical block sizes;
[0077] Write the logical block start address, logical block size, and type information into the first primary partition; the logical block start address and logical block size are located in the 9th to 16th bytes of the first primary partition.
[0078] Furthermore, the aforementioned second partition module is also specifically used to perform the following steps:
[0079] Obtain the starting address and file size of the image to be burned whose fill number is equal to the preset threshold minus 1;
[0080] Add the starting address and the file size to get the extended starting offset;
[0081] Subtract the expansion start offset from the preset disk capacity to obtain the expansion record size;
[0082] Use the extended starting offset and extended record size as extended information.
[0083] Furthermore, the aforementioned second partition module is also specifically used to perform the following steps:
[0084] Construct an array of length 512 bytes as an extended boot record;
[0085] Use bytes 447 to 462 of the extended boot record as the first extended partition;
[0086] Use bytes 463 to 478 of the extended boot record as the second extended partition;
[0087] Write the configuration information of the image to be burned to the first extended partition;
[0088] Write the configuration information of the next image to be burned to the second extended partition;
[0089] Set the 511th and 512th bytes of the extended boot record as the end marker.
[0090] Thirdly, embodiments of this application provide a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it performs the steps of a method for generating a partition based on image burning as described in any of the above embodiments.
[0091] Fourthly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, it implements the steps of a method for generating a partition based on image burning as described in any of the above embodiments.
[0092] In summary, compared with the prior art, the beneficial effects of the technical solution provided in this application include at least the following:
[0093] This application provides a method for generating partitions based on image burning. During image burning, a partition table for the Master Boot Record (MBR) is formed based on the starting address, file size, and type information of the image to be burned. The MBR partition table and the first image to be burned are then merged into a first firmware and written to an SD interface storage device. Firstly, the user only needs to perform a burning operation to complete partitioning and image burning; that is, this application only requires a burning tool to achieve partitioning, applicable to partitioning different types of SD interface storage devices. Secondly, this application directly integrates the MBR partition table and the first image to be burned into the first firmware, so that the first firmware already contains partition information. This allows the partition information to be read directly from the firmware to obtain the image, without needing to maintain a complete file system image in memory. When the Linux system boots, the roofs image can be read directly from the storage device without additional memory loading steps, thereby reducing memory usage. Attached Figure Description
[0094] Figure 1 A flowchart illustrating a method for generating a partition based on image burning, provided as an exemplary embodiment of this application.
[0095] Figure 2 This is a schematic diagram of the partitions of the Master Boot Record and Extended Boot Record provided for an exemplary embodiment of this application.
[0096] Figure 3 A flowchart of the Master Boot Record partitioning steps provided for an exemplary embodiment of this application.
[0097] Figure 4 A flowchart illustrating the steps of parsing the image to be burned, provided as an exemplary embodiment of this application.
[0098] Figure 5 A flowchart illustrating the extended information determination steps provided for an exemplary embodiment of this application.
[0099] Figure 6 A flowchart of the extended boot record partitioning steps provided for an exemplary embodiment of this application.
[0100] Figure 7 This is a structural diagram of an apparatus for generating partitions based on image burning, provided as an exemplary embodiment of this application. Detailed Implementation
[0101] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.
[0102] Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0103] Terminology Explanation:
[0104] 1) Image: An image refers to a single firmware file packaged from the files or folders to be burned using a specific command-line tool. Common types of images used in burning include:
[0105] 1. The required U-Boot image needs to be used to boot the Linux or RTOS system.
[0106] 2. For Linux or TOS systems that require a boot kernel image, it can be packaged into a FAT type image.
[0107] 3. Package the rootfs file system into an image.
[0108] 4. You can also package specified files or folders into an image as needed.
[0109] 5. The read / write types of the mirror include the readable and writable fat type, as well as the read-only squashfs type, etc.
[0110] 2) Master Boot Record: The MBR (Master Boot Record) is the first sector of the hard drive. It contains the hard drive partition table and the boot program. The hard drive partition table records information such as the location and size of all partitions on the hard drive, while the boot program is responsible for booting the operating system. The MBR occupies one sector, which is 512 bytes.
[0111] 3) LBA: Logical Block Address. LBA is a method for accessing and managing data in storage devices. It divides the storage device into fixed-size logical blocks, each with a unique LBA. A logical block is the smallest addressable unit in a storage device, typically 4KB or larger. Through LBA, the operating system or application can directly specify the location of data to be read or written, achieving efficient data access and management.
[0112] 4) Extended Boot Record: The EBR (Extended Boot Record) is the boot sector in the extended partition. It records information about the logical partitions in the extended partition, including the location and size of the logical partitions.
[0113] The EBR has a similar structure to the MBR, but it lacks a bootloader and disk signature, retaining only the partition table and end marker. The primary function of the EBR is to manage links between logical drives.
[0114] Please see Figure 1 and Figure 2 This application provides a method for generating partitions based on image burning, including:
[0115] Step S11: Obtain the configuration information of the image to be burned. The configuration information includes the starting address, file size, and type information. Among them, the type information includes the content and read / write type of the image to be burned.
[0116] Step S12: Determine the filling number of each image to be burned based on the preset system information and type information.
[0117] The preset system information refers to the system type to which the SD interface storage device is connected.
[0118] Specifically, the filling number of the image to be burned is determined by the boot process of the currently used system.
[0119] For example, in Linux or RTOS systems, the padding number for the uboot image is 1; the padding number for the dtb image is 2; the padding number for the kernel image is 3; and the padding number for the rootfs image is 4.
[0120] Step S13: Determine whether the number of images to be burned is less than or equal to a preset threshold.
[0121] Step S14: If yes, then write the configuration information of the image to be burned into the partition table of the master boot record sequentially according to the filling number. The preset threshold can be 4; the partition table of the master boot record includes the first primary partition, the second primary partition, the third primary partition, and the fourth primary partition; that is, the preset threshold is equal to the number of partitions in the partition table of the master boot record.
[0122] The above-mentioned configuration information of the image to be burned is sequentially written into the partition table of the Master Boot Record according to the filling number, including:
[0123] If the fill number is 1, the configuration information of the image to be burned will be written to the first primary partition.
[0124] If the fill number is 2, the configuration information of the image to be burned will be written to the second primary partition.
[0125] If the fill number is 3, the configuration information of the image to be burned will be written to the third primary partition.
[0126] If the fill number is 4, the configuration information of the image to be burned will be written to the fourth primary partition.
[0127] When the number of images to be burned is less than 4, the remaining primary partitions do not need to be set; for example, if there are only 2 images, then only the first and second primary partitions have partition information written, while the third and fourth primary partitions are empty.
[0128] Step S15: If not, determine the extended information based on the image to be burned whose fill number is equal to the preset threshold minus 1; write the configuration information and extended information of the image to be burned whose fill number is less than the preset threshold into the partition table of the master boot record in sequence.
[0129] Specifically, the process of sequentially writing the configuration information and extended information of the images to be burned (with numbers less than a preset threshold) into the partition table of the Master Boot Record can include:
[0130] Write the configuration information of the image to be burned, which has the number 1, into the first primary partition.
[0131] Write the configuration information of the image to be burned, which has the number 2, into the second primary partition.
[0132] Write the configuration information of the image to be burned, numbered 3, into the third primary partition.
[0133] Write extended information to the fourth primary partition.
[0134] It can be assumed that when the number of images to be burned is greater than 4, only the partition information of the first 3 main partitions is the configuration information of the images to be burned, and the partition information of the fourth main partition is the extended information.
[0135] This application generates the partition information of the corresponding main partition by parsing the starting address, file size and type of the image to be burned, which can ensure the accuracy and consistency of the partition.
[0136] Step S16: Write the configuration information of the images to be burned with a fill number greater than or equal to a preset threshold into the extended boot record.
[0137] Specifically, each image to be burned corresponds to one extended boot record, meaning the number of extended boot records is equal to the number of images to be burned whose filler numbers are greater than or equal to a preset threshold.
[0138] Step S17: Merge the partition table of the master boot record and the image to be burned with the filling number 1 into the first firmware.
[0139] Step S18: Write the first firmware to the storage device with the SD interface.
[0140] Specifically, merging the partition table and image of the master boot record into a single firmware means that during the burning process, not only is the image data written to the SD interface storage device, but also the partition table information that defines how this image data is organized is written together. This not only allows partitioning and data writing to be completed in a single burning step without the need for additional partitioning steps or the use of partitioning software, but also avoids users having to handle partition creation and data burning separately, reducing the complexity and error rate of the operation.
[0141] In addition, merging the image and partition information can reduce the overall burning time because there is no need to process the partitions separately after burning the image; and the merged first firmware can adapt to different types of storage devices, whether it is a removable SD card or a surface-mount (non-removable) SD NAND device. Since the partition information and operating system image are pre-stored and configured, the system can identify and load the necessary components more quickly during startup.
[0142] The above embodiments provide a method for generating partitions based on image burning. During image burning, a partition table for the Master Boot Record (MBR) is formed based on the starting address, file size, and type information of the image to be burned. The MBR partition table and the first image to be burned are then merged into a first firmware and written to the SD interface storage device. Firstly, the user only needs to perform a burning operation to complete partitioning and image burning; that is, this application only requires a burning tool to achieve partitioning, applicable to partitioning different types of SD interface storage devices. Secondly, this application directly integrates the MBR partition table and the first image to be burned into the first firmware, so that the first firmware already contains partition information. This allows the partition information to be read directly from the firmware to obtain the image, without needing to maintain a complete file system image in memory. When the Linux system starts, the roofs image can be read directly from the storage device without additional memory loading steps, thereby reducing memory usage.
[0143] In some embodiments, the method further includes:
[0144] Step S21: After writing the configuration information of the images to be burned with a fill number greater than or equal to a preset threshold into the extended boot record, merge each extended boot record and the corresponding image to be burned to obtain multiple second firmware.
[0145] Step S22: Write each of the second firmwares to the storage device of the SD interface.
[0146] Specifically, in addition to the partition table of the Master Boot Record, the partition information of the Extended Boot Record can also be written to the storage device in the form of firmware, so that the system can directly read it from the storage device without accessing memory.
[0147] Please see Figure 3In some embodiments, the method further includes:
[0148] Step S31: Construct an array of length 512 bytes as the master boot record.
[0149] Step S32: Use bytes 447 to 510 of the Master Boot Record as the partition table.
[0150] Specifically, the last two bytes of the Master Boot Record are the end marker, and the 64 bytes before the end marker are the partition table.
[0151] Step S33: Use bytes 447 to 462 of the partition table as the first primary partition.
[0152] Step S34: Bytes 463 to 478 of the partition table are used as the second primary partition.
[0153] Step S35: Bytes 479 to 494 of the partition table are designated as the third primary partition.
[0154] Step S36: Bytes 495 to 510 of the partition table are designated as the fourth primary partition.
[0155] Specifically, each primary partition requires 16 bytes to record its partition information, so at most only 4 partition information entries can be written into the 64-byte partition table of the Master Boot Record (first sector).
[0156] Step S37: After writing the configuration information of all images to be burned into the partition table, set the 511th and 512th bytes of the master boot record as the end marker.
[0157] The 511th byte is 0x55 and the 512th byte is 0xaa, which indicate the end of the partition table.
[0158] Please see Figure 4 In some embodiments, writing the configuration information of the image to be burned into the first primary partition includes:
[0159] Step S141: The starting address of the image to be burned is resolved into the starting address of the logical block.
[0160] Step S142: The file size of the image to be burned is parsed into logical block size.
[0161] Specifically, the above steps involve resolving the starting address of the image to be burned into the starting LBA address, and resolving the size of the image to be burned into the total number of sectors LBA address, thereby obtaining the LBA data.
[0162] Step S143: Write the logical block start address, logical block size, and type information into the first primary partition; wherein the logical block start address and logical block size are located in the 9th to 16th bytes of the first primary partition.
[0163] Specifically, the operations of writing the configuration information of the image to be burned with the number 1 to the first main partition, writing the configuration information of the image to be burned with the number 2 to the second main partition, and writing the configuration information of the image to be burned with the number 3 to the third main partition are the same as those of the first main partition. It is worth noting that the LBA data, namely the starting LBA address and the total number of sectors LBA address, occupies the 9th to 16th bytes of the target main partition, and the type information occupies the 1st to 8th bytes.
[0164] Please see Figure 5 In some embodiments, determining extended information based on the image to be programmed with a fill number equal to a preset threshold minus 1 may specifically include the following steps:
[0165] Step S151: Obtain the starting address and file size of the image to be burned, where the filling number is equal to the preset threshold minus 1.
[0166] Step S152: Add the starting address and the file size to obtain the extended starting offset.
[0167] Step S153: Subtract the expansion start offset from the preset disk capacity to obtain the expansion record size.
[0168] Specifically, the starting offset of the overall extended boot record = the starting address of the third image + its size, and the size of the overall extended boot record = the preset disk capacity - the starting offset of the extension.
[0169] Step S154: Use the extended starting offset and extended record size as extended information.
[0170] The above embodiment places the extended starting offset and extended record size as extended information into the fourth primary partition of the master boot record, so that the extended boot record can be found through the master boot record when reading sectors at boot.
[0171] Please see Figure 6 In some embodiments, writing the configuration information of the image to be burned with a fill number greater than or equal to a preset threshold into the extended boot record may specifically include:
[0172] Step S251: Construct an array of length 512 bytes as an extended boot record.
[0173] Step S252: Bytes 447 to 462 of the extended boot record are used as the first extended partition.
[0174] Step S253: Bytes 463 to 478 of the extended boot record are used as the second extended partition.
[0175] Specifically, the extended boot record also sets up the partition table in the 64 bytes before the last two bytes, but only the first 32 bytes of the 64 bytes set up two partitions, and the last 32 bytes are invalid bytes.
[0176] Step S254: Write the configuration information of the image to be burned into the first extended partition.
[0177] Step S255: Write the configuration information of the next image to be burned into the second extended partition.
[0178] Specifically, the "next image to be burned" here refers to the image to be burned corresponding to the padding code of the image to be burned corresponding to the first extended partition plus 1, that is, each extended boot record contains configuration information for two images to be burned.
[0179] However, when merging the second firmware, the partition information of the two extended partitions of the extended boot record is only merged with the image to be burned corresponding to the first extended partition to obtain the second firmware.
[0180] Step S256: Set the 511th and 512th bytes of the extended boot record as the end marker.
[0181] Specifically, unlike the partition information formed by the image in the Master Boot Record, the starting address of the logical block for burning the first extended partition in the Extended Boot Record is not the starting address of the image to be burned, but a fixed address.
[0182] In this application, the starting address of the logical block in the first extended partition is fixed at 0x2000, that is, 0x2000 is used as the starting LBA address of the first extended partition. Then, the file size of the image to be burned is parsed into the logical block size, that is, the total number of sectors LBA address, which together with the starting LBA address constitutes LBA data, and is then placed into the first extended partition along with the type information.
[0183] The starting address of the logical block placed in the second extended partition is the starting address of the next image to be burned, so that the current extended boot record can be linked to the next extended boot record.
[0184] Then, the file size of the next image to be burned is resolved into the logical block size of the second extended partition, so that it can be connected to the size LBA address of the image to be burned in the next extended boot record.
[0185] Finally, in addition to using the logical block start address and logical block size of the next image to be burned as LBA data and placing them in the second extended partition, its type information is also fixed at 0x05 and placed in the second extended partition.
[0186] This can be understood as follows: in each extended boot record, regardless of the content of the image to be burned, the starting address of the logical block of the first extended partition is fixed at 0x2000, and the type information in the second extended partition is fixed at 0x05.
[0187] The following specific embodiment illustrates the execution flow of the partitioning method of this application:
[0188] First, obtain the starting address, file size, and type information for burning the uboot.bin, env.img, dtb.fat.img, uimage.fat.img, and rootfs.sqsh4 images of each Linux system, as follows:
[0189] download1=u-boot.bin,0x0,uboot_size,0,flag1
[0190] download2=env.img,env_start,env_size,0,flag2
[0191] download3=dtb.fat32.img,dtb_start,dtb_size,0,flag3
[0192] download4=uImage.fat32.img,kernel_start,kernel_size,0,flag4
[0193] download5=root.sqsh4,rootfs_start,rootfs_size,0,flag5
[0194] We can determine whether the number of images obtained above is greater than 4; we know that the number of images is 5, which is greater than 4.
[0195] Therefore, uboot_start, uboot_size, and flag1 are obtained and used as the first image. The first primary partition of the Master Boot Record is set, and the partition information of the first primary partition of the MBR is generated by parsing the uboot.bin image.
[0196] Obtain env_start, env_size, and flag2, which will be used as the second image. Set the second primary partition of the Master Boot Record (MBR) and execute the parsing of the env.img image to generate the partition information of the second primary partition of the MBR.
[0197] Obtain dtb_start, dtb_size, and flag3, which will be used as the third image. Set the third primary partition of the Master Boot Record (MBR) and execute the parsing of the dtb.fat.img image to generate the partition information of the third primary partition of the MBR.
[0198] Calculate ebr_start (extended start offset) = dtb_start (start address of the 3rd image) + dtb_size (file size of the 3rd image), ebr_size (extended record size) = preset disk capacity - ebr_start, the type information is fixed at 0x05, and execute the parsing of the entire extended boot record to generate the partition information of the fourth primary partition of the MBR.
[0199] The partition information of the MBR is merged with the uboot.bin image into a single firmware.
[0200] After obtaining kernel_size, ebr_start, flag5, rootfs_start, and rootfs_size, the system automatically parses the uImage.fat32.img image to generate the partition information of the first extended partition of the first extended boot record; the partition information of the first extended partition of the first extended boot record is merged with the uImage.fat32.img image into a single firmware, i.e., the second firmware.
[0201] Obtain the rootfs_size, ebr_start, and flag6 of the next image, and automatically parse the root.sqsh4 image to generate the partition information of the second extended partition of the first extended boot record and the partition information of the first extended partition of the second extended boot record; write 0 to the partition information of the second extended partition of the second extended boot record, and merge the partition information of the first extended partition of the second extended boot record with the root.sqsh4 image into a single firmware, namely the second firmware.
[0202] The obtained first firmware and each of the second firmware are burned to a storage device with an SD protocol interface.
[0203] Please see Figure 7 Another embodiment of this application provides an apparatus for generating partitions based on image burning, comprising:
[0204] The acquisition module 101 is used to acquire the configuration information of the image to be burned, including the starting address, file size and type information.
[0205] The sequence determination module 102 is used to determine the filling number of each image to be burned based on preset system information and type information.
[0206] The judgment module 103 determines whether the number of images to be burned is less than or equal to a preset threshold.
[0207] The first partition module 104 is used to write the configuration information of the image to be burned into the partition table of the master boot record according to the filling number when the judgment result of the judgment module 103 is yes.
[0208] The second partition module 105 is used to determine extended information based on the image to be burned with a fill number equal to a preset threshold minus 1 when the judgment result is negative; to write the configuration information and extended information of the image to be burned with a fill number less than the preset threshold into the partition table of the master boot record in sequence; and to write the configuration information of the image to be burned with a fill number greater than or equal to the preset threshold into the extended boot record.
[0209] The first merging module 106 is used to merge the partition table of the master boot record and the image to be burned with the fill number 1 into the first firmware; and write the first firmware to the storage device with the SD interface.
[0210] Furthermore, the first partition module 104 is specifically used to perform the following steps:
[0211] If the fill number is 1, the configuration information of the image to be burned will be written to the first primary partition.
[0212] If the fill number is 2, the configuration information of the image to be burned will be written to the second primary partition.
[0213] If the fill number is 3, the configuration information of the image to be burned will be written to the third primary partition.
[0214] If the fill number is 4, the configuration information of the image to be burned will be written to the fourth primary partition.
[0215] Furthermore, the second partition module 105 is specifically used to perform the following steps:
[0216] Write the configuration information of the image to be burned, which has the number 1, into the first primary partition.
[0217] Write the configuration information of the image to be burned, which has the number 2, into the second primary partition.
[0218] Write the configuration information of the image to be burned, numbered 3, into the third primary partition.
[0219] Write extended information to the fourth primary partition.
[0220] Furthermore, it also includes a second merging module, used to: after writing the configuration information of the images to be burned with a fill number greater than or equal to a preset threshold into the extended boot record, merge each extended boot record and the corresponding image to be burned to obtain multiple second firmware; and write each second firmware into the storage device of the SD interface.
[0221] Furthermore, the device also includes:
[0222] The first building module is used to construct an array of 512 bytes as the master boot record.
[0223] The partition table determination module is used to determine the 447th to 510th bytes of the Master Boot Record as the partition table.
[0224] The partitioning module is used to designate bytes 447 to 462 of the partition table as the first primary partition; bytes 463 to 478 of the partition table as the second primary partition; bytes 479 to 494 of the partition table as the third primary partition; and bytes 495 to 510 of the partition table as the fourth primary partition.
[0225] The first termination module is used to set the 511th and 512th bytes of the master boot record as the termination flag after writing the configuration information of all images to be burned into the partition table.
[0226] Furthermore, the aforementioned first partition module 104 is specifically used for:
[0227] The starting address of the image to be burned is resolved into the starting address of the logical block.
[0228] The file size of the image to be burned is parsed into logical block sizes.
[0229] Write the logical block start address, logical block size, and type information into the first primary partition; the logical block start address and logical block size are located in the 9th to 16th bytes of the first primary partition.
[0230] Furthermore, the aforementioned second partition module 105 is also specifically used to perform the following steps:
[0231] Obtain the starting address and file size of the image to be burned whose fill number is equal to the preset threshold minus 1.
[0232] Add the starting address and the file size to get the extended starting offset.
[0233] Subtract the expansion start offset from the preset disk capacity to obtain the expanded record size.
[0234] Use the extended starting offset and extended record size as extended information.
[0235] Furthermore, the aforementioned second partition module 105 is also specifically used to perform the following steps:
[0236] Construct an array of length 512 bytes as the extended boot record.
[0237] Use bytes 447 to 462 of the extended boot record as the first extended partition.
[0238] Bytes 463 to 478 of the extended boot record are used as the second extended partition.
[0239] Write the configuration information of the image to be burned to the first extended partition.
[0240] Write the configuration information of the next image to be burned to the second extended partition.
[0241] Set the 511th and 512th bytes of the extended boot record as the end marker.
[0242] The specific limitations of the device for generating partitions based on image burning provided in this embodiment can be found in the embodiment of the method for generating partitions based on image burning described above, and will not be repeated here. Each module in the above-described device for generating partitions based on image burning can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0243] This application provides a computer device that may include a processor, memory, network interface, and database connected via a system bus. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface communicates with external terminals via a network connection. When the computer program is executed by the processor, it causes the processor to perform the steps of a method for generating a partition based on image burning, as described in any of the above embodiments.
[0244] The working process, working details and technical effects of the computer device provided in this embodiment can be found in the embodiment of a method for generating partitions based on image burning described above, and will not be repeated here.
[0245] This application provides a computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program implements the steps of a method for generating a partition based on image burning, as described in any of the above embodiments. The computer-readable storage medium refers to a data storage medium, which may include, but is not limited to, floppy disks, optical disks, hard disks, flash memory, USB flash drives, and / or Memory Sticks. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The working process, details, and technical effects of the computer-readable storage medium provided in this embodiment can be found in the above embodiments regarding a method for generating a partition based on image burning, and will not be repeated here.
[0246] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM).
[0247] 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.
[0248] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.
Claims
1. A method for generating partitions based on image burning, characterized in that, include: Obtain the configuration information of the image to be burned, including the starting address, file size and type information; The filling number of each image to be burned is determined based on the preset system information and the type information; Determine whether the number of images of the image to be burned is less than or equal to a preset threshold; If so, the configuration information of the image to be burned will be written into the partition table of the master boot record in sequence according to the filling number; If not, determine the extended information based on the image to be burned with a fill number equal to the preset threshold minus 1; write the configuration information of the image to be burned with a fill number less than the preset threshold and the extended information into the partition table of the master boot record in sequence; Write the configuration information of the images to be burned with a fill number greater than or equal to the preset threshold into the extended boot record; The partition table of the master boot record and the image to be burned with the filling number 1 are merged into the first firmware; Write the first firmware to the SD interface storage device.
2. The method for generating partitions based on image burning according to claim 1, characterized in that, The preset threshold is 4; the partition table of the master boot record includes a first primary partition, a second primary partition, a third primary partition, and a fourth primary partition; The step of writing the configuration information of the image to be burned into the partition table of the master boot record sequentially according to the filling number includes: If the filling number is 1, then the configuration information of the image to be burned is written into the first main partition; If the filling number is 2, then the configuration information of the image to be burned is written into the second main partition; If the filling number is 3, then the configuration information of the image to be burned is written into the third main partition; If the filling number is 4, then the configuration information of the image to be burned is written into the fourth main partition.
3. The method for generating partitions based on image burning according to claim 2, characterized in that, The step of sequentially writing the configuration information of the image to be burned (with a fill number less than a preset threshold) and the extended information into the partition table of the master boot record includes: Write the configuration information of the image to be burned, which has a fill number of 1, into the first main partition; Write the configuration information of the image to be burned, which has the fill number 2, into the second main partition; Write the configuration information of the image to be burned, which has the fill number 3, into the third main partition; The extended information is written to the fourth primary partition.
4. The method for generating partitions based on image burning according to claim 3, characterized in that, Also includes: After writing the configuration information of the images to be burned with a fill number greater than or equal to a preset threshold into the extended boot record, the extended boot records and the corresponding images to be burned are merged to obtain multiple second firmware; Write each of the second firmwares to the storage device with the SD interface.
5. The method for generating partitions based on image burning according to claim 2, characterized in that, Also includes: Construct an array of length 512 bytes as the Master Boot Record; Use bytes 447 to 510 of the Master Boot Record as a partition table; The 447th to 462nd bytes of the partition table are designated as the first primary partition; the 463rd to 478th bytes of the partition table are designated as the second primary partition; the 479th to 494th bytes of the partition table are designated as the third primary partition; the 495th to 510th bytes of the partition table are designated as the fourth primary partition; after writing the configuration information of all images to be burned into the partition table, the 511th and 512th bytes of the master boot record are set as the end marker.
6. The method for generating partitions based on image burning according to claim 5, characterized in that, The step of writing the configuration information of the image to be burned into the first primary partition includes: The starting address of the image to be burned is resolved into the starting address of the logical block; The file size of the image to be burned is parsed into logical block sizes; Write the logical block start address, logical block size, and type information into the first primary partition; wherein the logical block start address and the logical block size are located in the 9th to 16th bytes of the first primary partition.
7. The method for generating partitions based on image burning according to claim 6, characterized in that, The step of determining extended information based on the image to be burned, whose fill number is equal to a preset threshold minus 1, includes: Obtain the starting address and file size of the image to be burned, where the fill number is equal to a preset threshold minus 1; Add the starting address and the file size to obtain the extended starting offset; Subtract the expansion start offset from the preset disk capacity to obtain the expanded record size; The expansion start offset and the expansion record size are used as the expansion information.
8. The method for generating partitions based on image burning according to claim 7, characterized in that, The step of writing the configuration information of the images to be burned with a fill number greater than or equal to a preset threshold into the extended boot record includes: Construct an array of length 512 bytes as the extended boot record; The 447th to 462nd bytes of the extended boot record are used as the first extended partition; The 463rd to 478th bytes of the extended boot record are used as the second extended partition; Write the configuration information of the image to be burned into the first extended partition; Write the configuration information of the next image to be burned into the second extended partition; Set the 511th and 512th bytes of the extended boot record as the end marker.
9. The method for generating partitions based on image burning according to claim 8, characterized in that, The logical block starting address in the first extended partition is 0x2000; the type information in the second extended partition is 0x05.
10. An apparatus for generating partitions based on image burning, characterized in that, include: The acquisition module is used to acquire the configuration information of the image to be burned, including the starting address, file size and type information; The sequence determination module is used to determine the filling number of each image to be burned based on the preset system information and the type information; The judgment module determines whether the number of images of the image to be burned is less than or equal to a preset threshold; The first partitioning module is used to write the configuration information of the image to be burned into the partition table of the master boot record according to the filling number when the judgment result of the judgment module is yes. The second partitioning module is used to determine extended information based on the image to be burned with a fill number equal to a preset threshold minus 1 when the judgment result is negative; and to write the configuration information of the image to be burned with a fill number less than the preset threshold and the extended information into the partition table of the master boot record in sequence. Write the configuration information of the images to be burned with a fill number greater than or equal to the preset threshold into the extended boot record; The first merging module is used to merge the partition table of the master boot record and the image to be burned with the fill number 1 into a first firmware; and write the first firmware to the storage device with the SD interface.
11. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method for generating a partition based on image burning as described in any one of claims 1 to 9.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the method for generating partitions based on image burning as described in any one of claims 1 to 9.