pengutronix / genimage

tool to generate multiple filesystem and flash images from a tree
GNU General Public License v2.0
309 stars 110 forks source link

image-hd: fix CHS addresses in EBR #249

Closed sairon closed 3 months ago

sairon commented 4 months ago

All CHS addresses in the EBR should point to absolute address in the image instead of the relative addresses, currently they are only LBA-to-CHS conversion of the relative offsets. If correct, output of sfdisk -d of the genimage-produced disk image piped back to sfdisk file.img should produce binary identical (see note below) output. However, it is not true, because the CHS addresses differ. Even though the extended partition uses the 0xf type (LBA addressing) and CHS addressing is limited to 1023 sectors, the generated output should be comparable to other tools for easier debugging.

With this change the calculation of CHS addresses of the next EBRs and logical partitions within the extended partition adds the proper offset, so the addresses are absolute within the image.

Note: At least with the version of sfdisk I have tested with (from util-linux 2.37.2), the image is not completely identical - there are one byte differences in the MBR and each MBR. This is because even if the partition type is set as 0xf, sfdisk produces the extended partition and all the logical partition with 0x5 type.