Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
image-hd: add support for overridding optional fields of the MBR
The 'holes' property allows to describe holes in an image, for example to allow writing an image that spans accross the MBR partition table. The image-hd code creates a fake partition spanning from 440 bytes to 512 bytes to protect the area used by the partition table. However, it turns out that the Amlogic SoCs have a bootloader that is precisely written accross the partition table, with some bits before the partition table and some bits after. But those Amlogic SoCs use the first 444 bytes, instead of just the first 440 bytes (see [1]). This is possible because the first 2 fields of the MBR are optional fields (see [2]). The first optional field is the disk signature (4 bytes), the second optional field is the "copy protect" field (2 bytes). Therefore, to write a bootloader image for the Amlogic SoCs, we need to write something like: image fip/u-boot.bin.sd.bin { file { holes = {"(444; 512)"} } } But that isn't accepted because it overlaps with the fake MBR partition that starts at offset 440. In order to allow this, the present commit adds a new 'mbr-skip-optionals' property, which tells genimage that we would like to skip writing those optional fields, allowing the full 446 bytes to be used, as is needed for Amlogic SoC bootloader images. Implementation note: we would have preferred to write: mbr_data += sizeof(struct mbr_tail_optionals); but genimage has chosen to not allow arithmetic on void* pointers, so instead we have chosen to use: mbr_data = &mbr.part_entry[0]; when adjusting the start of the MBR data that have to be inserted into the image. This commit also adds two test cases for this new feature: - One positive test case, where we verify that we can write an image where the hole is (444, 512) and the mbr-skip-optionals = "true" option is passed - One negative test case, where we verify that we are not allowed to write an image where the hole is (444, 512) when mbr-skip-optionals = "false". [1] http://docs.khadas.com/products/sbc/vim3/development/create-bootable-tf-card [2] https://wiki.osdev.org/MBR_(x86) Co-Developed-by: Romain Naour <[email protected]> Signed-off-by: Thomas Petazzoni <[email protected]>
- Loading branch information