Search code examples
yoctou-bootyocto-wic

How to to duplicate a 4 partitions image on an eMMC from U-Boot?


I have an image (more specifically a wic image for those who are familiar with Yocto framework) that contains a partition table along with its 4 partitions. It's size is bit less than 1GB.

In order to write this image to the eMMC:

  • I first load it to RAM through TFTP
=> tftp 0x600000000 <image>.wic
  • Then I write the image from RAM to the eMMC
=> mmc write 0x600000000 0x0 0x1FFFFF
  • The image gets written correctly and I can list the 4 partitions. So far, so good.
=> mmc part

Partition Map for MMC device 1  --   Partition Type: EFI

Part    Start LBA       End LBA         Name
        Attributes
        Type GUID
        Partition GUID
  1     0x00000800      0x0000681f      "boot"
        attrs:  0x0000000000000000
        type:   0fc63daf-8483-4772-8e79-3d69d8477de4
        guid:   cd5df8ce-ded3-4cf4-b364-33d7a4b24953
  2     0x00006820      0x000139e7      "first"
        attrs:  0x0000000000000000
        type:   0fc63daf-8483-4772-8e79-3d69d8477de4
        guid:   3acc4557-2273-462a-a2bd-d130b3a5745d
  3     0x00014000      0x000fefff      "second"
        attrs:  0x0000000000000000
        type:   0fc63daf-8483-4772-8e79-3d69d8477de4
        guid:   efe25a87-e0ba-401e-8bf6-e81ae29cbc35
  4     0x000ff000      0x001e9fff      "third"
        attrs:  0x0000000000000000
        type:   0fc63daf-8483-4772-8e79-3d69d8477de4
        guid:   150f9151-7710-42f4-b819-3b3bd506a2bf

Now I want to duplicate the image in the eMMC so that I end up with 8 partitions like so:

Part    Start LBA       End LBA         Name
        Attributes
        Type GUID
        Partition GUID
  1     0x00000800      0x0000681f      "boot"
        attrs:  0x0000000000000000
        type:   0fc63daf-8483-4772-8e79-3d69d8477de4
        guid:   cd5df8ce-ded3-4cf4-b364-33d7a4b24953
  2     0x00006820      0x000139e7      "first"
        attrs:  0x0000000000000000
        type:   0fc63daf-8483-4772-8e79-3d69d8477de4
        guid:   3acc4557-2273-462a-a2bd-d130b3a5745d
  3     0x00014000      0x000fefff      "second"
        attrs:  0x0000000000000000
        type:   0fc63daf-8483-4772-8e79-3d69d8477de4
        guid:   efe25a87-e0ba-401e-8bf6-e81ae29cbc35
  4     0x000ff000      0x001e9fff      "third"
        attrs:  0x0000000000000000
        type:   0fc63daf-8483-4772-8e79-3d69d8477de4
        guid:   150f9151-7710-42f4-b819-3b3bd506a2bf
  5     0x00000800      0x0000681f      "boot"
        attrs:  0x0000000000000000
        type:   0fc63daf-8483-4772-8e79-3d69d8477de4
        guid:   cd5df8ce-ded3-4cf4-b364-33d7a4b24953
  6     0x00006820      0x000139e7      "first"
        attrs:  0x0000000000000000
        type:   0fc63daf-8483-4772-8e79-3d69d8477de4
        guid:   3acc4557-2273-462a-a2bd-d130b3a5745d
  7     0x00014000      0x000fefff      "second"
        attrs:  0x0000000000000000
        type:   0fc63daf-8483-4772-8e79-3d69d8477de4
        guid:   efe25a87-e0ba-401e-8bf6-e81ae29cbc35
  8     0x000ff000      0x001e9fff      "third"
        attrs:  0x0000000000000000
        type:   0fc63daf-8483-4772-8e79-3d69d8477de4
        guid:   150f9151-7710-42f4-b819-3b3bd506a2bf

So I write again the same image to eMMC with an offset (to not override the existing one)

=> mmc write 0x600000000 0x200000 0x3FFFFF

MMC write: dev # 1, block # 2097152, count 4194303 ... 4194303 blocks written: OK

However, I don't get the 8 partitions I was expecting but only 4 partitions:

=> mmc rescan
=> mmc part

Partition Map for MMC device 1  --   Partition Type: EFI

Part    Start LBA       End LBA         Name
        Attributes
        Type GUID
        Partition GUID
  1     0x00000800      0x0000681f      "boot"
        attrs:  0x0000000000000000
        type:   0fc63daf-8483-4772-8e79-3d69d8477de4
        guid:   cd5df8ce-ded3-4cf4-b364-33d7a4b24953
  2     0x00006820      0x000139e7      "first"
        attrs:  0x0000000000000000
        type:   0fc63daf-8483-4772-8e79-3d69d8477de4
        guid:   3acc4557-2273-462a-a2bd-d130b3a5745d
  3     0x00014000      0x000fefff      "second"
        attrs:  0x0000000000000000
        type:   0fc63daf-8483-4772-8e79-3d69d8477de4
        guid:   efe25a87-e0ba-401e-8bf6-e81ae29cbc35
  4     0x000ff000      0x001e9fff      "third"
        attrs:  0x0000000000000000
        type:   0fc63daf-8483-4772-8e79-3d69d8477de4
        guid:   150f9151-7710-42f4-b819-3b3bd506a2bf

Solution

  • When you write an image that contains one or more partitions, you also write the partition table, which is expected to be at some offset or your memory by u-boot (according to this post it must be 0x60000000). So if you write your image again somewhere else, u-boot will still refer to the partition table from your first writing operation, which itself contains the memory address of your first 4 partitions. Your second partition table is somewhere else on the disk, but u-boot doesn't know.

    You can try to repair the partition table using the testdisk command line utility. It will scan the whole disk and hopefully it will find that there is 8 partitions in total, and create a new partition table at 0x60000000 that refers to all of them.