siemens / meta-iot2050

SIMATIC IOT2050 Isar/Debian Board Support Package
MIT License
130 stars 79 forks source link

install-on-emmc: Improve the robustness #343

Closed BaochengSu closed 1 year ago

BaochengSu commented 2 years ago

Main change point:

  1. When using Win32 Disk Imager to make the boot-able SD card or USB stick that bigger than the eMMC size (16GB), the Backup LBA of the GPT header is set to the end of the device, which is beyond the 16GB range. After copying such image to the eMMC, linux does not treat the GPT partition table as a correct one and some wired problems happen, such as the new p1 could not be informed to kernel.

    The solution is, the Backup LBA must be adjusted to the end of the eMMC after copying the image to the eMMC. gdisk provides an easy way to handle that.

  2. If the eMMC has old partition data, (which is true for the Advanced device with Industrial OS), then better to wipe the eMMC partition table before copying the data to eMMC. This is because according to UEFI spec, there is a GPT backup header and backup partition table at the end of the device. When copying the new image via dd, normally the tail part of the device will not be touched. This is ok when everything goes smoothly, however, if problem happen during the install-on-emmc, the old backup partition data could be recovered during next boot.

    For example in the above problem, when Backup LBA is beyond the eMMC size, the new partition p1 could not be informed to kernel. however, the since there is already the old p1 before install-on-emmc, the script still continue to reboot the device, however, during next booting, the Backup LBA offset error is detected and the old backup partition table is recovered to overwrite the new GPT table.

    It is very hard to notice this issue especially when the old image and the new image have similar partition layout.

    The solution is, before install-on-emmc, wipe the old GPT partitioning data, including the backup LBA. sgdisk also provides an easy way to wipe it, meanwhile sfdisk could not do it easily.

BaochengSu commented 2 years ago

If this PR is got approved, the target merge point is after the 1.3.1 release, since the new introduced gdisk tool.

BaochengSu commented 2 years ago

For handling GPT, gdisk is doing better than fdisk

jan-kiszka commented 2 years ago

There more have to tweak on this, there clearer it gets that we rather need an flasher stick instead.

BaochengSu commented 1 year ago

Let's have a thorough rethinking of this feature first, before that, close this PR.