summaryrefslogtreecommitdiff
path: root/disk/part.c
AgeCommit message (Collapse)Author
2026-02-04disk: part: fix partition search boundariesMikhail Kshevetskiy
GPT disk partition with max available number (ex: /dev/mmcblk128) can't be read/write from U-Boot using read/write command. Here is an example: => mmc part Partition Map for mmc device 0 -- Partition Type: EFI Part Start LBA End LBA Name Attributes Type GUID Partition GUID 1 0x00001000 0x000013ff "env1" attrs: 0x0000000000000000 type: 0fc63daf-8483-4772-8e79-3d69d8477de4 guid: 5452574f-2211-4433-5566-778899aabb02 2 0x00001400 0x000017ff "env2" attrs: 0x0000000000000000 type: 0fc63daf-8483-4772-8e79-3d69d8477de4 guid: 5452574f-2211-4433-5566-778899aabb03 ................. 8 0x00158000 0x0034bfff "apps" attrs: 0x0000000000000000 type: 0fc63daf-8483-4772-8e79-3d69d8477de4 guid: 5452574f-2211-4433-5566-778899aabb09 128 0x00000420 0x00000fff "fip" attrs: 0x0000000000000000 type: c12a7328-f81f-11d2-ba4b-00a0c93ec93b guid: 5452574f-2211-4433-5566-778899aabb01 => read mmc 0#fip ${loadaddr} 0 4 Could not find "fip" partition ** Bad device specification mmc 0#fip ** ** Bad device specification mmc 0#fip ** Couldn't find partition mmc 0#fip The error is caused by invalid boundary checks. This patch fixes an issue. Fixes: 43fd4bcefd4e ("disk: part: implement generic function part_get_info_by_uuid()") Fixes: 56670d6fb83f ("disk: part: use common api to lookup part driver") Signed-off-by: Mikhail Kshevetskiy <[email protected]> Acked-by: Quentin Schulz <[email protected]> Reviewed-By: Michael Trimarchi <[email protected]>
2025-11-18disk/part.c: ensure strings in struct disk_partition are valid after ↵Rasmus Villemoes
successful get_info Not all ->get_info implementations necessarily populate all the string members of struct disk_partition. Currently, only part_get_info_by_type() (and thereby part_get_info) ensure that the uuid strings are initialized; part_get_info_by_type() and part_get_info_by_uuid() do not. In fact, the latter could lead to a false positive match - if the ->get_info backend does not populate info->uuid, stale contents in info could cause the strncasecmp() to succeed. None of the functions currently ensure that the ->name and ->type strings are initialized. Instead of forcing all callers of any of these functions to pre-initialize info, or all implementations of the ->get_info method to ensure there are valid C strings in all four fields, create a small helper function and factor all invocations of ->get_info through that. This also consolidates the -ENOSYS check and standardizes on using log_debug() for reporting absence, instead of the current mix of PRINTF and log_debug(). It does mean we have to special-case -ENOSYS in the error cases inside the loops in the _by_uuid() and _by_name() functions, but it's still a net win in #LOC. Acked-by: Quentin Schulz <[email protected]> Signed-off-by: Rasmus Villemoes <[email protected]> Tested-by: Anshul Dalal <[email protected]>
2025-10-14part: Export part_driver_lookup_type for external useJavier Tia
Make part_driver_lookup_type non-static so it can be used outside part.c. This allows external callers to determine the appropriate partition driver for a block device, enabling more flexible handling of partition types. Add a prototype and kernel-doc comment in part.h to document the function contract. Provide a stub inline implementation returning NULL when partition support is disabled, ensuring build consistency across configurations. Signed-off-by: Javier Tia <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
2025-06-02Merge patch series "Audit include list for include/[a-m]*.h"Tom Rini
Tom Rini <[email protected]> says: Hey all, Related to my other series I've posted recently on cleaning up some headers, this series here is the result of at least lightly auditing the #includes used in include/[a-m]*.h. This ignores subdirectories, as at least in part I think the top-level includes we've constructed are the most likely places to have some extra transitive include paths. I'm sure there's exceptions and I'll likely audit deeper once this first pass is done. This only gets as far as "include/m*.h" because I didn't want this to get too big. This also sets aside <miiphy.h> and <phy.h>. While miiphy.h does not directly need <phy.h> there are *so* many users and I think I had half of the tree just about not building when I first tried. It might be worth further investigation, but it might just be OK as-is. Link: https://lore.kernel.org/r/[email protected]
2025-06-02include/ide.h: Cleanup usageTom Rini
At this point in time, <ide.h> provides the IDE_BUS macro and the function prototype for ide_set_reset, which is used with IDE_RESET. The only files which should include this header are the ones that either use that macro or that function. Remove <blk.h> from <ide.h> and remove <ide.h> from places which do not need it. Signed-off-by: Tom Rini <[email protected]>
2025-05-29disk: part: implement generic function part_get_info_by_uuid()Varadarajan Narayanan
Add function to search for a partition by UUID as partition names may not be unique. Signed-off-by: Varadarajan Narayanan <[email protected]> Acked-by: Casey Connolly <[email protected]>
2024-10-11global: Use CONFIG_XPL_BUILD instead of CONFIG_SPL_BUILDSimon Glass
Complete this rename for all directories outside arch/ board/ drivers/ and include/ Use the new symbol to refer to any 'SPL' build, including TPL and VPL Signed-off-by: Simon Glass <[email protected]>
2024-08-08disk: don't try search for partition type if already setAlexey Romanov
Block devices can already set partition type at initialization stage, so, in this case is no point in searching for partition type. Signed-off-by: Alexey Romanov <[email protected]> Reviewed-by: Heiko Schocher <[email protected]> Signed-off-by: Michael Trimarchi <[email protected]>
2024-08-08disk: support MTD partitionsAlexey Romanov
Add new MTD partition driver, which can be useful with mtdblock driver combination. Signed-off-by: Alexey Romanov <[email protected]> Signed-off-by: Michael Trimarchi <[email protected]>
2024-05-20Restore patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet"Tom Rini
As part of bringing the master branch back in to next, we need to allow for all of these changes to exist here. Reported-by: Jonas Karlman <[email protected]> Signed-off-by: Tom Rini <[email protected]>
2024-05-19Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""Tom Rini
When bringing in the series 'arm: dts: am62-beagleplay: Fix Beagleplay Ethernet"' I failed to notice that b4 noticed it was based on next and so took that as the base commit and merged that part of next to master. This reverts commit c8ffd1356d42223cbb8c86280a083cc3c93e6426, reversing changes made to 2ee6f3a5f7550de3599faef9704e166e5dcace35. Reported-by: Jonas Karlman <[email protected]> Signed-off-by: Tom Rini <[email protected]>
2024-05-06part: Remove <common.h> and add needed includesTom Rini
Remove <common.h> from all "part/" files and when needed add missing include files directly. Signed-off-by: Tom Rini <[email protected]>
2024-04-12disk: simplify print_part_header()Heinrich Schuchardt
Using uclass_get_name() reduces the code size. Signed-off-by: Heinrich Schuchardt <[email protected]>
2024-04-12part: Check all partitions in part_get_info_by_name()Sam Protsenko
In part_get_info_by_name() the inability to get some partition info shouldn't be a reason for dropping out of the loop. That might happen e.g. if the partition is hidden or unused. An example of such case are Samsung devices, where they use the "unused" GUID type (00000000-0000-0000-0000-000000000000) to indicate that the partition should be hidden from the OS. Such partitions might not be seen in "part list" output, which creates "gaps" in numbering in between of the visible partitions: Part Start LBA End LBA Name 1 0x00000400 0x0000a3ff "efs" 5 0x00026420 0x00026c1f "dtbo" 12 0x0003f390 0x0074738f "super" In that case, the loop in part_get_info_by_name() would break after partition #1, so any attempt to obtain "dtbo" or "super" partition will fail. Fix that by continuing to iterate over the remaining partitions to make sure none of the visible ones is missed. That makes "part" command (e.g. "part start", "part size") able to work with such tables. Fixes: 87b8530fe244 ("disk: part: implement generic function part_get_info_by_name()") Signed-off-by: Sam Protsenko <[email protected]> Reviewed-by: Heinrich Schuchardt <[email protected]>
2023-10-24rockchip: dm: prepare rkmtd UCLASSJohan Jonker
Prepare a rkmtd UCLASS in use for writing Rockchip boot blocks in combination with existing userspace tools and rockusb command. Signed-off-by: Johan Jonker <[email protected]> Reviewed-by: Kever Yang <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2023-10-10disk: part: Handle blkmap device in print_part_header()Bin Meng
Print out the blkmap device type when showing partition header for a blkmap device. Signed-off-by: Bin Meng <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2023-10-10disk: part: Print out the unknown device uclass idBin Meng
It's helpful to output the device uclass id for unknown devices during the debugging process. Signed-off-by: Bin Meng <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2023-08-25part: Add accessors for struct disk_partition type_uuidSimon Glass
This field is only present when a CONFIG is set. To avoid annoying #ifdefs in the source code, add accessors. Update all code to use it. Note that the accessor is optional. It can be omitted if it is known that the option is enabled. Signed-off-by: Simon Glass <[email protected]>
2023-08-25part: Add accessors for struct disk_partition uuidSimon Glass
This field is only present when a CONFIG is set. To avoid annoying #ifdefs in the source code, add accessors. Update all code to use it. Note that the accessor is optional. It can be omitted if it is known that the option is enabled. Signed-off-by: Simon Glass <[email protected]>
2023-08-25part: Add comments for static functionsSimon Glass
Some internal functions could do with a few comments, to explain what they do. Add these, to make the code easier to follow. Signed-off-by: Simon Glass <[email protected]>
2023-08-25part: Use desc instead of dev_descSimon Glass
The dev_ prefix is a hangover from the pre-driver model days. The device is now a different thing, with driver model. Update the partition code to just use 'desc', as is done with driver model. Signed-off-by: Simon Glass <[email protected]>
2023-07-30part: check CONFIG_IS_ENABLED(ENV_SUPPORT)Heinrich Schuchardt
In SPL environment variables may not be enabled. Suggested-by: Tom Rini <[email protected]> Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Tom Rini <[email protected]>
2023-07-25part: eliminate part_get_info_by_name_type()Heinrich Schuchardt
Since commit 56670d6fb83f ("disk: part: use common api to lookup part driver") part_get_info_by_name_type() ignores the part_type parameter used to restrict the partition table type. omap_mmc_get_part_size() and part_get_info_by_name() are the only consumers. omap_mmc_get_part_size() calls with part_type = PART_TYPE_EFI because at the time of implementation a speed up could be gained by passing the partition table type. After 5 years experience without this restriction it looks safe to keep it that way. part_get_info_by_name() uses PART_TYPE_ALL. Move the logic of part_get_info_by_name_type() to part_get_info_by_name() and replace the function in omap_mmc_get_part_size(). Fixes: 56670d6fb83f ("disk: part: use common api to lookup part driver") Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2023-07-17disk: part: Add API to get partitions with specific driverJoshua Watt
Adds part_driver_get_type() API which can be used to force a specific driver to be used when getting partition information instead of relying on auto detection. Signed-off-by: Joshua Watt <[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-04-05cmd: blkmap: Add blkmap commandTobias Waldekranz
Add a frontend for the blkmap subsystem. In addition to the common block device operations, this allows users to create and destroy devices, and map in memory and slices of other block devices. With that we support two primary use-cases: - Being able to "distro boot" from a RAM disk. I.e., from an image where the kernel is stored in /boot of some filesystem supported by U-Boot. - Accessing filesystems not located on exact partition boundaries, e.g. when a filesystem image is wrapped in an FIT image and stored in a disk partition. Signed-off-by: Tobias Waldekranz <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2023-01-23part: Add a function to find the first bootable partitionSimon Glass
If a disk has a bootable partition we are expected to use it to locate the boot files. Add a function to find it. To test this, update mmc1 to have two paritions, fixing up other tests accordingly. Signed-off-by: Simon Glass <[email protected]>
2022-12-02disk: fix blk_get_device_part_str()Heinrich Schuchardt
blk_get_device_part_str() should always initialize all info fields including sys_ind. As a side effect the code is simplified. Replace '(0 ==' by '(!' to conform with Linux coding style. Fixes: 4d907025d6a5 ("sandbox: restore ability to access host fs through standard commands") Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Heiko Schocher <[email protected]>
2022-11-07dm: sandbox: Switch over to using the new host uclassSimon Glass
Update the sandbox implementation to use UCLASS_HOST and adjust all the pieces to continue to work: - Update the 'host' command to use the new API - Replace various uses of UCLASS_ROOT with UCLASS_HOST - Disable test_eficonfig since it doesn't work (this should have a unit test to allow this to be debugged) - Update the blk test to use the new API - Drop the old header file Unfortunately it does not seem to be possible to split this change up further. Signed-off-by: Simon Glass <[email protected]>
2022-09-25blk: Rename if_type to uclass_idSimon Glass
Use the word 'uclass' instead of 'if_type' to complete the conversion. Signed-off-by: Simon Glass <[email protected]>
2022-09-19Merge branch 'master' into nextTom Rini
Signed-off-by: Tom Rini <[email protected]>
2022-09-16disk: Handle UCLASS_EFI_MEDIA in dev_print()Simon Glass
This is currently missing. Add it. Fix the code style for the function while we are here. Suggested-by: AKASHI Takahiro <[email protected]> Signed-off-by: Simon Glass <[email protected]>
2022-09-16blk: Switch over to using uclass IDsSimon Glass
We currently have an if_type (interface type) and a uclass id. These are closely related and we don't need to have both. Drop the if_type values and use the uclass ones instead. Maintain the existing, subtle, one-way conversion between UCLASS_USB and UCLASS_MASS_STORAGE for now, and add a comment. Signed-off-by: Simon Glass <[email protected]>
2022-09-16blk: Drop IF_TYPE_SDSimon Glass
This is not really needed since it does the same things as MMC. Drop it. Signed-off-by: Simon Glass <[email protected]>
2022-09-16blk: Drop IF_TYPE_ATAPISimon Glass
This is not really needed since it does the same things as IDE. Drop it. Signed-off-by: Simon Glass <[email protected]>
2022-09-16blk: Drop IF_TYPE_DOCSimon Glass
This doesn't seem to be used for anything and it isn't clear what it is. It dates from the first U-Boot commit. Drop it. Signed-off-by: Simon Glass <[email protected]>
2022-09-16blk: Use a function for whether block devices are availableSimon Glass
At present we use HAVE_BLOCK_DEVICE to indicate when block devices are available. This is a very strange option, since it partially duplicates the BLK option used by driver model. It also covers both U-Boot proper and SPL, even though one might have block devices and another not. As a first step towards correcting this, create a new inline function called blk_enabled() which indicates if block devices are available. This cannot be used in Makefiles, or #if clauses, but can be used in C code. A function is useful because we cannot use CONFIG_IS_ENABLED(BLK) to decide if block devices are needed, since we must consider the legacy block interface, enabled by HAVE_BLOCK_DEVICE Update a few places where it can be used and drop some unnecessary #if checks around some functions in disk/part.c - rely on the compiler's dead-code elimination instead. Signed-off-by: Simon Glass <[email protected]>
2022-08-26disk: part: remove dependency to ubifs for splStefan Herbrechtsmeier
The spl doesn't support ubifs and thereby doesn't provide the ubifs_is_mounted function. Remove the dependency to ubifs for the spl. Signed-off-by: Stefan Herbrechtsmeier <[email protected]>
2022-04-12disk: part: add the device search failed log msgOleksii Bidnichenko
Add missing error message to blk_get_device_part_str. Signed-off-by: Oleksii Bidnichenko <[email protected]> Signed-off-by: Marcel Ziswiler <[email protected]>
2022-04-01fs: Add semihosting filesystemSean Anderson
This adds a filesystem which is backed by the host's filesystem. It is modeled off of sandboxfs, which has very similar aims. Semihosting doesn't support listing directories (except with SYS_SYSTEM), so neither do we. it's possible to optimize a bit for the common case of reading a whole file by omitting a call to smh_seek, but this is left as a future optimization. Signed-off-by: Sean Anderson <[email protected]>
2022-01-19doc: replace @return by Return:Heinrich Schuchardt
Sphinx expects Return: and not @return to indicate a return value. find . -name '*.c' -exec \ sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \; find . -name '*.h' -exec \ sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \; Signed-off-by: Heinrich Schuchardt <[email protected]>
2021-12-18part: call part_init() in blk_get_device_by_str() only for MMCAKASHI Takahiro
In blk_get_device_by_str(), the comment says: "Updates the partition table for the specified hw partition." Since hw partition is supported only on MMC, it makes no sense to do so for other devices. Signed-off-by: AKASHI Takahiro <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2021-12-09efi: Add uclass for devices provided by UEFI firmwareSimon Glass
UCLASS_EFI_LOADER is used for devices created by applications and drivers loaded by U-Boots UEFI implementation. This patch provides a new uclass (UCLASS_EFI_MEDIA) to be used for devices that provided by a UEFI firmware calling U-Boot as an EFI application. If the two uclasses can be unified, is left to future redesign. Signed-off-by: Simon Glass <[email protected]> Reviewed-by: Heinrich Schuchardt <[email protected]>
2021-11-18part: return -ENOSYS when get_info not valid.schspa
In some case, get_info() interface can be NULL, add this check to stop from crash. Signed-off-by: schspa <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2021-08-02global: Convert simple_strtoul() with hex to hextoul()Simon Glass
It is a pain to have to specify the value 16 in each call. Add a new hextoul() function and update the code to use it. Add a proper comment to simple_strtoul() while we are here. Signed-off-by: Simon Glass <[email protected]>
2021-05-26part: Add check for NULL dev_part_strSean Anderson
Some callers (e.g. cmd/fs.c) of fs_set_blk_dev may use a NULL dev_part_str. While blk_get_device_part_str handles this fine, part_get_info_by_dev_and_name does not. This fixes commands crashing when implicitly using bootdevice. The unit test has also been updated to set bootdevice to a known value and to restore it after we are done. Fixes: 7194527b6a ("cmd: fs: Use part_get_info_by_dev_and_name_or_num to parse partitions") Reported-by: Heinrich Schuchardt <[email protected]> Signed-off-by: Sean Anderson <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2021-04-22part: Fix bogus return from part_get_info_by_dev_and_nameSean Anderson
blk_get_device_by_str returns the device number on success. So we must check if the return was negative to determine an error. Signed-off-by: Sean Anderson <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2021-02-26part: Support string block devices in part_get_info_by_dev_and_nameSean Anderson
This adds support for things like "#partname" and "0.1#partname". The block device parsing is done like in blk_get_device_part_str. Signed-off-by: Sean Anderson <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2021-02-26part: Support getting whole disk from part_get_info_by_dev_and_name_or_numSean Anderson
This adds an option to part_get_info_by_dev_and_name_or_num to allow callers to specify whether whole-disk partitions are fine. Signed-off-by: Sean Anderson <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2021-02-26part: Give several functions more useful return valuesSean Anderson
Several functions in disk/part.c just return -1 on error. This makes them return different errnos for different failures. This helps callers differentiate between failures, even if they cannot read stdout. Signed-off-by: Sean Anderson <[email protected]> Reviewed-by: Simon Glass <[email protected]>