Padmarao Begari b5517950e6 cmd: part: add part dupcheck subcommand
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>
2026-03-27 13:19:04 -06:00
..
2026-02-04 09:04:36 +01:00
2025-04-03 11:43:22 -06:00
2025-07-11 10:43:29 -06:00
2024-02-15 10:38:34 +01:00
2025-05-13 11:30:08 -06:00
2025-05-30 09:49:31 +01:00
2024-10-09 22:04:56 -06:00
2024-07-15 12:12:17 -06:00
2024-08-02 15:16:51 -03:00
2024-07-15 12:12:17 -06:00
2024-09-12 17:35:37 +02:00
2024-09-12 17:35:37 +02:00
2026-03-14 08:10:26 +01:00
2022-03-15 16:19:29 -04:00
2024-10-29 16:17:47 -06:00
2025-12-05 08:54:44 -06:00
2024-10-18 14:10:21 -06:00
2025-04-02 20:00:59 -06:00
2025-07-08 15:00:17 +02:00
2025-08-06 07:49:13 +02:00
2025-08-06 08:41:30 +02:00
2026-03-18 13:07:36 -06:00
2024-06-30 10:59:42 -06:00
2025-01-26 11:06:56 +01:00
2024-03-07 09:23:10 -05:00
2025-06-02 17:26:16 -06:00
2025-08-23 16:37:20 +02:00
2026-03-27 13:19:04 -06:00
2022-09-02 13:40:42 -04:00
2025-12-30 11:22:57 -06:00
2024-12-24 17:02:23 +01:00
2024-12-02 07:40:39 -06:00
2025-04-10 20:55:53 -06:00
2025-12-04 09:38:58 -06:00
2020-08-07 22:31:32 -04:00
2024-10-17 03:12:47 +02:00
2024-07-15 12:12:17 -06:00
2025-12-04 09:38:58 -06:00
2024-12-31 19:00:46 -06:00
2025-10-08 11:34:54 +02:00
2024-07-15 12:12:17 -06:00
2024-09-18 13:00:59 -06:00
2024-07-15 12:12:17 -06:00