summaryrefslogtreecommitdiff
path: root/cmd/part.c
AgeCommit message (Collapse)Author
2026-03-27cmd: part: add part dupcheck subcommandPadmarao Begari
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 <[email protected]> Signed-off-by: Padmarao Begari <[email protected]>
2025-11-18cmd/part.c: implement "part name" subcommandRasmus Villemoes
This is a natural buddy to the existing "part number", allowing one to get the partition name for a given partition number. Acked-by: Quentin Schulz <[email protected]> Signed-off-by: Rasmus Villemoes <[email protected]> Acked-by: Quentin Schuloz <[email protected]> Tested-by: Anshul Dalal <[email protected]>
2024-05-22include: Move snprintf to stdio.hRaymond Mao
Move snprintf to stdio.h since it is needed by exteranl libraries. Signed-off-by: Raymond Mao <[email protected]> Reviewed-by: Tom Rini <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]>
2024-05-06cmd: Remove <common.h> and add needed includesTom Rini
Remove <common.h> from all "cmd/" files and when needed add missing include files directly. Signed-off-by: Tom Rini <[email protected]>
2023-12-20cmd: part: Cover both part type entries with GUID ifdefMarek Vasut
The 'part type' subcommand depends on GUID partition table support. The help text exposes one of two 'part type' subcommand entries, hide both in case GUID partition table support is not enabled to avoid confusing users. Signed-off-by: Marek Vasut <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2023-07-17part: Allow setting the partition-table typeSimon Glass
Some devices have multiple partition types available on the same media. It is sometimes useful to see these to check that everything is working correctly. Provide a way to manually set the partition-table type, avoiding the auto-detection process. Signed-off-by: Simon Glass <[email protected]> Reviewed-by: Bin Meng <[email protected]>
2023-01-18cmd: part: Add partition-related type commandEnric Balletbo i Serra
This implements the following command: part type mmc 0:1 -> print partition type UUID part type mmc 0:1 uuid -> set environment variable to partition type UUID "part type" can be useful when writing a bootcmd which searches for a specific partition type to enable automatic discovery of partitions and their intended usage or mount point. Signed-off-by: Enric Balletbo i Serra <[email protected]> Reviewed-by: Simon Glass <[email protected]> [trini: Fix when CONFIG_PARTITION_TYPE_GUID is disabled and have the command check for "types" before "type"] Signed-off-by: Tom Rini <[email protected]>
2022-01-15cmd: part: list all 128 GPT partitionsHeinrich Schuchardt
A GPT partition table typically has 128 entries. If a partition table contains a partition 128 'part list' should be able to list it. Signed-off-by: Heinrich Schuchardt <[email protected]>
2021-07-23cmd: part: Correct error handlingAnders Dellien
As 'part_get_info_by_name' now returns more status codes than just -1 to indicate failure, we need to update the return value check. Signed-off-by: Anders Dellien <[email protected]> Reviewed-by: Sean Anderson <[email protected]>
2020-07-07cmd: part: Add subcommand to list supported partition tablesNiel Fourie
Add a subcommand "types" to the part command, which lists the supported partition table types. Signed-off-by: Niel Fourie <[email protected]> Cc: Simon Glass <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2020-05-18command: Remove the cmd_tbl_t typedefSimon Glass
We should not use typedefs in U-Boot. They cannot be used as forward declarations which means that header files must include the full header to access them. Drop the typedef and rename the struct to remove the _s suffix which is now not useful. This requires quite a few header-file additions. Signed-off-by: Simon Glass <[email protected]>
2020-05-18part: Drop disk_partition_t typedefSimon Glass
We should not be using typedefs and these make it harder to use forward declarations (to reduce header file inclusions). Drop the typedef. Signed-off-by: Simon Glass <[email protected]>
2019-10-04cmd: part: number: return hexadecimal valueRoman Stratiienko
At this point we are using part number sub-command to retrieve UUID of the partition using it's name. e.g.: part number mmc $mmcdev system_a system_a_index part uuid mmc $mmcdev:${system_a_index} system_a_uuid Since 'part uuid' sub-command expects partition index in hex format and 'part number' returns decimal value, 'part uuid' command will provide wrong UUID or fail. Fixes: be683756f62034 ("cmd: part: Add 'number' sub-command") Cc: Dirk Behme <[email protected]> Reported-by: Pontus Fuchs <[email protected]> Signed-off-by: Roman Stratiienko <[email protected]> Signed-off-by: Eugeniu Rosca <[email protected]> Reviewed-by: Tom Rini <[email protected]> Reviewed-by: Igor Opaniuk <[email protected]>
2019-08-11env: Move env_set() to env.hSimon Glass
Move env_set() over to the new header file. Acked-by: Joe Hershberger <[email protected]> Signed-off-by: Simon Glass <[email protected]>
2019-07-24cmd: part: Add 'number' sub-commandRuslan Trofymenko
This sub-command serves for getting the partition index from partition name. Also it can be used to test the existence of specified partition. Use case: For example, in most CI environments this U-Boot command for automatic testing of Linux rootfs is used: => setenv bootpart 1:f where 0xf is "userdata" partition. But the number of "userdata" partition can be changed any time, when partition table is changed. So it would be nice to get rid of that 0xf magic number and use partition name instead, like this: => part number mmc 1 userdata part_num => setenv bootpart 1:${part_num} Signed-off-by: Ruslan Trofymenko <[email protected]> Signed-off-by: Igor Opaniuk <[email protected]> Reviewed-by: Alistair Strachan <[email protected]> Reviewed-by: Sam Protsenko <[email protected]> Reviewed-by: Simon Glass <[email protected]> Reviewed-by: Sam Protsenko <[email protected]>
2018-09-10cmd: part: use MAX_SEARCH_PARTITIONS for part searchKever Yang
Use Macro instead of hard code. Signed-off-by: Kever Yang <[email protected]> Reviewed-by: Philipp Tomsich <[email protected]>
2018-05-07SPDX: Convert all of our single license tags to Linux Kernel styleTom Rini
When U-Boot started using SPDX tags we were among the early adopters and there weren't a lot of other examples to borrow from. So we picked the area of the file that usually had a full license text and replaced it with an appropriate SPDX-License-Identifier: entry. Since then, the Linux Kernel has adopted SPDX tags and they place it as the very first line in a file (except where shebangs are used, then it's second line) and with slightly different comment styles than us. In part due to community overlap, in part due to better tag visibility and in part for other minor reasons, switch over to that style. This commit changes all instances where we have a single declared license in the tag as both the before and after are identical in tag contents. There's also a few places where I found we did not have a tag and have introduced one. Signed-off-by: Tom Rini <[email protected]>
2018-03-13cmd: part: Extract common code to separate functionSam Protsenko
Refactor the code for "part start" and "part size" commands to avoid code duplication. Signed-off-by: Sam Protsenko <[email protected]> Reviewed-by: Lukasz Majewski <[email protected]>
2018-03-13cmd: part: Allow passing partition name to start and sizeSam Protsenko
Allow passing the partition name to "part start" and "part size" commands, so we can avoid magic numbers in the environment. Consider one real use-case: in include/environment/ti/boot.h we have commands like these: setenv boot_part 9 part start mmc ${mmcdev} ${boot_part} boot_start part size mmc ${mmcdev} ${boot_part} boot_size mmc read ${loadaddr} ${boot_start} ${boot_size} Now suppose that we have changed the partition table and boot_part now is 10. We will need to fix commands above. And anyone who relies on these boot commands, will need to change them accordingly, too (this was an actual case in our lab while testing Linux boot on Android environment). By providing the option to pass partition name instead, we fix mentioned issue, by eliminating the necessity to use magic numbers. Signed-off-by: Sam Protsenko <[email protected]> Reviewed-by: Lukasz Majewski <[email protected]>
2017-08-16env: Rename setenv() to env_set()Simon Glass
We are now using an env_ prefix for environment functions. Rename setenv() for consistency. Also add function comments in common.h. Suggested-by: Wolfgang Denk <[email protected]> Signed-off-by: Simon Glass <[email protected]>
2017-01-28cmd, disk: convert CONFIG_PARTITION_UUIDS, CMD_PART and CMD_GPTPatrick Delaunay
We convert CONFIG_PARTITION_UUIDS to Kconfig first. But in order to cleanly update all of the config files we must also update CMD_PART and CMD_GPT to also be in Kconfig in order to avoid complex logic elsewhere to update all of the config files. Signed-off-by: Patrick Delaunay <[email protected]> Signed-off-by: Patrick Delaunay <[email protected]> Signed-off-by: Tom Rini <[email protected]>
2016-03-14dm: part: Rename some partition functionsSimon Glass
Rename three partition functions so that they start with part_. This makes it clear what they relate to. Signed-off-by: Simon Glass <[email protected]> Tested-by: Stephen Warren <[email protected]>
2016-03-14dm: blk: Rename get_device_and_partition()Simon Glass
Rename this function to blk_get_device_part_str(). This is a better name because it makes it clear that the function returns a block device and parses a string. Signed-off-by: Simon Glass <[email protected]> Reviewed-by: Bin Meng <[email protected]> Tested-by: Stephen Warren <[email protected]>
2016-03-14dm: blk: Rename get_device() to blk_get_device_by_str()Simon Glass
The current name is too generic. The function returns a block device based on a provided string. Rename it to aid searching and make its purpose clearer. Also add a few comments. Signed-off-by: Simon Glass <[email protected]> Reviewed-by: Bin Meng <[email protected]> Tested-by: Stephen Warren <[email protected]>
2016-03-14dm: Drop the block_dev_desc_t typedefSimon Glass
Use 'struct' instead of a typdef. Also since 'struct block_dev_desc' is long and causes 80-column violations, rename it to struct blk_desc. Signed-off-by: Simon Glass <[email protected]> Reviewed-by: Bin Meng <[email protected]> Tested-by: Stephen Warren <[email protected]>
2016-01-25Remove the cmd_ prefix from command filesSimon Glass
Now that they are in their own directory, we can remove this prefix. This makes it easier to find a file since the prefix does not get in the way. Signed-off-by: Simon Glass <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Heiko Schocher <[email protected]> Acked-by: Stefan Roese <[email protected]> Acked-by: Przemyslaw Marczak <[email protected]>