Add a 'part dupcheck' subcommand that scans all block devices probed
in U-Boot and reports any partitions sharing the same PARTUUID or
PARTLABEL. This helps detect situations where the same disk image has
been flashed onto multiple boot devices (e.g., USB stick and UFS),
which can lead to unpredictable boot behavior. Duplicate
PARTUUIDs break UUID-based partition lookup in Linux, and duplicate
PARTLABELs cause the wrong partition to be silently selected in
bootscripts that reference partitions by name.
A single collection pass iterates over all block devices using
blk_foreach_probe() and records every partition that carries a UUID
or label into a dynamically allocated alist of struct part_seen
entries (UUID string, name string, device pointer, partition number).
Duplicates are detected by calling detect_duplicates() twice, once
for UUIDs and once for labels. Each call sorts the list with qsort()
using a comparator that places empty fields at the end, then performs
a single linear pass to identify consecutive equal entries as
duplicate groups. Each group is reported with the device name and
partition number of every copy, followed by a per-field summary
count. Per-field counts are used consistently in both the
duplicate-found and no-duplicates paths.
Example output (with duplicates):
=> part dupcheck
Warning: duplicate PARTUUID 1234abcd-01 (2 copies)
found on usb_mass_storage.lun0:1
found on ufs_scsi.id0lun0:1
Found 1 duplicate PARTUUID(s) (2 total copies) among 4 partitions
Warning: duplicate PARTLABEL primary (2 copies)
found on usb_mass_storage.lun0:1
found on ufs_scsi.id0lun0:1
Found 1 duplicate PARTLABEL(s) (2 total copies) among 4 partitions
Example output (mixed: UUID duplicates, no label duplicates):
=> part dupcheck
Warning: duplicate PARTUUID 1234abcd-01 (2 copies)
found on usb_mass_storage.lun0:1
found on ufs_scsi.id0lun0:1
Found 1 duplicate PARTUUID(s) (2 total copies) among 4 partitions
No duplicate PARTLABELs found (3 labels)
Example output (no duplicates):
=> part dupcheck
No duplicate PARTUUIDs or PARTLABELs found (4 UUIDs, 3 labels)
The CONFIG_CMD_PART_DUPCHECK Kconfig option (depends on
CMD_PART and BLK) controls inclusion of this subcommand and is
disabled by default.
Signed-off-by: John Toomey <john.toomey@amd.com>
Signed-off-by: Padmarao Begari <padmarao.begari@amd.com>